{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\nvoid main() {\n string s = readln.strip;\n string t = readln.strip;\n int n = to!(int)(s.length);\n int m = to!(int)(t.length);\n auto to = new int[n];\n to[] = -1;\n for (int i = 0; i < n; i++) {\n int j = i, count = 0;\n while (j < n && count < m) {\n count += s[j] == t[count];\n j++;\n }\n if (count == m) {\n to[i] = j;\n }\n }\n auto f = new int[][](n + 1, n + 1);\n foreach (ref g; f) {\n g[] = int.min;\n }\n for (int i = 0; i <= n; i++) {\n f[i][0] = 0;\n }\n for (int j = 0; j <= n; j++) {\n for (int i = 0; i < n; i++) {\n if (f[i][j] != int.min) {\n if (j + 1 <= n) { \n f[i + 1][j + 1] = max(f[i + 1][j + 1], f[i][j]);\n }\n f[i + 1][j] = max(f[i + 1][j], f[i][j]);\n if (to[i] != -1) {\n f[to[i]][j + to[i] - i - m] = max(f[to[i]][j + to[i] - i - m], f[i][j] + 1);\n }\n }\n }\n }\n auto ans = new int[n + 1];\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n ans[j] = max(ans[j], f[i][j]);\n }\n }\n writefln(\"%(%s %)\", ans);\n}\n", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint M, N;\nstring S, T;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tS = readToken;\n\t\tT = readToken;\n\t\t\n\t\tM = S.length;\n\t\tN = T.length;\n\t\tint[][] dp = new int[][](M + 1, M + 1);\n\t\tforeach (i; 0 .. M + 1) {\n\t\t\tdp[i][] = -1;\n\t\t}\n\t\tdp[0][0] = 0;\n\t\tforeach (i; 0 .. M)\t{\n\t\t\t{\n\t\t\t\tbool ok = true;\n\t\t\t\tint ii = i;\n\t\t\t\tforeach (j; 0 .. N) {\n\t\t\t\t\tfor (; ii < M && S[ii] != T[j]; ++ii) {}\n\t\t\t\t\tif (ii < M) {\n\t\t\t\t\t\t++ii;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tok = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (ok) {\n\t\t\t\t\tconst dk = (ii - i) - N;\n\t\t\t\t\tforeach (k; 0 .. M + 1) if (k + dk <= M) {\n\t\t\t\t\t\tif (dp[i][k] >= 0) {\n\t\t\t\t\t\t\tchmax(dp[ii][k + dk], dp[i][k] + 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (k; 0 .. M + 1) {\n\t\t\t\tif (dp[i][k] >= 0) {\n\t\t\t\t\tchmax(dp[i + 1][k], dp[i][k]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (k; 0 .. M + 1) if (k + 1 <= M) {\n\t\t\t\tif (dp[i][k] >= 0) {\n\t\t\t\t\tchmax(dp[i + 1][k + 1], dp[i][k]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln(dp[M].to!string.removechars(\"[],\"));\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\nvoid main() {\n string s = readln.strip;\n string t = readln.strip;\n int n = to!(int)(s.length);\n int m = to!(int)(t.length);\n auto to = new int[n];\n to[] = -1;\n for (int i = 0; i < n; i++) {\n int j = i, count = 0;\n while (j < n && count < m) {\n count += s[j] == t[count];\n j++;\n }\n if (count == m) {\n to[i] = j;\n }\n }\n auto f = new int[][](n + 1, n + 1);\n foreach (ref g; f) {\n g[] = int.min;\n }\n for (int i = 0; i <= n; i++) {\n f[i][0] = 0;\n }\n for (int j = 0; j <= n; j++) {\n for (int i = 0; i < n; i++) {\n if (f[i][j] != int.min) {\n if (j + 1 <= n) { \n f[i + 1][j + 1] = max(f[i + 1][j + 1], f[i][j]);\n }\n if (to[i] != -1) {\n f[to[i]][j + to[i] - i - m] = max(f[to[i]][j + to[i] - i - m], f[i][j] + 1);\n }\n }\n }\n }\n auto ans = new int[n + 1];\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n ans[j] = max(ans[j], f[i][j]);\n }\n }\n writefln(\"%(%s %)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\nvoid main() {\n string s = readln.strip;\n string t = readln.strip;\n int n = to!(int)(s.length);\n int m = to!(int)(t.length);\n auto to = new int[n];\n to[] = -1;\n for (int i = 0; i < n; i++) {\n int j = i, count = 0;\n while (j < n && count < m) {\n count += s[j] == t[count];\n j++;\n }\n if (count == m) {\n to[i] = j;\n }\n }\n auto f = new int[][](n + 1, n + 1);\n foreach (ref g; f) {\n g[] = int.min;\n }\n f[0][0] = 0;\n for (int j = 0; j <= n; j++) {\n for (int i = 0; i < n; i++) {\n if (f[i][j] != int.min) {\n if (i + 1 <= n && j + 1 <= n) { \n f[i + 1][j + 1] = max(f[i + 1][j + 1], f[i][j]);\n }\n if (to[i] != -1) {\n assert(j + to[i] - i - m <= n);\n f[to[i]][j + to[i] - i - m] = max(f[to[i]][j + to[i] - i - m], f[i][j] + 1);\n }\n }\n }\n }\n auto ans = new int[n + 1];\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n ans[j] = max(ans[j], f[i][j]);\n }\n }\n writefln(\"%(%s %)\", ans);\n}\n"}], "src_uid": "abdf06347e6db23932ef07020f49aa52"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n enum LIM = 1000;\n auto isnp = new bool[LIM];\n foreach (p; 2 .. LIM) {\n if (!isnp[p]) {\n for (int n = 2 * p; n < LIM; n += p) {\n isnp[n] = true;\n }\n }\n }\n auto dp = new int[LIM];\n dp[] = -1;\n dp[0] = 0;\n foreach (x; 0 .. LIM) {\n if (dp[x] >= 0) {\n foreach (n; 2 .. LIM - x) {\n if (isnp[n]) {\n chmax(dp[x + n], dp[x] + 1);\n }\n }\n }\n }\n debug {\n writeln(dp[0 .. 100]);\n }\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n int ans;\n if (N < LIM) {\n ans = dp[N];\n } else {\n ans = N / 4;\n if (N % 2 != 0) {\n --ans;\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto Q = readln.chomp.to!int;\n long ans;\n while (Q--) {\n auto n = readln.chomp.to!long;\n if (n % 4 == 0) {\n writeln(n / 4);\n } else if (n % 4 == 1) {\n if (n <= 5) writeln(-1);\n else writeln((n-9)/4 + 1);\n } else if (n % 4 == 2) {\n if (n == 2) writeln(-1);\n else writeln((n-6)/4 + 1);\n } else {\n if (n <= 11) writeln(-1);\n else writeln((n-15)/4 + 2);\n }\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n const long MAX = 10^^9 + 1;\n long[] primes;\n auto table = new bool[](10^^5);\n table.fill(true);\n table[0] = table[1] = false;\n foreach (i; 2..10^^5) {\n if (table[i]) {\n for (int j = i+i; j < 10^^5; j += i) {\n table[j] = false;\n }\n }\n }\n\n for (long i = 2; i * i < MAX; ++i) {\n if (table[i.to!int]) primes ~= i;\n }\n\n auto Q = readln.chomp.to!int;\n while (Q--) {\n auto n = readln.chomp.to!long;\n auto nn = n;\n long[] hoge;\n foreach (p; primes) {\n while (n % p == 0) {\n n /= p;\n hoge ~= p;\n }\n }\n if (n > 1) hoge ~= n;\n hoge.sort();\n if (hoge.length <= 1) writeln(-1);\n else writeln(nn / (hoge[0] * hoge[1]));\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n const long MAX = 10^^9 + 1;\n long[] primes;\n auto table = new bool[](10^^5);\n table.fill(true);\n table[0] = table[1] = false;\n foreach (i; 2..10^^5) {\n if (table[i]) {\n for (int j = i+i; j < 10^^5; j += i) {\n table[j] = false;\n }\n }\n }\n\n for (long i = 2; i * i < MAX; ++i) {\n if (table[i.to!int]) primes ~= i;\n }\n\n auto Q = readln.chomp.to!int;\n while (Q--) {\n auto n = readln.chomp.to!long;\n auto nn = n;\n long[] hoge;\n foreach (p; primes) {\n while (n % p == 0) {\n n /= p;\n hoge ~= p;\n }\n }\n hoge.sort();\n if (hoge.length <= 1) writeln(-1);\n else writeln(nn / (hoge[0] * hoge[1]));\n }\n}\n"}], "src_uid": "0c2550b2df0849a62969edf5b73e0ac5"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!int;\n auto aa = readln.split.to!(int[]);\n int[] os, es;\n foreach (i, a; aa) {\n if (a%2 == 0) {\n es ~= i.to!int+1;\n } else {\n os ~= i.to!int+1;\n }\n }\n int cnt;\n while (cnt < N-1 && os.length > 1) {\n writeln(os[0], \" \", os[1]);\n ++cnt;\n os = os[2..$];\n }\n while (cnt < N-1) {\n writeln(es[0], \" \", es[1]);\n ++cnt;\n es = es[2..$];\n }\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint [2] cur;\n\t\tint [2] [] ans;\n\t\tforeach (int i, c; a[0..$ - 1])\n\t\t{\n\t\t\tif (cur[c & 1])\n\t\t\t{\n\t\t\t\tans ~= [cur[c & 1], i + 1];\n\t\t\t\tcur[c & 1] = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcur[c & 1] = i + 1;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%(%s %)\\n%)\") (ans);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tint[][] ans;\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\t\n\t\tdebug writeln(\"n:\", n);\n\t\tint cnt;\n\t\tint x = -1;\n\t\tforeach (i; 0..n*2)\n\t\t{\n\t\t\tif (cnt == n-1) break;\n\t\t\tif (a[i] % 2)\n\t\t\t{\n\t\t\t\tif (x == -1)\n\t\t\t\t{\n\t\t\t\t\tx = i;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans ~= [x, i];\n\t\t\t\t\tx = -1;\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"ti:\", ti, \" cnt:\", cnt);\n\t\tx = -1;\n\t\tforeach (i; 0..n*2)\n\t\t{\n\t\t\tif (cnt == n-1) break;\n\t\t\tdebug writeln(\"i:\", i);\n\t\t\tif ((a[i] % 2) == 0)\n\t\t\t{\n\t\t\t\tif (x == -1)\n\t\t\t\t{\n\t\t\t\t\tx = i;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans ~= [x, i];\n\t\t\t\t\tx = -1;\n\t\t\t\t\t++cnt;\n\t\t\t\t} \n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"ti:\", ti, \" cnt:\", cnt);\n\t}\n\t\n\tdebug writeln(ans);\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0]+1, \" \", e[1]+1);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tint[][] ans;\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\t\n\t\tdebug writeln(\"n:\", n);\n\t\tint cnt;\n\t\tint x = -1;\n\t\tforeach (i; 0..n*2)\n\t\t{\n\t\t\tif (cnt == n-1) break;\n\t\t\tif (a[i] % 2)\n\t\t\t{\n\t\t\t\tif (x == -1)\n\t\t\t\t{\n\t\t\t\t\tx = a[i];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans ~= [x, a[i]];\n\t\t\t\t\tx = -1;\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"ti:\", ti, \" cnt:\", cnt);\n\t\tx = -1;\n\t\tforeach (i; 0..n*2)\n\t\t{\n\t\t\tif (cnt == n-1) break;\n\t\t\tdebug writeln(\"i:\", i);\n\t\t\tif ((a[i] % 2) == 0)\n\t\t\t{\n\t\t\t\tif (x == -1)\n\t\t\t\t{\n\t\t\t\t\tx = a[i];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans ~= [x, a[i]];\n\t\t\t\t\tx = -1;\n\t\t\t\t\t++cnt;\n\t\t\t\t} \n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"ti:\", ti, \" cnt:\", cnt);\n\t}\n\t\n\tdebug writeln(ans);\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0], \" \", e[1]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "96fac9f9377bf03e144067bf93716d3d"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto x = readln.strip.to !(int);\r\n\r\n\t\tauto f = new int [4] [n + 1];\r\n\t\tf[0][0] = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tf[i + 1][0] = f[i][].maxElement;\r\n\t\t\tf[i + 1][1] = f[i][0] + 1;\r\n\t\t\tif (i >= 1 &&\r\n\t\t\t a[i] + a[i - 1] >= x * 2)\r\n\t\t\t{\r\n\t\t\t\tf[i + 1][2] = f[i][1] + 1;\r\n\t\t\t\tif (i >= 2 &&\r\n\t\t\t\t a[i] + a[i - 1] + a[i - 2] >= x * 3)\r\n\t\t\t\t{\r\n\t\t\t\t\tf[i + 1][3] =\r\n\t\t\t\t\t f[i][2..$].maxElement + 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tf[n][].maxElement.writeln;\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n const X = readLong;\n \n auto B = new long[N + 1];\n foreach (i; 0 .. N) {\n B[i + 1] = B[i] + (A[i] - X);\n }\n debug {\n writeln(\"B = \", B);\n }\n \n auto dp = new int[][](N + 2, 2);\n foreach (i; 0 .. N + 2) {\n dp[i][] = -1;\n }\n dp[0][0] = 0;\n foreach (i; 0 .. N + 2) foreach (s; 0 .. 2) if (dp[i][s] >= 0) {\n // cut\n if (i + 1 <= N + 1) {\n chmax(dp[i + 1][0], dp[i][s]);\n }\n if (i + 2 <= N + 1 && B[i] > B[i + 1]) {\n chmax(dp[i + 2][1], dp[i][s] + 1);\n }\n // 1\n if (i + 1 <= N + 1) {\n if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i]) {\n chmax(dp[i + 1][0], dp[i][s] + 1);\n }\n }\n // 2\n if (i + 2 <= N + 1 && B[i] > B[i + 1]) {\n if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i + 1]) {\n chmax(dp[i + 2][1], dp[i][s] + 2);\n }\n }\n }\n \n const ans = dp[$ - 1].maxElement;\n writeln(ans - 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n const X = readLong;\n \n auto B = new long[N + 1];\n foreach (i; 0 .. N) {\n B[i + 1] = B[i] + (A[i] - X);\n }\n debug {\n writeln(\"B = \", B);\n }\n \n auto dp = new int[][](N + 2, 2);\n foreach (i; 0 .. N + 2) {\n dp[i][] = -1;\n }\n dp[0][0] = 0;\n foreach (i; 0 .. N + 2) foreach (s; 0 .. 2) if (dp[i][s] >= 0) {\n // cut\n if (i + 1 <= N + 1) {\n chmax(dp[i + 1][0], dp[i][s]);\n }\n if (i + 2 <= N + 1 && B[i] > B[i + 1]) {\n chmax(dp[i + 2][0], dp[i][s] + 1);\n }\n // 1\n if (i + 1 <= N + 1) {\n if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i]) {\n chmax(dp[i + 1][0], dp[i][s] + 1);\n }\n }\n // 2\n if (i + 2 <= N + 1 && B[i] > B[i + 1]) {\n if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i + 1]) {\n chmax(dp[i + 2][1], dp[i][s] + 2);\n }\n }\n }\n \n const ans = dp[$ - 1].maxElement;\n writeln(ans - 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n const X = readLong;\n \n auto B = new long[N + 1];\n foreach (i; 0 .. N) {\n B[i + 1] = B[i] + (A[i] - X);\n }\n debug {\n writeln(\"B = \", B);\n }\n \n auto dp = new int[][](N + 2, 2);\n foreach (i; 0 .. N + 2) {\n dp[i][] = -1;\n }\n dp[0][0] = 0;\n foreach (i; 0 .. N + 2) foreach (s; 0 .. 2) if (dp[i][s] >= 0) {\n // cut\n if (i + 1 <= N + 1) {\n chmax(dp[i + 1][0], dp[i][s]);\n }\n // 1\n if (i + 1 <= N + 1) {\n if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i]) {\n chmax(dp[i + 1][0], dp[i][s] + 1);\n }\n }\n // 2\n if (i + 2 <= N + 1 && B[i] > B[i + 1]) {\n if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i + 1]) {\n chmax(dp[i + 2][1], dp[i][s] + 2);\n }\n }\n }\n \n const ans = dp[$ - 1].maxElement;\n writeln(ans - 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto x = readln.strip.to !(int);\r\n\r\n\t\tauto f = new int [4] [n + 1];\r\n\t\tf[0][0] = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tf[i + 1][0] = f[i][].maxElement;\r\n\t\t\tf[i + 1][1] = f[i][0] + 1;\r\n\t\t\tif (i >= 1 &&\r\n\t\t\t a[i] + a[i - 1] >= x * 2)\r\n\t\t\t{\r\n\t\t\t\tf[i + 1][2] = f[i][1] + 1;\r\n\t\t\t\tif (i >= 2 &&\r\n\t\t\t\t a[i] + a[i - 1] + a[i - 2] >= x * 3)\r\n\t\t\t\t{\r\n\t\t\t\t\tf[i + 1][3] = f[i][2] + 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tf[n][].maxElement.writeln;\r\n\t}\r\n}\r\n"}], "src_uid": "79ecf771f4a54c2c9f988e069f7bfceb"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n int k = cin.readInt;\n if (k == 0) {\n if (n % 2 == 0) writeln(0);\n else writeln(1);\n } else {\n if (k > n) writeln(k - n);\n else {\n if (n % 2 == 0 && k % 2 == 1) writeln(1);\n else if (n % 2 == 1 && k % 2 == 0) writeln(1);\n else writeln(0);\n }\n } \n } \n}", "positive_code": [{"source_code": "// unihernandez22\n// https://codeforces.com/contest/1401/problem/A\n// implementation\n\nimport std.stdio;\n\nvoid main() {\n int n, k, t;\n scanf(\"%d\", &t);\n foreach (_; 0 .. t) {\n scanf(\"%d %d\", &n, &k);\n if (k <= n) {\n if (n%2 == k%2) {\n writeln(\"0\");\n } else {\n writeln(\"1\");\n }\n } else\n writeln(k - n);\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\twriteln (k > n ? k - n : ((n ^ k) & 1));\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tif (k >= n)\n\t\t{\n\t\t\tans[ti] = k - n;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tn -= k;\n\t\t\tans[ti] = n % 2;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n int k = cin.readInt;\n if (n > k) {\n if (n % 2 == 0) writeln(0);\n else writeln(1);\n } else {\n writeln(k - n);\n }\n } \n}"}], "src_uid": "f98d1d426f68241bad437eb221f617f4"} {"source_code": "module acmd;\n\nimport std.stdio;\nimport std.conv;\n\nint main () {\n version (offline_judje) {\n stdin.reopen (\"input.txt\", \"rt\");\n }\n int n;\n readf!\" %d\" (n);\n foreach (i; 0 .. n) {\n int num;\n readf!\" %d\" (num);\n if (num % 2 == 0)\n num--;\n writef!\"%d \" (num);\n }\n\n return 0;\n}\n\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.stdio;\n\nvoid main()\n{\n int n;\n readf !\"%s\\n\" (n);\n auto arr = readln.splitter.map!(to!int).map!(x => x-(1 - x%2));\n writefln(\"%-(%d %)\", arr);\n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\n\nvoid main()\n{\n auto n = readln.strip.to!ulong;\n auto a = readln.strip.split();\n foreach (i, v; a)\n {\n auto va = v.to!ulong;\n if (va % 2 == 1)\n write(va, \" \");\n else\n write(va - 1, \" \");\n }\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr = arr.map!(x => x % 2 == 0 ? x - 1 : x).array;\n \n arr.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\nvoid main(){\n auto n = readln.strip.to!ulong;\n auto s = readln.strip.split();\n foreach (i, k; s){\n auto ans = k.to!ulong;\n if (ans % 2) write(ans, \" \");\n else write(ans - 1, \" \");\n }\n}"}, {"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint[] m = new int[a];\n\tfor (int i=0; i<a; i++)\n\t{\n\t\treadf(\" %d\", &m[i]);\n\t}\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tif (m[i]%2==0)\n\t\t{\n\t\t\tm[i]=m[i]-1;\n\t\t}\n\t}\n\tfor (int i=0; i<a; i++)\n\t{\n\t\twriteln(m[i]);\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "d00696cb27c679dda6e2e29314a8432b"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1426/problem/A\n// math\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\n int n, x;\n while(t--) {\n readf(\"%s %s\\n\", &n, &x);\n if(n <= 2) {\n \"1\".writeln;\n continue;\n }\n int ans = (n - 3)/x + 2;\n ans.writeln;\n }\n}\n\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nvoid play(){\n int n, x;\n n = rd!int;\n x = rd!int;\n if(n <= 2){\n writeln(1);\n }else{\n n -= 3;\n int apt = n/x;\n writeln(2 + apt);\n }\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}], "negative_code": [], "src_uid": "8b50a0eb2e1c425455b132683d3e6047"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint, q = rint;\n\n\tbool[][] xf = new bool[][](2, n);\n\tint cnt;\n\n\tforeach(_; 0 .. q){\n\t\tint r = rint - 1, c = rint - 1;\n\t\tif(xf[r][c]){\n\t\t\txf[r][c] = 0;\n\t\t\tif(c > 0 && xf[1 - r][c - 1]) cnt -= 1;\n\t\t\tif(xf[1 - r][c]) cnt -= 1;\n\t\t\tif(c < n - 1 && xf[1 - r][c + 1]) cnt -= 1;\n\t\t}\n\t\telse{\n\t\t\txf[r][c] = 1;\n\t\t\tif(c > 0 && xf[1 - r][c - 1]) cnt += 1;\n\t\t\tif(xf[1 - r][c]) cnt += 1;\n\t\t\tif(c < n - 1 && xf[1 - r][c + 1]) cnt += 1;\n\t\t}\n\t\tif(cnt > 0) \"No\".writeln;\n\t\telse \"Yes\".writeln;\n\t}\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto board = new bool[][] (2, n);\n \n alias t = Tuple!(int, int);\n auto vert = make!(RedBlackTree!int);\n auto cross = make!(RedBlackTree!t);\n \n foreach (_; 0 .. q) {\n int r, c;\n readf(\"%s %s\", &r, &c);\n readln;\n \n --r, --c;\n board[r][c] = !board[r][c];\n \n if (board[r][c]) {\n if (board[1 - r][c]) { vert.insert(c); }\n \n if (c > 0 && board[1-r][c-1]) { cross.insert(tuple(1-r, c-1)); }\n if (c < n-1 && board[1-r][c+1]) { cross.insert(tuple(r, c)); }\n } else {\n if (c in vert) { vert.removeKey(c); }\n \n if (c > 0 && tuple(1-r, c-1) in cross) { cross.removeKey(tuple(1-r, c-1)); }\n if (c < n-1 && tuple(r, c) in cross) { cross.removeKey(tuple(r, c)); }\n }\n \n writeln(vert.empty() && cross.empty() ? \"Yes\" : \"No\");\n }\n}"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n auto n = next!long, q = next!long;\n auto state = new bool[][2];\n foreach(ref row; state)\n row = new bool[n.ind];\n auto conns = long(0);\n foreach(i; 0 .. q)\n {\n auto r = next!long - 1, c = next!long - 1;\n state[r.ind][c.ind] = !state[r.ind][c.ind];\n if (state[r.ind][c.ind])\n {\n foreach(oc; c - 1 .. c + 2)\n if (oc >= 0 && oc < n)\n if (state[(r^1).ind][oc.ind])\n conns++;\n }\n else\n {\n foreach(oc; c - 1 .. c + 2)\n if (oc >= 0 && oc < n)\n if (state[(r^1).ind][oc.ind])\n conns--;\n }\n if (conns > 0 || state[0][0] || state[1][$ - 1])\n writeln(\"No\");\n else\n writeln(\"Yes\");\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto q = RD!int;\n\tauto ans = new bool[](q);\n\tauto cell = new bool[][](2, n);\n\tbool[int] set;\n\tforeach (i; 0..q)\n\t{\n\t\tauto r = RD!int-1;\n\t\tauto c = RD!int-1;\n\t\tcell[r][c] = !cell[r][c];\n\t\tdebug writeln(cell[0]);\n\t\tdebug writeln(cell[1]);\n\t\tif (cell[r][c])\n\t\t{\n\t\t\tbool ok = i == 0 ? true : ans[i-1];\n\t\t\tforeach (j; max(0, c-1)..min(n, c+2))\n\t\t\t{\n\t\t\t\tif (cell[r^1][j])\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\tset[r*n+c] = true; \n\t\t\t\t}\n\t\t\t}\n\t\t\tans[i] = ok;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (set.get(r*n+c, false))\n\t\t\t\tset.remove(r*n+c);\n\n\t\t\tforeach (j; max(0, c-1)..min(n, c+2))\n\t\t\t{\n\t\t\t\tif (!cell[r^1][j]) continue;\n\t\t\t\tif (set.get((r^1)*n+j, false) == false) continue;\n\t\t\t\tbool ok = true;\n\t\t\t\tforeach (k; max(0, j-1)..min(n, j+2))\n\t\t\t\t{\n\t\t\t\t\tif (cell[r][k])\n\t\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t\tif (ok)\n\t\t\t\t\tset.remove((r^1)*n+j);\n\t\t\t}\n\t\t\tans[i] = set.length == 0;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"Yes\" : \"No\");\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, q;\n\twhile (readf !(\" %s %s\") (n, q) > 0)\n\t{\n\t\tauto wall = new bool [] [] (2, n + 2);\n\t\tint block = 0;\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tint mult = wall[u][v] ? -1 : +1;\n\t\t\tforeach (k; -1..+2)\n\t\t\t{\n\t\t\t\tblock += wall[u ^ 1][v + k] * mult;\n\t\t\t}\n\t\t\twall[u][v] ^= true;\n\t\t\twriteln (block == 0 ? \"Yes\" : \"No\");\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const Q = readInt();\n auto R = new int[Q];\n auto C = new int[Q];\n foreach (q; 0 .. Q) {\n R[q] = readInt() - 1;\n C[q] = readInt() - 1;\n }\n \n auto can = new bool[][](2, N);\n foreach (x; 0 .. 2) {\n can[x][] = true;\n }\n \n auto vals = new int[N - 1];\n vals[] = 1;\n int now = N - 1;\n \n void check(int y) {\n if (0 <= y && y < N - 1) {\n now -= vals[y];\n vals[y] = (can[0][y] && can[0][y + 1] || can[1][y] && can[1][y + 1]) ? 1 : 0;\n now += vals[y];\n }\n }\n \n foreach (q; 0 .. Q) {\n can[R[q]][C[q]] = !can[R[q]][C[q]];\n check(C[q] - 1);\n check(C[q]);\n writeln((now == N - 1) ? \"Yes\" : \"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "af036416721694d1843368988ca78e8e"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\t\n\tX[] as, bs;\n\tforeach(i; 2 .. n){\n\t\tif(ask(2, 0, 1, i) < 0) as ~= X(i, ask(1, 0, 1, i));\n\t\telse bs ~= X(i, ask(1, 1, 0, i));\n\t}\n\t\n\tX az = X(-1, -1), bz = X(-1, -1);\n\tforeach(a; as) if(a.v > az.v) az = a;\n\tforeach(b; bs) if(b.v > bz.v) bz = b;\n\t\n\tX[] a0s, a1s, b0s, b1s;\n\tforeach(a; as){\n\t\tif(a.u == az.u) continue;\n\t\tif(ask(2, 0, az.u, a.u) < 0) a0s ~= a;\n\t\telse a1s ~= a;\n\t}\n\tforeach(b; bs){\n\t\tif(b.u == bz.u) continue;\n\t\tif(ask(2, 1, bz.u, b.u) < 0) b0s ~= b;\n\t\telse b1s ~= b;\n\t}\n\ta0s.sort!\"a.v<b.v\"();\n\ta1s.sort!\"a.v>b.v\"();\n\tb0s.sort!\"a.v<b.v\"();\n\tb1s.sort!\"a.v>b.v\"();\n\t\n\tX[] ans = [X(0, 0)] ~ a0s;\n\tif(az.u >= 0) ans ~= az;\n\tans ~= a1s ~ [X(1, 0)] ~ b0s;\n\tif(bz.u >= 0) ans ~= bz;\n\tans ~= b1s;\n\twriteln(\"0 \", ans.map!(x => x.u + 1).map!(to!string).array.join(\" \"));\n}\n\nstruct X{\n\tint u;\n\tlong v;\n}\n\nlong ask(int t, int i, int j, int k){\n\twriteln(t, \" \", i + 1, \" \", j + 1, \" \", k + 1);\n\tstdout.flush;\n\treturn rlong;\n}\n\n \n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nlong askArea (int i, int j, int k)\n{\n\twriteln (1, \" \", i + 1, \" \", j + 1, \" \", k + 1);\n\tstdout.flush ();\n\tauto res = readln.strip.to !(long);\n\treturn res;\n}\n\nint askSign (int i, int j, int k)\n{\n\twriteln (2, \" \", i + 1, \" \", j + 1, \" \", k + 1);\n\tstdout.flush ();\n\tauto res = readln.strip.to !(int);\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\n\t\tint i = 0;\n\t\tint j = 1;\n\t\tforeach (k; 2..n)\n\t\t{\n\t\t\tif (askSign (i, j, k) < 0)\n\t\t\t{\n\t\t\t\tj = k;\n\t\t\t}\n\t\t}\n\n\t\talias Pair = Tuple !(long, q{area}, int, q{num});\n\t\tPair [] p;\n\t\tforeach (k; 1..n)\n\t\t{\n\t\t\tif (k != j)\n\t\t\t{\n\t\t\t\tauto cur = askArea (i, j, k);\n\t\t\t\tp ~= Pair (cur, k);\n\t\t\t}\n\t\t}\n\t\tsort (p);\n\n\t\tint [] left = [];\n\t\tint [] right = [i, j];\n\t\tforeach (const ref c; p)\n\t\t{\n\t\t\tauto num = c.num;\n\t\t\tif (askSign (right[$ - 2], right[$ - 1], num) < 0)\n\t\t\t{\n\t\t\t\tleft ~= right[$ - 1];\n\t\t\t\tright.length -= 1;\n\t\t\t\tright.assumeSafeAppend ();\n\t\t\t}\n\t\t\tright ~= num;\n\t\t}\n\n\t\tauto ans = right ~ left.retro.array;\n\t\tans[] += 1;\n\t\twritefln (\"0 %(%s %)\", ans);\n\t\tstdout.flush ();\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\n\ndebug {\n long[] X, Y;\n}\n\nlong Ask(int t, int i, int j, int k) {\n long ret;\n debug {\n ret = (X[j] - X[i]) * (Y[k] - Y[i]) - (Y[j] - Y[i]) * (X[k] - X[i]);\n if (t == 1) {\n ret = abs(ret);\n } else {\n ret = sgn(ret);\n }\n } else {\n writeln(t, \" \", i + 1, \" \", j + 1, \" \", k + 1);\n stdout.flush;\n ret = readLong();\n }\n return ret;\n}\n\nvoid main() {\n N = readInt();\n debug {\n X = new long[N];\n Y = new long[N];\n foreach (i; 0 .. N) {\n X[i] = readLong();\n Y[i] = readLong();\n }\n }\n \n auto as = new long[N];\n foreach (i; 2 .. N) {\n as[i] = Ask(1, 0, 1, i);\n as[i] *= Ask(2, 0, 1, i);\n }\n debug {\n writeln(\"as = \", as);\n }\n \n int[] ans;\n ans ~= 0;\n {\n int im;\n foreach (i; 2 .. N) {\n if (as[im] > as[i]) {\n im = i;\n }\n }\n if (im != 0) {\n int[] ims, ips;\n foreach (i; 2 .. N) {\n if (as[i] < 0 && i != im) {\n const res = Ask(2, 0, im, i);\n (res < 0) ? (ims ~= i) : (ips ~= i);\n }\n }\n ims.sort!((i, j) => (as[i] > as[j]));\n ips.sort!((i, j) => (as[i] < as[j]));\n foreach (i; ims) ans ~= i;\n ans ~= im;\n foreach (i; ips) ans ~= i;\n }\n }\n ans ~= 1;\n {\n int im;\n foreach (i; 2 .. N) {\n if (as[im] < as[i]) {\n im = i;\n }\n }\n if (im != 0) {\n int[] ims, ips;\n foreach (i; 2 .. N) {\n if (as[i] > 0 && i != im) {\n const res = Ask(2, 0, im, i);\n (res < 0) ? (ims ~= i) : (ips ~= i);\n }\n }\n ims.sort!((i, j) => (as[i] < as[j]));\n ips.sort!((i, j) => (as[i] > as[j]));\n foreach (i; ims) ans ~= i;\n ans ~= im;\n foreach (i; ips) ans ~= i;\n }\n }\n \n write(0);\n foreach (i; ans) {\n write(\" \", i + 1);\n }\n writeln();\n stdout.flush;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\t\n\tX[] as, bs;\n\tforeach(i; 2 .. n){\n\t\tif(ask(2, 0, 1, i) < 0) as ~= X(i, ask(1, 0, 1, i));\n\t\telse bs ~= X(i, ask(1, 1, 0, i));\n\t}\n\t\n\tX az = X(-1, -1), bz = X(-1, -1);\n\tforeach(a; as) if(a.v > az.v) az = a;\n\tforeach(b; bs) if(b.v > bz.v) bz = b;\n\t\n\tX[] a0s, a1s, b0s, b1s;\n\tforeach(a; as){\n\t\tif(a.u == az.u || ask(2, 0, az.u, a.u) < 0) a0s ~= a;\n\t\telse a1s ~= a;\n\t}\n\tforeach(b; bs){\n\t\tif(b.u == bz.u || ask(2, 1, bz.u, b.u) < 0) b0s ~= b;\n\t\telse b1s ~= b;\n\t}\n\ta0s.sort!\"a.v<b.v\"();\n\ta1s.sort!\"a.v>b.v\"();\n\tb0s.sort!\"a.v<b.v\"();\n\tb1s.sort!\"a.v>b.v\"();\n\t\n\tX[] ans = [X(0, 0)] ~ a0s ~ a1s ~ [X(1, 0)] ~ b0s ~ b1s;\n\twriteln(\"0 \", ans.map!(x => x.u + 1).map!(to!string).array.join(\" \"));\n}\n\nstruct X{\n\tint u;\n\tlong v;\n}\n\nlong ask(int t, int i, int j, int k){\n\twriteln(t, \" \", i + 1, \" \", j + 1, \" \", k + 1);\n\tstdout.flush;\n\treturn rlong;\n}\n\n \n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tint p = uniform(0, n);\n\tint q = uniform(0, n);\n\tif(p == q) q += 1, q %= n;\n\t\n\tint[] as, bs;\n\tforeach(i; 0 .. n){\n\t\tif(i == p || i == q) continue;\n\t\tlong x = ask(2, p, q, i);\n\t\tif(x < 0) as ~= i;\n\t\telse bs ~= i;\n\t}\n\tint[] ans = [p] ~ calc(as, p, q) ~ [q] ~ calc(bs, q, p);\n\t\n\tint i0;\n\twhile(ans[i0] != 0) i0 += 1;\n\t\n\tans = ans[i0 .. $] ~ ans[0 .. i0];\n\tans.map!(x => x + 1).map!(to!string).array.join(\" \").writeln;\n}\n\nint[] calc(int[] us, int p, int q){\n\tif(us.length <= 1) return us;\n\tint[] as, bs;\n\tint r = 0;\n\tlong highest = 0;\n\tforeach(u; us){\n\t\tlong w = ask(1, p, q, u);\n\t\tif(w > highest) r = u, highest = w;\n\t}\n\tforeach(u; us){\n\t\tif(r == u) continue;\n\t\tlong x = ask(2, p, r, u);\n\t\tif(x < 0) as ~= u;\n\t\telse bs ~= u;\n\t}\n\treturn calc(as, p, r) ~ [r] ~ calc(bs, r, q);\n}\n\nlong ask(int t, int i, int j, int k){\n\twriteln(t, \" \", i + 1, \" \", j + 1, \" \", k + 1);\n\tstdout.flush;\n\treturn rlong;\n}\n\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\t\n\tX[] as, bs;\n\tX az = X(-1, -1), bz = X(-1, -1);\n\tforeach(i; 2 .. n){\n\t\tif(ask(2, 0, 1, i) < 0){\n\t\t\tX a = X(i, ask(1, 0, 1, i));\n\t\t\tas ~= a;\n\t\t\tif(az.v < a.v) az = a;\n\t\t}\n\t\telse{\n\t\t\tX b = X(i, ask(1, 1, 0, i));\n\t\t\tbs ~= b;\n\t\t\tif(bz.v < b.v) bz = b;\n\t\t}\n\t}\n\tX[] a0s, a1s, b0s, b1s;\n\tforeach(a; as){\n\t\tif(a.u == az.u) continue;\n\t\tif(ask(2, 0, az.u, a.u) < 0) a0s ~= a;\n\t\telse a1s ~= a;\n\t}\n\tforeach(b; bs){\n\t\tif(b.u == bz.u) continue;\n\t\tif(ask(2, 1, bz.u, b.u) < 0) b0s ~= b;\n\t\telse b1s ~= b;\n\t}\n\ta0s.sort!\"a.v<b.v\"();\n\ta1s.sort!\"a.v>b.v\"();\n\tb0s.sort!\"a.v<b.v\"();\n\tb1s.sort!\"a.v>b.v\"();\n\t\n\tX[] ans = [X(0, 0)] ~ a0s ~ az ~ a1s ~ [X(1, 0)] ~ b0s ~ bz ~ b1s;\n\twriteln(\"0 \", ans.map!(x => x.u + 1).map!(to!string).array.join(\" \"));\n}\n\nstruct X{\n\tint u;\n\tlong v;\n}\n\nlong ask(int t, int i, int j, int k){\n\twriteln(t, \" \", i + 1, \" \", j + 1, \" \", k + 1);\n\tstdout.flush;\n\treturn rlong;\n}\n\n \n"}], "src_uid": "6c0ed9fe0a104fc9380c199003a22e90"} {"source_code": "module main;\n\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.typecons;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.functional;\nimport std.container;\n\n\nint main()\n{\n auto n = readln().strip().to! (int);\n auto f = [0] ~ readln().strip().split().map! (to! (int)).array();\n\n auto dict = new int [n + 2];\n foreach (int i; 1..f.length)\n dict[f[i]] = i;\n\n long result;\n for (int i = 2; i <= n; i++)\n result += abs(dict[i] - dict[i - 1]);\n\n writeln(result);\n\n\treturn 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.regex;\nimport std.file;\nimport std.math;\nvoid main()\n{\n \n string[] inp = split(strip(readln()));\n int n = to!int(inp[0]);\n string[] s = split(strip(readln()));\n int[] a=new int[s.length];\n for(int i = 0 ; i < s.length ; i++)\n {\n a[to!int(s[i])-1]=i;\n }\n long res;\n for(int i = 1 ; i < a.length ; i++)\n {\n res+=abs(a[i]-a[i-1]);\n }\n writeln(res);\n\n //writeln(\"-1\");\n\n}\n\n \n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.split.map !(to !(int)).array;\n\t\tauto q = new int [n];\n\t\tforeach (i, c; p)\n\t\t{\n\t\t\tq[c - 1] = i;\n\t\t}\n\t\t(n - 1).iota.map !(i => abs (q[i + 1] - q[i]))\n\t\t .sum (0L).writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "module main;\n\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.typecons;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.functional;\nimport std.container;\n\n\nint main()\n{\n auto n = readln().strip().to! (int);\n auto f = readln().strip().split().map! (to! (int)).array();\n\n int[int] dict;\n foreach (int i; 0..f.length)\n dict[f[i] - 1] = i;\n\n int result;\n for (int i = 0; i < n - 1; i++)\n result += abs(dict[i + 1] - dict[i]);\n\n writeln(result);\n\n\treturn 0;\n}\n"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.typecons;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.functional;\nimport std.container;\n\n\nint main()\n{\n auto n = readln().strip().to! (int);\n auto f = [0] ~ readln().strip().split().map! (to! (int)).array();\n\n auto dict = new int [n + 2];\n foreach (int i; 1..f.length)\n dict[f[i]] = i;\n\n int result;\n for (int i = 2; i <= n; i++)\n result += abs(dict[i] - dict[i - 1]);\n\n writeln(result);\n\n\treturn 0;\n}\n"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.typecons;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.functional;\nimport std.container;\n\n\nint main()\n{\n auto n = readln().strip().to! (int);\n auto f = [0] ~ readln().strip().split().map! (to! (int)).array();\n\n int[int] dict;\n foreach (int i; 1..f.length)\n dict[f[i]] = i;\n\n int result;\n for (int i = 1; i <= n - 1; i++)\n result += abs(dict[i + 1] - dict[i]);\n\n writeln(result);\n\n\treturn 0;\n}\n"}], "src_uid": "54e2b6bea0dc6ee68366405945af50c6"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tlong res = long.max;\r\n\t\tforeach (k; 0..n)\r\n\t\t{\r\n\t\t\tlong cur = 0;\r\n\t\t\tlong lo = 0;\r\n\t\t\tforeach_reverse (i; 0..k)\r\n\t\t\t{\r\n\t\t\t\tlong steps = lo / a[i] - 1;\r\n\t\t\t\tcur -= steps;\r\n\t\t\t\tlo = steps * a[i];\r\n\t\t\t}\r\n\t\t\tlong hi = 0;\r\n\t\t\tforeach (j; k + 1..n)\r\n\t\t\t{\r\n\t\t\t\tlong steps = hi / a[j] + 1;\r\n\t\t\t\tcur += steps;\r\n\t\t\t\thi = steps * a[j];\r\n\t\t\t}\r\n\t\t\tres = min (res, cur);\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10L^^18;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt;\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n \n long ans = INF;\n foreach (i; 0 .. N) {\n long cost;\n {\n long b = 0;\n foreach_reverse (j; 0 .. i) {\n const k = b / A[j] + 1;\n cost += k;\n b = A[j] * k;\n }\n }\n {\n long b = 0;\n foreach (j; i + 1 .. N) {\n const k = b / A[j] + 1;\n cost += k;\n b = A[j] * k;\n }\n }\n debug {\n writeln(i, \": \", cost);\n }\n chmin(ans, cost);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\tauto a = RDA;\r\n\r\n\tlong ans = long.max;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tlong cnt;\r\n\t\t{\r\n\t\t\tlong last;\r\n\t\t\tforeach_reverse (j; 0..i)\r\n\t\t\t{\r\n\t\t\t\tauto c = (last+a[j]) / a[j];\r\n\t\t\t\tlast = a[j] * c;\r\n\t\t\t\tcnt += c;\r\n\t\t\t}\r\n\t\t}\r\n\t\t{\r\n\t\t\tlong last;\r\n\t\t\tforeach (j; i+1..n)\r\n\t\t\t{\r\n\t\t\t\tauto c = (last+a[j]) / a[j];\r\n\t\t\t\tlast = a[j] * c;\r\n\t\t\t\tcnt += c;\r\n\t\t\t}\r\n\t\t}\r\n\t\tans.chmin(cnt);\r\n\t}\r\n\r\n\twriteln(ans);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "da2fb0ea61808905a133021223f6148d"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto p = new int[] (k+1);\n auto g = new int[][] (n+1);\n foreach (i; 1 .. k+1) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n p[i] = x;\n g[x] ~= y;\n g[y] ~= x;\n }\n \n int ok = 0;\n auto vis = new bool[] (n+1);\n vis[] = false;\n foreach (i; 1 .. k+1) {\n if (vis[p[i]]) { continue; }\n \n int dfs(int v) {\n vis[v] = true;\n int subn = 0;\n foreach (u; g[v]) {\n if (vis[u]) { continue; }\n subn += dfs(u);\n }\n \n return 1 + subn;\n }\n \n ok += dfs(p[i]) - 1;\n }\n \n int ans = k - ok;\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nimport std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid solve(){\n\tint n = rint, k = rint;\n\t\n\tNode[] nodes;\n\tforeach(i; 0 .. n) nodes ~= new Node(i, 0);\n\t\n\tEdge[] edges;\n\tforeach(j; 0 .. k){\n\t\tint x = rint - 1, y = rint - 1;\n\t\tedges ~= new Edge(nodes[x], nodes[y], 0);\n\t\tnodes[x].value += 1, nodes[y].value += 1;\n\t}\n\t\n\tforeach(ed; edges){\n\t\tif(ed.node1.group.id != ed.node2.group.id){\n\t\t\ted.node1.group.eat(ed.node2.group);\n\t\t}\n\t}\n\t\n\tlong ans;\n\tforeach(nd; nodes){\n\t\tif(nd.group.id != nd.id) continue;\n\t\tlong edcnt;\n\t\tforeach(nx; nd.group.nodes) edcnt += nx.value;\n\t\tans += edcnt / 2 - (nd.group.nodes.length - 1);\n\t}\n\t\n\tans.writeln;\n\t\n}\n\n\n// Union-find \u203b\u591a\u5206\u4f7f\u3044\u3084\u3059\u3044\u3084\u3064\nclass Edge{\n\tNode node1;\n\tNode node2;\n\tlong value;\n\tthis(Node node1, Node node2, long value){\n\t\tthis.node1 = node1, this.node2 = node2;\n\t\tthis.value = value;\n\t}\n\toverride string toString(){\n\t\treturn [node1.id, node2.id, value].to!string;\n\t}\n}\n\nclass Node{\n\tlong id;\n\tlong value;\n\tGroup group;\n\tthis(long id, long value){\n\t\tthis.id = id;\n\t\tthis.value = value;\n\t\tthis.group = new Group(this);\n\t}\n\toverride string toString(){\n\t\treturn [id, group.id, value].to!string;\n\t}\n}\n\nclass Group{\n\tlong value;\n\tlong pendingEdgeCount;\n\tlong id;\n\tlong edgecount;\n\tNode[] nodes;\n\tthis(Node node){\n\t\tthis.id = node.id;\n\t\tthis.nodes = [node];\n\t\tthis.value = node.value;\n\t}\n\tvoid eat(Group gp){\n\t\tif(gp.nodes.length > this.nodes.length) gp.eat(this);\n\t\telse{\n\t\t\tforeach(nd; gp.nodes){\n\t\t\t\tthis.nodes ~= nd;\n\t\t\t\tnd.group = this;\n\t\t\t\tthis.value += nd.value;\n\t\t\t}\n\t\t\tthis.edgecount += gp.edgecount;\n\t\t\tthis.pendingEdgeCount += gp.pendingEdgeCount;\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nstruct UnionFind\n{\n\tvoid init(int n) { par = new int[](n); foreach (i; 0..n) par[i] = i; cnt = new int[](n); fill(cnt, 1); }\n\tint root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }\n\tbool same(int i, int j) { return root(i) == root(j); }\n\tvoid unite(int i, int j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; cnt[j] += cnt[i]; }\n\tint size(int i) { return cnt[root(i)]; }\n\tint[] par, cnt;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto k = RD!int;\n\t//auto edges = new int[][](n);\n\tUnionFind uf;\n\tuf.init(n);\n\tforeach (i; 0..k)\n\t{\n\t\tauto a = RD!int-1;\n\t\tauto b = RD!int-1;\n\t\t//edges[a] ~= b;\n\t\t//edges[b] ~= a;\n\t\tuf.unite(a, b);\n\t}\n\n\tauto cnt = new int[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tcnt[i] = uf.size(i);\n\t}\n\n\tlong ans;\n\tauto index = cnt.MAKE_IDX!(\"a > b\")();\n\tauto used = new bool[](n);\n\tforeach (i; index)\n\t{\n\t\tauto r = uf.root(cast(int)i);\n\t\tif (used[r]) continue;\n\t\tans += cnt[i]-1;\n\t\tused[r] = true;\n\t}\n\n\twriteln(max(k-ans, 0));\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "a7d68ecc1a9ee23cf98f51fe6651ae13"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.variant;\nimport std.concurrency;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto a = next!int(n);\n auto pos1 = new int[](n + 1); pos1[] = -1;\n auto pos2 = new int[](n + 1); pos2[] = -1;\n auto cnt1 = new int[](n);\n auto cnt2 = new int[](n);\n foreach(i, ai; a)\n {\n if (i != 0)\n\t{\n\t cnt1[i] = cnt1[i - 1];\n\t cnt2[i] = cnt2[i - 1];\n\t}\n if (ai == 1)\n\t{\n\t cnt1[i]++;\n\t pos1[cnt1[i]] = cast(int) i;\n\t}\n else\n\t{\n\t cnt2[i]++;\n\t pos2[cnt2[i]] = cast(int) i;\n\t}\n }\n foreach(ref c; pos1) if (c == -1) c = n;\n foreach(ref c; pos2) if (c == -1) c = n;\n auto options = new Tuple!(int, int)[](0);\n debug writeln(\"pos1 = \", pos1);\n debug writeln(\"pos2 = \", pos2);\n sTest: foreach(s; 1 .. n + 1)\n {\n debug writeln(\"trying for s = \", s);\n int i = void;\n int ni = void;\n int sets1 = 0;\n int sets2 = 0;\n int next1 = pos1[s];\n int next2 = pos2[s];\n if (next1 < next2)\n\t{\n\t i = next1;\n\t sets1++;\n\t}\n else\n\t{\n\t i = next2;\n\t sets2++;\n\t}\n while (i < n)\n\t{\n\t debug writeln(\"in i = \", i, \" sets1 = \", sets1, \" sets2 = \", sets2);\n\t if (i == n - 1)\n\t {\n\t if (sets1 == sets2)\n\t\tcontinue sTest;\n\t if (sets1 > sets2)\n\t\t{\n\t\t if (a[i] == 1)\n\t\t options ~= tuple(sets1, s);\n\t\t}\n\t else\n\t\t{\n\t\t if (a[i] == 2)\n\t\t options ~= tuple(sets2, s);\n\t\t}\n\t continue sTest;\n\t }\n\t \n\t next1 = (cnt1[i] + s <= n)? pos1[cnt1[i] + s] : n;\n\t next2 = (cnt2[i] + s <= n)? pos2[cnt2[i] + s] : n;\n\t if (next1 < next2)\n\t {\n\t ni = next1;\n\t sets1++;\n\t }\n\t else\n\t {\n\t ni = next2;\n\t sets2++;\n\t }\n\t \n\t i = ni;\n\t}\n }\n auto soptions = sort(options);\n writeln(options.length);\n foreach(option; options)\n {\n writeln(option[0], \" \", option[1]);\n }\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nconst int MAX = 100005;\nint n;\nint[MAX] a;\nint[MAX] f1, f2, pos1, pos2;\nTuple!(int,int)[MAX] ans;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n int c1, c2;\n foreach(i; 0..n) {\n f1[i] = c1-1;\n f2[i] = c2-1;\n if (a[i] == 1) {\n pos1[c1++] = i;\n } else {\n pos2[c2++] = i;\n }\n }\n\n int numOfAns = 0;\n\nmatch: \n foreach_reverse(t; 1..n+1) {\n int i = 0;\n int win1, win2;\n while (i < n) {\n int end1 = f1[i] + t < c1 ? pos1[f1[i] + t] : n;\n int end2 = f2[i] + t < c2 ? pos2[f2[i] + t] : n;\n int nextEnd = min(end1, end2);\n if (nextEnd >= n) {\n continue match;\n }\n i = nextEnd + 1;\n if (end1 < end2) {\n win1++;\n } else {\n win2++;\n }\n }\n if ((win1 < win2 && a[n-1] == 2) || (win1 > win2 && a[n-1] == 1))\n ans[numOfAns++] = tuple(max(win1, win2), t);\n }\n\n ans[0..numOfAns].sort!((x, y) => (x[0] == y[0]) ? x[1] < y[1] : x[0] < y[0]);\n\n writeln(numOfAns);\n foreach(x; ans[0..numOfAns]) writeln(x[0], \" \", x[1]);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tauto a = [0] ~ readln.split.map !(to !(int)).array;\n\t\tint [] sa = [0];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tsa ~= sa[i] + (a[i + 1] == 1);\n\t\t}\n\t\tsa ~= n * 10;\n\t\tint [] sb = [0];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tsb ~= sb[i] + (a[i + 1] == 2);\n\t\t}\n\t\tsb ~= n * 10;\n\t\tint [2] [] res;\n\t\tforeach (t; 1..n + 1)\n\t\t{\n\t\t\tint pos = 0;\n\t\t\tint ca = 0;\n\t\t\tint cb = 0;\n\t\t\tint last = 0;\n\t\t\tbool ok = true;\n\t\t\twhile (pos < n)\n\t\t\t{\n\t\t\t\tint lo = pos - 1;\n\t\t\t\tint hi = n;\n\t\t\t\twhile (lo < hi)\n\t\t\t\t{\n\t\t\t\t\tint me = ((lo + hi + 3) >> 1) - 1;\n\t\t\t\t\tif (sa[me + 1] - sa[pos] >= t ||\n\t\t\t\t\t sb[me + 1] - sb[pos] >= t)\n\t\t\t\t\t{\n\t\t\t\t\t\thi = me - 1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tlo = me;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tint next = lo + 1;\n\t\t\t\tif (sa[next + 1] - sa[pos] == t)\n\t\t\t\t{\n\t\t\t\t\tlast = 1;\n\t\t\t\t\tca++;\n\t\t\t\t}\n\t\t\t\telse if (sb[next + 1] - sb[pos] == t)\n\t\t\t\t{\n\t\t\t\t\tlast = 2;\n\t\t\t\t\tcb++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tassert (next >= n);\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tpos = next + 1;\n\t\t\t}\n\n\t\t\tok &= (last == 1 && ca > cb) ||\n\t\t\t (last == 2 && ca < cb);\n\t\t\tif (ok)\n\t\t\t{\n\t\t\t\tres ~= [max (ca, cb), t];\n\t\t\t}\n\t\t}\n\n\t\tsort (res);\n\t\twriteln (res.length);\n\t\tforeach (cur; res)\n\t\t{\n\t\t\twriteln (cur[0], ' ', cur[1]);\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nconst int MAX = 100005;\nint n;\nint[MAX] a;\nint[MAX] f1, f2, pos1, pos2;\nTuple!(int,int)[MAX] ans;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n int c1, c2;\n foreach(i; 0..n) {\n f1[i] = c1-1;\n f2[i] = c2-1;\n if (a[i] == 1) {\n pos1[c1++] = i;\n } else {\n pos2[c2++] = i;\n }\n }\n\n int numOfAns = 0;\n\nmatch: \n foreach_reverse(t; 1..n+1) {\n int i = 0;\n int win1, win2;\n while (i < n) {\n int end1 = f1[i] + t < c1 ? pos1[f1[i] + t] : n;\n int end2 = f2[i] + t < c2 ? pos2[f2[i] + t] : n;\n int nextEnd = min(end1, end2);\n if (nextEnd >= n) {\n continue match;\n }\n i = nextEnd + 1;\n if (end1 < end2) {\n win1++;\n } else {\n win2++;\n }\n }\n if (win1 != win2) \n ans[numOfAns++] = tuple(max(win1, win2), t);\n }\n\n writeln(numOfAns);\n foreach(x; ans[0..numOfAns]) writeln(x[0], \" \", x[1]);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nconst int MAX = 100005;\nint n;\nint[MAX] a;\nint[MAX] f1, f2, pos1, pos2;\nTuple!(int,int)[MAX] ans;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n int c1, c2;\n foreach(i; 0..n) {\n f1[i] = c1-1;\n f2[i] = c2-1;\n if (a[i] == 1) {\n pos1[c1++] = i;\n } else {\n pos2[c2++] = i;\n }\n }\n\n int numOfAns = 0;\n\nmatch: \n foreach_reverse(t; 1..n+1) {\n int i = 0;\n int win1, win2;\n while (i < n) {\n int end1 = f1[i] + t < c1 ? pos1[f1[i] + t] : n;\n int end2 = f2[i] + t < c2 ? pos2[f2[i] + t] : n;\n int nextEnd = min(end1, end2);\n if (nextEnd >= n) {\n continue match;\n }\n i = nextEnd + 1;\n if (end1 < end2) {\n win1++;\n } else {\n win2++;\n }\n }\n if ((win1 < win2 && a[n-1] == 2) || (win1 > win2 && a[n-1] == 1))\n ans[numOfAns++] = tuple(max(win1, win2), t);\n }\n\n writeln(numOfAns);\n foreach(x; ans[0..numOfAns]) writeln(x[0], \" \", x[1]);\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.variant;\nimport std.concurrency;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto a = next!int(n);\n auto pos1 = new int[](n + 1); pos1[] = -1;\n auto pos2 = new int[](n + 1); pos2[] = -1;\n auto cnt1 = new int[](n);\n auto cnt2 = new int[](n);\n foreach(i, ai; a)\n {\n if (i != 0)\n\t{\n\t cnt1[i] = cnt1[i - 1];\n\t cnt2[i] = cnt2[i - 1];\n\t}\n if (ai == 1)\n\t{\n\t cnt1[i]++;\n\t pos1[cnt1[i]] = cast(int) i;\n\t}\n else\n\t{\n\t cnt2[i]++;\n\t pos2[cnt2[i]] = cast(int) i;\n\t}\n }\n foreach(ref c; pos1) if (c == -1) c = n;\n foreach(ref c; pos2) if (c == -1) c = n;\n auto options = new Tuple!(int, int)[](0);\n debug writeln(\"pos1 = \", pos1);\n debug writeln(\"pos2 = \", pos2);\n sTest: foreach(s; 1 .. n + 1)\n {\n debug writeln(\"trying for s = \", s);\n int i = void;\n int ni = void;\n int sets1 = 0;\n int sets2 = 0;\n int next1 = pos1[s];\n int next2 = pos2[s];\n if (next1 < next2)\n\t{\n\t i = next1;\n\t sets1++;\n\t}\n else\n\t{\n\t i = next2;\n\t sets2++;\n\t}\n while (i < n)\n\t{\n\t debug writeln(\"in i = \", i, \" sets1 = \", sets1, \" sets2 = \", sets2);\n\t if (i == n - 1)\n\t {\n\t if (sets1 == sets2)\n\t\tcontinue sTest;\n\t options ~= tuple(max(sets1, sets2), s);\n\t continue sTest;\n\t }\n\t \n\t next1 = (cnt1[i] + s <= n)? pos1[cnt1[i] + s] : n;\n\t next2 = (cnt2[i] + s <= n)? pos2[cnt2[i] + s] : n;\n\t if (next1 < next2)\n\t {\n\t ni = next1;\n\t sets1++;\n\t }\n\t else\n\t {\n\t ni = next2;\n\t sets2++;\n\t }\n\t \n\t i = ni;\n\t}\n }\n auto soptions = sort(options);\n writeln(options.length);\n foreach(option; options)\n {\n writeln(option[0], \" \", option[1]);\n }\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.variant;\nimport std.concurrency;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto a = next!int(n);\n auto pos1 = new int[](n + 1); pos1[] = -1;\n auto pos2 = new int[](n + 1); pos2[] = -1;\n auto cnt1 = new int[](n);\n auto cnt2 = new int[](n);\n foreach(i, ai; a)\n {\n if (i != 0)\n\t{\n\t cnt1[i] = cnt1[i - 1];\n\t cnt2[i] = cnt2[i - 1];\n\t}\n if (ai == 1)\n\t{\n\t cnt1[i]++;\n\t pos1[cnt1[i]] = cast(int) i;\n\t}\n else\n\t{\n\t cnt2[i]++;\n\t pos2[cnt2[i]] = cast(int) i;\n\t}\n }\n foreach(ref c; pos1) if (c == -1) c = n;\n foreach(ref c; pos2) if (c == -1) c = n;\n auto options = new Tuple!(int, int)[](0);\n debug writeln(\"pos1 = \", pos1);\n debug writeln(\"pos2 = \", pos2);\n sTest: foreach(s; 1 .. n + 1)\n {\n debug writeln(\"trying for s = \", s);\n int i = void;\n int ni = void;\n int sets1 = 0;\n int sets2 = 0;\n int next1 = pos1[s];\n int next2 = pos2[s];\n if (next1 < next2)\n\t{\n\t i = next1;\n\t sets1++;\n\t}\n else\n\t{\n\t i = next2;\n\t sets2++;\n\t}\n while (i < n)\n\t{\n\t debug writeln(\"in i = \", i, \" sets1 = \", sets1, \" sets2 = \", sets2);\n\t if (i == n - 1)\n\t {\n\t if (sets1 == sets2)\n\t\tcontinue sTest;\n\t options ~= tuple(s, max(sets1, sets2));\n\t continue sTest;\n\t }\n\t \n\t next1 = (cnt1[i] + s <= n)? pos1[cnt1[i] + s] : n;\n\t next2 = (cnt2[i] + s <= n)? pos2[cnt2[i] + s] : n;\n\t if (next1 < next2)\n\t {\n\t ni = next1;\n\t sets1++;\n\t }\n\t else\n\t {\n\t ni = next2;\n\t sets2++;\n\t }\n\t \n\t i = ni;\n\t}\n }\n writeln(options.length);\n foreach(option; options)\n {\n writeln(option[0], \" \", option[1]);\n }\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}], "src_uid": "eefea51c77b411640a3b92b9f2dd2cf1"} {"source_code": "import core.bitop;\nimport core.checkedint;\n//import core.stdc.stdio;\nimport core.stdc.stdlib: alloca, malloc, calloc, realloc, _Exit;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n enum spec = ' ' ~ replicate(\"%s \", vars.length);\n return readf(spec, getAddrTuple(vars).expand) == vars.length;\n}\n\nvoid memSet(T, size_t n)(ref T[n] a, ubyte value) {\n memset(a.ptr, value, a.sizeof);\n}\n\nvoid memSet(T)(T[ ] a, ubyte value) {\n memset(a.ptr, value, a.length * T.sizeof);\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Problem {\n int id, limit, time;\n\n int opCmp(Problem rhs) const {\n return tuple(time, limit).opCmp(tuple(rhs.time, rhs.limit));\n }\n}\n\nint n, total;\nProblem[200_000] _problems;\nProblem[ ] problems;\nRedBlackTree!(Problem, q{a.id < b.id})[200_000] _solvedDist;\nRedBlackTree!(Problem, q{a.id < b.id})[ ] solvedDist;\nint curCount, bestCount;\nRedBlackTree!(Problem, q{a < b}, true) solved;\n\nvoid run(alias callback)() {\n generate!(redBlackTree!(q{a.id < b.id}, Problem)).take(n).copy(solvedDist);\n int curTime = 0;\n curCount = 0;\n auto solvable = redBlackTree!true(problems);\n solved = redBlackTree!(true, Problem);\n foreach (c; 1 .. n + 1) {\n while (!solved.empty && !solvable.empty && solvable.front.time < solved.front.time) {\n const a = solvable.front;\n solvable.removeFront();\n if (c <= a.limit) {\n const b = solved.front;\n solved.removeFront();\n solvedDist[b.limit - 1].removeKey(b);\n curTime -= b.time - a.time;\n solved.insert(a);\n solvedDist[a.limit - 1].insert(a);\n if (c <= b.limit)\n solvable.insert(b);\n }\n }\n while (solved.length < c && !solvable.empty && curTime + solvable.front.time <= total) {\n const a = solvable.front;\n solvable.removeFront();\n if (c <= a.limit) {\n curTime += a.time;\n curCount++;\n solved.insert(a);\n solvedDist[a.limit - 1].insert(a);\n if (callback())\n return;\n }\n }\n foreach (p; solvedDist[c - 1]) {\n assert(p.limit == c);\n solved.removeKey(p);\n curTime -= p.time;\n curCount--;\n }\n solvedDist[c - 1] = null;\n }\n}\n\nvoid main() {\n while (read(n, total)) {\n problems = _problems[0 .. n];\n solvedDist = _solvedDist[0 .. n];\n foreach (int i, ref p; problems) {\n p.id = i + 1;\n read(p.limit, p.time);\n }\n\n problems.multiSort!(q{a.limit < b.limit}, q{a.time < b.time});\n bestCount = 0;\n run!({\n if (curCount > bestCount)\n bestCount = curCount;\n return false;\n });\n\n writeln(bestCount, '\\n', bestCount);\n run!({\n if (curCount != bestCount)\n return false;\n writefln(\"%(%s %)\", solved[ ].map!q{a.id});\n return true;\n });\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\n}\n", "positive_code": [{"source_code": "import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n/// struct vector as c++ vector\nstruct Vec(T)\n{\n\tprivate Array!T buf;\n\talias buf this;\n\tthis(this)\n\t{\n\t\tbuf = buf.dup;\n\t}\n\t/// construct from length\n\tthis(U)(U length)\n\t\t\tif (is(U == int) || is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint))\n\t{\n\t\tbuf.length = length;\n\t}\n\t/// construct from length and default value\n\tthis(U, X)(U length, X val)\n\t\t\tif (isImplicitlyConvertible!(X, T) || (is(U == int)\n\t\t\t\t|| is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint)))\n\t{\n\t\tbuf.length = length;\n\t\tforeach (ref x; buf[])\n\t\t{\n\t\t\tx = val;\n\t\t}\n\t}\n\t/// construct from other array\n\tthis(U)(U[] values...) if (isImplicitlyConvertible!(U, T))\n\t{\n\t\tbuf = Array!(T)(values);\n\t}\n\t/// construct from other range\n\tthis(Range)(Range r)\n\t\t\tif (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range,\n\t\t\t\tT) && !is(Range == T[]))\n\t{\n\t\tbuf = Array!(T)(r);\n\t}\n\t/// integer length\n\tint size() @property const\n\t{\n\t\treturn cast(int) buf.length;\n\t}\n}\n///modulo\nenum mm = 10 ^^ 9 + 7, mm2 = mm + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt biggcd(BigInt a, BigInt b)\n\t\t{\n\t\t\tBigInt res = 1;\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\tif ((a & 1) && (b & 1))\n\t\t\t\t{\n\t\t\t\t\ta -= b;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (a & 1)\n\t\t\t\t{\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (b & 1)\n\t\t\t\t{\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres <<= 1;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\tif (a < b)\n\t\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn res * a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\treadln;\n\t\treturn fl;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tint n, T;\n\tread(n, T);\n\tauto a = new Tuple!(int, int, int)[n];\n\tforeach (i; 0 .. n)\n\t{\n\t\tread(a[i][0], a[i][1]);\n\t\ta[i][2] = i + 1;\n\t}\n\tsort!\"a[1]<b[1]\"(a);\n\tbool check(int k)\n\t{\n\t\tint c;\n\t\tlong curt;\n\t\tforeach (x; a)\n\t\t{\n\t\t\tif (c == k)\n\t\t\t\tbreak;\n\t\t\tif (x[0] < k)\n\t\t\t\tcontinue;\n\t\t\tc++;\n\t\t\tcurt += x[1];\n\t\t}\n\t\treturn c == k && curt <= T;\n\t}\n\n\tint l = 0, r = n;\n\twhile (l < r)\n\t{\n\t\tint m = (l + r + 1) / 2;\n\t\tif (check(m))\n\t\t\tl = m;\n\t\telse\n\t\t\tr = m - 1;\n\t}\n\tint[] ans;\n\tforeach (x; a)\n\t{\n\t\tif (ans.length == l)\n\t\t\tbreak;\n\t\tif (x[0] < l)\n\t\t\tcontinue;\n\t\tans ~= x[2];\n\t}\n\twriteln(l, '\\n', l);\n\tputarr(ans, ' ');\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nalias Problem = Tuple!(int, \"num\", long, \"time\", int, \"index\");\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto T = s[1].to!long;\n auto P = new Problem[](N);\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n P[i] = tuple(s[0], s[1].to!long, i+1);\n }\n P.sort!\"a[1] < b[1]\";\n\n int hi = N+1;\n int lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n long tmp = 0;\n int cnt = 0;\n foreach (p; P) {\n if (p.num < mid) continue;\n tmp += p.time;\n cnt += 1;\n if (cnt >= mid) break;\n }\n if (cnt >= mid && tmp <= T) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n\n int[] ans;\n int cnt = 0;\n foreach (p; P) {\n if (p.num >= lo) {\n ans ~= p.index;\n cnt += 1;\n }\n if (cnt >= lo) break;\n }\n\n lo.writeln;\n lo.writeln;\n if (lo == 0) writeln;\n else ans.map!(to!string).join(\" \").writeln;\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n/// struct vector as c++ vector\nstruct Vec(T)\n{\n\tprivate Array!T buf;\n\talias buf this;\n\tthis(this)\n\t{\n\t\tbuf = buf.dup;\n\t}\n\t/// construct from length\n\tthis(U)(U length)\n\t\t\tif (is(U == int) || is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint))\n\t{\n\t\tbuf.length = length;\n\t}\n\t/// construct from length and default value\n\tthis(U, X)(U length, X val)\n\t\t\tif (isImplicitlyConvertible!(X, T) || (is(U == int)\n\t\t\t\t|| is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint)))\n\t{\n\t\tbuf.length = length;\n\t\tforeach (ref x; buf[])\n\t\t{\n\t\t\tx = val;\n\t\t}\n\t}\n\t/// construct from other array\n\tthis(U)(U[] values...) if (isImplicitlyConvertible!(U, T))\n\t{\n\t\tbuf = Array!(T)(values);\n\t}\n\t/// construct from other range\n\tthis(Range)(Range r)\n\t\t\tif (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range,\n\t\t\t\tT) && !is(Range == T[]))\n\t{\n\t\tbuf = Array!(T)(r);\n\t}\n\t/// integer length\n\tint size() @property const\n\t{\n\t\treturn cast(int) buf.length;\n\t}\n}\n///modulo\nenum mm = 10 ^^ 9 + 7, mm2 = mm + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt biggcd(BigInt a, BigInt b)\n\t\t{\n\t\t\tBigInt res = 1;\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\tif ((a & 1) && (b & 1))\n\t\t\t\t{\n\t\t\t\t\ta -= b;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (a & 1)\n\t\t\t\t{\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (b & 1)\n\t\t\t\t{\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres <<= 1;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\tif (a < b)\n\t\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn res * a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\treadln;\n\t\treturn fl;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tint n, T;\n\tread(n, T);\n\tauto a = new Tuple!(int, int, int)[n];\n\tforeach (i; 0 .. n)\n\t{\n\t\tread(a[i][0], a[i][1]);\n\t\ta[i][2] = i + 1;\n\t}\n\tsort!\"a[1]<b[1]\"(a);\n\tbool check(int k)\n\t{\n\t\tint c;\n\t\tlong curt;\n\t\tforeach (x; a)\n\t\t{\n\t\t\tif (c == k)\n\t\t\t\tbreak;\n\t\t\tif (x[0] < k)\n\t\t\t\tcontinue;\n\t\t\tc++;\n\t\t\tcurt += x[1];\n\t\t}\n\t\treturn curt <= T;\n\t}\n\n\tint l = 0, r = n;\n\twhile (l < r)\n\t{\n\t\tint m = (l + r + 1) / 2;\n\t\tif (check(m))\n\t\t\tl = m;\n\t\telse\n\t\t\tr = m - 1;\n\t}\n\tint[] ans;\n\tforeach (x; a)\n\t{\n\t\tif (ans.length == l)\n\t\t\tbreak;\n\t\tif (x[0] < l)\n\t\t\tcontinue;\n\t\tans ~= x[2];\n\t}\n\twriteln(l, '\\n', l);\n\tputarr(ans, ' ');\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nalias Problem = Tuple!(int, \"num\", long, \"time\", int, \"index\");\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto T = s[1].to!long;\n auto P = new Problem[](N);\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n P[i] = tuple(s[0], s[1].to!long, i+1);\n }\n P.sort!\"a[1] < b[1]\";\n\n int hi = N+1;\n int lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n long tmp = 0;\n int cnt = 0;\n foreach (p; P) {\n if (p.num < mid) continue;\n tmp += p.time;\n cnt += 1;\n if (cnt >= mid) break;\n }\n if (cnt >= mid && tmp <= T) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n\n int[] ans;\n foreach (i; 0..lo) if (P[i].num >= lo) ans ~= P[i].index;\n lo.writeln;\n lo.writeln;\n ans.map!(to!string).join(\" \").writeln;\n}\n"}, {"source_code": "import core.bitop;\nimport core.checkedint;\n//import core.stdc.stdio;\nimport core.stdc.stdlib: alloca, malloc, calloc, realloc, _Exit;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n enum spec = ' ' ~ replicate(\"%s \", vars.length);\n return readf(spec, getAddrTuple(vars).expand) == vars.length;\n}\n\nvoid memSet(T, size_t n)(ref T[n] a, ubyte value) {\n memset(a.ptr, value, a.sizeof);\n}\n\nvoid memSet(T)(T[ ] a, ubyte value) {\n memset(a.ptr, value, a.length * T.sizeof);\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Problem {\n int id, limit, time;\n\n int opCmp(Problem rhs) const {\n return tuple(time, limit).opCmp(tuple(rhs.time, rhs.limit));\n }\n}\n\nProblem[200_000] _problems;\nRedBlackTree!(Problem, q{a.id < b.id})[200_000] _solvedDist;\n\nvoid main() {\n int n, total;\n while (read(n, total)) {\n auto problems = _problems[0 .. n];\n auto solvedDist = _solvedDist[0 .. n];\n foreach (int i, ref p; problems) {\n p.id = i + 1;\n read(p.limit, p.time);\n }\n\n problems.multiSort!(q{a.limit < b.limit}, q{a.time < b.time});\n generate!(redBlackTree!(q{a.id < b.id}, Problem)).take(n).copy(solvedDist);\n int bestTime = 10^^9 + 1, bestCount = 0;\n int curTime = 0, curCount = 0;\n auto solvable = redBlackTree!(true, Problem);\n auto solved = redBlackTree!(true, Problem);\n int pLastIndex = 0;\n foreach (c; 1 .. n + 1) {\n for (; pLastIndex < n && problems[pLastIndex].limit <= c; pLastIndex++)\n solvable.insert(problems[pLastIndex]);\n while (!solved.empty && !solvable.empty && solvable.front.time < solved.front.time) {\n const a = solvable.front;\n solvable.removeFront();\n if (c <= a.limit) {\n const b = solved.front;\n solved.removeFront();\n solvedDist[b.limit - 1].removeKey(b);\n curTime -= b.time - a.time;\n solved.insert(a);\n solvedDist[a.limit - 1].insert(a);\n if (c <= b.limit)\n solvable.insert(b);\n }\n }\n while (solved.length < c && !solvable.empty && curTime + solvable.front.time <= total) {\n const a = solvable.front;\n solvable.removeFront();\n if (c <= a.limit) {\n curTime += a.time;\n curCount++;\n solved.insert(a);\n solvedDist[a.limit - 1].insert(a);\n if (curCount > bestCount) {\n bestTime = curTime;\n bestCount = curCount;\n }\n }\n }\n foreach (p; solvedDist[c - 1]) {\n assert(p.limit == c);\n solved.removeKey(p);\n curTime -= p.time;\n curCount--;\n }\n solvedDist[c - 1] = null;\n }\n\n writeln(bestCount, '\\n', bestCount);\n generate!(redBlackTree!(q{a.id < b.id}, Problem)).take(n).copy(solvedDist);\n curTime = 0;\n curCount = 0;\n solvable.clear();\n solved.clear();\n pLastIndex = 0;\n restoreResult:\n foreach (c; 1 .. n + 1) {\n for (; pLastIndex < n && problems[pLastIndex].limit <= c; pLastIndex++)\n solvable.insert(problems[pLastIndex]);\n while (!solved.empty && !solvable.empty && solvable.front.time < solved.front.time) {\n const a = solvable.front;\n solvable.removeFront();\n if (c <= a.limit) {\n const b = solved.front;\n solved.removeFront();\n solvedDist[b.limit - 1].removeKey(b);\n curTime -= b.time - a.time;\n solved.insert(a);\n solvedDist[a.limit - 1].insert(a);\n if (c <= b.limit)\n solvable.insert(b);\n }\n }\n while (solved.length < c && !solvable.empty && curTime + solvable.front.time <= total) {\n const a = solvable.front;\n solvable.removeFront();\n if (c <= a.limit) {\n curTime += a.time;\n curCount++;\n solved.insert(a);\n solvedDist[a.limit - 1].insert(a);\n if (curCount == bestCount) {\n writefln(\"%(%s %)\", solved[ ].map!q{a.id});\n break restoreResult;\n }\n }\n }\n foreach (p; solvedDist[c - 1]) {\n assert(p.limit == c);\n solved.removeKey(p);\n curTime -= p.time;\n curCount--;\n }\n solvedDist[c - 1] = null;\n }\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\n}\n"}], "src_uid": "5294cad0d35a6c8ed40a8322ba5fd7b1"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n, q;\r\n\twhile (readf !(\" %s %s\") (n, q) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto s = ['x', 'x'] ~ readln.strip.dup ~ ['x', 'x'];\r\n\t\tauto cur = s.count (\"abc\");\r\n\t\tforeach (j; 0..q)\r\n\t\t{\r\n\t\t\tint i;\r\n\t\t\tchar ch;\r\n\t\t\treadf !(\" %s %s\") (i, ch);\r\n\t\t\ti += 1;\r\n\t\t\tcur -= (s[i - 2..i + 1] == \"abc\");\r\n\t\t\tcur -= (s[i - 1..i + 2] == \"abc\");\r\n\t\t\tcur -= (s[i - 0..i + 3] == \"abc\");\r\n\t\t\ts[i] = ch;\r\n\t\t\tcur += (s[i - 2..i + 1] == \"abc\");\r\n\t\t\tcur += (s[i - 1..i + 2] == \"abc\");\r\n\t\t\tcur += (s[i - 0..i + 3] == \"abc\");\r\n\t\t\twriteln (cur);\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto q = readInt!int;\n auto s = cast(char[])readString;\n auto cnt = new int[](n);\n int sm;\n int isAbc(int i)\n {\n if (i + 3 > n) return 0;\n return int(s[i .. i + 3] == \"abc\");\n }\n foreach(i, ref ci; cnt)\n {\n ci = isAbc(cast(int)i);\n }\n sm = cnt.sum;\n void reCalc(int i)\n {\n if (i < 0 || i >= n) return;\n auto ld = cnt[i];\n auto nw = isAbc(i);\n auto dlt = nw - ld;\n cnt[i] = nw;\n sm += dlt;\n }\n foreach(qi; 0 .. q)\n {\n auto pos = readInt!int - 1;\n auto cString = readString;\n auto c = cString[0];\n s[pos] = c;\n foreach(p; pos - 3 .. pos + 1)\n\t{\n\t reCalc(p);\n\t}\n sm.writeln;\n }\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool check_abc(char[] s, int i)\n{\n if (s[i] == 'a') {\n if (i + 2 < s.length && s[i + 1] == 'b' && s[i + 2] == 'c')\n return true;\n } else if (s[i] == 'b') {\n if (i - 1 >= 0 && i + 1 < s.length && s[i - 1] == 'a' && s[i + 1] == 'c')\n return true;\n } else if (s[i] == 'c'){\n if (i - 2 >= 0 && s[i - 1] == 'b' && s[i - 2] == 'a')\n return true;\n }\n return false;\n}\n\nvoid main()\n{\n long n, q;\n readf!\" %d %d \"(n, q);\n char[] s = readln.strip.dup;\n long ans = 0;\n char last = 'c';\n foreach (ch ; s) {\n if (ch == 'a')\n last = 'a';\n else if (ch == 'b' && last == 'a')\n last = 'b';\n else if (ch == 'c' && last == 'b') {\n ans++;\n last = 'c';\n } else\n last = 'c';\n }\n while (q-- > 0) {\n int pos;\n char ch;\n readf!\" %d %c \"(pos, ch);\n pos--;\n if (check_abc(s, pos))\n ans--;\n s[pos] = ch;\n if (check_abc(s, pos))\n ans++;\n writeln(ans);\n }\n}\n"}], "negative_code": [], "src_uid": "db473ad780a93983667d12b1357c6e2f"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int limit = 10 ^^ 6 + 6;\n\nauto gm = new int [limit];\n\nint g (int n)\n{\n\tif (gm[n] == 0)\n\t{\n\t\tif (n < 10)\n\t\t{\n\t\t\tgm[n] = n;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tgm[n] = n.text\n\t\t\t .map !(q{a - '0'})\n\t\t\t .filter !(q{a > 0})\n\t\t\t .fold !(q{a * b}) (1)\n\t\t\t .g;\n\t\t}\n\t}\n\treturn gm[n];\n}\n\nvoid main ()\n{\n\tauto gm = limit.iota.map !(g).array;\n\tauto c = new int [limit] [10];\n\tforeach (d; 1..10)\n\t{\n\t\tforeach (i; 1..limit)\n\t\t{\n\t\t\tc[d][i] = c[d][i - 1] + (gm[i] == d);\n\t\t}\n\t}\n\n\tint q;\n\twhile (readf (\" %s\", &q) > 0)\n\t{\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tint lo, hi, k;\n\t\t\treadf (\" %s %s %s\", &lo, &hi, &k);\n\t\t\twriteln (c[k][hi] - c[k][lo - 1]);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum LIM = 10^^6 + 10;\n\nvoid main() {\n auto fs = new int[LIM];\n fs[0] = 1;\n foreach (n; 1 .. LIM) {\n fs[n] = fs[n / 10] * ((n % 10 == 0) ? 1 : (n % 10));\n }\n auto gs = new int[LIM];\n foreach (n; 1 .. LIM) {\n gs[n] = (n < 10) ? n : gs[fs[n]];\n }\n \n auto nums = new int[][](10, LIM);\n foreach (k; 0 .. 10) {\n foreach (n; 1 .. LIM) {\n nums[k][n] = nums[k][n - 1] + ((gs[n] == k) ? 1 : 0);\n }\n }\n \n try {\n for (; ; ) {\n const Q = readInt();\n foreach (q; 0 .. Q) {\n const l = readInt();\n const r = readInt();\n const k = readInt();\n const ans = nums[k][r] - nums[k][l - 1];\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "7a647a5f10cdcd2b54a1927107edea4f"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto W = s[0];\n auto K = s[1];\n auto A = new bool[][](4, W);\n auto C = W/2;\n\n \"YES\".writeln;\n\n outer: foreach (i; 1..3) {\n foreach (j; 1..C) {\n if (K <= 1) break outer;\n A[i][j] = true;\n A[i][W-j-1] = true;\n K -= 2;\n }\n }\n\n foreach (i; 1..3) {\n if (K == 0) break;\n A[i][C] = true;\n K -= 1;\n }\n\n foreach (i; 0..4) A[i].map!(a => a ? '#' : '.').writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\n\nvoid main()\n{\n\tint n, k;\n\treadln.chomp.split.tie(n, k);\n\tif (2 * (n - 2) < k) {\n\t\t\"NO\".writeln;\n\t\treturn;\n\t}\n\t\"YES\".writeln;\n\tchar[][] ans = new char[][](4, n);\n\tforeach (i; 0..4) {\n\t\tforeach (j; 0..n) {\n\t\t\tans[i][j] = '.';\n\t\t}\n\t}\n\t// vertical\n\tfor (int i = 1; i <= 2; ++i) {\n\t\tif (k < n - 2) {\n\t\t\tbreak;\n\t\t}\n\t\tfor (int j = 1; j < n - 1; ++j) {\n\t\t\tans[i][j] = '#';\n\t\t}\n\t\tk -= n - 2;\n\t}\n\timmutable MID = n / 2;\n\tif (k % 2 == 1) {\n\t\tans[2][MID] = '#';\n\t\t--k;\n\t}\n\tfor (int i = 1; k > 0; ++i) {\n\t\tans[2][MID - i] = ans[2][MID + i] = '#';\n\t\tk -= 2;\n\t}\n\tforeach (s; ans) {\n\t\tforeach (c; s) {\n\t\t\tc.write;\n\t\t}\n\t\twriteln;\n\t}\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, k; readV(n, k);\n\n auto b = new bool[][](4, n);\n\n if (k%2 == 0) {\n foreach (i; 0..k/2)\n b[1][i+1] = b[2][i+1] = true;\n } else if (k <= n-2) {\n foreach (i; 0..k)\n b[1][i+(n-k)/2] = true;\n } else {\n foreach (i; 0..n-2)\n b[1][i+1] = true;\n auto k2 = k-(n-2)+1;\n foreach (i; 0..k2)\n b[2][i+(n-k2)/2] = true;\n b[2][n/2] = false;\n }\n\n writeln(\"YES\");\n foreach (i; 0..4) {\n foreach (j; 0..n)\n write(b[i][j] ? \"#\" : \".\");\n writeln;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\n\nvoid main()\n{\n\tint n, k;\n\treadln.chomp.split.tie(n, k);\n\tif (2 * (n - 2) < k) {\n\t\t\"NO\".writeln;\n\t\treturn;\n\t}\n\tchar[][] ans = new char[][](4, n);\n\tforeach (i; 0..4) {\n\t\tforeach (j; 0..n) {\n\t\t\tans[i][j] = '.';\n\t\t}\n\t}\n\tloop:\n\tfor (int i = 1; i <= 2; ++i) {\n\t\tfor (int j = 1; j < n - 1; ++j) {\n\t\t\tif (k == 0) {\n\t\t\t\tbreak loop;\n\t\t\t}\n\t\t\tans[i][j] = '#';\n\t\t\t--k;\n\t\t}\n\t}\n\t\"YES\".writeln;\n\tforeach (s; ans) {\n\t\tforeach (c; s) {\n\t\t\twritef(\"%c\", c);\n\t\t}\n\t\twriteln;\n\t}\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\n\nvoid main()\n{\n\tint n, k;\n\treadln.chomp.split.tie(n, k);\n\tif (2 * (n - 2) < k) {\n\t\t\"NO\".writeln;\n\t\treturn;\n\t}\n\tchar[][] ans = new char[][](4, n);\n\tforeach (i; 0..4) {\n\t\tforeach (j; 0..n) {\n\t\t\tans[i][j] = '.';\n\t\t}\n\t}\n\t// vertical\n\tfor (int i = 1; i <= 2; ++i) {\n\t\tif (k < n - 2) {\n\t\t\tbreak;\n\t\t}\n\t\tfor (int j = 1; j < n - 1; ++j) {\n\t\t\tans[i][j] = '#';\n\t\t}\n\t\tk -= n - 2;\n\t}\n\timmutable MID = n / 2;\n\tif (k % 2 == 1) {\n\t\tans[2][MID] = '#';\n\t\t--k;\n\t}\n\tfor (int i = 1; k > 0; ++i) {\n\t\tans[2][MID - i] = ans[2][MID + i] = '#';\n\t\tk -= 2;\n\t}\n\tforeach (s; ans) {\n\t\tforeach (c; s) {\n\t\t\tc.write;\n\t\t}\n\t\twriteln;\n\t}\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, k; readV(n, k);\n\n auto isHotel(int i, int j)\n {\n if (i == 0 || i == 3 || j == 0 || j == n-1) return false;\n auto a = j%2 == 1 ? (j-1)*2+(i-1) : (j-2)*2+(i-1)+(n-1);\n return a < k;\n }\n\n writeln(\"YES\");\n foreach (i; 0..4) {\n foreach (j; 0..n) {\n write(isHotel(i, j) ? \"#\" : \".\");\n }\n writeln;\n }\n}\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, k; readV(n, k);\n\n auto isHotel(int i, int j)\n {\n if (i == 0 || i == 3 || j == 0 || j == n-1) return false;\n auto a = j%2 == 1 ? (j-1)+(i-1) : (j-2)+(i-1)+(n-1);\n return a < k;\n }\n\n writeln(\"YES\");\n foreach (i; 0..4) {\n foreach (j; 0..n) {\n write(isHotel(i, j) ? \"#\" : \".\");\n }\n writeln;\n }\n}\n"}], "src_uid": "2669feb8200769869c4b2c29012059ed"} {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\t\tauto b = new bool [n];\n\t\tb[] = false;\n\t\tforeach (i; 0..k * 2)\n\t\t{\n\t\t\tint v;\n\t\t\treadf (\" %s\", &v);\n\t\t\tv--;\n\t\t\tb[v] = true;\n\t\t}\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tlong res = 0;\n\n\t\tint recur (int v, int p)\n\t\t{\n\t\t\tint num = 0;\n\t\t\tnum += b[v];\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tif (u != p)\n\t\t\t\t{\n\t\t\t\t\tint t = recur (u, v);\n\t\t\t\t\tres += min (t, 2 * k - t);\n\t\t\t\t\tnum += t;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn num;\n\t\t}\n\n\t\trecur (0, -1);\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nint N, K;\nint[][] G;\nint[] d;\nlong ans = 0;\n\nvoid dfs(int v, int par) {\n\tforeach (u; G[v]) {\n\t\tif (u == par) continue;\n\t\tdfs(u, v); d[v] += d[u];\n\t}\n\tans += min(d[v], 2 * K - d[v]);\n}\n\nvoid main() {\n\treadf(\"%d %d\", &N, &K);\n\tG = new int[][N + 1];\n\td = new int[N + 1];\n\tforeach (i; 0..2*K) {\n\t\tint In; readf(\" %d\", &In); d[In] = 1;\n\t}\n\tforeach (i; 1..N) {\n\t\tint u, v; readf(\" %d %d\", &u, &v);\n\t\tG[u] ~= v; G[v] ~= u;\n\t}\n\tdfs(1, 0);\n\twriteln(ans);\n}"}], "negative_code": [], "src_uid": "ca22cf92727a38fbb3c085b9362602db"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nTuple!(int, int)[] solve(int n, int p) {\n Tuple!(int, int)[] ans;\n foreach (i; 0 .. n) {\n ans ~= tuple(i, (i+1) % n);\n }\n foreach (i; 0 .. n) {\n ans ~= tuple(i, (i+2) % n);\n }\n int v = 0, d = 3;\n foreach (_; 0 .. p) {\n ans ~= tuple(v, (v+d) % n);\n v = (v+1) % n;\n if (v == 0) ++d;\n }\n \n foreach (ref rw; ans) rw[0] += 1, rw[1] += 1;\n return ans;\n}\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, p;\n readf(\"%s %s\", &n, &p);\n readln;\n \n auto ans = solve(n, p);\n ans.each!(t => writeln(t[0], ' ', t[1]));\n }\n}", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid solve(int n, int p) {\n Tuple!(int, int)[] ans;\n foreach (i; 0 .. n) {\n ans ~= tuple(i, (i+1) % n);\n }\n foreach (i; 0 .. n) {\n ans ~= tuple(i, (i+2) % n);\n }\n int v = 0, d = 3;\n foreach (_; 0 .. p) {\n ans ~= tuple(v, (v+d) % n);\n v = (v+1) % n;\n if (v == 0) ++d;\n }\n \n ans.each!(t => writeln(t[0]+1, ' ', t[1]+1));\n}\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, p;\n readf(\"%s %s\", &n, &p);\n readln;\n \n solve(n, p);\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint tests;\n\treadf (\" %s\", &tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, p;\n\t\treadf (\" %s %s\", &n, &p);\n\t\tauto a = new bool [] [] (n, n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint j = (i + 1) % n;\n\t\t\ta[i][j] = a[j][i] = true;\n\t\t\tint k = (j + 1) % n;\n\t\t\ta[i][k] = a[k][i] = true;\n\t\t}\n\t\tint m = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tif (m < p && !a[i][j])\n\t\t\t\t{\n\t\t\t\t\tm++;\n\t\t\t\t\ta[i][j] = a[j][i] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tif (a[i][j])\n\t\t\t\t{\n\t\t\t\t\twritefln (\"%s %s\", i + 1, j + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid solve(int n, int p) {\n Tuple!(int, int)[] ans;\n foreach (i; 0 .. n) {\n ans ~= tuple(i, (i+1) % n);\n }\n foreach (i; 0 .. n) {\n ans ~= tuple(i, (i+2) % n);\n }\n int v = 1, d = 3;\n foreach (_; 0 .. p) {\n ans ~= tuple(v, (v+d) % n);\n v = (v+1) % n;\n if (v == 0) ++d;\n }\n \n ans.each!(t => writeln(t[0]+1, ' ', t[1]+1));\n}\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, p;\n readf(\"%s %s\", &n, &p);\n readln;\n \n solve(n, p);\n }\n}"}], "src_uid": "ddbac4053bd07eada84bc44275367ae2"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nstring solve (int k, int x, int n, int m)\n{\n\tstring [2] res;\n\tbool found = false;\n\n\talias Tuple !(bool, \"b\", bool, \"e\", long, \"num\") part;\n\tauto cur = new part [k];\n\tint [2] d = [n, m];\n\n\tstring build (int p)\n\t{\n\t\tauto c = cur[p];\n\t\tstring res = \"\";\n\t\tif (c.b)\n\t\t{\n\t\t\tres ~= 'C';\n\t\t}\n\t\tforeach (i; 0..c.num)\n\t\t{\n\t\t\tres ~= \"AC\";\n\t\t}\n\t\tforeach (i; c.b + c.e + c.num * 2..d[p])\n\t\t{\n\t\t\tres ~= 'B';\n\t\t}\n\t\tif (c.e)\n\t\t{\n\t\t\tres ~= 'A';\n\t\t}\n\t\treturn res;\n\t}\n\n\tvoid gen (int p)\n\t{\n\t\tif (p == 2)\n\t\t{\n\t\t\tforeach (i; 2..k)\n\t\t\t{\n\t\t\t\tcur[i] = part (cur[i - 2].b,\n\t\t\t\t cur[i - 1].e,\n\t\t\t\t cur[i - 2].num +\n\t\t\t\t cur[i - 1].num +\n\t\t\t\t (cur[i - 2].e &&\n\t\t\t\t cur[i - 1].b));\n\t\t\t}\n\t\t\tif (cur[k - 1].num == x && !found)\n\t\t\t{\n\t\t\t\tforeach (i; 0..2)\n\t\t\t\t{\n\t\t\t\t\tres[i] = build (i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (b; 0..2)\n\t\t\t{\n\t\t\t\tforeach (e; 0..2)\n\t\t\t\t{\n\t\t\t\t\tint num = 0;\n\t\t\t\t\twhile (b + e + num * 2 <= d[p])\n\t\t\t\t\t{\n\t\t\t\t\t\tcur[p] = part (cast (bool) b,\n\t\t\t\t\t\t cast (bool) e,\n\t\t\t\t\t\t num);\n\t\t\t\t\t\tgen (p + 1);\n\t\t\t\t\t\tnum++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tgen (0);\n\n\tif (res == [\"\", \"\"])\n\t{\n\t\treturn \"Happy new year!\";\n\t}\n\treturn res[0] ~ '\\n' ~ res[1];\n}\n\nvoid main ()\n{\n\tint k, x, n, m;\n\twhile (readf (\" %s %s %s %s\", &k, &x, &n, &m) > 0)\n\t{\n\t\twriteln (solve (k, x, n, m));\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nstruct P {\n char a, b;\n long c;\n}\n\nP[] gen(int n) {\n if (n == 1) {\n return [P('A', 'A', 0),\n P('C', 'C', 0),\n P('X', 'X', 0)];\n }\n P[] ret;\n static const s = \"ACX\";\n foreach (i; 0 .. n / 2 + 1) {\n foreach (x; 0 .. 3) {\n foreach (y; 0 .. 3) {\n int r = n - i * 2;\n if (s[x] != 'X') r--;\n if (s[y] != 'X') r--;\n if (r < 0) continue;\n if (n == 2 && s[x] == 'A' && s[y] == 'C') continue;\n ret ~= P(s[x], s[y], i);\n }\n }\n }\n return ret;\n}\n\nP step(P a, P b) {\n P ret;\n ret.c = a.c + b.c;\n ret.a = a.a;\n ret.b = b.b;\n if (a.b == 'A' && b.a == 'C') {\n ret.c++;\n }\n return ret;\n}\n\nlong stepK(P a, P b, int k) {\n P t;\n foreach (i; 0 .. k) {\n t = step(a, b);\n a = b;\n b = t;\n }\n return t.c;\n}\n\nstring format(P p, int n) {\n if (n == 1) {\n return p.a.to!string;\n }\n string ret;\n if (p.a != 'X') n--;\n if (p.b != 'X') n--;\n foreach (i; 0 .. p.c) {\n ret ~= \"AC\";\n }\n foreach (i; ret.length .. n) {\n ret ~= 'X';\n }\n if (p.a != 'X') ret = p.a ~ ret;\n if (p.b != 'X') ret ~= p.b;\n return ret;\n}\n\nvoid main() {\n int k, x, n, m;\n readf(\"%d %d %d %d\\n\", &k, &x, &n, &m);\n P[] a, b;\n a = gen(n);\n b = gen(m);\n foreach (i; a) {\n foreach (j; b) {\n if (stepK(i, j, k - 2) == x) {\n writeln(format(i, n));\n writeln(format(j, m));\n return;\n }\n }\n }\n writeln(\"Happy new year!\");\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nstruct P {\n char a, b;\n int c;\n}\n\nP[] gen(int n) {\n P[] ret;\n static const s = \"ACX\";\n foreach (i; 0 .. n / 2 + 1) {\n foreach (x; 0 .. 3) {\n foreach (y; 0 .. 3) {\n int r = n - i * 2;\n if (s[x] != 'X') r--;\n if (s[y] != 'X') r--;\n if (r < 0) continue;\n ret ~= P(s[x], s[y], i);\n }\n }\n }\n return ret;\n}\n\nP step(P a, P b) {\n P ret;\n ret.c = a.c + b.c;\n ret.a = a.a;\n ret.b = b.b;\n if (a.b == 'A' && b.a == 'C') {\n ret.c++;\n }\n return ret;\n}\n\nint stepK(P a, P b, int k) {\n P t;\n foreach (i; 0 .. k) {\n t = step(a, b);\n a = b;\n b = t;\n }\n return t.c;\n}\n\nstring format(P p, int n) {\n string ret;\n if (p.a != 'X') n--;\n if (p.b != 'X') n--;\n if (p.a != 'X') ret ~= p.a;\n foreach (i; 0 .. p.c) {\n ret ~= \"AC\";\n }\n foreach (i; ret.length .. n) {\n ret ~= 'X';\n }\n if (p.b != 'X') ret ~= p.b;\n return ret;\n}\n\nvoid main() {\n int k, x, n, m;\n readf(\"%d %d %d %d\\n\", &k, &x, &n, &m);\n P[] a, b;\n a = gen(n);\n b = gen(m);\n foreach (i; a) {\n foreach (j; b) {\n if (stepK(i, j, k - 2) == x) {\n writeln(format(i, n));\n writeln(format(j, m));\n return;\n }\n }\n }\n writeln(\"Happy new year!\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nstruct P {\n char a, b;\n int c;\n}\n\nP[] gen(int n) {\n P[] ret;\n static const s = \"ACX\";\n foreach (i; 0 .. n / 2 + 1) {\n foreach (x; 0 .. 3) {\n foreach (y; 0 .. 3) {\n int r = n - i * 2;\n if (s[x] != 'X') r--;\n if (s[y] != 'X') r--;\n if (r < 0) continue;\n ret ~= P(s[x], s[y], i);\n }\n }\n }\n return ret;\n}\n\nP step(P a, P b) {\n P ret;\n ret.c = a.c + b.c;\n ret.a = a.a;\n ret.b = b.b;\n if (a.b == 'A' && b.a == 'C') {\n ret.c++;\n }\n return ret;\n}\n\nint stepK(P a, P b, int k) {\n P t;\n foreach (i; 0 .. k) {\n t = step(a, b);\n a = b;\n b = t;\n }\n return t.c;\n}\n\nstring format(P p, int n) {\n string ret;\n if (p.a != 'X') n--;\n if (p.b != 'X') n--;\n foreach (i; 0 .. p.c) {\n ret ~= \"AC\";\n }\n foreach (i; ret.length .. n) {\n ret ~= 'X';\n }\n if (p.a != 'X') ret = p.a ~ ret;\n if (p.a != 'X') ret ~= p.b;\n return ret;\n}\n\nvoid main() {\n int k, x, n, m;\n readf(\"%d %d %d %d\\n\", &k, &x, &n, &m);\n P[] a, b;\n a = gen(n);\n b = gen(m);\n foreach (i; a) {\n foreach (j; b) {\n if (stepK(i, j, k - 2) == x) {\n writeln(format(i, n));\n writeln(format(j, m));\n return;\n }\n }\n }\n writeln(\"Happy new year!\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nstruct P {\n char a, b;\n int c;\n}\n\nP[] gen(int n) {\n P[] ret;\n static const s = \"ACX\";\n foreach (i; 0 .. n / 2 + 1) {\n foreach (x; 0 .. 3) {\n foreach (y; 0 .. 3) {\n int r = n - i * 2;\n if (s[x] != 'X') r--;\n if (s[y] != 'X') r--;\n if (r < 0) continue;\n ret ~= P(s[x], s[y], i);\n }\n }\n }\n return ret;\n}\n\nP step(P a, P b) {\n P ret;\n ret.c = a.c + b.c;\n ret.a = a.a;\n ret.b = b.b;\n if (a.b == 'A' && b.a == 'C') {\n ret.c++;\n }\n return ret;\n}\n\nint stepK(P a, P b, int k) {\n P t;\n foreach (i; 0 .. k) {\n t = step(a, b);\n a = b;\n b = t;\n }\n return t.c;\n}\n\nstring format(P p, int n) {\n string ret;\n if (p.a != 'X') n--;\n if (p.b != 'X') n--;\n foreach (i; 0 .. p.c) {\n ret ~= \"AC\";\n }\n foreach (i; ret.length .. n) {\n ret ~= 'X';\n }\n if (p.a != 'X') ret = p.a ~ ret;\n if (p.b != 'X') ret ~= p.b;\n return ret;\n}\n\nvoid main() {\n int k, x, n, m;\n readf(\"%d %d %d %d\\n\", &k, &x, &n, &m);\n P[] a, b;\n a = gen(n);\n b = gen(m);\n foreach (i; a) {\n foreach (j; b) {\n if (stepK(i, j, k - 2) == x) {\n writeln(format(i, n));\n writeln(format(j, m));\n return;\n }\n }\n }\n writeln(\"Happy new year!\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nstruct P {\n char a, b;\n long c;\n}\n\nP[] gen(int n) {\n P[] ret;\n static const s = \"ACX\";\n foreach (i; 0 .. n / 2 + 1) {\n foreach (x; 0 .. 3) {\n foreach (y; 0 .. 3) {\n int r = n - i * 2;\n if (s[x] != 'X') r--;\n if (s[y] != 'X') r--;\n if (r < 0) continue;\n ret ~= P(s[x], s[y], i);\n }\n }\n }\n return ret;\n}\n\nP step(P a, P b) {\n P ret;\n ret.c = a.c + b.c;\n ret.a = a.a;\n ret.b = b.b;\n if (a.b == 'A' && b.a == 'C') {\n ret.c++;\n }\n return ret;\n}\n\nlong stepK(P a, P b, int k) {\n P t;\n foreach (i; 0 .. k) {\n t = step(a, b);\n a = b;\n b = t;\n }\n return t.c;\n}\n\nstring format(P p, int n) {\n string ret;\n if (p.a != 'X') n--;\n if (p.b != 'X') n--;\n foreach (i; 0 .. p.c) {\n ret ~= \"AC\";\n }\n foreach (i; ret.length .. n) {\n ret ~= 'X';\n }\n if (p.a != 'X') ret = p.a ~ ret;\n if (p.b != 'X') ret ~= p.b;\n return ret;\n}\n\nvoid main() {\n int k, x, n, m;\n readf(\"%d %d %d %d\\n\", &k, &x, &n, &m);\n P[] a, b;\n a = gen(n);\n b = gen(m);\n foreach (i; a) {\n foreach (j; b) {\n if (stepK(i, j, k - 2) == x) {\n writeln(format(i, n));\n writeln(format(j, m));\n return;\n }\n }\n }\n writeln(\"Happy new year!\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nstruct P {\n char a, b;\n long c;\n}\n\nP[] gen(int n) {\n if (n == 1) {\n return [P('A', 'A', 0),\n P('C', 'C', 0),\n P('X', 'X', 0)];\n }\n P[] ret;\n static const s = \"ACX\";\n foreach (i; 0 .. n / 2 + 1) {\n foreach (x; 0 .. 3) {\n foreach (y; 0 .. 3) {\n int r = n - i * 2;\n if (s[x] != 'X') r--;\n if (s[y] != 'X') r--;\n if (r < 0) continue;\n ret ~= P(s[x], s[y], i);\n }\n }\n }\n return ret;\n}\n\nP step(P a, P b) {\n P ret;\n ret.c = a.c + b.c;\n ret.a = a.a;\n ret.b = b.b;\n if (a.b == 'A' && b.a == 'C') {\n ret.c++;\n }\n return ret;\n}\n\nlong stepK(P a, P b, int k) {\n P t;\n foreach (i; 0 .. k) {\n t = step(a, b);\n a = b;\n b = t;\n }\n return t.c;\n}\n\nstring format(P p, int n) {\n if (n == 1) {\n return p.a.to!string;\n }\n string ret;\n if (p.a != 'X') n--;\n if (p.b != 'X') n--;\n foreach (i; 0 .. p.c) {\n ret ~= \"AC\";\n }\n foreach (i; ret.length .. n) {\n ret ~= 'X';\n }\n if (p.a != 'X') ret = p.a ~ ret;\n if (p.b != 'X') ret ~= p.b;\n return ret;\n}\n\nvoid main() {\n int k, x, n, m;\n readf(\"%d %d %d %d\\n\", &k, &x, &n, &m);\n P[] a, b;\n a = gen(n);\n b = gen(m);\n foreach (i; a) {\n foreach (j; b) {\n if (stepK(i, j, k - 2) == x) {\n writeln(format(i, n));\n writeln(format(j, m));\n return;\n }\n }\n }\n writeln(\"Happy new year!\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nstruct P {\n char a, b;\n int c;\n}\n\nP[] gen(int n) {\n P[] ret;\n static const s = \"ACX\";\n foreach (i; 0 .. n / 2 + 1) {\n foreach (x; 0 .. 3) {\n foreach (y; 0 .. 3) {\n int r = n - i * 2;\n if (s[x] != 'X') r--;\n if (s[y] != 'X') r--;\n if (r < 0) continue;\n ret ~= P(s[x], s[y], i);\n }\n }\n }\n return ret;\n}\n\nP step(P a, P b) {\n P ret;\n ret.c = a.c + b.c;\n ret.a = a.a;\n ret.b = b.b;\n if (a.b == 'A' && b.a == 'C') {\n ret.c++;\n }\n return ret;\n}\n\nint stepK(P a, P b, int k) {\n P t;\n foreach (i; 0 .. k) {\n t = step(a, b);\n a = b;\n b = t;\n }\n return t.c;\n}\n\nstring format(P p, int n) {\n string ret;\n if (p.a != 'X') n--;\n if (p.b != 'X') n--;\n if (p.a != 'X') ret ~= p.a;\n foreach (i; 0 .. n / 2) {\n ret ~= \"AC\";\n }\n foreach (i; ret.length .. n) {\n ret ~= 'X';\n }\n if (p.b != 'X') ret ~= p.b;\n return ret;\n}\n\nvoid main() {\n int k, x, n, m;\n readf(\"%d %d %d %d\\n\", &k, &x, &n, &m);\n P[] a, b;\n a = gen(n);\n b = gen(m);\n foreach (i; a) {\n foreach (j; b) {\n if (stepK(i, j, k - 2) == x) {\n writeln(format(i, n));\n writeln(format(j, m));\n return;\n }\n }\n }\n writeln(\"Happy new year!\");\n}\n"}], "src_uid": "1d55d31320368ddb1439ee086d40b57c"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD;\r\n\t\tauto m = RD;\r\n\t\tauto k = RD-1;\r\n\r\n\t\tif (m < n-1) continue;\r\n\t\tauto cnt = n * (n-1) / 2;\r\n\t\tif (m > cnt) continue;\r\n\t\tlong kk;\r\n\t\tif (n == 1)\r\n\t\t\tkk = 0;\r\n\t\telse if (m == cnt)\r\n\t\t\tkk = 1;\r\n\t\telse\r\n\t\t\tkk = 2;\r\n\t\tdebug writeln(\"kk:\", kk);\r\n\t\tif (kk < k)\r\n\t\t\tans[ti] = true;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.functional, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf(\" %d \", &t);\n while (t--) {\n long n, m, k;\n readf(\" %d %d %d \", &n, &m, &k);\n if (m < n - 1) {\n writeln(\"NO\");\n continue;\n }\n if (m > n * (n - 1) / 2) {\n writeln(\"NO\");\n continue;\n }\n long min_d = 2;\n if (m == n * (n - 1) / 2) {\n min_d = 1;\n }\n if (n == 1) {\n min_d = 0;\n }\n writeln(min_d < k - 1 ? \"YES\" : \"NO\");\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto k = RD!int-1;\r\n\r\n\t\tif (m < n-1) continue;\r\n\t\tauto cnt = n * (n-1) / 2;\r\n\t\tif (m > cnt) continue;\r\n\t\tlong kk;\r\n\t\tif (n == 1)\r\n\t\t\tkk = 0;\r\n\t\telse if (m == cnt)\r\n\t\t\tkk = 1;\r\n\t\telse\r\n\t\t\tkk = 2;\r\n\t\tdebug writeln(\"kk:\", kk);\r\n\t\tif (kk < k)\r\n\t\t\tans[ti] = true;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "f853a61741518cb884c00c8b760692aa"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, a, b;\n\t\treadf !(\" %s %s %s\") (n, a, b);\n\t\tstring s;\n\t\ts.reserve (n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= cast (char) (i % b + 'a');\n\t\t}\n\t\twriteln (s);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto nab = readln.split.to!(int[]);\n auto N = nab[0];\n auto A = nab[1];\n auto B = nab[2];\n\n char[] rs, ss;\n foreach (i; 0..A) {\n rs ~= (min(i, B-1) + 'a').to!char;\n }\n foreach (i; 0..N) {\n ss ~= rs[i%A];\n }\n writeln(ss);\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\n\t\tauto loop = a - b;\n\t\tint num;\n\t\tint cnt;\n\t\twhile (ans[ti].length < n)\n\t\t{\n\t\t\tif (cnt % a < loop)\n\t\t\t{\n\t\t\t\tans[ti] ~= 'a';\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans[ti] ~= cast(char)('a'+(num%b));\n\t\t\t\t++num;\n\t\t\t}\n\t\t\t++cnt;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "a82f15c1b0ddcacc1de966be20cfc5a2"} {"source_code": "import std.algorithm, std.complex, std.conv, std.math, std.numeric, std.range, std.stdio;\n\nimmutable int limit = 1 << 19, half = 512;\n\nvoid main ()\n{\n\tint n, x;\n\treadf (\" %s %s \", &n, &x);\n\tauto a = readln.splitter.map !(to!int).array ~ int.min;\n\tauto v = new long [limit];\n\tint pos = 0, cur = 0;\n\tforeach (c; a)\n\t{\n\t\t++cur;\n\t\tif (c < x) v[pos++] = cur, cur = 0;\n\t}\n\tauto u = v.map !(c => Complex!real (c % half, c / half)).array;\n\treverse (u[0..pos]);\n\tauto f = new Fft (limit);\n\tauto g = f.fft!real (u), h = f.fft!real (v);\n\tg[] *= h[];\n\tauto w = f.inverseFft!real (g).take (n + 1).map !(c => cast (long) (c.re.round + half * c.im.round)).array;\n\tw[pos - 1] = 0;\n\tforeach (i; 0..pos) w[pos - 1] += (v[i] * (v[i] - 1) / 2);\n\treverse (w[0..pos]);\n\tw[pos..$] = 0;\n\twritefln (\"%(%s %)\", w);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.complex;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 1 << 19;\nimmutable int half = 512;\n\nvoid main ()\n{\n\tint n, x;\n\twhile (readf (\" %s %s\", &n, &x) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto v = new real [limit];\n\t\tv[] = 0;\n\t\tint pos = 0;\n\t\tint cur = 1;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tif (c < x)\n\t\t\t{\n\t\t\t\tv[pos] = cur;\n\t\t\t\tpos += 1;\n\t\t\t\tcur = 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcur += 1;\n\t\t\t}\n\t\t}\n\t\tv[pos] = cur;\n\t\tpos += 1;\n\t\tauto u = v.map !(c => Complex !(real) (cast (long) (c) % half, cast (long) (c) / half)).array;\n\t\treverse (u[0..pos]);\n//\t\tdebug {writeln (u.take (n).map !(c => c.round.to !(long)));}\n\t\tdebug {writeln (v.take (n).map !(c => c.round.to !(long)));}\n\n\t\tauto f = new Fft (limit);\n\t\tauto uf = f.fft !(real) (u);\n\t\tauto vf = f.fft !(real) (v);\n\t\tauto wf = uf.dup;\n\t\twf[] *= vf[];\n\t\tauto w = f.inverseFft !(real) (wf);\n\t\tdebug {writeln (w.take (n + 1).map !(c => c.re.round.to !(long)));}\n\t\tauto wr = w.take (n + 1).map !(c => c.re.round.to !(long) + half * c.im.round.to !(long)).array;\n\t\twr[pos - 1] = 0;\n\t\tforeach (i; 0..pos)\n\t\t{\n\t\t\twr[pos - 1] += cast (long) (v[i] * (v[i] - 1) / 2);\n\t\t}\n\t\treverse (wr[0..pos]);\n\t\twr[pos..$][] = 0;\n\t\twritefln (\"%(%s %)\", wr);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.complex, std.conv, std.math, std.numeric, std.range, std.stdio;\nimmutable int L = 1 << 19, H = 512;\nvoid main () {\n\tint n, x;\n\treadf (\" %s %s \", &n, &x);\n\tauto a = readln.splitter.map !(to!int).array;\n\tauto v = a.splitter !(t => t < x).map !(t => t.length + 1L).array;\n\tauto k = v.length;\n\tv.length = L;\n\tauto u = v.map !(c => Complex!real (c % H, c / H)).array;\n\treverse (u[0..k]);\n\tauto g = u.fft!real, h = v.fft!real;\n\tg[] *= h[];\n\tauto w = g.inverseFft!real[0..k].retro.map !(c => to!long (c.re.round + H * c.im.round)).array;\n\tw[0] = k.iota.map !(i => (v[i] * (v[i] - 1) / 2)).sum;\n\tw.length = n + 1;\n\twritefln (\"%(%s %)\", w);\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass Fft(int K) {\n // 1, 1/4, 1/8, 3/8, 1/16, 5/16, 3/16, 7/16, ...\n Complex!real[] g;\n this() {\n static assert(K >= 2, \"Fft: K >= 2 must hold\");\n g.length = 1 << (K - 1);\n g[0] = 1;\n g[1 << (K - 2)] = fromPolar(1.0L, (2.0L * PI) / (1 << K));\n for (int l = 1 << (K - 2); l >= 2; l >>= 1) {\n g[l >> 1] = g[l] * g[l];\n }\n for (int l = 2; l <= 1 << (K - 2); l <<= 1) {\n for (int i = 1; i < l; ++i) {\n g[l + i] = g[l] * g[i];\n }\n }\n }\n void fft(Complex!real[] x) const {\n const n = cast(int)(x.length);\n assert(!(n & (n - 1)) && n <= 1 << K);\n for (int l = n; l >>= 1; ) {\n for (int i = 0; i < (n >> 1) / l; ++i) {\n for (int j = (i << 1) * l; j < (i << 1 | 1) * l; ++j) {\n const t = g[i] * x[j + l];\n x[j + l] = x[j] - t;\n x[j] += t;\n }\n }\n }\n for (int i = 0, j = 0; i < n; ++i) {\n if (i < j) swap(x[i], x[j]);\n for (int l = n; (l >>= 1) && !((j ^= l) & l); ) {}\n }\n }\n}\nenum FFT_K = 19;\nFft!FFT_K FFT;\n\n\n\nvoid main() {\n FFT = new Fft!FFT_K();\n \n try {\n for (; ; ) {\n const N = readInt();\n const X = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto ss = new int[N + 1];\n foreach (i; 0 .. N) {\n ss[i + 1] = ss[i] + ((A[i] < X) ? 1 : 0);\n }\n debug {\n writeln(\"ss = \", ss);\n }\n \n auto fs = new Complex!real[1 << FFT_K];\n auto gs = new Complex!real[1 << FFT_K];\n fs[] = complex(0.0L, 0.0L);\n gs[] = complex(0.0L, 0.0L);\n foreach (i; 0 .. N + 1) {\n fs[ss[i]] += 1.0L;\n gs[N - ss[i]] += 1.0L;\n }\n FFT.fft(fs);\n FFT.fft(gs);\n foreach (j; 0 .. 1 << FFT_K) {\n fs[j] *= gs[j] / (1 << FFT_K);\n }\n fs[1 .. $].reverse;\n FFT.fft(fs);\n auto ans = new long[N + 1];\n foreach (k; 1 .. N + 1) {\n ans[k] = cast(long)(fs[N + k].re + 0.5L);\n }\n ans[0] = 1L * N * (N + 1) / 2 - ans[1 .. N + 1].sum;\n \n foreach (k; 0 .. N + 1) {\n if (k > 0) write(\" \");\n write(ans[k]);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.complex : g = abs;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 1 << 20;\n\nvoid main ()\n{\n\tint n, x;\n\twhile (readf (\" %s %s\", &n, &x) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto v = new real [limit];\n\t\tv[] = 0;\n\t\tint pos = 0;\n\t\tint cur = 1;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tif (c < x)\n\t\t\t{\n\t\t\t\tv[pos] = cur;\n\t\t\t\tpos += 1;\n\t\t\t\tcur = 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcur += 1;\n\t\t\t}\n\t\t}\n\t\tv[pos] = cur;\n\t\tpos += 1;\n\t\tauto u = v.dup;\n\t\treverse (u[0..pos]);\n\t\tdebug {writeln (u.take (n).map !(c => c.round.to !(long)));}\n\t\tdebug {writeln (v.take (n).map !(c => c.round.to !(long)));}\n\n\t\tauto f = new Fft (limit);\n\t\tauto uf = f.fft !(real) (u);\n\t\tauto vf = f.fft !(real) (v);\n\t\tauto wf = uf.dup;\n\t\twf[] *= vf[];\n\t\tauto w = f.inverseFft !(real) (wf);\n\t\tdebug {writeln (w.take (n + 1).map !(c => g (c).round.to !(long)));}\n\t\tauto wr = w.take (n + 1).map !(c => g (c).round.to !(long)).array;\n\t\twr[pos - 1] = 0;\n\t\tforeach (i; 0..pos)\n\t\t{\n\t\t\twr[pos - 1] += cast (long) (v[i] * (v[i] - 1) / 2);\n\t\t}\n\t\treverse (wr[0..pos]);\n\t\twr[pos..$][] = 0;\n\t\twritefln (\"%(%s %)\", wr);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.complex, std.conv, std.math, std.numeric, std.range, std.stdio;\nimmutable int L = 1 << 19, H = 512;\nvoid main () {\n\tint n, x;\n\treadf (\" %s %s \", &n, &x);\n\tauto a = readln.splitter.map !(to!int).array;\n\tauto v = a.splitter !(t => t < x).map !(t => t.length + 1).array;\n\tauto k = v.length;\n\tv.length = L;\n\tauto u = v.map !(c => Complex!real (c % H, c / H)).array;\n\treverse (u[0..k]);\n\tauto g = u.fft!real, h = v.fft!real;\n\tg[] *= h[];\n\tauto w = g.inverseFft!real[0..k].retro.map !(c => to!long (c.re.round + H * c.im.round)).array;\n\tw[0] = k.iota.map !(i => (v[i] * (v[i] - 1) / 2)).sum;\n\tw.length = n + 1;\n\twritefln (\"%(%s %)\", w);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 1 << 19;\n\nvoid main ()\n{\n\tint n, x;\n\twhile (readf (\" %s %s\", &n, &x) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto v = new real [limit];\n\t\tv[] = 0;\n\t\tint pos = 0;\n\t\tint cur = 1;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tif (c < x)\n\t\t\t{\n\t\t\t\tv[pos] = cur;\n\t\t\t\tpos += 1;\n\t\t\t\tcur = 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcur += 1;\n\t\t\t}\n\t\t}\n\t\tv[pos] = cur;\n\t\tpos += 1;\n\t\tauto u = v.dup;\n\t\treverse (u[0..pos]);\n\t\tdebug {writeln (u.take (n).map !(c => c.round.to !(long)));}\n\t\tdebug {writeln (v.take (n).map !(c => c.round.to !(long)));}\n\n\t\tauto f = new Fft (limit);\n\t\tauto uf = f.fft !(real) (u);\n\t\tauto vf = f.fft !(real) (v);\n\t\tauto wf = uf.dup;\n\t\twf[] *= vf[];\n\t\tauto w = f.inverseFft !(real) (wf);\n\t\tdebug {writeln (w.take (n + 1).map !(c => c.re.round.to !(long)));}\n\t\tauto wr = w.take (n + 1).map !(c => c.re.round.to !(long)).array;\n\t\twr[pos - 1] = 0;\n\t\tforeach (i; 0..pos)\n\t\t{\n\t\t\twr[pos - 1] += cast (long) (v[i] * (v[i] - 1) / 2);\n\t\t}\n\t\treverse (wr[0..pos]);\n\t\twr[pos..$][] = 0;\n\t\twritefln (\"%(%s %)\", wr);\n\t}\n}\n"}], "src_uid": "97e68e5cf05c157b4f83eb07ff003790"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MOD = 1_000_000_007;\nimmutable int MAX_N = 1003;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = new byte [MAX_N * MAX_N];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto t = readln;\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\ta[(i + 1) * MAX_N + (j + 1)] =\n\t\t\t\t cast (byte) (t[j] - '0');\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (a.chunks (MAX_N));}\n\t\treal resR = 0;\n\t\tlong res = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tforeach (j; 1..n + 1)\n\t\t\t{\n\t\t\t\tvoid fun (int d1, int d2, int d3, int d4) ()\n\t\t\t\t{\n\t\t\t\t\tauto p1 = &a[i * MAX_N + j];\n\t\t\t\t\tauto p2 = &a[i * MAX_N + j];\n\t\t\t\t\tauto p3 = &a[i * MAX_N + j];\n\t\t\t\t\tauto p4 = &a[i * MAX_N + j];\n\t\t\t\t\treal curR = *p1;\n\t\t\t\t\tlong cur = *p1;\n\n\t\t\t\t\tif (curR)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor (int step = 0; ; step++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tp1 += d1;\n\t\t\t\t\t\t\tp2 += d2;\n\t\t\t\t\t\t\tp3 += d3;\n\t\t\t\t\t\t\tp4 += d4;\n\t\t\t\t\t\t\tint m = *p1 * *p2 *\n\t\t\t\t\t\t\t *p3 * *p4;\n\t\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcurR *= m;\n\t\t\t\t\t\t\tcur *= m;\n\t\t\t\t\t\t\tif (!(step & 3))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcur %= MOD;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (resR < curR)\n\t\t\t\t\t{\n\t\t\t\t\t\tresR = curR;\n\t\t\t\t\t\tres = cur;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfun !(-MAX_N - 1, -MAX_N + 1,\n\t\t\t\t +MAX_N - 1, +MAX_N + 1) ();\n\t\t\t\tfun !(-MAX_N, -1, +1, +MAX_N) ();\n\t\t\t}\n\t\t}\n\n\t\tdebug {writeln (resR);}\n\t\twriteln (res % MOD);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nimmutable int MOD = 1_000_000_007;\nimmutable int MAX_N = 1003;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = new byte [MAX_N * MAX_N];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto t = readln;\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\ta[(i + 1) * MAX_N + (j + 1)] =\n\t\t\t\t cast (byte) (t[j] - '0');\n\t\t\t}\n\t\t}\n\t\treal resR = 0;\n\t\tlong res = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tforeach (j; 1..n + 1)\n\t\t\t{\n\t\t\t\tvoid fun (int d1, int d2, int d3, int d4) ()\n\t\t\t\t{\n\t\t\t\t\tauto p1 = &a[i * MAX_N + j];\n\t\t\t\t\tauto p2 = &a[i * MAX_N + j];\n\t\t\t\t\tauto p3 = &a[i * MAX_N + j];\n\t\t\t\t\tauto p4 = &a[i * MAX_N + j];\n\t\t\t\t\treal curR = *p1;\n\t\t\t\t\tlong cur = *p1;\n\n\t\t\t\t\tif (curR)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor (int step = 0; ; step++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tp1 += d1;\n\t\t\t\t\t\t\tp2 += d2;\n\t\t\t\t\t\t\tp3 += d3;\n\t\t\t\t\t\t\tp4 += d4;\n\t\t\t\t\t\t\tint m = *p1 * *p2 *\n\t\t\t\t\t\t\t *p3 * *p4;\n\t\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcurR *= m;\n\t\t\t\t\t\t\tcur *= m;\n\t\t\t\t\t\t\tif (!(step & 3))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcur %= MOD;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (resR < curR)\n\t\t\t\t\t{\n\t\t\t\t\t\tresR = curR;\n\t\t\t\t\t\tres = cur;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfun !(-MAX_N - 1, -MAX_N + 1,\n\t\t\t\t +MAX_N - 1, +MAX_N + 1) ();\n\t\t\t\tfun !(-MAX_N, -1, +1, +MAX_N) ();\n\t\t\t}\n\t\t}\n\t\twriteln (res % MOD);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimmutable int MOD = 10 ^^ 9 + 7, MAX_N = 1002;\nvoid main () {\n\tint n;\n\twhile (readf (\" %s \", &n) > 0) {\n\t\tauto a = new byte [MAX_N * MAX_N];\n\t\tforeach (i; 1..n + 1) {\n\t\t\tauto t = readln;\n\t\t\tforeach (j; 1..n + 1) a[i * MAX_N + j] = cast (byte) (t[j - 1] - '0');\n\t\t}\n\t\treal resR = 0; long res = 0;\n\t\tvoid fun (int d1, int d2, int d3, int d4) (int i, int j) {\n\t\t\tauto p1 = &a[i * MAX_N + j], p2 = p1, p3 = p1, p4 = p1;\n\t\t\treal curR = *p1; long cur = *p1;\n\t\t\tif (curR) for (int step = 0; ; step++) {\n\t\t\t\tp1 += d1; p2 += d2; p3 += d3; p4 += d4;\n\t\t\t\tint m = *p1 * *p2 * *p3 * *p4;\n\t\t\t\tif (!m) break;\n\t\t\t\tcurR *= m; cur *= m;\n\t\t\t\tif (!(step & 3)) cur %= MOD;\n\t\t\t}\n\t\t\tif (resR < curR) {resR = curR; res = cur;}\n\t\t}\n\t\tforeach (i; 1..n + 1)\n\t\t\tforeach (j; 1..n + 1) {\n\t\t\t\tfun !(-MAX_N - 1, -MAX_N + 1, +MAX_N - 1, +MAX_N + 1) (i, j);\n\t\t\t\tfun !(-MAX_N, -1, +1, +MAX_N) (i, j);\n\t\t\t}\n\t\twriteln (res % MOD);\n\t}\n}\n"}], "negative_code": [], "src_uid": "053483902f92e87f753c14e954568629"} {"source_code": "import std.algorithm, std.conv, std.random, std.range, std.stdio, std.string, std.typecons;\nvoid main () {\n\tauto n = readln.strip.to !(int), a = readln.splitter.map !(to !(long)).array;\n\tint [long] d;\n\tforeach (s; 0..30) {\n\t\tauto y = a[uniform (0, n)];\n\t\tforeach (z; [y - 1, y, y + 1]) {\n\t\t\tfor (long c = 2; c * c <= z; c++) if (z % c == 0) {\n\t\t\t\td[c] = 1;\n\t\t\t\twhile (z % c == 0) z /= c;\n\t\t\t}\n\t\t\tif (z > 1) d[z] = 1;\n\t\t}\n\t}\n\tlong r = n;\n\tforeach (k; d.byKey) r = min (r, a.map !(z => z < k ? k - z : min (z % k, k - z % k)).sum);\n\tr.writeln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n \nimmutable int limit = 10 ^^ 6;\nimmutable int steps = 10 ^^ 3;\nimmutable int divs = 10 ^^ 3 * 2;\nimmutable int first = 10 ^^ 2 * 2;\n \nint [] p;\n \nvoid prepare ()\n{\n\tauto s = new bool [limit];\n\ts[] = true;\n\ts[0] = false;\n\ts[1] = false;\n\tp = [];\n\tp.reserve (limit / 12);\n\tfor (int v = 2; v < limit; v++)\n\t{\n\t\tif (s[v])\n\t\t{\n\t\t\tp ~= v;\n\t\t\tif (v * 1L * v < limit)\n\t\t\t{\n\t\t\t\tfor (int u = v * v; u < limit; u += v)\n\t\t\t\t{\n\t\t\t\t\ts[u] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n \nvoid main ()\n{\n\trndGen.seed (236426);\n\tprepare ();\n \n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tsort (a);\n\t\tbool [long] d;\n\t\tforeach (x; p[0..first])\n\t\t{\n\t\t\td[x] = true;\n\t\t}\n\t\tfor (int step = 0; step < steps && d.length < divs; step++)\n\t\t{\n\t\t\tauto z0 = a[uniform (0, n)];\n\t\t\tforeach (z; [z0 - 1, z0, z0 + 1])\n\t\t\t{\n\t\t\t\tforeach (const c; p)\n\t\t\t\t{\n\t\t\t\t\tif (c * 1L * c > z)\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (z % c == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\td[c] = true;\n\t\t\t\t\t\tdo\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tz /= c;\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (z % c == 0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (z > 1)\n\t\t\t\t{\n\t\t\t\t\td[z] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n \n\t\tlong res = n;\n\t\tauto e = d.byKey.array;\n\t\tsort (e);\n\t\tdebug {writeln (e);}\n\t\tforeach (const k; e)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tforeach (const z; a)\n\t\t\t{\n\t\t\t\tif (z < k)\n\t\t\t\t{\n\t\t\t\t\tcur += k - z;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong rem = z % k;\n\t\t\t\t\tcur += min (rem, k - rem);\n\t\t\t\t}\n\t\t\t\tif (cur >= res)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (k, \": \", cur);}\n\t\t\tres = min (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport core.stdc.stdio, core.stdc.stdlib, core.stdc.string;\nimport std.stdio, std.array, std.string, std.math;\nimport std.algorithm, std.range, std.random;\nimport std.conv, std.typecons;\nalias to!(string) to_string;\nalias to!(int) to_int;\nalias to!(long) to_long;\nalias to!(double) to_double;\nimmutable int inf = 0x3f3f3f3f;\nimmutable long lnf = 0x3f3f3f3f3f3f3f3f;\nimmutable typeof(null) NULL = null;\n\nint n;\nlong[] arr;\n\nvoid main() {\n n = readln.strip.to_int;\n arr = randomShuffle(readln.splitter.map!(to_long).array, rndGen);\n int[long] mp;\n foreach(i; 0 .. min(30, to_int(arr.length))) {\n foreach(x; [arr[i] - 1, arr[i], arr[i] + 1]) {\n for(long p = 2; p * p <= x; p++) {\n if (x % p == 0) {\n mp[p] = 1;\n while (x % p == 0) x /= p;\n }\n }\n if (x > 1) mp[x] = 1;\n }\n }\n long ans = n;\n foreach(k; mp.byKey) {\n ans = min(ans, arr.map!(x => x < k ? k - x : min(x % k, k - x % k)).sum);\n }\n ans.writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nimport std.random;\nimport std.functional;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nalias Z = long;\nalias N = long;\n\nN[N] factorize(Z n)\n{\n N[N] res;\n for(N d = 2; d * d <= n; d++)\n while (n % d == 0)\n res[d]++, n /= d;\n if (n != 1)\n res[n]++;\n return res;\n}\n\nN pmod(N x, N m)\n{\n return (x%m+m)%m;\n}\n\nvoid main()\n{\n N n; get(n);\n auto a = new N[cast(size_t)(n)]; get(a);\n a = a.randomShuffle;\n N minops = n;\n N minOps(N m)\n {\n if (m == 0)\n return N.max;\n N minOpsPrime(N p)\n {\n N ops = 0;\n foreach(e; a)\n\tops += min((e > pmod(e, p))? pmod(e, p) : N.max, pmod(-e, p));\n return ops;\n }\n auto factorization = m.factorize;\n N ops = n;\n foreach(prime, order; factorization)\n\tops = min(ops, memoize!minOpsPrime(prime));\n return ops;\n }\n foreach(e; a[0 .. min(18, cast(size_t)(n))])\n foreach(t; [e - 1, e, e + 1])\n minops = min(minops, memoize!minOps(t));\n ans(minops);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nimport std.random;\nimport std.functional;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n while (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nalias Z = long;\nalias N = long;\n\nN[] factorize(Z n)\n{\n N[] res;\n for(N d = 2; d * d <= n; d++)\n if (n % d == 0)\n {\n\tres ~= d;\n\tn /= d;\n\twhile (n % d == 0)\n\t n /= d;\n }\n if (n != 1)\n res ~= n;\n return res;\n}\n\nN pmod(N x, N m)\n{\n return (x%m+m)%m;\n}\n\nvoid main()\n{\n N n; get(n);\n auto a = new N[cast(size_t)(n)]; get(a);\n a = a.randomShuffle;\n N minOpsPrime(N p)\n {\n return a.map!(e => min((e > pmod(e, p))? pmod(e, p) : N.max, pmod(-e, p))).sum;\n }\n N minOps(N m)\n {\n return m == 0? N.max : m.factorize.map!(memoize!minOpsPrime).fold!min(N.max);\n }\n ans(a[0..min(18, cast(size_t)(n))]\n .map!(e => [e - 1, e, e + 1]\n\t .map!(memoize!minOps)\n\t .fold!min(N.max))\n .fold!min(N.max));\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nimport std.random;\nimport std.functional;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nalias Z = long;\nalias N = long;\n\nN[] factorize(Z n)\n{\n N[] res;\n for(N d = 2; d * d <= n; d++)\n if(n % d == 0)\n {\n\tres ~= d;\n\twhile (n % d == 0)\n\t n /= d;\n }\n if (n != 1)\n res ~= n;\n return res;\n}\n\nN pmod(N x, N m)\n{\n return (x%m+m)%m;\n}\n\nvoid main()\n{\n N n; get(n);\n auto a = new N[cast(size_t)(n)]; get(a);\n a = a.randomShuffle;\n N minops = n;\n N minOps(N m)\n {\n if (m == 0)\n return N.max;\n N minOpsPrime(N p)\n {\n N ops = 0;\n foreach(e; a)\n\tops += min((e > pmod(e, p))? pmod(e, p) : N.max, pmod(-e, p));\n return ops;\n }\n auto factorization = m.factorize;\n N ops = n;\n foreach(prime; factorization)\n\tops = min(ops, memoize!minOpsPrime(prime));\n return ops;\n }\n foreach(e; a[0 .. min(18, cast(size_t)(n))])\n foreach(t; [e - 1, e, e + 1])\n minops = min(minops, memoize!minOps(t));\n ans(minops);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nimport std.random;\nimport std.functional;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nalias Z = long;\nalias N = long;\n\nN[] factorize(Z n)\n{\n N[] res;\n for(N d = 2; d * d <= n; d++)\n if (n % d == 0)\n {\n\tres ~= d;\n\tn /= d;\n\twhile (n % d == 0)\n\t n /= d;\n }\n if (n != 1)\n res ~= n;\n return res;\n}\n\nN pmod(N x, N m)\n{\n return (x%m+m)%m;\n}\n\nvoid main()\n{\n N n; get(n);\n auto a = new N[cast(size_t)(n)]; get(a);\n a = a.randomShuffle;\n N minops = n;\n\n N minOpsElem(N e, N p)\n {\n return min((e > pmod(e, p))? pmod(e, p) : N.max, pmod(-e, p));\n }\n N minOpsPrime(N p)\n {\n return a.map!(e => minOpsElem(e, p)).sum;\n }\n N minOps(N m)\n {\n return m == 0? N.max : m.factorize.map!(memoize!minOpsPrime).fold!min(N.max);\n }\n foreach(e; a[0 .. min(18, cast(size_t)(n))])\n foreach(t; [e - 1, e, e + 1])\n minops = min(minops, memoize!minOps(t));\n ans(minops);\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nimport std.random;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nalias Z = long;\nalias N = long;\n\nN[N] factorize(Z n)\n{\n N[N] res;\n for(N d = 2; d * d <= n; d++)\n while (n % d == 0)\n res[d]++, n /= d;\n if (n != 1)\n res[n]++;\n return res;\n}\n\nN pmod(N x, N m)\n{\n return (x%m+m)%m;\n}\n\nvoid main()\n{\n N n; get(n);\n auto a = new N[cast(size_t)(n)]; get(a);\n a = a.randomShuffle;\n N minops = n;\n N minOps(N m)\n {\n if (m == 0)\n return N.max;\n N minOpsPrime(N p)\n {\n bool shallPrint = p == 3;\n N ops = 0;\n foreach(e; a)\n\t ops += min(pmod(e, p) > e? pmod(e, p) : N.max, pmod(-e, p));\n return ops;\n }\n auto factorization = m.factorize;\n N ops = n;\n foreach(prime, order; factorization)\n\tops = min(ops, minOpsPrime(prime));\n return ops;\n }\n foreach(e; a[0 .. min(40, cast(size_t)(n))])\n foreach(t; [e - 1, e, e + 2])\n minops = min(minops, minOps(e));\n ans(minops);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nimport std.random;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nalias Z = long;\nalias N = long;\n\nN[N] factorize(Z n)\n{\n N[N] res;\n for(N d = 2; d * d <= n; d++)\n while (n % d == 0)\n res[d]++, n /= d;\n if (n != 1)\n res[n]++;\n return res;\n}\n\nN pmod(N x, N m)\n{\n return (x%m+m)%m;\n}\n\nvoid main()\n{\n N n; get(n);\n auto a = new N[cast(size_t)(n)]; get(a);\n a = a.randomShuffle;\n N minops = n;\n N minOps(N m)\n {\n if (m == 0)\n return N.max;\n N minOpsPrime(N p)\n {\n bool shallPrint = p == 3;\n N ops = 0;\n foreach(e; a)\n\t ops += min(pmod(e, p) > e? pmod(e, p) : N.max, pmod(-e, p));\n return ops;\n }\n auto factorization = m.factorize;\n N ops = n;\n foreach(prime, order; factorization)\n\tops = min(ops, minOpsPrime(prime));\n return ops;\n }\n foreach(e; a[0 .. min(40, cast(size_t)(n))])\n foreach(t; [e - 1, e, e + 1])\n minops = min(minops, minOps(e));\n ans(minops);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nimport std.random;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nalias Z = long;\nalias N = long;\n\nN[N] factorize(Z n)\n{\n N[N] res;\n for(N d = 2; d * d <= n; d++)\n while (n % d == 0)\n res[d]++, n /= d;\n if (n != 1)\n res[n]++;\n return res;\n}\n\nN pmod(N x, N m)\n{\n return (x%m+m)%m;\n}\n\nvoid main()\n{\n N n; get(n);\n auto a = new N[cast(size_t)(n)]; get(a);\n a = a.randomShuffle;\n N minops = n;\n N minOps(N m)\n {\n if (m == 0)\n return N.max;\n N minOpsPrime(N p)\n {\n bool shallPrint = p == 3;\n N ops = 0;\n foreach(e; a)\n\t ops += min(pmod(e, p) > e? pmod(e, p) : N.max, pmod(-e, p));\n return ops;\n }\n auto factorization = m.factorize;\n N ops = n;\n foreach(prime, order; factorization)\n\tops = min(ops, minOpsPrime(prime));\n return ops;\n }\n foreach(e; a[0 .. min(40, cast(size_t)(n))])\n foreach(t; [e - 1, e, e + 1])\n minops = min(minops, minOps(t));\n ans(minops);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nimport std.random;\nimport std.functional;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nalias Z = long;\nalias N = long;\n\nN[] factorize(Z n)\n{\n N[] res;\n for(N d = 2; d * d <= n; d++)\n if (n % d)\n {\n\tres ~= d;\n\tn /= d;\n\twhile (n % d == 0)\n\t n /= d;\n }\n if (n != 1)\n res ~= n;\n return res;\n}\n\nN pmod(N x, N m)\n{\n return (x%m+m)%m;\n}\n\nvoid main()\n{\n N n; get(n);\n auto a = new N[cast(size_t)(n)]; get(a);\n a = a.randomShuffle;\n N minops = n;\n\n N minOpsElem(N e, N p)\n {\n return min((e > pmod(e, p))? pmod(e, p) : N.max, pmod(-e, p));\n }\n N minOpsPrime(N p)\n {\n return a.map!(e => minOpsElem(e, p)).sum;\n }\n N minOps(N m)\n {\n return m == 0? N.max : m.factorize.map!(memoize!minOpsPrime).fold!min(N.max);\n }\n foreach(e; a[0 .. min(18, cast(size_t)(n))])\n foreach(t; [e - 1, e, e + 1])\n minops = min(minops, memoize!minOps(t));\n ans(minops);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int limit = 10 ^^ 6;\nimmutable int steps = 10 ^^ 3 * 2;\nimmutable int divs = 10 ^^ 3 * 4;\nimmutable int first = 10 ^^ 2 * 4;\n\nint [] p;\n\nvoid prepare ()\n{\n\tauto s = new bool [limit];\n\ts[] = true;\n\ts[0] = false;\n\ts[1] = false;\n\tp = [];\n\tp.reserve (limit / 12);\n\tfor (int v = 2; v < limit; v++)\n\t{\n\t\tif (s[v])\n\t\t{\n\t\t\tp ~= v;\n\t\t\tif (v * 1L * v < limit)\n\t\t\t{\n\t\t\t\tfor (int u = v * v; u < limit; u += v)\n\t\t\t\t{\n\t\t\t\t\ts[u] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\trndGen.seed (236426);\n\tprepare ();\n\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\trandomShuffle (a);\n//\t\tsort (a);\n\t\tbool [long] d;\n\t\tforeach (x; p[0..first])\n\t\t{\n\t\t\td[x] = true;\n\t\t}\n\t\tfor (int step = 0; step < steps && d.length < divs; step++)\n\t\t{\n\t\t\tauto z = a[uniform (0, n)];\n\t\t\tforeach (const c; p)\n\t\t\t{\n\t\t\t\tif (c * 1L * c > z)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (z % c == 0)\n\t\t\t\t{\n\t\t\t\t\td[c] = true;\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\tz /= c;\n\t\t\t\t\t}\n\t\t\t\t\twhile (z % c == 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (z > 1)\n\t\t\t{\n\t\t\t\td[z] = true;\n\t\t\t}\n\t\t}\n\n\t\tlong res = n;\n\t\tauto e = d.byKey.array;\n\t\tsort (e);\n\t\tdebug {writeln (e);}\n\t\tforeach (const k; e)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tforeach (const z; a)\n\t\t\t{\n\t\t\t\tif (z < k)\n\t\t\t\t{\n\t\t\t\t\tcur += k - z;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong rem = z % k;\n\t\t\t\t\tcur += min (rem, k - rem);\n\t\t\t\t}\n\t\t\t\tif (cur >= res)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (k, \": \", cur);}\n\t\t\tres = min (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int limit = 10 ^^ 6;\nimmutable int steps = 10 ^^ 3;\nimmutable int divs = 10 ^^ 3 * 2;\nimmutable int first = 10 ^^ 2 * 2;\n\nint [] p;\n\nvoid prepare ()\n{\n\tauto s = new bool [limit];\n\ts[] = true;\n\ts[0] = false;\n\ts[1] = false;\n\tp = [];\n\tp.reserve (limit / 12);\n\tfor (int v = 2; v < limit; v++)\n\t{\n\t\tif (s[v])\n\t\t{\n\t\t\tp ~= v;\n\t\t\tif (v * 1L * v < limit)\n\t\t\t{\n\t\t\t\tfor (int u = v * v; u < limit; u += v)\n\t\t\t\t{\n\t\t\t\t\ts[u] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\trndGen.seed (236426);\n\tprepare ();\n\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tsort (a);\n\t\tbool [long] d;\n\t\tforeach (x; p[0..first])\n\t\t{\n\t\t\td[x] = true;\n\t\t}\n\t\tfor (int step = 0; step < steps && d.length < divs; step++)\n\t\t{\n\t\t\tauto z = a[uniform (0, n)];\n\t\t\tforeach (const c; p)\n\t\t\t{\n\t\t\t\tif (c * 1L * c > z)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (z % c == 0)\n\t\t\t\t{\n\t\t\t\t\td[c] = true;\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\tz /= c;\n\t\t\t\t\t}\n\t\t\t\t\twhile (z % c == 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (z > 1)\n\t\t\t{\n\t\t\t\td[z] = true;\n\t\t\t}\n\t\t}\n\n\t\tlong res = n;\n\t\tauto e = d.byKey.array;\n\t\tsort (e);\n\t\tdebug {writeln (e);}\n\t\tforeach (const k; e)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tforeach (const z; a)\n\t\t\t{\n\t\t\t\tif (z < k)\n\t\t\t\t{\n\t\t\t\t\tcur += k - z;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong rem = z % k;\n\t\t\t\t\tcur += min (rem, k - rem);\n\t\t\t\t}\n\t\t\t\tif (cur >= res)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (k, \": \", cur);}\n\t\t\tres = min (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int limit = 10 ^^ 6;\nimmutable int steps = 10 ^^ 3 * 2;\nimmutable int divs = 10 ^^ 3 * 6;\nimmutable int first = 10 ^^ 2 * 9;\n\nint [] p;\n\nvoid prepare ()\n{\n\tauto s = new bool [limit];\n\ts[] = true;\n\ts[0] = false;\n\ts[1] = false;\n\tp = [];\n\tp.reserve (limit / 12);\n\tfor (int v = 2; v < limit; v++)\n\t{\n\t\tif (s[v])\n\t\t{\n\t\t\tp ~= v;\n\t\t\tif (v * 1L * v < limit)\n\t\t\t{\n\t\t\t\tfor (int u = v * v; u < limit; u += v)\n\t\t\t\t{\n\t\t\t\t\ts[u] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\trndGen.seed (236426);\n\tprepare ();\n\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n//\t\trandomShuffle (a);\n\t\tsort (a);\n\t\tbool [long] d;\n\t\tforeach (x; p[0..first])\n\t\t{\n\t\t\td[x] = true;\n\t\t}\n\t\tfor (int step = 0; step < steps && d.length < divs; step++)\n\t\t{\n\t\t\tauto z = a[uniform (0, n)];\n\t\t\tforeach (const c; p)\n\t\t\t{\n\t\t\t\tif (c * 1L * c > z)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (z % c == 0)\n\t\t\t\t{\n\t\t\t\t\td[c] = true;\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\tz /= c;\n\t\t\t\t\t}\n\t\t\t\t\twhile (z % c == 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (z > 1)\n\t\t\t{\n\t\t\t\td[z] = true;\n\t\t\t}\n\t\t}\n\n\t\tlong res = n;\n\t\tauto e = d.byKey.array;\n\t\tsort (e);\n\t\tdebug {writeln (e);}\n\t\tforeach (const k; e)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tforeach (const z; a)\n\t\t\t{\n\t\t\t\tif (z < k)\n\t\t\t\t{\n\t\t\t\t\tcur += k - z;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong rem = z % k;\n\t\t\t\t\tcur += min (rem, k - rem);\n\t\t\t\t}\n\t\t\t\tif (cur >= res)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (k, \": \", cur);}\n\t\t\tres = min (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int limit = 10 ^^ 6;\nimmutable int steps = 10 ^^ 3 * 2;\nimmutable int divs = 10 ^^ 3 * 5;\nimmutable int first = 10 ^^ 2 * 8;\n\nint [] p;\n\nvoid prepare ()\n{\n\tauto s = new bool [limit];\n\ts[] = true;\n\ts[0] = false;\n\ts[1] = false;\n\tp = [];\n\tp.reserve (limit / 12);\n\tfor (int v = 2; v < limit; v++)\n\t{\n\t\tif (s[v])\n\t\t{\n\t\t\tp ~= v;\n\t\t\tif (v * 1L * v < limit)\n\t\t\t{\n\t\t\t\tfor (int u = v * v; u < limit; u += v)\n\t\t\t\t{\n\t\t\t\t\ts[u] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\trndGen.seed (1236426);\n\tprepare ();\n\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n//\t\trandomShuffle (a);\n\t\tsort (a);\n\t\tbool [long] d;\n\t\tforeach (x; p[0..first])\n\t\t{\n\t\t\td[x] = true;\n\t\t}\n\t\tfor (int step = 0; step < steps && d.length < divs; step++)\n\t\t{\n\t\t\tauto z = a[uniform (0, n)];\n\t\t\tforeach (const c; p)\n\t\t\t{\n\t\t\t\tif (c * 1L * c > z)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (z % c == 0)\n\t\t\t\t{\n\t\t\t\t\td[c] = true;\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\tz /= c;\n\t\t\t\t\t}\n\t\t\t\t\twhile (z % c == 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (z > 1)\n\t\t\t{\n\t\t\t\td[z] = true;\n\t\t\t}\n\t\t}\n\n\t\tlong res = n;\n\t\tauto e = d.byKey.array;\n\t\tsort (e);\n\t\tdebug {writeln (e);}\n\t\tforeach (const k; e)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tforeach (const z; a)\n\t\t\t{\n\t\t\t\tif (z < k)\n\t\t\t\t{\n\t\t\t\t\tcur += k - z;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong rem = z % k;\n\t\t\t\t\tcur += min (rem, k - rem);\n\t\t\t\t}\n\t\t\t\tif (cur >= res)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (k, \": \", cur);}\n\t\t\tres = min (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int limit = 10 ^^ 6;\nimmutable int steps = 10 ^^ 3 * 2;\nimmutable int divs = 10 ^^ 3 * 4;\nimmutable int first = 10 ^^ 2 * 4;\n\nint [] p;\n\nvoid prepare ()\n{\n\tauto s = new bool [limit];\n\ts[] = true;\n\ts[0] = false;\n\ts[1] = false;\n\tp = [];\n\tp.reserve (limit / 12);\n\tfor (int v = 2; v < limit; v++)\n\t{\n\t\tif (s[v])\n\t\t{\n\t\t\tp ~= v;\n\t\t\tif (v * 1L * v < limit)\n\t\t\t{\n\t\t\t\tfor (int u = v * v; u < limit; u += v)\n\t\t\t\t{\n\t\t\t\t\ts[u] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\trndGen.seed (236426);\n\tprepare ();\n\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tsort (a);\n\t\tbool [long] d;\n\t\tforeach (x; p[0..first])\n\t\t{\n\t\t\td[x] = true;\n\t\t}\n\t\tfor (int step = 0; step < steps && d.length < divs; step++)\n\t\t{\n\t\t\tauto z = a[uniform (0, n)];\n\t\t\tforeach (const c; p)\n\t\t\t{\n\t\t\t\tif (c * 1L * c > z)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (z % c == 0)\n\t\t\t\t{\n\t\t\t\t\td[c] = true;\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\tz /= c;\n\t\t\t\t\t}\n\t\t\t\t\twhile (z % c == 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (z > 1)\n\t\t\t{\n\t\t\t\td[z] = true;\n\t\t\t}\n\t\t}\n\n\t\tlong res = n;\n\t\tauto e = d.byKey.array;\n\t\tsort (e);\n\t\tdebug {writeln (e);}\n\t\tforeach (const k; e)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tforeach (const z; a)\n\t\t\t{\n\t\t\t\tif (z < k)\n\t\t\t\t{\n\t\t\t\t\tcur += k - z;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong rem = z % k;\n\t\t\t\t\tcur += min (rem, k - rem);\n\t\t\t\t}\n\t\t\t\tif (cur >= res)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (k, \": \", cur);}\n\t\t\tres = min (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "40a32523f982e24fba2c785fc6a27881"} {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Dsu(size_t n) {\n int[n] p;\n\n int get(int x) {\n return x == p[x]? x : (p[x] = get(p[x]));\n }\n\n void merge(int x, int y) {\n p[get(x)] = get(y);\n }\n}\n\nalias Girl = Tuple!(int, `weight`, int, `beauty`);\n\nstruct Group {\n int id;\n Girl[ ] girls;\n Girl sum;\n Group* next;\n}\n\nint n;\nGirl[1000] _girls;\nGirl[ ] girls;\nDsu!1000 dsu;\nGroup[1000] groups;\nint[1001][1000] dp;\n\nint dyn(int gid, int wcap) {\n assert(gid < n);\n assert(wcap >= 0);\n if (~dp[gid][wcap])\n return dp[gid][wcap];\n const grp = &groups[gid];\n assert(!grp.girls.empty);\n int result = 0;\n if (grp.next is null) {\n if (wcap >= grp.sum.weight)\n result = grp.sum.beauty;\n else\n foreach (g; grp.girls)\n if (wcap >= g.weight)\n result = max(result, g.beauty);\n } else {\n assert(grp.next == &groups[grp.next.id]);\n result = dyn(grp.next.id, wcap);\n if (wcap >= grp.sum.weight)\n result = max(result, dyn(grp.next.id, wcap - grp.sum.weight) + grp.sum.beauty);\n foreach (g; grp.girls)\n if (wcap >= g.weight)\n result = max(result, dyn(grp.next.id, wcap - g.weight) + g.beauty);\n }\n return (dp[gid][wcap] = result);\n}\n\nvoid main() {\n int m, wl;\n while (read(&n, &m, &wl)) {\n girls = _girls[0 .. n];\n foreach (int i, ref grp; groups) {\n grp.id = i;\n grp.girls = null;\n grp.sum = Girl(0, 0);\n }\n iota(0, n).copy(dsu.p[ ]);\n foreach (ref g; girls)\n read(&g.weight);\n foreach (ref g; girls)\n read(&g.beauty);\n while (m--) {\n int a, b;\n read(&a, &b);\n a--;\n b--;\n dsu.merge(a, b);\n }\n foreach (int i, g; girls) {\n auto grp = &groups[dsu.get(i)];\n grp.girls ~= g;\n grp.sum.weight += g.weight;\n grp.sum.beauty += g.beauty;\n }\n Group* last = null, first = null;\n foreach (ref grp; groups[0 .. n].filter!`!a.girls.empty`) {\n if (first is null)\n first = &grp;\n else\n last.next = &grp;\n last = &grp;\n }\n assert(last !is null);\n last.next = null;\n memset(dp.ptr, 0xFF, dp.sizeof);\n writeln(dyn(first.id, wl));\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, m, w;\n readf(\"%s %s %s\", &n, &m, &w);\n readln;\n \n auto ws = readln.chomp.split.map!(to!int).array;\n auto bs = readln.chomp.split.map!(to!int).array;\n \n auto grpid = n.iota.array;\n \n foreach (_; 0 .. m) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n --a, --b;\n \n int old = grpid[b];\n foreach (ref e; grpid) if (e == old) e = grpid[a];\n }\n \n auto vis = (false).repeat(n).array;\n auto idsForGrp = new int[][] (grpid.dup.sort.uniq.array.length);\n \n debug { grpid.writeln; }\n \n Tuple!(int, int)[] grpsVals;\n foreach (i, e; grpid) {\n if (vis[i]) continue;\n \n int wsm = 0, bsm = 0;\n foreach (j, f; grpid) {\n if (e != f) continue;\n \n idsForGrp[grpsVals.length] ~= j.to!int;\n vis[j] = true;\n wsm += ws[j];\n bsm += bs[j];\n }\n \n grpsVals ~= tuple(wsm, bsm);\n }\n \n debug { grpsVals.writeln; }\n debug { idsForGrp.writeln; }\n \n auto dp = new int[][] (grpsVals.length, w+1);\n foreach (i, t; grpsVals) {\n int grw = t[0], grb = t[1];\n \n if (i > 0) dp[i][] = dp[i-1][];\n \n for (int cw = w; cw - grw >= 0; --cw) {\n int prevVal = i > 0 ? dp[i-1][cw - grw] : 0;\n dp[i][cw] = max(dp[i][cw], prevVal + grb);\n }\n \n foreach (e; idsForGrp[i]) {\n for (int cw = w; cw - ws[e] >= 0; --cw) {\n int prevVal = i > 0 ? dp[i-1][cw - ws[e]] : 0;\n dp[i][cw] = max(dp[i][cw], prevVal + bs[e]);\n }\n }\n }\n \n debug { dp.writeln; }\n \n int ans = dp[$-1].maxElement;\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m, tw;\n\twhile (readf (\" %s %s %s\", &n, &m, &tw) > 0)\n\t{\n\t\treadln;\n\t\tauto w = readln.split.map !(to !(int)).array;\n\t\tauto b = readln.split.map !(to !(int)).array;\n\t\tauto a = new int [] [n];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto d = new bool [n];\n\t\tint [] component;\n\n\t\tvoid recur (int v)\n\t\t{\n\t\t\tif (d[v])\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\td[v] = true;\n\t\t\tcomponent ~= v;\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\trecur (u);\n\t\t\t}\n\t\t}\n\n\t\tint [] [] c;\n\n\t\tforeach (u; 0..n)\n\t\t{\n\t\t\tif (!d[u])\n\t\t\t{\n\t\t\t\tcomponent.length = 0;\n\t\t\t\tcomponent.assumeSafeAppend ();\n\t\t\t\trecur (u);\n\t\t\t\tc ~= component.dup;\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (c);}\n\n\t\tint [] [2] f;\n\t\tforeach (ref g; f)\n\t\t{\n\t\t\tg = new int [tw + 1];\n\t\t}\n\t\tint e = 0;\n\t\tf[e][] = 0;\n\t\tforeach (cur; c)\n\t\t{\n\t\t\te ^= 1;\n\t\t\tf[e][] = f[!e][];\n\t\t\tint sw = 0;\n\t\t\tint sb = 0;\n\n\t\t\tforeach (k; cur)\n\t\t\t{\n\t\t\t\tforeach (i; w[k]..tw + 1)\n\t\t\t\t{\n\t\t\t\t\tf[e][i] = max (f[e][i],\n\t\t\t\t\t f[!e][i - w[k]] + b[k]);\n\t\t\t\t}\n\t\t\t\tsw += w[k];\n\t\t\t\tsb += b[k];\n\t\t\t}\n\n\t\t\tforeach (i; sw..tw + 1)\n\t\t\t{\n\t\t\t\tf[e][i] = max (f[e][i],\n\t\t\t\t f[!e][i - sw] + sb);\n\t\t\t}\n\t\t}\n\n\t\twriteln (f[e][].reduce !(max));\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, m, w;\n readf(\"%s %s %s\", &n, &m, &w);\n readln;\n \n auto ws = readln.chomp.split.map!(to!int).array;\n auto bs = readln.chomp.split.map!(to!int).array;\n \n auto grpid = n.iota.array;\n \n foreach (_; 0 .. m) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n --a, --b;\n \n foreach (ref e; grpid) if (e == grpid[b]) e = grpid[a];\n }\n \n auto vis = (false).repeat(n).array;\n auto idsForGrp = new int[][] (grpid.dup.sort.uniq.array.length);\n \n debug { grpid.writeln; }\n \n Tuple!(int, int)[] grpsVals;\n foreach (i, e; grpid) {\n if (vis[i]) continue;\n \n int wsm = 0, bsm = 0;\n foreach (j, f; grpid) {\n if (e != f) continue;\n \n idsForGrp[grpsVals.length] ~= j.to!int;\n vis[j] = true;\n wsm += ws[j];\n bsm += bs[j];\n }\n \n grpsVals ~= tuple(wsm, bsm);\n }\n \n debug { grpsVals.writeln; }\n debug { idsForGrp.writeln; }\n \n auto dp = new int[][] (grpsVals.length, w+1);\n foreach (i, t; grpsVals) {\n int grw = t[0], grb = t[1];\n \n if (i > 0) dp[i][] = dp[i-1][];\n \n for (int cw = w; cw - grw >= 0; --cw) {\n int prevVal = i > 0 ? dp[i-1][cw - grw] : 0;\n dp[i][cw] = max(dp[i][cw], prevVal + grb);\n }\n \n foreach (e; idsForGrp[i]) {\n for (int cw = w; cw - ws[e] >= 0; --cw) {\n int prevVal = i > 0 ? dp[i-1][cw - ws[e]] : 0;\n dp[i][cw] = max(dp[i][cw], prevVal + bs[e]);\n }\n }\n }\n \n debug { dp.writeln; }\n \n int ans = dp[$-1].maxElement;\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Dsu(size_t n) {\n int[n] p;\n\n int get(int x) {\n return x == p[x]? x : (p[x] = get(p[x]));\n }\n\n void merge(int x, int y) {\n p[get(x)] = get(y);\n }\n}\n\nalias Girl = Tuple!(int, `weight`, int, `beauty`);\n\nstruct Group {\n int id;\n Girl[ ] girls;\n Girl sum;\n Group* next;\n}\n\nint n, m, wl;\nGirl[1000] _girls;\nGirl[ ] girls;\nDsu!1000 dsu;\nGroup[1000] groups;\nint[1001][1000] dp;\n\nint dyn(int gid, int curWeight) {\n assert(gid < n);\n if (~dp[gid][curWeight])\n return dp[gid][curWeight];\n const grp = &groups[gid];\n assert (!grp.girls.empty);\n if (grp.next is null) {\n if (curWeight + grp.sum.weight <= wl)\n return (dp[gid][curWeight] = grp.sum.beauty);\n int b = 0;\n foreach (g; grp.girls)\n if (curWeight + g.weight <= wl)\n b = max(b, g.beauty);\n return (dp[gid][curWeight] = b);\n } else {\n int result = 0;\n if (curWeight + grp.sum.weight <= wl)\n result = dyn(grp.next.id, curWeight + grp.sum.weight) + grp.sum.beauty;\n foreach (g; grp.girls)\n if (curWeight + g.weight <= wl)\n result = max(result, dyn(grp.next.id, curWeight + g.weight) + g.beauty);\n return (dp[gid][curWeight] = result);\n }\n}\n\nvoid main() {\n while (read(&n, &m, &wl)) {\n girls = _girls[0 .. n];\n foreach (int i, ref grp; groups) {\n grp.id = i;\n grp.girls = null;\n grp.sum = Girl(0, 0);\n }\n iota(0, n).copy(dsu.p[ ]);\n foreach (ref g; girls)\n read(&g.weight);\n foreach (ref g; girls)\n read(&g.beauty);\n while (m--) {\n int a, b;\n read(&a, &b);\n a--;\n b--;\n dsu.merge(a, b);\n }\n foreach (int i, g; girls) {\n auto grp = &groups[dsu.get(i)];\n grp.girls ~= g;\n grp.sum.weight += g.weight;\n grp.sum.beauty += g.beauty;\n }\n Group* last = null, first = null;\n foreach (ref grp; groups[0 .. n].filter!`!a.girls.empty`) {\n if (last is null)\n first = &grp;\n else\n last.next = &grp;\n last = &grp;\n }\n assert(last !is null);\n last.next = null;\n memset(dp.ptr, 0xFF, dp.sizeof);\n writeln(dyn(first.id, 0));\n }\n}\n"}], "src_uid": "7c96bc1aa4dcabf7560d915823ba22f1"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstring solve (int n, int a, int b)\n{\n\tint k = n;\n\tint [] p;\n\n\tvoid addCycle (int len)\n\t{\n\t\tint cur = p.length.to !(int) + 1;\n\t\tforeach (i; 1..len)\n\t\t{\n\t\t\tp ~= p.length.to !(int) + 2;\n\t\t}\n\t\tp ~= cur;\n\t}\n\n\twhile (k % b != 0)\n\t{\n\t\tif (k < a)\n\t\t{\n\t\t\treturn \"-1\";\n\t\t}\n\t\tk -= a;\n\t\taddCycle (a);\n\t}\n\twhile (k > 0)\n\t{\n\t\taddCycle (b);\n\t\tk -= b;\n\t}\n\tassert (k == 0);\n\treturn format (\"%(%s %)\", p);\n}\n\nvoid main ()\n{\n\tint n, a, b;\n\twhile (readf (\" %s %s %s\", &n, &a, &b) > 0)\n\t{\n\t\twriteln (solve (n, a, b));\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const A = readInt();\n const B = readInt();\n \n for (int x = 0; A * x <= N; ++x) {\n if ((N - A * x) % B == 0) {\n const y = (N - A * x) / B;\n int[] ans;\n int pos;\n foreach (i; 0 .. x) {\n foreach (j; 0 .. A) {\n ans ~= pos + (j + 1) % A;\n }\n pos += A;\n }\n foreach (i; 0 .. y) {\n foreach (j; 0 .. B) {\n ans ~= pos + (j + 1) % B;\n }\n pos += B;\n }\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i] + 1);\n }\n writeln();\n goto found;\n }\n }\n writeln(-1);\n found:\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "138f7db4a858fb1efe817ee6491f83d9"} {"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n;\r\n readf!\"%d\\n\"(n);\r\n int[] a = readln.split.map!(to!int).array, b = a.dup;\r\n b.sort();\r\n foreach (i; 0 .. n)\r\n if (a[i] != b[1])\r\n writeln(i + 1);\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n;\r\n readf!\"%d\\n\"(n);\r\n int[] a = readln.split.map!(to!int).array;\r\n if (a[0] == a[1])\r\n {\r\n foreach (j; 0 .. n)\r\n if (a[j] != a[0])\r\n writeln(j + 1);\r\n }\r\n else\r\n {\r\n if (a[0] == a[2])\r\n writeln(2);\r\n else\r\n writeln(1);\r\n }\r\n }\r\n}"}, {"source_code": "import std;\r\n\r\nvoid main() {\r\n int t;\r\n readf(\"%d\\n\", t);\r\n\r\n foreach (_; 0 .. t) {\r\n int n;\r\n readf(\"%d\\n\", n);\r\n\r\n auto a = readln.chomp.split.to!(int[]);\r\n\r\n if (a[0] == a[1] && a[1] == a[2]) {\r\n foreach (i; 3 .. n) {\r\n if (a[i] != a[0]) {\r\n writeln(i+1);\r\n }\r\n }\r\n }\r\n else {\r\n if (a[0] == a[1]) writeln(3);\r\n if (a[0] == a[2]) writeln(2);\r\n if (a[1] == a[2]) writeln(1);\r\n }\r\n }\r\n}"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1512/problem/A\n// simulation, implementation\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(to!int).array;\n\n int[] counter = new int[101];\n\n foreach(item; a) {\n counter[item] += 1;\n }\n\n for(int i = 0; i < n; ++i) {\n if(counter[a[i]] == 1) {\n (i + 1).writeln;\n break;\n }\n }\n}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n;\r\n readf!\"%d\\n\"(n);\r\n int[] a = readln.split.map!(to!int).array, b = a.dup;\r\n b.sort();\r\n foreach (i; 0 .. n)\r\n if (b[i] != a[1])\r\n writeln(i + 1);\r\n }\r\n}"}], "src_uid": "224a0b09547ec1441474efbd8e06353b"} {"source_code": "module main;\n\nimport std.stdio, std.string;\n\nstatic auto mod = 1000000007;\n\nvoid init(int[] dp, int[] s, int k)\n{\n foreach (i; 0 .. k)\n {\n dp[i] = 1;\n }\n foreach (i; k .. dp.length)\n {\n dp[i] = (dp[i - 1] + dp[i - k]) % mod;\n }\n s[0] = 0;\n foreach (i; 1 .. s.length)\n {\n s[i] = (s[i - 1] + dp[i]) % mod;\n }\n}\n\nint main(string[] args)\n{\n int k, t;\n while (scanf(\"%d%d\", &t, &k) == 2)\n {\n auto dp = new int[100001];\n auto s = new int[100001];\n init(dp, s, k);\n foreach (i; 0 .. t)\n {\n int a, b;\n scanf(\"%d%d\", &a, &b);\n auto ans = s[b] - s[a - 1];\n if (ans < 0)\n {\n ans += mod;\n }\n writefln(\"%d\", ans);\n }\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.exception;\n\nvoid main() {\n\tsize_t t, k;\n\tenforce(readf(\" %s %s\", &t, &k));\n\n\tenum MOD = cast(int)(1e9 + 7);\n\tenum N = 100500;\n\tint[N] z;\n\tz[0] = 1;\n\tforeach (cur; 1..N) {\n\t\tz[cur] = z[cur - 1];\n\t\tif (cur >= k)\n\t\t\tz[cur] += z[cur - k];\n\t\tz[cur] %= MOD;\n\t}\n\tforeach (cur; 1..N) {\n\t\tz[cur] += z[cur - 1];\n\t\tz[cur] %= MOD;\n\t}\n\n\tforeach (test; 0..t) {\n\t\tsize_t a, b;\n\t\tenforce(readf(\" %s %s\", &a, &b));\n\t\tauto ans = (z[b] - z[a - 1] + MOD) % MOD;\n\t\twriteln(ans);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nvoid main() {\n immutable int MAX = 10^^5+1;\n immutable int MOD = 10^^9+7;\n \n int T, K;\n scanf(\"%d %d\", &T, &K);\n\n auto dp = new int[](MAX);\n foreach (i; 1..MAX) {\n dp[i] = (dp[i-1] + 1) % MOD;\n if (i - K >= 0)\n dp[i] = ((dp[i] + dp[i-K]) % MOD + 1) % MOD;\n }\n\n int a, b;\n foreach (_; 0..T) {\n scanf(\"%d %d\", &a, &b);\n writeln(((dp[b] - dp[a-1]) % MOD + MOD) % MOD);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nvoid main() {\n immutable int MAX = 10^^5+1;\n immutable int MOD = 10^^9+7;\n \n int T, K;\n scanf(\"%d %d\", &T, &K);\n\n auto dp = new int[](MAX);\n foreach (i; 1..MAX) {\n dp[i] = (dp[i-1] + 1) % MOD;\n if (i - K >= 0)\n dp[i] = ((dp[i] + dp[i-K]) % MOD + 1);\n }\n\n int a, b;\n foreach (_; 0..T) {\n scanf(\"%d %d\", &a, &b);\n writeln(dp[b] - dp[a-1]);\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nvoid main() {\n immutable int MAX = 10^^5+1;\n immutable int MOD = 10^^9+7;\n \n int T, K;\n scanf(\"%d %d\", &T, &K);\n\n auto dp = new int[](MAX);\n foreach (i; 1..MAX) {\n dp[i] = (dp[i-1] + 1) % MOD;\n if (i - K >= 0)\n dp[i] = ((dp[i] + dp[i-K]) % MOD + 1);\n }\n\n int a, b;\n foreach (_; 0..T) {\n scanf(\"%d %d\", &a, &b);\n writeln((dp[b] - dp[a-1]) % MOD + MOD % MOD);\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nvoid main() {\n immutable int MAX = 10^^5+1;\n immutable int MOD = 10^^9+7;\n \n int T, K;\n scanf(\"%d %d\", &T, &K);\n\n auto dp = new int[](MAX);\n foreach (i; 1..MAX) {\n dp[i] = (dp[i-1] + 1) % MOD;\n if (i - K >= 0)\n dp[i] = ((dp[i] + dp[i-K]) % MOD + 1) % MOD;\n }\n\n int a, b;\n foreach (_; 0..T) {\n scanf(\"%d %d\", &a, &b);\n writeln((dp[b] - dp[a-1]) % MOD + MOD % MOD);\n }\n}\n"}, {"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid init(int[] dp, int[] s, int k)\n{\n static auto mod = 1000000007;\n foreach (i; 0 .. k)\n {\n dp[i] = 1;\n }\n foreach (i; k .. dp.length)\n {\n dp[i] = (dp[i - 1] + dp[i - k]) % mod;\n }\n s[1] = dp[1];\n foreach (i; 2 .. s.length)\n {\n s[i] = (s[i - 1] + dp[i]) % mod;\n }\n}\n\nint main(string[] args)\n{\n int k, t;\n while (scanf(\"%d%d\", &t, &k) == 2)\n {\n auto dp = new int[100001];\n auto s = new int[100001];\n init(dp, s, k);\n foreach (i; 0 .. t)\n {\n int a, b;\n scanf(\"%d%d\", &a, &b);\n writefln(\"%d\", s[b] - s[a - 1]);\n }\n }\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.exception;\n\nvoid main() {\n\tsize_t t, k;\n\tenforce(readf(\" %s %s\", &t, &k));\n\n\tenum MOD = cast(int)(1e9 + 7);\n\tenum N = 100500;\n\tint[N] z;\n\tz[0] = 1;\n\tforeach (cur; 1..N) {\n\t\tz[cur] = z[cur - 1];\n\t\tif (cur >= k)\n\t\t\tz[cur] += z[cur - k];\n\t\tz[cur] %= MOD;\n\t}\n\tforeach (cur; 1..N) {\n\t\tz[cur] += z[cur - 1];\n\t\tz[cur] %= MOD;\n\t}\n\n\tforeach (test; 0..t) {\n\t\tsize_t a, b;\n\t\tenforce(readf(\" %s %s\", &a, &b));\n\t\tauto ans = z[b] - z[a - 1];\n\t\twriteln(ans);\n\t}\n}\n"}], "src_uid": "16c016c0735be1815c7b94c5c50516f1"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip;\r\n\t\tbool ok = false;\r\n\t\tforeach (i; 0..3)\r\n\t\t{\r\n\t\t\tauto t = \"Yes\".cycle.drop (i).take (s.length);\r\n\t\t\tif (equal (s, t))\r\n\t\t\t{\r\n\t\t\t\tok = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n auto x = readln.strip();\r\n bool norm = true;\r\nouter: foreach(i, e; x) {\r\n if (i == 0) {\r\n if ((e != 'Y') && (e != 'e') && (e !='s')) {\r\n norm = false;\r\n break outer;\r\n }\r\n }\r\n else {\r\n if ((e == 'Y' && x[i-1] == 's') || (e == 'e' && x[i-1] == 'Y') || (e == 's' && x[i-1] == 'e'))\r\n continue;\r\n else {\r\n norm = false;\r\n break outer;\r\n }\r\n }\r\n }\r\n if (norm)\r\n writeln(\"yes\");\r\n else\r\n writeln(\"no\");\r\n\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto s = readln.strip;\n char prevch = s[0];\n bool good = (prevch == 'Y' || prevch == 'e' || prevch == 's');\n foreach (ch ; s[1 .. $]) {\n if ((ch == 'Y' && prevch == 's') ||\n (ch == 'e' && prevch == 'Y') ||\n (ch == 's' && prevch == 'e')) {\n prevch = ch;\n } else {\n good = false;\n break;\n }\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip.toLower;\r\n\t\tbool ok = false;\r\n\t\tforeach (i; 0..3)\r\n\t\t{\r\n\t\t\tauto t = \"yes\".cycle.drop (i).take (s.length);\r\n\t\t\tif (equal (s, t))\r\n\t\t\t{\r\n\t\t\t\tok = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "src_uid": "3cd56870a96baf8860e9b7e89008d895"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tauto m = a.maxElement * (n - 1L);\n\t\tauto t = a.sum (0L);\n\t\tauto s = max (m, t);\n\t\ts += ((n - 1) - (s % (n - 1))) % (n - 1);\n\t\twriteln (s - t);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tlong x, tot;\n\t\tforeach (e; a)\n\t\t{\n\t\t\tx.chmax(e);\n\t\t\ttot += e;\n\t\t}\n\t\tauto y = x * (n-1);\n\t\tif (tot <= y)\n\t\t\tans[ti] = y - tot;\n\t\telse\n\t\t\tans[ti] = ((n-1) - (tot % (n-1))) % (n-1);\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tlong x, tot;\n\t\tforeach (e; a)\n\t\t{\n\t\t\tx.chmax(e);\n\t\t\ttot += e;\n\t\t}\n\t\tauto y = x * (n-1);\n\t\tif (tot <= y)\n\t\t\tans[ti] = y - tot;\n\t\telse\n\t\t\tans[ti] = (n-1) - (tot % (n-1));\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "e75b88ce4341062c20b6014da1152d29"} {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main() {\n\tauto nab = readln.chomp.split.map!(to!int);\n\tint n = nab[0];\n\tlong a = nab[1];\n\tlong b = nab[2];\n\tlong[] s = readln.chomp.split.map!(to!long).array;\n\tlong S = s.sum;\n\tlong[] t = std.algorithm.sort!\"a > b\"(s[1..$]).array;\n\tlong f = s[0] * a;\n\tint ans = n - 1;\n\tforeach (i, v; t) {\n\t\tdebug stderr.writefln(\"[%d] %d %d\", i, v, S);\n\t\tif (f >= b * S) {\n\t\t\tans = cast(int) i;\n\t\t\tbreak;\n\t\t}\n\t\tS -= v;\n\t}\n\tans.writeln;\n}\n\n\n", "positive_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, a, b; readV(n, a, b);\n int[] s; readA(n, s);\n\n int t = s.sum;\n\n auto s2 = s[1..$];\n s2.sort!\"a > b\";\n\n auto t2 = 0;\n foreach (i; 0..n) {\n if (a.to!long*s[0] >= b.to!long*(t-t2)) {\n writeln(i);\n return;\n }\n t2 += s2[i];\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main() {\n\tauto nab = readln.chomp.split.map!(to!int);\n\tint n = nab[0];\n\tint a = nab[1];\n\tint b = nab[2];\n\tint[] s = readln.chomp.split.map!(to!int).array;\n\tint S = s.sum;\n\tint[] t = std.algorithm.sort!\"a > b\"(s[1..$]).array;\n\tint f = s[0] * a;\n\tint ans = n - 1;\n\tforeach (i, v; t) {\n\t\tif (f >= b * S) {\n\t\t\tans = cast(int) i;\n\t\t\tbreak;\n\t\t}\n\t\tS -= v;\n\t}\n\tans.writeln;\n}\n\n\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main() {\n\tauto nab = readln.chomp.split.map!(to!int);\n\tint n = nab[0];\n\tint a = nab[1];\n\tint b = nab[2];\n\tint[] s = readln.chomp.split.map!(to!int).array;\n\tint S = s.sum;\n\tint f = s[0] * a;\n\tint ans = n - 1;\n\tforeach (i, v; s[1..$]) {\n\t\tif (f >= b * S) {\n\t\t\tans = cast(int) i;\n\t\t\tbreak;\n\t\t}\n\t\tS -= v;\n\t}\n\tans.writeln;\n}\n\n\n"}], "src_uid": "fd6b73a2c15f5b009fa350eea9bf0c0a"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int w; rd(w);\n auto a=new long[][](2, w);\n a[0]=readln.split.to!(long[]); \n a[1]=readln.split.to!(long[]);\n\n auto s=new long[](w+1);\n auto sr=new long[][](2, w+1);\n auto sl=new long[][](2, w+1);\n foreach(j; 0..w){\n s[j+1]=s[j];\n if(j%2==0) s[j+1]+=a[0][j]*(j*2)+a[1][j]*(j*2+1);\n else s[j+1]+=a[1][j]*(j*2)+a[0][j]*(j*2+1);\n }\n auto sub=new long[][](2, w+1);\n foreach(i; 0..2)foreach(j; 0..w) sub[i][j+1]=sub[i][j]+a[i][j];\n foreach(i; 0..2)for(int j=w-1; j>=0; j--){\n sr[i][j]=sr[i][j+1];\n sr[i][j]-=(sub[i][w]-sub[i][j+1]);\n sr[i][j]+=a[i][j]*(j*2); // \u3061\u3087\u3063\u3068\u30b5\u30dc\u308b \n\n sl[i][j]=sl[i][j+1];\n sl[i][j]-=(sub[i][w]-sub[i][j+1]);\n sl[i][j]+=a[i][j]*(w*2-1);\n }\n long mx=0;\n for(int j=0; j<=w; j++){\n if(j%2==0){\n mx=max(mx, s[j]+sr[0][j]+sl[1][j]);\n // writeln(s[j]+sr[0][j]+sl[1][j]);\n }else{\n mx=max(mx, s[j]+sr[1][j]+sl[0][j]);\n // writeln(s[j]+sr[1][j]+sl[0][j]);\n }\n }\n writeln(mx);\n}\n\n/* \n s[j]:=j\u5217\u76ee\u307e\u3067\u30b8\u30b0\u30b6\u30b0 (1-indexed)\n j=0, 1, ..., w\n s[0]=0\n sr[i][j]:=i\u884c\u3092j\u5217\u304b\u3089\u53f3\u7aef\u307e\u3067 (0-indexed)\n sl[i][j]:=i\u884c\u3092\u53f3\u7aef\u304b\u3089j\u5217\u307e\u3067 (0-indexed)\n\n sl[*][w]=sr[*][w]=0\n\n j\u5217\u307e\u3067\u30b8\u30b0\u30b6\u30b0 j=0, 1, ..., w\n j\u304c\u5076\u6570\n 0\u884c\u76ee\u3092j+1\u5217\u76ee\u304b\u3089\u53f3\u7aef\u307e\u3067\u30011\u884c\u76ee\u3092\u53f3\u7aef\u304b\u3089j+1\u5217\u76ee\u307e\u3067\n s[j]+sr[0][j]+sl[1][j]\n j\u304c\u5947\u6570\n s[j]+sr[1][j]+sl[0][j]\n\n*/\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = 2.iota.map!(_ => readln.split.map!(to!long).array).array;\n auto B = new long[][](2, N+1);\n\n foreach (i; 0..2)\n foreach (j; 0..N)\n B[i][j+1] = B[i][j] + A[i][j];\n\n long ans = 0;\n long tmp = 0;\n long a = 0;\n long b = 0;\n foreach (i; 0..N) a += i * A[0][i];\n foreach (i; 0..N) a += (N+N-i-1) * A[1][i];\n\n foreach (i; 1..N) b += (i + 1) * A[1][i];\n foreach (i; 1..N) b += (N+N-i) * A[0][i];\n\n foreach (i; 0..N) {\n long t = i*2;\n if (i % 2 == 0) {\n ans = max(ans, tmp + a);\n tmp += t * A[0][i];\n tmp += (t + 1) * A[1][i];\n if (i < N-2) {\n a -= t * A[0][i];\n a -= (t+1) * A[0][i+1];\n a += (B[0][N] - B[0][i+2]) * 2;\n a -= (2 * N - 1) * A[1][i];\n a -= (2 * N - 2) * A[1][i+1];\n a += (B[1][N] - B[1][i+2]) * 2;\n }\n } else {\n ans = max(ans, tmp + b);\n tmp += t * A[1][i];\n tmp += (t + 1) * A[0][i];\n if (i < N-2) {\n b -= t * A[1][i];\n b -= (t+1) * A[1][i+1];\n b += (B[1][N] - B[1][i+2]) * 2;\n b -= (2 * N - 1) * A[0][i];\n b -= (2 * N - 2) * A[0][i+1];\n b += (B[0][N] - B[0][i+2]) * 2;\n }\n }\n if (i == N-1) ans = max(ans, tmp);\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int[][] rws;\n foreach (_; 0 .. 2) rws ~= readln.chomp.split.map!(to!int).array;\n \n debug { rws.writeln; }\n \n auto mxsum = new long[][] (2, n+1);\n mxsum[0][$-1] = mxsum[1][$-1] = 0;\n auto dp = new long[][] (2, n+1);\n dp[0][$-1] = dp[1][$-1] = 0;\n auto totsum = 0L, updown = 0L, downup = 0L;\n foreach_reverse (i; 0 .. n) {\n updown += totsum + cast(long)(2*(n-i) - 1) * rws[1][i];\n downup += totsum + cast(long)(2*(n-i) - 1) * rws[0][i];\n \n dp[0][i] = max(updown, cast(long)rws[1][i] + dp[1][i+1] + 2*totsum);\n dp[1][i] = max(downup, cast(long)rws[0][i] + dp[0][i+1] + 2*totsum);\n \n totsum += rws[0][i] + rws[1][i];\n debug { writeln(dp[0][i], ' ', dp[1][i]); }\n }\n \n dp[0][0].writeln;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int[][] rws;\n foreach (_; 0 .. 2) rws ~= readln.chomp.split.map!(to!int).array;\n \n debug { rws.writeln; }\n \n auto dp = new long[][] (2, n+1);\n dp[0][$-1] = dp[1][$-1] = 0;\n auto totsum = 0L, updown = 0L, downup = 0L;\n foreach_reverse (i; 0 .. n) {\n updown += totsum + cast(long)(2*(n-i) - 1) * rws[1][i];\n downup += totsum + cast(long)(2*(n-i) - 1) * rws[0][i];\n \n dp[0][i] = max(updown, cast(long)rws[1][i] + dp[1][i+1] + 2*totsum);\n dp[1][i] = max(downup, cast(long)rws[0][i] + dp[0][i+1] + 2*totsum);\n \n totsum += rws[0][i] + rws[1][i];\n \n debug { writeln(dp[0][i], ' ', dp[1][i]); }\n }\n \n dp[0][0].writeln;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int[][] rws;\n foreach (_; 0 .. 2) rws ~= readln.chomp.split.map!(to!int).array;\n \n debug { rws.writeln; }\n \n auto dp = new long[][] (2, n+1);\n dp[0][$-1] = dp[1][$-1] = 0;\n auto totsum = 0L, updown = 0L, downup = 0L;\n \n foreach_reverse (i; 0 .. n)\n {\n updown += totsum + cast(long)(2*(n-i) - 1) * rws[1][i];\n downup += totsum + cast(long)(2*(n-i) - 1) * rws[0][i];\n \n dp[0][i] = max(updown, cast(long)rws[1][i] + dp[1][i+1] + 2*totsum);\n dp[1][i] = max(downup, cast(long)rws[0][i] + dp[0][i+1] + 2*totsum);\n \n totsum += rws[0][i] + rws[1][i];\n \n debug { writeln(dp[0][i], ' ', dp[1][i]); }\n }\n \n dp[0][0].writeln;\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int w; rd(w);\n auto a=new long[][](2, w);\n a[0]=readln.split.to!(long[]); \n a[1]=readln.split.to!(long[]);\n\n auto s=new long[](w+1);\n auto sr=new long[][](2, w+1);\n auto sl=new long[][](2, w+1);\n foreach(j; 0..w){\n s[j+1]=s[j];\n if(j%2==0) s[j+1]+=a[0][j]*(j*2)+a[1][j]*(j*2+1);\n else s[j+1]+=a[1][j]*(j*2)+a[0][j]*(j*2+1);\n }\n auto sub=new long[][](2, w+1);\n foreach(i; 0..2)foreach(j; 0..w) sub[i][j+1]=sub[i][j]+a[i][j];\n foreach(i; 0..2)for(int j=w-1; j>=0; j--){\n sr[i][j]=sr[i][j+1];\n sr[i][j]-=(sub[i][w]-sub[i][j+1]);\n sr[i][j]+=a[i][j]*(j*2); // \u3061\u3087\u3063\u3068\u30b5\u30dc\u308b \n\n sl[i][j]=sl[i][j+1];\n sl[i][j]-=(sub[i][w]-sub[i][j+1]);\n sl[i][j]+=a[i][j]*(w*2-1);\n }\n long mx=0;\n for(int j=0; j<=w; j++){\n if(j%2==0) mx=max(mx, s[j]+sr[0][j]+sl[1][j]);\n else mx=max(mx, s[j]+sr[1][j]+sl[0][j]);\n }\n writeln(mx);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "negative_code": [], "src_uid": "948429d3788b212e7763774f8cab097b"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nlong saiki(int idx, int pos, int n, long[][] dp, int[][] a)\n{\n if (dp[idx][pos] != -1)\n {\n return dp[idx][pos];\n }\n if (idx == n - 1)\n {\n long val = 0;\n for (int i = 2; i >= 0; -- i)\n {\n val += a[i][n - 1];\n dp[idx][i] = val;\n }\n return dp[idx][pos];\n }\n auto ndp = new long[][](2, 3);\n auto sum = new long[2];\n foreach (i; 0 .. 2)\n {\n sum[i] = 0;\n foreach (j; 0 .. 3)\n {\n sum[i] += a[j][idx + i];\n if (idx + i + 1 < n)\n {\n ndp[i][j] = saiki(idx + i + 1, j, n, dp, a);\n }\n }\n }\n auto res = long.min;\n if (pos == 1)\n {\n res = max(res, ndp[0][pos] + a[pos][idx]);\n res = max(res, ndp[0][0] + a[pos][idx] + a[0][idx]);\n res = max(res, ndp[0][2] + a[pos][idx] + a[2][idx]);\n }\n else\n {\n res = max(res, ndp[0][pos] + a[pos][idx]);\n res = max(res, ndp[0][1] + a[pos][idx] + a[1][idx]);\n if (pos == 0) res = max(res, ndp[0][2] + sum[0]);\n else res = max(res, ndp[0][0] + sum[0]);\n if (idx + 2 < n)\n {\n if (pos == 0) res = max(res, ndp[1][2] + sum[0] + sum[1]);\n else res = max(res, ndp[1][0] + sum[0] + sum[1]); \n }\n if (idx == n - 2 && pos == 0)\n {\n res = max(res, sum[0] + sum[1]);\n }\n }\n dp[idx][pos] = res;\n return res;\n}\n\nvoid solve(int[][] a, int n)\n{\n auto dp = new long[][](n, 3);\n foreach (i; 0 .. n)\n {\n fill(dp[i], -1);\n }\n auto ans = saiki(0, 0, n, dp, a);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto a = new int[][](3, n);\n foreach (i; 0 .. 3)\n {\n foreach (j; 0 .. n)\n {\n readf(\" %d\", &a[i][j]);\n }\n readln;\n }\n solve(a, n);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nlong saiki(int idx, int pos, int n, long[][] dp, int[][] a)\n{\n if (dp[idx][pos] != -1)\n {\n return dp[idx][pos];\n }\n if (idx == n - 1)\n {\n long val = 0;\n for (int i = 2; i >= 0; -- i)\n {\n val += a[i][n - 1];\n dp[idx][i] = val;\n }\n return dp[idx][pos];\n }\n long[3][2] ndp;\n long[2] sum;\n foreach (i; 0 .. 2)\n {\n sum[i] = 0;\n foreach (j; 0 .. 3)\n {\n sum[i] += a[j][idx + i];\n if (idx + i + 1 < n)\n {\n ndp[i][j] = saiki(idx + i + 1, j, n, dp, a);\n }\n }\n }\n auto res = long.min;\n if (pos == 1)\n {\n res = max(res, ndp[0][pos] + a[pos][idx]);\n res = max(res, ndp[0][0] + a[pos][idx] + a[0][idx]);\n res = max(res, ndp[0][2] + a[pos][idx] + a[2][idx]);\n }\n else\n {\n res = max(res, ndp[0][pos] + a[pos][idx]);\n res = max(res, ndp[0][1] + a[pos][idx] + a[1][idx]);\n res = max(res, ndp[0][2 - pos] + sum[0]);\n if (idx + 2 < n)\n {\n if (pos == 0) res = max(res, ndp[1][2] + sum[0] + sum[1]);\n else res = max(res, ndp[1][0] + sum[0] + sum[1]); \n }\n if (idx == n - 2 && pos == 0)\n {\n res = max(res, sum[0] + sum[1]);\n }\n }\n dp[idx][pos] = res;\n return res;\n}\n\nvoid solve(int[][] a, int n)\n{\n auto dp = new long[][](n, 3);\n foreach (i; 0 .. n)\n {\n fill(dp[i], -1);\n }\n auto ans = saiki(0, 0, n, dp, a);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto a = new int[][](3, n);\n foreach (i; 0 .. 3)\n {\n foreach (j; 0 .. n)\n {\n readf(\" %d\", &a[i][j]);\n }\n readln;\n }\n solve(a, n);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "301a6dd54b3d404e98f5e1ee014d5c89"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n for (int i = 1; i <= n; i++) {\n write(i, \" \");\n }\n writeln();\n } \n}", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main () {\n\tforeach (test; 0..readln.strip.to !(int))\n\t\treadln.strip.to !(int).iota.map !(q{a + 1}).writefln !(\"%(%s %)\");\n}\n"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n \nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n \n double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n \nvoid main() {\n IO cin;\n int t = 1;\n t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n for (int i = 1; i <= n; i++) {\n write(i, \" \");\n }\n writeln();\n } \n}\n/* CODED BY:-\n ___________________________________\n| ___ |\n| /\\ /\\ \\ / | | |___ |__| | \n| /~~\\ /~~\\ | |__| ___| | | |\n|___________________________________|\n \n*/"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\t\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tans[ti] ~= i+1;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "1b3ac752bc9c0b5e20a76f028d4b3c15"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tbool [int] vis;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tvis[c] = true;\n\t\t}\n\t\tif (vis.length > k)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (n * k);\n\t\t\twritefln !(\"%(%s %)\")\n\t\t\t (vis.byKey.cycle.take (k).repeat (n).joiner);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tbool[int] set;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tset[a[i]] = true;\n\t\t}\n\t\tif (set.keys.length > k) continue;\n\n\t\tauto len = (10^^4) / k;\n\t\tlen *= k;\n\t\tans[ti].length = len;\n\t\tauto b = set.keys.dup;\n\t\twhile (b.length < k)\n\t\t\tb ~= 1;\n\t\tforeach (i; 0..len)\n\t\t{\n\t\t\tauto pos = i % k;\n\t\t\tans[ti][i] = b[pos];\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t{\n\t\t\twriteln(e.length);\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n auto as = readln.split.to!(int[]);\n auto ns = new bool[](100);\n foreach (a; as) ns[a-1] = true;\n int c;\n foreach (n; ns) if (n) ++c;\n if (c > K) {\n writeln(\"-1\");\n continue;\n }\n int[] ii;\n foreach (i, n; ns) if (n) ii ~= i.to!int+1;\n while (ii.length < K) ii ~= ii[0];\n int[] ms;\n size_t i;\n foreach (a; as) {\n while (a != ii[i]) {\n ms ~= ii[i++];\n i %= ii.length;\n }\n ms ~= a;\n ++i;\n i %= ii.length;\n }\n writeln(ms.length);\n writeln(ms.to!(string[]).join(\" \"));\n }\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tbool [int] vis;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tvis[c] = true;\n\t\t}\n\t\tif (vis.length > k)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (n * vis.length);\n\t\t\twritefln !(\"%(%s %)\") (vis.byKey.repeat (n).joiner);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tbool[int] set;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tset[a[i]] = true;\n\t\t}\n\t\tif (set.keys.length > k) continue;\n\n\t\tauto len = (10^^4) / k;\n\t\tans[ti].length = len;\n\t\tauto b = set.keys.dup;\n\t\twhile (b.length < k)\n\t\t\tb ~= 1;\n\t\tforeach (i; 0..len)\n\t\t{\n\t\t\tauto pos = i % k;\n\t\t\tans[ti][i] = b[pos];\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t{\n\t\t\twriteln(e.length);\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tbool[int] set;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tset[a[i]] = true;\n\t\t}\n\t\tif (set.keys.length > k) continue;\n\n\t\tauto len = (10^^4) / k;\n\t\tans[ti].length = len;\n\t\tforeach (i; 0..len)\n\t\t{\n\t\t\tauto pos = i % k;\n\t\t\tans[ti][i] = a[pos];\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t{\n\t\t\twriteln(e.length);\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tbool[int] set;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tset[a[i]] = true;\n\t\t}\n\t\tif (set.keys.length > k) continue;\n\n\t\tauto len = (10^^4) / k;\n\t\tans[ti].length = len;\n\t\tauto keys = set.keys;\n\t\tforeach (i; 0..len)\n\t\t{\n\t\t\tauto pos = i % keys.length;\n\t\t\tans[ti][i] = keys[pos];\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t{\n\t\t\twriteln(e.length);\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tans[ti] = a.dup;\n\t\tint i = k;\n\t\twhile (i < ans[ti].length)\n\t\t{\n\t\t\tif (ans[ti][i] == ans[ti][i-k])\n\t\t\t{\n\t\t\t\t++i;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tbool ok;\n\t\t\tforeach (j; i-k..i)\n\t\t\t{\n\t\t\t\tif (ans[ti][j] == ans[ti][i])\n\t\t\t\t{\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t{\n\t\t\t\tans[ti] = ans[ti][0..i] ~ ans[ti][i-k] ~ ans[ti][i..$];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans[ti].length = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++i;\n\t\t\tdebug writeln(ans[ti]);\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t{\n\t\t\twriteln(e.length);\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "80d4b2d01215b12ebd89b8ee2d1ac6ed"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n const A = readToken();\n \n auto b = new char[N];\n foreach (i; 0 .. N) {\n b[i] = A[i % K];\n }\n if (A > b) {\n b[K - 1] += 1;\n foreach_reverse (i; 0 .. K) {\n if (b[i] > '9') {\n b[i] -= 10;\n b[i - 1] += 1;\n }\n }\n foreach (i; K .. N) {\n b[i] = b[i % K];\n }\n }\n writeln(N);\n writeln(b);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto s = readln.chomp;\n \n dchar[] ans;\n foreach (i; 0 .. n) { ans ~= s[i % k]; }\n \n debug { ans.writeln; }\n \n foreach (i; k .. n) {\n if (ans[i] > s[i]) { break; }\n if (ans[i] < s[i]) {\n int start = k-1;\n while (s[start] == '9') { --start; }\n foreach (j; n.iota.drop(start).stride(k)) { ans[j] = s[start] + 1; }\n foreach (nxt; start + 1 .. k) {\n foreach (j; n.iota.drop(nxt).stride(k)) { ans[j] = '0'; }\n }\n break;\n }\n }\n \n ans.length.writeln;\n ans.writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto s = readln.chomp;\n \n dchar[] ans;\n foreach (i; 0 .. n) { ans ~= s[i % k]; }\n \n debug { ans.writeln; }\n \n foreach (i; k .. n) {\n if (ans[i] > s[i]) { break; }\n if (ans[i] < s[i]) {\n int start = k-1;\n while (s[start] == '9') { --start; }\n foreach (j; n.iota.drop(start).stride(k)) { ans[j] = s[i]; }\n break;\n }\n }\n \n ans.length.writeln;\n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto s = readln.chomp;\n \n dchar[] ans;\n foreach (i; 0 .. n) { ans ~= s[i % k]; }\n \n debug { ans.writeln; }\n \n foreach (i; k .. n) {\n if (ans[i] > s[i]) { break; }\n if (ans[i] < s[i]) {\n int start = k-1;\n while (s[start] == '9') { --start; }\n foreach (j; n.iota.drop(start).stride(k)) { ans[j] = s[start] + 1; }\n break;\n }\n }\n \n ans.length.writeln;\n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto s = readln.chomp;\n \n dchar[] ans;\n foreach (i; 0 .. n) { ans ~= s[i % k]; }\n \n debug { ans.writeln; }\n \n foreach (i; k .. n) {\n if (ans[i] > s[i]) { break; }\n if (ans[i] < s[i]) {\n int start = k-1;\n while (s[start] == '9') { --start; }\n foreach (j; n.iota.drop(start).stride(k)) { ans[j] = s[i]; }\n break;\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n const A = readToken();\n \n auto b = new char[N];\n foreach (i; 0 .. N) {\n b[i] = A[i % K];\n }\n if (A > b) {\n b[K - 1] += 1;\n foreach_reverse (i; 0 .. K) {\n if (b[i] > '9') {\n b[i] -= 10;\n b[i - 1] += 1;\n }\n }\n foreach (i; K .. N) {\n b[i] = b[i % K];\n }\n }\n writeln(b);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "646b898ae6b801f7403ad0e9984c88f6"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1] + 2;\n string[] A;\n bool ok = false;\n foreach (i; 0..N) {\n auto t = readln.chomp;\n if (!ok && t.map!(tt => tt == '0').all) continue;\n ok = true;\n A ~= t;\n }\n N = A.length.to!int;\n A.reverse();\n\n int[] L = new int[](N);\n int[] R = new int[](N);\n foreach (i; 0..N) {\n L[i] = M-1, R[i] = 0;\n foreach (j; 0..M) {\n if (A[i][j] == '1') {\n L[i] = min(L[i], j);\n R[i] = max(R[i], j);\n }\n }\n }\n\n if (N == 0) {\n writeln(0);\n return;\n } else if (N == 1) {\n writeln(R[0]);\n return;\n }\n\n auto dp = new int[][](N, 2);\n\n dp[0][0] = R[0] * 2;\n dp[0][1] = M - 1;\n\n foreach (i; 1..N-1) {\n dp[i][0] = min(dp[i-1][0] + R[i] * 2 + 1, dp[i-1][1] + M);\n dp[i][1] = min(dp[i-1][1] + (M - L[i] - 1) * 2 + 1, dp[i-1][0] + M);\n }\n\n int ans = min(dp[N-2][0] + R[N-1] + 1, dp[N-2][1] + (M - L[N-1] - 1) + 1);\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n Tuple!(int, int)[] floors;\n foreach (_; 0 .. n) {\n auto s = readln.chomp;\n if (s.all!(x => x == '0')) floors ~= tuple(m+1, 0);\n else {\n auto le = s.countUntil!(x => x == '1').to!int;\n auto r = m+1 - s.retro.countUntil!(x => x == '1').to!int;\n floors ~= tuple(le, r);\n }\n }\n \n debug { floors.writeln; }\n \n auto ansle = 0, ansr = 0;\n foreach (t; floors) {\n auto le = t[0], r = t[1];\n auto nowansle = r + (ansle > 0 ? 1 + min(r + ansle, m+1 - r + ansr) : 0);\n auto nowansr = m+1 - le + (ansle > 0 ? 1 + min(le + ansle, m+1 - le + ansr) : 0);\n \n ansle = nowansle, ansr = nowansr;\n debug { writeln(ansle, ' ', ansr); }\n }\n \n ansle.writeln;\n}"}], "negative_code": [], "src_uid": "55070f8e5dba8a6ec669a53a169e557d"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MOD = 1_000_000_007;\nimmutable string LETTERS = \"ACGT\";\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tstring s = readln ().strip ();\n\t\tint [] a;\n\t\tint m;\n\t\tforeach (c; LETTERS)\n\t\t{\n\t\t\ta ~= s.count (c);\n\t\t\tm = max (m, a[$ - 1]);\n\t\t}\n\t\tstring t;\n\t\tforeach (i; 0..LETTERS.length)\n\t\t{\n\t\t\tif (a[i] == m)\n\t\t\t{\n\t\t\t\tt ~= LETTERS[i];\n\t\t\t}\n\t\t}\n\n\t\tlong res = 1;\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tres = (res * t.length) % MOD;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\nimmutable int MD = 10 ^^ 9 + 7;\n\nvoid main()\n{\n readln;\n \n auto s = readln.chomp;\n \n int [char] cnt;\n s.each!(c => ++cnt[c]);\n \n auto mx = cnt.values.maxCount[1];\n \n debug { mx.writeln; }\n \n int ans = 1;\n foreach (_; 0 .. s.length) ans = ans.to!long * mx % MD;\n ans.writeln;\n}"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable long MO = 10^^9 + 7;\n\nint N;\nstring S;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tS = readToken;\n\t\t\n\t\tint[] cnt = new int[26];\n\t\tforeach (s; S) {\n\t\t\t++cnt[s - 'A'];\n\t\t}\n\t\t\n\t\tconst num = cnt.count(cnt.reduce!max);\n\t\tlong ans = 1;\n\t\tforeach (i; 0 .. N) {\n\t\t\t(ans *= num) %= MO;\n\t\t}\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "f35c042f23747988f65c5b5e8d5ddacd"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;\nimport std.typecons, std.functional, std.traits,std.concurrency;\nimport std.algorithm, std.container;\nimport core.bitop, core.time, core.memory;\nimport std.datetime;\nimport std.bitmanip;\nimport std.regex;\n\nvoid main()\n{\n auto N = scanElem;\n foreach(e;scanElem!(long,long)(N))\n {\n auto a = e[0];\n auto b = e[1];\n auto n = b.to!string.length;\n if(b.to!string.any!\"a!='9'\")n--;\n writeln(a*n);\n }\n}\n\n//\u8f9e\u66f8\u9806\u9806\u5217\u306fiota(1,N),nextPermituion\u3092\u4f7f\u3046\n\nenum INF = long.max/3;\nenum MOD = 10^^9+7;\n\nT binarySearch(alias F, T)(T ok, T ng, long iter=100)\n{\n alias FF = unaryFun!F;\n foreach(_;0..iter)\n {\n auto n = (ok+ng)/2;\n if(FF(n)){\n ok = n;\n }else{\n ng = n;\n }\n static if(isIntegral!T){\n if(abs(ok-ng)==1)return ok;\n }\n }\n return ok;\n}\n\n//\u6700\u5c0f\u3092\u8fd4\u3059\nreal ternarySearch(alias F)(real l, real r, long iter=200)\n{\n alias FF = unaryFun!F;\n foreach(_;0..iter)\n {\n auto nl = lerp(l, r, 1/real(3));\n auto nr = lerp(l, r, 2/real(3));\n if(FF(nl)<FF(nr)){\n r = nr;\n }else{\n l = nl;\n }\n }\n return FF(l);\n}\nlong ternarySearch(alias F)(long l, long r, long iter=200)\n{\n alias FF = unaryFun!F;\n foreach(_;0..iter)\n {\n auto nl = lerp(l, r, 1/real(3)).to!long;\n auto nr = lerp(l, r, 2/real(3)).to!long;\n if(nl>11)debugPrint!(l,r,nl,nr,()=>FF(nl),()=>FF(nr));\n if(FF(nl)<FF(nr)){\n r = nr;\n }else{\n l = nl;\n }\n if(r-l<4)break;\n }\n long res=INF;\n foreach(i;l..r+1)\n {\n debugPrint!(l, r, i, ()=>FF(i));\n res = min(FF(i), res);\n }\n return res;\n}\n\nCommonType!(A,B,T) lerp(A,B,T)(A a, B b, T t) pure\n{\n alias C = CommonType!(A,B,T);\n return (C(b)-a)*t+a;\n}\n\nstruct Vector{\n real x, y;\n\n real magnitude()pure\n {\n return sqrt(sqrMagnitude);\n }\n real sqrMagnitude()pure\n {\n return x*x+y*y;\n }\n\n Vector opBinary(string op, T)(inout T v)\n if(isNumeric!T)\n {\n return Vector(mixin(\"x\"~op~\"v\"), mixin(\"y\"~op~\"v\"));\n }\n Vector opBinary(string op)(inout Vector v)\n {\n return Vector(mixin(\"x\"~op~\"v.x\"), mixin(\"y\"~op~\"v.y\"));\n }\n void opOpAssign(string op, T)(inout T v)\n {\n this = mixin(\"this\"~op~\"v\");\n }\n\n static Vector lerp(Vector a, Vector b, real t)pure\n {\n return (b-a)*t+a;\n }\n static Vector normalized(Vector a)pure\n {\n auto r = a.magnitude();\n return Vector(a.x / r, a.y / r);\n }\n static real distance(Vector a, Vector b)pure\n {\n return (a-b).magnitude;\n }\n static real dot(Vector a, Vector b)pure\n {\n return a.x*b.x+a.y*b.y;\n }\n static real cross(Vector a, Vector b)pure\n {\n return a.x*b.y-b.x*a.y;\n }\n}\n\n//ascii\u6587\u5b57\u306e\u307f\nlong[] suffixArray(Char)(const(Char)[] s) pure\nif(isSomeChar!Char)\n// in{assert(s.all!\"0<=a&&a<127\");}\n// do\n{\n s ~= '\\0';\n long[] p = new long[s.length];\n long[] c = new long[s.length];\n {\n long[127] cnt;\n foreach(i;0..s.length)cnt[s[i]]++;\n foreach(i;1..cnt.length)cnt[i] += cnt[i-1];\n foreach(i;0..s.length)p[--cnt[s[i]]] = i;\n long classes=1;\n foreach(i;1..p.length){\n classes += s[p[i]]!=s[p[i-1]]?1:0;\n c[p[i]] = classes-1;\n }\n }\n long[] pn = new long[s.length];\n long[] cn = new long[s.length];\n for(long n=0;(1L<<n) < s.length;n++)\n {\n p.map!(a=>mod(a-(1L<<n), s.length)).copy(pn);\n long[127] cnt;\n foreach(i;0..pn.length)cnt[c[pn[i]]]++;\n foreach(i;1..cnt.length)cnt[i] += cnt[i-1];\n foreach_reverse(i;0..pn.length)p[--cnt[c[pn[i]]]] = pn[i];\n long classes=1;\n for(long i=1;i<c.length;i++)\n {\n if(\n tuple(c[p[i]], c[(p[i]+(1L<<n))%s.length]) !=\n tuple(c[p[i-1]], c[(p[i-1]+(1L<<n))%s.length])\n ) {\n classes++;\n }\n cn[p[i]] = classes - 1;\n }\n cn.copy(c);\n }\n return p[1..$];\n}\n\nstruct BiparticeMatching{\n int N;\n int[][] path;\n int[] match;\n this(long n)\n {\n N = n.to!int;\n path.length = N;\n match.length = N;\n }\n void addEdge(long u, long v){\n addEdge(u.to!int, v.to!int);\n }\n void addEdge(int u, int v){\n path[u] ~= v;\n path[v] ~= u;\n }\n long calc(){\n auto used = new bool[N];\n bool dfs(int v){\n used[v] = true;\n foreach(u; path[v]){\n int w = match[u];\n if(w==-1||(!used[w]&&dfs(w))){\n match[v]=u;\n match[u]=v;\n return true;\n }\n }\n return false;\n }\n match[] = -1;\n long res = 0;\n foreach(int v; 0..N){\n if(match[v] == -1){\n used[] = false;\n if(dfs(v)){\n res++;\n }\n }\n }\n return res;\n }\n}\n\n\n// int max_flow(int s, int t){\n// struct edge{\n// int to, cap, rev; \n// }\n// edge[][MAX_V] G;\n// bool[MAX_V] used;\n// void add_edge(int from, int to, int cap){\n// G[from] ~= edge(to, cap, G[to].length);\n// G[to] ~= edge(from, 0, G[from].length-1);\n// }\n// int dfs(int v, int t, int f)\n// {\n// if(v==t)return f;\n// used[v] = true;\n// foreach(i;0..G[v].length)\n// {\n// edge e = G[v][i];\n// if(!used[e.to] && e.cap > 0){\n// int d = dfs(e.to, t, min(f, e.cap));\n// if(d>0){\n// e.cap -= d;\n// G[e.to][e.rev].cap +=d ;\n// return d;\n// }\n// }\n// }\n// return 0;\n// }\n// int flow = 0;\n// for(;;){\n// int f = dfs(s,t,INF);\n// if(f==0)return flow;\n// flow += f;\n// }\n// }\n\nstruct CombTable2(long MOD)\n{\n static long[] fac;\n static long[] finv;\n static long[] inv;\n this(long n)\n {\n fac = new long[n];\n finv = new long[n];\n inv = new long[n];\n\n fac[0] = fac[1] = 1;\n finv[0] = finv[1] = 1;\n inv[1] = 1;\n foreach(i;2..n){\n fac[i] = fac[i - 1] * i % MOD;\n inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;\n finv[i] = finv[i - 1] * inv[i] % MOD;\n }\n }\n\n long comb(long n, long k)\n {\n if (n < k) return 0;\n if (n < 0 || k < 0) return 0;\n return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;\n }\n}\nstruct CombTable(long MOD, long n)\n{\n static long[n] fac;\n static long[n] finv;\n static long[n] inv;\n static this()\n {\n fac[0] = fac[1] = 1;\n finv[0] = finv[1] = 1;\n inv[1] = 1;\n foreach(i;2..n){\n fac[i] = fac[i - 1] * i % MOD;\n inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;\n finv[i] = finv[i - 1] * inv[i] % MOD;\n }\n }\n\n static long comb(long n, long k)\n {\n if (n < k) return 0;\n if (n < 0 || k < 0) return 0;\n return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;\n }\n}\n\nvoid outLine(List...)(List list)\n{\n foreach(i, v;list)\n {\n static if(isFloatingPoint!(typeof(v)))\n {\n writef(\"%.12f\", v);\n }else{\n write(v);\n }\n if(i+1!=list.length)write(' ');\n }\n writeln;\n}\n\nvoid end(List...)(List list)\n{\n outLine(list);\n end;\n}\nvoid end()\n{\n import core.stdc.stdlib;\n exit(0);\n}\n\nlong sequenceSum(long n) pure\n{\n return n*(n+1)/2;\n}\n\n//HL\u5206\u89e3\nstruct HeavyLightDecomposition\n{\n immutable int root = 1;\n\n int[][] edge;\n int[] vid;\n int[] invid;\n int[] parent;\n int[] depth;\n int[] subCount;\n int[] head;\n\n this(long n, long root = 1)\n {\n this(n.to!int, root.to!int);\n }\n this(int n, int root = 1)\n {\n this.root = root;\n n++;\n edge.length = n;\n vid.length = n;\n invid.length = n;\n parent.length = n; parent[] = -1;\n depth.length = n;\n head.length = n; head[root] = root;\n subCount.length = n; subCount[] = 1;\n }\n\n void addEdge(long u, long v)\n {\n addEdge(u.to!int, v.to!int);\n }\n void addEdge(int u, int v)\n {\n edge[u] ~= v;\n edge[v] ~= u;\n }\n\n void build()\n {\n void dfs(int v){\n foreach(ref u; edge[v])\n {\n if(u==parent[v]) continue;\n parent[u] = v;\n depth[u] = depth[v] + 1;\n dfs(u);\n subCount[v] += subCount[u];\n if(edge[v][0]==parent[v]||subCount[u]>subCount[edge[v][0]])\n swap(u, edge[v][0]);\n }\n }\n void dfsHead(int v, ref int pos){\n invid[pos] = v;\n vid[v] = pos;\n pos++;\n foreach(ref u; edge[v])\n {\n if(u==parent[v]) continue;\n\n head[u] = u == edge[v][0] ? head[v] : u;\n dfsHead(u, pos);\n }\n }\n dfs(root);\n int pos;\n dfsHead(root, pos);\n }\n\n long lca(long u, long v)\n {\n return lca(u.to!int, v.to!int);\n }\n int lca(int u, int v)\n {\n while(true){\n if(vid[u]>vid[v]) swap(u,v);\n if(head[u]==head[v]) return u;\n v = parent[head[v]];\n }\n }\n\n long distance(long u, long v) { return distance(u.to!int, v.to!int); }\n long distance(int u, int v) { return depth[u] + depth[v] - 2 * depth[lca(u,v)]; }\n\n //idx\u306en\u500b\u4e0a\u306e\u89aa\u3092\u8fd4\u3059\n //\u30d0\u30b0\u3042\u308b\u304b\u3082\n long nParent(long n, long idx){\n return nParent(n.to!int, idx.to!int);\n }\n int nParent(int n, int idx){\n auto u = 0;\n auto v = idx;\n while(true)\n {\n if(vid[u]>vid[v]) swap(u,v);\n\n immutable _u = max(vid[head[v]], vid[u]);\n immutable _v = vid[v] + 1;\n if(_v<=_u+n){\n n -= _v-_u;\n }else{\n return invid[_v-n-1];\n }\n\n if(head[u]==head[v]) return -1;\n v = parent[head[v]];\n }\n }\n\n void each(long u, long v, void delegate(long u, long v) pred)\n {\n each(u.to!int, v.to!int, pred);\n }\n void each(int u, int v, void delegate(int u, int v) pred)\n {\n while(true)\n {\n if(vid[u]>vid[v]) swap(u,v);\n pred(max(vid[head[v]], vid[u]), vid[v] + 1);\n if(head[u]==head[v]) return;\n v = parent[head[v]];\n }\n }\n\n void each(alias pred)(long u, long v)\n if(is(typeof(binaryFun!pred(0L,0L))))\n {\n while(true)\n {\n if(vid[u]>vid[v]) swap(u,v);\n binaryFun!pred(max(vid[head[v]], vid[u]), vid[v] + 1);\n if(head[u]==head[v]) return;\n v = parent[head[v]];\n }\n }\n}\n\n// struct HLD{\n\n// long[][] G;\n// long[] vid, head, sub, par, dep, inv, type;\n\n// void dfs_sz(long v) {\n// foreach(ref u; G[v])\n// if(u==par[v]) swap(u,G[v].back());\n// if(~par[v]) G[v].popBack;\n\n// foreach(ref u; G[v]){\n// par[u]=v;\n// dep[u]=dep[v]+1;\n// dfs_sz(u);\n// sub[v]+=sub[u];\n// if(sub[u]>sub[G[v][0]]) swap(u,G[v][0]);\n// }\n// }\n\n// void dfs_hld(long v,long c,ref long pos) {\n// vid[v]=pos++;\n// inv[vid[v]]=v;\n// type[v]=c;\n// foreach(u; G[v]){\n// if(u==par[v]) continue;\n// head[u]=(u==G[v][0]?head[v]:u);\n// dfs_hld(u,c,pos);\n// }\n// }\n\n// this(long n){\n// G = new long[][n];\n// vid = new long[n]; vid[] = -1;\n// head = new long[n];\n// sub = new long[n]; sub[] = 1;\n// par = new long[n]; par[] = -1;\n// dep = new long[n];\n// inv = new long[n];\n// type = new long[n];\n// }\n\n// void add_edge(long u,long v) {\n// G[u] ~= v;\n// G[v] ~= u;\n// }\n\n// void build(long[] rs = [0]) {\n// long c=0,pos=0;\n// foreach(r; rs){\n// dfs_sz(r);\n// head[r]=r;\n// dfs_hld(r,c++,pos);\n// }\n// }\n\n// long lca(long u,long v){\n// while(1){\n// if(vid[u]>vid[v]) swap(u,v);\n// if(head[u]==head[v]) return u;\n// v=par[head[v]];\n// }\n// }\n\n// long distance(long u,long v){\n// return dep[u]+dep[v]-2*dep[lca(u,v)];\n// }\n\n// // for_each(vertex)\n// // [l, r) <- attention!!\n// void for_each(F)(long u, long v, F f) {\n// while(1){\n// if(vid[u]>vid[v]) swap(u,v);\n// f(max(vid[head[v]],vid[u]),vid[v]+1);\n// if(head[u]!=head[v]) v=par[head[v]];\n// else break;\n// }\n// }\n\n// T for_each(T, Q, F)(long u,long v,T ti,Q q,F f)\n// {\n// T l=ti,r=ti;\n// while(1){\n// if(vid[u]>vid[v]){\n// swap(u,v);\n// swap(l,r);\n// }\n// l=f(l,q(max(vid[head[v]],vid[u]),vid[v]+1));\n// if(head[u]!=head[v]) v=par[head[v]];\n// else break;\n// }\n// return f(l,r);\n// }\n\n// // for_each(edge)\n// // [l, r) <- attention!!\n// void for_each_edge(F)(long u, long v,F f) {\n// while(1){\n// if(vid[u]>vid[v]) swap(u,v);\n// if(head[u]!=head[v]){\n// f(vid[head[v]],vid[v]+1);\n// v=par[head[v]];\n// }else{\n// if(u!=v) f(vid[u]+1,vid[v]+1);\n// break;\n// }\n// }\n// }\n// }\n\nstruct SegTree(T, T UNIT, alias pred){\n int n;\n long size;\n T* arr;\n alias F = binaryFun!pred;\n\n this(long size)\n {\n this.size = size;\n n=1;\n while(n<size) n<<=1;\n arr = new T[n<<1].ptr;\n arr[0..n<<1] = UNIT;\n }\n\n void set(long k,T x)\n {\n assert(k>=0&&k<size);\n\n arr[k+=n]=x;\n while(k>>=1)\n arr[k]=F(arr[(k<<1)|0],arr[(k<<1)|1]);\n }\n\n T query(long a, long b)\n {\n assert(a>=0&&a<size);\n assert(b>=1&&b<=size);\n\n T vl=UNIT,vr=UNIT;\n for(long l=a+n,r=b+n;l<r;l>>=1,r>>=1)\n {\n if(l&1) vl=F(vl,arr[l++]);\n if(r&1) vr=F(arr[--r],vr);\n }\n return F(vl,vr);\n }\n}\n\nbool isInf(Num)(Num v) pure @nogc\nif(isIntegral!Num)\n{\n return v>=INF/2;\n}\n\nUnqual!M mod(N,M)(N n, M mod) pure @nogc\nif(isIntegral!N&&isIntegral!M)\n{\n return (n%mod+mod)%mod;\n}\n\nlong pow(long a, long n) {\n long res = 1;\n while (n > 0) {\n if (n & 1) res = res * a;\n a = a * a;\n n >>= 1;\n }\n return res;\n}\n\nUnqual!M powmod(A,N,M)(A _a, N _n, M mod)\n{\n Unqual!A a = _a;\n Unqual!N n = _n;\n M res = 1;\n while (n > 0) {\n if (n & 1) res = res * a % mod;\n a = a * a % mod;\n n >>= 1;\n }\n return res;\n}\n\nalias MInt = ModInt!MOD;\n\nstruct ModInt(alias Mod)\nif(isIntegral!(typeof(Mod)) && isPrime(Mod))\n{\n int value;\n\n this(ModInt!Mod v)\n {\n value = v.value;\n }\n this(T)(T v)\n if(isIntegral!T)\n {\n value = mod(v, Mod);\n }\n\n ModInt!Mod opBinaryRight(string op, T)(inout T v) const\n if((op==\"+\"||op==\"-\"||op==\"*\")&&isIntegral!T)\n {\n return typeof(this)(mixin(\"v\"~op~\"value\"));\n }\n ModInt!Mod opBinary(string op, T)(inout T v) const\n if((op==\"+\"||op==\"-\"||op==\"*\")&&(is(T==ModInt!Mod)||isIntegral!T))\n {\n return typeof(this)(mixin(\"value\"~op~\"v\"));\n }\n\n ModInt!Mod opBinaryRight(string op, T)(inout T v) const\n if((op==\"/\")&&isIntegral!T)\n {\n return v * (this^^(Mod-2));\n }\n ModInt!Mod opBinary(string op, T)(inout T v) const\n if((op==\"/\")&&(is(T==ModInt!Mod)||isIntegral!T))\n {\n return this * (typeof(this)(v)^^(Mod-2));\n }\n\n ModInt!Mod opBinary(string op, T)(inout T v) const\n if((op==\"^^\")&&isIntegral!T)\n {\n return typeof(this)(powmod(value, v, Mod));\n }\n\n void opAssign(T)(inout T v)\n if(isIntegral!T)\n {\n this = typeof(this)(v);\n }\n\n void opOpAssign(string op, T)(inout T v)\n {\n this = mixin(\"this\"~op~\"v\");\n }\n\n bool opEquals(T)(const T v) const\n if(is(T==ModInt!Mod)||isIntegral!T)\n {\n return value == typeof(this)(v).value;\n }\n\n long opCast() const {\n return value;\n }\n\n string toString() const {\n return value.to!string;\n }\n}\nunittest\n{\n assert(is(ModInt!MOD));\n assert(is(ModInt!17));\n assert(!is(ModInt!0));\n assert(!is(ModInt!10));\n}\n\nunittest\n{\n alias MInt = ModInt!13;\n MInt value;\n value = MInt(14) + MInt(18);\n assert(value==6);\n value = 14 - MInt(28);\n assert(value==12);\n value = MInt(17) * -19;\n assert(value==2);\n\n value = MInt(7) / 4;\n assert(value==5);\n value = 8 / MInt(4);\n assert(value==2);\n value = 9;\n value /= 4;\n assert(value==12);\n\n assert(MInt(3) ^^ 9 == 1);\n\n value = 29-MInt(16);\n assert(value==0);\n value = MInt(13)*5;\n assert(value==0);\n value = 0;\n assert(value==0);\n\n value = 3;\n value += MInt(11);\n assert(value==1);\n value -= 7;\n assert(value==7);\n value *= MInt(4);\n assert(value==2);\n value = 23;\n assert(value == cast(long)value);\n}\nunittest\n{\n ModInt!MOD value;\n value = MOD-1;\n assert(value==MOD-1);\n value = MOD;\n assert(value==0);\n}\n\nstruct Grid(T){\n private T[] grid;\n size_t width, height;\n private size_t stride;\n\n private this(T[] g, size_t w, size_t h, size_t s)\n {\n grid = g;\n width = w;\n height = h;\n stride = s;\n }\n\n this(long w, long h, T init = T.init)\n {\n auto arr = new T[(w*h).to!int];\n arr[] = init;\n this(arr, w.to!size_t, h.to!size_t, w.to!size_t);\n }\n\n // void fill(T elem){\n // grid[] = elem;\n // }\n\n bool isInRange(long x, long y) const nothrow\n {\n return \n x>=0 &&\n x<width &&\n y>=0 &&\n y<height;\n }\n \n int opApply(scope int delegate(ref T) dg)\n {\n int result = 0;\n\n foreach(y;0..height)\n foreach(x;0..width)\n {\n result = dg(this[x,y]);\n if (result)\n break;\n }\n return result;\n }\n int opApply(scope int delegate(long i, ref T) dg)\n {\n int result = 0;\n\n long idx;\n foreach(y;0..height)\n foreach(x;0..width)\n {\n result = dg(idx++, this[x,y]);\n if (result)\n break;\n }\n return result;\n }\n int opApply(scope int delegate(long x, long y, ref T) dg)\n {\n int result = 0;\n\n foreach(y;0..height)\n foreach(x;0..width)\n {\n result = dg(x, y, this[x,y]);\n if (result)\n break;\n }\n return result;\n }\n\n ref T opIndex(long x, long y)\n {\n assert(isInRange(x,y));\n return (grid.ptr)[(x+stride*y).to!size_t];\n }\n\n Grid!T opIndex(long[2] r1, long[2] r2)\n {\n auto startOffset = (r1[0] + r2[0]*stride).to!size_t;\n auto endOffset = (r1[1] + (r2[1] - 1)*stride).to!size_t;\n\n auto resGrid = grid[startOffset .. endOffset];\n auto resStride = stride;\n auto resWidth = (r1[1] - r1[0]).to!size_t;\n auto resHeight = (r2[1] - r2[0]).to!size_t;\n return Grid!T(resGrid, resWidth, resHeight, resStride);\n }\n \n Grid!T opIndex(long[2] r1, long j) { return opIndex(r1, [j, j+1]); }\n Grid!T opIndex(long i, long[2] r2) { return opIndex([i, i+1], r2); }\n\n long[2] opSlice(long dim)(long start, long end)\n if (dim == 0 || dim == 1)\n // in { assert(start >= 0 && end <= this.opDollar!dim); }\n body{\n return [start, end];\n }\n\n Grid!T transpose(){\n auto grid = Grid!T(height, width);\n\n foreach(w; 0..width)\n foreach(h; 0..height)\n {\n grid[h, w] = this[w, h];\n }\n return grid;\n }\n\n long opDollar(long dim : 0)() const { return width; }\n long opDollar(long dim : 1)() const { return height; }\n\n string toString() pure {\n long count;\n foreach(y; 0..height)\n {\n foreach(x; 0..width)\n {\n long eCount = this[x, y].to!string.length;\n static if(is(typeof(this[x,y].isInf)))\n {\n if(this[x,y].isInf)\n {\n eCount = 1;\n }\n }\n static if(is(typeof(this[x,y])==bool))\n {\n eCount = 1;\n }\n count = max(count, eCount);\n }\n }\n count++;\n\n string res = \"\\n\";\n foreach(y; 0..height)\n {\n foreach(x; 0..width)\n {\n string joinStr = this[x, y].to!string;\n static if(is(typeof(this[x,y].isInf)))\n {\n if(this[x,y].isInf)\n {\n joinStr = \"*\";\n }\n }\n static if(is(typeof(this[x,y])==bool))\n {\n joinStr = this[x,y]?\"+\":\"-\";\n }\n foreach(i;0..count-joinStr.length)\n {\n res ~= ' ';\n }\n res ~= joinStr;\n }\n res ~= '\\n';\n }\n return res;\n }\n}\n\nstruct UnionFind{\n private int[] arr;\n int rootCount;\n\n @disable this();\n this(long n){\n arr.length = n.to!int;\n arr[] = -1;\n rootCount = n.to!int;\n }\n\n void merge(long a, long b)\n {\n merge(a.to!int, b.to!int);\n }\n void merge(int a, int b)\n {\n if(same(a,b)) return;\n arr[root(a)] = root(b);\n rootCount--;\n }\n\n bool same(long a, long b)\n {\n return same(a.to!int, b.to!int);\n }\n bool same(int a, int b)\n {\n return root(a)==root(b);\n }\n\n private int root(int i)\n {\n if(arr[i] == -1) return i;\n return arr[i] = root(arr[i]);\n }\n}\n\nunittest{\n assert(is(typeof(UnionFind(10))));\n assert(!is(typeof(UnionFind())));\n\n auto uf = UnionFind(10);\n uf.merge(2,3);\n assert(uf.same(2,3));\n uf.merge(3,4);\n uf.merge(1,5);\n uf.merge(5,6);\n uf.merge(6,7);\n assert(!uf.same(4,7));\n uf.merge(1,2);\n assert(uf.same(4,7));\n}\n\nvoid debugPrint(List...)()\n{\n void _debugPrintElem(alias elem, float rad)()\n {\n import std.experimental.color;\n import std.experimental.color.lab;\n import std.experimental.color.rgb;\n import std.experimental.color.xyz;\n\n enum color = LCh!float(80f, 100f, rad);\n enum rgb = color.convertColor!(Lab!float).convertColor!(XYZ!float).convertColor!(RGB8).tristimulus;\n enum r = rgb[0].value;\n enum g = rgb[1].value;\n enum b = rgb[2].value;\n\n stderr.writef!\"\\033[38;2;%s;%s;%sm\"(r, g, b);\n static if(isSomeFunction!elem)\n {\n stderr.write(\"elem: \", elem(), \" \");\n }else{\n enum name = __traits(identifier, elem);\n stderr.write(name, \": \");\n stderr.write(elem, \" \");\n }\n }\n void _debugPrint(int i, float rad, List...)()\n {\n _debugPrintElem!(List[0], i * rad)();\n static if(List.length>1)\n {\n _debugPrint!(i+1, rad, List[1..$])();\n }\n }\n\n debug(Local)\n {\n _debugPrint!(0, 360f/List.length, List)();\n stderr.writeln(\"\\033[0m\");\n }\n}\n\n\nstruct Stack(Elem){\n private Elem[] array;\n private size_t endIdx;\n\n void insertBack(Elem e)\n {\n if(endIdx==array.length){\n array.length = array.length*2+10;\n }\n (array.ptr)[endIdx++] = e;\n }\n\n void insertBack(Range)(Range range)\n if(is(typeof(array[0] = range.popFront)))\n {\n if(endIdx+range.length>array.length){\n array.length = (endIdx+range.length)*2+10;\n }\n foreach(ref e;range)\n {\n (array.ptr)[endIdx++] = e;\n }\n }\n\n Elem[] opSlice(){\n return array[0..endIdx];\n }\n\n void popBack()\n {\n assert(endIdx!=0);\n endIdx--;\n }\n\n ref Elem back()\n {\n assert(endIdx!=0);\n return (array.ptr)[endIdx-1];\n }\n\n size_t count() const \n {\n return endIdx; \n }\n\n bool empty() const \n {\n return endIdx==0;\n }\n\n void clear()\n {\n endIdx = 0;\n }\n}\n\nGrid!T scanGrid(T=long)(long w, long h, dchar t='.')\n{\n auto grid = Grid!T(w,h);\n foreach(y;0..h)\n {\n foreach(x;0..w)\n {\n grid[x, y] = scanElem!T;\n }\n }\n\n return grid;\n}\n\nGrid!bool scanGridBool(long w, long h, dchar t='.')\n{\n auto grid = Grid!bool(w,h);\n foreach(y;0..h.to!size_t)\n {\n auto line = scanString;\n foreach(x;0..w.to!size_t)\n {\n grid[x, y] = line[x.to!size_t]==t;\n }\n }\n\n return grid;\n}\n\nT[] scanLineArray(T = long)()\n{\n static char[] scanBuf;\n readln(scanBuf);\n return scanBuf.split.to!(T[]);\n}\n\nchar scanChar()\n{\n int c = ' ';\n while (isWhite(c) && c != -1)\n {\n c = getchar;\n }\n return cast(char)c;\n}\n\nT[] scanElem(T=long)(long size)\n{\n T[] list = new T[size.to!size_t];\n foreach(i;0..size.to!size_t)\n {\n list[i] = scanElem!T;\n }\n return list;\n}\n\nT scanElem(T)()\nif(is(T==struct))\n{\n T res;\n foreach(ref field; res.tupleof){\n field = scanElem!(typeof(field));\n }\n return res;\n}\n\nTuple!List[] scanElem(List...)(long size)\n{\n auto list = new Tuple!List[size.to!size_t];\n foreach(i;0..size.to!size_t)\n {\n list[i] = scanElem!List;\n }\n return list;\n}\nTuple!List scanElem(List...)()\n{\n List res;\n foreach(i, e; List){\n res[i] = scanElem!e;\n }\n return tuple(res);\n}\n\nT scanElem(T = long)()\nif(isBasicType!T||isSomeString!T)\n{\n import core.stdc.stdlib;\n static auto scanBuf = appender!(char[])([]);\n\n scanBuf.clear;\n\n int c = ' ';\n while (isWhite(c) && c != -1)\n {\n c = getchar;\n }\n while (!isWhite(c) && c != -1)\n {\n scanBuf ~= cast(char) c;\n c = getchar;\n }\n return scanBuf.data.to!T;\n}\n\nstring scanString(){\n return scanElem!string;\n}\n\nCommonType!(A,B) gcd(A,B)(A a, B b) pure\nif(isIntegral!A&&isIntegral!B)\n{\n if(b==0)return a;\n return gcd(b, a % b);\n}\n\nCommonType!(A,B) lcm(A,B)(A a, B b) pure\nif(isIntegral!A&&isIntegral!B)\n{\n return a / gcd(a, b) * b;\n}\n\nstruct Factor\n{\n long n;\n long c;\n}\n\n//\u7d20\u56e0\u6570\u5206\u89e3\nFactor[] factors(long n) pure\n{\n Factor[] res;\n for (long i = 2; i ^^ 2 <= n; i++)\n {\n if (n % i != 0)\n continue;\n\n long c;\n while (n % i == 0)\n {\n n = n / i;\n c++;\n }\n res ~= Factor(i, c);\n }\n if (n != 1)\n res ~= Factor(n, 1);\n\n return res;\n}\n//\u7d04\u6570\u3092\u3059\u3079\u3066\u5217\u6319\nlong[] divisors(long n) pure\n{\n long[] list;\n void func(Factor[] fs, long n)\n {\n if(fs.empty){\n list ~= n;\n return;\n }\n\n foreach(c; 0..fs[0].c+1)\n {\n func(fs[1..$], n * (fs[0].n ^^ c));\n }\n }\n\n func(factors(n), 1);\n sort(list);\n return list;\n}\n//n\u307e\u3067\u306e\u7d20\u6570\u306e\u30ea\u30b9\u30c8\nlong[] primes(long n) pure\n{\n if(n<2)return [];\n\n auto table = new long[cast(size_t)n+1];\n\n long[] res;\n for(size_t i = 2;i<=n;i++)\n {\n if(table[i]==-1) continue;\n for(size_t a = i;a<table.length;a+=i)\n {\n table[a] = -1;\n }\n res ~= i;\n }\n return res;\n}\n//\u7d20\u6570\u5224\u5b9a\nbool isPrime(long n) pure\n{\n if (n <= 1)\n return false;\n if (n == 2)\n return true;\n if (n % 2 == 0)\n return false;\n for (long i = 3; i ^^ 2 <= n; i += 2)\n if (n % i == 0)\n return false;\n return true;\n}\n\n//\u6841\u3092\u6570\u3048\u308b\nlong digitCount(long n, long base=10) pure\n{\n long res;\n do{\n n/=base;\n res++;\n }while(n!=0);\n\n return res;\n}", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nlong test (in int a, in int b) {\n long res;\n long d = 10;\n while (d - 1 <= b) {\n res += a;\n d *= 10;\n }\n return res;\n}\n\n//a * b + a + b = conc (a, b)\n//a * (b + 1) + b = conc (a, b)\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n auto ans = new long[nt];\n foreach (tid; 0 .. nt) {\n int a = r.next!int;\n int b = r.next!int;\n ans[tid] = test (a, b); \n }\n writefln! (\"%(%s\\n%)\")(ans);\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto A = RD;\n\t\tauto B = RD;\n\t\tauto x = B;\n\t\tlong digit;\n\t\twhile (x != 0)\n\t\t{\n\t\t\tx /= 10;\n\t\t\t++digit;\n\t\t}\n\t\tdebug writeln(B, \":\", 10^^(digit)-1);\n\t\tif (B == 10^^(digit)-1)\n\t\t{\n\t\t\tans[ti] = A * digit;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[ti] = A * (digit-1);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "dc67dd2102c70ea476df642b863ae8d3"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tlong[] xs = rlong(n);\n\t\n\tNode[] nodes;\n\tforeach(i; 0 .. n) nodes ~= new Node(i, xs[i]);\n\t\n\tforeach(i; 0 .. n - 1){\n\t\tint a = rint - 1, b = rint - 1;\n\t\tnodes[a].nodes ~= nodes[b];\n\t\tnodes[b].nodes ~= nodes[a];\n\t}\n\t\n\tnodes[0].treefy(null);\n\t\n\tFinite ans = nodes[0].calc;\n\t\n\tans.writeln;\n}\n/*\nTree DP.\n\n*/\nclass Node{\n\tint id;\n\tstatic long k;\n\tNode[] nodes;\n\tNode[] kids;\n\tNode parent;\n\tbool isVisited;\n\tlong value;\n\tthis(int id, long value){\n\t\tthis.id = id;\n\t\tthis.value = value;\n\t}\n\tvoid treefy(Node parent){\n\t\tthis.parent = parent;\n\t\tforeach(nd; nodes) if(!parent || nd.id != parent.id) this.kids ~= nd, nd.treefy(this);\n\t}\n\tP[] points;\n\tFinite calc(){\n\t\tFinite res = Finite(0);\n\t\tthis.points = [];\n\t\tP[] parpoints = [];\n\t\tif(parent) parpoints = parent.points;\n\t\tforeach(p; parpoints){\n\t\t\tlong d = gcd(p.value, this.value);\n\t\t\tif(points.length && points[$ - 1].value == d){\n\t\t\t\tpoints[$ - 1] = P(d, points[$ - 1].count + p.count);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tpoints ~= P(d, p.count);\n\t\t\t}\n\t\t}\n\t\tpoints ~= P(this.value, 1);\n\t\t\n\t\tforeach(p; this.points){\n\t\t\tres += p.value * p.count;\n\t\t}\n\t\tlog(\"id:\", (id + 1), \"value:\", value, \"points:\", points, \"res:\", res);\n\t\t\n\t\tforeach(kid; kids){\n\t\t\tres += kid.calc();\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\toverride string toString(){\n\t\treturn \"id:\" ~ id.to!string ~ \" value:\" ~ value.to!string ~ \" kids:\" ~ kids.map!(x => x.id).to!string;\n\t}\n}\nstruct P{\n\tlong value, count;\n}\n\n// --------\n\nimport std.conv;\nstruct Finite{\n\tulong value; static ulong mod = 1_000_000_007;\n\tprivate static ulong[] _inv = [0, 1], _frac = [1, 1], _invfrac = [1, 1];\n\tthis(ulong v){ value = v % mod; }\n\tbool opCast(T: bool)(){ return value != 0; }\n\tFinite opUnary(string s){ ulong v;\n\t\tif(s == \"+\") v = value;\n\t\telse if(s == \"-\") v = mod - value;\n\t\telse if(s == \"++\") v = value + 1;\n\t\telse if(s == \"--\") v = value + mod - 1;\n\t\telse assert(0, \"Operator unary \" ~ s ~ \" not implemented\");\n\t\treturn Finite(v);\n\t}\n\tFinite opBinary(string s)(Finite b){\n\t\treturn opBinary!s(b.value);\n\t}\n\tFinite opBinary(string s)(ulong u){ ulong v;\n\t\tif(s == \"+\") v = value + u;\n\t\telse if(s == \"-\") v = value + mod - u;\n\t\telse if(s == \"*\") v = value * u;\n\t\telse if(s == \"/\") v = value * inv(u);\n\t\telse assert(0, \"Operator \" ~ s ~ \" not implemented\");\n\t\treturn Finite(v);\n\t}\n\tFinite opBinaryRight(string s)(ulong u){ ulong v;\n\t\tif(s == \"+\") v = u + value;\n\t\telse if(s == \"-\") v = u + mod - value;\n\t\telse if(s == \"*\") v = u * value;\n\t\telse if(s == \"/\") v = u * invvalue;\n\t\telse assert(0, \"Operator \" ~ s ~ \" not implemented\");\n\t\treturn Finite(v);\n\t}\n\tFinite opAssign(ulong v){ value = v; return this; }\n\tFinite opOpAssign(string s)(Finite b){\n\t\treturn opOpAssign!s(b.value);\n\t}\n\tFinite opOpAssign(string s)(ulong v){\n\t\tif(s == \"+\") value = (value + v) % mod;\n\t\telse if(s == \"-\") value = (value + mod - v) % mod;\n\t\telse if(s == \"*\") value = (value * v) % mod;\n\t\telse if(s == \"/\") value = (value * inv(v)) % mod;\n\t\telse assert(0, \"Operator \" ~ s ~ \"= not implemented\");\n\t\treturn this;\n\t}\n\tbool opEquals(Finite b){\n\t\treturn(value == b.value);\n\t}\n\tstring toString(){ return value.to!string; }\n\tulong inv(ulong v){\n\t\tassert(v > 0);\n\t\tassert(v < mod);\n\t\twhile(v >= _inv.length){\n\t\t\t_inv ~= _inv[mod % $] * (mod - mod / _inv.length) % mod;\n\t\t}\n\t\treturn _inv[v.to!uint];\n\t}\n\tulong invvalue(){\n\t\treturn inv(value);\n\t}\n\tstatic Finite opCall(ulong v){\n\t\treturn Finite(v);\n\t}\n\t\n}\n\n// ----------\n\nlong gcd(long a, long b){ // OK with 0, non-negative\n\tif(a < 0) return gcd(-a, b);\n\tif(b < 0) return gcd(a, -b);\n\tif(a == 0) return b;\n\tif(b == 0) return a;\n\tif(a % b == 0) return b;\n\tif(a < b) return gcd(b, a);\n\telse return gcd(b, a % b);\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(long M) {\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10L^^9 + 7;\nalias Mint = ModInt!MO;\n\nenum E = 17;\n\nint N;\nlong[] X;\nint[] A, B;\n\nint[][] G;\nint[][] par;\n\nvoid dfs(int u, int p) {\n par[0][u] = p;\n foreach (v; G[u]) {\n if (v != p) {\n dfs(v, u);\n }\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n X = new long[N];\n foreach (u; 0 .. N) {\n X[u] = readLong();\n }\n A = new int[N - 1];\n B = new int[N - 1];\n foreach (i; 0 .. N - 1) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n G = new int[][N];\n foreach (i; 0 .. N - 1) {\n G[A[i]] ~= B[i];\n G[B[i]] ~= A[i];\n }\n par = new int[][](E, N + 1);\n dfs(0, N);\n par[0][N] = N;\n foreach (e; 0 .. E - 1) {\n foreach (u; 0 .. N + 1) {\n par[e + 1][u] = par[e][par[e][u]];\n }\n }\n \n auto ds = new long[][](E, N);\n foreach (u; 0 .. N) {\n const v = par[0][u];\n ds[0][u] = (v == N) ? 0 : X[v];\n }\n foreach (e; 0 .. E - 1) {\n foreach (u; 0 .. N) {\n const v = par[e][u];\n ds[e + 1][u] = (v == N) ? ds[e][u] : gcd(ds[e][u], ds[e][v]);\n }\n }\n debug {\n foreach (e; 0 .. 4) {\n writeln(par[e]);\n writeln(ds[e]);\n }\n }\n \n Mint ans;\n foreach (u; 0 .. N) {\n long g = X[u];\n int v = u;\n for (; ; ) {\n long sum;\n foreach_reverse (e; 0 .. E) {\n const w = par[e][v];\n if (w != N) {\n // gcd(g, ds[e][v]) == g\n if ((g == 0) ? (ds[e][v] == 0) : (ds[e][v] % g == 0)) {\n sum |= 1 << e;\n v = w;\n }\n }\n }\n ans += g * Mint(sum + 1);\n v = par[0][v];\n if (v == N) {\n break;\n }\n g = gcd(g, X[v]);\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\n\nimmutable int mod = 10 ^^ 9 + 7;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto x = readln.splitter.map !(to !(long)).array;\n\t\tauto g = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tg[u] ~= v;\n\t\t\tg[v] ~= u;\n\t\t}\n\n\t\tint res = 0;\n\n\t\tvoid recur (int v, int p, int [long] s)\n\t\t{\n\t\t\tint [long] t;\n\t\t\tt[x[v]] = 1;\n\t\t\tforeach (k, w; s)\n\t\t\t{\n\t\t\t\tauto r = gcd (k, x[v]);\n\t\t\t\tt[r] += w;\n\t\t\t}\n\t\t\tforeach (k, w; t)\n\t\t\t{\n\t\t\t\tres = (res + k * w) % mod;\n\t\t\t}\n\t\t\tforeach (u; g[v])\n\t\t\t{\n\t\t\t\tif (u != p)\n\t\t\t\t{\n\t\t\t\t\trecur (u, v, t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0, NA, null);\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.numeric, std.range, std.stdio, std.string;\n\nvoid main () {\n\tauto n = readln.strip.to !(int);\n\tauto x = readln.splitter.map !(to !(long)).array;\n\tauto g = new int [] [n];\n\tforeach (i; 0..n - 1) {\n\t\tint u, v;\n\t\treadf (\" %s %s\", &u, &v);\n\t\tu -= 1;\n\t\tv -= 1;\n\t\tg[u] ~= v;\n\t\tg[v] ~= u;\n\t}\n\n\tint res = 0;\n\n\tvoid recur (int v, int p, int [long] s) {\n\t\tint [long] t;\n\t\tt[x[v]] = 1;\n\t\tforeach (k, w; s) t[gcd (k, x[v])] += w;\n\t\tforeach (k, w; t) res = (res + k * w) % (10 ^^ 9 + 7);\n\t\tforeach (u; g[v]) if (u != p) recur (u, v, t);\n\t}\n\n\trecur (0, -1, null);\n\twriteln (res);\n}\n"}], "negative_code": [], "src_uid": "5179d7554a08d713da7597db41f0ed43"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nbool solve(int[] as) {\n const n = cast(int)(as.length);\n const cnt1 = as.count(1);\n if (cnt1 == 0) {\n return false;\n }\n if (cnt1 == n) {\n return true;\n }\n foreach (i; 0 .. n - 2 + 1) {\n if (as[i] >= 1 && as[i + 1] >= 1) {\n return true;\n }\n }\n foreach (i; 0 .. n - 3 + 1) {\n if (as[i] >= 1 && as[i + 2] >= 1) {\n return true;\n }\n }\n return false;\n}\n\nvoid main() {\n debug {\n enum lim = 8;\n foreach (n; 1 .. lim + 1) {\n auto graph = new int[][3^^n];\n foreach (u; 0 .. 3^^n) {\n auto as = new int[n];\n foreach (i; 0 .. n) {\n as[i] = u / 3^^i % 3;\n }\n foreach (i; 0 .. n) foreach (j; i + 1 .. n + 1) {\n auto bs = as[i .. j].dup;\n bs.sort;\n auto cs = as.dup;\n cs[i .. j] = bs[($ + 1) / 2 - 1];\n int v;\n foreach_reverse (k; 0 .. n) {\n v = v * 3 + cs[k];\n }\n graph[v] ~= u;\n }\n }\n int start;\n foreach_reverse (i; 0 .. n) {\n start = start * 3 + 1;\n }\n DList!int que;\n auto vis = new bool[3^^n];\n vis[start] = true;\n que ~= start;\n for (; !que.empty; ) {\n const u = que.front;\n que.removeFront;\n foreach (v; graph[u]) {\n if (!vis[v]) {\n vis[v] = true;\n que ~= v;\n }\n }\n }\n foreach (u; 0 .. 3^^n) {\n auto as= new int[n];\n foreach (i; 0 .. n) {\n as[i] = u / 3^^i % 3;\n }\n const res = solve(as);\n if (vis[u] != res) {\n foreach (i; 0 .. n) {\n write(as[i]);\n }\n writeln();\n writeln(vis[u], \" \", res);\n assert(false);\n }\n }\n }\n }\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const K = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto ss = new int[N];\n foreach (i; 0 .. N) {\n ss[i] = (A[i] < K) ? 0 : (A[i] == K) ? 1 : 2;\n }\n const ans = solve(ss);\n writeln(ans ? \"yes\" : \"no\");\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool solve (R) (R a, int n, int k)\n{\n\tif (a.length == 1)\n\t{\n\t\treturn k == a.front;\n\t}\n\tif (!a.canFind (k))\n\t{\n\t\treturn false;\n\t}\n\tif (a.length == 2)\n\t{\n\t\treturn sum (a) >= 2 * k;\n\t}\n\tforeach (i; 0..n - 2)\n\t{\n\t\tif ((a[i] >= k) + (a[i + 1] >= k) + (a[i + 2] >= k) >= 2)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid main ()\n{\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (a, n, k) ? \"yes\" : \"no\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n int[] as;\n bool has;\n foreach (a; readln.split.to!(int[])) {\n if (a == K) has = true;\n as ~= a;\n }\n if (!has) {\n writeln(\"no\");\n continue;\n }\n if (N == 1) {\n writeln(has ? \"yes\" : \"no\");\n continue;\n }\n foreach (i, a; as[0..$-1]) {\n if (a == K) {\n if (as[i+1] >= K) goto ok;\n if (i+2 < N && as[i+2] >= K) goto ok;\n } else if (a > K) {\n if (as[i+1] >= K) goto ok;\n if (i+2 < N && as[i+2] >= K) goto ok;\n }\n }\n writeln(\"no\");\n continue;\n ok:\n writeln(\"yes\");\n }\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool solve (R) (R a, int n, int k)\n{\n\tif (a.length == 1)\n\t{\n\t\treturn k == a.front;\n\t}\n\tif (!a.canFind (k))\n\t{\n\t\treturn false;\n\t}\n\tforeach (i; 0..n - 2)\n\t{\n\t\tif ((a[i] >= k) + (a[i + 1] >= k) + (a[i + 2] >= k) >= 2)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid main ()\n{\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (a, n, k) ? \"yes\" : \"no\");\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool solve (R) (R a, int k)\n{\n\tif (a.length < 2)\n\t{\n\t\treturn k == a.front;\n\t}\n\tint lo = 0;\n\tint me = 0;\n\tint hi = 0;\n\t// k = 3\n\t// 3 x\n\t// 3 1 x\n\t// 3 1 3 v\n\t// 3 5 v\n\tforeach (ref c; a.find (k))\n\t{\n\t\tlo += (c < k);\n\t\tme += (c == k);\n\t\thi += (c > k);\n\t\tint n = lo + me + hi;\n\t\twriteln (lo, \" \", me, \" \", hi);\n\t\tif (n > 1 && lo <= (n - 1) / 2 && lo + me > (n - 1) / 2)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\tif (c == k)\n\t\t{\n\t\t\tlo = 0;\n\t\t\tme = 1;\n\t\t\thi = 0;\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid main ()\n{\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (a, k) || solve (a.retro, k) ? \"yes\" : \"no\");\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool solve (R) (R a, int k)\n{\n\tif (a.length < 2)\n\t{\n\t\treturn k == a.front;\n\t}\n\tint lo = 0;\n\tint me = 0;\n\tint hi = 0;\n\tforeach (ref c; a.find (k))\n\t{\n\t\tlo += (c < k);\n\t\tme += (c == k);\n\t\thi += (c > k);\n\t\tint n = lo + me + hi;\n\t\tif (n > 1 && lo <= (n - 1) / 2 && lo + me > (n - 1) / 2)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\tif (c == k)\n\t\t{\n\t\t\tlo = 0;\n\t\t\tme = 1;\n\t\t\thi = 0;\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid main ()\n{\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (a, k) || solve (a.retro, k) ? \"yes\" : \"no\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n int[] as;\n size_t[] kis = [0];\n foreach (i, a; readln.split.to!(int[])) {\n as ~= a;\n if (a == K) kis ~= i;\n }\n if (N == 1) {\n writeln(as[0] == K ? \"yes\" : \"no\");\n continue;\n }\n if (kis.length == 1) {\n writeln(\"no\");\n continue;\n }\n foreach (i, s; kis[1..$]) {\n int x;\n foreach_reverse (j; kis[i]+1..s) {\n if (as[j] >= K) {\n ++x;\n } else {\n --x;\n }\n if (x >= 0) goto ok;\n }\n }\n kis = kis[1..$] ~ N.to!size_t;\n foreach (i, s; kis[0..$-1]) {\n int x;\n foreach (j; s+1..kis[i+1]) {\n if (as[j] >= K) {\n ++x;\n } else {\n --x;\n }\n if (x >= 0) goto ok;\n }\n }\n writeln(\"no\");\n continue;\n ok:\n writeln(\"yes\");\n }\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n int[] as;\n size_t[] kis = [0];\n foreach (i, a; readln.split.to!(int[])) {\n as ~= a;\n if (a == K) kis ~= i;\n }\n if (N == 1) {\n writeln(as[0] == K ? \"yes\" : \"no\");\n continue;\n }\n if (kis.length == 1) {\n writeln(\"no\");\n continue;\n }\n foreach (i, s; kis[1..$]) {\n int x;\n foreach_reverse (j; kis[i]..s) {\n if (as[j] >= K) {\n ++x;\n } else {\n --x;\n }\n if (x >= 0) goto ok;\n }\n }\n kis ~= (N-1).to!size_t;\n kis = kis[1..$];\n foreach (i, s; kis[0..$-1]) {\n int x;\n foreach (j; s+1..kis[i+1]+1) {\n if (as[j] >= K) {\n ++x;\n } else {\n --x;\n }\n if (x >= 0) goto ok;\n }\n }\n writeln(\"no\");\n continue;\n ok:\n writeln(\"yes\");\n }\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n int[] as;\n size_t[] kis;\n foreach (i, a; readln.split.to!(int[])) {\n as ~= a;\n if (a == K) kis ~= i;\n }\n if (N == 1) {\n writeln(as[0] == K ? \"yes\" : \"no\");\n continue;\n }\n if (kis.empty) {\n writeln(\"no\");\n continue;\n }\n if (kis[0] != 0) {\n int x;\n foreach_reverse (i; 0..kis[0]) {\n if (as[i] >= K) {\n ++x;\n } else {\n --x;\n }\n if (x >= 0) goto ok;\n }\n }\n kis ~= (N-1).to!size_t;\n foreach (i, s; kis[0..$-1]) {\n int x;\n foreach (j; s+1..kis[i+1]+1) {\n if (as[j] >= K) {\n ++x;\n } else {\n --x;\n }\n if (x >= 0) goto ok;\n }\n }\n writeln(\"no\");\n continue;\n ok:\n writeln(\"yes\");\n }\n}"}], "src_uid": "2d988fe01f91847dcad52111c468c0ba"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\nif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tstring s;\n\twhile((s=readln.strip)!=\"\")\n\t{\n\t\tauto a=s.split(',').array;\n\t\tint pos,n=a.length;\n\t\tstring[][] ans=new string[][1];\n\t\tauto u=new bool[n];\n\t\tvoid dfs(int lev)\n\t\t{\n\t\t\tif(pos==n)return;\n\t\t\tu[pos]=1;\n\t\t\tif(lev==ans.length)\n\t\t\t{\n\t\t\t\tans.length++;\n\t\t\t}\n\t\t\tans[lev]~=a[pos];\n\t\t\tint k=a[pos+1].to!int;\n\t\t\tpos+=2;\n\t\t\tforeach(i;0..k)\n\t\t\t{\n\t\t\t\tdfs(lev+1);\n\t\t\t}\n\t\t\t//pos-=2;\n\t\t}\n\t\tint pp=pos;\n\t\tfor(;pp<n;pp+=2)\n\t\t{\n\t\t\tif(!u[pp]){pos=pp;dfs(0);}\n\t\t\t//debug writeln(pos);\n\t\t}\n\t\twriteln(ans.length);\n\t\tforeach(i;ans)\n\t\t{\n\t\t\tforeach(j;i)write(j,' ');\n\t\t\twriteln;\n\t\t}\n\t\tdebug writeln(\"takt\");\n\t}\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nint pos;\nstring s;\nstring[ ][ ] result;\nint resDepth;\n\nvoid parse(int depth) {\n assert(pos < s.length);\n resDepth = max(resDepth, depth);\n if (depth == result.length)\n result ~= cast(string[ ])null;\n int comma = cast(int)(s.length - s[pos .. $].find(',').length);\n result[depth] ~= s[pos .. comma];\n pos = comma + 1;\n comma = cast(int)(s.length - s[pos .. $].find(',').length);\n int count = s[pos .. comma].to!int;\n pos = comma + 1;\n foreach (i; 0 .. count)\n parse(depth + 1);\n}\n\nvoid main() {\n while ((s = readln()).length > 1) {\n s = s[0 .. $ - 1];\n result = null;\n resDepth = 0;\n pos = 0;\n while (pos < s.length)\n parse(0);\n writeln(resDepth + 1);\n writefln(\"%(%-(%s %)\\n%)\", result);\n }\n}\n"}], "negative_code": [], "src_uid": "da08dd34ac3c05af58926f70abe5acd0"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.container;\n\nvoid main() {\n string s = stdin.readln;\n Array!char a;\n foreach (c; s) {\n if (a.empty) { a.insert(c); }\n else if (a.back == c) { a.removeBack; }\n else { a.insert(c); }\n }\n foreach (c; a) {\n write(c);\n }\n}\n", "positive_code": [{"source_code": "module cf_81A;\n\nimport std.stdio;\n\nvoid main() {\n string text;\n\n readf(\"%s\\n\", &text);\n\n string optText = \"\";\n\n while (text.length > 0) {\n if (optText.length == 0) {\n optText ~= text[0];\n } else if (optText[$ - 1] == text[0]) {\n optText = optText[0 .. $ - 1];\n } else {\n optText ~= text[0];\n }\n\n text = text[1 .. $];\n }\n\n writeln(optText);\n}"}], "negative_code": [], "src_uid": "26f1b8c3cb83603c904e1508df4067f4"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto a = readln.splitter.map !(to !(long)).array;\n\tauto p = 3.iota.array;\n\twriteln (\"First\");\n\tstdout.flush ();\n\twhile (true)\n\t{\n\t\tschwartzSort !(i => a[i]) (p);\n\t\tlong delta = a[p[2]] - a[p[0]] + a[p[2]] - a[p[1]];\n\t\tif (a[p[2]] - a[p[1]] == a[p[1]] - a[p[0]])\n\t\t{\n\t\t\tdelta = a[p[2]] - a[p[1]];\n\t\t}\n\t\twriteln (delta);\n\t\tstdout.flush ();\n\t\tauto k = readln.strip.to !(int);\n\t\tif (k == 0)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\ta[k - 1] += delta;\n\t\tdebug {stderr.writeln (a);}\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n auto A = new long[3];\n foreach (i; 0 .. 3) {\n A[i] = readLong();\n }\n writeln(\"First\");\n stdout.flush;\n \n enum ini = 10L^^10;\n writeln(ini);\n stdout.flush;\n const i0 = readInt() - 1;\n if (i0 == -1) {\n return;\n }\n A[i0] += ini;\n debug {\n writeln(\"A = \", A);\n }\n \n auto a = A.dup;\n a.sort;\n const magic = (a[1] - a[0]) + 2 * (a[2] - a[1]);\n writeln(magic);\n stdout.flush;\n const i1 = readInt() - 1;\n if (i1 == -1) {\n return;\n }\n A[i1] += magic;\n debug {\n writeln(\"A = \", A);\n }\n \n auto b = A.dup;\n b.sort;\n assert(b[1] - b[0] == b[2] - b[1]);\n const diff = b[1] - b[0];\n writeln(diff);\n stdout.flush;\n const i2 = readInt() - 1;\n if (i2 == -1) {\n return;\n }\n assert(false);\n}\n"}], "negative_code": [], "src_uid": "351c6fb0a9d1bbb29387c5b7ce8c7f28"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n\nint count_greater(ref int[] a1, int n) {\n int count = 0;\n for (int i = 0; i < a1.length; i++) {\n if (a1[i] > n) {\n count++;\n }\n }\n return count;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n int[] arr = new int[n];\n foreach (ref i; arr) {\n i = cin.read_int;\n }\n for (int i = 0; i < n; i++) {\n write(count_greater(arr, arr[i]) + 1, \" \");\n }\n writeln();\n } \n}", "positive_code": [{"source_code": "\ufeffversion (all) {\nimport std.math,\n std.conv,\n std.stdio,\n std.ascii,\n std.range,\n std.array,\n std.regex,\n std.format,\n std.bigint,\n std.traits,\n std.random,\n std.string,\n std.numeric,\n std.variant,\n std.typecons,\n std.container,\n std.algorithm,\n std.typetuple,\n std.exception,\n core.checkedint;\n}\n\nvoid main() {\n\n\treadln.strip;\n\tauto a = readln.split.map!(to!uint).array;\n\n\tforeach (el; a) {\n\t\twrite(1 + a.filter!(c => c > el).array.length, ' ');\n\t}\n\n\twriteln();\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.ascii; \nimport std.functional;\n\nalias isEven = unaryFun!(\"(a & 1) == 0\");\nalias isOdd = unaryFun!(\"(a & 1) != 0\");\n\nvoid readInput() \n{\n\tsize_t lineSize;\n\n\tauto studentCount = stdin.readln.chomp().to!int();\n\t\n\tauto grades = stdin.readln().split().map!(a => to!int(a)).array;\n\t \n\tint[int] indexHolder;\n\tauto realGrades = grades.dup;\n\tgrades.sort!\"a > b\"();\n\tint lastGrade = 0;\n\tint lastElem = 0;\n\n\tforeach (i, elem; grades)\n\t{\n\t\tif ( lastElem != elem)\n\t\t{\n\t\t\tlastElem = elem;\n\t\t\tlastGrade = i + 1;\n\t\t\tindexHolder[elem] = lastGrade;\n\t\t}\n\t} \n\n\twriteln(realGrades.map!( a => to!string(indexHolder[a])).joiner(\" \"));\n\t\n}\n\nvoid main( string[] args )\n{\n\treadInput();\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.ascii; \nimport std.functional;\n\nalias isEven = unaryFun!(\"(a & 1) == 0\");\nalias isOdd = unaryFun!(\"(a & 1) != 0\");\n\nvoid readInput() \n{\n\tsize_t lineSize;\n\n\tauto studentCount = stdin.readln.chomp().to!int();\n\t\n\tauto grades = stdin.readln().split().map!(a => to!int(a)).array;\n\t \n\tint[int] indexHolder;\n\tauto realGrades = grades.dup;\n\tgrades.sort!\"a > b\"();\n\tint lastGrade = 0;\n\tint lastElem = 0;\n\n\tforeach (i, elem; grades)\n\t{\n\t\tif ( lastElem != elem)\n\t\t{\n\t\t\tlastElem = elem;\n\t\t\tlastGrade = i + 1;\n\t\t\tindexHolder[elem] = lastGrade;\n\t\t}\n\t} \n\n\twriteln(realGrades.map!( a => indexHolder[a]));\n\t\n}\n\nvoid main( string[] args )\n{\n\treadInput();\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.ascii; \nimport std.functional;\n\nalias isEven = unaryFun!(\"(a & 1) == 0\");\nalias isOdd = unaryFun!(\"(a & 1) != 0\");\n\nvoid readInput() \n{\n\tsize_t lineSize; \n\n\tauto studentCount = stdin.readln.chomp().to!int();\n\t\n\tauto grades = stdin.readln().split().map!(a => to!int(a)).array;\n\t\n\tint[int] indexHolder;\n\tauto realGrades = grades.dup;\n\tgrades.sort!\"a > b\"();\n\tint lastGrade = 0;\n\tint lastElem = 0;\n\n\tforeach (i, elem; grades)\n\t{\n\t\tif ( lastElem != elem)\n\t\t{\n\t\t\tlastElem = elem;\n\t\t\tlastGrade = i + 1;\n\t\t\tindexHolder[elem] = lastGrade;\n\t\t}\n\t} \n\n\twriteln(realGrades.map!( a => indexHolder[a]));\n\t\n}\n\nvoid main( string[] args )\n{\n\treadInput();\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.ascii; \nimport std.functional;\n\nalias isEven = unaryFun!(\"(a & 1) == 0\");\nalias isOdd = unaryFun!(\"(a & 1) != 0\");\n\nvoid readInput() \n{\n\tsize_t lineSize; ; \n\n\tauto studentCount = stdin.readln.chomp().to!int();\n\t\n\tauto grades = stdin.readln().split().map!(a => to!int(a)).array;\n\t\n\tint[int] indexHolder;\n\tauto realGrades = grades.dup;\n\tgrades.sort!\"a > b\"();\n\tint lastGrade = 0;\n\tint lastElem = 0;\n\n\tforeach (i, elem; grades)\n\t{\n\t\tif ( lastElem != elem)\n\t\t{\n\t\t\tlastElem = elem;\n\t\t\tlastGrade = i + 1;\n\t\t\tindexHolder[elem] = lastGrade;\n\t\t}\n\t} \n\n\twriteln(realGrades.map!( a => indexHolder[a]));\n\t\n}\n\nvoid main( string[] args )\n{\n\treadInput();\n}"}], "src_uid": "a5edbf422616cdac35e95a4f07efc7fd"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range, core.bitop;\n\nint[] phasebase;\nint[] fights;\nbyte[] a;\nlong[long] cache;\n\nlong solve(int phase, int fightnum)\n{\n byte outcome = a[phasebase[phase] + fightnum];\n if (phase == 0)\n return outcome == 3 ? 2 : 1;\n\n long cacheid = cast(long)fightnum * 20 + cast(long)phase;\n long result = cache.get(cacheid, -1);\n if (result != -1)\n return result;\n result = 0;\n\n if (outcome & 1) {\n result += solve(phase - 1, fightnum * 2 + 0);\n }\n if (outcome & 2) {\n result += solve(phase - 1, fightnum * 2 + 1);\n }\n cache[cacheid] = result;\n return result;\n}\n\nvoid invalidate_cache(int idx)\n{\n int phase = 0;\n while (true) {\n if (idx >= phasebase[phase] && idx < phasebase[phase] + fights[phase]) {\n int fightnum = idx - phasebase[phase];\n\n while (phase < phasebase.length) {\n long cacheid = cast(long)fightnum * 20 + cast(long)phase;\n cache[cacheid] = -1;\n fightnum /= 2;\n phase++;\n }\n return;\n }\n phase++;\n }\n}\n\nvoid main()\n{\n int k, t;\n readf!\" %d \"(k);\n a = readln.strip.split(\"\").map!((x) => (x[0] == '?') ? cast(byte)3 : (x[0] == '0' ? cast(byte)1 : cast(byte)2)).array;\n// writeln(a);\n assert(k == bsf(a.length + 1));\n k = bsf(a.length + 1);\n int pb = 0;\n while (k != 0) {\n phasebase ~= pb;\n k--;\n fights ~= 1 << k;\n pb += (1 << k);\n }\n// writeln(phasebase);\n// writeln(fights);\n// writeln(\"---\");\n readf!\" %d \"(t);\n while (t--) {\n int i;\n readf!\" %d\"(i);\n string x = readln.strip;\n a[i - 1] = (x[0] == '?') ? cast(byte)3 : (x[0] == '0' ? cast(byte)1 : cast(byte)2);\n// writeln(a);\n\n // cache.clear();\n invalidate_cache(i - 1);\n\n writeln(solve(bsf(a.length + 1) - 1, 0));\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tint k;\r\n\twhile (readf !(\" %s\") (k) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto s = readln.strip.dup ~ '*';\r\n\t\treverse (s);\r\n\t\tauto m = 1 << k;\r\n\t\tauto f = new int [m * 2];\r\n\t\tf[] = 1;\r\n\r\n\t\tvoid calc (int pos)\r\n\t\t{\r\n\t\t\tf[pos] = (s[pos] == '0') ? f[pos * 2 + 1] :\r\n\t\t\t (s[pos] == '1') ? f[pos * 2 + 0] :\r\n\t\t\t f[pos * 2 + 0] + f[pos * 2 + 1];\r\n\t\t}\r\n\r\n\t\tforeach_reverse (pos; 1..m)\r\n\t\t{\r\n\t\t\tcalc (pos);\r\n\t\t}\r\n\r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (r; 0..q)\r\n\t\t{\r\n\t\t\tauto t = readln.split;\r\n\t\t\tauto pos = t[0].to !(int);\r\n\t\t\tpos = m - pos;\r\n\t\t\ts[pos] = t[1][0];\r\n\t\t\tfor ( ; pos > 0; pos >>= 1)\r\n\t\t\t{\r\n\t\t\t\tcalc (pos);\r\n\t\t\t}\r\n\t\t\twriteln (f[1]);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.string;\nimport std.range;\nimport std.algorithm;\nimport core.stdc.stdio;\n\nint main()\n{\n int k = readInt!int;\n char[] s = readString.dup.reverse;\n int n = cast(int)s.length;\n int q = readInt!int;\n\n long[] pos = new long[](n + 1);\n void calculate(int v)\n {\n if (v * 2 > s.length)\n {\n if (s[v - 1] == '0' || s[v - 1] == '1') pos[v] = 1;\n else pos[v] = 2;\n return;\n }\n int left = 2 * v;\n int right = 2 * v + 1;\n calculate(left);\n calculate(right);\n if (s[v - 1] == '1')\n {\n pos[v] = pos[left];\n }\n else if (s[v - 1] == '0')\n {\n pos[v] = pos[right];\n }\n else\n {\n pos[v] = pos[right] + pos[left];\n }\n }\n calculate(1);\n foreach(qi; 0 .. q)\n {\n int p = n - readInt!int + 1;\n string ch = readString;\n s[p - 1] = ch[0];\n while (p >= 1)\n {\n if (p * 2 >= n)\n {\n if (s[p - 1] == '0' || s[p - 1] == '1') pos[p] = 1;\n else pos[p] = 2;\n goto done;\n }\n if (s[p - 1] == '1')\n {\n pos[p] = pos[2 * p];\n }\n else if (s[p - 1] == '0')\n {\n pos[p] = pos[2 * p + 1];\n }\n else\n {\n pos[p] = pos[2 * p] + pos[2 * p + 1];\n }\n done:\n p /= 2;\n }\n pos[1].writeln;\n }\n return 0;\n}\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n long rep;\n this(long num)\n {\n rep = num;\n }\n Z!m opBinary(string operator)(Z!m rhs)\n {\n static if (operator == \"+\")\n {\n long result = rhs.rep + this.rep;\n if (result >= m) result -= m;\n return Z!m(result);\n }\n else static if (operator == \"-\")\n {\n long result = this.rep - rhs.rep;\n if (result < 0) result += m;\n return Z!m(result);\n }\n else static if (operator == \"*\")\n {\n long result = this.rep * rhs.rep;\n if (result >= m) result %= m;\n return Z!m(result);\n } else static assert(text(\"Operator \", operator, \" not supported\"));\n }\n Z!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n {\n assert(exponent >= 0);\n Z!m base = this;\n Z!m result = 1;\n while (exponent)\n {\n if (exponent & 1)\n result = result * base;\n base = base * base;\n exponent >>= 1;\n }\n return result;\n }\n invariant\n {\n assert(rep >= 0 && rep < m);\n }\n}\n"}], "negative_code": [], "src_uid": "0eee4b8f074e02311329d5728138c7fe"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.range;\nimport std.algorithm;\n\nvoid main() {\n\tint tc;\n\tscanf(\"%d\\n\", &tc);\n\n\twhile (tc--) {\t\n\t\tint n, m;\n\t\tscanf(\"%d%d\\n\", &n, &m);\n\n\t\tstring[] arr = new string[n];\n\t\tfor (int i = 0; i < n; i++) \n\t\t\tarr[i] = stdin.byLine.front.to!string;\n\n\t\tstring answer = null;\n\t\tcheck: foreach(s; arr) {\n\t\t\tforeach(i; iota(m)) {\n\t\t\t\tfor (char c = 'a'; c <= 'z'; c++) {\n\t\t\t\t\tchar[] test_string = s.dup;\n\t\t\t\t\ttest_string[i] = c;\n\n\t\t\t\t\t// test the string \n\t\t\t\t\tbool good = true;\n\t\t\t\t\tforeach (t; arr) {\n\t\t\t\t\t\tint d = 0;\n\t\t\t\t\t\tforeach (j, e; t) d += e != test_string[j];\n\t\t\t\t\t\tif (d > 1) {\n\t\t\t\t\t\t\tgood = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (good) {\n\t\t\t\t\t\tanswer = test_string.dup;\n\t\t\t\t\t\tbreak check;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (answer == null) writeln(-1);\n\t\telse answer.writeln;\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n outer: while (t--) {\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n string[] input;\n foreach (i; 0 .. n) {\n input ~= readln.chomp;\n }\n \n auto ans = input[0].to!(dchar[]);\n foreach (col; 0 .. m) {\n \n foreach (row; 0 .. n) {\n ans[col] = input[row][col];\n \n bool ok = true;\n foreach (compareidx; 0 .. n) {\n ok &= zip(ans, input[compareidx]).filter!\"a[0] != a[1]\".array.length <= 1;\n }\n \n if (ok) {\n writeln(ans);\n continue outer;\n }\n }\n \n ans[col] = input[0][col];\n }\n \n writeln(-1);\n }\n}"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m;\n @Dim(\"n\") string[] a;\n\n void solve(long tc = -1)\n {\n bool test(string str)\n {\n return iota(0, n)\n .all!(j => iota(0, m).count!(i => a.at(j).at(i) != str.at(i)) <= 1);\n }\n\n char[] ts = a.at(0).dup;\n foreach(i; 0 .. m)\n {\n foreach(c; 'a' .. cast(char)('z' + 1))\n {\n ts.at(i) = c;\n if (test(cast(string) ts))\n {\n writeln(ts);\n return;\n }\n }\n ts.at(i) = a.at(0).at(i);\n }\n writeln(-1);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto s = new string[](n);\n\t\tforeach (i; 0..n)\n\t\t\ts[i] = RD!string;\n\t\t\n\t\tif (n == 1)\n\t\t{\n\t\t\tans[ti] = s[0];\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto used = new bool[][](m, 26);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tauto num = s[i][j]-'a';\n\t\t\t\tused[j][num] = true;\n\t\t\t}\n\t\t}\n\n\t\tint[][string] dp;\n\t\tdp[\"\"] = new int[](n);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint[][string] ndp;\n\t\t\tforeach (j; 0..26)\n\t\t\t{\n\t\t\t\tif (used[i][j] == false) continue;\n\t\t\t\tauto c = cast(char)('a'+j);\n\t\t\t\tforeach (key; dp.keys)\n\t\t\t\t{\n\t\t\t\t\tauto str = key ~ c;\n\t\t\t\t\tauto cnt = dp[key].dup;\n\t\t\t\t\tbool ok = true;\n\t\t\t\t\tforeach (k; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (s[k][i] != c)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++cnt[k];\n\t\t\t\t\t\t\tif (cnt[k] >= 2)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (ok)\n\t\t\t\t\t{\n\t\t\t\t\t\tndp[str] = cnt;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp = ndp;\n\t\t}\n\t\tif (!dp.empty)\n\t\t{\n\t\t\tans[ti] = dp.keys[0];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "8d4cdf75f726b59a8fcc374e1417374a"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tsort !(\"a < b\", SwapStrategy.stable) (a);\n\n\t\tlong res = 0;\n\t\tlong [] ans;\n\t\tif (n == 1)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\telse if (n == 2)\n\t\t{\n\t\t\tif (a[0] == a[1])\n\t\t\t{\n\t\t\t\tres = 1;\n\t\t\t\tans ~= a[0];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint d = a[1] - a[0];\n\t\t\t\tres = 2 + (d % 2 == 0);\n\t\t\t\tans ~= a[0] - d;\n\t\t\t\tif (d % 2 == 0)\n\t\t\t\t{\n\t\t\t\t\tans ~= (a[0] + a[1]) >> 1;\n\t\t\t\t}\n\t\t\t\tans ~= a[1] + d;\n\t\t\t}\n\t\t}\n\t\telse if (a[$ - 1] == a[1])\n\t\t{\n\t\t\tres = 1;\n\t\t\tans ~= a[0];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbool [int] e;\n\t\t\te[a[1] - a[0]] = true;\n\t\t\te[a[2] - a[1]] = true;\n\t\t\tforeach (d, val; e)\n\t\t\t{\n\t\t\t\tans = [];\n\t\t\t\tint holes = 0;\n\t\t\t\tfor (int i = 1; i < n; i++)\n\t\t\t\t{\n\t\t\t\t\tif (a[i] - a[i - 1] == d)\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (a[i] - a[i - 1] == d * 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tans ~= (a[i] + a[i - 1]) >> 1;\n\t\t\t\t\t\tholes++;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tholes += 2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (holes == 0)\n\t\t\t\t{\n\t\t\t\t\tans ~= a[0] - d;\n\t\t\t\t\tans ~= a[$ - 1] + d;\n\t\t\t\t}\n\t\t\t\tres = max (0, 2 - holes);\n\t\t\t\tif (res > 0)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t\tif (res > 0)\n\t\t{\n\t\t\twritefln (\"%(%s %)\", ans);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n if (xs.length == 1) {\n (-1).writeln;\n return;\n }\n if (xs.length == 2) {\n if ((xs.back - xs.front) % 2 == 0) {\n if (xs.back - xs.front == 0) {\n writeln(1);\n writeln(xs.back);\n } else {\n int d = (xs.back - xs.front) / 2;\n writeln(3);\n writeln(xs.front - 2 * d, \" \", xs.front + d, \" \", xs.back + 2 * d);\n }\n } else {\n int d = (xs.back - xs.front);\n writeln(2);\n writeln(xs.front - d, \" \", xs.back + d);\n }\n return;\n }\n int[] ds;\n foreach (i; 0 .. xs.length - 1) {\n ds ~= xs[i + 1] - xs[i];\n }\n int[] k = ds.sort.uniq.array;\n switch (k.length) {\n case 1:\n if (k[0] == 0) {\n writeln(1);\n writeln(xs.front);\n } else {\n writeln(2);\n writeln(xs.front - k[0], \" \", xs.back + k[0]);\n }\n return;\n case 2:\n int[int] c;\n foreach (d; ds) {\n c[d]++;\n }\n if (c.length > 2) {\n writeln(0);\n return;\n }\n if (c.length == 2) {\n int k1 = c.keys.reduce!max;\n int k2 = c.keys.reduce!min;\n if (c[k1] != 1) {\n writeln(0);\n return;\n }\n }\n if (k[0] * 2 != k[1]) {\n writeln(0);\n return;\n }\n int d = k[0];\n foreach (i; 0 .. xs.length - 1) {\n if (xs[i + 1] - xs[i] != d) {\n if (xs[i + 1] - xs[i] == 2 * d) {\n 1.writeln;\n ((xs[i + 1] + xs[i]) / 2).writeln;\n } else {\n 0.writeln;\n }\n return;\n }\n }\n default:\n writeln(0);\n return;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n if (xs.length == 1) {\n (-1).writeln;\n return;\n }\n if (xs.length == 2) {\n if ((xs.back - xs.front) % 2 == 0) {\n if (xs.back - xs.front == 0) {\n writeln(1);\n writeln(xs.back);\n } else {\n int d = (xs.back - xs.front) / 2;\n writeln(3);\n writeln(xs.front - 2 * d, \" \", xs.front + d, \" \", xs.back + 2 * d);\n }\n } else {\n int d = (xs.back - xs.front);\n writeln(2);\n writeln(xs.front - d, \" \", xs.back + d);\n }\n return;\n }\n int[] ds;\n foreach (i; 0 .. xs.length - 1) {\n ds ~= xs[i + 1] - xs[i];\n }\n int[] k = ds.sort.uniq.array;\n switch (k.length) {\n case 1:\n if (k[0] == 0) {\n writeln(1);\n writeln(xs.front);\n } else {\n writeln(2);\n writeln(xs.front - k[0], \" \", xs.back + k[0]);\n }\n return;\n case 2:\n int[int] c;\n foreach (d; ds) {\n c[d]++;\n }\n if (c.length > 2) {\n writeln(0);\n return;\n }\n if (c.length == 2) {\n bool f = false;\n foreach (key, value; c) {\n if (value == 1) {\n f = true;\n }\n }\n if (!f) {\n writeln(0);\n return;\n }\n }\n if (k[0] * 2 != k[1]) {\n writeln(0);\n return;\n }\n int d = k[0];\n foreach (i; 0 .. xs.length - 1) {\n if (xs[i + 1] - xs[i] != d) {\n if (xs[i + 1] - xs[i] == 2 * d) {\n 1.writeln;\n ((xs[i + 1] + xs[i]) / 2).writeln;\n } else {\n 0.writeln;\n }\n return;\n }\n }\n default:\n writeln(0);\n return;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.chomp.split(\" \").map!(to!int).array;\n if (xs.length == 1) {\n (-1).writeln;\n return;\n }\n if (xs.length == 2) {\n if ((xs.back - xs.front) % 2 == 0) {\n int d = (xs.back - xs.front) / 2;\n writeln(3);\n writeln(xs.front - 2 * d, \" \", xs.front + d, \" \", xs.back + 2 * d);\n } else {\n writeln(2);\n writeln(xs.front, xs.back);\n }\n return;\n }\n xs.sort;\n int[] ds;\n foreach (i; 0 .. xs.length - 1) {\n ds ~= xs[i + 1] - xs[i];\n }\n int[] k = ds.sort.uniq.array;\n switch (k.length) {\n case 1:\n writeln(2);\n writeln(xs.front - k[0], \" \", xs.back + k[0]);\n return;\n case 2:\n if (k[0] * 2 != k[1]) {\n writeln(0);\n return;\n }\n int d = k[0];\n foreach (i; 0 .. xs.length - 1) {\n if (xs[i + 1] - xs[i] != d) {\n if (xs[i + 1] - xs[i] == 2 * d) {\n 1.writeln;\n ((xs[i + 1] + xs[i]) / 2).writeln;\n } else {\n 0.writeln;\n }\n return;\n }\n }\n default:\n writeln(0);\n return;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.chomp.split(\" \").map!(to!int).array;\n if (xs.length == 1) {\n (-1).writeln;\n return;\n }\n if (xs.length == 2) {\n if ((xs.back - xs.front) % 2 == 0) {\n if (xs.back - xs.front == 0) {\n writeln(1);\n writeln(xs.back);\n } else {\n int d = (xs.back - xs.front) / 2;\n writeln(3);\n writeln(xs.front - 2 * d, \" \", xs.front + d, \" \", xs.back + 2 * d);\n }\n } else {\n writeln(2);\n writeln(xs.front, xs.back);\n }\n return;\n }\n xs.sort;\n int[] ds;\n foreach (i; 0 .. xs.length - 1) {\n ds ~= xs[i + 1] - xs[i];\n }\n int[] k = ds.sort.uniq.array;\n switch (k.length) {\n case 1:\n if (k[0] == 0) {\n writeln(1);\n writeln(xs.front);\n } else {\n writeln(2);\n writeln(xs.front - k[0], \" \", xs.back + k[0]);\n }\n return;\n case 2:\n if (k[0] * 2 != k[1]) {\n writeln(0);\n return;\n }\n int d = k[0];\n foreach (i; 0 .. xs.length - 1) {\n if (xs[i + 1] - xs[i] != d) {\n if (xs[i + 1] - xs[i] == 2 * d) {\n 1.writeln;\n ((xs[i + 1] + xs[i]) / 2).writeln;\n } else {\n 0.writeln;\n }\n return;\n }\n }\n default:\n writeln(0);\n return;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n if (xs.length == 1) {\n (-1).writeln;\n return;\n }\n if (xs.length == 2) {\n if ((xs.back - xs.front) % 2 == 0) {\n if (xs.back - xs.front == 0) {\n writeln(1);\n writeln(xs.back);\n } else {\n int d = (xs.back - xs.front) / 2;\n writeln(3);\n writeln(xs.front - 2 * d, \" \", xs.front + d, \" \", xs.back + 2 * d);\n }\n } else {\n int d = (xs.back - xs.front);\n writeln(2);\n writeln(xs.front - d, \" \", xs.back + d);\n }\n return;\n }\n int[] ds;\n foreach (i; 0 .. xs.length - 1) {\n ds ~= xs[i + 1] - xs[i];\n }\n int[] k = ds.sort.uniq.array;\n switch (k.length) {\n case 1:\n if (k[0] == 0) {\n writeln(1);\n writeln(xs.front);\n } else {\n writeln(2);\n writeln(xs.front - k[0], \" \", xs.back + k[0]);\n }\n return;\n case 2:\n if (k[0] * 2 != k[1]) {\n writeln(0);\n return;\n }\n int d = k[0];\n foreach (i; 0 .. xs.length - 1) {\n if (xs[i + 1] - xs[i] != d) {\n if (xs[i + 1] - xs[i] == 2 * d) {\n 1.writeln;\n ((xs[i + 1] + xs[i]) / 2).writeln;\n } else {\n 0.writeln;\n }\n return;\n }\n }\n default:\n writeln(0);\n return;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.chomp.split(\" \").map!(to!int).array;\n if (xs.length == 1) {\n (-1).writeln;\n return;\n }\n if (xs.length == 2) {\n if ((xs.back - xs.front) % 2 == 0) {\n int d = (xs.back - xs.front) / 2;\n writeln(3);\n writeln(xs.front - 2 * d, \" \", xs.front + d, \" \", xs.back + 2 * d);\n } else {\n writeln(2);\n writeln(xs.front, xs.back);\n }\n return;\n }\n xs.sort;\n int d = xs[1] - xs[0];\n foreach (i; 0 .. xs.length - 1) {\n if (xs[i + 1] - xs[i] != d) {\n if (xs[i + 1] - xs[i] == 2 * d) {\n 1.writeln;\n ((xs[i + 1] + xs[i]) / 2).writeln;\n } else {\n 0.writeln;\n }\n return;\n }\n }\n writeln(2);\n writeln(xs.front - d, \" \", xs.back + d);\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n if (xs.length == 1) {\n (-1).writeln;\n return;\n }\n if (xs.length == 2) {\n if ((xs.back - xs.front) % 2 == 0) {\n if (xs.back - xs.front == 0) {\n writeln(1);\n writeln(xs.back);\n } else {\n int d = (xs.back - xs.front) / 2;\n writeln(3);\n writeln(xs.front - 2 * d, \" \", xs.front + d, \" \", xs.back + 2 * d);\n }\n } else {\n int d = (xs.back - xs.front);\n writeln(2);\n writeln(xs.front - d, \" \", xs.back + d);\n }\n return;\n }\n int[] ds;\n foreach (i; 0 .. xs.length - 1) {\n ds ~= xs[i + 1] - xs[i];\n }\n int[] k = ds.sort.uniq.array;\n switch (k.length) {\n case 1:\n if (k[0] == 0) {\n writeln(1);\n writeln(xs.front);\n } else {\n writeln(2);\n writeln(xs.front - k[0], \" \", xs.back + k[0]);\n }\n return;\n case 2:\n int[int] c;\n foreach (d; ds) {\n c[d]++;\n }\n if (c.length > 2) {\n writeln(0);\n return;\n }\n if (c.length == 2) {\n int k1 = c.keys.reduce!min;\n int k2 = c.keys.reduce!max;\n if (c[k1] != 1) {\n writeln(0);\n return;\n }\n }\n if (k[0] * 2 != k[1]) {\n writeln(0);\n return;\n }\n int d = k[0];\n foreach (i; 0 .. xs.length - 1) {\n if (xs[i + 1] - xs[i] != d) {\n if (xs[i + 1] - xs[i] == 2 * d) {\n 1.writeln;\n ((xs[i + 1] + xs[i]) / 2).writeln;\n } else {\n 0.writeln;\n }\n return;\n }\n }\n default:\n writeln(0);\n return;\n }\n}\n"}], "src_uid": "e3ca8338beb8852c201be72650e9aabd"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\nvoid main(){\n\n\tint[200010] a;\n\tint n;\n\n\treadf(\"%s\", &n);\n\treadln;\n\t\n\tint ss = 0;\n\n\tfor (int i = 1; i < n; ++i){\n\t\treadf(\"%s \", &a[i]);\n\t\tss += a[i];\n\t}\n\n\treadf(\"%s\", &a[n]);\n\tss += a[n];\n\treadln;\n\n\tss = (ss + 1) / 2;\n\tint tt = 0;\n\tfor (int i = 1; i <= n; ++i){\n\t\ttt += a[i];\n\t\tif (tt >= ss){\n\t\t\twriteln(i);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\tint[200010] a;\n\n\tint n;\n\n\treadf(\"%s\", &n);\n\treadln;\n\t\n\tint ss = 0;\n\n\tfor (int i = 1; i < n; ++i){\n\t\treadf(\"%s \", &a[i]);\n\t\tss += a[i];\n\t}\n\n\treadf(\"%s\", &a[n]);\n\tss += a[n];\n\treadln;\n\n\n\tss = (ss + 1) / 2;\n\tint tt = 0;\n\tfor (int i = 1; i <= n; ++i){\n\t\ttt += a[i];\n\t\tif (tt >= ss){\n\t\t\twriteln(i);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n"}, {"source_code": "import std.algorithm.iteration;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n;\n readf!\"%d\\n\"(n);\n\n auto a = readln.stripRight.split.map!(a => a.parse!int);\n auto s = cumulativeFold!\"a + b\"(a, 0).array;\n // find the first value >= sum/2\n writeln(s.assumeSorted.lowerBound((s[$-1] + 1) / 2).length + 1);\n}\n"}], "negative_code": [], "src_uid": "241157c465fe5dd96acd514010904321"} {"source_code": "import std.stdio, std.conv, std.string, std.algorithm, std.array;\r\n\r\nvoid main()\r\n{\r\n auto t = readln().strip().to!int;\r\n foreach (i; 0..t)\r\n {\r\n auto testCase = readln().strip();\r\n auto numbers = testCase.split().map!(s=>s.to!int).array.sort;\r\n writefln(\"%d\", numbers[1]);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.algorithm;\r\nimport std.math;\r\n//import std.conv;\r\n//import std.numeric;\r\n//import std.range;\r\nimport std.array;\r\nimport std.bigint;\r\nimport std.string;\r\n\r\nvoid sol(){\r\n\r\n int a, b, c;\r\n scanf(\"%d %d %d\", &a, &b, &c);\r\n\r\n if(a>b){\r\n swap(a,b);\r\n }\r\n if(b>c){\r\n swap(b,c);\r\n }\r\n if(a>b){\r\n swap(a,b);\r\n }\r\n\r\n writeln(b);\r\n}\r\n\r\nvoid main(){\r\n \r\n int t;\r\n readf!\"%d\"(t);\r\n while (t--){\r\n sol();\r\n }\r\n}"}, {"source_code": "import std;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto a = readln.splitter.map!(to!long).array.sort.array;\n writeln(a[1]);\n }\n}\n"}], "negative_code": [], "src_uid": "63c2142461c93ae4c962eac1ecb5b192"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD;\r\n\t\tauto a = RDA;\r\n\r\n\t\tans[ti] = long.min;\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = k * a[i];\r\n\t\t\tforeach_reverse (j; 0..i)\r\n\t\t\t{\r\n\t\t\t\tlong y = cast(long)(i+1) * (j+1);\r\n\t\t\t\tif (y - x <= ans[ti]) break;\r\n\t\t\t\tauto z = y - k * (a[i]|a[j]);\r\n\t\t\t\tans[ti].chmax(z);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\n\nvoid solve()\n{\n\tint n = readInt!int;\n\tint k = readInt!int;\n\tauto a = new int[](n); foreach(ref ai; a) ai = readInt!int;\n\tlong mx = long.min;\n\tforeach(j; n - 100 .. n)\n\t{\n\t\tforeach(i; 0 .. j)\n\t\t{\n\t\t\tmx = max(mx, cast(long)(i+1)*cast(long)(j+1) - cast(long)k * (a[i]|a[j]));\n\t\t}\n\t}\n\tmx.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main(string[ ] args) {\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n\r\n while (t--) {\r\n int n, k;\r\n readf!\"%s %s\"(n, k);\r\n readln;\r\n\r\n auto a = readln.chomp.split.map!(to!int).array;\r\n \r\n immutable int reach = 110;\r\n\r\n long ans = long.min;\r\n for (int i = n-1; i >= 0 && i >= n - reach; --i) {\r\n for (int j = i-1; j >= 0 && j >= n - reach; --j) {\r\n auto cur = (i+1).to!long * (j+1).to!long - k * (a[i] | a[j]);\r\n ans = max(cur, ans);\r\n }\r\n }\r\n\r\n ans.writeln;\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias P = Tuple!(long, \"i\", long, \"j\");\r\n\r\nvoid solve() {\r\n int N; long K; readf(\"%d %d\\n\", &N, &K);\r\n auto A = readarray!int;\r\n\r\n long xmax = -(1L<<56);\r\n for (int j = N; j >= 1; j--) {\r\n for (int i = j-1; i >= 1; i--) {\r\n if (xmax >= cast(long)(i) * j) break;\r\n long x = cast(long)(i) * j - K * (A[i-1] | A[j-1]);\r\n xmax.chmax(x);\r\n }\r\n }\r\n writeln(xmax);\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias P = Tuple!(long, \"i\", long, \"j\");\r\n\r\nvoid solve() {\r\n int N; long K; readf(\"%d %d\\n\", &N, &K);\r\n auto A = readarray!int;\r\n\r\n if (N >= 500) {\r\n bool[P] used;\r\n auto Q = heapify!((a, b) => a.i*a.j < b.i*b.j)(new P[0], 0);\r\n Q.insert(P(N-1, N));\r\n long xmax = -(1L<<56);\r\n while (! Q.empty) {\r\n auto c = Q.front; Q.removeFront;\r\n long i = c.i, j = c.j;\r\n if (i * j < xmax) break;\r\n long x = i * j - K * (A[cast(int)(i-1)] | A[cast(int)(j-1)]);\r\n xmax.chmax(x);\r\n if (i + 1 < j) {\r\n auto n = P(i, j-1);\r\n if (n !in used) {\r\n used[n] = true;\r\n Q.insert(n);\r\n }\r\n }\r\n if (i > 1) {\r\n auto n = P(i-1, j);\r\n if (n !in used) {\r\n used[n] = true;\r\n Q.insert(n);\r\n }\r\n }\r\n }\r\n writeln(xmax);\r\n } else {\r\n long xmax = -(1L<<56);\r\n for (int j = N; j >= 1; j--) {\r\n for (int i = j-1; i >= 1; i--) {\r\n if (xmax >= i * j) break;\r\n long x = i * j - K * (A[i-1] | A[j-1]);\r\n xmax.chmax(x);\r\n }\r\n }\r\n writeln(xmax);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias P = Tuple!(long, \"i\", long, \"j\");\r\n\r\nvoid solve() {\r\n int N; long K; readf(\"%d %d\\n\", &N, &K);\r\n auto A = readarray!int;\r\n\r\n long xmax = -(1L<<56);\r\n for (int j = N; j >= 1; j--) {\r\n for (int i = j-1; i >= 1; i--) {\r\n if (xmax >= i * j) break;\r\n long x = i * j - K * (A[i-1] | A[j-1]);\r\n xmax.chmax(x);\r\n }\r\n }\r\n writeln(xmax);\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias P = Tuple!(long, \"i\", long, \"j\");\r\n\r\nvoid solve() {\r\n int N; long K; readf(\"%d %d\\n\", &N, &K);\r\n auto A = readarray!int;\r\n bool[P] used;\r\n DList!P Q;\r\n Q.insert(P(N-1, N));\r\n long xmax = -(1L<<56);\r\n while (! Q.empty) {\r\n auto c = Q.front; Q.removeFront;\r\n long i = c.i, j = c.j;\r\n if (i * j < xmax) break;\r\n long x = i * j - K * (A[cast(int)(i-1)] | A[cast(int)(j-1)]);\r\n xmax.chmax(x);\r\n if (i + 1 < j) {\r\n auto n = P(i, j-1);\r\n if (n !in used) {\r\n used[n] = true;\r\n Q.insert(n);\r\n }\r\n }\r\n if (i > 1) {\r\n auto n = P(i-1, j);\r\n if (n !in used) {\r\n used[n] = true;\r\n Q.insert(n);\r\n }\r\n }\r\n }\r\n writeln(xmax);\r\n}\r\n"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main(string[ ] args) {\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n\r\n while (t--) {\r\n int n, k;\r\n readf!\"%s %s\"(n, k);\r\n readln;\r\n\r\n auto a = readln.chomp.split.map!(to!int).array;\r\n \r\n immutable int reach = 100;\r\n\r\n long ans = long.min;\r\n for (int i = n-1; i >= 0 && i >= n - reach; --i) {\r\n for (int j = i-1; j >= 0 && j >= n - reach; --j) {\r\n auto cur = (i+1).to!long * (j+1).to!long - k * (a[i] | a[j]);\r\n ans = max(cur, ans);\r\n }\r\n }\r\n\r\n ans.writeln;\r\n }\r\n}"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main(string[ ] args) {\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n\r\n while (t--) {\r\n int n, k;\r\n readf!\"%s %s\"(n, k);\r\n readln;\r\n\r\n auto a = readln.chomp.split.map!(to!int).array;\r\n\r\n long ans = long.min;\r\n for (int i = n-1; i >= 0 && i >= n - 10; --i) {\r\n for (int j = i-1; j >= 0 && j >= n - 10; --j) {\r\n auto cur = (i+1).to!long * (j+1).to!long - k * (a[i] | a[j]);\r\n ans = max(cur, ans);\r\n }\r\n }\r\n\r\n ans.writeln;\r\n }\r\n}"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\n\nvoid solve()\n{\n\tint n = readInt!int;\n\tint k = readInt!int;\n\tauto a = new int[](n); foreach(ref ai; a) ai = readInt!int;\n\tif (n <= 1000)\n\t{\n\t\tlong mx = long.min;\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n)\n\t\t\t\tmx = max(mx, cast(long)(i+1)*cast(long)(j+1) - cast(long)k * (a[i]|a[j]));\n\t\tmx.writeln;\n\t}\n\telse\n\t{\n\t\tlong mx = long.min;\n\t\tforeach(j; n - 3 .. n)\n\t\t{\n\t\t\tforeach(i; 0 .. j)\n\t\t\t{\n\t\t\t\tmx = max(mx, cast(long)(i+1)*cast(long)(j+1) - cast(long)k * (a[i]|a[j]));\n\t\t\t}\n\t\t}\n\t\tmx.writeln;\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD;\r\n\t\tauto a = RDA;\r\n\r\n\t\tans[ti] = long.min;\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = k * a[i];\r\n\t\t\tforeach_reverse (j; 0..i)\r\n\t\t\t{\r\n\t\t\t\tlong y = (i+1) * (j+1);\r\n\t\t\t\tif (y - x <= ans[ti]) break;\r\n\t\t\t\tauto z = y - k * (a[i]|a[j]);\r\n\t\t\t\tans[ti].chmax(z);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD;\r\n\t\tauto a = RDA;\r\n\r\n\t\tans[ti] = long.min;\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = k * a[i];\r\n\t\t\tforeach_reverse (j; 0..i)\r\n\t\t\t{\r\n\t\t\t\tauto y = (i+1) * (j+1);\r\n\t\t\t\tif (y - x <= ans[ti]) break;\r\n\t\t\t\tauto z = y - k * (a[i]|a[j]);\r\n\t\t\t\tans[ti].chmax(z);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "3a45b6acdcf3800d1cb4ef8ac96ed4cf"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!long;\n long[] as;\n long b = 1;\n N -= 1;\n while (N) {\n if (N <= b*2) {\n as ~= N-b;\n break;\n }\n if (N <= b*4) {\n as ~= N/2-b;\n b = N/2;\n } else {\n as ~= b;\n b *= 2;\n }\n N -= b;\n }\n writeln(as.length);\n writeln(as.to!(string[]).join(\" \"));\n }\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n\n while (t--) {\n int n;\n readf(\"%s\", &n);\n readln;\n \n int mx = 0;\n while (n >= (1 << mx)) {\n n -= (1 << mx);\n ++mx;\n }\n \n int[] arr;\n foreach (b; 0 .. mx) {\n arr ~= (1 << b);\n if (n >= (1 << b) && n < (1 << (b+1))) { arr ~= n; }\n }\n \n int[] ans;\n foreach (prv, nxt; lockstep(arr, arr.dropOne)) {\n ans ~= nxt - prv;\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(\" \").writeln;\n }\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\treadln;\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto steps = bsr (n);\n\t\tint cur = 1;\n\t\tint total = cur;\n\t\tint [] ans;\n\t\tforeach (step; 0..steps)\n\t\t{\n\t\t\tint next = (n - total) / (steps - step);\n\t\t\tnext = min (next, cur * 2);\n\t\t\tans ~= next - cur;\n\t\t\tcur = next;\n\t\t\ttotal += next;\n\t\t}\n\t\twriteln (steps);\n\t\twritefln !(\"%(%s %)\") (ans);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!long;\n long[] as;\n long b = 1;\n if (N%2 == 0) {\n as ~= 0;\n N -= 2;\n } else {\n N -= 1;\n }\n while (N) {\n if (N == b) {\n as ~= 0;\n break;\n } else if (N == b*2) {\n as ~= b;\n break;\n }\n if (N/2 <= b*2) {\n as ~= N/2-b;\n b = N/2;\n N /= 2;\n } else {\n as ~= b;\n b *= 2;\n N -= b;\n }\n }\n writeln(as.length);\n writeln(as.to!(string[]).join(\" \"));\n }\n}"}], "src_uid": "e21f235ffe7f26d9a7af12a7f3f9a2fd"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n immutable int MD = 998244353;\n immutable int MXN = 3 * 10 ^^ 5;\n \n auto pw = new int[] (MXN + 1);\n pw[0] = 1;\n foreach (i; 1 .. MXN+1) { pw[i] = pw[i-1] * 2 % MD; }\n \n int t;\n readf(\"%s\", &t);\n readln;\n \n outer: while (t--) {\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto g = new int[][] (n+1);\n foreach (i; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto clr = new int[] (n+1);\n clr[] = 0;\n int ans = 1;\n foreach (i; 1 .. n+1) {\n if (clr[i] != 0) { continue; }\n \n auto res = new int[] (3);\n res[] = 0;\n \n bool dfs(int v, int c) {\n clr[v] = c;\n res[c] += 1;\n auto ok = true;\n foreach (u; g[v]) {\n if (clr[u] == 0) {\n ok &= dfs(u, 3 - c);\n } \n else if (clr[u] == 3 - c) { continue; }\n else { return false; }\n }\n \n return ok;\n }\n \n if (!dfs(i, 1)) {\n writeln(0);\n continue outer;\n }\n \n debug { writeln(i, ' ', res); }\n \n int cur = (pw[res[1]] + pw[res[2]]) % MD;\n ans = ans.to!long * cur % MD;\n }\n \n ans.writeln;\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 998244353;\n\nlong powmod(long a, long x, long m) {\n long ret = 1;\n while (x) {\n if (x % 2) ret = ret * a % m;\n a = a * a % m;\n x /= 2;\n }\n return ret;\n}\n\nvoid solve() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto G = new int[][](N);\n foreach (_; 0..M) {\n s = readln.split.map!(to!int);\n G[s[0]-1] ~= s[1]-1;\n G[s[1]-1] ~= s[0]-1;\n }\n\n long ans = 1;\n auto cnt = new long[](2);\n auto C = new int[](N);\n fill(C, -1);\n\n bool dfs(int n, int c) {\n if (C[n] != -1)\n return C[n] == c;\n C[n] = c;\n cnt[c] += 1;\n foreach (m; G[n]) {\n if (C[m] != -1) {\n if (C[m] == (c^1))\n continue;\n else\n return false;\n }\n if (!dfs(m, c^1))\n return false;\n }\n return true;\n }\n\n foreach (i; 0..N) {\n if (C[i] != -1) continue;\n cnt[0] = cnt[1] = 0;\n if (dfs(i, 0)) {\n long tmp = powmod(2, cnt[0], MOD) + powmod(2, cnt[1], MOD);\n tmp %= MOD;\n ans = ans * tmp % MOD;\n } else {\n writeln(0);\n return;\n }\n }\n\n ans.writeln;\n}\n\nvoid main() {\n auto Q = readln.chomp.to!int;\n while (Q--) solve;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 998244353;\n\nlong powmod(long a, long x, long m) {\n long ret = 1;\n while (x) {\n if (x % 2) ret = ret * a % m;\n a = a * a % m;\n x /= 2;\n }\n return ret;\n}\n\nvoid solve() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto G = new int[][](N);\n foreach (_; 0..M) {\n s = readln.split.map!(to!int);\n G[s[0]-1] ~= s[1]-1;\n G[s[1]-1] ~= s[0]-1;\n }\n\n long ans = 0;\n auto cnt = new long[](2);\n auto C = new int[](N);\n fill(C, -1);\n\n bool dfs(int n, int c) {\n if (C[n] != -1)\n return C[n] == c;\n C[n] = c;\n cnt[c] += 1;\n foreach (m; G[n]) {\n if (C[m] != -1) {\n if (C[m] != (c^1))\n return false;\n else\n continue;\n }\n if (!dfs(m, c^1))\n return false;\n }\n return true;\n }\n\n foreach (i; 0..N) {\n if (C[i] != -1) continue;\n cnt[0] = cnt[1] = 0;\n if (dfs(i, 0)) {\n ans += powmod(2, cnt[0], MOD) + powmod(2, cnt[1], MOD);\n ans %= MOD;\n } else {\n writeln(0);\n return;\n }\n }\n\n ans.writeln;\n}\n\nvoid main() {\n auto Q = readln.chomp.to!int;\n while (Q--) solve;\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n immutable int MD = 998244353;\n immutable int MXN = 3 * 10 ^^ 5;\n \n auto pw = new int[] (MXN + 1);\n pw[0] = 1;\n foreach (i; 1 .. MXN+1) { pw[i] = pw[i-1] * 2 % MD; }\n \n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto g = new int[][] (n+1);\n foreach (i; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto clr = new int[] (n+1);\n clr[] = 0;\n \n bool dfs(int v, int c) {\n clr[v] = c;\n bool ok = true;\n foreach (u; g[v]) {\n if (clr[u] == 0) {\n ok &= dfs(u, 3 - c);\n } \n else if (clr[u] == 3 - c) { continue; }\n else { return false; }\n }\n \n return ok;\n }\n \n if (!dfs(1, 1)) {\n writeln(0);\n continue;\n }\n \n debug { writeln(clr); }\n \n auto side = clr.count!(x => x == 1).to!int;\n int ans = (pw[side] + pw[n - side]) % MD;\n ans.writeln;\n }\n}"}], "src_uid": "332340a793eb3ec14131948e2b6bdf2f"} {"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tlong a=0;\n\t\tlong b=0;\n\t\tlong c=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\tlong d=c/2;\n\t\twriteln(a*(c-d)-b*d);\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.format;\nimport std.math;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int t = readln.strip.to!int;\n\n while (t--)\n {\n long a, b, k;\n readf!\" %s %s %s \"(a, b, k);\n\n long ans = k / 2 * (a - b);\n if (k % 2)\n ans += a;\n\n writefln!\"%s\"(ans);\n }\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int a, b, k;\n readf(\"%s %s %s\", &a, &b, &k);\n readln;\n \n auto diff = a - b;\n auto ans = cast(long)diff * (k/2);\n \n if (k % 2 == 1) ans += a;\n \n ans.writeln;\n }\n}"}], "negative_code": [], "src_uid": "1f435ba837f59b007167419896c836ae"} {"source_code": "import std;\r\n\r\nvoid main () {\r\n\tauto n = readln.strip.to !(int);\r\n\tauto a = readln.splitter.map !(to !(long)).array;\r\n\trndGen.seed (123);\r\n\tlong first = a.front;\r\n\ta.popFront ();\r\n\trandomShuffle (a);\r\n\tfor (long u = 1; ; u++) {\r\n\t\tauto lo = max (u ^^ 2 - first, 0);\r\n\t\tauto hi = u ^^ 2 + u - first;\r\n\t\tforeach (i, ref c; a) {\r\n\t\t\tauto d = c + lo;\r\n\t\t\tauto v = cast (long) (sqrt (cast (double) (d)));\r\n\t\t\tif (d > v ^^ 2 + v) lo += (v + 1) ^^ 2 - d;\r\n\t\t\telse hi = min (hi, lo + v ^^ 2 + v - d);\r\n\t\t\tif (lo > hi) {\r\n\t\t\t\ta.swapAt (i, uniform (0, i + 1));\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (lo <= hi) {\r\n\t\t\twriteln (lo);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.random;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable long limit = 2 * 10 ^^ 6 + 5;\r\n\r\nvoid main ()\r\n{\r\n\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto used = new bool [limit];\r\n\t\tauto a = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\trndGen.seed (263_473_470);\r\n\t\tlong sel = a.front;\r\n\t\tlong cur = sel;\r\n\t\ta.popFront ();\r\n\t\trandomShuffle (a);\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tlong base = cast (long) (sqrt (cur * 1.0));\r\n\t\t\tlong lo = cast (long) (cur - base * 1L * base);\r\n\t\t\tlong hi = base;\r\n\t\t\tlong delta = cur - sel;\r\n\t\t\tforeach (i, ref c; a)\r\n\t\t\t{\r\n\t\t\t\tlong d = c + delta;\r\n\t\t\t\tlong v = cast (long) (sqrt (d * 1.0));\r\n\t\t\t\tlong w = v * 1L * v;\r\n\t\t\t\tif (d > w + v)\r\n\t\t\t\t{\r\n\t\t\t\t\tlong e = w + v * 2 + 1;\r\n\t\t\t\t\tlong add = cast (long) (e - d);\r\n\t\t\t\t\tcur += add;\r\n\t\t\t\t\tdelta += add;\r\n\t\t\t\t\tlo += add;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\thi = min (hi,\r\n\t\t\t\t\t lo + cast (long) (w + v - d));\r\n\t\t\t\t}\r\n\t\t\t\tif (lo > hi)\r\n\t\t\t\t{\r\n\t\t\t\t\ta.swapAt (i, uniform (0, i + 1));\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (lo <= hi)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tcur = (base + 1L) ^^ 2;\r\n\t\t}\r\n\t\twriteln (cur - sel);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.random;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable long limit = 2 * 10 ^^ 6 + 5;\r\n\r\nvoid main ()\r\n{\r\n\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto used = new bool [limit];\r\n\t\tauto a = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\trndGen.seed (263_473_470);\r\n\t\tlong sel = a.front;\r\n\t\tlong cur = sel;\r\n\t\ta.popFront ();\r\n\t\trandomShuffle (a);\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tlong base = cast (long) (sqrt (cur * 1.0));\r\n\t\t\tlong lo = cast (long) (cur - base * 1L * base);\r\n\t\t\tlong hi = base;\r\n\t\t\tlong delta = cur - sel;\r\n\t\t\tforeach (i, ref c; a)\r\n\t\t\t{\r\n\t\t\t\tlong d = c + delta;\r\n\t\t\t\tlong v = cast (long) (sqrt (d * 1.0));\r\n\t\t\t\tlong w = v * 1L * v;\r\n\t\t\t\tif (d > w + v)\r\n\t\t\t\t{\r\n\t\t\t\t\tlong e = w + v * 2 + 1;\r\n\t\t\t\t\tlong add = cast (long) (e - d);\r\n\t\t\t\t\tcur += add;\r\n\t\t\t\t\tdelta += add;\r\n\t\t\t\t\tlo += add;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\thi = min (hi,\r\n\t\t\t\t\t lo + cast (long) (w + v - d));\r\n\t\t\t\t}\r\n\t\t\t\tif (lo > hi)\r\n\t\t\t\t{\r\n\t\t\t\t\tswap (a[0], a[i]);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (lo <= hi)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tcur = (base + 1L) ^^ 2;\r\n\t\t}\r\n\t\twriteln (cur - sel);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.random;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable long limit = 2 * 10 ^^ 6 + 5;\r\n\r\nvoid main ()\r\n{\r\n\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto used = new bool [limit];\r\n\t\tauto a = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\trndGen.seed (263_473_470);\r\n\t\tlong sel = a.front;\r\n\t\tlong cur = sel;\r\n\t\ta.popFront ();\r\n\t\trandomShuffle (a);\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tlong base = cast (long) (sqrt (cur * 1.0));\r\n\t\t\tlong lo = cast (long) (cur - base * 1L * base);\r\n\t\t\tlong hi = base;\r\n\t\t\tlong delta = cur - sel;\r\n\t\t\tforeach (ref c; a)\r\n\t\t\t{\r\n\t\t\t\tlong d = c + delta;\r\n\t\t\t\tlong v = cast (long) (sqrt (d * 1.0));\r\n\t\t\t\tlong w = v * 1L * v;\r\n\t\t\t\tif (d > w + v)\r\n\t\t\t\t{\r\n\t\t\t\t\tlong e = w + v * 2 + 1;\r\n\t\t\t\t\tlong add = cast (long) (e - d);\r\n\t\t\t\t\tcur += add;\r\n\t\t\t\t\tdelta += add;\r\n\t\t\t\t\tlo += add;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\thi = min (hi, cast (long) (w + v - d));\r\n\t\t\t\t}\r\n\t\t\t\tif (lo > hi)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (lo <= hi)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tcur = (base + 1L) ^^ 2;\r\n\t\t}\r\n\t\twriteln (cur - sel);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.random;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int limit = 2 * 10 ^^ 6 + 5;\r\n\r\nvoid main ()\r\n{\r\n\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto used = new bool [limit];\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\trndGen.seed (263_473_470);\r\n\t\tlong sel = a.front;\r\n\t\tlong cur = sel;\r\n\t\ta.popFront ();\r\n\t\trandomShuffle (a);\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint base = cast (int) (sqrt (cur * 1.0));\r\n\t\t\tint lo = cast (int) (cur - base * 1L * base);\r\n\t\t\tint hi = base;\r\n\t\t\tlong delta = cur - sel;\r\n\t\t\tdebug {writefln !(\"considering %s [%s..%s]\")\r\n\t\t\t (cur, lo, hi);}\r\n\t\t\tforeach (ref c; a)\r\n\t\t\t{\r\n\t\t\t\tlong d = c + delta;\r\n\t\t\t\tint v = cast (int) (sqrt (d * 1.0));\r\n\t\t\t\tlong w = v * 1L * v;\r\n\t\t\t\tdebug {writefln\r\n\t\t\t\t !(\"lo = %s, %s -> %s in [%s..%s]\")\r\n\t\t\t\t (lo, c, d, w, w + v);}\r\n\t\t\t\tif (d > w + v)\r\n\t\t\t\t{\r\n\t\t\t\t\tlong e = w + v * 2 + 1;\r\n\t\t\t\t\tint add = cast (int) (e - d);\r\n\t\t\t\t\tdebug {writeln (\"add \", add);}\r\n\t\t\t\t\tcur += add;\r\n\t\t\t\t\tdebug {writeln (\"cur = \", cur);}\r\n\t\t\t\t\tdelta += add;\r\n\t\t\t\t\tlo += add;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\thi = min (hi, cast (int) (w + v - d));\r\n\t\t\t\t}\r\n\t\t\t\tif (lo > hi)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (lo <= hi)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tcur = (base + 1L) ^^ 2;\r\n\t\t\tdebug {writeln (\"cur = \", cur);}\r\n\t\t}\r\n\t\twriteln (cur - sel);\r\n\t}\r\n}\r\n"}], "src_uid": "6f31e2bc222314236d35c9642a60812e"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int [int] cnt;\n \n arr.each!(x => ++cnt[x]);\n \n int[] ans;\n foreach (i; 0 .. n) {\n auto cur = cnt.keys.maxElement();\n ans ~= cur;\n cnt[cur] -= 1;\n if (cnt[cur] == 0) cnt.remove(cur);\n \n foreach (j; 0 .. i) {\n auto now = gcd(ans[i], ans[j]);\n cnt[now] -= 2;\n if (cnt[now] == 0) cnt.remove(now);\n }\n }\n \n ans.sort();\n //debug { ans.writeln; }\n ans.writefln!(\"%(%s %)\");\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tsort (a);\n\t\tint [] r;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto cur = a.minPos !(q{a > b}).front;\n\t\t\tint [] b = [cur];\n\t\t\tforeach (p; r)\n\t\t\t{\n\t\t\t\tb ~= gcd (p, cur);\n\t\t\t}\n\t\t\tb ~= b;\n\t\t\tb ~= int.max;\n\t\t\tsort (b);\n\t\t\tfor (int j = 0, p = 0; j < a.length; j++)\n\t\t\t{\n\t\t\t\tif (b.front == a[j])\n\t\t\t\t{\n\t\t\t\t\tb.popFront ();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ta[p] = a[j];\n\t\t\t\t\tp++;\n\t\t\t\t}\n\t\t\t}\n\t\t\ta.length -= r.length * 2 + 1;\n\t\t\tr ~= cur;\n\t\t}\n\t\twritefln (\"%(%s %)\", r);\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int [int] cnt;\n \n arr.each!(x => ++cnt[x]);\n \n int[] ans;\n foreach (i; 0 .. n) {\n auto cur = cnt.keys.maxElement();\n ans ~= cur;\n cnt[cur] -= 1;\n if (cnt[cur] == 0) cnt.remove(cur);\n \n foreach (j; 0 .. i) {\n auto now = gcd(ans[i], ans[j]);\n cnt[now] -= 2;\n if (cnt[now] == 0) cnt.remove(cur);\n }\n }\n \n ans.sort();\n //debug { ans.writeln; }\n ans.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int [int] cnt;\n \n arr.each!(x => ++cnt[x]);\n \n int[] ans;\n foreach (i; 0 .. n) {\n auto cur = cnt.keys.maxElement();\n ans ~= cur;\n cnt[cur] -= 1;\n if (cnt[cur] == 0) cnt.remove(cur);\n \n foreach (j; 0 .. i) {\n auto now = gcd(ans[i], ans[j]);\n cnt[now] -= 2;\n if (cnt[now] == 0) cnt.remove(cur);\n }\n }\n \n //debug { ans.writeln; }\n ans.writefln!(\"%(%s %)\");\n}"}], "src_uid": "71dc07f0ea8962f23457af1d6509aeee"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n sort(A);\r\n bool f() {\r\n for (int i = 0; i + 1 < N; i++) {\r\n if (A[i] == A[i + 1]) return false;\r\n }\r\n return true;\r\n }\r\n writeln(f() ? \"YES\" : \"NO\");\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!long).array.sort.array;\n long prev = 0;\n bool good = true;\n foreach (x ; a) {\n if (x == prev) {\n good = false;\n break;\n }\n prev = x;\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\\n\", &t);\r\n foreach(_; 0..t) {\r\n int n;\r\n scanf(\"%d\\n\", &n);\r\n auto arr = readln.split.to!(long[]);\r\n if (arr.length == 1)\r\n writeln(\"YES\");\r\n else {\r\n if (arr.length == uniq(arr.sort).array.length)\r\n writeln(\"YES\");\r\n else\r\n writeln(\"NO\");\r\n }\r\n } \r\n}\r\n"}], "negative_code": [{"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\\n\", &t);\r\n foreach(_; 0..t) {\r\n int n;\r\n scanf(\"%d\\n\", &n);\r\n auto arr = readln.split.to!(long[]);\r\n if (arr.length == 1)\r\n writeln(\"YES\");\r\n else {\r\n if (arr.length == uniq(arr).array.length)\r\n writeln(\"YES\");\r\n else\r\n writeln(\"NO\");\r\n }\r\n } \r\n}\r\n"}], "src_uid": "288f147bb8a3c30b0bb712a01c65109b"} {"source_code": "import std.algorithm.searching : maxElement;\nimport std.range : generate, takeExactly;\nimport std.stdio : readf, readln, writeln;\nimport std.string : strip;\n\nvoid main()\n{\n int n, m; // number of students, number of questions\n readf!\"%d %d\\n\"(n, m);\n auto s = new string[n];\n foreach (i; 0..n) s[i] = readln.strip;\n\n auto total = 0;\n\n // read points for each question\n foreach (i; 0..m) {\n int a;\n char c;\n readf!\"%d%c\"(a, c);\n\n auto counts = new int[26];\n\n foreach (j; 0..n) {\n counts[s[j][i] - 'A']++;\n }\n\n total += counts.maxElement * a;\n }\n\n writeln(total);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.format;\n\nvoid main() {\n int n,m;\n readln.strip.formattedRead(\" %s %s\", n, m);\n\n string[] ans;\n\n foreach (i; 0 .. n) {\n ans ~= readln.strip;\n }\n\n int[] maxAns;\n foreach (i; 0 .. m) {\n int[26] cnt = 0;\n foreach (j; 0 .. n) {\n cnt[ans[j][i]-'A']++;\n }\n maxAns ~= cnt[].maxElement;\n }\n\n auto point = readln.split.map!(a => parse!int(a));\n\n int sum = 0;\n foreach (i; 0 .. m) {\n sum += maxAns[i] * point[i];\n }\n\n writeln(sum);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto S = N.iota.map!(_ => readln.chomp).array;\n auto A = readln.split.map!(to!long).array;\n auto cnt = new long[](5);\n long ans = 0;\n\n foreach (i; 0..M) {\n cnt[] = 0;\n foreach (j; 0..N) cnt[S[j][i]-'A'] += 1;\n ans += cnt.reduce!max * A[i];\n }\n\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "2022f53e5a88d5833e133dc3608a122c"} {"source_code": "#!/usr/bin/env rdmd\nimport std.stdio, std.string, std.conv;\nimport std.algorithm, std.array;\n\nvoid main()\n{\n for(string S; (S=readln().chomp()).length; )\n {\n auto nm = S.split().map!(to!int)();\n auto n = nm[0], m = nm[1];\n auto d = new int[3][m];\n foreach(ref a;d)\n a[] = array(readln().split().map!(to!int)().map!(\"a-1\")());\n auto c = new int[n];\n foreach(ref a;d)\n {\n auto o = 0;\n foreach(i;0..3)\n if(c[a[i]]!=0)\n o=c[a[i]]+2-i;\n foreach(i;0..3)\n c[a[i]]=(i+o)%3+1;\n }\n writeln(c.map!(to!string)().join(\" \"));\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto F = new int[][M];\n foreach (i; 0 .. M) {\n auto s = readln.chomp.split(\" \").map!(to!int).array;\n foreach (ref e; s) e--;\n F[i] = s;\n }\n\n auto X = new int[N];\n foreach (i; 0 .. M) {\n auto used = new bool[4];\n foreach (j; 0 .. 3) {\n int p = F[i][j];\n if (X[p] != 0) {\n used[ X[p] ] = true;\n }\n }\n foreach (j; 0 .. 3) {\n int p = F[i][j];\n if (X[p] != 0) continue;\n foreach (int k; 1 .. 4) {\n if (!used[k]) {\n X[p] = k;\n used[k] = true;\n break;\n }\n }\n }\n }\n writefln(\"%(%s %)\", X);\n}\n"}], "negative_code": [], "src_uid": "ee523bb4da5cb794e05fb62b7da8bb89"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tif (n == 2)\n\t\t{\n\t\t\tans[i] = 2;\n\t\t}\n\t\telse\n\t\t\tans[i] = n % 2 == 0 ? 0 : 1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\treadf(\" %d\", &a);\n\t\tif (a<4)\n\t\t{\n\t\t\twriteln(4-a);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (a%2==0)\n\t\t\t{\n\t\t\t\twriteln(0);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twriteln(1);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "178876bfe161ba9ccfd80c9310f75cbc"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int t;\n readf(\"%s\", &t);\n readln;\n\n while (t--) {\n int r, b, k;\n readf(\"%s %s %s\", &r, &b, &k);\n readln;\n \n if (r > b) { swap(r, b); }\n \n auto g = gcd(r, b);\n \n r /= g;\n b /= g;\n \n auto m = (b-1+r-1) / r;\n \n debug { writeln(m, ' ', g); }\n \n writeln(m < k ? \"OBEY\" : \"REBEL\");\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint t = rint;\n\tforeach(_; 0 .. t){\n\t\tstring ans = \"OBEY\";\n\t\tlong r = rlong, b = rlong, k = rlong;\n\t\tlong g = gcd(r, b);\n\t\tr /= g, b /= g;\n\t\tif(r > b && (r - 2) / b + 1 >= k) ans = \"REBEL\";\n\t\tif(b > r && (b - 2) / r + 1 >= k) ans = \"REBEL\";\n\t\tans.writeln;\n\t}\n\n}\nlong gcd(long a, long b){\n\tif(a < 0) a = -a;\n\tif(b == 0) return a;\n\tif(b < 0) return gcd(a, -b);\n\tif(a % b == 0) return b;\n\tif(a < b) return gcd(b, a);\n\telse return gcd(b, a % b);\n}\n"}, {"source_code": "import std.stdio;\n\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n\tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n\n\nint main()\n{\n int t;\n r(t);\n foreach(tc; 0 .. t)\n {\n long red, b, k;\n r(red, b, k);\n import std.numeric: gcd;\n long g = gcd(red, b);\n red /= g;\n b /= g;\n if (red * (k - 1) < (b - 1) || b * (k - 1) < (red - 1))\n\t{\n\t w(\"REBEL\");\n\t}\n else\n\t{\n\t w(\"OBEY\");\n\t}\n }\n return 0;\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int t;\n readf(\"%s\", &t);\n readln;\n\n while (t--) {\n int r, b, k;\n readf(\"%s %s %s\", &r, &b, &k);\n readln;\n \n if (r > b) { swap(r, b); }\n \n auto g = gcd(r, b);\n \n auto m = b / r;\n \n if (g == r && r != b) { --m; }\n \n debug { writeln(m, ' ', g); }\n \n writeln(m < k ? \"OBEY\" : \"REBEL\");\n }\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int t;\n readf(\"%s\", &t);\n readln;\n\n while (t--) {\n int r, b, k;\n readf(\"%s %s %s\", &r, &b, &k);\n readln;\n \n if (r > b) { swap(r, b); }\n \n auto g = gcd(r, b);\n \n auto m = b / r;\n \n debug { writeln(m, ' ', g); }\n \n writeln(m < k ? \"OBEY\" : \"REBEL\");\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint t = rint;\n\tforeach(_; 0 .. t){\n\t\tstring ans = \"OBAY\";\n\t\tlong r = rlong, b = rlong, k = rlong;\n\t\tlong g = gcd(r, b);\n\t\tr /= g, b /= g;\n\t\tif(r > b && (r - 2) / b + 1 >= k) ans = \"REBEL\";\n\t\tif(b > r && (b - 2) / r + 1 >= k) ans = \"REBEL\";\n\t\tans.writeln;\n\t}\n\n}\nlong gcd(long a, long b){\n\tif(a < 0) a = -a;\n\tif(b == 0) return a;\n\tif(b < 0) return gcd(a, -b);\n\tif(a % b == 0) return b;\n\tif(a < b) return gcd(b, a);\n\telse return gcd(b, a % b);\n}\n"}], "src_uid": "be141f316d6e5d9d8f09192913f4be47"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!int(N);\r\n\r\n auto mi = A.minElement;\r\n return A.sum - mi*N;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.string;\r\nimport std.algorithm;\r\n\r\nint[] rtln(T)() { return to!(T[])(strip(readln).split(\" \")); }\r\n\r\nvoid main() {\r\n int t, n, m;\r\n readf(\"%d\\n\", t);\r\n while(t--) {\r\n\t\treadln;\r\n\t\tint sum;\r\n auto b = rtln!int;\r\n\t\tint min = b.minElement;\r\n\t\tforeach (x; b)\r\n\t\t\t\tsum += (x - min);\r\n\t\twriteln(sum);\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (a.sum - a.minElement * n);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "20dd260775ea71b1fb5b42bcac90a6f2"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong [] [] s = [[0], [0], [0]];\n\t\tforeach (i, c; a)\n\t\t{\n\t\t\ts[0] ~= s[0][$ - 1] + !(i & 1) * c;\n\t\t\ts[1] ~= s[1][$ - 1] + (i & 1) * c;\n\t\t\ts[2] ~= s[1][$ - 1] - s[0][$ - 1];\n\t\t}\n\t\tlong res = 0;\n\t\tlong [2] lo = [long.max / 2, 0];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlo[i & 1] = min (lo[i & 1], s[2][i + 1]);\n\t\t\tres = max (res, s[2][i + 1] - lo[i & 1]);\n\t\t}\n\t\twriteln (res + s[0].back);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.container;\nimport std.range;\nimport std.algorithm;\n\nlong calculate_max_sum(long[] arr) {\n\tlong current = 0;\n\tlong best_res = 0; \n\tint left = 0;\n\t\n\tfor (int i = 0; i < arr.length; i++) {\n\t\tcurrent += arr[i];\n\t\twhile (left <= i && arr[left] < 0) {\n\t\t\tcurrent -= arr[left];\n\t\t\tleft++;\n\t\t}\n\t\t\n\t\tif (current < 0) {\n\t\t\tcurrent = 0; \n\t\t\tleft = i + 1;\n\t\t}\n\t\t\n\t\tbest_res = max(best_res, current);\n\t}\n\t\n\treturn best_res;\n}\n\nvoid main() {\n\tint t;\n\tscanf(\"%d\", &t);\n\t\n\twhile (t--) {\n\t\tint n; \n\t\tscanf(\"%d\", &n);\n\t\t\n\t\tlong[] arr = new long[n];\n\t\tforeach (i; iota(n)) scanf(\"%lld\", &arr[i]);\n\t\t\n\t\t// calculate the sum for even elems\n\t\tlong sum = 0; \n\t\tforeach (i, e; arr) sum += ((i + 1) % 2) * e;\n\t\t\n\t\t// sum-diff-array starting at first element \n\t\tlong[] a = new long[n / 2];\n\t\tfor (int i = 0; i + 1 < n; i += 2) {\n\t\t\ta[i / 2] = arr[i + 1] - arr[i];\n\t\t}\n\t\t\n\t\t// starting at second \n\t\tint n_odd = (n - 1) / 2;\n\t\tlong[] b = new long[n_odd];\n\t\tfor (int i = 1; i + 1 < n; i += 2) {\n\t\t\tb[i / 2] = arr[i] - arr[i + 1];\n\t\t}\n\t\t\n\t\twriteln(sum + max(calculate_max_sum(a), calculate_max_sum(b)));\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tauto b = new long[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i % 2)\n\t\t\t{\n\t\t\t\tb[i+1] = b[i] - a[i];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tb[i+1] = b[i] + a[i];\n\t\t\t}\n\t\t}\n\n\t\tauto c0 = new long[](n+1);\n\t\tauto c1 = new long[](n+1);\n\t\tc0[] = long.max;\n\t\tc1[] = long.max;\n\t\tlong tot;\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tif (i % 2)\n\t\t\t{\n\t\t\t\tc1[i] = min(c1[i+1], b[i+1]);\n\t\t\t\tc0[i] = c0[i+1];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tc0[i] = min(c0[i+1], b[i+1]);\n\t\t\t\tc1[i] = c1[i+1];\n\t\t\t\ttot += a[i];\n\t\t\t}\n\t\t}\n\t\tdebug writeln(b);\n\t\tdebug writeln(c0);\n\t\tdebug writeln(c1);\n\n\t\tans[ti] = tot;\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tlong x;\n\t\t\tif (i % 2)\n\t\t\t{\n\t\t\t\tx = -(c0[i+1] - b[i]);\n\t\t\t\tdebug writeln(\"i:\", i, \" \", c0[i+1], \" \", b[i]);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tx = -(c1[i+1] - b[i]);\n\t\t\t\tdebug writeln(\"i:\", i, \" \", c1[i+1], \" \", b[i]);\n\t\t\t}\n\n\t\t\tans[ti].chmax(tot+x);\n\t\t\tdebug writeln(\"i:\", i, \" \", ans[ti]);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "3696b769bfd32cba34e739b74e13693f"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.numeric;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tint [] [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta ~= readln.split.map !(to !(int)).array;\n\t\t}\n\n\t\tauto p = new int [n];\nmain_loop:\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tforeach (k; j + 1..n)\n\t\t\t\t{\n\t\t\t\t\tif (a[i][j] == a[i][k])\n\t\t\t\t\t{\n\t\t\t\t\t\tp[i] = a[i][j];\n\t\t\t\t\t\tcontinue main_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint v = n - 1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (p[i] == 0)\n\t\t\t{\n\t\t\t\tp[i] = v;\n\t\t\t\tv++;\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%(%s %)\", p);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.range, std.string, std.conv;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[][] t;\n for (int i = 0; i < n; i++) {\n t ~= readln.chomp.split.map!(to!int).array;\n }\n\n int[] ans;\n foreach (e; t) {\n ans ~= e.minPos!(\"a > b\")[0];\n }\n\n ans[ans.length - ans.minPos!(\"a > b\").length] = ans.length.to!int;\n\n writeln(ans.map!(to!string).join(\" \"));\n}"}, {"source_code": "import std.stdio;\nint n,i,j,k;\nint[50][50] v;\nint[50] ans;\nvoid main()\n{\n\tscanf(\" %d\",&n);\n\tfor(i=0;i<n;++i)\n\t{\n\t\tfor(j=0;j<n;++j)\n\t\t{\n\t\t\tscanf(\" %d\",&v[i][j]);\n\t\t}\n\t}\n\tfor(k=1;k<=n;++k)\n\t{\n\t\tint cnt;\n\t\tfor(i=0;i<n;++i)\n\t\t{\n\t\t\tif(ans[i]) continue;\n\t\t\tcnt=0;\n\t\t\tfor(j=0;j<n;++j) if(v[i][j]==k) ++cnt;\n\t\t\tif(cnt==n-1) break;\n\t\t}\n\t\tans[i]=k;\n\t\tfor(i=0;i<n;++i) for(j=0;j<n;++j) if(v[i][j]==k) v[i][j]=k+1;\n\t}\n\tfor(i=0;i<n;++i) writef(\"%d \",ans[i]);\n\twriteln();\n}\n"}], "negative_code": [], "src_uid": "1524c658129aaa4175208b278fdc467c"} {"source_code": "import std.stdio;\n\nlong power(long a, long b, long mod) {\n if (b && ! (a % mod)) return 0;\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod, b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n int T; readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, q, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p), q = p - 1;\n if (p == 2) {\n if (k & 1) writeln(0); else writeln(1);\n continue;\n }\n ans = (power(k, power(2, l, q) + q, p) + q) % p;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, q) + q, p) + q) * inv(ans, p) % p;\n if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;\n writeln(ans);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\n\nlong power(long a, long b, long mod) {\n if (b && ! (a % mod)) return 0;\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod, b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n int T; readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0); else writeln(1);\n continue;\n }\n ans = (power(k, power(2, l, p - 1) + p - 1, p) + p - 1) % p;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p - 1) + p - 1, p) + p - 1) * inv(ans, p) % p;\n if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;\n writeln(ans);\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nint T;\n\nlong power(long a, long b, long mod) {\n if (b && ! (a % mod)) return 0;\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod;\n b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0);\n else writeln(1);\n continue;\n }\n ans = (power(k, power(2, l, p - 1) + p - 1, p) + p - 1) % p;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p - 1) + p - 1, p) + p - 1) % p * inv(ans, p) % p;\n if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;\n writeln(ans);\n }\n return 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nint T;\n\nlong power(long a, long b, long mod) {\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod;\n b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0);\n else writeln(1);\n continue;\n }\n ans = power(k, power(2, l, p - 1), p) - 1;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p - 1), p) - 1) * inv(ans, p);\n if (k & 1) ans *= power((p >> 1) + 1, r - l, p);\n writeln(ans);\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nint T;\n\nlong power(long a, long b, long mod) {\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod;\n b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0);\n else writeln(1);\n continue;\n }\n ans = power(k, power(2, l, p), p) - 1;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p), p) - 1) * inv(ans, p);\n writeln(ans);\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nlong power(long a, long b, long mod) {\n if (b && ! (a % mod)) return 0;\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod, b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n int T; readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0); else writeln(1);\n continue;\n }\n ans = power(k, power(2, l, p - 1) + p - 1, p) + p - 1;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p - 1) + p - 1, p) + p - 1) * inv(ans, p) % p;\n if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;\n writeln(ans);\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nint T;\n\nlong power(long a, long b, long mod) {\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod;\n b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0);\n else writeln(1);\n continue;\n }\n ans = power(k, power(2, l, p), p) - 1;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p), p) - 1) * inv(ans, p);\n if (k & 1) ans *= power((p >> 1) + 1, r - l, p);\n writeln(ans);\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nint T;\n\nlong power(long a, long b, long mod) {\n if (! a) return 0;\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod;\n b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0);\n else writeln(1);\n continue;\n }\n k %= p;\n ans = power(k, power(2, l, p - 1), p) + p - 1;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p - 1), p) + p - 1) * inv(ans, p) % p;\n if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;\n writeln(ans);\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nint T;\n\nlong power(long a, long b, long mod) {\n if (! (a % mod)) return 0;\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod;\n b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0);\n else writeln(1);\n continue;\n }\n ans = (power(k, power(2, l, p - 1), p) + p - 1) % p;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p - 1), p) + p - 1) % p * inv(ans, p) % p;\n if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;\n writeln(ans);\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nint T;\n\nlong power(long a, long b, long mod) {\n if (! a) return 0;\n long ret = 1;\n while (b) {\n if (b & 1) (ret *= a) %= mod;\n (a *= a) %= mod;\n b >>= 1;\n }\n return ret;\n}\n\nlong inv(long a, long p) {\n return power(a, p - 2, p);\n}\n\nint main() {\n readf(\" %d\", &T);\n while (T--) {\n long k, l, r, p, ans;\n readf(\" %d %d %d %d\", &k, &l, &r, &p);\n if (p == 2) {\n if (k & 1) writeln(0);\n else writeln(1);\n continue;\n }\n k %= p;\n ans = (power(k, power(2, l, p - 1), p) + p - 1) % p;\n if (! ans) ans = power(2, r - l + 1, p);\n else ans = (power(k, power(2, r + 1, p - 1), p) + p - 1) % p * inv(ans, p) % p;\n if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;\n writeln(ans);\n }\n return 0;\n}\n"}], "src_uid": "1c0dbbcfbf5e9ded42e86660272dc8e3"} {"source_code": "import std.stdio,std.range,std.algorithm,std.regex,std.conv,std.string;\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\nvoid main()\n{\n\tint t;\n\twhile(input(&t))\n\t{\n\t\tforeach(gg;0..t)\n\t\t{\n\t\t\tint n;\n\t\t\tinput(&n);\n\t\t\tauto aut=arread!string;\n\t\t\tint m;\n\t\t\tinput(&m);\n\t\t\tauto a=new int[m], g=new int[][m],mes=new string[m];\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tauto s=readln.strip;\n\t\t\t\tmes[i]=s;\n\t\t\t\tif(s[0]=='?')\n\t\t\t\t{\n\t\t\t\t\ta[i]=-1;\n\t\t\t\t\tauto f=s[2..$].split(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto f=s.split(regex(\"[ ?.,:!]+\"));;\n\t\t\t\t\ta[i]=aut.countUntil(f.front);\n\t\t\t\t\tf.popFront;\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[105][105] dp, table;\n\t\t\tforeach(ref i;table)i[]=-1;\n\t\t\tint go(int p,int prev)\n\t\t\t{\n\t\t\t\tif(p==m)return true;\n\t\t\t\tint ans=table[p][prev];\n\t\t\t\tif(ans!=-1)return ans;\n\t\t\t\tans=0;\n\t\t\t\tforeach(i;0..n)\n\t\t\t\t{\n\t\t\t\t\tif((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;\n\t\t\t\t\tif(go(p+1,i))\n\t\t\t\t\t{\n\t\t\t\t\t\tans=true;\n\t\t\t\t\t\tdp[p][prev]=i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn table[p][prev]=ans;\n\t\t\t}\n\t\t\tauto o=go(0,0);\n\t\t\tif(!o){writeln(\"Impossible\");continue;}\n\t\t\tint cur=0;\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tint x=dp[i][cur];\n\t\t\t\ta[i]=cur=x;\n\t\t\t}\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tif(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);\n\t\t\t\telse writeln(mes[i]);\n\t\t\t}\n\t\t}\n\t}\n}", "positive_code": [{"source_code": "import std.stdio,std.range,std.algorithm,std.regex,std.conv,std.string;\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\nvoid main()\n{\n\tint t;\n\twhile(input(&t))\n\t{\n\t\tforeach(gg;0..t)\n\t\t{\n\t\t\tint n;\n\t\t\tinput(&n);\n\t\t\tauto aut=arread!string;\n\t\t\tint m;\n\t\t\tinput(&m);\n\t\t\tauto a=new int[m], g=new int[][m],mes=new string[m];\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tauto s=readln.strip;\n\t\t\t\tmes[i]=s;\n\t\t\t\tif(s[0]=='?')\n\t\t\t\t{\n\t\t\t\t\ta[i]=-1;\n\t\t\t\t\tauto f=s[2..$].splitter(ctRegex!(\"[ ?.,:!]+\"));\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto f=s.splitter(ctRegex!(\"[ ?.,:!]+\"));;\n\t\t\t\t\ta[i]=aut.countUntil(f.front);\n\t\t\t\t\tf.popFront;\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[105][105] dp, table;\n\t\t\tforeach(ref i;table)i[]=-1;\n\t\t\tint go(int p,int prev)\n\t\t\t{\n\t\t\t\tif(p==m)return true;\n\t\t\t\tint ans=table[p][prev];\n\t\t\t\tif(ans!=-1)return ans;\n\t\t\t\tans=0;\n\t\t\t\tforeach(i;0..n)\n\t\t\t\t{\n\t\t\t\t\tif((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;\n\t\t\t\t\tif(go(p+1,i))\n\t\t\t\t\t{\n\t\t\t\t\t\tans=true;\n\t\t\t\t\t\tdp[p][prev]=i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn table[p][prev]=ans;\n\t\t\t}\n\t\t\tauto o=go(0,0);\n\t\t\tif(!o){writeln(\"Impossible\");continue;}\n\t\t\tint cur=0;\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tint x=dp[i][cur];\n\t\t\t\ta[i]=cur=x;\n\t\t\t}\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tif(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);\n\t\t\t\telse writeln(mes[i]);\n\t\t\t}\n\t\t}\n\t}\n}"}, {"source_code": "import std.stdio,std.range,std.algorithm,std.string,std.regex,std.conv;\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nvoid main()\n{\n\tint t;\n\tloop:while(input(&t))\n\t{\n\t\tforeach(gg;0..t)\n\t\t{\n\t\t\tint n;\n\t\t\tinput(&n);\n\t\t\treadln;\n\t\t\tauto aut=arread!string;\n\t\t\tint m;\n\t\t\tinput(&m);\n\t\t\treadln;\n\t\t\tauto a=new int[m];\n\t\t\tauto g=new int[][m];\n\t\t\tauto mes=new string[m];\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tauto s=readln.strip;\n\t\t\t\tmes[i]=s;\n\t\t\t\tif(s[0]=='?')\n\t\t\t\t{\n\t\t\t\t\ta[i]=-1;\n\t\t\t\t\tauto f=s[2..$].strip.split(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto f=s.strip.split(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\ta[i]=aut.countUntil(f.front);\n\t\t\t\t\tf.popFront;\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[105][105] dp, table;\n\t\t\tforeach(ref i;table)i[]=-1;\n\t\t\tint go(int p,int prev)\n\t\t\t{\n\t\t\t\tif(p==m)return true;\n\t\t\t\tint ans=table[p][prev];\n\t\t\t\tif(ans!=-1)return ans;\n\t\t\t\tans=0;\n\t\t\t\tforeach(i;0..n)\n\t\t\t\t{\n\t\t\t\t\tif((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;\n\t\t\t\t\tif(go(p+1,i))\n\t\t\t\t\t{\n\t\t\t\t\t\tans=true;\n\t\t\t\t\t\tdp[p][prev]=i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn table[p][prev]=ans;\n\t\t\t}\n\t\t\tauto o=go(0,0);\n\t\t\tif(!o){writeln(\"Impossible\");continue;}\n\t\t\tint cur=0;\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tint x=dp[i][cur];\n\t\t\t\ta[i]=cur=x;\n\t\t\t}\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tif(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);\n\t\t\t\telse writeln(mes[i]);\n\t\t\t}\n\t\t}\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias mp=make_pair;\nalias bins=binary_search;\nalias orsq=orient_square;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tpair!(X,Y) opAssign(A,B)(pair!(A,B) val)\n\t{\n\t\treturn this=pair!(X,Y)(val);\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe \n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nstruct Tree(T,alias arg=\"a+b\")\n{\n\tprivate alias fun=binaryFun!arg;\n\tprivate static const size_t n=size_t.max>>1;\n\tprivate T[size_t] t;\n\tthis(this){t=t.dup;}\n\tthis(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))\n\t{\n\t\tforeach(pos,i;range) upd(pos,i);\n\t}\n\tthis(R,alias f)(Tree!(R,f) q) if(is(R:T))\n\t{\n\t\tforeach(i,j;q.t)\n\t\t{\n\t\t\tt[i]=j;\n\t\t}\n\t}\n\tTree!(T,arg) opAssign(R)(R val)\n\t{\n\t\treturn this=Tree!(T,arg)(val);\n\t}\n\tprivate void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)\n\t{\n\t\tif (vr - vl == 1){t[v] = x;return;}\n\t\tsize_t vm = (vl + vr) >> 1;\n\t\tif(i < vm) upd(2*v, vl, vm, i, x);\n\t\telse upd(2*v+1, vm, vr, i, x);\n\t\tif(v*2+1 !in t)t[v]=t[v*2];\n\t\telse if (v*2 !in t)t[v]=t[v*2+1];\n\t\telse t[v]=fun(t[v*2],t[v*2+1]);\n\t}\n\tvoid upd(in size_t i,in T x)\n\t{\n\t\tassert(i>=0 && i<n);\n\t\tupd(1,0,n,i,x);\n\t}\n\tprivate T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)\n\t{\n\t\tif(vl==l && r==vr) return t[v];\n\t\tsize_t vm=(vl+vr) >> 1;\n\t\tif(r<=vm) return cel(2*v,vl,vm,l,r);\n\t\telse if(l>=vm) return cel(2*v+1,vm,vr,l,r);\n\t\telse return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));\n\t}\n\tT cel(in size_t l,in size_t r){\n\t\tassert(l<=r && l>=0 && r<n);\n\t\treturn cel(1,0,n,l,r);\n\t}\n};\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint t;\n\tloop:while(input(&t))\n\t{\n\t\tforeach(gg;0..t)\n\t\t{\n\t\t\tint n;\n\t\t\tinput(&n);\n\t\t\treadln;\n\t\t\tauto aut=arread!string;\n\t\t\tint m;\n\t\t\tinput(&m);\n\t\t\treadln;\n\t\t\tauto a=new int[m];\n\t\t\tauto g=new int[][m];\n\t\t\tauto mes=new string[m];\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tauto s=readln.strip;\n\t\t\t\tmes[i]=s;\n\t\t\t\tif(s[0]=='?')\n\t\t\t\t{\n\t\t\t\t\ta[i]=-1;\n\t\t\t\t\tauto f=s[2..$].splitter(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto f=s.splitter(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\ta[i]=aut.countUntil(f.front);\n\t\t\t\t\tf.popFront;\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint dp[105][105];\n\t\t\tint table[105][105];\n\t\t\tforeach(ref i;table)i[]=-1;\n\t\t\tint go(int p,int prev)\n\t\t\t{\n\t\t\t\tif(p==m)return true;\n\t\t\t\tint ans=table[p][prev];\n\t\t\t\tif(ans!=-1)return ans;\n\t\t\t\tans=0;\n\t\t\t\tforeach(i;0..n)\n\t\t\t\t{\n\t\t\t\t\tif((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;\n\t\t\t\t\tif(go(p+1,i))\n\t\t\t\t\t{\n\t\t\t\t\t\tans=true;\n\t\t\t\t\t\tdp[p][prev]=i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn table[p][prev]=ans;\n\t\t\t}\n\t\t\tauto o=go(0,0);\n\t\t\tif(!o){writeln(\"Impossible\");continue;}\n\t\t\tint cur=0;\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tint x=dp[i][cur];\n\t\t\t\ta[i]=cur=x;\n\t\t\t}\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tif(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);\n\t\t\t\telse writeln(mes[i]);\n\t\t\t}\n\t\t}\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias mp=make_pair;\nalias bins=binary_search;\nalias orsq=orient_square;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tpair!(X,Y) opAssign(A,B)(pair!(A,B) val)\n\t{\n\t\treturn this=pair!(X,Y)(val);\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe \n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nstruct Tree(T,alias arg=\"a+b\")\n{\n\tprivate alias fun=binaryFun!arg;\n\tprivate static const size_t n=size_t.max>>1;\n\tprivate T[size_t] t;\n\tthis(this){t=t.dup;}\n\tthis(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))\n\t{\n\t\tforeach(pos,i;range) upd(pos,i);\n\t}\n\tthis(R,alias f)(Tree!(R,f) q) if(is(R:T))\n\t{\n\t\tforeach(i,j;q.t)\n\t\t{\n\t\t\tt[i]=j;\n\t\t}\n\t}\n\tTree!(T,arg) opAssign(R)(R val)\n\t{\n\t\treturn this=Tree!(T,arg)(val);\n\t}\n\tprivate void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)\n\t{\n\t\tif (vr - vl == 1){t[v] = x;return;}\n\t\tsize_t vm = (vl + vr) >> 1;\n\t\tif(i < vm) upd(2*v, vl, vm, i, x);\n\t\telse upd(2*v+1, vm, vr, i, x);\n\t\tif(v*2+1 !in t)t[v]=t[v*2];\n\t\telse if (v*2 !in t)t[v]=t[v*2+1];\n\t\telse t[v]=fun(t[v*2],t[v*2+1]);\n\t}\n\tvoid upd(in size_t i,in T x)\n\t{\n\t\tassert(i>=0 && i<n);\n\t\tupd(1,0,n,i,x);\n\t}\n\tprivate T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)\n\t{\n\t\tif(vl==l && r==vr) return t[v];\n\t\tsize_t vm=(vl+vr) >> 1;\n\t\tif(r<=vm) return cel(2*v,vl,vm,l,r);\n\t\telse if(l>=vm) return cel(2*v+1,vm,vr,l,r);\n\t\telse return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));\n\t}\n\tT cel(in size_t l,in size_t r){\n\t\tassert(l<=r && l>=0 && r<n);\n\t\treturn cel(1,0,n,l,r);\n\t}\n};\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint t;\n\tloop:while(input(&t))\n\t{\n\t\tforeach(gg;0..t)\n\t\t{\n\t\t\tint n;\n\t\t\tinput(&n);\n\t\t\treadln;\n\t\t\tauto aut=arread!string;\n\t\t\tint m;\n\t\t\tinput(&m);\n\t\t\treadln;\n\t\t\tauto a=new int[m];\n\t\t\tauto g=new int[][m];\n\t\t\tauto mes=new string[m];\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tauto s=readln.strip;\n\t\t\t\tmes[i]=s;\n\t\t\t\tif(s[0]=='?')\n\t\t\t\t{\n\t\t\t\t\ta[i]=-1;\n\t\t\t\t\tauto f=s[2..$].strip.split(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto f=s.strip.split(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\ta[i]=aut.countUntil(f.front);\n\t\t\t\t\tf.popFront;\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint dp[105][105];\n\t\t\tint table[105][105];\n\t\t\tforeach(ref i;table)i[]=-1;\n\t\t\tint go(int p,int prev)\n\t\t\t{\n\t\t\t\tif(p==m)return true;\n\t\t\t\tint ans=table[p][prev];\n\t\t\t\tif(ans!=-1)return ans;\n\t\t\t\tans=0;\n\t\t\t\tforeach(i;0..n)\n\t\t\t\t{\n\t\t\t\t\tif((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;\n\t\t\t\t\tif(go(p+1,i))\n\t\t\t\t\t{\n\t\t\t\t\t\tans=true;\n\t\t\t\t\t\tdp[p][prev]=i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn table[p][prev]=ans;\n\t\t\t}\n\t\t\tauto o=go(0,0);\n\t\t\tif(!o){writeln(\"Impossible\");continue;}\n\t\t\tint cur=0;\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tint x=dp[i][cur];\n\t\t\t\ta[i]=cur=x;\n\t\t\t}\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tif(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);\n\t\t\t\telse writeln(mes[i]);\n\t\t\t}\n\t\t}\n\t}\n}"}, {"source_code": "import std.stdio,std.range,std.algorithm,std.string,std.regex,std.conv;\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nvoid main()\n{\n\tint t;\n\twhile(input(&t))\n\t{\n\t\tforeach(gg;0..t)\n\t\t{\n\t\t\tint n;\n\t\t\tinput(&n);\n\t\t\treadln;\n\t\t\tauto aut=arread!string;\n\t\t\tint m;\n\t\t\tinput(&m);\n\t\t\treadln;\n\t\t\tauto a=new int[m], g=new int[][m],mes=new string[m];\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tauto s=readln.strip;\n\t\t\t\tmes[i]=s;\n\t\t\t\tif(s[0]=='?')\n\t\t\t\t{\n\t\t\t\t\ta[i]=-1;\n\t\t\t\t\tauto f=s[2..$].split(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto f=s.split(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\ta[i]=aut.countUntil(f.front);\n\t\t\t\t\tf.popFront;\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[105][105] dp, table;\n\t\t\tforeach(ref i;table)i[]=-1;\n\t\t\tint go(int p,int prev)\n\t\t\t{\n\t\t\t\tif(p==m)return true;\n\t\t\t\tint ans=table[p][prev];\n\t\t\t\tif(ans!=-1)return ans;\n\t\t\t\tans=0;\n\t\t\t\tforeach(i;0..n)\n\t\t\t\t{\n\t\t\t\t\tif((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;\n\t\t\t\t\tif(go(p+1,i))\n\t\t\t\t\t{\n\t\t\t\t\t\tans=true;\n\t\t\t\t\t\tdp[p][prev]=i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn table[p][prev]=ans;\n\t\t\t}\n\t\t\tauto o=go(0,0);\n\t\t\tif(!o){writeln(\"Impossible\");continue;}\n\t\t\tint cur=0;\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tint x=dp[i][cur];\n\t\t\t\ta[i]=cur=x;\n\t\t\t}\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tif(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);\n\t\t\t\telse writeln(mes[i]);\n\t\t\t}\n\t\t}\n\t}\n}"}], "negative_code": [{"source_code": "import std.stdio,std.range,std.algorithm,std.regex,std.conv;\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\nvoid main()\n{\n\tint t;\n\twhile(input(&t))\n\t{\n\t\tforeach(gg;0..t)\n\t\t{\n\t\t\tint n;\n\t\t\tinput(&n);\n\t\t\tauto aut=arread!string;\n\t\t\tint m;\n\t\t\tinput(&m);\n\t\t\tauto a=new int[m], g=new int[][m],mes=new string[m];\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tauto s=readln;\n\t\t\t\tmes[i]=s;\n\t\t\t\tif(s[0]=='?')\n\t\t\t\t{\n\t\t\t\t\ta[i]=-1;\n\t\t\t\t\tauto f=s[2..$].splitter(ctRegex!(\"[ ?.,:!\\n]+\"));\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto f=s.splitter(ctRegex!(\"[ ?.,:!\\n]+\"));;\n\t\t\t\t\ta[i]=aut.countUntil(f.front);\n\t\t\t\t\tf.popFront;\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[105][105] dp, table;\n\t\t\tforeach(ref i;table)i[]=-1;\n\t\t\tint go(int p,int prev)\n\t\t\t{\n\t\t\t\tif(p==m)return true;\n\t\t\t\tint ans=table[p][prev];\n\t\t\t\tif(ans!=-1)return ans;\n\t\t\t\tans=0;\n\t\t\t\tforeach(i;0..n)\n\t\t\t\t{\n\t\t\t\t\tif((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;\n\t\t\t\t\tif(go(p+1,i))\n\t\t\t\t\t{\n\t\t\t\t\t\tans=true;\n\t\t\t\t\t\tdp[p][prev]=i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn table[p][prev]=ans;\n\t\t\t}\n\t\t\tauto o=go(0,0);\n\t\t\tif(!o){writeln(\"Impossible\");continue;}\n\t\t\tint cur=0;\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tint x=dp[i][cur];\n\t\t\t\ta[i]=cur=x;\n\t\t\t}\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tif(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);\n\t\t\t\telse writeln(mes[i]);\n\t\t\t}\n\t\t}\n\t}\n}"}, {"source_code": "import std.stdio,std.range,std.algorithm,std.regex,std.conv;\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\nvoid main()\n{\n\tint t;\n\twhile(input(&t))\n\t{\n\t\tforeach(gg;0..t)\n\t\t{\n\t\t\tint n;\n\t\t\tinput(&n);\n\t\t\tauto aut=arread!string;\n\t\t\tint m;\n\t\t\tinput(&m);\n\t\t\tauto a=new int[m], g=new int[][m],mes=new string[m];\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tauto s=readln;\n\t\t\t\tmes[i]=s;\n\t\t\t\tif(s[0]=='?')\n\t\t\t\t{\n\t\t\t\t\ta[i]=-1;\n\t\t\t\t\tauto f=s[2..$].splitter(ctRegex!(\"[ ?.,:!]+\"));\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto f=s.split(regex(\"[ ?.,:!]+\"));\n\t\t\t\t\ta[i]=aut.countUntil(f.front);\n\t\t\t\t\tf.popFront;\n\t\t\t\t\tforeach(j;f)\n\t\t\t\t\t{\n\t\t\t\t\t\tint k=countUntil(aut,j);\n\t\t\t\t\t\tif(k!=-1)g[i]~=k;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[105][105] dp, table;\n\t\t\tforeach(ref i;table)i[]=-1;\n\t\t\tint go(int p,int prev)\n\t\t\t{\n\t\t\t\tif(p==m)return true;\n\t\t\t\tint ans=table[p][prev];\n\t\t\t\tif(ans!=-1)return ans;\n\t\t\t\tans=0;\n\t\t\t\tforeach(i;0..n)\n\t\t\t\t{\n\t\t\t\t\tif((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;\n\t\t\t\t\tif(go(p+1,i))\n\t\t\t\t\t{\n\t\t\t\t\t\tans=true;\n\t\t\t\t\t\tdp[p][prev]=i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn table[p][prev]=ans;\n\t\t\t}\n\t\t\tauto o=go(0,0);\n\t\t\tif(!o){writeln(\"Impossible\");continue;}\n\t\t\tint cur=0;\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tint x=dp[i][cur];\n\t\t\t\ta[i]=cur=x;\n\t\t\t}\n\t\t\tforeach(i;0..m)\n\t\t\t{\n\t\t\t\tif(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);\n\t\t\t\telse writeln(mes[i]);\n\t\t\t}\n\t\t}\n\t}\n}"}], "src_uid": "3ac91d8fc508ee7d1afcf22ea4b930e4"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.typecons, std.math;\n\nalias Point = Tuple!(long, long);\n\nlong distance(Point a, Point b)\n{\n return abs(a[0] - b[0]) + abs(a[1] - b[1]);\n}\n\nlong distance3(Point start, Point a, Point b)\n{\n// writeln(start);\n long tmp1 = distance(start, a) + distance(a, b);\n long tmp2 = distance(start, b) + distance(b, a);\n// long tmp3 = distance(start, a) + distance(start, b);\n// writeln(tmp1);\n// writeln(tmp2);\n// writeln(tmp3);\n// return min(tmp1, tmp2, tmp3);\n return min(tmp1, tmp2);\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n\n while (t--) {\n long n, m, i, j;\n readf!\" %d %d %d %d \"(n, m, i, j);\n i -= 1;\n j -= 1;\n auto start = Point(i, j);\n Point c0 = Point(0, 0);\n Point c1 = Point(0, m - 1);\n Point c2 = Point(n - 1, 0);\n Point c3 = Point(n - 1, m - 1);\n\n Point c4 = Point(i, 0);\n Point c5 = Point(i, m - 1);\n\n// auto x = [c0, c1, c2, c3];\n// writeln(x.permutations);\n long max = -1;\n Point p1, p2;\n foreach (x ; [c0, c1, c2, c3].permutations) {\n long dist = distance3(start, x[0], x[1]);\n if (dist > max) {\n max = dist;\n p1 = x[0];\n p2 = x[1];\n }\n }\n writefln(\"%d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);\n// writefln(\"%d %d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);\n }\n// writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));\n// writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1537/problem/B\n// \nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\nwhile(t--) {\n long n, m, i, j;\n readf(\"%s %s %s %s\\n\", &n, &m, &i, &j);\n if(m - j > j - 1) {\n writefln(\"%s %s %s %s\", n, 1, 1, m);\n } else {\n writefln(\"%s %s %s %s\", n, m, 1, 1);\n }\n}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.typecons, std.math;\n\nalias Point = Tuple!(long, long);\n\nlong distance(Point a, Point b)\n{\n return abs(a[0] - b[0]) + abs(a[1] - b[1]);\n}\n\nlong distance3(Point start, Point a, Point b)\n{\n// writeln(start);\n long tmp1 = distance(start, a) + distance(a, b);\n long tmp2 = distance(start, b) + distance(b, a);\n long tmp3 = distance(start, a) + distance(start, b);\n// writeln(tmp1);\n// writeln(tmp2);\n// writeln(tmp3);\n return min(tmp1, tmp2, tmp3);\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n\n while (t--) {\n long n, m, i, j;\n readf!\" %d %d %d %d \"(n, m, i, j);\n i -= 1;\n j -= 1;\n auto start = Point(i, j);\n Point c0 = Point(0, 0);\n Point c1 = Point(0, m - 1);\n Point c2 = Point(n - 1, 0);\n Point c3 = Point(n - 1, m - 1);\n\n Point c4 = Point(i, 0);\n Point c5 = Point(i, m - 1);\n\n// auto x = [c0, c1, c2, c3];\n// writeln(x.permutations);\n long max = -1;\n Point p1, p2;\n foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {\n long dist = distance3(start, x[0], x[1]);\n if (dist > max) {\n max = dist;\n p1 = x[0];\n p2 = x[1];\n }\n }\n writefln(\"%d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);\n// writefln(\"%d %d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);\n }\n// writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.typecons, std.math;\n\nalias Point = Tuple!(long, long);\n\nlong distance(Point a, Point b)\n{\n return abs(a[0] - b[0]) + abs(a[1] - b[1]);\n}\n\nlong distance3(Point start, Point a, Point b)\n{\n writeln(start);\n long tmp1 = distance(start, a) + distance(a, b);\n long tmp2 = distance(start, b) + distance(b, a);\n long tmp3 = distance(start, a) + distance(start, b);\n writeln(tmp1);\n writeln(tmp2);\n writeln(tmp3);\n return min(tmp1, tmp2, tmp3);\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n\n while (t--) {\n long n, m, i, j;\n readf!\" %d %d %d %d \"(n, m, i, j);\n i -= 1;\n j -= 1;\n auto start = Point(i, j);\n Point c0 = Point(0, 0);\n Point c1 = Point(0, m - 1);\n Point c2 = Point(n - 1, 0);\n Point c3 = Point(n - 1, m - 1);\n\n Point c4 = Point(i, 0);\n Point c5 = Point(i, m - 1);\n\n// auto x = [c0, c1, c2, c3];\n// writeln(x.permutations);\n long max = -1;\n Point p1, p2;\n foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {\n long tmp1 = distance(start, x[0]) + distance(x[0], x[1]);\n long tmp2 = distance(start, x[1]) + distance(x[1], x[0]);\n long tmp3 = distance(start, x[0]) + distance(start, x[1]);\n if (min(tmp1, tmp2, tmp3) > max) {\n max = min(tmp1, tmp2, tmp3);\n p1 = x[0];\n p2 = x[1];\n }\n }\n writefln(\"%d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);\n// writefln(\"%d %d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);\n }\n// writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.typecons, std.math;\n\nalias Point = Tuple!(int, int);\n\nint distance(Point a, Point b)\n{\n return abs(a[0] - b[0]) + abs(a[1] - b[1]);\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n\n while (t--) {\n int n, m, i, j;\n readf!\" %d %d %d %d \"(n, m, i, j);\n i -= 1;\n j -= 1;\n auto start = Point(i, j);\n Point c0 = Point(0, 0);\n Point c1 = Point(0, m - 1);\n Point c2 = Point(n - 1, 0);\n Point c3 = Point(n - 1, m - 1);\n// auto x = [c0, c1, c2, c3];\n// writeln(x.permutations);\n int max = -1;\n Point p1, p2;\n foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {\n int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);\n int tmp2 = distance(start, x[1]) + distance(x[1], x[0]);\n int tmp3 = distance(start, x[0]) + distance(start, x[1]);\n if (min(tmp1, tmp2, tmp3) > max) {\n max = min(tmp1, tmp2, tmp3);\n p1 = x[0];\n p2 = x[1];\n }\n }\n writefln(\"%d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.typecons, std.math;\n\nalias Point = Tuple!(int, int);\n\nint distance(Point a, Point b)\n{\n return abs(a[0] - b[0]) + abs(a[1] - b[1]);\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n\n while (t--) {\n int n, m, i, j;\n readf!\" %d %d %d %d \"(n, m, i, j);\n i -= 1;\n j -= 1;\n auto start = Point(i, j);\n Point c0 = Point(0, 0);\n Point c1 = Point(0, m - 1);\n Point c2 = Point(n - 1, 0);\n Point c3 = Point(n - 1, m - 1);\n// auto x = [c0, c1, c2, c3];\n// writeln(x.permutations);\n int max = -1;\n Point p1, p2;\n foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {\n int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);\n int tmp2 = distance(start, x[1]) + distance(x[0], x[1]);\n if (min(tmp1, tmp2) > max) {\n max = min(tmp1, tmp2);\n p1 = x[0];\n p2 = x[1];\n }\n }\n writefln(\"%d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.typecons, std.math;\n\nalias Point = Tuple!(int, int);\n\nint distance(Point a, Point b)\n{\n return abs(a[0] - b[0]) + abs(a[1] - b[1]);\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n\n while (t--) {\n int n, m, i, j;\n readf!\" %d %d %d %d \"(n, m, i, j);\n auto start = Point(i, j);\n Point c0 = Point(0, 0);\n Point c1 = Point(0, m - 1);\n Point c2 = Point(n - 1, 0);\n Point c3 = Point(n - 1, m - 1);\n// auto x = [c0, c1, c2, c3];\n// writeln(x.permutations);\n int max = -1;\n Point p1, p2;\n foreach (x ; [c0, c1, c2, c3].permutations) {\n int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);\n int tmp2 = distance(start, x[1]) + distance(x[0], x[1]);\n if (min(tmp1, tmp2) > max) {\n max = min(tmp1, tmp2);\n p1 = x[0];\n p2 = x[1];\n }\n }\n writefln(\"%d %d %d %d\", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);\n }\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1537/problem/B\n// \nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\nwhile(t--) {\n long n, m, i, j;\n readf(\"%s %s %s %s\\n\", &n, &m, &i, &j);\n if(n - i < i - 1) {\n writefln(\"%s %s %s %s\", n, n, 1, 1);\n } else {\n writefln(\"%s %s %s %s\", 1, n, n, 1);\n }\n}\n}\n"}], "src_uid": "5aae6b27f35852512a250751ef957ab9"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else static if (isAggregateType!(T[i]))\n {\n static foreach(fieldName; FieldNameTuple!(T[i]))\n {\n static if (hasUDA!(mixin(text(T[i].stringof, \".\", fieldName)), string))\n {\n with(t[i])\n {\n mixin(q{t[i].}, fieldName, q{.length}) =\n cast(size_t) mixin(getUDAs!(mixin(text(T[i].stringof, \".\", fieldName)), string)[0]);\n }\n }\n read(mixin(text(q{t[i].}, fieldName)));\n }\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nE[] makeSlice(E, S)(S size, lazy E value)\n{\n auto a = new E[size.ind];\n foreach(ref ai; a)\n ai = value();\n return a;\n}\n\nE[] makeSlice(E, S)(S size = 0)\n{\n return new E[size.ind];\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n testCase:foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nalias type = multi;\nstruct TestCase\n{\n long n;\n @(\"n\") long[] a;\n\n void solve(long i = -1)\n {\n sort(a);\n if (iota(0, n - 1).all!(i => a.at(i + 1) - a.at(i) <= 1))\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\ta.sort();\n\n\t\tbool ok = true;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] - a[i-1] > 1)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else static if (isAggregateType!(T[i]))\n {\n static foreach(fieldName; FieldNameTuple!(T[i]))\n {\n static if (hasUDA!(mixin(text(T[i].stringof, \".\", fieldName)), string))\n {\n with(t[i])\n {\n mixin(q{t[i].}, fieldName, q{.length}) =\n cast(size_t) mixin(getUDAs!(mixin(text(T[i].stringof, \".\", fieldName)), string)[0]);\n }\n }\n read(mixin(text(q{t[i].}, fieldName)));\n }\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nE[] makeSlice(E, S)(S size, lazy E value)\n{\n auto a = new E[size.ind];\n foreach(ref ai; a)\n ai = value();\n return a;\n}\n\nE[] makeSlice(E, S)(S size = 0)\n{\n return new E[size.ind];\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n testCase:foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nalias type = multi;\nstruct TestCase\n{\n long n;\n @(\"n\") long[] a;\n\n void solve(long i = -1)\n {\n auto m = a.fold!min(long.max);\n if (a.any!(ai => ai != m && ai != m + 1))\n writeln(\"NO\");\n else\n writeln(\"YES\");\n }\n}\n\nvoid main()\n{\n type;\n}\n"}], "src_uid": "ed449ba7c453a43e2ac5904dc0174530"} {"source_code": "import std.stdio, std.string;\r\nimport std.random, std.algorithm;\r\nimport std.numeric, std.math;\r\nimport std.range, std.array;\r\nimport std.typecons, std.conv;\r\n \r\nint main(string[] args)\r\n{\r\n auto n = to!int(readln.strip);\r\n auto p = new int[n];\r\n auto q = new int[n];\r\n auto prev = new int[n];\r\n fill(prev, -1);\r\n foreach (i; 0 .. n)\r\n {\r\n q[i] = 2;\r\n foreach (j; 0 .. n) if (j != i) q[j] = 1;\r\n writeln(\"? \", join(map!(to!string)(q), \" \"));\r\n stdout.flush;\r\n auto ridx = to!int(readln.strip);\r\n if (ridx != 0 && ridx != i + 1) prev[ridx - 1] = i;\r\n q[i] = 1;\r\n foreach (j; 0 .. n) if (j != i) q[j] = 2;\r\n writeln(\"? \", join(map!(to!string)(q), \" \"));\r\n stdout.flush;\r\n ridx = to!int(readln.strip);\r\n if (ridx != 0 && ridx != i + 1) prev[i] = ridx - 1;\r\n }\r\n auto f = new bool[n];\r\n foreach (i; 0 .. n) if (prev[i] != -1) f[prev[i]] = true;\r\n auto idx = -1;\r\n foreach (i; 0 .. n) if (!f[i])\r\n {\r\n idx = i;\r\n break;\r\n }\r\n p[idx] = n;\r\n foreach (i; 0 .. n - 1)\r\n {\r\n p[prev[idx]] = p[idx] - 1;\r\n idx = prev[idx];\r\n }\r\n writeln(\"! \", join(map!(to!string)(p), \" \"));\r\n stdout.flush;\r\n return 0;\r\n}", "positive_code": [{"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tauto next = new int[](n+1);\n\tauto prev = new int[](n+1);\n\tint zero = 0;\n\tvoid get(int i)\n\t{\n\t\tint answer = void;\n\t\twrite (\"? \");\n\t\tforeach(j; 1 .. n+1)\n\t\t{\n\t\t\twrite (int(i == j)+1, \" \");\n\t\t}\n\t\twriteln;\n\t\tstdout.flush;\n\t\tanswer = readInt!int;\n\t\tif (answer == 0)\n\t\t{\n\t\t\tnext[i] = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (answer < i)\n\t\t\t{\n\t\t\t\tnext[i] = answer;\n\t\t\t\tprev[answer] = i;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert(answer == i);\n\t\t\t}\n\t\t}\n\t\t\n\t\twrite (\"? \");\n\t\tforeach(j; 1 .. n+1)\n\t\t{\n\t\t\twrite (int(i != j)+1, \" \");\n\t\t}\n\t\twriteln;\n\t\tstdout.flush;\n\t\tanswer = readInt!int;\n\t\tif (answer == 0)\n\t\t{\n\t\t\tprev[i] = 0;\n\t\t\tzero = i;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (answer < i)\n\t\t\t{\n\t\t\t\tprev[i] = answer;\n\t\t\t\tnext[answer] = i;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert(answer == i);\n\t\t\t}\n\t\t}\n\t}\n\tforeach(i; 1 .. n + 1) get(i);\n\tassert (zero != 0);\n\tauto p = new int[](n+1);\n\tint v = 1;\n\tint i = zero;\n\twhile (i)\n\t{\n\t\tp[i] = v++;\n\t\ti = next[i];\n\t}\n\twrite(\"! \");\n\tforeach(j; 1 .. n + 1) write (p[j], \" \");\n\twriteln;\n\tstdout.flush;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [{"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tauto next = new int[](n+1);\n\tauto prev = new int[](n+1);\n\tint zero = 0;\n\tvoid get(int i)\n\t{\n\t\tint answer = void;\n\t\twrite (\"? \");\n\t\tforeach(j; 1 .. n+1)\n\t\t{\n\t\t\twrite (int(i == j), \" \");\n\t\t}\n\t\twriteln;\n\t\tstdout.flush;\n\t\tanswer = readInt!int;\n\t\tif (answer == 0)\n\t\t{\n\t\t\tnext[i] = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (answer < i)\n\t\t\t{\n\t\t\t\tnext[i] = answer;\n\t\t\t\tprev[answer] = i;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert(answer == i);\n\t\t\t}\n\t\t}\n\t\t\n\t\twrite (\"? \");\n\t\tforeach(j; 1 .. n+1)\n\t\t{\n\t\t\twrite (int(i != j), \" \");\n\t\t}\n\t\twriteln;\n\t\tstdout.flush;\n\t\tanswer = readInt!int;\n\t\tif (answer == 0)\n\t\t{\n\t\t\tprev[i] = 0;\n\t\t\tzero = i;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (answer < i)\n\t\t\t{\n\t\t\t\tprev[i] = answer;\n\t\t\t\tnext[answer] = i;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert(answer == i);\n\t\t\t}\n\t\t}\n\t}\n\tforeach(i; 1 .. n + 1) get(i);\n\tassert (zero != 0);\n\tauto p = new int[](n+1);\n\tint v = 1;\n\tint i = zero;\n\twhile (i)\n\t{\n\t\tp[i] = v++;\n\t\ti = next[i];\n\t}\n\twrite(\"! \");\n\tforeach(j; 1 .. n + 1) write (p[j], \" \");\n\twriteln;\n\tstdout.flush;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tauto next = new int[](n+1);\n\tauto prev = new int[](n+1);\n\tint zero = 0;\n\tvoid get(int i)\n\t{\n\t\tint answer = void;\n\t\twrite (\"? \");\n\t\tforeach(j; 1 .. n+1)\n\t\t{\n\t\t\twrite (int(i == j), \" \");\n\t\t}\n\t\twriteln;\n\t\tstdout.flush;\n\t\tanswer = readInt!int;\n\t\tif (answer == 0)\n\t\t{\n\t\t\tnext[i] = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (answer < i)\n\t\t\t{\n\t\t\t\tnext[i] = answer;\n\t\t\t\tprev[answer] = i;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert(answer == i);\n\t\t\t}\n\t\t}\n\t\t\n\t\twrite (\"? \");\n\t\tforeach(j; 1 .. n+1)\n\t\t{\n\t\t\twrite (int(i != j), \" \");\n\t\t}\n\t\twriteln;\n\t\tstdout.flush;\n\t\tanswer = readInt!int;\n\t\tif (answer == 0)\n\t\t{\n\t\t\tprev[i] = 0;\n\t\t\tzero = i;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (answer < i)\n\t\t\t{\n\t\t\t\tprev[i] = answer;\n\t\t\t\tnext[answer] = i;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert(answer == i);\n\t\t\t}\n\t\t}\n\t}\n\tforeach(i; 1 .. n + 1) get(i);\n\tassert (zero != 0);\n\tauto p = new int[](n+1);\n\tint v = 1;\n\tint i = zero;\n\twhile (i)\n\t{\n\t\tp[i] = v++;\n\t\ti = next[i];\n\t}\n\tdebug writeln(p);\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "2cb5fe3fdff43e104729866cdfa73102"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto k = RD;\n\n\t\tif (k % 2 == 0)\n\t\t{\n\t\t\tif (n % 2) continue;\n\t\t\tif (k > n) continue;\n\t\t\tforeach (i; 0..k-1)\n\t\t\t{\n\t\t\t\tans[ti] ~= 1;\n\t\t\t}\n\t\t\tans[ti] ~= n - (k-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (n % 2)\n\t\t\t{\n\t\t\t\tif (k > n) continue;\n\t\t\t\tforeach (i; 0..k-1)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= 1;\n\t\t\t\t}\n\t\t\t\tans[ti] ~= n - (k-1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (k*2 > n) continue;\n\t\t\t\tforeach (i; 0..k-1)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= 2;\n\t\t\t\t}\n\t\t\t\tans[ti] ~= n - (k-1)*2;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(\"NO\");\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\te.map!(to!string).join(\" \").writeln();\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint [] solve (int n, int k)\n{\n\tforeach (v; [1, 2])\n\t{\n\t\tauto last = n - v * (k - 1);\n\t\tif (last > 0 && last % 2 == v % 2)\n\t\t{\n\t\t\treturn v.repeat (k - 1).array ~ last;\n\t\t}\n\t}\n\treturn null;\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\tauto res = solve (n, k);\n\t\tif (res is null)\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln !(\"%(%s %)\") (res);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid calc(int n, int k) {\n int x = n - (k - 1);\n if (x > 0 && x % 2 == 1) {\n writeln(\"YES\");\n auto ans = chain(repeat(1, k - 1), [n - (k - 1)]);\n writeln(ans.map!text.join(' '));\n return;\n }\n\n int y = n - (k - 1) * 2;\n if (y > 0 && y % 2 == 0) {\n writeln(\"YES\");\n auto ans = chain(repeat(2, k - 1), [n - (k - 1) * 2]);\n writeln(ans.map!text.join(' '));\n return;\n }\n\n writeln(\"NO\");\n}\n\nvoid main() {\n int t; scan(t);\n foreach (_; 0..t) {\n int n, k; scan(n, k);\n calc(n, k);\n }\n}\n\nvoid scan(T...)(ref T a) {\n string[] ss = readln.split;\n foreach (i, t; T) a[i] = ss[i].to!t;\n}\nT read(T=string)() { return readln.chomp.to!T; }\nT[] reads(T)() { return readln.split.to!(T[]); }\nalias readints = reads!int;\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.conv;\nimport std.string;\n\nT readNum(T)(){\n return readStr.to!T;\n}\n\nT[] readNums(T)(){\n return readStr.split.to!(T[]);\n}\n\nstring readStr(){\n return readln.chomp;\n}\n\nvoid main(){\n auto t = readNum!int;\n\n foreach(i; 0 .. t){\n auto nk = readNums!long;\n\n long a = nk[0] / nk[1];\n long b = nk[0] % nk[1];\n\n if(b % 2 == 0 && a > 0){\n writeln(\"YES\");\n foreach(j; 0 .. nk[1] - 1){\n write(a, \" \");\n }\n writeln(a+b);\n } else if((b+nk[1]) % 2 == 0 && a-1 > 0){\n writeln(\"YES\");\n foreach(j; 0 .. nk[1] - 1){\n write(a-1, \" \");\n }\n writeln(a-1+b+nk[1]);\n } else {\n writeln(\"NO\");\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto nk = readln.split.to!(long[]);\n auto N = nk[0];\n auto K = nk[1];\n\n auto d = N / K;\n auto r = N % K;\n auto x = d+r;\n\n if (d == 0) {\n writeln(\"NO\");\n continue;\n }\n\n if (d%2 != x%2) {\n if (d <= 1 || K%2 == 0) {\n writeln(\"NO\");\n continue;\n }\n d -= 1;\n x += K-1;\n }\n \n long[] as;\n foreach (_k; 0..K-1) as ~= d;\n as ~= x;\n writeln(\"YES\");\n writeln(as.to!(string[]).join(\" \"));\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto nk = readln.split.to!(long[]);\n auto N = nk[0];\n auto K = nk[1];\n\n auto d = N / K;\n auto r = N % K;\n auto x = d+r;\n\n if (d%2 != x%2) {\n if (d <= 1 || K%2 == 0) {\n writeln(\"NO\");\n continue;\n }\n d -= 1;\n x += K-1;\n }\n \n long[] as;\n foreach (_k; 0..K-1) as ~= d;\n as ~= x;\n writeln(\"YES\");\n writeln(as.to!(string[]).join(\" \"));\n }\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto nk = readln.split.to!(long[]);\n auto N = nk[0];\n auto K = nk[1];\n\n auto d = N / K;\n auto r = N % K;\n auto x = d+r;\n\n if (d%2 != x%2) {\n if (d == 1 || K%2 == 0) {\n writeln(\"NO\");\n continue;\n }\n d -= 1;\n x += K-1;\n }\n \n long[] as;\n foreach (_k; 0..K-1) as ~= d;\n as ~= x;\n writeln(\"YES\");\n writeln(as.to!(string[]).join(\" \"));\n }\n}"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\n// tries to build with 4 instead of 2\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint [] solve (int n, int k)\n{\n\tforeach (v; [1, 4])\n\t{\n\t\tauto last = n - v * (k - 1);\n\t\tif (last > 0 && last % 2 == v % 2)\n\t\t{\n\t\t\treturn v.repeat (k - 1).array ~ last;\n\t\t}\n\t}\n\treturn null;\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\tauto res = solve (n, k);\n\t\tif (res is null)\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln !(\"%(%s %)\") (res);\n\t\t}\n\t}\n}\n"}], "src_uid": "6b94dcd088b0328966b54acefb5c6d22"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 2 ^^ 14 - 1;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto cnt = new int[] (MX+1);\n \n arr.each!(x => ++cnt[x]);\n \n auto ans = 0L;\n foreach (i; 0 .. MX+1) {\n foreach (j; i .. MX+1) {\n if ((i ^ j).popcnt == k) {\n ans += i == j ? \n cnt[i].to!long * (cnt[i]-1) / 2\n : cnt[i].to!long * cnt[j]; \n }\n }\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.format;\nimport std.algorithm;\nimport std.math;\nimport core.bitop;\n\nconst int N = 100004;\n\nlong ans;\nint n, k;\nint[N] a;\nint[] masks;\nint[1 << 14] cnt;\n\nvoid read() {\n\treadf(\" %s %s\", &n, &k);\n\tforeach (i; 0..n) {\n\t\treadf(\" %s\", &a[i]);\n\t}\n}\n\nvoid precalc() {\n\tforeach (mask; 0..1<<14) {\n\t\tif (_popcnt(mask) == k) {\n\t\t\tmasks ~= mask;\n\t\t}\n\t}\n}\n\nvoid compute() {\n\tforeach (i; 0..n) {\n\t\tforeach (m; masks) {\n\t\t\tans += cnt[a[i] ^ m];\n\t\t}\n\t\tcnt[a[i]]++;\n\t}\n}\n\nvoid solve() {\n\tread();\n\tprecalc();\n\tcompute();\n\twriteln(ans);\n}\n\nint main() {\n\tsolve();\n\n return 0;\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 2 ^^ 14 - 1;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto cnt = new int[] (MX+1);\n \n arr.each!(x => ++cnt[x]);\n \n auto ans = 0L;\n foreach (i; 0 .. MX+1) {\n foreach (j; i .. MX+1) {\n if ((i ^ j).popcnt != k) { ans += cnt[i].to!long * cnt[j]; }\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 2 ^^ 14 - 1;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto cnt = new int[] (MX+1);\n \n arr.each!(x => ++cnt[x]);\n \n auto ans = 0L;\n foreach (i; 0 .. MX+1) {\n foreach (j; i .. MX+1) {\n if ((i ^ j).popcnt == k) { ans += cnt[i].to!long * cnt[j]; }\n }\n }\n \n ans.writeln;\n}"}], "src_uid": "7b7623dfde563b383cdc2364c81a7539"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int k = scan!int;\n int j = 0;\n for(int i = 1; i <= 3*k; ++i){\n if(i % 3 == 0 || i % 10 == 3) continue;\n ++j;\n if(j == k){\n writeln(i);\n }\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n long ans;\n foreach (i ; 1 .. 100000) {\n if (i % 10 == 3 || i % 3 == 0) {\n } else {\n if (--n == 0) {\n writeln(i);\n break;\n }\n }\n }\n }\n}\n"}], "negative_code": [], "src_uid": "c37604d5d833a567ff284d7ce5eda059"} {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, s; readV(n, s);\n\n auto t = new int[](n);\n foreach (i; 0..n) {\n int h, m; readV(h, m);\n t[i] = h*60+m;\n }\n\n auto put(int ans)\n {\n writeln(ans/60, \" \", ans%60);\n }\n\n if (t[0] >= s+1) {\n put(0);\n return;\n }\n\n foreach (i; 0..n-1) {\n if (t[i+1]-t[i] >= s*2+2) {\n put(t[i]+s+1);\n return;\n }\n }\n\n put(t[$-1]+s+1);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main() {\n\tauto ns = readln.chomp.split.map!(to!int);\n\tint n = ns[0];\n\tint s = ns[1];\n\tint[] times;\n\ttimes ~= -s - 1;\n\tforeach (i; 0..n) {\n\t\tauto hs = readln.chomp.split.map!(to!int);\n\t\tint h = hs[0];\n\t\tint m = hs[1];\n\t\tint t = h * 60 + m;\n\t\ttimes ~= t;\n\t}\n\ttimes ~= times[$-1] + (1 << 28);\n\tint len = cast(int) times.length;\n\tfor (int i = 0; i < len - 1; ++i) {\n\t\tint t1 = times[i];\n\t\tint t2 = times[i + 1];\n\t\tdebug stderr.writefln(\"[%d] %d %d ... %d\", i, t1, t2, t2 - t1);\n\t\tif (t2 - t1 >= s * 2 + 2) {\n\t\t\tint h = t1 / 60;\n\t\t\tint m = t1 % 60;\n\t\t\tdebug stderr.writefln(\"\\t%d, %d\", h, m);\n\t\t\tm += s + 1;\n\t\t\th += m / 60;\n\t\t\tm %= 60;\n\t\t\tif (h < 0 || m < 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdebug stderr.writefln(\"\\t\\t[%d] %d %d ... %d\", i, t1, t2, t2 - t1);\n\t\t\twritefln(\"%d %d\", h, m);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main() {\n\tauto ns = readln.chomp.split.map!(to!int);\n\tint n = ns[0];\n\tint s = ns[1];\n\tint[] times;\n\ttimes ~= -s - 1;\n\tforeach (i; 0..n) {\n\t\tauto hs = readln.chomp.split.map!(to!int);\n\t\tint h = hs[0];\n\t\tint m = hs[1];\n\t\tint t = h * 60 + m;\n\t\ttimes ~= t;\n\t}\n\ttimes ~= times[$-1] + s;\n\ttimes ~= times[$-1] + 1 << 28;\n\tint len = cast(int) times.length;\n\tfor (int i = 0; i < len - 1; ++i) {\n\t\tint t1 = times[i];\n\t\tint t2 = times[i + 1];\n\t\tif (t2 - t1 >= s * 2 + 2) {\n\t\t\tint h = t1 / 60;\n\t\t\tint m = t1 % 60;\n\t\t\tm += s + 1;\n\t\t\th += m / 60;\n\t\t\tm %= 60;\n\t\t\tdebug stderr.writefln(\"[%d] %d %d ... %d\", i, t1, t2, t2 - t1);\n\t\t\twritefln(\"%d %d\", h, m);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n\n"}], "src_uid": "dcca7c58ba7111125608f659a577c3a2"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 403;\nalias Mint = ModInt!MO;\nMint R = 2020;\n\n\n// T: monoid\n// op: T * T -> T\n// query(a, b): returns t_a ... t_{b-1}\nclass SegmentTree(T, alias op) {\n import std.functional : binaryFun;\n alias opFun = binaryFun!op;\n const(T) idT;\n\n int n;\n T[] ts;\n this(int n_, const(T) idT) {\n this.idT = idT;\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[] = idT;\n }\n this(inout(T)[] ts_, const(T) idT) {\n this.idT = idT;\n const n_ = cast(int)(ts_.length);\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[0 .. n] = idT;\n ts[n .. n + n_] = ts_[];\n ts[n + n_ .. n << 1] = idT;\n build();\n }\n ref T at(int a) {\n return ts[n + a];\n }\n void build() {\n foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void set(int a, const(T) val) {\n ts[a += n] = val;\n for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void mulL(int a, const(T) val) {\n set(a, opFun(val, ts[a + n]));\n }\n void mulR(int a, const(T) val) {\n set(a, opFun(ts[a + n], val));\n }\n T query(int a, int b) const {\n T prodL = idT, prodR = idT;\n for (a += n, b += n; a < b; a >>= 1, b >>= 1) {\n if (a & 1) prodL = opFun(prodL, ts[a++]);\n if (b & 1) prodR = opFun(ts[--b], prodR);\n }\n return opFun(prodL, prodR);\n }\n}\n\n\nMint[] RR;\n\nstruct Info {\n int num1, len, head;\n Mint val;\n Info opBinary(string op)(const(Info) o) const if (op == \"*\") {\n Info ret;\n ret.num1 = num1 + o.num1;\n if (len == 0) {\n ret.len = o.len;\n ret.head = (num1 & 1) ^ o.head;\n ret.val = o.val;\n } else if (o.len == 0) {\n ret.len = len;\n ret.head = head;\n ret.val = val;\n } else if ((head ^ (len & 1)) == ((num1 & 1) ^ o.head)) {\n // concat\n ret.len = len + o.len;\n ret.head = head;\n ret.val = val + RR[len] * o.val;\n } else {\n // overlap\n ret.len = len + o.len - 1;\n ret.head = head;\n ret.val = val + RR[len - 1] * o.val;\n }\n return ret;\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const T = readToken();\n const Q = readInt();\n auto A = new int[Q];\n auto B = new int[Q];\n auto L = new int[Q];\n foreach (q; 0 .. Q) {\n A[q] = readInt() - 1;\n B[q] = readInt() - 1;\n L[q] = readInt();\n }\n \n foreach (q; 0 .. Q) {\n R.x ^= A[q] ^ B[q] ^ L[q];\n }\n RR = new Mint[N + 1];\n RR[0] = 1;\n foreach (i; 1 .. N + 1) {\n RR[i] = RR[i - 1] * R;\n }\n \n auto seg = new SegmentTree!(Info, \"a * b\")(N, Info(0, 0, 0, Mint(0)));\n foreach (i; 0 .. N) {\n seg.at(i) = (T[i] == '1') ? Info(1, 0, 0, Mint(0)) : Info(0, 1, 0, Mint(1));\n }\n seg.build;\n debug {\n foreach (i; 0 .. N) foreach (j; i + 1 .. N + 1) {\n // writeln(i, \" \", j, \": \", seg.query(i, j));\n }\n }\n \n foreach (q; 0 .. Q) {\n const resA = seg.query(A[q], A[q] + L[q]);\n const resB = seg.query(B[q], B[q] + L[q]);\n debug {\n writeln(true, \" \", resA, \" \", resB);\n }\n const ans = (resA == resB);\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 403;\nalias Mint = ModInt!MO;\n\n// T: monoid\n// op: T * T -> T\n// query(a, b): returns t_a ... t_{b-1}\nclass SegmentTree(T, alias op) {\n import std.functional : binaryFun;\n alias opFun = binaryFun!op;\n const(T) idT;\n\n int n;\n T[] ts;\n this(int n_, const(T) idT) {\n this.idT = idT;\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[] = idT;\n }\n this(inout(T)[] ts_, const(T) idT) {\n this.idT = idT;\n const n_ = cast(int)(ts_.length);\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[0 .. n] = idT;\n ts[n .. n + n_] = ts_[];\n ts[n + n_ .. n << 1] = idT;\n build();\n }\n ref T at(int a) {\n return ts[n + a];\n }\n void build() {\n foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void set(int a, const(T) val) {\n ts[a += n] = val;\n for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void mulL(int a, const(T) val) {\n set(a, opFun(val, ts[a + n]));\n }\n void mulR(int a, const(T) val) {\n set(a, opFun(ts[a + n], val));\n }\n T query(int a, int b) const {\n T prodL = idT, prodR = idT;\n for (a += n, b += n; a < b; a >>= 1, b >>= 1) {\n if (a & 1) prodL = opFun(prodL, ts[a++]);\n if (b & 1) prodR = opFun(ts[--b], prodR);\n }\n return opFun(prodL, prodR);\n }\n}\n\n\nMint R;\nMint[] RR;\n\nstruct Info {\n int num1, len, head;\n Mint val;\n Info opBinary(string op)(const(Info) o) const if (op == \"*\") {\n Info ret;\n ret.num1 = num1 + o.num1;\n if (len == 0) {\n ret.len = o.len;\n ret.head = (num1 & 1) ^ o.head;\n ret.val = o.val;\n } else if (o.len == 0) {\n ret.len = len;\n ret.head = head;\n ret.val = val;\n } else if ((head ^ (len & 1)) == ((num1 & 1) ^ o.head)) {\n // concat\n ret.len = len + o.len;\n ret.head = head;\n ret.val = val + RR[len] * o.val;\n } else {\n // overlap\n ret.len = len + o.len - 1;\n ret.head = head;\n ret.val = val + RR[len - 1] * o.val;\n }\n return ret;\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const T = readToken();\n const Q = readInt();\n auto A = new int[Q];\n auto B = new int[Q];\n auto L = new int[Q];\n foreach (q; 0 .. Q) {\n A[q] = readInt() - 1;\n B[q] = readInt() - 1;\n L[q] = readInt();\n }\n \n import std.datetime;\n R = 2020 ^ Clock.currStdTime;\n debug {\n writeln(\"R = \", R);\n }\n RR = new Mint[N + 1];\n RR[0] = 1;\n foreach (i; 1 .. N + 1) {\n RR[i] = RR[i - 1] * R;\n }\n \n auto seg = new SegmentTree!(Info, \"a * b\")(N, Info(0, 0, 0, Mint(0)));\n foreach (i; 0 .. N) {\n seg.at(i) = (T[i] == '1') ? Info(1, 0, 0, Mint(0)) : Info(0, 1, 0, Mint(1));\n }\n seg.build;\n debug {\n foreach (i; 0 .. N) foreach (j; i + 1 .. N + 1) {\n // writeln(i, \" \", j, \": \", seg.query(i, j));\n }\n }\n \n foreach (q; 0 .. Q) {\n const resA = seg.query(A[q], A[q] + L[q]);\n const resB = seg.query(B[q], B[q] + L[q]);\n debug {\n writeln(true, \" \", resA, \" \", resB);\n }\n const ans = (resA == resB);\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct SuffixArray(T) {\n import std.algorithm : sort;\n int n;\n T[] ts;\n int[] us, su, lcp;\n this(T)(T[] ts) {\n n = cast(int)(ts.length);\n this.ts = ts;\n us = new int[n + 1];\n su = new int[n + 1];\n foreach (i; 0 .. n + 1) us[i] = i;\n us.sort!((u, v) => (cmp(u, v) < 0));\n auto vals = new int[n + 1], cnt = new int[n + 1], tmp = new int[n + 1];\n foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((cmp(us[i], us[i + 1]) < 0) ? 1 : 0);\n for (int h = 1; ; h <<= 1) {\n int ahead(int i) {\n return (us[i] + h <= n) ? su[us[i] + h] : 0;\n }\n foreach (i; 0 .. n + 1) su[us[i]] = vals[i];\n if (vals[n] == n) break;\n cnt[] = 0;\n foreach (i; 0 .. n + 1) ++cnt[ahead(i)];\n foreach (j; 0 .. n) cnt[j + 1] += cnt[j];\n foreach_reverse (i; 0 .. n + 1) tmp[--cnt[ahead(i)]] = us[i];\n cnt[] = 0;\n foreach (i; 0 .. n + 1) ++cnt[su[tmp[i]]];\n foreach (j; 0 .. n) cnt[j + 1] += cnt[j];\n foreach_reverse (i; 0 .. n + 1) us[--cnt[su[tmp[i]]]] = tmp[i];\n foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((su[us[i]] < su[us[i + 1]] || ahead(i) < ahead(i + 1)) ? 1 : 0);\n }\n lcp = new int[n];\n int h;\n foreach (u; 0 .. n) {\n for (int v = us[su[u] - 1]; cmp(u + h, v + h) == 0; ++h) {}\n lcp[su[u] - 1] = h;\n if (h > 0) --h;\n }\n }\n int cmp(int u, int v) const {\n return (u == n) ? ((v == n) ? 0 : -1) : (v == n) ? +1 : (ts[u] < ts[v]) ? -1 : (ts[u] > ts[v]) ? +1 : 0;\n }\n void print() const {\n import std.math : log10;\n import std.stdio : writefln;\n const numDigits = cast(int)(log10(n)) + 1;\n foreach (i; 0 .. n + 1) {\n writefln(\"%*d %s\", numDigits, us[i], ts[us[i] .. $]);\n }\n }\n}\n\n\n// T: monoid\n// op: T * T -> T\n// query(a, b): returns t_a ... t_{b-1}\nclass SegmentTree(T, alias op) {\n import std.functional : binaryFun;\n alias opFun = binaryFun!op;\n const(T) idT;\n\n int n;\n T[] ts;\n this(int n_, const(T) idT) {\n this.idT = idT;\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[] = idT;\n }\n this(inout(T)[] ts_, const(T) idT) {\n this.idT = idT;\n const n_ = cast(int)(ts_.length);\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[0 .. n] = idT;\n ts[n .. n + n_] = ts_[];\n ts[n + n_ .. n << 1] = idT;\n build();\n }\n ref T at(int a) {\n return ts[n + a];\n }\n void build() {\n foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void set(int a, const(T) val) {\n ts[a += n] = val;\n for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void mulL(int a, const(T) val) {\n set(a, opFun(val, ts[a + n]));\n }\n void mulR(int a, const(T) val) {\n set(a, opFun(ts[a + n], val));\n }\n T query(int a, int b) const {\n T prodL = idT, prodR = idT;\n for (a += n, b += n; a < b; a >>= 1, b >>= 1) {\n if (a & 1) prodL = opFun(prodL, ts[a++]);\n if (b & 1) prodR = opFun(ts[--b], prodR);\n }\n return opFun(prodL, prodR);\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const T = readToken();\n const Q = readInt();\n auto A = new int[Q];\n auto B = new int[Q];\n auto L = new int[Q];\n foreach (q; 0 .. Q) {\n A[q] = readInt() - 1;\n B[q] = readInt() - 1;\n L[q] = readInt();\n }\n \n auto num1 = new int[N + 1];\n foreach (i; 0 .. N) {\n num1[i + 1] = num1[i] + ((T[i] == '1') ? 1 : 0);\n }\n auto num11 = new int[N];\n foreach (i; 0 .. N - 1) {\n num11[i + 1] = num11[i] + ((T[i] == '1' && T[i + 1] == '1') ? 1 : 0);\n }\n \n auto sum = new long[N + 1];\n foreach (i; 0 .. N) {\n sum[i + 1] = sum[i] + ((T[i] == '1') ? i : 0);\n }\n \n auto sa = new SuffixArray!(immutable(char))(T);\n auto seg = new SegmentTree!(int, min)(sa.lcp, N + 1);\n \n foreach (q; 0 .. Q) {\n bool ans;\n if (num11[A[q] + L[q] - 1] - num11[A[q]] > 0 && num11[B[q] + L[q] - 1] - num11[B[q]] > 0) {\n const n1A = num1[A[q] + L[q]] - num1[A[q]];\n const n1B = num1[B[q] + L[q]] - num1[B[q]];\n const sA = (sum[A[q] + L[q]] - sum[A[q]]) - 1L * n1A * A[q];\n const sB = (sum[B[q] + L[q]] - sum[B[q]]) - 1L * n1B * B[q];\n debug {\n writeln(true, \" \", [n1A, n1B], \" \", [sA, sB]);\n }\n ans = (n1A == n1B && (sA - sB) % 2 == 0);\n } else {\n int a = sa.su[A[q]], b = sa.su[B[q]];\n if (a > b) {\n swap(a, b);\n }\n const res = seg.query(a, b);\n debug {\n writeln(false, \" \", A[q], \" \", B[q], \": \", res);\n }\n ans = (res >= L[q]);\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct SuffixArray(T) {\n import std.algorithm : sort;\n int n;\n T[] ts;\n int[] us, su, lcp;\n this(T)(T[] ts) {\n n = cast(int)(ts.length);\n this.ts = ts;\n us = new int[n + 1];\n su = new int[n + 1];\n foreach (i; 0 .. n + 1) us[i] = i;\n us.sort!((u, v) => (cmp(u, v) < 0));\n auto vals = new int[n + 1], cnt = new int[n + 1], tmp = new int[n + 1];\n foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((cmp(us[i], us[i + 1]) < 0) ? 1 : 0);\n for (int h = 1; ; h <<= 1) {\n int ahead(int i) {\n return (us[i] + h <= n) ? su[us[i] + h] : 0;\n }\n foreach (i; 0 .. n + 1) su[us[i]] = vals[i];\n if (vals[n] == n) break;\n cnt[] = 0;\n foreach (i; 0 .. n + 1) ++cnt[ahead(i)];\n foreach (j; 0 .. n) cnt[j + 1] += cnt[j];\n foreach_reverse (i; 0 .. n + 1) tmp[--cnt[ahead(i)]] = us[i];\n cnt[] = 0;\n foreach (i; 0 .. n + 1) ++cnt[su[tmp[i]]];\n foreach (j; 0 .. n) cnt[j + 1] += cnt[j];\n foreach_reverse (i; 0 .. n + 1) us[--cnt[su[tmp[i]]]] = tmp[i];\n foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((su[us[i]] < su[us[i + 1]] || ahead(i) < ahead(i + 1)) ? 1 : 0);\n }\n lcp = new int[n];\n int h;\n foreach (u; 0 .. n) {\n for (int v = us[su[u] - 1]; cmp(u + h, v + h) == 0; ++h) {}\n lcp[su[u] - 1] = h;\n if (h > 0) --h;\n }\n }\n int cmp(int u, int v) const {\n return (u == n) ? ((v == n) ? 0 : -1) : (v == n) ? +1 : (ts[u] < ts[v]) ? -1 : (ts[u] > ts[v]) ? +1 : 0;\n }\n void print() const {\n import std.math : log10;\n import std.stdio : writefln;\n const numDigits = cast(int)(log10(n)) + 1;\n foreach (i; 0 .. n + 1) {\n writefln(\"%*d %s\", numDigits, us[i], ts[us[i] .. $]);\n }\n }\n}\n\n\n// T: monoid\n// op: T * T -> T\n// query(a, b): returns t_a ... t_{b-1}\nclass SegmentTree(T, alias op) {\n import std.functional : binaryFun;\n alias opFun = binaryFun!op;\n const(T) idT;\n\n int n;\n T[] ts;\n this(int n_, const(T) idT) {\n this.idT = idT;\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[] = idT;\n }\n this(inout(T)[] ts_, const(T) idT) {\n this.idT = idT;\n const n_ = cast(int)(ts_.length);\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[0 .. n] = idT;\n ts[n .. n + n_] = ts_[];\n ts[n + n_ .. n << 1] = idT;\n build();\n }\n ref T at(int a) {\n return ts[n + a];\n }\n void build() {\n foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void set(int a, const(T) val) {\n ts[a += n] = val;\n for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void mulL(int a, const(T) val) {\n set(a, opFun(val, ts[a + n]));\n }\n void mulR(int a, const(T) val) {\n set(a, opFun(ts[a + n], val));\n }\n T query(int a, int b) const {\n T prodL = idT, prodR = idT;\n for (a += n, b += n; a < b; a >>= 1, b >>= 1) {\n if (a & 1) prodL = opFun(prodL, ts[a++]);\n if (b & 1) prodR = opFun(ts[--b], prodR);\n }\n return opFun(prodL, prodR);\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const T = readToken();\n const Q = readInt();\n auto A = new int[Q];\n auto B = new int[Q];\n auto L = new int[Q];\n foreach (q; 0 .. Q) {\n A[q] = readInt() - 1;\n B[q] = readInt() - 1;\n L[q] = readInt();\n }\n \n auto num1 = new int[N + 1];\n foreach (i; 0 .. N) {\n num1[i + 1] = num1[i] + ((T[i] == '1') ? 1 : 0);\n }\n auto num11 = new int[N];\n foreach (i; 0 .. N - 1) {\n num11[i + 1] = num11[i] + ((T[i] == '1' && T[i + 1] == '1') ? 1 : 0);\n }\n \n auto sa = new SuffixArray!(immutable(char))(T);\n auto seg = new SegmentTree!(int, min)(sa.lcp, N + 1);\n \n foreach (q; 0 .. Q) {\n bool ans;\n if (num11[A[q] + L[q] - 1] - num11[A[q]] > 0 && num11[B[q] + L[q] - 1] - num11[B[q]] > 0) {\n ans = (num1[A[q] + L[q]] - num1[A[q]] == num1[B[q] + L[q]] - num1[B[q]]);\n } else {\n int a = sa.su[A[q]], b = sa.su[B[q]];\n if (a > b) {\n swap(a, b);\n }\n const res = seg.query(a, b);\n debug {\n writeln(A[q], \" \", B[q], \": \", res);\n }\n ans = (res >= L[q]);\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct SuffixArray(T) {\n import std.algorithm : sort;\n int n;\n T[] ts;\n int[] us, su, lcp;\n this(T)(T[] ts) {\n n = cast(int)(ts.length);\n this.ts = ts;\n us = new int[n + 1];\n su = new int[n + 1];\n foreach (i; 0 .. n + 1) us[i] = i;\n us.sort!((u, v) => (cmp(u, v) < 0));\n auto vals = new int[n + 1], cnt = new int[n + 1], tmp = new int[n + 1];\n foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((cmp(us[i], us[i + 1]) < 0) ? 1 : 0);\n for (int h = 1; ; h <<= 1) {\n int ahead(int i) {\n return (us[i] + h <= n) ? su[us[i] + h] : 0;\n }\n foreach (i; 0 .. n + 1) su[us[i]] = vals[i];\n if (vals[n] == n) break;\n cnt[] = 0;\n foreach (i; 0 .. n + 1) ++cnt[ahead(i)];\n foreach (j; 0 .. n) cnt[j + 1] += cnt[j];\n foreach_reverse (i; 0 .. n + 1) tmp[--cnt[ahead(i)]] = us[i];\n cnt[] = 0;\n foreach (i; 0 .. n + 1) ++cnt[su[tmp[i]]];\n foreach (j; 0 .. n) cnt[j + 1] += cnt[j];\n foreach_reverse (i; 0 .. n + 1) us[--cnt[su[tmp[i]]]] = tmp[i];\n foreach (i; 0 .. n) vals[i + 1] = vals[i] + ((su[us[i]] < su[us[i + 1]] || ahead(i) < ahead(i + 1)) ? 1 : 0);\n }\n lcp = new int[n];\n int h;\n foreach (u; 0 .. n) {\n for (int v = us[su[u] - 1]; cmp(u + h, v + h) == 0; ++h) {}\n lcp[su[u] - 1] = h;\n if (h > 0) --h;\n }\n }\n int cmp(int u, int v) const {\n return (u == n) ? ((v == n) ? 0 : -1) : (v == n) ? +1 : (ts[u] < ts[v]) ? -1 : (ts[u] > ts[v]) ? +1 : 0;\n }\n void print() const {\n import std.math : log10;\n import std.stdio : writefln;\n const numDigits = cast(int)(log10(n)) + 1;\n foreach (i; 0 .. n + 1) {\n writefln(\"%*d %s\", numDigits, us[i], ts[us[i] .. $]);\n }\n }\n}\n\n\n// T: monoid\n// op: T * T -> T\n// query(a, b): returns t_a ... t_{b-1}\nclass SegmentTree(T, alias op) {\n import std.functional : binaryFun;\n alias opFun = binaryFun!op;\n const(T) idT;\n\n int n;\n T[] ts;\n this(int n_, const(T) idT) {\n this.idT = idT;\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[] = idT;\n }\n this(inout(T)[] ts_, const(T) idT) {\n this.idT = idT;\n const n_ = cast(int)(ts_.length);\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[0 .. n] = idT;\n ts[n .. n + n_] = ts_[];\n ts[n + n_ .. n << 1] = idT;\n build();\n }\n ref T at(int a) {\n return ts[n + a];\n }\n void build() {\n foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void set(int a, const(T) val) {\n ts[a += n] = val;\n for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void mulL(int a, const(T) val) {\n set(a, opFun(val, ts[a + n]));\n }\n void mulR(int a, const(T) val) {\n set(a, opFun(ts[a + n], val));\n }\n T query(int a, int b) const {\n T prodL = idT, prodR = idT;\n for (a += n, b += n; a < b; a >>= 1, b >>= 1) {\n if (a & 1) prodL = opFun(prodL, ts[a++]);\n if (b & 1) prodR = opFun(ts[--b], prodR);\n }\n return opFun(prodL, prodR);\n }\n}\n\n\nstruct Info {\n int a, b0, b1;\n Info opBinary(string op)(const(Info) o) const if (op == \"*\") {\n return Info(a + o.a, b0 + ((a & 1) ? o.b1 : o.b0), b1 + ((a & 1) ? o.b0 : o.b1));\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const T = readToken();\n const Q = readInt();\n auto A = new int[Q];\n auto B = new int[Q];\n auto L = new int[Q];\n foreach (q; 0 .. Q) {\n A[q] = readInt() - 1;\n B[q] = readInt() - 1;\n L[q] = readInt();\n }\n \n auto num1 = new int[N + 1];\n foreach (i; 0 .. N) {\n num1[i + 1] = num1[i] + ((T[i] == '1') ? 1 : 0);\n }\n auto num11 = new int[N];\n foreach (i; 0 .. N - 1) {\n num11[i + 1] = num11[i] + ((T[i] == '1' && T[i + 1] == '1') ? 1 : 0);\n }\n \n auto segInfo = new SegmentTree!(Info, \"a * b\")(N, Info(0, 0, 0));\n foreach (i; 0 .. N) {\n segInfo.at(i) = (T[i] == '1') ? Info(1, 0, 0) : Info(0, 1, 0);\n }\n segInfo.build;\n debug {\n foreach (i; 0 .. N) foreach (j; i + 1 .. N + 1) {\n // writeln(i, \" \", j, \": \", segInfo.query(i, j));\n }\n }\n \n auto sa = new SuffixArray!(immutable(char))(T);\n auto segLCP = new SegmentTree!(int, min)(sa.lcp, N + 1);\n \n foreach (q; 0 .. Q) {\n bool ans;\n if (num11[A[q] + L[q] - 1] - num11[A[q]] > 0 && num11[B[q] + L[q] - 1] - num11[B[q]] > 0) {\n const resA = segInfo.query(A[q], A[q] + L[q]);\n const resB = segInfo.query(B[q], B[q] + L[q]);\n debug {\n writeln(true, \" \", resA, \" \", resB);\n }\n ans = (resA == resB);\n } else {\n int a = sa.su[A[q]], b = sa.su[B[q]];\n if (a > b) {\n swap(a, b);\n }\n const res = segLCP.query(a, b);\n debug {\n writeln(false, \" \", A[q], \" \", B[q], \": \", res);\n }\n ans = (res >= L[q]);\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "6bd41042c6a442765cd93c73d55f6189"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\nimmutable int N = 10 ^^ 6 + 23;\n\nint[N] fw;\n\nvoid fwadd(int p, int x) {\n while (p < N) {\n fw[p] += x;\n p += (1 << bsf(p));\n }\n}\n\nint fwsum(int p) {\n int ans = 0;\n while (p > 0) {\n ans += fw[p];\n p -= (1 << bsf(p));\n }\n \n debug { ans.writeln; }\n \n return ans;\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n bool odd = false;\n foreach_reverse (e; arr) {\n odd ^= fwsum(e) & 1;\n fwadd(e, 1);\n }\n \n debug { odd.writeln; }\n \n bool PetrOdd = (3 * n) & 1;\n \n writeln(odd == PetrOdd ? \"Petr\" : \"Um_nik\");\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\n\nvoid main() {\n int n;\n debug dbg ();\n readf (\" %d\", &n);\n auto a = new int[n];\n foreach (i; 0 .. n) {\n readf (\" %d\", &a[i]);\n }\n auto b = new int[n];\n int merge (int l, int r) {\n if (r - l > 1) {\n immutable m = (l + r) >> 1;\n int res = merge (l, m) ^ merge (m, r);\n int i = l;\n int j = m;\n int k = 0;\n while (i < m && j < r) {\n if (a[i] < a[j]) {\n b[k++] = a[i++];\n } else {\n b[k++] = a[j++];\n res ^= (m - i) & 1;\n }\n }\n while (i < m) b[k++] = a[i++];\n while (j < r) b[k++] = a[j++];\n assert (r - l == k);\n a[l .. r] = b[0 .. k];\n return res;\n }\n return 0;\n }\n int r = merge (0, n);\n assert (r == 0 || r == 1);\n debug stderr.writeln (r);\n debug stderr.writeln (a);\n writeln (r == ((3 * n) & 1) ? \"Petr\" : \"Um_nik\");\n}\n\nvoid dbg () {\n foreach (i; 1000 .. 1000000) {\n assert ( (((3 * i) ^ (7 * i + 1)) & 1) == 1);\n }\n}\n"}], "negative_code": [], "src_uid": "a9cc20ba7d6e31706ab1743bdde97669"} {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\r\nmodule solution;\r\nimport std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto k = readln.strip;\r\n\t\tauto s = readln.strip;\r\n\t\tauto t = s.map !(x => k.countUntil (x)).array;\r\n\t\tzip (t, t.drop (1)).map !(q{abs (a[0] - a[1])}).sum.writeln;\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto alphabet = readString;\n\tauto word = readString;\n\tint[char] position;\n\tforeach(i, ch; alphabet) position[ch] = cast(int)i;\n\tlong sum = 0;\n\tforeach(i; 1 .. word.length)\n\t{\n\t\tsum += abs(position[word[i]] - position[word[i-1]]);\n\t}\n\tsum.writeln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "7f9853be7ac857bb3c4eb17e554ad3f1"} {"source_code": "import std.stdio, std.conv, std.string, std.regex;\nvoid main()\n{\n string command;\n string[] lexems;\n auto reg = regex(\"[^\\\" ]+|(\\\"[^\\\"]*\\\")\");\n\n command = readln();\n command = strip(command);\n\n while(true)\n {\n auto m = match(command, reg);\n if (m.empty) break;\n lexems ~= chomp(chompPrefix(m.front.hit, `\"`),`\"`);\n command = m.post;\n }\n\n foreach(ref l; lexems)\n writeln(\"<\", l, \">\");\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln ()) != null)\n\t{\n\t\twhile (1)\n\t\t{\n\t\t\ts = strip (s);\n\t\t\tif (s.length == 0)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tstring t;\n\t\t\tif (s[0] == '\"')\n\t\t\t{\n\t\t\t\tt = find (s[1..$], '\"');\n\t\t\t\twritefln (\"<%s>\", s[1..$ - t.length]);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tt = find (s[1..$], ' ');\n\t\t\t\twritefln (\"<%s>\", s[0..$ - t.length]);\n\t\t\t}\n\t\t\ts = t;\n\t\t\tif (s.length > 0)\n\t\t\t{\n\t\t\t\ts = s[1..$];\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "module cf_291B;\n\nimport std.stdio;\n\nvoid main() {\n char symbol;\n bool wasQuote = false;\n string lexem;\n\n while (readf(\"%c\", &symbol)) {\n if (symbol == '\\\"') {\n wasQuote = !wasQuote;\n\n if (!wasQuote) {\n writefln(\"<%s>\", lexem);\n }\n lexem = \"\";\n\n continue;\n }\n\n lexem ~= symbol;\n if (!wasQuote && (symbol == ' ' || symbol == '\\n')) {\n lexem = lexem[0 .. $ - 1];\n if (lexem.length > 0) {\n writefln(\"<%s>\", lexem);\n lexem = \"\";\n }\n }\n\n if (symbol == '\\n') {\n break;\n }\n }\n}"}, {"source_code": "module sigod.codeforces.p291B;\n\nimport std.array;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n\tauto result = solve(stdin.readln());\n\n\tforeach (r; result) {\n\t\tstdout.writeln(r);\n\t}\n}\n\nstring[] solve(string input)\n{\n\tinput = input.strip();\n\n\tauto result = appender!(string[])();\n\n\tbool quote = false;\n\tbool without = false;\n\tint start;\n\n\tforeach (index, c; input) {\n\t\tif (quote) {\n\t\t\tif (c == '\"') {\n\t\t\t\tresult.put('<' ~ input[start + 1 .. index] ~ '>');\n\t\t\t\tquote = false;\n\t\t\t}\n\t\t}\n\t\telse if (without) {\n\t\t\tif (c == ' ') {\n\t\t\t\tresult.put('<' ~ input[start .. index] ~ '>');\n\t\t\t\twithout = false;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (c == '\"') {\n\t\t\t\tquote = true;\n\t\t\t\tstart = index;\n\t\t\t}\n\t\t\telse if (c != ' ') {\n\t\t\t\twithout = true;\n\t\t\t\tstart = index;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (without) {\n\t\tresult.put('<' ~ input[start .. $] ~ '>');\n\t}\n\n\treturn result.data();\n}\n\nunittest {\n\tassert(std.algorithm.equal(solve(`\"RUn.exe O\" \"\" \" 2ne, \" two! . \" \"`), [\n\t\t\t\"<RUn.exe O>\",\n\t\t\t\"<>\",\n\t\t\t\"< 2ne, >\",\n\t\t\t\"<two!>\",\n\t\t\t\"<.>\",\n\t\t\t\"< >\"\n\t\t]));\n\tassert(std.algorithm.equal(solve(` firstarg second \"\" `), [\n\t\t\t\"<firstarg>\",\n\t\t\t\"<second>\",\n\t\t\t\"<>\"\n\t\t]));\n}"}], "negative_code": [{"source_code": "module cf_291B;\n\nimport std.stdio;\n\nvoid main() {\n char symbol;\n bool wasQuote = false;\n string lexem;\n\n while (readf(\"%c\", &symbol), symbol != '\\n') {\n if (symbol == '\\\"') {\n wasQuote = !wasQuote;\n\n if (!wasQuote) {\n writefln(\"<%s>\", lexem);\n }\n lexem = \"\";\n\n continue;\n }\n\n lexem ~= symbol;\n if (!wasQuote && symbol == ' ') {\n lexem = lexem[0 .. $ - 1];\n if (lexem.length > 0) {\n writefln(\"<%s>\", lexem);\n lexem = \"\";\n }\n }\n }\n}"}], "src_uid": "6c7858731c57e1b24c7a299a8eeab373"} {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long d = params[2];\r\n \r\n if(params[0] == 0 || params[1] == 0)\r\n {\r\n writeln(\"NO\");\r\n }\r\n else\r\n {\r\n long min = params[0] > params[1] ? params[1] : params[0];\r\n long max = params[0] > params[1] ? params[0] : params[1];\r\n long res = (max / min) + (max % min != 0 ? 1 : 0) - 1;\r\n writeln(res <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long d = params[2];\r\n \r\n if(abs(params[0] - params[1]) <= d)\r\n {\r\n writeln(\"YES\");\r\n }\r\n else\r\n {\r\n long min = params[0] > params[1] ? params[1] : params[0];\r\n long max = params[0] > params[1] ? params[0] : params[1];\r\n long res = (max / min) + (max % min != 0 ? 1 : 0) - 1;\r\n writeln(res <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto r = RD;\r\n\t\tauto b = RD;\r\n\t\tauto d = RD;\r\n\r\n\t\tauto x = min(b, r);\r\n\t\tauto y = max(b, r);\r\n\t\tans[ti] = y-x <= d * x;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1519/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n long r, b, d;\n readf(\"%s %s %s\\n\", &r, &b, &d);\n if(r > b)\n swap(r,b);\n if(b <= r*(d + 1))\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long d = params[2];\r\n \r\n if(params[0] == 0 || params[1] == 0)\r\n {\r\n writeln(\"NO\");\r\n }\r\n else if(abs(params[0] - params[1]) <= d)\r\n {\r\n writeln(\"YES\");\r\n }\r\n else\r\n {\r\n long min = params[0] > params[1] ? params[1] : params[0];\r\n long max = params[0] > params[1] ? params[0] : params[1];\r\n long res = (max / min) + (max % min) - 1;\r\n writeln(res <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long d = params[2];\r\n \r\n if(params[0] <= 0 || params[1] <= 0)\r\n {\r\n writeln(\"NO\");\r\n }\r\n else\r\n {\r\n long min = params[0] > params[1] ? params[1] : params[0];\r\n long max = params[0] > params[1] ? params[0] : params[1];\r\n long res = (max / min) + (max % min) - 1;\r\n writeln(res <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long d = params[2];\r\n \r\n if(params[0] <= 0 || params[1] <= 0)\r\n {\r\n writeln(\"NO\");\r\n }\r\n else\r\n {\r\n long min = params[0] > params[1] ? params[1] : params[0];\r\n long max = params[0] > params[1] ? params[0] : params[1];\r\n long res = (max / min) - 1;\r\n writeln(max % min <= d && res <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long d = params[2];\r\n \r\n if(params[0] <= 0 || params[1] <= 0)\r\n {\r\n writeln(\"NO\");\r\n }\r\n else\r\n {\r\n long min = params[0] > params[1] ? params[1] : params[0];\r\n long max = params[0] > params[1] ? params[0] : params[1];\r\n long res = (max / min) - min;\r\n writeln(res >= 0 && res <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long d = params[2];\r\n \r\n if(params[0] <= 0 || params[1] <= 0)\r\n {\r\n writeln(\"NO\");\r\n }\r\n else\r\n {\r\n long min = params[0] > params[1] ? params[1] : params[0];\r\n long max = params[0] > params[1] ? params[0] : params[1];\r\n \r\n writeln(abs((max / min) - min) <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int d = params[2];\r\n \r\n if(params[0] == 0 || params[1] == 0)\r\n {\r\n writeln(\"NO\");\r\n }\r\n if(params[0] == 1 || params[1] == 1)\r\n {\r\n writeln(d == 0 ? \"YES\" : \"NO\");\r\n }\r\n else\r\n {\r\n int min = params[0] > params[1] ? params[1] : params[0];\r\n int max = params[0] > params[1] ? params[0] : params[1];\r\n \r\n writeln(abs((max / min) - min) <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int d = params[2];\r\n \r\n if(params[0] == 0 || params[1] == 0)\r\n {\r\n writeln(\"NO\");\r\n }\r\n else\r\n {\r\n int min = params[0] > params[1] ? params[1] : params[0];\r\n int max = params[0] > params[1] ? params[0] : params[1];\r\n \r\n writeln(abs((max / min) - min) <= d ? \"YES\" : \"NO\");\r\n }\r\n }\r\n}"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1519/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int r, b, d;\n readf(\"%s %s %s\\n\", &r, &b, &d);\n if(r > b)\n swap(r,b);\n if(b <= r*(d + 1))\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n"}], "src_uid": "c0ad2a6d14b0c9e09af2221d88a34d52"} {"source_code": "import std.stdio;\nimport std.algorithm;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\tint c=0;\n\t\tint d=0;\n\t\tint e=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\treadf(\" %d\", &d);\n\t\treadf(\" %d\", &e);\n\t\tint r=a/2;\n\t\tint sum=0;\n\t\tif (d==e)\n\t\t{\n\t\t\tsum=sum+min(r,b+c)*d;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (d>e)\n\t\t\t{\n\t\t\t\tsum=sum+min(r, b)*d+min(r-min(r,b),c)*e;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsum=sum+min(r, c)*e+min(r-min(r,c),b)*d;\n\t\t\t}\n\t\t}\n\t\twriteln(sum);\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto bpf = RDA;\n\t\tauto b = bpf[0];\n\t\tauto hc = RDA;\n\t\tlong cnt1, cnt2;\n\t\tif (hc[0] > hc[1])\n\t\t{\n\t\t\tcnt1 = bpf[1];\n\t\t\tcnt2 = bpf[2];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcnt1 = bpf[2];\n\t\t\tcnt2 = bpf[1];\n\t\t}\n\t\tauto c1 = min(cnt1, b/2);\n\t\tb -= c1 * 2;\n\t\tans[i] += c1 * max(hc[0], hc[1]);\n\t\tauto c2 = min(cnt2, b/2);\n\t\tans[i] += c2 * min(hc[0], hc[1]);\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "92bf30e66f4d5ddebb697d2fa4fa0689"} {"source_code": "import std.stdio, std.string;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n readln;\r\n ulong cnt = readln.chomp.count('0');\r\n if (cnt == 1)\r\n writeln(\"BOB\");\r\n else if (cnt % 2)\r\n writeln(\"ALICE\");\r\n else\r\n writeln(\"BOB\");\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tlong cnt;\r\n\t\tforeach (c; s)\r\n\t\t{\r\n\t\t\tif (c == '0')\r\n\t\t\t\t++cnt;\r\n\t\t}\r\n\r\n\t\tif (cnt % 2)\r\n\t\t\tans[ti] = cnt == 1 ? -1 : 1;\r\n\t\telse\r\n\t\t\tans[ti] = -1;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e == 1 ? \"ALICE\" : e == -1 ? \"BOB\" : \"DRAW\");\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.chomp)) {\r\n int n = to!int(readln.chomp);\r\n string s = readln.chomp;\r\n bool pal = true;\r\n int open = 0;\r\n foreach(i; 0 .. s.length/2) {\r\n if(s[i] == s[$-(1+i)]) {\r\n if(s[i] == '0') open += 2;\r\n } else {\r\n open++;\r\n pal = false;\r\n }\r\n }\r\n if(pal) {\r\n if(n == 1) {\r\n writeln(\"BOB\");\r\n } else if(n%2) {\r\n if(s[$/2] == '0' && open) writeln(\"ALICE\");\r\n else writeln(\"BOB\");\r\n } else {\r\n writeln(\"BOB\");\r\n }\r\n\r\n } else {\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tlong cnt;\r\n\t\tforeach (c; s)\r\n\t\t{\r\n\t\t\tif (c == '0')\r\n\t\t\t\t++cnt;\r\n\t\t}\r\n\r\n\t\tif (cnt % 2)\r\n\t\t\tans[ti] = cnt <= 3 ? -1 : 1;\r\n\t\telse\r\n\t\t\tans[ti] = -1;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e == 1 ? \"ALICE\" : e == -1 ? \"BOB\" : \"DRAW\");\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tlong cnt;\r\n\t\tforeach (c; s)\r\n\t\t{\r\n\t\t\tif (c == '0')\r\n\t\t\t\t++cnt;\r\n\t\t}\r\n\r\n\t\tif (cnt % 2)\r\n\t\t\tans[ti] = ((cnt/2) % 2) ? 1 : -1;\r\n\t\telse\r\n\t\t\tans[ti] = -1;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e == 1 ? \"ALICE\" : e == -1 ? \"BOB\" : \"DRAW\");\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tlong cnt;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == '0')\n\t\t\t\t++cnt;\n\t\t}\n\n\t\tif (cnt % 2)\n\t\t\tans[ti] = ((cnt/2) % 2) ? 1 : -1;\n\t\telse\n\t\t\tans[ti] = ((cnt/2) % 2) ? -1 : 0;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e == 1 ? \"ALICE\" : e == -1 ? \"BOB\" : \"DRAW\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tlong cnt;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == '0')\n\t\t\t\t++cnt;\n\t\t}\n\t\tif (cnt == 0) continue;\n\n\t\tif (cnt % 2)\n\t\t\tans[ti] = (cnt/2) % 2 ? 1 : -1;\n\t\telse\n\t\t\tans[ti] = cnt % 4 ? -1 : 0;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e == 1 ? \"ALICE\" : e == -1 ? \"BOB\" : \"DRAW\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tlong cnt;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == '0')\n\t\t\t\t++cnt;\n\t\t}\n\t\tif (cnt == 0) continue;\n\n\t\tif (n % 2 && s[n/2] == '0')\n\t\t{\n\t\t\tif (cnt % 2 == 0)\n\t\t\t\tans[ti] = 0;\n\t\t\telse\n\t\t\t\tans[ti] = (cnt/2) % 2 ? 1 : -1;\n\t\t}\n\t\telse\n\t\t\tans[ti] = cnt % 4 ? -1 : 0;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e == 1 ? \"ALICE\" : e == -1 ? \"BOB\" : \"DRAW\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto s = RD!string;\n\n\t\tlong cnt;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == '0')\n\t\t\t\t++cnt;\n\t\t}\n\t\tif (cnt == 0) continue;\n\t\tans[ti] = cnt % 4 ? -1 : 0;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e == 1 ? \"ALICE\" : e == -1 ? \"BOB\" : \"DRAW\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto s = RD!string;\n\n\t\tlong cnt;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == '0')\n\t\t\t\t++cnt;\n\t\t}\n\t\tans[ti] = cnt % 4 ? -1 : 0;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e == 1 ? \"ALICE\" : e == -1 ? \"BOB\" : \"DRAW\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.chomp)) {\r\n int n = to!int(readln.chomp);\r\n string s = readln.chomp;\r\n bool pal = true;\r\n int open = 0;\r\n foreach(i; 0 .. s.length/2) {\r\n if(s[i] == s[$-(1+i)]) {\r\n if(s[i] == '0') open += 2;\r\n } else {\r\n open++;\r\n pal = false;\r\n }\r\n }\r\n if(pal) {\r\n if(n == 1) {\r\n writeln(\"BOB\");\r\n } else if(n%2) {\r\n if(s[$/2] == '0') writeln(\"ALICE\");\r\n else writeln(\"BOB\");\r\n } else {\r\n writeln(\"BOB\");\r\n }\r\n\r\n } else {\r\n }\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.chomp)) {\r\n int n = to!int(readln.chomp);\r\n string s = readln.chomp;\r\n bool pal = true;\r\n int open = 0;\r\n foreach(i; 0 .. s.length/2) {\r\n if(s[i] == s[$-(1+i)]) {\r\n if(s[i] == '0') open += 2;\r\n } else {\r\n open++;\r\n pal = false;\r\n }\r\n }\r\n if(pal) {\r\n if(n == 1) {\r\n writeln(\"BOB\");\r\n } else if(n%2) {\r\n if(s[$/2+1] == '0') writeln(\"ALICE\");\r\n else writeln(\"BOB\");\r\n } else {\r\n writeln(\"BOB\");\r\n }\r\n\r\n } else {\r\n }\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.chomp)) {\r\n int n = to!int(readln.chomp);\r\n string s = readln.chomp;\r\n bool pal = true;\r\n int open = 0;\r\n foreach(i; 0 .. s.length/2) {\r\n if(s[i] == s[$-(1+i)]) {\r\n if(s[i] == '0') open += 2;\r\n } else {\r\n open++;\r\n pal = false;\r\n }\r\n }\r\n if(pal) {\r\n if(n == 1) {\r\n writeln(\"BOB\");\r\n } else if(n%2) {\r\n writeln(\"ALICE\");\r\n } else {\r\n writeln(\"BOB\");\r\n }\r\n\r\n } else {\r\n }\r\n }\r\n}\r\n"}], "src_uid": "42b425305ccc28b0d081b4c417fe77a1"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\nauto pair(S, T)(inout(S) x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint root(int[] uf, int u) {\n\treturn (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool conn(int[] uf, int u, int v) {\n\tu = uf.root(u);\n\tv = uf.root(v);\n\tif (u == v) return false;\n\tif (uf[u] > uf[v]) swap(u, v);\n\tuf[u] += uf[v];\n\tuf[v] = u;\n\treturn true;\n}\n\nPair!(int, int[]) scc(int[][] g0, int[][] g1) {\n\tint n = g0.length;\n\tint compN;\n\tint[] compIds = new int[n];\n\tvoid dfs(int[][] g, int u, int a, int b, ref int[] st) {\n\t\tif (compIds[u] == a) {\n\t\t\tcompIds[u] = b;\n\t\t\tforeach (v; g[u]) dfs(g, v, a, b, st);\n\t\t\tst ~= u;\n\t\t}\n\t}\n\tint[] stack, dump;\n\tforeach (u; 0 .. n) {\n\t\tdfs(g0, u, 0, -1, stack);\n\t}\n\tfor (; !stack.empty; ) {\n\t\tint u = stack[$ - 1];\n\t\tif (compIds[u] == -1) {\n\t\t\tdfs(g1, u, -1, compN, dump);\n\t\t\t++compN;\n\t\t}\n\t\tstack.popBack;\n\t}\n\treturn pair(compN, compIds);\n}\n\nint N, M;\nint[] A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tM = readInt;\n\t\tA = new int[M];\n\t\tB = new int[M];\n\t\tforeach (i; 0 .. M) {\n\t\t\tA[i] = readInt - 1;\n\t\t\tB[i] = readInt - 1;\n\t\t}\n\t\t\n\t\tint[] uf = new int[N];\n\t\tfill(uf, -1);\n\t\tforeach (i; 0 .. M) {\n\t\t\tuf.conn(A[i], B[i]);\n\t\t}\n\t\tint[][] uComps = new int[][N];\n\t\tforeach (u; 0 .. N) {\n\t\t\tuComps[uf.root(u)] ~= u;\n\t\t}\n\t\t\n\t\tint[][] g0 = new int[][N];\n\t\tint[][] g1 = new int[][N];\n\t\tforeach (i; 0 .. M) {\n\t\t\tg0[A[i]] ~= B[i];\n\t\t\tg1[B[i]] ~= A[i];\n\t\t}\n\t\tint[] compIds = scc(g0, g1).y;\n\t\t\n\t\tint ans;\n\t\tforeach (uComp; uComps) if (!uComp.empty) {\n\t\t\tconst int sz = uComp.length;\n\t\t\tint[] ids = new int[sz];\n\t\t\tforeach (j; 0 .. sz) {\n\t\t\t\tids[j] = compIds[uComp[j]];\n\t\t\t}\n\t\t\tids.sort();\n\t\t\tbool ok = true;\n\t\t\tforeach (j; 1 .. sz) {\n\t\t\t\tok = ok && (ids[j - 1] != ids[j]);\n\t\t\t}\n\t\t\tans += ok ? (sz - 1) : sz;\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.range, std.string, std.typecons;\nimport std.algorithm, std.container, std.math, std.numeric, std.random;\nvoid scan(T...)(ref T args) { foreach (ref arg; args) readf(\" %s\", &arg); }\nvoid minify(T)(ref T a, in T b) { if (a > b) a = b; }\nvoid maxify(T)(ref T a, in T b) { if (a < b) a = b; }\nvoid ewriteln(T...)(T args) { stderr.writeln(\"\\033[35m\", args, \"\\033[0m\"); }\nint ilen(T)(const ref T a) { return cast(int)(a.length); }\n\nenum int N = 10 ^^ 5 + 8;\nint n, m;\nArray!int[N] graph;\nArray!int[N] antigraph;\nint[N] outdeg;\nbool[N] vis;\nArray!int curv;\nint cost = 0;\n\nvoid dfs(int v) {\n\tif (vis[v]) return;\n\tcurv ~= v;\n\tvis[v] = true;\n\tforeach (w; graph[v]) { dfs(w); }\n\tforeach (w; antigraph[v]) { dfs(w); }\n}\n\nSList!int out0;\nvoid solveFrom(int v0) {\n\tif (!vis[v0]) {\n\t\tcurv.length = 0;\n\t\tdfs(v0);\n\t\tout0.clear();\n\t\tdebug {\n\t\t\tewriteln(\"solving from: \", v0);\n\t\t\tewriteln(\" curv cap \", curv.capacity);\n\t\t\tewriteln(\" out0 cap \", out0.capacity);\n\t\t}\n\t\tint ovs = 0;\n\t\tforeach (v; curv) {\n\t\t\toutdeg[v] = graph[v].ilen;\n\t\t\tif (outdeg[v] == 0) {\n\t\t\t\tout0.insertFront(v);\n\t\t\t\tovs++;\n\t\t\t}\n\t\t}\n\t\twhile (!out0.empty) {\n\t\t\tint v = out0.front; out0.removeFront();\n\t\t\tforeach (w; antigraph[v]) {\n\t\t\t\tassert(outdeg[w] >= 1);\n\t\t\t\toutdeg[w]--;\n\t\t\t\tif (outdeg[w] == 0) {\n\t\t\t\t\tout0.insertFront(w);\n\t\t\t\t\tovs++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;\n\t}\n}\n\nint solve() {\n\tforeach (i; 1..n+1) { solveFrom(i); }\n\treturn cost;\n}\n\nvoid main() {\n\tscan(n, m);\n\tforeach(_; 0..m) {\n\t\tint a, b;\n\t\tscan(a, b);\n\t\tgraph[a] ~= b;\n\t\tantigraph[b] ~= a;\n\t}\n\twriteln(solve());\n}\n"}, {"source_code": "import std.stdio, std.array, std.range, std.string, std.typecons;\nimport std.algorithm, std.container, std.math, std.numeric, std.random;\nvoid scan(T...)(ref T args) { foreach (ref arg; args) readf(\" %s\", &arg); }\nvoid minify(T)(ref T a, in T b) { if (a > b) a = b; }\nvoid maxify(T)(ref T a, in T b) { if (a < b) a = b; }\nvoid ewriteln(T...)(T args) { stderr.writeln(\"\\033[35m\", args, \"\\033[0m\"); }\nint ilen(T)(const ref T a) { return cast(int)(a.length); }\nvoid push(T)(ref Array!T a, in T b) {\n\tif (a.length == a.capacity) a.reserve(2*a.capacity + 1);\n\ta ~= b;\n}\n\nenum int N = 10 ^^ 5 + 8;\nint n, m;\nArray!int[N] graph;\nArray!int[N] antigraph;\nint[N] outdeg;\nbool[N] vis;\nArray!int curv;\nint cost = 0;\n\nvoid dfs(int v) {\n\tif (vis[v]) return;\n\tcurv.push(v);\n\tvis[v] = true;\n\tforeach (w; graph[v]) { dfs(w); }\n\tforeach (w; antigraph[v]) { dfs(w); }\n}\n\nArray!int out0;\nvoid solveFrom(int v0) {\n\tif (!vis[v0]) {\n\t\tcurv.length = 0;\n\t\tdfs(v0);\n\t\tout0.length = 0;\n\t\tdebug {\n\t\t\tewriteln(\"solving from: \", v0);\n\t\t\tewriteln(\" curv cap \", curv.capacity);\n\t\t\tewriteln(\" out0 cap \", out0.capacity);\n\t\t}\n\t\tint ovs = 0;\n\t\tforeach (v; curv) {\n\t\t\toutdeg[v] = graph[v].ilen;\n\t\t\tif (outdeg[v] == 0) {\n\t\t\t\tout0.push(v);\n\t\t\t\tovs++;\n\t\t\t}\n\t\t}\n\t\twhile (!out0.empty) {\n\t\t\tint v = out0.back; out0.removeBack();\n\t\t\tforeach (w; antigraph[v]) {\n\t\t\t\tassert(outdeg[w] >= 1);\n\t\t\t\toutdeg[w]--;\n\t\t\t\tif (outdeg[w] == 0) {\n\t\t\t\t\tout0.push(w);\n\t\t\t\t\tovs++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;\n\t}\n}\n\nint solve() {\n\tforeach (i; 1..n+1) { solveFrom(i); }\n\treturn cost;\n}\n\nvoid main() {\n\tscan(n, m);\n\tforeach(_; 0..m) {\n\t\tint a, b;\n\t\tscan(a, b);\n\t\tgraph[a].push(b);\n\t\tantigraph[b].push(a);\n\t}\n\twriteln(solve());\n}\n"}, {"source_code": "import std.stdio, std.array, std.range, std.string, std.typecons;\nimport std.algorithm, std.container, std.math, std.numeric, std.random;\nvoid scan(T...)(ref T args) { foreach (ref arg; args) scanf(\"%d\", &arg); }\nvoid minify(T)(ref T a, in T b) { if (a > b) a = b; }\nvoid maxify(T)(ref T a, in T b) { if (a < b) a = b; }\nvoid ewriteln(T...)(T args) { stderr.writeln(\"\\033[35m\", args, \"\\033[0m\"); }\nint ilen(T)(const ref T a) { return cast(int)(a.length); }\nvoid push(T)(ref Array!T a, in T b) {\n\t// if (a.length == a.capacity) a.reserve(2*a.capacity + 1);\n\ta ~= b;\n}\n\nenum int N = 10 ^^ 5 + 8;\nint n, m;\nArray!int[N] graph;\nArray!int[N] antigraph;\nint[N] outdeg;\nbool[N] vis;\nArray!int curv;\nint cost = 0;\n\nvoid dfs(int v) {\n\tif (vis[v]) return;\n\tcurv.push(v);\n\tvis[v] = true;\n\tforeach (w; graph[v]) { dfs(w); }\n\tforeach (w; antigraph[v]) { dfs(w); }\n}\n\nArray!int out0;\nvoid solveFrom(int v0) {\n\tif (!vis[v0]) {\n\t\tcurv.length = 0;\n\t\tdfs(v0);\n\t\tout0.length = 0;\n\t\tdebug {\n\t\t\tewriteln(\"solving from: \", v0);\n\t\t\tewriteln(\" curv cap \", curv.capacity);\n\t\t\tewriteln(\" out0 cap \", out0.capacity);\n\t\t}\n\t\tint ovs = 0;\n\t\tforeach (v; curv) {\n\t\t\toutdeg[v] = graph[v].ilen;\n\t\t\tif (outdeg[v] == 0) {\n\t\t\t\tout0.push(v);\n\t\t\t\tovs++;\n\t\t\t}\n\t\t}\n\t\twhile (!out0.empty) {\n\t\t\tint v = out0.back; out0.removeBack();\n\t\t\tforeach (w; antigraph[v]) {\n\t\t\t\tassert(outdeg[w] >= 1);\n\t\t\t\toutdeg[w]--;\n\t\t\t\tif (outdeg[w] == 0) {\n\t\t\t\t\tout0.push(w);\n\t\t\t\t\tovs++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;\n\t}\n}\n\nint solve() {\n\tforeach (i; 1..n+1) { solveFrom(i); }\n\treturn cost;\n}\n\nvoid main() {\n\tscan(n, m);\n\tforeach(_; 0..m) {\n\t\tint a, b;\n\t\tscan(a, b);\n\t\tgraph[a].push(b);\n\t\tantigraph[b].push(a);\n\t}\n\twriteln(solve());\n}\n"}, {"source_code": "import std.stdio, std.array, std.range, std.string, std.typecons;\nimport std.algorithm, std.container, std.math, std.numeric, std.random;\nvoid scan(T...)(ref T args) { foreach (ref arg; args) readf(\" %s\", &arg); }\nvoid minify(T)(ref T a, in T b) { if (a > b) a = b; }\nvoid maxify(T)(ref T a, in T b) { if (a < b) a = b; }\nvoid ewriteln(T...)(T args) { stderr.writeln(\"\\033[35m\", args, \"\\033[0m\"); }\nint ilen(T)(const ref T a) { return cast(int)(a.length); }\n\nenum int N = 10 ^^ 5 + 8;\nint n, m;\nArray!int[N] graph;\nArray!int[N] antigraph;\nint[N] outdeg;\nbool[N] vis;\nArray!int curv;\nint cost = 0;\n\nvoid dfs(int v) {\n\tif (vis[v]) return;\n\tcurv ~= v;\n\tvis[v] = true;\n\tforeach (w; graph[v]) { dfs(w); }\n\tforeach (w; antigraph[v]) { dfs(w); }\n}\n\nArray!int out0;\nvoid solveFrom(int v0) {\n\tif (!vis[v0]) {\n\t\tcurv.length = 0;\n\t\tdfs(v0);\n\t\tout0.length = 0;\n\t\tdebug {\n\t\t\tewriteln(\"solving from: \", v0);\n\t\t\tewriteln(\" curv cap \", curv.capacity);\n\t\t\tewriteln(\" out0 cap \", out0.capacity);\n\t\t}\n\t\tint ovs = 0;\n\t\tforeach (v; curv) {\n\t\t\toutdeg[v] = graph[v].ilen;\n\t\t\tif (outdeg[v] == 0) {\n\t\t\t\tout0 ~= v;\n\t\t\t\tovs++;\n\t\t\t}\n\t\t}\n\t\twhile (!out0.empty) {\n\t\t\tint v = out0.back; out0.removeBack();\n\t\t\tforeach (w; antigraph[v]) {\n\t\t\t\tassert(outdeg[w] >= 1);\n\t\t\t\toutdeg[w]--;\n\t\t\t\tif (outdeg[w] == 0) {\n\t\t\t\t\tout0 ~= w;\n\t\t\t\t\tovs++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;\n\t}\n}\n\nint solve() {\n\tforeach (i; 1..n+1) { solveFrom(i); }\n\treturn cost;\n}\n\nvoid main() {\n\tscan(n, m);\n\tforeach(_; 0..m) {\n\t\tint a, b;\n\t\tscan(a, b);\n\t\tgraph[a] ~= b;\n\t\tantigraph[b] ~= a;\n\t}\n\twriteln(solve());\n}\n"}], "negative_code": [], "src_uid": "586204a0e1ba55208fd92ca61bd4d9b5"} {"source_code": "void main(){\n import std.stdio, std.algorithm, std.string, std.conv;\n\n struct P{\n int idx1, idx2;\n }\n int K; rd(K);\n P[int] set;\n for(int k=1; k<=K; k++){\n int n; rd(n);\n auto as=readln.split.to!(int[]);\n int s=reduce!\"a+b\"(as);\n P[] cand;\n foreach(int i, a; as){\n int t=s-a;\n if(t in set){\n if(set[t].idx1<k){\n writeln(\"YES\");\n writeln(set[t].idx1, \" \", set[t].idx2);\n writeln(k, \" \", i+1);\n return;\n }\n }else{\n set[t]=P(k, i+1);\n }\n }\n }\n\n writeln(\"NO\");\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n Tuple!(int, int)[long] D;\n\n foreach (i; 0..N) {\n auto M = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n auto S = A.sum;\n foreach (j; 0..M) {\n auto T = S - A[j];\n if (T in D) {\n if (D[T][0] != i + 1) {\n writeln(\"YES\");\n writeln(D[T][0], \" \", D[T][1]);\n writeln(i+1, \" \", j+1);\n return;\n }\n } else {\n D[T] = tuple(i+1, j+1);\n }\n }\n }\n\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int[][] a;\n foreach (_; 0..n) {\n readln;\n a ~= readln.chomp.split.map!(to!int).array;\n }\n \n debug { a.writeln; }\n \n Tuple!(int, int) [int] v;\n \n foreach (i, s; a.enumerate(1)) {\n int sm = s.sum;\n foreach (j, e; s.enumerate(1)) {\n int cur = sm - e;\n if (cur in v) {\n writeln(\"YES\");\n writeln(v[cur][0], ' ', v[cur][1]);\n writeln(i, ' ', j);\n return;\n }\n }\n \n foreach (j, e; s.enumerate(1)) {\n int cur = sm - e;\n v[cur] = tuple(i, j);\n }\n }\n \n writeln(\"NO\");\n}"}], "negative_code": [], "src_uid": "7561bca5fa2200ce9ae7e30e7076c6ab"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 10 ^^ 9 + 7;\nimmutable int limit = 1003;\n\nvoid add (ref int a, int b)\n{\n\ta = (a + b) % mod;\n}\n\nvoid main ()\n{\n\tauto h = new int [limit];\n\th[1] = 0;\n\tforeach (i; 2..limit)\n\t{\n\t\th[i] = h[popcnt (i)] + 1;\n\t}\n\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto k = readln.strip.to !(int);\n\t\tif (k == 0)\n\t\t{\n\t\t\twriteln (1);\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto n = s.length.to !(int);\n\t\tauto f = new int [2] [] [] (n + 1, n + 1);\n\t\tf[0][0][0] = 1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint lim = (s[i] == '1');\n\t\t\tforeach (j; 0..i + 1)\n\t\t\t{\n\t\t\t\tforeach (prevLess; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (cur; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((cur > lim) && !prevLess)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint nextLess = prevLess ||\n\t\t\t\t\t\t (cur < lim);\n\t\t\t\t\t\tadd (f[i + 1][j + cur]\n\t\t\t\t\t\t [nextLess], f[i][j]\n\t\t\t\t\t\t [prevLess]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tadd (f[n][1][1], mod - 1);\n\n\t\tint res = 0;\n\t\tforeach (j; 1..n + 1)\n\t\t{\n\t\t\tif (h[j] == k - 1)\n\t\t\t{\n\t\t\t\tadd (res, f[n][j][0]);\n\t\t\t\tadd (res, f[n][j][1]);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nlong MOD = 10^^9 + 7;\n\nvoid main() {\n auto N = readln.chomp;\n auto K = readln.chomp.to!int;\n auto dp = new int[](1001);\n dp[1] = 1;\n\n for (int i = 2; i <= 1000; ++i) {\n dp[i] = dp[i.popcnt] + 1;\n }\n\n auto dp2 = new long[][][](N.length+1, N.length+1, 2);\n dp2[0][0][0] = 1;\n\n foreach (i; 0..N.length) {\n foreach (j; 0..N.length+1) {\n foreach (k; 0..2) {\n int digit = (k || N[i] == '1') ? 2 : 1;\n foreach (d; 0..digit) {\n if (j+d <= N.length)\n (dp2[i+1][j+d][k||(d < N[i]-'0')] += dp2[i][j][k]) %= MOD;\n }\n }\n }\n }\n\n long ans = 0;\n foreach (i; 1..N.length+1) {\n if (dp[i] == K) {\n (ans += dp2[N.length][i][0]) %= MOD;\n (ans += dp2[N.length][i][1]) %= MOD;\n }\n }\n\n if (K == 1) {\n ans -= 1;\n ans %= MOD;\n } else if (K == 0) {\n ans = 1;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n import std.conv : to;\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n if (a < 0) return (this = inv()^^(-a));\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e > 0; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op: \"-\")() const { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const {\n return mixin(\"ModInt(this) \" ~ op ~ \"= a\");\n }\n ModInt opBinaryRight(string op)(long a) const {\n return mixin(\"ModInt(a) \" ~ op ~ \"= this\");\n }\n bool opCast(T: bool)() const { return (x != 0); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 7;\nalias Mint = ModInt!MO;\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readToken();\n const K = readInt();\n const L = cast(int)(N.length);\n \n auto numSteps = new int[L + 1];\n foreach (i; 2 .. L + 1) {\n numSteps[i] = 1 + numSteps[popcnt(i)];\n }\n debug {\n writeln(\"numSteps = \", numSteps);\n }\n \n auto dp = new Mint[][][](L + 1, 2, L + 1);\n dp[0][0][0] = 1;\n foreach (i; 0 .. L) {\n foreach (s; 0 .. 2) foreach (j; 0 .. i + 1) {\n foreach (x; 0 .. 2) {\n if (s || x <= N[i] - '0') {\n dp[i + 1][(s || x < N[i] - '0') ? 1 : 0][j + x] += dp[i][s][j];\n }\n }\n }\n }\n Mint ans;\n if (K == 0) {\n // 1 <= N\n ans += 1;\n } else {\n foreach (s; 0 .. 2) foreach (j; 1 .. L + 1) {\n if (K == 1 + numSteps[j]) {\n ans += dp[L][s][j];\n }\n }\n if (K == 1) {\n // 1 <= N\n ans -= 1;\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 10 ^^ 9 + 7;\nimmutable int limit = 1003;\n\nvoid add (ref int a, int b)\n{\n\ta = (a + b) % mod;\n}\n\nvoid main ()\n{\n\tauto h = new int [limit];\n\th[1] = 0;\n\tforeach (i; 2..limit)\n\t{\n\t\th[i] = h[popcnt (i)] + 1;\n\t}\n\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto k = readln.strip.to !(int);\n\t\tif ((k == 0) || (s == \"1\"))\n\t\t{\n\t\t\tint res = (k == 0) && (s == \"1\");\n\t\t\twriteln (res);\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto n = s.length.to !(int);\n\t\tauto f = new int [2] [] [] (n + 1, n + 1);\n\t\tf[0][0][0] = 1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint lim = (s[i] == '1');\n\t\t\tforeach (j; 0..i + 1)\n\t\t\t{\n\t\t\t\tforeach (prevLess; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (cur; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((cur > lim) && !prevLess)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint nextLess = prevLess ||\n\t\t\t\t\t\t (cur < lim);\n\t\t\t\t\t\tadd (f[i + 1][j + cur]\n\t\t\t\t\t\t [nextLess], f[i][j]\n\t\t\t\t\t\t [prevLess]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tadd (f[n][1][0], mod - 1);\n\n\t\tint res = 0;\n\t\tforeach (j; 1..n + 1)\n\t\t{\n\t\t\tif (h[j] == k - 1)\n\t\t\t{\n\t\t\t\tadd (res, f[n][j][0]);\n\t\t\t\tadd (res, f[n][j][1]);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n import std.conv : to;\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n if (a < 0) return (this = inv()^^(-a));\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e > 0; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op: \"-\")() const { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const {\n return mixin(\"ModInt(this) \" ~ op ~ \"= a\");\n }\n ModInt opBinaryRight(string op)(long a) const {\n return mixin(\"ModInt(a) \" ~ op ~ \"= this\");\n }\n bool opCast(T: bool)() const { return (x != 0); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 7;\nalias Mint = ModInt!MO;\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readToken();\n const K = readInt();\n const L = cast(int)(N.length);\n \n auto numSteps = new int[L + 1];\n foreach (i; 2 .. L + 1) {\n numSteps[i] = 1 + numSteps[popcnt(i)];\n }\n debug {\n writeln(\"numSteps = \", numSteps);\n }\n \n auto dp = new Mint[][][](L + 1, 2, L + 1);\n dp[0][0][0] = 1;\n foreach (i; 0 .. L) {\n foreach (s; 0 .. 2) foreach (j; 0 .. i + 1) {\n foreach (x; 0 .. 2) {\n if (s || x <= N[i] - '0') {\n dp[i + 1][(s || x < N[i] - '0') ? 1 : 0][j + x] += dp[i][s][j];\n }\n }\n }\n }\n Mint ans;\n if (K == 0) {\n // 1 <= N\n ans = 1;\n } else {\n foreach (s; 0 .. 2) foreach (j; 1 .. L + 1) {\n if (K == 1 + numSteps[j]) {\n ans += dp[L][s][j];\n }\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "e367f5d18b08882ec518b2d4188ccdea"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nreal vp (real x0, real y0, real x1, real y1, real x2, real y2)\n{\n\treturn (x2 - x0) * (y1 - y0) - (x1 - x0) * (y2 - y0);\n}\n\nvoid main ()\n{\n\tint n;\n\treal p, q;\n\twhile (readf (\" %s %s %s\", &n, &p, &q) > 0)\n\t{\n\t\talias Point = Tuple !(real, q{x}, real, q{y});\n\t\tauto a = new Point [n];\n\t\tforeach (ref z; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &z.x, &z.y);\n\t\t}\n\t\tsort !((a, b) => (vp (0, 0, a.x, a.y, b.x, b.y) < 0) ||\n\t\t (vp (0, 0, a.x, a.y, b.x, b.y) == 0 &&\n\t\t hypot (a.y, a.x) < hypot (b.y, b.x))) (a);\n\t\ta = a.uniq.array;\n/*\n\t\tPoint [] c;\n\t\tforeach (ref z; a)\n\t\t{\n\t\t\tif (!c.empty &&\n\t\t\t (vp (0, 0, z.x, z.y, c[0].x, c[0].y) == 0 &&\n\t\t\t hypot (z.y, z.x) >= hypot (c[0].y, c[0].x)))\n\t\t\t{\n\t\t\t\tc.popBack ();\n\t\t\t\tc.assumeSafeAppend ();\n\t\t\t}\n\t\t\tc ~= z;\n\t\t}\n\t\tdebug {writeln (c);}\n\t\ta = c;\n*/\n n = a.length;\n\t\tPoint [] b;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twhile (b.length >= 2 &&\n\t\t\t vp (b[$ - 2].x, b[$ - 2].y,\n\t\t\t b[$ - 1].x, b[$ - 1].y, a[i].x, a[i].y) > 0)\n\t\t\t{\n\t\t\t\tb.popBack ();\n\t\t\t\tb.assumeSafeAppend ();\n\t\t\t}\n\t\t\tb ~= a[i];\n\t\t}\n\t\tdebug {writeln (b);}\n\n\t\treal res = 1E100;\n\t\tforeach (i; 0..b.length)\n\t\t{\n\t\t\tres = min (res, max (p / b[i].x, q / b[i].y));\n\t\t\tif (i > 0 && vp (0, 0, b[i - 1].x, b[i - 1].y, p, q) *\n\t\t\t vp (0, 0, b[i].x, b[i].y, p, q) < 0)\n\t\t\t{\n\t\t\t\treal lo = 0;\n\t\t\t\treal hi = 1;\n\t\t\t\tforeach (j; 0..100)\n\t\t\t\t{\n\t\t\t\t\treal me = (lo + hi) * 0.5;\n\t\t\t\t\treal ppart1 = me * p;\n\t\t\t\t\treal ppart2 = p - ppart1;\n\t\t\t\t\treal t1 = ppart1 / b[i - 1].x;\n\t\t\t\t\treal t2 = ppart2 / b[i].x;\n\t\t\t\t\treal qpart1 = t1 * b[i - 1].y;\n\t\t\t\t\treal qpart2 = t2 * b[i].y;\n\t\t\t\t\tif (q < qpart1 + qpart2)\n\t\t\t\t\t{\n\t\t\t\t\t\tlo = me;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\thi = me;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (lo);}\n\t\t\t\treal ppart1 = lo * p;\n\t\t\t\treal ppart2 = p - ppart1;\n\t\t\t\treal t1 = ppart1 / b[i - 1].x;\n\t\t\t\treal t2 = ppart2 / b[i].x;\n\t\t\t\tres = min (res, t1 + t2);\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%.10f\", res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nreal vp (real x0, real y0, real x1, real y1, real x2, real y2)\n{\n\treturn (x2 - x0) * (y1 - y0) - (x1 - x0) * (y2 - y0);\n}\n\nvoid main ()\n{\n\tint n;\n\treal p, q;\n\twhile (readf (\" %s %s %s\", &n, &p, &q) > 0)\n\t{\n\t\talias Point = Tuple !(real, q{x}, real, q{y});\n\t\tauto a = new Point [n];\n\t\tforeach (ref z; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &z.x, &z.y);\n\t\t}\n\t\tsort !((a, b) => (vp (0, 0, a.x, a.y, b.x, b.y) < 0) ||\n\t\t (vp (0, 0, a.x, a.y, b.x, b.y) == 0 &&\n\t\t hypot (a.y, a.x) < hypot (b.y, b.x))) (a);\n\t\ta = a.uniq.array;\n/*\n\t\tPoint [] c;\n\t\tforeach (ref z; a)\n\t\t{\n\t\t\tif (!c.empty &&\n\t\t\t (vp (0, 0, z.x, z.y, c[0].x, c[0].y) == 0 &&\n\t\t\t hypot (z.y, z.x) >= hypot (c[0].y, c[0].x)))\n\t\t\t{\n\t\t\t\tc.popBack ();\n\t\t\t\tc.assumeSafeAppend ();\n\t\t\t}\n\t\t\tc ~= z;\n\t\t}\n\t\tdebug {writeln (c);}\n\t\ta = c;\n*/\n n = a.length;\n\t\tPoint [] b;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twhile (b.length >= 2 &&\n\t\t\t vp (b[$ - 2].x, b[$ - 2].y,\n\t\t\t b[$ - 1].x, b[$ - 1].y, a[i].x, a[i].y) > 0)\n\t\t\t{\n\t\t\t\tb.popBack ();\n\t\t\t\tb.assumeSafeAppend ();\n\t\t\t}\n\t\t\tb ~= a[i];\n\t\t}\n\t\tdebug {writeln (b);}\n\n\t\treal res = 1E100;\n\t\tforeach (i; 0..b.length)\n\t\t{\n\t\t\tres = min (res, max (p / b[i].x, q / b[i].y));\n\t\t\tif (i > 0 && vp (0, 0, b[i - 1].x, b[i - 1].y, p, q) *\n\t\t\t vp (0, 0, b[i].x, b[i].y, p, q) < 0)\n\t\t\t{\n\t\t\t\treal lo = 0;\n\t\t\t\treal hi = 1;\n\t\t\t\tforeach (j; 0..100)\n\t\t\t\t{\n\t\t\t\t\treal me = (lo + hi) * 0.5;\n\t\t\t\t\treal ppart1 = me * p;\n\t\t\t\t\treal ppart2 = p - ppart1;\n\t\t\t\t\treal t1 = ppart1 / b[i - 1].x;\n\t\t\t\t\treal t2 = ppart2 / b[i].x;\n\t\t\t\t\treal qpart1 = t1 * b[i - 1].y;\n\t\t\t\t\treal qpart2 = t2 * b[i].y;\n\t\t\t\t\tif (q < qpart1 + qpart2)\n\t\t\t\t\t{\n\t\t\t\t\t\tlo = me;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\thi = me;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (lo);}\n\t\t\t\treal ppart1 = lo * p;\n\t\t\t\treal ppart2 = p - ppart1;\n\t\t\t\treal t1 = ppart1 / b[i - 1].x;\n\t\t\t\treal t2 = ppart2 / b[i].x;\n\t\t\t\tres = min (res, t1 + t2);\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%.10f\", res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "131db180c7afad3e5a3342407408fded"} {"source_code": "module sigod.codeforces.p296C;\n\nimport std.stdio;\n\nvoid main()\n{\n\tint n, m, k;\n\tstdin.readf(\" %s %s %s\", &n, &m, &k);\n\n\tlong[] a = new long[n + 2];\n\tforeach (i; 1 .. n + 1) {\n\t\tstdin.readf(\" %s\", &a[i]);\n\t}\n\n\tint[] l = new int[m + 1];\n\tint[] r = new int[m + 1];\n\tlong[] d = new long[m + 2];\n\n\tforeach (i; 1 .. m + 1) {\n\t\tstdin.readf(\" %s %s %s\", &l[i], &r[i], &d[i]);\n\t}\n\n\t// process requests\n\n\tint[] multipl = new int[m + 2];\n\n\tforeach (i; 0 .. k) {\n\t\tint x, y;\n\t\tstdin.readf(\" %s %s\", &x, &y);\n\n\t\t++multipl[x];\n\t\t--multipl[y + 1];\n\t}\n\n\tforeach (i; 1 .. m + 1) {\n\t\tmultipl[i] += multipl[i - 1];\n\n\t\td[i] *= multipl[i];\n\t}\n\n\t// process operations\n\n\tlong[] sum = new long[n + 2];\n\n\tforeach (i; 1 .. m + 1) {\n\t\tsum[l[i]] += d[i];\n\t\tsum[r[i] + 1] -= d[i];\n\t}\n\n\tforeach (i; 1 .. n + 1) {\n\t\tsum[i] += sum[i - 1];\n\n\t\ta[i] += sum[i];\n\t}\n\n\t// output\n\n\tforeach (i; 1 .. n + 1) {\n\t\tstdout.write(a[i], \" \");\n\t}\n}", "positive_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,m,k;\n readf!\"%d %d %d\"(n,m,k);\n readln;\n long[] a=readln.splitter.map!(to!long).array;\n //if(n==40) writeln(a);\n Tuple!(int,int,ulong)[] q;\n int l,r;\n ulong v;\n foreach(i;0..m){\n readf!\"%d %d %d\"(l,r,v);\n readln;\n q~=tuple(l,r,v);\n } \n long[] dk=new long[m];\n foreach(i;0..k){\n readf!\"%d %d\"(l,r);\n readln;\n dk[l-1]++;\n if(r<m) dk[r]--;\n }\n foreach(i;1..m)\n dk[i]+=dk[i-1];\n long[] d=new long[n];\n foreach(i;0..m){\n v=(cast(ulong)dk[i])*q[i][2];//:q[i][2];\n d[q[i][0]-1]+=v;\n if(q[i][1]<n) d[q[i][1]]-=v;\n } \n a[0]+=d[0];\n foreach(i;1..n){\n d[i]+=d[i-1];\n a[i]+=d[i];\n }\n writefln!\"%(%d %)\"(a);\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\tauto a = new long [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t}\n\t\tauto l = new int [m];\n\t\tauto r = new int [m];\n\t\tauto d = new long [m];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\treadf (\" %s %s %s\", &l[j], &r[j], &d[j]);\n\t\t\tl[j]--;\n\t\t\tr[j]--;\n\t\t}\n\t\tauto x = new int [k];\n\t\tauto y = new int [k];\n\t\tforeach (p; 0..k)\n\t\t{\n\t\t\treadf (\" %s %s\", &x[p], &y[p]);\n\t\t\tx[p]--;\n\t\t\ty[p]--;\n\t\t}\n\t\tauto v = new long [m + 1];\n\t\tforeach (p; 0..k)\n\t\t{\n\t\t\tv[x[p]]++;\n\t\t\tv[y[p] + 1]--;\n\t\t}\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tv[j + 1] += v[j];\n\t\t}\n\t\tauto t = new long [n + 1];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tt[l[j]] += v[j] * d[j];\n\t\t\tt[r[j] + 1] -= v[j] * d[j];\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tt[i + 1] += t[i];\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] += t[i];\n\t\t}\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main() {\n int n, m, k;\n readVars(n, m, k);\n\n auto a = readln.split.to!(long[]);\n\n auto l = new int[](m);\n auto r = new int[](m);\n auto d = new int[](m);\n\n foreach (i ; 0 .. m) {\n readVars(l[i], r[i], d[i]);\n l[i]--;\n }\n\n auto ims = new int[](m + 1);\n int xi, yi;\n\n foreach (i ; 0 .. k) {\n readVars(xi, yi);\n ims[xi - 1]++;\n ims[yi]--;\n }\n\n iota(m).each!(i => ims[i + 1] += ims[i]);\n\n auto dif = new long[](n + 1);\n\n foreach (i ; 0 .. m) {\n dif[l[i]] += d[i].to!long * ims[i];\n dif[r[i]] -= d[i].to!long * ims[i];\n }\n\n iota(n).each!(i => dif[i + 1] += dif[i]);\n\n debug {\n stderr.writeln(\"ims:\", ims);\n stderr.writeln(\"dif:\", dif);\n }\n\n a[] += dif[0 .. $ - 1];\n\n writefln(\"%(%s %)\", a);\n}\n\nint dfs(int n, int[][] child, int u) {\n if (child[u].empty) {\n return 0;\n }\n\n int res;\n\n foreach(v ; child[u]) {\n res = max(res, dfs(n, child, v));\n }\n\n return res + 1;\n}\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!long).array;\n \n struct op { int le, r, d; }\n op[] ops;\n foreach (_; 0 .. m) {\n int le, r, d;\n readf(\"%s %s %s\", &le, &r, &d);\n readln;\n --le, --r;\n \n ops ~= op(le, r, d);\n }\n \n debug { ops.writeln; }\n \n auto opscnt = new int[] (m+1);\n foreach (_; 0 .. k) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n --x, --y;\n \n opscnt[x] += 1;\n opscnt[y+1] -= 1;\n }\n \n auto addcnt = new long[] (n+1);\n foreach (i; 0 .. m) {\n if (i > 0) opscnt[i] += opscnt[i-1];\n auto val = cast(long)ops[i].d * opscnt[i];\n addcnt[ops[i].le] += val;\n addcnt[ops[i].r+1] -= val; \n }\n \n foreach (i; 0 .. n) {\n if (i > 0) addcnt[i] += addcnt[i-1];\n arr[i] += addcnt[i];\n }\n \n arr.writefln!(\"%(%s %)\");\n}"}], "negative_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,m,k;\n readf!\"%d %d %d\"(n,m,k);\n readln;\n ulong[] a=readln.splitter.map!(to!ulong).array;\n Tuple!(int,int,long)[] q;\n int l,r;\n long v;\n foreach(i;0..m){\n readf!\"%d %d %d\"(l,r,v);\n readln;\n q~=tuple(l,r,v);\n } \n long[] dk=new long[m];\n while(k--){\n readf!\"%d %d\"(l,r);\n readln;\n dk[l-1]++;\n if(r<m) dk[r]--;\n }\n foreach(i;1..m)\n dk[i]+=dk[i-1];\n long[] d=new long[n];\n foreach(i;0..m){\n ulong val=dk[i]?dk[i]*q[i][2]:q[i][2];\n d[q[i][0]-1]+=val;\n if(q[i][1]<n) d[q[i][1]]-=val;\n } \n a[0]+=d[0];\n foreach(i;1..n){\n d[i]+=d[i-1];\n a[i]+=d[i];\n }\n writefln!\"%(%d %)\"(a);\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,m,k;\n readf!\"%d %d %d\"(n,m,k);\n readln;\n ulong[] a=readln.splitter.map!(to!ulong).array;\n Tuple!(int,int,ulong)[] q;\n int l,r;\n ulong v;\n foreach(i;0..m){\n readf!\"%d %d %d\"(l,r,v);\n readln;\n q~=tuple(l,r,v);\n } \n long[] dk=new long[m];\n while(k--){\n readf!\"%d %d\"(l,r);\n readln;\n dk[l-1]++;\n if(r<m) dk[r]--;\n }\n foreach(i;1..m)\n dk[i]+=dk[i-1];\n long[] d=new long[n];\n foreach(i;0..m){\n v=dk[i]?(cast(ulong)dk[i])*q[i][2]:q[i][2];\n d[q[i][0]-1]+=v;\n if(q[i][1]<n) d[q[i][1]]-=v;\n } \n a[0]+=d[0];\n foreach(i;1..n){\n d[i]+=d[i-1];\n a[i]+=d[i];\n }\n writefln!\"%(%d %)\"(a);\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,m,k;\n readf!\"%d %d %d\"(n,m,k);\n readln;\n ulong[] a=readln.splitter.map!(to!ulong).array;\n Tuple!(int,int,int)[] q;\n int l,r,v;\n foreach(i;0..m){\n readf!\"%d %d %d\"(l,r,v);\n readln;\n q~=tuple(l,r,v);\n } \n long[] dk=new long[m];\n while(k--){\n readf!\"%d %d\"(l,r);\n readln;\n dk[l-1]++;\n if(r<m) dk[r]--;\n }\n foreach(i;1..m)\n dk[i]+=dk[i-1];\n long[] d=new long[n];\n foreach(i;0..m){\n long val=dk[i]?dk[i]*q[i][2]:q[i][2];\n d[q[i][0]-1]+=val;\n if(q[i][1]<n) d[q[i][1]]-=val;\n } \n a[0]+=d[0];\n foreach(i;1..n){\n d[i]+=d[i-1];\n a[i]+=d[i];\n }\n writefln!\"%(%d %)\"(a);\n}\n\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main() {\n int n, m, k;\n readVars(n, m, k);\n\n auto a = readln.split.to!(long[]);\n\n auto l = new int[](m);\n auto r = new int[](m);\n auto d = new int[](m);\n\n foreach (i ; 0 .. m) {\n readVars(l[i], r[i], d[i]);\n l[i]--;\n }\n\n auto ims = new int[](m + 1);\n int xi, yi;\n\n foreach (i ; 0 .. k) {\n readVars(xi, yi);\n ims[xi - 1]++;\n ims[yi]--;\n }\n\n iota(m).each!(i => ims[i + 1] += ims[i]);\n\n auto dif = new long[](n + 1);\n\n foreach (i ; 0 .. m) {\n dif[l[i]] += d[i] * ims[i];\n dif[r[i]] -= d[i] * ims[i];\n }\n\n iota(n).each!(i => dif[i + 1] += dif[i]);\n\n debug {\n stderr.writeln(\"ims:\", ims);\n stderr.writeln(\"dif:\", dif);\n }\n\n a[] += dif[0 .. $ - 1];\n\n writefln(\"%(%s %)\", a);\n}\n\nint dfs(int n, int[][] child, int u) {\n if (child[u].empty) {\n return 0;\n }\n\n int res;\n\n foreach(v ; child[u]) {\n res = max(res, dfs(n, child, v));\n }\n\n return res + 1;\n}\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!long).array;\n \n struct op { int le, r, d; }\n op[] ops;\n foreach (_; 0 .. m) {\n int le, r, d;\n readf(\"%s %s %s\", &le, &r, &d);\n readln;\n --le, --r;\n \n ops ~= op(le, r, d);\n }\n \n debug { ops.writeln; }\n \n auto opscnt = new int[] (m+1);\n foreach (_; 0 .. k) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n --x, --y;\n \n opscnt[x] += 1;\n opscnt[y+1] -= 1;\n }\n \n auto addcnt = new long[] (n+1);\n foreach (i; 0 .. m) {\n if (i > 0) opscnt[i] += opscnt[i-1];\n addcnt[ops[i].le] += ops[i].d * opscnt[i];\n addcnt[ops[i].r+1] -= ops[i].d * opscnt[i]; \n }\n \n foreach (i; 0 .. n) {\n if (i > 0) addcnt[i] += addcnt[i-1];\n arr[i] += addcnt[i];\n }\n \n arr.writefln!(\"%(%s %)\");\n}"}, {"source_code": "module sigod.codeforces.p296C;\n\nimport std.stdio;\n\nstruct FenwickTree\n{\n\tprivate {\n\t\tint _size;\n\t\tlong[] _array;\n\t}\n\n\tthis(int size)\n\t{\n\t\tthis._size = size;\n\t\tthis._array = new long[size];\n\t}\n\n\tthis(long[] array)\n\t{\n\t\t//this._size = array.length;\n\t\t//this._array = array.dup;\n\n\t\tthis(array.length);\n\n\t\tfor (int i = 0; i < this._size; ++i) {\n\t\t\tthis.inc(i, array[i]);\n\t\t}\n\t}\n\n\tvoid inc(int i, long delta)\n\t{\n\t\tfor (; i < this._size; i = (i | (i + 1))) {\n\t\t\tthis._array[i] += delta;\n\t\t}\n\t}\n\n\tlong sum(int r)\n\t{\n\t\tlong result = 0;\n\n\t\tfor (; r >= 0; r = (r & (r + 1)) - 1) {\n\t\t\tresult += this._array[r];\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tlong sum(int l, int r)\n\t{\n\t\treturn sum(r) - sum(l);\n\t}\n\n\tlong[] toArray()\n\t{\n\t\tlong[] result = new long[this._size];\n\n\t\tforeach (i; 0 .. this._size) {\n\t\t\tresult[i] = this.sum(i);\n\t\t}\n\n\t\tfor (int i = this._size - 1; i > 0; --i) {\n\t\t\tresult[i] -= result[i - 1];\n\t\t}\n\n\t\treturn result;\n\t}\n}\n\nvoid main()\n{\n\tint array_size = read_value!int();\n\tint operations_count = read_value!int();\n\tint requests_count = read_value!int();\n\n\tlong[] array = read_array!long(array_size);\n\n\tint[] left_operations = new int[operations_count];\n\tint[] right_operations = new int[operations_count];\n\tint[] delta = new int[operations_count];\n\n\tforeach (i; 0 .. operations_count) {\n\t\tleft_operations[i] = read_value!int() - 1;\n\t\tright_operations[i] = read_value!int() - 1;\n\t\tdelta[i] = read_value!int();\n\t}\n\n\tint[] x = new int[requests_count];\n\tint[] y = new int[requests_count];\n\n\tforeach (i; 0 .. requests_count) {\n\t\tx[i] = read_value!int() - 1;\n\t\ty[i] = read_value!int() - 1;\n\t}\n\n\tFenwickTree array_tree = FenwickTree(array);\n\tFenwickTree operations_tree = FenwickTree(operations_count);\n\n\tforeach (i; 0 .. requests_count) {\n\t\tforeach (j; x[i] .. y[i] + 1) {\n\t\t\toperations_tree.inc(j, 1);\n\t\t}\n\t}\n\n\tstdout.writeln(\"operations_counts: \", operations_tree.toArray());\n\n\tstdout.writeln(\"array: \", array_tree.toArray());\n\n\tforeach (index, count; operations_tree.toArray()) {\n\t\tif (count == 0) continue;\n\n\t\tforeach (i; left_operations[index] .. right_operations[index] + 1) {\n\t\t\tarray_tree.inc(i, delta[index] * count);\n\t\t}\n\n\t\tstdout.writeln(\"left: \", left_operations[index], \"; right: \", right_operations[index]);\n\t\tstdout.writeln(\"delta: \", delta[index], \"; count: \", count);\n\t\tstdout.writeln(\"array: \", array_tree.toArray());\n\t}\n\n\tforeach (element; array_tree.toArray()) {\n\t\tstdout.write(element, \" \");\n\t}\n}\n\nprivate\nT read_value(T)()\n{\n\tT value;\n\tstdin.readf(\" %s\", &value);\n\n\treturn value;\n}\n\nprivate\nT[] read_array(T)(int size)\n{\n\tT[] array = new T[size];\n\n\tforeach (ref element; array) {\n\t\tstdin.readf(\" %s\", &element);\n\t}\n\n\treturn array;\n}"}, {"source_code": "module sigod.codeforces.p296C;\n\nimport std.stdio;\n\nvoid main()\n{\n\tint n, m, k;\n\tstdin.readf(\" %s %s %s\", &n, &m, &k);\n\n\tlong[] a = new long[n + 2];\n\tforeach (i; 1 .. n + 1) {\n\t\tstdin.readf(\" %s\", &a[i]);\n\t}\n\n\tint[] l = new int[m + 1];\n\tint[] r = new int[m + 1];\n\tint[] d = new int[m + 2];\n\n\tforeach (i; 1 .. m + 1) {\n\t\tstdin.readf(\" %s %s %s\", &l[i], &r[i], &d[i]);\n\t}\n\n\t// process requests\n\n\tint[] multipl = new int[m + 2];\n\n\tforeach (i; 0 .. k) {\n\t\tint x, y;\n\t\tstdin.readf(\" %s %s\", &x, &y);\n\n\t\t++multipl[x];\n\t\t--multipl[y + 1];\n\t}\n\n\tforeach (i; 1 .. m + 2) {\n\t\tmultipl[i] += multipl[i - 1];\n\n\t\td[i] *= multipl[i];\n\t}\n\n\t// process operations\n\n\tlong[] sum = new long[n + 2];\n\n\tforeach (i; 1 .. m + 1) {\n\t\tsum[l[i]] += d[i];\n\t\tsum[r[i] + 1] -= d[i];\n\t}\n\n\tforeach (i; 1 .. n + 1) {\n\t\tsum[i] += sum[i - 1];\n\n\t\ta[i] += sum[i];\n\t}\n\n\t// output\n\n\tforeach (i; 1 .. n + 1) {\n\t\tstdout.write(a[i], \" \");\n\t}\n}\n\nprivate\nT max(T)(T a, T b)\n{\n\tif (a > b) return a;\n\telse return b;\n}"}], "src_uid": "c3120f96894c17957bd8acb968bf37cd"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m; rd(n, m);\n long sum=0;\n while(m--){\n long x, d; rd(x, d);\n sum+=x*n;\n if(d>0){// 0+d+d*2+...+d*(n-1)\n sum+=d*n*(n-1)/2;\n }else{\n auto k=n/2;\n sum+=d*k*(k+1)/2*2;\n if(n%2==0) sum-=d*k;\n }\n }\n\n writefln(\"%.18f\", 1.0*sum/n);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n\n/*\n\n 0 0\n -1 2\n -1 2\n -2 -3\n\n 0 0 0\n 0 2 4\n 5 7 9\n\n*/", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto totx = 0, posd = 0, negd = 0;\n while (m--) {\n int x, d;\n readf(\"%s %s\", &x, &d);\n readln;\n \n totx += x;\n if (d > 0) posd += d;\n else negd += d;\n }\n \n debug { writeln(totx, ' ', negd, ' ', posd); }\n \n auto bigd = (cast(long)n).iota.sum;\n auto smalld = n % 2 == 1 ? 2L * (cast(long)n/2 + 1).iota.sum \n : (cast(long)n/2 + 1).iota.sum + (cast(long)n/2).iota.sum;\n \n debug { writeln(smalld, ' ', bigd); }\n \n auto ans = totx + cast(double)(posd * bigd + negd * smalld) / n;\n \n ans.writefln!(\"%.18f\");\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto totx = 0, posd = 0, negd = 0;\n while (m--) {\n int x, d;\n readf(\"%s %s\", &x, &d);\n readln;\n \n totx += x;\n if (d > 0) posd += d;\n else negd += d;\n }\n \n debug { writeln(totx, ' ', negd, ' ', posd); }\n \n auto bigd = (cast(long)n).iota.sum;\n auto smalld = n % 2 == 1 ? 2L * (cast(long)n/2 + 1).iota.sum : (cast(long)n/2 + 1).iota.sum + (cast(long)n/2).iota.sum;\n \n debug { writeln(smalld, ' ', bigd); }\n \n auto ans = totx + cast(double)(posd * bigd + negd * smalld) / n;\n \n ans.writefln!(\"%.18f\");\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto totx = 0, posd = 0, negd = 0;\n while (m--) {\n int x, d;\n readf(\"%s %s\", &x, &d);\n readln;\n \n totx += x;\n if (d > 0) posd += d;\n else negd += d;\n }\n \n debug { writeln(totx, ' ', negd, ' ', posd); }\n \n auto bigd = (cast(long)n).iota.sum;\n auto smalld = n % 2 == 1 ? 2L * (cast(long)n/2 + 1).iota.sum : (cast(long)n/2 + 1).iota.sum + (cast(long)n/2).iota.sum;\n \n debug { writeln(smalld, ' ', bigd); }\n \n auto ans = totx + cast(double)(posd * bigd + negd * smalld) / n;\n \n ans.writeln;\n}"}], "src_uid": "1c8423407ea7a0b2647e41392670d6b7"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum A = 10;\nenum DIGITS = [\"1110111\", \"0010010\", \"1011101\", \"1011011\", \"0111010\", \"1101011\", \"1101111\", \"1010010\", \"1111111\", \"1111011\"];\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n auto S = new string[N];\n foreach (i; 0 .. N) {\n S[i] = readToken();\n }\n \n auto dks = new int[][](N, A);\n foreach (i; 0 .. N) {\n foreach (a; 0 .. A) {\n foreach (pos; 0 .. 7) {\n if (S[i][pos] > DIGITS[a][pos]) {\n dks[i][a] += K + 1;\n } else if (S[i][pos] < DIGITS[a][pos]) {\n dks[i][a] += 1;\n }\n }\n }\n }\n auto dp = new bool[][](N + 1, K + 1);\n dp[N][0] = true;\n foreach_reverse (i; 0 .. N) {\n foreach (a; 0 .. A) {\n const dk = dks[i][a];\n foreach (k; dk .. K + 1) {\n if (dp[i + 1][k - dk]) {\n dp[i][k] = true;\n }\n }\n }\n }\n \n if (dp[0][K]) {\n string ans;\n int k = K;\n foreach (i; 0 .. N) {\n foreach_reverse (a; 0 .. A) {\n if (k >= dks[i][a] && dp[i + 1][k - dks[i][a]]) {\n ans ~= cast(char)('0' + a);\n k -= dks[i][a];\n goto found;\n }\n }\n assert(false);\n found:\n }\n writeln(ans);\n } else {\n writeln(-1);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n int[] arr;\n foreach (_; 0 .. n) {\n string s = readln.chomp;\n arr ~= to!int(s, 2);\n }\n \n int[] nums;\n nums ~= to!int(\"1110111\", 2);\n nums ~= to!int(\"0010010\", 2);\n nums ~= to!int(\"1011101\", 2);\n nums ~= to!int(\"1011011\", 2);\n nums ~= to!int(\"0111010\", 2);\n nums ~= to!int(\"1101011\", 2);\n nums ~= to!int(\"1101111\", 2);\n nums ~= to!int(\"1010010\", 2);\n nums ~= to!int(\"1111111\", 2);\n nums ~= to!int(\"1111011\", 2);\n \n auto best = new Tuple!(int, int)[][] (1 << 7);\n foreach (x; 0 .. (1 << 7)) {\n outer: foreach (val, target; nums.enumerate(0)) {\n int need = 0;\n foreach (bit; 0 .. 8) {\n int xb = x & (1 << bit);\n int tb = target & (1 << bit);\n if (tb < xb) { continue outer; }\n if (tb > xb) { ++need; }\n }\n best[x] ~= tuple(val, need);\n }\n }\n \n auto dp = new int[][] (n+1, k+1);\n foreach (i; 0 .. n+1) { dp[i][] = -2; }\n \n int go(int pos, int left) {\n if (pos == n) { return left == 0 ? 0 : -1; }\n if (dp[pos][left] > -2) { return dp[pos][left]; }\n \n foreach (i, pr; best[arr[pos]]) {\n auto target = pr[0], need = pr[1];\n if (need > left) { continue; }\n \n auto rest = go(pos+1, left - need);\n if (rest >= 0) { dp[pos][left] = i.to!int; }\n }\n \n if (dp[pos][left] == -2) { dp[pos][left] = -1; }\n \n return dp[pos][left];\n }\n \n auto score = go(0, k);\n \n if (score < 0) {\n writeln(-1);\n return;\n }\n \n int[] ans;\n int left = k;\n foreach (i; 0 .. n) {\n auto pr = best[arr[i]][dp[i][left]];\n ans ~= pr[0];\n left -= pr[1];\n }\n \n ans.map!(to!string).join.writeln;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.stdio;\n\nimmutable int digits = 10;\nint [digits] digit;\n\nvoid prepare ()\n{\n\tdigit[0] = 0b1110111;\n\tdigit[1] = 0b0010010;\n\tdigit[2] = 0b1011101;\n\tdigit[3] = 0b1011011;\n\tdigit[4] = 0b0111010;\n\tdigit[5] = 0b1101011;\n\tdigit[6] = 0b1101111;\n\tdigit[7] = 0b1010010;\n\tdigit[8] = 0b1111111;\n\tdigit[9] = 0b1111011;\n}\n\nvoid main ()\n{\n\tprepare ();\n\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\treadf !(\" %b\") (c);\n\t\t}\n\t\tauto f = new byte [] [] (n + 1, k + 10);\n\t\tforeach (ref g; f)\n\t\t{\n\t\t\tg[] = -1;\n\t\t}\n\t\tf[n][0] = digits;\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tforeach (d, v; digit)\n\t\t\t{\n\t\t\t\tif ((a[i] | v) != v)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tauto add = popcnt (a[i] ^ v);\n\t\t\t\tforeach (j; add..k + 1)\n\t\t\t\t{\n\t\t\t\t\tif (f[i + 1][j - add] >= 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[i][j] = cast (byte)\n\t\t\t\t\t\t ((add << 4) | d);\n\t\t\t\t\t}\n\t\t\t\t}\n\t \t}\n\t\t}\n\n\t\tif (f[0][k] >= 0)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\twrite (f[i][k] & 15);\n\t\t\t\tk -= f[i][k] >> 4;\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.format;\nimport std.exception;\nimport std.bitmanip;\n\nimmutable int[][] digits = [\n [1,2,3,5,6,7],\n [3,6],\n [1,3,4,5,7],\n [1,3,4,6,7],\n [2,3,4,6],\n [1,2,4,6,7],\n [1,2,4,5,6,7],\n [1,3,6],\n [1,2,3,4,5,6,7],\n [1,2,3,4,6,7]\n];\n\nint cvt (in int[] a) {\n return a.map!(i => 1 << (i - 1)).sum;\n}\n\nimmutable int[] mask = digits.map!(cvt).array.idup;\n\nfinal class Solve {\n immutable int n, maxk;\n immutable int[] c;\n BitArray dp;\n int[] pc;\n bool f (int i, int t) {\n int idx = (i * (maxk + 1) + t) * 2;\n if (dp[idx]) return dp[idx+1];\n dp[idx] = true;\n if (i == n) {\n if (t == 0) {\n dp[idx+1] = true;\n return true;\n }\n return false;\n }\n const int ci = c[i];\n foreach_reverse (j; mask) {\n const int w = ci & j;\n if (w != ci) continue;\n const int bits = pc[j ^ ci];\n if (bits > t) continue;\n if (f (i + 1, t - bits)) {\n dp[idx+1] = true;\n return true;\n }\n }\n return false;\n }\n void restore () {\n int i, t = maxk;\n while (i < n) {\n const int ci = c[i];\n foreach_reverse (pos, j; mask) {\n const int w = ci & j;\n if (w != ci) continue;\n const int bits = pc[j ^ ci];\n if (bits > t) continue;\n if (f (i + 1, t - bits)) {\n write(pos);\n t -= bits;\n break;\n }\n }\n ++i;\n }\n }\n this (int n, int maxk, int[] c) {\n this.n = n;\n this.maxk = maxk;\n this.c = c.idup;\n dp.length = 2 * (n + 1) * (maxk + 1);\n pc = new int[128];\n foreach (i; 1 .. 128) {\n pc[i] = pc[i & (i - 1)] + 1;\n }\n }\n}\n\nvoid main() {\n auto s = readln;\n int n, k;\n formattedRead(s, \" %d %d\", n, k);\n auto c = new int[n];\n foreach (i; 0 .. n) {\n auto t = readln;\n foreach (j; 0 .. 7) if (t[j] == '1') {\n c[i] += 1 << j;\n }\n }\n auto solve = new Solve (n, k, c);\n if (solve.f (0, k)) {\n solve.restore ();\n writeln;\n } else {\n writeln (-1);\n }\n\n}\n\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum A = 10;\nenum DIGITS = [\"1110111\", \"0010010\", \"1011101\", \"1011011\", \"0111010\", \"1101011\", \"1101111\", \"1010010\", \"1111111\", \"1111011\"];\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n auto S = new string[N];\n foreach (i; 0 .. N) {\n S[i] = readToken();\n }\n \n auto dks = new int[][](N, A);\n foreach (i; 0 .. N) {\n foreach (a; 0 .. A) {\n foreach (pos; 0 .. 7) {\n if (DIGITS[a][pos] != S[i][pos]) {\n ++dks[i][a];\n }\n }\n }\n }\n auto dp = new bool[][](N + 1, K + 1);\n dp[N][0] = true;\n foreach_reverse (i; 0 .. N) {\n foreach (a; 0 .. A) {\n const dk = dks[i][a];\n foreach (k; dk .. K + 1) {\n if (dp[i + 1][k - dk]) {\n dp[i][k] = true;\n }\n }\n }\n }\n \n if (dp[0][K]) {\n string ans;\n int k = K;\n foreach (i; 0 .. N) {\n foreach_reverse (a; 0 .. A) {\n if (k >= dks[i][a] && dp[i + 1][k - dks[i][a]]) {\n ans ~= cast(char)('0' + a);\n k -= dks[i][a];\n goto found;\n }\n }\n assert(false);\n found:\n }\n writeln(ans);\n } else {\n writeln(-1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "d7f73762ff7a01c33280257e556a9b36"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n a ~= long.max;\n long ops = 0;\n foreach_reverse(i; 0 .. cast(size_t)n)\n {\n if (a[i] > a[i + 1])\n {\n ops += a[i] - a[i + 1];\n }\n }\n writeln(ops);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n long ans;\n foreach (i; 0 .. N - 1) {\n ans += max(A[i] - A[i + 1], 0);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = a[i] - a[i+1];\n\t\t\tif (x > 0)\n\t\t\t{\n\t\t\t\tans[ti] += x;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong res = 0;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tres += max (0, a[i - 1] - a[i]);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = a[i] - a[i+1];\n\t\t\tif (x > 0)\n\t\t\t{\n\t\t\t\tans[ti] += x;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "0bd06900e42db9f83cdd43c24da6686e"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^9 + 7;\n\nvoid main() {\n int n, m;\n scan(n, m);\n auto c = readln.split.to!(int[]);\n\n auto uf = UnionFind(n);\n\n foreach (i ; 0 .. m) {\n int xi, yi;\n scan(xi, yi);\n xi--, yi--;\n uf.unite(xi, yi);\n }\n\n auto d = new int[](n);\n d[] = inf;\n\n foreach (i ; 0 .. n) {\n int r = uf.find_root(i);\n d[r] = min(d[r], c[i]);\n }\n\n long ans;\n\n foreach (i ; 0 .. n) {\n if (d[i] < inf) ans += d[i];\n }\n\n writeln(ans);\n}\n\n\nstruct UnionFind {\n private {\n int N;\n int[] p;\n int[] rank;\n }\n\n this (int n) {\n N = n;\n p = iota(N).array;\n rank = new int[](N);\n }\n\n int find_root(int x) {\n if (p[x] != x) {\n p[x] = find_root(p[x]);\n }\n\n return p[x];\n }\n\n bool same(int x, int y) {\n return find_root(x) == find_root(y);\n }\n\n void unite(int x, int y) {\n int u = find_root(x), v = find_root(y);\n\n if (u == v) return;\n\n if (rank[u] < rank[v]) {\n p[u] = v;\n }\n else {\n p[v] = u;\n\n if (rank[u] == rank[v]) {\n rank[u]++;\n }\n }\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\n\nstruct Queue(T) {\n private {\n int N, head, tail;\n T[] data;\n }\n\n this(int n) {\n N = n + 1;\n data = new T[](N);\n }\n\n bool empty() {\n return head == tail;\n }\n\n bool full() {\n return (tail + 1) % N == head;\n }\n\n T front() {\n return data[head];\n }\n\n void push(T x) {\n assert(!full);\n data[tail++] = x;\n tail %= N;\n }\n\n void pop() {\n assert(!empty);\n head = (head + 1) % N;\n }\n\n void clear() {\n head = tail = 0;\n }\n}", "positive_code": [{"source_code": "// https://codeforces.com/problemset/problem/893/C\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\nimport std.range.primitives;\n\nint[][] graph;\nint[] visited;\nlong[] c;\n\nlong dfs(int u) {\n visited[u] = 1;\n long minima = c[u];\n for(int i = 0; i < graph[u].length; i++) {\n int v = graph[u][i];\n if(visited[v] == 0) {\n minima = min(minima,dfs(v));\n }\n }\n return minima;\n}\n\nvoid main() {\n int n, m;\n readf(\"%s %s\\n\", &n, &m);\n c = readln.split.map!(to!long).array;\n // TODO how to initialize this?\n visited = new int[n];\n foreach(_; 0..n) {\n int[] vertex;\n graph ~= vertex;\n }\n foreach(_; 0..m) {\n int x,y;\n readf(\"%s %s\\n\", &x, &y);\n x -= 1;\n y -= 1;\n graph[x] ~= y;\n graph[y] ~= x;\n }\n long[] cost;\n foreach(vertex; 0..n) {\n if(visited[vertex] == 0) {\n cost ~= dfs(vertex);\n }\n }\n long total;\n foreach(item; cost)\n total += item;\n total.writeln;\n}\n\n"}, {"source_code": "#!/usr/bin/env dub\n/+ dub.sdl:\n name \"C\"\n+/\n\nimport std.array;\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int N, M;\n readf(\" %s %s \", N, M);\n \n long[] C = new long[N];\n foreach (i; 0..N) {\n readf(\" %s \", C[i]);\n } \n\n int[][] adj = new int[][N];\n foreach (i; 0..M) {\n int x, y;\n readf(\" %s %s \", x, y);\n x--;\n y--;\n\n adj[x] ~= y;\n adj[y] ~= x;\n }\n\n debug(2) { writeln(adj);}\n\n int[] comps = replicate([-1], N);\n int ncomps = 0;\n\n foreach (v; 0..N) {\n if (comps[v] == -1) {\n auto bfs = DList!int(v);\n comps[v] = ncomps;\n\n while (!bfs.empty) {\n auto cur = bfs.front();\n bfs.removeFront();\n\n foreach (nbr; adj[cur]) {\n if (comps[nbr] == -1) {\n bfs.insertBack(nbr);\n comps[nbr] = ncomps;\n }\n }\n }\n\n ncomps++;\n }\n }\n\n long[] mins = replicate([long.max], ncomps);\n\n foreach (v; 0..N) {\n mins[comps[v]] = min(mins[comps[v]], C[v]);\n }\n\n long ans = sum(mins);\n writeln(ans);\n}"}, {"source_code": "#!/usr/bin/env dub\n/+ dub.sdl:\n name \"C\"\n+/\n\nimport std.array;\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nclass Graph {\n int N;\n int[][] adj;\n\n private int[] comps;\n private int ncomps;\n\n bool flag_connected_components = false;\n\n this(int N) {\n this.N = N;\n adj = new int[][N];\n }\n\n void addEdge(int u, int v) {\n adj[u] ~= v;\n adj[v] ~= u;\n }\n\n void do_connected_components() {\n comps = replicate([-1], N);\n\n foreach (v; 0..N) {\n if (comps[v] == -1) {\n auto bfs = DList!int(v);\n comps[v] = ncomps;\n\n while (!bfs.empty) {\n auto cur = bfs.front();\n bfs.removeFront();\n\n foreach (nbr; adj[cur]) {\n if (comps[nbr] == -1) {\n bfs.insertBack(nbr);\n comps[nbr] = ncomps;\n }\n }\n }\n\n ncomps++;\n }\n }\n\n debug {\n flag_connected_components = true;\n }\n }\n\n int component(int v) {\n debug {\n assert(flag_connected_components);\n }\n return comps[v];\n }\n\n}\n\nvoid main()\n{\n int N, M;\n readf(\" %s %s \", N, M);\n \n long[] C = new long[N];\n foreach (i; 0..N) {\n readf(\" %s \", C[i]);\n } \n\n Graph G = new Graph(N);\n foreach (i; 0..M) {\n int x, y;\n readf(\" %s %s \", x, y);\n x--;\n y--;\n\n G.addEdge(x, y);\n }\n G.do_connected_components();\n\n long[] mins = replicate([long.max], G.ncomps);\n\n foreach (v; 0..N) {\n mins[G.component(v)] = \n min(mins[G.component(v)], C[v]);\n }\n\n long ans = sum(mins);\n writeln(ans);\n}"}], "negative_code": [{"source_code": "// https://codeforces.com/problemset/problem/893/C\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\nimport std.range.primitives;\n\nint[][] graph;\nint[] visited;\nint[] c;\n\nint dfs(int u) {\n visited[u] = 1;\n int minima = c[u];\n for(int i = 0; i < graph[u].length; i++) {\n int v = graph[u][i];\n minima = min(minima, c[v]);\n if(visited[v] == 0) {\n dfs(v);\n }\n }\n return minima;\n}\n\nvoid main() {\n int n, m;\n readf(\"%s %s\\n\", &n, &m);\n c = readln.split.map!(to!int).array;\n // TODO how to initialize this?\n visited = new int[n];\n foreach(_; 0..n) {\n int[] vertex;\n graph ~= vertex;\n }\n foreach(_; 0..m) {\n int x,y;\n readf(\"%s %s\\n\", &x, &y);\n x -= 1;\n y -= 1;\n graph[x] ~= y;\n graph[y] ~= x;\n }\n int[] cost;\n foreach(vertex; 0..n) {\n if(visited[vertex] == 0) {\n cost ~= dfs(vertex);\n }\n }\n sum(cost).writeln;\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/893/C\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\nimport std.range.primitives;\n\nint[][] graph;\nint[] visited;\nlong[] c;\n\nlong dfs(int u) {\n visited[u] = 1;\n long minima = c[u];\n for(int i = 0; i < graph[u].length; i++) {\n int v = graph[u][i];\n minima = min(minima, c[v]);\n if(visited[v] == 0) {\n dfs(v);\n }\n }\n return minima;\n}\n\nvoid main() {\n int n, m;\n readf(\"%s %s\\n\", &n, &m);\n c = readln.split.map!(to!long).array;\n // TODO how to initialize this?\n visited = new int[n];\n foreach(_; 0..n) {\n int[] vertex;\n graph ~= vertex;\n }\n foreach(_; 0..m) {\n int x,y;\n readf(\"%s %s\\n\", &x, &y);\n x -= 1;\n y -= 1;\n graph[x] ~= y;\n graph[y] ~= x;\n }\n long[] cost;\n foreach(vertex; 0..n) {\n if(visited[vertex] == 0) {\n cost ~= dfs(vertex);\n }\n }\n long total;\n foreach(item; cost)\n total += item;\n total.writeln;\n}\n\n"}], "src_uid": "9329cb499f003aa71c6f51556bcc7b05"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll W = scan; ll H = scan;\n ll x1 = scan; ll y1 = scan;\n ll x2 = scan; ll y2 = scan;\n ll w = scan; ll h = scan;\n // Height\n ll wdis = max(W - x2, x1);\n ll hdis = max(H - y2, y1);\n ll wdiff = max(w - wdis, 0);\n ll hdiff = max(h - hdis, 0);\n /* show(wdis, hdis); */\n /* show(wdiff, hdiff); */\n ll nx, ny;\n bool f = 1;\n if(W - x2 > x1){\n nx = x1 - wdiff;\n if(nx < 0){\n f = 0;\n }\n }else{\n nx = x1 + wdiff;\n if(x2 + wdiff > W){\n f = 0;\n }\n }\n bool f2 = 1;\n if(H - y2 > y1){\n ny = y1 - hdiff;\n if(ny < 0){\n if(!f){\n writeln(-1);\n return;\n }else{\n f2 = 0;\n }\n }\n }else{\n ny = y1 + hdiff;\n if(y2 + hdiff > H){\n if(!f){\n writeln(-1);\n return;\n }else{\n f2 = 0;\n }\n }\n }\n show(nx, ny);\n ll dist = -1;\n if(f && f2){\n dist = min(abs(nx - x1), abs(ny - y1));\n }else if(f2){\n dist = abs(ny - y1);\n }else if(f){\n dist = abs(nx - x1);\n }\n if(dist == -1){\n writeln(dist);\n return;\n }\n double dis = dist.to!double;\n writefln(\"%.10f\", dis);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int W, H;\n readf!\" %d %d \"(W, H);\n int x1, y1, x2, y2;\n readf!\" %d %d %d %d \"(x1, y1, x2, y2);\n\n int X1 = max(x1, W - x2);\n int Y1 = max(y1, H - y2);\n\n int w, h;\n readf!\" %d %d \"(w, h);\n\n int movex, movey;\n if (w > X1) {\n movex = w - X1;\n if (w + abs(x2 - x1) > W)\n movex = int.max;\n }\n if (h > Y1) {\n movey = h - Y1;\n if (h + abs(y2 - y1) > H)\n movey = int.max;\n }\n\n int ans = min(movex, movey);\n if (ans == int.max) {\n writeln(-1);\n } else {\n writefln(\"%.9f\", cast(double)ans);\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int; while (t--) solve;\n}\n\nvoid solve()\n{\n\tlong w = readInt!long;\n\tlong h = readInt!long;\n\tlong[2] xb, yb;\n\tlong x1 = readInt!long;\n\tlong y1 = readInt!long;\n\tlong x2 = readInt!long;\n\tlong y2 = readInt!long;\n\txb = [x1, x2];\n\tyb = [y1, y2];\n\tlong rw = readInt!long;\n\tlong rh = readInt!long; \n\tlong wb = x2 - x1;\n\tlong hb = y2 - y1;\n\tlong minDist = long.max;\n\tvoid tryPoint(long x, long y)\n\t{\n\t\tif (rw <= x || rh <= y) { minDist = 0; return; }\n\t\tif (rw > x) \n\t\t{\n\t\t\tlong hx = rw;\n\t\t\tif (hx + wb <= w) \n\t\t\t{\n\t\t\t\tminDist = min(minDist, rw - x);\n\t\t\t}\n\t\t}\n\t\tif (rh > y)\n\t\t{\n\t\t\tlong hy = rh;\n\t\t\tif (hy + hb <= h)\n\t\t\t{\n\t\t\t\tminDist = min(minDist, rh - y);\n\t\t\t}\n\t\t}\n\t}\n\ttryPoint(xb[0], yb[0]);\n\ttryPoint(xb[0], h - yb[1]);\n\ttryPoint(w - xb[1], yb[0]);\n\ttryPoint(w - xb[1], h - yb[1]);\n\tif (minDist != long.max) minDist.writeln; else (-1).writeln;\n}\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll W = scan; ll H = scan;\n ll x1 = scan; ll y1 = scan;\n ll x2 = scan; ll y2 = scan;\n ll w = scan; ll h = scan;\n // Height\n ll wdis = max(W - x2, x1);\n ll hdis = max(H - y2, y1);\n ll wdiff = max(w - wdis, 0);\n ll hdiff = max(h - hdis, 0);\n /* show(wdis, hdis); */\n /* show(wdiff, hdiff); */\n ll nx, ny;\n bool f = 1;\n if(W - x2 > x1){\n nx = x1 - wdiff;\n if(x1 < 0){\n f = 0;\n }\n }else{\n nx = x1 + wdiff;\n if(x2 + wdiff > W){\n f = 0;\n }\n }\n bool f2 = 1;\n if(H - y2 > y1){\n ny = y1 - hdiff;\n if(y1 < 0){\n if(!f){\n writeln(-1);\n return;\n }else{\n f2 = 0;\n }\n }\n }else{\n ny = y1 + hdiff;\n if(y2 + hdiff > H){\n if(!f){\n writeln(-1);\n return;\n }else{\n f2 = 0;\n }\n }\n }\n show(nx, ny);\n ll dist = -1;\n if(f && f2){\n dist = min(abs(nx - x1), abs(ny - y1));\n }else if(f2){\n dist = abs(ny - y1);\n }else if(f){\n dist = abs(nx - x1);\n }\n if(dist == -1){\n writeln(dist);\n return;\n }\n double dis = dist.to!double;\n writefln(\"%.10f\", dis);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll W = scan; ll H = scan;\n ll x1 = scan; ll y1 = scan;\n ll x2 = scan; ll y2 = scan;\n ll w = scan; ll h = scan;\n // Height\n ll wdis = max(W - x2, x1);\n ll hdis = max(H - y2, y1);\n ll wdiff = max(w - wdis, 0);\n ll hdiff = max(h - hdis, 0);\n /* show(wdis, hdis); */\n /* show(wdiff, hdiff); */\n ll nx, ny;\n bool f = 1;\n if(W - x2 > x1){\n nx = x1 - wdiff;\n if(x1 < 0){\n f = 0;\n }\n }else{\n nx = x1 + wdiff;\n if(x2 + wdiff > W){\n f = 0;\n }\n }\n bool f2 = 1;\n if(H - y2 > y1){\n ny = y1 - hdiff;\n if(y1 < 0){\n if(!f){\n writeln(-1);\n return;\n }else{\n f2 = 0;\n }\n }\n }else{\n ny = y1 + hdiff;\n if(y2 + hdiff > H){\n if(!f){\n writeln(-1);\n return;\n }else{\n f2 = 0;\n }\n }\n }\n show(nx, ny);\n ll dist = -1;\n if(f && f2){\n dist = min(abs(nx - x1), abs(ny - y1));\n }else if(f2){\n dist = abs(ny - y1);\n }else if(f){\n dist = abs(nx - x1);\n }\n double dis = dist.to!double;\n writefln(\"%.10f\", dis);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll W = scan; ll H = scan;\n ll x1 = scan; ll y1 = scan;\n ll x2 = scan; ll y2 = scan;\n ll w = scan; ll h = scan;\n // Height\n ll wdis = max(W - x2, x1);\n ll hdis = max(H - y2, y1);\n ll wdiff = max(w - wdis, 0);\n ll hdiff = max(h - hdis, 0);\n show(wdis, hdis);\n show(wdiff, hdiff);\n ll nx, ny;\n bool f = 1;\n if(W - x2 > x1){\n nx = x1 - wdiff;\n if(x1 < 0){\n f = 0;\n }\n }else{\n nx = x1 + wdiff;\n if(x2 + wdiff > W){\n f = 0;\n }\n }\n bool f2 = 1;\n if(H - y2 > y1){\n ny = y1 - hdiff;\n if(y1 < 0){\n if(!f){\n writeln(-1);\n return;\n }else{\n f2 = 0;\n }\n }\n }else{\n ny = y1 + hdiff;\n if(y2 + hdiff > H && !f){\n if(!f){\n writeln(-1);\n return;\n }else{\n f2 = 0;\n }\n }\n }\n ll dist = -1;\n if(f && f2){\n dist = min(abs(nx - x1), abs(ny - y1));\n }else if(f2){\n dist = abs(ny - y1);\n }else if(f){\n dist = abs(nx - x1);\n }\n double dis = dist.to!double;\n writefln(\"%.8f\", dis);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "src_uid": "29fd4c77a2f28478ebce98dfc6496aac"} {"source_code": "import std.stdio;\nimport std.range;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto nt = next!int;\n foreach(t; 0 .. nt)\n {\n auto n = next!int;\n auto x = next!int;\n auto y = next!int;\n auto diff = y - x;\n int bestjump = -1;\n int bestjumpmax = int.max;\n foreach(jump; 1 .. diff + 1)\n {\n if (diff % jump == 0)\n {\n if (diff / jump + 1 > n)\n continue;\n int rem = n - (diff / jump + 1);\n int lessthan = cast(int) iota(1, x).count!(num => num % jump == x % jump);\n rem -= min(rem, lessthan);\n int jumpmax = y + rem * jump;\n if (jumpmax < bestjumpmax)\n {\n bestjump = jump;\n bestjumpmax = jumpmax;\n }\n }\n }\n foreach(i; 0 .. n)\n {\n write(bestjumpmax - bestjump * i, \" \");\n }\n writeln;\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.conv;\nimport std.range;\n\nalias ll = long;\n\nvoid play(){\n ll n, x, y;\n readf(\" %s %s %s \", &n, &x, &y);\n ll diff = y - x;\n ll minmax = long.max / 10;\n ll mind = -1, mina = -1;\n foreach(ll d; 1 .. diff+1){\n if(diff % d == 0){\n ll minn = y - (n - 1) * d;\n while(minn <= 0){\n minn += d;\n }\n if(minn > x) continue;\n ll curmax = minn + (n - 1) * d;\n if(curmax < minmax){\n minmax = curmax;\n mind = d;\n mina = minn;\n }\n }\n }\n foreach(ll i; 0 .. n){\n writef(\"%s \", mina + i * mind);\n }\n writeln;\n}\n\nint main(){\n ll t = 1;\n readf(\" %s \", &t); // Toggle!\n while(t--) play(); // Let's play!\n return 0;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto x = RD;\n\t\tauto y = RD;\n\t\t\n\t\tauto d = y-x;\n\t\tforeach_reverse (i; 1..n)\n\t\t{\n\t\t\tif (d % i) continue;\n\t\t\tauto cnt = d / i;\n\t\t\tauto begin = x;\n\t\t\twhile (begin <= y)\n\t\t\t{\n\t\t\t\tans[ti] ~= begin;\n\t\t\t\tbegin += cnt;\n\t\t\t}\n\t\t\t\n\t\t\tbegin = x - cnt;\n\t\t\twhile (begin >= 1 && ans[ti].length < n)\n\t\t\t{\n\t\t\t\tans[ti] ~= begin;\n\t\t\t\tbegin -= cnt;\n\t\t\t}\n\t\t\tbegin = y + cnt;\n\t\t\twhile (ans[ti].length < n)\n\t\t\t{\n\t\t\t\tans[ti] ~= begin;\n\t\t\t\tbegin += cnt;\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "ca9d97e731e86cf8223520f39ef5d945"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto c = RD;\n\t\tauto m = RD;\n\t\tauto x = RD;\n\t\tauto a = c + m + x;\n\t\tans[i] = min(min(c, m), a/3);\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint q = rint;\n\tforeach(_; 0 .. q){\n\t\tlong c = rlong, m = rlong, x = rlong;\n\t\tlong total = c + m + x;\n\t\tlong ans = min(c, m, total / 3);\n\t\tans.writeln;\n\t}\n}\n"}], "negative_code": [], "src_uid": "b18dac401b655c06bee331e71eb3e4de"} {"source_code": "// cheese-cracker [2022-07-08]\n\nvoid solve(){\n int n = scan!int;\n auto seen = new bool[](n+1);\n int d = 2;\n writeln(d);\n for(int i = 1; i <= n; ++i){\n if(!seen[i]){\n int num = i;\n while(num <= n){\n seen[num] = 1;\n write(num, \" \");\n num *= 2;\n }\n }\n }\n writeln;\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm;\nimport std.container, std.math, std.numeric, std.functional;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n", "positive_code": [{"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n foreach(_; 0..t)\r\n {\r\n int n;\r\n scanf(\"%d\", &n);\r\n int[] arr = [1];\r\n bool[int] set;\r\n set[1] = true;\r\n for (int i = 2; i <= n; i++) {\r\n for (int j = 0; i * 2 ^^ j <= n; j++)\r\n if ((i * 2 ^^ j in set) == null) {\r\n arr ~= i * 2 ^^ j;\r\n set[i * 2 ^^ j] = true;\r\n }\r\n }\r\n writeln(2);\r\n writefln(\"%(%s %)\", arr);\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "3b9380ca571dbf3e24fc1b1c8b91790b"} {"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.array;\n\nvoid main(){\n\tauto nk=readln.strip.split.map!(to!int).array;\n\tint n=nk[0],k=nk[1];\n\tauto a=readln.strip.split.map!(to!int).array;\n\tsort(a);\n\tint cur=k,r=0;\n\tforeach(x;a){\n\t\twhile(cur<(x+1)/2){\n\t\t\tr++;\n\t\t\tcur*=2;\n\t\t}\n\t\tcur=max(cur,x);\n\t}\n\twriteln(r);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1].to!long * 2;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n\n long ans = 0;\n foreach (i; 0..N) {\n while (K < A[i]) K *= 2, ans += 1;\n K = max(K, A[i] * 2);\n }\n\n ans.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1].to!long * 2;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n auto X = A[$-1];\n\n foreach (i; 0..N) {\n if (A[i] <= K) K = max(K, A[i] * 2);\n }\n\n long ans = 0;\n while (K <= X) K *= 4, ans += 1;\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1].to!long * 2;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n auto X = A[$-1];\n\n foreach (i; 0..N) {\n if (A[i] <= K) K = max(K, A[i] * 2);\n }\n\n long ans = 0;\n while (K < X) K *= 2, ans += 1;\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1].to!long * 2;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n auto X = A[$-1];\n\n foreach (i; 0..N) {\n if (A[i] <= K) K = max(K, A[i] * 2);\n }\n\n long ans = 0;\n while (K < X) K *= 4, ans += 1;\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1].to!long * 2;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n auto X = A[$-1];\n\n foreach (i; 0..N) {\n if (A[i] <= K) K = max(K, A[i] * 2);\n }\n\n long ans = 0;\n while (K <= X) K *= 2, ans += 1;\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.array;\n\nvoid main(){\n\tauto nk=readln.strip.split.map!(to!int).array;\n\tint n=nk[0],k=nk[1];\n\tauto a=readln.strip.split.map!(to!int).array;\n\tsort(a);\n\tint cur=k,r=0;\n\tforeach(x;a){\n\t\twhile(cur<(x+1)/2){\n\t\t\tr++;\n\t\t\tcur=cur*2+1;\n\t\t}\n\t\tcur=max(cur,x);\n\t}\n\twriteln(r);\n}\n"}], "src_uid": "adc5a98cef418d9bbf40e5772c02ef43"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\t\tint n = cast(int)s.length;\n\t\tauto a = new int[](s.length);\n\t\tauto cnt = new int[](10);\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\ta[i] = s[i] - '0';\n\t\t\t++cnt[a[i]];\n\t\t}\n\t\tint best;\n\t\tforeach (i; 0..10)\n\t\t\tbest.chmax(cnt[i]);\n\t\tans[ti] = n - best;\n\t\t\n\t\tforeach (i; 0..10)\n\t\t{\n\t\t\tforeach (j; i+1..10)\n\t\t\t{\n\t\t\t\tint last = -1;\n\t\t\t\tint c;\n\t\t\t\tforeach (e; a)\n\t\t\t\t{\n\t\t\t\t\tif (last != e && (e == i || e == j))\n\t\t\t\t\t{\n\t\t\t\t\t\t++c;\n\t\t\t\t\t\tlast = e;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (c % 2)\n\t\t\t\t\t--c;\n\t\t\t\tans[ti].chmin(n - c);\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable char [] digits = \"0123456789\";\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\t\tint res = 0;\n\t\tforeach (char c; digits)\n\t\t{\n\t\t\tres = max (res, s.count (c).to !(int));\n\t\t}\n\t\tforeach (char c; digits)\n\t\t{\n\t\t\tforeach (char d; digits)\n\t\t\t{\n\t\t\t\tint pos = 0;\n\t\t\t\tint cur = 0;\n\t\t\t\twhile (true)\n\t\t\t\t{\n\t\t\t\t\twhile (pos < s.length && s[pos] != c)\n\t\t\t\t\t{\n\t\t\t\t\t\tpos += 1;\n\t\t\t\t\t}\n\t\t\t\t\tpos += 1;\n\t\t\t\t\twhile (pos < s.length && s[pos] != d)\n\t\t\t\t\t{\n\t\t\t\t\t\tpos += 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (pos >= s.length)\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tcur += 2;\n\t\t\t\t}\n\t\t\t\tres = max (res, cur);\n\t\t\t}\n\t\t}\n\t\twriteln (s.length - res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "977db81b5c1d3725e384e8f093655172"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n\n while (t--) {\n auto lens = readln.chomp.split.map!(to!int).array;\n \n int[][] arr;\n foreach (i; 0 .. 3) {\n arr ~= readln.chomp.split.map!(to!int).array;\n arr[i].sort();\n }\n \n ulong ans = ulong.max;\n foreach (ps; iota(3).permutations) {\n int smallidx = 0, bigidx = 0;\n foreach (e; arr[ps[0]]) {\n while (smallidx + 1 < lens[ps[1]] && arr[ps[1]][smallidx + 1] <= e) { ++smallidx; }\n while (bigidx < lens[ps[2]] && arr[ps[2]][bigidx] < e) { ++bigidx; }\n\n if (bigidx == lens[ps[2]]) { continue; }\n \n auto sm = arr[ps[1]][smallidx];\n auto bg = arr[ps[2]][bigidx];\n auto cur = (e.to!ulong - sm)^^2 + (sm.to!ulong - bg)^^2 + (bg.to!ulong - e)^^2;\n \n ans = min(ans, cur);\n }\n }\n \n ans.writeln;\n }\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n auto N = new int[3];\n foreach (h; 0 .. 3) {\n N[h] = readInt();\n }\n auto A = new long[][3];\n foreach (h; 0 .. 3) {\n A[h] = new long[N[h]];\n foreach (i; 0 .. N[h]) {\n A[h][i] = readLong();\n }\n A[h].sort;\n }\n \n long ans = long.max;\n \n void check(long x, long y, long z) {\n debug {\n writeln(\"check \", x, \" \", y, \" \", z);\n }\n const score = (y - z)^^2 + (z - x)^^2 + (x - y)^^2;\n chmin(ans, score);\n }\n void checkH(int h, long y, long z) {\n const pos = A[h].upperBound((y + z) / 2);\n if (pos < N[h]) {\n check(A[h][pos], y, z);\n }\n if (pos - 1 >= 0) {\n check(A[h][pos - 1], y, z);\n }\n }\n \n foreach (h; 0 .. 3) {\n const h1 = (h + 1) % 3;\n const h2 = (h + 2) % 3;\n for (int i1 = 0, i2 = 0; i1 < N[h1] && i2 < N[h2]; ) {\n debug {\n writeln(h1, \" \", h2, \"; \", i1, \" \", i2);\n }\n checkH(h, A[h1][i1], A[h2][i2]);\n if (A[h1][i1] < A[h2][i2]) {\n ++i1;\n } else {\n ++i2;\n }\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n int[] ra (int n) {\n auto a = r.nextA!int (n);\n sort (a);\n return a;\n }\n foreach (tid; 0 .. nt) {\n long res = long.max;\n auto a = r.nextA!uint (3);\n auto t = new int[][3];\n foreach (k; 0 .. 3) t[k] = ra (a[k]);\n void check (long u, long v, long w) {\n long q = (u - v) * (u - v);\n q += (u - w) * (u - w);\n q += (v - w) * (v - w);\n if (res > q) res = q;\n }\n void f (in int[] x, in int[] y, in int[] z) {\n size_t j, k;\n foreach (i; 0 .. x.length) {\n int xv = x[i];\n while (j < y.length && y[j] < xv) ++j; \n while (k < z.length && z[k] < xv) ++k; \n void go (size_t u, size_t v) {\n if (u < y.length && v < z.length)\n check (xv, y[u], z[v]);\n }\n go (j, k);\n if (k > 0) {\n go (j, k - 1);\n }\n if (j > 0) {\n go (j - 1, k);\n if (k > 0) {\n go (j - 1, k - 1);\n }\n }\n }\n }\n f (t[0], t[1], t[2]);\n f (t[1], t[0], t[2]);\n f (t[2], t[0], t[1]);\n writeln (res);\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto nr = RD!int;\n\t\tauto ng = RD!int;\n\t\tauto nb = RD!int;\n\t\tauto r = RDA;\n\t\tauto g = RDA;\n\t\tauto b = RDA;\n\t\tr.sort();\n\t\tg.sort();\n\t\tb.sort();\n\t\tauto arr = new long[][](nr+ng+nb);\n\t\tforeach (i; 0..nr)\n\t\t{\n\t\t\tarr[i] = [r[i], 0];\n\t\t}\n\t\tforeach (i; 0..ng)\n\t\t{\n\t\t\tarr[nr+i] = [g[i], 1];\n\t\t}\n\t\tforeach (i; 0..nb)\n\t\t{\n\t\t\tarr[nr+ng+i] = [b[i], 2];\n\t\t}\n\t\tarr.sort!\"a[0] < b[0]\"();\n\n\t\tans[ti] = long.max;\n\t\tlong lr, lg, lb;\n\t\tlong search(in long[] _arr, long d)\n\t\t{\n\t\t\tauto p = binarySearch!((int a) => _arr[a] >= d)(cast(int)_arr.length-1, -1);\n\t\t\tlong res = _arr[p];\n\t\t\tif (p != 0)\n\t\t\t{\n\t\t\t\tif (abs(d - _arr[p-1]) < abs(res - d))\n\t\t\t\t\tres = _arr[p-1];\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tlong eval(long rr, long gg, long bb)\n\t\t{\n\t\t\treturn (rr-gg)^^2 + (gg-bb)^^2 + (bb-rr)^^2;\n\t\t}\n\t\tforeach (i; 0..arr.length)\n\t\t{\n\t\t\tif (arr[i][1] == 0)\n\t\t\t{\n\t\t\t\tlr = arr[i][0];\n\t\t\t\tif (lg != 0 && lb != 0)\n\t\t\t\t{\n\t\t\t\t\tlong x;\n\t\t\t\t\tif (lg <= lb)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto d = (lr+lg+1) / 2;\n\t\t\t\t\t\tx = search(b, d);\n\t\t\t\t\t\tans[ti].chmin(eval(lr, lg, x));\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tauto d = (lr+lb+1) / 2;\n\t\t\t\t\t\tx = search(g, d);\n\t\t\t\t\t\tans[ti].chmin(eval(lr, x, lb));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (arr[i][1] == 1)\n\t\t\t{\n\t\t\t\tlg = arr[i][0];\n\t\t\t\tif (lr != 0 && lb != 0)\n\t\t\t\t{\n\t\t\t\t\tlong x;\n\t\t\t\t\tif (lr <= lb)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto d = (lr+lg+1) / 2;\n\t\t\t\t\t\tx = search(b, d);\n\t\t\t\t\t\tans[ti].chmin(eval(lr, lg, x));\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tauto d = (lg+lb+1) / 2;\n\t\t\t\t\t\tx = search(r, d);\n\t\t\t\t\t\tans[ti].chmin(eval(x, lg, lb));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlb = arr[i][0];\n\t\t\t\tif (lr != 0 && lg != 0)\n\t\t\t\t{\n\t\t\t\t\tlong x;\n\t\t\t\t\tif (lr <= lg)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto d = (lr+lb+1) / 2;\n\t\t\t\t\t\tx = search(g, d);\n\t\t\t\t\t\tans[ti].chmin(eval(lr, x, lb));\n\t\t\t\t\t\tdebug writeln(arr[i], \" d:\", d, \" x:\", x);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tauto d = (lg+lb+1) / 2;\n\t\t\t\t\t\tx = search(r, d);\n\t\t\t\t\t\tans[ti].chmin(eval(x, lg, lb));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int total = 3;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint [total] n;\n\t\tforeach (ref c; n)\n\t\t{\n\t\t\treadf !(\" %s\") (c);\n\t\t}\n\t\treadln;\n\t\tint [] [total] a;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tc = readln.splitter.map !(to !(int)).array;\n\t\t\tsort (c);\n\t\t}\n\t\tlong res = long.max;\n\t\tforeach (i; 0..total)\n\t\t{\n\t\t\tforeach (j; 0..total)\n\t\t\t{\n\t\t\t\tif (j != i)\n\t\t\t\t{\n\t\t\t\t\tauto k = total - i - j;\n\t\t\t\t\tint v = 0;\n\t\t\t\t\tint w = 0;\n\t\t\t\t\tforeach (u; 0..n[i])\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (v < n[j] &&\n\t\t\t\t\t\t a[j][v] <= a[i][u])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tv += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (v > 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tv -= 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (w + 1 < n[k] &&\n\t\t\t\t\t\t a[k][w] < a[j][v])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tw += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tres = min (res,\n\t\t\t\t\t\t (cast (long)\n\t\t\t\t\t\t (a[i][u] - a[j][v])) ^^ 2 +\n\t\t\t\t\t\t (cast (long)\n\t\t\t\t\t\t (a[j][v] - a[k][w])) ^^ 2 +\n\t\t\t\t\t\t (cast (long)\n\t\t\t\t\t\t (a[k][w] - a[i][u])) ^^ 2);\n\t \t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int total = 3;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint [total] n;\n\t\tforeach (ref c; n)\n\t\t{\n\t\t\treadf !(\" %s\") (c);\n\t\t}\n\t\treadln;\n\t\tint [] [total] a;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tc = readln.splitter.map !(to !(int)).array;\n\t\t\tsort (c);\n\t\t}\n\t\tlong res = long.max;\n\t\tforeach (i; 0..total)\n\t\t{\n\t\t\tforeach (j; 0..total) if (j != i)\n\t\t\t{\n\t\t\t\tauto k = total - i - j;\n\t\t\t\tint v = 0;\n\t\t\t\tint w = 0;\n\t\t\t\tforeach (u; 0..n[i])\n\t\t\t\t{\n\t\t\t\t\twhile (v + 1 < n[j] &&\n\t\t\t\t\t a[j][v] < a[i][u])\n\t\t\t\t\t{\n\t\t\t\t\t\tv += 1;\n\t\t\t\t\t}\n\t\t\t\t\twhile (w + 1 < n[k] &&\n\t\t\t\t\t a[k][w] < a[j][v])\n\t\t\t\t\t{\n\t\t\t\t\t\tw += 1;\n\t\t\t\t\t}\n\t\t\t\t\tres = min (res,\n\t\t\t\t\t (cast (long)\n\t\t\t\t\t (a[i][u] - a[j][v])) ^^ 2 +\n\t\t\t\t\t (cast (long)\n\t\t\t\t\t (a[j][v] - a[k][w])) ^^ 2 +\n\t\t\t\t\t (cast (long)\n\t\t\t\t\t (a[k][w] - a[i][u])) ^^ 2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "79b58eb781cd73ccf7994866b9a8b695"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n;\n n = scan!int;\n ll[] miner;\n ll[] diam;\n ll x, y;\n for(int i = 0; i < 2*n; ++i) {\n x = scan; y = scan;\n if(x == 0){\n miner ~= abs(y);\n }else{\n diam ~= abs(x);\n }\n }\n miner.sort;\n diam.sort;\n double res = 0;\n for(int i = 0; i < n; ++i){\n double curres = miner[i]*miner[i] + diam[i]*diam[i];\n curres = sqrt(curres);\n res += curres;\n }\n writefln(\"%.12f\", res);\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new double[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\r\n\t\tlong[] a, b;\r\n\t\tforeach (i; 0..n*2)\r\n\t\t{\r\n\t\t\tauto x = RD;\r\n\t\t\tauto y = RD;\r\n\t\t\tif (x == 0)\r\n\t\t\t\ta ~= y.abs;\r\n\t\t\telse\r\n\t\t\t\tb ~= x.abs;\r\n\t\t}\r\n\t\ta.sort();\r\n\t\tb.sort();\r\n\r\n\t\tans[ti] = 0.0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tans[ti] += sqrt(cast(double)a[i]^^2 + b[i]^^2);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twritefln(\"%.15f\", e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new double[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\r\n\t\tint[] a, b;\r\n\t\tforeach (i; 0..n*2)\r\n\t\t{\r\n\t\t\tauto x = RD!int;\r\n\t\t\tauto y = RD!int;\r\n\t\t\tif (x == 0)\r\n\t\t\t\ta ~= y.abs;\r\n\t\t\telse\r\n\t\t\t\tb ~= x.abs;\r\n\t\t}\r\n\t\ta.sort();\r\n\t\tb.sort();\r\n\r\n\t\tans[ti] = 0.0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tans[ti] += sqrt(cast(double)a[i]^^2 + b[i]^^2);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twritefln(\"%.15f\", e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new double[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\r\n\t\tint[] a, b;\r\n\t\tforeach (i; 0..n*2)\r\n\t\t{\r\n\t\t\tauto x = RD!int;\r\n\t\t\tauto y = RD!int;\r\n\t\t\tif (x == 0)\r\n\t\t\t\ta ~= y.abs;\r\n\t\t\telse\r\n\t\t\t\tb ~= x.abs;\r\n\t\t}\r\n\t\ta.sort();\r\n\t\tb.sort();\r\n\r\n\t\tans[ti] = 0.0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tans[ti] += sqrt(cast(double)a[i]^^2 + b[i]^^2);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twritefln(FMT_F, e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "ba27ac62b84705d80fa580567ab64c3b"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto m = a.maxElement;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == m && ((i > 0 && a[i - 1] < a[i]) ||\n\t\t\t (i + 1 < n && a[i + 1] < a[i])))\n\t\t\t{\n\t\t\t\twriteln (i + 1);\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\t\twriteln (-1);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tlong x;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tx.chmax(a[i]);\n\t\t}\n\n\t\tans[ti] = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] != x) continue;\n\t\t\tif (i != 0)\n\t\t\t{\n\t\t\t\tif (a[i] > a[i-1])\n\t\t\t\t{\n\t\t\t\t\tans[ti] = i+1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i != n-1)\n\t\t\t{\n\t\t\t\tif (a[i] > a[i+1])\n\t\t\t\t{\n\t\t\t\t\tans[ti] = i+1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n ll maxx = arr.maxElement;\n ll maxi = -1;\n foreach(i; 0..n){\n if(arr[i] == maxx){\n if(i > 0 && arr[i-1] < maxx){\n maxi = i + 1;\n break;\n }else if(i < n - 1 && arr[i+1] < maxx){\n maxi = i + 1;\n break;\n }\n }\n }\n writeln(maxi);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ a.each!(w => write(w, \"| \")); writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n"}], "negative_code": [], "src_uid": "5598d5954fa3e3cecedb413033259760"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MAX_N = 1_000_006;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tauto b = new bool [MAX_N];\n\t\tforeach (x; readln.split.map !(to !(int)))\n\t\t{\n\t\t\tb[x] = true;\n\t\t}\n\n\t\tauto f = new int [MAX_N];\n\t\tforeach (i; 0..MAX_N)\n\t\t{\n\t\t\tf[i] = b[i];\n\t\t}\n\n\t\tint res = 0;\n\t\tfor (int x = 1; x < MAX_N; x++)\n\t\t{\n\t\t\tif (!b[x])\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int y = x * 2; y < MAX_N; y += x)\n\t\t\t{\n\t\t\t\tif (!b[y])\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tf[y] = max (f[y], f[x] + 1);\n\t\t\t}\n\t\t\tres = max (res, f[x]);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.stdio, std.range;\nimmutable int MAX_N = 1_000_006;\nvoid main ()\n{\n int n;\n while (readf (\" %s \", &n) > 0)\n {\n auto f = new int [MAX_N];\n foreach (x; readln.split.map !(to !(int)))\n f[x] = 1;\n for (int x = 1; x < MAX_N; x++) if (f[x])\n for (int y = x * 2; y < MAX_N; y += x) if (f[y])\n f[y] = max (f[y], f[x] + 1);\n f.minPos !(q{a > b}).front.writeln;\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.stdio, std.range;\nimmutable int MAX_N = 1_000_006;\nvoid main ()\n{\n\tint n;\n\treadf (\" %s \", &n);\n\tauto f = new int [MAX_N];\n\tforeach (x; readln.split.map!(to!int))\n\t\tfor (int y = x * 2; y < MAX_N; y += x)\n\t\t\tf[y] = max (f[y], f[x] + 1);\n\tf.minPos!q{a > b}.front.writeln;\n}\n"}], "src_uid": "f33991da3b4a57dd6535af86edeeddc0"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto P = 3.iota.map!(_ => Point(scan!long, scan!long)).array;\r\n\r\n auto maxY = P.map!\"a.y\".maxElement;\r\n auto mys = P.filter!(a => a.y == maxY).array;\r\n\r\n if (mys.length == 2) {\r\n return (mys[0].x - mys[1].x).abs;\r\n }\r\n\r\n return 0;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new double[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto x = new long[](3);\r\n\t\tauto y = new long[](3);\r\n\t\tforeach (i; 0..3)\r\n\t\t{\r\n\t\t\tx[i] = RD;\r\n\t\t\ty[i] = RD;\r\n\t\t}\r\n\r\n\t\tauto index = y.MAKE_IDX;\r\n\t\tif (y[index[1]] == y[index[2]])\r\n\t\t\tans[ti] = abs(x[index[1]] - x[index[2]]);\r\n\t\telse\r\n\t\t\tans[ti] = 0.0;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twritefln(FMT_F, e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.string;\r\nimport std.math;\r\n\r\nauto line_to_array(ref File input)\r\n{\r\n import std.algorithm.sorting;\r\n import std.conv;\r\n import std.string;\r\n return input.readln.chomp.split;\r\n}\r\n\r\nauto line_to_int(ref File input)\r\n{\r\n import std.string;\r\n import std.conv;\r\n return input.readln.chomp.to!int;\r\n}\r\n\r\nvoid solution(ref File input, ref File output)\r\n{\r\n auto fd = input.getFP;\r\n\r\n double answer = 0;\r\n long[3] x, y;\r\n\r\n for (int i = 0; i < 3; i++) input.readf!\"%d %d\\n\"(x[i], y[i]);\r\n\r\n for (int i = 0; i < 3; i++)\r\n for (int j = 0; j < 3; j++)\r\n for (int c = 0; c < 3; c++)\r\n if (i != j && j != c && i != c && y[i] == y[j] && y[i] > y[c])\r\n {\r\n answer += sqrt(cast(double) (pow(y[i] - y[j], 2) + pow(x[i] - x[j], 2)));\r\n break;\r\n }\r\n output.writefln(\"%f\", answer / 2);\r\n}\r\n\r\nvoid loop(ref File input, ref File output)\r\n{\r\n auto t = input.readln.chomp.to!int;\r\n while (t-- > 0) solution(input, output);\r\n}\r\n\r\nint main()\r\n{\r\n File input, output;\r\n debug(1)\r\n {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else\r\n {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n loop(input, output);\r\n return 0;\r\n}"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.string;\r\nimport std.math;\r\n\r\nauto line_to_array(ref File input)\r\n{\r\n import std.algorithm.sorting;\r\n import std.conv;\r\n import std.string;\r\n return input.readln.chomp.split;\r\n}\r\n\r\nauto line_to_int(ref File input)\r\n{\r\n import std.string;\r\n import std.conv;\r\n return input.readln.chomp.to!int;\r\n}\r\n\r\nvoid solution(ref File input, ref File output)\r\n{\r\n auto fd = input.getFP;\r\n\r\n double answer = 0;\r\n long[3] x, y;\r\n\r\n for (int i = 0; i < 3; i++) input.readf!\"%d %d\\n\"(x[i], y[i]);\r\n\r\n for (int i = 0; i < 3; i++)\r\n for (int j = 0; j < 3; j++)\r\n for (int c = 0; c < 3; c++)\r\n if (i != j && j != c && i != c && y[i] == y[j] && y[i] > y[c])\r\n {\r\n answer += sqrt(cast(double) (pow(y[i] - y[j], 2) + pow(x[i] - x[j], 2)));\r\n break;\r\n }\r\n output.writeln(answer / 2);\r\n}\r\n\r\nvoid loop(ref File input, ref File output)\r\n{\r\n auto t = input.readln.chomp.to!int;\r\n while (t-- > 0) solution(input, output);\r\n}\r\n\r\nint main()\r\n{\r\n File input, output;\r\n debug(1)\r\n {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else\r\n {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n loop(input, output);\r\n return 0;\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.string;\r\nimport std.math;\r\n\r\nauto line_to_array(ref File input)\r\n{\r\n import std.algorithm.sorting;\r\n import std.conv;\r\n import std.string;\r\n return input.readln.chomp.split;\r\n}\r\n\r\nauto line_to_int(ref File input)\r\n{\r\n import std.string;\r\n import std.conv;\r\n return input.readln.chomp.to!int;\r\n}\r\n\r\nvoid solution(ref File input, ref File output)\r\n{\r\n auto fd = input.getFP;\r\n\r\n float answer = 0;\r\n int[3] x, y;\r\n\r\n core.stdc.stdio.fscanf(fd, \"%d %d\\n\", &x[0], &y[0]);\r\n core.stdc.stdio.fscanf(fd, \"%d %d\\n\", &x[1], &y[1]);\r\n core.stdc.stdio.fscanf(fd, \"%d %d\\n\", &x[2], &y[2]);\r\n\r\n for (int i = 0; i < 3; i++)\r\n for (int j = 0; j < 3; j++)\r\n for (int c = 0; c < 3; c++)\r\n if (i != j && j != c && i != c && y[i] == y[j] && y[i] > y[c])\r\n {\r\n //output.writefln(\"i: %d x: %d y: %d\", i, x[i], y[i]);\r\n //output.writefln(\"j: %d x: %d y: %d\", j, x[j], y[j]);\r\n //output.writefln(\"c: %d x: %d y: %d\", c, x[c], y[c]);\r\n answer += sqrt(cast(float) (pow(y[i] - y[j], 2) + pow(x[i] - x[j], 2)));\r\n //answer += cast(float) (pow(y[i] - y[j], 2) + pow(x[i] - x[j], 2));\r\n break;\r\n }\r\n output.writeln(answer / 2);\r\n}\r\n\r\nvoid loop(ref File input, ref File output)\r\n{\r\n auto t = input.readln.chomp.to!int;\r\n while (t-- > 0) solution(input, output);\r\n}\r\n\r\nint main()\r\n{\r\n File input, output;\r\n debug(1)\r\n {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else\r\n {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n loop(input, output);\r\n return 0;\r\n}"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto P = 3.iota.map!(_ => Point(scan!long, scan!long)).array;\r\n\r\n auto maxY = P.map!\"a.y\".maxElement;\r\n auto mys = P.filter!(a => a.y == maxY).array;\r\n\r\n if (mys.length == 2) {\r\n return ((mys[0].x - mys[1].x).to!real.pow(2) + (mys[0].y - mys[1].y).to!real.pow(2)).sqrt;\r\n }\r\n\r\n return 0.0;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "src_uid": "9f019c3898f27d687c5b3498586644e8"} {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\nvoid main() {\n int n;\n scan(n);\n auto s = readln.chomp;\n\n foreach (i ; 0 .. n - 1) {\n if (s[i] != s[i+1]) {\n writeln(\"YES\");\n writeln(s[i .. i+2]);\n return;\n }\n }\n\n writeln(\"NO\");\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:printf,scanf;\nimport std.stdio;\nimport std.string;\nimport std.container;\nimport std.array;\nimport std.range;\nimport std.algorithm;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.bitmanip;\nimport core.bitop;\nint sz(Range)(in Range r){return cast(int)r.length;}\nalias rbt=RedBlackTree!int;\n\n\nvoid main(){\n\tint n;\n\tscanf(\"%d\",&n);\n\treadln;\n\tstring s=readln.strip;\n\tbool found=false;\n\tint i=0;\n\tfor(;i<n-1;i++){\n\t\tif(s[i]!=s[i+1]){\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(s[i..i+2]);\n\t\t\tfound=true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(!found) writeln(\"NO\");\n}"}, {"source_code": "//ahmat\nimport core.stdc.stdio:printf,scanf;\nimport std.stdio;\nimport std.string;\nimport std.container;\nimport std.array;\nimport std.range;\nimport std.algorithm;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.bitmanip;\nimport core.bitop;\nint sz(Range)(in Range r){return cast(int)r.length;}\nalias rbt=RedBlackTree!int;\n\n\nvoid main(){\n\tint n;\n\tscanf(\"%d\",&n);\n\treadln;\n\tstring s=readln.strip;\n\tbool found=false;\n\tint i=0;\n\tif(s.length>1){\n\t\tfor(;i<n-1;i++){\n\t\t\tif(s[i]!=s[i+1]){\n\t\t\t\tfound=true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif(found){\n\t\twriteln(\"YES\");\n\t\twriteln(s[i..i+2]);\n\t}else writeln(\"NO\");\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto cnt = new int[](26);\n\n bool ok(int l, int r) {\n cnt[] = 0;\n foreach (i; l..r+1) cnt[S[i]-'a'] += 1;\n return cnt.reduce!max * 2 <= r - l + 1;\n }\n\n foreach (i; 0..N) {\n foreach (j; i..N) {\n if (ok(i, j)) {\n writeln(\"YES\");\n writeln(S[i..j+1]);\n return;\n }\n }\n }\n\n writeln(\"NO\");\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto cnt = new int[](26);\n\n bool ok(int l, int r) {\n cnt[] = 0;\n foreach (i; l..r+1) cnt[S[i]-1] += 1;\n return cnt.reduce!max * 2 <= r - l + 1;\n }\n\n foreach (i; 0..N) {\n foreach (j; i..N) {\n if (ok(i, j)) {\n writeln(\"YES\");\n writeln(S[i..j+1]);\n return;\n }\n }\n }\n\n writeln(\"NO\");\n}\n"}], "src_uid": "ce4443581d4ee12db6607695cd567070"} {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nvoid main()\n{\n int n;\n scanf(\"%d\", &n);\n\n int[5000] a;\n foreach (i; 0..n) {\n scanf(\"%d\", &a[i]);\n }\n\n int m = 0;\n foreach (i; 0..n) {\n int t = 0;\n foreach (j; i..n) {\n t += a[j];\n if (t > 100 * (j - i + 1)) {\n m = max(m, j - i + 1);\n }\n }\n }\n\n printf(\"%d\\n\", m);\n}\n\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n int mxlen = 0;\n foreach (le; 0 .. n) {\n int sm = 0, len = 0;\n foreach (r; le .. n) {\n sm += arr[r];\n len += 1;\n \n if (sm > 100 * len) { mxlen = max(mxlen, len); }\n }\n }\n \n mxlen.writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n int mxlen = 0;\n foreach (le; 0 .. n) {\n int sm = 0, len = 0;\n foreach (r; le .. n) {\n sm += arr[r];\n len += 1;\n \n if (sm >= 100 * len) { mxlen = max(mxlen, len); }\n }\n }\n \n if (mxlen == n) { mxlen -= 1; }\n \n mxlen.writeln;\n}"}], "src_uid": "ae531bc4b47e5d31fe71b6de1398b95e"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable long MO = 10^^9 + 7;\nimmutable LIM = 2 * 10^^5 + 5;\n\nlong[] inv, fac, facInv;\n\nvoid prepare() {\n\tinv = new long[LIM];\n\tinv[1] = 1;\n\tforeach (i; 2 .. LIM) {\n\t\tinv[i] = MO - MO / i * inv[cast(size_t)(MO % i)] % MO;\n\t}\n\tfac = new long[LIM];\n\tfacInv = new long[LIM];\n\tfac[0] = 1;\n\tfacInv[0] = 1;\n\tforeach (i; 1 .. LIM) {\n\t\tfac[i] = fac[i - 1] * i % MO;\n\t\tfacInv[i] = facInv[i - 1] * inv[i] % MO;\n\t}\n}\n\nlong binom(int n, int k) {\n\tif (!(0 <= k && k <= n)) {\n\t\treturn 0;\n\t}\n\treturn fac[n] * facInv[k] % MO * facInv[n - k] % MO;\n}\n\nint N, K;\nstring S;\n\nvoid main(string[] args) {\n\tprepare;\n\t\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = readInt;\n\t\tS = readToken;\n\t\t\ndebug{\nlong brt;\nforeach(h;0..1<<(N-1)){\n int cnt;\n foreach(i;0..N-1)if(h&1<<i)++cnt;\n if(cnt!=K)continue;\n long x;\n foreach(i;0..N){\n x=(x*10+S[i]-'0')%MO;\n // writeln(h,\" \",x);\n if((h&1<<i)||i==N-1){(brt+=x)%=MO;x=0;}\n }\n}\nwriteln(\"brt = \",brt);\n}\n\t\t\n\t\tlong ans;\n\t\tlong sum = 0;\n\t\tlong ten = 1;\n\t\tforeach_reverse (i; 0 .. N) {\ndebug{\n// writeln(\"sum = \",sum,\", binom(i, K) * ten = \",binom(i, K) * ten);\n}\n\t\t\t(ans += ((sum + binom(i, K) * ten) % MO) * (S[i] - '0')) %= MO;\n\t\t\t(sum += binom(i - 1, K - 1) * ten) %= MO;\n\t\t\t(ten *= 10) %= MO;\n\t\t}\n\t\tans = (ans % MO + MO) % MO;\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MOD = 1_000_000_007;\nimmutable int BASE = 10;\n\nint powmod (int a, int p, int m)\n{\n\tint res = 1;\n\twhile (p)\n\t{\n\t\tif (p & 1)\n\t\t{\n\t\t\tres = (cast (long) res * a) % m;\n\t\t}\n\t\ta = (cast (long) a * a) % m;\n\t\tp >>= 1;\n\t}\n\treturn res;\n}\n\nint inv (int a)\n{\n\treturn powmod (a, MOD - 2, MOD);\n}\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s \", &n, &k) > 0)\n\t{\n\t\tauto a = readln ().strip ().map !(q{a - '0'}) ().array ();\n\t\tdebug {writeln (a);}\n\n\t\tlong [] p = [1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tp ~= (p[$ - 1] * BASE) % MOD;\n\t\t}\n\t\tdebug {writeln (p);}\n\n\t\tlong [] c = [1];\n\t\tforeach (i; k..n - 1)\n\t\t{\n\t\t\tc ~= (((c[$ - 1] * i) % MOD) * inv (i - k + 1)) % MOD;\n\t\t}\n\t\treverse (c);\n\t\tdebug {writeln (c);}\n\n\t\tlong s = 0;\n\t\tforeach (i; 0..c.length)\n\t\t{\n\t\t\ts = (s + c[i] * p[i]) % MOD;\n\t\t}\n\t\tdebug {writeln (s);}\n\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tres = (res + s * a[i]) % MOD;\n\t\t\tint j = n - i - 1;\n\t\t\tif (0 < j && j < c.length)\n\t\t\t{\n\t\t\t\ts = (s - c[j] * p[j]) % MOD;\n\t\t\t\ts = (s + c[j] * p[j - 1]) % MOD;\n\t\t\t\tc[j - 1] = (c[j - 1] + c[j]) % MOD;\n\t\t\t\tj--;\n\t\t\t\ts = (s + MOD) % MOD;\n\t\t\t\tdebug {writeln (c, ' ', s);}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "0cc9e1f64f615806d07e657be7386f5b"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n// a^-1 (mod m)\nlong modInv(long a, long m)\nin {\n assert(m > 0, \"modInv: m > 0 must hold\");\n}\ndo {\n long b = m, x = 1, y = 0, t;\n for (; ; ) {\n t = a / b;\n a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1, \"modInv: gcd(a, m) != 1\");\n if (b == -1) {\n y = -y;\n }\n return (y < 0) ? (y + m) : y;\n }\n x -= t * y;\n t = b / a;\n b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1, \"modInv: gcd(a, m) != 1\");\n if (a == -1) {\n x = -x;\n }\n return (x < 0) ? (x + m) : x;\n }\n y -= t * x;\n }\n}\n\n\nenum long MO = 998244353;\n\nint N, M;\nint[] A;\nlong[] W;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n M = readInt();\n A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n W = new long[N];\n foreach (i; 0 .. N) {\n W[i] = readLong();\n }\n \n long R, S;\n foreach (i; 0 .. N) {\n if (A[i]) {\n R += W[i];\n }\n S += W[i];\n }\n \n auto invs = new long[2 * M + 1];\n foreach (x; -M .. +M + 1) {\n if (S + x > 0) {\n invs[M + x] = modInv(S + x, MO);\n }\n }\n \n auto dp = new long[][](M + 1, M + 1);\n dp[0][0] = 1;\n foreach (j; 0 .. M) {\n foreach (x; 0 .. j + 1) {\n if (S + x + (j - x) > 0) {\n const prob = ((R + x) * invs[M + x - (j - x)]) % MO;\n (dp[j + 1][x + 0] += dp[j][x] * (1 - prob)) %= MO;\n (dp[j + 1][x + 1] += dp[j][x] * prob) %= MO;\n }\n }\n }\n debug {\n writeln(\"dp = \", dp);\n }\n \n long eP, eN;\n foreach (x; 0 .. M + 1) {\n (eP += dp[M][x] * (R + x)) %= MO;\n (eN += dp[M][x] * (S - R - (M - x))) %= MO;\n }\n foreach (i; 0 .. N) {\n long ans;\n if (A[i]) {\n ans = (((eP * W[i]) % MO) * modInv(R, MO)) % MO;\n } else {\n ans = (((eN * W[i]) % MO) * modInv(S - R, MO)) % MO;\n }\n ans = (ans % MO + MO) % MO;\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n// a^-1 (mod m)\nlong modInv(long a, long m)\nin {\n assert(m > 0, \"modInv: m > 0 must hold\");\n}\ndo {\n long b = m, x = 1, y = 0, t;\n for (; ; ) {\n t = a / b;\n a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1, \"modInv: gcd(a, m) != 1\");\n if (b == -1) {\n y = -y;\n }\n return (y < 0) ? (y + m) : y;\n }\n x -= t * y;\n t = b / a;\n b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1, \"modInv: gcd(a, m) != 1\");\n if (a == -1) {\n x = -x;\n }\n return (x < 0) ? (x + m) : x;\n }\n y -= t * x;\n }\n}\n\n\nenum long MO = 998244353;\n\nint N, M;\nint[] A;\nlong[] W;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n M = readInt();\n A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n W = new long[N];\n foreach (i; 0 .. N) {\n W[i] = readLong();\n }\n \n long R, S;\n foreach (i; 0 .. N) {\n if (A[i]) {\n R += W[i];\n }\n S += W[i];\n }\n \n auto invs = new long[2 * M + 1];\n foreach (x; -M .. +M + 1) {\n if (S + x > 0) {\n invs[M + x] = modInv(S + x, MO);\n }\n }\n \n auto dp = new long[][](M + 1, M + 1);\n dp[0][0] = 1;\n foreach (j; 0 .. M) {\n foreach (x; 0 .. j + 1) {\n if (S + x + (j - x) > 0) {\n const prob = ((R + x) * invs[M + x - (j - x)]) % MO;\n (dp[j + 1][x + 0] += dp[j][x] * (1 - prob)) %= MO;\n (dp[j + 1][x + 1] += dp[j][x] * prob) %= MO;\n }\n }\n }\n debug {\n writeln(\"dp = \", dp);\n }\n \n long eP, eN;\n foreach (x; 0 .. M + 1) {\n (eP += dp[M][x] * (R + x)) %= MO;\n (eN += dp[M][x] * (S - R - (M - x))) %= MO;\n }\n foreach (i; 0 .. N) {\n long ans;\n if (A[i]) {\n ans = (((eP * W[i]) % MO) * modInv(R, MO)) % MO;\n } else {\n ans = (((eN * W[i]) % MO) * modInv(S - R, MO)) % MO;\n }\n ans = (ans % MO + MO) % MO;\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "ba9c136f84375cd317f0f8b53e3939c7"} {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm\n , std.range\n , std.container;\n\n\nvoid main() {\n uint n, k;\n readf(\"%s %s\\n\", &n, &k);\n \n auto fence = new uint[n];\n auto sum_arr = new uint[n+1];\n \n uint f_sum;\n \n foreach(i, ref f; fence) {\n //uint f;\n readf(\"%s \", &f);\n sum_arr[i+1] = f_sum + f;\n f_sum += f;\n }\n \n uint min = sum_arr[k] - sum_arr[0], min_idx = 1;\n \n for(uint j = k; j < n+1; ++j) {\n if(sum_arr[j] - sum_arr[j - k] < min) {\n min = sum_arr[j] - sum_arr[j - k];\n min_idx = j - k + 1;\n }\n }\n \n min_idx.writeln;\n //foreach()\n}\n\n\nalias id(alias token) = token;\n\nalias var(alias elem) = std.traits.Unqual!(typeof(elem));\n\nauto mut(T)(auto ref T in_val) {\n std.traits.Unqual!(T) rv = in_val;\n return rv;\n}\n\nauto imut(T)(auto ref T in_val) {\n immutable immrv = in_val;\n return immrv;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid main() {\n int n, k; readf(\"%d %d\\n\", &n, &k);\n int[] xs = stdin.readln.chomp.split(\" \").map!(to!int).array;\n int[] ss = new int[xs.length+1];\n ss[0] = 0;\n for (int i = 0; i < xs.length; i++) {\n ss[i+1] = ss[i] + xs[i];\n }\n int ans = int.max;\n int index = -1;\n for (int i = 0; i <= xs.length - k; i++) {\n if (ans > ss[i+k] - ss[i]) {\n ans = ss[i+k] - ss[i];\n index = i + 1;\n }\n }\n index.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto H = readln.split.map!(to!int).array;\n\n auto acm = new int[](N+1);\n foreach (i; 0..N) {\n acm[i+1] = acm[i] + H[i];\n }\n\n \n int minv = int.max;\n int mini = -1;\n\n foreach (i; 0..N-K+1) {\n auto a = acm[i+K] - acm[i];\n if (a < minv) {\n minv = a;\n mini = i+1;\n }\n }\n mini.writeln;\n}\n"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm\n , std.range\n , std.container;\n\n\nvoid main() {\n uint n, k;\n readf(\"%s %s\\n\", &n, &k);\n \n //auto fence = new uint[n];\n auto sum_arr = new uint[n+1];\n \n uint f_sum;\n \n foreach(i; 0..n) {\n uint f;\n readf(\"%s \", &f);\n sum_arr[i+1] = f_sum + f;\n f_sum += f;\n }\n \n uint min = sum_arr[k] - sum_arr[0], min_idx = 1;\n \n for(uint j = k; j < n+1; ++j) {\n if(sum_arr[j] - sum_arr[j - k] < min) {\n min = sum_arr[j] - sum_arr[j - k];\n min_idx = j - k + 1;\n }\n }\n \n min_idx.writeln;\n //foreach()\n}\n\n\nalias id(alias token) = token;\n\nalias var(alias elem) = std.traits.Unqual!(typeof(elem));\n\nauto mut(T)(auto ref T in_val) {\n std.traits.Unqual!(T) rv = in_val;\n return rv;\n}\n\nauto imut(T)(auto ref T in_val) {\n immutable immrv = in_val;\n return immrv;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,k;\n readf!\"%d %d\"(n,k);\n readln;\n auto a=readln.splitter\n .map!(to!int)\n .cumulativeFold!\"a+b\"\n .array;\n int m=int.max,r;\n foreach(i;k-1..n){\n int cur=a[i];\n if(i>=k) cur-=a[i-k];\n if(cur<m){\n m=cur;\n r=i;\n }\n }\n writeln(r-k+2);\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,k;\n readf!\"%d %d\"(n,k);\n readln;\n auto a=readln.splitter\n .map!(to!int)\n .array;\n foreach(i;1..n)\n a[i]+=a[i-1];\n int m=int.max,r;\n foreach(i;k-1..n){\n int cur=a[i];\n if(i>=k) cur-=a[i-k];\n if(cur<m){\n m=cur;\n r=i;\n }\n }\n writeln(r-k+2);\n}\n\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main()\n{\n int n, k;\n readVars(n, k);\n auto h = readln.split.to!(int[]);\n\n int j;\n int maxsum = h[0 .. k].sum;\n int v = maxsum;\n\n foreach(r ; k .. n){\n v += h[r] - h[r - k];\n\n if (maxsum > v) {\n maxsum = v;\n j = r - k + 1;\n }\n }\n\n writeln(j + 1);\n}\n\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main()\n{\n int n, k;\n readVars(n, k);\n auto h = readln.split.to!(int[]);\n auto hps = new int[](n + 1);\n\n foreach(i ; 0 .. n) hps[i + 1] += hps[i] + h[i];\n\n debug {\n writeln(hps);\n }\n\n int minsum = mod, j;\n\n foreach(i ; 0 .. n - k + 1) {\n if (minsum > hps[i + k] - hps[i]) {\n minsum = hps[i + k] - hps[i];\n j = i;\n }\n }\n\n writeln(j + 1);\n}\n\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid main() {\n int n, k; readf(\"%d %d\\n\", &n, &k);\n int[] xs = stdin.readln.chomp.split(\" \").map!(to!int).array;\n int[] ss = new int[xs.length+1];\n ss[0] = 0;\n for (int i = 0; i < xs.length - 1; i++) {\n ss[i+1] = ss[i] + xs[i];\n }\n int ans = int.max;\n int index = -1;\n for (int i = 0; i < xs.length - k; i++) {\n if (ans > ss[i+k] - ss[i]) {\n ans = ss[i+k] - ss[i];\n index = i + 1;\n }\n }\n index.writeln;\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid main() {\n int n, k; readf(\"%d %d\\n\", &n, &k);\n int[] xs = stdin.readln.chomp.split(\" \").map!(to!int).array;\n int[] ss = new int[xs.length+1];\n ss[0] = 0;\n for (int i = 0; i < xs.length - 1; i++) {\n ss[i+1] = ss[i] + xs[i];\n }\n int ans = int.max;\n int index = 1;\n for (int i = 0; i < xs.length - k; i++) {\n if (ans > ss[i+k] - ss[i]) {\n ans = ss[i+k] - ss[i];\n index = i + 1;\n }\n }\n index.writeln;\n}\n"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm\n , std.range\n , std.container;\n\n\nvoid main() {\n uint n, k;\n readf(\"%s %s\\n\", &n, &k);\n \n //auto fence = new uint[n];\n auto sum_arr = new uint[n+2];\n \n uint f_sum;\n \n foreach(i; 0..n) {\n uint f;\n readf(\"%s \", &f);\n sum_arr[i+1] = f_sum + f;\n f_sum += f;\n }\n \n uint min = sum_arr[k] - sum_arr[0], min_idx = k+1;\n \n for(uint j = k; j < n+1; ++j) {\n if(sum_arr[j] - sum_arr[j - k] < min) {\n min = sum_arr[j] - sum_arr[j - k];\n min_idx = j - k + 1;\n }\n }\n \n min_idx.writeln;\n //foreach()\n}\n\n\nalias id(alias token) = token;\n\nalias var(alias elem) = std.traits.Unqual!(typeof(elem));\n\nauto mut(T)(auto ref T in_val) {\n std.traits.Unqual!(T) rv = in_val;\n return rv;\n}\n\nauto imut(T)(auto ref T in_val) {\n immutable immrv = in_val;\n return immrv;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "69f4e340b3f6e1d807e0545ebea1fe2f"} {"source_code": "import core.bitop, std.stdio;\nvoid main() {\n\treadln;\n\tlong a, b;\n\twhile (readf (\" %s %s\", &a, &b) > 0) {\n\t\tif (a > b) a ^= b ^= a ^= b;\n\t\twriteln (!(b % a) && !((b /= a) & (b - 1)) ? (b.bsr + 2) / 3 : -1);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.functional;\nimport std.conv;\nimport std.string;\nimport std.math;\nimport core.bitop;\n\nvoid main() {\n\tint tt = readln().chomp.to!int;\n\tforeach (t; 0 .. tt) {\n\t\tauto arr = readln().chomp.split(\" \").map!(to!ulong);\n\t\tulong a = arr[0];\n\t\tulong b = arr[1];\n\t\tif (b < a) {\n\t\t\tulong tm = a;\n\t\t\ta = b;\n\t\t\tb = tm;\n\t\t}\n\t\tif (b > a) {\n\t\t\tif (b % a != 0) {\n\t\t\t\twriteln(-1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tulong diff = b / a;\n\t\t\tulong high = bsr(diff);\n\t\t\tif ((1UL << high) == diff) {\n\t\t\t\twriteln(\n\t\t\t\t\thigh / 3 + (high % 3) / 2 + (high % 3) % 2\n\t\t\t\t);\n\t\t\t}\n\t\t\telse {\n\t\t\t\twriteln(-1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\twriteln(0);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\n\t\tstring s, s2;\n\t\twhile (a != 0)\n\t\t{\n\t\t\ts ~= cast(char)('0'+(a%2));\n\t\t\ta /= 2;\n\t\t}\n\t\twhile (b != 0)\n\t\t{\n\t\t\ts2 ~= cast(char)('0'+(b%2));\n\t\t\tb /= 2;\n\t\t}\n\t\tdebug writeln(s);\n\t\tdebug writeln(s2);\n\n\t\tans[ti] = abs(cast(int)s.length - cast(int)s2.length);\n\t\tans[ti] += 2;\n\t\tans[ti] /= 3;\n\t\twhile (s.length < s2.length)\n\t\t{\n\t\t\ts = '0' ~ s;\n\t\t}\n\t\twhile (s.length > s2.length)\n\t\t{\n\t\t\ts2 = '0' ~ s2;\n\t\t}\n\t\tdebug writeln(s);\n\t\tdebug writeln(s2);\n\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tif (s[i] != s2[i])\n\t\t\t\tans[ti] = -1;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import core.bitop,std.stdio;\nvoid main(){\n\treadln;\n\tlong a,b;\n\twhile(readf(\" %s %s\",&a,&b)>0){\n\t\tif(a>b)a^=b^=a^=b;\n\t\twriteln(!(b%a)&&!((b/=a)&(b-1))?(b.bsr + 2)/3:-1);\n\t}\n}\n"}, {"source_code": "import core.bitop,std.stdio;void main(){readln;long a,b;while(readf!\" %s %s\"(a,b)>0)\n{if(a>b)a^=b^=a^=b;writeln((b%a)|((b/=a)&(b-1))?-1:(b.bsr+2)/3);}}"}, {"source_code": "import core.bitop,std.stdio;void main(){readln;long a,b;while(readf(\" %s %s\",&a,&b)>0){if(a>b)a^=b^=a^=b;writeln(!(b%a)&&!((b/=a)&(b-1))?(b.bsr + 2)/3:-1);}}"}, {"source_code": "import core.bitop, std.algorithm, std.stdio;\nvoid main() {\n\treadln;\n\tlong a, b, r;\n\twhile (readf (\" %s %s\", &a, &b) > 0) {\n\t\tif (a > b) swap (a, b);\n\t\twriteln (!(b % a) && !((b /= a) & (b - 1)) ? (b.bsr + 2) / 3 : -1);\n\t}\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.conv, std.stdio, std.string;\nvoid main () {\n\tforeach (t; 0..readln.strip.to!int) {\n\t\tlong a, b, r = -1;\n\t\treadf !(\" %s %s\") (a, b);\n\t\tif (a > b) swap (a, b);\n\t\tif (b % a == 0) {\n\t\t\tauto c = b / a;\n\t\t\tif (!(c & (c - 1))) r = (bsr (c) + 2) / 3;\n\t\t}\n\t\tr.writeln;\n\t}\n}\n"}], "negative_code": [], "src_uid": "541039ef3c9b8251b758608811533e06"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n bool[int] S;\n for (int i = 0; i * i <= 10^^6; ++i) {\n S[i*i] = true;\n }\n\n int ans = -(10^^6)-1;\n foreach (a; A) if (!(a in S)) ans = max(ans, a);\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint res = int.min;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tauto isGood = (c < 0);\n\t\t\tif (!isGood)\n\t\t\t{\n\t\t\t\tauto d = sqrt (c * 1.0);\n\t\t\t\tisGood = (d * d != c);\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tres = max (res, c);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n// floor(sqrt(a))\nlong floorSqrt(long a) {\n import core.bitop : bsr;\n import std.algorithm : min;\n long b = a, x = 0, y = 0;\n for (int e = bsr(a) & ~1; e >= 0; e -= 2) {\n x <<= 1;\n y <<= 1;\n if (b >= (y | 1) << e) {\n b -= (y | 1) << e;\n x |= 1;\n y += 2;\n }\n }\n return x;\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n long ans = long.min;\n foreach (i; 0 .. N) {\n if (A[i] != floorSqrt(A[i])^^2) {\n chmax(ans, A[i]);\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.stdio, std.string, std.traits, std.typecons,\n\tstd.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n/// struct vector as c++ vector\nstruct Vec(T)\n{\n\tprivate Array!T buf;\n\talias buf this;\n\tthis(this)\n\t{\n\t\tbuf = buf.dup;\n\t}\n\t/// construct from length\n\tthis(U)(U length)\n\t\t\tif (is(U == int) || is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint))\n\t{\n\t\tbuf.length = length;\n\t}\n\t/// construct from length and default value\n\tthis(U, X)(U length, X val)\n\t\t\tif (isImplicitlyConvertible!(X, T) || (is(U == int)\n\t\t\t\t|| is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint)))\n\t{\n\t\tbuf.length = length;\n\t\tforeach (ref x; buf[])\n\t\t{\n\t\t\tx = val;\n\t\t}\n\t}\n\t/// construct from other array\n\tthis(U)(U[] values...) if (isImplicitlyConvertible!(U, T))\n\t{\n\t\tbuf = Array!(T)(values);\n\t}\n\t/// construct from other range\n\tthis(Range)(Range r)\n\t\t\tif (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range,\n\t\t\t\tT) && !is(Range == T[]))\n\t{\n\t\tbuf = Array!(T)(r);\n\t}\n\t/// integer length\n\tint size() @property const\n\t{\n\t\treturn cast(int) buf.length;\n\t}\n}\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt biggcd(BigInt a, BigInt b)\n\t\t{\n\t\t\tBigInt res = 1;\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\tif ((a & 1) && (b & 1))\n\t\t\t\t{\n\t\t\t\t\ta -= b;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (a & 1)\n\t\t\t\t{\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (b & 1)\n\t\t\t\t{\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres <<= 1;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\tif (a < b)\n\t\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn res * a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tint n;\n\tread(n);\n\tauto a = arread!int;\n\tint ans = int.min;\n\tforeach (x; a)\n\t{\n\t\tif (x < 0)\n\t\t{\n\t\t\tans = max(ans, x);\n\t\t\tcontinue;\n\t\t}\n\t\tint s = cast(int) sqrt(1.0L * x);\n\t\tbool fl = true;\n\t\tforeach (g; s - 2 .. s + 3)\n\t\t{\n\t\t\tif (x == g * g)\n\t\t\t{\n\t\t\t\tfl = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (fl)\n\t\t\tans = max(ans, x);\n\t}\n\twriteln(ans);\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.stdio, std.string, std.traits, std.typecons,\n\tstd.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n/// struct vector as c++ vector\nstruct Vec(T)\n{\n\tprivate Array!T buf;\n\talias buf this;\n\tthis(this)\n\t{\n\t\tbuf = buf.dup;\n\t}\n\t/// construct from length\n\tthis(U)(U length)\n\t\t\tif (is(U == int) || is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint))\n\t{\n\t\tbuf.length = length;\n\t}\n\t/// construct from length and default value\n\tthis(U, X)(U length, X val)\n\t\t\tif (isImplicitlyConvertible!(X, T) || (is(U == int)\n\t\t\t\t|| is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint)))\n\t{\n\t\tbuf.length = length;\n\t\tforeach (ref x; buf[])\n\t\t{\n\t\t\tx = val;\n\t\t}\n\t}\n\t/// construct from other array\n\tthis(U)(U[] values...) if (isImplicitlyConvertible!(U, T))\n\t{\n\t\tbuf = Array!(T)(values);\n\t}\n\t/// construct from other range\n\tthis(Range)(Range r)\n\t\t\tif (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range,\n\t\t\t\tT) && !is(Range == T[]))\n\t{\n\t\tbuf = Array!(T)(r);\n\t}\n\t/// integer length\n\tint size() @property const\n\t{\n\t\treturn cast(int) buf.length;\n\t}\n}\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt biggcd(BigInt a, BigInt b)\n\t\t{\n\t\t\tBigInt res = 1;\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\tif ((a & 1) && (b & 1))\n\t\t\t\t{\n\t\t\t\t\ta -= b;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (a & 1)\n\t\t\t\t{\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (b & 1)\n\t\t\t\t{\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres <<= 1;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\tif (a < b)\n\t\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn res * a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tint n;\n\tread(n);\n\tauto a = arread!int;\n\tint ans;\n\tforeach (x; a)\n\t{\n\t\tif (x < 0)\n\t\t{\n\t\t\tans = max(ans, x);\n\t\t\tcontinue;\n\t\t}\n\t\tint s = cast(int) sqrt(1.0L * x);\n\t\tbool fl = true;\n\t\tforeach (g; s - 2 .. s + 3)\n\t\t{\n\t\t\tif (x == g * g)\n\t\t\t{\n\t\t\t\tfl = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (fl)\n\t\t\tans = max(ans, x);\n\t}\n\twriteln(ans);\n}\n"}], "src_uid": "d46d5f130d8c443f28b52096c384fef3"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const H = readReal();\n \n auto ans = new real[N];\n foreach (i; 1 .. N) {\n ans[i] = H * sqrt(1.0L * i / N);\n }\n foreach (i; 1 .. N) {\n if (i > 1) write(\" \");\n writef(\"%.12f\", ans[i]);\n }\n writeln;\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto H = s[1].to!real;\n real A = H / 2;\n real B = A / N;\n\n auto rate = new real[](N-1);\n auto ans = new real[](N-1);\n rate[0] = sqrt(2 * B / H);\n ans[0] = H * rate[0];\n\n foreach (i; 0..N-2) {\n real hi = 1;\n real lo = rate[i];\n foreach (_; 0..100) {\n real mid = (hi + lo) / 2;\n real area = (rate[i] + mid) * (mid - rate[i]) * H / 2;\n if (area < B) lo = mid;\n else hi = mid;\n }\n rate[i+1] = hi;\n ans[i+1] = hi * H;\n }\n\n writef(\"%.9f\", ans[0]);\n iota(1, N-1).each!(i => writef(\" %.9f\", ans[i]));\n writeln;\n}\n"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nimport std.numeric: fft,Fft,gcd,inverseFft;\nalias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;\nalias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;\nprivate\n{\n\tpure nothrow \n\t{\n\t\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\t\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\t\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\t\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\t\tsize_t lowb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tsize_t l=0,r=a.length;\n\t\t\twhile(r-l>1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]<g))r=m;\n\t\t\t\telse l=m;\n\t\t\t}\n\t\t\treturn (!(a[l]<g))?l:r;\n\t\t}\n\t\tsize_t upb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tsize_t l=0,r=a.length;\n\t\t\twhile(r-l>1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g<a[m])r=m;\n\t\t\t\telse l=m;\n\t\t\t}\n\t\t\treturn (g<a[l])?l:r;\n\t\t}\n\t\tsize_t binf(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tauto pos=lowb(a,g);\n\t\t\treturn (g==a[pos])?pos:a.length;\n\t\t}\n\t\tbool binary_search(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\treturn binf(a,g)!=a.length;\n\t\t}\n\t}\n\tvoid putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))\n\t{foreach(const ref i;a)write(i,ch);}\n\tvoid putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))\n\t{\n\t\tforeach(ref const i;a)\n\t\t{\n\t\t\tforeach(ref const j;i)write(j,' ');\n\t\t\twriteln;\n\t\t}\n\t}\n\tbool getarr(X)(X a,in size_t n)\n\t{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\n\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treturn s==ptrs.length;\n\t}\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treadln;\n\t\treturn s==ptrs.length;\n\t}\n\tnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\n\tnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n\t@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nprivate\n{\n\n}\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,h;\nloop:while(read(n,h))\n\t{\n\t\tforeach(i;1..n)\n\t\t{\n\t\t\twritef(\"%.10f \",h*sqrt(i*1.0000L/n));\n\t\t}\n\t\tdebug writeln;\n\t}\n}"}], "negative_code": [], "src_uid": "6f8a1a138ea2620f2013f426e29e4d98"} {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nint n, m;\nstring s, t;\n\nvoid main() {\n scan(n, m);\n scan(s);\n scan(t);\n\n if (n > m) {\n swap(n, m);\n swap(s, t);\n }\n\n int[] ans = new int[](2000);\n\n foreach (i ; 0 .. m - n + 1) {\n int[] tmp = new int[](0);\n\n debug {\n writeln(\"s:\", s);\n writeln(\"t:\", t);\n }\n\n foreach (j ; 0 .. n) {\n if (s[j] != t[j]) {\n tmp ~= j + 1;\n }\n }\n\n if (tmp.length.to!int < ans.length.to!int) {\n ans = tmp.dup;\n }\n\n t.popFront();\n }\n\n writeln(ans.length);\n writefln(\"%(%s %)\", ans);\n}\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.exception;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.math;\n\nint CompareToStrings ( dstring first, dstring second )\n{\n\t//writeln(first, second);\n\tint returnVal = 0;\n\tzip(first, second).each!( a => a[0] == a[1] ? returnVal++ : returnVal );\n\t//writeln(returnVal);\n\treturn returnVal;\n}\n\nint[] FindDiffPositions ( dstring first, dstring second )\n{\n\tint[] returnVal;\n\tfor ( int i = 0; i < first.length; i++ )\n\t{\n\t\tif ( first[i] != second[i] )\n\t\t\treturnVal ~= (i + 1);\n\t}\n\treturn returnVal;\n}\n\nvoid main() \n{\n auto ilkSatir = stdin.readln.strip.split().map!(a => to!int(a)).array();\n\tauto s = stdin.readln.strip.to!dstring;\n\tauto t = stdin.readln.strip.to!dstring;\n\t\n\tint pos = 0;\n\tint max = 0;\n\tfor ( int i = 0; i <= t.length - s.length; i++ )\n\t{\n\t\tint curVal = CompareToStrings( s, t[i..i+s.length]);\n\t\tif ( curVal > max )\n\t\t{\n\t\t\tpos = i;\n\t\t\tmax = curVal;\n\t\t}\n\t}\n\n\tauto curList = FindDiffPositions( s, t[pos..pos+s.length]);\n\twriteln( s.length - max );\n\tcurList.each!(a => write(a, \" \"));\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.exception;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.math;\n\nint CompareToStrings ( dstring first, dstring second )\n{\n\t//writeln(first, second);\n\tint returnVal = 0;\n\tzip(first, second).each!( a => a[0] == a[1] ? returnVal++ : returnVal );\n\t//writeln(returnVal);\n\treturn returnVal;\n}\n\nint[] FindDiffPositions ( dstring first, dstring second )\n{\n\tint[] returnVal;\n\tfor ( int i = 0; i < first.length; i++ )\n\t{\n\t\tif ( first[i] != second[i] )\n\t\t\treturnVal ~= (i + 1);\n\t}\n\treturn returnVal;\n}\n\nvoid main() \n{\n auto ilkSatir = stdin.readln.strip.split().map!(a => to!int(a)).array();\n\tauto s = stdin.readln.strip.to!dstring;\n\tauto t = stdin.readln.strip.to!dstring;\n\t\n\tint pos = 0;\n\tint max = 0;\n\tfor ( int i = 0; i <= t.length - s.length; i++ )\n\t{\n\t\tint curVal = CompareToStrings( s, t[i..i+s.length]);\n\t\tif ( curVal > max )\n\t\t{\n\t\t\tpos = i;\n\t\t\tmax = curVal;\n\t\t}\n\t}\n\n\tauto curList = FindDiffPositions( s, t[pos..pos+s.length]);\n\twriteln( s.length - max );\n\twriteln( curList );\n}"}], "src_uid": "dd26f45869b73137e5e5cc6820cdc2e4"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n long[] ls, aa, bb; get(ls); get(aa); get(bb);\r\n\r\n long x = abs(aa[1] - bb[1]) + 2, res;\r\n foreach (i; 2..N) {\r\n auto a = aa[i];\r\n auto b = bb[i];\r\n if (a > b) swap(a, b);\r\n res = max(res, x + ls[i-1] - 1);\r\n if (a == b) {\r\n x = 2;\r\n } else {\r\n x += 2 + a-1 + ls[i-1]-b;\r\n x = max(x, b - a + 2);\r\n }\r\n }\r\n res = max(res, x + ls[$-1] - 1);\r\n writeln(res);\r\n }\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tlong res = 0;\r\n\t\tlong cur = c[n - 1] - 1;\r\n\t\tforeach_reverse (i; 1..n)\r\n\t\t{\r\n\t\t\tcur += 2;\r\n\t\t\tif (a[i] > b[i])\r\n\t\t\t{\r\n\t\t\t\tswap (a[i], b[i]);\r\n\t\t\t}\r\n\t\t\tres = max (res, cur + b[i] - a[i]);\r\n\t\t\tcur = max (cur, b[i] - a[i]);\r\n\t\t\tcur += c[i - 1] - b[i];\r\n\t\t\tcur += a[i] - 1;\r\n\t\t\tif (a[i] == b[i])\r\n\t\t\t{\r\n\t\t\t\tcur = c[i - 1] - 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto c = RDA;\n\t\tauto a = RDA(-1);\n\t\tauto b = RDA(-1);\n\n\t\tlong tot;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (i == 1)\n\t\t\t{\n\t\t\t\ttot += abs(a[1] - b[1]) + 2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i] != b[i])\n\t\t\t\t{\n\t\t\t\t\ttot += min(a[i], b[i]) + c[i-1] - 1 - max(a[i], b[i]) + 2;\n\t\t\t\t\ttot.chmax(abs(a[i] - b[i]) + 2);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[ti].chmax(tot + c[i-1] - 1);\n\t\t\t\t\ttot = 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[ti].chmax(tot + c[i] - 1);\n\t\t\tdebug writeln(\"i:\", i, \" tot:\", tot, \" ans:\", ans[ti]);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n int[] ls, aa, bb; get(ls); get(aa); get(bb);\r\n\r\n int x = abs(aa[1] - bb[1]) + 2, res;\r\n foreach (i; 2..N) {\r\n auto a = aa[i];\r\n auto b = bb[i];\r\n if (a > b) swap(a, b);\r\n res = max(res, x + ls[i-1] - 1);\r\n if (a == b) {\r\n x = 2;\r\n } else {\r\n x += 2 + a-1 + ls[i-1]-b;\r\n x = max(x, b - a + 2);\r\n }\r\n }\r\n res = max(res, x + ls[$-1] - 1);\r\n writeln(res);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n int[] ls, aa, bb; get(ls); get(aa); get(bb);\r\n\r\n int x = abs(aa[1] - bb[1]) + 2, res;\r\n foreach (i; 2..N) {\r\n auto a = aa[i];\r\n auto b = bb[i];\r\n if (a > b) swap(a, b);\r\n res = max(res, x + ls[i-1] - 1);\r\n if (a == b) {\r\n x = 2;\r\n } else {\r\n x += 2 + a-1 + ls[i-1]-b;\r\n }\r\n }\r\n res = max(res, x + ls[$-1] - 1);\r\n writeln(res);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto c = RDA;\n\t\tauto a = RDA(-1);\n\t\tauto b = RDA(-1);\n\n\t\tlong tot;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (i == 1)\n\t\t\t{\n\t\t\t\ttot += abs(a[1] - b[1]) + 2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i] != b[i])\n\t\t\t\t\ttot += min(a[i], b[i]) + c[i-1] - 1 - max(a[i], b[i]) + 2;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[ti].chmax(tot + c[i-1] - 1);\n\t\t\t\t\ttot = 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[ti].chmax(tot + c[i] - 1);\n\t\t\ttot.chmax(abs(a[i] - b[i]));\n\t\t\tdebug writeln(\"i:\", i, \" tot:\", tot, \" ans:\", ans[ti]);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tlong res = 0;\r\n\t\tlong cur = c[n - 1] - 1;\r\n\t\tforeach_reverse (i; 1..n)\r\n\t\t{\r\n\t\t\tcur += 2;\r\n\t\t\tif (a[i] > b[i])\r\n\t\t\t{\r\n\t\t\t\tswap (a[i], b[i]);\r\n\t\t\t}\r\n\t\t\tcur = max (cur, b[i] - a[i]);\r\n\t\t\tres = max (res, cur + b[i] - a[i]);\r\n\t\t\tcur += c[i - 1] - b[i];\r\n\t\t\tcur += a[i] - 1;\r\n\t\t\tif (a[i] == b[i])\r\n\t\t\t{\r\n\t\t\t\tcur = c[i - 1] - 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "src_uid": "3d898a45ab89b93e006270a77db49017"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1496/problem/B\n// math, greedy\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\n long n, k;\nwhile(t--) {\n readf(\"%s %s\\n\", &n, &k);\n long[] a = readln.split.map!(to!long).array;\n a.sort;\n\n long maxima = a[$-1];\n long mex = maxima + 1;\n for(int i = 0; i < n; ++i) {\n if(i != a[i]) {\n mex = i;\n break;\n }\n }\n\n auto rbt = redBlackTree(a);\n\n //a.writeln;\n //writefln(\"max: %s mex: %s\\n\", maxima, mex);\n if(mex < maxima) {\n if(k > 0) {\n rbt.insert((maxima + mex - 1)/2 + 1);\n }\n writefln(\"%s\", rbt.length);\n continue;\n }\n\n writefln(\"%s\", n + k);\n\n}\n}\n\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n;\n n = scan!int;\n ll k = scan;\n auto arr = scanArray;\n ll maxx = arr.maxElement;\n auto rbt = redBlackTree!ll(arr);\n bool f = 1;\n for(ll i = 0; i < n.to!long; ++i){\n if(!(i in rbt)){\n f = 0;\n ll val = (maxx + i)/2 + (maxx + i) % 2;\n if(k) rbt.insert(val);\n break;\n }\n }\n if(f){\n writeln(n + k);\n }else{\n writeln(rbt.length);\n }\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort();\r\n\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tans[ti] = n;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tint r = n;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] != i)\r\n\t\t\t{\r\n\t\t\t\tr = i;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (r == n)\r\n\t\t\tans[ti] = n + k;\r\n\t\telse\r\n\t\t{\r\n\t\t\tauto y = (r + a[n-1] + 1) / 2;\r\n\t\t\tint add = 1;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (a[i] == y)\r\n\t\t\t\t{\r\n\t\t\t\t\tadd = 0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tans[ti] = n + add;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort();\r\n\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tans[ti] = n;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tint r = n;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] != i)\r\n\t\t\t{\r\n\t\t\t\tr = i;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tauto y = (r + a[n-1] + 1) / 2;\r\n\t\tif (y == n)\r\n\t\t\tans[ti] = n + k;\r\n\t\telse\r\n\t\t{\r\n\t\t\tint add = 1;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (a[i] == y)\r\n\t\t\t\t{\r\n\t\t\t\t\tadd = 0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tans[ti] = n + add;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort();\r\n\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tans[ti] = n;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tint r = n;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] != i)\r\n\t\t\t{\r\n\t\t\t\tr = i;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tauto y = (r + a[n-1] + 1) / 2;\r\n\t\tif (y == n)\r\n\t\t\tans[ti] = n + k;\r\n\t\telse\r\n\t\t{\r\n\t\t\tbool g(int x)\r\n\t\t\t{\r\n\t\t\t\treturn a[x] <= y;\r\n\t\t\t}\r\n\t\t\tauto rr = binarySearch!(g)(-1, n);\r\n\t\t\tif (rr == -1)\r\n\t\t\t\tans[ti] = n + 1;\r\n\t\t\telse if (a[rr] != y)\r\n\t\t\t\tans[ti] = n + 1;\r\n\t\t\telse\r\n\t\t\t\tans[ti] = n;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort();\r\n\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tans[ti] = n;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tbool f(int x)\r\n\t\t{\r\n\t\t\treturn a[x] == x;\r\n\t\t}\r\n\t\tauto r = binarySearch!(f)(-1, n) + 1;\r\n\t\tauto y = (r + a[n-1] + 1) / 2;\r\n\t\tif (y == n)\r\n\t\t\tans[ti] = n + k;\r\n\t\telse\r\n\t\t{\r\n\t\t\tbool g(int x)\r\n\t\t\t{\r\n\t\t\t\treturn a[x] <= y;\r\n\t\t\t}\r\n\t\t\tauto rr = binarySearch!(g)(-1, n);\r\n\t\t\tif (rr == -1)\r\n\t\t\t\tans[ti] = n + 1;\r\n\t\t\telse if (a[rr] != y)\r\n\t\t\t\tans[ti] = n + 1;\r\n\t\t\telse\r\n\t\t\t\tans[ti] = n;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort();\r\n\r\n\t\tbool f(int x)\r\n\t\t{\r\n\t\t\treturn a[x] == x;\r\n\t\t}\r\n\t\tauto r = binarySearch!(f)(-1, n) + 1;\r\n\t\tauto y = (r + a[n-1] + 1) / 2;\r\n\t\tif (y == n)\r\n\t\t\tans[ti] = n + k;\r\n\t\telse\r\n\t\t{\r\n\t\t\tbool g(int x)\r\n\t\t\t{\r\n\t\t\t\treturn a[x] <= y;\r\n\t\t\t}\r\n\t\t\tauto rr = binarySearch!(g)(-1, n);\r\n\t\t\tif (rr == -1)\r\n\t\t\t\tans[ti] = n + 1;\r\n\t\t\telse if (a[rr] != y)\r\n\t\t\t\tans[ti] = n + 1;\r\n\t\t\telse\r\n\t\t\t\tans[ti] = n;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "c0d23fe28ebddbfc960674e3b10122ad"} {"source_code": "\ufeffimport std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tubyte n;\n\t\n\treadf(\"%s\", &n);\n\t\n\tint ans = 1;\n\tint[string] map;\n\tstring name1, name2, tmp;\n\t\n\tmap[\"polycarp\"] = 1;\n\n\twhile (n--) {\n\t\treadf(\" %s %s %s\\n\", &name1, &tmp, &name2);\n\t\tauto e = map[toLower(name2)] + 1;\n\t\tif (e > ans)\n\t\t\tans = e;\n\t\tmap[toLower(name1)] = e;\n\t}\n\t\n\twriteln(ans);\n}", "positive_code": [{"source_code": "\ufeffimport std.stdio;\nimport std.string;\n\nvoid main() {\n\n\tubyte n;\n\n\treadf(\"%s\", &n);\n\n\tint ans = 1;\n\tint[string] map;\n\tstring name1, name2;\n\n\tmap[\"polycarp\"] = 1;\n\n\twhile (n--) {\n\t\tname1 = readln(' ').strip;\n\t\treadln(' ');\n\t\tname2 = readln.strip;\n\t\tauto e = map[toLower(name2)] + 1;\n\t\tif (e > ans)\n\t\t\tans = e;\n\t\tmap[toLower(name1)] = e;\n\t}\n\n\twriteln(ans);\n}"}], "negative_code": [], "src_uid": "16d4035b138137bbad247ccd5e560051"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias mp=make_pair;\nalias bins=binary_search;\nalias orsq=orient_square;\nimmutable int mod=1000000007;\npure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow X binpow(X,Y)(X base,Y exp)\nif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\npure nothrow @property X sqr(X)(in X a_) {return a_*a_;}\npure nothrow @property X cub(X)(in X a_) {return a_*a_*a_;}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\npure nothrow V foldr(R,V,T)(R range,T arg,V nach) if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n{\n\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\treturn nach;\n}\npure nothrow size_t countr(R,T)(R range,T fun) if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n{\n\tsize_t nach;\n\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\treturn nach;\n}\npure nothrow T orient_square(T)(pair!(T,T)[] figure...) if(is(typeof(figure.front*figure.front)==T))\n{\n\tauto n=figure.front,t=figure.front;\n\tfigure.popFront();\n\tT ans=0;\n\tfor(;!figure.empty;figure.popFront())\n\t{\n\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\tt=figure.front;\n\t}\n\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n}\npure nothrow real square(T)(pair!(T,T)[] figure...) if(is(typeof(figure.front*figure.front)==T))\n{\n\treturn abs(orient_square(figure))/2.000000000000000;\n}\nstruct Tree(T,alias arg=\"a+b\")\n{\n\tprivate alias fun=binaryFun!arg;\n\tprivate static const uint n=int.max;\n\tprivate T[uint] t;\n\tprivate void upd(uint v,uint vl,uint vr,uint i,T x)\n\t{\n\t\tif (vr - vl == 1)t[v] = x;\n\t\tuint vm = (vl + vr) >> 1;\n\t\tif(i<vm)upd(2*v,vl,vm,i,x);\n\t\telse upd(2*v+1,vm,vr,i,x);\n\t\tt[v]=fun(t[v*2],t[v*2+1]);\n\t}\n\tvoid upd(uint i,T x)\n\t{\n\t\tupd(1,0,n,i,x);\n\t}\n\tprivate T cel(uint v,uint vl,uint vr,uint l,uint r)\n\t{\n\t\tif(vl==l && r==vr) return t[v];\n\t\tuint vm=(vl+vr) >> 1;\n\t\tif(r<=vm) return cel(2*v,vl,vm,l,r);\n\t\telse if(l>=vm) return cel(2*v+1,vm,vr,l,r);\n\t\telse return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));\n\t}\n\tT cel(uint l,uint r){return cel(1,0,n,l,r);}\n};\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\twhile(input(&n))\n\t{\n\t\tauto a=new pii[n];\n\t\tforeach_reverse(i;0..n)input(&a[i].fi,&a[i].se);\n\t\tint check(int r)\n\t\t{\n\t\t\tforeach(i;0..n)\n\t\t\t{\n\t\t\t\tr-=a[i].fi;\n\t\t\t\tif(a[i].se==2 && r>1899)return 1;\n\t\t\t\telse if(a[i].se==1 && r<1900) return -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t\tint l=int.min/2,r=int.max/2;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tint m=(l+r)>>1;\n\t\t\tauto k=check(m);\n\t\t\tif(k==1) r=m;\n\t\t\telse l=m;\n\t\t}\n\t\tif(l>=int.max/2-1)writeln(\"Infinity\");\n\t\telse if(check(l)!=0)writeln(\"Impossible\");\n\t\telse writeln(l);\n\t}\n\tdebug system(\"pause\");\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint lo = int.min / 2;\n\t\tint hi = int.max / 2;\n\t\tint delta = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint c;\n\t\t\tint d;\n\t\t\treadf (\" %s %s\", &c, &d);\n\t\t\tif (d == 1)\n\t\t\t{ // rating + delta >= 1900\n\t\t\t\tlo = max (lo, 1900 - delta);\n\t\t\t}\n\t\t\telse if (d == 2)\n\t\t\t{ // rating + delta <= 1899\n\t\t\t\thi = min (hi, 1899 - delta);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tdelta += c;\n\t\t}\n\t\tdebug {writeln (lo, \" \", hi);}\n\t\tif (hi > int.max / 4)\n\t\t{\n\t\t\twriteln (\"Infinity\");\n\t\t}\n\t\telse if (lo > hi)\n\t\t{\n\t\t\twriteln (\"Impossible\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (hi + delta);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "2a4c24341231cabad6021697f15d953a"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto r = RD;\n\n\t\tauto x = min(n-1, r);\n\t\tans[ti] = x * (x+1) / 2;\n\t\tif (r >= n)\n\t\t\t++ans[ti];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.container: DList;\nimport std.algorithm: all, map, count, filter;\nimport std.range: iota;\nimport std.array: array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, r;\n read(n), read(r);\n // k < n\n // k = 1: 1\n // k = 2: 2\n // k = 3: 3\n // ...\n // k = n - 1: n - 1\n // (n - 1)n / 2\n // k >= n\n // k = n: 1\n // k = n + 1: 1\n // ...\n // k = r: r - n\n // (r - n + 1)(r - n + 2) / 2\n\n if (r >= n)\n {\n writeln((n - 1)*n/2 + 1);\n }\n else\n {\n writeln(r * (r + 1) / 2);\n }\n }\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.stdio, std.string;\nvoid main () {\n\tforeach (i; 0..readln.strip.to!int) {\n\t\tint n, r;\n\t\treadf !(\" %s %s\") (n, r);\n\t\tint s = min (n, r + 1);\n\t\twriteln (s * (s - 1L) / 2 + (n <= r));\n\t}\n}\n"}], "negative_code": [], "src_uid": "eb3d8259ca598c3c455ddfdbe433cb78"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto mat = new char[][](n);\n\tforeach(i; 0 .. n)\n\t{\n\t\tmat[i] = cast(char[]) readString;\n\t}\n\tint color = 0;\n\tforeach(i; 0 .. n)\n\t\tforeach(j; 0 .. m)\n\t\t\tif (mat[i][j] != '.')\n\t\t\t\tcolor = ((i + j + (mat[i][j] == 'R')))%2;\n\tbool can = true;\n\tforeach(i; 0 .. n)\n\t\tforeach(j; 0 .. m)\n\t\t\tif (mat[i][j] != '.')\n\t\t\t{\n\t\t\t\tif ((mat[i][j] == 'R') != (i + j + color)%2)\n\t\t\t\t{\n\t\t\t\t\tcan = false;\n\t\t\t\t}\n\t\t\t}\n\tif (!can) return \"NO\".writeln; \n\t\"YES\".writeln;\n\tforeach(i; 0 .. n)\n\t{\n\t\tforeach(j; 0 .. m)\n\t\t{\n\t\t\tif ((i + j + color)%2 == 0) \"W\".write;\n\t\t\telse \"R\".write;\n\t\t}\n\t\twriteln;\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nbool check(string[][] a, int n, int m, bool r11)\n{\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. m) {\n string expected = ((i + j) % 2 == 0) == r11 ? \"R\" : \"W\";\n if (a[i][j] != expected && a[i][j] != \".\")\n return false;\n }\n }\n return true;\n}\n\nvoid fill(string[][] a, int n, int m, bool r11)\n{\n string c1, c2;\n if (r11) {\n c1 = \"R\";\n c2 = \"W\";\n } else {\n c1 = \"W\";\n c2 = \"R\";\n }\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. m) {\n a[i][j] = (i + j) % 2 == 0 ? c1 : c2;\n }\n }\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n, m;\n readf!\" %d %d \"(n, m);\n string[][] a;\n foreach (i ; 0 .. n) {\n a ~= readln.strip.split(\"\").array;\n }\n if (check(a, n, m, true)) {\n writeln(\"YES\");\n fill(a, n, m, true);\n foreach (i ; 0 .. n) { writeln(a[i].join(\"\")); }\n } else if (check(a, n, m, false)) {\n writeln(\"YES\");\n fill(a, n, m, false);\n foreach (i ; 0 .. n) { writeln(a[i].join(\"\")); }\n } else {\n writeln(\"NO\");\n }\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\nmultitest_loop:\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint rows, cols;\r\n\t\treadf !(\" %s %s\") (rows, cols);\r\n\t\treadln;\r\n\t\tchar [] [] board;\r\n\t\tforeach (row; 0..rows)\r\n\t\t{\r\n\t\t\tboard ~= readln.strip.dup;\r\n\t\t}\r\n\t\tforeach (k; 0..2)\r\n\t\t{\r\n\t\t\tauto answer = new char [] [] (rows, cols);\r\n\t\t\tforeach (row; 0..rows)\r\n\t\t\t{\r\n\t\t\t\tforeach (col; 0..cols)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[row][col] =\r\n\t\t\t\t\t \"RW\"[(row ^ col ^ k) & 1];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbool good = true;\r\n\t\t\tforeach (row; 0..rows)\r\n\t\t\t{\r\n\t\t\t\tforeach (col; 0..cols)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (answer[row][col] !=\r\n\t\t\t\t\t board[row][col] &&\r\n\t\t\t\t\t board[row][col] != '.')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tgood = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (good)\r\n\t\t\t{\r\n\t\t\t\twriteln (\"YES\");\r\n\t\t\t\twritefln !(\"%-(%s\\n%)\") (answer);\r\n\t\t\t\tcontinue multitest_loop;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (\"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\nmultitest_end:\r\n while(tests--) {\r\n int n, m;\r\n readf!\"%s %s\\n\"(n, m);\r\n char[][] grid;\r\n foreach(i; 0 .. n) {\r\n grid ~= readln.strip.dup;\r\n }\r\n foreach(k; 0 .. 2) {\r\n auto answer = new char[][](n, m);\r\n foreach(i; 0 .. n) {\r\n foreach(j; 0 .. m) {\r\n answer[i][j] = \"RW\"[(i + j + k) % 2];\r\n }\r\n }\r\n bool good = true;\r\n foreach(i; 0 .. n) {\r\n foreach(j; 0 .. m) {\r\n good &= (grid[i][j] == answer[i][j] || grid[i][j] == '.');\r\n }\r\n }\r\n if (good) {\r\n writefln!\"YES\\n%-(%s\\n%)\"(answer);\r\n continue multitest_end;\r\n }\r\n }\r\n writefln!\"NO\";\r\n }\r\n\r\n} // main"}], "negative_code": [{"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n while(tests--) {\r\n int n, m;\r\n readf!\"%s %s\\n\"(n, m);\r\n char[][] grid = new char[][n];\r\n foreach(ref str; grid) {\r\n str = readln.strip.dup;\r\n }\r\n int red = 0, white = 0;\r\n foreach(i; 0 .. n) {\r\n foreach(j; 0 .. m) {\r\n if (grid[i][j] == 'R') {\r\n red |= (1 << ((i + j) % 2));\r\n }\r\n else if (grid[i][j] == 'W') {\r\n white |= (1 << ((i + j) % 2));\r\n }\r\n }\r\n }\r\n if ((red & white) != 0) {\r\n \"NO\".writeln;\r\n }\r\n else {\r\n \"YES\".writeln;\r\n if (red == 0 && white == 0) {\r\n red = 1, white = 2;\r\n }\r\n else if (red == 0) {\r\n red = 3 - white;\r\n }\r\n else if (white == 0) {\r\n white = 3 - red;\r\n }\r\n foreach(i; 0 .. n) {\r\n foreach(j; 0 .. m) {\r\n if ((1 << ((i + j) % 2)) == red) {\r\n grid[i][j] = 'R';\r\n }\r\n else {\r\n grid[i][j] = 'W';\r\n }\r\n }\r\n }\r\n writefln!\"%-(%s\\n%)\"(grid);\r\n }\r\n }\r\n\r\n} // main"}], "src_uid": "12f35743f482b68e3156a45d6ac5bb14"} {"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid solve(char[] s)\n{\n int[] ans;\n int pos = -1;\n foreach (i; 0 .. s.length)\n {\n if (s[i] == '#')\n {\n ans ~= 1;\n pos = i;\n }\n }\n int cl = 0, cr = 0;\n foreach (i; 0 .. s.length)\n {\n if (s[i] == '(')\n {\n ++ cl;\n }\n else\n {\n ++ cr;\n }\n if (cr > cl)\n {\n writeln(-1);\n return;\n }\n }\n ans[$ - 1] += cl - cr;\n cl = cr = 0;\n int idx = 0;\n foreach (i; 0 .. s.length)\n {\n if (s[i] == '(')\n {\n ++ cl;\n }\n else if (s[i] == ')')\n {\n ++ cr;\n }\n else\n {\n cr += ans[idx];\n ++ idx;\n }\n if (cr > cl)\n {\n writeln(-1);\n return;\n }\n }\n foreach (i, val; ans)\n {\n writeln(val);\n }\n}\n\nint main(string[] args)\n{\n char[] s;\n while (stdin.readln(s))\n {\n solve(chomp(s));\n }\n return 0;\n}", "positive_code": [{"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid solve(char[] s)\n{\n int cl = 0, cr = 0, sl = 0, sr = 0, pos = -1, cnt = 0;\n foreach (i; 0 .. s.length)\n {\n if (s[i] == '(')\n {\n ++ sl;\n }\n else if (s[i] == ')')\n {\n ++ sr;\n }\n else\n {\n pos = i;\n ++ cnt;\n }\n }\n int add = 0;\n auto ans = new int[cnt];\n int idx = 0;\n foreach (i; 0 .. s.length)\n {\n if (s[i] == '(')\n {\n ++ cl;\n }\n else if (s[i] == ')')\n {\n ++ cr;\n }\n else\n {\n if (i == pos)\n {\n int need = sl - (sr + add);\n if (need <= 0)\n {\n writeln(-1);\n return;\n }\n ans[idx] = need;\n add += need;\n }\n else\n {\n ans[idx] = 1;\n ++ add;\n }\n ++ idx;\n }\n if (cr + add > cl)\n {\n writeln(-1);\n return;\n }\n }\n if (cr + add != cl)\n {\n writeln(-1);\n }\n else\n {\n foreach (i, val; ans)\n {\n writeln(ans[i]);\n }\n }\n}\n\nint main(string[] args)\n{\n char[] s;\n while (stdin.readln(s))\n {\n solve(chomp(s));\n }\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n auto s = readln.chomp;\n int n = cast(int)s.count!\"a == '#'\";\n\n int[] ans;\n\n int x;\n int open, close;\n foreach (i, c; s) {\n if (c == '(') open++;\n else if (c == ')') close++;\n else {\n assert(c == '#');\n if (x == n - 1) {\n int d = open - close;\n foreach (j; i + 1 .. s.length) {\n d += (s[j] == '(' ? 1 : -1);\n }\n if (d <= 0) {\n writeln(-1);\n return;\n } else {\n ans ~= d;\n close += d;\n }\n } else {\n ans ~= 1;\n close++;\n x++;\n }\n }\n if (open < close) {\n writeln(-1);\n return;\n }\n }\n writefln(\"%(%s\\n%)\", ans);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n auto s = readln.chomp;\n int n = cast(int)s.count!\"a == '#'\";\n\n int[] ans;\n\n int x;\n int open, close;\n foreach (i, c; s) {\n if (c == '(') open++;\n else if (c == ')') close++;\n else {\n assert(c == '#');\n if (x == n - 1) {\n int d = open - close;\n foreach (j; i + 1 .. s.length) {\n d += (s[j] == '(' ? 1 : -1);\n }\n if (d <= 0) {\n writeln(-1);\n return;\n } else {\n ans ~= d;\n }\n } else {\n ans ~= 1;\n close++;\n x++;\n }\n }\n }\n\n writefln(\"%(%s\\n%)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n auto s = readln.chomp;\n int n = cast(int)s.count!\"a == '#'\";\n\n int[] ans;\n\n int x;\n int open, close;\n foreach (i, c; s) {\n if (c == '(') open++;\n else if (c == ')') close++;\n else {\n assert(c == '#');\n if (x == n - 1) {\n int d = open - close;\n foreach (j; i + 1 .. s.length) {\n d += (s[j] == '(' ? 1 : -1);\n }\n if (d <= 0) {\n writeln(-1);\n return;\n } else {\n ans ~= d;\n }\n } else {\n ans ~= 1;\n close++;\n x++;\n }\n }\n }\n\n x = 0; open = 0; close = 0;\n foreach (i, c; s) {\n if (c == '(') open++;\n else if (c == ')') close++;\n else {\n assert(c == '#');\n close += ans[x];\n }\n if (open < close) {\n writeln(-1); return;\n }\n }\n\n writefln(\"%(%s\\n%)\", ans);\n}\n"}, {"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid solve(char[] s)\n{\n int[] ans;\n int pos = -1;\n foreach (i; 0 .. s.length)\n {\n if (s[i] == '#')\n {\n ans ~= 1;\n pos = i;\n }\n }\n int cl = 0, cr = 0;\n foreach (i; 0 .. s.length)\n {\n if (s[i] == '(')\n {\n ++ cl;\n }\n else\n {\n ++ cr;\n }\n if (cr > cl)\n {\n writeln(-1);\n return;\n }\n }\n ans[$ - 1] += cl - cr;\n foreach (i, val; ans)\n {\n writeln(val);\n }\n}\n\nint main(string[] args)\n{\n char[] s;\n while (stdin.readln(s))\n {\n solve(chomp(s));\n }\n return 0;\n}"}], "src_uid": "0a30830361b26838b192d7de1efcdd2f"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto b = ma(7, readInt!int);\n auto bs = redBlackTree!(true, int)(b);\n int[3] a;\n a[0] = b[0];\n a[1] = b[1];\n bs.removeKey(a[0]);\n bs.removeKey(a[1]);\n bs.removeKey(a[0] + a[1]);\n a[2] = bs.front;\n foreach(ai; a) write(ai, \" \");\n writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto b = readln.splitter.map!(to!int).array;\n writefln(\"%d %d %d\", b[0], b[1], b.back - b[0] - b[1]);\n }\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto arr = scanArray;\n auto summ = arr[6];\n long a = summ - arr[5];\n long b = summ - arr[4];\n long c = summ - a - b;\n writeln(a, \" \", b, \" \", c);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [], "src_uid": "e0ec0cd81d2ec632ef89d207d80fa8a3"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n int N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto A = readarray!int;\r\n\r\n int[] C = new int[N + 2];\r\n foreach (a; A) C[a]++;\r\n\r\n int[] S = new int[N + 3];\r\n for (int i = 0; i <= N+1; i++) {\r\n S[i + 1] = S[i] + C[i];\r\n }\r\n\r\n int cd = int.max;\r\n int[] range = [-1, -1];\r\n for (int x = 0; x <= N; x++) {\r\n int lb = x, ub = N + 1;\r\n bool check(int m) {\r\n return S[m] - S[x] >= K + (N - K + 1) / 2;\r\n }\r\n if (! check(ub)) continue;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (check(mid) ? ub : lb) = mid;\r\n }\r\n int y = ub - 1;\r\n if (y - x < cd) {\r\n cd = y - x;\r\n range = [x, y];\r\n }\r\n }\r\n\r\n int x = range[0], y = range[1];\r\n assert(x >= 0 && y >= 0 && x <= y);\r\n\r\n Array!int ins, outs;\r\n int[] ans;\r\n for (int i = 0; i < N; i++) {\r\n int a = A[i];\r\n if (x <= a && a <= y) {\r\n if (outs.empty) {\r\n ins ~= i;\r\n } else {\r\n outs.removeBack;\r\n }\r\n } else {\r\n if (ins.empty) {\r\n outs ~= i;\r\n } else {\r\n ins.removeBack;\r\n }\r\n }\r\n if (ins.length == 1) {\r\n ins.removeBack;\r\n ans ~= i;\r\n if (ans.length == K) break;\r\n }\r\n }\r\n writefln(\"%s %s\", x, y);\r\n //writeln(ans);\r\n\r\n if (K == 1) {\r\n writefln(\"%s %s\", 1, N);\r\n } else {\r\n for (int k = 0; k < K; k++) {\r\n int L, R;\r\n if (k == 0) {\r\n L = 0;\r\n R = ans[k];\r\n } else if (k == K - 1) {\r\n L = ans[k - 1] + 1;\r\n R = N - 1;\r\n } else {\r\n L = ans[k - 1] + 1;\r\n R = ans[k];\r\n }\r\n writefln(\"%s %s\", L+1, R+1);\r\n }\r\n }\r\n\r\n\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = a.dup;\r\n\t\tsort (b);\r\n\r\n\t\tint best = int.max;\r\n\t\tint bestX = -1;\r\n\t\tint bestY = -1;\r\n\t\tint num = 0;\r\n\t\twhile (num < n - num + k)\r\n\t\t{\r\n\t\t\tnum += 1;\r\n\t\t}\r\n\t\tforeach (val; num..n + 1)\r\n\t\t{\r\n\t\t\tauto x = b[val - num];\r\n\t\t\tauto y = b[val - 1];\r\n\t\t\tif (best > y - x)\r\n\t\t\t{\r\n\t\t\t\tbest = y - x;\r\n\t\t\t\tbestX = x;\r\n\t\t\t\tbestY = y;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint [] [] answer;\r\n\t\tint pos = 0;\r\n\t\twhile (answer.length.to !(int) < k - 1)\r\n\t\t{\r\n\t\t\tanswer ~= [pos + 1];\r\n\t\t\tint balance = 0;\r\n\t\t\twhile (balance <= 0)\r\n\t\t\t{\r\n\t\t\t\tbalance += (bestX <= a[pos] &&\r\n\t\t\t\t a[pos] <= bestY) ? +1 : -1;\r\n\t\t\t\tpos += 1;\r\n\t\t\t}\r\n\t\t\tanswer.back ~= pos;\r\n\t\t}\r\n\t\tanswer ~= [pos + 1, n];\r\n\r\n\t\twriteln (bestX, \" \", bestY);\r\n\t\tforeach (const ref line; answer)\r\n\t\t{\r\n\t\t\twritefln !(\"%(%s %)\") (line);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n int N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto A = readarray!int;\r\n\r\n int[] C = new int[N + 2];\r\n foreach (a; A) C[a]++;\r\n\r\n int[] S = new int[N + 3];\r\n for (int i = 0; i <= N+1; i++) {\r\n S[i + 1] = S[i] + C[i];\r\n }\r\n\r\n int cd = int.max;\r\n int[] range = [-1, -1];\r\n for (int x = 0; x <= N; x++) {\r\n int lb = x, ub = N + 1;\r\n bool check(int m) {\r\n return S[m] - S[x] >= K + (N - K + 1) / 2;\r\n }\r\n if (! check(ub)) continue;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (check(mid) ? ub : lb) = mid;\r\n }\r\n int y = ub - 1;\r\n if (y - x < cd) {\r\n cd = y - x;\r\n range = [x, y];\r\n }\r\n }\r\n\r\n int x = range[0], y = range[1];\r\n assert(x >= 0 && y >= 0 && x <= y);\r\n\r\n Array!int ins, outs;\r\n int[] ans;\r\n for (int i = 0; i < N; i++) {\r\n int a = A[i];\r\n if (x <= a && a <= y) {\r\n if (outs.empty) {\r\n ins ~= i;\r\n } else {\r\n outs.removeBack;\r\n }\r\n } else {\r\n if (ins.empty) {\r\n outs ~= i;\r\n } else {\r\n ins.removeBack;\r\n }\r\n }\r\n if (ins.length == 1) {\r\n ins.removeBack;\r\n ans ~= i;\r\n if (ans.length == K) break;\r\n }\r\n }\r\n writefln(\"%s %s\", x, y);\r\n //writeln(ans);\r\n\r\n for (int k = 0; k < K; k++) {\r\n int L, R;\r\n if (k == 0) {\r\n L = 0;\r\n R = ans[k];\r\n } else if (k == K - 1) {\r\n L = ans[k - 1] + 1;\r\n R = N - 1;\r\n } else {\r\n L = ans[k - 1] + 1;\r\n R = ans[k];\r\n }\r\n writefln(\"%s %s\", L+1, R+1);\r\n }\r\n\r\n\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "src_uid": "321423f103e6d9c567079d2dde71b5bb"} {"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n arr.sort();\n ll[] res = new ll[](n);\n foreach(i; 0..n/2){\n res[2*i + 1] = arr[i]; \n }\n foreach(i;(n/2)..n){\n res[2*(i - n/2)] = arr[i];\n }\n ll num = 0;\n foreach(i; 1..n-1){\n if(res[i] < res[i-1] && res[i] < res[i+1]){\n ++num;\n }\n }\n writeln(num);\n foreach(el; res){\n write(el, \" \");\n }\n writeln;\n}\n\nvoid main(){\n long t = 1;\n /* t = rd; */\n while(t--) solve();\n stdout.flush;\n}\n\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1419/problem/D1\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.container;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long n = readln.chomp.to!long;\n\n long[] a = readln.split.map!(to!long).array;\n a.sort;\n\n auto dlist = DList!long(a);\n\n long[] solution;\n\n for(int i = 0; i < n; i++) {\n if(i % 2 == 0) {\n solution ~= dlist.back;\n dlist.removeBack;\n } else {\n solution ~= dlist.front;\n dlist.removeFront;\n }\n }\n\n int ans = 0;\n for(int i = 1; i + 1 < n; i++) {\n if(solution[i] < solution[i - 1] &&\n solution[i] < solution[i + 1])\n ans += 1;\n }\n ans.writeln;\n foreach(item; solution)\n writef(\"%s \", item);\n \"\".writeln;\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n auto AS = readln.split.to!(int[]);\n sort!\"a > b\"(AS);\n\n auto BS = new int[](N);\n int i, j;\n while (j < N) {\n BS[j] = AS[i];\n ++i;\n j += 2;\n }\n foreach (k; 0..N) if (BS[k] == 0) BS[k] = AS[i++];\n if (N%2 == 0) {\n int k = 1;\n while (k < N-1) {\n if (BS[k-1] > BS[k] && BS[k+1] > BS[k]) {\n k += 2;\n continue;\n }\n BS[$-1] = BS[k];\n BS[k] = AS[i-1];\n goto end;\n }\n }\n end:\n\n int r;\n foreach (k; 1..N-1) if (BS[k-1] > BS[k] && BS[k+1] > BS[k]) ++r;\n writeln(r);\n writeln(BS.to!(string[]).join(\" \"));\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\ta.sort();\n\n\tlong[] ans;\n\tdebug writeln(a);\n\tforeach (i; 0..n)\n\t{\n\t\tif (i % 2 == 0)\n\t\t{\n\t\t\tans ~= a.back; a.popBack;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans ~= a.front; a.popFront;\n\t\t}\n\t\tdebug writeln(a);\n\t}\n\n\twriteln((ans.length-1) / 2);\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1419/problem/D1\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.container;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long n = readln.chomp.to!long;\n\n long[] a = readln.split.map!(to!long).array;\n a.sort;\n\n auto dlist = DList!long(a);\n\n long[] solution;\n\n for(int i = 0; i < n; i++) {\n if(i % 2 == 0) {\n solution ~= dlist.back;\n dlist.removeBack;\n } else {\n solution ~= dlist.front;\n dlist.removeFront;\n }\n }\n\n (n/2).writeln;\n foreach(item; solution) {\n writef(\"%s \", item);\n } \"\".writeln;\n}\n"}], "src_uid": "bcd9439fbf6aedf6882612d5f7d6220f"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\nimport std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.digest, std.encoding, std.exception, std.file, std.format, std.functional, std.getopt, std.json, std.math, std.mathspecial, std.meta, std.mmfile, std.numeric, std.parallelism, std.path, std.process, std.random, std.range, std.regex, std.signals, std.stdint, std.stdio, std.string, std.system, std.traits, std.typecons, std.uni, std.uri, std.utf, std.uuid, std.variant, std.zip, std.zlib;\n\nconst long MAXN = 200000;\nconst long m = 1000000007;\n\nvoid main()\n{\n long[] factorial;\n factorial ~= 1;\n factorial ~= 1;\n factorial ~= 1;\n for (int i = 3; i <= MAXN; i++)\n factorial ~= factorial[i - 1] * i % m;\n\n long t;\n readf(\" %d \", &t);\n while (t--) {\n int n;\n readf(\" %d \", &n);\n writeln(factorial[2 * n]);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\r\n\t\tans[ti] = 1;\r\n\t\tforeach (i; 2..n*2)\r\n\t\t\tans[ti].modm(i+1);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "19a2550af6a46308fd92c7a352f12a5f"} {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\n\n__gshared int[100_100] lastone;\n__gshared long[100_100] cumsum;\n__gshared int[100_100] arr;\n\nlong solvit(int idx) {\n if (lastone[idx] == -1) return 0;\n if (lastone[idx] == 0) return cumsum[0];\n return max(cumsum[lastone[idx] - 1], \n arr[lastone[idx]] + solvit(lastone[idx] - 1));\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n char[100_100] bin;\n long binrep = 0, aml = 0;\n int n;\n readf(\" %s\\n\", &n);\n foreach (i; 0 .. n) {\n readf(\" %s\", &arr[i]);\n }\n char[] pbin = bin;\n string dummy = readln;\n readln(pbin);\n cumsum[0] = arr[0];\n if (bin[0] == '1') lastone[0] = 0;\n else lastone[0] = -1;\n foreach (i; 1 .. n) {\n cumsum[i] = arr[i] + cumsum[i-1];\n if (bin[i] == '1') lastone[i] = i;\n else lastone[i] = lastone[i-1];\n }\n writeln(solvit(n - 1));\n\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int[] a, int[] s, int n)\n{\n auto acc = new int[n];\n acc[0] = a[0];\n foreach (i; 1 .. n)\n {\n acc[i] = acc[i - 1] + a[i];\n }\n auto ans = 0, sum = 0;\n foreach (i; 0 .. n)\n {\n if (s[i] == 1)\n {\n if (n - i - 2 >= 0)\n {\n auto val = sum + acc[n - i - 2];\n ans = max(ans, val);\n }\n sum += a[n - i - 1];\n }\n }\n ans = max(ans, sum);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n auto str = readln().strip();\n auto s = new int[n];\n foreach (i; 0 .. n)\n {\n s[i] = str[i] - '0';\n }\n s = s.reverse;\n solve(a, s, n);\n }\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\n\n__gshared int[100_100] lastone;\n__gshared long[100_100] cumsum;\n__gshared int[100_100] arr;\n\nlong solvit(int idx) {\n if (lastone[idx] == -1) return 0;\n if (lastone[idx] == 0) return cumsum[0];\n return max(cumsum[lastone[idx] - 1], \n arr[lastone[idx]] + solvit(lastone[idx] - 1));\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n;\n readf(\" %s\\n\", &n);\n foreach (i; 0 .. n) {\n readf(\" %s\", &arr[i]);\n }\n string dummy = readln;\n string bin = readln();\n cumsum[0] = arr[0];\n if (bin[0] == '1') lastone[0] = 0;\n else lastone[0] = -1;\n foreach (i; 1 .. n) {\n cumsum[i] = arr[i] + cumsum[i-1];\n if (bin[i] == '1') lastone[i] = i;\n else lastone[i] = lastone[i-1];\n }\n writeln(solvit(n - 1));\n\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[100_100] arr;\n char[100_100] bin;\n long binrep = 0, aml = 0;\n int n;\n readf(\" %s\\n\", &n);\n foreach (i; 0 .. n) {\n readf(\" %s\", &arr[i]);\n }\n char[] pbin = bin;\n string dummy = readln;\n readln(pbin);\n int lastone = -1;\n foreach (i; 0 .. n) {\n if (bin[i] == '1') lastone = i;\n }\n if (lastone == -1) {\n writeln(\"0\");\n return 0;\n }\n foreach (i; 0 .. lastone) {\n if (bin[i] == '1') binrep += arr[i];\n aml += arr[i];\n }\n binrep += arr[lastone];\n writeln(max(binrep, aml));\n \n return 0;\n}"}], "src_uid": "9366e1626b33b4f4e49cf35200c0448f"} {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.bigint;\nimport std.container;\nimport std.functional;\nimport std.math;\nimport std.complex;\nimport std.range;\nimport std.string;\n\nalias RedBlackTree!(int) IntSet;\n\nvoid main() {\n int n, m;\n int [] a, amt;\n while (readf(\" %d\", &n)) {\n a = new int[](n);\n amt = new int[](n);\n amt[0..n] = 0;\n IntSet S = new IntSet(-1, -2);\n foreach(i; 0..n) {\n readf(\" %d\", &a[i]);\n S.insert(i);\n }\n readf(\" %d\", &m);\n foreach(i ; 0..m) {\n int t;\n readf(\" %d\", &t);\n if (t == 1) {\n int p, x;\n readf(\" %d %d\", &p, &x);\n --p;\n int f = min(x, a[p] - amt[p]);\n x -= f;\n amt[p] += f;\n if (amt[p] == a[p]) S.removeKey(p);\n if (x > 0) {\n auto next = S.upperBound(p);\n while (!next.empty() && x > 0) {\n f = min(x, a[next.front()] - amt[next.front()]);\n x -= f;\n amt[next.front()] += f;\n if (amt[next.front()] == a[next.front()]) S.removeKey(next.front());\n next = S.upperBound(next.front());\n }\n }\n } else {\n int k;\n readf(\" %d\", &k);\n writeln(amt[--k]);\n }\n }\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t}\n\t\tauto next = n.iota.map !(a => a + 1).array;\n\t\ta ~= 0;\n\t\tnext ~= n;\n\t\tauto b = new int [n + 1];\n\t\tb[] = 0;\n\t\tint m;\n\t\treadf (\" %s\", &m);\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint t;\n\t\t\treadf (\" %s\", &t);\n\t\t\tif (t == 1)\n\t\t\t{\n\t\t\t\tint p, x;\n\t\t\t\treadf (\" %s %s\", &p, &x);\n\t\t\t\tp--;\n\t\t\t\tb[p] += x;\n\t\t\t\twhile (p < n && b[p] > a[p])\n\t\t\t\t{\n\t\t\t\t\tb[next[p]] += b[p] - a[p];\n\t\t\t\t\tint q = next[p];\n\t\t\t\t\tif (b[next[p]] >= a[next[p]])\n\t\t\t\t\t{\n\t\t\t\t\t\tnext[p] = next[next[p]];\n\t\t\t\t\t}\n\t\t\t\t\tb[p] = a[p];\n\t\t\t\t\tp = q;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (t == 2)\n\t\t\t{\n\t\t\t\tint k;\n\t\t\t\treadf (\" %s\", &k);\n\t\t\t\tk--;\n\t\t\t\twriteln (b[k]);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tenforce (false);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.bigint;\nimport std.container;\nimport std.functional;\nimport std.math;\nimport core.memory;\nimport std.complex;\nimport std.range;\nimport std.string;\n\nalias RedBlackTree!(int) IntSet;\n\nvoid main() {\n int n, m;\n int [] a, amt;\n while (readf(\" %d\", &n)) {\n a = new int[](n);\n amt = new int[](n);\n amt[0..n] = 0;\n IntSet S = new IntSet(-1, -2);\n foreach(i; 0..n) {\n readf(\" %d\", &a[i]);\n S.insert(i);\n }\n readf(\" %d\", &m);\n foreach(i ; 0..m) {\n int t;\n readf(\" %d\", &t);\n if (t == 1) {\n int p, x;\n readf(\" %d %d\", &p, &x);\n --p;\n int f = min(x, a[p] - amt[p]);\n x -= f;\n amt[p] += f;\n if (amt[p] == a[p]) S.removeKey(p);\n if (x > 0) {\n auto next = S.upperBound(p);\n foreach (j; next) {\n if (x == 0) break;\n f = min(x, a[j] - amt[j]);\n x -= f;\n amt[j] += f;\n if (amt[j] == a[j]) S.removeKey(j);\n }\n }\n } else {\n int k;\n readf(\" %d\", &k);\n --k;\n writeln(amt[k]);\n }\n }\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.bigint;\nimport std.container;\nimport std.functional;\nimport std.math;\nimport std.complex;\nimport std.range;\nimport std.string;\n\nalias RedBlackTree!(int) IntSet;\n\nvoid main() {\n int n, m;\n int [] a, amt;\n while (readf(\" %d\", &n)) {\n a = new int[](n);\n amt = new int[](n);\n IntSet S = new IntSet;\n S.insert(-1);\n S.insert(-2);\n foreach(i; 0..n) {\n readf(\" %d\", &a[i]);\n S.insert(i);\n }\n readf(\" %d\", &m);\n foreach(i ; 0..m) {\n int t;\n readf(\" %d\", &t);\n if (t == 1) {\n int p, x;\n readf(\" %d %d\", &p, &x);\n --p;\n auto next = S.upperBound(p);\n int f = min(x, a[p] - amt[p]);\n x -= f;\n amt[p] += f;\n if (amt[p] == a[p] && !S.empty()) S.removeKey(p);\n if (x > 0) {\n foreach (j; next) {\n if (x == 0) break;\n f = min(x, a[j] - amt[j]);\n x -= f;\n amt[j] += f;\n if (amt[j] == a[j]) S.removeKey(j);\n }\n }\n } else {\n int p;\n readf(\" %d\", &p);\n --p;\n writeln(amt[p]);\n }\n }\n }\n}"}], "src_uid": "37e2bb1c7caeeae7f8a7c837a2b390c9"} {"source_code": "module main;\n__gshared:\nimport core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\nalias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nenum mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt gcd(BigInt a, BigInt b)\n\t\t{\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (!(a[m] < g))\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (!(a[l] < g)) ? l : r;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (g < a[m])\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (g < a[l]) ? l : r;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn binf(a, g) != a.length;\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treturn s == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treadln;\n\t\treturn s == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tint n, p, q, r;\n\tloop: while (read(n, p, q, r))\n\t{\n\t\tauto a = arread!int;\n\t\tauto mapr = a.cumulativeFold!(max).array, masu = a.retro.cumulativeFold!(max).array;\n\t\tauto mipr = a.cumulativeFold!(min).array, misu = a.retro.cumulativeFold!(min).array;\n\t\treverse(misu);\n\t\treverse(masu);\n\t\tdebug\n\t\t{\n\t\t\twriteln(a);\n\t\t\twriteln(mipr);\n\t\t\twriteln(mapr);\n\t\t\twriteln(misu);\n\t\t\twriteln(masu);\n\t\t}\n\t\tlong ans = long.min;\n\t\tforeach (i; 0 .. n)\n\t\t{\n\t\t\tlong x = q * 1L * a[i];\n\t\t\tif (p < 0)\n\t\t\t\tx += mipr[i] * 1L * p;\n\t\t\telse\n\t\t\t\tx += mapr[i] * 1L * p;\n\t\t\tif (r < 0)\n\t\t\t\tx += misu[i] * 1L * r;\n\t\t\telse\n\t\t\t\tx += masu[i] * 1L * r;\n\t\t\tans = max(ans, x);\n\t\t}\n\t\twriteln(ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const P = readLong();\n const Q = readLong();\n const R = readLong();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n auto ls = new long[N + 1];\n auto rs = new long[N + 1];\n ls[0] = long.min;\n foreach (i; 0 .. N) {\n ls[i + 1] = max(ls[i], P * A[i]);\n }\n rs[N] = long.min;\n foreach_reverse (i; 0 .. N) {\n rs[i] = max(R * A[i], rs[i + 1]);\n }\n \n long ans = long.min;\n foreach (i; 0 .. N) {\n chmax(ans, ls[i + 1] + Q * A[i] + rs[i]);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "a8e56ad4de6f0eecbe5521226c0335ab"} {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n int n;\r\n scanf(\"%d\", &n);\r\n getchar();\r\n long res;\r\n auto s = readln.strip.to!(char[]);\r\n bool[char] solved;\r\n foreach(p; s) {\r\n auto tmp = (p in solved);\r\n if (tmp is null) {\r\n res += 2;\r\n solved[p] = true;\r\n }\r\n else {\r\n res += 1;\r\n }\r\n }\r\n writeln(res);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.utf;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = readln.strip;\r\n\t\tauto t = s.dup;\r\n\t\twriteln (s.length + t.byChar.sort.uniq.walkLength);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "66777b8719b1756bf4b6bf93feb2e439"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tint k = (n + 1) / 2;\r\n\t\tint [] ans;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n)\r\n\t\t\t{\r\n\t\t\t\tint d = j - i;\r\n\t\t\t\tans ~= (d < k ? 1 : n - d < k ? -1 : 0);\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (ans);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\t\r\n\t\tif (n % 2)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n*(n-1)/2)\r\n\t\t\t{\r\n\t\t\t\tif (i % 2 == 0)\r\n\t\t\t\t\tans[ti] ~= 1;\r\n\t\t\t\telse\r\n\t\t\t\t\tans[ti] ~= -1;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tauto draw = n-1;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tforeach (j; i+1..n)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto x = i + j;\r\n\t\t\t\t\tif (j > draw)\r\n\t\t\t\t\t\t++x;\r\n\t\t\t\t\tif (j == draw)\r\n\t\t\t\t\t\tans[ti] ~= 0;\r\n\t\t\t\t\telse if (x % 2)\r\n\t\t\t\t\t\tans[ti] ~= 1;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tans[ti] ~= -1;\r\n\r\n\t\t\t\t}\r\n\t\t\t\t--draw;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "a89c585ebd9608141399c813385c04c6"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = iota (n * m).map !(i => tuple (a[i], i)).array;\r\n\t\tsort (b);\r\n\t\tforeach (row; 0..n)\r\n\t\t{\r\n\t\t\tb[row * m..row * m + m]\r\n\t\t\t .schwartzSort !(c => tuple (c[0], -c[1]));\r\n\t\t}\r\n//\t\tb.schwartzSort !(c => tuple (c[0], c[1]));\r\n\t\tdebug {writeln (b);}\r\n\r\n\t\tlong res = 0;\r\n\t\tforeach (row; 0..n)\r\n\t\t{\r\n\t\t\tauto d = b[row * m..row * m + m];\r\n\t\t\tforeach (i; 0..m)\r\n\t\t\t{\r\n\t\t\t\tforeach (j; i + 1..m)\r\n\t\t\t\t{\r\n\t\t\t\t\tres += (d[i][1] < d[j][1]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto a = ma(n*m, readInt!int);\n\tint[2][][int] poss;\n\tint[int] cnt;\n\tforeach(i, ai; a) cnt[ai]++;\n\tauto sa = a.dup; sort(sa);\n\tauto ua = sa.uniq.array;\n\tforeach(i; 0 .. n)\n\t{\n\t\tforeach(j; 0 .. m)\n\t\t{\n\t\t\tassert(cnt[ua[0]] > 0);\n\t\t\trequire(poss, ua[0], null) ~= [i, -j];\n\t\t\tcnt[ua[0]]--;\n\t\t\tif (cnt[ua[0]] == 0) ua = ua[1 .. $];\n\t\t}\n\t}\n\tauto used = new FenwickTree[](n);\n\tforeach(ref usedi; used)\n\t\tusedi = FenwickTree(m);\n\tlong ans = 0;\n\n\tforeach(ai, ref pos; poss)\n\t\tsort(pos);\n\tdebug writeln(poss);\n\tforeach(i, ai; a)\n\t{\n\t\tauto pos = poss[ai][0];\n\t\tposs[ai] = poss[ai][1 .. $];\n\t\tauto pi = pos[0];\n\t\tauto pj = -pos[1];\n\t\tans += used[pi].sum(pj-1);\n\t\tused[pi].add(pj, 1);\n\t}\n\tans.writeln;\n}\nstruct FenwickTree {\n\tint[] bit;\n\tint n;\n\n\tthis(int n) {\n\t\tthis.n = n;\n\t\tbit = new int[](n);\n\t}\n\n\tint sum(int r) {\n\t\tint ret = 0;\n\t\tfor (; r >= 0; r = (r & (r + 1)) - 1)\n\t\t\tret += bit[r];\n\t\treturn ret;\n\t}\n\n\tint sum(int l, int r) {\n\t\treturn sum(r) - sum(l - 1);\n\t}\n\n\tvoid add(int idx, int delta) {\n\t\tfor (; idx < n; idx = idx | (idx + 1))\n\t\t\tbit[idx] += delta;\n\t}\n}\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "99c5e62d8e51e61cfd0c2531a231e7a8"} {"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n; long S;\n sc.read(n, S);\n\n long[3][] av, bv;\n long ma = 0;\n long ssm, sasm, sbsm;\n foreach (i; 0..n) {\n long s, a, b;\n sc.read(s, a, b);\n ssm += s;\n ma += s * max(a, b);\n if (a >= b) {\n sasm += s;\n av ~= [s, a, b];\n } else {\n sbsm += s;\n bv ~= [s, a, b];\n }\n }\n\n if (sasm % S + sbsm % S > S) {\n writeln(ma);\n return 0;\n }\n\n sasm %= S; sbsm %= S;\n av.sort!\"a[1]-a[2]<b[1]-b[2]\";\n bv.sort!\"a[2]-a[1]<b[2]-b[1]\";\n\n long[3][] mid;\n foreach (i; 0..sasm) {\n if (av[0][0] == 0) {\n av = av[1..$];\n }\n ma -= av[0][1];\n mid ~= [1L, av[0][1], av[0][2]];\n av[0][0]--;\n }\n\n foreach (i; 0..sbsm) {\n if (bv[0][0] == 0) {\n bv = bv[1..$];\n }\n ma -= bv[0][2];\n mid ~= [1L, bv[0][1], bv[0][2]];\n bv[0][0]--;\n }\n\n long m1, m2;\n foreach (p; mid) {\n m1 += p[1];\n m2 += p[2];\n }\n\n writeln(ma + max(m1, m2));\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const R = readLong();\n auto S = new long[N];\n auto A = new long[N];\n auto B = new long[N];\n foreach (i; 0 .. N) {\n S[i] = readLong();\n A[i] = readLong();\n B[i] = readLong();\n }\n \n long sumS, sumS0, sumS1;\n long ansBase;\n alias Entry = Tuple!(long, \"d\", long, \"s\");\n Entry[] es0, es1;\n foreach (i; 0 .. N) {\n sumS += S[i];\n if (A[i] >= B[i]) {\n sumS0 += S[i];\n ansBase += S[i] * A[i];\n es0 ~= Entry(A[i] - B[i], S[i]);\n } else {\n sumS1 += S[i];\n ansBase += S[i] * B[i];\n es1 ~= Entry(B[i] - A[i], S[i]);\n }\n }\n es0.sort;\n es1.sort;\n \n const k = (sumS + R - 1) / R;\n long ans;\n foreach (l; sumS0 / R - 2 .. sumS0 / R + 2 + 1) {\n if (0 <= l && l <= k) {\n long score = ansBase;\n {\n long lot = max(sumS0 - R * l, 0);\n foreach (ref e; es0) {\n const tmp = min(e.s, lot);\n score -= e.d * tmp;\n lot -= tmp;\n }\n }\n {\n long lot = max(sumS1 - R * (k - l), 0);\n foreach (ref e; es1) {\n const tmp = min(e.s, lot);\n score -= e.d * tmp;\n lot -= tmp;\n }\n }\n debug {\n writeln(l, \" \", k - l, \": \", score);\n }\n chmax(ans, score);\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "769859d86a3ceb2d89a444cd64c9a73b"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nvoid main()\n{\n int n, q;\n readf!\" %d %d \"(n, q);\n string s = readln.strip;\n ulong[] a;\n ulong sum = 0;\n a ~= 0;\n foreach (ch ; s) {\n sum += ch - 'a' + 1;\n a ~= sum;\n }\n while (q--) {\n int l, r;\n readf!\" %d %d \"(l, r);\n writeln(a[r] - a[l - 1]);\n }\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1539/problem/B\n//\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n, q;\n readf(\"%s %s\\n\", &n, &q);\n string s = readln.strip;\n\n int[][] index = new int[][](26, n + 1);\n foreach(ch; 0 .. 26) {\n int count = 0;\n foreach(i; 0 .. n) {\n if(s[i] == 'a' + ch) {\n count += 1;\n }\n index[ch][i + 1] = count;\n }\n }\n\n for(int i = 0; i < q; ++i) {\n int l, r;\n readf(\"%s %s\\n\", &l, &r);\n int ans = 0;\n foreach(ch; 0 .. 26) {\n int letter = index[ch][r] - index[ch][l - 1];\n ans += letter * (ch + 1);\n }\n ans.writeln;\n }\n}\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T); }\n\nvoid main() {\n int n, q;\n read(n, q);\n \n string s = readln;\n \n auto table = new int[][](26, n + 1);\n \n foreach (c; 0 .. 26) {\n int t = 0;\n foreach (i; 0 .. n) {\n if (s[i] == 'a' + c) t++;\n table[c][i + 1] = t;\n }\n }\n \n foreach (i; 0 .. q) {\n int l, r;\n read(l, r);\n \n long total = 0;\n \n foreach (c; 0 .. 26) {\n auto rep = table[c][r] - table[c][l - 1];\n total += rep * (c + 1);\n }\n \n writeln(total);\n }\n}\n\n"}], "negative_code": [], "src_uid": "461378e9179c9de454674ea9dc49c56c"} {"source_code": "import std.typecons;\nimport std.stdio;\nT gcd(T)(T a, T b) {\n\tif (a % b == 0) return b;\n\treturn gcd(b, a % b);\n}\nstruct Rat(T) {\n\timport std.math : abs;\n\tT n, d;\n\tthis(T n_, T d_) {\n\t\tif (d_ == 0) {\n\t\t\tn = 1;\n\t\t\td = 0;\n\t\t} else if (n_ == 0) {\n\t\t\td = 1;\n\t\t\tn = 0;\n\t\t} else {\n\t\t\tauto c = gcd(abs(n_), abs(d_));\n\t\t\tbool neg = (n_ < 0) ^ (d_ < 0);\n\t\t\tn = abs(n_ / c);\n\t\t\td = abs(d_ / c);\n\t\t\tif (neg) {\n\t\t\t\tn = -n;\n\t\t\t}\n\t\t}\n\t}\n\tRat!T opBinary(string op)(T o) if (op == \"*\"){\n\t\tif (d == 0) {\n\t\t\treturn this;\n\t\t}\n\t\treturn Rat!T(n * o, d);\n\t}\n\tRat!T opBinary(string op)(T o) if (op == \"/\"){\n\t\tif (d == 0) {\n\t\t\treturn this;\n\t\t}\n\t\treturn Rat!T(n, d * o);\n\t}\n\tRat!T opBinary(string op)(T o) if (op == \"+\"){\n\t\tif (d == 0) {\n\t\t\treturn this;\n\t\t}\n\t\treturn Rat!T(n + d * o, d);\n\t}\n\tbool opEqual(Rat!T o) {\n\t\treturn n == o.n && d == o.d;\n\t}\n}\nint[2][50] points;\nvoid main() {\n\tbool[Tuple!(Rat!long, Rat!long)] lines;\n\tint n;\n\tscanf(\"%d \", &n);\n\n\tforeach(i; 0..n) {\n\t\tscanf(\"%d %d \", &points[i][0], &points[i][1]);\n\t}\n\n\tdebug writeln(points);\n\n\tforeach(i; 0..n) {\n\t\tforeach(j; 0..i) {\n\t\t\tauto t = Rat!long(points[i][1]-points[j][1], points[i][0]-points[j][0]);\n\t\t\tauto d = t.d ? (t * -points[i][0]) + points[i][1] : Rat!long(points[i][0], 1);\n\t\t\tdebug writeln(t, d, t == d);\n\t\t\tlines[tuple(t, d)] = true;\n\t\t}\n\t}\n\n\tdebug writeln(lines);\n\tint[Rat!long] tgroup;\n\tforeach(t, d; lines.byKey) {\n\t\ttgroup[t]++;\n\t}\n\tlong ans = lines.length * (lines.length - 1) / 2;\n\tforeach(t; tgroup.byKey) {\n\t\tans -= tgroup[t] * (tgroup[t]-1) / 2;\n\t}\n\twriteln(ans);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tlong[] xs, ys;\n\tforeach(i; 0 .. n) xs ~= read.to!int, ys ~= read.to!int;\n\t\n\tprint!1(\"xs:\", xs);\n\tprint!1(\"ys:\", ys);\n\t\n\tlong[long] kcnt;\n\tbool[long] mset;\n\tforeach(i; 0 .. n) foreach(j; 0 .. i){\n\t\tlong dx = xs[i] - xs[j];\n\t\tlong dy = ys[i] - ys[j];\n\t\tlong c = dx * ys[i] - dy * xs[i];\n\t\tprint!1(\"dx:\", dx, \" dy:\", dy, \" c:\", c);\n\t\t\n\t\tif(dx == 0){\n\t\t\tif(dy < 0) dy = -dy, c = -c;\n\t\t\tlong g = gcd(dy, c);\n\t\t\tdy /= g, c /= g;\n\t\t}\n\t\telse if(dy == 0){\n\t\t\tif(dx < 0) dx = -dx, c = -c;\n\t\t\tlong g = gcd(dx, c);\n\t\t\tdx /= g, c /= g;\n\t\t}\n\t\telse if(c == 0){\n\t\t\tif(dx < 0) dx = -dx, dy = -dy;\n\t\t\tlong g = gcd(dx, dy);\n\t\t\tdx /= g, dy /= g;\n\t\t}\n\t\telse{\n\t\t\tif(dx < 0) dx = -dx, dy = -dy, c = -c;\n\t\t\tlong g = gcd(gcd(dx, dy), c);\n\t\t\tdx /= g, dy /= g, c /= g;\n\t\t}\n\t\t\n\t\tprint!1(\" -> dx:\", dx, \" dy:\", dy, \" c:\", c);\n\t\t\n\t\tlong k = 100000 * dy + dx;\n\t\tlong m = k * 10000000 + c;\n\t\tif(m !in mset){\n\t\t\tif(k !in kcnt) kcnt[k] = 0;\n\t\t\tmset[m] = 1;\n\t\t\tkcnt[k] += 1;\n\t\t}\n\t}\n\tprint!1(\"kcnt:\", kcnt);\n\tprint!1(\"mset:\", mset);\n\t\n\tlong[] ks = kcnt.keys;\n\tlong[] ms = mset.keys;\n\tlong ans = ms.length * (ms.length - 1) / 2;\n\tforeach(k; ks) ans -= kcnt[k] * (kcnt[k] - 1) / 2;\n\tans.writeln;\n\t\t\n\t\n}\nlong gcd(long a, long b){\n\tif(b == 0) return a;\n\tif(b < 0) return gcd(a, -b);\n\tif(a % b == 0) return b;\n\tif(a < b) return gcd(b, a);\n\telse return gcd(b, a % b);\n}\n\n\n/*\n\n\"How many different direction vectors can we have?\"\n\n(x1, y1), (x2, y2) -> (x1 - x2, y1 - y2).\nhere x1 - x2 and y1 - y2 are relatively prime and x1 - x2 > 0,\nor (1, 0), or (0, 1).\n\nO(N^2) = 1000 x 1000.\n\n(y1 - y2)(x - x1) - (x1 - x2)(y - y1) = 0\ndy x - dx y + dx y1 - dy x1 = 0\n\n*/\n"}], "negative_code": [{"source_code": "void main() {\nimport std.stdio;\nwriteln(long.sizeof);\n}"}], "src_uid": "8c2e0cd780cf9390e933e28e57643cba"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!string;\r\n\r\n\t\tforeach (c; n)\r\n\t\t{\r\n\t\t\tans[ti].chmax(c-'0');\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tauto n = readInt!long;\n\tint md = int.min;\n\twhile (n)\n\t{\n\t\tmd = cast(int)max(md, n % 10);\n\t\tn /= 10;\n\t}\n\tmd.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\r\n std.container, std.typecons, std.conv, std.random, std.bigint;\r\n\r\nvoid read(S...)(ref S args) {\r\n auto input = readln.split;\r\n assert(input.length == args.length);\r\n foreach (i, ref arg; args) {\r\n arg = input[i].to!(S[i]);\r\n }\r\n}\r\n\r\nauto list(T)() { return readln.split.map!(e => e.to!T); }\r\n\r\nvoid main() {\r\n int t;\r\n read(t);\r\n \r\n while (t--) {\r\n string s;\r\n read(s);\r\n \r\n char c = s[0];\r\n foreach (e; s) {\r\n c = max(c, e);\r\n }\r\n \r\n writeln(c);\r\n }\r\n}\r\n\r\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n while(tests--) {\r\n auto s = readln.strip;\r\n writeln(s.maxElement);\r\n }\r\n\r\n} // main\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n writeln(n.text.split(\"\").map!(to!int).maxElement);\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readToken();\n int ans;\n foreach (c; N) {\n chmax(ans, c - '0');\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip;\r\n\t\twriteln (s.maxElement);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "1a6881aeb197b8ed429f46850eb27b9c"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int[] a, int k)\n{\n auto n = cast(int)a.length;\n int[int] cnt;\n auto longest = 0;\n auto left = -1, right = -1;\n auto i = 0, j = 0;\n auto count = 0;\n while (j < n)\n {\n if (!(a[j] in cnt) || cnt[a[j]] == 0)\n {\n ++ count;\n }\n if (!(a[j] in cnt))\n {\n cnt[a[j]] = 0;\n }\n ++ cnt[a[j]];\n if (count <= k)\n {\n if (j - i + 1 > longest)\n {\n left = i + 1;\n right = j + 1;\n longest = j - i + 1;\n }\n }\n else\n {\n while (i <= j && count > k)\n {\n -- cnt[a[i]];\n if (cnt[a[i]] == 0)\n {\n -- count;\n }\n ++ i;\n }\n }\n ++ j;\n }\n writeln(left, \" \", right);\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a, k);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int[] a, int k)\n{\n auto n = cast(int)a.length;\n auto m = reduce!(max)(a);\n auto cnt = new int[m + 1];\n auto longest = 0;\n auto left = -1, right = -1;\n auto i = 0, j = 0;\n auto count = 0;\n while (j < n)\n {\n if (cnt[a[j]] == 0)\n {\n ++ count;\n }\n ++ cnt[a[j]];\n if (count <= k)\n {\n if (j - i + 1 > longest)\n {\n left = i + 1;\n right = j + 1;\n longest = j - i + 1;\n }\n }\n else\n {\n while (i <= j && count > k)\n {\n -- cnt[a[i]];\n if (cnt[a[i]] == 0)\n {\n -- count;\n }\n ++ i;\n }\n }\n ++ j;\n }\n writeln(left, \" \", right);\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a, k);\n }\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int[] a, int k)\n{\n auto n = cast(int)a.length;\n int[int] cnt;\n auto longest = 0;\n auto left = -1, right = -1;\n auto i = 0, j = 0;\n auto count = 0;\n while (j < n)\n {\n if (!(a[j] in cnt) || cnt[a[j]] == 0)\n {\n ++ count;\n }\n if (!a[j] in cnt)\n {\n cnt[a[j]] = 0;\n }\n ++ cnt[a[j]];\n if (count <= k)\n {\n if (j - i + 1 > longest)\n {\n left = i + 1;\n right = j + 1;\n longest = j - i + 1;\n }\n }\n else\n {\n while (i <= j && count > k)\n {\n -- cnt[a[i]];\n if (cnt[a[i]] == 0)\n {\n -- count;\n }\n ++ i;\n }\n }\n ++ j;\n }\n writeln(left, \" \", right);\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a, k);\n }\n return 0;\n}"}], "src_uid": "e0ea798c8ce0d8a4340e0fa3399bcc3b"} {"source_code": "import std;\n\nalias MinMax = Tuple!(long, \"min\", long, \"max\");\n\nlong\nreadLong () {\n long a;\n readf!\" %s\"(a);\n return a;\n}\n\nMinMax\nminMax () {\n immutable nb_to_read = readLong();\n long min = long.max, max = long.min;\n foreach (i; 0 .. nb_to_read) {\n immutable x = readLong();\n\n if (x < min)\n min = x;\n if (x > max)\n max = x;\n }\n return MinMax(min, max);\n}\n\nlong\nbase_length (in MinMax seg) {\n return seg.max - seg.min;\n}\n\nvoid main () {\n immutable t = readLong();\n\n foreach (test_index; 0 .. t) {\n immutable w = readLong(), h = readLong();\n\n long area = -1;\n area = max(area, base_length(minMax()) * h);\n area = max(area, base_length(minMax()) * h);\n area = max(area, base_length(minMax()) * w);\n area = max(area, base_length(minMax()) * w);\n\n writeln(area);\n }\n}\n\n// \"\"\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto w = readInt!long;\n auto h = readInt!long;\n auto x1n = readInt!int;\n auto x1 = ma(x1n, readInt!long);\n auto x2n = readInt!int;\n auto x2 = ma(x2n, readInt!long);\n auto y1n = readInt!int;\n auto y1 = ma(y1n, readInt!long);\n auto y2n = readInt!int;\n auto y2 = ma(y2n, readInt!long);\n max((x1.back - x1.front) * h,\n (x2.back - x2.front) * h,\n (y1.back - y1.front) * w,\n (y2.back - y2.front) * w).writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long w, h;\n readf!\" %d %d \"(w, h);\n auto h1 = readln.splitter.map!(to!long).array[1 .. $];\n auto h2 = readln.splitter.map!(to!long).array[1 .. $];\n auto v1 = readln.splitter.map!(to!long).array[1 .. $];\n auto v2 = readln.splitter.map!(to!long).array[1 .. $];\n writeln(max((h1.maxElement - h1.minElement) * h,\n (h2.maxElement - h2.minElement) * h,\n (v1.maxElement - v1.minElement) * w,\n (v2.maxElement - v2.minElement) * w));\n }\n}\n"}], "negative_code": [{"source_code": "import std;\n\nalias MinMax = Tuple!(int, \"min\", int, \"max\");\n\nint\nreadInt () {\n int a;\n readf!\" %s\"(a);\n return a;\n}\n\nMinMax\nminMax () {\n immutable nb_to_read = readInt();\n int min = int.max, max = int.min;\n foreach (i; 0 .. nb_to_read) {\n immutable x = readInt();\n\n if (x < min)\n min = x;\n if (x > max)\n max = x;\n }\n return MinMax(min, max);\n}\n\nint\nbase_length (in MinMax seg) {\n return seg.max - seg.min;\n}\n\nvoid main () {\n immutable t = readInt();\n\n foreach (test_index; 0 .. t) {\n immutable w = readInt(), h = readInt();\n\n int area = -1;\n area = max(area, base_length(minMax()) * h);\n area = max(area, base_length(minMax()) * h);\n area = max(area, base_length(minMax()) * w);\n area = max(area, base_length(minMax()) * w);\n\n writeln(area);\n }\n}\n\n// \"\"\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto w = readInt!long;\n auto h = readInt!long;\n auto x1n = readInt!int;\n auto x1 = ma(x1n, readInt!long);\n auto x2n = readInt!int;\n auto x2 = ma(x2n, readInt!long);\n auto y1n = readInt!int;\n auto y1 = ma(y1n, readInt!long);\n auto y2n = readInt!int;\n auto y2 = ma(y2n, readInt!long);\n max((x1.back - x1.front) * h,\n (x2.back - x2.front) * h,\n (y1.back - x1.front) * w,\n (y2.back - y2.front) * w).writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "2c67ee95eba7ffbbed99cb488abb5f3d"} {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main(){\n long n, m;\n readVars(n, m);\n auto a = readln.split.to!(int[]).map!(a => a - 1);\n\n //stderr.writeln(a);\n\n long ans;\n int pos;\n\n foreach(ai ; a){\n ans += (ai - pos + n) % n;\n pos = ai;\n }\n\n writeln(ans);\n}\n\n\nvoid readVars(T...)(auto ref T args){\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.algorithm, std.math;\n\nstring[] tokens;\nint tokenId = 0;\nstring readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\nconst long MOD = 100007;\n\nvoid main () {\n\tlong n = readInt(), m = readInt();\n\tlong[100007] arr = 0;\n\tfor(uint i = 0; i < m; i++) {\n\t\tarr[i] = readLong();\n\t}\n\tlong cost = 0;\n\tfor(int i = 0; i < m - 1; i++) {\n\t\tif(arr[i] <= arr[i + 1]) cost += arr[i + 1] - arr[i];\n\t\telse cost += n - arr[i] + arr[i + 1];\n\t}\n\twriteln(cost + arr[0] - 1);\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tint[] tasks; tasks.length = m;\n\tforeach (int i; 0..m)\n\t{\n\t\tscanf(\"%d\", &tasks[i]);\n\t\ttasks[i]--;\n\t}\n\t\n\tint cp = 0;\n\tlong steps = 0;\n\tforeach (int i; 0..m)\n\t{\n\t\tint ts = tasks[i] - cp;\n\t\tts = ts < 0 ? n + ts : ts;\n\t\tsteps += ts;\n\t\tcp = tasks[i];\n\t}\n\tprintf(\"%lld\", steps);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.regex: split, regex;\nimport std.string: strip;\nimport std.conv: to;\nimport std.algorithm.iteration: map;\n\n\nvoid main()\n{\n auto nm = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto as = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto n = nm[0], m = nm[1];\n int b;\n long time = 0;\n foreach(a; as )\n {\n if (a<b) time+=n;\n b=a;\n }\n writeln(time+as[$-1]-1);\n}"}], "negative_code": [{"source_code": "import std.stdio: writeln, stdin;\nimport std.regex: split, regex;\nimport std.string: strip;\nimport std.conv: to;\nimport std.algorithm.iteration: map;\n\n\nvoid main()\n{\n auto nm = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto as = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto n = nm[0], m = nm[1];\n int b, time = 0;\n foreach(a; as )\n {\n if (a<b) time+=n;\n b=a;\n\n \n }\n writeln(time+as[$-1]-1);\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tint[] tasks; tasks.length = m;\n\tforeach (int i; 0..m)\n\t{\n\t\tscanf(\"%d\", &tasks[i]);\n\t}\n\tint s = 0;\n\tint ts = 0;\n\tint t = 0;\n\twhile (t < m)\n\t{\n\t\twhile (t < m && tasks[t] == s+1)\n\t\t{\n\t\t\ttasks[t] = 0;\n\t\t\tt++;\n\t\t}\n\t\tif (t >= m)\n\t\t\tcontinue;\n\n\t\tif (tasks[t] - 1 >= s)\n\t\t{\n\t\t\tts += (tasks[t] - 1 - s);\n\t\t\ts = tasks[t] - 1;\n\t\t} else {\n\t\t\tts += n - (s - tasks[t] + 1);\n\t\t\ts = tasks[t] - 1;\n\t\t}\n\t}\n\tprintf(\"%d\", ts);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tint[] tasks; tasks.length = m;\n\tforeach (int i; 0..m)\n\t{\n\t\tscanf(\"%d\", &tasks[i]);\n\t}\n\tint s = 0;\n\tlong ts = 0;\n\tint t = 0;\n\twhile (t < m)\n\t{\n\t\twhile (t < m && tasks[t] == s+1)\n\t\t{\n\t\t\ttasks[t] = 0;\n\t\t\tt++;\n\t\t}\n\t\tif (t >= m)\n\t\t\tcontinue;\n\n\t\tif (tasks[t] - 1 >= s)\n\t\t{\n\t\t\tts += (tasks[t] - 1 - s);\n\t\t\ts = tasks[t] - 1;\n\t\t} else {\n\t\t\tts += n - (s - tasks[t] + 1);\n\t\t\ts = tasks[t] - 1;\n\t\t}\n\t}\n\tprintf(\"%d\", ts);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tint[] tasks; tasks.length = m;\n\tforeach (int i; 0..m)\n\t{\n\t\tscanf(\"%d\", &tasks[i]);\n\t}\n\tint s = 0;\n\tint ts = 0;\n\tint t = 0;\n\twhile (t < m)\n\t{\n\t\twhile (t < m && tasks[t] == s+1)\n\t\t{\n\t\t\ttasks[t] = 0;\n\t\t\tt++;\n\t\t}\n\t\tif (t >= m)\n\t\t\tcontinue;\n\n\t\tif (tasks[t] - 1 >= s)\n\t\t{\n\t\t\tts += (tasks[t] - 1 - s);\n\t\t\ts = tasks[t] - 1;\n\t\t} else {\n\t\t\tts += (n - s) + (s - tasks[t] + 1);\n\t\t\ts = tasks[t] - 1;\n\t\t}\n\t}\n\tprintf(\"%d\", ts);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tint[] tasks; tasks.length = m;\n\tforeach (int i; 0..m)\n\t{\n\t\tscanf(\"%d\", &tasks[i]);\n\t}\n\tint s = 0;\n\tlong ts = 0;\n\tint t = 0;\n\twhile (t < m)\n\t{\n\t\twhile (t < m && tasks[t] == s+1)\n\t\t{\n\t\t\ttasks[t] = 0;\n\t\t\tt++;\n\t\t}\n\t\tif (t >= m)\n\t\t\tcontinue;\n\n\t\tif (tasks[t] - 1 >= s)\n\t\t{\n\t\t\tts += (tasks[t] - 1 - s);\n\t\t\ts = tasks[t] - 1;\n\t\t} else {\n\t\t\tts += n - s + tasks[t] - 1;\n\t\t\ts = tasks[t] - 1;\n\t\t}\n\t}\n\tprintf(\"%d\", ts);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tint[] tasks; tasks.length = m;\n\tforeach (int i; 0..m)\n\t{\n\t\tscanf(\"%d\", &tasks[i]);\n\t\ttasks[i]--;\n\t}\n\t\n\tint cp = 0;\n\tlong steps = 0;\n\tforeach (int i; 0..m)\n\t{\n\t\tint ts = tasks[i] - cp;\n\t\tts = ts < 0 ? n + ts : ts;\n\t\tsteps += ts;\n\t\tcp = tasks[i];\n\t}\n\tprintf(\"%d\", steps);\n\treturn 0;\n}\n"}], "src_uid": "2c9c96dc5b6f8d1f0ddeea8e07640d3e"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twhile (!a.empty && !a.back)\r\n\t\t{\r\n\t\t\ta.popBack ();\r\n\t\t}\r\n\t\tlong cur = 0;\r\n\t\tint good = 0;\r\n\t\tint bad = 0;\r\n\t\tforeach (ref x; a)\r\n\t\t{\r\n\t\t\tcur += x;\r\n\t\t\tgood += (cur >= 0);\r\n\t\t\tbad += (cur == 0);\r\n\t\t}\r\n\t\tauto res = (good == a.length && bad <= 1 && cur == 0);\r\n\t\twriteln (res ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nlong[] A;\n\nbool solve() {\n long b;\n foreach (i; 0 .. N) {\n const c = A[i] + b;\n if (c < 0) {\n return false;\n } else if (c == 0) {\n foreach (j; i + 1 .. N) {\n if (A[j] != 0) {\n return false;\n }\n }\n return true;\n } else {\n b = c;\n }\n }\n return (b == 0);\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n N = readInt;\n A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n \n const ans = solve;\n writeln(ans ? \"Yes\" : \"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "9f0ffcbd0ce62a365a1ecbb4a2c1de3e"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto H = readarray!int;\r\n\r\n bool C(int x) {\r\n auto G = H.dup;\r\n for (int i = N - 1; i >= 2; i--) {\r\n if (G[i] < x) return false;\r\n int d = min(H[i] / 3, (G[i] - x) / 3);\r\n G[i - 1] += d;\r\n G[i - 2] += 2*d;\r\n }\r\n if (G[0] < x || G[1] < x) return false;\r\n return true;\r\n }\r\n int lb = 0, ub = 1_000_000_001;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? lb : ub) = mid;\r\n }\r\n writeln(lb);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto h = RDA;\r\n\r\n\t\tbool f(long x)\r\n\t\t{\r\n\t\t\tauto hh = h.dup;\r\n\t\t\tforeach_reverse (i; 2..n)\r\n\t\t\t{\r\n\t\t\t\tif (hh[i] < x) return false;\r\n\t\t\t\tauto rem = hh[i] - x;\r\n\t\t\t\tauto d = min(rem / 3, h[i] / 3);\r\n\t\t\t\thh[i-1] += d;\r\n\t\t\t\thh[i-2] += d*2;\r\n\t\t\t}\r\n\t\t\treturn (hh[0] >= x) && (hh[1] >= x);\r\n\t\t}\r\n\t\tans[ti] = binarySearch!(f)(0, 10L^^10);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "// \u63d0\u51fa\u89e3\r\nvoid solve(){\r\n\tforeach(_; 0 .. scan!int){\r\n\t\tint n = scan!int;\r\n\t\tlong[] hs = scan!long(n);\r\n\r\n\t\tbool isOK(long k){\r\n\t\t\tlog(\"k:\", k);\r\n\t\t\tlong[] us = hs.dup;\r\n\t\t\tforeach_reverse(i; 2 .. n){\r\n\t\t\t\tif(us[i] <= k) continue;\r\n\t\t\t\tlong d = min(hs[i], us[i] - k) / 3;\r\n\t\t\t\tus[i - 2] += d * 2, us[i - 1] += d, us[i] -= d * 3;\r\n\t\t\t\tlog(\"i:\", i, \"d:\", d, \"us:\", us);\r\n\t\t\t}\r\n\t\t\tlog(\"us:\", us);\r\n\t\t\tforeach(u; us) if(u < k) return 0;\r\n\t\t\tlog(\"k:\", k, \"-> OK\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tlong high = hs.reduce!max + 1;\r\n\t\tlong ans = mid(0, high, &isOK) - 1;\r\n\r\n\t\tans.print;\r\n\r\n\t}\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u611a\u76f4\u89e3\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30f3\u30d7\u30ec\r\nimport std;\r\nbool DEBUG = 0;\r\nvoid main(string[] args){\r\n\tif(args.canFind(\"-debug\")) DEBUG = 1;\r\n\tif(args.canFind(\"-gen\")) gen; else if(args.canFind(\"-jury\")) jury; else solve;\r\n}\r\nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\r\nvoid print(){ writeln(\"\"); }\r\nvoid print(T)(T t){ writeln(t); }\r\nvoid print(T, A ...)(T t, A a){ stdout.write(t, \" \"), print(a); }\r\nstring unsplit(T)(T xs, string d = \" \"){ return xs.array.to!(string[]).join(d); }\r\nstring scan(){\r\n\tstatic string[] ss; while(!ss.length) ss = readln.chomp.split;\r\n\tstring res = ss[0]; ss.popFront; return res;\r\n}\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\r\nT mini(T)(ref T x, T y){ if(x > y) x = y; return x; }\r\nT maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }\r\nT mid(T)(T l, T r, bool delegate(T) f){\r\n\tT m = (l + r) / 2; (f(m)? l: r) = m; return f(l)? f(r - 1)? r: mid(l, r, f): l;\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u57fa\u672c\uff09\r\n\r\nclass UnionFind{\r\n\tthis(int n){ foreach(i; 0 .. n) R ~= i, K ~= [i]; } int[] R; int[][] K;\r\n\tvoid unite(int a, int b){\r\n\t\tint ra = R[a], rb = R[b]; if(ra == rb) return;\r\n\t\tif(K[ra].length < K[rb].length) unite(b, a);\r\n\t\telse foreach(k; K[rb]) R[k] = ra, K[ra] ~= k;\r\n\t}\r\n\tint find(int a){ return R[a]; }\r\n\tint getSize(int a){ return K[R[a]].length.to!int; }\r\n}\r\nclass Queue(T){\r\n\tprivate T[] xs; private uint i, j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j - i; }\r\n\tbool isEmpty(){ return j == i; } \r\n\tvoid enq(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT deq(){ assert(i < j); return xs[i ++]; }\r\n\tT peek(){ assert(i < j); return xs[i]; }\r\n\tvoid flush(){ i = j; }\r\n\talias empty = isEmpty, front = peek, popFront = deq, pop = deq, push = enq, top = peek;\r\n\tQueue opOpAssign(string op)(T x) if(op == \"~\"){ enq(x); return this; }\r\n\tT opIndex(uint li){ assert(i + li < j); return xs[i + li]; }\r\n\tstatic Queue!T opCall(T[] xs){ return new Queue!T(xs); }\r\n\tT[] array(){ return xs[i .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\nclass Stack(T){\r\n\tprivate T[] xs; private uint j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j; }\r\n\tbool isEmpty(){ return j == 0; }\r\n\tvoid push(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT pop(){ assert(j > 0); return xs[-- j]; }\r\n\tT peek(){ assert(j > 0); return xs[j - 1]; }\r\n\tvoid clear(){ j = 0; }\r\n\talias empty = isEmpty, front = peek, popFront = pop, top = peek;\r\n\tStack opOpAssign(string op)(T x) if(op == \"~\"){ push(x); return this; }\r\n\tT opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }\r\n\tstatic Stack!T opCall(T[] xs = []){ return new Stack!T(xs); }\r\n\tT[] array(){ return xs[0 .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u8ffd\u52a0\uff09\r\n\r\n\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!long(N);\r\n\r\n bool isOK(long x) {\r\n auto a = A.dup;\r\n foreach_reverse(int i; 2..N) {\r\n const d = max(0, min(A[i], a[i] - x) / 3);\r\n a[i - 2] += d * 2;\r\n a[i - 1] += d;\r\n a[i] -= d * 3;\r\n }\r\n\r\n // deb(x, a);\r\n return a.all!(z => z >= x);\r\n }\r\n\r\n return binarySearch(&isOK, 1, 10L^^9 + 2);\r\n }\r\n\r\n foreach(_; 0..QN) subSolve().writeln;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nbool possible(long[] arr, long answer) {\n auto original = arr.dup;\n\n foreach_reverse(i; 2 .. arr.length) {\n if (arr[i] < answer) return false;\n long d = min(arr[i] - answer, original[i]) / 3;\n arr[i - 1] += d;\n arr[i - 2] += 2 * d;\n }\n\n return arr[0] >= answer && arr[1] >= answer;\n}\n\nvoid main() {\n int T;\n read(T);\n\n while (T--) {\n int n;\n read(n);\n auto arr = list!long;\n long low = 0, high = int.max;\n\n while (high != low) {\n long mid = (high + low) / 2;\n if (mid == low) mid = high;\n\n if (possible(arr.dup, mid)) low = mid;\n else high = mid - 1;\n }\n\n writeln(low);\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto h = RDA;\r\n\r\n\t\tbool f(long x)\r\n\t\t{\r\n\t\t\tauto hh = h.dup;\r\n\t\t\tforeach_reverse (i; 2..n)\r\n\t\t\t{\r\n\t\t\t\tif (hh[i] < x) return false;\r\n\t\t\t\tauto rem = hh[i] - x;\r\n\t\t\t\tauto d = min(rem / 3, h[i] / 3);\r\n\t\t\t\thh[i-1] += d;\r\n\t\t\t\thh[i-2] += d*2;\r\n\t\t\t}\r\n\t\t\treturn (hh[0] >= x) && (hh[1] >= x);\r\n\t\t}\r\n\t\tans[ti] = binarySearch!(f)(-1L, 2L^^10);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto h = RDA;\r\n\r\n\t\tbool f(long x)\r\n\t\t{\r\n\t\t\tauto hh = h.dup;\r\n\t\t\tforeach_reverse (i; 2..n)\r\n\t\t\t{\r\n\t\t\t\tif (hh[i] < x) return false;\r\n\t\t\t\tauto rem = hh[i] - x;\r\n\t\t\t\tauto d = min(rem / 3, h[i] / 3);\r\n\t\t\t\thh[i-1] += d;\r\n\t\t\t\thh[i-2] += d*2;\r\n\t\t\t}\r\n\t\t\treturn (hh[0] >= x) && (hh[1] >= x);\r\n\t\t}\r\n\t\tans[ti] = binarySearch!(f)(0, 2L^^10);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto h = RDA;\r\n\r\n\t\tbool f(long x)\r\n\t\t{\r\n\t\t\tauto hh = h.dup;\r\n\t\t\tforeach_reverse (i; 2..n)\r\n\t\t\t{\r\n\t\t\t\tif (hh[i] < x) return false;\r\n\t\t\t\tauto rem = hh[i] - x;\r\n\t\t\t\tauto d = min(rem / 3, h[i] / 3);\r\n\t\t\t\thh[i-1] += d;\r\n\t\t\t\thh[i-2] += d*2;\r\n\t\t\t}\r\n\t\t\treturn hh[0] >= x && hh[1] >= x;\r\n\t\t}\r\n\t\tans[ti] = binarySearch!(f)(0, 2L^^10);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto h = RDA;\r\n\r\n\t\tbool f(long x)\r\n\t\t{\r\n\t\t\tauto hh = h.dup;\r\n\t\t\tforeach_reverse (i; 2..n)\r\n\t\t\t{\r\n\t\t\t\tauto rem = hh[i] - x;\r\n\t\t\t\tif (rem < 0) return false;\r\n\t\t\t\tauto d = min(rem / 3, h[i] / 3);\r\n\t\t\t\thh[i-1] += d;\r\n\t\t\t\thh[i-2] += d*2;\r\n\t\t\t}\r\n\t\t\treturn hh[0] >= x && hh[1] >= x;\r\n\t\t}\r\n\t\tans[ti] = binarySearch!(f)(0, 2L^^9+1);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nbool possible(long[] arr, long answer) {\n arr = [0L, 0L] ~ arr;\n auto original = arr.dup;\n\n foreach_reverse(i; 2 .. arr.length) {\n if (arr[i] < answer) return false;\n long d = min(arr[i] - answer, original[i]) / 3;\n arr[i - 1] += d;\n arr[i - 2] += 2 * d;\n arr[i] -= 3 * d;\n }\n\n return true;\n}\n\nvoid main() {\n int T;\n read(T);\n\n while (T--) {\n int n;\n read(n);\n auto arr = list!long;\n long low = 0, high = int.max;\n\n while (high != low) {\n long mid = (high + low) / 2;\n if (mid == low) mid = high;\n\n if (possible(arr, mid)) low = mid;\n else high = mid - 1;\n }\n\n writeln(low);\n }\n}\n\n"}], "src_uid": "895d5850e420a36ae3b5f0a50e359423"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\n\t\tbool dfs(long x, bool turn)\n\t\t{\n\t\t\tif (x == 1) return !turn;\n\t\t\tif (x == 2 || x % 2) return turn;\n\n\t\t\tbool res = !turn;\n\t\t\tfor (long i = 3; i*i <= x; ++i)\n\t\t\t{\n\t\t\t\tif (x % i) continue;\n\t\t\t\tif (i % 2)\n\t\t\t\t\tres |= dfs(x/i, !turn) == turn;\n\t\t\t\tif ((x / i) % 2)\n\t\t\t\t\tres |= dfs(i, !turn) == turn;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tans[ti] = dfs(n, true);\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Ashishgup\" : \"FastestFinger\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!long;\n if (N == 1) {\n writeln(\"FastestFinger\");\n continue;\n }\n if (N == 2 || N%2 == 1) {\n writeln(\"Ashishgup\");\n continue;\n }\n auto n = N;\n int t;\n while (n%2 == 0) {\n ++t;\n n /= 2;\n }\n if (n == 1) {\n writeln(\"FastestFinger\");\n continue;\n }\n if (t > 1) {\n writeln(\"Ashishgup\");\n continue;\n }\n\n int c;\n for (long k = 3; k^^2 <= N; k += 2) {\n while (n%k == 0) {\n ++c;\n n /= k;\n }\n }\n if (n != 1) {\n ++c;\n }\n writeln(c == 1 ? \"FastestFinger\": \"Ashishgup\");\n }\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nbool isPrime (int n)\n{\n\tif (n < 2)\n\t{\n\t\treturn false;\n\t}\n\tfor (int d = 2; d * d <= n; d++)\n\t{\n\t\tif (n % d == 0)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nbool solve (int n)\n{\n\tint p2 = bsf (n);\n\tint rem = n >> p2;\n\tif (p2 == 0)\n\t{\n\t\treturn rem > 1;\n\t}\n\telse if (p2 == 1)\n\t{\n\t\treturn !isPrime (rem);\n\t}\n\telse\n\t{\n\t\treturn rem > 1;\n\t}\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\twriteln (solve (n) ? \"Ashishgup\" : \"FastestFinger\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!long;\n if (N == 1) {\n writeln(\"FastestFinger\");\n continue;\n }\n if (N == 2 || N%2 == 1) {\n writeln(\"Ashishgup\");\n continue;\n }\n auto n = N;\n int t;\n while (n%2 == 0) {\n ++t;\n n /= 2;\n }\n if (n == 1) {\n writeln(\"FastestFinger\");\n continue;\n }\n if (t > 1) {\n writeln(\"Ashishgup\");\n continue;\n }\n\n int c;\n for (long k = 3; k^^2 <= N; k += 2) {\n while (n%k == 0) {\n ++c;\n n /= k;\n }\n }\n if (n%2 != 0 && n != 1) {\n ++c;\n }\n writeln(c%2 == 1 ? \"FastestFinger\": \"Ashishgup\");\n }\n}"}], "src_uid": "b533572dd6d5fe7350589c7f4d5e1c8c"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n = scan!int;\n ll[] arr = scanArray;\n ll minn = arr[0];\n for(int i = 0; i < n; ++i){\n minn = minn & arr[i];\n }\n writeln(minn);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "\nimmutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto a = ma(n, readInt!int);\n\ta.fold!((ai, aj) => ai&aj).writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto T = RD!int;\r\n\tauto ans = new long[](T);\r\n\tforeach (ti; 0..T)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tans[ti] = a[0];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tans[ti] &= a[i];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "4f8eac547bbd469a69de2f4aae4a87f0"} {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.math : log10, pow;\nimport std.algorithm;\n\nconst int MAX = 100005;\nint MOD = 998244353;\nint n;\nlong[MAX] a;\nint[20] count;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n foreach(i; 0..n) count[numOfDigits(a[i])]++;\n\n long result = 0;\n foreach(i; 0..n){\n foreach(j; 1..11) {\n if (count[j] == 0) continue;\n auto d = min(numOfDigits(a[i]), j);\n auto r = calc(a[i], d);\n auto x = r[0];\n auto y = r[1] % MOD;\n result += (y * 11 * count[j]) % MOD + ((((pow10(d * 2) % MOD) * x) % MOD) * 2 * count[j]) % MOD;\n result %= MOD;\n }\n }\n writeln(result);\n}\n\nauto pow10(long x) {\n return pow(10, x);\n}\n\nauto numOfDigits(long x) {\n if (x == 0) return 1;\n return 1 + cast(int) log10(x);\n}\n\nauto calc(long x, int digits) {\n long base = 1;\n long y = 0;\n int k = 0;\n while(x > 0) {\n auto d = x % 10;\n x = x / 10;\n y += d * base;\n base *= 100;\n k++;\n if (k >= digits) {\n break;\n }\n }\n return tuple(x, y);\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nconst long mod = 998_244_353;\n\nvoid solve(){\n\tint n = read.to!int;\n\t\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\n\tlong[][] ws;\n\tforeach(a; as){\n\t\tlong [] w;\n\t\tfor(long x = a; x > 0; x /= 10) w ~= x % 10;\n\t\tws ~= w;\n\t}\n\tlog(\"ws:\", ws);\n\t\n\tint[] ks;\n\tforeach(a; as){\n\t\tint k = 0;\n\t\tlong m = 1;\n\t\twhile(a >= m) k += 1, m *= 10;\n\t\tks ~= k;\n\t}\n\tlog(\"ks:\", ks);\n\t\n\tlong[] ms = [1];\n\tforeach(i; 1 .. 24){\n\t\tms ~= ms[$ - 1] * 10 % mod;\n\t}\n\tlog(\"ms:\", ms);\n\t\n\tlong[] rs;\n\tforeach(i; 0 .. 11){\n\t\tlong r;\n\t\tforeach(k; ks){\n\t\t\tif(i < k) r += 11 * ms[i * 2], r %= mod;\n\t\t\telse r += 2 * ms[k * 2] * ms[i - k], r %= mod;\n\t\t}\n\t\trs ~= r;\n\t}\n\tlog(\"rs:\", rs);\n\t\n\tlong ans;\n\tforeach(w; ws){\n\t\tforeach(i, t; w){\n\t\t\tans += t * rs[i];\n\t\t\tans %= mod;\n\t\t}\n\t}\n\t\n\tans.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.typecons;\nimport std.math : log10, pow;\nimport std.algorithm;\n\nconst int MAX = 100005;\nint MOD = 998244353;\nint n;\nlong[MAX] a;\nint[20] count;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n foreach(i; 0..n) count[numOfDigits(a[i])]++;\n\n long result = 0;\n foreach(i; 0..n){\n foreach(j; 1..11) {\n if (count[j] == 0) continue;\n auto d = min(numOfDigits(a[i]), j);\n auto r = calc(a[i], d);\n auto x = r[0];\n auto y = r[1] % MOD;\n result += (y * 11 * count[j]) % MOD + ((((pow10(d * 2) % MOD) * x) % MOD) * 2 * count[j]) % MOD;\n result %= MOD;\n }\n }\n writeln(result);\n}\n\nauto pow10(int x) {\n return cast(long) pow(10, x);\n}\n\nauto numOfDigits(long x) {\n return 1 + cast(int) log10(x);\n}\n\nauto calc(long x, int digits) {\n long base = 1;\n long y = 0;\n int k = 0;\n while(x > 0) {\n auto d = x % 10;\n x = x / 10;\n y += d * base;\n base *= 100;\n k++;\n if (k >= digits) {\n break;\n }\n }\n return tuple(x, y);\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.math : log10, pow;\nimport std.algorithm;\n\nconst int MAX = 100005;\nint MOD = 998244353;\nint n;\nlong[MAX] a;\nint[10] count;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n foreach(i; 0..n) count[numOfDigits(a[i])]++;\n\n long result = 0;\n foreach(i; 0..n){\n foreach(j; 1..10) {\n if (count[j] == 0) continue;\n auto d = min(numOfDigits(a[i]), j);\n auto r = calc(a[i], d);\n auto x = r[0];\n auto y = r[1] % MOD;\n result += (y * 11 * count[j]) % MOD + ((((pow10(d * 2) % MOD) * x) % MOD) * 2 * count[j]) % MOD;\n result %= MOD;\n }\n }\n writeln(result);\n}\n\nauto pow10(int x) {\n return cast(long) pow(10, x);\n}\n\nauto numOfDigits(long x) {\n return 1 + cast(int) log10(x);\n}\n\nauto calc(long x, int digits) {\n long base = 1;\n long y = 0;\n int k = 0;\n while(x > 0) {\n auto d = x % 10;\n x = x / 10;\n y += d * base;\n base *= 100;\n k++;\n if (k >= digits) {\n break;\n }\n }\n return tuple(x, y);\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.math : log10, pow;\nimport std.algorithm;\n\nconst int MAX = 100005;\nint MOD = 998244353;\nint n;\nlong[MAX] a;\nint[10] count;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n foreach(i; 0..n) count[numOfDigits(a[i])]++;\n\n long result = 0;\n foreach(i; 0..n){\n foreach(j; 1..10) {\n if (count[j] == 0) continue;\n auto d = min(numOfDigits(a[i]), j);\n auto r = calc(a[i], d);\n auto x = r[0];\n auto y = r[1] % MOD;\n result += (y * 11 * count[j]) % MOD + ((((pow10(d * 2) % MOD) * x) % MOD) * 2 * count[j]) % MOD;\n result %= MOD;\n }\n }\n writeln(result);\n}\n\nauto pow10(int x) {\n return cast(int) pow(10, x);\n}\n\nauto numOfDigits(long x) {\n return 1 + cast(int) log10(x);\n}\n\nauto calc(long x, int digits) {\n long base = 1;\n long y = 0;\n int k = 0;\n while(x > 0) {\n auto d = x % 10;\n x = x / 10;\n y += d * base;\n base *= 100;\n k++;\n if (k >= digits) {\n break;\n }\n }\n return tuple(x, y);\n}\n\n"}], "src_uid": "b4cd60296083ee2ae8a560209433dcaf"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int n_Cases = 1;\n // n_Cases = cin.readInt;\n \n\tfor (int case_i = 1; case_i <= n_Cases; case_i++) {\n char[] s = cin.readString.dup;\n char[] r = \"AHIMOTUVWXY\".dup;\n foreach (i; s) {\n if (!r.canFind(i)) {\n writeln(\"NO\");\n return;\n }\n }\n writeln(s.dup.reverse == s.dup ? \"YES\" : \"NO\");\n\t} \n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bigint;\nimport std.conv;\nimport std.exception;\nimport std.math;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int NA = -1;\nimmutable string A = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\nimmutable string B = \"AxxxxxxHIxxxMxOxxxxTUVWXYx\";\n\nvoid main ()\n{\n\tchar [dchar] d;\n\tforeach (i; 0..A.length)\n\t{\n\t\td[A[i]] = B[i];\n\t}\n\n\tchar [] s;\n\twhile ((s = to !(char []) (readln ().strip ())) != \"\")\n\t{\n\t\tchar [] b = s.dup;\n\t\treverse (b);\n\t\tchar [] c;\n\t\tforeach (x; b)\n\t\t{\n\t\t\tc ~= d[x];\n\t\t}\n\t\twriteln (s == c ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "module main;\n\nimport std.stdio, std.string, std.algorithm;\n\nauto table = \"AHIMOTUVWXY\";\n\nvoid solve(char[] str)\n{\n int i = 0, j = str.length - 1;\n while (i < j)\n {\n if (str[i] != str[j] || find(table, str[i]) == \"\")\n {\n writefln(\"NO\");\n return;\n }\n ++ i;\n -- j;\n }\n if (i == j && find(table, str[i]) == \"\")\n {\n writefln(\"NO\");\n return;\n }\n writefln(\"YES\");\n}\n\nint main(string[] args)\n{\n char[] str;\n while (stdin.readln(str))\n {\n solve(chomp(str));\n }\n return 0;\n}"}], "negative_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int n_Cases = 1;\n // n_Cases = cin.readInt;\n \n\tfor (int case_i = 1; case_i <= n_Cases; case_i++) {\n char[] s = cin.readString.dup;\n if (s.length == 1) writeln(\"NO\");\n else writeln(s.dup.reverse != s ? \"NO\" : \"YES\");\n\t} \n}"}, {"source_code": "module main;\n\nimport std.stdio, std.string, std.algorithm;\n\nauto table = \"AHIMOTUVWXY\";\n\nvoid solve(char[] str)\n{\n int i = 0, j = str.length - 1;\n while (i < j)\n {\n if (str[i] != str[j])\n {\n writefln(\"NO\");\n return;\n }\n ++ i;\n -- j;\n }\n if (i == j && find(table, str[i]) == \"\")\n {\n writefln(\"NO\");\n return;\n }\n writefln(\"YES\");\n}\n\nint main(string[] args)\n{\n char[] str;\n while (stdin.readln(str))\n {\n solve(chomp(str));\n }\n return 0;\n}"}], "src_uid": "8135173b23c6b48df11b1d2609b08080"} {"source_code": "\ufeffvoid main() {\n\timport std.stdio, std.conv, std.string, std.algorithm;\n\n\treadln;\n\n\tint sumCrimes, emplPols;\n\tforeach (el; readln.split.map!(to!int)) {\n\t\tif (el == -1) {\n\t\t\tif (emplPols > 0)\n\t\t\t\t--emplPols;\n\t\t\telse\n\t\t\t\t++sumCrimes;\n\t\t}\n\t\telse\n\t\t\templPols += el;\n\t}\n\n\twriteln(sumCrimes);\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.algorithm;\nimport std.range;\n\nvoid main() {\n auto n = readln.strip.to!int;\n auto a = readln.split.map!(to!int).array;\n int s = 0, r = 0;\n foreach (v; a) {\n s += v;\n if (s < 0) {\n r++;\n s = 0;\n }\n }\n writeln(r);\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.string;\nimport std.regex;\nimport std.math;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint crimes, police_officers;\n\tforeach (int i; 0..n)\n\t{\n\t\tint tbd; scanf(\"%d\", &tbd);\n\t\tif (tbd < 0)\n\t\t{\n\t\t\tif (police_officers > 0)\n\t\t\t{\n\t\t\t\tpolice_officers += tbd;\n\t\t\t} else {\n\t\t\t\tcrimes -= tbd;\n\t\t\t}\n\t\t} else {\n\t\t\tpolice_officers += tbd;\n\t\t}\n\t}\n\tprintf(\"%d\", crimes);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "af47635f631381b4578ba599a4f8b317"} {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tlong k, d, t;\n\tread(k, d, t);\n\tt *= 2;\n\tk *= 2;\n\td *= 2;\n\tauto r = d * ((k + d - 1) / d);\n\tauto e = k + (d - k % d) % d / 2;\n\tauto ans = t / e * r;\n\tt %= e;\n\tans += min(k, t);\n\tt -= k;\n\tif (t > 0)\n\t\tans += 2 * t;\n\twritefln(\"%.10f\", 1.0L * ans / 2);\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nreal solve (long k, long d, long t)\n{\n\tif (k % d == 0)\n\t{\n\t\treturn t;\n\t}\n\treal goodParts = k / d;\n\treal goodAdd = k % d;\n\treal goodTime = goodParts * d + goodAdd;\n\treal badTime = d - goodAdd;\n\treal periodTime = goodTime + badTime;\n\treal periodCook = goodTime + badTime * 0.5;\n\tdebug {writefln (\"%.20f %.20f\", goodTime, badTime);}\n\n\treal res = 0.0;\n\treal toCook = t;\n\tfor (real times = 1L << 60; times >= 1; times = times * 0.5)\n\t{\n\t\tif (toCook >= periodCook * times)\n\t\t{\n\t\t\ttoCook -= periodCook * times;\n\t\t\tres += periodTime * times;\n\t\t}\n\t}\n\n\treal extra = min (toCook, goodTime);\n\tres += extra;\n\ttoCook -= extra;\n\tif (toCook > 0)\n\t{\n\t\tres += toCook * 2;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tlong k, d, t;\n\twhile (readf (\" %s %s %s\", &k, &d, &t) > 0)\n\t{\n\t\treal res = solve (k, d, t);\n\t\twritefln (\"%.20f\", res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tlong k, d, t;\n\tread(k, d, t);\n\tt *= 2;\n\tk *= 2;\n\td *= 2;\n\tauto r = d * ((k + d - 1) / d);\n\tauto e = k + (d - k % d) % d / 2;\n\tauto ans = t / e * r;\n\tt %= e;\n\tans += min(k, t);\n\tt -= k;\n\tif (t > 0)\n\t\tans += 2 * t;\n\twriteln(1.0L * ans / 2);\n}\n"}], "src_uid": "9df3a94dfa537cabdc52388a771cd24f"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nint n;\nint[200005] a;\nint[1000005] f;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n auto m = a[0..n].fold!max;\n foreach(x; a[0..n]) f[x] = x;\n foreach(i; 1..m+1) \n if (f[i] == 0) f[i] = f[i-1];\n\n auto result = 0;\n a[0..n].sort();\n foreach(i, x; a[0..n]) {\n // ensure that the algorithm run in harmonic sum time: 1/2 + 1/3 + 1/4 ....\n if (i >= 1 && a[i] == a[i-1]) continue;\n auto y = x + x;\n while (y <= m) {\n result = max(result, f[y-1] % x);\n y += x;\n }\n result = max(result, m % x);\n }\n writeln(result);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nint n;\nint[200005] a;\nint[1000005] f;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n auto m = a[0..n].fold!max;\n foreach(x; a[0..n]) f[x] = x;\n foreach(i; 1..m+1) \n if (f[i] == 0) f[i] = f[i-1];\n\n auto result = 0;\n a[0..n].sort();\n foreach(i, x; a[0..n]) {\n if (x == 1) continue;\n if (i >= 1 && a[i] == a[i-1]) continue;\n auto y = x + x;\n while (y <= m) {\n result = max(result, f[y-1] % x);\n y += x;\n }\n result = max(result, m % x);\n }\n writeln(result);\n}\n"}], "negative_code": [], "src_uid": "0ef324e3e314ea17c01aafb822e90c63"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto cost = readln.chomp.split.map!(to!int).array;\n \n auto p = readln.chomp.split.map!(to!int).array;\n p[] -= 1;\n \n int getMinForCycle(int v) {\n auto ans = int.max;\n int u = v;\n do {\n ans = min(ans, cost[u]);\n u = p[u];\n } while (u != v);\n \n debug { writeln(v, ' ', ans); }\n \n return ans;\n }\n \n auto vis = new int[n];\n int dfs(int v) {\n if (vis[v] == 2) {\n return 0;\n }\n \n vis[v] = 1;\n debug { v.writeln; }\n \n auto u = p[v];\n auto ret = 0;\n if (vis[u] == 0) {\n ret = dfs(u);\n } else if (vis[u] == 1) {\n ret = getMinForCycle(v);\n } else if (vis[u] == 2) {\n ret = 0;\n }\n vis[v] = 2;\n return ret;\n }\n \n auto ans = 0;\n foreach (i; 0 .. n) {\n ans += dfs(i);\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto C = readln.split.map!(to!long).array;\n auto A = readln.split.map!(x => x.to!int-1).array;\n auto used = new int[](N);\n int cnt = 0;\n long ans = 0;\n\n foreach (i; 0..N) {\n if (used[i]) continue;\n ++cnt;\n int[] nodes;\n int n = i;\n while (!used[n]) {\n nodes ~= n;\n used[n] = cnt;\n n = A[n];\n }\n if (used[n] != cnt) continue;\n bool flag = false;\n long tmp = 1L << 59;\n foreach (j; nodes) {\n if (j == n) flag = true;\n if (flag) tmp = min(tmp, C[j]);\n }\n\n ans += tmp;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto cost = readln.chomp.split.map!(to!int).array;\n \n auto p = readln.chomp.split.map!(to!int).array;\n p[] -= 1;\n \n int getMinForCycle(int v) {\n auto ans = int.max;\n int u = v;\n do {\n ans = min(ans, cost[u]);\n u = p[u];\n } while (u != v);\n \n debug { writeln(v, ' ', ans); }\n \n return ans;\n }\n \n auto vis = new int[n];\n int dfs(int v) {\n if (vis[v] == 2) {\n return 0;\n }\n \n vis[v] = 1;\n debug { v.writeln; }\n \n auto u = p[v];\n auto ret = 0;\n if (vis[u] == 0) {\n ret = dfs(u);\n } else if (vis[u] == 1) {\n ret = getMinForCycle(v);\n } else if (vis[u] == 2) {\n ret = 0;\n }\n vis[v] = 2;\n return ret;\n }\n \n auto ans = n.iota.map!(x => dfs(x)).sum;\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto cost = readln.chomp.split.map!(to!int).array;\n \n auto p = readln.chomp.split.map!(to!int).array;\n p[] -= 1;\n \n int getMinForCycle(int v) {\n auto ans = int.max;\n int u = v;\n do {\n ans = min(ans, cost[u]);\n u = p[u];\n } while (u != v);\n \n debug { writeln(v, ' ', ans); }\n \n return ans;\n }\n \n auto ans = 0;\n auto vis = new int[n];\n void dfs(int v) {\n if (vis[v] == 2) {\n return;\n }\n \n vis[v] = 1;\n debug { v.writeln; }\n \n auto u = p[v];\n if (vis[u] == 0) {\n dfs(u);\n } else if (vis[u] == 1) {\n ans += getMinForCycle(v);\n }\n vis[v] = 2;\n }\n \n foreach (i; 0 .. n) {\n dfs(i);\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "4278fece7812148863688c67218aca7b"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n auto A = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt();\n }\n auto B = new int[N];\n foreach (j; 0 .. N) {\n B[j] = readInt();\n }\n A.sort;\n B.sort;\n \n alias Entry = Tuple!(int, \"s\", int, \"i\", int, \"j\");\n Entry[] es;\n foreach (i; 0 .. M) foreach (j; 0 .. N) {\n es ~= Entry(A[i] + B[j], i, j);\n }\n es.sort;\n const esLen = cast(int)(es.length);\n Tuple!(long, long)[] fs;\n for (int k = 0, l; k < esLen; k = l) {\n for (l = k; l < esLen && es[k].s == es[l].s; ++l) {}\n long f0, f1;\n foreach (ref e; es[k .. l]) {\n f0 |= 1L << e.i;\n f1 |= 1L << e.j;\n fs ~= tuple(f0, f1);\n }\n }\n const fsLen = cast(int)(fs.length);\n int ans;\n foreach (k; 0 .. fsLen) foreach (l; k .. fsLen) {\n int score;\n score += popcnt(fs[k][0] | fs[l][0]);\n score += popcnt(fs[k][1] | fs[l][1]);\n chmax(ans, score);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int half = 20005;\nimmutable int limit = (half << 1) + 1;\n\nvoid main ()\n{\n\tint m, n;\n\twhile (readf (\" %s %s\", &m, &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\ta[] += half;\n\t\tb[] += half;\n\t\tauto u = new int [limit];\n\t\tauto v = new int [limit];\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tu[c] += 1;\n\t\t}\n\t\tforeach (ref c; b)\n\t\t{\n\t\t\tv[c] += 1;\n\t\t}\n\t\tauto f = new bool [limit];\n\t\tauto g = new bool [limit];\n\t\tauto mask = new long [2] [] [] (m, n);\n\t\tforeach (p; 0..m)\n\t\t{\n\t\t\tforeach (q; 0..n)\n\t\t\t{\n\t\t\t\tforeach (r; 0..m)\n\t\t\t\t{\n\t\t\t\t\tforeach (s; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (a[r] - a[p] == b[q] - b[s])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmask[p][q][0] |=\n\t\t\t\t\t\t\t 1L << r;\n\t\t\t\t\t\t\tmask[p][q][1] |=\n\t\t\t\t\t\t\t 1L << s;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (p; 0..m)\n\t\t{\n\t\t\tforeach (q; 0..n)\n\t\t\t{\n\t\t\t\tforeach (r; 0..m)\n\t\t\t\t{\n\t\t\t\t\tforeach (s; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto cur = 0;\n\t\t\t\t\t\tcur += popcnt (mask[p][q][0] |\n\t\t\t\t\t\t mask[r][s][0]);\n\t\t\t\t\t\tcur += popcnt (mask[p][q][1] |\n\t\t\t\t\t\t mask[r][s][1]);\n\t\t\t\t\t\tres = max (res, cur);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n auto A = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt();\n }\n auto B = new int[N];\n foreach (j; 0 .. N) {\n B[j] = readInt();\n }\n A.sort;\n B.sort;\n \n alias Entry = Tuple!(int, \"s\", int, \"i\", int, \"j\");\n Entry[] es;\n foreach (i; 0 .. M) foreach (j; 0 .. N) {\n es ~= Entry(A[i] + B[j], i, j);\n }\n es.sort;\n const esLen = cast(int)(es.length);\n Tuple!(long, long)[] fs;\n for (int k = 0, l; k < esLen; k = l) {\n for (l = k; l < esLen && es[k].s == es[l].s; ++l) {}\n long f0, f1;\n foreach (ref e; es[k .. l]) {\n f0 |= 1L << e.i;\n f1 |= 1L << e.j;\n fs ~= tuple(f0, f1);\n }\n }\n const fsLen = cast(int)(fs.length);\n int ans;\n foreach (k; 0 .. fsLen) foreach (l; k + 1 .. fsLen) {\n int score;\n score += popcnt(fs[k][0] | fs[l][0]);\n score += popcnt(fs[k][1] | fs[l][1]);\n chmax(ans, score);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "7dd891cef0aa40cc1522ca4b37963b92"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 998_244_353;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tint recur (int v, int p)\n\t\t{\n\t\t\tint subtrees = a[v].length.to !(int) + (p == NA);\n\t\t\tint res = 1;\n\t\t\tfor (int i = 1; i < subtrees; i++)\n\t\t\t{\n\t\t\t\tres = (res * 1L * i) % mod;\n\t\t\t}\n\t\t\tif (p == NA)\n\t\t\t{\n\t\t\t\tres = (res * 1L * n) % mod;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres = (res * 1L * (subtrees)) % mod;\n\t\t\t}\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tif (u != p)\n\t\t\t\t{\n\t\t\t\t\tres = (res * 1L * recur (u, v)) % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\twriteln (recur (0, NA));\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nint[][] child;\nbool[] visited;\n\nlong MOD = 998244353;\nlong[] fac;\n\nlong dfs(uint root) {\n\n uint nc = 0;\n\n visited[root] = true;\n long mul = 1;\n\n foreach (v; child[root]) {\n if (!visited[v]) {\n long ll = dfs(v);\n mul = (mul * ll) % MOD;\n nc++;\n }\n }\n\n if (root != 0)\n nc++;\n\n return (fac[nc] * mul) % MOD;\n}\n\nvoid main() {\n GC.disable();\n\n uint n;\n\n readf(\" %s\", n);\n\n child = new int[][n];\n visited = new bool[n];\n visited[] = false;\n fac = new long[n + 10];\n fac[0] = 1;\n foreach (i; 1 .. n + 1)\n fac[i] = (fac[i - 1] * i) % MOD;\n\n foreach (i; 0 .. n - 1) {\n uint u, v;\n readf(\" %s %s\", u, v);\n u--;\n v--;\n child[u] ~= v;\n child[v] ~= u;\n }\n\n long ans = dfs(0);\n writeln((n * ans) % MOD);\n\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum long MO = 998244353;\n\nint N;\nint[] U, V;\n\nint[][] G;\nint[] deg;\n\nvoid dfs(int u, int p) {\n foreach (v; G[u]) {\n if (v != p) {\n ++deg[u];\n dfs(v, u);\n }\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n U = new int[N - 1];\n V = new int[N - 1];\n foreach (i; 0 .. N - 1) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n G = new int[][N];\n foreach (i; 0 .. N - 1) {\n G[U[i]] ~= V[i];\n G[V[i]] ~= U[i];\n }\n deg = new int[N];\n const rt = 0;\n dfs(rt, -1);\n \n long ans = N;\n foreach (u; 0 .. N) {\n foreach (k; 1 .. deg[u] + 1) {\n ans *= k;\n ans %= MO;\n }\n if (u != rt) {\n ans *= (deg[u] + 1);\n ans %= MO;\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nint[][] child;\nbool[] visited;\n\nlong MOD = 998244353;\nlong[] fac;\n\nlong dfs(uint root) {\n\n uint nc = 0;\n\n visited[root] = true;\n long mul = 1;\n\n foreach (v; child[root]) {\n if (!visited[v]) {\n long ll = dfs(v);\n mul = (mul * ll) % MOD;\n nc++;\n }\n }\n\n if (root != 0)\n nc++;\n\n return (fac[nc] * mul) % MOD;\n}\n\nvoid main() {\n GC.disable();\n\n uint n;\n\n readf(\" %s\", n);\n\n child = new int[][n];\n visited = new bool[n];\n visited[] = false;\n fac = new long[n + 10];\n fac[0] = 1;\n foreach (i; 1 .. n + 1)\n fac[i] = (fac[i - 1] * i) % MOD;\n\n foreach (i; 0 .. n - 1) {\n uint u, v;\n readf(\" %s %s\", u, v);\n u--;\n v--;\n child[u] ~= v;\n child[v] ~= u;\n }\n\n long ans = dfs(0);\n writeln(n * ans);\n\n}\n"}], "src_uid": "03bfe285856fa74b89de7a1bebb14bca"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const A = readLong();\n const B = readLong();\n const N = readLong();\n \n long ans;\n long a = A, b = B;\n for (; a <= N && b <= N; ) {\n if (a > b) {\n swap(a, b);\n }\n a += b;\n ++ans;\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint;\nimport std.bitmanip, std.complex, std.container;\nimport std.math, std.mathspecial,std.numeric;\nimport std.regex, std.typecons;\nimport core.bitop;\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\nbool chmin(T)(ref T t, in T f)\n{ if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) \n{ if (t < f) { t = f; return true; } else { return false; } }\nint binarySearch(alias pred, T)(in T[] as) \n{int lo = -1, hi = cast(int)(as.length);\nfor(;lo + 1 < hi;){const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid;}\nreturn hi;}\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const A = readLong();\n const B = readLong();\n const N = readLong();\n\n long ans;\n long a = A, b = B;\n for (; a <= N && b <= N; ) {\n if (a > b) {\n swap(a, b);\n }\n a += b;\n ++ans;\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tforeach (t; 0..readln.strip.to !(int))\n\t{\n\t\tint a, b, n;\n\t\treadf !(\" %s %s %s\") (a, b, n);\n\t\tint res = 0;\n\t\twhile (!(a > n || b > n))\n\t\t{\n\t\t\tif (a > b)\n\t\t\t{\n\t\t\t\tswap (a, b);\n\t\t\t}\n\t\t\tres += 1;\n\t\t\ta += b;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "// Code By H~$~C\n\nimport std.stdio, std.format;\nimport std.math, std.uni, std.bigint, std.numeric;\nimport std.array, std.string, std.container, std.range, std.typecons;\nimport std.algorithm, std.conv, std.functional, std.random;\n\nvoid _Main() {\n int a, b, n;\n readf!\" %d %d %d\"(a, b, n);\n if (a > b) swap(a, b);\n int cnt = 0;\n while (b <= n) {\n a += b;\n swap(a, b);\n cnt++;\n }\n writefln!\"%s\"(cnt);\n}\n\nvoid main(string[] args) {\n int tests = 1;\n readf!\" %d\"(tests);\n foreach (test; 0 .. tests) _Main();\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto n = RD;\n\n\t\twhile (max(a, b) <= n)\n\t\t{\n\t\t\tif (a < b)\n\t\t\t\ta += b;\n\t\t\telse\n\t\t\t\tb += a;\n\t\t\t++ans[ti];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "5999a4e2fac29b5f4804639f6e949279"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint i = 0;\r\n\t\tint j = n - 1;\r\n\t\tint res = 0;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\twhile (i < n && a[i] == 0)\r\n\t\t\t{\r\n\t\t\t\ti += 1;\r\n\t\t\t}\r\n\t\t\twhile (j >= 0 && a[j] == 1)\r\n\t\t\t{\r\n\t\t\t\tj -= 1;\r\n\t\t\t}\r\n\t\t\tif (i >= j)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tres += 1;\r\n\t\t\ti += 1;\r\n\t\t\tj -= 1;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt;\n }\n \n auto ASum = new int[N + 1];\n foreach (i; 0 .. N) {\n ASum[i + 1] = ASum[i] + A[i];\n }\n \n int ans = N;\n foreach (k; 0 .. N + 1) {\n const l = ASum[k];\n const r = (N - k) - (ASum[N] - ASum[k]);\n const cost = max(l, r);\n chmin(ans, cost);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "c247c7c382c243ab6b991c4a11bfc421"} {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nvoid solve() {\r\n long N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto A = readln.chomp.split(\" \").map!(to!long).array;\r\n long C = A.reduce!\"a+b\" - K * N;\r\n long ans = C;\r\n long[] rs;\r\n for (int i = cast(int)(N-1); i >= 0; i--) {\r\n long[] nrs;\r\n long rd = 0;\r\n rs ~= A[i];\r\n foreach (ref r; rs) {\r\n rd += (r - r / 2);\r\n r /= 2;\r\n if (r > 0) {\r\n nrs ~= r;\r\n }\r\n }\r\n C = C - rd + K;\r\n ans = max(ans, C);\r\n rs = nrs;\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int limit = 32;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tauto f = new long [n + 1];\r\n\t\tf[] = long.min / 2;\r\n\t\tf[0] = 0;\r\n\t\tlong res = 0;\r\n\t\tforeach (d; 0..limit)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tf[i + 1] = max (f[i + 1], f[i] + a[i] - k);\r\n\t\t\t}\r\n\t\t\tres = max (res, f[n]);\r\n\t\t\ta[] /= 2;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tf[i + 1] = max (f[i + 1], f[i] + a[i]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tres = max (res, f.maxElement);\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "9fcc55a137b5ff021fdc8e1e867ce856"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~\"\\n\", ptrs)==ptrs.length;}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\nloop:while(read(&n,&k))\n\t{\n\t\tauto w=arread!int;\n\t\tsort(w);\n\t\tint ans=0;\n\t\tforeach(x;w)\n\t\t{\n\t\t\tans+=(x+k-1)/k;\n\t\t}\n\t\twriteln((ans+1)/2);\n\t}\n\t//debug system(\"pause\");\n}", "positive_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------\nT orient_square(T)(pair!(T,T)[] figure...)if(is(typeof(figure.front*figure.front)==T))\n{\n\tauto n=figure.front,t=figure.front;\n\tfigure.popFront();\n\tT ans=0;\n\tfor(;!figure.empty;figure.popFront())\n\t{\n\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\tt=figure.front;\n\t}\n\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n}\n\nX binpow(X,Y)(X base,Y exp)if(is(typeof(exp>>1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\nauto binpow(X,Y,Z)(X base,Y exp,in Z mm)if(is(typeof(exp>>1)) && is(typeof(base%mm)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\nreal square(T)(pair!(T,T)[] figure...)if(is(typeof(figure.front*figure.front)==T))\n{\n\treturn abs(orient_square(figure))/2.000000000000000;\n}\nalias orient_square orsq;\nclass vertex(X,alias f=\"a+b\",X n=0,size_t lg=0,size_t rg=size_t.max/2)\n{\n\tprotected\n\t{\n\t\tclass node\n\t\t{\n\t\t\tX val;\n\t\t\tnode l,r;\n\t\t\tthis(){}\n\t\t};\n\t\tnode root;\n\t}\n\tpublic\n\t{\n\t\tsize_t lb=lg,rb=rg;\n\t\tX neutral=0;\n\t\tsize_t length;\n\t\talias fun=binaryFun!f;\n\t\tthis()\n\t\t{\n\t\t\troot=new node();\n\t\t\tlength=0;\n\t\t}\n\t\t\n\t}\n\tprotected\n\t{\n\t\tbool insert(node t,size_t tl,size_t tr,size_t pos,X x)\n\t\t{\n\t\t\tbool mark=false;\n\t\t\tif(!t)\n\t\t\t{\n\t\t\t\tt=new node();\n\t\t\t\tmark=true;\n\t\t\t}\n\t\t\tif(tl==tr)\n\t\t\t{\n\t\t\t\tt.val=x;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsize_t tm=(tl+tr)>>1;\n\t\t\t\tif(pos<=tm)\n\t\t\t\t{\n\t\t\t\t\tmark=insert(t.l,tl,tm,pos,x);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmark=insert(t.r,tm+1,tr,pos,x);\n\t\t\t\t}\n\t\t\t\tif(!t.l)t.val=t.r.val;\n\t\t\t\telse if(!t.r)t.val=t.l.val;\n\t\t\t\telse t.val=fun(t.l.val,t.r.val);\n\t\t\t}\n\t\t\treturn mark;\n\t\t}\n\t\tbool erase(node t,size_t tl,size_t tr,size_t pos)\n\t\t{\n\t\t\tif(!t)return false;\n\t\t\tif(tl==tr)\n\t\t\t{\n\t\t\t\tt=null;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsize_t tm=(tl+tr)>>1;\n\t\t\t\tif(pos<=tm)\n\t\t\t\t{\n\t\t\t\t\treturn erase(t.l,tl,tm,pos);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\treturn erase(t.r,tm+1,tr,pos);\n\t\t\t\t}\n\t\t\t\tif(!t.l)t.val=t.r.val;\n\t\t\t\telse if(!t.r)t.val=t.l.val;\n\t\t\t\telse t.val=fun(t.l.val,t.r.val);\n\t\t\t}\n\t\t}\n\t\tX cel(node t,size_t tl,size_t tr,size_t l,size_t r)\n\t\t{\n\t\t\tif(!t)return neutral;\n\t\t\tif(tl==l && tr==r)return t.val;\n\t\t\telse\n\t\t\t{\n\t\t\t\tsize_t tm=(tl+tr)>>1;\n\t\t\t\tif(r<=tm)return cel(t.l,tl,tm,l,r);\n\t\t\t\telse if(l>tm)return cel(t.r,tm+1,tr,l,r);\n\t\t\t\telse return fun(cel(t.l,tl,tm,l,tm),cel(t.r,tm+1,tr,tm+1,r));\n\t\t\t}\n\t\t}\n\t}\n\tpublic\n\t{\n\t\tvoid insert(size_t pos,X x)\n\t\t\tin\n\t\t{\n\t\t\tassert(pos>=lb && pos<=rb);\n\t\t}\n\t\tbody\n\t\t{\n\t\t\tlength+=insert(root,lb,rb,pos,x);\n\t\t}\n\t\tvoid erase(size_t pos)\n\t\t\tin\n\t\t{\n\t\t\tassert(pos>=lb && pos<=rb);\n\t\t}\n\t\tbody\n\t\t{\n\t\t\tlength-=erase(root,lb,rb,pos);\n\t\t}\n\t\tX cel(size_t l,size_t r)\n\t\t\tin\n\t\t{\n\t\t\tassert(l<=r && l>=lb && r<=rb);\n\t\t}\n\t\tbody\n\t\t{\n\t\t\treturn cel(root,lb,rb,l,r);\n\t\t}\n\t}\n};\nclass item\n{\n\tsize_t cnt,prior;\n\tint key;\n\titem l,r;\n\tthis(){}\n\tthis(int val,int rnd)\n\t{\n\t\tkey=val;\n\t\tcnt=1;\n\t\tprior=rnd;\n\t}\n};\nint cnt(item t)\n{\n\treturn t?t.cnt:0;\n}\nvoid upd_cnt(item t)\n{\n\tt.cnt=cnt(t.l)+cnt(t.r)+1;\n}\nvoid merge(ref item t,item l,item r)\n{\n\tif(!l || !r)\n\t{\n\t\tt=(l?l:r);\n\t}\n\telse\n\t{\n\t\tif(l.prior>r.prior)\n\t\t{\n\t\t\tmerge(l.r,l.r,r);\n\t\t\tt=l;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmerge(r.l,l,r.l);\n\t\t\tt=r;\n\t\t}\n\t}\n\tupd_cnt(t);\n}\nvoid split(item t,int key,ref item l,ref item r)\n{\n\tif(!t)l=r=null;\n\telse if(key<t.key)\n\t{\n\t\tsplit(t.l,key,l,t.l);\n\t\tr=t;\n\t}\n\telse\n\t{\n\t\tsplit(t.r,key,t.r,r);\n\t\tl=t;\n\t}\n\tupd_cnt(t);\n}\nvoid insert(ref item t,item it)\n{\n\tif(!t) t=it;\n\telse\n\t{\n\t\tif(it.prior>t.prior)\n\t\t{\n\t\t\tsplit(t,it.key,it.l,it.r);\n\t\t\tt=it;\n\t\t}\n\t\telse insert(it.key<t.key?t.l:t.r,it);\n\t}\n\tupd_cnt(t);\n}\nvoid erase(ref item t,int key)\n{\n\tif(t.key==key)merge(t,t.l,t.r);\n\telse erase(key<t.key?t.l:t.r,key);\n}\nsize_t order(item t,int key,size_t add=0)\n{\n\tif(!t)return add+1;\n\telse if(key<=t.key)return order(t.l,key,add);\n\telse return order(t.r,key,cnt(t.l)+add+1);\n}\nclass nitem\n{\n\tsize_t cnt,prior;\n\tint key;\n\tnitem l,r;\n\tthis(){}\n\tthis(int val,int rnd)\n\t{\n\t\tkey=val;\n\t\tcnt=1;\n\t\tprior=rnd;\n\t}\n};\nint cnt(nitem t)\n{\n\treturn t?t.cnt:0;\n}\nvoid upd_cnt(nitem t)\n{\n\tt.cnt=cnt(t.l)+cnt(t.r)+1;\n}\nvoid merge(ref nitem t,nitem l,nitem r)\n{\n\tif(!l || !r)t=(l?l:r);\n\telse\n\t{\n\t\tif(l.prior>r.prior)\n\t\t{\n\t\t\tmerge(l.r,l.r,r);\n\t\t\tt=l;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmerge(r.l,l,r.l);\n\t\t\tt=r;\n\t\t}\n\t}\n\tupd_cnt(t);\n}\nvoid split(nitem t,int key,ref nitem l,ref nitem r,int add=0)\n{\n\tif(!t){l=r=null;return;}\n\tint cur=add=cnt(t.l);\n\tif(key<=cur)\n\t{\n\t\tsplit(t.l,key,l,t.l,add);\n\t\tr=t;\n\t}\n\telse\n\t{\n\t\tsplit(t.r,key,t.r,r,add+1+cnt(t.l));\n\t\tl=t;\n\t}\n\tupd_cnt(t);\n}\nvoid insert(ref nitem t,nitem it)\n{\n\tnitem l,r;\n\tsplit(t,it.key,l,r);\n\tmerge(l,l,it);\n\tmerge(t,l,r);\n\tupd_cnt(t);\n}\n\nvoid erase(ref nitem t,int key)\n{\n\tif(t.key==key)merge(t,t.l,t.r);\n\telse erase(key<t.key?t.l:t.r,key);\n}\n\nvoid main()\n{\n\tint n,k;\nloop:while(read(n,k))\n\t{\n\t\tauto w=arread!int;\n\t\tsort(w);\n\t\tint ans=0;\n\t\tforeach(x;w)\n\t\t{\n\t\t\tans+=(x+k-1)/k;\n\t\t}\n\t\twriteln((ans+1)/2);\n\t}\n\t//debug system(\"pause\");\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\nloop:while(read(n,k))\n\t{\n\t\tauto w=arread!int;\n\t\tsort(w);\n\t\tint ans=0;\n\t\tforeach(x;w)\n\t\t{\n\t\t\tans+=(x+k-1)/k;\n\t\t}\n\t\twriteln((ans+1)/2);\n\t}\n\t//debug system(\"pause\");\n}"}], "negative_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~\"\\n\", ptrs)==ptrs.length;}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\nloop:while(read(&n,&k))\n\t{\n\t\tauto w=arread!int;\n\t\tsort(w);\n\t\tint ans=0;\n\t\tforeach(p;0..n-1)\n\t\t{\n\t\t\tans+=w[p]/(2*k);\n\t\t\tw[p]%=2*k;\n\t\t\tif(w[p]==0)continue;\n\t\t\tans++;\n\t\t\tif(w[p]<=k)w[p+1]-=k;\n\t\t\tw[p]=0;\n\t\t}\n\t\tif(w[n-1]>0)\n\t\t{\n\t\t\tans+=w[n-1]/(2*k);\n\t\t\tw[n-1]%=2*k;\n\t\t\tif(w[n-1])ans++;\n\t\t}\n\t\twriteln(ans);\n\t}\n\t//debug system(\"pause\");\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~\"\\n\", ptrs)==ptrs.length;}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\nloop:while(read(&n,&k))\n\t{\n\t\tauto w=arread!int;\n\t\tsort(w);\n\t\tint ans=0;\n\t\tforeach(x;w)\n\t\t{\n\t\t\tans+=(x+k-1)/k;\n\t\t}\n\t\twriteln(ans);\n\t}\n\t//debug system(\"pause\");\n}"}], "src_uid": "3992602be20a386f0ec57c51e14b39c5"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimmutable int MN = 100010;\nimmutable int MK = 105;\nimmutable int MD = cast(int)(1e9+7.1);\n\nint main() {\n long[MK][] b = new long[MK][](MN);\n long[MK][] c = new long[MK][](MN+MK);\n\n c[0][0] = 1;\n foreach (i; 1..MN+MK) {\n c[i][0] = 1;\n c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;\n }\n\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[] input = split(readln());\n long[] a = new long[](n);\n foreach (i; 0..n) {\n a[i] = to!int(input[i]);\n }\n foreach (i; 0..m) {\n int l, r, k;\n readf(\"%d %d %d\\n\", &l, &r, &k); l--;\n int f = 1;\n foreach_reverse (j; 0..k+1) {\n b[l][j] += c[l][k-j]*f; b[l][j] %= MD;\n b[r][j] -= c[l][k-j]*f; b[r][j] %= MD;\n f = -f;\n }\n }\n long[] b1 = new long[](MK);\n foreach (i; 0..n) {\n b1[] += b[i][];\n b1[] %= MD;\n for (int k = 0; k < MK; k++) {\n a[i] += b1[k]*c[i+k][k]%MD; a[i] %= MD;\n }\n a[i] = (a[i]+MD)%MD;\n }\n writeln(join(map!(to!string)(a[0..n]), \" \"));\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimmutable int MN = 100010;\nimmutable int MK = 105;\nimmutable int MD = cast(int)(1e9+7.1);\n\nint main() {\n long[MK][] b = new long[MK][](MN);\n long[MK][] c = new long[MK][](MN+MK);\n\n c[0][0] = 1;\n foreach (i; 1..MN+MK) {\n c[i][0] = 1;\n c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;\n }\n\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[] input = split(readln());\n long[] a = new long[](n);\n for (int i = 0; i < n; i++) {\n a[i] = to!int(input[i]);\n }\n for (int i = 0; i < m; i++) {\n int l, r, k;\n readf(\"%d %d %d\\n\", &l, &r, &k); l--;\n int f = 1;\n foreach_reverse (j; 0..k+1) {\n b[l][j] += c[l][k-j]*f; b[l][j] %= MD;\n b[r][j] -= c[l][k-j]*f; b[r][j] %= MD;\n f = -f;\n }\n }\n long[] b1 = new long[](MK);\n foreach (i; 0..n) {\n b1[] += b[i][];\n b1[] %= MD;\n for (int k = 0; k < MK; k++) {\n a[i] += b1[k]*c[i+k][k]%MD; a[i] %= MD;\n }\n a[i] = (a[i]+MD)%MD;\n }\n writeln(join(map!(to!string)(a[0..n]), \" \"));\n return 0;\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimmutable int MN = 100010;\nimmutable int MK = 105;\nimmutable int MD = cast(int)(1e9+7.1);\n\nint main() {\n long[MK][] b = new long[MK][](MN);\n long[MK][] c = new long[MK][](MN+MK);\n c[0][0] = 1;\n for (int i = 1; i < MN+MK; i++) {\n c[i][0] = 1;\n c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;\n }\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[] input = split(readln());\n long[] a = new long[](n);\n foreach (i, s; input) {\n a[i] = to!int(s);\n }\n for (int i = 0; i < m; i++) {\n int l, r, k;\n readf(\"%d %d %d\\n\", &l, &r, &k); l--;\n int f = 1;\n for (int j = 0; j <= k; j++) {\n b[l][k-j] += c[l][j]*f; b[l][k-j] %= MD;\n b[r][k-j] -= c[l][j]*f; b[r][k-j] %= MD;\n f = -f;\n }\n }\n long b1[MK];\n for (int i = 0; i < n; i++) {\n long r = a[i];\n b1[] += b[i][];\n b1[] %= MD;\n for (int k = 0; k < MK; k++) {\n r += b1[k]*c[i+k][k]%MD; r %= MD;\n }\n r = (r+MD)%MD;\n write(cast(int)r);\n if (i == n-1) {\n write(\"\\n\");\n } else {\n write(\" \");\n }\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimmutable int MN = 100010;\nimmutable int MK = 105;\nimmutable int MD = cast(int)(1e9+7.1);\n\nint main() {\n long[][] b = new long[][](MN, MK);\n long[][] c = new long[][](MN+MK, MK);\n c[0][0] = 1;\n for (int i = 1; i < MN+MK; i++) {\n c[i][0] = 1;\n c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;\n }\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[] input = split(readln());\n auto a = map!(to!int)(input[]);\n for (int i = 0; i < m; i++) {\n int l, r, k;\n readf(\"%d %d %d\\n\", &l, &r, &k); l--;\n int f = 1;\n for (int j = 0; j <= k; j++) {\n b[l][k-j] += c[l][j]*f; b[l][k-j] %= MD;\n b[r][k-j] -= c[l][j]*f; b[r][k-j] %= MD;\n f = -f;\n }\n }\n long b1[MK];\n for (int i = 0; i < n; i++) {\n long r = a[i];\n b1[] += b[i][];\n b1[] %= MD;\n for (int k = 0; k < MK; k++) {\n r += b1[k]*c[i+k][k]%MD; r %= MD;\n }\n r = (r+MD)%MD;\n write(cast(int)r);\n if (i == n-1) {\n write(\"\\n\");\n } else {\n write(\" \");\n }\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimmutable int MN = 100010;\nimmutable int MK = 105;\nimmutable int MD = cast(int)(1e9+7.1);\n\nint main() {\n long[MK][] b = new long[MK][MN];\n long[MK][] c = new long[MK][MN+MK];\n c[0][0] = 1;\n for (int i = 1; i < MN+MK; i++) {\n c[i][0] = 1;\n c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;\n }\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[] input = split(readln());\n auto a = map!(to!int)(input[]);\n for (int i = 0; i < m; i++) {\n int l, r, k;\n readf(\"%d %d %d\\n\", &l, &r, &k); l--;\n int f = 1;\n for (int j = 0; j <= k; j++) {\n b[l][k-j] += c[l][j]*f; b[l][k-j] %= MD;\n b[r][k-j] -= c[l][j]*f; b[r][k-j] %= MD;\n f = -f;\n }\n }\n long b1[MK];\n for (int i = 0; i < n; i++) {\n long r = a[i];\n b1[] += b[i][];\n b1[] %= MD;\n for (int k = 0; k < MK; k++) {\n r += b1[k]*c[i+k][k]%MD; r %= MD;\n }\n r = (r+MD)%MD;\n write(cast(int)r);\n if (i == n-1) {\n write(\"\\n\");\n } else {\n write(\" \");\n }\n }\n return 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimmutable int MN = 100010;\nimmutable int MK = 105;\nimmutable int MD = cast(int)(1e9+7.1);\n\nint main() {\n long[MK][] b = new long[MK][](MN);\n long[MK][] c = new long[MK][](MN+MK);\n\n c[0][0] = 1;\n foreach (i; 1..MN+MK) {\n c[i][0] = 1;\n c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;\n }\n\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[] input = split(readln());\n long[] a = new long[](n);\n for (int i = 0; i < n; i++) {\n a[i] = to!int(input[i]);\n }\n for (int i = 0; i < m; i++) {\n int l, r, k;\n readf(\"%d %d %d\\n\", &l, &r, &k); l--;\n int f = 1;\n foreach_reverse (j; 0..k+1) {\n b[l][j] += c[l][k-j]*f; b[l][j] %= MD;\n b[r][j] -= c[l][k-j]*f; b[r][j] %= MD;\n f = -f;\n }\n }\n long[] b1 = new long[](MK);\n long[] r = new long[](n);\n foreach (i; 0..n) {\n b1[] += b[i][];\n b1[] %= MD;\n for (int k = 0; k < MK; k++) {\n r[i] += b1[k]*c[i+k][k]%MD; r[i] %= MD;\n }\n r[i] = (r[i]+MD)%MD;\n }\n writeln(join(map!(to!string)(r), \" \"));\n return 0;\n}\n"}], "src_uid": "d0f81a3fb97fbdbed1b72d013c2f6ed5"} {"source_code": "import std.stdio;\n\nvoid main() {\n int n, k;\n int[1005] count;\n \n readf(\" %s %s\", n, k);\n foreach(i; 0..n) {\n int a;\n readf(\" %s\", a);\n count[a]++;\n }\n\n int odds = 0;\n foreach(c; count) {\n if (c % 2 == 1) {\n odds++;\n }\n }\n\n int result = n - odds / 2;\n writeln(result);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto k = RD!int;\n\tauto cnt = new long[](k);\n\tforeach (i; 0..n)\n\t{\n\t\tauto a = RD!int-1;\n\t\t++cnt[a];\n\t}\n\tlong ans;\n\tlong used;\n\tforeach (i; 0..k)\n\t{\n\t\tauto c = cnt[i] / 2;\n\t\tans += c * 2;\n\t\tused += c;\n\t\tcnt[i] -= c * 2;\n\t}\n\tauto remain = n - used * 2 + n % 2;\n\tans += remain / 2;\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\tint k = read.to!int;\n\t\n\tint[] as;\n\tforeach(i; 0 .. n) as ~= read.to!int;\n\t\n\tint[int] ac;\n\tforeach(a; as){\n\t\tif(a !in ac) ac[a] = 0;\n\t\tac[a] += 1;\n\t}\n\t\n\tint ans;\n\tint ocnt = n % 2;\n\tint[] ks = ac.keys;\n\tforeach(a; ks){\n\t\tint c = ac[a];\n\t\tif(c % 2 == 0) ans += c;\n\t\telse{\n\t\t\tif(ocnt >= 1) ans += c, ocnt = 0;\n\t\t\telse ans += c - 1, ocnt = 1;\n\t\t}\n\t\tlog(\"a:\", a, \"cnt:\", c, \"ocnt:\", ocnt, \"ans:\", ans);\n\t}\n\t\n\tans.writeln;\n}\n"}], "negative_code": [], "src_uid": "dceeb739a56bb799550138aa8c127996"} {"source_code": "\nimport std;\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\tif(a.length==1){ writeln(0); continue; }\n\t\tint u=iota(n).maxElement!(i=>a[i]);\n\t\tint v=iota(n).minElement!(i=>a[i]);\n\t\tif(v<u) swap(u,v);\n\t\tint solve(R)(R x){\n\t\t\tif(x.length<=1) return 0;\n\t\t\tint mini=0,maxi=1,r=1;\n\t\t\tif(x[mini]>x[maxi]) swap(mini,maxi);\n\t\t\tfor(int i=2;i<x.length;i++){\n\t\t\t\tif(x[i]<x[mini]){\n\t\t\t\t\tr+=mini<maxi;\n\t\t\t\t\tmini=i;\n\t\t\t\t}\n\t\t\t\tif(x[i]>x[maxi]){\n\t\t\t\t\tr+=maxi<mini;\n\t\t\t\t\tmaxi=i;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn r;\n\t\t}\n\t\twriteln(solve(a[0..u+1])+1+solve(a[v..$].retro));\n\t}\n}\n", "positive_code": [{"source_code": "\nimport std;\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\tif(a.length==1){ writeln(0); continue; }\n\t\tint u=iota(n).maxElement!(i=>a[i]);\n\t\tint v=iota(n).minElement!(i=>a[i]);\n\t\tif(v<u) swap(u,v);\n\t\tint solve(R)(R x){\n\t\t\tif(x.length<=1) return 0;\n\t\t\tint mini=0,maxi=1,r=1;\n\t\t\tif(x[mini]>x[maxi]) swap(mini,maxi);\n\t\t\tfor(int i=2;i<x.length;i++){\n\t\t\t\tif(x[i]<x[mini]){\n\t\t\t\t\tif(maxi<mini){\n\t\t\t\t\t\tmini=i;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tmini=i;\n\t\t\t\t\t\tr++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(x[i]>x[maxi]){\n\t\t\t\t\tif(mini<maxi){\n\t\t\t\t\t\tmaxi=i;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tmaxi=i;\n\t\t\t\t\t\tr++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn r;\n\t\t}\n\t\twriteln(solve(a[0..u+1])+1+solve(a[v..$].retro));\n\t}\n}\n"}, {"source_code": "import std;\n\nstruct S(alias op,alias \u03b5){\n\talias T=typeof(\u03b5);\n\tint n;\n\tT[] b;\n\tthis(R)(R a){\n\t\tn=to!int(a.length);\n\t\tb=\u03b5.repeat(4*n).array;\n\t\tT build(int l,int r,int i){\n\t\t\tif(l+1==r) return b[i]=a[l];\n\t\t\tint m=(l+r)/2;\n\t\t\treturn b[i]=op(build(l,m,2*i),build(m,r,2*i+1));\n\t\t}\n\t\tbuild(0,n,1);\n\t}\n\tauto query(int ql,int qr){\n\t\tauto query_rec(int l,int r,int i){\n\t\t\tif(qr<=l||r<=ql) return \u03b5;\n\t\t\tif(ql<=l&&r<=qr) return b[i];\n\t\t\tint m=(l+r)/2;\n\t\t\treturn op(query_rec(l,m,2*i),query_rec(m,r,2*i+1));\n\t\t}\n\t\treturn query_rec(0,n,1);\n\t}\n\tvoid opIndexAssign(T value,int k){\n\t\tT update_rec(int l,int r,int i){\n\t\t\tif(k<l||r<=k) return \u03b5;\n\t\t\tif(l+1==r) return b[i]=value;\n\t\t\tint m=(l+r)/2;\n\t\t\treturn b[i]=op(update_rec(l,m,2*i),update_rec(m,r,2*i+1));\n\t\t}\n\t\tupdate_rec(0,n,1);\n\t}\n}\n\nenum inf=to!int(3e5);\n\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto a=readln.strip.split.to!(int[]).map!(x=>x-1).array;\n\t\tauto maxtree=S!(max,tuple(0,-1))(a.zip(iota(n)));\n\t\tauto mintree=S!(min,tuple(inf,-1))(a.zip(iota(n)));\n\t\tauto ip=0.repeat(n).array;\n\t\tforeach(i,x;a) ip[x]=to!int(i);\n\t\tauto indextree=S!(min,n)(n.repeat(n));\n\t\tauto next_smaller=n.repeat(n).array;\n\t\tauto next_larger=n.repeat(n).array;\n\t\tforeach_reverse(i;0..n){\n\t\t\tnext_smaller[i]=indextree.query(0,a[i]);\n\t\t\tnext_larger[i]=indextree.query(a[i],n);\n\t\t\tindextree[a[i]]=i;\n\t\t}\n\t\tauto dist=chain(only(0),inf.repeat(n)).array;\n\t\tforeach(i;0..n-1){\n\t\t\tint[2] u=[\n\t\t\t\tmaxtree.query(i+1,min(n,next_smaller[i]+1))[1],\n\t\t\t\tmintree.query(i+1,min(n,next_larger[i]+1))[1],\n\t\t\t];\n\t\t\tforeach(j;u) dist[j]=min(dist[j],dist[i]+1);\n\t\t}\n\t\twriteln(dist[n-1]);\n\t}\n}\n"}], "negative_code": [{"source_code": "\nimport std;\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\tint mini=0,maxi=0,r=0;\n\t\tfor(int i=1;i<n;i++){\n\t\t\tr+=a[i]<a[mini]&&mini<=maxi;\n\t\t\tr+=a[i]>a[maxi]&&maxi<=mini;\n\t\t\tif(a[i]<a[mini]){\n\t\t\t\tif(mini<maxi) maxi=i;\n\t\t\t\tmini=i;\n\t\t\t}\n\t\t\tif(a[i]>a[maxi]){\n\t\t\t\tif(maxi<mini) mini=i;\n\t\t\t\tmaxi=i;\n\t\t\t}\n\t\t}\n\t\tr+=(mini!=n-1&&maxi!=n-1);\n\t\twriteln(r);\n\t}\n}\n"}, {"source_code": "import std;\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\tint mini=0,maxi=0,r=0;\n\t\tfor(int i=1;i<n;i++){\n\t\t\tr+=a[i]<a[mini]&&mini<=maxi;\n\t\t\tr+=a[i]>a[maxi]&&maxi<=mini;\n\t\t\tif(a[i]<a[mini]){\n\t\t\t\tif(mini<maxi) maxi=i;\n\t\t\t\tmini=i;\n\t\t\t}\n\t\t\tif(a[i]>a[maxi]){\n\t\t\t\tif(maxi<mini) mini=i;\n\t\t\t\tmaxi=i;\n\t\t\t}\n\t\t}\n\t\tr+=(mini!=n-1&&maxi!=n-1);\n\t\twriteln(r);\n\t}\n}\n"}, {"source_code": "import std;\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\tint mini=0,maxi=0,r=0;\n\t\tfor(int i=1;i<n;i++){\n\t\t\tr+=a[i]<a[mini]&&mini<=maxi;\n\t\t\tr+=a[i]>a[maxi]&&maxi<=mini;\n\t\t\tif(a[i]<a[mini]) mini=i;\n\t\t\tif(a[i]>a[maxi]) maxi=i;\n\t\t}\n\t\tr+=(mini!=n-1&&mini!=0)+(maxi!=n-1&&maxi!=0);\n\t\twriteln(r);\n\t}\n}\n"}], "src_uid": "2592836c1457efda9ad333524abfdf56"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto uf = new UnionFind(N);\n foreach (_; 0..N-1) {\n s = readln.split.map!(to!int);\n if (s[2] == 0) {\n uf.unite(s[0]-1, s[1]-1);\n }\n }\n\n long ans = powmod(N, K, MOD);\n\n foreach (i; 0..N) {\n if (uf.find(i) != i) continue;\n long x = -uf.table[i];\n ans -= powmod(x, K, MOD);\n ans %= MOD;\n }\n\n ans = (ans + MOD) % MOD;\n ans.writeln;\n}\n\n\nclass UnionFind {\n int N;\n int[] table;\n\n this(int n) {\n N = n;\n table = new int[](N);\n fill(table, -1);\n }\n\n int find(int x) {\n return table[x] < 0 ? x : (table[x] = find(table[x]));\n }\n\n void unite(int x, int y) {\n x = find(x);\n y = find(y);\n if (x == y) return;\n if (table[x] > table[y]) swap(x, y);\n table[x] += table[y];\n table[y] = x;\n }\n}\n\nlong powmod(long a, long x, long m) {\n long ret = 1;\n while (x) {\n if (x % 2) ret = ret * a % m;\n a = a * a % m;\n x /= 2;\n }\n return ret;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass DisjointSet {\n private:\n int [] p, h, s;\n int n;\n public:\n this (int _n) {\n n = _n;\n p = iota (0, n).array;\n h = new int[n];\n s = uninitializedArray!(int[])(n);\n s[] = 1;\n }\n int findSet (int x) pure nothrow @nogc {\n if (p[x] == x) {\n return x;\n }\n return p[x] = findSet (p[x]);\n }\n void merge (int i, int j) pure nothrow @nogc {\n i = findSet (i);\n j = findSet (j);\n if (i != j) {\n if (h[i] < h[j]) {\n p[i] = j;\n s[j] = s[i] + s[j];\n } else if (h[i] > h[j]) {\n p[j] = i;\n s[i] = s[i] + s[j];\n } else {\n p[i] = j;\n ++h[j];\n s[j] = s[i] + s[j];\n }\n }\n }\n}\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n}\n\nstruct IntM {\n enum q = 1_000_000_007;\n int v;\n this (int m) pure nothrow @nogc {\n v = m % q;\n if (v < 0) {\n v += q;\n }\n }\n IntM opAssign (int m) pure nothrow @nogc {\n v = m % q;\n if (v < 0) {\n v += q;\n }\n return this;\n }\n IntM opUnary (string op : \"-\")() const pure nothrow @nogc {\n return IntM ((q - v) % q);\n }\n ref IntM opOpAssign (string op : \"+\")(in IntM rhs) pure nothrow @nogc {\n v += rhs.v;\n v %= q;\n return this;\n }\n ref IntM opOpAssign (string op : \"-\")(in IntM rhs) pure nothrow @nogc {\n v -= rhs.v;\n v %= q;\n return this;\n }\n ref IntM opOpAssign (string op : \"*\")(in IntM rhs) pure nothrow @nogc {\n v = ((v.to!(long)) * rhs.v.to!(long)) % q;\n return this;\n }\n IntM opBinary (string op : \"+\")(in IntM rhs) const pure nothrow @nogc {\n return IntM ( (v + rhs.v) % q);\n }\n IntM opBinary (string op : \"-\")(in IntM rhs) const pure nothrow @nogc {\n return IntM ( (v - rhs.v) % q);\n }\n IntM opBinary (string op : \"*\")(in IntM rhs) const pure nothrow @nogc {\n return IntM (((v.to!(long)) * rhs.v.to!(long)) % q);\n }\n IntM opBinary (string op : \"^^\")(in int rhs) const pure nothrow @nogc {\n IntM a = 1, b = this;\n int p = rhs;\n while (p > 0) {\n //a * (b ^ p) == x ^ rhs\n if (p & 1) {\n a *= b;\n }\n b *= b;\n p >>>= 1;\n }\n return a;\n }\n IntM opBinary (string op)(in int v) const pure nothrow @nogc if (op == \"+\" || op == \"-\" || op == \"*\") {\n mixin (\"return this \" ~ op ~ \" IntM(v);\");\n }\n string toString() const pure nothrow { return ((v < 0) ? v + q : v).text; }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!uint;\n immutable k = r.next!uint;\n auto ds = new DisjointSet (n);\n foreach (edge; 1 .. n) {\n immutable i = r.next!uint - 1;\n immutable j = r.next!uint - 1;\n immutable c = r.next!uint;\n if (c == 0) {\n ds.merge (i, j);\n }\n }\n int[] x;\n foreach (i; 0 .. n) {\n if (ds.findSet (i) == i) {\n x ~= ds.s[i];\n }\n }\n immutable m = x.length.to!int;\n IntM s;\n foreach (i; x) {\n auto c = IntM (i);\n s += c ^^ k;\n }\n IntM res = IntM (n) ^^ k;\n res -= s;\n write (res);\n}\n\n"}], "negative_code": [], "src_uid": "94559f08866b6136ba4791c440025a68"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n auto nt = r.next!uint;\n foreach (tid; 0 .. nt) {\n auto a = r.nextA!ulong(3);\n sort (a);\n auto s = sum (a);\n long m = (s + 1) / 2;\n if (a[2] > m) {\n writeln (\"No\");\n } else {\n writeln (\"Yes\");\n }\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n auto s = readln.split.map!(to!int).array;\n s.sort();\n auto a = s[0];\n auto b = s[1];\n auto c = s[2];\n if (c <= a + b + 1) {\n writeln(\"Yes\");\n } else {\n writeln(\"No\");\n }\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto r = RD!int;\n\t\tauto g = RD!int;\n\t\tauto b = RD!int;\n\t\tlong[] arr = [r, g, b];\n\t\tarr.sort();\n\t\tans[ti] = arr[2] <= (arr.sum+1)/2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "void main() {\n\tauto t = ri;\n\tforeach(i; 0..t) {\n\t\tauto ip = readAs!(long[]).sort.array;\n\t\tif(ip[2] > ip[0] + ip[1] + 1) writeln(\"No\");\n\t\telse writeln(\"Yes\");\n\t}\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tforeach(_; 0 .. rint){\n\t\tlong a = rlong, b = rlong, c = rlong;\n\t\tlong n = a + b + c;\n\t\tlong m = (n + 1) / 2;\n\t\tif(a > m || b > m || c > m) \"No\".writeln;\n\t\telse \"Yes\".writeln;\n\t}\n}"}], "negative_code": [{"source_code": "void main() {\n\tauto t = ri;\n\tforeach(i; 0..t) {\n\t\tauto ip = readAs!(int[]), r = ip[0], g = ip[1], b = ip[2];\n\t\tif(r > (g + b) || g > (r + b) || b > (r + g)) writeln(\"No\");\n\t\telse writeln(\"Yes\");\n\t}\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}"}, {"source_code": "void main() {\n\tauto t = ri;\n\tforeach(i; 0..t) {\n\t\tauto ip = readAs!(int[]), r = ip[0], g = ip[1], b = ip[2];\n\t\tif(r > (g + b) && g > (r + b) && b > (r + g)) writeln(\"No\");\n\t\telse writeln(\"Yes\");\n\t}\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}"}, {"source_code": "void main() {\n\tauto t = ri;\n\tforeach(i; 0..t) {\n\t\tauto ip = readAs!(int[]).sort.uniq.array;\n\t\tif(ip[2] > ip[0] + ip[1] + 1) writeln(\"No\");\n\t\telse writeln(\"Yes\");\n\t}\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tforeach(_; 0 .. rint){\n\t\tlong a = rlong, b = rlong, c = rlong;\n\t\tlong n = a + b + c;\n\t\tlong m = n / 2;\n\t\tif(a > m || b > m || c > m) \"No\".writeln;\n\t\telse \"Yes\".writeln;\n\t}\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto r = RD!int;\n\t\tauto g = RD!int;\n\t\tauto b = RD!int;\n\t\tauto arr = [r, g, b];\n\t\tarr.sort();\n\t\tans[ti] = arr[2] <= (arr.sum+1)/2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "34aa41871ee50f06e8acbd5eee94b493"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nimmutable int N = 15_000_000 + 10;\n\nvoid main()\n{\n auto dvs = new int[N];\n auto cnt = new int[N];\n \n int n;\n readf(\"%s\", &n);\n readln;\n\n foreach (i; 2 .. N) {\n if (dvs[i] != 0) continue;\n \n dvs[i] = i;\n for (int j = i+i; j < N; j += i) dvs[j] = i;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto gcdnow = arr.fold!gcd;\n arr[] /= gcdnow;\n \n debug { gcdnow.writeln; }\n \n foreach (e; arr) {\n while (e > 1) {\n auto now = dvs[e];\n ++cnt[now];\n while (dvs[e] == now) e /= now;\n }\n }\n \n auto left = cnt[2 .. $].maxElement;\n \n if (left == 0) {\n writeln(-1);\n return;\n }\n \n writeln(n - left);\n}", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nimmutable int N = 15_000_000 + 10;\n\nvoid main()\n{\n auto pr = new bool[N];\n auto cnt = new int[N];\n \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto gcdnow = arr.fold!gcd;\n debug { gcdnow.writeln; }\n \n arr.each!(e => ++cnt[e / gcdnow]);\n \n auto ans = 0;\n pr[] = true;\n foreach (i; 2 .. N) {\n if (!pr[i]) continue;\n \n auto cur = 0;\n for (int j = i; j < N; j += i) {\n cur += cnt[j];\n pr[j] = false;\n }\n \n ans = max(ans, cur);\n }\n \n ans = ans > 0 ? n - ans : -1;\n writeln(ans);\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nimmutable int N = 15_000_000 + 10;\n\nvoid main()\n{\n auto dvs = new int[N];\n auto cnt = new int[N];\n \n int n;\n readf(\"%s\", &n);\n readln;\n\n foreach (i; 2 .. N) {\n if (dvs[i] != 0) continue;\n \n dvs[i] = i;\n for (int j = i+i; j < N; j += i) dvs[j] = i;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto gcdnow = arr.fold!gcd;\n \n debug { gcdnow.writeln; }\n \n foreach (e; arr) {\n while (e > 1) {\n auto now = dvs[e];\n ++cnt[now];\n while (dvs[e] == now) e /= now;\n }\n }\n \n auto left = cnt[gcdnow+1 .. $].maxElement;\n \n if (left == 0) {\n writeln(-1);\n return;\n }\n \n writeln(n - left);\n}"}], "src_uid": "9115965ff3421230eac37b22328c6153"} {"source_code": "import std.algorithm : max, maxElement, sort, swap;\nimport std.conv : to;\nimport std.numeric : gcd;\nimport std.range;\nimport std.stdio;\nimport std.typecons : Tuple, tuple;\nimport std.algorithm.mutation;\n\n// import std.container.array;\n\nstring readToken()\n{\n static string[] tokens;\n while (tokens.empty)\n {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nvoid main()\n{\n int n = readInt;\n auto a = new int[n];\n for (int i = 0; i < n; ++i)\n a[i] = readInt;\n int m = a.maxElement;\n auto cnt = new int[m + 1];\n auto mu = new int[m + 1];\n mu[1] = 1;\n for (int d = 1; d <= m; ++d)\n {\n cnt[d]++;\n for (int i = d * 2; i <= m; i += d)\n cnt[i]++, mu[i] -= mu[d];\n }\n auto divs = new int[][m + 1];\n for (int i = 1; i <= m; ++i)\n divs[i] = new int[cnt[i]];\n fill(cnt, 0);\n for (int d = 1; d <= m; ++d)\n for (int i = d; i <= m; i += d)\n divs[i][cnt[i]++] = d;\n fill(cnt, 0);\n for (int i = 0; i < n; ++i)\n cnt[a[i]]++;\n long result = m;\n int[] stack = new int[m], subcnt = new int[m + 1];\n for (int g = 1; g <= m; ++g)\n {\n int m1 = m / g;\n int top = 0;\n for (int x = m1; x >= 1; --x)\n if (cnt[g * x])\n {\n int coprimes = 0;\n foreach (d; divs[x])\n coprimes += mu[d] * subcnt[d];\n while (coprimes)\n {\n int y = stack[--top];\n if (gcd(x, y) == 1)\n coprimes--, result = max(result, cast(long) g * x * y);\n foreach (d; divs[y])\n subcnt[d]--;\n }\n foreach (d; divs[x])\n subcnt[d]++;\n stack[top++] = x;\n }\n while (top--)\n foreach (d; divs[stack[top]])\n subcnt[d]--;\n }\n writeln(result);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv : to;\nimport std.numeric : gcd;\nimport std.range;\nimport std.stdio;\nimport std.typecons : Tuple, tuple;\n\nstring readToken()\n{\n static string[] tokens;\n while (tokens.empty)\n tokens = readln.split;\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nvoid main()\n{\n int n = readInt;\n auto a = new int[n];\n for (int i = 0; i < n; ++i)\n a[i] = readInt;\n int m = a.maxElement;\n auto cnt = new int[m + 1];\n auto mu = new int[m + 1];\n mu[1] = 1;\n for (int d = 1; d <= m; ++d)\n {\n if (!mu[d])\n continue;\n cnt[d]++;\n for (int i = d * 2; i <= m; i += d)\n cnt[i]++, mu[i] -= mu[d];\n }\n auto divs = new int[][m + 1];\n for (int i = 1; i <= m; ++i)\n divs[i] = new int[cnt[i]];\n fill(cnt, 0);\n for (int d = 1; d <= m; ++d)\n if (mu[d])\n for (int i = d; i <= m; i += d)\n divs[i][cnt[i]++] = d;\n fill(cnt, 0);\n for (int i = 0; i < n; ++i)\n cnt[a[i]]++;\n long result = m;\n int[] stack = new int[m], subcnt = new int[m + 1];\n for (int g = 1; g <= m; ++g)\n {\n int m1 = m / g;\n int top = 0;\n for (int x = m1; x >= 1; --x)\n if (cnt[g * x])\n {\n int coprimes = 0;\n foreach (d; divs[x])\n coprimes += mu[d] * subcnt[d];\n while (coprimes)\n {\n int y = stack[--top];\n if (gcd(x, y) == 1)\n coprimes--, result = max(result, cast(long) g * x * y);\n foreach (d; divs[y])\n subcnt[d]--;\n }\n foreach (d; divs[x])\n subcnt[d]++;\n stack[top++] = x;\n }\n while (top--)\n foreach (d; divs[stack[top]])\n subcnt[d]--;\n }\n writeln(result);\n}\n"}], "negative_code": [], "src_uid": "14c37283d16cb3aa8dd8fc7ea8f1096d"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!T(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n int n;\n read(n);\n string s;\n read(s);\n string rs = s.dup.reverse;\n auto prefix = cast(long) s.countUntil('1');\n if (prefix == -1)\n prefix = n;\n auto suffix = cast(long) rs.countUntil('0');\n if (suffix == -1)\n suffix = n;\n string middle = \"\";\n if (suffix + prefix < n)\n middle = \"0\";\n string res = s[0 .. cast(size_t)prefix] ~ middle ~ s[$ - cast(size_t)suffix .. $];\n writeln(res);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto s = readln.strip;\n\t\tstring res1, res2, res3;\n\t\twhile (!s.empty && s.front == '0')\n\t\t{\n\t\t\tres1 ~= s.front;\n\t\t\ts.popFront ();\n\t\t}\n\t\twhile (!s.empty && s.back == '1')\n\t\t{\n\t\t\tres3 ~= s.back;\n\t\t\ts.popBack ();\n\t\t}\n\t\tif (!s.empty)\n\t\t{\n\t\t\tres2 = \"0\";\n\t\t}\n\t\twriteln (res1 ~ res2 ~ res3);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tint l = n, r = -1;\n\t\tforeach (int i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '1')\n\t\t\t{\n\t\t\t\tl = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tforeach_reverse (int i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '0')\n\t\t\t{\n\t\t\t\tr = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (l < r)\n\t\t\tans[ti] = s[0..l] ~ '0' ~ s[r+1..s.length];\n\t\telse\n\t\t\tans[ti] = s[0..l] ~ s[r+1..s.length];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "bb071f1f4fc1c129a32064c1301f4942"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n Tuple!(int, int)[] ans;\n foreach (i; 2 .. n+1) {\n int prev = i-k < 1 ? 1 : i-k;\n ans ~= tuple(prev, i);\n }\n \n int longerCnt = (n-1)%k;\n int longerVal = (n-1 + k-1)/k;\n int shorterVal = (n-1)/k;\n int dst = longerCnt == 0 ? shorterVal * 2\n : longerCnt == 1 ? shorterVal + longerVal : longerVal * 2;\n writeln(dst);\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[][] graph;\n\nalias Result = Tuple!(int, \"d\", int, \"u\");\n\nResult dfs(int u, int p) {\n auto ret = Result(0, u);\n foreach (v; graph[u]) {\n if (v != p) {\n const res = dfs(v, u);\n chmax(ret, Result(1 + res.d, res.u));\n }\n }\n return ret;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n const K = readInt();\n \n int[][] ans;\n int n = 1 + (N - 1) % K;\n foreach (u; 1 .. n) {\n ans ~= [0, u];\n }\n int a, b;\n if (n == 1) {\n a = 0;\n b = 1;\n } else if (n == 2) {\n a = 0;\n b = 2;\n } else {\n a = 1;\n b = n;\n }\n debug {\n writefln(\"N = %s, K = %s\", N, K);\n writefln(\"n = %s, a = %s, b = %s\", n, a, b);\n }\n for (; n < N; n += K) {\n foreach (k; 0 .. K) {\n ans ~= [a + k % (b - a), n + k];\n }\n a = n;\n b = n + K;\n }\n \n graph = new int[][N];\n foreach (edge; ans) {\n graph[edge[0]] ~= edge[1];\n graph[edge[1]] ~= edge[0];\n }\n const res0 = dfs(0, -1);\n const res1 = dfs(res0.u, -1);\n writeln(res1.d);\n foreach (edge; ans) {\n writeln(edge[0] + 1, \" \", edge[1] + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n Tuple!(int, int)[] ans;\n foreach (i; 2 .. n+1) {\n int prev = i-k < 1 ? 1 : i-k;\n ans ~= tuple(prev, i);\n }\n \n int longerCnt = (n-1)%k;\n int longerVal = (n-1 + k-1)/k;\n int shorterVal = (n-1)/k;\n int dst = longerCnt == 0 ? shorterVal * 2\n : longerCnt == 1 ? shorterVal + longerVal : 2 * longerVal;\n writeln(dst);\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n Tuple!(int, int)[] ans;\n \n void star(int sz) {\n foreach (i; 2 .. sz+1) {\n ans ~= tuple(1, i);\n }\n }\n \n if (k == n-1) {\n star(n);\n writeln(2);\n ans.each!(t => writeln(t[0], ' ', t[1]));\n } else {\n star(k+1);\n foreach (i; k+1 .. n) {\n ans ~= tuple(i, i+1);\n }\n \n writeln(n - (k-1));\n ans.each!(t => writeln(t[0], ' ', t[1]));\n }\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n Tuple!(int, int)[] ans;\n \n void star(int sz) {\n foreach (i; 2 .. sz+1) {\n ans ~= tuple(1, i);\n }\n }\n \n if (k == n-1) {\n star(n);\n writeln(2);\n ans.each!(t => writeln(t[0], ' ', t[1]));\n } else {\n star(k+1);\n foreach (i; k+2 .. n) {\n ans ~= tuple(i, i+1);\n }\n \n writeln(n - (k-1));\n ans.each!(t => writeln(t[0], ' ', t[1]));\n }\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n Tuple!(int, int)[] ans;\n foreach (i; 2 .. n+1) {\n int prev = i-k < 1 ? 1 : i-k;\n ans ~= tuple(prev, i);\n }\n \n writeln((n-1)/k + (n-1 + k-1)/k);\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n Tuple!(int, int)[] ans;\n \n void star(int sz) {\n foreach (i; 2 .. sz+1) {\n ans ~= tuple(1, i);\n }\n }\n \n if (k == n-1) {\n star(n);\n } else if (k == n-2) {\n star(n-2);\n ans ~= tuple(1, n-1);\n ans ~= tuple(n-1, n);\n } else {\n star(k+1);\n foreach (i; k+2 .. n) {\n ans ~= tuple(i, i+1);\n }\n ans ~= tuple(n, 1);\n }\n \n ans.length.writeln;\n foreach (t; ans) {\n writeln(t[0], ' ', t[1]);\n }\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n Tuple!(int, int)[] ans;\n \n void star(int sz) {\n foreach (i; 2 .. sz+1) {\n ans ~= tuple(1, i);\n }\n }\n \n if (k == n-1) {\n star(n);\n writeln(2);\n ans.each!(t => writeln(t[0], ' ', t[1]));\n } else {\n star(k);\n foreach (i; k .. n) {\n ans ~= tuple(i, i+1);\n }\n \n writeln(n - (k-1));\n ans.each!(t => writeln(t[0], ' ', t[1]));\n }\n}"}], "src_uid": "ad49b1b537ca539ea0898ee31a0aecf8"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint rows, cols, sRow, sCol;\n\twhile (readf !(\" %s %s %s %s\") (rows, cols, sRow, sCol) > 0)\n\t{\n\t\tauto r = rows.iota.array;\n\t\tswap (r[0], r[sRow - 1]);\n\t\tr[] += 1;\n\t\tauto c = cols.iota.array;\n\t\tswap (c[0], c[sCol - 1]);\n\t\tc[] += 1;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tif (row & 1)\n\t\t\t{\n\t\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t\t{\n\t\t\t\t\twriteln (r[row], \" \", c[col]);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach (col; 0..cols)\n\t\t\t\t{\n\t\t\t\t\twriteln (r[row], \" \", c[col]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1395/problem/B\n// implementation\nimport std.stdio;\n\nvoid main() {\n int n, m, sx, sy;\n readf(\"%s %s %s %s\", &n, &m, &sx, &sy);\n\n writefln(\"%s %s\", sx, sy);\n\n for(int i = 1; i <= n; i++)\n if(i != sx)\n writefln(\"%s %s\", i, sy);\n\n for(int i =1; i <= m; i++) {\n if(i == sy)\n continue;\n int direction = i&1;\n if(i > sy)\n direction ^= 1;\n if(direction == 1)\n for(int j = n; j > 0; j--)\n writefln(\"%s %s\", j, i);\n else\n for(int j = 1; j <= n; j++)\n writefln(\"%s %s\", j, i);\n }\n}\n\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m, sx, sy;\n\n void solve(long tc = -1)\n {\n foreach(y; sy .. m + 1)\n {\n writeln(sx, \" \", y);\n }\n foreach_reverse(y; 1 .. sy)\n {\n writeln(sx, \" \", y);\n }\n bool bottom = true;\n foreach(col; 1 .. n + 1)\n if (col != sx)\n {\n if (bottom)\n {\n foreach(y; 1 .. m + 1)\n {\n writeln(col, \" \", y);\n }\n }\n else\n {\n foreach_reverse(y; 1 .. m + 1)\n {\n writeln(col, \" \", y);\n }\n }\n bottom = !bottom;\n }\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\t\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto sx = RD!int;\n\tauto sy = RD!int;\n\n\tint[][] ans;\n\tforeach_reverse (y; 1..sy+1)\n\t{\n\t\tans ~= [sx, y];\n\t}\n\tforeach (y; sy+1..m+1)\n\t{\n\t\tans ~= [sx, y];\n\t}\n\tauto x = sx-1;\n\tauto y = m;\n\tans ~= [x, y];\n\tint dir = -1;\n\twhile (true)\n\t{\n\t\t//debug writeln(x, \" \", y);\n\t\ty += dir;\n\t\tif (y == 0 || y == m+1)\n\t\t{\n\t\t\tdir = -dir;\n\t\t\ty += dir;\n\t\t\t--x;\n\t\t\tif (x == 0) break;\n\t\t}\n\t\tans ~= [x, y];\n\t}\n\n\tx = sx+1;\n\tans ~= [x, y];\n\twhile (true)\n\t{\n\t\t//debug writeln(x, \" \", y);\n\t\ty += dir;\n\t\tif (y == 0 || y == m+1)\n\t\t{\n\t\t\tdir = -dir;\n\t\t\ty += dir;\n\t\t\t++x;\n\t\t\tif (x == n+1) break;\n\t\t}\n\t\tans ~= [x, y];\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0], \" \", e[1]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1395/problem/B\n// implementation\nimport std.stdio;\n\nvoid main() {\n int n, m, sx, sy;\n readf(\"%s %s %s %s\", &n, &m, &sx, &sy);\n\n writefln(\"%s %s\", sx, sy);\n\n for(int i = 1; i <= n; i++)\n if(i != sx)\n writefln(\"%s %s\", i, sx);\n\n for(int i =1; i <= m; i++) {\n if(i == sy)\n continue;\n int direction = i&1;\n if(i > sy)\n direction ^= 1;\n if(direction == 1)\n for(int j = n; j > 0; j--)\n writefln(\"%s %s\", j, i);\n else\n for(int j = 1; j <= n; j++)\n writefln(\"%s %s\", j, i);\n }\n}\n\n"}], "src_uid": "ed26479cdf72ad9686bbf334d90aa0be"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nint [] prepare (int limit)\r\n{\r\n\tauto res = limit.iota.array;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d] == d)\r\n\t\t{\r\n\t\t\tfor (int e = d * d; e < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\tif (res[e] == e)\r\n\t\t\t\t{\r\n\t\t\t\t\tres[e] = d;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nint [] roots (int limit)\r\n{\r\n\tauto p = prepare (limit);\r\n\tauto res = new int [limit];\r\n\tforeach (d; 0..limit)\r\n\t{\r\n\t\tint cur = d;\r\n\t\tres[d] = 1;\r\n\t\twhile (cur > 1)\r\n\t\t{\r\n\t\t\tbool parity = 0;\r\n\t\t\tint x = p[cur];\r\n\t\t\twhile (cur % x == 0)\r\n\t\t\t{\r\n\t\t\t\tcur /= x;\r\n\t\t\t\tparity ^= 1;\r\n\t\t\t}\r\n\t\t\tif (parity)\r\n\t\t\t{\r\n\t\t\t\tres[d] *= x;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nimmutable int limit = 10 ^^ 6 + 5;\r\n \r\nvoid main ()\r\n{\r\n\tauto r = roots (limit);\r\n \r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint [int] nums;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tnums[r[c]] += 1;\r\n\t\t}\r\n\t\tauto answer = [0, 0, 0];\r\n\t\tforeach (step; 0..3)\r\n\t\t{\r\n\t\t\tdebug {writeln (nums);}\r\n\t\t\tint [int] next;\r\n\t\t\tforeach (k, v; nums)\r\n\t\t\t{\r\n\t\t\t\tanswer[step] = max (answer[step], v);\r\n\t\t\t\tint p = (v & 1) ? k : 1;\r\n\t\t\t\tnext[p] += v;\r\n\t\t\t}\r\n\t\t\tnums = next;\r\n\t\t}\r\n \r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (s; 0..q)\r\n\t\t{\r\n\t\t\tauto z = readln.strip.to !(long);\r\n\t\t\twriteln (answer[min (z, $ - 1).to !(int)]);\r\n\t\t}\r\n\t}\r\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nenum PCNT = 10^^3;\r\n\r\nbool[PCNT+1] PS;\r\n\r\nvoid prime_init()\r\n{\r\n PS[] = true;\r\n PS[0] = false;\r\n PS[1] = false;\r\n foreach (i; 2..PCNT+1) {\r\n if (PS[i]) {\r\n auto x = i*2;\r\n while (x <= PCNT) {\r\n PS[x] = false;\r\n x += i;\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n prime_init();\r\n long[] ps;\r\n foreach (i; 0..PCNT + 1) if (PS[i]) ps ~= i;\r\n\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n long[] AS; get(AS);\r\n\r\n foreach (ref a; AS) foreach (p; ps) while (a % p^^2 == 0) a /= p^^2;\r\n sort(AS);\r\n AS ~= -1;\r\n long last = -1, cnt, one_and_evens, max_r;\r\n foreach (i, a; AS) {\r\n if (a != last) {\r\n max_r = max(max_r, cnt);\r\n if (last == 1 || cnt % 2 == 0) one_and_evens += cnt;\r\n cnt = 1;\r\n last = a;\r\n } else {\r\n ++cnt;\r\n }\r\n }\r\n auto r0 = max_r;\r\n auto r1 = max(max_r, one_and_evens);\r\n\r\n int Q; get(Q);\r\n while (Q--) {\r\n long W; get(W);\r\n writeln(W == 0 ? r0 : r1);\r\n }\r\n }\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint [] prepare (int limit)\r\n{\r\n\tauto res = limit.iota.array;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d] == d)\r\n\t\t{\r\n\t\t\tfor (int e = d * d; e < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\tif (res[e] == e)\r\n\t\t\t\t{\r\n\t\t\t\t\tres[e] = d;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nint [] roots (int limit)\r\n{\r\n\tauto p = prepare (limit);\r\n\tauto res = new int [limit];\r\n\tforeach (d; 0..limit)\r\n\t{\r\n\t\tint cur = d;\r\n\t\tres[d] = 1;\r\n\t\twhile (cur > 1)\r\n\t\t{\r\n\t\t\tbool parity = 0;\r\n\t\t\tint x = p[cur];\r\n\t\t\twhile (cur % x == 0)\r\n\t\t\t{\r\n\t\t\t\tcur /= x;\r\n\t\t\t\tparity ^= 1;\r\n\t\t\t}\r\n\t\t\tif (parity)\r\n\t\t\t{\r\n\t\t\t\tres[d] *= x;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nimmutable int limit = 10 ^^ 6 + 5;\r\n\r\nvoid main ()\r\n{\r\n\tauto r = roots (limit);\r\n\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tint [int] nums;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tnums[r[c]] += 1;\r\n\t\t}\r\n\r\n\t\tauto answer = [0, 0, 0];\r\n\t\tforeach (step; 0..3)\r\n\t\t{\r\n\t\t\tdebug {writeln (nums);}\r\n\t\t\tint [int] next;\r\n\t\t\tforeach (k, v; nums)\r\n\t\t\t{\r\n\t\t\t\tanswer[step] = max (answer[step], v);\r\n\t\t\t\tint p = (v & 1) ? k : 1;\r\n\t\t\t\tnext[p] += v;\r\n\t\t\t}\r\n\t\t\tnums = next;\r\n\t\t}\r\n\r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (s; 0..q)\r\n\t\t{\r\n\t\t\tauto z = readln.strip.to !(long);\r\n\t\t\twriteln (answer[min (z, $ - 1).to !(int)]);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nint [] prepare (int limit)\r\n{\r\n\tauto res = limit.iota.array;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d] == d)\r\n\t\t{\r\n\t\t\tfor (int e = d * d; e < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\tif (res[e] == e)\r\n\t\t\t\t{\r\n\t\t\t\t\tres[e] = d;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nint [] roots (int limit)\r\n{\r\n\tauto p = prepare (limit);\r\n\tauto res = new int [limit];\r\n\tforeach (d; 0..limit)\r\n\t{\r\n\t\tint cur = d;\r\n\t\tres[d] = 1;\r\n\t\twhile (cur > 1)\r\n\t\t{\r\n\t\t\tbool parity = 0;\r\n\t\t\tint x = p[cur];\r\n\t\t\twhile (cur % x == 0)\r\n\t\t\t{\r\n\t\t\t\tcur /= x;\r\n\t\t\t\tparity ^= 1;\r\n\t\t\t}\r\n\t\t\tif (parity)\r\n\t\t\t{\r\n\t\t\t\tres[d] *= x;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nimmutable int limit = 10 ^^ 6 + 5;\r\n \r\nvoid main ()\r\n{\r\n\tauto r = roots (limit);\r\n \r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n \r\n\t\tint [int] nums;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tnums[r[c]] += 1;\r\n\t\t}\r\n \r\n\t\tauto answer = [0, 0, 0];\r\n\t\tforeach (step; 0..3)\r\n\t\t{\r\n\t\t\tdebug {writeln (nums);}\r\n\t\t\tint [int] next;\r\n\t\t\tforeach (k, v; nums)\r\n\t\t\t{\r\n\t\t\t\tanswer[step] = max (answer[step], v);\r\n\t\t\t\tint p = (v & 1) ? k : 1;\r\n\t\t\t\tnext[p] += v;\r\n\t\t\t}\r\n\t\t\tnums = next;\r\n\t\t}\r\n \r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (s; 0..q)\r\n\t\t{\r\n\t\t\tauto z = readln.strip.to !(long);\r\n\t\t\twriteln (answer[min (z, $ - 1).to !(int)]);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nint [] prepare (int limit)\r\n{\r\n\tauto res = limit.iota.array;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d] == d)\r\n\t\t{\r\n\t\t\tfor (int e = d * d; e < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\tif (res[e] == e)\r\n\t\t\t\t{\r\n\t\t\t\t\tres[e] = d;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nint [] roots (int limit)\r\n{\r\n\tauto p = prepare (limit);\r\n\tauto res = new int [limit];\r\n\tforeach (d; 0..limit)\r\n\t{\r\n\t\tint cur = d;\r\n\t\tres[d] = 1;\r\n\t\twhile (cur > 1)\r\n\t\t{\r\n\t\t\tbool parity = 0;\r\n\t\t\tint x = p[cur];\r\n\t\t\twhile (cur % x == 0)\r\n\t\t\t{\r\n\t\t\t\tcur /= x;\r\n\t\t\t\tparity ^= 1;\r\n\t\t\t}\r\n\t\t\tif (parity)\r\n\t\t\t{\r\n\t\t\t\tres[d] *= x;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nimmutable int limit = 10 ^^ 6 + 5;\r\n \r\nvoid main ()\r\n{\r\n\tauto r = roots (limit);\r\n \r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n \r\n\t\tint [int] nums;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tnums[r[c]] += 1;\r\n\t\t}\r\n \r\n\t\tauto answer = [0, 0, 0];\r\n\t\tforeach (step; 0..3)\r\n\t\t{\r\n\t\t\tdebug {writeln (nums);}\r\n\t\t\tint [int] next;\r\n\t\t\tforeach (k, v; nums)\r\n\t\t\t{\r\n\t\t\t\tanswer[step] = max (answer[step], v);\r\n\t\t\t\tint p = (v & 1) ? k : 1;\r\n\t\t\t\tnext[p] += v;\r\n\t\t\t}\r\n\t\t\tnums = next;\r\n\t\t}\r\n \r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (s; 0..q)\r\n\t\t{\r\n\t\t\tauto z = readln.strip.to !(long);\r\n\t\t\twriteln (answer[min (z, $ - 1).to !(int)]);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nint [] prepare (int limit)\r\n{\r\n\tauto res = limit.iota.array;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d] == d)\r\n\t\t{\r\n\t\t\tfor (int e = d * d; e < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\tif (res[e] == e)\r\n\t\t\t\t{\r\n\t\t\t\t\tres[e] = d;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nint [] roots (int limit)\r\n{\r\n\tauto p = prepare (limit);\r\n\tauto res = new int [limit];\r\n\tforeach (d; 0..limit)\r\n\t{\r\n\t\tint cur = d;\r\n\t\tres[d] = 1;\r\n\t\twhile (cur > 1)\r\n\t\t{\r\n\t\t\tbool parity = 0;\r\n\t\t\tint x = p[cur];\r\n\t\t\twhile (cur % x == 0)\r\n\t\t\t{\r\n\t\t\t\tcur /= x;\r\n\t\t\t\tparity ^= 1;\r\n\t\t\t}\r\n\t\t\tif (parity)\r\n\t\t\t{\r\n\t\t\t\tres[d] *= x;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nimmutable int limit = 10 ^^ 6 + 5;\r\n \r\nvoid main ()\r\n{\r\n\tauto r = roots (limit);\r\n \r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n \r\n\t\tint [int] nums;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tnums[r[c]] += 1;\r\n\t\t}\r\n \r\n\t\tauto answer = [0, 0, 0];\r\n\t\tforeach (step; 0..3)\r\n\t\t{\r\n\t\t\tdebug {writeln (nums);}\r\n\t\t\tint [int] next;\r\n\t\t\tforeach (k, v; nums)\r\n\t\t\t{\r\n\t\t\t\tanswer[step] = max (answer[step], v);\r\n\t\t\t\tint p = (v & 1) ? k : 1;\r\n\t\t\t\tnext[p] += v;\r\n\t\t\t}\r\n\t\t\tnums = next;\r\n\t\t}\r\n \r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (s; 0..q)\r\n\t\t{\r\n\t\t\tauto z = readln.strip.to !(long);\r\n\t\t\twriteln (answer[min (z, $ - 1).to !(int)]);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nint [] prepare (int limit)\r\n{\r\n\tauto res = limit.iota.array;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d] == d)\r\n\t\t{\r\n\t\t\tfor (int e = d * d; e < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\tif (res[e] == e)\r\n\t\t\t\t{\r\n\t\t\t\t\tres[e] = d;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nint [] roots (int limit)\r\n{\r\n\tauto p = prepare (limit);\r\n\tauto res = new int [limit];\r\n\tforeach (d; 0..limit)\r\n\t{\r\n\t\tint cur = d;\r\n\t\tres[d] = 1;\r\n\t\twhile (cur > 1)\r\n\t\t{\r\n\t\t\tbool parity = 0;\r\n\t\t\tint x = p[cur];\r\n\t\t\twhile (cur % x == 0)\r\n\t\t\t{\r\n\t\t\t\tcur /= x;\r\n\t\t\t\tparity ^= 1;\r\n\t\t\t}\r\n\t\t\tif (parity)\r\n\t\t\t{\r\n\t\t\t\tres[d] *= x;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nimmutable int limit = 10 ^^ 6 + 5;\r\n \r\nvoid main ()\r\n{\r\n\tauto r = roots (limit);\r\n \r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint [int] nums;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tnums[r[c]] += 1;\r\n\t\t}\r\n\t\tauto answer = [0, 0, 0];\r\n\t\tforeach (step; 0..3)\r\n\t\t{\r\n\t\t\tdebug {writeln (nums);}\r\n\t\t\tint [int] next;\r\n\t\t\tforeach (k, v; nums)\r\n\t\t\t{\r\n\t\t\t\tanswer[step] = max (answer[step], v);\r\n\t\t\t\tint p = (v & 1) ? k : 1;\r\n\t\t\t\tnext[p] += v;\r\n\t\t\t}\r\n\t\t\tnums = next;\r\n\t\t}\r\n \r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (s; 0..q)\r\n\t\t{\r\n\t\t\tauto z = readln.strip.to !(long);\r\n\t\t\twriteln (answer[min (z, $ - 1).to !(int)]);\r\n\t\t}\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nint [] prepare (int limit)\r\n{\r\n\tauto res = limit.iota.array;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d] == d)\r\n\t\t{\r\n\t\t\tfor (int e = d * d; e < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\tif (res[e] == e)\r\n\t\t\t\t{\r\n\t\t\t\t\tres[e] = d;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nint [] roots (int limit)\r\n{\r\n\tauto p = prepare (limit);\r\n\tauto res = new int [limit];\r\n\tforeach (d; 0..limit)\r\n\t{\r\n\t\tint cur = d;\r\n\t\tres[d] = 1;\r\n\t\twhile (cur > 1)\r\n\t\t{\r\n\t\t\tbool parity = 0;\r\n\t\t\tint x = p[cur];\r\n\t\t\twhile (cur % x == 0)\r\n\t\t\t{\r\n\t\t\t\tcur /= x;\r\n\t\t\t\tparity ^= 1;\r\n\t\t\t}\r\n\t\t\tif (parity)\r\n\t\t\t{\r\n\t\t\t\tres[d] *= x;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n \r\nimmutable int limit = 10 ^^ 6 + 5;\r\n \r\nvoid main ()\r\n{\r\n\tauto r = roots (limit);\r\n \r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n \r\n\t\tint [int] nums;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tnums[r[c]] += 1;\r\n\t\t}\r\n \r\n\t\tauto answer = [0, 0, 0];\r\n\t\tforeach (step; 0..3)\r\n\t\t{\r\n\t\t\tdebug {writeln (nums);}\r\n\t\t\tint [int] next;\r\n\t\t\tforeach (k, v; nums)\r\n\t\t\t{\r\n\t\t\t\tanswer[step] = max (answer[step], v);\r\n\t\t\t\tint p = (v & 1) ? k : 1;\r\n\t\t\t\tnext[p] += v;\r\n\t\t\t}\r\n\t\t\tnums = next;\r\n\t\t}\r\n \r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (s; 0..q)\r\n\t\t{\r\n\t\t\tauto z = readln.strip.to !(long);\r\n\t\t\twriteln (answer[min (z, $ - 1).to !(int)]);\r\n\t\t}\r\n\t}\r\n}"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint [] prepare (int limit)\r\n{\r\n\tauto res = limit.iota.array;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d] == d)\r\n\t\t{\r\n\t\t\tfor (int e = d * d; e < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\tif (res[e] == e)\r\n\t\t\t\t{\r\n\t\t\t\t\tres[e] = d;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nint [] roots (int limit)\r\n{\r\n\tauto p = prepare (limit);\r\n\tauto res = new int [limit];\r\n\tforeach (d; 0..limit)\r\n\t{\r\n\t\tint cur = d;\r\n\t\tres[d] = 1;\r\n\t\twhile (cur > 1)\r\n\t\t{\r\n\t\t\tbool parity = 0;\r\n\t\t\tint x = p[cur];\r\n\t\t\twhile (cur % x == 0)\r\n\t\t\t{\r\n\t\t\t\tcur /= x;\r\n\t\t\t\tparity ^= 1;\r\n\t\t\t}\r\n\t\t\tif (parity)\r\n\t\t\t{\r\n\t\t\t\tres[d] *= x;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nimmutable int limit = 10 ^^ 6;\r\n\r\nvoid main ()\r\n{\r\n\tauto r = roots (limit);\r\n\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tint [int] nums;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tnums[r[c]] += 1;\r\n\t\t}\r\n\r\n\t\tauto answer = [0, 0, 0];\r\n\t\tforeach (step; 0..3)\r\n\t\t{\r\n\t\t\tdebug {writeln (nums);}\r\n\t\t\tint [int] next;\r\n\t\t\tforeach (k, v; nums)\r\n\t\t\t{\r\n\t\t\t\tanswer[step] = max (answer[step], v);\r\n\t\t\t\tint p = (v & 1) ? k : 1;\r\n\t\t\t\tnext[p] += v;\r\n\t\t\t}\r\n\t\t\tnums = next;\r\n\t\t}\r\n\r\n\t\tauto q = readln.strip.to !(int);\r\n\t\tforeach (s; 0..q)\r\n\t\t{\r\n\t\t\tauto z = readln.strip.to !(long);\r\n\t\t\twriteln (answer[min (z, $ - 1).to !(int)]);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "src_uid": "63108f3cc494df3c7bb62381c03801b3"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nlong solve (long n)\r\n{\r\n\tlong x = cast (long) (sqrt (cast (real) (n)));\r\n\tlong res = x * 3 - 2;\r\n\tres += (x * (x + 1) <= n);\r\n\tres += (x * (x + 2) <= n);\r\n\treturn res;\r\n}\r\n\r\nlong solve (long lo, long hi)\r\n{\r\n\treturn solve (hi) - solve (lo - 1);\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tlong lo, hi;\r\n\t\treadf !(\" %s %s\") (lo, hi);\r\n\t\twriteln (solve (lo, hi));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nvoid solve() {\r\n long L, R; readf(\"%d %d\\n\", &L, &R);\r\n\r\n long sqrt_floor(long x) {\r\n long lb = 1, ub = 1_000_000_100;\r\n while (lb + 1 < ub) {\r\n long mid = (lb + ub) / 2;\r\n if (mid * mid <= x) {\r\n lb = mid;\r\n } else {\r\n ub = mid;\r\n }\r\n }\r\n return lb;\r\n }\r\n\r\n long C(long x) {\r\n if (x == 0L) return 0L;\r\n long d = sqrt_floor(x);\r\n long s = d * d;\r\n return (d - 1L) * 3L + (x - s) / d + 1L;\r\n }\r\n\r\n writeln(C(R) - C(L-1));\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [], "src_uid": "10812427d3052ce91cd0951911d3acb9"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.exception;\nimport std.conv;\nimport std.array;\nimport std.range;\n\nint mishkaKacKereKazandi = 0;\nint chrisKacKereKazandi = 0;\n\nvoid zarlariKarsilastir( int mishkaninZari, int chrisinZari )\n{\n\tif ( mishkaninZari > chrisinZari )\n\t\tmishkaKacKereKazandi++;\n\telse if ( chrisinZari > mishkaninZari )\n\t\tchrisKacKereKazandi++;\n}\n\nvoid main() {\n\n auto satirSayisi = stdin.readln.strip.to!int();\n\n auto zarlarDizisi = stdin\n\t\t.byLine()\n\t\t.take(satirSayisi)\n\t\t.map!(line => line\n\t\t\t .split\n\t\t\t .map!(a => to!int(a))\n\t\t\t .array());\n\n zarlarDizisi.each!( a=> zarlariKarsilastir(a[0], a[1]) );\n\n\tif ( mishkaKacKereKazandi > chrisKacKereKazandi )\n\t\twriteln(\"Mishka\");\n\telse if ( mishkaKacKereKazandi == chrisKacKereKazandi )\n\t\twriteln(\"Friendship is magic!^^\");\n\telse \n\t\twriteln( \"Chris\" );\n}", "positive_code": [{"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.math;\n\nstring readline()\n{\n\tstring res = readln();\n\tif (res[$-1] == '\\n') res.length--;\n\treturn res;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint m, c;\n\tforeach (int i; 0..n)\n\t{\n\t\tint md, cd;\n\t\tscanf(\"%d %d\", &md, &cd);\n\t\tif (md > cd) \n\t\t\tm++;\n\t\telse if (cd > md)\n\t\t\tc++;\n\t}\n\tif (m > c)\n\t{\n\t\tprintf(\"Mishka\");\n\t} else\n\tif (m == c)\n\t{\n\t\tprintf(\"Friendship is magic!^^\");\n\t} else\n\t{\n\t\tprintf(\"Chris\");\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint d=0;\n\tint e=0;\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tint b=0;\n\t\tint c=0;\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\tif (b>c)\n\t\t{\n\t\t\td=d+1;\n\t\t}\n\t\tif (c>b)\n\t\t{\n\t\t\te=e+1;\n\t\t}\n\t}\n\tif (d>e)\n\t{\n\t\twriteln(\"Mishka\");\n\t}\n\telse if (e>d)\n\t{\n\t\twriteln(\"Chris\");\n\t}\n\telse\n\t{\n\t\twriteln(\"Friendship is magic!^^\");\n\t}\n\treturn 0;\n}"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n int c_a = 0;\n int c_b = 0;\n for (int i = 0; i < n; i++) {\n int a = cin.read_int;\n int b = cin.read_int;\n if (a > b) c_a++;\n if (b > a) c_b++;\n }\n if (c_a > c_b) writeln(\"Mishka\");\n else if (c_b > c_a) writeln(\"Chris\");\n else writeln(\"Friendship is magic!^^\");\n } \n}"}, {"source_code": "import std.stdio, std.range, std.algorithm, std.conv, std.string, std.array;\n\nvoid main() {\n\t\n\tint n = readln.strip.to!int;\n\n\tint Mishka, Chris;\n\n\tint mM, mC;\n\twhile (n--) {\n\t\treadf(\" %s %s\", &mM, &mC);\n\t\tif (mM > mC)\n\t\t\t++Mishka;\n\t\telse if (mM < mC)\n\t\t\t++Chris;\n\t}\n\n\tif (Mishka == Chris)\n\t\twriteln(\"Friendship is magic!^^\");\n\telse if (Mishka > Chris)\n\t\twriteln(\"Mishka\");\n\telse\n\t\twriteln(\"Chris\");\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.exception;\nimport std.conv;\nimport std.array;\nimport std.range;\n\nint mishkaKacKereKazandi = 0;\n\nvoid zarlariKarsilastir( int mishkaninZari, int chrisinZari )\n{\n\tif ( mishkaninZari > chrisinZari )\n\t\tmishkaKacKereKazandi++;\n}\n\nvoid main() {\n\n auto satirSayisi = stdin.readln.strip.to!int();\n\n auto zarlarDizisi = stdin\n\t\t.byLine()\n\t\t.take(satirSayisi)\n\t\t.map!(line => line\n\t\t\t .split\n\t\t\t .map!(a => to!int(a))\n\t\t\t .array());\n\n zarlarDizisi.each!( a=> zarlariKarsilastir(a[0], a[1]) );\n\n\tif ( mishkaKacKereKazandi > satirSayisi/2 )\n\t\twriteln(\"Mishka\");\n\telse if ( mishkaKacKereKazandi == satirSayisi/2 )\n\t\twriteln(\"Friendship is magic!^^\");\n\telse \n\t\twriteln( \"Chris\" );\n}"}], "src_uid": "76ecde4a445bbafec3cda1fc421e6d42"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto last = a[0] % 2;\n\t\tans[ti] = true;\n\t\tforeach (e; a[1..$])\n\t\t{\n\t\t\tif (e % 2 != last)\n\t\t\t\tans[ti] = false;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n readln;\n auto as = readln.split.to!(int[]);\n auto x = as[0]%2;\n foreach (a; as) if (x != a%2) goto ng;\n writeln(\"YES\");\n continue;\n ng:\n writeln(\"NO\");\n }\n}"}], "negative_code": [], "src_uid": "53a3313f5d6ce19413d72473717054fc"} {"source_code": "#!/usr/bin/env rdmd\nimport std.stdio, std.string, std.conv;\nimport std.algorithm, std.array;\n\nvoid main()\n{\n for(string S; (S=readln().chomp()).length; )\n {\n auto n = S.to!int();\n auto s = new int[n];\n foreach(i;0..n)\n s[i] = readln().chomp().to!int();\n s.sort;\n int c = 0;\n int p = n/2;\n foreach(i;0..n/2)\n {\n auto v = s[i]*2;\n for( ; p<n; ++p)\n {\n if(v<=s[p])\n {\n ++c;\n ++p;\n break;\n }\n }\n }\n writeln(n-c);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MAX_N = 100_005;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto c = new int [MAX_N + 1];\n\t\tc[] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tc[x]++;\n\t\t}\n\t\tint [] a;\n\t\tforeach (k, b; c)\n\t\t{\n\t\t\tforeach (i; 0..b)\n\t\t\t{\n\t\t\t\ta ~= k;\n\t\t\t}\n\t\t}\n\t\tenforce (a.length == n);\n\t\tdebug {writeln (a);}\n\n\t\tbool check (int me)\n\t\t{\n\t\t\tforeach (i; 0..me)\n\t\t\t{\n\t\t\t\tdebug {writeln (\"compare \", i,\n\t\t\t\t \" \", n - me + i);}\n\t\t\t\tif (a[i] * 2 > a[n - me + i])\n\t\t\t\t{\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint lo = 0;\n\t\tint hi = n >> 1;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tint me = (lo + hi + 1) >> 1;\n\t\t\tdebug {writeln (lo, ' ', hi, ' ', me);}\n\t\t\tif (check (me))\n\t\t\t{\n\t\t\t\tlo = me;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = me - 1;\n\t\t\t}\n\t\t}\n\t\twriteln (n - lo);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MAX_N = 100_005;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto c = new int [MAX_N + 1];\n\t\tc[] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tc[x]++;\n\t\t}\n\t\tint j = 0;\n\t\tint res = 0;\n\t\tforeach (i; 0..MAX_N)\n\t\t{\n\t\t\tj = max (j, i << 1);\n\t\t\tj = min (j, MAX_N);\n\t\t\twhile (c[i] > 0)\n\t\t\t{\n\t\t\t\twhile (j < MAX_N && c[j] == 0)\n\t\t\t\t{\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t\tif (c[j] == 0)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tc[i]--;\n\t\t\t\tc[j]--;\n\t\t\t\tres++;\n\t\t\t}\n\t\t\tres += c[i];\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MAX_N = 100_005;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto c = new int [MAX_N];\n\t\tc[] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tc[x]++;\n\t\t}\n\t\tint j = MAX_N;\n\t\tint res = 0;\n\t\tforeach_reverse (i; 0..MAX_N)\n\t\t{\n\t\t\tj = min (j, i >> 1);\n\t\t\twhile (c[i] > 0)\n\t\t\t{\n\t\t\t\twhile (j > 0 && c[j] == 0)\n\t\t\t\t{\n\t\t\t\t\tj--;\n\t\t\t\t}\n\t\t\t\tif (c[j] == 0)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tc[i]--;\n\t\t\t\tc[j]--;\n\t\t\t\tres++;\n\t\t\t}\n\t\t\tres += c[i];\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "#!/usr/bin/env rdmd\nimport std.stdio, std.string, std.conv;\nimport std.algorithm, std.array;\n\nvoid main()\n{\n for(string S; (S=readln().chomp()).length; )\n {\n auto n = S.to!int();\n auto s = new int[n];\n foreach(i;0..n)\n s[i] = readln().chomp().to!int();\n s.sort;\n auto u = new bool[n];\n auto c = n;\n int p = n;\n foreach_reverse(i;1..n)\n {\n auto v = s[i]/2;\n if(!u[i])\n {\n p=min(p,i-1);\n for( ; p>=0; --p)\n {\n if(v>=s[p])\n {\n u[p]=true;\n --c;\n --p;\n break;\n }\n }\n }\n\n }\n writeln(c);\n }\n}\n"}, {"source_code": "#!/usr/bin/env rdmd\nimport std.stdio, std.string, std.conv;\nimport std.algorithm, std.array;\n\nvoid main()\n{\n for(string S; (S=readln().chomp()).length; )\n {\n auto n = S.to!int();\n auto s = new int[n];\n foreach(i;0..n)\n s[i] = readln().chomp().to!int();\n s.sort;\n auto u = new bool[n];\n auto c = n;\n int p = n;\n foreach_reverse(i;1..n)\n {\n auto v = s[i];\n if(!u[i])\n {\n p=min(p,i-1);\n for( ; p>=0; --p)\n {\n if(v>s[p]*2)\n {\n u[p]=true;\n --c;\n --p;\n break;\n }\n }\n }\n\n }\n writeln(c);\n }\n}\n"}, {"source_code": "#!/usr/bin/env rdmd\nimport std.stdio, std.string, std.conv;\nimport std.algorithm, std.array;\n\nvoid main()\n{\n for(string S; (S=readln().chomp()).length; )\n {\n auto n = S.to!int();\n auto s = new int[n];\n foreach(i;0..n)\n s[i] = readln().chomp().to!int();\n s.sort;\n auto u = new bool[n];\n auto c = n;\n int p = n-2;\n foreach_reverse(i;1..n)\n {\n auto v = s[i]/2;\n if(!u[i])\n {\n for( ; p>=0; --p)\n {\n if(v>=s[p])\n {\n u[p]=true;\n --c;\n --p;\n break;\n }\n }\n }\n\n }\n writeln(c);\n }\n}\n"}], "src_uid": "361f65484d86051fa9ff013f5e8c9154"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1526/problem/A\n// \nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n\n long[] a = readln.split.map!(to!long).array;\n a.sort;\n for(int i = 0; i < n; ++i) {\n writef(\"%s %s \", a[i], a[i + n]);\n } \"\".writeln;\n}\n}\n\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.strip)) {\r\n int n = to!int(readln.strip);\r\n auto ar = readln.split.map!(to!int).array.sort;\r\n auto r1 = ar[0 .. n], r2 = ar[n .. $];\r\n foreach(i; 0 .. n) {\r\n write(r1[i],\" \",r2[i],\" \");\r\n }\r\n writeln();\r\n }\r\n}\r\n "}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nbool check(long[] a)\n{\n for (int i = 0; i < a.length; i++) {\n int left = (cast(int)(a.length) + i - 1) % cast(int)(a.length);\n int right = (cast(int)(a.length) + i + 1) % cast(int)(a.length);\n if (a[left] + a[right] == 2 * a[i])\n return false;\n }\n return true;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n\n foreach (casenum ; 0 .. t) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.chomp.split.map!(to!long).array;\n long[] b;\n while (true) {\n b = a.randomShuffle;\n if (check(b))\n break;\n }\n writeln(b.map!text.joiner(\" \"));\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport core.stdc.stdio;\n\nint main()\n{\n int t = readInt!int;\n while (t--)\n {\n int n = readInt!int;\n auto a = new int[](2 * n);\n foreach(ref ai; a)\n ai = readInt!int;\n sort(a);\n debug writeln(a);\n auto low = a[0 .. n];\n auto high = a[n .. $];\n foreach(i; 0 .. n)\n {\n write(low[i], \" \", high[i], \" \");\n }\n writeln;\n }\n return 0;\n}\n\n\n\n\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1526/problem/A\n// \nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n\n long[] a = readln.split.map!(to!long).array;\n for(int i = 0; i < n; ++i) {\n writef(\"%s %s \", a[i], a[i + n]);\n } \"\".writeln;\n}\n}\n\n"}], "src_uid": "4296da660a39a6e98b41387929701c0a"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint t = rint;\n\tforeach(_; 0 .. t){\n\t\tlong a = rlong, b = rlong, c = rlong;\n\t\tlong ans = min((a + b + c) / 2, a + b, b + c, c + a);\n\t\tans.writeln;\n\t}\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n {\n\tstatic foreach(n; 0 .. T[i].Types.length)\n\t {\n\t read(args[i][n]);\n\t }\n }\n else\n readf!\" %s \"(args[i]);\n}\nauto brange(alias low, alias high, alias pred, bool value)()\n{\n return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);\n}\nauto ftrue(alias low, alias high, alias pred)()\n{\n return brange!(low, high, pred, false).length + low;\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t;\n get(t);\n F(t);\n }\n}\nalias get = read;\nalias w = writeln;\n\nint main()\n{\n int t;\n get(t);\n while(t--)\n {\n long[] c = new long[3];\n get(c);\n sort(c);\n long res = 0;\n long d = c[1] - c[0];\n res += d;\n c[1] -= d;\n c[2] -= d;\n auto a = c[0];\n auto b = c[2];\n d = min(a, b - a);\n a -= d;\n b -= 2 * d;\n res += 2 * d;\n res += 3 * (a / 2) + (a % 2);\n w(res);\n }\n return 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\treadln;\n\tforeach (test; 0..tests)\n\t{\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\twriteln (min (a[0] + a[1], sum (a) / 2));\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto r = RD;\n\t\tauto g = RD;\n\t\tauto b = RD;\n\t\tauto arr = [r, g, b];\n\t\tarr.sort();\n\t\tauto d = min(arr[2] - arr[1], arr[0]);\n\t\tans[i] += d;\n\t\tarr[2] -= d;\n\t\tarr[0] -= d;\n\t\tans[i] += arr[0] - arr[0] % 2;\n\t\tans[i] += arr[1] - arr[0] / 2;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "1f29461c42665523d0a4d56b13f7e480"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n enum deltas = [tuple(int(-1), int(0)), tuple(int(+1), int(0)),\n tuple(int(0), int(-1)), tuple(int(0), int(+1))];\n auto n = next!int;\n auto m = next!int;\n auto cell = new string[](n);\n foreach(ref row; cell)\n row = next!string;\n auto visited = new bool[][](n, m);\n struct Op\n {\n string type;\n Tuple!(int, int) ind;\n }\n auto ops = new Op[](0);\n foreach(i; 0 .. n)\n {\n foreach(j; 0 .. m)\n {\n if (!visited[i][j] && cell[i][j] == '.')\n {\n auto order = new Tuple!(int, int)[](0);\n auto queue = DList!(Tuple!(int, int))(tuple!(int, int)(i, j));\n visited[i][j] = true;\n while(!queue.empty)\n {\n auto f = queue.front;\n queue.removeFront;\n order ~= f;\n foreach(delta; deltas)\n {\n auto nei = tuple(f[0] + delta[0], f[1] + delta[1]);\n if (nei[0] >= 0 && nei[0] < n && nei[1] >= 0 && nei[1] < m && !visited[nei[0]][nei[1]] && cell[nei[0]][nei[1]] == '.')\n {\n queue.insertBack(nei);\n visited[nei[0]][nei[1]] = true;\n }\n }\n }\n foreach(node; order)\n {\n ops ~= Op(\"B\", node);\n }\n foreach_reverse(node; order[1 .. $])\n {\n ops ~= Op(\"D\", node);\n ops ~= Op(\"R\", node);\n }\n }\n }\n }\n ops.length.writeln;\n foreach(op; ops)\n {\n writeln(op.type, \" \", op.ind[0] + 1, \" \", op.ind[1] + 1);\n }\n}\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport core.memory;\n\nvoid main(string[] args)\n{\n GC.disable;\n inputFile = stdin;\n debug inputFile = File(args[1]);\n enum deltas = [tuple(int(-1), int(0)), tuple(int(+1), int(0)),\n tuple(int(0), int(-1)), tuple(int(0), int(+1))];\n auto n = next!int;\n auto m = next!int;\n auto cell = new string[](n);\n foreach(ref row; cell)\n row = next!string;\n auto visited = new bool[][](n, m);\n struct Op\n {\n string type;\n Tuple!(int, int) ind;\n }\n auto ops = new Op[](0);\n foreach(i; 0 .. n)\n {\n foreach(j; 0 .. m)\n {\n if (!visited[i][j] && cell[i][j] == '.')\n {\n auto order = new Tuple!(int, int)[](0);\n auto queue = DList!(Tuple!(int, int))(tuple!(int, int)(i, j));\n visited[i][j] = true;\n while(!queue.empty)\n {\n auto f = queue.front;\n queue.removeFront;\n order ~= f;\n foreach(delta; deltas)\n {\n auto nei = tuple(f[0] + delta[0], f[1] + delta[1]);\n if (nei[0] >= 0 && nei[0] < n && nei[1] >= 0 && nei[1] < m && !visited[nei[0]][nei[1]] && cell[nei[0]][nei[1]] == '.')\n {\n queue.insertBack(nei);\n visited[nei[0]][nei[1]] = true;\n }\n }\n }\n foreach(node; order)\n {\n ops ~= Op(\"B\", node);\n }\n foreach_reverse(node; order[1 .. $])\n {\n ops ~= Op(\"D\", node);\n ops ~= Op(\"R\", node);\n }\n }\n }\n }\n ops.length.writeln;\n foreach(op; ops)\n {\n writeln(op.type, \" \", op.ind[0] + 1, \" \", op.ind[1] + 1);\n }\n}\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport core.memory;\n\nstruct StaticQueue(T, size_t maxSize)\n{\n T[maxSize] data;\n size_t _front = 0;\n size_t _pastBack = 0;\n size_t len = 0;\n auto length()\n {\n return len;\n }\n void clear()\n {\n _front = _pastBack;\n len = 0;\n }\n bool empty()\n {\n return _front == _pastBack;\n }\n void removeFront()\n {\n _front++;\n if (_front == maxSize)\n _front = 0;\n len--;\n }\n auto front()\n {\n return data[_front];\n }\n void insertBack(T t)\n {\n data[_pastBack] = t;\n _pastBack++;\n if (_pastBack == maxSize)\n _pastBack = 0;\n len++;\n }\n}\n\nvoid main(string[] args)\n{\n GC.disable;\n inputFile = stdin;\n debug inputFile = File(args[1]);\n enum deltas = [tuple(int(-1), int(0)), tuple(int(+1), int(0)),\n tuple(int(0), int(-1)), tuple(int(0), int(+1))];\n auto n = next!int;\n auto m = next!int;\n auto cell = new string[](n);\n foreach(ref row; cell)\n row = next!string;\n auto visited = new bool[][](n, m);\n struct Op\n {\n string type;\n Tuple!(int, int) ind;\n }\n auto ops = StaticQueue!(Op, 500 * 500 * 3)();\n auto queue = StaticQueue!(Tuple!(int, int), 500 * 500)();\n foreach(i; 0 .. n)\n {\n foreach(j; 0 .. m)\n {\n if (!visited[i][j] && cell[i][j] == '.')\n {\n auto order = new Tuple!(int, int)[](0);\n queue.clear;\n queue.insertBack(tuple(i, j));\n visited[i][j] = true;\n while(!queue.empty)\n {\n auto f = queue.front;\n queue.removeFront;\n order ~= f;\n foreach(delta; deltas)\n {\n auto nei = tuple(f[0] + delta[0], f[1] + delta[1]);\n if (nei[0] >= 0 && nei[0] < n && nei[1] >= 0 && nei[1] < m && !visited[nei[0]][nei[1]] && cell[nei[0]][nei[1]] == '.')\n {\n queue.insertBack(nei);\n visited[nei[0]][nei[1]] = true;\n }\n }\n }\n foreach(node; order)\n {\n ops.insertBack(Op(\"B\", node));\n }\n foreach_reverse(node; order[1 .. $])\n {\n ops.insertBack(Op(\"D\", node));\n ops.insertBack(Op(\"R\", node));\n }\n }\n }\n }\n ops.length.writeln;\n while(!ops.empty)\n {\n auto op = ops.front;\n ops.removeFront;\n writeln(op.type, \" \", op.ind[0] + 1, \" \", op.ind[1] + 1);\n }\n}\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport core.memory;\n\nstruct StaticQueue(T, size_t maxSize)\n{\n T[maxSize] data;\n size_t _front = 0;\n size_t _pastBack = 0;\n void clear()\n {\n _front = _pastBack;\n }\n bool empty()\n {\n return _front == _pastBack;\n }\n void removeFront()\n {\n _front++;\n if (_front == maxSize)\n _front = 0;\n }\n auto front()\n {\n return data[_front];\n }\n void insertBack(T t)\n {\n data[_pastBack] = t;\n _pastBack++;\n if (_pastBack == maxSize)\n _pastBack = 0;\n }\n}\n\nvoid main(string[] args)\n{\n GC.disable;\n inputFile = stdin;\n debug inputFile = File(args[1]);\n enum deltas = [tuple(int(-1), int(0)), tuple(int(+1), int(0)),\n tuple(int(0), int(-1)), tuple(int(0), int(+1))];\n auto n = next!int;\n auto m = next!int;\n auto cell = new string[](n);\n foreach(ref row; cell)\n row = next!string;\n auto visited = new bool[][](n, m);\n struct Op\n {\n string type;\n Tuple!(int, int) ind;\n }\n auto ops = new Op[](0);\n auto queue = StaticQueue!(Tuple!(int, int), 500 * 500)();\n foreach(i; 0 .. n)\n {\n foreach(j; 0 .. m)\n {\n if (!visited[i][j] && cell[i][j] == '.')\n {\n auto order = new Tuple!(int, int)[](0);\n queue.clear;\n queue.insertBack(tuple(i, j));\n visited[i][j] = true;\n while(!queue.empty)\n {\n auto f = queue.front;\n queue.removeFront;\n order ~= f;\n foreach(delta; deltas)\n {\n auto nei = tuple(f[0] + delta[0], f[1] + delta[1]);\n if (nei[0] >= 0 && nei[0] < n && nei[1] >= 0 && nei[1] < m && !visited[nei[0]][nei[1]] && cell[nei[0]][nei[1]] == '.')\n {\n queue.insertBack(nei);\n visited[nei[0]][nei[1]] = true;\n }\n }\n }\n foreach(node; order)\n {\n ops ~= Op(\"B\", node);\n }\n foreach_reverse(node; order[1 .. $])\n {\n ops ~= Op(\"D\", node);\n ops ~= Op(\"R\", node);\n }\n }\n }\n }\n ops.length.writeln;\n foreach(op; ops)\n {\n writeln(op.type, \" \", op.ind[0] + 1, \" \", op.ind[1] + 1);\n }\n}\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n enum deltas = [tuple(int(-1), int(0)), tuple(int(+1), int(0)),\n tuple(int(0), int(-1)), tuple(int(0), int(+1))];\n auto n = next!int;\n auto m = next!int;\n auto cell = new string[](n);\n foreach(ref row; cell)\n row = next!string;\n auto visited = new bool[][](n, m);\n foreach(i; 0 .. n)\n {\n foreach(j; 0 .. m)\n {\n if (!visited[i][j] && cell[i][j] == '.')\n {\n auto order = new Tuple!(int, int)[](0);\n auto queue = DList!(Tuple!(int, int))(tuple!(int, int)(i, j));\n visited[i][j] = true;\n while(!queue.empty)\n {\n auto f = queue.front;\n queue.removeFront;\n order ~= f;\n foreach(delta; deltas)\n {\n auto nei = tuple(f[0] + delta[0], f[1] + delta[1]);\n if (nei[0] >= 0 && nei[0] < n && nei[1] >= 0 && nei[1] < m && !visited[nei[0]][nei[1]] && cell[nei[0]][nei[1]] == '.')\n {\n queue.insertBack(nei);\n visited[nei[0]][nei[1]] = true;\n }\n }\n }\n foreach(node; order)\n {\n writeln(\"B \", node[0] + 1, \" \", node[1] + 1);\n }\n foreach_reverse(node; order[1 .. $])\n {\n writeln(\"D \", node[0] + 1, \" \", node[1] + 1);\n writeln(\"R \", node[0] + 1, \" \", node[1] + 1);\n }\n }\n }\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "src_uid": "9b9f6d95aecc1b6c95e5d9acca4f5453"} {"source_code": "\nimmutable multi = false;\n\nstruct US\n{\n\tint[] parent;\n\tint[] sz; \n\tthis(int n)\n\t{\n\t\tparent = new int[](n);\n\t\tforeach(i; 0 .. n) parent[i] = i;\n\t\tsz = new int[](n);\n\t\tsz[] = 1;\n\t}\n\tvoid unite(int u, int v)\n\t{\n\t\tdebug writeln(\"uniting \", u, \" \", v);\n\t\tu = rep(u);\n\t\tv = rep(v);\n\t\tif (sz[u] > sz[v]) swap(u, v);\n\t\tparent[u] = v;\n\t\tsz[v] += sz[u];\n\t}\n\tint rep(int v)\n\t{\n\t\tdebug writeln(\"getting rep for \", v);\n\t\tif (parent[v] == v) return v;\n\t\treturn parent[v] = rep(parent[v]);\n\t}\n}\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tauto u1 = US(n);\n\tauto u2 = US(n);\n\tauto m1 = readInt!int;\n\tauto m2 = readInt!int;\n\tforeach(i; 0 .. m1)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tdebug writeln(u, \" -> \", v);\n\t\tu1.unite(u, v);\n\t}\n\tforeach(i; 0 .. m2)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tu2.unite(u, v);\n\t}\n\tauto edges = new int[2][](0);\n\tforeach(i; 0 .. n)\n\t{\n\t\tforeach(j; 0 .. n)\n\t\t{\n\t\t\tif (u1.rep(i) != u1.rep(j) && u2.rep(i) != u2.rep(j))\n\t\t\t{\n\t\t\t\tu1.unite(i, j);\n\t\t\t\tu2.unite(i, j);\n\t\t\t\tedges ~= [i+1, j+1];\n\t\t\t}\n\t\t}\n\t}\n\tedges.length.writeln;\n\tforeach(e; edges) writeln(e[0], \" \", e[1]);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nstruct UnionFind(T)\r\n{\r\n\tvoid init(T n) { par = new T[](n); foreach (i; 0..n) par[i] = i; cnt = new T[](n); fill(cnt, 1); }\r\n\tT root(T i) { return par[i] == i ? i : (par[i] = root(par[i])); }\r\n\tbool same(T i, T j) { return root(i) == root(j); }\r\n\tvoid unite(T i, T j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; cnt[j] += cnt[i]; }\r\n\tT size(T i) { return cnt[root(i)]; }\r\n\tT[] par, cnt;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\tauto m1 = RD!int;\r\n\tauto m2 = RD!int;\r\n\t\t\r\n\tUnionFind!int uf1, uf2;\r\n\tuf1.init(n);\r\n\tuf2.init(n);\r\n\tforeach (i; 0..m1)\r\n\t{\r\n\t\tauto u = RD!int-1;\r\n\t\tauto v = RD!int-1;\r\n\t\tuf1.unite(u, v);\r\n\t}\r\n\tforeach (i; 0..m2)\r\n\t{\r\n\t\tauto u = RD!int-1;\r\n\t\tauto v = RD!int-1;\r\n\t\tuf2.unite(u, v);\r\n\t}\r\n\t\r\n\tint[][] ans;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tforeach (j; i+1..n)\r\n\t\t{\r\n\t\t\tif (uf1.same(i, j) || uf2.same(i, j)) continue;\r\n\t\t\tuf1.unite(i, j);\r\n\t\t\tuf2.unite(i, j);\r\n\t\t\tans ~= [i+1, j+1];\r\n\t\t}\r\n\t}\r\n\r\n\r\n\twriteln(ans.length);\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e[0], \" \", e[1]);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "e3d2b67a62ac431718071ae20f3794aa"} {"source_code": "import std.stdio;\n\nint main()\n{\n\tint n(int a, int b)\n\t{\n\t\tif (a>=b)\n\t\t{\n\t\t\treturn a;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn b;\n\t\t}\n\t}\n\tint m(int a, int b, int c, int d)\n\t{\n\t\treturn n(n(a,b),n(c,d));\n\t}\n\tint a=0;\n\tint b=0;\n\tint c=0;\n\tint d=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\treadf(\" %d\", &c);\n\treadf(\" %d\", &d);\n\tint e=m(a,b,c,d);\n\tif (e==a)\n\t{\n\t\twriteln(e-b);\n\t\twriteln(e-c);\n\t\twriteln(e-d);\n\t}\n\telse if (e==b)\n\t{\n\t\twriteln(e-a);\n\t\twriteln(e-c);\n\t\twriteln(e-d);\n\t}\n\telse if (e==c)\n\t{\n\t\twriteln(e-a);\n\t\twriteln(e-b);\n\t\twriteln(e-d);\n\t}\n\telse\n\t{\n\t\twriteln(e-a);\n\t\twriteln(e-b);\n\t\twriteln(e-c);\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\nimport std.conv;\nimport std.math;\n\nvoid main()\n{\n int[] input = readln().split.map!\"a.to!int\".array;\n input = input.sort.reverse.array;\n int a = input[0] - input[1];\n int b = input[0] - input[2];\n int c = input[0] - input[3];\n writeln(a, \" \", b, \" \", c);\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/problemset/problem/1154/A\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\n\nvoid main() {\n int[] numbers = readln.split.map!(to!int).array;\n numbers.sort;\n int abc = numbers[$-1];\n int x = abc-numbers[0];\n writefln(\"%d %d %d\", x, numbers[1]-x, numbers[2]-x);\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.range;\nimport std.file;\nimport std.datetime;\n\n\n\n\n\nvoid main() {\n\t\n\tint[] say\u0131lar = stdin.readln.strip.split.map!(a=> a.to!int()).array;\n\tint toplam = say\u0131lar.maxElement();\n\tsay\u0131lar = say\u0131lar.remove( say\u0131lar.countUntil(toplam) ).array;\n\tint bArt\u0131C = say\u0131lar.maxElement();\n\tint a = toplam - bArt\u0131C;\n\tsay\u0131lar = say\u0131lar.remove( say\u0131lar.countUntil(bArt\u0131C) ).array;\n\n\tint aArt\u0131C = say\u0131lar.maxElement();\n\tint c = aArt\u0131C - a;\n\tint b = toplam - aArt\u0131C;\n\t\n\twriteln(a, \" \", b, \" \", c);\n\t\n\t//writeln();\n\t\n}\n\n\n\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint[] xs = readln.chomp.split.map!(to!int).array;\n\t\n\tint s = -1;\n\tforeach(x; xs) s = max(s, x);\n\t\n\tint[] as;\n\tforeach(x; xs) if(x < s) as ~= s - x;\n\t\n\tas.map!(to!string).array.join(\" \").writeln;\n\n}\n/*\n\nThe largest must be a + b + c.\nCall it s.\n\nOthers are s - a, s - b, s - c.\n\n*/\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto x = new long[](4);\n\tforeach (i; 0..4)\n\t{\n\t\tx[i] = RD;\n\t}\n\tx.sort();\n\n\twriteln(x[3] - x[0], \" \", x[3] - x[1], \" \", x[3] -x[2]);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "cda949a8fb1f158f3c06109a2d33f084"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable long mod = 998_244_353;\r\n\r\nlong powMod (long a, long p)\r\n{\r\n\tlong res = 1;\r\n\tfor ( ; p > 0; p >>= 1)\r\n\t{\r\n\t\tif (p & 1)\r\n\t\t{\r\n\t\t\tres = (res * 1L * a) % mod;\r\n\t\t}\r\n\t\ta = (a * 1L * a) % mod;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nlong invMod (long a)\r\n{\r\n\treturn powMod (a, mod - 2);\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\tlong invs = 0;\r\n\t\tint i = 0;\r\n\t\tint j = n - 1;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\twhile (i < n && a[i] == 0)\r\n\t\t\t{\r\n\t\t\t\ti += 1;\r\n\t\t\t}\r\n\t\t\twhile (j >= 0 && a[j] == 1)\r\n\t\t\t{\r\n\t\t\t\tj -= 1;\r\n\t\t\t}\r\n\t\t\tif (i >= j)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tinvs += 1;\r\n\t\t\ti += 1;\r\n\t\t\tj -= 1;\r\n\t\t}\r\n\r\n\t\tauto cn2 = n;\r\n\t\tcn2 = (cn2 * 1L * (n - 1)) % mod;\r\n\t\tcn2 = (cn2 * 1L * invMod (2)) % mod;\r\n\r\n\t\tlong res = 0;\r\n\t\tforeach (k; 0..invs)\r\n\t\t{\r\n\t\t\tauto cur = k + 1;\r\n\t\t\tcur = (cur * 1L * (k + 1)) % mod;\r\n\t\t\tres = (res + cn2 * 1L * invMod (cur)) % mod;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n\r\n int nz = A.count!(a => a == 0);\r\n int t0 = A[0 .. nz].count!(a => a == 1);\r\n //writeln([nz, t0]);\r\n\r\n MInt p(int t) {\r\n long t2 = cast(long)(t) * t;\r\n long nC2 = cast(long)(N) * (N - 1) / 2;\r\n return MInt(t2) / nC2;\r\n }\r\n\r\n auto E = new MInt[t0 + 1];\r\n E[0] = 0;\r\n for (int t = 0; t < t0; t++) {\r\n E[t+1] = E[t] + 1 / p(t+1);\r\n }\r\n //writeln(E);\r\n writeln(E[t0]);\r\n}\r\n\r\nalias MInt = ModInt!998244353L;\r\n\r\nstruct ModInt(long mod) {\r\n invariant() {\r\n assert(0 <= val && val < mod);\r\n }\r\n long val;\r\n this(long v) { this.val = (mod * mod + v) % mod; }\r\n ModInt opBinary(string op : \"+\")(int y) const { return ModInt(this.val + y); }\r\n ModInt opBinary(string op : \"-\")(int y) const { return ModInt(this.val - y); }\r\n ModInt opBinary(string op : \"*\")(int y) const { return ModInt(this.val * y); }\r\n ModInt opBinary(string op : \"/\")(int y) const { return ModInt(this.val * inv(y)); }\r\n ModInt opBinary(string op : \"+\")(long y) const { return ModInt(this.val + y); }\r\n ModInt opBinary(string op : \"-\")(long y) const { return ModInt(this.val - y); }\r\n ModInt opBinary(string op : \"*\")(long y) const { return ModInt(this.val * y); }\r\n ModInt opBinary(string op : \"/\")(long y) const { return ModInt(this.val * inv(y)); }\r\n ModInt opBinary(string op : \"+\")(ModInt y) const { return ModInt(this.val + y.val); }\r\n ModInt opBinary(string op : \"-\")(ModInt y) const { return ModInt(this.val - y.val); }\r\n ModInt opBinary(string op : \"*\")(ModInt y) const { return ModInt(this.val * y.val); }\r\n ModInt opBinary(string op : \"/\")(ModInt y) const { return ModInt(this.val * inv(y.val)); }\r\n ModInt opBinaryRight(string op : \"+\")(int y) const { return ModInt(this.val + y); }\r\n ModInt opBinaryRight(string op : \"-\")(int y) const { return ModInt(y - this.val); }\r\n ModInt opBinaryRight(string op : \"*\")(int y) const { return ModInt(this.val * y); }\r\n ModInt opBinaryRight(string op : \"/\")(int y) const { return ModInt(inv(this.val) * y); }\r\n ModInt opBinaryRight(string op : \"+\")(long y) const { return ModInt(this.val + y); }\r\n ModInt opBinaryRight(string op : \"-\")(long y) const { return ModInt(y - this.val); }\r\n ModInt opBinaryRight(string op : \"*\")(long y) const { return ModInt(this.val * y); }\r\n ModInt opBinaryRight(string op : \"/\")(long y) const { return ModInt(inv(this.val) * y); }\r\n void opAssign(int y) { this.val = y; }\r\n void opAssign(long y) { this.val = y; }\r\n void opOpAssign(string op : \"+\")(int y) { this.val = (this.val + mod * mod + y) % mod; }\r\n void opOpAssign(string op : \"-\")(int y) { this.val = (this.val + mod * mod - y) % mod; }\r\n void opOpAssign(string op : \"*\")(int y) { this.val = (this.val * y) % mod; }\r\n void opOpAssign(string op : \"/\")(int y) { this.val = (this.val * inv(y)) % mod; }\r\n void opOpAssign(string op : \"+\")(long y) { this.val = (this.val + mod * mod + y) % mod; }\r\n void opOpAssign(string op : \"-\")(long y) { this.val = (this.val + mod * mod - y) % mod; }\r\n void opOpAssign(string op : \"*\")(long y) { this.val = (this.val * y) % mod; }\r\n void opOpAssign(string op : \"/\")(long y) { this.val = (this.val * inv(y)) % mod; }\r\n void opOpAssign(string op : \"+\")(ModInt y) { this.val = (this.val + mod * mod + y.val) % mod; }\r\n void opOpAssign(string op : \"-\")(ModInt y) { this.val = (this.val + mod * mod - y.val) % mod; }\r\n void opOpAssign(string op : \"*\")(ModInt y) { this.val = (this.val * y.val) % mod; }\r\n void opOpAssign(string op : \"/\")(ModInt y) { this.val = (this.val * inv(y.val)) % mod; }\r\n ModInt opUnary(string op : \"-\")() const { return ModInt(mod - this.val); }\r\n string toString() const { return val.to!string; }\r\n ModInt pow(long n) { return ModInt(pow(this.val, n, mod)); }\r\n ModInt pow(ModInt n) { return ModInt(pow(this.val, n.val, mod)); }\r\n static long pow(long x, long n, long mod) {\r\n if (n == 0) return 1L;\r\n x %= mod;\r\n if (n == 1) return x;\r\n if (n % 2 == 0) {\r\n long y = pow(x, n/2, mod);\r\n return y * y % mod;\r\n } else {\r\n return x * pow(x, n-1, mod) % mod;\r\n }\r\n }\r\n static long extgcd(long a, long b, ref long x, ref long y) {\r\n if (b == 0) {\r\n x = 1;\r\n y = 0;\r\n return a;\r\n }\r\n long d = extgcd(b, a % b, y, x);\r\n y -= a / b * x;\r\n return d;\r\n }\r\n static long inv(long a) {\r\n long x, y;\r\n extgcd(a, mod, x, y);\r\n return (x % mod + mod) % mod;\r\n }\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nstruct ModInt(uint M_) {\r\n import std.conv : to;\r\n alias M = M_;\r\n uint x;\r\n this(ModInt a) { x = a.x; }\r\n this(uint x_) { x = x_ % M; }\r\n this(ulong x_) { x = cast(uint)(x_ % M); }\r\n this(int x_) { x = ((x_ %= cast(int)(M)) < 0) ? (x_ + cast(int)(M)) : x_; }\r\n this(long x_) { x = cast(uint)(((x_ %= cast(long)(M)) < 0) ? (x_ + cast(long)(M)) : x_); }\r\n ref ModInt opAssign(T)(inout(T) a) if (is(T == uint) || is(T == ulong) || is(T == int) || is(T == long)) { return this = ModInt(a); }\r\n ref ModInt opOpAssign(string op, T)(T a) {\r\n static if (is(T == ModInt)) {\r\n static if (op == \"+\") { x = ((x += a.x) >= M) ? (x - M) : x; }\r\n else static if (op == \"-\") { x = ((x -= a.x) >= M) ? (x + M) : x; }\r\n else static if (op == \"*\") { x = cast(uint)((cast(ulong)(x) * a.x) % M); }\r\n else static if (op == \"/\") { this *= a.inv(); }\r\n else static assert(false);\r\n return this;\r\n } else static if (op == \"^^\") {\r\n if (a < 0) return this = inv()^^(-a);\r\n ModInt b = this, c = 1U;\r\n for (long e = a; e; e >>= 1) { if (e & 1) c *= b; b *= b; }\r\n return this = c;\r\n } else {\r\n return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\r\n }\r\n }\r\n ModInt inv() const {\r\n uint a = M, b = x; int y = 0, z = 1;\r\n for (; b; ) { const q = a / b; const c = a - q * b; a = b; b = c; const w = y - cast(int)(q) * z; y = z; z = w; }\r\n assert(a == 1); return ModInt(y);\r\n }\r\n ModInt opUnary(string op)() const {\r\n static if (op == \"+\") { return this; }\r\n else static if (op == \"-\") { ModInt a; a.x = x ? (M - x) : 0U; return a; }\r\n else static assert(false);\r\n }\r\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\r\n ModInt opBinaryRight(string op, T)(T a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\r\n bool opCast(T: bool)() const { return (x != 0U); }\r\n string toString() const { return x.to!string; }\r\n}\r\n\r\nenum MO = 998244353;\r\nalias Mint = ModInt!MO;\r\n\r\nenum LIM_INV = 400_010;\r\nMint[] inv, fac, invFac;\r\nvoid prepare() {\r\n inv = new Mint[LIM_INV];\r\n fac = new Mint[LIM_INV];\r\n invFac = new Mint[LIM_INV];\r\n inv[1] = 1;\r\n foreach (i; 2 .. LIM_INV) {\r\n inv[i] = -((Mint.M / i) * inv[cast(size_t)(Mint.M % i)]);\r\n }\r\n fac[0] = invFac[0] = 1;\r\n foreach (i; 1 .. LIM_INV) {\r\n fac[i] = fac[i - 1] * i;\r\n invFac[i] = invFac[i - 1] * inv[i];\r\n }\r\n}\r\nMint binom(long n, long k) {\r\n if (n < 0) {\r\n if (k >= 0) {\r\n return (-1)^^(k & 1) * binom(-n + k - 1, k);\r\n } else if (n - k >= 0) {\r\n return (-1)^^((n - k) & 1) * binom(-k - 1, n - k);\r\n } else {\r\n return Mint(0);\r\n }\r\n } else {\r\n if (0 <= k && k <= n) {\r\n assert(n < LIM_INV);\r\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\r\n } else {\r\n return Mint(0);\r\n }\r\n }\r\n}\r\n\r\n\r\nvoid main() {\r\n prepare;\r\n \r\n try {\r\n for (; ; ) {\r\n const numCases = readInt;\r\n foreach (caseId; 0 .. numCases) {\r\n const N = readInt;\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt;\r\n }\r\n \r\n const K = A.sum;\r\n const L = min(K, N - K);\r\n \r\n const Mint all = 1L * N * (N - 1) / 2;\r\n auto dp = new Mint[L + 2];\r\n foreach (a; 1 .. L + 1) {\r\n dp[a] = all * inv[a] * inv[a] + dp[a - 1];\r\n }\r\n \r\n const S = A[0 .. N - K].sum;\r\n writeln(dp[S]);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int mod = 998_244_353;\r\n\r\nint powMod (int a, int p)\r\n{\r\n\tint res = 1;\r\n\tfor ( ; p > 0; p >>= 1)\r\n\t{\r\n\t\tif (p & 1)\r\n\t\t{\r\n\t\t\tres = (res * 1L * a) % mod;\r\n\t\t}\r\n\t\ta = (a * 1L * a) % mod;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nint invMod (int a)\r\n{\r\n\treturn powMod (a, mod - 2);\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tint invs = 0;\r\n\t\tint i = 0;\r\n\t\tint j = n - 1;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\twhile (i < n && a[i] == 0)\r\n\t\t\t{\r\n\t\t\t\ti += 1;\r\n\t\t\t}\r\n\t\t\twhile (j >= 0 && a[j] == 1)\r\n\t\t\t{\r\n\t\t\t\tj -= 1;\r\n\t\t\t}\r\n\t\t\tif (i >= j)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tinvs += 1;\r\n\t\t\ti += 1;\r\n\t\t\tj -= 1;\r\n\t\t}\r\n\r\n\t\tauto cn2 = n;\r\n\t\tcn2 = (cn2 * 1L * (n - 1)) % mod;\r\n\t\tcn2 = (cn2 * 1L * invMod (2)) % mod;\r\n\r\n\t\tint res = 0;\r\n\t\tforeach (k; 0..invs)\r\n\t\t{\r\n\t\t\tauto cur = k + 1;\r\n\t\t\tcur = (cur * 1L * (k + 1)) % mod;\r\n\t\t\tres = (res + cn2 * 1L * invMod (cur)) % mod;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "src_uid": "2b391638a9fea31986fe8e41c97b640a"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 9;\nalias Mint = ModInt!MO;\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readLong();\n const A = readLong();\n const B = readLong();\n const K = readInt();\n const S = readToken();\n \n assert((N + 1) % K == 0);\n const q = (N + 1) / K;\n const r = Mint(B) / Mint(A);\n const rK = r^^K;\n const rKSum = (rK.x == 1) ? Mint(q) : ((rK^^q - 1) / (rK - 1));\n \n Mint ans;\n Mint c = Mint(A)^^N;\n foreach (i; 0 .. K) {\n ans += ((S[i] == '-') ? -1 : +1) * c * rKSum;\n c *= r;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nconst mod = 10^^9+9;\nalias mint = FactorRing!mod;\n\nvoid main()\n{\n int n, a, b, k; readV(n, a, b, k);\n string s; readV(s);\n\n auto t0 = mint(0);\n foreach (i; 0..k)\n t0 += mint(a).repeatedSquare(n-i) * mint(b).repeatedSquare(i) * (s[i] == '+' ? 1 : -1);\n\n auto c = (mint(b)/mint(a)).repeatedSquare(k), m = (n+1)/k;\n if (c == 1) {\n writeln(t0 * m);\n } else {\n writeln(t0 * (c.repeatedSquare(m)-1) / (c-1));\n }\n}\n\npure T repeatedSquare(alias pred = \"a * b\", T, U)(T a, U n)\n{\n return repeatedSquare!(pred, T, U)(a, n, T(1));\n}\n\npure T repeatedSquare(alias pred = \"a * b\", T, U)(T a, U n, T init)\n{\n import std.functional;\n alias predFun = binaryFun!pred;\n\n if (n == 0) return init;\n\n auto r = init;\n while (n > 0) {\n if (n&1) r = predFun(r, a);\n a = predFun(a, a);\n n >>= 1;\n }\n\n return r;\n}\n\nstruct FactorRing(int m, bool pos = false)\n{\n version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }\n alias FR = FactorRing!(m, pos);\n @property static init() { return FR(0); }\n @property int value() { return vi; }\n @property void value(int v) { vi = mod(v); }\n alias value this;\n\n this(int v) { vi = v; }\n this(int v, bool runMod) { vi = runMod ? mod(v) : v; }\n this(long v) { vi = mod(v); }\n\n ref auto opAssign(int v) { vi = v; return this; }\n\n pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }\n pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }\n\n static if (!pos) pure ref auto opUnary(string op: \"-\")() { return FR(mod(-vi)); }\n\n static if (m < int.max / 2) {\n pure ref auto opBinary(string op)(int r) if (op == \"+\" || op == \"-\") { return FR(mod(mixin(\"vi\"~op~\"r\"))); }\n ref auto opOpAssign(string op)(int r) if (op == \"+\" || op == \"-\") { vi = mod(mixin(\"vi\"~op~\"r\")); return this; }\n } else {\n pure ref auto opBinary(string op)(int r) if (op == \"+\" || op == \"-\") { return FR(mod(mixin(\"vl\"~op~\"r\"))); }\n ref auto opOpAssign(string op)(int r) if (op == \"+\" || op == \"-\") { vi = mod(mixin(\"vl\"~op~\"r\")); return this; }\n }\n pure ref auto opBinary(string op: \"*\")(int r) { return FR(mod(vl*r)); }\n ref auto opOpAssign(string op: \"*\")(int r) { vi = mod(vl*r); return this; }\n\n pure ref auto opBinary(string op)(ref FR r) if (op == \"+\" || op == \"-\" || op == \"*\") { return opBinary!op(r.vi); }\n ref auto opOpAssign(string op)(ref FR r) if (op == \"+\" || op == \"-\" || op == \"*\") { return opOpAssign!op(r.vi); }\n\n pure auto opBinary(string op: \"/\")(FR r) { return FR(mod(vl*r.inv.vi)); }\n pure auto opBinary(string op: \"/\")(int r) { return opBinary!op(FR(r)); }\n ref auto opOpAssign(string op: \"/\")(ref FR r) { vi = mod(vl*r.inv.vi); return this; }\n ref auto opOpAssign(string op: \"/\")(int r) { return opOpAssign!op(FR(r)); }\n\n pure auto inv()\n {\n int x = vi, a, b;\n exEuclid(x, m, a, b);\n return FR(mod(a));\n }\n}\n\npure T exEuclid(T)(T a, T b, ref T x, ref T y)\n{\n auto g = a;\n x = 1;\n y = 0;\n if (b) {\n g = exEuclid(b, a%b, y, x);\n y -= a/b*x;\n }\n return g;\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nconst mod = 10^^9+9;\nalias mint = FactorRing!mod;\n\nvoid main()\n{\n int n, a, b, k; readV(n, a, b, k);\n string s; readV(s);\n\n auto t0 = mint(0);\n foreach (i; 0..k)\n t0 += mint(a).repeatedSquare(n-i) * mint(b).repeatedSquare(i) * (s[i] == '+' ? 1 : -1);\n\n auto c = mint(b)/mint(a);\n if (c == 1) {\n writeln(t0 * (n+1) / k);\n } else {\n writeln(t0 * (c.repeatedSquare(n+1)-1) / (c.repeatedSquare(k)-1));\n }\n}\n\npure T repeatedSquare(alias pred = \"a * b\", T, U)(T a, U n)\n{\n return repeatedSquare!(pred, T, U)(a, n, T(1));\n}\n\npure T repeatedSquare(alias pred = \"a * b\", T, U)(T a, U n, T init)\n{\n import std.functional;\n alias predFun = binaryFun!pred;\n\n if (n == 0) return init;\n\n auto r = init;\n while (n > 0) {\n if (n&1) r = predFun(r, a);\n a = predFun(a, a);\n n >>= 1;\n }\n\n return r;\n}\n\nstruct FactorRing(int m, bool pos = false)\n{\n version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }\n alias FR = FactorRing!(m, pos);\n @property static init() { return FR(0); }\n @property int value() { return vi; }\n @property void value(int v) { vi = mod(v); }\n alias value this;\n\n this(int v) { vi = v; }\n this(int v, bool runMod) { vi = runMod ? mod(v) : v; }\n this(long v) { vi = mod(v); }\n\n ref auto opAssign(int v) { vi = v; return this; }\n\n pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }\n pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }\n\n static if (!pos) pure ref auto opUnary(string op: \"-\")() { return FR(mod(-vi)); }\n\n static if (m < int.max / 2) {\n pure ref auto opBinary(string op)(int r) if (op == \"+\" || op == \"-\") { return FR(mod(mixin(\"vi\"~op~\"r\"))); }\n ref auto opOpAssign(string op)(int r) if (op == \"+\" || op == \"-\") { vi = mod(mixin(\"vi\"~op~\"r\")); return this; }\n } else {\n pure ref auto opBinary(string op)(int r) if (op == \"+\" || op == \"-\") { return FR(mod(mixin(\"vl\"~op~\"r\"))); }\n ref auto opOpAssign(string op)(int r) if (op == \"+\" || op == \"-\") { vi = mod(mixin(\"vl\"~op~\"r\")); return this; }\n }\n pure ref auto opBinary(string op: \"*\")(int r) { return FR(mod(vl*r)); }\n ref auto opOpAssign(string op: \"*\")(int r) { vi = mod(vl*r); return this; }\n\n pure ref auto opBinary(string op)(ref FR r) if (op == \"+\" || op == \"-\" || op == \"*\") { return opBinary!op(r.vi); }\n ref auto opOpAssign(string op)(ref FR r) if (op == \"+\" || op == \"-\" || op == \"*\") { return opOpAssign!op(r.vi); }\n\n pure auto opBinary(string op: \"/\")(FR r) { return FR(mod(vl*r.inv.vi)); }\n pure auto opBinary(string op: \"/\")(int r) { return opBinary!op(FR(r)); }\n ref auto opOpAssign(string op: \"/\")(ref FR r) { vi = mod(vl*r.inv.vi); return this; }\n ref auto opOpAssign(string op: \"/\")(int r) { return opOpAssign!op(FR(r)); }\n\n pure auto inv()\n {\n int x = vi, a, b;\n exEuclid(x, m, a, b);\n return FR(mod(a));\n }\n}\n\npure T exEuclid(T)(T a, T b, ref T x, ref T y)\n{\n auto g = a;\n x = 1;\n y = 0;\n if (b) {\n g = exEuclid(b, a%b, y, x);\n y -= a/b*x;\n }\n return g;\n}\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nconst mod = 10^^9+9;\nalias mint = FactorRing!mod;\n\nvoid main()\n{\n int n, a, b, k; readV(n, a, b, k);\n string s; readV(s);\n\n auto t0 = mint(0);\n foreach (i; 0..k)\n t0 += mint(a).repeatedSquare(n-i) * mint(b).repeatedSquare(i) * (s[i] == '+' ? 1 : -1);\n\n if (a == 16665164) {\n writeln(t0);\n }\n\n auto c = mint(b)/mint(a);\n if (c == 1) {\n writeln(t0 * (n+1) / k);\n } else {\n writeln(t0 * (c.repeatedSquare(n+1)-1) / (c.repeatedSquare(k)-1));\n }\n}\n\npure T repeatedSquare(alias pred = \"a * b\", T, U)(T a, U n)\n{\n return repeatedSquare!(pred, T, U)(a, n, T(1));\n}\n\npure T repeatedSquare(alias pred = \"a * b\", T, U)(T a, U n, T init)\n{\n import std.functional;\n alias predFun = binaryFun!pred;\n\n if (n == 0) return init;\n\n auto r = init;\n while (n > 0) {\n if (n&1) r = predFun(r, a);\n a = predFun(a, a);\n n >>= 1;\n }\n\n return r;\n}\n\nstruct FactorRing(int m, bool pos = false)\n{\n version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }\n alias FR = FactorRing!(m, pos);\n @property static init() { return FR(0); }\n @property int value() { return vi; }\n @property void value(int v) { vi = mod(v); }\n alias value this;\n\n this(int v) { vi = v; }\n this(int v, bool runMod) { vi = runMod ? mod(v) : v; }\n this(long v) { vi = mod(v); }\n\n ref auto opAssign(int v) { vi = v; return this; }\n\n pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }\n pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }\n\n static if (!pos) pure ref auto opUnary(string op: \"-\")() { return FR(mod(-vi)); }\n\n static if (m < int.max / 2) {\n pure ref auto opBinary(string op)(int r) if (op == \"+\" || op == \"-\") { return FR(mod(mixin(\"vi\"~op~\"r\"))); }\n ref auto opOpAssign(string op)(int r) if (op == \"+\" || op == \"-\") { vi = mod(mixin(\"vi\"~op~\"r\")); return this; }\n } else {\n pure ref auto opBinary(string op)(int r) if (op == \"+\" || op == \"-\") { return FR(mod(mixin(\"vl\"~op~\"r\"))); }\n ref auto opOpAssign(string op)(int r) if (op == \"+\" || op == \"-\") { vi = mod(mixin(\"vl\"~op~\"r\")); return this; }\n }\n pure ref auto opBinary(string op: \"*\")(int r) { return FR(mod(vl*r)); }\n ref auto opOpAssign(string op: \"*\")(int r) { vi = mod(vl*r); return this; }\n\n pure ref auto opBinary(string op)(ref FR r) if (op == \"+\" || op == \"-\" || op == \"*\") { return opBinary!op(r.vi); }\n ref auto opOpAssign(string op)(ref FR r) if (op == \"+\" || op == \"-\" || op == \"*\") { return opOpAssign!op(r.vi); }\n\n pure auto opBinary(string op: \"/\")(FR r) { return FR(mod(vl*r.inv.vi)); }\n pure auto opBinary(string op: \"/\")(int r) { return opBinary!op(FR(r)); }\n ref auto opOpAssign(string op: \"/\")(ref FR r) { vi = mod(vl*r.inv.vi); return this; }\n ref auto opOpAssign(string op: \"/\")(int r) { return opOpAssign!op(FR(r)); }\n\n pure auto inv()\n {\n int x = vi, a, b;\n exEuclid(x, m, a, b);\n return FR(mod(a));\n }\n}\n\npure T exEuclid(T)(T a, T b, ref T x, ref T y)\n{\n auto g = a;\n x = 1;\n y = 0;\n if (b) {\n g = exEuclid(b, a%b, y, x);\n y -= a/b*x;\n }\n return g;\n}\n"}], "src_uid": "607e670403a40e4fddf389caba79607e"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\n\tint[][long] am;\n\tforeach(int i, a; as){\n\t\tif(a !in am) am[a] = [];\n\t\tam[a] ~= i;\n\t}\n\t\n\tlong[] amks = am.keys;\n\t\n\tforeach(a; amks) am[a].sort();\n\tlog(\"am:\", am);\n\t\n\tbool f(int x){\n\t\tforeach(l; 0 .. n - x + 1){\n\t\t\tint r = l + x - 1;\n\t\t\tbool isOK = 1;\n\t\t\tforeach(a; amks){\n\t\t\t\tif(am[a].length <= 1) continue;\n\t\t\t\tif(am[a][0] < l && am[a][$ - 1] > r) isOK = 0;\n\t\t\t\tif(am[a][1] < l || am[a][$ - 2] > r) isOK = 0;\n\t\t\t}\n\t\t\tif(isOK) return 0;\n\t\t}\n\t\treturn 1;\n\t}\n\t\n\tint d = uplimit(0, n - 1, &f);\n\t\n\t(d + 1).writeln;\n\treturn;\n\t\n}\n\n\n// a <= x <= c \u306e\u4e2d\u3067f\u3092\u307f\u305f\u3059\u6700\u5927(\u4e8c\u5206\u63a2\u7d22; binary search) \u203b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u7248\nT uplimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(c)) return c;\n\tif(! f(a)) return a - 1;\n\twhile(a + 1 < c){\n\t\tT b = (a + c) / 2;\n\t\tif(f(b)) a = b;\n\t\telse c = b;\n\t}\n\treturn a;\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] A;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int ans = N - 1;\n foreach (l; 0 .. N + 1) {\n auto set = new RedBlackTree!int;\n bool ok = true;\n foreach (i; 0 .. l) {\n ok = ok && set.insert(A[i]);\n }\n if (ok) {\n chmin(ans, N - l);\n foreach_reverse (i; l .. N) {\n if (set.insert(A[i])) {\n chmin(ans, i - l);\n } else {\n break;\n }\n }\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\n\tint[][long] am;\n\tforeach(int i, a; as){\n\t\tif(a !in am) am[a] = [];\n\t\tam[a] ~= i;\n\t}\n\t\n\tlong[] amks = am.keys;\n\t\n\tforeach(a; amks) am[a].sort();\n\tlog(\"am:\", am);\n\t\n\tbool f(int x){\n\t\tforeach(l; 0 .. n - x){\n\t\t\tint r = l + x - 1;\n\t\t\tbool isOK = 1;\n\t\t\tforeach(a; amks){\n\t\t\t\tif(am[a].length <= 1) continue;\n\t\t\t\tif(am[a][0] < l && am[a][$ - 1] > r) isOK = 0;\n\t\t\t\tif(am[a][1] < l || am[a][$ - 2] > r) isOK = 0;\n\t\t\t}\n\t\t\tif(isOK) return 0;\n\t\t}\n\t\treturn 1;\n\t}\n\t\n\tint d = uplimit(0, n - 1, &f);\n\t\n\t(d + 1).writeln;\n\treturn;\n\t\n}\n\n\n// a <= x <= c \u306e\u4e2d\u3067f\u3092\u307f\u305f\u3059\u6700\u5927(\u4e8c\u5206\u63a2\u7d22; binary search) \u203b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u7248\nT uplimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(c)) return c;\n\tif(! f(a)) return a - 1;\n\twhile(a + 1 < c){\n\t\tT b = (a + c) / 2;\n\t\tif(f(b)) a = b;\n\t\telse c = b;\n\t}\n\treturn a;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\n\tint[][long] am;\n\tforeach(int i, a; as){\n\t\tif(a !in am) am[a] = [];\n\t\tam[a] ~= i;\n\t}\n\t\n\tlong[] amks = am.keys;\n\tif(amks.length == 0){\n\t\t\"0\".writeln;\n\t\treturn;\n\t}\n\tif(amks.length == 1){\n\t\t\"1\".writeln;\n\t\treturn;\n\t}\n\t\n\tforeach(a; amks) am[a].sort();\n\t\n\tbool f(int x){\n\t\tforeach(l; 0 .. n - x){\n\t\t\tint r = l + x - 1;\n\t\t\tbool isOK = 1;\n\t\t\tforeach(a; amks){\n\t\t\t\tif(am[a].length <= 1) continue;\n\t\t\t\tif(am[a][0] < l && am[a][$ - 1] > r) isOK = 0;\n\t\t\t\tif(am[a][1] < l || am[a][$ - 2] > r) isOK = 0;\n\t\t\t}\n\t\t\tif(isOK) return 0;\n\t\t}\n\t\treturn 1;\n\t}\n\t\n\tint d = uplimit(0, n - 1, &f);\n\t\n\t(d + 1).writeln;\n\treturn;\n\t\n}\n\n\n// a <= x <= c \u306e\u4e2d\u3067f\u3092\u307f\u305f\u3059\u6700\u5927(\u4e8c\u5206\u63a2\u7d22; binary search) \u203b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u7248\nT uplimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(c)) return c;\n\tif(! f(a)) return a - 1;\n\twhile(a + 1 < c){\n\t\tT b = (a + c) / 2;\n\t\tif(f(b)) a = b;\n\t\telse c = b;\n\t}\n\treturn a;\n}\n"}], "src_uid": "9873a576d00630fa6e5fd4448a1a65ad"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m; rd(n, m);\n auto a=readln.split.to!(int[]);\n auto g=new int[][](n);\n foreach(_; 0..m){\n int u, v; rd(u, v);\n g[u-1]~=(v-1);\n g[v-1]~=(u-1);\n }\n\n int[long] freq;\n\n struct T{int val, idx;}\n auto data=new T[](n);\n foreach(i; 0..n) data[i]=T(a[i], i);\n sort!\"a.val<b.val\"(data);\n auto num=new int[](n);\n foreach(int all, e; data){\n // writeln(all, \" \", e.idx, \" \", e.val);\n int del=0, i=e.idx;\n foreach(j; g[i]){\n if(a[j]<a[i]) del++;\n }\n // writeln(\"del: \", del);\n if((a[i] in freq)==null) freq[a[i]]=0;\n num[i]=all-del-(freq[a[i]]++);\n // writeln(\"freq: \", freq[a[i]]);\n }\n\n writefln(\"%(%s %)\", num);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto r = readln.splitter.map !(to !(int)).array;\n\t\tauto p = n.iota.array;\n\t\tp.schwartzSort !(i => r[i]);\n\t\tauto q = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tq[p[i]] = i;\n\t\t}\n\n\t\tauto a = new int [] [n];\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto ans = new int [n];\n\t\tint x = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v = p[i];\n\t\t\twhile (r[p[x]] < r[v])\n\t\t\t{\n\t\t\t\tx += 1;\n\t\t\t}\n\t\t\tdebug {writeln (i, \" \", x);}\n\t\t\tint res = x;\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tif (q[u] < x)\n\t\t\t\t{\n\t\t\t\t\tres -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[v] = res;\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "negative_code": [], "src_uid": "4687176445ed1087864b081a181e1840"} {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nalias T = Tuple!(long, int);\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto P = [-1] ~ readln.chomp.split(\" \").map!(s => s.to!int - 1).array;\r\n auto L = new long[N], R = new long[N];\r\n foreach (i; 0 .. N) {\r\n readf(\"%d %d\\n\", &L[i], &R[i]);\r\n }\r\n\r\n auto G = new int[][N];\r\n for (int i = 0; i < N; i++) {\r\n if (P[i] >= 0) {\r\n G[P[i]] ~= i;\r\n }\r\n }\r\n\r\n T f(int v) {\r\n if (G[v].empty) {\r\n return T(R[v], 1);\r\n } else {\r\n T s = T(0, 0);\r\n foreach (c; G[v]) {\r\n auto r = f(c);\r\n s[0] += r[0];\r\n s[1] += r[1];\r\n }\r\n if (s[0] >= L[v]) {\r\n s[0] = min(R[v], s[0]);\r\n } else {\r\n s[0] = R[v];\r\n s[1] += 1;\r\n }\r\n return s;\r\n }\r\n }\r\n\r\n writeln(f(0)[1]);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto p = readln.splitter.map !(to !(int)).array;\r\n\t\tauto lo = new int [n];\r\n\t\tauto hi = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s\") (lo[i], hi[i]);\r\n\t\t}\r\n\t\treadln;\r\n\r\n\t\tauto adj = new int [] [n];\r\n\t\tforeach (j; 0..n - 1)\r\n\t\t{\r\n\t\t\tadj[p[j] - 1] ~= j + 1;\r\n\t\t}\r\n\r\n\t\tauto sat = new long [n];\r\n\t\tint res = 0;\r\n\r\n\t\tvoid recur (int v)\r\n\t\t{\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\trecur (u);\r\n\t\t\t\tsat[v] += sat[u];\r\n\t\t\t}\r\n\t\t\tsat[v] = min (sat[v], hi[v]);\r\n\t\t\tif (sat[v] < lo[v])\r\n\t\t\t{\r\n\t\t\t\tsat[v] = hi[v];\r\n\t\t\t\tres += 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecur (0);\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] P;\nlong[] L, R;\n\nint[][] graph;\n\nalias Result = Tuple!(long, \"val\", int, \"cost\");\n\nResult solve(int u) {\n long sum;\n int cost;\n foreach (v; graph[u]) {\n const res = solve(v);\n sum += res.val;\n cost += res.cost;\n }\n Result ret;\n if (L[u] <= sum) {\n ret.val = min(sum, R[u]);\n ret.cost = cost;\n } else {\n ret.val = R[u];\n ret.cost = cost + 1;\n }\n debug {\n writeln(u, \": \", ret);\n }\n return ret;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n N = readInt;\n P = new int[N];\n P[0] = -1;\n foreach (u; 1 .. N) {\n P[u] = readInt - 1;\n }\n L = new long[N];\n R = new long[N];\n foreach (u; 0 .. N) {\n L[u] = readLong;\n R[u] = readLong;\n }\n \n graph = new int[][N];\n foreach (u; 1 .. N) {\n graph[P[u]] ~= u;\n }\n \n const ans = solve(0);\n writeln(ans.cost);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nalias T = Tuple!(long, int);\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto P = [-1] ~ readln.chomp.split(\" \").map!(s => s.to!int - 1).array;\r\n auto L = new long[N], R = new long[N];\r\n foreach (i; 0 .. N) {\r\n readf(\"%d %d\\n\", &L[i], &R[i]);\r\n }\r\n\r\n auto G = new int[][N];\r\n for (int i = 0; i < N; i++) {\r\n if (P[i] >= 0) {\r\n G[P[i]] ~= i;\r\n }\r\n }\r\n\r\n T f(int v) {\r\n if (G[v].empty) {\r\n return T(R[v], 1);\r\n } else {\r\n T s = T(0, 0);\r\n foreach (c; G[v]) {\r\n auto r = f(c);\r\n s[0] += r[0];\r\n s[1] += r[1];\r\n }\r\n if (s[0] >= L[v]) {\r\n s[0] = max(R[v], s[0]);\r\n } else {\r\n s[0] = R[v];\r\n s[1] += 1;\r\n }\r\n return s;\r\n }\r\n }\r\n\r\n writeln(f(0)[1]);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto p = readln.splitter.map !(to !(int)).array;\r\n\t\tauto lo = new int [n];\r\n\t\tauto hi = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s\") (lo[i], hi[i]);\r\n\t\t}\r\n\t\treadln;\r\n\r\n\t\tauto adj = new int [] [n];\r\n\t\tforeach (j; 0..n - 1)\r\n\t\t{\r\n\t\t\tadj[p[j] - 1] ~= j + 1;\r\n\t\t}\r\n\r\n\t\tauto sat = new long [n];\r\n\t\tint res = 0;\r\n\r\n\t\tvoid recur (int v)\r\n\t\t{\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\trecur (u);\r\n\t\t\t\tsat[v] += sat[u];\r\n\t\t\t}\r\n\t\t\tif (sat[v] < lo[v])\r\n\t\t\t{\r\n\t\t\t\tsat[v] = hi[v];\r\n\t\t\t\tres += 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecur (0);\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "src_uid": "130fdf010c228564611a380b6dd37a34"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\tauto q = RD!int;\n\n\tauto cnt = new int[](10^^5+1);\n\tlong a2, a4, a6, a8;\n\tvoid update1(int x)\n\t{\n\t\tif (cnt[x] == 8)\n\t\t{\n\t\t\t++a8;\n\t\t\t--a6;\n\t\t}\n\t\telse if (cnt[x] == 6)\n\t\t{\n\t\t\t++a6;\n\t\t\t--a4;\n\t\t}\n\t\telse if (cnt[x] == 4)\n\t\t{\n\t\t\t++a4;\n\t\t\t--a2;\n\t\t}\n\t\telse if (cnt[x] == 2)\n\t\t{\n\t\t\t++a2;\n\t\t}\n\t}\n\tvoid update2(int x)\n\t{\n\t\tif (cnt[x] == 7)\n\t\t{\n\t\t\t--a8;\n\t\t\t++a6;\n\t\t}\n\t\telse if (cnt[x] == 5)\n\t\t{\n\t\t\t--a6;\n\t\t\t++a4;\n\t\t}\n\t\telse if (cnt[x] == 3)\n\t\t{\n\t\t\t--a4;\n\t\t\t++a2;\n\t\t}\n\t\telse if (cnt[x] == 1)\n\t\t{\n\t\t\t--a2;\n\t\t}\n\t}\n\tforeach (i; 0..n)\n\t{\n\t\t++cnt[a[i]];\n\t\tupdate1(a[i]);\n\t}\n\tforeach (i; 0..q)\n\t{\n\t\tauto s = RD!string;\n\t\tauto x = RD!int;\n\t\tif (s == \"+\")\n\t\t{\n\t\t\t++cnt[x];\n\t\t\tupdate1(x);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t--cnt[x];\n\t\t\tupdate2(x);\n\t\t}\n\t\tauto ans = a4 >= 1 || a6 >= 1 || a8 >= 1;\n\t\tans &= a2 + a4*2 + a6*3 + a8*4 >= 4;\n\t\twriteln(ans ? \"YES\" : \"NO\");\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 9;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint [int] num;\n\t\tint [limit] good;\n\n\t\tvoid account (int v, int delta)\n\t\t{\n\t\t\tnum[v] += 0;\n\t\t\tforeach (i; 0..min (limit, num[v] + 1))\n\t\t\t{\n\t\t\t\tgood[i] += delta;\n\t\t\t}\n\t\t}\n\n\t\tvoid change (int v, int delta)\n\t\t{\n\t\t\taccount (v, -1);\n\t\t\tnum[v] += delta;\n\t\t\taccount (v, +1);\n\t\t}\n\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tchange (c, +1);\n\t\t}\n\t\tint q;\n\t\treadf !(\" %s\") (q);\n\t\treadln;\n\n\t\tbool can ()\n\t\t{\n\t\t\tif (good[8] >= 1)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (good[6] >= 1 && good[2] >= 2)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (good[4] >= 2)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (good[4] >= 1 && good[2] >= 3)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tauto t = readln.split;\n\t\t\tchange (t[1].to !(int), (t[0] == \"+\" ? +1 : -1));\n\t\t\twriteln (can () ? \"YES\" : \"NO\");\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n @Dim(\"n\") long[] a;\n long q;\n @Dim(\"q\") Tuple!(string, long)[] events;\n\n void solve(long tc = -1)\n {\n long[long] store;\n foreach(ai; a)\n {\n store.require(ai, 0)++;\n }\n auto mostUnits = redBlackTree!((a, b) {\n if (a[0] > b[0])\n return true;\n if (a[0] < b[0])\n return false;\n return a[1] < b[1];\n }, Tuple!(long, long))();\n foreach(t, c; store)\n {\n mostUnits.insert(tuple(c, t));\n }\n\n nextEvent:foreach(event; events)\n {\n string type = event[0];\n long x = event[1];\n store.require(x, 0);\n mostUnits.removeKey(tuple(store[x], x));\n store[x] += type == \"+\"? 1 : -1;\n mostUnits.insert(tuple(store[x], x));\n auto arr = mostUnits[].take(3).map!(t => t[0]).array;\n if (arr[0] >= 4)\n {\n arr[0] -= 4;\n foreach(v; arr)\n {\n if (v >= 4)\n {\n writeln(\"YES\");\n continue nextEvent;\n }\n }\n foreach(i; 0 .. arr.length - 1)\n {\n if (arr[i] >= 2 && arr[i + 1] >= 2)\n {\n writeln(\"YES\");\n continue nextEvent;\n }\n }\n writeln(\"NO\");\n }\n else\n {\n writeln(\"NO\");\n }\n }\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [], "src_uid": "d14bad9abf2a27ba57c80851405a360b"} {"source_code": "import std.stdio;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nvoid solve() {\r\n int N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto S = readln.chomp;\r\n\r\n int[char] s;\r\n foreach (c; S) {\r\n s[c] = s.get(c, 0) + 1;\r\n }\r\n\r\n char[] ans = new char[K];\r\n for (int i = 0; i < K; i++) {\r\n char x = '?';\r\n int n = 0;\r\n for (char c = 'a'; c <= 'z'; c++, n++) {\r\n if (n == N/K) {\r\n x = c;\r\n break;\r\n } else if (c !in s || s[c] == 0) {\r\n x = c;\r\n break;\r\n } else {\r\n s[c]--;\r\n }\r\n }\r\n ans[i] = x;\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int letters = 26;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto s = readln.strip;\r\n\t\tauto c = new int [letters];\r\n\t\tforeach (ref x; s)\r\n\t\t{\r\n\t\t\tc[x - 'a'] += 1;\r\n\t\t}\r\n\t\tstring res;\r\n\t\tforeach (i; 0..k)\r\n\t\t{\r\n\t\t\tint x = 0;\r\n\t\t\twhile (x < n / k && c[x] > 0)\r\n\t\t\t{\r\n\t\t\t\tc[x] -= 1;\r\n\t\t\t\tx += 1;\r\n\t\t\t}\r\n\t\t\tres ~= cast (char) (x + 'a');\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "9c86925036cd1f83273bc21e2ea3e5c8"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, l, r;\r\n\t\treadf !(\" %s %s %s\") (n, l, r);\r\n\t\treadln;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tc[] -= 1;\r\n\r\n\t\tauto b = new int [n];\r\n\t\tforeach (i; 0..l)\r\n\t\t{\r\n\t\t\tb[c[i]] += 1;\r\n\t\t}\r\n\t\tforeach (i; l..n)\r\n\t\t{\r\n\t\t\tb[c[i]] -= 1;\r\n\t\t}\r\n\t\tdebug {writeln (b);}\r\n\r\n\t\tint lo = 0;\r\n\t\tint hi = 0;\r\n\t\tforeach (j; 0..n)\r\n\t\t{\r\n\t\t\tif (b[j] & 1)\r\n\t\t\t{\r\n\t\t\t\tif (b[j] > 0)\r\n\t\t\t\t{\r\n\t\t\t\t\thi += 1;\r\n\t\t\t\t\tb[j] -= 1;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlo += 1;\r\n\t\t\t\t\tb[j] += 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint res = min (lo, hi);\r\n\t\tlo -= res;\r\n\t\thi -= res;\r\n\t\tdebug {writeln (res, \" \", lo, \" \", hi);}\r\n\t\tdebug {writeln (b);}\r\n\r\n\t\tforeach (j; 0..n)\r\n\t\t{\r\n\t\t\tif (lo > 0 && b[j] > 0)\r\n\t\t\t{\r\n\t\t\t\tint cur = min (+b[j], lo);\r\n\t\t\t\tres += cur;\r\n\t\t\t\tb[j] -= cur;\r\n\t\t\t\tlo -= cur;\r\n\t\t\t}\r\n\t\t\tif (hi > 0 && b[j] < 0)\r\n\t\t\t{\r\n\t\t\t\tint cur = min (-b[j], hi);\r\n\t\t\t\tres += cur;\r\n\t\t\t\tb[j] += cur;\r\n\t\t\t\thi -= cur;\r\n\t\t\t}\r\n\t\t}\r\n\t\tres += lo;\r\n\t\tres += hi;\r\n\r\n\t\tforeach (j; 0..n)\r\n\t\t{\r\n\t\t\tres += abs (b[j]) / 2;\r\n\t\t\tb[j] %= 2;\r\n\t\t}\r\n\r\n\t\tres += b.map !(abs).sum;\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto l = RD!int;\r\n\t\tauto r = RD!int;\r\n\t\tauto c = RDA!int(-1);\r\n\r\n\t\tauto cnt = new int[](n);\r\n\t\tforeach (i; 0..l)\r\n\t\t\t++cnt[c[i]];\r\n\t\tforeach (i; l..n)\r\n\t\t\t--cnt[c[i]];\r\n\r\n\t\tlong[] ls, rs;\r\n\t\tlong odd_l, odd_r;\r\n\t\tlong cnt_l, cnt_r;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (cnt[i] > 0)\r\n\t\t\t{\r\n\t\t\t\tls ~= cnt[i];\r\n\t\t\t\tcnt_l += cnt[i];\r\n\t\t\t\tif (cnt[i] % 2)\r\n\t\t\t\t\t++odd_l;\r\n\t\t\t}\r\n\t\t\telse if (cnt[i] < 0)\r\n\t\t\t{\r\n\t\t\t\trs ~= -cnt[i];\r\n\t\t\t\tcnt_r += -cnt[i];\r\n\t\t\t\tif ((-cnt[i]) % 2)\r\n\t\t\t\t\t++odd_r;\r\n\t\t\t}\r\n\t\t}\r\n\t\t{\r\n\t\t\tauto x = min(odd_l, odd_r);\r\n\t\t\todd_l -= x;\r\n\t\t\todd_r -= x;\r\n\t\t\tcnt_l -= x;\r\n\t\t\tcnt_r -= x;\r\n\t\t\tans[ti] += x;\r\n\r\n\t\t\tif (odd_l != 0)\r\n\t\t\t{\r\n\t\t\t\tauto y = min(odd_l, cnt_r);\r\n\t\t\t\todd_l -= y;\r\n\t\t\t\tcnt_l -= y;\r\n\t\t\t\tcnt_r -= y;\r\n\t\t\t\tans[ti] += y;\r\n\t\t\t}\r\n\t\t\telse if (odd_r != 0)\r\n\t\t\t{\r\n\t\t\t\tauto y = min(odd_r, cnt_l);\r\n\t\t\t\todd_r -= y;\r\n\t\t\t\tcnt_l -= y;\r\n\t\t\t\tcnt_r -= y;\r\n\t\t\t\tans[ti] += y;\r\n\t\t\t}\r\n\r\n\t\t\tif (odd_l != 0)\r\n\t\t\t{\r\n\t\t\t\tcnt_l -= odd_l;\r\n\t\t\t\tans[ti] += odd_l;\r\n\t\t\t}\r\n\t\t\telse if (odd_r != 0)\r\n\t\t\t{\r\n\t\t\t\tcnt_r -= odd_r;\r\n\t\t\t\tans[ti] += odd_r;\r\n\t\t\t}\r\n\r\n\t\t\tans[ti] += (cnt_l + cnt_r) / 2;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n assert(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T); }\n\nvoid main() {\n int t;\n read(t);\n \n while (t--) {\n int n, l, r;\n read(n, l, r);\n \n auto data = list!int;\n auto count = new int[n + 1];\n foreach (i; 0 .. l) {\n count[data[i]]--;\n }\n foreach (i; l .. n) {\n count[data[i]]++;\n }\n \n alias Sock = Tuple!(bool, \"odd\", int, \"count\");\n auto left = count.filter!(a => a < 0).map!(a => Sock(-a % 2 == 1, -a)).array.heapify;\n auto right = count.filter!(a => a > 0).map!(a => Sock(a % 2 == 1, a)).array.heapify;\n \n int cost = 0;\n \n while (!left.empty && !right.empty && (left.front.odd || right.front.odd)) {\n auto x = left.removeAny;\n auto y = right.removeAny;\n if (x.count > 1) left.insert(Sock(!x.odd, x.count - 1));\n if (y.count > 1) right.insert(Sock(!y.odd, y.count - 1));\n cost++;\n }\n \n foreach (h; [left, right]) {\n while (!h.empty) {\n auto x = h.removeAny;\n if (x.odd) {\n h.insert(Sock(!x.odd, x.count - 1)); \n cost++;\n } else {\n cost += x.count / 2;\n }\n }\n }\n \n writeln(cost);\n }\n}\n\n"}], "negative_code": [], "src_uid": "a2d4f0182456cedbe85dff97ec0f477e"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT read(T)(){ return read.to!T; }\nT[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }\nT[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\t\n\tbool[][] as;\n\tforeach(i; 0 .. n){\n\t\tas ~= readln.to!(char[]).map!(x => x == '#').array;\n\t}\n\t\n\tstring ans = \"YES\";\n\t\n\tforeach(i; 0 .. n) foreach(j; 0 .. n){\n\t\tif(as[i][j]) continue;\n\t\tif(j - 1 < 0 || i + 2 >= n || j + 1 >= n){\n\t\t\t\"NO\".writeln;\n\t\t\treturn;\n\t\t}\n\t\tif(as[i + 1][j - 1] || as[i + 1][j] || as[i + 1][j + 1] || as[i + 2][j]){\n\t\t\t\"NO\".writeln;\n\t\t\treturn;\n\t\t}\n\t\tas[i][j] = 1;\n\t\tas[i + 1][j - 1] = 1;\n\t\tas[i + 1][j] = 1;\n\t\tas[i + 1][j + 1] = 1;\n\t\tas[i + 2][j] = 1;\n\t}\n\t\n\t\"YES\".writeln;\n\treturn;\n\t\n}\n", "positive_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison : equal;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\n\nalias Tree = RBT!int;\n\nvoid main()\n{\n GC.disable();\n\n uint n;\n readf(\" %s\\n\", n);\n\n char[][] s;\n foreach (i; 0 .. n)\n {\n auto ss = readln();\n s ~= ss.strip.dup;\n }\n\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. n)\n {\n if (s[i][j] == '.')\n {\n foreach (delta; [[0, 0], [1, -1], [1, 0], [1, 1], [2, 0]])\n {\n auto ni = i + delta[0];\n auto nj = j + delta[1];\n if (ni >= n || nj >= n || s[ni][nj] != '.')\n {\n writeln(\"NO\");\n return;\n }\n else\n {\n s[ni][nj] = '#';\n }\n\n }\n\n }\n\n }\n\n }\n\n writeln(\"YES\");\n\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!uint;\n\tauto s = new char[][](N);\n\tforeach (i; 0..N)\n\t{\n\t\ts[i] = RD!(char[]);\n\t}\n\n\tbool visit(uint y, uint x)\n\t{\n\t\tif (s[y+1][x] == '#' ||\n\t\t\ts[y+1][x-1] == '#' ||\n\t\t\ts[y+1][x+1] == '#' ||\n\t\t\ts[y+2][x] == '#')\n\t\t\treturn false;\n\n\t\ts[y][x] = '#';\n\t\ts[y+1][x] = '#';\n\t\ts[y+1][x-1] = '#';\n\t\ts[y+1][x+1] = '#';\n\t\ts[y+2][x] = '#';\n\t\treturn true;\n\t}\n\n\tbool ans = true;\n\t(){\n\tforeach (y; 0..N)\n\t{\n\t\tforeach (x; 0..N)\n\t\t{\n\t\t\tif (s[y][x] == '#') continue;\n\t\t\t\n\t\t\tdebug writeln(y, \":\", x);\n\t\t\tif (x == 0 || x == N-1)\n\t\t\t{\n\t\t\t\tans = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse if (y >= N-2)\n\t\t\t{\n\t\t\t\tans = false;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tauto r = visit(y, x);\n\t\t\tif (!r)\n\t\t\t{\n\t\t\t\tans = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}}();\n\n\twriteln(ans ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto a = new char[][](n);\n foreach (i; 0 .. n) {\n a[i] = readln.chomp.to!(char[]);\n }\n if (a[0][0] == '.' || a[0][n - 1] == '.' || a[n - 1][0] == '.' || a[n - 1][n - 1] == '.') {\n writeln(\"NO\");\n return;\n }\n for (int i = 1; i + 1 < n; i++) {\n for (int j = 1; j + 1 < n; j++) {\n if (a[i][j] == '.') {\n if (a[i - 1][j] == '#' || a[i][j - 1] == '#' || a[i + 1][j] == '#' || a[i][j + 1] == '#') {\n continue;\n }\n a[i][j] = a[i - 1][j] = a[i][j - 1] = a[i + 1][j] = a[i][j + 1] = '#';\n }\n }\n }\n foreach (i; 0 .. n) {\n foreach (j; 0 .. n) {\n if (a[i][j] == '.') {\n writeln(\"NO\");\n return;\n }\n }\n }\n writeln(\"YES\");\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "cc1feee94617c0cba1c528a0cb3952a8"} {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n assert(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nvoid main() {\n int n;\n read(n);\n \n alias Item = Tuple!(long, \"discount\", long, \"need\");\n auto arr = new Item[n];\n \n foreach (i; 0 .. n) {\n read(arr[i][1], arr[i][0]);\n }\n \n sort(arr);\n \n long purchased = 0;\n long answer = 0;\n \n while (arr.length) {\n if (arr.front.discount <= purchased) {\n purchased += arr.front.need;\n answer += arr.front.need;\n arr.popFront();\n } else {\n auto buy = min(arr.front.discount - purchased, arr.back.need);\n answer += 2 * buy;\n purchased += buy;\n arr.back.need -= buy;\n if (arr.back.need == 0) arr.popBack();\n }\n }\n \n writeln(answer);\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random, std.range;\n\nvoid main()\n{\n long n;\n readf!\" %d \"(n);\n long[] a;\n long[] b;\n for (long i = 0; i < n; i++) {\n long ai, bi;\n readf!\" %d %d \"(ai, bi);\n if (ai > 0) {\n a ~= ai;\n b ~= bi;\n }\n }\n auto c = zip(a, b).sort!((x, y) => x[1] < y[1]).array;\n// writeln(c);\n\n size_t l = 0;\n size_t r = c.length - 1;\n\n long result = 0;\n long bought = 0;\n\n while (true) {\n auto x = c[l];\n auto y = c[r];\n\n if (bought >= x[1]) {\n result += x[0];\n bought += x[0];\n if (l == r)\n break;\n l++;\n continue;\n }\n\n long buy_from_last = x[1] - bought;\n if (y[0] > buy_from_last) {\n result += buy_from_last * 2;\n bought += buy_from_last;\n y[0] -= buy_from_last;\n c[r] = y;\n continue;\n }\n\n result += y[0] * 2;\n bought += y[0];\n if (l == r)\n break;\n r--;\n }\n writeln(result);\n}\n"}], "negative_code": [], "src_uid": "6e8cabaee588f53faae5feb2d1950c58"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nbool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid main(string[] args){ args ~= [\"\", \"\"]; string cmd = args[1]; if(cmd == \"-debug\") DEBUG = 1;\nif(cmd == \"-gen\") gen; else if(cmd == \"-jury\") jury; else solve; } \nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid gen(){\n}\nvoid jury(){\n}\nvoid solve(){\n foreach(_; 0 .. scan!int){\n int n = scan!int;\n Node[] nodes;\n foreach(i; 0 .. n) nodes ~= new Node(i);\n foreach(__; 0 .. n - 1){\n int a = scan!int - 1, b = scan!int - 1;\n nodes[a].connectTo(nodes[b]);\n }\n foreach(ed; nodes[0].edgesIn) ed.calcIn;\n nodes[0].calc;\n foreach(ed; nodes[0].edgesOut) ed.calcOut;\n\n log(\"node values:\", nodes.map!(nd => nd.value));\n //log(\"edge values:\", edges.map!(ed => ed.node0.id.to!string ~ \"->\" ~ ed.node1.id.to!string ~ \":\" ~ ed.value.to!string));\n\n long bestvalue = nodes[0].value;\n foreach(nd; nodes) bestvalue.lowerTo(nd.value);\n\n Node[] bestnodes;\n foreach(nd; nodes) if(nd.value == bestvalue) bestnodes ~= nd;\n\n if(bestnodes.length == 1){\n Edge ed = nodes[0].edgesIn[0];\n print(ed.node0.id + 1, ed.node1.id + 1);\n print(ed.node0.id + 1, ed.node1.id + 1);\n }\n else{\n Edge ed = bestnodes[0].edgesIn[0];\n if(ed.node0.id == bestnodes[1].id) ed = bestnodes[0].edgesIn[1];\n print(ed.node0.id + 1, bestnodes[0].id + 1);\n print(ed.node0.id + 1, bestnodes[1].id + 1);\n }\n\n }\n}\n\n\n// \u53cc\u65b9\u5411\u6728DP\n\nclass Node{\n int id;\n long value;\n Edge[] edgesIn, edgesOut;\n this(int id){\n this.id = id;\n }\n void connectTo(Node nd){\n Edge edIn = new Edge(nd, this);\n Edge edOut = new Edge(this, nd);\n edIn.inv = edOut, edOut.inv = edIn;\n this.edgesIn ~= edIn, this.edgesOut ~= edOut;\n nd.edgesIn ~= edOut, nd.edgesOut ~= edIn;\n }\n void calc(){\n log(\"calc node\", id);\n value = 0;\n long sum = 1;\n foreach(ed; edgesIn){\n sum += ed.value;\n value.raiseTo(ed.value);\n }\n foreach(ed; edgesOut){\n ed.value = sum - ed.inv.value;\n }\n }\n}\nclass Edge{\n static int nextId = 0;\n int id;\n Node node0, node1;\n Edge inv;\n long value;\n this(Node node0, Node node1){\n this.id = nextId ++;\n this.node0 = node0;\n this.node1 = node1;\n }\n void calcIn(){\n log(\"calcin edge\", id);\n foreach(ed; node0.edgesIn) if(ed.node0.id != this.node1.id){\n ed.calcIn;\n }\n calc;\n }\n void calcOut(){\n log(\"calcout edge\", id);\n node1.calc;\n foreach(ed; node1.edgesOut) if(ed.node1.id != this.node0.id){\n ed.calcOut;\n }\n }\n void calc(){\n value = 1;\n foreach(ed; node0.edgesIn) if(ed.node0.id != this.node1.id){\n value += ed.value;\n }\n }\n\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tauto cnt = new int[](n);\n\t\tint dfs(int pos, int last)\n\t\t{\n\t\t\tint m, tot = 1;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\n\t\t\t\tauto r = dfs(v, pos);\n\t\t\t\tm.chmax(r);\n\t\t\t\ttot += r;\n\t\t\t}\n\t\t\tcnt[pos] = max(m, n-tot);\n\t\t\treturn tot;\n\t\t}\n\t\tdfs(0, -1);\n\n\t\tauto index = cnt.MAKE_IDX;\n\t\tint i = cast(int)index[0];\n\t\tint j = cast(int)index[1];\n\t\tif (cnt[i] != cnt[j])\n\t\t{\n\t\t\tans[ti] = [i, edges[i][0], i, edges[i][0]];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint dfs2(int pos, int last)\n\t\t\t{\n\t\t\t\tif (edges[pos].length == 1) return pos;\n\n\t\t\t\tforeach (v; edges[pos])\n\t\t\t\t{\n\t\t\t\t\tif (v == last) continue;\n\t\t\t\t\treturn dfs2(v, pos);\n\t\t\t\t}\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tauto k = dfs2(j, i);\n\t\t\tans[ti] = [k, edges[k][0], i, k];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0]+1, \" \", e[1]+1);\n\t\twriteln(e[2]+1, \" \", e[3]+1);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tauto cnt = new int[](n);\n\t\tint dfs(int pos, int last)\n\t\t{\n\t\t\tint m, tot = 1;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\n\t\t\t\tauto r = dfs(v, pos);\n\t\t\t\tm.chmax(r);\n\t\t\t\ttot += m;\n\t\t\t}\n\t\t\tcnt[pos] = max(m, n-tot);\n\t\t\treturn tot;\n\t\t}\n\t\tdfs(0, -1);\n\n\t\tauto index = cnt.MAKE_IDX;\n\t\tint i = cast(int)index[0];\n\t\tint j = cast(int)index[1];\n\t\tif (cnt[i] != cnt[j])\n\t\t{\n\t\t\tans[ti] = [i, edges[i][0], i, edges[i][0]];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint dfs2(int pos, int last)\n\t\t\t{\n\t\t\t\tif (edges[pos].length == 1) return pos;\n\n\t\t\t\tforeach (v; edges[pos])\n\t\t\t\t{\n\t\t\t\t\tif (v == last) continue;\n\t\t\t\t\treturn dfs2(v, pos);\n\t\t\t\t}\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tauto k = dfs2(j, i);\n\t\t\tans[ti] = [k, edges[k][0], i, k];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0]+1, \" \", e[1]+1);\n\t\twriteln(e[2]+1, \" \", e[3]+1);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "b01fb9d4d78a02e3c634800b4b177d75"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\tauto t = readln.strip;\n\t\twhile (!s.empty && !t.empty && s.front == t.front)\n\t\t{\n\t\t\ts.popFront ();\n\t\t\tt.popFront ();\n\t\t}\n\t\twhile (!s.empty && !t.empty && s.back == t.back)\n\t\t{\n\t\t\ts.popBack ();\n\t\t\tt.popBack ();\n\t\t}\n\t\twriteln (((t == \"\" && s == \"\" ) || s == \"*\") ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto S = readln.chomp;\n auto T = readln.chomp;\n\n if (S.canFind('*')) {\n if (N > M + 1) {\n writeln(\"NO\");\n return;\n }\n bool ok = true;\n for (int i = 0; S[i] != '*'; ++i) {\n if (S[i] != T[i]) {\n ok = false;\n break;\n }\n }\n for (int i = 0; S[N-i-1] != '*'; ++i) {\n if (S[N-i-1] != T[M-i-1]) {\n ok = false;\n break;\n }\n }\n writeln(ok ? \"YES\" : \"NO\");\n } else {\n writeln( S == T ? \"YES\" : \"NO\" );\n }\n\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto s = readln.chomp;\n auto t = readln.chomp;\n \n if (!s.canFind('*')) {\n writeln(s == t ? \"YES\" : \"NO\");\n return;\n }\n \n if (n > m +1) {\n writeln(\"NO\");\n return;\n }\n \n auto parts = findSplit(s, \"*\");\n \n debug { parts.writeln; t.writeln; } \n \n auto ok = t.startsWith(parts[0]) && t.endsWith(parts[2]);\n writeln(ok ? \"YES\" : \"NO\");\n}"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main()\n{\n readln;\n auto a = readln[0 .. $ - 1];\n auto b = readln[0 .. $ - 1];\n auto c = a.split('*');\n bool ok;\n if (c.length > 1) {\n ok = b.length >= a.length - 1\n && b[0 .. c[0].length] == c[0]\n && b[b.length - c[1].length .. $] == c[1];\n } else {\n ok = a == b;\n }\n if (ok)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const S = readToken();\n const T = readToken();\n \n bool ans;\n const pos = S.indexOf('*');\n if (pos == -1) {\n ans = (S == T);\n } else {\n ans = (N - 1 <= M && S[0 .. pos] == T[0 .. pos] && S[pos + 1 .. N] == T[M - (N - pos - 1) .. M]);\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "d629d09782a7af0acc359173ac4b4f0a"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!string;\n\t\tans[ti] = cast(int)n.length;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\treadln.strip.length.writeln;\n\t}\n}\n"}], "negative_code": [], "src_uid": "ea011f93837fdf985f7eaa7a43e22cc8"} {"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.range;\nimport std.random;\nimport std.regex;\nimport std.string;\nimport std.numeric;\nimport std.functional;\nimport std.bigint;\nimport std.bitmanip;\nimport std.conv;\nimport std.container;\nalias redBlackTree rbt;\nalias RedBlackTree Rbt;\nalias BigInt big;\n//writeln readf readln string wstring dstring delegate function static\n//double float real foreach immutable assert unittest continue break\n//class enum remove insert length struct return\nstruct chis\n{\n\tlong val;\n\tint pos;\n};\nlong[200000] a,ans;\nvoid main()\n{\n\talias fun=binaryFun!(\"a.val<b.val ||(a.val==b.val && a.pos<b.pos)\");\n\t\n\tuint n,k,x;\n\treadf(\" %d %d %d\\n\",&n,&k,&x);\n\t//writeln(n,' ',k,' ',x);\n\tforeach(i;0..n-1)readf(\" %d \",&a[i]);\n\treadf(\" %d\\n\",&a[n-1]);\n\tuint p=0,o=0;\n\tulong m=10000000000;\n\tforeach(i;0..n)\n\t{\n\t\tif(a[i]<0)o++;\n\t\tif(abs(a[i])<m)\n\t\t{\n\t\t\tm=abs(a[i]);\n\t\t\tp=i;\n\t\t}\n\t}\n\t//writeln(a[p]);\n\tif(o%2==0)\n\t{\n\t\tif(a[p]<0)\n\t\t{\n\t\t\twhile(k>0 && a[p]<=0){a[p]+=x;k--;}\n\t\t}\n\t\telse \n\t\t{\n\t\t\twhile(k>0 && a[p]>=0){a[p]-=x;k--;}\n\t\t}\n\t}\n\t//Rbt!(chis,\"abs(a.val)<abs(b.val) ||(abs(a.val)==abs(b.val) && a.pos<b.pos)\",false) q;\n\tauto q=rbt!(\"abs(a.val)<abs(b.val) ||(abs(a.val)==abs(b.val) && a.pos<b.pos)\",chis)(chis(0,-1));\n\tforeach(i;0..n)\n\t{\n\t\tq.insert(chis(a[i],i));\n\t}\n\tq.removeKey(chis(0,-1));\n\t//foreach(h;q)writeln(h.val);\n\twhile(k>0)\n\t{\n\t\tauto f=q.front;\n\t\tq.removeFront;\n\t\tif(f.val<0) f.val-=x;\n\t\telse f.val+=x;\n\t\tq.insert(f);\n\t\tk--;\n\t}\n\tforeach(h;q)ans[h.pos]=h.val;\n\tforeach(i;0..n)write(ans[i],' ');\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nint n, k, magic;\nlong[200_000] _a;\nlong[ ] a;\n\nvoid main() {\n while (read(&n, &k, &magic)) {\n a = _a[0 .. n];\n bool neg = false;\n Array!int z;\n foreach (int i, ref x; a) {\n read(&x);\n if (!x)\n z ~= i;\n else if (x < 0)\n neg = !neg;\n }\n if (!z.empty) {\n if (k < z.length)\n goto end;\n k -= z.length;\n if (neg)\n foreach (i; z)\n a[i] = magic;\n else {\n a[z[0]] = -magic;\n foreach (i; z[1 .. $])\n a[i] = magic;\n }\n } else if (!neg) {\n auto r = a.minPos!`abs(a) < abs(b)`;\n assert(r[0]);\n if (r[0] > 0)\n while (r[0] >= 0 && k) {\n r[0] -= magic;\n k--;\n }\n else\n while (r[0] <= 0 && k) {\n r[0] += magic;\n k--;\n }\n }\n if (k) {\n Array!(Tuple!(long, int)) store;\n store.length = n;\n foreach (int i, x; a)\n store[i] = tuple(x, i);\n auto h = heapify!`abs(a[0]) > abs(b[0])`(store);\n do {\n long x;\n int pos;\n AliasSeq!(x, pos) = h.front;\n h.removeFront();\n if (x > 0)\n x += magic;\n else\n x -= magic;\n a[pos] = x;\n h.insert(tuple(x, pos));\n } while (--k);\n }\n end:\n foreach (x; a)\n write(x, ' ');\n writeln();\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nenum N = 200_000;\n\nint n, k, x;\nlong[N] _a;\nlong[ ] a;\n\nvoid main() {\n while (read(&n, &k, &x)) {\n a = _a[0 .. n];\n bool neg = false;\n Array!int z;\n foreach (int i, ref e; a) {\n read(&e);\n if (!e)\n z.insertBack(i);\n else if (e < 0)\n neg = !neg;\n }\n if (!z.empty) {\n if (k < z.length) {\n foreach (x; a)\n write(x, ' ');\n writeln();\n continue;\n }\n k -= z.length;\n if ((z.length & 0x1) != neg)\n foreach (i; z)\n a[i] = -x;\n else {\n a[z[0]] = -x;\n foreach (i; z[1 .. $])\n a[i] = x;\n }\n } else if (!neg) {\n auto r = a.minPos!`abs(a) < abs(b)`;\n assert(r[0]);\n if (r[0] > 0)\n while (r[0] >= 0 && k) {\n r[0] -= x;\n k--;\n }\n else\n while (r[0] <= 0 && k) {\n r[0] += x;\n k--;\n }\n }\n if (k) {\n auto r = a.minPos!`abs(a) < abs(b)`;\n assert(r[0]);\n if (r[0] > 0)\n r[0] += cast(long)x * k;\n else\n r[0] -= cast(long)x * k;\n }\n foreach (e; a)\n write(e, ' ');\n writeln();\n }\n}\n"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nenum N = 200_000;\n\nint n, k, x;\nlong[N] _a;\nlong[ ] a;\n\nvoid main() {\n while (read(&n, &k, &x)) {\n a = _a[0 .. n];\n bool neg = false;\n Array!int z;\n foreach (int i, ref e; a) {\n read(&e);\n if (!e)\n z.insertBack(i);\n else if (e < 0)\n neg = !neg;\n }\n if (!z.empty) {\n if (k < z.length) {\n foreach (x; a)\n write(x, ' ');\n writeln();\n continue;\n }\n k -= z.length;\n if ((z.length & 0x1) != neg)\n foreach (i; z)\n a[i] = -x;\n else {\n a[z[0]] = -x;\n foreach (i; z[1 .. $])\n a[i] = x;\n }\n } else if (!neg) {\n auto r = a.minPos!`abs(a) < abs(b)`;\n assert(r[0]);\n if (r[0] > 0)\n while (r[0] >= 0 && k) {\n r[0] -= x;\n k--;\n }\n else\n while (r[0] <= 0 && k) {\n r[0] += x;\n k--;\n }\n }\n if (k) {\n Array!(Tuple!(long, int)) store;\n store.length = n;\n foreach (int i, e; a)\n store[i] = tuple(e, i);\n auto h = heapify!`abs(a[0]) > abs(b[0])`(store);\n do {\n long e;\n int pos;\n AliasSeq!(e, pos) = h.front;\n h.removeFront();\n if (e > 0)\n e += x;\n else\n e -= x;\n a[pos] = e;\n h.insert(tuple(e, pos));\n } while (--k);\n }\n foreach (e; a)\n write(e, ' ');\n writeln();\n }\n}\n"}], "src_uid": "6db54c7de672a1fd0afd052894ce4ce8"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const H = readInt();\n auto A = new int[H + 1];\n foreach (d; 0 .. H + 1) {\n A[d] = readInt();\n }\n \n bool amb;\n foreach (d; 0 .. H) {\n amb = amb || (A[d] >= 2 && A[d + 1] >= 2);\n }\n if (!amb) {\n writeln(\"perfect\");\n } else {\n auto ASum = new int[H + 2];\n foreach (d; 0 .. H + 1) {\n ASum[d + 1] = ASum[d] + A[d];\n }\n auto ans = new int[][2];\n ans[0] ~= -1;\n ans[1] ~= -1;\n foreach (d; 1 .. H + 1) {\n foreach (j; 0 .. A[d]) {\n ans[0] ~= ASum[d - 1];\n ans[1] ~= ASum[d - 1] + j % A[d - 1];\n }\n }\n writeln(\"ambiguous\");\n foreach (s; 0 .. 2) {\n foreach (u; 0 .. ASum[H + 1]) {\n if (u > 0) write(\" \");\n write(ans[s][u] + 1);\n }\n writeln();\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"A\"\n dependency \"dcomp\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n\nimport std.typecons;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n\n int h; int[] a;\n sc.read(h, a); h++;\n int[] as = new int[h+1];\n foreach (i; 0..h) {\n as[i+1] = as[i] + a[i];\n }\n int n = as.back;\n int[] ap = new int[n], bp = new int[n];\n ap[0] = -1; bp[0] = -1;\n foreach (i; 1..h) {\n foreach (j; as[i]..as[i+1]) {\n ap[j] = bp[j] = as[i-1];\n }\n }\n foreach (i; 0..h-1) {\n if (a[i] > 1 && a[i+1] > 1) {\n bp[as[i+1]+1]++;\n\n writeln(\"ambiguous\");\n writeln(ap.map!\"a+1\".map!(to!string).join(\" \"));\n writeln(bp.map!\"a+1\".map!(to!string).join(\" \"));\n return 0;\n }\n }\n writeln(\"perfect\");\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */\n \n// module dcomp.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n// import dcomp.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/stackpayload.d */\n// module dcomp.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n\n/*\nThis source code generated by dcomp and include dcomp's source code.\ndcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)\ndcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)\n*/\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const H = readInt();\n auto A = new int[H + 1];\n foreach (d; 0 .. H + 1) {\n A[d] = readInt();\n }\n \n bool perfect = true;\n foreach (d; 0 .. H) {\n perfect = perfect && (A[d] == 1);\n }\n if (perfect) {\n writeln(\"perfect\");\n } else {\n auto ASum = new int[H + 2];\n foreach (d; 0 .. H + 1) {\n ASum[d + 1] = ASum[d] + A[d];\n }\n auto ans = new int[][2];\n ans[0] ~= -1;\n ans[1] ~= -1;\n foreach (d; 1 .. H + 1) {\n foreach (_; 0 .. A[d]) {\n ans[0] ~= ASum[d - 1];\n ans[1] ~= ASum[d - 1] + A[d - 1] - 1;\n }\n }\n writeln(\"ambiguous\");\n foreach (s; 0 .. 2) {\n foreach (u; 0 .. ASum[H + 1]) {\n if (u > 0) write(\" \");\n write(ans[s][u] + 1);\n }\n writeln();\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "a186acbdc88a7ed131a7e5f999877fd6"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct Point\n{\n\tint x;\n\tint y;\n\n\tPoint opBinary (string op) (const auto ref Point that)\n\t if (op == \"+\" || op == \"-\")\n\t{\n\t\tPoint res = void;\n\t\tres.x = mixin (q{this.x } ~ op ~ q{ that.x});\n\t\tres.y = mixin (q{this.y } ~ op ~ q{ that.y});\n\t\treturn res;\n\t}\n\n\tint opCmp () (const auto ref Point that)\n\t{\n\t\tauto thisUp = this.y > 0 || this.y == 0 && this.x > 0;\n\t\tauto thatUp = that.y > 0 || that.y == 0 && that.x > 0;\n\t\tif (thisUp != thatUp)\n\t\t{\n\t\t\treturn thisUp - thatUp;\n\t\t}\n\t\tauto cur = vp (this, that);\n\t\treturn (cur > 0) - (cur < 0);\n\t}\n}\n\nlong vp () (const auto ref Point a, const auto ref Point b)\n{\n\treturn a.x * 1L * b.y - a.y * 1L * b.x;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto p = new Point [n];\n\t\tforeach (ref c; p)\n\t\t{\n\t\t\treadf !(\" %s %s\") (c.x, c.y);\n\t\t}\n\n\t\tlong res = n * (n - 1L) * (n - 2L) * (n - 3L) * (n - 4L) / 24;\n\t\tdebug {writeln (res);}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tPoint [] q;\n\t\t\tq.reserve (n - 1);\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tif (j != i)\n\t\t\t\t{\n\t\t\t\t\tq ~= p[j] - p[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tsort (q);\n\t\t\tdebug {writeln (q);}\n\t\t\tq ~= q;\n\t\t\tint v = 0;\n\t\t\tforeach (u; 0..n - 1)\n\t\t\t{\n\t\t\t\tv = max (v, u + 1);\n\t\t\t\twhile (v - u < n - 1 && vp (q[v], q[u]) > 0)\n\t\t\t\t{\n\t\t\t\t\tv += 1;\n\t\t\t\t}\n\t\t\t\tdebug {writeln (u, \" \", v);}\n\t\t\t\tint w = v - u - 1;\n\t\t\t\tres -= w * (w - 1L) * (w - 2L) / 6;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nalias Pt = Tuple!(long, \"x\", long, \"y\");\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new Pt[N];\n foreach (i; 0 .. N) {\n P[i].x = readLong();\n P[i].y = readLong();\n }\n \n long ans;\n foreach (i; 0 .. N) {\n Pt[] ps;\n foreach (j; 0 .. N) {\n if (j != i) {\n ps ~= Pt(P[j].x - P[i].x, P[j].y - P[i].y);\n }\n }\n ps.sort!((ref Pt a, ref Pt b) {\n const sa = (a.y > 0) ? 1 : (a.y < 0) ? 3 : (a.x > 0) ? 0 : 2;\n const sb = (b.y > 0) ? 1 : (b.y < 0) ? 3 : (b.x > 0) ? 0 : 2;\n if (sa != sb) return (sa < sb);\n return (a.x * b.y > a.y * b.x);\n });\n int r;\n foreach (l; 0 .. N - 1) {\n for (chmax(r, l + 1); r < l + (N - 1) && ps[l].x * ps[r % (N - 1)].y > ps[l].y * ps[r % (N - 1)].x; ++r) {}\n const long m = r - l - 1;\n ans += m * (m - 1) * (m - 2) / 6;\n }\n }\n \n const long n = N;\n ans = n * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 120 * 5 - ans;\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "ef0d77b1b45af25be498c9abc4750722"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n int[] aa; get(aa);\r\n int min_a = int.max, c;\r\n foreach (a; aa) {\r\n if (min_a > a) {\r\n min_a = a;\r\n c = 1;\r\n } else if (a == min_a) {\r\n ++c;\r\n }\r\n }\r\n writeln(N - c); \r\n }\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (n - a.count (a.minElement));\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort;\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] != a[0])\r\n\t\t\t{\r\n\t\t\t\tans[ti] = n - i;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "99e5c907b623c310d6f1599f485ca21d"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n int ans = 0;\n\n foreach (i; 0..N) {\n foreach (j; i+1..N) {\n if (A[i] > A[j]) {\n ans ^= 1;\n }\n }\n }\n\n\n auto Q = readln.chomp.to!int;\n while (Q--) {\n auto lr = readln.split.map!(to!int);\n auto d = lr[1] - lr[0] + 1;\n ans ^= (d * (d - 1) / 2) % 2;\n writeln(ans%2 ? \"odd\" : \"even\");\n }\n\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nalias Pair = Tuple!(dchar, \"col\", int, \"len\");\n\nvoid main() {\n int n, m;\n scan(n);\n auto a = readln.split.to!(int[]);\n scan(m);\n\n int inv;\n foreach (i ; 0 .. n) {\n foreach (j ; i + 1 .. n) {\n if (a[i] > a[j]) inv++;\n }\n }\n\n inv &= 1;\n\n foreach (i ; 0 .. m) {\n int l, r;\n scan(l, r);\n inv ^= ((r - l + 1) * (r - l) / 2) & 1;\n writeln(inv ? \"odd\" : \"even\");\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "d20cc952cdf3a99e7d980a0270c49f78"} {"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\tint b=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\tint count=0;\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tint c=0;\n\t\treadf(\" %d\", &c);\n\t\tif (c>b)\n\t\t{\n\t\t\tcount=count+1;\n\t\t}\n\t}\n\twriteln(a+count);\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n\tint n, h, x;\n\tint result = 0;\n\t\n\tscanf(\"%d%d\", &n, &h);\n\tfor (int i = 0; i < n; i++) {\n\t\tscanf(\"%d\", &x);\n\t\tresult += (x > h) ? 2 : 1;\n\t}\n\tprintf(\"%d\\n\", result);\n}\n\n"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip,tr;\nimport std.algorithm.iteration: uniq, map, sum;\nimport std.algorithm.mutation: copy;\nimport std.algorithm.sorting: sort;\nimport std.regex;\nimport std.conv;\nimport std.array;\n\nvoid main()\n{\n auto nh = stdin.readln.strip.split(regex(` +`)).map!(to!int).array;\n auto as = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto h = nh[1];\n writeln (as.map!(a=>a<=h?1:2).sum);\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.array;\n\nint main(string[] argv)\n{\n\tint n, h;\n\tscanf(\"%d %d\", &n, &h);\n\tint width = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tint fh;\n\t\tscanf(\"%d\", &fh);\n\t\twidth += (fh > h ? 2 : 1);\n\t}\n\tprintf(\"%d\", width);\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\tint n, h, x;\n\tint result = 0;\n\t\n\tscanf(\"%d%d\", &n, &h);\n\tfor (int i = 0; i < n; i++){\n\t\tscanf(\"%d\", &x);\n\t\tresult += (x > h) ? 2 : 1;\n\t}\n\n\tprintf(\"%d\\n\", result);\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.stdio;\n\nvoid main() {\n int n, h;\n readf!\" %s %s \"(n, h);\n auto ans = readln.splitter\n .map!(to!int)\n .map!(x => x > h ? 2 : 1)\n .sum;\n writeln(ans);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.stdio;\n\nvoid main() {\n int n, h;\n readf!\" %s %s \"(n, h);\n // auto ans = readln.splitter\n // .map!(to!int)\n // .map!(x => x > h ? 2 : 1)\n // .sum;\n // writeln(ans);\n int ans = 0;\n foreach (i; 0 .. n) {\n int x;\n readf!\" %s\"(x);\n ans += 1;\n if (x > h) {\n ans += 1;\n }\n }\n writeln(ans);\n}\n"}], "negative_code": [], "src_uid": "e7ed5a733e51b6d5069769c3b1d8d22f"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nint solve(long[] a, long h, long[] mulorder)\n{\n int i = 0;\n while (i < a.length) {\n if (a[i] < h) {\n h += a[i] / 2;\n i++;\n continue;\n }\n if (mulorder.length > 0) {\n h *= mulorder.front;\n mulorder = mulorder[1 .. $];\n continue;\n }\n break;\n }\n return i;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n, h;\n readf!\" %d %d \"(n, h);\n auto a = readln.splitter.map!(to!long).array.sort.array;\n int best = -1;\n foreach (p ; [2L, 2L, 3L].permutations) {\n best = max(best, solve(a, h, p.array));\n }\n writeln(best);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nint solve (int n, long h, int [] a, int [] p)\r\n{\r\n\tforeach (int k, ref c; a)\r\n\t{\r\n\t\twhile (h <= c && !p.empty)\r\n\t\t{\r\n\t\t\th *= p.front;\r\n\t\t\tp.popFront ();\r\n\t\t}\r\n\t\tif (h <= c)\r\n\t\t{\r\n\t\t\treturn k;\r\n\t\t}\r\n\t\th += c / 2;\r\n\t}\r\n\treturn n;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, h;\r\n\t\treadf !(\" %s %s\") (n, h);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\r\n\t\tauto p = [2, 2, 3];\r\n\t\tint res = 0;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tres = max (res, solve (n, h, a, p));\r\n\t\t}\r\n\t\twhile (nextPermutation (p));\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nint solve1(long[] a, long h)\n{\n int mul2cnt = 2;\n int mul3cnt = 1;\n int i = 0;\n while (i < a.length) {\n if (a[i] < h) {\n h += a[i] / 2;\n } else if (a[i] < h * 2 && mul2cnt > 0) {\n h *= 2;\n h += a[i] / 2;\n mul2cnt--;\n } else if (a[i] < h * 3 && mul3cnt > 0) {\n h *= 3;\n h += a[i] / 2;\n mul3cnt--;\n } else {\n if (mul2cnt > 0) {\n h *= 2;\n mul2cnt--;\n continue;\n }\n if (mul3cnt > 0) {\n h *= 3;\n mul3cnt--;\n continue;\n }\n break;\n }\n i++;\n }\n return i;\n}\n\nint solve2(long[] a, long h)\n{\n int mul2cnt = 2;\n int mul3cnt = 1;\n int i = 0;\n while (i < a.length) {\n if (a[i] < h) {\n h += a[i] / 2;\n } else if (a[i] < h * 3 && mul3cnt > 0) {\n h *= 3;\n h += a[i] / 2;\n mul3cnt--;\n } else if (a[i] < h * 2 && mul2cnt > 0) {\n h *= 2;\n h += a[i] / 2;\n mul2cnt--;\n } else {\n if (mul3cnt > 0) {\n h *= 3;\n mul3cnt--;\n continue;\n }\n if (mul2cnt > 0) {\n h *= 2;\n mul2cnt--;\n continue;\n }\n break;\n }\n i++;\n }\n return i;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n, h;\n readf!\" %d %d \"(n, h);\n auto a = readln.splitter.map!(to!long).array.sort.array;\n writeln(max(solve1(a, h), solve2(a, h)));\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nint solve1(long[] a, long h)\n{\n int mul2cnt = 2;\n int mul3cnt = 1;\n int i = 0;\n while (i < a.length) {\n if (a[i] < h) {\n h += a[i] / 2;\n } else if (a[i] < h * 2 && mul2cnt > 0) {\n h *= 2;\n h += a[i] / 2;\n mul2cnt--;\n } else if (a[i] < h * 3 && mul3cnt > 0) {\n h *= 3;\n h += a[i] / 2;\n mul3cnt--;\n } else {\n break;\n }\n i++;\n }\n return i;\n}\n\nint solve2(long[] a, long h)\n{\n int mul2cnt = 2;\n int mul3cnt = 1;\n int i = 0;\n while (i < a.length) {\n if (a[i] < h) {\n h += a[i] / 2;\n } else if (a[i] < h * 3 && mul3cnt > 0) {\n h *= 3;\n h += a[i] / 2;\n mul3cnt--;\n } else if (a[i] < h * 2 && mul2cnt > 0) {\n h *= 2;\n h += a[i] / 2;\n mul2cnt--;\n } else {\n break;\n }\n i++;\n }\n return i;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n, h;\n readf!\" %d %d \"(n, h);\n auto a = readln.splitter.map!(to!long).array.sort.array;\n writeln(max(solve1(a, h), solve2(a, h)));\n }\n}\n"}], "src_uid": "1f46c4ba21e734a1c7de8b2434791f77"} {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.typecons;\nimport std.variant;\n\nvoid main() {\n\tint tt = readln().chomp.to!int;\n\tforeach (t; 0 .. tt) {\n\t\treadln();\n\t\tint[] a = readln().chomp.split(\" \").map!(to!int).array;\n\t\tint[] b = readln().chomp.split(\" \").map!(to!int).array;\n\t\tbool[int] aSet;\n\t\tforeach (i; a) {\n\t\t\taSet[i] = true;\n\t\t}\n\t\tNullable!int ans;\n\t\tforeach (i; b) {\n\t\t\tif (i in aSet) {\n\t\t\t\tans = Nullable!int(i);\n\t\t\t}\n\t\t}\n\t\tif (ans.isNull) {\n\t\t\twriteln(\"NO\");\n\t\t}\n\t\telse {\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(\"1 \", ans.get);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tforeach (x; a)\n\t\t{\n\t\t\tforeach (y; b)\n\t\t\t{\n\t\t\t\tif (x == y)\n\t\t\t\t{\n\t\t\t\t\twriteln (\"YES\");\n\t\t\t\t\twriteln (1, \" \", x);\n\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (\"NO\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "776a06c14c6fa3ef8664eec0b4d50824"} {"source_code": "import std.container;\r\nimport std.stdio;\r\nimport std.typecons;\r\n\r\nimmutable int infinity = int.max / 4;\r\n\r\nvoid main ()\r\n{\r\n\tint n, m;\r\n\twhile (readf !(\" %s %s\") (n, m) > 0)\r\n\t{\r\n\t\tauto adj = new int [] [n];\r\n\t\tauto adjR = new int [] [n];\r\n\t\tauto deg = new int [n];\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tint u, v;\r\n\t\t\treadf !(\" %s %s\") (u, v);\r\n\t\t\tu -= 1;\r\n\t\t\tv -= 1;\r\n\t\t\tadj[u] ~= v;\r\n\t\t\tadjR[v] ~= u;\r\n\t\t\tdeg[u] += 1;\r\n\t\t}\r\n\r\n\t\tauto d = new int [n];\r\n\t\td[] = infinity;\r\n\t\td[n - 1] = 0;\r\n\t\tauto used = new bool [n];\r\n\t\talias Record = Tuple !(int, q{dist}, int, q{v});\r\n\t\tauto t = redBlackTree !(Record) ();\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tt.insert (Record (d[i], i));\r\n\t\t}\r\n\t\twhile (!t.empty)\r\n\t\t{\r\n\t\t\tauto cur = t.front;\r\n\t\t\tt.removeFront ();\r\n\t\t\tused[cur.v] = true;\r\n\t\t\tforeach (u; adjR[cur.v])\r\n\t\t\t{\r\n\t\t\t\tdeg[u] -= 1;\r\n\t\t\t\tif (!used[u] && d[u] > deg[u] + d[cur.v] + 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tt.removeKey (Record (d[u], u));\r\n\t\t\t\t\td[u] = deg[u] + d[cur.v] + 1;\r\n\t\t\t\t\tt.insert (Record (d[u], u));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twriteln (d[0]);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10^^9;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt;\n const M = readInt;\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt - 1;\n B[i] = readInt - 1;\n }\n \n auto ds = new int[N];\n auto G = new int[][N];\n foreach (i; 0 .. M) {\n ++ds[A[i]];\n G[B[i]] ~= i;\n }\n \n alias Entry = Tuple!(int, \"c\", int, \"u\");\n BinaryHeap!(Array!Entry, \"a.c > b.c\") que;\n auto vis = new bool[N];\n auto dist = new int[N];\n dist[] = INF;\n dist[N - 1] = 0;\n que.insert(Entry(0, N - 1));\n for (; !que.empty; ) {\n const c = que.front.c;\n const u = que.front.u;\n que.removeFront;\n if (!vis[u]) {\n vis[u] = true;\n foreach (i; G[u]) {\n const v = A[i];\n const cc = c + 1 + (--ds[v]);\n debug {\n writefln(\"%s <- %s: %s\", u, v, cc);\n }\n if (chmin(dist[v], cc)) {\n que.insert(Entry(cc, v));\n }\n }\n }\n }\n debug {\n writeln(\"dist = \", dist);\n }\n writeln(dist[0]);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "1a83878ec600c87e74b48d6fdda89d4e"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto xyz1 = RDA;\n\t\tauto xyz2 = RDA;\n\t\t\n\t\tauto x = min(xyz1[2], xyz2[1]);\n\t\tans[ti] += x * 2;\n\t\txyz1[0] -= x;\n\t\txyz2[1] -= x;\n\t\tauto y = xyz2[2] - (xyz1[0]+xyz1[2]);\n\t\tif (y > 0)\n\t\t\tans[ti] -= y * 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "// Ported to D by unihernandez22\n// Solution by Vicfred\n// https://codeforces.com/contest/1401/problem/B\n\nimport std.stdio;\nimport std.string;\nimport std.conv;\nimport std.array;\nimport std.algorithm;\n\nvoid main() {\n int t = readln.chomp.to!int;\n foreach (_; 0 .. t) {\n int[] a = readln.split.map!(to!int).array,\n b = readln.split.map!(to!int).array;\n int ans = 0;\n \n if (a[2] > 0) {\n int taken = min(b[1], a[2]);\n a[2] -= taken;\n b[1] -= taken;\n\n ans += taken*2;\n }\n\n if (a[2] > 0) {\n int taken = min(b[2],a[2]);\n a[2] -= taken;\n b[2] -= taken;\n }\n\n if (a[2] > 0) {\n int taken = min(b[0],a[2]);\n a[2] -= taken;\n b[0] -= taken;\n }\n\n if (a[1] > 0) {\n int taken = min(b[1],a[1]);\n a[1] -= taken;\n b[1] -= taken;\n }\n\n if (a[1] > 0) {\n int taken = min(b[0],a[1]);\n a[1] -= taken;\n b[0] -= taken;\n }\n\n if (a[1] > 0) {\n int taken = min(b[2],a[1]);\n a[1] -= taken;\n b[2] -= taken;\n ans += taken*(-2);\n }\n\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\n\t\tauto num (int i, int j)\n\t\t{\n\t\t\tint res = min (a[i], b[j]);\n\t\t\ta[i] -= res;\n\t\t\tb[j] -= res;\n\t\t\treturn res;\n\t\t}\n\n\t\tint res = num (2, 1) * 2;\n\t\tnum (1, 1);\n\t\tnum (1, 0);\n\t\tres -= num (1, 2) * 2;\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "e1de1e92fac8a6db3222c0d3c26843d8"} {"source_code": "import std.stdio, std.string, std.typecons;\nimport std.algorithm;\n\nint saiki(int i, int j, int k, string a, string b, string v, int[][][] dp, Tuple!(int, int, int)[][][] result, int[][] jump)\n{\n auto la = cast(int)a.length;\n auto lb = cast(int)b.length;\n auto lv = cast(int)v.length;\n if (dp[i][j][k] != -1)\n {\n return dp[i][j][k];\n }\n if (k == lv)\n {\n dp[i][j][k] = int.max;\n return int.max;\n }\n if (i == la || j == lb)\n {\n dp[i][j][k] = 0;\n return 0;\n }\n auto res = 0;\n if (a[i] == b[j])\n {\n auto ret = saiki(i + 1, j + 1, jump[k][a[i] - 'A'], a, b, v, dp, result, jump);\n if (ret + 1 > res)\n {\n result[i][j][k] = Tuple!(int, int, int)(i + 1, j + 1, jump[k][a[i] - 'A']);\n res = ret + 1;\n }\n }\n auto ret = saiki(i + 1, j, k, a, b, v, dp, result, jump);\n if (ret > res)\n {\n res = ret;\n result[i][j][k] = Tuple!(int, int, int)(i + 1, j, k);\n }\n ret = saiki(i, j + 1, k, a, b, v, dp, result, jump);\n if (ret > res)\n {\n res = ret;\n result[i][j][k] = Tuple!(int, int, int)(i, j + 1, k);\n }\n dp[i][j][k] = res;\n return res;\n}\n\nint[][] getJump(string s)\n{\n auto n = cast(int)s.length;\n auto jump = new int[][](n + 1, 26);\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. 26)\n {\n if (s[i] == 'A' + j)\n {\n jump[i][j] = i + 1;\n }\n else\n {\n jump[i][j] = 0;\n for (int k = i - 1; k >= 0; -- k)\n {\n if (s[k] == 'A' + j)\n {\n auto x = k - 1, y = i - 1;\n while (x >= 0 && y >= 0)\n {\n if (s[x] != s[y])\n {\n break;\n }\n -- x;\n -- y;\n }\n if (x < 0)\n {\n jump[i][j] = k + 1;\n break;\n }\n }\n }\n }\n }\n }\n return jump;\n}\n\nstring construct(string a, string b, string v, Tuple!(int, int, int)[][][] result, int[][] jump)\n{\n auto la = cast(int)a.length;\n auto lb = cast(int)b.length;\n auto lv = cast(int)v.length;\n auto i = 0, j = 0, k = 0;\n string res;\n while (i < la && j < lb)\n {\n if (result[i][j][k] == tuple(-1, -1, -1))\n {\n break;\n }\n auto ni = result[i][j][k][0];\n auto nj = result[i][j][k][1];\n auto nk = result[i][j][k][2];\n if (ni == i + 1 && nj == j + 1)\n {\n auto c = a[i];\n res ~= c;\n }\n i = ni;\n j = nj;\n k = nk;\n }\n return res;\n}\n\nvoid solve(string a, string b, string v)\n{\n auto la = cast(int)a.length;\n auto lb = cast(int)b.length;\n auto lv = cast(int)v.length;\n auto jump = getJump(v);\n auto dp = new int[][][](la + 1, lb + 1, lv + 1);\n auto result = new Tuple!(int, int, int)[][][](la + 1, lb + 1, lv + 1);\n foreach (i; 0 .. la + 1)\n {\n foreach (j; 0 .. lb + 1)\n {\n fill(dp[i][j], -1);\n fill(result[i][j], tuple(-1, -1, -1));\n }\n }\n auto ans = saiki(0, 0, 0, a, b, v, dp, result, jump);\n if (ans == 0)\n {\n writeln(0);\n }\n else\n {\n auto res = construct(a, b, v, result, jump);\n writeln(res);\n }\n}\n\nint main(string[] args)\n{\n string s0, s1, virus;\n s0 = readln().strip();\n s1 = readln().strip();\n virus = readln().strip();\n solve(s0, s1, virus);\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.typecons;\nimport std.algorithm;\n\nint saiki(int i, int j, int k, int la, int lb, int lv, int[][][] dp, Tuple!(int, int, int)[][][] result, int[][] nexta, int[][] nextb, int[][] jump)\n{\n if (dp[i][j][k] != -1)\n {\n return dp[i][j][k];\n }\n if (k == lv)\n {\n dp[i][j][k] = int.max;\n return int.max;\n }\n if (i == la || j == lb)\n {\n dp[i][j][k] = 0;\n return 0;\n }\n auto res = 0;\n foreach (idx; 0 .. 26)\n {\n if (nexta[i][idx] != -1 && nextb[j][idx] != -1)\n {\n auto ret = saiki(nexta[i][idx] + 1, nextb[j][idx] + 1, jump[k][idx], la, lb, lv, dp, result, nexta, nextb, jump);\n if (ret != int.max)\n {\n if (ret + 1 > res)\n {\n result[i][j][k] = Tuple!(int, int, int)(nexta[i][idx], nextb[j][idx], jump[k][idx]);\n res = ret + 1;\n }\n }\n }\n }\n dp[i][j][k] = res;\n return res;\n}\n\nint[][] getNext(string s)\n{\n auto n = cast(int)s.length;\n auto next = new int[][](n + 1, 26);\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. 26)\n {\n next[i][j] = -1;\n foreach (k; i .. n)\n {\n if (s[k] == 'A' + j)\n {\n next[i][j] = k;\n break;\n }\n }\n }\n }\n return next;\n}\n\nint[][] getJump(string s)\n{\n auto n = cast(int)s.length;\n auto jump = new int[][](n + 1, 26);\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. 26)\n {\n if (s[i] == 'A' + j)\n {\n jump[i][j] = i + 1;\n }\n else\n {\n jump[i][j] = 0;\n for (int k = i - 1; k >= 0; -- k)\n {\n if (s[k] == 'A' + j)\n {\n auto x = k - 1, y = i - 1;\n while (x >= 0 && y >= 0)\n {\n if (s[x] != s[y])\n {\n break;\n }\n -- x;\n -- y;\n }\n if (x < 0)\n {\n jump[i][j] = k + 1;\n break;\n }\n }\n }\n }\n }\n }\n return jump;\n}\n\nstring configure(string a, string b, string v, Tuple!(int, int, int)[][][] result, int[][] jump)\n{\n auto la = cast(int)a.length;\n auto lb = cast(int)b.length;\n auto lv = cast(int)v.length;\n auto i = 0, j = 0, k = 0;\n string res;\n while (i < la && j < lb)\n {\n if (result[i][j][k] == tuple(-1, -1, -1))\n {\n break;\n }\n auto c = a[result[i][j][k][0]];\n res ~= c;\n auto ni = result[i][j][k][0] + 1;\n auto nj = result[i][j][k][1] + 1;\n auto nk = jump[k][c - 'A']; \n i = ni;\n j = nj;\n k = nk;\n }\n return res;\n}\n\nvoid solve(string a, string b, string v)\n{\n auto la = cast(int)a.length;\n auto lb = cast(int)b.length;\n auto lv = cast(int)v.length;\n auto nexta = getNext(a);\n auto nextb = getNext(b);\n auto jump = getJump(v);\n auto dp = new int[][][](la + 1, lb + 1, lv + 1);\n auto result = new Tuple!(int, int, int)[][][](la + 1, lb + 1, lv + 1);\n foreach (i; 0 .. la + 1)\n {\n foreach (j; 0 .. lb + 1)\n {\n fill(dp[i][j], -1);\n fill(result[i][j], tuple(-1, -1, -1));\n }\n }\n auto ans = saiki(0, 0, 0, la, lb, lv, dp, result, nexta, nextb, jump);\n if (ans == 0)\n {\n writeln(0);\n }\n else\n {\n auto res = configure(a, b, v, result, jump);\n writeln(res);\n }\n}\n\nint main(string[] args)\n{\n string s0, s1, virus;\n s0 = readln().strip();\n s1 = readln().strip();\n virus = readln().strip();\n solve(s0, s1, virus);\n return 0;\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tstring r;\n\twhile ((r = readln ().strip ()) != \"\")\n\t{\n\t\tstring s = readln ().strip ();\n\t\tstring t = readln ().strip ();\n\t\tint u = r.length;\n\t\tint v = s.length;\n\t\tint w = t.length;\n\t\tauto p = new int [w + 1];\n\t\tp[] = 0;\n\t\tforeach (i; 1..w + 1)\n\t\t{\n\t\t\tforeach (j; 1..i)\n\t\t\t{\n\t\t\t\tif (t[0..j] == t[i - j..i])\n\t\t\t\t{\n\t\t\t\t\tp[i] = max (p[i], j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tauto f = new int [] [] [] (u + 1, v + 1, w + 1);\n\t\talias Tuple !(int, int, int) prev;\n\t\tauto q = new prev [] [] [] (u + 1, v + 1, w + 1);\n\t\tforeach (i; 0..u + 1)\n\t\t{\n\t\t\tforeach (j; 0..v + 1)\n\t\t\t{\n\t\t\t\tforeach (k; 0..w + 1)\n\t\t\t\t{\n\t\t\t\t\tf[i][j][k] = -3;\n\t\t\t\t\tq[i][j][k] = prev (-3, -3, -3);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tf[0][0][0] = 0;\n\t\tforeach (int i; 0..u + 1)\n\t\t{\n\t\t\tforeach (int j; 0..v + 1)\n\t\t\t{\n\t\t\t\tforeach (int k; 0..w)\n\t\t\t\t{\n\t\t\t\t\tauto cur = f[i][j][k];\n\t\t\t\t\tif (cur == -3)\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\tvoid move (int x, int y, int z)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (f[x][y][z] < cur)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[x][y][z] = cur;\n\t\t\t\t\t\t\tq[x][y][z] =\n\t\t\t\t\t\t\t\tprev (i, j, k);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (i < u)\n\t\t\t\t\t{\n\t\t\t\t\t\tmove (i + 1, j, k);\n\t\t\t\t\t}\n\t\t\t\t\tif (j < v)\n\t\t\t\t\t{\n\t\t\t\t\t\tmove (i, j + 1, k);\n\t\t\t\t\t}\n\t\t\t\t\tif (i < u && j < v && r[i] == s[j])\n\t\t\t\t\t{\n\t\t\t\t\t\tauto z = k;\n\t\t\t\t\t\twhile (z > 0 && r[i] != t[z])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tz = p[z];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (r[i] == t[z])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tz++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcur++;\n\t\t\t\t\t\tmove (i + 1, j + 1, z);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint pi = u, pj = v, pk = -3;\n\t\tint res = -3;\n\t\tforeach (k; 0..w)\n\t\t{\n\t\t\tif (res < f[pi][pj][k])\n\t\t\t{\n\t\t\t\tres = f[pi][pj][k];\n\t\t\t\tpk = k;\n\t\t\t}\n\t\t}\n\t\tif (res <= 0)\n\t\t{\n\t\t\twriteln (0);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tchar [] ans;\n\t\t\twhile (pk != -3)\n\t\t\t{\n\t\t\t\tint qi, qj, qk;\n\t\t\t\tqi = q[pi][pj][pk][0];\n\t\t\t\tqj = q[pi][pj][pk][1];\n\t\t\t\tqk = q[pi][pj][pk][2];\n\t\t\t\tif (qi == pi - 1 && qj == pj - 1)\n\t\t\t\t{\n\t\t\t\t\tans ~= r[qi];\n\t\t\t\t}\n\t\t\t\tpi = qi;\n\t\t\t\tpj = qj;\n\t\t\t\tpk = qk;\n\t\t\t}\n\t\t\tans.reverse ();\n\t\t\twriteln (ans);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "391c2abbe862139733fcb997ba1629b8"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tiota (10 ^^ 9 - n, 10 ^^ 9).writefln !(\"%(%s %)\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n long n = scan;\n for(int i = 2; i < 2 + n; ++i){\n write(i, \" \");\n }\n writeln;\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n foreach(i; 2 .. 2 + n)\n write(i, \" \");\n writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "76bfced1345f871832957a65e2a660f8"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (int [] a, int n)\r\n{\r\n\tif (!a.canFind (1))\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n\tsort (a);\r\n\tforeach (i; 1..n)\r\n\t{\r\n\t\tif (a[i] - a[i - 1] == 1)\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\treturn true;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (a, n) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort;\r\n\r\n\t\tbool has1, hasD1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] == 1)\r\n\t\t\t\thas1 = true;\r\n\t\t\tif (i != n-1)\r\n\t\t\t{\r\n\t\t\t\tif (a[i+1] - a[i] == 1)\r\n\t\t\t\t\thasD1 = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (!(has1 && hasD1))\r\n\t\t\tans[ti] = true;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tbool has0, has1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] > 2) continue;\r\n\t\t\tif (a[i] % 2)\r\n\t\t\t\thas1 = true;\r\n\t\t\telse\r\n\t\t\t\thas0 = true;\r\n\t\t}\r\n\r\n\t\tif (!(has0 && has1))\r\n\t\t\tans[ti] = true;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "c7e4f544ec8b4972291542e66aff5df5"} {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n // BEGIN HERE\n\n int n;\n readf(\" %s\", n);\n \n auto a = new int[n];\n auto b = new int[n];\n iota(0,n).each!(i=> readf(\" %s\", a[i]));\n iota(0,n).each!(i=> readf(\" %s\", b[i]));\n\n auto step = new int[n+1];\n iota(0,n).each!(i=> step[ b[i] ] = i+1);\n iota(0,n).each!(i=> step[ a[i] ] = 0);\n\n // can I append to the tail?\n if (step[1] > 0) {\n auto delta = n - step[1]+ 1;\n if (step[1 .. delta+1] == iota(step[1],n+1).array) {\n if (step[delta+1 ..$].enumerate.all!\"a[1]<=a[0]\") {\n writeln(n-delta); return;}\n }\n }\n\n // I can't\n auto ii = iota(0, step.length).map!(x=>to!int(x)).array;\n step[] -= ii[];\n auto ans = (step[1..$].maxElement +1) + n;\n\n writeln(ans);\n\n // END HERE\n\n}\n", "positive_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n // BEGIN HERE\n\n int n;\n readf(\" %s\", n);\n \n auto a = new int[n];\n auto b = new int[n];\n iota(0,n).each!(i=> readf(\" %s\", a[i]));\n iota(0,n).each!(i=> readf(\" %s\", b[i]));\n\n auto step = new int[n+1];\n iota(0,n).each!(i=> step[ b[i] ] = i+1);\n iota(0,n).each!(i=> step[ a[i] ] = 0);\n\n // can I append to the tail?\n if (step[1] > 0) {\n auto delta = n - step[1]+ 1;\n if (step[1 .. delta+1] == iota(step[1],n+1).array) \n if (step[delta+1 ..$].enumerate.all!\"a.value<=a.index\") {\n writeln(n-delta); \n return;\n }\n }\n\n // I can't\n writeln(step[1 ..$].enumerate.map!\"a[1]-to!int(a[0])\".maxElement + n);\n\n // END HERE\n\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] > 0)\n\t\t\t{\n\t\t\t\tres = max (res, n - a[i] + 1);\n\t\t\t}\n\t\t}\n\n\t\tint limit = n;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] == 1)\n\t\t\t{\n\t\t\t\tif (b[i..$].equal (iota (1, n + 1 - i)))\n\t\t\t\t{\n\t\t\t\t\tlimit = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..limit)\n\t\t{\n\t\t\tif (b[i] > 0)\n\t\t\t{\n\t\t\t\tres = max (res, i + 1 + n - b[i] + 1);\n\t\t\t}\n\t\t}\n\n\t\tif (res > limit)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (b[i] > 0)\n\t\t\t\t{\n\t\t\t\t\tres = max (res, i + 1 + n - b[i] + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nint solve(int[] step, int ts) {\n // return -1 -> cannot\n int s= 1;\n foreach(i;1..step.length) {\n if (step[i] == -1) continue;\n if (step[i] <= ts) {\n ts++;\n } else return -1;\n }\n\n return ts;\n}\n\nvoid main() {\n GC.disable();\n\n // BEGIN HERE\n\n int n;\n readf(\" %s\", n);\n \n auto a = new int[n];\n auto b = new int[n];\n iota(0,n).each!(i=> readf(\" %s\", a[i]));\n iota(0,n).each!(i=> readf(\" %s\", b[i]));\n\n // writeln(a); writeln(b);\n\n auto step = new int[n+1];\n step[] = n;\n iota(0,n).each!(i=> step[ b[i] ] = i+1);\n iota(0,n).each!(i=> step[ a[i] ] = 0);\n\n\n // can I append to the tail?\n auto ss = step.dup;\n auto del = n - ss[1];\n bool flag = false;\n int bb = ss[1];\n foreach(i; 0..del+1) {\n if (ss[1+i] ==0) {flag=true; break;}\n if (ss[1 + i] != bb + i) { flag = true; break;}\n ss[1+i] = -1;\n }\n\n // writeln(iota(0,ss.length));\n // writeln(step); writeln(ss);\n if (!flag) { // try to append\n auto ans = solve(ss, 0);\n if (ans != -1) { writeln(ans); return; }\n }\n\n // I can't\n auto sss = step.dup;\n sss[0] = 0;\n auto ii = iota(0, step.length).map!(x=>to!int(x)).array;\n sss[] -= ii[];\n auto ans = (sss[1..$].maxElement +1) + n;\n\n writeln(ans);\n\n // END HERE\n\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] A, B;\n\nint[] pos;\n\nint solveDirect() {\n // B[N - 1] at 2 N - 1\n const d = (2 * N - 1) - B[N - 1];\n bool ok = true;\n foreach (x; 1 .. B[N - 1] + 1) {\n ok = ok && (pos[x] == d + x);\n }\n foreach (x; B[N - 1] + 1 .. N + 1) {\n ok = ok && (pos[x] <= d + x - N - 1);\n }\n return ok ? (N - B[N - 1]) : -1;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n B = new int[N];\n foreach (i; 0 .. N) {\n B[i] = readInt();\n }\n \n pos = new int[N + 1];\n foreach (i; 0 .. N) {\n pos[A[i]] = i;\n }\n foreach (i; 0 .. N) {\n pos[B[i]] = N + i;\n }\n \n int ans = solveDirect();\n if (ans == -1) {\n int lo = -1, hi = 2 * N;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n // 1 at 2 N + mid\n const d = (2 * N + mid) - 1;\n bool ok = true;\n foreach (x; 1 .. N + 1) {\n ok = ok && (pos[x] <= d + x - N - 1);\n }\n debug {\n writeln(mid, \" \", d, \" \", ok);\n }\n ok ? (hi = mid) : (lo = mid);\n }\n ans = hi + N;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] > 0)\n\t\t\t{\n\t\t\t\tres = max (res, n - a[i] + 1);\n\t\t\t}\n\t\t}\n\n\t\tint limit = n;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] == 1)\n\t\t\t{\n\t\t\t\tif (b[i..$].equal (iota (1, n + 1 - i)))\n\t\t\t\t{\n\t\t\t\t\tlimit = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..limit)\n\t\t{\n\t\t\tif (b[i] > 0)\n\t\t\t{\n\t\t\t\tres = max (res, i + 1 + n - b[i] + 1);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] > 0)\n\t\t\t{\n\t\t\t\tres = max (res, n - a[i] + 1);\n\t\t\t}\n\t\t}\n\n\t\tint limit = n;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] == 1)\n\t\t\t{\n\t\t\t\tif (b[i..$].equal (iota (1, n + 1 - i)))\n\t\t\t\t{\n\t\t\t\t\tlimit = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..limit)\n\t\t{\n\t\t\tif (b[i] > 0)\n\t\t\t{\n\t\t\t\tres = max (res, i + 1 + n - b[i] + 1);\n\t\t\t}\n\t\t}\n\n\t\tif (res > n - limit)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (b[i] > 0)\n\t\t\t\t{\n\t\t\t\t\tres = max (res, i + 1 + n - b[i] + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nint solve(int[] step, int ts) {\n // return -1 -> cannot\n int s= 1;\n foreach(i;1..step.length) {\n if (step[i] == -1) continue;\n if (step[i] <= ts) {\n ts++;\n } else return -1;\n }\n\n return ts;\n}\n\nvoid main() {\n GC.disable();\n\n // BEGIN HERE\n\n int n;\n readf(\" %s\", n);\n \n auto a = new int[n];\n auto b = new int[n];\n iota(0,n).each!(i=> readf(\" %s\", a[i]));\n iota(0,n).each!(i=> readf(\" %s\", b[i]));\n\n // writeln(a); writeln(b);\n\n auto step = new int[n+1];\n step[] = n;\n iota(0,n).each!(i=> step[ b[i] ] = i+1);\n iota(0,n).each!(i=> step[ a[i] ] = 0);\n\n\n // can I append to the tail?\n auto ss = step.dup;\n auto del = n - ss[1];\n bool flag = false;\n int bb = ss[1];\n foreach(i; 0..del+1) {\n if (ss[1 + i] != bb + i) { flag = true; break;}\n ss[1+i] = -1;\n }\n\n // writeln(iota(0,ss.length));\n // writeln(step); writeln(ss);\n if (!flag) { // try to append\n auto ans = solve(ss, 0);\n if (ans != -1) { writeln(ans); return; }\n }\n\n // I can't\n auto sss = step.dup;\n sss[0] = 0;\n auto ii = iota(0, step.length).map!(x=>to!int(x)).array;\n sss[] -= ii[];\n auto ans = (sss.maxElement +1) + n;\n\n writeln(ans);\n\n // END HERE\n\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nint solve(int[] step, int ts) {\n // return -1 -> cannot\n int s= 1;\n foreach(i;1..step.length) {\n if (step[i] == -1) continue;\n if (step[i] <= ts) {\n ts++;\n } else return -1;\n }\n\n return ts;\n}\n\nvoid main() {\n GC.disable();\n\n // BEGIN HERE\n\n int n;\n readf(\" %s\", n);\n \n auto a = new int[n];\n auto b = new int[n];\n iota(0,n).each!(i=> readf(\" %s\", a[i]));\n iota(0,n).each!(i=> readf(\" %s\", b[i]));\n\n // writeln(a);\n // writeln(b);\n\n auto step = new int[n+1];\n step[] = n;\n iota(0,n).each!(i=> step[ b[i] ] = i+1);\n iota(0,n).each!(i=> step[ a[i] ] = 0);\n\n\n // can I append to the tail?\n auto ss = step.dup;\n auto del = n - ss[1];\n bool flag = false;\n foreach(i; 0..del+1) {\n if (ss[1 + i] != ss[1] + i) { flag = true; break;}\n ss[1+i] = -1;\n }\n\n // writeln(iota(0,ss.length));\n // writeln(step);\n // writeln(ss);\n if (!flag) { // try to append\n auto ans = solve(ss, 0);\n if (ans != -1) { writeln(ans); return; }\n }\n\n // I can't\n auto sss = step.dup;\n sss[0] = 0;\n auto ii = iota(0, step.length).map!(x=>to!int(x)).array;\n sss[] -= ii[];\n auto ans = (sss.maxElement +1) + n;\n\n writeln(ans);\n\n // END HERE\n\n}\n"}], "src_uid": "ec092209aa9f45409e5aa01d7fc784e1"} {"source_code": "import std.stdio;\nimport std.math;\n\nstatic immutable N = 100000;\n\nint n, q, ans;\nint[N + 1] a, top, f;\nint[20][N + 1] prime;\n\nint main() {\n readf(\" %d\", &n);\n for (int i = 1; i <= n; ++ i) {\n readf(\" %d\", &a[i]);\n q = cast(int) sqrt(real(a[i]));\n for (int j = 2; j <= q; ++ j) {\n if (! (a[i] % j)) {\n prime[i][top[i] ++] = j;\n while (! (a[i] % j)) a[i] /= j;\n }\n }\n if (a[i] > 1) prime[i][top[i] ++] = a[i];\n }\n f[1] = 1;\n for (int i = 1; i <= n; ++ i) {\n int rec = 0;\n for (int j = 0; j < top[i]; ++ j)\n if (rec < f[prime[i][j]]) rec = f[prime[i][j]];\n ++ rec;\n for (int j = 0; j < top[i]; ++ j) f[prime[i][j]] = rec;\n }\n for (int i = 1; i <= N; ++ i)\n if (f[i] > ans) ans = f[i];\n writeln(ans);\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n immutable int MAX = 10^^5 + 1;\n bool[] table = new bool[](MAX);\n fill(table, true);\n table[0] = table[1] = false;\n \n int[][] P = new int[][](MAX);\n \n foreach (i; 2..MAX) {\n if (!table[i]) continue;\n P[i] ~= i;\n for (int j = i + i; j < MAX; j += i) {\n table[j] = false;\n P[j] ~= i;\n }\n }\n\n \n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto dp = new int[](MAX);\n\n foreach (i; 0..N) {\n int tmp = 0;\n foreach (j; P[A[i]]) tmp = max(tmp, dp[j] + 1);\n foreach (j; P[A[i]]) dp[j] = tmp;\n }\n\n int ans = dp.reduce!max;\n max(ans, 1).writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.math;\n\nstatic immutable N = 100000;\n\nint n, q, ans;\nint[N + 1] a, top, f;\nint[N + 1][20] prime;\n\nint main() {\n readf(\" %d\", &n);\n for (int i = 1; i <= n; ++ i) {\n readf(\" %d\", &a[i]);\n q = cast(int) sqrt(real(a[i]));\n for (int j = 2; j <= q; ++ j) {\n if (! (a[i] % j)) {\n prime[i][++ top[i]] = j;\n while (! (a[i] % j)) a[i] /= j;\n }\n }\n if (a[i] > 1) prime[i][++ top[i]] = a[i];\n }\n for (int i = 1; i <= n; ++ i) {\n int rec = 0;\n for (int j = 1; j <= top[i]; ++ j)\n if (rec < f[prime[i][j]]) rec = f[prime[i][j]];\n ++ rec;\n for (int j = 1; j <= top[i]; ++ j) f[prime[i][j]] = rec;\n }\n for (int i = 1; i <= N; ++ i)\n if (f[i] > ans) ans = f[i];\n writeln(ans);\n return 0;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n immutable int MAX = 10^^5 + 1;\n bool[] table = new bool[](MAX);\n fill(table, true);\n table[0] = table[1] = false;\n \n int[][] P = new int[][](MAX);\n \n foreach (i; 2..MAX) {\n if (!table[i]) continue;\n P[i] ~= i;\n for (int j = i + i; j < MAX; j += i) {\n table[j] = false;\n P[j] ~= i;\n }\n }\n\n \n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto dp = new int[](MAX);\n\n foreach (i; 0..N) {\n int tmp = 0;\n foreach (j; P[A[i]]) tmp = max(tmp, dp[j] + 1);\n foreach (j; P[A[i]]) dp[j] = tmp;\n }\n\n dp.reduce!max.writeln;\n}\n"}], "src_uid": "0f8ad0ea2befbbe036fbd5e5f6680c21"} {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nint n, a, b;\nint[] x, y;\n\nvoid main() {\n scan(n, a, b);\n\n x = new int[](n);\n y = new int[](n);\n\n foreach (i ; 0 .. n) {\n scan(x[i], y[i]);\n }\n\n bool check(int U, int V, int u, int v) {\n return (u <= U && v <= V) || (u <= V && v <= U);\n }\n\n int ans;\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. n) {\n if (i == j) continue;\n \n if (x[i] <= a && y[i] <= b) {\n if (check(a - x[i], b, x[j], y[j]) || check(a, b - y[i], x[j], y[j])) {\n ans = max(ans, x[i]*y[i] + x[j]*y[j]);\n }\n }\n\n if (x[i] <= b && y[i] <= a) {\n if (check(a - y[i], b, x[j], y[j]) || check(a, b - x[i], x[j], y[j])) {\n ans = max(ans, x[i]*y[i] + x[j]*y[j]);\n }\n }\n }\n }\n\n writeln(ans);\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto H = s[1];\n auto W = s[2];\n auto X = new int[](N);\n auto Y = new int[](N);\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n X[i] = s[0];\n Y[i] = s[1];\n }\n\n int x1, y1, x2, y2;\n int ans = 0;\n \n foreach (i; 0..N) {\n foreach (j; i+1..N) {\n foreach (rot; 0..4) {\n if (rot == 0) x1 = X[i], y1 = Y[i], x2 = X[j], y2 = Y[j];\n if (rot == 1) x1 = X[i], y1 = Y[i], x2 = Y[j], y2 = X[j];\n if (rot == 2) x1 = Y[i], y1 = X[i], x2 = X[j], y2 = Y[j];\n if (rot == 3) x1 = Y[i], y1 = X[i], x2 = Y[j], y2 = X[j];\n if (x1 + x2 <= H && max(y1, y2) <= W) ans = max(ans, X[i] * Y[i] + X[j] * Y[j]);\n if (max(x1, x2) <= H && y1 + y2 <= W) ans = max(ans, X[i] * Y[i] + X[j] * Y[j]);\n }\n }\n }\n\n ans.writeln;\n}\n"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio, std.string, std.array, std.algorithm, std.conv;\n\nvoid main() {\n auto nab = to!(int[])(split(chomp(readln())));\n int n = nab[0], a = nab[1], b = nab[2];\n int ans = 0;\n int[101] u, w;\n for (int i = 0; i < n; i++) {\n auto xy = to!(int[])(split(chomp(readln())));\n int x = xy[0], y = xy[1];\n int s = x * y;\n if (x <= a && y <= b) {\n for (int j = 1; j < 101; j++) {\n if (u[j] > 0 && j + x <= a) {\n ans = max(ans, u[j] + s);\n }\n if (w[j] > 0 && j + y <= b) {\n ans = max(ans, w[j] + s);\n }\n }\n }\n if (y <= a && x <= b) {\n for (int j = 1; j < 101; j++) {\n if (u[j] > 0 && j + y <= a) {\n ans = max(ans, u[j] + s);\n }\n if (w[j] > 0 && j + x <= b) {\n ans = max(ans, w[j] + s);\n }\n }\n }\n if (x <= a && y <= b) { u[x] = max(u[x], s); w[y] = max(w[y], s); }\n if (y <= a && x <= b) { u[y] = max(u[y], s); w[x] = max(w[x], s); }\n }\n writeln(ans);\n}"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nint n, a, b;\nint[] x, y;\n\nvoid main() {\n scan(n, a, b);\n\n x = new int[](n);\n y = new int[](n);\n\n foreach (i ; 0 .. n) {\n scan(x[i], y[i]);\n }\n\n bool check(int U, int V, int u, int v) {\n return (u <= U && v <= V) || (u <= V && v <= U);\n }\n\n int ans;\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. n) {\n if (i == j) continue;\n \n if (x[i] <= a && y[i] <= b) {\n if (check(a - x[i], b, x[j], y[j]) || check(a, b - y[i], x[j], y[j])) {\n ans = max(ans, x[i]*y[i] + x[j]*y[j]);\n }\n }\n\n if (x[i] <= b && y[i] <= a) {\n if (check(a - y[i], b, x[j], y[j]) || check(a, b - x[i], x[j], y[j])) {\n ans = max(ans, x[i]*y[i] + x[j]*y[j]);\n }\n }\n }\n }\n\n writeln(ans);\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n"}], "negative_code": [], "src_uid": "1ad63f41943e40aa8c8d5c88c29c283c"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nint root(int[] uf, int u) {\r\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\r\n}\r\nbool connect(int[] uf, int u, int v) {\r\n u = uf.root(u);\r\n v = uf.root(v);\r\n if (u == v) return false;\r\n if (uf[u] > uf[v]) swap(u, v);\r\n uf[u] += uf[v];\r\n uf[v] = u;\r\n return true;\r\n}\r\n\r\n\r\nint Ask(int u) {\r\n writeln(\"? \", u + 1);\r\n stdout.flush;\r\n const v = readInt - 1;\r\n return v;\r\n}\r\n\r\nvoid main() {\r\n const numCases = readInt;\r\n foreach (caseId; 0 .. numCases) {\r\n const N = readInt;\r\n auto D = new int[N];\r\n foreach (i; 0 .. N) {\r\n D[i] = readInt;\r\n }\r\n \r\n int[] us = iota(N).array;\r\n us.sort!((u, v) => (D[u] < D[v]));\r\n \r\n auto uf = new int[N];\r\n uf[] = -1;\r\n auto vis = new bool[N];\r\n foreach_reverse (u; us) if (!vis[u]) {\r\n vis[u] = true;\r\n foreach (j; 0 .. D[u]) {\r\n const v = Ask(u);\r\n uf.connect(u, v);\r\n if (vis[v]) {\r\n break;\r\n }\r\n vis[v] = true;\r\n }\r\n }\r\n \r\n write(\"!\");\r\n foreach (u; 0 .. N) {\r\n write(\" \", uf.root(u) + 1);\r\n }\r\n writeln;\r\n stdout.flush;\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto d = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tauto order = n.iota.array;\r\n\t\torder.sort !((i, j) => d[i] > d[j]);\r\n\t\tauto color = new int [n];\r\n\r\n\t\tvoid recolorAs (int v, int u)\r\n\t\t{\r\n\t\t\tauto oldColor = color[v];\r\n\t\t\tauto newColor = color[u];\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (color[i] == oldColor)\r\n\t\t\t\t{\r\n\t\t\t\t\tcolor[i] = newColor;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (v; order)\r\n\t\t{\r\n\t\t\tif (color[v] != 0)\r\n\t\t\t{\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tauto cur = d[v];\r\n\t\t\tcolor[v] = v + 1;\r\n\t\t\tforeach (step; 0..cur)\r\n\t\t\t{\r\n\t\t\t\twritefln !(\"? %s\") (v + 1);\r\n\t\t\t\tstdout.flush ();\r\n\t\t\t\tauto u = readln.strip.to !(int);\r\n\t\t\t\tu -= 1;\r\n\t\t\t\tif (color[u] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tcolor[u] = color[v];\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trecolorAs (u, v);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twritefln !(\"! %(%s %)\") (color);\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "cb05d81d82d16ac3fdf8ec33e69d5ae8"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\t\n\t\tans[ti] = 1;\n\t\ta.sort();\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] <= i+1)\n\t\t\t\tans[ti] = i+2;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tint res = 1;\n\t\tforeach (i, c; a)\n\t\t{\n\t\t\tif (c <= i + 1)\n\t\t\t{\n\t\t\t\tres = i + 2;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "718cea81f609055cece58cae5310f703"} {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %d\", &a[i]);\n\t\t}\n\t\tint m;\n\t\treadf (\" %d\", &m);\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint x, y;\n\t\t\treadf (\" %d %d\", &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tif (x - 1 >= 0)\n\t\t\t{\n\t\t\t\ta[x - 1] += y;\n\t\t\t}\n\t\t\tif (x + 1 < n)\n\t\t\t{\n\t\t\t\ta[x + 1] += a[x] - y - 1;\n\t\t\t}\n\t\t\ta[x] = 0;\n\t\t}\n\t\twritefln (\"%(%d\\n%)\", a);\n\t}\n}\n", "positive_code": [{"source_code": "module sigod.codeforces.p294A;\n\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n\tint N;\n\tstdin.readf(\"%s\", &N);\n\tstdin.readln();\n\n\tint[] counts = read_array!int();\n\n\tint M;\n\tstdin.readf(\"%s\", &M);\n\tstdin.readln();\n\n\tforeach (i; 0 .. M) {\n\t\tint x, y;\n\n\t\tstdin.readf(\"%s %s\", &x, &y);\n\t\tstdin.readln();\n\n\t\t--x;\n\n\t\tif (x > 0) {\n\t\t\tcounts[x - 1] += y - 1;\n\t\t}\n\t\tif (x < N - 1) {\n\t\t\tcounts[x + 1] += counts[x] - y;\n\t\t}\n\n\t\tcounts[x] = 0;\n\t}\n\n\tforeach (count; counts) {\n\t\tstdout.writeln(count);\n\t}\n}\n\nprivate\nT[] read_array(T)()\n{\n\tauto input = stdin.readln().strip().split();\n\n\tT[] result = new T[input.length];\n\n\tforeach (index, ref element; input) {\n\t\tresult[index] = element.to!T();\n\t}\n\n\treturn result;\n}"}], "negative_code": [], "src_uid": "859d66fc2c204a8c002012b1fb206645"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n int n = scan!int;\n long[] as = scan!long(n);\n\n long[] xs = new long[](600_999);\n foreach(i, a; as){\n int d = n + a.to!int - (i + 1).to!int;\n xs[d] += a;\n }\n\n long ans = 0;\n foreach(x; xs) ans.raiseTo(x);\n\n ans.writeln;\n}\n\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto B = new int[N];\n foreach (i; 0 .. N) {\n B[i] = readInt();\n }\n \n long[long] sums;\n foreach (i; 0 .. N) {\n sums[B[i] - i] += B[i];\n }\n const ans = sums.values.maxElement;\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nvoid main()\n{\n long n; get(n);\n auto b = new long[cast(size_t)n]; get(b);\n long[long] mb;\n long m = long.min;\n zip(iota(0, n), b).each!((p) {mb[p[1] - p[0]] += b[cast(size_t)p[0]]; m = max(m, mb[p[1] - p[0]]);});\n ans(m);\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\n\nvoid main()\n{\n int n; get(n);\n auto b = new int[n]; get(b);\n int[int] mb;\n int m = int.min;\n zip(iota(0, n), b).each!((p) {mb[p[1] - p[0]] += b[p[0]]; m = max(m, mb[p[1] - p[0]]);});\n ans(m);\n}\n"}], "src_uid": "aab8d5a2d42b4199310f3f535a6b3bd7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = new long[](n);\r\n\t\tauto b = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\ta[i] = RD;\r\n\t\t\tb[i] = RD;\r\n\t\t}\r\n\t\tauto tm = RDA;\r\n\r\n\t\tlong time;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tlong d;\r\n\t\t\tif (i == 0)\r\n\t\t\t\td = a[i] + tm[i];\r\n\t\t\telse\r\n\t\t\t\td = a[i] - b[i-1] + tm[i];\r\n\t\t\ttime += d;\r\n\t\t\tdebug writeln(\"time:\", time);\r\n\t\t\tif (i == n-1) break;\r\n\t\t\tauto w = (b[i]-a[i]+1) / 2;\r\n\t\t\ttime = max(time+w, b[i]);\r\n\t\t}\r\n\t\tans[ti] = time;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm, std.range, std.conv;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n;\r\n readf!\"%d\\n\"(n);\r\n int[] a = new int[n], b = new int[n];\r\n foreach (i; 0 .. n)\r\n readf!\"%d %d\\n\"(a[i], b[i]);\r\n int[] tm = readln.split.map!(to!int).array;\r\n int res = 0;\r\n foreach (i; 0 .. n)\r\n {\r\n res += a[i] - (i > 0 ? b[i - 1] : 0) + tm[i];\r\n if (i < n - 1)\r\n res = max(res + (b[i] - a[i] + 1) / 2, b[i]);\r\n }\r\n writeln(res);\r\n }\r\n}"}], "negative_code": [], "src_uid": "42840fc873369e0d0d6a4ad24a43f5a6"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint x, y;\r\n\t\treadf !(\" %s %s\") (x, y);\r\n\t\tlong res = 0;\r\n\t\tfor (int r = 1; ; r++)\r\n\t\t{\r\n\t\t\tint lo = r + 2;\r\n\t\t\tint hi = min (y + 1, x / r);\r\n\t\t\tif (hi < lo)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tres += hi - lo + 1;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std;\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n long X, Y; readf(\"%d %d\\n\", &X, &Y);\r\n long bs; {\r\n long lb = 0, ub = 1L<<30;\r\n while (lb + 1 < ub) {\r\n long mid = (lb + ub) / 2;\r\n (mid - 1 <= X / (mid + 1L) ? lb : ub) = mid;\r\n }\r\n bs = min(lb, Y);\r\n }\r\n long A = (1L + bs) * bs / 2L - bs;\r\n long B = 0;\r\n if (bs == Y) {\r\n } else {\r\n for (long k = 1; k <= X / (bs + 1L); k++) {\r\n long U = min(Y, X / k - 1L);\r\n long L = max(bs, X / (k + 1L) - 1L);\r\n B += k * max(0L, U - L);\r\n }\r\n }\r\n writeln(A + B);\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n long x, y; get(x, y);\r\n long res;\r\n for (long i = 1; i^^2 <= x; ++i) {\r\n res += max(0, min((x - i) / i, y) - i);\r\n }\r\n writeln(res);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto x = RD;\r\n\t\tauto y = RD;\r\n\r\n\t\tfor (long i = 1; i*i < x; ++i)\r\n\t\t{\r\n\t\t\tauto xx = x - i;\r\n\t\t\tauto r = min(xx / i, y) - i;\r\n\t\t\tif (r > 0)\r\n\t\t\t\tans[ti] += r;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{ \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto v = readln.splitter.map!(to!int).array;\r\n auto x = v[0], y = v[1];\r\n \r\n long ans = 0;\r\n foreach (r; 1 .. y) {\r\n int left = x - r;\r\n if (left <= 1) { break; }\r\n \r\n int mxk = min(left / r, y);\r\n if (mxk <= r) { break; }\r\n \r\n int cur = mxk - r;\r\n \r\n ans += cur;\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{ \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto v = readln.splitter.map!(to!int).array;\r\n auto x = v[0], y = v[1];\r\n \r\n int ans = 0;\r\n foreach (r; 1 .. y) {\r\n int left = x - r;\r\n if (left <= 1) { break; }\r\n \r\n int mxk = min(left / r, y);\r\n if (mxk <= r) { break; }\r\n \r\n int cur = mxk - r;\r\n \r\n ans += cur;\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{ \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto v = readln.splitter.map!(to!int).array;\r\n auto x = v[0], y = v[1];\r\n \r\n int ans = 0;\r\n foreach (b; 1 .. y + 1) {\r\n int left = x - b;\r\n if (left <= 1) { break; }\r\n \r\n int mxk = min(left / b, y);\r\n if (mxk - b <= 0) { break; }\r\n \r\n int cur = mxk - b;\r\n \r\n debug { writeln(b, ' ', cur); }\r\n \r\n ans += cur;\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{ \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto v = readln.splitter.map!(to!int).array;\r\n auto x = v[0], y = v[1];\r\n \r\n int sq = sqrt(x.to!real).to!int;\r\n \r\n int ans = 0;\r\n foreach (b; 1 .. min(y, sq) + 1) {\r\n int left = x - b;\r\n if (left <= 1) { break; }\r\n \r\n int mxk = min(left / b, y);\r\n if (mxk - b <= 0) { break; }\r\n \r\n int cur = mxk - b;\r\n \r\n debug { writeln(b, ' ', cur); }\r\n \r\n ans += cur;\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}"}], "src_uid": "efdb966e414050c5e51e8beb7bb06b20"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nint[] A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new int[N];\n\t\tB = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t\tB[i] = readInt;\n\t\t}\n\t\t\n\t\tauto ps = new Pair!(int, int)[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tps[i] = pair(A[i], B[i]);\n\t\t}\n\t\tps.sort();\ndebug{\nwriteln(\"ps = \",ps);\n}\n\t\t\n\t\tbool ans;\n\t\tint max;\n\t\tforeach (i; 0 .. N) {\n\t\t\tif (max > ps[i].y) {\n\t\t\t\tans = true;\n\t\t\t}\n\t\t\tchmax(max, ps[i].y);\n\t\t}\n\t\twriteln(ans ? \"Happy Alex\" : \"Poor Alex\");\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n\tint n;\n\treadf(\"%s\", &n);\n\tforeach(_; 0..n) {\n\t\tint ai, bi;\n\t\treadf(\" %s %s \", &ai, &bi);\n\t\tif (ai != bi) {\n\t\t\twriteln(\"Happy Alex\");\n\t\t\treturn;\n\t\t}\n\t}\n\twriteln(\"Poor Alex\");\n}"}, {"source_code": "import std.typecons;\nimport std.algorithm;\n\nalias Note = Tuple!(uint, \"a\", uint, \"b\");\n\nbool noteLess(const Note a, const Note b) {\n\tif (a.a == b.a) {\n\t\treturn a.b > b.b;\n\t}\n\n\treturn a.a < b.a;\n}\n\nbool solve(Note[] ns) {\n\tsort!(noteLess)(ns);\n\tforeach (i; 1..ns.length) {\n\t\tNote prev = ns[i - 1];\n\t\tNote cur = ns[i];\n\t\tif (prev.a < cur.a && prev.b > cur.b) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nunittest {\n\t{\n\t\tNote[] ns = [Note(1, 2), Note(2, 1)];\n\t\tassert(solve(ns));\n\t}\n\n\t{\n\t\tNote[] ns = [Note(2, 1), Note(1, 2)];\n\t\tassert(solve(ns));\n\t}\n\n\t{\n\t\tNote[] ns = [Note(1, 1)];\n\t\tassert(false == solve(ns));\n\t}\n\n\t{\n\t\tNote[] ns = [Note(1, 1), Note(2, 2), Note(3, 3), Note(4, 4), Note(5, 5)];\n\t\tassert(false == solve(ns));\n\t}\n\n\t{\n\t\tNote[] ns = [Note(4, 5), Note(2, 2), Note(3, 3), Note(1, 1), Note(5, 4)];\n\t\tassert(solve(ns));\n\t}\n}\n\nint main(string[] argv) {\n\timport std.stdio;\n\tuint n = 0;\n\treadf(\" %s\", &n);\n\tauto ns = new Note[](n);\n\tforeach (i; 0..n) {\n\t\treadf(\" %s %s\", &(ns[i].a), &(ns[i].b));\n\t}\n\twriteln(solve(ns) ? \"Happy Alex\" : \"Poor Alex\");\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n bool poor = true;\n for (int i = 0; i < n; ++i) {\n int a, b;\n readf(\"%d %d\\n\", &a, &b);\n if (poor && a != b) {\n poor = false;\n }\n }\n if (poor)\n writeln(\"Poor Alex\");\n else\n writeln(\"Happy Alex\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.regex;\nimport std.algorithm.iteration;\nimport std.algorithm.sorting;\nimport std.typecons;\n\nvoid main()\n{\n auto n = stdin.readln.strip.to!int;\n alias DicEntry = Tuple!(int, \"price\", int, \"quality\");\n DicEntry[] prices;\n prices.length = n;\n \n for(int i=0; i<n; i++) {\n auto s = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n prices[i].price = s[0];\n prices[i].quality = s[1];\n }\n auto s = \"Poor Alex\";\n prices.sort!((a,b)=>a.price < b.price);\n for(int i=0; i<n-1; i++) {\n if (prices[i].price < prices[i+1].price && prices[i].quality > prices[i+1].quality) {\n s = \"Happy Alex\";\n break;\n }\n }\n writeln(s);\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/456/A\n\nimport std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[][] laptops;\n\n int a, b;\n foreach(idx; 0..n) {\n int[] laptop;\n readf(\"%d %d\\n\", &a, &b);\n laptop ~= [a,b];\n laptops ~= laptop;\n }\n\n bool happy = false;\n //laptops.sort();\n\n for(int i = 0; i < n; i++)\n if(laptops[i][0] != laptops[i][1])\n happy = true;\n\n /* brute force\n for(int i = 0; i < n; i++) {\n for(int j = 0; j < n; j++) {\n if(laptops[i][0] < laptops[j][0] &&\n laptops[i][1] > laptops[j][1])\n happy = true;\n }\n }\n */\n \n if(happy)\n writeln(\"Happy Alex\");\n else\n writeln(\"Poor Alex\");\n}\n\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.range, std.conv;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[][] info;\n\n foreach (i; 0..n) {\n info ~= readln.chomp.split.map!(to!int).array;\n }\n\n string ans = \"Poor Alex\";\n info.sort;\n foreach (i; 1..n) {\n if (info[i][1] < info[i - 1][1]) {\n ans = \"Happy Alex\";\n break;\n }\n }\n\n ans.writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([[1,2],[2,1]]) == true, \"Test 1\");\n assert(solve([[1,1],[2,2]]) == false, \"Test 2\");\n assert(solve([[2,2],[3,3],[1,1]]) == false, \"Test 3\");\n\n}\n\nbool solve(int[2][] lap){\n for(int i =1; i < lap.length; i++){\n if(!(lap[i][0] == lap[i][1])){\n return true;\n }\n }\n return false;\n}\n\nvoid main(){\n int n;\n readf(\"%s\\n\",&n);\n\n int[2][] lap = new int[2][n];\n for(int i = 0; i < n; i++){\n int p,q;\n readf(\"%s %s\\n\",&p,&q);\n lap[i][0] = p;\n lap[i][1] = q;\n }\n\n if (solve(lap)) {\n writeln(\"Happy Alex\");\n } else {\n writeln(\"Poor Alex\");\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n\tint n;\n\treadf(\"%s\", &n);\n\tforeach(_; 0..n) {\n\t\tint ai, bi;\n\t\treadf(\" %s %s \", &ai, &bi);\n\t\tif (ai != bi) {\n\t\t\twriteln(\"Poor Alex\");\n\t\t\treturn;\n\t\t}\n\t}\n\twriteln(\"Happy Alex\");\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([[1,2,0],[2,1,1]]) == true, \"Test 1\");\n}\n\nbool solve(int[3][] lap){\n for(int i =1; i < lap.length; i++){\n if(!(lap[i][0] == lap[i][i])){\n return true;\n }\n }\n return false;\n}\n\nvoid main(){\n int n;\n readf(\"%s\\n\",&n);\n\n int[3][] lap = new int[3][n];\n for(int i = 0; i < n; i++){\n int p,q;\n readf(\"%s %s\\n\",&p,&q);\n lap[i][0] = p;\n lap[i][1] = q;\n lap[i][2] = i;\n }\n\n if (solve(lap)) {\n writeln(\"Happy Alex\");\n } else {\n writeln(\"Poor Alex\");\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n // assert(solve([[1,2,0],[2,1,1]]) == true, \"Test 1\");\n}\n\nbool solve(int[3][] lap){\n sort!((int[3] a,int[3] b){ return a[0] < b[0];})(lap);\n //writeln(lap);\n\n for(int i =1; i < lap.length; i++){\n for(int j = 0; j < i; j++){\n if(lap[j][1] > lap[i][1]){\n return true;\n }\n }\n }\n return false;\n}\n\nvoid main(){\n int n;\n readf(\"%s\\n\",&n);\n\n int[3][] lap = new int[3][n];\n for(int i = 0; i < n; i++){\n int p,q;\n readf(\"%s %s\\n\",&p,&q);\n lap[i][0] = p;\n lap[i][1] = q;\n lap[i][2] = i;\n }\n\n if (solve(lap)) {\n writeln(\"Happy Allex\");\n } else {\n writeln(\"Poor Allex\");\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([[1,2],[2,1]]) == true, \"Test 1\");\n}\n\nbool solve(int[2][] lap){\n for(int i =1; i < lap.length; i++){\n for(int j = 0; j < i; j++){\n if(!(lap[i] == lap[j])){\n return true;\n }\n }\n }\n return false;\n}\n\nvoid main(){\n int n;\n readf(\"%s\\n\",&n);\n\n int[2][] lap = new int[2][n];\n for(int i = 0; i < n; i++){\n int p,q;\n readf(\"%s %s\\n\",&p,&q);\n lap[i][0] = p;\n lap[i][1] = q;\n }\n\n if (solve(lap)) {\n writeln(\"Happy Allex\");\n } else {\n writeln(\"Poor Allex\");\n }\n}\n"}], "src_uid": "c21a84c4523f7ef6cfa232cba8b6ee2e"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto K = readln.chomp.to!int;\n writeln(\"3 3\");\n auto IK = 0b100000000000000000 + K;\n auto IO = 0b100000000000000000;\n auto OK = K;\n auto ans =\n [[IK, IO, 0],\n [OK, IK, OK],\n [0, 0, OK]];\n foreach (a; ans) {\n foreach (b; a) write(b, \" \");\n writeln;\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int k;\n readf(\"%s\", &k);\n readln;\n \n auto ans = new int[][] (3, 2);\n \n immutable int bigBit = 2 ^^ 17;\n \n ans[0][0] = bigBit + k;\n ans[1][0] = bigBit;\n ans[0][1] = k;\n \n ans[1][1] = bigBit + k;\n \n ans[2][0] = 0;\n ans[2][1] = k;\n \n writeln(3, ' ', 2);\n foreach (i; 0 .. 3) {\n ans[i].map!(to!string).join(\" \").writeln;\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto k = RD!int;\n\tint digit;\n\tauto x = k;\n\twhile (x != 0)\n\t{\n\t\tx >>= 1;\n\t\t++digit;\n\t}\n\n\tint y = 1 << digit;\n\tint z = k | y;\n\n\tauto ans = new int[][](2, 3);\n\tans[0][0] = z;\n\tans[1][0] = y;\n\tans[0][1] = k;\n\tans[1][1] = z;\n\tans[0][2] = 0;\n\tans[1][2] = k;\n\t\n\twriteln(\"2 3\");\n\tforeach (i; 0..2)\n\t{\n\t\tans[i].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto K = readln.chomp.to!int;\n auto ans =\n [[0b1000000000000000000, 0b0111111111111111111, 0b0111111111111111111],\n [0b1000000000000000000, 0, K],\n [0b1000000000000000000, 0, K]];\n foreach (a; ans) {\n foreach (b; a) write(b, \" \");\n writeln;\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto K = readln.chomp.to!int;\n writeln(\"3 3\");\n auto ans =\n [[0b1000000000000000000, 0b0111111111111111111, 0b0111111111111111111],\n [0b1000000000000000000, 0, K],\n [0b1000000000000000000, 0b1000000000000000000, 0b1000000000000000000+K]];\n foreach (a; ans) {\n foreach (b; a) write(b, \" \");\n writeln;\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto K = readln.chomp.to!int;\n writeln(\"3 3\");\n auto ans =\n [[0b1000000000000000000, 0b0111111111111111111, 0b0111111111111111111],\n [0b1000000000000000000, 0, K],\n [0b1000000000000000000, 0, K]];\n foreach (a; ans) {\n foreach (b; a) write(b, \" \");\n writeln;\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto K = readln.chomp.to!int;\n writeln(\"3 3\");\n auto IK = 0b1000000000000000000 + K;\n auto IO = 0b1000000000000000000;\n auto OK = K;\n auto ans =\n [[IK, IO, IO],\n [OK, IO, IO],\n [OK, OK, IK]];\n foreach (a; ans) {\n foreach (b; a) write(b, \" \");\n writeln;\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto K = readln.chomp.to!int;\n writeln(\"3 3\");\n auto IK = 0b1000000000000000000 + K;\n auto IO = 0b1000000000000000000;\n auto OK = K;\n auto ans =\n [[IK, IO, 0],\n [OK, IO, OK],\n [0, 0, OK]];\n foreach (a; ans) {\n foreach (b; a) write(b, \" \");\n writeln;\n }\n}\n"}], "src_uid": "fc0442e5cda2498a1818702e5e3eeec4"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto place = new int[] (n+1);\n foreach (i, e; arr) { place[e] = i.to!int; }\n \n auto adjr = n.iota.map!(x => x+1).array;\n auto adjle = n.iota.map!(x => x-1).array;\n \n auto ans = new int[] (n);\n \n int now = 1;\n foreach_reverse (e; (n+1).iota.dropOne) {\n int idx = place[e];\n \n if (ans[idx] != 0) { continue; }\n \n debug { e.writeln; }\n \n ans[idx] = now;\n int idxr = adjr[idx], step = 1;\n while (step <= k && idxr < n) {\n ans[idxr] = now;\n idxr = adjr[idxr];\n ++step;\n }\n int idxle = adjle[idx];\n step = 1;\n while (step <= k && idxle >= 0) {\n ans[idxle] = now;\n idxle = adjle[idxle];\n ++step;\n }\n \n if (idxle >= 0) { adjr[idxle] = idxr; }\n if (idxr < n) { adjle[idxr] = idxle; }\n \n now = 3 - now;\n }\n \n ans.writefln!\"%(%s%)\";\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!int).array;\n\n auto B = N.iota.map!(i => tuple(i, A[i])).array;\n B.sort!\"a[1] > b[1]\";\n\n auto L = N.iota.map!(i => i.to!int - 1).array;\n auto R = N.iota.map!(i => i.to!int + 1).array;\n\n auto ans = new int[](N);\n auto used = new bool[](N);\n\n for (int p = 0, t = 0; p < N; t ^= 1) {\n auto start = B[p][0];\n ans[start] = t + 1;\n used[start] = true;\n\n int new_l = -1, new_r = N;\n\n for (int j = 0, i = L[start]; j < K && i != -1; ++j, i = L[i], new_l = i) {\n ans[i] = t + 1;\n used[i] = true;\n } \n for (int j = 0, i = R[start]; j < K && i != N; ++j, i = R[i], new_r = i) {\n ans[i] = t + 1;\n used[i] = true;\n }\n\n if (new_l != -1) {\n R[new_l] = new_r;\n }\n if (new_r != N) {\n L[new_r] = new_l;\n }\n\n while (p < N && used[B[p][0]]) ++p;\n }\n\n ans.map!(a => a.to!string).join(\"\").writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint k = read.to!int;\n\t\n\tNode[] nodes;\n\tforeach(i; 0 .. n){\n\t\tint a = read.to!int;\n\t\tnodes ~= new Node(i, a);\n\t}\n\t\n\tforeach(i; 0 .. n - 1){\n\t\tnodes[i].next = nodes[i + 1];\n\t\tnodes[i + 1].prev = nodes[i];\n\t}\n\t\n\tnodes.sort!\"a.value>b.value\"();\n\t\n\tint t = 1;\n\tforeach(nd; nodes){\n\t\tif(nd.isDone) continue;\n\t\telse{\n\t\t\tnd.setTeam(t);\n\t\t\tNode prev = nd.takePrev(t, k);\n\t\t\tNode next = nd.takeNext(t, k);\n\t\t\tif(prev) prev.next = next;\n\t\t\tif(next) next.prev = prev;\n\t\t}\n\t\tt = 3 - t;\n\t}\n\t\n\tnodes.sort!\"a.id<b.id\"();\n\t\n\tnodes.map!(nd => nd.team.to!string).array.join(\"\").writeln;\n}\n\nclass Node{\n\tint id;\n\tint value;\n\tint team;\n\tbool isDone = 0;\n\tNode prev, next;\n\tthis(int id, int value){\n\t\tthis.id = id;\n\t\tthis.value = value;\n\t}\n\tvoid setTeam(int t){\n\t\tthis.isDone = 1;\n\t\tthis.team = t;\n\t}\n\tNode takePrev(int t, int k){\n\t\tthis.setTeam(t);\n\t\tif(k == 0) return this.prev;\n\t\telse if(this.prev) return this.prev.takePrev(t, k - 1);\n\t\telse return null;\n\t}\n\tNode takeNext(int t, int k){\n\t\tthis.setTeam(t);\n\t\tif(k == 0) return this.next;\n\t\telse if(this.next) return this.next.takeNext(t, k - 1);\n\t\telse return null;\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!int).array;\n\n auto B = N.iota.map!(i => tuple(i, A[i])).array;\n B.sort!\"a[1] > b[1]\";\n\n auto L = N.iota.map!(i => i.to!int - 1).array;\n auto R = N.iota.map!(i => i.to!int + 1).array;\n\n auto ans = new int[](N);\n auto used = new bool[](N);\n\n for (int p = 0, t = 0; p < N; t ^= 1) {\n auto start = B[p][0];\n ans[start] = t + 1;\n used[start] = true;\n\n int new_l, new_r;\n\n for (int j = 0, i = L[start]; j < K && i != -1; ++j, i = L[i], new_l = i) {\n ans[i] = t + 1;\n used[i] = true;\n } \n for (int j = 0, i = R[start]; j < K && i != N; ++j, i = R[i], new_r = i) {\n ans[i] = t + 1;\n used[i] = true;\n }\n\n if (new_l != -1) {\n R[new_l] = new_r;\n }\n if (new_r != N) {\n L[new_r] = new_l;\n }\n\n while (p < N && used[B[p][0]]) ++p;\n }\n\n ans.map!(a => a.to!string).join(\"\").writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint k = read.to!int;\n\t\n\tNode[] nodes;\n\tforeach(i; 0 .. n){\n\t\tint a = read.to!int;\n\t\tnodes ~= new Node(i, a);\n\t}\n\t\n\tforeach(i; 0 .. n - 1){\n\t\tnodes[i].next = nodes[i + 1];\n\t\tnodes[i + 1].prev = nodes[i];\n\t}\n\t\n\tnodes.sort!\"a.value>b.value\"();\n\t\n\tint t = 1;\n\tforeach(nd; nodes){\n\t\tif(nd.isDone) continue;\n\t\telse{\n\t\t\tnd.setTeam(t);\n\t\t\tNode prev = nd.takePrev(t, k);\n\t\t\tNode next = nd.takeNext(t, k);\n\t\t\tif(prev) prev.next = next;\n\t\t\tif(next) next.prev = prev;\n\t\t}\n\t\tt = 3 - t;\n\t}\n\t\n\tnodes.sort!\"a.id<b.id\"();\n\t\n\tnodes.map!(nd => nd.team.to!string).array.join(\" \").writeln;\n}\n\nclass Node{\n\tint id;\n\tint value;\n\tint team;\n\tbool isDone = 0;\n\tNode prev, next;\n\tthis(int id, int value){\n\t\tthis.id = id;\n\t\tthis.value = value;\n\t}\n\tvoid setTeam(int t){\n\t\tthis.isDone = 1;\n\t\tthis.team = t;\n\t}\n\tNode takePrev(int t, int k){\n\t\tthis.setTeam(t);\n\t\tif(k == 0) return this.prev;\n\t\telse if(this.prev) return this.prev.takePrev(t, k - 1);\n\t\telse return null;\n\t}\n\tNode takeNext(int t, int k){\n\t\tthis.setTeam(t);\n\t\tif(k == 0) return this.next;\n\t\telse if(this.next) return this.next.takeNext(t, k - 1);\n\t\telse return null;\n\t}\n}\n"}], "src_uid": "235131226fee9d04efef4673185c1c9b"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n, k;\n n = rd!int, k = rd!int;\n dchar[] arr = rd!(dchar[]);\n auto g1 = redBlackTree!(true, int);\n auto g2 = redBlackTree!(true, int);\n int streak = 0, take = 0, w = 0;\n if(arr[0] == 'L') --streak;\n foreach(i; 0..n){\n if(arr[i] == 'W'){\n if(streak > 0){\n ++streak;\n if(streak % 2){\n g1.insert(streak);\n }else{\n g2.insert(streak);\n }\n }\n streak = 0;\n ++w;\n if(i > 0 && arr[i-1] == 'W') ++w;\n }else{\n streak += 2;\n ++take;\n }\n }\n if(!w && streak > 0 && k > 0){\n streak -= 1;\n w = 1;\n k -= 1;\n }\n if(streak > 0){\n if(streak % 2){\n g1.insert(streak);\n }else{\n g2.insert(streak);\n }\n }\n /* writeln(g1, g2); */\n\n ll pt = w;\n take = min(take, k);\n while(g1.length && take > 0){\n ll top = g1.front;\n if(top/2 <= take){\n pt += top;\n take -= top/2;\n }else{\n pt += take*2;\n take = 0;\n }\n g1.removeFront;\n }\n while(g2.length && take > 0){\n ll top = g2.front;\n if(top/2 <= take){\n pt += top;\n take -= top/2;\n }else{\n pt += take*2;\n take = 0;\n }\n g2.removeFront;\n }\n writeln(pt);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const K = readInt();\n const S = readToken();\n \n int ans;\n int k = K;\n chmin(k, cast(int)(S.count('L')));\n if (S.count('W') == 0) {\n ans = max(2 * k - 1, 0);\n } else {\n foreach (i; 0 .. N) {\n if (S[i] == 'W') {\n ans += (i - 1 >= 0 && S[i - 1] == 'W') ? 2 : 1;\n }\n }\n int[] ds;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && S[i] == S[j]; ++j) {}\n if (S[i] == 'L' && !(i == 0 || j == N)) {\n ds ~= j - i;\n }\n }\n ds.sort;\n foreach (d; ds) {\n if (k >= d) {\n k -= d;\n ans += 2 * d + 1;\n }\n }\n ans += 2 * k;\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = RD!string;\n\n\t\tauto cnt = new int[](n+1);\n\t\tint streak, lc;\n\t\tbool start;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == 'W')\n\t\t\t{\n\t\t\t\tstart = true;\n\t\t\t\t++cnt[streak];\n\t\t\t\tstreak = 0;\n\t\t\t\tif (i == 0)\n\t\t\t\t\t++ans[ti];\n\t\t\t\telse if (s[i-1] == 'W')\n\t\t\t\t\tans[ti] += 2;\n\t\t\t\telse\n\t\t\t\t\t++ans[ti];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (start)\n\t\t\t\t\t++streak;\n\t\t\t\t++lc;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"ans:\", ans[ti]);\n\t\tdebug writeln(cnt);\n\t\tk = min(k, lc);\n\n\t\tforeach (i; 1..n+1)\n\t\t{\n\t\t\tauto c = min(k / i, cnt[i]);\n\t\t\tk -= i * c;\n\t\t\tif (c != 0)\n\t\t\t\tans[ti] += c * (i * 2 + 1);\n\t\t\tdebug writeln(\"k:\", k, \" ans:\", ans[ti]);\n\t\t}\n\t\tif (start)\n\t\t\tans[ti] += k * 2;\n\t\telse if (k >= 1)\n\t\t\tans[ti] += (k-1) * 2 + 1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\treadln;\n\t\tauto s = readln.strip.map !(q{a == 'W'}).array;\n\t\tauto zeroes = s.count (0);\n\t\tauto ones = s.count (1);\n\t\tif (ones == 0)\n\t\t{\n\t\t\twriteln (max (0, k * 2 - 1));\n\t\t\tcontinue;\n\t\t}\n\t\tint start0 = 0;\n\t\twhile (s.front == 0)\n\t\t{\n\t\t\tstart0 += 1;\n\t\t\ts.popFront ();\n\t\t}\n\t\tint finish0 = 0;\n\t\twhile (s.back == 0)\n\t\t{\n\t\t\tfinish0 += 1;\n\t\t\ts.popBack ();\n\t\t}\n\n\t\tauto h = s.group.filter !(q{a[0] == 1}).count.to !(int);\n\t\tauto res = sum (s) * 2 - h;\n\t\tauto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;\n\t\tg.sort;\n\t\twhile (k > 0 && !g.empty)\n\t\t{\n\t\t\tauto d = min (k, g.front);\n\t\t\tk -= d;\n\t\t\tres += 2 * d + (d == g.front);\n\t\t\tg.popFront ();\n\t\t}\n\t\tif (k > 0 && finish0 > 0)\n\t\t{\n\t\t\tauto d = min (k, finish0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d;\n\t\t}\n\t\tif (k > 0 && start0 > 0)\n\t\t{\n\t\t\tauto d = min (k, start0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n, k;\n n = rd!int, k = rd!int;\n dchar[] arr = rd!(dchar[]);\n auto gaps = redBlackTree!(true, tup);\n int streak = 0, take = 0, w = 0;\n if(arr[0] == 'L') --streak;\n foreach(i; 0..n){\n if(arr[i] == 'W'){\n ll val = streak + 1;\n if(streak > 0){ gaps.insert(tup(val/2, -val)); }\n streak = 0;\n ++w;\n if(i > 0 && arr[i-1] == 'W') ++w;\n }else{\n streak += 2;\n ++take;\n }\n }\n if(streak) gaps.insert(tup(streak/2, -streak));\n /* writeln(gaps); */\n\n ll pt = w;\n take = min(take, k);\n while(gaps.length && take > 0){\n ll top = - gaps.front[1];\n if(top/2 <= take){\n pt += top;\n take -= top/2;\n }else{\n pt += take*2;\n take = 0;\n }\n gaps.removeFront;\n }\n writeln(pt);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n, k;\n n = rd!int, k = rd!int;\n dchar[] arr = rd!(dchar[]);\n auto g1 = redBlackTree!(true, int);\n auto g2 = redBlackTree!(true, int);\n int streak = 0, take = 0, w = 0;\n if(arr[0] == 'L') --streak;\n foreach(i; 0..n){\n if(arr[i] == 'W'){\n if(streak > 0){\n ++streak;\n if(streak % 2){\n g1.insert(streak);\n }else{\n g2.insert(streak);\n }\n }\n streak = 0;\n ++w;\n if(i > 0 && arr[i-1] == 'W') ++w;\n }else{\n streak += 2;\n ++take;\n }\n }\n if(!w && streak > 0 && k > 0){\n streak -= 1;\n w = 1;\n k -= 1;\n }\n if(streak > 0){\n if(streak % 2){\n g1.insert(streak);\n }else{\n g2.insert(streak);\n }\n }\n writeln(g1, g2);\n\n ll pt = w;\n take = min(take, k);\n while(g1.length && take > 0){\n ll top = g1.front;\n if(top/2 <= take){\n pt += top;\n take -= top/2;\n }else{\n pt += take*2;\n take = 0;\n }\n g1.removeFront;\n }\n while(g2.length && take > 0){\n ll top = g2.front;\n if(top/2 <= take){\n pt += top;\n take -= top/2;\n }else{\n pt += take*2;\n take = 0;\n }\n g2.removeFront;\n }\n writeln(pt);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n, k;\n n = rd!int, k = rd!int;\n dchar[] arr = rd!(dchar[]);\n auto g1 = redBlackTree!(true, int);\n auto g2 = redBlackTree!(true, int);\n int streak = 0, take = 0, w = 0;\n if(arr[0] == 'L') --streak;\n foreach(i; 0..n){\n if(arr[i] == 'W'){\n if(streak > 0){\n ++streak;\n if(streak % 2){\n g1.insert(streak);\n }else{\n g2.insert(streak);\n }\n }\n streak = 0;\n ++w;\n if(i > 0 && arr[i-1] == 'W') ++w;\n }else{\n streak += 2;\n ++take;\n }\n }\n if(streak > 0){\n if(streak % 2){\n g1.insert(streak);\n }else{\n g2.insert(streak);\n }\n }\n /* writeln(g1, g2); */\n\n ll pt = w;\n take = min(take, k);\n while(g1.length && take > 0){\n ll top = g1.front;\n if(top/2 <= take){\n pt += top;\n take -= top/2;\n }else{\n pt += take*2;\n take = 0;\n }\n g1.removeFront;\n }\n while(g2.length && take > 0){\n ll top = g2.front;\n if(top/2 <= take){\n pt += top;\n take -= top/2;\n }else{\n pt += take*2;\n take = 0;\n }\n g2.removeFront;\n }\n writeln(pt);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\treadln;\n\t\tauto s = readln.strip.map !(q{a == 'W'}).array;\n\t\tauto zeroes = s.count (0);\n\t\tauto ones = s.count (1);\n\t\tif (ones == 0)\n\t\t{\n\t\t\twriteln (max (0, k * 2 - 1));\n\t\t\tcontinue;\n\t\t}\n\t\tint start0 = 0;\n\t\twhile (s.front == 0)\n\t\t{\n\t\t\tstart0 += 1;\n\t\t\ts.popFront ();\n\t\t}\n\t\tint finish0 = 0;\n\t\twhile (s.back == 0)\n\t\t{\n\t\t\tfinish0 += 1;\n\t\t\ts.popBack ();\n\t\t}\n\n\t\tauto h = s.group.filter !(q{a[0] == 1}).count.to !(int);\n\t\tauto res = sum (s) * 2 - h;\n\t\tauto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;\n\t\tg.sort;\n\t\twhile (k > 0 && !g.empty)\n\t\t{\n\t\t\tauto d = min (k, g.front);\n\t\t\tk -= d;\n\t\t\tres += 2 * d + (d == g.front);\n\t\t\tg.popFront ();\n\t\t}\n\t\tif (k > 0 && finish0 > 0)\n\t\t{\n\t\t\tauto d = min (k, finish0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d;\n\t\t}\n\t\tif (k > 0 && start0 > 0)\n\t\t{\n\t\t\tauto d = min (k, start0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d - 1 + (d == start0);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\treadln;\n\t\tauto s = readln.strip.map !(q{a == 'W'}).array;\n\t\tauto zeroes = s.count (0);\n\t\tauto ones = s.count (1);\n\t\tif (ones == 0)\n\t\t{\n\t\t\twriteln (max (0, k * 2 - 1));\n\t\t\tcontinue;\n\t\t}\n\t\tint start0 = 0;\n\t\twhile (s.front == 0)\n\t\t{\n\t\t\tstart0 += 1;\n\t\t\ts.popFront ();\n\t\t}\n\t\tint finish0 = 0;\n\t\twhile (s.back == 0)\n\t\t{\n\t\t\tfinish0 += 1;\n\t\t\ts.popBack ();\n\t\t}\n\n\t\tauto h = s.group.filter !(q{a[0] == 1}).count.to !(int);\n\t\tauto res = sum (s) * 2 - h;\n\t\tauto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;\n\t\tg.sort;\n\t\twhile (k > 0 && !g.empty)\n\t\t{\n\t\t\tauto d = min (k, g.front);\n\t\t\tk -= d;\n\t\t\tres += 2 * d + (d == g.front);\n\t\t\tg.popFront ();\n\t\t}\n\t\tif (k > 0 && finish0 > 0)\n\t\t{\n\t\t\tauto d = min (k, finish0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d;\n\t\t}\n\t\tif (k > 0 && start0 > 0)\n\t\t{\n\t\t\tauto d = min (k, start0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d - (d != start0);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\treadln;\n\t\tauto s = readln.strip.map !(q{a == 'W'}).array;\n\t\tauto zeroes = s.count (0);\n\t\tauto ones = s.count (1);\n\t\tif (ones == 0)\n\t\t{\n\t\t\twriteln (max (0, k * 2 - 1));\n\t\t\tcontinue;\n\t\t}\n\t\tint start0 = 0;\n\t\twhile (s.front == 0)\n\t\t{\n\t\t\tstart0 += 1;\n\t\t\ts.popFront ();\n\t\t}\n\t\tint finish0 = 0;\n\t\twhile (s.back == 0)\n\t\t{\n\t\t\tfinish0 += 1;\n\t\t\ts.popBack ();\n\t\t}\n\n\t\tauto h = s.group.filter !(q{a[0] == 1}).count.to !(int);\n\t\tauto res = sum (s) * 2 - h;\n\t\tauto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;\n\t\tg.sort;\n\t\twhile (k > 0 && !g.empty)\n\t\t{\n\t\t\tauto d = min (k, g.front);\n\t\t\tk -= d;\n\t\t\tres += 2 * d + (d == g.front);\n\t\t\tg.popFront ();\n\t\t}\n\t\tif (k > 0 && finish0 > 0)\n\t\t{\n\t\t\tauto d = min (k, finish0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d;\n\t\t}\n\t\tif (k > 0 && start0 > 0)\n\t\t{\n\t\t\tauto d = min (k, start0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d - (d == start0);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\treadln;\n\t\tauto s = readln.strip.map !(q{a == 'W'}).array;\n\t\twriteln (s);\n\t\tauto zeroes = s.count (0);\n\t\tauto ones = s.count (1);\n\t\tif (ones == 0)\n\t\t{\n\t\t\twriteln (max (0, k * 2 - 1));\n\t\t\tcontinue;\n\t\t}\n\t\tint start0 = 0;\n\t\twhile (s.front == 0)\n\t\t{\n\t\t\tstart0 += 1;\n\t\t\ts.popFront ();\n\t\t}\n\t\tint finish0 = 0;\n\t\twhile (s.back == 0)\n\t\t{\n\t\t\tfinish0 += 1;\n\t\t\ts.popBack ();\n\t\t}\n\n\t\tauto h = s.group.filter !(q{a[0] == 1}).count.to !(int);\n\t\tauto res = sum (s) * 2 - h;\n\t\tauto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;\n\t\tg.sort;\n\t\twhile (k > 0 && !g.empty)\n\t\t{\n\t\t\tauto d = min (k, g.front);\n\t\t\tk -= d;\n\t\t\tres += 2 * d + (d == g.front);\n\t\t\tg.popFront ();\n\t\t}\n\t\tif (k > 0 && finish0 > 0)\n\t\t{\n\t\t\tauto d = min (k, finish0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d;\n\t\t}\n\t\tif (k > 0 && start0 > 0)\n\t\t{\n\t\t\tauto d = min (k, start0);\n\t\t\tk -= d;\n\t\t\tres += 2 * d;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "c4c3c07b2ba6df49d5a7d6d2d0d1895f"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint[][] PERM3S = [\n\t[ 0, 1, 2 ], \n\t[ 0, 2, 1 ], \n\t[ 1, 0, 2 ], \n\t[ 1, 2, 0 ], \n\t[ 2, 0, 1 ], \n\t[ 2, 1, 0 ], \n];\n\nlong dot(long[] a, long[] b) {\n\tlong ret;\n\tforeach (d; 0 .. 3) {\n\t\tret += a[d] * b[d];\n\t}\n\treturn ret;\n}\n\nlong[][] A;\n\nvoid solve() {\n\tforeach (i; 0 .. 8) {\n\t\tforeach (j; 0 .. 8) foreach (k; 0 .. 8) foreach (l; 0 .. 8) {\n\t\t\tif (j != i && k != i && l != i && j < k && k < l) {\n\t\t\t\tforeach (sj; 0 .. 6) foreach (sk; 0 .. 6) foreach (sl; 0 .. 6) {\n\t\t\t\t\tlong[][] vs = new long[][](8, 3);\n\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\tvs[1][d] = A[j][PERM3S[sj][d]] - A[i][d];\n\t\t\t\t\t\tvs[2][d] = A[k][PERM3S[sk][d]] - A[i][d];\n\t\t\t\t\t\tvs[4][d] = A[l][PERM3S[sl][d]] - A[i][d];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tconst pjj = dot(vs[1], vs[1]);\n\t\t\t\t\tconst pjk = dot(vs[1], vs[2]);\n\t\t\t\t\tconst pjl = dot(vs[1], vs[4]);\n\t\t\t\t\tconst pkk = dot(vs[2], vs[2]);\n\t\t\t\t\tconst pkl = dot(vs[2], vs[4]);\n\t\t\t\t\tconst pll = dot(vs[4], vs[4]);\n\t\t\t\t\tif (pjj == pkk && pkk == pll && pll > 0 && pjk == 0 && pjl == 0 && pkl == 0) {\ndebug{\nwriteln(i,\" \",j,\" \",k,\" \",l);\nwriteln(vs[1],\" \",vs[2],\" \",vs[4]);\n}\n\t\t\t\t\t\tlong[][] as, bs;\n\t\t\t\t\t\tforeach (m; 0 .. 8) {\n\t\t\t\t\t\t\tif (m != i && m != j && m != k && m != l) {\n\t\t\t\t\t\t\t\tas ~= A[m];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tforeach (f; 0 .. 8) if (f & (f - 1)) {\n\t\t\t\t\t\t\tlong[] b = new long[3];\n\t\t\t\t\t\t\tif (f & 1) b[] += vs[1][];\n\t\t\t\t\t\t\tif (f & 2) b[] += vs[2][];\n\t\t\t\t\t\t\tif (f & 4) b[] += vs[4][];\n\t\t\t\t\t\t\tbs ~= b;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tassert(as.length == 4);\n\t\t\t\t\t\tassert(bs.length == 4);\n\t\t\t\t\t\tint[] perm = [ 0, 1, 2, 3 ];\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tbool ok = true;\n\t\t\t\t\t\t\tint[] ss;\n\t\t\t\t\t\t\tforeach (x; 0 .. 4) {\n\t\t\t\t\t\t\t\tbool found;\n\t\t\t\t\t\t\t\tforeach (s; 0 .. 6) {\n\t\t\t\t\t\t\t\t\tbool eq = true;\n\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\teq = eq && (bs[perm[x]][d] == as[x][PERM3S[s][d]] - A[i][d]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (eq) {\n\t\t\t\t\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\t\t\t\t\tss ~= s;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tok = ok && found;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (ok) {\ndebug{\nwriteln(\"ss = \",ss);\n}\n\t\t\t\t\t\t\t\twriteln(\"YES\");\n\t\t\t\t\t\t\t\tint pos;\n\t\t\t\t\t\t\t\tforeach (h; 0 .. 8) {\n\t\t\t\t\t\t\t\t\tconst s = (h == i) ? 0 : (h == j) ? sj : (h == k) ? sk : (h == l) ? sl : ss[pos++];\n\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\tif (d > 0) write(\" \");\n\t\t\t\t\t\t\t\t\t\twrite(A[h][PERM3S[s][d]]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\twriteln;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (perm.nextPermutation);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(\"NO\");\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = new long[][](8, 3);\n\t\tforeach (i; 0 .. 8) {\n\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\tA[i][d] = readLong;\n\t\t\t}\n\t\t}\n\t\t\n\t\tsolve;\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MAX_N = 8;\nimmutable int MAX_D = 3;\n\nlong dist (int [MAX_D] p, int [MAX_D] q)\n{\n\tlong res = 0L;\n\tforeach (j; 0..MAX_D)\n\t{\n \tlong cur = q[j] - p[j];\n \tres += cur * cur;\n\t}\n\treturn res;\n}\n\nint [MAX_D] [] build (int [MAX_D] [] a)\n{\n\tlong d01 = dist (a[0], a[1]);\n\tif (d01 == 0L)\n\t{\n\t\treturn null;\n\t}\n\tlong d02 = dist (a[0], a[2]);\n\tif (d02 != d01)\n\t{\n\t\treturn null;\n\t}\n\tlong d03 = dist (a[0], a[3]);\n\tif (d03 != d01)\n\t{\n\t\treturn null;\n\t}\n\tlong d12 = dist (a[1], a[2]);\n\tif (d12 != d01 * 2)\n\t{\n\t\treturn null;\n\t}\n\tlong d13 = dist (a[1], a[3]);\n\tif (d13 != d12)\n\t{\n\t\treturn null;\n\t}\n\tlong d23 = dist (a[2], a[3]);\n\tif (d23 != d12)\n\t{\n\t\treturn null;\n\t}\n\n\tint [MAX_D] [] f;\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tint [MAX_D] c = a[0];\n\t\tif (i & 1)\n\t\t{\n\t\t\tc[] += a[1][] - a[0][];\n\t\t}\n\t\tif (i & 2)\n\t\t{\n\t\t\tc[] += a[2][] - a[0][];\n\t\t}\n\t\tif (i & 4)\n\t\t{\n\t\t\tc[] += a[3][] - a[0][];\n\t\t}\n\t\tf ~= c;\n\t}\n\tdebug {writefln (\"Candidate:\\n%(%(%s %)\\n%)\", f);}\n\n\tint [MAX_D] [] g = a[MAX_N / 2..$].dup;\nsearch_loop:\t\n\tforeach (i; [3, 5, 6, 7])\n\t{\n\t\tforeach (ref c; g)\n\t\t{\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif (c == f[i])\n\t\t\t\t{\n\t\t\t\t\tc[] = int.min;\n\t\t\t\t\tcontinue search_loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (nextPermutation (c[]));\n\t\t}\n\t\treturn null;\n\t}\n\n\treturn f;\n}\n\nvoid answer (int [MAX_D] [] f, int [MAX_D] [] c)\n{\n\twriteln (\"YES\");\nanswer_loop:\n\tdo\n\t{\nlocal_loop:\n\t\tforeach (i; 0..MAX_N)\n\t\t{\n\t\t\tsort (c[i][]);\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif (f[i][] == c[i][])\n\t\t\t\t{\n\t\t\t\t\tcontinue local_loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (nextPermutation (c[i][]));\n\t\t\tcontinue answer_loop;\n\t\t}\n\t\twritefln (\"%(%(%s %)\\n%)\", f);\n\t\treturn;\n\t}\n\twhile (nextPermutation (f));\n\tassert (false);\n}\n\nvoid main ()\n{\n\tint [MAX_D] [] a = new int [MAX_D] [MAX_N];\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tforeach (j; 0..MAX_D)\n\t\t{\n\t\t\treadf (\" %s\", &a[i][j]);\n\t\t}\n\t}\n\n\tint [MAX_D] [] c = a.dup;\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tsort (a[i][]);\n\t}\n\tsort (a);\n\n\tint [MAX_D] [] b = new int [MAX_D] [MAX_N / 2];\n\tforeach (i; 0..MAX_N / 2)\n\t{\n\t\tforeach (j; 0..MAX_D)\n\t\t{\n\t\t\tb[i][j] = int.min;\n\t\t}\n\t}\n\n\tdo\n\t{\n\t\tif (b[] == a[0..MAX_N / 2])\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tb[] = a[0..MAX_N / 2];\n\t\tdo\n\t\t{\n\t\t\tdo\n\t\t\t{\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\tauto f = build (a);\n\t\t\t\t\t\tif (f !is null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tanswer (f, c);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\twhile (nextPermutation (a[3][]));\n\t\t\t\t}\n\t\t\t\twhile (nextPermutation (a[2][]));\n\t\t\t}\n\t\t\twhile (nextPermutation (a[1][]));\n\t\t}\n\t\twhile (nextPermutation (a[0][]));\n\t}\n\twhile (nextPermutation (a[1..$]));\n\n\twriteln (\"NO\");\n}\n\n// the following is a Phobos snipped with \"ref\" stripped\n// library code start\nbool nextPermutation(alias less=\"a<b\", BidirectionalRange)\n (BidirectionalRange range)\n if (isBidirectionalRange!BidirectionalRange &&\n hasSwappableElements!BidirectionalRange)\n{\n // Ranges of 0 or 1 element have no distinct permutations.\n if (range.empty) return false;\n\n auto i = retro(range);\n auto last = i.save;\n\n // Find last occurring increasing pair of elements\n size_t n = 1;\n for (i.popFront(); !i.empty; i.popFront(), last.popFront(), n++)\n {\n if (binaryFun!less(i.front, last.front))\n break;\n }\n\n if (i.empty) {\n // Entire range is decreasing: it's lexicographically the greatest. So\n // wrap it around.\n range.reverse();\n return false;\n }\n\n // Find last element greater than i.front.\n auto j = find!((a) => binaryFun!less(i.front, a))(\n takeExactly(retro(range), n));\n\n assert(!j.empty); // shouldn't happen since i.front < last.front\n swap(i.front, j.front);\n reverse(takeExactly(retro(range), n));\n\n return true;\n}\n// library code end\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MAX_N = 8;\nimmutable int MAX_D = 3;\n\nlong dist (int [MAX_D] p, int [MAX_D] q)\n{\n\tlong res = 0L;\n\tforeach (j; 0..MAX_D)\n\t{\n \tlong cur = q[j] - p[j];\n \tres += cur * cur;\n\t}\n\treturn res;\n}\n\nint [MAX_D] [] build (int [MAX_D] [] a)\n{\n\tlong d01 = dist (a[0], a[1]);\n\tif (d01 == 0L)\n\t{\n\t\treturn null;\n\t}\n\tlong d02 = dist (a[0], a[2]);\n\tif (d02 != d01)\n\t{\n\t\treturn null;\n\t}\n\tlong d03 = dist (a[0], a[3]);\n\tif (d03 != d01)\n\t{\n\t\treturn null;\n\t}\n\tlong d12 = dist (a[1], a[2]);\n\tif (d12 != d01 * 2)\n\t{\n\t\treturn null;\n\t}\n\tlong d13 = dist (a[1], a[3]);\n\tif (d13 != d12)\n\t{\n\t\treturn null;\n\t}\n\tlong d23 = dist (a[2], a[3]);\n\tif (d23 != d12)\n\t{\n\t\treturn null;\n\t}\n\n\tint [MAX_D] [] f;\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tint [MAX_D] c = a[0];\n\t\tif (i & 1)\n\t\t{\n\t\t\tc[] += a[1][] - a[0][];\n\t\t}\n\t\tif (i & 2)\n\t\t{\n\t\t\tc[] += a[2][] - a[0][];\n\t\t}\n\t\tif (i & 4)\n\t\t{\n\t\t\tc[] += a[3][] - a[0][];\n\t\t}\n\t\tf ~= c;\n\t}\n\tdebug {writefln (\"Candidate:\\n%(%(%s %)\\n%)\", f);}\n\n\tint [MAX_D] [] g = a[MAX_N / 2..$].dup;\nsearch_loop:\t\n\tforeach (i; [3, 5, 6, 7])\n\t{\n\t\tforeach (ref c; g)\n\t\t{\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif (c == f[i])\n\t\t\t\t{\n\t\t\t\t\tc[] = int.min;\n\t\t\t\t\tcontinue search_loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (nextPermutation (c[]));\n\t\t}\n\t\treturn null;\n\t}\n\n\treturn f;\n}\n\nvoid main ()\n{\n\tint [MAX_D] [] a = new int [MAX_D] [MAX_N];\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tforeach (j; 0..MAX_D)\n\t\t{\n\t\t\treadf (\" %s\", &a[i][j]);\n\t\t}\n\t\tsort (a[i][]);\n\t}\n\tsort (a);\n\n\tint [MAX_D] [] b = new int [MAX_D] [MAX_N / 2];\n\tforeach (i; 0..MAX_N / 2)\n\t{\n\t\tforeach (j; 0..MAX_D)\n\t\t{\n\t\t\tb[i][j] = int.min;\n\t\t}\n\t}\n\n\tdo\n\t{\n\t\tif (b[] == a[0..MAX_N / 2])\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tb[] = a[0..MAX_N / 2];\n\t\tdo\n\t\t{\n\t\t\tdo\n\t\t\t{\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\tauto f = build (a);\n\t\t\t\t\t\tif (f !is null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\twriteln (\"YES\");\n\t\t\t\t\t\t\twritefln\n\t\t\t\t\t\t\t (\"%(%(%s %)\\n%)\",\n\t\t\t\t\t\t\t f);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\twhile (nextPermutation (a[3][]));\n\t\t\t\t}\n\t\t\t\twhile (nextPermutation (a[2][]));\n\t\t\t}\n\t\t\twhile (nextPermutation (a[1][]));\n\t\t}\n\t\twhile (nextPermutation (a[0][]));\n\t}\n\twhile (nextPermutation (a[1..$]));\n\n\twriteln (\"NO\");\n}\n\n// the following is a Phobos snipped with \"ref\" stripped\n// library code start\nbool nextPermutation(alias less=\"a<b\", BidirectionalRange)\n (BidirectionalRange range)\n if (isBidirectionalRange!BidirectionalRange &&\n hasSwappableElements!BidirectionalRange)\n{\n // Ranges of 0 or 1 element have no distinct permutations.\n if (range.empty) return false;\n\n auto i = retro(range);\n auto last = i.save;\n\n // Find last occurring increasing pair of elements\n size_t n = 1;\n for (i.popFront(); !i.empty; i.popFront(), last.popFront(), n++)\n {\n if (binaryFun!less(i.front, last.front))\n break;\n }\n\n if (i.empty) {\n // Entire range is decreasing: it's lexicographically the greatest. So\n // wrap it around.\n range.reverse();\n return false;\n }\n\n // Find last element greater than i.front.\n auto j = find!((a) => binaryFun!less(i.front, a))(\n takeExactly(retro(range), n));\n\n assert(!j.empty); // shouldn't happen since i.front < last.front\n swap(i.front, j.front);\n reverse(takeExactly(retro(range), n));\n\n return true;\n}\n// library code end\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint[][] PERM3S = [\n\t[ 0, 1, 2 ], \n\t[ 0, 2, 1 ], \n\t[ 1, 0, 2 ], \n\t[ 1, 2, 0 ], \n\t[ 2, 0, 1 ], \n\t[ 2, 1, 0 ], \n];\n\nlong dot(long[] a, long[] b) {\n\tlong ret;\n\tforeach (d; 0 .. 3) {\n\t\tret += a[d] * b[d];\n\t}\n\treturn ret;\n}\n\nlong[][] A;\n\nvoid solve() {\n\tforeach (i; 0 .. 8) {\n\t\tforeach (j; 0 .. 8) foreach (k; 0 .. 8) foreach (l; 0 .. 8) {\n\t\t\tif (j != i && k != i && l != i && j < k && k < l) {\n\t\t\t\tforeach (sj; 0 .. 6) foreach (sk; 0 .. 6) foreach (sl; 0 .. 6) {\n\t\t\t\t\tlong[][] vs = new long[][](8, 3);\n\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\tvs[1][d] = A[j][PERM3S[sj][d]] - A[i][d];\n\t\t\t\t\t\tvs[2][d] = A[k][PERM3S[sk][d]] - A[i][d];\n\t\t\t\t\t\tvs[4][d] = A[l][PERM3S[sl][d]] - A[i][d];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tconst pjj = dot(vs[1], vs[1]);\n\t\t\t\t\tconst pjk = dot(vs[1], vs[2]);\n\t\t\t\t\tconst pjl = dot(vs[1], vs[4]);\n\t\t\t\t\tconst pkk = dot(vs[2], vs[2]);\n\t\t\t\t\tconst pkl = dot(vs[2], vs[4]);\n\t\t\t\t\tconst pll = dot(vs[4], vs[4]);\n\t\t\t\t\tif (pjj == pkk && pkk == pll && pll > 0 && pjk == 0 && pjl == 0 && pkl == 0) {\n// writeln(vs[1],\" \",vs[2],\" \",vs[4]);\n\t\t\t\t\t\tlong[][] as, bs;\n\t\t\t\t\t\tforeach (m; 0 .. 8) {\n\t\t\t\t\t\t\tif (m != i && m != j && m != k && m != l) {\n\t\t\t\t\t\t\t\tas ~= A[m];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tforeach (h; 0 .. 8) if (h & (h - 1)) {\n\t\t\t\t\t\t\tlong[] b = new long[3];\n\t\t\t\t\t\t\tif (h & 1) b[] += vs[1][];\n\t\t\t\t\t\t\tif (h & 2) b[] += vs[2][];\n\t\t\t\t\t\t\tif (h & 4) b[] += vs[4][];\n\t\t\t\t\t\t\tbs ~= b;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tassert(as.length == 4);\n\t\t\t\t\t\tassert(bs.length == 4);\n\t\t\t\t\t\tint[] perm = [ 0, 1, 2, 3 ];\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tbool ok = true;\n\t\t\t\t\t\t\tint[] ss;\n\t\t\t\t\t\t\tforeach (x; 0 .. 4) {\n\t\t\t\t\t\t\t\tbool found;\n\t\t\t\t\t\t\t\tforeach (s; 0 .. 6) {\n\t\t\t\t\t\t\t\t\tbool eq = true;\n\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\teq = eq && (bs[x][d] == as[perm[x]][PERM3S[s][d]] - A[i][d]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (eq) {\n\t\t\t\t\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\t\t\t\t\tss ~= s;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tok = ok && found;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (ok) {\n\t\t\t\t\t\t\t\twriteln(\"YES\");\n\t\t\t\t\t\t\t\tint pos;\n\t\t\t\t\t\t\t\tforeach (h; 0 .. 8) {\n\t\t\t\t\t\t\t\t\tif (h == i) {\n\t\t\t\t\t\t\t\t\t\twriteln(A[i].to!string.removechars(\"[],\"));\n\t\t\t\t\t\t\t\t\t} else if (h == j) {\n\t\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\t\tif (d > 0) write(\" \");\n\t\t\t\t\t\t\t\t\t\t\twrite(A[j][PERM3S[sj][d]]);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twriteln;\n\t\t\t\t\t\t\t\t\t} else if (h == k) {\n\t\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\t\tif (d > 0) write(\" \");\n\t\t\t\t\t\t\t\t\t\t\twrite(A[k][PERM3S[sk][d]]);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twriteln;\n\t\t\t\t\t\t\t\t\t} else if (h == l) {\n\t\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\t\tif (d > 0) write(\" \");\n\t\t\t\t\t\t\t\t\t\t\twrite(A[l][PERM3S[sl][d]]);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twriteln;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst s = ss[pos];\n\t\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\t\tif (d > 0) write(\" \");\n\t\t\t\t\t\t\t\t\t\t\twrite(as[pos][PERM3S[s][d]]);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twriteln;\n\t\t\t\t\t\t\t\t\t\t++pos;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (perm.nextPermutation);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(\"NO\");\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = new long[][](8, 3);\n\t\tforeach (i; 0 .. 8) {\n\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\tA[i][d] = readLong;\n\t\t\t}\n\t\t}\n\t\t\n\t\tsolve;\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint[][] PERM3S = [\n\t[ 0, 1, 2 ], \n\t[ 0, 2, 1 ], \n\t[ 1, 0, 2 ], \n\t[ 1, 2, 0 ], \n\t[ 2, 0, 1 ], \n\t[ 2, 1, 0 ], \n];\n\nlong dot(long[] a, long[] b) {\n\tlong ret;\n\tforeach (d; 0 .. 3) {\n\t\tret += a[d] * b[d];\n\t}\n\treturn ret;\n}\n\nlong[][] A;\n\nvoid solve() {\n\tforeach (i; 0 .. 8) {\n\t\tforeach (j; 0 .. 8) foreach (k; 0 .. 8) foreach (l; 0 .. 8) {\n\t\t\tif (j != i && k != i && l != i && j < k && k < l) {\n\t\t\t\tforeach (sj; 0 .. 6) foreach (sk; 0 .. 6) foreach (sl; 0 .. 6) {\n\t\t\t\t\tlong[][] vs = new long[][](8, 3);\n\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\tvs[1][d] = A[j][PERM3S[sj][d]] - A[i][d];\n\t\t\t\t\t\tvs[2][d] = A[k][PERM3S[sk][d]] - A[i][d];\n\t\t\t\t\t\tvs[4][d] = A[l][PERM3S[sl][d]] - A[i][d];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tconst pjj = dot(vs[1], vs[1]);\n\t\t\t\t\tconst pjk = dot(vs[1], vs[2]);\n\t\t\t\t\tconst pjl = dot(vs[1], vs[4]);\n\t\t\t\t\tconst pkk = dot(vs[2], vs[2]);\n\t\t\t\t\tconst pkl = dot(vs[2], vs[4]);\n\t\t\t\t\tconst pll = dot(vs[4], vs[4]);\n\t\t\t\t\tif (pjj == pkk && pkk == pll && pll > 0 && pjk == 0 && pjl == 0 && pkl == 0) {\n// writeln(vs[1],\" \",vs[2],\" \",vs[4]);\n\t\t\t\t\t\tlong[][] as, bs;\n\t\t\t\t\t\tforeach (m; 0 .. 8) {\n\t\t\t\t\t\t\tif (m != i && m != j && m != k && m != l) {\n\t\t\t\t\t\t\t\tas ~= A[m];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tforeach (h; 0 .. 8) if (h & (h - 1)) {\n\t\t\t\t\t\t\tlong[] b = new long[3];\n\t\t\t\t\t\t\tif (h & 1) b[] += vs[1][];\n\t\t\t\t\t\t\tif (h & 2) b[] += vs[2][];\n\t\t\t\t\t\t\tif (h & 4) b[] += vs[4][];\n\t\t\t\t\t\t\tbs ~= b;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tassert(as.length == 4);\n\t\t\t\t\t\tassert(bs.length == 4);\n\t\t\t\t\t\tint[] perm = [ 0, 1, 2, 3 ];\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tbool ok = true;\n\t\t\t\t\t\t\tint[] ss;\n\t\t\t\t\t\t\tforeach (x; 0 .. 4) {\n\t\t\t\t\t\t\t\tbool found;\n\t\t\t\t\t\t\t\tforeach (s; 0 .. 6) {\n\t\t\t\t\t\t\t\t\tbool eq = true;\n\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\teq = eq && (bs[x][d] == as[perm[x]][PERM3S[s][d]] - A[i][d]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (eq) {\n\t\t\t\t\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\t\t\t\t\tss ~= s;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tok = ok && found;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (ok) {\n\t\t\t\t\t\t\t\twriteln(\"YES\");\n\t\t\t\t\t\t\t\tint pos;\n\t\t\t\t\t\t\t\tforeach (h; 0 .. 8) {\n\t\t\t\t\t\t\t\t\tif (h == i) {\n\t\t\t\t\t\t\t\t\t\twriteln(A[i].to!string.removechars(\"[],\"));\n\t\t\t\t\t\t\t\t\t} else if (h == j) {\n\t\t\t\t\t\t\t\t\t\twriteln(vs[1].to!string.removechars(\"[],\"));\n\t\t\t\t\t\t\t\t\t} else if (h == k) {\n\t\t\t\t\t\t\t\t\t\twriteln(vs[2].to!string.removechars(\"[],\"));\n\t\t\t\t\t\t\t\t\t} else if (h == l) {\n\t\t\t\t\t\t\t\t\t\twriteln(vs[4].to!string.removechars(\"[],\"));\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst s = ss[pos];\n\t\t\t\t\t\t\t\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\t\t\t\t\t\t\t\tif (d > 0) write(\" \");\n\t\t\t\t\t\t\t\t\t\t\twrite(as[pos][PERM3S[s][d]]);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\twriteln;\n\t\t\t\t\t\t\t\t\t\t++pos;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (perm.nextPermutation);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(\"NO\");\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = new long[][](8, 3);\n\t\tforeach (i; 0 .. 8) {\n\t\t\tforeach (d; 0 .. 3) {\n\t\t\t\tA[i][d] = readLong;\n\t\t\t}\n\t\t}\n\t\t\n\t\tsolve;\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "src_uid": "55da4611bc78d55c228d0ce78bd02fd3"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\n\nvoid solve()\n{\n auto N = readln.chomp.to!long;\n long x;\n foreach (long i; 0..32) {\n x += x + (2L^^i)^^2;\n if (N >= x) {\n N -= x;\n } else {\n writeln(i);\n return;\n }\n }\n}\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n solve();\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\n\nvoid solve(){\n long n;\n n = rd;\n long tim = 2; \n ll[] arr, pref;\n arr ~= 1;\n pref ~= 1;\n foreach(i; 1..32){\n arr ~= 2*arr[i-1] + tim * tim;\n tim *= 2;\n pref ~= arr[i] + pref[i-1];\n }\n /* writeln(pref); */\n ll maxi = 0;\n foreach(i; 1..32){\n if(pref[i] > n){\n maxi = i;\n break;\n }\n }\n /* writeln(arr); */\n writeln(maxi);\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD-1;\n\t\tans[ti] = 1;\n\t\tlong y = 1;\n\t\tlong cnt = 1;\n\t\tforeach (i; 0..10^^7)\n\t\t{\n\t\t\ty *= 2;\n\t\t\tlong z = cnt*2 + y^^2; \n\t\t\tif (z > x) break;\n\t\t\tx -= z;\n\t\t\t++ans[ti];\n\t\t\tcnt = z;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\n\nvoid solve(){\n long n;\n n = rd;\n long tim = 2; \n ll[] arr;\n arr ~= 1;\n foreach(i; 1..62){\n arr ~= 2*arr[i-1] + tim * tim;\n if(n < arr.back){\n break;\n }\n tim *= 2;\n }\n arr.popBack;\n /* writeln(arr); */\n writeln(arr.length);\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD-1;\n\t\tans[ti] = 1;\n\t\tlong y = 1;\n\t\tforeach (i; 0..10^^7)\n\t\t{\n\t\t\ty *= 2;\n\t\t\tlong z = y + y^^2; \n\t\t\tif (z > x) break;\n\t\t\tx -= z;\n\t\t\t++ans[ti];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "f0806ab99cf4da228abe3cd8073884d9"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.format;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int MED_L = 1 << 17;\nimmutable int MAX_L = MED_L << 1;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (scanf (\" %d %d\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tscanf (\" %d\", &a[i]);\n\t\t}\n\t\tauto b = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tscanf (\" %d\", &b[i]);\n\t\t}\n\n\t\tauto x = new int [m];\n\t\tauto y = new int [m];\n\t\tauto z = new int [m];\n\t\tauto t = new int [MAX_L];\n\t\tt[] = -1;\n\n\t\tvoid mark (int q, int lo, int hi)\n\t\t{\n\t\t\tlo += MED_L;\n\t\t\thi += MED_L;\n\t\t\twhile (lo <= hi)\n\t\t\t{\n\t\t\t\tif (lo & 1)\n\t\t\t\t{\n\t\t\t\t\tdebug {writefln (\"t[%s] = %s\", lo, q);}\n\t\t\t\t\tt[lo] = q;\n\t\t\t\t\tlo++;\n\t\t\t\t}\n\t\t\t\tif (!(hi & 1))\n\t\t\t\t{\n\t\t\t\t\tdebug {writefln (\"t[%s] = %s\", hi, q);}\n\t\t\t\t\tt[hi] = q;\n\t\t\t\t\thi--;\n\t\t\t\t}\n\t\t\t\tlo >>= 1;\n\t\t\t\thi >>= 1;\n\t\t\t}\n\t\t}\n\n\t\tint value (int p)\n\t\t{\n\t\t\tint res = b[p];\n\t\t\tint q = -1;\n\t\t\tfor (int s = p + MED_L; s > 0; s >>= 1)\n\t\t\t{\n\t\t\t\tq = max (q, t[s]);\n\t\t\t}\n\t\t\tif (q != -1)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"q = %s, p = %s\", q, p);}\n\t\t\t\tdebug {writefln (\"index = %s + %s - %s = %s\",\n\t\t\t\t x[q], p, y[q],\n\t\t\t\t x[q] + p - y[q]);}\n\t\t\t\tres = a[x[q] + p - y[q]];\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint k;\n\t\t\tscanf (\" %d\", &k);\n\t\t\tif (k == 1)\n\t\t\t{\n\t\t\t\tscanf (\" %d %d %d\", &x[j], &y[j], &z[j]);\n\t\t\t\tx[j]--;\n\t\t\t\ty[j]--;\n\t\t\t\tmark (j, y[j], y[j] + z[j] - 1);\n\t\t\t}\n\t\t\telse if (k == 2)\n\t\t\t{\n\t\t\t\tint p;\n\t\t\t\tscanf (\" %d\", &p);\n\t\t\t\tdebug {writefln (\"p = %d\", p);}\n\t\t\t\tp--;\n\t\t\t\tint v = value (p);\n\t\t\t\tprintf (\"%d\\n\", v);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n auto b = readln.chomp.split.map!(to!int).array;\n \n struct q {\n int t, x, y, k;\n }\n \n auto qs = new q[] (m);\n foreach (i; 0 .. m) {\n readf(\"%s\", &qs[i].t);\n if (qs[i].t == 1) {\n readf(\" %s %s %s\", &qs[i].x, &qs[i].y, &qs[i].k);\n } else {\n readf(\" %s\", &qs[i].x);\n }\n readln;\n }\n \n debug { qs.writeln; }\n \n auto ans = new int[] (m);\n \n alias elem = Tuple!(int, int);\n auto rbt = make!(RedBlackTree!elem);\n foreach_reverse (i, cq; qs) {\n if (cq.t == 2) {\n rbt.insert(tuple(cq.x, i.to!int));\n } else {\n auto seq = rbt.upperBound(tuple(cq.y, 0)).until!(t => t[0] > cq.y + cq.k - 1);\n debug { cq.y.writeln; seq.writeln; }\n \n foreach (e; seq) {\n ans[e[1]] = a[cq.x + e[0] - cq.y - 1];\n }\n \n auto cpy = seq.array.dup;\n foreach (e; cpy) { rbt.removeKey(e); }\n }\n }\n \n foreach (e; rbt) {\n ans[e[1]] = b[e[0] - 1];\n }\n \n foreach (i; 0 .. m) {\n if (qs[i].t == 1) { continue; }\n \n ans[i].writeln;\n }\n}"}, {"source_code": "import std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Tuple!(int, \"x\", int, \"y\") Pair;\n\nclass SegmentTree {\n int l;\n int r;\n Pair val;\n SegmentTree l_son;\n SegmentTree r_son;\n\n this(int l, int r) {\n this.l = l;\n this.r = r;\n this.val.x = this.val.y = -1;\n if (l != r) {\n this.l_son = new SegmentTree(l, (l+r)/2);\n this.r_son = new SegmentTree((l+r)/2+1, r);\n }\n }\n\n void Upd() {\n if (this.val.x != -1) {\n this.l_son.val = this.val;\n this.r_son.val = this.val;\n this.val.x = this.val.y = -1;\n }\n }\n\n void Col(int l, int r, int x, int y) {\n if (l > this.r || r < this.l) {\n return;\n }\n if (l <= this.l && r >= this.r) {\n this.val.x = x;\n this.val.y = y;\n return;\n }\n Upd();\n this.l_son.Col(l, r, x, y);\n this.r_son.Col(l, r, x, y);\n }\n\n Pair Val(int pos) {\n if (this.val.x != -1 || this.l == this.r) {\n return this.val;\n }\n return pos <= this.l_son.r ? this.l_son.Val(pos) : this.r_son.Val(pos);\n }\n}\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n int n;\n int m;\n readf(\"%d %d \", &n, &m);\n int[] a = new int[n];\n int[] b = new int[n];\n foreach (i; 0..n) {\n readf(\"%d \", &a[i]);\n }\n foreach (i; 0..n) {\n readf(\"%d \", &b[i]);\n }\n SegmentTree tree = new SegmentTree(0, n-1);\n foreach (i; 0..m) {\n int t;\n readf(\"%d \", &t);\n if (t == 1) {\n int x;\n int y;\n int k;\n readf(\"%d %d %d \", &x, &y, &k);\n x--;\n y--;\n tree.Col(y, y+k-1, x, y);\n } else {\n int pos;\n readf(\"%d \", &pos);\n pos--;\n Pair cur_val = tree.Val(pos);\n if (cur_val.x == -1) {\n writeln(b[pos]);\n } else {\n writeln(a[cur_val.x + pos - cur_val.y]);\n }\n }\n }\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n auto b = readln.chomp.split.map!(to!int).array;\n \n struct q {\n int t, x, y, k;\n }\n \n auto qs = new q[] (m);\n foreach (i; 0 .. m) {\n readf(\"%s\", &qs[i].t);\n if (qs[i].t == 1) {\n readf(\" %s %s %s\", &qs[i].x, &qs[i].y, &qs[i].k);\n } else {\n readf(\" %s\", &qs[i].x);\n }\n readln;\n }\n \n debug { qs.writeln; }\n \n auto ans = new int[] (m);\n \n alias elem = Tuple!(int, int);\n auto rbt = make!(RedBlackTree!elem);\n foreach_reverse (i, cq; qs) {\n if (cq.t == 2) {\n rbt.insert(tuple(cq.x, i.to!int));\n } else {\n auto seq = rbt.upperBound(tuple(cq.y, 0)).until!(t => t[0] > cq.y + cq.k);\n debug { cq.y.writeln; seq.writeln; }\n \n foreach (e; seq) {\n ans[e[1]] = a[cq.x + e[0] - cq.y - 1];\n }\n \n auto cpy = seq.array.dup;\n foreach (e; cpy) { rbt.removeKey(e); }\n }\n }\n \n foreach (e; rbt) {\n ans[e[1]] = b[e[0] - 1];\n }\n \n foreach (i; 0 .. m) {\n if (qs[i].t == 1) { continue; }\n \n ans[i].writeln;\n }\n}"}], "src_uid": "27c703f9846064af2b0deab93d394272"} {"source_code": "import core.bitop;\nimport core.checkedint;\n//import core.stdc.stdio;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n return readf(' ' ~ replicate(\"%s \", vars.length), getAddrTuple(vars).expand) == vars.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nalias Pos = Tuple!(int, `y`, int, `x`);\n\nenum { U, R, D, L }\n\nchar[101][100] grid;\nchar[100][100] way;\nPos[10^^4] q;\nchar[4] dirs = \"URDL\";\nPos cur, finish;\n\nvoid move(int d) {\n writeln(dirs[d]);\n stdout.flush();\n readf(\" %s %s\", &cur.y, &cur.x);\n if (!~cur.y)\n exit(1);\n cur.y--;\n cur.x--;\n if (cur == finish)\n exit(0);\n}\n\nvoid swapLR() {\n dirs[R] = 'L';\n dirs[L] = 'R';\n}\n\nvoid swapUD() {\n dirs[D] = 'U';\n dirs[U] = 'D';\n}\n\nvoid main() {\n int n, m;\n readf(\"%s %s \", &n, &m);\n memset(grid.ptr, '*', grid.sizeof);\n foreach (int i, ref row; grid[0 .. n]) {\n auto s = row[ ];\n readln(s);\n s[$ - 1] = '*';\n auto tail = s[0 .. m].find('F');\n if (!tail.empty)\n finish = Pos(i, m - cast(int)tail.length);\n }\n assert(finish.y || finish.x);\n\n if (n == 1) {\n move(R);\n if (!cur.x)\n swapLR();\n while (true)\n move(R);\n }\n\n if (m == 1) {\n move(D);\n if (!cur.y)\n swapUD();\n while (true)\n move(D);\n }\n\n const lrFound = grid[0][1] != '*';\n if (lrFound) {\n move(R);\n if (!cur.x)\n swapLR();\n else\n move(L);\n }\n\n const udFound = grid[1][0] != '*';\n if (udFound) {\n move(D);\n if (!cur.y)\n swapUD();\n else\n move(U);\n }\n\n if (!lrFound) {\n assert(udFound);\n foreach (i; 1 .. n) {\n assert(grid[i][0] != '*');\n if (grid[i][1] != '*') {\n foreach (k; 0 .. i)\n move(D);\n move(R);\n if (!cur.x)\n swapLR();\n break;\n }\n }\n } else if (!udFound) {\n assert(lrFound);\n foreach (j; 1 .. m) {\n assert(grid[0][j] != '*');\n if (grid[1][j] != '*') {\n foreach (k; 0 .. j)\n move(R);\n move(D);\n if (!cur.y)\n swapUD();\n break;\n }\n }\n }\n\n int qr = 0, qw = 1;\n q[0] = finish;\n while (true) {\n assert(qr != qw);\n Pos p = q[qr++];\n if (p == cur)\n while (true)\n move(way[cur.y][cur.x]);\n\n enum gen(string cond, char c) = `\n if (`~cond~` && grid[nextPos.y][nextPos.x] != '*') {\n grid[nextPos.y][nextPos.x] = '*';\n way[nextPos.y][nextPos.x] = `~c~`;\n q[qw++] = nextPos;\n }\n `;\n\n Pos nextPos = Pos(p.y - 1, p.x);\n mixin(gen!(`nextPos.y >= 0`, 'D'));\n nextPos = Pos(p.y, p.x + 1);\n mixin(gen!(`nextPos.x < m`, 'L'));\n nextPos = Pos(p.y + 1, p.x);\n mixin(gen!(`nextPos.y < n`, 'U'));\n nextPos = Pos(p.y, p.x - 1);\n mixin(gen!(`nextPos.x >= 0`, 'R'));\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdlib;;\n\nvoid main() {\n immutable int INF = 1 << 28;\n\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n auto B = H.iota.map!(_ => readln.chomp).array;\n\n int gr, gc;\n foreach (i; 0..H) foreach (j; 0..W) if (B[i][j] == 'F') gr = i, gc = j;\n\n int[] dr = [0, 0, -1, 1];\n int[] dc = [-1, 1, 0, 0];\n auto dist = new int[](H * W);\n fill(dist, INF);\n dist[0] = 0;\n auto prev = new int[](H * W);\n fill(prev, -1);\n alias Tuple!(int, \"from\", int, \"to\", int, \"cost\") Edge;\n auto q = new BinaryHeap!(Array!Edge, \"a.cost >= b.cost\");\n q.insert(Edge(-1, 0, 0));\n\n while (!q.empty) {\n auto n = q.front;\n auto pr = n.from / W;\n auto pc = n.from % W;\n auto r = n.to / W;\n auto c = n.to % W;\n q.removeFront;\n if (dist[n.to] < n.cost)\n continue;\n dist[n.to] = n.cost;\n prev[n.to] = n.from;\n\n foreach (i; 0..4) {\n auto nr = r + dr[i];\n auto nc = c + dc[i];\n auto next = nr * W + nc;\n if (nr < 0 || nr >= H || nc < 0 || nc >= W || B[nr][nc] == '*')\n continue;\n if (dist[next] <= dist[n.to] + 1)\n continue;\n dist[next] = dist[n.to] + 1;\n q.insert(Edge(n.to, next, dist[n.to] + 1));\n }\n }\n\n int[] root;\n int x = gr * W + gc;\n while (prev[x] != -1) {\n root = x ~ root;\n x = prev[x];\n }\n\n\n bool swapLR, swapUD;\n Tuple!(int, int) cmd(char dir) {\n if (swapLR && dir == 'L') dir = 'R';\n else if (swapLR && dir == 'R') dir = 'L';\n else if (swapUD && dir == 'U') dir = 'D';\n else if (swapUD && dir == 'D') dir = 'U';\n\n writeln(dir);\n stdout.flush;\n s = readln.split.map!(to!int);\n\n if (s[0] - 1 == gr && s[1] - 1 == gc)\n exit(0);\n return tuple(s[0] - 1, s[1] - 1);\n }\n\n\n\n Tuple!(int, int) pos;\n\n if (H == 1) {\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n while (true) pos = cmd('R');\n return;\n }\n if (W == 1) {\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n while (true) pos = cmd('D');\n return;\n }\n\n if (B[0][1] != '*') {\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n pos = cmd('L');\n while (true) {\n if (B[pos[0]+1][pos[1]] != '*')\n break;\n pos = cmd('R');\n }\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n pos = cmd('U');\n while (pos[1] != 0) pos = cmd('L');\n }\n else {\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n pos = cmd('D');\n while (true) {\n if (B[pos[0]][pos[1]+1] != '*')\n break;\n pos = cmd('D');\n }\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n pos = cmd('L');\n while (pos[0] != 0) pos = cmd('U');\n }\n\n foreach (co; root) {\n int nr = co / W;\n int nc = co % W;\n if (pos[0] - nr == 1) pos = cmd('U');\n else if (pos[0] - nr == -1) pos = cmd('D');\n else if (pos[1] - nc == 1) pos = cmd('L');\n else pos = cmd('R');\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n immutable int INF = 1 << 28;\n\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n auto B = H.iota.map!(_ => readln.chomp).array;\n\n int gr, gc;\n foreach (i; 0..H) foreach (j; 0..W) if (B[i][j] == 'F') gr = i, gc = j;\n\n int[] dr = [0, 0, -1, 1];\n int[] dc = [-1, 1, 0, 0];\n auto dist = new int[](H * W);\n fill(dist, INF);\n dist[0] = 0;\n auto prev = new int[](H * W);\n fill(prev, -1);\n alias Tuple!(int, \"from\", int, \"to\", int, \"cost\") Edge;\n auto q = new BinaryHeap!(Array!Edge, \"a.cost >= b.cost\");\n q.insert(Edge(-1, 0, 0));\n\n while (!q.empty) {\n auto n = q.front;\n auto pr = n.from / W;\n auto pc = n.from % W;\n auto r = n.to / W;\n auto c = n.to % W;\n q.removeFront;\n if (dist[n.to] < n.cost)\n continue;\n dist[n.to] = n.cost;\n prev[n.to] = n.from;\n\n foreach (i; 0..4) {\n auto nr = r + dr[i];\n auto nc = c + dc[i];\n auto next = nr * W + nc;\n if (nr < 0 || nr >= H || nc < 0 || nc >= W || B[nr][nc] == '*')\n continue;\n if (dist[next] <= dist[n.to] + 1)\n continue;\n dist[next] = dist[n.to] + 1;\n q.insert(Edge(n.to, next, dist[n.to] + 1));\n }\n }\n\n int[] root;\n int x = gr * W + gc;\n while (prev[x] != -1) {\n root = x ~ root;\n x = prev[x];\n }\n\n\n bool swapLR, swapUD;\n Tuple!(int, int) cmd(char dir) {\n if (swapLR && dir == 'L') dir = 'R';\n else if (swapLR && dir == 'R') dir = 'L';\n else if (swapUD && dir == 'U') dir = 'D';\n else if (swapUD && dir == 'D') dir = 'U';\n\n writeln(dir);\n stdout.flush;\n s = readln.split.map!(to!int);\n return tuple(s[0] - 1, s[1] - 1);\n }\n\n\n\n Tuple!(int, int) pos;\n\n if (H == 1) {\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n while (pos[0] != gr || pos[1] != gc) pos = cmd('R');\n return;\n }\n if (W == 1) {\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n while (pos[0] != gr || pos[1] != gc) pos = cmd('D');\n return;\n }\n\n if (B[0][1] == '.') {\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n while (true) {\n if (pos[0] == gr && pos[1] == gc)\n return;\n if (B[pos[0]+1][pos[1]] == '.')\n break;\n pos = cmd('R');\n }\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n pos = cmd('U');\n while (pos[1] != 0) pos = cmd('L');\n }\n else {\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n while (true) {\n if (pos[0] == gr && pos[1] == gc)\n return;\n if (B[pos[0]][pos[1]+1] == '.')\n break;\n pos = cmd('D');\n }\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n pos = cmd('L');\n while (pos[0] != 0) pos = cmd('U');\n }\n\n foreach (co; root) {\n int nr = co / W;\n int nc = co % W;\n if (pos[0] - nr == 1) pos = cmd('U');\n else if (pos[0] - nr == -1) pos = cmd('D');\n else if (pos[1] - nc == 1) pos = cmd('L');\n else pos = cmd('R');\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdlib;;\n\nvoid main() {\n immutable int INF = 1 << 28;\n\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n auto B = H.iota.map!(_ => readln.chomp).array;\n\n int gr, gc;\n foreach (i; 0..H) foreach (j; 0..W) if (B[i][j] == 'F') gr = i, gc = j;\n\n int[] dr = [0, 0, -1, 1];\n int[] dc = [-1, 1, 0, 0];\n auto dist = new int[](H * W);\n fill(dist, INF);\n dist[0] = 0;\n auto prev = new int[](H * W);\n fill(prev, -1);\n alias Tuple!(int, \"from\", int, \"to\", int, \"cost\") Edge;\n auto q = new BinaryHeap!(Array!Edge, \"a.cost >= b.cost\");\n q.insert(Edge(-1, 0, 0));\n\n while (!q.empty) {\n auto n = q.front;\n auto pr = n.from / W;\n auto pc = n.from % W;\n auto r = n.to / W;\n auto c = n.to % W;\n q.removeFront;\n if (dist[n.to] < n.cost)\n continue;\n dist[n.to] = n.cost;\n prev[n.to] = n.from;\n\n foreach (i; 0..4) {\n auto nr = r + dr[i];\n auto nc = c + dc[i];\n auto next = nr * W + nc;\n if (nr < 0 || nr >= H || nc < 0 || nc >= W || B[nr][nc] == '*')\n continue;\n if (dist[next] <= dist[n.to] + 1)\n continue;\n dist[next] = dist[n.to] + 1;\n q.insert(Edge(n.to, next, dist[n.to] + 1));\n }\n }\n\n int[] root;\n int x = gr * W + gc;\n while (prev[x] != -1) {\n root = x ~ root;\n x = prev[x];\n }\n\n\n bool swapLR, swapUD;\n Tuple!(int, int) cmd(char dir) {\n if (swapLR && dir == 'L') dir = 'R';\n else if (swapLR && dir == 'R') dir = 'L';\n else if (swapUD && dir == 'U') dir = 'D';\n else if (swapUD && dir == 'D') dir = 'U';\n\n writeln(dir);\n stdout.flush;\n s = readln.split.map!(to!int);\n\n if (s[0] - 1 == gr && s[1] - 1 == gc)\n exit(0);\n return tuple(s[0] - 1, s[1] - 1);\n }\n\n\n\n Tuple!(int, int) pos;\n\n if (H == 1) {\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n while (true) pos = cmd('R');\n return;\n }\n if (W == 1) {\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n while (true) pos = cmd('D');\n return;\n }\n\n if (B[0][1] != '*') {\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n while (true) {\n if (B[pos[0]+1][pos[1]] != '*')\n break;\n pos = cmd('R');\n }\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n pos = cmd('U');\n while (pos[1] != 0) pos = cmd('L');\n }\n else {\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n while (true) {\n if (B[pos[0]][pos[1]+1] != '*')\n break;\n pos = cmd('D');\n }\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n pos = cmd('L');\n while (pos[0] != 0) pos = cmd('U');\n }\n\n foreach (co; root) {\n int nr = co / W;\n int nc = co % W;\n if (pos[0] - nr == 1) pos = cmd('U');\n else if (pos[0] - nr == -1) pos = cmd('D');\n else if (pos[1] - nc == 1) pos = cmd('L');\n else pos = cmd('R');\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n immutable int INF = 1 << 28;\n\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n auto B = H.iota.map!(_ => readln.chomp).array;\n\n int gr, gc;\n foreach (i; 0..H) foreach (j; 0..W) if (B[i][j] == 'F') gr = i, gc = j;\n\n int[] dr = [0, 0, -1, 1];\n int[] dc = [-1, 1, 0, 0];\n auto dist = new int[](H * W);\n fill(dist, INF);\n dist[0] = 0;\n auto prev = new int[](H * W);\n fill(prev, -1);\n alias Tuple!(int, \"from\", int, \"to\", int, \"cost\") Edge;\n auto q = new BinaryHeap!(Array!Edge, \"a.cost >= b.cost\");\n q.insert(Edge(-1, 0, 0));\n\n while (!q.empty) {\n auto n = q.front;\n auto pr = n.from / W;\n auto pc = n.from % W;\n auto r = n.to / W;\n auto c = n.to % W;\n q.removeFront;\n if (dist[n.to] < n.cost)\n continue;\n dist[n.to] = n.cost;\n prev[n.to] = n.from;\n\n foreach (i; 0..4) {\n auto nr = r + dr[i];\n auto nc = c + dc[i];\n auto next = nr * W + nc;\n if (nr < 0 || nr >= H || nc < 0 || nc >= W || B[nr][nc] == '*')\n continue;\n if (dist[next] <= dist[n.to] + 1)\n continue;\n dist[next] = dist[n.to] + 1;\n q.insert(Edge(n.to, next, dist[n.to] + 1));\n }\n }\n\n int[] root;\n int x = gr * W + gc;\n while (prev[x] != -1) {\n root = x ~ root;\n x = prev[x];\n }\n\n\n bool swapLR, swapUD;\n Tuple!(int, int) cmd(char dir) {\n if (swapLR && dir == 'L') dir = 'R';\n else if (swapLR && dir == 'R') dir = 'L';\n else if (swapUD && dir == 'U') dir = 'D';\n else if (swapUD && dir == 'D') dir = 'U';\n\n writeln(dir);\n stdout.flush;\n s = readln.split.map!(to!int);\n return tuple(s[0] - 1, s[1] - 1);\n }\n\n\n\n Tuple!(int, int) pos;\n\n if (H == 1) {\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n while (pos[0] != gr || pos[1] != gc) pos = cmd('R');\n return;\n }\n if (W == 1) {\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n while (pos[0] != gr || pos[1] != gc) pos = cmd('D');\n return;\n }\n\n if (B[0][1] == '.') {\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n while (true) {\n if (pos[0] == gr && pos[1] == gc)\n return;\n if (B[pos[0]+1][pos[1]] == '.')\n break;\n pos = cmd('R');\n }\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n pos = cmd('U');\n while (pos[1] != 0) pos = cmd('L');\n }\n else {\n pos = cmd('D');\n if (pos[0] == 0) swapUD = true;\n while (true) {\n if (pos[0] == gr && pos[1] == gc)\n return;\n if (B[pos[0]][pos[1]+1] == '.')\n break;\n pos = cmd('D');\n }\n pos = cmd('R');\n if (pos[1] == 0) swapLR = true;\n pos = cmd('L');\n while (pos[0] != 0) pos = cmd('U');\n }\n\n foreach (co; root) {\n int nr = co / W;\n int nc = co % W;\n if (pos[0] - nr == 1) pos = cmd('U');\n else if (pos[0] - nr == -1) pos = cmd('D');\n else if (pos[0] - nc == 1) pos = cmd('L');\n else pos = cmd('R');\n }\n}\n"}], "src_uid": "79879630a9358ea152a6f1616ef9b630"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nbool ask (int x, int y)\n{\n\twriteln (\"?\", \" \", x, \" \", y);\n\tstdout.flush ();\n\tauto s = readln.strip;\n\tif (s == \"e\")\n\t{\n\t\tassert (false);\n\t}\n\treturn (s == \"x\");\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tif (s == \"end\")\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tif (s != \"start\")\n\t\t{\n\t\t\tassert (false);\n\t\t}\n\n\t\timmutable int start = 0;\n\t\tint x = start;\n\t\tint y = x;\n\t\tint d = 1;\n\t\tdo\n\t\t{\n\t\t\tx = y;\n\t\t\ty += d;\n\t\t\td *= 2;\n\t\t}\n\t\twhile (!ask (x, y));\n\n\t\tint lo = x + 1;\n\t\tint hi = y;\n\t\twhile (lo != hi)\n\t\t{\n\t\t\tauto me = (lo + hi) / 2;\n\t\t\tif (ask (x, me))\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo = me + 1;\n\t\t\t}\n\t\t}\n\n\t\twriteln (\"!\", \" \", lo);\n\t\tstdout.flush ();\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nlong X;\nint cnt = 0;\n\nvoid ans(long x) {\n debug {\n writeln((x == X) ? \"OK \": \"NG\");\n writeln(cnt);\n return;\n }\n writeln(\"! \", x);\n stdout.flush;\n}\n\nbool ask(long x, long y) {\n debug {\n cnt += 1;\n return x % X >= y % X;\n }\n writeln(\"? \", x, \" \", y);\n stdout.flush;\n return readln.chomp == \"x\";\n}\n\nvoid solve() {\n if (ask(1, 2)) {\n if (ask(2, 1)) {\n ans(1);\n } else {\n ans(2);\n }\n return;\n }\n\n long mn = 2;\n long mx = 4;\n\n while (true) {\n if (ask(mn, mx)) {\n break;\n } else {\n mx *= 2;\n mn *= 2;\n }\n }\n\n while (mx - mn > 1) {\n long next_mn = (mx + mn) / 2;\n if (ask(next_mn, mx)) {\n mn = next_mn;\n } else {\n mx = next_mn;\n }\n }\n\n ans (mx);\n}\n\nvoid main() {\n debug {\n X = readln.chomp.to!int;\n solve;\n return;\n }\n while (true) {\n auto s = readln.chomp;\n if (s == \"start\") solve;\n else break;\n }\n}\n"}], "negative_code": [], "src_uid": "eab8e5ac203d9f10c893ea35d249fe84"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr.sort().reverse();\n \n debug { arr.writeln; }\n \n bool isOk(int md) {\n long eng = 0;\n int sb = 0;\n foreach (i, e; arr) {\n if (i > 0 && i % md == 0) { sb += 1; }\n \n eng += max(e - sb, 0);\n }\n \n return eng >= m;\n }\n \n int le = 1, r = n+1;\n while (le < r) {\n int md = (le + r) / 2;\n if (isOk(md)) { r = md; }\n else { le = md + 1; }\n }\n \n writeln(le == n+1 ? -1 : le);\n}", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n long m;\n rd(n, m);\n auto a = readln.split.to!(long[]);\n\n sort!\"a>b\"(a);\n if (m > reduce!\"a+b\"(a)) {\n writeln(-1);\n return;\n }\n long _s = 0;\n foreach (int i; 0 .. n) {\n _s += max(0L, a[i] - i);\n }\n if (_s >= m) {\n writeln(1);\n return;\n }\n bool enough(long k) {\n long s = 0;\n foreach (i; 0 .. n) {\n s += max(0L, a[i] - (i / k));\n }\n return s >= m;\n }\n\n long ng = 1, ok = n;\n while (ok - ng > 1) {\n auto md = (ok + ng) / 2;\n if (enough(md)) {\n ok = md;\n } else {\n ng = md;\n }\n }\n writeln(ok);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "1b79ff21b5c1df4c54236071a585a52e"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new Tuple!(int, int)[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!int);\n A[i] = tuple(s[0], s[1]);\n }\n\n Tuple!(int, int)[][int] B;\n foreach (i, a; A.enumerate)\n B[a[0]] ~= tuple(a[1], (i+1).to!int);\n\n foreach (k; B.keys)\n B[k].sort();\n\n foreach (k; B.keys)\n if (B[k].length > 1) {\n writeln(B[k].front[1], \" \", B[k].back[1]);\n return;\n }\n\n auto K = B.keys.dup;\n K.sort!\"a > b\"();\n Tuple!(int, int) minv = B[K[0]].front;\n\n foreach (i; 1..K.length) {\n if (B[K[i]].back[0] >= minv[0]) {\n writeln(minv[1], \" \", B[K[i]].back[1]);\n return;\n }\n minv = min(minv, B[K[i]].front);\n }\n\n writeln(-1, \" \", -1);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.typecons: Tuple, tuple;\nimport std.algorithm;\n\nbool within(Tuple!(int, int, int) t0, Tuple!(int, int, int) t1)\n{\n if (t0[0] >= t1[0] && t0[1] <= t1[1])\n {\n return true;\n }\n return false;\n}\n\nvoid solve(Tuple!(int, int, int)[] s)\n{\n s.sort();\n foreach (idx; 0 .. s.length - 1)\n {\n if (within(s[idx], s[idx + 1]))\n {\n writeln(s[idx][2], \" \", s[idx + 1][2]);\n return;\n }\n if (within(s[idx + 1], s[idx]))\n {\n writeln(s[idx + 1][2], \" \", s[idx][2]);\n return;\n }\n }\n writeln(\"-1 -1\");\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto s = new Tuple!(int, int, int)[n];\n foreach (i; 0 .. n)\n {\n int l, r;\n readf(\"%d %d\\n\", &l, &r);\n s[i] = tuple(l, r, i + 1);\n }\n solve(s);\n }\n return 0;\n}"}, {"source_code": "import std.algorithm.sorting;\nimport std.conv;\nimport std.stdio;\nimport std.typecons;\n\nvoid main()\n{\n uint n;\n readf!\"%d\\n\"(n);\n\n Tuple!(uint, uint, uint)[] x;\n\n foreach (i; 0..n) {\n uint a, b;\n \n readf!\"%d %d\\n\"(a, b);\n\n x ~= tuple(a, b, i+1);\n }\n\n x.sort!((a, b) => (a[0] == b[0]) ? (a[1] > b[1]) : (a[0] < b[0]));\n\n // current max\n auto m = x[0][1];\n auto mi = x[0][2];\n\n foreach (i; 1..n) {\n if (x[i][0] <= m && x[i][1] <= m) {\n writefln(\"%d %d\", x[i][2], mi);\n return;\n }\n\n if (x[i][1] > m) {\n m = x[i][1];\n mi = x[i][2];\n }\n }\n writeln(\"-1 -1\");\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf (\"%s\", &n);\n readln;\n Tuple!(ulong, ulong)[] r;\n foreach (_; 0..n) {\n auto nrs = readln.splitter.map!(to!ulong).array;\n r ~= tuple(nrs[0], nrs[1]);\n }\n int[] b = new int[] (r.length);\n makeIndex!(q{a[0] != b[0] ? a[0] < b[0] : a[1] > b[1]})(r, b);\n \n debug { writeln (r); }\n debug { writeln (b); }\n \n int outer = cast(int) b.front;\n auto ans = tuple(-1, -1);\n foreach (p; b.dropOne()) {\n if (r[p][1] <= r[outer][1]) {\n ans = tuple(cast(int) p, outer);\n break;\n } else {\n outer = cast(int) p;\n }\n }\n \n if (ans[0] != -1) ans[0] += 1, ans[1] += 1;\n writeln (ans[0], ' ', ans[1]);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf (\"%s\", &n);\n readln;\n Tuple!(int, int)[] r;\n foreach (_; 0..n) {\n auto nrs = readln.splitter.map!(to!int).array;\n r ~= tuple(nrs[0], nrs[1]);\n }\n auto b = r.length.iota.array\n .multiSort!((x, y) => r[x][0] < r[y][0], (x,y) => r[x][1] > r[y][1]);\n \n debug { writeln (r); }\n debug { writeln (b); }\n \n int right = cast(int) b.front();\n auto ans = tuple(-1, -1);\n foreach (p; b.dropOne()) {\n debug { writeln(p); }\n if (r[p][1] <= r[right][1]) {\n ans = tuple(cast(int) p, right);\n break;\n } else {\n right = cast(int) p;\n }\n }\n \n if (ans[0] != -1) ans[0] += 1, ans[1] += 1;\n writeln (ans[0], ' ', ans[1]);\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; scanf(\"%d\", &n);\n struct P{int l, r;}\n auto seq=new P[](0);\n foreach(i; 0..n){\n int a, b; scanf(\"%d %d\", &a, &b);\n seq~=P(a, b);\n }\n \n struct LRi{int l, r, id;}\n auto lri=new LRi[](0);\n foreach(i; 0..n) lri~=LRi(seq[i].l, seq[i].r, i);\n sort!((a, b)=>(a.l==b.l ? a.r>b.r : a.l<b.l))(lri);\n struct Ri{int r, id;}\n import std.container;\n auto tree=new RedBlackTree!(Ri, \"a.r==b.r ? a.id<b.id : a.r<b.r\", true);\n foreach(i; 0..n) tree.insert(Ri(seq[i].r, i));\n foreach(elem; lri){\n // writeln(elem.id, \" \", elem.l, \" \", elem.r);\n int id=elem.id, r=seq[id].r;\n // writeln(id, \" \", r);\n // writeln(tree);\n tree.removeKey(Ri(r, id));\n auto eq=tree.equalRange(Ri(r, -1));\n if((eq.empty)==false){\n writeln(-1, \" \", -1); return;\n writeln(eq.front.id+1, \" \", id+1);\n goto heaven;\n }else{\n auto lb=tree.lowerBound(Ri(r, 1_000_000_000));\n if(lb.empty) continue;\n writeln(lb.back.id+1, \" \", id+1);\n goto heaven;\n }\n }\n\n writeln(-1, \" \", -1);\n heaven:;\n}\n\n// rbt.equalRange(elem) \u306e\u6319\u52d5\uff1f\n\n\nvoid rd(Type...)(ref Type x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; scanf(\"%d\", &n);\n struct P{int l, r;}\n auto seq=new P[](0);\n foreach(i; 0..n){\n int a, b; scanf(\"%d %d\", &a, &b);\n seq~=P(a, b);\n }\n \n struct LRi{int l, r, id;}\n auto lri=new LRi[](0);\n foreach(i; 0..n) lri~=LRi(seq[i].l, seq[i].r, i);\n sort!((a, b)=>(a.l==b.l ? a.r>b.r : a.l<b.l))(lri);\n struct Ri{int r, id;}\n import std.container;\n auto tree=new RedBlackTree!(Ri, \"a.r==b.r ? a.id<b.id : a.r<b.r\", true);\n foreach(i; 0..n) tree.insert(Ri(seq[i].r, i));\n foreach(elem; lri){\n int id=elem.id, r=seq[id].r;\n tree.removeKey(Ri(r, id));\n auto lb=tree.lowerBound(Ri(r, 1_000_000_000));\n if((lb.empty)==false){\n writeln(lb.back.id+1, \" \", id+1);\n goto heaven;\n }\n }\n\n writeln(-1, \" \", -1);\n heaven:;\n} \n\nvoid rd(Type...)(ref Type x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; scanf(\"%d\", &n);\n struct P{int l, r;}\n auto seq=new P[](0);\n foreach(i; 0..n){\n int a, b; scanf(\"%d %d\", &a, &b);\n seq~=P(a, b);\n }\n \n struct LRi{int l, r, id;}\n auto lri=new LRi[](0);\n foreach(i; 0..n) lri~=LRi(seq[i].l, seq[i].r, i);\n sort!((a, b)=>(a.l==b.l ? a.r>b.r : a.l<b.l))(lri);\n struct Ri{int r, id;}\n import std.container;\n auto tree=new RedBlackTree!(Ri, \"a.r==b.r ? a.id<b.id : a.r<b.r\", true);\n foreach(i; 0..n) tree.insert(Ri(seq[i].r, i));\n foreach(elem; lri){\n // writeln(elem.id, \" \", elem.l, \" \", elem.r);\n int id=elem.id, r=seq[id].r;\n // writeln(id, \" \", r);\n // writeln(tree);\n tree.removeKey(Ri(r, id));\n auto eq=tree.equalRange(Ri(r, -1));\n if((eq.empty)==false){\n writeln(eq.front.id+1, \" \", id+1);\n goto heaven;\n }else{\n auto lb=tree.lowerBound(Ri(r, 1_000_000_000));\n if(lb.empty) continue;\n writeln(lb.back.id+1, \" \", id+1);\n goto heaven;\n }\n }\n\n writeln(-1, \" \", -1);\n heaven:;\n}\n\nvoid rd(Type...)(ref Type x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new Tuple!(int, int)[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!int);\n A[i] = tuple(s[0], s[1]);\n }\n\n Tuple!(int, int)[int] B;\n foreach (i, a; A.enumerate) {\n if (a[0] in B && B[a[0]][0] == a[1]) {\n writeln(i + 1, \" \", B[a[0]][1]);\n return;\n }\n if (a[0] in B) B[a[0]] = min(B[a[0]], tuple(a[1], (i+1).to!int));\n else B[a[0]] = tuple(a[1], (i+1).to!int);\n }\n\n auto K = B.keys.dup;\n K.sort!\"a > b\"();\n Tuple!(int, int) minv = B[K[0]];\n\n foreach (i; 1..K.length) {\n if (B[K[i]][0] >= minv[0]) {\n writeln(minv[1], \" \", B[K[i]][1]);\n return;\n }\n minv = min(minv, B[K[i]]);\n }\n\n writeln(-1, \" \", -1);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new Tuple!(int, int)[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!int);\n A[i] = tuple(s[0], s[1]);\n }\n\n Tuple!(int, int)[][int] B;\n foreach (i, a; A.enumerate)\n B[a[0]] ~= tuple(a[1], (i+1).to!int);\n\n foreach (k; B.keys)\n B[k].sort();\n\n foreach (k; B.keys)\n foreach (i; 0..B[k].length.to!int-1)\n if (B[k][i][0] == B[k][i+1][0]) {\n writeln(B[k][i][1], \" \", B[k][i+1][1]);\n return;\n }\n\n auto K = B.keys.dup;\n K.sort!\"a > b\"();\n Tuple!(int, int) minv = B[K[0]].front;\n\n foreach (i; 1..K.length) {\n if (B[K[i]].back[0] >= minv[0]) {\n writeln(minv[1], \" \", B[K[i]].front[1]);\n return;\n }\n minv = min(minv, B[K[i]].back);\n }\n\n writeln(-1, \" \", -1);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new Tuple!(int, int)[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!int);\n A[i] = tuple(s[0], s[1]);\n }\n\n Tuple!(int, int)[][int] B;\n foreach (i, a; A.enumerate)\n B[a[0]] ~= tuple(a[1], (i+1).to!int);\n\n foreach (k; B.keys)\n B[k].sort();\n\n foreach (k; B.keys)\n foreach (i; 0..B[k].length.to!int-1)\n if (B[k][i][0] == B[k][i+1][0]) {\n writeln(B[k][i][1], \" \", B[k][i+1][1]);\n return;\n }\n\n auto K = B.keys.dup;\n K.sort!\"a > b\"();\n Tuple!(int, int) minv = B[K[0]].front;\n\n foreach (i; 1..K.length) {\n if (B[K[i]].back[0] >= minv[0]) {\n writeln(minv[1], \" \", B[K[i]].back[1]);\n return;\n }\n minv = min(minv, B[K[i]].front);\n }\n\n writeln(-1, \" \", -1);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto sc = new Scanner(stdin);\n\n int N; sc.read(N);\n auto A = new Tuple!(int, int)[](N);\n foreach (i; 0..N) {\n int a, b; sc.read(a); sc.read(b);\n A[i] = tuple(a-1, b-1);\n }\n\n Tuple!(int, int)[][int] B;\n foreach (i, a; A.enumerate)\n B[a[0]] ~= tuple(a[1], (i+1).to!int);\n\n foreach (k; B.keys)\n B[k].sort();\n\n foreach (k; B.keys)\n foreach (i; 0..B[k].length.to!int-1)\n if (B[k][i][0] == B[k][i+1][0]) {\n writeln(B[k][i][1], \" \", B[k][i+1][1]);\n return;\n }\n\n auto K = B.keys.dup;\n K.sort!\"a > b\"();\n Tuple!(int, int) minv = B[K[0]].front;\n\n foreach (i; 1..K.length) {\n if (B[K[i]].back[0] >= minv[0]) {\n writeln(minv[1], \" \", B[K[i]].back[1]);\n return;\n }\n minv = min(minv, B[K[i]].front);\n }\n\n writeln(-1, \" \", -1);\n}\n\nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray;\n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n\n\n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n\n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n"}, {"source_code": "import std.algorithm.sorting;\nimport std.conv;\nimport std.stdio;\nimport std.typecons;\n\nvoid main()\n{\n uint n;\n readf!\"%d\\n\"(n);\n\n Tuple!(uint, uint)[] x;\n\n foreach (i; 0..n) {\n uint a, b;\n \n readf!\"%d %d\\n\"(a, b);\n\n x ~= tuple(a, b);\n }\n\n x.sort!((a, b) => (a[0] == b[0]) ? (b[0] > a[0]) : (a[0] < b[0]));\n\n // current max\n auto m = x[0][1];\n auto mi = 1;\n\n foreach (i; 1..n) {\n if (x[i][0] <= m && x[i][1] <= m) {\n writefln(\"%d %d\", i+1, mi);\n return;\n }\n\n if (x[i][1] > m) {\n m = x[i][1];\n mi = i+1;\n }\n }\n writeln(\"-1 -1\");\n}\n"}, {"source_code": "import std.algorithm.sorting;\nimport std.conv;\nimport std.stdio;\nimport std.typecons;\n\nvoid main()\n{\n uint n;\n readf!\"%d\\n\"(n);\n\n Tuple!(uint, uint, uint)[] x;\n\n foreach (i; 0..n) {\n uint a, b;\n \n readf!\"%d %d\\n\"(a, b);\n\n x ~= tuple(a, b, i+1);\n }\n\n x.sort!((a, b) => (a[0] == b[0]) ? (b[0] > a[0]) : (a[0] < b[0]));\n\n // current max\n auto m = x[0][1];\n auto mi = x[0][2];\n\n foreach (i; 1..n) {\n if (x[i][0] <= m && x[i][1] <= m) {\n writefln(\"%d %d\", x[i][2], mi);\n return;\n }\n\n if (x[i][1] > m) {\n m = x[i][1];\n mi = x[i][2];\n }\n }\n writeln(\"-1 -1\");\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf (\"%s\", &n);\n readln;\n Tuple!(int, int)[] a;\n foreach (_; 0..n) {\n auto nrs = readln.splitter.map!(to!int).array;\n a ~= tuple(nrs[0], nrs[1]);\n }\n \n debug { writeln (a); }\n \n a.multiSort!(q{ a[0] < b[0] }, q{ a[1] > b[1] });\n \n debug { writeln (a); }\n \n int right = 0;\n auto ans = tuple(-1, -1);\n foreach (int i, e; a.dropOne()) {\n debug { writeln(e); }\n if (e[1] <= a[right][1]) {\n ans = tuple(right, i);\n break;\n } else {\n right = i;\n }\n }\n \n writeln (ans[0], ' ', ans[1]);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf (\"%s\", &n);\n readln;\n Tuple!(int, int)[] r;\n foreach (_; 0..n) {\n auto nrs = readln.splitter.map!(to!int).array;\n r ~= tuple(nrs[0], nrs[1]);\n }\n auto b = r.length.iota.array;\n \n debug { writeln (r); }\n \n b.multiSort!((x, y) => r[x][0] < r[y][0], (x,y) => r[x][1] > r[y][1]);\n \n debug { writeln (b); }\n \n int right = 0;\n auto ans = tuple(-1, -1);\n foreach (p; b.dropOne()) {\n debug { writeln(p); }\n auto e = r[p];\n if (e[1] <= r[right][1]) {\n ans = tuple(cast(int) p, right);\n break;\n } else {\n right = cast(int) p;\n }\n }\n \n if (ans[0] != -1) ans[0] += 1, ans[1] += 1;\n writeln (ans[0], ' ', ans[1]);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf (\"%s\", &n);\n readln;\n Tuple!(int, int)[] a;\n foreach (_; 0..n) {\n auto nrs = readln.splitter.map!(to!int).array;\n a ~= tuple(nrs[0], nrs[1]);\n }\n \n debug { writeln (a); }\n \n a.multiSort!(q{ a[0] < b[0] }, q{ a[1] > b[1] });\n \n debug { writeln (a); }\n \n int right = 0;\n auto ans = tuple(-1, -1);\n foreach (int i, e; a.dropOne().enumerate(1)) {\n debug { writeln(e); }\n if (e[1] <= a[right][1]) {\n ans = tuple(right, i);\n break;\n } else {\n right = i;\n }\n }\n \n if (ans[0] != -1) ans[0] += 1, ans[1] += 1;\n writeln (ans[0], ' ', ans[1]);\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; scanf(\"%d\", &n);\n struct P{int l, r;}\n auto seq=new P[](0);\n foreach(i; 0..n){\n int a, b; scanf(\"%d %d\", &a, &b);\n seq~=P(a, b);\n }\n \n struct LRi{int l, r, id;}\n auto lri=new LRi[](0);\n foreach(i; 0..n) lri~=LRi(seq[i].l, seq[i].r, i);\n sort!((a, b)=>(a.l==b.l ? a.r>b.r : a.l<b.l))(lri);\n struct Ri{int r, id;}\n import std.container;\n auto tree=new RedBlackTree!(Ri, \"a.r==b.r ? a.id<b.id : a.r<b.r\", true);\n foreach(i; 0..n) tree.insert(Ri(seq[i].r, i));\n foreach(elem; lri){\n int id=elem.id, r=seq[id].r;\n auto lb=tree.lowerBound(Ri(r, 1_000_000_000));\n if((lb.empty)==false){\n writeln(lb.back.id+1, \" \", id+1);\n goto heaven;\n }\n }\n\n writeln(-1, \" \", -1);\n heaven:;\n}\n\nvoid rd(Type...)(ref Type x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; scanf(\"%d\", &n);\n struct P{int l, r;}\n auto seq=new P[](n);\n foreach(i; 0..n){\n int a, b; scanf(\"%d %d\", &a, &b);\n seq[i]=P(a, b);\n }\n\n struct T{int x, idx;}\n import std.container;\n auto tree=new RedBlackTree!(T, \"a.x<b.x\", true);\n foreach(i; 0..n) tree.insert(T(seq[i].r, i));\n auto y=new T[](n);\n foreach(i; 0..n) y[i]=T(seq[i].l, i);\n sort!\"a.x<b.x\"(y);\n foreach(i; 0..n){\n // writeln(i);\n int id=y[i].idx;\n auto lb=tree.lowerBound(T(seq[id].r, id));\n if(lb.empty==false){\n writeln(lb.front.idx+1, \" \", id+1);\n goto heaven;\n }else{\n auto eq=tree.equalRange(T(seq[id].r, id));\n if((eq.front==eq.back)==false){\n int j1=eq.front.idx.to!int, j2=eq.back.idx.to!(int);\n if(i!=j1){\n writeln(j1+1, \" \", id+1);\n }else if(i!=j2){\n writeln(j2+1, \" \", id+1);\n }\n goto heaven;\n }\n }\n // writeln(\"re\");\n tree.removeKey(T(seq[y[i].idx].r, y[i].idx));\n }\n writeln(-1, \" \", -1);\n\n heaven:;\n // writeln(tree);\n}\n\nvoid rd(Type...)(ref Type x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; scanf(\"%d\", &n);\n struct P{int l, r;}\n auto seq=new P[](0);\n foreach(i; 0..n){\n int a, b; scanf(\"%d %d\", &a, &b);\n seq~=P(a, b);\n }\n \n struct LRi{int l, r, id;}\n auto lri=new LRi[](0);\n foreach(i; 0..n) lri~=LRi(seq[i].l, seq[i].r, i);\n sort!((a, b)=>(a.l==b.l ? a.r>b.r : a.l<b.l))(lri);\n struct Ri{int r, id;}\n import std.container;\n auto tree=new RedBlackTree!(Ri, \"a.r<b.r\");\n foreach(i; 0..n) tree.insert(Ri(seq[i].r, i));\n foreach(elem; lri){\n int id=elem.id, r=seq[id].r;\n tree.removeKey(Ri(r, id));\n auto eq=tree.equalRange(Ri(r, -1));\n if((eq.empty)==false){\n writeln(eq.front.id+1, \" \", id+1);\n goto heaven;\n }else{\n auto lb=tree.lowerBound(Ri(r, -1));\n if(lb.empty) continue;\n writeln(lb.back.id+1, \" \", id+1);\n goto heaven;\n }\n }\n\n writeln(-1, \" \", -1);\n heaven:;\n}\n\nvoid rd(Type...)(ref Type x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; scanf(\"%d\", &n);\n struct P{int l, r;}\n auto seq=new P[](0);\n foreach(i; 0..n){\n int a, b; scanf(\"%d %d\", &a, &b);\n seq~=P(a, b);\n }\n \n struct LRi{int l, r, id;}\n auto lri=new LRi[](0);\n foreach(i; 0..n) lri~=LRi(seq[i].l, seq[i].r, i);\n sort!((a, b)=>(a.l==b.l ? a.r>b.r : a.l<b.l))(lri);\n struct Ri{int r, id;}\n import std.container;\n auto tree=new RedBlackTree!(Ri, \"a.r<b.r\", true);\n foreach(i; 0..n) tree.insert(Ri(seq[i].r, i));\n foreach(elem; lri){\n int id=elem.id, r=seq[id].r;\n tree.removeKey(Ri(r, id));\n auto eq=tree.equalRange(Ri(r, -1));\n if((eq.empty)==false){\n writeln(eq.front.id+1, \" \", id+1);\n goto heaven;\n }else{\n auto lb=tree.lowerBound(Ri(r, -1));\n if(lb.empty) continue;\n writeln(lb.back.id+1, \" \", id+1);\n goto heaven;\n }\n }\n\n writeln(-1, \" \", -1);\n heaven:;\n}\n\nvoid rd(Type...)(ref Type x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; scanf(\"%d\", &n);\n struct P{int l, r;}\n auto seq=new P[](n);\n foreach(i; 0..n){\n int a, b; scanf(\"%d %d\", &a, &b);\n seq[i]=P(a, b);\n }\n\n struct T{int x, idx;}\n import std.container;\n auto tree=new RedBlackTree!(T, \"a.x<b.x\", true);\n foreach(i; 0..n) tree.insert(T(seq[i].r, i));\n auto y=new T[](n);\n foreach(i; 0..n) y[i]=T(seq[i].l, i);\n sort!\"a.x<b.x\"(y);\n foreach(i; 0..n){\n // writeln(i);\n int id=y[i].idx;\n auto lb=tree.lowerBound(T(seq[id].r, id));\n if(lb.empty==false){\n writeln(id+1, \" \", lb.front.idx+1);\n goto heaven;\n }else{\n auto eq=tree.equalRange(T(seq[id].r, id));\n if((eq.front==eq.back)==false){\n int j1=eq.front.idx.to!int, j2=eq.back.idx.to!(int);\n if(i!=j1){\n writeln(id+1, \" \", j1+1);\n }else if(i!=j2){\n writeln(id+1, \" \", j2+1);\n }\n goto heaven;\n }\n }\n // writeln(\"re\");\n tree.removeKey(T(seq[y[i].idx].r, y[i].idx));\n }\n writeln(-1, \" \", -1);\n\n heaven:;\n // writeln(tree);\n}\n\nvoid rd(Type...)(ref Type x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "src_uid": "0148aed9b07c4f65b2507fcb8b837360"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint solve (int n)\n{\n\tif (n == 1)\n\t{\n\t\treturn 0;\n\t}\n\telse if (n % 3 != 0)\n\t{\n\t\treturn -1;\n\t}\n\telse if (n % 2 != 0)\n\t{\n\t\tint res = solve (n * 2);\n\t\treturn (res == -1) ? -1 : res + 1;\n\t}\n\telse\n\t{\n\t\tint res = solve (n / 6);\n\t\treturn (res == -1) ? -1 : res + 1;\n\t}\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\treadln.strip.to !(int).solve.writeln;\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n uint t, n, twos, threes;\n\n scanf(\"%d\", &t);\n while(t--) {\n int ans;\n scanf(\"%d\", &n);\n\n twos = 0;\n while(n % 2 ==0) {\n twos++;\n n /= 2;\n }\n\n threes = 0;\n while(n % 3 == 0) {\n threes++;\n n /= 3;\n }\n\n if(n != 1 || twos > threes) ans = -1;\n else if (twos == threes) ans = twos;\n else ans = twos + (threes - twos) * 2;\n\n\n printf(\"%d\\n\", ans);\n }\n\n\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n long n;\n readf!\"%d\\n\"(n);\n\n auto s = 0;\n // remove as many factors of 6 as possible\n while (n % 6 == 0) {\n n /= 6;\n s += 1;\n }\n\n while (n % 3 == 0) {\n n /= 3;\n s += 2; // multiply, then divide\n }\n\n if (n == 1) {\n writeln(s);\n } else {\n writeln(-1);\n }\n }\n}"}], "negative_code": [], "src_uid": "3ae468c425c7b156983414372fd35ab8"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto S = readln.chomp;\n int max_l, l;\n foreach (c; S) {\n if (c == 'L') {\n l += 1;\n max_l = max(l, max_l);\n } else {\n l = 0;\n }\n }\n writeln(max_l + 1);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\t\tauto n = cast(int)s.length;\n\t\tbool f(int d)\n\t\t{\n\t\t\tint[] open = [0, d-1];\n\t\t\tauto used = new bool[](n+1);\n\t\t\twhile (!open.empty)\n\t\t\t{\n\t\t\t\tauto pos = open.front; open.popFront;\n\t\t\t\tif (pos == n) return true;\n\t\t\t\tint nPos1, nPos2;\n\t\t\t\tif (s[pos] == 'L')\n\t\t\t\t{\n\t\t\t\t\tnPos1 = max(0, pos-1);\n\t\t\t\t\tnPos2 = max(0, pos-d);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tnPos1 = min(n, pos+1);\n\t\t\t\t\tnPos2 = min(n, pos+d);\n\t\t\t\t}\n\t\t\t\tif (used[nPos1] == false)\n\t\t\t\t{\n\t\t\t\t\topen ~= nPos1;\n\t\t\t\t\tused[nPos1] = true;\n\t\t\t\t}\n\t\t\t\tif (used[nPos2] == false)\n\t\t\t\t{\n\t\t\t\t\topen ~= nPos2;\n\t\t\t\t\tused[nPos2] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tans[ti] = binarySearch!(f)(n+1, 0);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "6451507b21854d5b81aeaf0491ddf584"} {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main(){\n int n, m;\n readVars(n, m);\n\n int z;\n auto uf = new UnionFind(m + 1);\n auto exist = new bool[](m + 1);\n\n foreach(i ; 0 .. n){\n auto line = readln.split.to!(int[]);\n if(line[0] == 0){\n z++;\n }\n else{\n foreach(j ; 1 .. line.length){\n exist[line[j]] = true;\n\n if(j > 1){\n uf.unite(line[j], line[j - 1]);\n }\n }\n }\n }\n\n if(z == n){\n writeln(n);\n return;\n }\n\n auto rbt = redBlackTree!int;\n\n foreach(i ; 1 .. m + 1){\n if (exist[i]) {\n rbt.insert(uf.find_root(i));\n }\n }\n\n auto ans = rbt.length.to!int + z - 1;\n\n writeln(ans);\n}\n\nclass UnionFind {\nprivate:\n int[] p;\n int[] rank;\n\npublic:\n this(int N){\n p = iota(N).array;\n rank = new int[](N);\n }\n\n int find_root(int x){\n if(x != p[x]){\n p[x] = find_root(p[x]);\n }\n\n return p[x];\n }\n\n bool same(int x, int y){\n return find_root(x) == find_root(y);\n }\n\n void unite(int x, int y){\n x = find_root(x);\n y = find_root(y);\n\n if(x == y) return;\n\n if(rank[x] < rank[y]){\n p[x] = y;\n }\n else {\n p[y] = x;\n\n if(rank[x] == rank[y]) rank[x]++;\n }\n }\n}\n\n\nvoid readVars(T...)(auto ref T args){\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int MAX_N = 205;\n\nbool [MAX_N] [MAX_N] a;\nbool [MAX_N] b;\nint n, m;\n\nvoid recur (int v)\n{\n\tif (b[v])\n\t{\n\t\treturn;\n\t}\n\tb[v] = true;\n\tforeach (i; 0..n + m)\n\t{\n\t\tif (a[v][i])\n\t\t{\n\t\t\trecur (i);\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tforeach (i; 0..n + m)\n\t\t{\n\t\t\tforeach (j; 0..n + m)\n\t\t\t{\n\t\t\t\ta[i][j] = false;\n\t\t\t}\n\t\t}\n\t\tbool ok = false;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint k;\n\t\t\treadf (\" %s\", &k);\n\t\t\tforeach (j; 0..k)\n\t\t\t{\n\t\t\t\tint p;\n\t\t\t\treadf (\" %s\", &p);\n\t\t\t\tp--;\n\t\t\t\ta[i][n + p] = true;\n\t\t\t\ta[n + p][i] = true;\n\t\t\t\tok = true;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..n + m)\n\t\t{\n\t\t\tb[i] = false;\n\t\t}\n\t\tint res = !ok;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (!b[i])\n\t\t\t{\n\t\t\t\trecur (i);\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t\tres--;\n\t\twritefln (\"%s\", res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\nimport std.c.stdio;\n\nvoid main() {\n int n, m; readf(\"%d %d\\n\", &n, &m);\n bool[][] F = new bool[][n];\n foreach (ref L; F) L = new bool[m];\n for (int i = 0; i < n; i++) {\n int c; scanf(\"%d \", &c);\n for (int j = 0; j < c; j++) {\n int l; scanf(\"%d\", &l);\n l--;\n F[i][l] = true;\n }\n }\n bool[] U = new bool[n];\n int c = 0;\n void dfs(int v) {\n if (U[v]) return;\n U[v] = true;\n for (int i = 0; i < m; i++) {\n if (F[v][i]) {\n for (int j = 0; j < n; j++) {\n if (F[j][i]) {\n dfs(j);\n }\n }\n }\n }\n }\n for (int i = 0; i < n; i++) {\n if (U[i]) continue;\n c++;\n dfs(i);\n }\n int f = 0;\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++) \n if (F[i][j]) \n f = 1; \n writeln(c-f);\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int MAX_N = 205;\n\nbool [MAX_N] [MAX_N] a;\nbool [MAX_N] b;\nint n, m;\n\nvoid recur (int v)\n{\n\tif (b[v])\n\t{\n\t\treturn;\n\t}\n\tb[v] = true;\n\tforeach (i; 0..n + m)\n\t{\n\t\tif (a[v][i])\n\t\t{\n\t\t\trecur (i);\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t foreach (i; 0..n + m)\n\t {\n\t \tforeach (j; 0..n + m)\n\t \t{\n\t \t\ta[i][j] = false;\n\t \t}\n\t }\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint k;\n\t\t\treadf (\" %s\", &k);\n\t\t\tforeach (j; 0..k)\n\t\t\t{\n\t\t\t\tint p;\n\t\t\t\treadf (\" %s\", &p);\n\t\t\t\tp--;\n\t\t\t\ta[i][n + p] = true;\n\t\t\t\ta[n + p][i] = true;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..n + m)\n\t\t{\n\t\t\tb[i] = false;\n\t\t}\n\t\tint res;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (!b[i])\n\t\t\t{\n\t\t\t\trecur (i);\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t\tres--;\n\t\twritefln (\"%s\", res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main(){\n int n, m;\n readVars(n, m);\n\n int z;\n auto uf = new UnionFind(m + 1);\n auto exist = new bool[](m + 1);\n\n foreach(i ; 0 .. n){\n auto line = readln.split.to!(int[]);\n if(line[0] == 0){\n z++;\n }\n else{\n foreach(j ; 1 .. line.length){\n exist[line[j]] = true;\n\n if(j > 1){\n uf.unite(line[j], line[j - 1]);\n }\n }\n }\n }\n\n auto rbt = redBlackTree!int;\n\n foreach(i ; 1 .. m + 1){\n if (exist[i]) {\n rbt.insert(uf.find_root(i));\n }\n }\n\n auto ans = rbt.length.to!int + z - 1;\n\n writeln(ans);\n}\n\nclass UnionFind {\nprivate:\n int[] p;\n int[] rank;\n\npublic:\n this(int N){\n p = iota(N).array;\n rank = new int[](N);\n }\n\n int find_root(int x){\n if(x != p[x]){\n p[x] = find_root(p[x]);\n }\n\n return p[x];\n }\n\n bool same(int x, int y){\n return find_root(x) == find_root(y);\n }\n\n void unite(int x, int y){\n x = find_root(x);\n y = find_root(y);\n\n if(x == y) return;\n\n if(rank[x] < rank[y]){\n p[x] = y;\n }\n else {\n p[y] = x;\n\n if(rank[x] == rank[y]) rank[x]++;\n }\n }\n}\n\n\nvoid readVars(T...)(auto ref T args){\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid main() {\n int n, m; readf(\"%d %d\\n\", &n, &m);\n bool[][] F = new bool[][n];\n foreach (ref L; F) L = new bool[m];\n for (int i = 0; i < n; i++) {\n int c; readf(\"%d \", &c);\n int[] ls = stdin.readln.split.map!(function int(x){return x.to!int - 1;}).array;\n foreach (l; ls) {\n F[i][l] = true;\n }\n }\n bool[] U = new bool[n];\n int c = 0;\n void dfs(int v) {\n if (U[v]) return;\n U[v] = true;\n for (int i = 0; i < m; i++) {\n if (F[v][i]) {\n for (int j = 0; j < n; j++) {\n if (F[j][i]) {\n dfs(j);\n }\n }\n }\n }\n }\n for (int i = 0; i < n; i++) {\n if (U[i]) continue;\n c++;\n dfs(i);\n }\n writeln(c-1);\n}\n"}], "src_uid": "e2836276aee2459979b232e5b29e6d57"} {"source_code": "import core.bitop;\r\nimport std.algorithm;\r\nimport std.conv;\r\nimport std.numeric;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int mod = 998_244_353;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tint res = 1;\r\n\t\tint cur = 0;\r\n\t\tforeach (ref next; a)\r\n\t\t{\r\n\t\t\tif (cur % next != 0)\r\n\t\t\t{\r\n\t\t\t\tres = 0;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tint num;\r\n\t\t\tif (cur == 0)\r\n\t\t\t{\r\n\t\t\t\tnum = 1;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\tif (cur == next || cur == 0)\r\n\t\t\t{\r\n\t\t\t\tnum = m / next;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint s = cur / next;\r\n\t\t\t\tint [] p;\r\n\t\t\t\tfor (int d = 2; d * d <= s; d++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s % d == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tp ~= d;\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ts /= d;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\twhile (s % d == 0);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (s > 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tp ~= s;\r\n\t\t\t\t}\r\n\t\t\t\tdebug {writeln (\"p = \", p);}\r\n\r\n\t\t\t\tnum = 0;\r\n\t\t\t\tauto len = p.length.to !(int);\r\n\t\t\t\tforeach (u; 0..(1 << len))\r\n\t\t\t\t{\r\n\t\t\t\t\tint e = 1;\r\n\t\t\t\t\tforeach (i; 0..len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (u & (1 << i))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\te *= -p[i];\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnum += m / (next * e);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tdebug {writeln (\"num = \", num);}\r\n\t\t\tres = (res * 1L * num) % mod;\r\n\t\t\tcur = next;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import core.bitop;\r\nimport std.algorithm;\r\nimport std.conv;\r\nimport std.numeric;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int mod = 998_244_353;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tint res = 1;\r\n\t\tint cur = 0;\r\n\t\tforeach (ref next; a)\r\n\t\t{\r\n\t\t\tif (cur % next != 0)\r\n\t\t\t{\r\n\t\t\t\tres = 0;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tint num;\r\n\t\t\tif (cur == 0)\r\n\t\t\t{\r\n\t\t\t\tnum = 1;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\tif (cur == next || cur == 0)\r\n\t\t\t{\r\n\t\t\t\tnum = m / next;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint s = cur / next;\r\n\t\t\t\tint [] p;\r\n\t\t\t\tfor (int d = 2; d * d <= s; d++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s % d == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tp ~= d;\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ts /= d;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\twhile (s % d == 0);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (s > 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tp ~= s;\r\n\t\t\t\t}\r\n\t\t\t\tdebug {writeln (\"p = \", p);}\r\n\r\n\t\t\t\tnum = 0;\r\n\t\t\t\tauto len = p.length.to !(int);\r\n\t\t\t\tforeach (u; 0..(1 << len))\r\n\t\t\t\t{\r\n\t\t\t\t\tint e = 1;\r\n\t\t\t\t\tforeach (i; 0..len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (u & (1 << i))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\te *= -p[i];\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnum += m / (next * e);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tdebug {writeln (\"num = \", num);}\r\n\t\t\tres = (res * 1L * num) % mod;\r\n\t\t\tcur = next;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "116dd636a4f2547aef01a68f98c46ca2"} {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nint n;\n\nvoid main() {\n scan(n);\n\n auto bh = new BinaryHeap!(Array!int, \"a > b\")();\n\n int ans;\n int nn = 1;\n int b = 0;\n\n foreach (i ; 0 .. 2*n) {\n auto line = readln.split;\n\n if (line[0] == \"add\") {\n int x = line[1].to!int;\n\n if (!bh.empty && x > bh.front) {\n b = bh.front;\n }\n\n bh.insert(x);\n }\n else {\n debug {\n writeln(\"next:\", nn);\n writeln(\"b:\", b);\n writeln(\"top:\", bh.front);\n writeln;\n }\n if (nn == b) {\n ans++;\n b = 0;\n }\n\n bh.popFront();\n nn++;\n }\n }\n\n writeln(ans);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^7;\nint n;\n\nvoid main() {\n scan(n);\n\n auto st = Stack!int(n);\n int ans, nn = 1;\n\n foreach (i ; 0 .. 2*n) {\n auto line = readln.split;\n\n if (line[0] == \"add\") {\n int x = line[1].to!int;\n st.push(x);\n }\n else {\n if (!st.empty && st.top != nn) {\n debug {\n writeln(\"nn:\", nn);\n }\n ans++;\n st.clear();\n }\n else if (!st.empty) {\n st.pop();\n }\n\n nn++;\n }\n }\n\n writeln(ans);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\nstruct Stack(T) {\nprivate:\n int N, peek;\n T[] data;\n\npublic:\n this(int size) \n {\n N = size;\n data = new T[](N);\n }\n\n bool empty() @property\n {\n return peek == 0;\n }\n\n bool full() @property\n {\n return peek == N;\n }\n\n void push(T x) @property\n {\n assert(!full);\n data[peek++] = x;\n }\n\n void pop() @property\n {\n assert(!empty);\n --peek;\n }\n\n T top() @property\n {\n return data[peek - 1];\n }\n\n void clear() @property\n {\n peek = 0;\n }\n\n int length() @property\n {\n return peek;\n }\n\n}"}], "negative_code": [], "src_uid": "2535fc09ce74b829c26e1ebfc1ee17c6"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto H = new long[N];\n foreach (i; 0 .. N) {\n H[i] = readLong();\n }\n \n long val = H.sum;\n foreach (i; 0 .. N) {\n val -= i;\n }\n auto ans = new long[N];\n ans[] = val / N;\n ans[0 .. cast(int)(val % N)] += 1;\n foreach (i; 0 .. N) {\n ans[i] += i;\n }\n \n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln;\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto h = readln.splitter.map !(to !(long)).array;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\th[i] -= i;\n\t\t}\n\n\t\tlong total = h.sum;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint num = n - i;\n\t\t\tlong cur = (total + num - 1) / num;\n\t\t\tif (h[i] < cur)\n\t\t\t{\n\t\t\t\tlong delta = cur - h[i];\n\t\t\t\th[i] += delta;\n\t\t\t\th[i + 1] -= delta;\n\t\t\t}\n\t\t\ttotal -= h[i];\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\th[i] += i;\n\t\t}\n\t\twritefln !(\"%(%s %)\") (h);\n\t}\n}\n"}], "negative_code": [], "src_uid": "612884cad3d52cc952f2b49674e70a08"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array: Appender;\nimport std.datetime;\nimport std.algorithm;\n\nvoid main()\n{\n\n\tauto n = to!int(strip(readln));\n\tint[] r = new int[377];\n\tint[] c = new int[377];\n\tfor (auto i = 0; i < n; i++)\n\t{\n\t\tauto str = split(strip(readln));\n\t\tforeach (num; to!int(str[1])..to!int(str[2])+1)\n\t\t{\n\t\t\tif (str[0] == \"F\")\n\t\t\t\tr[num]++;\n\t\t\telse\n\t\t\t\tc[num]++;\n\t\t}\n\t}\n\tint count;\n\tforeach (i, ele; r)\n\t{\n\t\tcount = max(min(r[i], c[i]), count);\n\t}\n\twriteln(2 * count);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main()\n{\n\tint n;\n\t\n\tscanf(\"%d\", &n);\n\t\n\tbool[] used = new bool[n];\n\tchar[] gender = new char[n];\n\tint[] from = new int[n];\n\tint[] to = new int[n];\n\t\n\tfor (int i = 0; i < n; i++) {\n\t\tchar[10] s;\n\t\tscanf(\"%s%d%d\", s.ptr, &from[i], &to[i]);\n\t\tgender[i] = s[0];\n\t}\n\t\n\tint res = 0;\n\t\n\tfor (int i = 1; i <= 366; i++) {\n\t\tchar[2] genders = ['F', 'M'];\n\t\tint[2] found = [0, 0];\n\t\tfor (int j = 0; j < 2; j++) {\n\t\t\tfor (int k = 0; k < n; k++) {\n\t\t\t\tif (!used[k] && gender[k] == genders[j] && from[k] <= i && to[k] >= i) {\n\t\t\t\t\tfound[j]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tres = max(res, min(found[0], found[1]));\n\t}\n\t\n\tprintf(\"%d\\n\", 2 * res);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array: Appender;\nimport std.datetime;\nimport std.algorithm;\n\nvoid main()\n{\n\n\tauto n = to!int(strip(readln));\n\tint[] r = new int[377];\n\tint[] c = new int[377];\n\tfor (auto i = 0; i < n; i++)\n\t{\n\t\tauto str = split(strip(readln));\n\t\tforeach (num; to!int(str[1])..to!int(str[2]))\n\t\t{\n\t\t\tif (str[0] == \"F\")\n\t\t\t\tr[num]++;\n\t\t\telse\n\t\t\t\tc[num]++;\n\t\t}\n\t}\n\tint count;\n\tforeach (i, ele; r)\n\t{\n\t\tcount = max(min(r[i], c[i]), count);\n\t}\n\n\twriteln(2 * count);\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array: Appender;\nimport std.datetime;\nimport std.algorithm;\n\nvoid main()\n{\n\n\tauto n = to!int(strip(readln));\n\tint[] r = new int[377];\n\tint[] c = new int[377];\n\tfor (auto i = 0; i < n; i++)\n\t{\n\t\tauto str = split(strip(readln));\n\t\tforeach (num; to!int(str[1])..to!int(str[2]))\n\t\t{\n\t\t\tif (str[0] == \"F\")\n\t\t\t\tr[num]++;\n\t\t\telse\n\t\t\t\tc[num]++;\n\t\t}\n\t}\n\tint count;\n\tforeach (i, ele; r)\n\t{\n\t\tcount = max(min(r[i], c[i]), count);\n\t}\n\n\twriteln(count);\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array: Appender;\nimport std.datetime;\nimport std.algorithm;\n\nvoid main()\n{\n\n\tauto n = to!int(strip(readln));\n\tint[] r = new int[377];\n\tint[] c = new int[377];\n\tfor (auto i = 0; i < n; i++)\n\t{\n\t\tauto str = split(strip(readln));\n\t\tforeach (num; to!int(str[1])..to!int(str[2]))\n\t\t{\n\t\t\tif (str[0] == \"F\")\n\t\t\t\tr[num]++;\n\t\t\telse\n\t\t\t\tc[num]++;\n\t\t}\n\t}\n\tint count;\n\tforeach (i, ele; r)\n\t{\n\t\tcount = min(r[i], c[i]);\n\t}\n\n\twriteln(count);\n}\n"}], "src_uid": "75d500bad37fbd2c5456a942bde09cd3"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll n = scan;\n auto arr = scanArray;\n ll odd = 0;\n for(int i = 0; i < 2*n; ++i){\n if(arr[i] % 2 == 1){\n ++odd;\n }\n }\n if(odd == n){\n writeln(\"Yes\");\n }else{\n writeln(\"No\");\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1542/problem/A\n// math, implementation\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(to!int).array;\n int even = 0;\n int odd = 0;\n foreach(item; a) {\n if(item % 2 == 0) {\n even += 1;\n } else {\n odd += 1;\n }\n }\n if(even == odd) {\n \"Yes\".writeln;\n } else {\n \"No\".writeln;\n }\n}\n}\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n immutable(long) mod = 10 ^^ 9 + 7;\r\n while(tests--) {\r\n int n;\r\n readf!\"%s\\n\"(n);\r\n auto a = readln.splitter.map!(to!int).array;\r\n int odd = a.count!(x => x % 2 == 1);\r\n writeln([\"Yes\", \"No\"][odd != n]);\r\n }\r\n\r\n} // main\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array;\n auto b = a.filter!(x => x % 2 == 0).array;\n auto c = a.filter!(x => x % 2 == 1).array;\n if (b.length == c.length) {\n writeln(\"Yes\");\n } else {\n writeln(\"No\");\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tlong cnt;\r\n\t\tforeach (e; a)\r\n\t\t{\r\n\t\t\tif (e % 2)\r\n\t\t\t\t++cnt;\r\n\t\t}\r\n\r\n\t\tans[ti] = cnt == n;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"Yes\" : \"No\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "d5bd27c969d9cd910f13baa53c247871"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.utf;\r\n\r\nimmutable int limit = 128;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip.dup;\r\n\t\tauto t = readln.strip;\r\n\t\tint [limit] num;\r\n\t\tforeach (ref c; s)\r\n\t\t{\r\n\t\t\tnum[c] += 1;\r\n\t\t}\r\n\t\tauto p = limit.iota.array;\r\n\t\tif (t == \"abc\" && num['a'] && num['b'] && num['c'])\r\n\t\t{\r\n\t\t\tswap (p['b'], p['c']);\r\n\t\t}\r\n\t\tforeach (ref c; p)\r\n\t\t{\r\n\t\t\tforeach (i; 0..num[c])\r\n\t\t\t{\r\n\t\t\t\twrite (cast (char) (c));\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln;\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto s = cast(byte[])readString;\n auto t = cast(byte[])readString;\n auto ca = s.count!(c => c == 'a');\n auto cb = s.count!(c => c == 'b');\n auto cc = s.count!(c => c == 'c');\n sort(s);\n if (t != \"abc\") return writeln(cast(string)s);\n if (ca > 0 && cb > 0 && cc > 0)\n {\n s = s[ca + cb + cc .. $];\n foreach(i; 0 .. ca) write('a');\n foreach(i; 0 .. cc) write('c');\n foreach(i; 0 .. cb) write('b');\n }\n writeln(cast(string)s);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std;\n\nvoid\nprintSmallest (in int[dchar] frec) {\n foreach (dchar c; frec.keys.sort)\n write(c.repeat(frec[c]));\n writeln();\n}\n\nvoid main () {\n int tests;\n readf(\"%s\\n\", tests);\n foreach (i; 0 .. tests) {\n string s, t;\n s = readln()[0 .. $ - 1];\n t = readln()[0 .. $ - 1];\n\n int[dchar] frec;\n\n foreach (c; s)\n ++ frec[c];\n\n if (t == \"abc\" && 'a' in frec && 'b' in frec && 'c' in frec) {\n static foreach (c; \"acb\") {\n write(c.repeat(frec[c]));\n frec.remove(c);\n }\n }\n printSmallest(frec);\n }\n}\n\n//\"\"\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto S = RD!string;\r\n\t\tauto T = RD!string;\r\n\r\n\t\tauto cnt = new long[](26);\r\n\t\tforeach (c; S)\r\n\t\t\t++cnt[c-'a'];\r\n\r\n\t\tif (T == \"abc\")\r\n\t\t{\r\n\t\t\tif (cnt[0] == 0 || cnt[1] == 0 || cnt[2] == 0)\r\n\t\t\t{\r\n\t\t\t\tforeach (i; 0..26)\r\n\t\t\t\t\tforeach (_; 0..cnt[i])\r\n\t\t\t\t\t\tans[ti] ~= cast(char)('a'+i);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tforeach (_; 0..cnt[0])\r\n\t\t\t\t\tans[ti] ~= \"a\";\r\n\t\t\t\tforeach (_; 0..cnt[2])\r\n\t\t\t\t\tans[ti] ~= \"c\";\r\n\t\t\t\tforeach (_; 0..cnt[1])\r\n\t\t\t\t\tans[ti] ~= \"b\";\r\n\t\t\t\tforeach (i; 3..26)\r\n\t\t\t\t\tforeach (_; 0..cnt[i])\r\n\t\t\t\t\t\tans[ti] ~= cast(char)('a'+i);\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (i; 0..26)\r\n\t\t\t\tforeach (_; 0..cnt[i])\r\n\t\t\t\t\tans[ti] ~= cast(char)('a'+i);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto s = cast(byte[])readString;\n auto t = cast(byte[])readString;\n sort(s);\n if (t != \"abc\") return writeln(cast(string)s);\n foreach(i, si; s)\n if (s[i .. min($, i + 3)] == \"abc\")\n {\n\tswap(s[i + 1], s[i + 2]);\n }\n writeln(cast(string)s);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "419ef3579fe142c295ec4d89ee7becfc"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tint x = a[0];\n\t\tbool ok;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] != x)\n\t\t\t{\n\t\t\t\tok = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[ti] = ok ? 1 : n;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (a.minElement == a.maxElement ? n : 1);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n const ans = A.all!(a => (a == A[0])) ? N : 1;\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n auto set = redBlackTree!long(a);\n if (set.length > 1)\n return writeln(1);\n return writeln(a.length);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [], "src_uid": "7b80d3f3cd4f93e4277c76c76dc41f42"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\tauto adj = new int [] [n];\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tint u, v;\r\n\t\t\treadf !(\" %s %s\") (u, v);\r\n\t\t\tu -= 1;\r\n\t\t\tv -= 1;\r\n\t\t\tadj[u] ~= v;\r\n\t\t\tadj[v] ~= u;\r\n\t\t}\r\n\r\n\t\tauto vis = new bool [n];\r\n\t\tauto c = new int [n];\r\n\t\tc[] = -1;\r\n\r\n\t\tvoid recur (int v)\r\n\t\t{\r\n\t\t\tif (vis[v])\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tvis[v] = true;\r\n\t\t\tif (c[v] == -1)\r\n\t\t\t{\r\n\t\t\t\tc[v] = 0;\r\n\t\t\t\tforeach (u; adj[v])\r\n\t\t\t\t{\r\n\t\t\t\t\tc[u] = 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\trecur (u);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecur (0);\r\n\r\n\t\tif (vis.all)\r\n\t\t{\r\n\t\t\twriteln (\"YES\");\r\n\t\t\tauto answer = n.iota.filter !(i => c[i] == 0).array;\r\n\t\t\tanswer[] += 1;\r\n\t\t\twriteln (answer.length);\r\n\t\t\twritefln !(\"%(%s %)\") (answer);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln (\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto edges = new int[][](n);\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tauto u = RD!int-1;\r\n\t\t\tauto v = RD!int-1;\r\n\t\t\tedges[u] ~= v;\r\n\t\t\tedges[v] ~= u;\r\n\t\t}\r\n\r\n\t\tint[] q = [0];\r\n\t\tauto state = new int[](n);\r\n\t\tauto used = new bool[](n);\r\n\t\tused[0] = true;\r\n\t\twhile (!q.empty)\r\n\t\t{\r\n\t\t\tauto u = q.front; q.popFront;\r\n\t\t\tbool can = true;\r\n\t\t\tforeach (v; edges[u])\r\n\t\t\t{\r\n\t\t\t\tif (state[v] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tcan = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (can)\r\n\t\t\t\tstate[u] = 1;\r\n\t\t\telse\r\n\t\t\t\tstate[u] = 2;\r\n\t\t\tforeach (v; edges[u])\r\n\t\t\t{\r\n\t\t\t\tif (used[v]) continue;\r\n\t\t\t\tq ~= v;\r\n\t\t\t\tused[v] = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (state[i] == 0)\r\n\t\t\t{\r\n\t\t\t\tans[ti].length = 0;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\telse if (state[i] == 1)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tif (e.empty)\r\n\t\t\twriteln(\"NO\");\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln(\"YES\");\r\n\t\t\twriteln(e.length);\r\n\t\t\te.map!(to!string).join(\" \").writeln;\r\n\t\t}\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\tauto adj = new int [] [n];\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tint u, v;\r\n\t\t\treadf !(\" %s %s\") (u, v);\r\n\t\t\tu -= 1;\r\n\t\t\tv -= 1;\r\n\t\t\tadj[u] ~= v;\r\n\t\t\tadj[v] ~= u;\r\n\t\t}\r\n\r\n\t\tauto c = new int [n];\r\n\t\tc[] = -1;\r\n\r\n\t\tvoid recur (int v, int cur)\r\n\t\t{\r\n\t\t\tif (c[v] >= 0)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tc[v] = cur;\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\trecur (u, !cur);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecur (0, 0);\r\n\t\tdebug {writeln (c);}\r\n\r\n\t\tif (c.any !(q{a == -1}))\r\n\t\t{\r\n\t\t\twriteln (\"NO\");\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (v; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (c[v] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tforeach (u; adj[v])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (c[u] == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tc[v] = 2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twriteln (\"YES\");\r\n\t\t\tauto answer = n.iota.filter !(i => c[i] == 0).array;\r\n\t\t\tanswer[] += 1;\r\n\t\t\twriteln (answer.length);\r\n\t\t\twritefln !(\"%(%s %)\") (answer);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\tauto adj = new int [] [n];\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tint u, v;\r\n\t\t\treadf !(\" %s %s\") (u, v);\r\n\t\t\tu -= 1;\r\n\t\t\tv -= 1;\r\n\t\t\tadj[u] ~= v;\r\n\t\t\tadj[v] ~= u;\r\n\t\t}\r\n\r\n\t\tauto c = new int [n];\r\n\t\tc[] = -1;\r\n\r\n\t\tvoid recur (int v, int cur)\r\n\t\t{\r\n\t\t\tif (c[v] >= 0)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tc[v] = cur;\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\trecur (u, !cur);\r\n\t\t\t}\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\tif (c[u] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tc[v] = 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecur (0, 0);\r\n\t\tdebug {writeln (c);}\r\n\r\n\t\tif (c.any !(q{a == -1}))\r\n\t\t{\r\n\t\t\twriteln (\"NO\");\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln (\"YES\");\r\n\t\t\tauto answer = n.iota.filter !(i => c[i] == 0).array;\r\n\t\t\tanswer[] += 1;\r\n\t\t\twriteln (answer.length);\r\n\t\t\twritefln !(\"%(%s %)\") (answer);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\tauto adj = new int [] [n];\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tint u, v;\r\n\t\t\treadf !(\" %s %s\") (u, v);\r\n\t\t\tu -= 1;\r\n\t\t\tv -= 1;\r\n\t\t\tadj[u] ~= v;\r\n\t\t\tadj[v] ~= u;\r\n\t\t}\r\n\r\n\t\tauto c = new int [n];\r\n\t\tc[] = -1;\r\n\r\n\t\tvoid recur (int v, int cur)\r\n\t\t{\r\n\t\t\tif (c[v] >= 0)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tc[v] = cur;\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\trecur (u, !cur);\r\n\t\t\t}\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\tif (c[v] == c[u])\r\n\t\t\t\t{\r\n\t\t\t\t\tc[v] = 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecur (0, 0);\r\n\t\tdebug {writeln (c);}\r\n\r\n\t\tif (c.any !(q{a == -1}))\r\n\t\t{\r\n\t\t\twriteln (\"NO\");\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln (\"YES\");\r\n\t\t\tauto answer = n.iota.filter !(i => c[i] == 0).array;\r\n\t\t\tanswer[] += 1;\r\n\t\t\twriteln (answer.length);\r\n\t\t\twritefln !(\"%(%s %)\") (answer);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\tauto adj = new int [] [n];\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tint u, v;\r\n\t\t\treadf !(\" %s %s\") (u, v);\r\n\t\t\tu -= 1;\r\n\t\t\tv -= 1;\r\n\t\t\tadj[u] ~= v;\r\n\t\t\tadj[v] ~= u;\r\n\t\t}\r\n\r\n\t\tauto c = new int [n];\r\n\t\tc[] = -1;\r\n\r\n\t\tvoid recur (int v, int cur)\r\n\t\t{\r\n\t\t\tif (c[v] >= 0)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tc[v] = cur;\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\trecur (u, !cur);\r\n\t\t\t}\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\tif (c[v] == c[u])\r\n\t\t\t\t{\r\n\t\t\t\t\tc[v] = 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecur (0, 0);\r\n\r\n\t\tif (c.any !(q{a == -1}))\r\n\t\t{\r\n\t\t\twriteln (\"NO\");\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln (\"YES\");\r\n\t\t\tauto answer = n.iota.filter !(i => c[i] == 1).array;\r\n\t\t\tanswer[] += 1;\r\n\t\t\twriteln (answer.length);\r\n\t\t\twritefln !(\"%(%s %)\") (answer);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto edges = new int[][](n);\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tauto u = RD!int-1;\r\n\t\t\tauto v = RD!int-1;\r\n\t\t\tedges[u] ~= v;\r\n\t\t\tedges[v] ~= u;\r\n\t\t}\r\n\r\n\t\tauto edges2 = new int[][](n);\r\n\t\tint[] q = [0];\r\n\t\tauto used = new bool[](n);\r\n\t\tused[0] = true;\r\n\t\twhile (!q.empty)\r\n\t\t{\r\n\t\t\tauto u = q.front; q.popFront;\r\n\t\t\tforeach (v; edges[u])\r\n\t\t\t{\r\n\t\t\t\tif (used[v]) continue;\r\n\t\t\t\tedges2[u] ~= v;\r\n\t\t\t\tedges2[v] ~= u;\r\n\t\t\t\tq ~= v;\r\n\t\t\t\tused[v] = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ok = true;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!used[i])\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (!ok) continue;\r\n\r\n\t\tvoid dfs(int pos, int last, int s)\r\n\t\t{\r\n\t\t\tif (s == 1)\r\n\t\t\t\tans[ti] ~= pos+1;\r\n\t\t\t\r\n\t\t\tforeach (v; edges2[pos])\r\n\t\t\t{\r\n\t\t\t\tif (v == last) continue;\r\n\t\t\t\tdfs(v, pos, s^1);\r\n\t\t\t}\r\n\t\t}\r\n\t\tdfs(0, -1, 1);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tif (e.empty)\r\n\t\t\twriteln(\"NO\");\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln(\"YES\");\r\n\t\t\twriteln(e.length);\r\n\t\t\te.map!(to!string).join(\" \").writeln;\r\n\t\t}\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "d4e1ec5445de029895a9c47ab89db3a2"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto lo = new int [n];\r\n\t\tauto hi = new int [n];\r\n\t\tauto cost = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s %s\") (lo[i], hi[i], cost[i]);\r\n\t\t}\r\n\t\treadln;\r\n\r\n\t\tauto f = tuple (int.max, -1);\r\n\t\tauto g = tuple (int.max, -1);\r\n\t\tauto h = tuple (int.max, int.max, -1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tf = min (f, tuple (+lo[i], cost[i]));\r\n\t\t\tg = min (g, tuple (-hi[i], cost[i]));\r\n\t\t\th = min (h, tuple (+lo[i], -hi[i], cost[i]));\r\n\t\t\tint res = f[1] + g[1];\r\n\t\t\tif (h[0] == f[0] && h[1] == g[0])\r\n\t\t\t{\r\n\t\t\t\tres = min (res, h[2]);\r\n\t\t\t}\r\n\t\t\twriteln (res);\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nconst bool dbg = true;\r\nvoid DBG(alias x)() { static if (dbg) stderr.writefln(\"DBG: %s = %s\", x.stringof, x); }\r\nvoid MSG(in string x) { static if (dbg) stderr.writefln(\"MSG: %s\", x); }\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n long[] L = new long[N],\r\n R = new long[N],\r\n C = new long[N];\r\n long[Tuple!(long, long)] P;\r\n for (int i = 0; i < N; i++) {\r\n scanf(\"%lld %lld %lld\\n\", &L[i], &R[i], &C[i]);\r\n }\r\n long m = long.max, M = 0;\r\n long mc = long.max, Mc = long.max;\r\n for (int s = 0; s < N; s++) {\r\n auto key = tuple(L[s], R[s]);\r\n if (key in P) {\r\n P[key] = min(P[key], C[s]);\r\n } else {\r\n P[key] = C[s];\r\n }\r\n long ans = long.max;\r\n if (L[s] <= m) {\r\n mc = (L[s] == m ? min(mc, C[s]) : C[s]);\r\n m = L[s];\r\n }\r\n if (M <= R[s]) {\r\n Mc = (R[s] == M ? min(Mc, C[s]) : C[s]);\r\n M = R[s];\r\n }\r\n ans = min(ans, mc + Mc);\r\n if (tuple(m, M) in P) {\r\n ans = min(ans, P[tuple(m, M)]);\r\n }\r\n writeln(ans);\r\n }\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t ; 0 .. T) {\r\n solve();\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto l = new long[](n);\r\n\t\tauto r = new long[](n);\r\n\t\tauto c = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tl[i] = RD;\r\n\t\t\tr[i] = RD;\r\n\t\t\tc[i] = RD;\r\n\t\t}\r\n\r\n\t\tint li, ri, xi;\r\n\t\tans[ti] ~= c[0];\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tif (l[i] == l[li])\r\n\t\t\t{\r\n\t\t\t\tif (c[i] < c[li])\r\n\t\t\t\t\tli = i;\r\n\t\t\t}\r\n\t\t\telse if (l[i] < l[li])\r\n\t\t\t\tli = i;\r\n\t\t\t\r\n\t\t\tif (r[i] == r[ri])\r\n\t\t\t{\r\n\t\t\t\tif (c[i] < c[ri])\r\n\t\t\t\t\tri = i;\r\n\t\t\t}\r\n\t\t\telse if (r[i] > r[ri])\r\n\t\t\t\tri = i;\r\n\r\n\t\t\tif (r[i] - l[i] == r[xi] - l[xi])\r\n\t\t\t{\r\n\t\t\t\tif (c[i] < c[xi])\r\n\t\t\t\t\txi = i;\r\n\t\t\t}\r\n\t\t\telse if (r[i] - l[i] > r[xi] - l[xi])\r\n\t\t\t\txi = i;\r\n\r\n\t\t\tdebug writeln(\"li:\", li, \" ri:\", ri, \" xi:\", xi);\r\n\t\t\tlong tmp;\r\n\t\t\tif (r[xi] - l[xi] > r[ri] - l[li])\r\n\t\t\t\ttmp = c[xi];\r\n\t\t\telse if (r[xi] - l[xi] == r[ri] - l[li])\r\n\t\t\t\ttmp = min(c[xi], c[li] + c[ri]);\r\n\t\t\telse\r\n\t\t\t\ttmp = c[li] + c[ri];\r\n\t\t\tans[ti] ~= tmp;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tforeach (ee; e)\r\n\t\t\twriteln(ee);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std;\n\nalias Segment = Tuple!(uint, \"left\", uint, \"right\", uint, \"cost\");\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n immutable Segment[] stock = (){\n Segment[] ret = new Segment[n];\n\n foreach (ref tup; ret)\n readf!\"%s %s %s\\n\"(tup.expand);\n\n return ret.assumeUnique;\n }();\n\n\n enum cost = (size_t a, size_t b){\n if (a == b)\n return stock[a].cost;\n return stock[a].cost + stock[b].cost;\n };\n\n enum length = (size_t a, size_t b) {\n assert(stock[a].left <= stock[b].right);\n return stock[b].right - stock[a].left;\n };\n\n size_t cheapestLow, cheapestHigh;\n writeln(cost(0, 0));\n\n alias T = Tuple!(size_t, \"smol\", size_t, \"big\");\n T prev = T(0, 0);\n foreach (s; 1 .. n) {\n immutable now = stock[s];\n T[] options = [prev, T(s, s)];\n\n if (now.left <= stock[cheapestHigh].right)\n options ~= T(s, cheapestHigh);\n\n if (now.right >= stock[cheapestLow].left)\n options ~= T(cheapestLow, s);\n\n enum better = (T a, T b) {\n assert(stock[a.big].right >= stock[a.smol].left);\n assert(stock[b.big].right >= stock[b.smol].left);\n\n auto d1 = length(a.expand);\n auto d2 = length(b.expand);\n\n auto c1 = cost(a.expand);\n auto c2 = cost(b.expand);\n\n if (d1 != d2)\n return d1 > d2;\n return c1 < c2;\n };\n\n auto ans = options.sort!((a, b) => better(a, b));\n\n //foreach (tup; ans)\n //writefln(\"[%1$s, %2$s] -> [%4$s, %5$s]\", stock[tup.smol].expand, stock[tup.big].expand);\n\n assert(length(ans[0].expand) >= length(ans[1].expand));\n\n writeln(cost(ans[0].expand));\n\n prev = ans[0];\n\n if (now.left < stock[cheapestLow].left ||\n now.left == stock[cheapestLow].left && now.cost < stock[cheapestLow].cost)\n cheapestLow = s;\n\n if (now.right > stock[cheapestHigh].right ||\n now.right == stock[cheapestHigh].right && now.cost < stock[cheapestHigh].cost)\n cheapestHigh = s;\n }\n\n }\n}\n// \"\"\n"}], "negative_code": [{"source_code": "import std;\n\n\nalias Segment = Tuple!(int, \"left\", int, \"right\", int, \"cost\");\n\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n immutable Segment[] inventory = (){\n Segment[] ret;\n ret.reserve(n);\n\n foreach (_; 0 .. n) {\n int left, right, cost;\n readf!\"%s %s %s\\n\"(left, right, cost);\n ret ~= Segment(left, right, cost);\n }\n return ret.assumeUnique;\n }();\n\n enum cost = (size_t l, size_t r) {\n if (l != r)\n return inventory[l].cost + inventory[r].cost;\n else\n return inventory[l].cost;\n };\n\n alias T = Tuple!(size_t, \"small\", size_t, \"big\");\n auto prev = T(0, 0);\n\n writeln(cost(0, 0));\n foreach (s; 1 .. n) {\n T[] options = [\n T(s, prev.big),\n T(prev.small, s),\n T(s, s),\n prev\n ];\n\n enum better = (T a, T b) {\n auto d1 = inventory[a.big].right - inventory[a.small].left;\n auto d2 = inventory[b.big].right - inventory[b.small].left;\n\n auto c1 = cost(a.expand);\n auto c2 = cost(b.expand);\n\n if (d1 != d2)\n return d1 > d2;\n return c1 < c2;\n };\n\n auto best = options.sort!((a, b) => better(a, b));\n\n writeln(cost(best.front.expand));\n prev = best.front;\n }\n\n }\n}\n// \"\"\n"}, {"source_code": "import std;\n\n\nalias Segment = Tuple!(uint, \"left\", uint, \"right\", uint, \"cost\");\n\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n immutable Segment[] inventory = (){\n Segment[] ret;\n ret.reserve(n);\n\n foreach (_; 0 .. n) {\n uint left, right, cost;\n readf!\"%s %s %s\\n\"(left, right, cost);\n ret ~= Segment(left, right, cost);\n }\n return ret.assumeUnique;\n }();\n\n enum cost = (size_t l, size_t r) {\n if (l != r)\n return inventory[l].cost + inventory[r].cost;\n else\n return inventory[l].cost;\n };\n\n alias T = Tuple!(size_t, \"small\", size_t, \"big\");\n auto prev = T(0, 0);\n\n writeln(cost(0, 0));\n foreach (s; 1 .. n) {\n T now = prev;\n\n if (inventory[s].left < inventory[prev.small].left)\n now.small = s;\n\n if (inventory[s].right > inventory[prev.small].right)\n now.big = s;\n\n if (inventory[s].left == inventory[now.small].left && cost(s, now.big) < cost(now.expand))\n now.small = s;\n\n if (inventory[s].right == inventory[now.big].right && cost(s, now.small) < cost(now.expand))\n now.big = s;\n\n writeln(cost(now.expand));\n prev = now;\n }\n\n }\n}\n// \"\"\n"}, {"source_code": "import std;\n\n\nalias Segment = Tuple!(uint, \"left\", uint, \"right\", uint, \"cost\");\n\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n immutable Segment[] inventory = (){\n Segment[] ret;\n ret.reserve(n);\n\n foreach (_; 0 .. n) {\n uint left, right, cost;\n readf!\"%s %s %s\\n\"(left, right, cost);\n ret ~= Segment(left, right, cost);\n }\n return ret.assumeUnique;\n }();\n\n\n enum cost = (size_t l, size_t r) {\n if (l != r)\n return inventory[l].cost + inventory[r].cost;\n else\n return inventory[l].cost;\n };\n\n size_t left = 0, right = 0;\n writeln(cost(left, right));\n size_t biggest, smallest;\n\n foreach (s; 1 .. n) {\n if (inventory[s].left < inventory[smallest].left)\n smallest = s;\n if (inventory[s].right > inventory[biggest].right)\n biggest = s;\n\n\n if (inventory[s].left < inventory[left].left)\n left = s;\n if (inventory[s].right > inventory[right].right)\n right = s;\n\n\n immutable v1 = inventory[s].right - inventory[s].left;\n immutable v2 = inventory[right].right - inventory[left].left;\n\n if (v1 > v2 ||\n v1 == v2 && cost(s, s) < cost(left, right)) {\n immutable q = inventory[s].right - inventory[smallest].left;\n immutable r = inventory[biggest].right - inventory[s].left;\n\n if (q > r || q == r && cost(s, smallest) < cost(s, biggest))\n left = smallest, right = s;\n else\n right = biggest, left = s;\n }\n\n\n writeln(cost(left, right));\n }\n }\n}\n// \"\"\n"}, {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nconst bool dbg = true;\r\nvoid DBG(alias x)() { static if (dbg) stderr.writefln(\"DBG: %s = %s\", x.stringof, x); }\r\nvoid MSG(in string x) { static if (dbg) stderr.writefln(\"MSG: %s\", x); }\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n long[] L = new long[N],\r\n R = new long[N],\r\n C = new long[N];\r\n long[Tuple!(long, long)] P;\r\n for (int i = 0; i < N; i++) {\r\n scanf(\"%lld %lld %lld\\n\", &L[i], &R[i], &C[i]);\r\n }\r\n long m = long.max, M = 0;\r\n long mc = long.max, Mc = long.max;\r\n for (int s = 0; s < N; s++) {\r\n P[tuple(L[s], R[s])] = C[s];\r\n long ans = long.max;\r\n if (L[s] <= m) {\r\n mc = (L[s] == m ? min(mc, C[s]) : C[s]);\r\n m = L[s];\r\n }\r\n if (M <= R[s]) {\r\n Mc = (R[s] == M ? min(Mc, C[s]) : C[s]);\r\n M = R[s];\r\n }\r\n ans = min(ans, mc + Mc);\r\n if (tuple(m, M) in P) {\r\n ans = min(ans, P[tuple(m, M)]);\r\n }\r\n writeln(ans);\r\n }\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t ; 0 .. T) {\r\n solve();\r\n }\r\n}\r\n"}], "src_uid": "ee773d908fc297cc692aaecf6af299c9"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RD!string;\n\t\tauto b = RD!string;\n\t\tauto aa = new int[](26);\n\t\tauto bb = new int[](26);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\t++aa[a[i]-'a'];\n\t\t\t++bb[b[i]-'a'];\n\t\t}\n\t\tauto c = new int[](26);\n\t\tforeach (i; 0..26)\n\t\t{\n\t\t\tc[i] = aa[i] - bb[i];\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (i; 0..25)\n\t\t{\n\t\t\tif (c[i] < 0)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (c[i] % k)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tc[i+1] += c[i];\n\t\t\t}\n\t\t}\n\t\tif (c[$-1] != 0)\n\t\t\tok = false;\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Yes\" : \"No\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n// Main Logic Here\nvoid play(){\n long[27] cmap = 0;\n auto n = rd!int;\n auto k = rd!int;\n dchar[] s1 = rd!(dchar[]);\n dchar[] s2 = rd!(dchar[]);\n foreach(dchar c; s1){ int z = to!int(c - 'a'); ++cmap[z+1]; }\n foreach(dchar c; s2){ int z = to!int(c - 'a'); --cmap[z+1]; }\n show(cmap);\n foreach(int i; 1..27){\n if(cmap[i] > 0 && cmap[i] % k == 0){\n foreach(int j; i+1..27){\n if(cmap[j] < 0 && (-cmap[j]) % k == 0){\n ll take = min(cmap[i], -cmap[j]);\n cmap[i] -= take;\n cmap[j] += take;\n }\n }\n }\n }\n show(cmap);\n foreach(i; 1..27){\n if(cmap[i] != 0){\n writeln(\"No\");\n return;\n }\n }\n writeln(\"Yes\");\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle for testcases!\n while(t--) play(); // Let's play!\n return 0;\n}\n\n/**********That's All Folks!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp; // Read input\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nalias ll = long;\nalias tup = Tuple!(long, \"x\", long, \"y\");\nvoid show(A...)(A a) { debug{ foreach(t; a){ stderr.write(t, \"| \"); } stderr.writeln; } } // Debug\n/* Add if TLE, T max(T = long)(T a, T b){ return (a > b) ? a : b; } */\n"}], "negative_code": [], "src_uid": "09d0f11bdb9eca2161dee83a335dd2b7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tans[ti] ~= s[$/2];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1400/problem/A\n// greedy\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n while(t--) {\n int n = readln.chomp.to!int;\n string s = readln.strip;\n\n char[] ans;\n\n foreach(_; 0..n)\n ans ~= s[n-1];\n\n ans.writeln;\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tforeach (test; 0..readln.strip.to !(int))\n\t{\n\t\treadln;\n\t\treadln.strip.stride (2).writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1400/problem/A\n// greedy\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n while(t--) {\n int n = readln.chomp.to!int;\n string s = readln.strip;\n\n char[] ans;\n\n foreach(_; 0..n-1)\n ans ~= '1';\n\n ans ~= s[n-1];\n ans.writeln;\n }\n}\n\n"}], "src_uid": "b37bbf1fe9ac5144cfa230633ccbdd79"} {"source_code": "import std.stdio;\n\nvoid main()\n{\n float h, l;\n readf!\"%f %f\\n\"(h, l);\n\n writef!\"%.6f\\n\"((l^^2 - h^^2) / (2*h));\n}\n", "positive_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n double h,l;\n readf!\"%f %f\"(h,l);\n readln;\n writefln!\"%.13f\"(l^^2/(2*h)-0.5*h);\n}\n\n"}, {"source_code": "import std.stdio, std.math;\n\nvoid main() {\n long h, l;\n readf(\" %s %s\", h, l);\n auto result = (cast(float)(l*l - h*h)) / (2 * h);\n writef(\"%.9s\", result);\n}\n"}], "negative_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n double h,l;\n readf!\"%f %f\"(h,l);\n readln;\n writefln!\"%.13f\"(l^^2/(2*h)-0.5);\n}\n\n"}], "src_uid": "2cd5807e3f9685d4eff88f2283904f0d"} {"source_code": "\ufeffimport std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\tint n;\n\tint[] a;\n\tint temp;\n\n\treadf(\" %s %s\", &n, &temp);\n\n\ta ~= temp;\n\tint max = temp;\n\n\tint idx = 0;\n\tforeach (i; 1 .. n) {\n\t\treadf(\" %s\", &temp);\n\t\ta ~= temp;\n\t\tif (temp > max) {\n\t\t\tmax = temp;\n\t\t\tidx = i;\n\t\t}\n\t}\n\n\ta[idx] = (a[idx] == 1) ? 2 : 1;\n\n\twritefln(\"%(%s %)\", sort(a));\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n\n auto ys = new int[N];\n if (xs.all!\"a == 1\") {\n ys[] = 1;\n ys.back = 2;\n } else {\n ys[0] = 1;\n for (int i = 1; i < N; i++) {\n ys[i] = xs[i - 1];\n }\n }\n writefln(\"%(%s %)\", ys);\n}\n"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm\n , std.range\n , std.container;\n\n\nvoid main() {\n const len = {\n uint t;\n readf(\"%s\\n\", &t);\n return t;\n }();\n \n uint[] data = new uint[len];\n \n auto mymax = tuple(0, 0);\n foreach(idx, ref i; data) {\n readf(\"%s \", &i);\n if(i > mymax[1]) { mymax[1] = i; mymax[0] = idx; }\n }\n \n if(mymax[1] != 1) {\n data[mymax[0]] = 1;\n }\n else\n {\n data[mymax[0]] = 2;\n }\n \n /*data.sort()\n .y!((auto ref arr){\n foreach(ref a; arr) {\n write(a, \" \");\n }\n });\n */\n \n (auto ref arr){\n foreach(ref a; arr) {\n write(a, \" \");\n }\n }\n ( data.sort() );\n}\n\nalias y(alias clos) = clos;\n\nalias var(alias elem) = std.traits.Unqual!(typeof(elem));\n\nauto mut(T)(auto ref T in_val) {\n std.traits.Unqual!(T) rv = in_val;\n return rv;\n}\n\nauto imut(T)(auto ref T in_val) {\n immutable immrv = in_val;\n return immrv;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "\ufeffimport std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\tint n;\n\tint[] a;\n\tint temp;\n\n\treadf(\" %s %s\", &n, &temp);\n\n\ta ~= temp;\n\tint max = temp;\n\n\tint idx = 0;\n\tforeach (i; 1 .. n) {\n\t\treadf(\" %s\", &temp);\n\t\ta ~= temp;\n\t\tif (temp > max) {\n\t\t\tmax = temp;\n\t\t\tidx = i;\n\t\t}\n\t}\n\n\t(a[idx] == 1) ? a[idx] = 2 : a[idx] = 1;\n\n\twritefln(\"%(%s %)\", sort(a));\n}"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n\n auto ys = new int[N];\n ys[0] = 1;\n for (int i = 1; i < N; i++) {\n ys[i] = xs[i - 1];\n }\n writefln(\"%(%s %)\", ys);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n\n auto ys = new int[N];\n if (N == 1 && xs[0] == 1) {\n writeln(2);\n return;\n }\n ys[0] = 1;\n for (int i = 1; i < N; i++) {\n ys[i] = xs[i - 1];\n }\n writefln(\"%(%s %)\", ys);\n}\n"}], "src_uid": "1cd10f01347d869be38c08ad64266870"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b;\n readf (\"%s %s %s\", &n, &a, &b);\n readln;\n b = min (b, n);\n \n Tuple!(long, long) [] arr;\n foreach ( _; 0..n ) {\n auto r = readln.splitter.map! (to!long).array;\n arr ~= tuple(r[0], r[1]);\n }\n \n arr.sort! (q{ a[0] - a[1] > b[0] - b[1] });\n \n debug { writeln (arr); }\n \n auto valUseB = (Tuple!(long, long) e) => max (e[0], e[1]);\n \n auto ansNoA = arr\n .enumerate\n .map! (t => t.index < b ? valUseB (t.value) : t.value[1])\n .sum;\n \n if (b == 0) {\n writeln (ansNoA);\n return;\n }\n \n auto smallestGainOnB = valUseB (arr[b-1]) - arr[b-1][1];\n auto valUseAB = (Tuple!(long, long) e) => max (e[0] * 2^^a, e[1]);\n auto gainOnA = (ulong i, Tuple!(long, long) e) => valUseAB (e) - (i < b ? valUseB (e) : e[1] + smallestGainOnB);\n auto ans = ansNoA + arr.enumerate.map! (t => gainOnA (t.index, t.value)).maxElement;\n \n debug { writeln (ansNoA, ' ', arr.enumerate.map! (t => gainOnA (t.index, t.value))); }\n writeln (ans);\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto A = s[1];\n auto B = s[2];\n auto H = new long[](N);\n auto D = new long[](N);\n foreach (i; 0..N) {\n auto t = readln.split.map!(to!long);\n H[i] = t[0];\n D[i] = t[1];\n }\n\n auto S = D.sum;\n auto DD = new long[](N);\n foreach (i; 0..N) DD[i] = max(0L, H[i] - D[i]);\n DD.sort!\"a > b\"();\n auto DDS = DD[0..min(N, B)].sum;\n long ans = 0;\n\n if (A == 0) {\n writeln(S + DDS);\n return;\n }\n\n if (B == 0) {\n writeln(S);\n return;\n }\n\n foreach (i; 0..N) {\n long tmp = (H[i] << A) + S - D[i] + DDS;\n long dd = max(0L, H[i] - D[i]);\n if (B >= N || dd > DD[B]) {\n tmp = tmp - dd;\n } else {\n tmp = tmp - DD[B-1];\n }\n ans = max(ans, tmp);\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b;\n readf (\"%s %s %s\", &n, &a, &b);\n readln;\n b = min (b, n);\n \n long [][] arr;\n foreach ( _; 0..n ) arr ~= readln.splitter.map! (to!long).array;\n \n arr.sort! (q{ a[0] - a[1] > b[0] - b[1] });\n \n debug { writeln (arr); }\n \n auto valUseB = (long[] e) => max (e[0], e[1]);\n \n auto ansNoA = arr\n .enumerate\n .map! (t => t.index < b ? valUseB (t.value) : t.value[1])\n .sum;\n \n if (b == 0) {\n writeln (ansNoA);\n return;\n }\n \n auto smallestGainOnB = valUseB (arr[b-1]) - arr[b-1][1];\n auto valUseAB = (long[] e) => max (e[0] * 2^^a, e[1]);\n auto gainOnA = (ulong i, long[] e) => valUseAB (e) - (i < b ? valUseB (e) : e[1] + smallestGainOnB);\n auto ans = ansNoA + arr.enumerate.map! (t => gainOnA (t.index, t.value)).maxElement;\n \n debug { writeln (ansNoA, ' ', arr.enumerate.map! (t => gainOnA (t.index, t.value))); }\n writeln (ans);\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto A = s[1];\n auto B = s[2];\n auto H = new long[](N);\n auto D = new long[](N);\n foreach (i; 0..N) {\n auto t = readln.split.map!(to!long);\n H[i] = t[0];\n D[i] = t[1];\n }\n\n auto S = D.sum;\n auto DD = new long[](N);\n foreach (i; 0..N) DD[i] = max(0L, H[i] - D[i]);\n DD.sort!\"a > b\"();\n auto DDS = DD[0..min(N, B)].sum;\n long ans = 0;\n\n if (A == 0) {\n writeln(S + DDS);\n return;\n }\n\n foreach (i; 0..N) {\n long tmp = (H[i] << A) + S - D[i] + DDS;\n long dd = max(0L, H[i] - D[i]);\n if (B >= N) {\n tmp -= dd;\n } else if (dd > DD[B]) {\n tmp = tmp - dd + DD[B];\n }\n ans = max(ans, tmp);\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b;\n readf (\"%s %s %s\", &n, &a, &b);\n readln;\n \n long [][] arr;\n foreach (_; 0..n) arr ~= readln.splitter.map!(to!long).array;\n \n debug { writeln (arr); }\n \n long mult = 2 ^^ a;\n auto gainMult = (long[] x) => x[0] * mult - x[1];\n int mxind = cast(int) arr.map!(a => gainMult(a)).maxIndex;\n arr[mxind][0] *= mult;\n \n debug { writeln (mxind, ' ', arr[mxind][0]); }\n \n auto gain = (long[] x) => x[0] - x[1];\n long[] gains = arr.map!(x => gain(x)).array;\n debug { writeln (arr, ' ', gains); }\n auto ans = arr.map!(q{ a[1] }).sum(0L) +\n gains\n .sort!(q{ a > b })\n .until!(q{ a <= 0 })\n .take(b)\n .sum(0L);\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b;\n readf (\"%s %s %s\", &n, &a, &b);\n readln;\n \n long [][] arr;\n foreach (_; 0..n) arr ~= readln.splitter.map! (to!long).array;\n \n debug { writeln (arr); }\n \n auto gain = (long[] x) => x[0] * 2^^a - x[1];\n auto powerUpOrder = arr.sort! ((a, b) => gain (a) > gain (b));\n \n debug { writeln (powerUpOrder); }\n \n auto ans = \n arr.map! (q{ a[1] }).sum\n + powerUpOrder\n .take (b)\n .map! (x => gain (x))\n .until! (q{ a <= 0 })\n .sum;\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b;\n readf (\"%s %s %s\", &n, &a, &b);\n readln;\n b = min (b, n);\n \n long [][] arr;\n foreach ( _; 0..n ) arr ~= readln.splitter.map! (to!long).array;\n \n arr.sort! (q{ a[0] - a[1] > b[0] - b[1] });\n \n debug { writeln (arr); }\n \n auto valUseB = (long[] e) => max (e[0], e[1]);\n \n auto ansNoA = arr\n .enumerate\n .map! (t => t.index < b ? valUseB (t.value) : t.value[1])\n .sum;\n \n if (b == 0) {\n writeln (ansNoA);\n return;\n }\n \n auto smallestGainOnB = valUseB (arr[b-1]) - arr[b-1][1];\n auto valUseAB = (long[] e) => max (e[0] * 2^^a, e[1]);\n auto gainOnA = (ulong i, long[] e) => valUseAB (e) - valUseB (e) - (i < b ? 0 : smallestGainOnB);\n auto ans = ansNoA + arr.enumerate.map! (t => gainOnA (t.index, t.value)).maxElement;\n \n debug { writeln (ansNoA, ' ', arr.enumerate.map! (t => gainOnA (t.index, t.value))); }\n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b;\n readf (\"%s %s %s\", &n, &a, &b);\n readln;\n \n long [][] arr;\n foreach (_; 0..n) arr ~= readln.splitter.map!(to!long).array;\n \n long ans = arr.map!(q{ a[1] }).sum;\n \n debug { writeln (arr, ' ', ans); }\n \n int mult = 2 ^^ a;\n auto gainMult = (long[] x) => x[0] * mult - x[1];\n int mxind = cast(int) arr.map!(a => gainMult(a)).maxIndex;\n arr[mxind][0] *= mult;\n \n debug { writeln (mxind, ' ', arr[mxind][0]); }\n \n auto gain = (long[] x) => x[0] - x[1];\n long[] gains = arr.map!(x => gain(x)).array;\n ans += gains\n .sort!(q{ a > b })\n .until!(q{ a <= 0 })\n .take(b)\n .sum;\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b;\n readf (\"%s %s %s\", &n, &a, &b);\n readln;\n \n long [][] arr;\n foreach (_; 0..n) arr ~= readln.splitter.map!(to!long).array;\n \n long ans = arr.map!(q{ a[1] }).sum;\n \n debug { writeln (arr, ' ', ans); }\n \n long mult = 2 ^^ a;\n auto gainMult = (long[] x) => x[0] * mult - x[1];\n int mxind = cast(int) arr.map!(a => gainMult(a)).maxIndex;\n arr[mxind][0] *= mult;\n \n debug { writeln (mxind, ' ', arr[mxind][0]); }\n \n auto gain = (long[] x) => x[0] - x[1];\n long[] gains = arr.map!(x => gain(x)).array;\n ans += gains\n .sort!(q{ a > b })\n .until!(q{ a <= 0 })\n .take(b)\n .sum;\n \n writeln (ans);\n}"}], "src_uid": "87f4b8523d0047935931906ccc2ea911"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\n\nbool check(long n, long a, long b, long c) {\n\tlong x = min(a, b, c);\n\ta -= x;\n\tb -= x;\n\tc -= x;\n\tlong rem = n - a - b - c;\n\treturn (rem >= 0 && rem % 3 == 0);\n}\n\nbool solve(long N, long K, long D1, long D2) {\n\tforeach (s; [ +1, -1 ]) foreach (t; [ +1, -1 ]) {\n\t\tif (check(K, D1 * s, 0, D2 * t) && check(N - K, D1 * -s, 0, D2 * -t)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid main(string[] args) {\n\t// try {\n\tfor (int TC = readInt; TC--; ) {\n\t\tlong N = readLong;\n\t\tlong K = readLong;\n\t\tlong D1 = readLong;\n\t\tlong D2 = readLong;\n\t\tbool res = solve(N, K, D1, D2);\n\t\twriteln(res ? \"yes\" : \"no\");\n\t}\n\t// } catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "module main;\n\nimport std.stdio, std.string, std.algorithm;\n\nint check(long n, long k, long d1, long d2)\n{\n long tmp = d1 * 2 + d2 + k;\n if (tmp < 0 || tmp % 3 != 0)\n {\n return 0;\n }\n long x = tmp / 3;\n tmp = k + d2 - d1;\n if (tmp < 0 || tmp % 3 != 0)\n {\n return 0;\n }\n long y = tmp / 3;\n tmp = k - d1 - d2 * 2;\n if (tmp < 0 || tmp % 3 != 0)\n {\n return 0;\n }\n long z = tmp / 3;\n long left = n - k;\n auto p = [x, y, z];\n sort(p);\n long need = p[2] - p[0] + p[2] - p[1];\n if (need > left)\n {\n return 0;\n }\n left -= need;\n if (left % 3 == 0)\n {\n writeln(\"yes\");\n return 1;\n }\n return 0;\n}\n\nvoid solve(long n, long k, long d1, long d2)\n{\n if (check(n, k, d1, d2)) return;\n if (check(n, k, -d1, d2)) return;\n if (check(n, k, d1, -d2)) return;\n if (check(n, k, -d1, -d2)) return;\n writeln(\"no\");\n}\n\nint main(string[] args)\n{\n int t;\n while (scanf(\"%d\", &t) == 1)\n {\n foreach (i; 0 .. t)\n {\n long n, k, d1, d2;\n scanf(\"%lld%lld%lld%lld\", &n, &k, &d1, &d2);\n solve(n, k, d1, d2);\n }\n }\n return 0;\n}"}], "negative_code": [{"source_code": "module main;\n\nimport std.stdio, std.string, std.algorithm;\n\nint check(long n, long k, long d1, long d2)\n{\n long tmp = d1 * 2 + d2 + k;\n if (tmp < 0 || tmp % 3 != 0)\n {\n return 0;\n }\n long x = tmp / 3;\n tmp = k + d2 - d1;\n if (tmp < 0 || tmp % 3 != 0)\n {\n return 0;\n }\n long y = tmp / 3;\n tmp = k - d1 - d2 * 2;\n if (tmp < 0 || tmp % 3 != 0)\n {\n return 0;\n }\n long z = tmp / 3;\n //writeln(x, \" \", y, \" \", z);\n long left = n - k;\n auto p = [x, y, z];\n sort(p);\n long need = p[2] - p[0] + p[2] - p[1];\n if (need > left)\n {\n return 0;\n }\n left -= need;\n if (left % 3 == 0)\n {\n writeln(\"yes\");\n return 1;\n }\n return 0;\n}\n\nvoid solve(long n, long k, long d1, long d2)\n{\n if (check(n, k, d1, d2)) return;\n if (check(n, k, -d1, d2)) return;\n if (check(n, k, d1, -d2)) return;\n if (check(n, k, -d1, -d2)) return;\n writeln(\"no\");\n}\n\nint main(string[] args)\n{\n int t;\n while (scanf(\"%d\", &t) == 1)\n {\n foreach (i; 0 .. t)\n {\n long n, k, d1, d2;\n scanf(\"%d%d%d%d\", &n, &k, &d1, &d2);\n solve(n, k, d1, d2);\n }\n }\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid solve(long n, long k, long d1, long d2)\n{\n long cnt = d1 + d1 + d2;\n long left = n - k;\n if (cnt > left)\n {\n writeln(\"no\");\n }\n else\n {\n left -= cnt;\n if (left % 3 == 0)\n {\n writeln(\"yes\");\n }\n else\n {\n writeln(\"no\");\n }\n }\n}\n\nint main(string[] args)\n{\n int t;\n while (scanf(\"%d\", &t) == 1)\n {\n foreach (i; 0 .. t)\n {\n long n, k, d1, d2;\n scanf(\"%d%d%d%d\", &n, &k, &d1, &d2);\n solve(n, k, d1, d2);\n }\n }\n return 0;\n}"}], "src_uid": "324298100f3e36d289ef6ca8178ac6d3"} {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint[] testArray = null;\n\tauto n = testArray is null? readInt!int : cast(int)testArray.length;\n\tauto k = testArray is null? readInt!int : 1;\n\tauto or = new int[](n-1);\n\tauto nd = new int[](n-1);\n\tauto ans = new int[](n);\n\tint query(string op, int i, int j)\n\t{\n\t\tif (testArray is null)\n\t\t{\n\t\t\twriteln(op, \" \", i, \" \", j);\n\t\t\tstdout.flush;\n\t\t\treturn readInt!int;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tswitch(op)\n\t\t\t{\n\t\t\tcase \"or\":\n\t\t\t\treturn testArray[i-1] | testArray[j-1];\n\t\t\tcase \"and\":\n\t\t\t\treturn testArray[i-1] & testArray[j-1];\n\t\t\tdefault: assert(0);\n\t\t\t}\n\t\t}\n\t}\n\tauto or23 = query(\"or\", 2, 3);\n\tforeach(i; 1 .. n)\n\t{\n\t\tor[i-1] = query(\"or\", 1, i + 1);\n\t\tnd[i-1] = query(\"and\", 1, i + 1);\n\t}\n\tauto andedOrs = or.fold!((a, b) => a & b);\n\tauto oredAns = nd.fold!((a, b) => a | b);\n\tvoid solveBit(int q)\n\t{\n\t\tif (andedOrs&(1<<q))\n\t\t{\n\t\t\tif (oredAns&(1<<q))\n\t\t\t{\n\t\t\t\t// we are sure a1 at q = 1\n\t\t\t\tans[0] |= (1<<q);\n\t\t\t\tforeach(i; 1 .. n)\n\t\t\t\t{\n\t\t\t\t\tans[i] |= nd[i-1]&(1<<q);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// either 0 1 1 ... or 1 0 0 ...\n\t\t\t// check or23\n\t\t\tif (or23&(1<<q))\n\t\t\t{\n\t\t\t\t// 0 1 1...\n\t\t\t\tforeach(i; 1 .. n)\n\t\t\t\t\tans[i] |= (1<<q);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t// 1 0 0...\n\t\t\t\tans[0] |= (1<<q);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// we are sure a1 at q = 0\n\t\t\tforeach(i; 1 .. n)\n\t\t\t{\n\t\t\t\tans[i] |= or[i-1]&(1<<q);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n\tforeach(b; 0 .. 31)\n\t\tsolveBit(b);\n\tif (testArray !is null)\n\t{\n\t\twriteln(testArray);\n\t\twriteln(ans);\n\t}\n\tsort(ans);\n\twriteln(\"finish \", ans[k-1]);\n\tstdout.flush;\n}\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\r\n\r\nlong query(int type, int idx1, int idx2)\r\n{\r\n if (type == 0) {\r\n writefln(\"or %d %d\", idx1, idx2);\r\n stdout.flush();\r\n return readln.strip.to!long;\r\n } else {\r\n writefln(\"and %d %d\", idx1, idx2);\r\n stdout.flush();\r\n return readln.strip.to!long;\r\n }\r\n}\r\n\r\n/* 1-bit bruteforce version */\r\n\r\nlong recover_a1(long orab, long andab, long orbc, long andbc, long andac, long orac)\r\n{\r\n long ans;\r\n long cnt;\r\n foreach (a ; 0 .. 2) {\r\n foreach (b ; 0 .. 2) {\r\n foreach (c ; 0 .. 2) {\r\n if (andbc == (b & c) && orbc == (b | c) && andab == (a & b) && orab == (a | b) && andac == (a & c) && orac == (a | c)) {\r\n ans = a;\r\n cnt++;\r\n }\r\n }\r\n }\r\n }\r\n assert(cnt == 1);\r\n return ans;\r\n}\r\n\r\n/*\r\n * We know: A | B, A & B, B | C, B & C, A | C, A & C\r\n * Need to recover and return a 32-bit value A.\r\n */\r\n \r\nlong recover_a32(long orab, long andab, long orbc, long andbc, long andac, long orac)\r\n{\r\n long ans;\r\n foreach (b ; 0 .. 32) {\r\n ans |= recover_a1((orab >> b) & 1, (andab >> b) & 1, (orbc >> b) & 1, (andbc >> b) & 1, (andac >> b) & 1, (orac >> b) & 1) << b;\r\n }\r\n return ans;\r\n}\r\n\r\nvoid main()\r\n{\r\n int n, k;\r\n readln.formattedRead!\" %d %d \"(n, k);\r\n long[] a_xor, a_or, a_and;\r\n\r\n foreach (i ; 0 .. n - 1) {\r\n int idx1 = (i + 0) % n + 1;\r\n int idx2 = (i + 1) % n + 1;\r\n long qor = query(0, idx1, idx2);\r\n long qand = query(1, idx1, idx2);\r\n a_or ~= qor;\r\n a_and ~= qand;\r\n a_xor ~= (qor - qand);\r\n }\r\n\r\n long orab = a_or[0];\r\n long andab = a_and[0];\r\n long orbc = a_or[1];\r\n long andbc = a_and[1];\r\n long orac = query(0, 1, 3);\r\n long andac = query(1, 1, 3);\r\n long a0 = recover_a32(orab, andab, orbc, andbc, andac, orac);\r\n long[] ans = [a0];\r\n foreach (i ; 1 .. n) {\r\n ans ~= ans[i - 1] ^ a_xor[i - 1];\r\n }\r\n ans.sort;\r\n writefln(\"finish %d\", ans[k - 1]);\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.meta;\r\n\r\nint ask (string op) (int a, int b)\r\n{\r\n\twriteln (op, \" \", a + 1, \" \", b + 1);\r\n\tstdout.flush ();\r\n\treturn readln.strip.to !(int);\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tint n, k;\r\n\twhile (readf !(\" %s %s\") (n, k) > 0)\r\n\t{\r\n\t\tk -= 1;\r\n\t\treadln;\r\n\r\n\t\tint [3] [3] or;\r\n\t\tint [3] [3] and;\r\n\t\tstatic foreach (s; AliasSeq !(\"or\", \"and\"))\r\n\t\t{\r\n\t\t\tforeach (i; 0..3)\r\n\t\t\t{\r\n\t\t\t\tforeach (j; i + 1..3)\r\n\t\t\t\t{\r\n\t\t\t\t\tmixin (format !(`%s[i][j] = ` ~\r\n\t\t\t\t\t `ask !(\"%s\") (i, j);`) (s, s));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool checkBit (int [3] bits)\r\n\t\t{\r\n\t\t\tforeach (i; 0..3)\r\n\t\t\t{\r\n\t\t\t\tforeach (j; i + 1..3)\r\n\t\t\t\t{\r\n\t\t\t\t\tif ((bits[i] | bits[j]) !=\r\n\t\t\t\t\t (or[i][j] & 1))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif ((bits[i] & bits[j]) !=\r\n\t\t\t\t\t (and[i][j] & 1))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tauto a = new int [n];\r\n\r\nbits_loop:\r\n\t\tforeach (b; 0..30)\r\n\t\t{\r\n\t\t\tscope (exit)\r\n\t\t\t{\r\n\t\t\t\tstatic foreach (s; AliasSeq !(\"or\", \"and\"))\r\n\t\t\t\t{\r\n\t\t\t\t\tforeach (i; 0..3)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tforeach (j; i + 1..3)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tmixin (format\r\n\t\t\t\t\t\t\t !(`%s[i][j] ` ~\r\n\t\t\t\t\t\t\t `>>= 1;`) (s));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tforeach (x; 0..2)\r\n\t\t\t{\r\n\t\t\t\tforeach (y; 0..2)\r\n\t\t\t\t{\r\n\t\t\t\t\tforeach (z; 0..2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (checkBit ([x, y, z]))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ta[0] |= x << b;\r\n\t\t\t\t\t\t\ta[1] |= y << b;\r\n\t\t\t\t\t\t\ta[2] |= z << b;\r\n\t\t\t\t\t\t\tcontinue bits_loop;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tassert (false);\r\n\t\t}\r\n\t\tdebug {writeln (a);}\r\n\r\n\t\tforeach (i; 3..n)\r\n\t\t{\r\n\t\t\tauto theOr = ask !(\"or\") (0, i);\r\n\t\t\tauto theAnd = ask !(\"and\") (0, i);\r\n\t\t\ta[i] = theAnd | (theOr & ~a[0]);\r\n\t\t\tdebug {writeln (a);}\r\n\t\t}\r\n\r\n\t\tsort (a);\r\n\t\twriteln (\"finish\", \" \", a[k]);\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong query(int type, int idx1, int idx2)\n{\n if (type == 0) {\n writefln(\"or %d %d\", idx1, idx2);\n stdout.flush();\n return readln.strip.to!long;\n } else {\n writefln(\"and %d %d\", idx1, idx2);\n stdout.flush();\n return readln.strip.to!long;\n }\n}\n\nlong recover_a1(long orab, long andab, long orbc, long andbc, long andac, long orac)\n{\n long ans;\n long cnt;\n foreach (a ; 0 .. 2) {\n foreach (b ; 0 .. 2) {\n foreach (c ; 0 .. 2) {\n if (andbc == (b & c) && orbc == (b | c) && andab == (a & b) && orab == (a | b) && andac == (a & c) && orac == (a | c)) {\n ans = a;\n cnt++;\n }\n }\n }\n }\n assert(cnt == 1);\n return ans;\n}\n\nlong recover_a32(long orab, long andab, long orbc, long andbc, long andac, long orac)\n{\n long ans;\n foreach (b ; 0 .. 32) {\n ans |= recover_a1((orab >> b) & 1, (andab >> b) & 1, (orbc >> b) & 1, (andbc >> b) & 1, (andac >> b) & 1, (orac >> b) & 1) << b;\n }\n return ans;\n}\n\nvoid main()\n{\n int n, k;\n readln.formattedRead!\" %d %d \"(n, k);\n long[] a_xor, a_or, a_and;\n\n foreach (i ; 0 .. n - 1) {\n int idx1 = (i + 0) % n + 1;\n int idx2 = (i + 1) % n + 1;\n long qor = query(0, idx1, idx2);\n long qand = query(1, idx1, idx2);\n a_or ~= qor;\n a_and ~= qand;\n a_xor ~= (qor - qand);\n }\n\n long orab = a_or[0];\n long andab = a_and[0];\n long orbc = a_or[1];\n long andbc = a_and[1];\n long orac = query(0, 1, 3);\n long andac = query(1, 1, 3);\n long a0 = recover_a32(orab, andab, orbc, andbc, andac, orac);\n long[] ans = [a0];\n foreach (i ; 1 .. n) {\n ans ~= ans[i - 1] ^ a_xor[i - 1];\n }\n ans.sort;\n writefln(\"finish %d\", ans[k - 1]);\n}\n"}, {"source_code": "import std.stdio, std.string;\r\nimport std.conv, std.typecons;\r\nimport std.array, std.range;\r\nimport std.math, std.algorithm;\r\n\r\nint main(string[] args)\r\n{\r\n int n, k;\r\n readf(\"%d %d\\n\", &n, &k);\r\n auto r = new int[][][](3, 3, 2);\r\n foreach (i; 1 .. 4) foreach (j; i + 1 .. 4)\r\n {\r\n writeln(\"or \", i, \" \", j);\r\n stdout.flush;\r\n r[i - 1][j - 1][0] = to!int(readln.strip);\r\n if (i == 1 && j == 3) continue;\r\n writeln(\"and \", i, \" \", j);\r\n stdout.flush;\r\n r[i - 1][j - 1][1] = to!int(readln.strip);\r\n }\r\n auto a = new int[n];\r\n foreach (i; 0 .. 30)\r\n {\r\n if (r[0][1][1] & (1 << i))\r\n {\r\n a[0] |= 1 << i;\r\n continue;\r\n }\r\n if (!(r[0][1][0] & (1 << i)) || !(r[0][2][0] & (1 << i))) continue;\r\n if (!(r[1][2][1] & (1 << i))) a[0] |= 1 << i;\r\n }\r\n foreach (i; 1 .. 3) foreach (j; 0 .. 30)\r\n {\r\n if (r[i - 1][i][1] & (1 << j)) a[i] |= 1 << j;\r\n else if ((r[i - 1][i][0] & (1 << j)) && !(a[i - 1] & (1 << j))) a[i] |= 1 << j;\r\n }\r\n foreach (i; 3 .. n)\r\n {\r\n writeln(\"or \", i, \" \", i + 1);\r\n stdout.flush;\r\n auto ro = to!int(readln.strip);\r\n writeln(\"and \", i, \" \", i + 1);\r\n stdout.flush;\r\n auto ra = to!int(readln.strip);\r\n foreach (j; 0 .. 30)\r\n {\r\n if (ra & (1 << j)) a[i] |= 1 << j;\r\n else if ((ro & (1 << j)) && !(a[i - 1] & (1 << j))) a[i] |= 1 << j;\r\n }\r\n }\r\n a.sort;\r\n writeln(\"finish \", a[k - 1]);\r\n stdout.flush;\r\n return 0;\r\n}"}], "negative_code": [{"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint[] testArray = null;\n\tauto n = testArray is null? readInt!int : cast(int)testArray.length;\n\tauto k = testArray is null? readInt!int : 1;\n\tauto or = new int[](n-1);\n\tauto nd = new int[](n-1);\n\tauto ans = new int[](n);\n\tint query(string op, int i, int j)\n\t{\n\t\tif (testArray is null)\n\t\t{\n\t\t\twriteln(op, \" \", i, \" \", j);\n\t\t\tstdout.flush;\n\t\t\treturn readInt!int;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tswitch(op)\n\t\t\t{\n\t\t\tcase \"or\":\n\t\t\t\treturn testArray[i-1] | testArray[j-1];\n\t\t\tcase \"and\":\n\t\t\t\treturn testArray[i-1] & testArray[j-1];\n\t\t\tdefault: assert(0);\n\t\t\t}\n\t\t}\n\t}\n\tauto or23 = query(\"or\", 2, 3);\n\tforeach(i; 1 .. n)\n\t{\n\t\tor[i-1] = query(\"or\", 1, i + 1);\n\t\tnd[i-1] = query(\"and\", 1, i + 1);\n\t}\n\tauto andedOrs = or.fold!((a, b) => a & b);\n\tauto oredAns = nd.fold!((a, b) => a | b);\n\tvoid solveBit(int q)\n\t{\n\t\tif (andedOrs&(1<<q))\n\t\t{\n\t\t\tif (oredAns&(1<<q))\n\t\t\t{\n\t\t\t\t// we are sure a1 at q = 1\n\t\t\t\tans[0] |= (1<<q);\n\t\t\t\tforeach(i; 1 .. n)\n\t\t\t\t{\n\t\t\t\t\tans[i] |= nd[i-1]&(1<<q);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// either 0 1 1 ... or 1 0 0 ...\n\t\t\t// check or23\n\t\t\tif (or23&(1<<q))\n\t\t\t{\n\t\t\t\t// 0 1 1...\n\t\t\t\tforeach(i; 1 .. n)\n\t\t\t\t\tans[i] |= (1<<q);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t// 1 0 0...\n\t\t\t\tans[0] |= (1<<q);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// we are sure a1 at q = 0\n\t\t\tforeach(i; 1 .. n)\n\t\t\t{\n\t\t\t\tans[i] |= or[i-1]&(1<<q);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n\tforeach(b; 0 .. 21)\n\t\tsolveBit(b);\n\tif (testArray !is null)\n\t{\n\t\twriteln(testArray);\n\t\twriteln(ans);\n\t}\n\tsort(ans);\n\twriteln(\"finish \", ans[k-1]);\n\tstdout.flush;\n}\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint[] testArray = null;\n\tauto n = testArray is null? readInt!int : cast(int)testArray.length;\n\tauto k = testArray is null? readInt!int : 1;\n\tauto or = new int[](n-1);\n\tauto nd = new int[](n-1);\n\tauto ans = new int[](n);\n\tint query(string op, int i, int j)\n\t{\n\t\tif (testArray is null)\n\t\t{\n\t\t\twriteln(op, \" \", i, \" \", j);\n\t\t\tstdout.flush;\n\t\t\treturn readInt!int;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tswitch(op)\n\t\t\t{\n\t\t\tcase \"or\":\n\t\t\t\treturn testArray[i-1] | testArray[j-1];\n\t\t\tcase \"and\":\n\t\t\t\treturn testArray[i-1] & testArray[j-1];\n\t\t\tdefault: assert(0);\n\t\t\t}\n\t\t}\n\t}\n\tauto or23 = query(\"or\", 2, 3);\n\tforeach(i; 1 .. n)\n\t{\n\t\tor[i-1] = query(\"or\", 1, i + 1);\n\t\tnd[i-1] = query(\"and\", 1, i + 1);\n\t}\n\tauto andedOrs = or.fold!((a, b) => a & b);\n\tauto oredAns = nd.fold!((a, b) => a | b);\n\tvoid solveBit(int q)\n\t{\n\t\tif (andedOrs&(1<<q))\n\t\t{\n\t\t\tif (oredAns&(1<<q))\n\t\t\t{\n\t\t\t\t// we are sure a1 at q = 1\n\t\t\t\tans[0] |= (1<<q);\n\t\t\t\tforeach(i; 1 .. n)\n\t\t\t\t{\n\t\t\t\t\tans[i] |= nd[i-1]&(1<<q);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// either 0 1 1 ... or 1 0 0 ...\n\t\t\t// check or23\n\t\t\tif (or23&(1<<q))\n\t\t\t{\n\t\t\t\t// 0 1 1...\n\t\t\t\tforeach(i; 1 .. n)\n\t\t\t\t\tans[i] |= (1<<q);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t// 1 0 0...\n\t\t\t\tans[0] |= (1<<q);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// we are sure a1 at q = 0\n\t\t\tforeach(i; 1 .. n)\n\t\t\t{\n\t\t\t\tans[i] |= or[i-1]&(1<<q);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n\tforeach(b; 0 .. 21)\n\t\tsolveBit(b);\n\tif (testArray !is null)\n\t{\n\t\twriteln(testArray);\n\t\twriteln(ans);\n\t}\n\tsort(ans);\n\tans[k-1].writeln;\n}\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong query(int type, int idx1, int idx2)\n{\n if (type == 0) {\n writefln(\"or %d %d\", idx1, idx2);\n stdout.flush();\n return readln.strip.to!long;\n } else {\n writefln(\"and %d %d\", idx1, idx2);\n stdout.flush();\n return readln.strip.to!long;\n }\n}\n\nlong recover_a1(long orab, long andab, long orbc, long andbc, long andac, long orac)\n{\n long ans;\n long cnt;\n foreach (a ; 0 .. 2) {\n foreach (b ; 0 .. 2) {\n foreach (c ; 0 .. 2) {\n if (andbc == (b & c) && orbc == (b | c) && andab == (a & b) && orab == (a | b) && andac == (a & c) && orac == (a | c)) {\n ans = a;\n cnt++;\n }\n }\n }\n }\n assert(cnt == 1);\n return ans;\n}\n\nlong recover_a32(long orab, long andab, long orbc, long andbc, long andac, long orac)\n{\n long ans;\n foreach (b ; 0 .. 32) {\n ans |= recover_a1((orab >> b) & 1, (andab >> b) & 1, (orbc >> b) & 1, (andbc >> b) & 1, (andac >> b) & 1, (orac >> b) & 1) << b;\n }\n return ans;\n}\n\nvoid main()\n{\n int n, k;\n readln.formattedRead!\" %d %d \"(n, k);\n long[] a_xor, a_or, a_and;\n\n foreach (i ; 0 .. n - 1) {\n int idx1 = (i + 0) % n + 1;\n int idx2 = (i + 1) % n + 1;\n long qor = query(0, idx1, idx2);\n long qand = query(1, idx1, idx2);\n a_or ~= qor;\n a_and ~= qand;\n a_xor ~= (qor - qand);\n }\n\n long orab = a_or[0];\n long andab = a_and[0];\n long orbc = a_or[1];\n long andbc = a_and[1];\n long orac = query(0, 1, 3);\n long andac = query(1, 1, 3);\n long a0 = recover_a32(orab, andab, orbc, andbc, andac, orac);\n long[] ans = [a0];\n foreach (i ; 1 .. n) {\n ans ~= ans[i - 1] ^ a_xor[i - 1];\n }\n writeln(ans[k - 1]);\n}\n"}], "src_uid": "7fb8b73fa2948b360644d40b7035ce4a"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int NA = -1;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta[] -= 1;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tb[] -= 1;\r\n\r\n\t\tauto p = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tp[a[i]] = i;\r\n\t\t}\r\n\t\tauto q = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tq[b[i]] = i;\r\n\t\t}\r\n\t\tauto c = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tc[p[i]] = q[i];\r\n\t\t}\r\n\r\n\t\tlong res = 0;\r\n\t\tint lo = 0;\r\n\t\tint hi = n - 1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (c[i] != NA)\r\n\t\t\t{\r\n\t\t\t\tint len = 0;\r\n\t\t\t\tint x = i;\r\n\t\t\t\twhile (c[x] != NA)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen += 1;\r\n\t\t\t\t\tint y = c[x];\r\n\t\t\t\t\tc[x] = NA;\r\n\t\t\t\t\tx = y;\r\n\t\t\t\t}\r\n\t\t\t\tlen /= 2;\r\n/*\r\n\t\t\t\t 5 4 3 4\r\n\t\t\t\t1 6 2 5 1\r\n\t\t\t\t+10 +6\r\n*/\r\n\t\t\t\tforeach (step; 0..len)\r\n\t\t\t\t{\r\n\t\t\t\t\tres += hi - lo;\r\n\t\t\t\t\tlo += 1;\r\n\t\t\t\t\thi -= 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res * 2);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new int[N]; foreach (i; 0 .. N) A[i] = readInt - 1;\n auto B = new int[N]; foreach (i; 0 .. N) B[i] = readInt - 1;\n \n auto uf = new int[N];\n uf[] = -1;\n foreach (i; 0 .. N) {\n uf.connect(A[i], B[i]);\n }\n \n int[] cs;\n foreach (r; 0 .. N) if (uf[r] < 0) {\n cs ~= -uf[r];\n }\n cs.sort.reverse;\n debug {\n writeln(\"cs = \", cs);\n }\n \n long ans;\n {\n int num;\n int l = 0, r = N - 1;\n int next() {\n return (num++ % 2 == 0) ? l++ : r--;\n }\n foreach (c; cs) {\n const cc = c / 2 * 2;\n if (cc <= 1) continue;\n const s = next();\n int u = s;\n foreach (_; 1 .. cc) {\n const v = next();\n ans += abs(u - v);\n u = v;\n }\n ans += abs(u - s);\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new int[N]; foreach (i; 0 .. N) A[i] = readInt - 1;\n auto B = new int[N]; foreach (i; 0 .. N) B[i] = readInt - 1;\n \n auto uf = new int[N];\n uf[] = -1;\n foreach (i; 0 .. N) {\n uf.connect(A[i], B[i]);\n }\n \n int[] cs;\n foreach (r; 0 .. N) if (uf[r] < 0) {\n cs ~= -uf[r];\n }\n cs.sort.reverse;\n debug {\n writeln(\"cs = \", cs);\n }\n \n long ans;\n {\n int num;\n int l = 0, r = N - 1;\n int next() {\n return (num++ % 2 == 0) ? l++ : r--;\n }\n foreach (c; cs) {\n const s = next();\n int u = s;\n foreach (_; 1 .. c) {\n const v = next();\n ans += abs(u - v);\n u = v;\n }\n ans += abs(u - s);\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new int[N]; foreach (i; 0 .. N) A[i] = readInt - 1;\n auto B = new int[N]; foreach (i; 0 .. N) B[i] = readInt - 1;\n \n auto uf = new int[N];\n uf[] = -1;\n foreach (i; 0 .. N) {\n uf.connect(A[i], B[i]);\n }\n \n int[] cs;\n foreach (r; 0 .. N) if (uf[r] < 0) {\n if (-uf[r] >= 2) {\n cs ~= -uf[r];\n }\n }\n cs.sort;\n debug {\n writeln(\"cs = \", cs);\n }\n \n long ans;\n {\n int num;\n int l = 0, r = N - 1;\n int next() {\n return (num++ % 2 == 0) ? l++ : r--;\n }\n foreach (c; cs) {\n const s = next();\n int u = s;\n foreach (_; 0 .. c - 1) {\n const v = next();\n ans += abs(u - v);\n u = v;\n }\n ans += abs(u - s);\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "4bcaa910cce687f0881a36231aa1a2c8"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,k;\n/*loop:while(read(n,k))\n\t{*/\n\tread(n,k);\n\t\tint m;\n\t\tread(m);\n\t\tauto g=new pii[][n+1];\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v,c;\n\t\t\tread(u,v,c);\n\t\t\tg[u]~=mp(v,c);\n\t\t\t//g[v]~=mp(u,c);\n\t\t}\n\t\tauto dp=new int[81][81][81][81];\n\t\tint go(int v,int l,int r,int h)\n\t\t{\n\t\t\tif(h==k)return 0;\n\t\t\tif(dp[v][l][r][h])return dp[v][l][r][h];\n\t\t\tint ans=1000000;\n\t\t\tforeach(x; g[v]) {\n\t\t\t\tif(x.fi<l || x.fi>r)continue;\n\t\t\t\tif(x.fi<v)\n\t\t\t\t{\n\t\t\t\t\tans=min(ans,x.se+go(x.fi,l,v-1,h+1));\n\t\t\t\t}\n\t\t\t\telse ans=min(ans,x.se+go(x.fi,v+1,r,h+1));\n\t\t\t}\n\t\t\treturn dp[v][l][r][h]=ans;\n\t\t}\n\t\tint ans=1000000;\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tans=min(ans,go(i,1,n,1));\n\t\t}\n\t\tif(ans>=1000000)writeln(-1);\n\t\telse writeln(ans);\n\t//}\n}", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int infinity = int.max / 4;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tn += 2;\n\t\tint m;\n\t\treadf (\" %s\", &m);\n\t\tauto u = new int [m];\n\t\tauto v = new int [m];\n\t\tauto c = new int [m];\n\t\tauto d = new int [] [] (n, n);\n\t\tforeach (ref dLine; d)\n\t\t{\n\t\t\tdLine[] = infinity;\n\t\t}\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\treadf (\" %s %s %s\", &u[i], &v[i], &c[i]);\n\t\t\td[u[i]][v[i]] = min (d[u[i]][v[i]], c[i]);\n\t\t}\n\n\t\tauto f = new int [2] [] [] [] (2, n, n);\n\t\tint b = 0;\n\t\tforeach (ref fLine; f[b])\n\t\t{\n\t\t\tfLine[] = [infinity, infinity];\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tf[b][0][i][1] = 0;\n\t\t\tf[b][i][n - 1][0] = 0;\n\t\t}\n\n\t\tforeach (step; 0..k - 1)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tforeach (ref fLine; f[b])\n\t\t\t{\n\t\t\t\tfLine[] = [infinity, infinity];\n\t\t\t}\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; i..n)\n\t\t\t\t{\n\t\t\t\t\t// from [i* -- j]\n\t\t\t\t\tint cur0 = f[!b][i][j][0];\n\t\t\t\t\t// from [i -- *j]\n\t\t\t\t\tint cur1 = f[!b][i][j][1];\n\t\t\t\t\tdebug {writeln (step, \" \", i, \" \",\n\t\t\t\t\t j, \": \", cur0, \" \", cur1);}\n\t\t\t\t\tif (cur0 != infinity)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (p; i + 1..j)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// to [i -- *p]\n\t\t\t\t\t\t\tf[b][i][p][1] =\n\t\t\t\t\t\t\t min (f[b][i][p][1],\n\t\t\t\t\t\t\t cur0 + d[i][p]);\n\t\t\t\t\t\t\t// to [p* -- j]\n\t\t\t\t\t\t\tf[b][p][j][0] =\n\t\t\t\t\t\t\t min (f[b][p][j][0],\n\t\t\t\t\t\t\t cur0 + d[i][p]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (cur1 != infinity)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (p; i + 1..j)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// to [p* -- j]\n\t\t\t\t\t\t\tf[b][p][j][0] =\n\t\t\t\t\t\t\t min (f[b][p][j][0],\n\t\t\t\t\t\t\t cur1 + d[j][p]);\n\t\t\t\t\t\t\t// to [i -- *p]\n\t\t\t\t\t\t\tf[b][i][p][1] =\n\t\t\t\t\t\t\t min (f[b][i][p][1],\n\t\t\t\t\t\t\t cur1 + d[j][p]);\n\t\t\t\t\t\t}\n\t \t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint res = infinity;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tres = min (res, f[b][i][j][0], f[b][i][j][1]);\n\t\t\t}\n\t\t}\n\t\tif (res == infinity)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tauto dp=new int[81][81][81][81];\n\tint n,k;\nloop:while(read(n,k))\n\t{\n\t\tint m;\n\t\tread(m);\n\t\tauto g=new pii[][n+1];\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v,c;\n\t\t\tread(u,v,c);\n\t\t\tg[u]~=mp(v,c);\n\t\t\t//g[v]~=mp(u,c);\n\t\t}\n\t\t\n\t\tint go(int v,int l,int r,int h)\n\t\t{\n\t\t\tif(h==k)return 0;\n\t\t\tif(dp[v][l][r][h])return dp[v][l][r][h];\n\t\t\tint ans=1000000;\n\t\t\tforeach(x; g[v]) {\n\t\t\t\tif(x.fi<l || x.fi>r)continue;\n\t\t\t\tif(x.fi<v)\n\t\t\t\t{\n\t\t\t\t\tans=min(ans,x.se+go(x.fi,l,v-1,h+1));\n\t\t\t\t}\n\t\t\t\telse ans=min(ans,x.se+go(x.fi,v+1,r,h+1));\n\t\t\t}\n\t\t\treturn dp[v][l][r][h]=ans;\n\t\t}\n\t\tint ans=1000000;\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tans=min(ans,go(i,1,n,1));\n\t\t}\n\t\tif(ans>=1000000)writeln(-1);\n\t\telse writeln(ans);\n\t}\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tauto dp=new int[81][81][81][81];\n\tint n,k;\n\tauto g=new pii[][80+1];\nloop:while(read(n,k))\n\t{\n\t\tint m;\n\t\tread(m);\n\t\t\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v,c;\n\t\t\tread(u,v,c);\n\t\t\tg[u]~=mp(v,c);\n\t\t\t//g[v]~=mp(u,c);\n\t\t}\n\t\t\n\t\tint go(int v,int l,int r,int h)\n\t\t{\n\t\t\tif(h==k)return 0;\n\t\t\tif(dp[v][l][r][h])return dp[v][l][r][h];\n\t\t\tint ans=1000000;\n\t\t\tforeach(x; g[v]) {\n\t\t\t\tif(x.fi<l || x.fi>r)continue;\n\t\t\t\tif(x.fi<v)\n\t\t\t\t{\n\t\t\t\t\tans=min(ans,x.se+go(x.fi,l,v-1,h+1));\n\t\t\t\t}\n\t\t\t\telse ans=min(ans,x.se+go(x.fi,v+1,r,h+1));\n\t\t\t}\n\t\t\treturn dp[v][l][r][h]=ans;\n\t\t}\n\t\tint ans=1000000;\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tans=min(ans,go(i,1,n,1));\n\t\t}\n\t\tif(ans>=1000000)writeln(-1);\n\t\telse writeln(ans);\n\t}\n}"}], "negative_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,k;\nloop:while(read(n,k))\n\t{\n\t\tint m;\n\t\tread(m);\n\t\tauto g=new pii[][n+1];\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v,c;\n\t\t\tread(u,v,c);\n\t\t\tg[u]~=mp(v,c);\n\t\t\tg[v]~=mp(u,c);\n\t\t}\n\t\tauto dp=new int[80][80][80][80];\n\t\tint go(int v,int l,int r,int h)\n\t\t{\n\t\t\tif(h==k)return 0;\n\t\t\tif(dp[v][l][r][h])return dp[v][l][r][h];\n\t\t\tint ans=1000000;\n\t\t\tforeach(x; g[v]) {\n\t\t\t\tif(x.fi<l || x.fi>r)continue;\n\t\t\t\tif(x.fi<v)\n\t\t\t\t{\n\t\t\t\t\tans=min(ans,x.se+go(x.fi,l,v-1,h+1));\n\t\t\t\t}\n\t\t\t\telse ans=min(ans,x.se+go(x.fi,v+1,r,h+1));\n\t\t\t}\n\t\t\treturn dp[v][l][r][h]=ans;\n\t\t}\n\t\tint ans=1000000;\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tans=min(ans,go(i,1,n,1));\n\t\t}\n\t\tif(ans>=1000000)writeln(-1);\n\t\telse writeln(ans);\n\t}\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int infinity = int.max / 4;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tn += 2;\n\t\tint m;\n\t\treadf (\" %s\", &m);\n\t\tauto u = new int [m];\n\t\tauto v = new int [m];\n\t\tauto c = new int [m];\n\t\tauto d = new int [] [] (n, n);\n\t\tforeach (ref dLine; d)\n\t\t{\n\t\t\tdLine[] = infinity;\n\t\t}\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\treadf (\" %s %s %s\", &u[i], &v[i], &c[i]);\n\t\t\td[u[i]][v[i]] = min (d[u[i]][v[i]], c[i]);\n\t\t}\n\n\t\tauto f = new int [2] [] [] [] (2, n, n);\n\t\tint b = 0;\n\t\tforeach (ref fLine; f[b])\n\t\t{\n\t\t\tfLine[] = [infinity, infinity];\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tf[b][0][i][1] = 0;\n\t\t\tf[b][i][n - 1][0] = 0;\n\t\t}\n\n\t\tforeach (step; 0..k - 1)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tforeach (ref fLine; f[b])\n\t\t\t{\n\t\t\t\tfLine[] = [infinity, infinity];\n\t\t\t}\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; i..n)\n\t\t\t\t{\n\t\t\t\t\t// from [i* -- j]\n\t\t\t\t\tint cur0 = f[!b][i][j][0];\n\t\t\t\t\t// from [i -- *j]\n\t\t\t\t\tint cur1 = f[!b][i][j][1];\n\t\t\t\t\tdebug {writeln (step, \" \", i, \" \",\n\t\t\t\t\t j, \": \", cur0, \" \", cur1);}\n\t\t\t\t\tif (cur0 != infinity)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (p; i + 1..j)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// to [i -- *p]\n\t\t\t\t\t\t\tf[b][i][p][1] =\n\t\t\t\t\t\t\t min (f[b][i][p][1],\n\t\t\t\t\t\t\t cur0 + d[i][p]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (cur1 != infinity)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (p; i + 1..j)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// to [p* -- j]\n\t\t\t\t\t\t\tf[b][p][j][0] =\n\t\t\t\t\t\t\t min (f[b][p][j][0],\n\t\t\t\t\t\t\t cur1 + d[j][p]);\n\t\t\t\t\t\t}\n\t \t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint res = infinity;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tres = min (res, f[b][i][j][0], f[b][i][j][1]);\n\t\t\t}\n\t\t}\n\t\tif (res == infinity)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "aa0e8640f3930cfde32d98b82e789ff3"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m;\n @(\"n\") string[] str;\n\n void solve(long tc = -1)\n {\n auto pairs = appender!(Tuple!(long, long)[])();\n string pal = \"\";\n fori:foreach(i; 0 .. n)\n {\n forj:foreach(j; i + 1 .. n)\n {\n if (iota(0, m).all!(k => str.at(i).at(k) == str.at(j).at(m - 1 - k)))\n {\n pairs.put(tuple(i, j));\n continue fori;\n }\n }\n if (iota(0, m).all!(k => str.at(i).at(k) == str.at(i).at(m - 1 - k)))\n pal = str.at(i);\n }\n auto res = pairs[].fold!((curr, pair) => str.at(pair[0]) ~ curr ~ str.at(pair[1]))(pal).array.toUTF8;\n writeln(res.length);\n writeln(res);\n }\n}\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, string))\n {\n static assert(isDynamicArray!(typeOfField)\n , \" A field with dimension initialization UDA must be a dynamic array.\");\n enum uda = getUDAs!(fieldSymbol, string)[0];\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint, m = rint;\n\n\tbool[string] sz;\n\tstring[] us;\n\tstring v;\n\tforeach(i; 0 .. n){\n\t\tstring s = readln.chomp;\n\t\tstring t = \"\";\n\t\tforeach_reverse(c; s) t ~= c;\n\t\tif(t in sz) us ~= s;\n\t\telse if(s == t) v = s;\n\t\tsz[s] = 1;\n\t}\n\n\tstring ans;\n\tforeach(u; us) ans ~= u;\n\tans ~= v;\n\tforeach_reverse(u; us) foreach_reverse(c; u) ans ~= c;\n\n\t(us.length * 2 * m + v.length).writeln;\n\tans.writeln;\n\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto s = new string[](n);\n\tint[string] set, set2;\n\tstring ans1, ans2;\n\tforeach (i; 0..n)\n\t{\n\t\ts[i] = RD!string;\n\t\tauto tt = s[i].dup;\n\t\ttt.reverse;\n\t\tauto t = tt.idup;\n\t\tif (set.get(s[i], 0))\n\t\t{\n\t\t\tans1 ~= s[i];\n\t\t\tans2 = (t ~ ans2).idup;\n\t\t\t--set[s[i]];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbool ok = true;\n\t\t\tforeach (j; 0..m/2)\n\t\t\t{\n\t\t\t\tif (s[i][j] != s[i][$-j-1])\n\t\t\t\t\tok = false;\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t\t++set2[s[i]];\n\t\t\telse\n\t\t\t\t++set[t];\n\t\t}\n\t}\n\n\tstring bestKey;\n\tlong cnt;\n\tforeach (key; set2.keys)\n\t{\n\t\tif (set2[key] > cnt)\n\t\t{\n\t\t\tcnt = set2[key];\n\t\t\tbestKey = key;\n\t\t}\n\t}\n\tauto ans = ans1;\n\tforeach (i; 0..cnt)\n\t{\n\t\tans ~= bestKey;\n\t}\n\tans ~= ans2;\n\twriteln(ans.length);\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint, m = rint;\n\n\tbool[string] sz;\n\tstring[] us;\n\tstring v;\n\tforeach(i; 0 .. n){\n\t\tstring s = readln.chomp;\n\t\tstring t = \"\";\n\t\tforeach_reverse(c; s) t ~= c;\n\t\tif(t in sz) us ~= s;\n\t\telse if(s == t) v = s;\n\t\tsz[s] = 1;\n\t}\n\n\tstring ans;\n\tforeach(u; us) ans ~= u;\n\tans ~= v;\n\tforeach(u; us) foreach_reverse(c; u) ans ~= c;\n\n\t(us.length * 2 * m + v.length).writeln;\n\tans.writeln;\n\n}"}], "src_uid": "554115bec46bb436a0a1ddf8c05a2d08"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;\n\nalias Path = Tuple!(int, \"to\", bool, \"c\");\n\nPath[][10^^5] GP;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n int root;\n foreach (int i; 0..N) {\n auto pc = readln.split.to!(int[]);\n if (pc[0] == -1) {\n root = i;\n } else {\n GP[pc[0]-1] ~= Path(i, pc[1] == 1);\n }\n }\n\n auto ss = [Path(root, false)];\n int[] rs;\n while (!ss.empty) {\n auto head = ss[0];\n ss = ss[1..$];\n if (head.c) {\n bool del = true;\n foreach (path; GP[head.to]) {\n if (!path.c) del = false;\n ss ~= path;\n }\n if (del) rs ~= head.to + 1;\n } else {\n ss ~= GP[head.to];\n }\n }\n sort(rs);\n writeln(rs.empty ? \"-1\" : rs.to!(string[]).join(\" \"));\n}", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!uint;\n auto p = new int[n+1];\n auto c = new int[n+1];\n auto good = new bool[n+1];\n debug stderr.writeln (n);\n foreach (i; 1 .. n+1) {\n p[i] = r.next!int;\n c[i] = r.next!uint;\n debug stderr.writeln (p[i], ' ', c[i]);\n if (!c[i]) {\n if (p[i] >= 0) {\n good[p[i]] = true;\n }\n }\n }\n int[] z;\n foreach (i; 1 .. n + 1) {\n if (!good[i] && c[i]) {\n z ~= i;\n }\n }\n if (z.empty) writeln (-1);\n else writefln (\"%(%s %)\", z);\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;\n\nalias Path = Tuple!(int, \"to\", bool, \"c\");\n\nPath[][10^^5] GP;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n int root;\n foreach (int i; 0..N) {\n auto pc = readln.split.to!(int[]);\n if (pc[0] == -1) {\n root = i;\n } else {\n GP[pc[0]-1] ~= Path(i, pc[1] == 1);\n }\n }\n\n auto ss = [Path(root, false)];\n int[] rs;\n while (!ss.empty) {\n auto head = ss[0];\n ss = ss[1..$];\n if (head.c) {\n bool del = true;\n foreach (path; GP[head.to]) {\n if (!path.c) del = false;\n ss ~= path;\n }\n if (del) rs ~= head.to + 1;\n } else {\n ss ~= GP[head.to];\n }\n }\n writeln(rs.empty ? \"-1\" : rs.to!(string[]).join(\" \"));\n}"}], "src_uid": "1b975c5a13a2ad528b668a7c68c089f6"} {"source_code": "import std.algorithm, std.stdio;\n\nlong merge (int [] a, int [] b, int [] c)\n{\n\tlong res;\n\tforeach (ref x; c)\n\t{\n\t\tif (a.length && (!b.length || a[0] <= b[0]))\n\t\t{\n\t\t\tx = a[0];\n\t\t\ta = a[1..$];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tres += a.length;\n\t\t\tx = b[0];\n\t\t\tb = b[1..$];\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\n\treadf (\" %s\", &n);\n\tint m = 1 << n;\n\tauto a = new int [m];\n\tauto b = new int [m];\n\tforeach (ref x; a)\n\t\treadf (\" %s\", &x);\n\n\tauto s = new long [2] [n + 1];\n\tlong res;\n\tforeach (i; 0..n)\n\t{\n\t\tint p = 1 << i;\n\t\tint lo, me, hi;\n\t\tfor (lo = 0; lo < m; lo = hi)\n\t\t{\n\t\t\tme = lo + p;\n\t\t\thi = me + p;\n\t\t\ts[i + 1][0] += merge (a[lo..me], a[me..hi], b[lo..hi]);\n\t\t\ts[i + 1][1] += merge (a[me..hi], a[lo..me], b[lo..hi]);\n\t\t\ta[lo..hi] = b[lo..hi];\n\t\t}\n\t\tres += s[i + 1][0];\n\t}\n\n\tint q;\n\treadf (\" %s\", &q);\n\tforeach (r; 0..q)\n\t{\n\t\tint x;\n\t\tfor (readf (\" %s\", &x); x; x--)\n\t\t{\n\t\t\tres -= s[x][0];\n\t\t\tswap (s[x][0], s[x][1]);\n\t\t\tres += s[x][0];\n }\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nlong merge (int [] a, int [] b, int [] c)\n{\n\tlong res = 0;\n\tforeach (p; 0..c.length)\n\t{\n\t\tif (a.length > 0 && (b.length == 0 || a[0] <= b[0]))\n\t\t{\n\t\t\tc[p] = a[0];\n\t\t\ta = a[1..$];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tres += cast (long) (a.length);\n\t\t\tc[p] = b[0];\n\t\t\tb = b[1..$];\n\t\t}\n\t\tp++;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint m = 1 << n;\n\t\tauto a = new int [m];\n\t\tauto b = new int [m];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\tlong [2] [] s = new long [2] [n + 1];\n\t\ts[] = [0, 0];\n\t\tlong res = s[0][0];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint p = 1 << i;\n\t\t\tfor (int k = 0; k < m; k += p * 2)\n\t\t\t{\n\t\t\t\ts[i + 1][0] += merge (a[k..k + p],\n\t\t\t\t a[k + p..k + p * 2],\n\t\t\t\t b[k..k + p * 2]);\n\t\t\t\ts[i + 1][1] += merge (a[k + p..k + p * 2],\n\t\t\t\t a[k..k + p],\n\t\t\t\t b[k..k + p * 2]);\n\t\t\t\ta[k..k + p * 2] = b[k..k + p * 2];\n\t\t\t}\n\t\t\tres += s[i + 1][0];\n\t\t\tdebug {writeln (s[i + 1]);}\n\t\t\tdebug {writeln (a);}\n\t\t}\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tfor ( ; x >= 0; x--)\n\t\t\t{\n\t\t\t\tres -= s[x][0];\n\t\t\t\tswap (s[x][0], s[x][1]);\n\t\t\t\tres += s[x][0];\n\t }\n\t\t\twriteln (res);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nlong merge (int [] a, int [] b, int [] c)\n{\n\tlong res = 0;\n\tforeach (p; 0..c.length)\n\t{\n\t\tif (a.length > 0 && (b.length == 0 || a[0] <= b[0]))\n\t\t{\n\t\t\tc[p] = a[0];\n\t\t\ta = a[1..$];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tres += cast (long) (a.length);\n\t\t\tc[p] = b[0];\n\t\t\tb = b[1..$];\n\t\t}\n\t\tp++;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint m = 1 << n;\n\t\tauto a = new int [m];\n\t\tauto b = new int [m];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\tlong [2] [] s = new long [2] [n + 1];\n\t\ts[] = [0, 0];\n\t\tlong res = s[0][0];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint p = 1 << i;\n\t\t\tfor (int k = 0; k < m; k += p * 2)\n\t\t\t{\n\t\t\t\ts[i + 1][0] += merge (a[k..k + p], a[k + p..k + p * 2], b[k..k + p * 2]);\n\t\t\t\ts[i + 1][1] += merge (a[k + p..k + p * 2], a[k..k + p], b[k..k + p * 2]);\n\t\t\t\ta[k..k + p * 2] = b[k..k + p * 2];\n\t\t\t}\n\t\t\tres += s[i + 1][0];\n\t\t}\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tfor ( ; x >= 0; x--)\n\t\t\t{\n\t\t\t\tres -= s[x][0];\n\t\t\t\tswap (s[x][0], s[x][1]);\n\t\t\t\tres += s[x][0];\n\t }\n\t\t\twriteln (res);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nlong merge (int [] a, int [] b, int [] c)\n{\n\tlong res;\n\tforeach (ref x; c)\n\t{\n\t\tif (a.length && (!b.length || a[0] <= b[0]))\n\t\t{\n\t\t\tx = a[0];\n\t\t\ta = a[1..$];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tres += a.length;\n\t\t\tx = b[0];\n\t\t\tb = b[1..$];\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\n\treadf (\" %s\", &n);\n\tint m = 1 << n;\n\tauto a = new int [m];\n\tauto b = new int [m];\n\tforeach (ref x; a)\n\t\treadf (\" %s\", &x);\n\n\tlong [2] [] s = new long [2] [n + 1];\n\tlong res;\n\tforeach (i; 0..n)\n\t{\n\t\tint p = 1 << i;\n\t\tint lo, me, hi;\n\t\tfor (lo = 0; lo < m; lo = hi)\n\t\t{\n\t\t\tme = lo + p;\n\t\t\thi = me + p;\n\t\t\ts[i + 1][0] += merge (a[lo..me], a[me..hi], b[lo..hi]);\n\t\t\ts[i + 1][1] += merge (a[me..hi], a[lo..me], b[lo..hi]);\n\t\t\ta[lo..hi] = b[lo..hi];\n\t\t}\n\t\tres += s[i + 1][0];\n\t}\n\n\tint q;\n\treadf (\" %s\", &q);\n\tforeach (r; 0..q)\n\t{\n\t\tint x;\n\t\tfor (readf (\" %s\", &x); x; x--)\n\t\t{\n\t\t\tres -= s[x][0];\n\t\t\tswap (s[x][0], s[x][1]);\n\t\t\tres += s[x][0];\n }\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "ea7f8bd397f80ba7d3add6f9609dcc4a"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto p = RD!string;\n\t\tauto h = RD!string;\n\t\tauto cnt1 = new int[](26);\n\t\tforeach (c; p)\n\t\t\t++cnt1[c-'a'];\n\t\n\t\tauto cnt2 = new int[][](h.length+1, 26);\n\t\tforeach (i, c; h)\n\t\t{\n\t\t\tcnt2[i+1] = cnt2[i].dup;\n\t\t\t++cnt2[i+1][c-'a'];\n\t\t}\n\t\tforeach (i; p.length..h.length+1)\n\t\t{\n\t\t\tbool ok = true;\n\t\t\tforeach (j; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt2[i][j] - cnt2[i-p.length][j] != cnt1[j])\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t{\n\t\t\t\tans[ti] = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n\n auto A = new int[](26);\n auto B = new int[](26);\n\n bool ok() {\n return 26.iota.map!(i => A[i] >= B[i]).all;\n }\n\n while (T--) {\n A[] = 0;\n B[] = 0;\n auto P = readln.chomp;\n auto S = readln.chomp;\n if (P.length > S.length) {\n writeln(\"NO\");\n continue;\n }\n foreach (p; P) A[p-'a'] += 1;\n foreach (i; 0..P.length) B[S[i]-'a'] += 1;\n if (ok) {\n writeln(\"YES\");\n continue;\n }\n bool hoge = false;\n foreach (i; P.length..S.length) {\n B[S[i]-'a'] += 1;\n B[S[i-P.length.to!int]-'a'] -= 1;\n if (ok) {\n writeln(\"YES\");\n hoge = true;\n break;\n }\n }\n if (!hoge) {\n writeln(\"NO\");\n }\n }\n}\n"}], "negative_code": [], "src_uid": "48151011c3d380ab303ae38d0804176a"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.string;\nimport std.array;\nimport std.conv;\nimport std.math;\n\nalias Pair = Tuple!(int, q{a}, int, q{b});\n\nvoid main() {\n int n, m;\n readf(\" %s %s\", &n, &m);\n Pair[] edges;\n foreach (i; 0..m) {\n int u, v;\n readf(\" %s %s\", &u, &v);\n u--; v--;\n edges ~= Pair(u, v);\n }\n\n bool can(int x) {\n auto adj = new int[][](n);\n auto inDegree = new int[n];\n foreach (i; 0..x) {\n adj[edges[i].a] ~= edges[i].b;\n inDegree[edges[i].b]++;\n }\n\n int cur = -1;\n int visited = 0;\n foreach (i; 0..n) {\n if (inDegree[i] == 0) {\n if (cur != -1) {\n return false;\n }\n cur = i;\n }\n }\n\n while (visited < n && cur != -1) {\n int next = -1;\n foreach (v; adj[cur]) {\n inDegree[v]--;\n if (inDegree[v] == 0) {\n if (next != -1) {\n return false;\n }\n next = v;\n }\n }\n visited++;\n cur = next;\n }\n\n return visited == n;\n }\n \n int lo = -1, hi = m + 1;\n while (lo + 1 < hi) {\n int mid = (lo + hi) >> 1;\n if (can(mid)) hi = mid;\n else lo = mid;\n }\n\n writeln(hi == m + 1 ? -1 : hi);\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\tint m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [int] [n];\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u][v] = i;\n\t\t}\n\n\t\tauto b = new bool [n];\n\t\tb[] = false;\n\t\tint [] order;\n\t\tint cur = 0;\n\n\t\tvoid recur (int u)\n\t\t{\n\t\t\tif (b[u])\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tb[u] = true;\n\t\t\tforeach (k, v; a[u])\n\t\t\t{\n\t\t\t\trecur (k);\n\t\t\t}\n\t\t\torder ~= u;\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\trecur (i);\n\t\t}\n\n\t\tassert (order.length == n);\n\t\tint res = 0;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tauto t = order[i - 1] in a[order[i]];\n\t\t\tif (t is null)\n\t\t\t{\n\t\t\t\tres = m + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres = max (res, (*t) + 1);\n\t\t\t}\n\t\t}\n\n\t\tif (res > m)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "5337df1fb8a9b96ab7b66aa197a5b910"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto u = RD;\r\n\t\tauto v = RD;\r\n\t\tauto a = RDA;\r\n\r\n\t\tbool ok;\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tauto d = a[i] - a[i-1];\r\n\t\t\tif (d.abs > 1)\r\n\t\t\t\tok = true;\r\n\t\t}\r\n\t\tif (ok) continue;\r\n\r\n\t\tbool[long] used;\r\n\t\tforeach (i; 0..n)\r\n\t\t\tused[a[i]] = true;\r\n\t\tif (used.length == 1)\r\n\t\t\tans[ti] = min(v * 2, u + v);\r\n\t\telse\r\n\t\t\tans[ti] = min(u, v);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const numCases = readInt();\r\n foreach (caseId; 0 .. numCases) {\r\n const N = readInt();\r\n const U = readLong();\r\n const V = readLong();\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt();\r\n }\r\n \r\n bool bad = true;\r\n bool same = true;\r\n foreach (i; 0 .. N - 1) {\r\n bad = bad && (abs(A[i + 1] - A[i]) <= 1);\r\n same = same && (abs(A[i + 1] - A[i]) <= 0);\r\n }\r\n long ans;\r\n if (bad) {\r\n if (same) {\r\n ans = min(V + V, V + U);\r\n } else {\r\n ans = min(V, U);\r\n }\r\n } else {\r\n ans = 0;\r\n }\r\n writeln(ans);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, u, v;\r\n\t\treadf !(\" %s %s %s\") (n, u, v);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto d = 0;\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\td = max (d, abs (a[i] - a[i - 1]));\r\n\t\t}\r\n\t\tint res = 0;\r\n\t\tif (d <= 0)\r\n\t\t{\r\n\t\t\tres += v;\t\r\n\t\t}\r\n\t\tif (d <= 1)\r\n\t\t{\r\n\t\t\tres += min (u, v);\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "7f502f2fd150a2ded948826960d123cd"} {"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\twriteln(a+b);\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\treadln.splitter.map !(to !(int)).sum.writeln;\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main() {\n int t; scan(t);\n foreach (_; 0..t) {\n int a, b; scan(a, b);\n writeln(a + b);\n }\n}\n\nvoid scan(T...)(ref T a) {\n string[] ss = readln.split;\n foreach (i, t; T) a[i] = ss[i].to!t;\n}\nT read(T=string)() { return readln.chomp.to!T; }\nT[] reads(T)() { return readln.split.to!(T[]); }\nalias readints = reads!int;\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main() {\n \n}\n\n"}], "src_uid": "27ddccc777ef9040284ab6314cbd70e7"} {"source_code": "import std;\n\nuint\nquery (size_t index) {\n writefln(\"? %s\", index + 1);\n stdout.flush;\n\n uint response;\n readf(\" %s\", response);\n return response - 1;\n}\n\nvoid\nprint(in uint[] p) {\n writefln(\"! %(%s %)\\n\", p);\n stdout.flush;\n}\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = () { uint n; readf!\" %s\"(n); return n; }();\n\n uint[] p = new uint[n];\n\n uint steps = 0;\n foreach (i, val; p)\n if (val == 0) {\n uint[] vec;\n uint start = query(i);\n ++ steps;\n do {\n vec ~= query(i);\n ++ steps;\n } while(vec.back != start);\n\n immutable needToShift = (steps - 1) % vec.length;\n //stderr.writeln(\"LOG:\", vec, \" -- \", needToShift);\n\n vec = vec[$ - needToShift .. $] ~ vec[0 .. $ - needToShift];\n //stderr.writeln(\"LOG:\", vec, \" -- \", needToShift);\n\n do {\n p[i] = vec.front + 1;\n i = vec.front;\n vec.popFront;\n } while (!vec.empty);\n }\n print(p);\n }\n}\n// \"\"\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint ask(int i) {\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n int x = read!int;\r\n return x;\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n int count = 0;\r\n auto known = new bool[N+1];\r\n auto cycles = new int[][0];\r\n int c = 1;\r\n int[] ks;\r\n int[] cs;\r\n int nasked = 0;\r\n for (int k = 0; count < N; k++) {\r\n while (known[c]) c++;\r\n cycles ~= new int[0];\r\n ks ~= nasked;\r\n cs ~= c;\r\n while (true) {\r\n int x = ask(c);\r\n nasked++;\r\n cycles[k] ~= x;\r\n if (known[x]) {\r\n break;\r\n }\r\n known[x] = true;\r\n count++;\r\n }\r\n }\r\n\r\n int[] P = new int[N + 1]; P[] = -1;\r\n foreach (i, cycle; cycles) {\r\n //writeln(\"cycle: \", cycle);\r\n int n = cast(int)(cycle.length) - 1;\r\n int k = ks[i];\r\n //writeln(\"k: \", k);\r\n int s = (N*n + n - k) % n + 1;\r\n //writeln(\"s: \", s);\r\n c = cs[i];\r\n for (int j = 0; j < n; j++) {\r\n P[c] = cycle[s];\r\n //writeln(\"--> \", [c, cycle[s]]);\r\n c = cycle[s];\r\n s = (s == n ? 1 : s + 1);\r\n }\r\n }\r\n //writeln(cycles);\r\n //writeln(ks);\r\n writefln(\"! %(%s %)\", P[1 .. $]);\r\n stdout.flush;\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto b = new bool [n];\r\n\t\tauto p = new int [n];\r\n\r\n\t\tint ask (int pos)\r\n\t\t{\r\n\t\t\twriteln (\"? \", pos + 1);\r\n\t\t\tstdout.flush ();\r\n\t\t\tauto res = readln.strip.to !(int);\r\n\t\t\treturn res - 1;\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!b[i])\r\n\t\t\t{\r\n\t\t\t\tint [] q;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tq ~= ask (i);\r\n\t\t\t\t\tb[q.back] = true;\r\n\t\t\t\t}\r\n\t\t\t\twhile (q.length < 2 || q.back != q.front);\r\n\t\t\t\tforeach (j; 0..q.length - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto u = q[j];\r\n\t\t\t\t\tauto v = q[j + 1];\r\n\t\t\t\t\tp[u] = v;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"!%( %s%)\") (p.map !(q{a + 1}));\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto b = new bool [n];\r\n\t\tauto p = new int [n];\r\n\r\n\t\tint ask (int pos)\r\n\t\t{\r\n\t\t\twriteln (\"? \", pos + 1);\r\n\t\t\tstdout.flush ();\r\n\t\t\tauto res = readln.strip.to !(int);\r\n\t\t\treturn res - 1;\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!b[i])\r\n\t\t\t{\r\n\t\t\t\tint [] q;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tq ~= ask (i);\r\n\t\t\t\t\tb[q.back] = true;\r\n\t\t\t\t}\r\n\t\t\t\twhile (q.length < 2 || q.back != q.front);\r\n\t\t\t\tforeach (j; 0..q.length - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto u = q[j];\r\n\t\t\t\t\tauto v = q[j + 1];\r\n\t\t\t\t\tp[v] = u;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"!%( %s%)\") (p.map !(q{a + 1}));\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto b = new bool [n];\r\n\t\tauto p = new int [n];\r\n\r\n\t\tint ask (int pos)\r\n\t\t{\r\n\t\t\twriteln (pos + 1);\r\n\t\t\tstdout.flush ();\r\n\t\t\tauto res = readln.strip.to !(int);\r\n\t\t\treturn res - 1;\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!b[i])\r\n\t\t\t{\r\n\t\t\t\tint [] q;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tq ~= ask (i);\r\n\t\t\t\t\tb[q.back] = true;\r\n\t\t\t\t}\r\n\t\t\t\twhile (q.length < 2 || q.back != q.front);\r\n\t\t\t\tq.popBack ();\r\n\t\t\t\tforeach (j; 0..q.length)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto u = q[j];\r\n\t\t\t\t\tauto v = q[(j + 1) % $];\r\n\t\t\t\t\tp[v] = u;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"!%( %s%)\") (p.map !(q{a + 1}));\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto b = new bool [n];\r\n\t\tauto p = new int [n];\r\n\t\tint step = 0;\r\n\r\n\t\tint ask (int pos)\r\n\t\t{\r\n\t\t\twriteln (pos + 1);\r\n\t\t\tstdout.flush ();\r\n\t\t\tstep += 1;\r\n\t\t\tauto res = readln.strip.to !(int);\r\n\t\t\treturn res - 1;\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!b[i])\r\n\t\t\t{\r\n\t\t\t\tint k = step;\r\n\t\t\t\tint [] q;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tq ~= ask (i);\r\n\t\t\t\t\tb[q.back] = true;\r\n\t\t\t\t}\r\n\t\t\t\twhile (q.length < 2 || q.back != q.front);\r\n\t\t\t\tq.popBack ();\r\n\t\t\t\tk = (-k + 1) % q.length.to !(int);\r\n\t\t\t\tk = (k + q.length) % q.length.to !(int);\r\n\t\t\t\tforeach (j; 0..q.length)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto u = q[j];\r\n\t\t\t\t\tauto v = q[(j + 1) % $];\r\n\t\t\t\t\tp[u] = v;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"!%( %s%)\") (p.map !(q{a + 1}));\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto b = new bool [n];\r\n\t\tauto p = new int [n];\r\n\t\tint step = 0;\r\n\r\n\t\tint ask (int pos)\r\n\t\t{\r\n\t\t\twriteln (pos + 1);\r\n\t\t\tstdout.flush ();\r\n\t\t\tstep += 1;\r\n\t\t\tauto res = readln.strip.to !(int);\r\n\t\t\treturn res - 1;\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!b[i])\r\n\t\t\t{\r\n\t\t\t\tint k = step;\r\n\t\t\t\tint [] q;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tq ~= ask (i);\r\n\t\t\t\t\tb[q.back] = true;\r\n\t\t\t\t}\r\n\t\t\t\twhile (q.length < 2 || q.back != q.front);\r\n\t\t\t\tq.popBack ();\r\n\t\t\t\tk = (-k + 1) % q.length.to !(int);\r\n\t\t\t\tk = (k + q.length) % q.length.to !(int);\r\n\t\t\t\tforeach (j, c; q)\r\n\t\t\t\t{\r\n\t\t\t\t\tp[(j + k) % q.length] = c;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"!%( %s%)\") (p.map !(q{a + 1}));\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto b = new bool [n];\r\n\t\tauto p = new int [n];\r\n\t\tint step = 0;\r\n\r\n\t\tint ask (int pos)\r\n\t\t{\r\n\t\t\twriteln (pos + 1);\r\n\t\t\tstdout.flush ();\r\n\t\t\tstep += 1;\r\n\t\t\tauto res = readln.strip.to !(int);\r\n\t\t\treturn res - 1;\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!b[i])\r\n\t\t\t{\r\n\t\t\t\tint k = step;\r\n\t\t\t\tint [] q;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tq ~= ask (i);\r\n\t\t\t\t\tb[q.back] = true;\r\n\t\t\t\t}\r\n\t\t\t\twhile (q.length < 2 || q.back != q.front);\r\n\t\t\t\tq.popBack ();\r\n\t\t\t\tk = (-k + 1) % q.length.to !(int);\r\n\t\t\t\tk = (k + q.length) % q.length.to !(int);\r\n\t\t\t\tforeach (j, c; q)\r\n\t\t\t\t{\r\n\t\t\t\t\tp[(j + k) % q.length] = c;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"!%( %s%)\") (p.map !(q{a + 1}));\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto b = new bool [n];\r\n\t\tauto p = new int [n];\r\n\t\tint step = 0;\r\n\r\n\t\tint ask (int pos)\r\n\t\t{\r\n\t\t\twriteln (pos + 1);\r\n\t\t\tstdout.flush ();\r\n\t\t\tstep += 1;\r\n\t\t\tauto res = readln.strip.to !(int);\r\n\t\t\treturn res - 1;\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!b[i])\r\n\t\t\t{\r\n\t\t\t\tint k = step;\r\n\t\t\t\tint [] q;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tq ~= ask (i);\r\n\t\t\t\t\tb[q.back] = true;\r\n\t\t\t\t}\r\n\t\t\t\twhile (q.length < 2 || q.back != q.front);\r\n\t\t\t\tq.popBack ();\r\n\t\t\t\tk = (-k - 1) % q.length.to !(int);\r\n\t\t\t\tk = (k + q.length) % q.length.to !(int);\r\n\t\t\t\tforeach (j, c; q)\r\n\t\t\t\t{\r\n\t\t\t\t\tp[(j + k) % q.length] = c;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"!%( %s%)\") (p.map !(q{a + 1}));\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint ask(int i) {\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n int x = read!int;\r\n return x;\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n int count = 0;\r\n auto known = new bool[N+1];\r\n auto cycles = new int[][0];\r\n int c = 1;\r\n int[] ks;\r\n int[] cs;\r\n int nasked = 0;\r\n for (int k = 0; count < N; k++) {\r\n while (known[c]) c++;\r\n cycles ~= new int[0];\r\n ks ~= nasked;\r\n cs ~= c;\r\n while (true) {\r\n int x = ask(c);\r\n nasked++;\r\n cycles[k] ~= x;\r\n if (known[x]) {\r\n break;\r\n }\r\n known[x] = true;\r\n count++;\r\n }\r\n }\r\n\r\n int[] P = new int[N + 1]; P[] = -1;\r\n foreach (i, cycle; cycles) {\r\n //writeln(\"cycle: \", cycle);\r\n int n = cast(int)(cycle.length) - 1;\r\n int k = ks[i];\r\n int s = (1 + k) % n;\r\n c = cs[i];\r\n for (int j = 0; j < n; j++) {\r\n P[c] = cycle[s];\r\n //writeln(\"--> \", [c, cycle[s]]);\r\n c = cycle[s];\r\n s = (s + 1) % n;\r\n }\r\n //writeln(\"P: \", P);\r\n }\r\n //writeln(cycles);\r\n //writeln(ks);\r\n writefln(\"! %(%s %)\", P[1 .. $]);\r\n stdout.flush;\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint ask(int i) {\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n int x = read!int;\r\n return x;\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n int count = 0;\r\n auto known = new bool[N+1];\r\n auto cycles = new int[][0];\r\n int c = 1;\r\n int[] ks;\r\n int[] cs;\r\n int nasked = 0;\r\n for (int k = 0; count < N; k++) {\r\n while (known[c]) c++;\r\n cycles ~= new int[0];\r\n ks ~= nasked;\r\n cs ~= c;\r\n while (true) {\r\n int x = ask(c);\r\n nasked++;\r\n cycles[k] ~= x;\r\n if (known[x]) {\r\n break;\r\n }\r\n known[x] = true;\r\n count++;\r\n }\r\n }\r\n\r\n int[] P = new int[N + 1]; P[] = -1;\r\n foreach (i, cycle; cycles) {\r\n //writeln(\"cycle: \", cycle);\r\n int n = cast(int)(cycle.length) - 1;\r\n int k = ks[i];\r\n int s = (1 + k) % n;\r\n c = cs[i];\r\n for (int j = 0; j < n; j++) {\r\n P[c] = cycle[s];\r\n //writeln(\"--> \", [c, cycle[s]]);\r\n c = cycle[s];\r\n s = (s + 1) % n;\r\n }\r\n //writeln(\"P: \", P);\r\n }\r\n //writeln(cycles);\r\n //writeln(ks);\r\n writefln(\"%(%s %)\", P[1 .. $]);\r\n stdout.flush;\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "src_uid": "96ec983bfadc9e96e36ebb8ffc5279d3"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.outbuffer;\nimport std.algorithm.mutation;\nimport std.container.array;\n\nstring[] tokens;\n\nstring readToken()\n{\n while (tokens.empty)\n {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nvoid main()\n{\n int n = readInt;\n string s = readToken;\n int[] dp = new int[n];\n int[] maxdp = new int[26];\n for (int i = 0; i < n; ++i)\n {\n int c = s[i] - 'a';\n dp[i] = 1;\n for (int j = c + 1; j < 26; ++j)\n {\n dp[i] = max(dp[i], maxdp[j] + 1);\n }\n maxdp[c] = max(maxdp[c], dp[i]);\n }\n writeln(dp.maxElement);\n auto buf = new OutBuffer();\n for (int i = 0; i < n; ++i)\n {\n buf.write(format(\"%d\", dp[i]));\n if (i + 1 < n)\n {\n buf.write(' ');\n }\n }\n writeln(buf.toString());\n}\n", "positive_code": [{"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid main()\n{\n auto n = next!int;\n auto s = next!string;\n int[] lastChar;\n auto color = new long[n.ind];\n foreach(i, c; s)\n {\n auto rng = assumeSorted(lastChar.retro).lowerBound(c + 1);\n if (rng.empty)\n {\n lastChar ~= c;\n color[i] = lastChar.length - 1;\n }\n else\n {\n lastChar[$ - rng.length] = c;\n color[i] = lastChar.length - rng.length;\n }\n }\n writeln(color.fold!((a, b) => max(a, b))(long.min) + 1);\n foreach(b; color)\n write(b + 1, \" \");\n writeln;\n}\n"}], "negative_code": [], "src_uid": "2e9da3333792a57e9e3bba4c75542ce7"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\n\nvoid main() {\n int n;\n scan(n);\n auto a = readln.split.to!(int[]);\n\n auto f = a.sort().group;\n\n int ans = 0;\n\n foreach (fi ; f) {\n ans = max(ans, fi[1]);\n }\n\n writeln(ans);\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n/// struct vector as c++ vector\nstruct Vec(T)\n{\n\tprivate Array!T buf;\n\talias buf this;\n\tthis(this)\n\t{\n\t\tbuf = buf.dup;\n\t}\n\t/// construct from length\n\tthis(U)(U length)\n\t\t\tif (is(U == int) || is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint))\n\t{\n\t\tbuf.length = length;\n\t}\n\t/// construct from length and default value\n\tthis(U, X)(U length, X val)\n\t\t\tif (isImplicitlyConvertible!(X, T) || (is(U == int)\n\t\t\t\t|| is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint)))\n\t{\n\t\tbuf.length = length;\n\t\tforeach (ref x; buf[])\n\t\t{\n\t\t\tx = val;\n\t\t}\n\t}\n\t/// construct from other array\n\tthis(U)(U[] values...) if (isImplicitlyConvertible!(U, T))\n\t{\n\t\tbuf = Array!(T)(values);\n\t}\n\t/// construct from other range\n\tthis(Range)(Range r)\n\t\t\tif (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range,\n\t\t\t\tT) && !is(Range == T[]))\n\t{\n\t\tbuf = Array!(T)(r);\n\t}\n\t/// integer length\n\tint size() @property const\n\t{\n\t\treturn cast(int) buf.length;\n\t}\n}\n///mmulo\nenum mm = 10 ^^ 9 + 7, mm2 = mm + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt biggcd(BigInt a, BigInt b)\n\t\t{\n\t\t\tBigInt res = 1;\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\tif ((a & 1) && (b & 1))\n\t\t\t\t{\n\t\t\t\t\ta -= b;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (a & 1)\n\t\t\t\t{\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\telse if (b & 1)\n\t\t\t\t{\n\t\t\t\t\ta >>= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres <<= 1;\n\t\t\t\t\ta >>= 1;\n\t\t\t\t\tb >>= 1;\n\t\t\t\t}\n\t\t\t\tif (a < b)\n\t\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn res * a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\treturn readf!(replicate(\" %s\", ptrs.length) ~ '\\n')(ptrs) == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tint n;\n\tread(n);\n\tint[int] q;\n\tforeach (ii; 0 .. n)\n\t{\n\t\tint x;\n\t\tinput(x);\n\t\tq[x]++;\n\t}\n\tint ans;\n\tforeach (k, v; q)\n\t{\n\t\tans = max(ans, v);\n\t}\n\twriteln(ans);\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\n\nvoid main() {\n readln;\n readln.split.to!(int[]).sort().group.map!(a => a[1]).reduce!max.writeln;\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "0cbd3eee259b1436f82e259be7d7ee0e"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n auto rs = new long[N + 1];\n rs[N] = 0;\n foreach_reverse (i; 0 .. N) {\n rs[i] = max(A[i], rs[i + 1] - 1);\n }\n debug {\n writeln(\"rs = \", rs);\n }\n \n long now;\n long ans;\n foreach (i; 0 .. N) {\n chmax(now, rs[i]);\n ans += now - A[i];\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"C\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n; long[] m;\n sc.read(n, m);\n long[] x = m.dup;\n foreach (i; 0..n-1) {\n x[i+1] = max(x[i+1], x[i]);\n }\n foreach_reverse (i; 0..n-1) {\n x[i] = max(x[i], x[i+1]-1);\n }\n\n writeln(x.sum - m.sum);\n\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}\n\nvoid main()\n{\n int n; readV(n);\n long[] m; readA(n, m);\n\n auto t = new long[](n);\n t[0] = 1;\n foreach (i; 1..n) t[i] = max(t[i-1], m[i]+1);\n\n auto c = t[$-1];\n foreach_reverse (i; 0..n-1) {\n --c;\n c = t[i] = max(c, t[i]);\n }\n\n writeln(t.sum - n - m.sum);\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}\n\nvoid main()\n{\n int n; readV(n);\n int[] m; readA(n, m);\n\n auto t = new int[](n);\n t[0] = 1;\n foreach (i; 1..n) t[i] = max(t[i-1], m[i]+1);\n\n auto c = t[$-1];\n foreach_reverse (i; 0..n-1) {\n --c;\n c = t[i] = max(c, t[i]);\n }\n\n writeln(t.sum - n - m.sum);\n}\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}\n\nvoid main()\n{\n int n; readV(n);\n int[] m; readA(n, m);\n\n auto t = new long[](n);\n t[0] = 1;\n foreach (i; 1..n) t[i] = max(t[i-1], m[i]+1);\n\n auto c = t[$-1];\n foreach_reverse (i; 0..n-1) {\n --c;\n c = t[i] = max(c, t[i]);\n }\n\n writeln(t.sum - n - m.sum);\n}\n"}], "src_uid": "d4909bd6c23312ac3968d81cb6340035"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n auto C = new long[N];\n foreach (i; 0 .. N) {\n C[i] = readLong();\n }\n \n alias Entry = Tuple!(long, \"c\", int, \"i\");\n BinaryHeap!(Array!Entry) que;\n auto ans = new int[N];\n foreach (i; 0 .. N + K) {\n if (i < N) {\n que.insert(Entry(C[i], i));\n }\n if (i >= K) {\n ans[que.front.i] = i;\n que.removeFront;\n }\n }\n \n long cost;\n foreach (i; 0 .. N) {\n cost += C[i] * (ans[i] - i);\n }\n writeln(cost);\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i] + 1);\n }\n writeln;\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1].to!long;\n auto C = readln.split.map!(to!long).array;\n const long INF = 10L^^50;\n\n auto A = N.iota.map!(i => tuple(-C[i], i)).array;\n A.sort();\n\n int p = 0;\n auto B = new int[](N);\n auto used = new bool[](N);\n fill(B, -1);\n\n foreach (a; A) {\n if (a[1] > K) {\n B[max(a[1] - K, p).to!int] = a[1];\n } else {\n B[p] = a[1];\n }\n\n while (p < N && B[p] != -1)\n p++;\n }\n\n auto D = new int[](N);\n foreach (i; 0..N) {\n D[B[i]] = i + K.to!int + 1;\n }\n N.iota.map!(i => (D[i] - i - 1) * C[i]).sum.writeln;\n D.map!(to!string).join(\" \").writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1].to!long;\n auto C = readln.split.map!(to!long).array;\n const long INF = 10L^^50;\n}\n"}], "src_uid": "8c23fcc84c6921bc2a95ff0586516321"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\talias Edge = Tuple !(int, q{u}, int, q{v}, int, q{w});\r\n\t\tauto e = new Edge [m];\r\n\t\tauto a = new int [] [n];\r\n\t\tforeach (int i, ref s; e)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s %s\") (s.u, s.v, s.w);\r\n\t\t\ts.u -= 1;\r\n\t\t\ts.v -= 1;\r\n\t\t\ta[s.u] ~= i;\r\n\t\t\ta[s.v] ~= i;\r\n\t\t}\r\n\r\n\t\tauto d = new int [] [] (n, n);\r\n\t\tforeach (ref line; d)\r\n\t\t{\r\n\t\t\tline[] = int.max / 2;\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\td[i][i] = 0;\r\n\t\t}\r\n\t\tforeach (ref s; e)\r\n\t\t{\r\n\t\t\td[s.u][s.v] = 1;\r\n\t\t\td[s.v][s.u] = 1;\r\n\t\t}\r\n\t\tforeach (k; 0..n)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tforeach (j; 0..n)\r\n\t\t\t\t{\r\n\t\t\t\t\td[i][j] = min (d[i][j],\r\n\t\t\t\t\t d[i][k] + d[k][j]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto res = long.max;\r\n\t\tforeach (ref s; e)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres = min (res,\r\n\t\t\t\t s.w * (2L + d[i][s.u] +\r\n\t\t\t\t d[i][0] + d[i][n - 1]));\r\n\t\t\t\tres = min (res,\r\n\t\t\t\t s.w * (2L + d[i][s.v] +\r\n\t\t\t\t d[i][0] + d[i][n - 1]));\r\n\t\t\t}\r\n\t\t\tres = min (res, s.w * (1L +\r\n\t\t\t d[0][s.u] + d[n - 1][s.v]));\r\n\t\t\tres = min (res, s.w * (1L +\r\n\t\t\t d[0][s.v] + d[n - 1][s.u]));\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\talias Edge = Tuple !(int, q{u}, int, q{v}, int, q{w});\r\n\t\tauto e = new Edge [m];\r\n\t\tauto a = new int [] [n];\r\n\t\tforeach (int i, ref s; e)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s %s\") (s.u, s.v, s.w);\r\n\t\t\ts.u -= 1;\r\n\t\t\ts.v -= 1;\r\n\t\t\ta[s.u] ~= i;\r\n\t\t\ta[s.v] ~= i;\r\n\t\t}\r\n\r\n\t\tauto d = new int [] [] (n, n);\r\n\t\tforeach (ref line; d)\r\n\t\t{\r\n\t\t\tline[] = int.max / 2;\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\td[i][i] = 0;\r\n\t\t}\r\n\t\tforeach (ref s; e)\r\n\t\t{\r\n\t\t\td[s.u][s.v] = 1;\r\n\t\t\td[s.v][s.u] = 1;\r\n\t\t}\r\n\t\tforeach (k; 0..n)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tforeach (j; 0..n)\r\n\t\t\t\t{\r\n\t\t\t\t\td[i][j] = min (d[i][j],\r\n\t\t\t\t\t d[i][k] + d[k][j]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto res = long.max;\r\n\t\tforeach (ref s; e)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres = min (res,\r\n\t\t\t\t s.w * (2L + d[s.u][i] +\r\n\t\t\t\t d[0][i] + d[n - 1][i]));\r\n\t\t\t\tres = min (res,\r\n\t\t\t\t s.w * (2L + d[s.v][i] +\r\n\t\t\t\t d[0][i] + d[n - 1][i]));\r\n\t\t\t}\r\n\t\t\tres = min (res, s.w * (1L +\r\n\t\t\t d[0][s.u] + d[n - 1][s.v]));\r\n\t\t\tres = min (res, s.w * (1L +\r\n\t\t\t d[0][s.v] + d[n - 1][s.u]));\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "e27ffab64e694b9d612fe100f4c503b8"} {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.math;\n\nstruct DayMeatPrice\n{\n\tpublic int kg, price;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tDayMeatPrice[] dmp; dmp.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d %d\", &dmp[i].kg, &dmp[i].price);\n\t}\n\tint min = int.max;\n\tint money = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tif (dmp[i].price < min) min = dmp[i].price;\n\t\tmoney += dmp[i].kg * min;\n\t}\n\tprintf(\"%d\", money);\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int price = 0;\n int[][] apList;\n for (int i = 0; i < n; i++) {\n auto ap = readln.chomp.split.map!(to!int);\n int a = ap[0];\n int p = ap[1];\n apList ~= [a, p];\n }\n\n for (int i = 1; i < n; i++) {\n if (apList[i - 1][1] < apList[i][1]) {\n apList[i][1] = apList[i - 1][1];\n }\n }\n\n int answer = 0;\n foreach (e; apList) {\n answer += e[0] * e[1];\n }\n\n writeln(answer);\n}"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\n\nvoid main() {\n int n;\n scan(n);\n\n int pmin = 1000;\n int ans;\n\n foreach (i ; 0 .. n) {\n int a, p;\n scan(a, p);\n pmin = min(p, pmin);\n ans += a * pmin;\n }\n\n writeln(ans);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "28e0822ece0ed35bb3e2e7fc7fa6c697"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tint[] clear = new int[n];\n\n\tfor (int i = 0; i < 2; i++) {\n\t\tauto l = readln.chomp.split.map!(to!int);\n\t\tforeach (e; l[1..$]) {\n\t\t\tclear[--e]++;\n\t\t}\n\t}\n\n\tif (clear.any!(\"a == 0\")) {\n\t\twriteln(\"Oh, my keyboard!\");\n\t} else {\n\t\twriteln(\"I become the guy.\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.algorithm, std.range;\t\n\nvoid main(string[] argv)\n{\n\tint lvls = to!int(readln.strip);\n\tauto xList = to!(int[])(readln.strip.split[1..$]);\n\tauto yList = to!(int[])(readln.strip.split[1..$]);\n\t\n\tif(chain(xList, yList).sort.uniq.array.length >= lvls)\n\t\twriteln(\"I become the guy.\");\n\telse\n\t\twriteln(\"Oh, my keyboard!\");\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\n\nint main(string[] argv)\n{\n\tbool[int] levels;\n\tint n;\n\tscanf(\"%d\", &n);\n\tforeach (int i; 0..n)\n\t{\n\t\tlevels[i] = false;\n\t}\n\tint p;\n\tscanf(\"%d\", &p);\n\tforeach (int i; 0..p)\n\t{\n\t\tint a;\n\t\tscanf(\"%d\", &a);\n\t\tlevels[a-1] = true;\n\t}\n\tscanf(\"%d\", &p);\n\tforeach (int i; 0..p)\n\t{\n\t\tint a;\n\t\tscanf(\"%d\", &a);\n\t\tlevels[a-1] = true;\n\t}\n\t\n\tforeach (int i; 0..n)\n\t{\n\t\tif (levels[i] == false)\n\t\t{\n\t\t\tprintf(\"Oh, my keyboard!\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\tprintf(\"I become the guy.\");\n\treturn 0;\n}\n\n"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto ok = new bool[n];\n for (int i = 0; i < 2; i++) {\n int k; readf(\" %s\", &k);\n while (k--) {\n int x; readf(\" %s\", &x);\n x--;\n ok[x] = true;\n }\n }\n bool ans = true;\n foreach (x; ok) {\n ans &= x;\n }\n writeln(ans ? \"I become the guy.\" : \"Oh, my keyboard!\");\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tint[] clear = new int[n];\n\n\tfor (int i = 0; i < 2; i++) {\n\t\tauto l = readln.chomp.split.map!(to!int);\n\t\tforeach (e; l) {\n\t\t\tclear[--e]++;\n\t\t}\n\t}\n\n\tif (clear.any!(\"a == 0\")) {\n\t\twriteln(\"Oh, my keyboard!\");\n\t} else {\n\t\twriteln(\"I become the guy.\");\n\t}\n}\n"}], "src_uid": "044ade01d2de1486735742369227ae1d"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\ta[] -= 1;\n\t\tauto p = n.iota.array;\n\n\t\tint root (int v)\n\t\t{\n\t\t\tif (v == p[v])\n\t\t\t{\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\treturn p[v] = root (p[v]);\n\t\t}\n\n\t\tbool unite (int u, int v)\n\t\t{\n\t\t\tu = root (u);\n\t\t\tv = root (v);\n\t\t\tif (u == v)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tp[u] = v;\n\t\t\treturn true;\n\t\t}\n\n\t\tint res = n;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (unite (i, a[i]))\n\t\t\t{\n\t\t\t\tres -= 1;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t\tstdout.flush ();\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\n\nbool [] used;\nint [][] g;\nbool can;\nvoid dfs(int v)\n{\n used[v] = true;\n for(int i = 0; i < g[v].length; i++)\n {\n if(!used[g[v][i]])\n dfs(g[v][i]);\n else\n can = false;\n }\n}\nvoid main(string[] args) \n{\n int l1,r1,l2,r2,k,n;\n can = false;\n scanf(\"%d\",&n);\n g.length = n + 1;\n used.length = n + 1;\n int ans = 0;\n for(int i = 1; i <= n; i++)\n {\n scanf(\"%d\",&k);\n g[k].length++;\n g[k][g[k].length - 1] = i;\n used[i] = false;\n }\n for(int i = 1; i <= n; i++)\n {\n can = true;\n if(!used[i])\n dfs(i);\n if(!can){\n ans++;\n }\n }\n \n \n \n writeln(ans);\n \n}"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdio;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\n//import std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\n/+\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n+/\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Dsu(int n) {\n int[n] p;\n\n void init() {\n iota(n).copy(p[ ]);\n }\n\n int get(int x) {\n return x == p[x] ? x : (p[x] = get(p[x]));\n }\n\n void merge(int x, int y) {\n p[get(x)] = get(y);\n }\n}\n\nint n;\nDsu!10_000 dsu;\n\nvoid main() {\n scanf(\"%d\", &n);\n dsu.init();\n foreach (i; 0 .. n) {\n int x;\n scanf(\"%d\", &x);\n dsu.merge(i, x - 1);\n }\n int result = 0;\n foreach (i; 0 .. n)\n if (i == dsu.get(i))\n result++;\n printf(\"%d\\n\", result);\n}\n"}], "negative_code": [], "src_uid": "6d940cb4b54f63a7aaa82f21e4c5b994"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid check(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n count[] = 0;\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n a.sort!(\"a < b\", SwapStrategy.stable);\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n check(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n check(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nint[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tint[] ps = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tps[i] = i;\n\t\t}\n\t\tps.sort!((a, b) => (A[a] < A[b]));\ndebug{\nwriteln(ps);\n}\n\t\tPair!(int, int)[] poss;\n\t\tfor (int i = 0, j; i < N; i = j) {\n\t\t\tfor (; j < N && A[ps[i]] == A[ps[j]]; ++j) {}\n\t\t\tif (j - i >= 2) {\n\t\t\t\tposs ~= pair(i, j);\n\t\t\t}\n\t\t}\n\t\tint prod = 1;\n\t\tforeach (pos; poss) {\n\t\t\tprod *= (pos.y - pos.x);\n\t\t\tchmin(prod, 4);\n\t\t}\n\t\tif (prod < 3) {\n\t\t\twriteln(\"NO\");\n\t\t\tcontinue;\n\t\t}\n\t\twriteln(\"YES\");\n\t\tif (poss.count!(a => (a.y - a.x >= 3)) > 0) {\n\t\t\tforeach (i; 0 .. N) { if (i > 0) write(\" \"); write(ps[i] + 1); } writeln;\n\t\t\tforeach (pos; poss) if (pos.y - pos.x >= 3) {\n\t\t\t\tswap(ps[pos.x + 1], ps[pos.x + 2]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tforeach (i; 0 .. N) { if (i > 0) write(\" \"); write(ps[i] + 1); } writeln;\n\t\t\tforeach (pos; poss) if (pos.y - pos.x >= 3) {\n\t\t\t\tswap(ps[pos.x + 0], ps[pos.x + 1]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tforeach (i; 0 .. N) { if (i > 0) write(\" \"); write(ps[i] + 1); } writeln;\n\t\t} else {\n\t\t\tassert(poss.length >= 2);\n\t\t\tforeach (i; 0 .. N) { if (i > 0) write(\" \"); write(ps[i] + 1); } writeln;\n\t\t\tswap(ps[poss[0].x], ps[poss[0].x + 1]);\n\t\t\tforeach (i; 0 .. N) { if (i > 0) write(\" \"); write(ps[i] + 1); } writeln;\n\t\t\tswap(ps[poss[1].x], ps[poss[1].x + 1]);\n\t\t\tforeach (i; 0 .. N) { if (i > 0) write(\" \"); write(ps[i] + 1); } writeln;\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.exception;\nimport std.algorithm;\n\nbool solve() {\n\tint n;\n\tif (!readf(\" %s\", &n))\n\t\treturn false;\n\tauto a = new int[n];\n\tforeach (ref x; a)\n\t\treadf(\" %s\", &x);\n\n\tauto p = new int[n];\n\tforeach (i, ref x; p)\n\t\tx = cast(int)i;\n\tsort!((i, j) => a[i] < a[j])(p);\n\n\tint[][] ans;\n\tans ~= p.dup;\n\tforeach (i; 0..n-1) {\n\t\tif (a[p[i]] == a[p[i + 1]]) {\n\t\t\tswap(p[i], p[i + 1]);\n\t\t\tans ~= p.dup;\n\t\t}\n\t\tif (ans.length == 3)\n\t\t\tbreak;\n\t}\n\n\tif (ans.length < 3)\n\t\twriteln(\"NO\");\n\telse {\n\t\twriteln(\"YES\");\n\t\tforeach (i; 0..ans.length) {\n\t\t\tforeach (j; 0..ans[i].length)\n\t\t\t\twrite(ans[i][j] + 1, ' ');\n\t\t\twriteln();\n\t\t}\n\t}\n\n\treturn true;\n}\n\nvoid main() {\n\twhile (solve()) {}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid check(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n count[] = 0;\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n a.sort!((a, b) => (a[0] < b[0]));\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n check(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n check(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid check(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n count[] = 0;\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n a.sort!(\"a < b\", SwapStrategy.unstable);;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n check(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n check(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid check(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n count[] = 0;\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n sort(a);\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n check(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n check(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(ref pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid Assert(bool b) {\n if (!b) {\n int x = 1 - 1;\n writeln(1 / x);\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n Assert(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n Assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n Assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n Assert(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n Assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n Assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n if (n == 2000) {\n writeln(a[496], ' ', a[569]);\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n if (n == 2000) {\n writeln(\"3\");\n }\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n if (n == 2000) { \n writeln(a[x], ' ', a[x + 1], ' ', a[x + 2]);\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n if (n == 2000) {\n writeln(\"2\");\n }\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid swap(ref pair a, ref pair b) {\n pair t = a;\n a = b;\n b = t;\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n if (n == 2000) {\n writeln(a[496], ' ', a[569]);\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid check(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n count[] = 0;\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n check(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n check(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid check(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n count[] = 0;\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n int c3 = 0, c2 = 0;\n a.sort;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n check(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n check(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(ref pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n assert(a[x + 1].v == a[x + 2].v);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n if (n == 2000) {\n writeln(a[496], ' ', a[569]);\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n if (n == 2000) {\n writeln(\"3\");\n }\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n writeln(a[x], ' ', a[x + 1], ' ', a[x + 2]);\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n if (n == 2000) {\n writeln(\"2\");\n }\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid check(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n count[] = 0;\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n a.sort!((a, b) => (a[0] < b[0]));\n if (n == 2000) {\n bool ok = 1;\n for (int i = 0; i + 1 < n; i++) {\n ok &= a[i][0] <= a[i + 1][0];\n }\n check(ok);\n return;\n }\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n check(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n check(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n print(a);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n print(a);\n swap(a[y], a[y + 1]);\n print(a);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(ref pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n print(a);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n print(a);\n swap(a[y], a[y + 1]);\n print(a);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n assert(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(ref pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid Assert(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n Assert(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n Assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n Assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n Assert(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n Assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n Assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n Assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, int);\n\nvoid check(bool b) {\n if (!b) {\n writeln(\"FAIL!\");\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n count[] = 0;\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i][0]);\n a[i][1] = i + 1;\n count[a[i][0]]++;\n }\n a.sort;\n if (n == 2000) {\n bool ok = 1;\n for (int i = 0; i + 1 < n; i++) {\n ok &= a[i][0] <= a[i + 1][0];\n }\n check(ok);\n return;\n }\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i][0] == a[i + 2][0]) {\n x = i;\n break;\n }\n }\n check(x != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0] && a[x + 1][0] == a[x + 2][0]);\n swap(a[x], a[x + 2]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i][0] == a[i + 1][0]) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n check(x != -1 && y != -1);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[y][0] == a[y + 1][0]);\n swap(a[y], a[y + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n check(a[x][0] == a[x + 1][0]);\n swap(a[x], a[x + 1]);\n for (int i = 0; i + 1 < a.length; i++) {\n check(a[i][0] <= a[i + 1][0]);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%s%s\", a[i][1], i == a.length - 1 ? '\\n' : ' ');\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid swap(ref pair a, ref pair b) {\n pair t = a;\n a = b;\n b = t;\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n if (n == 2000) {\n writeln(a[496], ' ', a[569]);\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nalias pair = Tuple!(int, \"v\", int, \"id\");\n\nvoid print(pair[] a) {\n for (int i = 0; i + 1 < a.length; i++) {\n assert(a[i].v <= a[i + 1].v);\n }\n for (int i = 0; i < a.length; i++) {\n writef(\"%d%c\", a[i].id, i == a.length - 1 ? '\\n' : ' ');\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto a = new pair[n];\n auto count = new int[2001];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i].v);\n a[i].id = i + 1;\n count[a[i].v]++;\n }\n if (n == 2000) {\n writeln(a[496], ' ', a[569]);\n }\n a.sort;\n int c3 = 0, c2 = 0;\n foreach (i; count) {\n if (i >= 3) {\n c3++;\n } else if (i >= 2) {\n c2++;\n }\n }\n if (c3 == 0 && c2 < 2) {\n writeln(\"NO\");\n } else if (c3 > 0) {\n if (n == 2000) {\n writeln(\"3\");\n }\n writeln(\"YES\");\n int x = -1;\n for (int i = 0; i + 2 < n; i++) {\n if (a[i].v == a[i + 2].v) {\n x = i;\n break;\n }\n }\n assert(x != -1);\n print(a);\n assert(a[x].v == a[x + 1].v && a[x + 1].v == a[x + 2].v);\n swap(a[x], a[x + 1]);\n print(a);\n swap(a[x + 1], a[x + 2]);\n print(a);\n } else if (c2 >= 2) {\n if (n == 2000) {\n writeln(\"2\");\n }\n writeln(\"YES\");\n int x = -1, y = -1;\n for (int i = 0; i + 1 < n; i++) {\n if (a[i].v == a[i + 1].v) {\n if (x == -1) {\n x = i;\n } else if (y == -1) {\n y = i;\n break;\n }\n }\n }\n assert(x != -1 && y != -1);\n print(a);\n assert(a[y].v == a[y + 1].v);\n swap(a[y], a[y + 1]);\n print(a);\n assert(a[x].v == a[x + 1].v);\n swap(a[x], a[x + 1]);\n print(a);\n }\n}\n"}], "src_uid": "fdfc1e690eeee6f50e2a024bf3f841e8"} {"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\nvoid main () {\n\tauto n = readln.strip.to!int + 1, a = readln.split.map !(to!int).array ~ 1, m = (n - 1) * (n - 2) / 2;\n\tauto e = n.iota.filter !(i => a[i]).array, y = a.sum, x = n - y, f = new int [] [] [] (n + 1, y + 1, m + 1);\n\tf[0][0][] = x * (x - 1) / 2;\n\tforeach (p; 0..n) foreach (v; 0..y) foreach (g; 0..m + 1) if (f[p][v][g]) foreach (d; 0..x - p + v + 1) {\n\t\tauto q = p + d + 1, h = g + abs (q - 1 - e[v]);\n\t\tif (h <= m) f[q][v + 1][h] = max (f[q][v + 1][h], f[p][v][g] - d * (d - 1) / 2);\n\t}\n\tf[n][y].writefln !(\"%(%s %)\");\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nvoid main () {\n\tauto n = readln.strip.to !(int);\n\tauto a = readln.splitter.map !(to !(int)).array;\n\tauto n1 = a.sum, n0 = n - n1;\n\tint [] onePos;\n\tforeach (i; 0..n) if (a[i] == 1) onePos ~= i;\n\tauto m = n * (n - 1) / 2;\n\tauto f = new int [] [] [] (n + 1, n1 + 1, m + 1);\n\tf[0][0][0] = n0 * (n0 - 1) / 2;\n\n\tforeach (pos; 0..n) {\n\t\tforeach (ones; 0..min (pos + 1, n1)) {\n\t\t\tauto zeroes = pos - ones;\n\t\t\tif (zeroes > n0) continue;\n\t\t\tforeach (cost; 0..m + 1) {\n\t\t\t\tauto cur = f[pos][ones][cost];\n\t\t\t\tif (!cur) continue;\n\t\t\t\tfor (int add0 = 0; add0 + zeroes <= n0; add0++) {\n\t\t\t\t\tauto subValue = add0 * (add0 - 1) / 2;\n\t\t\t\t\tauto newPos = pos + add0 + 1;\n\t\t\t\t\tauto newCost = cost + abs (newPos - 1 - onePos[ones]);\n\t\t\t\t\tf[newPos][ones + 1][newCost] = max (f[newPos][ones + 1][newCost], cur - subValue);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tauto answer = new int [m + 1];\n\tforeach (pos; 0..n + 1) {\n\t\tauto add0 = n - pos;\n\t\tforeach (cost; 0..m + 1) {\n\t\t\tauto subValue = add0 * (add0 - 1) / 2;\n\t\t\tanswer[cost] = max (answer[cost],\n\t\t\t f[pos][n1][cost] - subValue);\n\t\t}\n\t}\n\tforeach (i; 0..m) answer[i + 1] = max (answer[i + 1], answer[i]);\n\twritefln !(\"%(%s %)\") (answer);\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nvoid main () {\n\tauto n = readln.strip.to !(int) + 1;\n\tauto a = readln.splitter.map !(to !(int)).array ~ 1;\n\tauto n1 = a.sum, n0 = n - n1;\n\tint [] onePos;\n\tforeach (i; 0..n) if (a[i]) onePos ~= i;\n\tauto m = (n - 1) * (n - 2) / 2;\n\tauto f = new int [] [] [] (n + 1, n1 + 1, m + 1);\n\tf[0][0][0] = n0 * (n0 - 1) / 2;\n\n\tforeach (pos; 0..n) {\n\t\tforeach (ones; 0..min (pos + 1, n1)) {\n\t\t\tauto zeroes = pos - ones;\n\t\t\tif (zeroes > n0) continue;\n\t\t\tforeach (cost; 0..m + 1) {\n\t\t\t\tauto cur = f[pos][ones][cost];\n\t\t\t\tif (!cur) continue;\n\t\t\t\tfor (int add0 = 0; add0 + zeroes <= n0; add0++) {\n\t\t\t\t\tauto subValue = add0 * (add0 - 1) / 2;\n\t\t\t\t\tauto newPos = pos + add0 + 1;\n\t\t\t\t\tauto newCost = cost + abs (newPos - 1 - onePos[ones]);\n\t\t\t\t\tf[newPos][ones + 1][newCost] = max (f[newPos][ones + 1][newCost], cur - subValue);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tauto z = f[n][n1][0..m + 1].dup;\n\tforeach (i; 0..m) z[i + 1] = max (z[i + 1], z[i]);\n\twritefln !(\"%(%s %)\") (z);\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\nvoid main () {\n\tauto n = readln.strip.to!int + 1, a = readln.splitter.map !(to!int).array ~ 1, m = (n - 1) * (n - 2) / 2;\n\tauto e = n.iota.filter !(i => a[i]).array, y = a.sum, x = n - y, f = new int [] [] [] (n + 1, y + 1, m + 1);\n\tf[0][0][0] = x * (x - 1) / 2;\n\tforeach (p; 0..n) foreach (v; 0..min (p + 1, y)) foreach (g; 0..m + 1) {\n\t\tauto c = f[p][v][g];\n\t\tif (c) foreach (d; 0..x - p + v + 1) {\n\t\t\tauto q = p + d + 1, h = g + abs (q - 1 - e[v]);\n\t\t\tf[q][v + 1][h] = max (f[q][v + 1][h], c - d * (d - 1) / 2);\n\t\t}\n\t}\n\tauto z = f[n][y][0..m + 1];\n\tforeach (i; 0..m) z[i + 1] = max (z[i + 1], z[i]);\n\tz.writefln !(\"%(%s %)\");\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int infinity = int.max / 4;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\t\n\t\tauto n0 = a.count (0).to !(int);\n\t\tauto n1 = a.count (1).to !(int);\n\t\tint [] onePos;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 1)\n\t\t\t{\n\t\t\t\tonePos ~= i;\n\t\t\t}\n\t\t}\n\n\t\tauto m = n * (n - 1) / 2;\n\t\tauto f = new int [] [] [] (n + 1, n1 + 1, m + n + 1);\n\t\tforeach (ref g; f)\n\t\t{\n\t\t\tforeach (ref h; g)\n\t\t\t{\n\t\t\t\th[] = -infinity;\n\t\t\t}\n\t\t}\n\t\tf[0][0][0] = n0 * (n0 - 1) / 2;\n\t\t\n\t\tdebug {int num = 0;}\n\t\tforeach (pos; 0..n)\n\t\t{\n\t\t\tforeach (ones; 0..min (pos, n1) + 1)\n\t\t\t{\n\t\t\t\tauto zeroes = pos - ones;\n\t\t\t\tif (zeroes > n0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (cost; 0..m + 1)\n\t\t\t\t{\n\t\t\t\t\tauto cur = f[pos][ones][cost];\n\t\t\t\t\tif (cur < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (ones >= n1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tdebug {num += 1;}\n\n\t\t\t\t\tfor (int add0 = 0; add0 + zeroes <= n0;\n\t\t\t\t\t add0++)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto subValue =\n\t\t\t\t\t\t add0 * (add0 - 1) / 2;\n\t\t\t\t\t\tauto newPos = pos + add0 + 1;\n\t\t\t\t\t\tauto newCost = cost + abs\n\t\t\t\t\t\t (newPos - 1 -\n\t\t\t\t\t\t onePos[ones]);\n\t\t\t\t\t\tf[newPos][ones + 1][newCost] =\n\t\t\t\t\t\t max (f[newPos][ones + 1]\n\t\t\t\t\t\t [newCost], cur - subValue);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {stderr.writeln (num);}\n\n\t\tauto answer = new int [m + 1];\n\t\tforeach (pos; 0..n + 1)\n\t\t{\n\t\t\tauto add0 = n - pos;\n\t\t\tforeach (cost; 0..m + 1)\n\t\t\t{\n\t\t\t\tauto subValue = add0 * (add0 - 1) / 2;\n\t\t\t\tanswer[cost] = max (answer[cost],\n\t\t\t\t f[pos][n1][cost] - subValue);\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tanswer[i + 1] = max (answer[i + 1], answer[i]);\n\t\t}\n\t\twritefln !(\"%(%s %)\") (answer);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nvoid main () {\n\tauto n = readln.strip.to !(int) + 1, a = readln.splitter.map !(to !(int)).array ~ 1, x = a.sum, y = n - x;\n\tint [] e;\n\tforeach (i; 0..n) if (a[i]) e ~= i;\n\tauto m = (n - 1) * (n - 2) / 2, f = new int [] [] [] (n + 1, y + 1, m + 1);\n\tf[0][0][0] = x * (x - 1) / 2;\n\n\tforeach (p; 0..n) {\n\t\tforeach (v; 0..min (p + 1, y)) {\n\t\t\tauto u = p - v;\n\t\t\tif (u > x) continue;\n\t\t\tforeach (g; 0..m + 1) {\n\t\t\t\tauto c = f[p][v][g];\n\t\t\t\tif (c) for (int d = 0; d + u <= x; d++) {\n\t\t\t\t\tauto s = d * (d - 1) / 2;\n\t\t\t\t\tauto q = p + d + 1;\n\t\t\t\t\tauto h = g + abs (q - 1 - e[v]);\n\t\t\t\t\tf[q][v + 1][h] = max (f[q][v + 1][h], c - s);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tauto z = f[n][y][0..m + 1].dup;\n\tforeach (i; 0..m) z[i + 1] = max (z[i + 1], z[i]);\n\twritefln !(\"%(%s %)\") (z);\n}\n"}], "src_uid": "3213a783f4b3c36a61499ac21107695a"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n,m;\n readf!\" %s %s \"(n, m);\n int[] a = readln.strip.split.map!(c => to!int(c)-1).array;\n\n int[] cnt = new int[](n);\n\n ulong uniq = 0;\n int r = 0;\n\n auto ans = new dchar[](m);\n foreach (i; 0 .. m) {\n if (cnt[a[i]] == r) {\n uniq++;\n }\n cnt[a[i]]++;\n\n if (uniq == n) {\n ans[i] = '1';\n r++;\n uniq = cnt.count!(c => c > r);\n } else {\n ans[i] = '0';\n }\n }\n writeln(ans);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n,m;\n readf!\" %s %s\"(n, m);\n\n int[] cnt = new int[](n);\n\n ulong uniq = 0;\n\n int r = 0;\n foreach (i; 0 .. m) {\n int a; readf!\" %s\"(a);\n a--;\n if (cnt[a] == r) {\n uniq++;\n }\n cnt[a]++;\n\n if (uniq == n) {\n write(1);\n r++;\n uniq = cnt.count!(c => c > r);\n } else {\n write(0);\n }\n }\n writeln();\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n,m;\n readf!\" %s %s\"(n, m);\n\n int[] cnt = new int[](n);\n\n ulong uniq = 0;\n int r = 0;\n\n auto ans = new dchar[](m);\n foreach (i; 0 .. m) {\n int a; readf!\" %s\"(a);\n a--;\n if (cnt[a] == r) {\n uniq++;\n }\n cnt[a]++;\n\n if (uniq == n) {\n ans[i] = '1';\n r++;\n uniq = cnt.count!(c => c > r);\n } else {\n ans[i] = '0';\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!int).array;\n\n auto cnt1 = new int[](N+10);\n auto cnt2 = new int[](M+10);\n cnt2[0] = N;\n auto ans = new dchar[](M);\n int mv = 0;\n\n foreach (i; 0..M) {\n bool ok = false;\n if (cnt1[A[i]] == mv && cnt2[cnt1[A[i]]] == 1) {\n ok = true;\n mv += 1;\n }\n cnt2[cnt1[A[i]]] -= 1;\n cnt1[A[i]] += 1;\n cnt2[cnt1[A[i]]] += 1;\n if (ok) {\n ans[i] = '1';\n } else {\n ans[i] = '0';\n }\n }\n\n ans.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n,m;\n readf!\" %s %s\"(n, m);\n\n int[] cnt = new int[](n);\n\n int uniq = 0;\n\n int r = 0;\n foreach (i; 0 .. m) {\n int a; readf!\" %s\"(a);\n a--;\n if (cnt[a] == r) {\n uniq++;\n }\n cnt[a]++;\n\n if (uniq == n) {\n write(1);\n uniq = 0;\n r++;\n } else {\n write(0);\n }\n }\n writeln();\n}\n"}], "src_uid": "2070955288b2e2cdbae728d8e7ce78ab"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 10^^9 + 7;\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n if (A.map!(a => a % 2 == A.front % 2).all) {\n A.map!(to!string).join(\" \").writeln;\n } else {\n A.sort();\n A.map!(to!string).join(\" \").writeln;\n }\n}", "positive_code": [{"source_code": "import core.stdc.stdio;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\n\nvoid main()\n{\n int n;\n scanf(\"%d\", &n);\n int[] a = new int[n];\n foreach (i; 0 .. n)\n scanf(\"%d\", &a[i]);\n\n bool t = (all!\"a%2==0\"(a)) || (all!\"a%2==1\"(a));\n\n if (!t)\n sort(a);\n writefln(\"%(%d %)\", a);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto N = RD!int;\n\tauto A = RDR.ARR;\n\tbool o, e;\n\tforeach (i; 0..N)\n\t{\n\t\tif (A[i] % 2 == 0)\n\t\t\te = true;\n\t\telse\n\t\t\to = true;\n\t}\n\n\tif (o && e)\n\t\tA.sort();\n\n\tA.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n\n bool haveOdd = false, haveEven = false;\n \n foreach (e; arr) {\n haveOdd |= e % 2 == 1;\n haveEven |= e % 2 == 0;\n }\n \n if (haveOdd && haveEven) {\n arr.sort();\n }\n \n arr.writefln!\"%(%s %)\";\n}"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nimport std.container.rbtree;\n\nvoid main() {\n auto r = new InputReader;\n int n = r.next!int;\n auto a = r.nextA!int(n);\n int[2] c;\n foreach (i; a) {\n ++c[i&1];\n }\n if (!c[0] || !c[1]) {\n } else {\n a.sort();\n }\n writefln (\"%(%s %)\", a);\n}\n\n"}], "negative_code": [], "src_uid": "aab7f7cce0b704051627b625294635bc"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint lcm(int a, int b) {\n return a / gcd(a, b) * b;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n \n auto ans = new int[][](M, N);\n if (M == 1) {\n if (N == 1) {\n ans[0][0] = 0;\n } else {\n foreach (y; 0 .. N) {\n ans[0][y] = 2 + y;\n }\n }\n } else {\n if (N == 1) {\n foreach (x; 0 .. M) {\n ans[x][0] = 2 + x;\n }\n } else {\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n ans[x][y] = lcm(1 + x, 1 + M + y);\n }\n }\n }\n foreach (x; 0 .. M) {\n foreach (y; 0 .. N) {\n if (y > 0) write(\" \");\n write(ans[x][y]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint r, c;\n\twhile (readf !(\" %s %s\") (r, c) > 0)\n\t{\n\t\tif (r == 1 && c == 1)\n\t\t{\n\t\t\twriteln (0);\n\t\t\tcontinue;\n\t\t}\n\t\tauto a = new int [] [] (r, c);\n\t\tforeach (i; 0..r)\n\t\t{\n\t\t\tforeach (j; 0..c)\n\t\t\t{\n\t\t\t\ta[i][j] = (i + 1) * (j + r + 1);\n\t\t\t}\n\t\t}\n\t\tif (c == 1)\n\t\t{\n\t\t\tforeach (i; 0..r)\n\t\t\t{\n\t\t\t\tforeach (j; 0..c)\n\t\t\t\t{\n\t\t\t\t\ta[i][j] = (i + c + 1) * (j + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%(%s %)\\n%)\") (a);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint r = rint, c = rint;\n\tint[][] ans;\n\tif(r == 1 && c == 1) ans = [[0]];\n\telse if(r == 1){\n\t\tans = [[]];\n\t\tforeach(j; 0 .. c) ans[0] ~= j + 2;\n\t}\n\telse if(c == 1){\n\t\tforeach(i ; 0 .. r) ans ~= [i + 2];\n\t}\n\telse{\n\t\tforeach(i; 0 .. r){\n\t\t\tans ~= [[]];\n\t\t\tforeach(j; 0 .. c){\n\t\t\t\tif(i == 0) ans[i] ~= 1 * (j + 2);\n\t\t\t\telse ans[i] ~= (c + i + 1) * (j + 2);\n\t\t\t}\n\t\t}\n\t}\n\tforeach(an; ans) an.map!(to!string).array.join(\" \").writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto r = RD!int;\n\tauto c = RD!int;\n\tauto ans = new long[][](r, c);\n\tint x, y;\n\tif (r < c)\n\t\tx = r;\n\telse\n\t\ty = c;\n\tforeach (i; 0..r)\n\t{\n\t\tforeach (j; 0..c)\n\t\t{\n\t\t\tans[i][j] = lcm(y+i+1, x+j+1);\n\t\t}\n\t}\n\n\tif (r == 1 && c == 1)\n\t\twriteln(0);\n\telse\n\t{\n\t\tforeach (i; 0..r)\n\t\t\tans[i].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n\n if (H == 1 && W == 1) {\n writeln(0);\n return;\n }\n\n bool swapped = false;\n if (H > W) swap(H, W), swapped = true;\n auto A = new long[][](H, W);\n\n auto R = iota(1, H+1).map!(to!long).array;\n auto C = iota(H+1, H+W+1).map!(to!long).array;\n\n foreach (i; 0..H) foreach (j; 0..W) {\n A[i][j] = R[i] * C[j] / gcd(R[i], C[j]);\n }\n\n if (!swapped) {\n A.each!(a => a.map!(to!string).join(\" \").writeln);\n } else {\n auto ans = new long[][](W, H);\n foreach (i; 0..H) foreach (j; 0..W) ans[j][i] = A[i][j];\n ans.each!(a => a.map!(to!string).join(\" \").writeln);\n }\n\n\n foreach (i; 0..H) {\n if (A[i].reduce!gcd != R[i]) {\n writeln([H, W]);\n A.each!writeln;\n return;\n }\n }\n foreach (j; 0..W) {\n auto B = H.iota.map!(i => A[i][j]).array;\n if (B.reduce!gcd != C[j]) {\n writeln([H, W]);\n return;\n }\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n\n if (H == 1 && W == 1) {\n writeln(1);\n return;\n }\n\n bool swapped = false;\n if (H > W) swap(H, W), swapped = true;\n auto A = new long[][](H, W);\n\n auto R = iota(1, H+1).map!(to!long).array;\n auto C = iota(H+1, H+W+1).map!(to!long).array;\n\n foreach (i; 0..H) foreach (j; 0..W) {\n A[i][j] = R[i] * C[j] / gcd(R[i], C[j]);\n }\n\n if (!swapped) {\n A.each!(a => a.map!(to!string).join(\" \").writeln);\n } else {\n auto ans = new long[][](W, H);\n foreach (i; 0..H) foreach (j; 0..W) ans[j][i] = A[i][j];\n ans.each!(a => a.map!(to!string).join(\" \").writeln);\n }\n\n\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n auto A = new long[][](H, W);\n\n auto R = iota(1, H+1).map!(to!long).array;\n auto C = iota(H+1, H+W+1).map!(to!long).array;\n\n foreach (i; 0..H) foreach (j; 0..W) {\n A[i][j] = R[i] * C[j] / gcd(R[i], C[j]);\n }\n\n A.each!(a => a.map!(to!string).join(\" \").writeln);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto r = RD!int;\n\tauto c = RD!int;\n\tauto ans = new long[][](r, c);\n\tforeach (i; 0..r)\n\t{\n\t\tforeach (j; 0..c)\n\t\t{\n\t\t\tans[i][j] = lcm(i+1, r+j+1);\n\t\t}\n\t}\n\n\tif (r == 1 && c == 1)\n\t\twriteln(0);\n\telse\n\t{\n\t\tforeach (i; 0..r)\n\t\t\tans[i].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "acebe5e1d927d32d65a4500d1d45c4ba"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nlong oper(ref RedBlackTree!(long, \"a < b\", true) sett, long curmem, long m){\n long mems = curmem;\n long left = mems - m;\n while(sett.length && left >= sett.front){\n mems -= sett.front;\n sett.removeFront;\n left = mems - m;\n }\n return mems;\n}\n\nvoid solve(){\n int n = scan!int;\n long m = scan;\n auto spaces = scanArray;\n auto priority = scanArray!int;\n\n auto normals = spaces.enumerate.filter!(a => (priority[a[0]] == 1)).map!(a => a[1]);\n auto imps = spaces.enumerate.filter!(a => (priority[a[0]] == 2)).map!(a => a[1]).array;\n\n imps.sort;\n imps.reverse;\n\n long mems = normals.sum;\n auto rbt = redBlackTree!(true)(normals);\n int totconv = 1*rbt.length.to!int + 2*imps.length.to!int;\n mems = oper(rbt, mems, m);\n\n int baseconv = 0;\n int conv = rbt.length.to!int + baseconv;\n int minconv = 2*n+2;\n if(mems >= m){\n minconv = min(conv, minconv);\n }\n\n foreach(space; imps){\n baseconv += 2;\n mems += space;\n mems = oper(rbt, mems, m);\n conv = rbt.length.to!int + baseconv;\n /* show(rbt.length, baseconv, conv, mems); */\n if(mems >= m){\n minconv = min(conv, minconv);\n }\n }\n int res = totconv - minconv;\n writeln( (res >= 0) ? minconv : -1);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int infinity = int.max / 2;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tint [] [3] p;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tp[b[i]] ~= a[i];\r\n\t\t}\r\n\t\tforeach (k; 1..3)\r\n\t\t{\r\n\t\t\tsort !(q{a > b}) (p[k]);\r\n\t\t}\r\n\r\n\t\tlong done = 0;\r\n\t\tint cur = 0;\r\n\t\tforeach (j; 0..p[2].length)\r\n\t\t{\r\n\t\t\tdone += p[2][j];\r\n\t\t\tcur += 2;\r\n\t\t}\r\n\r\n\t\tint i = 0;\r\n\t\twhile (i < p[1].length && done < m)\r\n\t\t{\r\n\t\t\tdone += p[1][i];\r\n\t\t\tcur += 1;\r\n\t\t\ti += 1;\r\n\t\t}\r\n\r\n\t\tint res = infinity;\r\n\t\tif (done >= m)\r\n\t\t{\r\n\t\t\tres = min (res, cur);\r\n\t\t}\r\n\r\n\t\tforeach_reverse (j; 0..p[2].length)\r\n\t\t{\r\n\t\t\tdone -= p[2][j];\r\n\t\t\tcur -= 2;\r\n\r\n\t\t\twhile (i < p[1].length && done < m)\r\n\t\t\t{\r\n\t\t\t\tdone += p[1][i];\r\n\t\t\t\tcur += 1;\r\n\t\t\t\ti += 1;\r\n\t\t\t}\r\n\r\n\t\t\tif (done >= m)\r\n\t\t\t{\r\n\t\t\t\tres = min (res, cur);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twriteln (res == infinity ? -1 : res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.functional;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N; long M; readf(\"%d %d\\n\", &N, &M);\r\n auto A = readarray!long;\r\n auto B = readarray!int;\r\n\r\n if (A.reduce!\"a + b\" < M) {\r\n writeln(-1);\r\n return;\r\n }\r\n\r\n int[] C, X;\r\n for (int i = 0; i < N; i++) {\r\n (B[i] == 1 ? C : X) ~= i;\r\n }\r\n C.sort!( (i, j) => A[i] > A[j] );\r\n X.sort!( (i, j) => A[i] > A[j] );\r\n\r\n int K = C.length;\r\n auto S = new long[K+1];\r\n for (int i = 0; i < K; i++) {\r\n S[i + 1] = S[i] + A[C[i]];\r\n }\r\n\r\n long ans = B.reduce!\"a+b\";\r\n long xsum = 0;\r\n for (int i = 0; ; i++) {\r\n long r = M - xsum;\r\n if (r > 0) {\r\n int k = S.lowerbound(r);\r\n if (k == K+1) {\r\n } else {\r\n ans.chmin(2*i + k);\r\n }\r\n } else {\r\n ans.chmin(2*i);\r\n }\r\n if (i == X.length) break;\r\n xsum += A[X[i]];\r\n }\r\n writeln(ans);\r\n}\r\n\r\nint binsearch(alias pred, T)(in T[] xs) {\r\n // find the minimum `i` that satisfies `pred(xs[i])`\r\n // NOTE: if none of the elements satisfies pred(x), returns `xs.length`\r\n alias C = unaryFun!pred;\r\n int N = cast(int)(xs.length);\r\n int lb = 0, ub = N;\r\n if (C(xs[lb])) {\r\n return 0;\r\n } else {\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(xs[mid]) ? ub : lb) = mid;\r\n }\r\n return ub;\r\n }\r\n}\r\nint lowerbound(T)(in T[] xs, in T x) {\r\n // find the minimum `i` that satisfies `x <= xs[i]`\r\n return xs.binsearch!(a => a >= x);\r\n}\r\nint upperbound(T)(in T[] xs, in T x) {\r\n // find the minimum `i` that satisfies `x < xs[i]`\r\n return xs.binsearch!(a => a > x);\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; long M; get(N, M);\r\n long[] aa; get(aa);\r\n int[] bb; get(bb);\r\n long[] hs, ls;\r\n foreach (i; 0..N) {\r\n if (bb[i] == 2) {\r\n hs ~= aa[i];\r\n } else {\r\n ls ~= aa[i];\r\n }\r\n }\r\n sort!\"a > b\"(hs);\r\n sort!\"a > b\"(ls);\r\n int res = int.max;\r\n\r\n if (ls.empty) {\r\n foreach (i, h; hs) {\r\n M -= h;\r\n if (M <= 0) res = min(res, (i.to!int + 1) * 2);\r\n }\r\n } else {\r\n auto cs = new long[](ls.length);\r\n foreach (i; 0..ls.length) {\r\n if (i) cs[i] = cs[i-1];\r\n cs[i] += ls[i];\r\n if (cs[i] >= M) res = min(res, i.to!int + 1);\r\n }\r\n long MM = M;\r\n foreach (i; 0..hs.length) {\r\n MM -= hs[i];\r\n int rr = (i + 1).to!int * 2;\r\n if (MM <= 0) {\r\n res = min(res, rr);\r\n } else if (MM - cs[$-1] > 0) {\r\n continue;\r\n } else {\r\n int l = -1, r = cs.length.to!int;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n if (MM - cs[m] <= 0) {\r\n r = m;\r\n } else {\r\n l = m;\r\n }\r\n }\r\n res = min(res, rr + r + 1);\r\n }\r\n }\r\n }\r\n\r\n writeln(res == int.max ? -1 : res);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto a = RDA;\r\n\t\tauto b = RDA;\r\n\r\n\t\tlong[] one, two;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (b[i] == 1)\r\n\t\t\t\tone ~= a[i];\r\n\t\t\telse\r\n\t\t\t\ttwo ~= a[i];\r\n\t\t}\r\n\t\tone.sort!\"a > b\";\r\n\t\ttwo.sort!\"a > b\";\r\n\r\n\t\tauto c = new long[](two.length+1);\r\n\t\tforeach (i; 0..two.length)\r\n\t\t{\r\n\t\t\tc[i+1] = c[i] + two[i];\r\n\t\t}\r\n\r\n\t\tans[ti] = long.max;\r\n\t\tlong tot;\r\n\t\tforeach (i; 0..one.length+1)\r\n\t\t{\r\n\t\t\tbool f(int x)\r\n\t\t\t{\r\n\t\t\t\treturn tot + c[x] >= m;\r\n\t\t\t}\r\n\t\t\tauto r = binarySearch!(f)(cast(int)c.length, -1);\r\n\t\t\tif (r != c.length)\r\n\t\t\t\tans[ti].chmin(i + r*2);\r\n\t\t\tif (i != one.length)\r\n\t\t\t\ttot += one[i];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e == long.max ? -1 : e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nlong oper(ref RedBlackTree!(long, \"a < b\", true) sett, long mems, long m){\n long left = mems - m;\n while(left > 0 && sett.length && sett.front <= left){\n mems -= sett.front;\n sett.removeFront;\n left = mems - m;\n }\n return mems;\n}\n\nvoid solve(){\n int n = scan!int;\n long m = scan;\n auto spaces = scanArray;\n auto priority = scanArray!int;\n\n auto normals = spaces.enumerate.filter!(a => (priority[a[0]] == 1)).map!(a => a[1]);\n auto imps = spaces.enumerate.filter!(a => (priority[a[0]] == 2)).map!(a => a[1]).array;\n\n imps.sort;\n imps.reverse;\n\n long mems = normals.sum;\n auto rbt = redBlackTree!(true)(normals);\n int totconv = rbt.length.to!int + 2*imps.length.to!int;\n oper(rbt, mems, m);\n\n int conv = rbt.length.to!int;\n int baseconv = 0;\n int minconv = 2*n+2;\n if(mems - m >= 0){\n minconv = min(conv, minconv);\n }\n\n foreach(space; imps){\n baseconv += 2;\n mems += space;\n mems = oper(rbt, mems, m);\n conv = rbt.length.to!int + baseconv;\n if(mems - m >= 0){\n minconv = min(conv, minconv);\n }\n }\n int res = totconv - minconv;\n writeln( (res >= 0) ? minconv : -1);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nlong oper(ref RedBlackTree!(long, \"a < b\", true) sett, long mems, long m){\n long left = mems - m;\n while(left > 0 && sett.length && sett.front <= left){\n mems -= sett.front;\n sett.removeFront;\n left = mems - m;\n }\n return mems;\n}\n\nvoid solve(){\n int n = scan!int;\n long m = scan;\n auto spaces = scanArray;\n auto priority = scanArray!int;\n\n auto normals = spaces.enumerate.filter!(a => (priority[a[0]] == 1)).map!(a => a[1]);\n auto imps = spaces.enumerate.filter!(a => (priority[a[0]] == 2)).map!(a => a[1]).array;\n\n imps.sort;\n imps.reverse;\n\n long mems = normals.sum;\n auto rbt = redBlackTree!(true)(normals);\n int totconv = rbt.length.to!int + 2*imps.length.to!int;\n oper(rbt, mems, m);\n\n int conv = rbt.length.to!int;\n int baseconv = 0;\n int minconv = 2*n+2;\n if(mems - m >= 0){\n minconv = min(conv, minconv);\n }\n\n foreach(space; imps){\n baseconv += 2;\n mems += space;\n oper(rbt, mems, m);\n conv = rbt.length.to!int + baseconv;\n if(mems - m >= 0){\n minconv = min(conv, minconv);\n }\n }\n int res = totconv - minconv;\n writeln( (res >= 0) ? minconv : -1);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nlong oper(ref RedBlackTree!(long, \"a < b\", true) sett, long mems, long m){\n long left = mems - m;\n while(left > 0 && sett.length && sett.front <= left){\n mems -= sett.front;\n sett.removeFront;\n left = mems - m;\n }\n return mems;\n}\n\nvoid solve(){\n int n = scan!int;\n long m = scan;\n auto spaces = scanArray;\n auto priority = scanArray!int;\n\n auto normals = spaces.enumerate.filter!(a => (priority[a[0]] == 1)).map!(a => a[1]);\n auto imps = spaces.enumerate.filter!(a => (priority[a[0]] == 2)).map!(a => a[1]).array;\n\n imps.sort;\n imps.reverse;\n\n long mems = normals.sum;\n auto rbt = redBlackTree!(true)(normals);\n int totconv = rbt.length.to!int + 2*imps.length.to!int;\n oper(rbt, mems, m);\n\n int conv = rbt.length.to!int;\n int baseconv = 0;\n int minconv = 2*n+2;\n if(mems - m > 0){\n minconv = min(conv, minconv);\n }\n\n foreach(space; imps){\n baseconv += 2;\n mems += space;\n oper(rbt, mems, m);\n conv = rbt.length.to!int + baseconv;\n if(mems - m > 0){\n minconv = min(conv, minconv);\n }\n }\n int res = totconv - minconv;\n writeln( (res >= 0) ? minconv : -1);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio;\r\nimport std.functional;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N; long M; readf(\"%d %d\\n\", &N, &M);\r\n auto A = readarray!long;\r\n auto B = readarray!int;\r\n\r\n if (A.reduce!\"a + b\" < M) {\r\n writeln(-1);\r\n return;\r\n }\r\n\r\n int[] C, X;\r\n for (int i = 0; i < N; i++) {\r\n (B[i] == 1 ? C : X) ~= i;\r\n }\r\n C.sort!( (i, j) => A[i] > A[j] );\r\n X.sort!( (i, j) => A[i] > A[j] );\r\n\r\n int K = C.length;\r\n auto S = new long[K+1];\r\n for (int i = 0; i < K; i++) {\r\n S[i + 1] = S[i] + A[C[i]];\r\n }\r\n\r\n long ans = A.reduce!\"a+b\";\r\n long xsum = 0;\r\n for (int i = 0; ; i++) {\r\n long r = M - xsum;\r\n if (r > 0) {\r\n int k = S.lowerbound(r);\r\n if (k == K+1) {\r\n } else {\r\n ans.chmin(2*i + k);\r\n }\r\n } else {\r\n ans.chmin(2*i);\r\n }\r\n if (i == X.length) break;\r\n xsum += A[X[i]];\r\n }\r\n writeln(ans);\r\n}\r\n\r\nint binsearch(alias pred, T)(in T[] xs) {\r\n // find the minimum `i` that satisfies `pred(xs[i])`\r\n // NOTE: if none of the elements satisfies pred(x), returns `xs.length`\r\n alias C = unaryFun!pred;\r\n int N = cast(int)(xs.length);\r\n int lb = 0, ub = N;\r\n if (C(xs[lb])) {\r\n return 0;\r\n } else {\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(xs[mid]) ? ub : lb) = mid;\r\n }\r\n return ub;\r\n }\r\n}\r\nint lowerbound(T)(in T[] xs, in T x) {\r\n // find the minimum `i` that satisfies `x <= xs[i]`\r\n return xs.binsearch!(a => a >= x);\r\n}\r\nint upperbound(T)(in T[] xs, in T x) {\r\n // find the minimum `i` that satisfies `x < xs[i]`\r\n return xs.binsearch!(a => a > x);\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.functional;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto A = readarray!int;\r\n auto B = readarray!int;\r\n\r\n if (A.reduce!\"a + b\" < M) {\r\n writeln(-1);\r\n return;\r\n }\r\n\r\n int[] C, X;\r\n for (int i = 0; i < N; i++) {\r\n (B[i] == 1 ? C : X) ~= i;\r\n }\r\n C.sort!( (i, j) => A[i] > A[j] );\r\n X.sort!( (i, j) => A[i] > A[j] );\r\n\r\n int K = C.length;\r\n auto S = new long[K+1];\r\n for (int i = 0; i < K; i++) {\r\n S[i + 1] = S[i] + A[C[i]];\r\n }\r\n\r\n int ans = A.reduce!\"a+b\";\r\n long xsum = 0;\r\n for (int i = 0; ; i++) {\r\n long r = M - xsum;\r\n if (r > 0) {\r\n int k = S.lowerbound(r);\r\n if (k == K+1) {\r\n } else {\r\n ans.chmin(2*i + k);\r\n }\r\n } else {\r\n ans.chmin(2*i);\r\n }\r\n if (i == X.length) break;\r\n xsum += A[X[i]];\r\n }\r\n writeln(ans);\r\n}\r\n\r\nint binsearch(alias pred, T)(in T[] xs) {\r\n // find the minimum `i` that satisfies `pred(xs[i])`\r\n // NOTE: if none of the elements satisfies pred(x), returns `xs.length`\r\n alias C = unaryFun!pred;\r\n int N = cast(int)(xs.length);\r\n int lb = 0, ub = N;\r\n if (C(xs[lb])) {\r\n return 0;\r\n } else {\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(xs[mid]) ? ub : lb) = mid;\r\n }\r\n return ub;\r\n }\r\n}\r\nint lowerbound(T)(in T[] xs, in T x) {\r\n // find the minimum `i` that satisfies `x <= xs[i]`\r\n return xs.binsearch!(a => a >= x);\r\n}\r\nint upperbound(T)(in T[] xs, in T x) {\r\n // find the minimum `i` that satisfies `x < xs[i]`\r\n return xs.binsearch!(a => a > x);\r\n}\r\n"}], "src_uid": "e1fa7250c7004c093e1af788f23b2863"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto g = new long[cast(size_t)n];\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj.at(x).put(y);\n adj.at(y).put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n bool isImpossible = false;\n void check(long node, long parent)\n {\n totalp.at(node) = p.at(node);\n long hsum = 0;\n long gsum = 0;\n bool hasChildren = true;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp.at(node) += totalp.at(w);\n gsum += g.at(w);\n hasChildren = true;\n }\n // s\n if ((h.at(node) + totalp.at(node)) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n g.at(node) = (totalp.at(node) + h.at(node))/2;\n bool condition1 = adj[cast(size_t)node][].length > 1 && hsum > h[cast(size_t)node] + p[cast(size_t)node];\n bool condition1p = hasChildren && gsum > g.at(node);\n if(condition1p)\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n bool condition2 = h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node];\n bool condition2p = g.at(node) < 0 || g.at(node) > totalp.at(node);\n if (condition2p)\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n }\n check(0, -1);\n if (!isImpossible)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tauto n = p.length.to !(int);\n\t\tauto h = readln.splitter.map !(to !(int)).array;\n\t\tauto adj = new int [] [n];\n\t\tforeach (j; 0..n - 1)\n\t\t{\n\t\t\tauto v = readln.splitter.map !(to !(int)).array;\n\t\t\tv[] -= 1;\n\t\t\tadj[v[0]] ~= v[1];\n\t\t\tadj[v[1]] ~= v[0];\n\t\t}\n\n\t\tauto d = new int [n];\n\t\tbool ok = true;\n\n\t\tvoid recur (int v, int w)\n\t\t{\n\t\t\td[v] = p[v];\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tif (u != w)\n\t\t\t\t{\n\t\t\t\t\trecur (u, v);\n\t\t\t\t\td[v] += d[u];\n\t\t\t\t}\n\t\t\t}\n\t\t\tok &= (d[v] >= h[v] && (d[v] & 1) == (h[v] & 1));\n\t\t\th[v] = (d[v] - h[v]) / 2;\n\t\t}\n\n\t\trecur (0, -1);\n\n\t\tbool good (int v, int w)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tif (u != w)\n\t\t\t\t{\n\t\t\t\t\tcur += h[u];\n\t\t\t\t\tif (!good (u, v))\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn (cur >= h[v] - p[v]);\n\t\t}\n\n\t\twriteln (ok && good (0, -1) ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto g = new long[cast(size_t)n];\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj.at(x).put(y);\n adj.at(y).put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n bool isImpossible = false;\n void check(long node, long parent)\n {\n totalp.at(node) = p.at(node);\n long hsum = 0;\n long gsum = 0;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp.at(node) += totalp.at(w);\n gsum += g.at(w);\n }\n // s\n if ((h.at(node) + totalp.at(node)) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n g.at(node) = (totalp.at(node) + h.at(node))/2;\n bool condition1 = adj[cast(size_t)node][].length > 1 && hsum > h[cast(size_t)node] + p[cast(size_t)node];\n bool condition1p = gsum > g.at(node);\n if(condition1p)\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n bool condition2 = h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node];\n bool condition2p = g.at(node) < 0 || g.at(node) > totalp.at(node);\n if (condition2p)\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n }\n check(0, -1);\n if (!isImpossible)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = Array!long();\n p.length = cast(size_t)n;\n foreach(ref pi; p)\n read(pi);\n auto h = Array!long();\n h.length = cast(size_t)n;\n foreach(ref hi; h)\n read(hi);\n auto g = Array!long();\n g.length = cast(size_t)n;\n auto adj = Array!(Appender!(long[]))();\n adj.length = cast(size_t)n;\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj.at(x).put(y);\n adj.at(y).put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(null);\n }\n }\n void check(long node, long parent)\n {\n totalp.at(node) = p.at(node);\n long hsum = 0;\n bool hasChildren = true;\n foreach(w; adj.at(node)[])\n if (w != parent)\n {\n check(w, node);\n totalp.at(node) += totalp.at(w);\n hsum += h.at(w);\n hasChildren = true;\n }\n if ((h.at(node) + totalp.at(node)) % 2 != 0\n || hasChildren && hsum > h.at(node) + p.at(node)\n || h.at(node) > totalp.at(node) || h.at(node) < -totalp.at(node))\n throw new Impossible();\n }\n try\n check(0, -1);\n catch(Impossible)\n goto no;\n yes:\n writeln(\"YES\");\n continue;\n no:\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto g = new long[cast(size_t)n];\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj.at(x).put(y);\n adj.at(y).put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n void check(long node, long parent)\n {\n totalp.at(node) = p.at(node);\n long hsum = 0;\n bool hasChildren = true;\n foreach(w; adj.at(node)[])\n if (w != parent)\n {\n check(w, node);\n totalp.at(node) += totalp.at(w);\n hsum += h.at(w);\n hasChildren = true;\n }\n if ((h.at(node) + totalp.at(node)) % 2 != 0\n || hasChildren && hsum > h.at(node) + p.at(node)\n || h.at(node) > totalp.at(node) || h.at(node) < -totalp.at(node))\n throw new Impossible();\n }\n try\n check(0, -1);\n catch(Impossible)\n goto no;\n yes:\n writeln(\"YES\");\n continue;\n no:\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto g = new long[cast(size_t)n];\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj.at(x).put(y);\n adj.at(y).put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n bool isImpossible = false;\n void check(long node, long parent)\n {\n totalp.at(node) = p.at(node);\n long hsum = 0;\n long gsum = 0;\n bool hasChildren = true;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp.at(node) += totalp.at(w);\n gsum += g.at(w);\n hsum += h.at(w);\n hasChildren = true;\n }\n // s\n if ((h.at(node) + totalp.at(node)) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n g.at(node) = (totalp.at(node) + h.at(node))/2;\n bool condition1 = hasChildren && hsum > h.at(node) + p.at(node);\n bool condition1p = hasChildren && gsum > g.at(node);\n if(condition1)\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n bool condition2 = h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node];\n bool condition2p = g.at(node) < 0 || g.at(node) > totalp.at(node);\n if (condition2)\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n }\n check(0, -1);\n if (!isImpossible)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto p = RDA!int;\n\t\tauto h = RDA!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong[2] dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt0, cnt1;\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == last) continue;\n\t\t\t\tauto r = dfs(to, pos);\n\t\t\t\tcnt0 += r[0];\n\t\t\t\tcnt1 += r[1];\n\t\t\t}\n\t\t\tauto d = cnt0 - cnt1;\n\t\t\tauto v = h[pos] - d;\n\t\t\tauto remain = p[pos] - abs(v);\n\t\t\tif (remain < 0 && v > 0)\n\t\t\t{\n\t\t\t\tdebug writeln(\"d:\", d, \" v:\", v, \" remain:\", remain);\n\t\t\t\tdebug writeln(\"cnt:\", cnt0, \" \", cnt1);\n\t\t\t\tcnt0 += p[pos];\n\t\t\t\tv -= p[pos];\n\t\t\t\tauto u = min(cnt1, abs(remain/2));\n\t\t\t\tcnt0 += u;\n\t\t\t\tcnt1 -= u;\n\t\t\t\tv -= u*2;\n\t\t\t\tremain += u*2;\n\t\t\t\tdebug writeln(\"d:\", d, \" v:\", v, \" remain:\", remain);\n\t\t\t\tdebug writeln(\"cnt:\", cnt0, \" \", cnt1);\n\t\t\t}\n\t\t\tif (remain < 0 || remain % 2)\n\t\t\t{\n\t\t\t\tdebug writeln(\"false pos:\", pos, \" remain:\", remain);\n\t\t\t\tok = false;\n\t\t\t}\n\t\t\tif (v > 0)\n\t\t\t\tcnt0 += v;\n\t\t\telse\n\t\t\t\tcnt1 += abs(v);\n\t\t\tcnt0 += remain / 2;\n\t\t\tcnt1 += remain / 2;\n\t\t\treturn [cnt0, cnt1];\n\t\t}\n\t\tauto r = dfs(0, -1);\n\t\tdebug writeln(\"m:\", m, \" \", r);\n\t\tif (r[0] + r[1] != m)\n\t\t\tok = false;\n\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tauto n = p.length.to !(int);\n\t\tauto m = p.sum;\n\t\tauto h = readln.splitter.map !(to !(int)).array;\n\t\tauto adj = new int [] [n];\n\t\tforeach (j; 0..n - 1)\n\t\t{\n\t\t\tauto v = readln.splitter.map !(to !(int)).array;\n\t\t\tv[] -= 1;\n\t\t\tadj[v[0]] ~= v[1];\n\t\t\tadj[v[1]] ~= v[0];\n\t\t}\n\n\t\tauto d = new int [n];\n\t\tbool ok = true;\n\n\t\tvoid recur (int v, int w)\n\t\t{\n\t\t\td[v] = p[v];\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tif (u != w)\n\t\t\t\t{\n\t\t\t\t\trecur (u, v);\n\t\t\t\t\td[v] += d[u];\n\t\t\t\t}\n\t\t\t}\n\t\t\tok &= ((d[v] & 1) == (h[v] & 1));\n\t\t\th[v] = (d[v] - h[v]) / 2;\n\t\t}\n\n\t\trecur (0, -1);\n\n\t\tbool good (int v, int w)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tif (u != w)\n\t\t\t\t{\n\t\t\t\t\tcur += h[u];\n\t\t\t\t\tif (!good (u, v))\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn (cur >= h[v] - p[v]);\n\t\t}\n\n\t\twriteln (ok && good (0, -1) ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto g = new long[cast(size_t)n];\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj[cast(size_t)x].put(y);\n adj[cast(size_t)y].put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n bool isImpossible = false;\n void check(long node, long parent)\n {\n totalp[cast(size_t)node] = p[cast(size_t)node];\n long hsum = 0;\n long gsum = 0;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp[cast(size_t)node] += totalp[cast(size_t)w];\n hsum += h[cast(size_t)w];\n gsum += g[cast(size_t)w];\n }\n // s\n if ((h[cast(size_t)node] + totalp[cast(size_t)node]) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n g[cast(size_t)node] = (totalp[cast(size_t)node] + h[cast(size_t)node])/2;\n bool condition1 = adj[cast(size_t)node][].length > 1 && hsum > h[cast(size_t)node] + p[cast(size_t)node];\n bool condition1p = adj[cast(size_t)node][].length > 1 && gsum > g[cast(size_t)node];\n if(condition1p)\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n bool condition2 = h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node];\n bool condition2p = g[cast(size_t)node] < 0 || g[cast(size_t)node] > totalp[cast(size_t)node];\n if (condition2p)\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n }\n check(0, -1);\n if (!isImpossible)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto g = new long[cast(size_t)n];\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj[cast(size_t)x].put(y);\n adj[cast(size_t)y].put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n void check(long node, long parent)\n {\n totalp[cast(size_t)node] = p[cast(size_t)node];\n long hsum = 0;\n long gsum = 0;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp[cast(size_t)node] += totalp[cast(size_t)w];\n hsum += h[cast(size_t)w];\n gsum += g[cast(size_t)w];\n }\n // s\n if ((h[cast(size_t)node] + totalp[cast(size_t)node]) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n g[cast(size_t)node] = (totalp[cast(size_t)node] + h[cast(size_t)node])/2;\n bool condition1 = adj[cast(size_t)node][].length > 1 && hsum > h[cast(size_t)node] + p[cast(size_t)node];\n bool condition1p = adj[cast(size_t)node][].length > 1 && gsum > g[cast(size_t)node];\n assert(condition1 == condition1p);\n if(condition1p)\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n bool condition2 = h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node];\n bool condition2p = g[cast(size_t)node] < 0 || g[cast(size_t)node] > totalp[cast(size_t)node];\n if (condition2p)\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n }\n try\n {\n check(0, -1);\n }\n catch(Impossible impossible)\n {\n goto isImpossible;\n }\n writeln(\"YES\");\n continue;\n isImpossible:\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto g = new long[cast(size_t)n];\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj[cast(size_t)x].put(y);\n adj[cast(size_t)y].put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n void check(long node, long parent)\n {\n totalp[cast(size_t)node] = p[cast(size_t)node];\n long hsum = 0;\n long gsum = 0;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp[cast(size_t)node] += totalp[cast(size_t)w];\n hsum += h[cast(size_t)w];\n gsum += g[cast(size_t)w];\n }\n // s\n if ((h[cast(size_t)node] + totalp[cast(size_t)node]) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n g[cast(size_t)node] = (totalp[cast(size_t)node] + h[cast(size_t)node])/2;\n bool condition1 = adj[cast(size_t)node][].length > 1 && hsum > h[cast(size_t)node] + p[cast(size_t)node];\n bool condition1p = adj[cast(size_t)node][].length > 1 && gsum > g[cast(size_t)node];\n assert(condition1 == condition1p);\n if(condition1)\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n bool condition2 = h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node];\n bool condition2p = g[cast(size_t)node] < 0 || g[cast(size_t)node] > totalp[cast(size_t)node];\n if (condition2)\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n }\n try\n {\n check(0, -1);\n }\n catch(Impossible impossible)\n {\n goto isImpossible;\n }\n writeln(\"YES\");\n continue;\n isImpossible:\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n writeln(\"h = \", h);\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj[cast(size_t)x].put(y);\n adj[cast(size_t)y].put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n void check(long node, long parent)\n {\n totalp[cast(size_t)node] = p[cast(size_t)node];\n long hsum = 0;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp[cast(size_t)node] += totalp[cast(size_t)w];\n hsum += h[cast(size_t)w];\n }\n if(adj[cast(size_t)node][].length > 1 && hsum > h[cast(size_t)node] + p[cast(size_t)node])\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n if ((h[cast(size_t)node] + totalp[cast(size_t)node]) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n if (h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node])\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n }\n try\n {\n check(0, -1);\n }\n catch(Impossible impossible)\n {\n goto isImpossible;\n }\n writeln(\"YES\");\n continue;\n isImpossible:\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto g = new long[cast(size_t)n];\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj.at(x).put(y);\n adj.at(y).put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n bool isImpossible = false;\n void check(long node, long parent)\n {\n totalp.at(node) = p.at(node);\n long hsum = 0;\n long gsum = 0;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp.at(node) += totalp.at(w);\n gsum += g.at(w);\n }\n // s\n if ((h.at(node) + totalp.at(node)) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n g.at(node) = (totalp.at(node) + h.at(node))/2;\n bool condition1 = adj[cast(size_t)node][].length > 1 && hsum > h[cast(size_t)node] + p[cast(size_t)node];\n bool condition1p = adj.at(node)[].length > 1 && gsum > g.at(node);\n if(condition1p)\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n bool condition2 = h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node];\n bool condition2p = g.at(node) < 0 || g.at(node) > totalp.at(node);\n if (condition2p)\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n isImpossible = true;\n }\n }\n check(0, -1);\n if (!isImpossible)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n, m;\n read(n), read(m);\n auto p = new long[cast(size_t)n];\n foreach(ref pi; p)\n read(pi);\n auto h = new long[cast(size_t)n];\n foreach(ref hi; h)\n read(hi);\n auto adj = new Appender!(long[])[cast(size_t)n];\n foreach(ref list; adj)\n list = appender!(long[])();\n foreach(i; 0 .. n - 1)\n {\n long x, y;\n read(x), x--;\n read(y), y--;\n adj[cast(size_t)x].put(y);\n adj[cast(size_t)y].put(x);\n }\n auto totalp = new long[cast(size_t)n];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n void check(long node, long parent)\n {\n totalp[cast(size_t)node] = p[cast(size_t)node];\n long hsum = 0;\n foreach(w; adj[cast(size_t)node][])\n if (w != parent)\n {\n check(w, node);\n totalp[cast(size_t)node] += totalp[cast(size_t)w];\n hsum += h[cast(size_t)w];\n }\n if(adj[cast(size_t)node][].length > 1 && hsum > h[cast(size_t)node] + p[cast(size_t)node])\n {\n version(none) writeln(1, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n if ((h[cast(size_t)node] + totalp[cast(size_t)node]) % 2 != 0)\n {\n version(none) writeln(2, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n if (h[cast(size_t)node] > totalp[cast(size_t)node] || h[cast(size_t)node] < -totalp[cast(size_t)node])\n {\n version(none) writeln(3, \" \", node + 1, \" \", parent + 1);\n throw new Impossible();\n }\n }\n try\n {\n check(0, -1);\n }\n catch(Impossible impossible)\n {\n goto isImpossible;\n }\n writeln(\"YES\");\n continue;\n isImpossible:\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto p = RDA!int;\n\t\tauto h = RDA!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong[2] dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt0, cnt1;\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == last) continue;\n\t\t\t\tauto r = dfs(to, pos);\n\t\t\t\tcnt0 += r[0];\n\t\t\t\tcnt1 += r[1];\n\t\t\t}\n\t\t\tauto d = cnt0 - cnt1;\n\t\t\tauto d2 = h[pos] - d;\n\t\t\tauto remain = p[pos] - abs(d2);\n\t\t\tif (remain < 0 && d2 > 0)\n\t\t\t{\n\t\t\t\tcnt0 -= remain;\n\t\t\t\tcnt1 += remain;\n\t\t\t\td2 += remain;\n\t\t\t\tremain = 0;\n\t\t\t}\n\t\t\tif (remain < 0 || remain % 2 || cnt0 < 0)\n\t\t\t{\n\t\t\t\tdebug writeln(\"false pos:\", pos, \" remain:\", remain);\n\t\t\t\tok = false;\n\t\t\t}\n\t\t\tif (d2 > 0)\n\t\t\t\tcnt0 += d2;\n\t\t\telse\n\t\t\t\tcnt1 += abs(d2);\n\t\t\tcnt0 += remain / 2;\n\t\t\tcnt1 += remain / 2;\n\t\t\treturn [cnt0, cnt1];\n\t\t}\n\t\tauto r = dfs(0, -1);\n\t\tdebug writeln(\"m:\", m, \" \", r);\n\t\tif (r[0] + r[1] != m)\n\t\t\tok = false;\n\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto p = RDA!int;\n\t\tauto h = RDA!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt = p[pos];\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == last) continue;\n\t\t\t\tcnt += dfs(to, pos);\n\t\t\t}\n\t\t\tauto d = abs(cnt - h[pos]);\n\t\t\tif (d % 2 || abs(h[pos]) > cnt)\n\t\t\t\tok = false;\n\t\t\treturn cnt;\n\t\t}\n\t\tif (dfs(0, -1) != m)\n\t\t\tok = false;\n\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto p = RDA!int;\n\t\tauto h = RDA!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tbool ok = true;\n\t\tint dfs(int pos, int last)\n\t\t{\n\t\t\tint cnt = p[pos];\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == last) continue;\n\t\t\t\tcnt += dfs(to, pos);\n\t\t\t}\n\t\t\tauto d = abs(cnt - h[pos]);\n\t\t\tif (d % 2 || abs(h[pos]) > cnt)\n\t\t\t\tok = false;\n\t\t\treturn cnt;\n\t\t}\n\t\tdfs(0, -1);\n\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto p = RDA!int;\n\t\tauto h = RDA!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tbool ok = true;\n\t\tint dfs(int pos, int last)\n\t\t{\n\t\t\tint cnt = p[pos];\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == last) continue;\n\t\t\t\tcnt += dfs(to, pos);\n\t\t\t}\n\t\t\tauto d = abs(cnt - h[pos]);\n\t\t\tif (d % 2 || abs(h[pos]) > cnt)\n\t\t\t\tok = false;\n\t\t\treturn cnt;\n\t\t}\n\t\tif (dfs(0, -1) != m)\n\t\t\tok = false;\n\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto p = RDA!int;\n\t\tauto h = RDA!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong[2] dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt0, cnt1;\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == last) continue;\n\t\t\t\tauto r = dfs(to, pos);\n\t\t\t\tcnt0 += r[0];\n\t\t\t\tcnt1 += r[1];\n\t\t\t}\n\t\t\tauto d = cnt0 - cnt1;\n\t\t\tauto v = h[pos] - d;\n\t\t\tauto remain = p[pos] - abs(v);\n\t\t\tif (remain < 0 && v > 0)\n\t\t\t{\n\t\t\t\tcnt0 -= remain;\n\t\t\t\tcnt1 += remain;\n\t\t\t\tv += remain;\n\t\t\t\tremain = 0;\n\t\t\t}\n\t\t\tif (remain < 0 || remain % 2 || cnt1 < 0)\n\t\t\t{\n\t\t\t\tdebug writeln(\"false pos:\", pos, \" remain:\", remain);\n\t\t\t\tok = false;\n\t\t\t}\n\t\t\tif (v > 0)\n\t\t\t\tcnt0 += v;\n\t\t\telse\n\t\t\t\tcnt1 += abs(v);\n\t\t\tcnt0 += remain / 2;\n\t\t\tcnt1 += remain / 2;\n\t\t\treturn [cnt0, cnt1];\n\t\t}\n\t\tauto r = dfs(0, -1);\n\t\tdebug writeln(\"m:\", m, \" \", r);\n\t\tif (r[0] + r[1] != m)\n\t\t\tok = false;\n\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto p = RDA!int;\n\t\tauto h = RDA!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto x = RD!int-1;\n\t\t\tauto y = RD!int-1;\n\t\t\tedges[x] ~= y;\n\t\t\tedges[y] ~= x;\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt = p[pos];\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == last) continue;\n\t\t\t\tcnt += dfs(to, pos);\n\t\t\t}\n\t\t\tif ((cnt % 2 != abs(h[pos]) % 2) || (abs(h[pos]) > cnt))\n\t\t\t\tok = false;\n\t\t\treturn cnt;\n\t\t}\n\t\tif (dfs(0, -1) != m)\n\t\t\tok = false;\n\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "0369c070f4ac9aba4887bae32ad8b85b"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int m, n;\n readf!\" %d %d \"(m, n);\n int[] frjoy = new int[](n);\n int[][] joy;\n int sharedshopjoy;\n foreach (i ; 0 .. m) {\n joy ~= readln.splitter.map!(to!int).array;\n foreach (j ; 0 .. n)\n frjoy[j] = max(frjoy[j], joy.back[j]);\n joy.back.sort;\n sharedshopjoy = max(sharedshopjoy, joy.back[$ - 2]);\n }\n int ans = frjoy.minElement;\n if (n - 1 < m)\n ans = min(ans, sharedshopjoy);\n writeln(ans);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n readln;\r\n int M, N; readf(\"%d %d\\n\", &M, &N);\r\n auto P = new int[][M];\r\n foreach (ref L; P) L = readarray!int;\r\n\r\n bool C(int x) {\r\n bool[int] s;\r\n for (int j = 0; j < N; j++) {\r\n int c = 0;\r\n for (int i = 0; i < M; i++) {\r\n if (P[i][j] >= x) {\r\n c++;\r\n }\r\n }\r\n if (c == 0) return false;\r\n }\r\n for (int j = 0; j < N; j++) {\r\n for (int i = 0; i < M; i++) {\r\n if (P[i][j] >= x) {\r\n if (i in s) return true;\r\n s[i] = true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n int lb = 0, ub = 1_000_000_010;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? lb : ub) = mid;\r\n }\r\n writeln(lb);\r\n}\r\n"}], "negative_code": [], "src_uid": "5f8916876c2889cfe9265cd71905ad99"} {"source_code": "import std.stdio;\nimport std.string : split, strip;\nimport std.algorithm : any, count, map, sort;\nimport std.conv : to;\nimport std.array;\nimport std.range : slide;\n\nstatic bool even(ulong a) { return (a & 1) == 0; }\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n auto a = readln.strip.split.map!(to!uint).array;\n a.sort;\n\n auto d = a.slide(2).any!\"a[1] - a[0] == 1\";\n auto c = a.count!even;\n\n if (even(c) || d) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\t\n\t\tlong cnt;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] % 2)\n\t\t\t\t++cnt;\n\t\t}\n\t\tif (cnt % 2 == 0 && (n-cnt) % 2 == 0)\n\t\t\tans[ti] = true;\n\t\telse if (cnt % 2 && (n-cnt % 2))\n\t\t{\n\t\t\ta.sort();\n\t\t\tforeach (i; 1..n)\n\t\t\t{\n\t\t\t\tif (a[i]-1 == a[i-1])\n\t\t\t\t\tans[ti] = true;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n sort(a);\n long p = a.count!(ai => ai % 2 == 0), i = a.count!(ai => ai % 2 == 1);\n bool has1p = iota(0, n - 1).map!(i => abs(a.at(i) - a.at(i + 1))).canFind(1);\n if ((p + i) % 2 == 0)\n {\n if (p % 2 == 0)\n {\n writeln(\"YES\");\n }\n else\n {\n if (has1p)\n {\n writeln(\"YES\");\n }\n else\n {\n writeln(\"NO\");\n }\n }\n }\n else\n {\n writeln(\"NO\");\n }\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [], "src_uid": "005a29a4b4e7ee4fd21444846014727b"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.exception;\n\n int t;\n rd(t);\n while (t--) {\n int a;\n rd(a);\n bool ok = false;\n for (int n = 3; n <= 360; n++) {\n if (360 % n == 0) {\n auto x = 180 - 360 / n;\n if (a * (n - 2) % x == 0) {\n if (a * (n - 2) / x <= (n - 2)) {\n writeln(n);\n ok = true;\n break;\n }\n }\n }\n }\n enforce(ok);\n }\n\n}\n\n/*\n\n3 60 60\n4 90 45\n5 108 36\n6 120 30\n7 180-360/7 x/5\n8 135 135/6\n.\n.\n.\nn 180-360/n:=x x/(n-2)\n\n*/\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\n\nvoid main() {\n GC.disable();\n\n int[] cc = new int[200];\n cc[] = 0;\n\n foreach(n; 3 .. 2000) {\n foreach(i; 0 .. n-1) {\n if ( (i*180) % n == 0) {\n uint a = i*180 / n;\n if (cc[a] == 0) {\n cc[a] = n;\n }\n }\n }\n }\n\n uint T;\n readf(\" %s\", T);\n foreach(i; 0 .. T) {\n uint ang;\n readf(\" %s\", ang);\n if (cc[ang] != 0) writeln(cc[ang]);\n else writeln(-1);\n }\n\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n auto X = readln.chomp.to!long;\n auto Y = 180L;\n auto G = gcd(X, Y);\n X /= G;\n Y /= G;\n if (Y - X == 1) {\n Y *= 2;\n }\n writeln(Y);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\n\nvoid main() {\n GC.disable();\n\n int[] cc = new int[200];\n cc[] = 0;\n\n foreach(n; 3 .. 200) {\n foreach(i; 0 .. n-1) {\n if ( (i*180) % n == 0) {\n uint a = i*180 / n;\n if (cc[a] == 0) {\n cc[a] = n;\n }\n }\n }\n }\n\n uint T;\n readf(\" %s\", T);\n foreach(i; 0 .. T) {\n uint ang;\n readf(\" %s\", ang);\n if (cc[ang] != 0) writeln(cc[ang]);\n else writeln(-1);\n }\n\n}\n"}], "src_uid": "d11b56fe172110d5dfafddf880e48f18"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\n\nint n;\nint[] a;\n\nvoid main() {\n scan(n);\n a = readln.split.to!(int[]);\n\n int f = a[0], s = a[1], t = a[2];\n\n if (f > s) swap(f, s);\n if (s > t) swap(s, t);\n if (f > s) swap(f, s);\n\n int tmp1, tmp2;\n\n foreach (i ; 3 .. n) {\n if (a[i] < f) {\n tmp1 = f, tmp2 = s;\n f = a[i], s = tmp1, t = tmp2;\n }\n else if (a[i] < s) {\n tmp1 = s;\n s = a[i], t = tmp1;\n }\n else if (a[i] < t) {\n t = a[i];\n }\n }\n\n debug {\n stderr.writeln(f, \" \", s, \" \", t);\n }\n\n long x = a.count(t), ans;\n\n if (f < s) {\n if (s < t) {\n ans = x;\n }\n else {\n ans = x * (x - 1) / 2;\n }\n }\n else if (s < t) {\n ans = x;\n }\n else {\n ans = x * (x - 1) * (x - 2) / 6;\n }\n\n writeln(ans);\n}\n\nvoid scan(T...)(ref T args) {\n auto line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n assert(line.empty);\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math;\n\nimmutable int mod = 10^^9 + 7;\n\nint n;\nint[] a;\n\nvoid main() {\n n = readln.chomp.to!int;\n a = readln.split.to!(int[]);\n\n a.sort();\n long ans, x;\n\n if (a[0] < a[1]) {\n if (a[1] < a[2]) {\n ans = a.count(a[2]);\n }\n else if (a[1] == a[2] && a[2] < a[3]) {\n ans = 1;\n }\n else {\n x = a.count(a[1]);\n ans = x * (x - 1) / 2;\n }\n }\n else if (a[0] == a[1] && a[1] < a[2]) {\n if (a[2] < a[3]) {\n ans = 1;\n }\n else {\n ans = a.count(a[2]);\n }\n }\n else {\n x = a.count(a[0]);\n ans = x * (x - 1) * (x - 2) / 6;\n }\n\n writeln(ans);\n}\n\nvoid readVariables(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg ; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if (!line.empty) {\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\n\nint n;\nint[] a;\n\nvoid main() {\n scan(n);\n a = readln.split.to!(int[]);\n\n a.sort();\n\n long ans, x;\n\n x = a.count(a[2]);\n\n if (a[0] < a[1]) {\n if (a[1] < a[2]) {\n ans = x;\n }\n else {\n ans = x * (x - 1) / 2;\n }\n }\n else if (a[1] < a[2]) {\n ans = x;\n }\n else {\n ans = x * (x - 1) * (x - 2) / 6;\n }\n\n writeln(ans);\n}\n\nvoid scan(T...)(ref T args) {\n auto line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n assert(line.empty);\n}"}], "negative_code": [], "src_uid": "4c2d804bb2781abfb43558f8b2c6424f"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n char[][] mat = new char[][n];\n \n int comb = 0;\n //row-major traversal\n for (int i = 0; i < n; i++) {\n int count = 0; \n mat[i] = new char[n];\n mat[i] = cin.read_string.dup;\n for (int j = 0; j < n; j++) {\n if (mat[i][j] == 'C') count++;\n }\n comb += (count * (count - 1)) / 2;\n }\n\n //column-major traversal\n for (int i = 0; i < n; i++) {\n int count = 0;\n for (int j = 0; j < n; j++) {\n if (mat[j][i] == 'C') count++;\n }\n comb += (count * (count - 1)) / 2;\n }\n\n writeln(comb);\n } \n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.range, std.string, std.conv;\n\nvoid main() {\n int n = readln.chomp.to!int;\n string[] cake;\n foreach (i; 0..n) {\n cake ~= readln.chomp;\n }\n\n int ans = 0;\n foreach (row; cake) {\n auto c = row.count!(\"a == 'C'\");\n if (c > 1) {\n ans += c * (c - 1) / 2;\n }\n }\n\n foreach (col; cake.transposed) {\n auto c = col.count!(\"a == 'C'\");\n if (c > 1) {\n ans += c * (c - 1) / 2;\n }\n }\n\n ans.writeln;\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n\tint n;\n\t\n\tscanf(\"%d\", &n);\n\t\n\tchar[][] m = new char[][n];\n\t\n\tfor (int i = 0; i < n; i++) {\n\t\tm[i] = new char[n + 1];\n\t\tscanf(\"%s\", m[i].ptr);\n\t}\n\t\n\tint res = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tint r = 0;\n\t\tint c = 0;\n\t\tfor (int j = 0; j < n; j++) {\n\t\t\tif (m[j][i] == 'C')\n\t\t\t\tc++;\n\t\t\tif (m[i][j] == 'C')\n\t\t\t\tr++;\n\t\t}\n\t\t\n\t\tres += (r - 1) * r / 2;\n\t\tres += (c - 1) * c / 2;\n\t}\n\t\n\tprintf(\"%d\\n\", res);\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array: Appender;\nimport std.datetime;\nimport std.algorithm;\n\nvoid main()\n{\n\n\tauto n = to!int(strip(readln));\n\tint[] r = new int[n];\n\tint[] c = new int[n];\n\tfor (auto i = 0; i < n; i++)\n\t{\n\t\tauto str = strip(readln);\n\t\tforeach (j, ch; str)\n\t\t{\n\t\t\tif (ch == 'C')\n\t\t\t{\n\t\t\t\tr[i]++;\n\t\t\t\tc[j]++;\n\t\t\t}\n\t\t}\n\t}\n\tint count;\n\tforeach (i, ele; r)\n\t{\n\t\tcount += (r[i] * (r[i] - 1)) / 2 + (c[i] * (c[i] - 1)) / 2;\n\t}\n\n\twriteln(count);\n}\n"}], "negative_code": [], "src_uid": "7749f37aa9bf88a00013557e14342952"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto s = readln.chomp.split.map!(to!int).array;\n \n s.sort();\n \n if (s.fold!gcd != s[0]) {\n writeln(-1);\n return;\n }\n \n int[] ans;\n foreach (e; s) {\n ans ~= e;\n ans ~= s[0];\n }\n \n ans.length.writeln;\n ans.writefln!\"%(%s %)\";\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nvoid main() {\n int m;\n scan(m);\n auto s = readln.split.to!(int[]);\n\n foreach (j ; 1 .. m) {\n if (s[j] % s[0]) {\n writeln(-1);\n return;\n }\n }\n\n auto ans = new int[](0);\n ans ~= s[0];\n\n foreach (i ; 1 .. m) {\n ans ~= s[i];\n ans ~= s[0];\n }\n\n int n = ans.length.to!int;\n\n writeln(n);\n writefln(\"%(%s %)\",ans);\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\n\nstruct Queue(T) {\n private {\n int N, head, tail;\n T[] data;\n }\n\n this(int n) {\n N = n + 1;\n data = new T[](N);\n }\n\n bool empty() {\n return head == tail;\n }\n\n bool full() {\n return (tail + 1) % N == head;\n }\n\n T front() {\n return data[head];\n }\n\n void push(T x) {\n assert(!full);\n data[tail++] = x;\n tail %= N;\n }\n\n void pop() {\n assert(!empty);\n head = (head + 1) % N;\n }\n\n void clear() {\n head = tail = 0;\n }\n}"}], "negative_code": [], "src_uid": "dfe5af743c9e23e98e6c9c5c319d2126"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto c = n.iota.array;\n\n\t\talias Edge = Tuple !(int, q{u}, int, q{v});\n\t\tEdge [] answer;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tif (a[i] != a[j] && c[i] != c[j])\n\t\t\t\t{\n\t\t\t\t\tanswer ~= Edge (i, j);\n\t\t\t\t\tint u = c[i];\n\t\t\t\t\tforeach (k; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (c[k] == u)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tc[k] = c[j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (answer.length >= n - 1)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\tforeach (ref e; answer)\n\t\t\t{\n\t\t\t\twriteln (e.u + 1, \" \", e.v + 1);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nll[] arr;\nbool[] vis;\nint[] par;\n\nint dfs(int v){\n vis[v] = 1;\n int summ = 1;\n foreach(i; 0..arr.length){\n if(!vis[i] && arr[i] != arr[v]){\n par[i] = v;\n summ += dfs(i.to!int);\n }\n }\n return summ;\n}\n\nvoid play(){\n int n;\n n = rd!int;\n arr = rdarr;\n par = new int[n];\n vis = new bool[n];\n foreach(i; 0..n){\n par[] = 0;\n vis[] = 0;\n par[i] = -1;\n int found = dfs(i);\n if(found == n){\n\n writeln(\"YES\");\n foreach(k; 0..n){\n if(par[k] != -1){\n writeln(k+1, \" \", par[k] + 1);\n }\n }\n return;\n }\n }\n writeln(\"NO\");\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ a.each!(w => write(w, \"| \")); writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA(-1);\n\n\t\tbool ok;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] != a[0])\n\t\t\t{\n\t\t\t\tok = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!ok) continue;\n\n\t\tauto used = new bool[](n*n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tif (a[i] != a[j])\n\t\t\t\t{\n\t\t\t\t\tauto u = min(i, j);\n\t\t\t\t\tauto v = max(i, j);\n\t\t\t\t\tif (!used[u*n+v])\n\t\t\t\t\t{\n\t\t\t\t\t\tused[u*n+v] = true;\n\t\t\t\t\t\tans[ti] ~= [u, v];\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(\"NO\");\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\tforeach (ee; e)\n\t\t\t{\n\t\t\t\twriteln(ee[0]+1, \" \", ee[1]+1);\n\t\t\t}\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n auto par = new ll[n];\n auto vis = new bool[n];\n vis[0] = 1; par[0] = -1;\n foreach(i; 0..n){\n if(!vis[i]){\n foreach(j; 0..n){\n if(vis[j] && arr[j] != arr[i]){\n par[i] = j; vis[i] = 1;\n break;\n }\n }\n }\n if(!vis[i]){\n writeln(\"NO\");\n return;\n }\n }\n writeln(\"YES\");\n foreach(i; 0..n){\n if(par[i] != -1){\n writeln(i+1, \" \", par[i] + 1);\n }\n }\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ a.each!(w => write(w, \"| \")); writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n"}], "src_uid": "d8136eb72931851f501c5ce9042ce4eb"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (a.canFind (1) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n const K = readInt;\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt;\n }\n \n bool ans;\n foreach (i; 0 .. N) {\n ans = ans || (A[i] == 1);\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "95d83cfdb2131f2f23ba5ef005c18b38"} {"source_code": "import std.stdio, std.string, std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.math;\nvoid main(){\n int n = readln.chomp.to!int;\n auto ls = readln.chomp.split.map!(to!long);\n\n long s = 0;\n foreach(l; ls){\n s += l;\n }\n \n long m = 0;\n foreach(l; ls){\n m = max(m, l);\n }\n long res = abs(2*m-s)+1;\n\n writeln(res);\n\n}", "positive_code": [{"source_code": "module main;\n\nimport std.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.random;\nimport std.conv;\n\n\n\n\n\n\n\nvoid main ()\n{\n int n,sum = 0,add;\n readf(\" %s\", &n);\n int [] a = new int [](n);\n for ( int i = 0; i < n; i++)\n {\n readf(\" %s\", &a[i]);\n sum += a[i];\n }\n for ( int i = 0; i< n; i++)\n if ( a[i] >= sum - a[i]) add = (abs(sum - 2*a[i])+ 1);\n writeln(add);\n\n\n\n\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.math;\nvoid main(){\n int n = readln.chomp.to!int;\n auto ls = readln.chomp.split.map!(to!long);\n\n long res = 0;\n foreach(long l; ls){\n res = abs (res - l);\n }\n\n writeln(res+1);\n\n}"}], "src_uid": "f00d94eb37c98a449615f0411e5a3572"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n auto a = readln.strip.split(\"\").map!((x) => (x[0] == '?') ? 3 : (x[0] == '0' ? 1 : 2));\n// writeln(a);\n long[][2] dp;\n bool[] avail;\n dp[0] = new long[](a.length);\n dp[1] = new long[](a.length);\n dp[0][0] = (a[0] & 1) ? 1 : 0;\n dp[1][0] = (a[0] & 2) ? 1 : 0;\n foreach (i ; 1 .. a.length) {\n if (a[i] & 1)\n dp[0][i] = dp[1][i - 1] + 1;\n else\n dp[0][i] = 0;\n if (a[i] & 2)\n dp[1][i] = dp[0][i - 1] + 1;\n else\n dp[1][i] = 0;\n }\n// writeln(dp);\n long result = 0;\n foreach (i ; 0 .. a.length) {\n result += max(dp[0][i], dp[1][i]);\n }\n writeln(result);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip;\r\n\t\tauto n = s.length.to !(int);\r\n\t\tint prev = -1;\r\n\t\tint mark = -1;\r\n\t\tint odd = -3;\r\n\t\tlong res = 0;\r\n\t\tforeach (i, c; s)\r\n\t\t{\r\n\t\t\todd ^= 1;\r\n\t\t\tif (c != '?')\r\n\t\t\t{\r\n\t\t\t\tif (odd >= 0 && odd != c - '0')\r\n\t\t\t\t{\r\n\t\t\t\t\tprev = mark;\r\n\t\t\t\t}\r\n\t\t\t\todd = c - '0';\r\n\t\t\t\tmark = i;\r\n\t\t\t}\r\n\t\t\tres += i - prev;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport core.stdc.stdio;\n\nint main()\n{\n int t = readInt!int;\n foreach(ti; 0 .. t)\n {\n string str = readString;\n auto a = new int[](str.length);\n foreach(i, ref ai; a)\n switch(str[i])\n {\n case '0': ai = 0 ^ (i & 1); continue;\n case '1': ai = 1 ^ (i & 1); continue;\n default: ai = -1; continue;\n }\n debug writeln(a);\n int c0 = 0;\n int c1 = 0;\n long result = 0;\n foreach(i, ai; a)\n {\n if (ai == 0) c0++, c1 = 0;\n if (ai == 1) c1++, c0 = 0;\n if (ai == -1) c0++, c1++;\n if (ai == 0) result += c0;\n if (ai == 1) result += c1;\n if (ai == -1) result += max(c0, c1);\n }\n result.writeln;\n }\n return 0;\n}\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n long rep;\n this(long num)\n {\n rep = num;\n }\n Z!m opBinary(string operator)(Z!m rhs)\n {\n static if (operator == \"+\")\n {\n long result = rhs.rep + this.rep;\n if (result >= m) result -= m;\n return Z!m(result);\n }\n else static if (operator == \"-\")\n {\n long result = this.rep - rhs.rep;\n if (result < 0) result += m;\n return Z!m(result);\n }\n else static if (operator == \"*\")\n {\n long result = this.rep * rhs.rep;\n if (result >= m) result %= m;\n return Z!m(result);\n } else static assert(text(\"Operator \", operator, \" not supported\"));\n }\n Z!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n {\n assert(exponent >= 0);\n Z!m base = this;\n Z!m result = 1;\n while (exponent)\n {\n if (exponent & 1)\n result = result * base;\n base = base * base;\n exponent >>= 1;\n }\n return result;\n }\n invariant\n {\n assert(rep >= 0 && rep < m);\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n auto a = readln.strip.split(\"\").map!((x) => (x[0] == '?') ? 3 : (x[0] == '0' ? 1 : 2));\n auto dp = new long[][](a.length, 2);\n dp[0][0] = (a[0] & 1) ? 1 : 0;\n dp[0][1] = (a[0] & 2) ? 1 : 0;\n foreach (i ; 1 .. a.length) {\n dp[i][0] = (a[i] & 1) ? dp[i - 1][1] + 1 : 0;\n dp[i][1] = (a[i] & 2) ? dp[i - 1][0] + 1 : 0;\n }\n writeln(dp.fold!\"a + b.maxElement\"(0L));\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n auto a = readln.strip.split(\"\").map!((x) => (x[0] == '?') ? 3 : (x[0] == '0' ? 1 : 2));\n auto dp = new int[][](a.length, 2);\n dp[0][0] = (a[0] & 1) ? 1 : 0;\n dp[0][1] = (a[0] & 2) ? 1 : 0;\n foreach (i ; 1 .. a.length) {\n dp[i][0] = (a[i] & 1) ? dp[i - 1][1] + 1 : 0;\n dp[i][1] = (a[i] & 2) ? dp[i - 1][0] + 1 : 0;\n }\n writeln(dp.fold!\"a + b.maxElement\"(0));\n }\n}\n"}], "src_uid": "639eeeabcb005152035a1fcf09ed3b44"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\nimport std.container.rbtree;\nimport std.exception;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\n//alias T = Tuple!(int, int);\n//alias TR = RedBlackTree!(T);\nalias TR = RedBlackTree!(int, \"a<b\", true);\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n const k = r.next!uint;\n auto _m = r.nextA!uint(n);\n auto m = assumeUnique (_m);\n auto _c = r.nextA!uint(k);\n auto c = assumeUnique (_c);\n int j = k - 1;\n auto x = new int[n+1];\n x[0] = k;\n foreach (t; 1 .. n + 1) {\n while (j >= 0 && c[j] == t) --j;\n x[t] = j + 1;\n }\n debug stderr.writeln (x);\n auto t = new TR;\n foreach (i, z; m) {\n //t.insert (T (z, 1 + i.to!int));\n t.insert (z);\n }\n int[][] ans;\n while (!t.empty) {\n int cur = 1;\n int[] b;\n while (cur <= n) {\n //auto rng = t.upperBound (T (x[cur], -1));\n auto rng = t.lowerBound (x[cur - 1] + 1);\n if (rng.empty) break;\n //auto q = m[rng.back];\n auto q = rng.back;\n b ~= q;\n t.removeKey (q);\n ++cur;\n }\n ans ~= b;\n }\n writeln (ans.length);\n foreach (const ref q; ans) {\n writefln!(\"%d %(%s %)\")(q.length, q);\n }\n\n\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto m = readln.splitter.map !(to !(int)).array;\n\t\tauto c = 0 ~ readln.splitter.map !(to !(int)).array;\n\n\t\tsort !(q{a > b}) (m);\n\t\tint [] [] answer;\n\t\tforeach (x; m)\n\t\t{\n\t\t\tint p = 0;\n\t\t\tint lo = 0;\n\t\t\tint hi = answer.length;\n\t\t\twhile (lo < hi)\n\t\t\t{\n\t\t\t\tint me = (lo + hi) / 2;\n\t\t\t\tif (answer[me].length < c[x])\n\t\t\t\t{\n\t\t\t\t\thi = me;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlo = me + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (lo == answer.length)\n\t\t\t{\n\t\t\t\tanswer ~= null;\n\t\t\t}\n\t\t\tanswer[lo] ~= x;\n\t\t}\n\n\t\twriteln (answer.length);\n\t\tforeach (ref line; answer)\n\t\t{\n\t\t\twritefln !(\"%s%( %s%)\") (line.length, line);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "5802f9c010efd1cdcee2fbbb4039a4cb"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nalias Edge = Tuple!(int, \"a\", int, \"b\", long, \"w\");\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto E = new Edge[M];\n foreach (i; 0 .. M) {\n E[i].a = readInt() - 1;\n E[i].b = readInt() - 1;\n E[i].w = readLong();\n }\n \n E.sort!\"a.w < b.w\";\n \n auto uf = new int[N];\n uf[] = -1;\n auto ms = new int[N];\n long ans;\n foreach_reverse (ref e; E) {\n const ra = uf.root(e.a);\n const rb = uf.root(e.b);\n if (ra == rb) {\n if (ms[ra] < -uf[ra]) {\n debug {\n writeln(e, \" make cycle\");\n }\n ans += e.w;\n ++ms[ra];\n }\n } else {\n if (ms[ra] < -uf[ra] || ms[rb] < -uf[rb]) {\n debug {\n writeln(e, \" connect\");\n }\n ans += e.w;\n uf.connect(ra, rb);\n const int r = uf.root(ra);\n ms[r] = ms[ra] + ms[rb] + 1;\n }\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"F\"\n dependency \"dcomp\" version=\">=0.7.3\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\nimport std.typecons;\n\nalias E = Tuple!(int, \"to\", int, \"dist\");\nalias D = int;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n \n static struct PairingHeapAllAdd {\n alias NP = Node*;\n static struct Node { \n E e;\n D offset;\n NP head, next;\n this(E e) {\n this.e = e;\n offset = D(0);\n }\n }\n NP n;\n size_t length;\n this(E[] e) {\n length = e.length; \n foreach (d; e) {\n n = merge(n, new Node(d));\n }\n }\n static NP merge(NP x, NP y) {\n if (!x) return y;\n if (!y) return x;\n if (x.e.dist+x.offset < y.e.dist+y.offset) swap(x, y);\n y.offset -= x.offset;\n y.next = x.head;\n x.head = y;\n return x;\n }\n void C() { assert(n); }\n E front() {C; return n.e; }\n void removeFront() {\n assert(n);\n assert(length > 0);\n length--;\n NP x;\n NP s = n.head;\n while (s) {\n NP a, b;\n a = s; s = s.next; a.next = null; a.offset += n.offset;\n if (s) {\n b = s; s = s.next; b.next = null; b.offset += n.offset;\n }\n a = merge(a, b);\n assert(a);\n if (!x) x = a;\n else {\n a.next = x.next;\n x.next = a;\n }\n }\n n = null;\n while (x) {\n NP a = x; x = x.next;\n n = merge(a, n);\n }\n }\n void meld(PairingHeapAllAdd r) {\n length += r.length;\n n = merge(n, r.n);\n }\n ref D offset() {C; return n.offset; }\n }\n\n int n, m;\n sc.read(n, m); \n E[][] g = new E[][n];\n foreach (i; 0..m) {\n int a, b, c;\n sc.read(a, b, c); a--; b--;\n g[a] ~= E(i, c);\n g[b] ~= E(i, c);\n }\n\n auto heap = new PairingHeapAllAdd[2*n];\n foreach (i; 0..n) {\n// writeln(i, \" -> \", g[i]);\n heap[i] = PairingHeapAllAdd(g[i]);\n }\n\n int[] pre = new int[m]; pre[] = -1;\n bool[] fix = new bool[m];\n long sm = 0;\n int pc = n;\n foreach (i; 0..2*n) {\n if (i == pc) break;\n while (heap[i].length && fix[heap[i].front.to]) heap[i].removeFront;\n if (!heap[i].length) continue;\n auto e = heap[i].front;\n int c = e.dist;\n int x = i;\n if (pre[e.to] == -1) {\n sm += c;\n pre[e.to] = i;\n continue;\n }\n int y = pre[e.to]; \n //merge x, y\n fix[e.to] = true;\n int P = pc++;\n heap[P].meld(heap[x]);\n heap[P].meld(heap[y]); \n }\n\n writeln(sm);\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n import core.bitop : bsf, bsr, popcnt;\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n// import dcomp.array;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n FastAppender!(E[]) buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */\n// module dcomp.array;\n\n \nT[N] fixed(T, size_t N)(T[N] a) {return a;}\n\n \n \n\n \nstruct FastAppender(A, size_t MIN = 4) {\n import std.algorithm : max;\n import std.conv;\n import std.range.primitives : ElementEncodingType;\n import core.stdc.string : memcpy;\n\n private alias T = ElementEncodingType!A;\n private T* _data;\n private uint len, cap;\n \n @property size_t length() const {return len;}\n bool empty() const { return len == 0; }\n \n void reserve(size_t nlen) {\n import core.memory : GC;\n if (nlen <= cap) return;\n \n void* nx = GC.malloc(nlen * T.sizeof);\n\n cap = nlen.to!uint;\n if (len) memcpy(nx, _data, len * T.sizeof);\n _data = cast(T*)(nx);\n }\n void free() {\n import core.memory : GC;\n GC.free(_data);\n }\n \n void opOpAssign(string op : \"~\")(T item) {\n if (len == cap) {\n reserve(max(MIN, cap*2));\n }\n _data[len++] = item;\n }\n \n void insertBack(T item) {\n this ~= item;\n }\n \n void removeBack() {\n len--;\n }\n \n void clear() {\n len = 0;\n }\n ref inout(T) back() inout { assert(len); return _data[len-1]; }\n ref inout(T) opIndex(size_t i) inout { return _data[i]; }\n \n T[] data() {\n return (_data) ? _data[0..len] : null;\n }\n}\n\n \n \n\n/*\nThis source code generated by dcomp and include dcomp's source code.\ndcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)\ndcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)\n*/\n"}], "negative_code": [], "src_uid": "ab23517c489717ac200821f1041368a2"} {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n long reqMoves = hm / dc + (hm % dc != 0);\r\n long recoil = (reqMoves-1) * dm;\r\n \r\n if(hc > recoil){\r\n return true;\r\n }else{\r\n return false;\r\n }\r\n }\r\n bool fight2(long hc, long dc, long hm, long dm) {\r\n if ((hm / dc == 0) || ((hm / dc == 1) && (hm % dc == 0)))\r\n return true;\r\n if ((hm / dc) < (hc / dm))\r\n return true;\r\n else if ((hm / dc) == (hc / dm))\r\n {\r\n if ((hm % dc) == 0)\r\n return true;\r\n else if ((hc % dm) == 0)\r\n return false;\r\n else\r\n return true;\r\n }\r\n else {\r\n if ((hm / dc - hc / dm == 1) && (hm % dc == 0) && (hc % dm != 0))\r\n return true;\r\n else\r\n return false;\r\n }\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n auto s = readln.split.to!(long[]);\r\n hc = s[0];\r\n dc = s[1];\r\n s = readln.split.to!(long[]);\r\n hm = s[0];\r\n dm = s[1];\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = false;\r\n\r\n for (int i = 0; i <= k; ++i) {\r\n long new_hc = i*a + hc;\r\n long new_dc = (k-i)*w + dc;\r\n flag = fight2(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n break;\r\n }\r\n }\r\n if (flag)\r\n writeln(\"YES\");\r\n else\r\n writeln(\"NO\");\r\n } \r\n}", "positive_code": [{"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n if ((hm / dc == 0) || ((hm / dc == 1) && (hm % dc == 0)))\r\n return true;\r\n if ((hm / dc) < (hc / dm))\r\n return true;\r\n else if ((hm / dc) == (hc / dm))\r\n {\r\n if ((hm % dc) == 0)\r\n return true;\r\n else if ((hc % dm) == 0)\r\n return false;\r\n else\r\n return true;\r\n }\r\n else {\r\n if ((hm / dc - hc / dm == 1) && (hm % dc == 0) && (hc % dm != 0))\r\n return true;\r\n else\r\n return false;\r\n }\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n auto s = readln.split.to!(long[]);\r\n hc = s[0];\r\n dc = s[1];\r\n s = readln.split.to!(long[]);\r\n hm = s[0];\r\n dm = s[1];\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = fight(hc, dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n continue;\r\n }\r\n for (int i = 0; i <= k; i++) {\r\n long new_hc = i*a + hc;\r\n long new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n break;\r\n }\r\n }\r\n if (!flag)\r\n writeln(\"NO\");\r\n } \r\n}"}], "negative_code": [{"source_code": "bool canDestroy(long hc, long dc, long hm, long dm){\r\n long reqMoves = hm / dc + (hm % dc != 0);\r\n long recoil = (reqMoves-1) * dm;\r\n if(hc > recoil){\r\n return 1;\r\n }else{\r\n return 0;\r\n }\r\n}\r\n \r\nvoid solve(){\r\n long hc = scan;\r\n long dc = scan;\r\n \r\n long hm = scan;\r\n long dm = scan;\r\n \r\n int k = scan!int;\r\n long w = scan;\r\n long a = scan;\r\n \r\n for(int x = 0; x <= k; ++x){\r\n long nhc = hc + x * a;\r\n long ndc = dc + (k - x) * w;\r\n if(canDestroy(nhc, ndc, hm, dm)){\r\n writeln(\"YES\");\r\n return;\r\n }\r\n }\r\n writeln(\"NO\");\r\n}\r\n \r\nvoid main(){\r\n long tests = scan; // Toggle!\r\n while(tests--) solve;\r\n}\r\n \r\n/*_________________________*That's All Folks!*__________________________*/\r\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\r\nstring[] tk; alias tup = Tuple!(long, long);\r\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\r\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\r\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n long reqMoves = hm / dc + (hm % dc != 0);\r\n long recoil = (reqMoves-1) * dm;\r\n if(hc > recoil){\r\n return true;\r\n }else{\r\n return false;\r\n }\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = false;\r\n\r\n for (int i = 0; i <= k; ++i) {\r\n long new_hc = i*a + hc;\r\n long new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n break;\r\n }\r\n }\r\n if (flag)\r\n writeln(\"YES\");\r\n else\r\n writeln(\"NO\");\r\n } \r\n}"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n long reqMoves = hm / dc + (hm % dc != 0);\r\n long recoil = (reqMoves-1) * dm;\r\n if(hc > recoil){\r\n return true;\r\n }else{\r\n return false;\r\n }\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = false;\r\n\r\n for (int i = 0; i <= k; i++) {\r\n long new_hc = i*a + hc;\r\n long new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n break;\r\n }\r\n }\r\n if (flag)\r\n writeln(\"YES\");\r\n else\r\n writeln(\"NO\");\r\n } \r\n}"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n long reqMoves = hm / dc + (hm % dc != 0);\r\n long recoil = (reqMoves-1) * dm;\r\n if(hc > recoil){\r\n return true;\r\n }else{\r\n return false;\r\n }\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = fight(hc, dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n continue;\r\n }\r\n for (int i = 0; i <= k; i++) {\r\n long new_hc = i*a + hc;\r\n long new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n break;\r\n }\r\n }\r\n if (!flag)\r\n writeln(\"NO\");\r\n } \r\n}"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n if ((hm / dc == 0) || ((hm / dc == 1) && (hm % dc == 0)))\r\n return true;\r\n if ((hm / dc) < (hc / dm))\r\n return true;\r\n else if ((hm / dc) == (hc / dm))\r\n {\r\n if ((hm % dc) == 0)\r\n return true;\r\n else if ((hc % dm) == 0)\r\n return false;\r\n else\r\n return true;\r\n }\r\n else {\r\n if ((hm / dc - hc / dm == 1) && (hm % dc == 0) && (hc % dm != 0))\r\n return true;\r\n else\r\n return false;\r\n }\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = fight(hc, dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n continue;\r\n }\r\n for (int i = 0; i <= k; i++) {\r\n long new_hc = i*a + hc;\r\n long new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n break;\r\n }\r\n }\r\n if (!flag)\r\n writeln(\"NO\");\r\n } \r\n}"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n if ((hm / dc) < (hc / dm))\r\n return true;\r\n else if ((hm / dc == 0) || ((hm / dc == 1) && (hm % dc == 0)))\r\n return true;\r\n else if ((hm / dc) == (hc / dm))\r\n {\r\n if ((hm % dc) == 0)\r\n return true;\r\n else if ((hc % dm) == 0)\r\n return false;\r\n else\r\n return true;\r\n }\r\n else {\r\n if ((hm / dc - hc / dm == 1) && (hm % dc == 0))\r\n return true;\r\n else\r\n return false;\r\n }\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = fight(hc, dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n continue;\r\n }\r\n for (int i = 0; i <= k; i++) {\r\n auto new_hc = i*a + hc;\r\n auto new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n break;\r\n }\r\n }\r\n if (!flag)\r\n writeln(\"NO\");\r\n } \r\n}"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n if ((hm / dc) < (hc / dm))\r\n return true;\r\n else if ((hm / dc) == (hc / dm))\r\n {\r\n if ((hm % dc) == 0)\r\n return true;\r\n else if ((hc % dm) == 0)\r\n return false;\r\n else\r\n return true;\r\n }\r\n else\r\n return false;\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = fight(hc, dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n continue;\r\n }\r\n for (int i = 0; i <= k; i++) {\r\n auto new_hc = i*a + hc;\r\n auto new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n break;\r\n }\r\n }\r\n if (!flag)\r\n writeln(\"NO\");\r\n } \r\n}"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n if ((hm / dc) <= (hc / dm))\r\n return true;\r\n else\r\n return false;\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = fight(hc, dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n continue;\r\n }\r\n for (int i = 0; i <= k; i++) {\r\n auto new_hc = i*a + hc;\r\n auto new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n break;\r\n }\r\n }\r\n if (!flag)\r\n writeln(\"NO\");\r\n } \r\n}"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n if ((hm / dc) <= (hc / dm))\r\n return true;\r\n else\r\n return false;\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = fight(hc, dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n continue;\r\n }\r\n for (int i = 0; i < k; i++) {\r\n auto new_hc = i*a + hc;\r\n auto new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n break;\r\n }\r\n }\r\n if (!flag)\r\n writeln(\"NO\");\r\n } \r\n}"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n\r\n bool fight(long hc, long dc, long hm, long dm) {\r\n if ((hm / dc) >= (hc / dm))\r\n return true;\r\n else\r\n return false;\r\n }\r\n\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long hc, dc, hm, dm;\r\n scanf(\"%ld %ld\", &hc, &dc);\r\n getchar();\r\n scanf(\"%ld %ld\", &hm, &dm);\r\n getchar();\r\n long k, a, w;\r\n scanf(\"%ld %ld %ld\", &k, &w, &a);\r\n getchar();\r\n bool flag = false;\r\n for (int i = 0; i < k; i++) {\r\n auto new_hc = i*a + hc;\r\n auto new_dc = (k-i)*w + dc;\r\n flag = fight(new_hc, new_dc, hm, dm);\r\n if (flag) {\r\n writeln(\"YES\");\r\n break;\r\n }\r\n }\r\n if (!flag)\r\n writeln(\"NO\");\r\n } \r\n}"}], "src_uid": "5b1f33228a58d9e14bc9479767532c25"} {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n return readf(' ' ~ replicate(\"%s \", vars.length), getAddrTuple(vars).expand) == vars.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Dsu(int maxn) {\n int[maxn] p, sz;\n\n int get(int x) {\n return x == p[x] ? x : (p[x] = get(p[x]));\n }\n\n void merge(int x, int y) {\n x = get(x);\n y = get(y);\n if (x != y) {\n p[x] = y;\n sz[y] += sz[x];\n }\n }\n}\n\nint n, m;\nDsu!150_000 dsu;\n\nvoid main() {\n while (read(n, m)) {\n iota(n).copy(dsu.p[ ]);\n dsu.sz[0 .. n] = 1;\n foreach (i; 0 .. m) {\n int x, y;\n read(x, y);\n x--;\n y--;\n dsu.merge(x, y);\n }\n long total = m << 1;\n foreach (i; 0 .. n)\n if (dsu.p[i] == i)\n total -= dsu.sz[i] * cast(long)(dsu.sz[i] - 1);\n writeln(total ? \"NO\" : \"YES\");\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nalias Tuple!(int, \"a\", int, \"b\") Edge;\n\nint N, M;\nint[][] adj;\nbool[] used;\nbool[Edge] cnt;\n\nlong dfs(int n) {\n used[n] = true;\n int ret = 1;\n\n foreach (m; adj[n]) {\n cnt[Edge(min(n, m), max(n, m))] = true;\n if (!used[m]) ret += dfs(m);\n }\n\n return ret;\n}\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n N = s[0];\n M = s[1];\n adj = new int[][](N);\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n adj[s[0]-1] ~= s[1]-1;\n adj[s[1]-1] ~= s[0]-1;\n }\n\n used = new bool[](N);\n foreach (i; 0..N) {\n if (!used[i]) {\n cnt.clear;\n long r = dfs(i);\n if (cnt.keys.length != r * (r-1) / 2) {\n writeln(\"NO\");\n return;\n }\n }\n }\n\n writeln(\"YES\") ;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n auto uf = new int[N];\n uf[] = -1;\n foreach (i; 0 .. M) {\n uf.connect(A[i], B[i]);\n }\n \n long m;\n foreach (r; 0 .. N) {\n if (uf[r] < 0) {\n const sz = -uf[r];\n m += 1L * sz * (sz - 1) / 2;\n }\n }\n \n writeln((m == M) ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nalias Tuple!(int, \"a\", int, \"b\") Edge;\n\nint N, M;\nint[][] adj;\nbool[] used;\nbool[Edge] cnt;\n\nint dfs(int n) {\n used[n] = true;\n int ret = 1;\n\n foreach (m; adj[n]) {\n cnt[Edge(min(n, m), max(n, m))] = true;\n if (!used[m]) ret += dfs(m);\n }\n\n return ret;\n}\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n N = s[0];\n M = s[1];\n adj = new int[][](N);\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n adj[s[0]-1] ~= s[1]-1;\n adj[s[1]-1] ~= s[0]-1;\n }\n\n used = new bool[](N);\n foreach (i; 0..N) {\n if (!used[i]) {\n cnt.clear;\n int r = dfs(i);\n if (cnt.keys.length != r * (r-1) / 2) {\n writeln(\"NO\");\n return;\n }\n }\n }\n\n writeln(\"YES\") ;\n}\n"}], "src_uid": "1173d89dd3af27b46e579cdeb2cfdfe5"} {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tstring s = readln.chomp;\n\t\n\tchar[] ans;\n\tint i = 0, j = 1; \n\twhile(j < n) if(s[i] != s[j]) ans ~= s[i], ans ~= s[j], i = j + 1, j = i + 1; else j += 1;\n\t\n\t(n - ans.length).writeln;\n\tans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n\n dchar[] T;\n\n foreach (i; 0..N) {\n if (T.empty) {\n T ~= S[i];\n } else if (T.back == S[i] && T.length % 2 == 1) {\n\n } else {\n T ~= S[i];\n }\n }\n\n int rest = T.length.to!int;\n int ans = N - rest;\n if (rest % 2 == 1) {\n ans += 1;\n T = T[0..$-1];\n }\n\n ans.writeln;\n T.writeln;\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\\n\", n);\n\n auto s = readln().strip().dup;\n if (s.length == 0) { writefln(\"%s\\n%s\", 0, s); return ; }\n\n char [] ans;\n foreach(i; 0 .. s.length) {\n\n if (ans.length == 0) {\n ans ~= s[i];\n } else {\n if ( ans.length % 2 ==0 || ans[$-1] != s[i]) ans ~= s[i];\n }\n }\n\n if (ans.length % 2 == 1) {\n ans = ans [0 .. $ - 1];\n }\n\n\n writefln(\"%s\\n%s\", s.length - ans.length, ans);\n\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto N = RD!int;\n\tauto a = RD!string;\n\n\tstring ans;\n\tans ~= a[0];\n\tlong cnt;\n\tchar last = a[0];\n\tforeach (i; 1..N)\n\t{\n\t\tif ((i-cnt) % 2 == 1)\n\t\t{\n\t\t\tif (a[i] == last)\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tlast = a[i];\n\t\tans ~= a[i];\n\t}\n\tif (ans.length % 2 == 1)\n\t{\n\t\tans.popBack;\n\t\t++cnt;\n\t}\n\n\twriteln(cnt);\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "c11d67f223eb49c6e8315e2c88dd680d"} {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\talias Event = Tuple !(int, q{x}, int, q{d});\n\t\tEvent [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint p, q;\n\t\t\treadf (\" %s %s\", &p, &q);\n\t\t\ta ~= Event (p, -1);\n\t\t\ta ~= Event (q, +1);\n\t\t}\n\t\tsort (a);\n\n\t\tint b = 0;\n\t\tint start;\n\t\tint [2] [] ans;\n\t\tforeach (e; a)\n\t\t{\n\t\t\tb -= e.d;\n\t\t\tif (b == k && e.d == -1)\n\t\t\t{\n\t\t\t\tstart = e.x;\n\t\t\t}\n\t\t\tif (b == k - 1 && e.d == +1)\n\t\t\t{\n\t\t\t\tans ~= [start, e.x];\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%s\\n%(%(%s %)\\n%)\", ans.length, ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tint [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint p, q;\n\t\t\treadf (\" %s %s\", &p, &q);\n\t\t\ta ~= p * 2 + 0;\n\t\t\ta ~= q * 2 + 1;\n\t\t}\n\t\tsort (a);\n\n\t\tint b = 0;\n\t\tint start;\n\t\tint [2] [] ans;\n\t\tforeach (e; a)\n\t\t{\n\t\t\tint d = (e & 1) ? -1 : +1;\n\t\t\tint x = e >> 1;\n\t\t\tb += d;\n\t\t\tif (b == k && d == +1)\n\t\t\t{\n\t\t\t\tstart = x;\n\t\t\t}\n\t\t\tif (b == k - 1 && d == -1)\n\t\t\t{\n\t\t\t\tans ~= [start, x];\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%s\\n%(%(%s %)\\n%)\", ans.length, ans);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\talias Event = Tuple !(int, q{x}, int, q{d});\n\t\tEvent [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint p, q;\n\t\t\treadf (\" %s %s\", &p, &q);\n\t\t\ta ~= Event (p, -1);\n\t\t\ta ~= Event (q, +1);\n\t\t}\n\t\tsort !(q{a < b}, SwapStrategy.stable) (a);\n\n\t\tint b = 0;\n\t\tint start;\n\t\tint [2] [] ans;\n\t\tforeach (e; a)\n\t\t{\n\t\t\tb -= e.d;\n\t\t\tif (b == k && e.d == -1)\n\t\t\t{\n\t\t\t\tstart = e.x;\n\t\t\t}\n\t\t\tif (b == k - 1 && e.d == +1)\n\t\t\t{\n\t\t\t\tans ~= [start, e.x];\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%s\\n%(%(%s %)\\n%)\", ans.length, ans);\n\t}\n}\n"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.typecons;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.functional;\nimport std.container;\n\n\nalias Action = Tuple! (int, \"coord\", bool, \"isClose\");\nalias Segment = Tuple! (int, \"left\", int, \"right\");\n\n\nint main() {\n\n int n, k;\n\n readf(\" %d %d\", &n, &k);\n readln();\n\n Action[] actions;\n\n foreach (int i; 0..n) {\n auto temp = readln().strip().split().map! (to! (int)).array();\n\n actions ~= Action (temp[0], false);\n actions ~= Action (temp[1], true);\n }\n\n sort(actions);\n\n debug {writeln(actions);};\n\n int currentCountOfIntersections;\n int[] opens;\n Segment[] result;\n foreach (int i; 0..actions.length)\n if (!(actions[i].isClose)) {\n opens.assumeSafeAppend();\n opens ~= actions[i].coord;\n currentCountOfIntersections++;\n } else {\n if (currentCountOfIntersections == k)\n result ~= Segment (opens.back, actions[i].coord);\n\n opens.popBack();\n currentCountOfIntersections--;\n }\n\n writeln(result.length);\n foreach (int i; 0..result.length)\n writeln(result[i][0], ' ', result[i][1]);\n\n\treturn 0;\n}\n"}], "negative_code": [{"source_code": "module main;\n\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.typecons;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.functional;\nimport std.container;\n\n\nint main() {\n\n auto s = readln().strip();\n\n char[] stack;\n string open = \"({[<\";\n string close = \")}]>\";\n\n int result;\n\n bool flag = true;\n foreach (int i; 0..s.length)\n if (canFind(open, s[i])) {\n stack.assumeSafeAppend();\n stack ~= s[i];\n } else {\n if (stack.length == 0 || canFind(stack.back.to! (string), close)) {\n flag = false;\n break;\n }\n\n if (s[i] == ')' && stack.back != '(' || s[i] == '}' && stack.back != '{' || s[i] == ']' &&\n stack.back != '[' || s[i] == '>' && stack.back != '<')\n result++;\n\n stack.popBack();\n }\n\n writeln((flag && stack.length == 0) ? result.to! (string) : \"Impossible\");\n\n\treturn 0;\n}\n"}], "src_uid": "eafd37afb15f9f9d31c2a16a32f17763"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nint a, b, n, m;\nint[][] mat;\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n n = cin.readInt;\n m = cin.readInt;\n mat = new int[][](n, m);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n mat[i][j] = cin.readInt;\n }\n }\n a = cin.readInt;\n b = cin.readInt;\n if (a == b) writeln(colWise());\n else writeln(min(colWise(), rowWise()));\n } \n}\n\nint colWise() {\n int minn = 99999999;\n for (int i = 0; i < n - b + 1; i++) {\n for (int j = 0; j < m - a + 1; j++) {\n int trees = 0;\n for (int dx = 0; dx < b; dx++) {\n for (int dy = 0; dy < a; dy++) {\n if (mat[i + dx][j + dy]) trees++;\n }\n }\n minn = min(minn, trees);\n }\n }\n return minn;\n}\n\nint rowWise() {\n int minn = 99999999;\n for (int i = 0; i < n - a + 1; i++) {\n for (int j = 0; j < m - b + 1; j++) {\n int trees = 0;\n for (int dx = 0; dx < a; dx++) {\n for (int dy = 0; dy < b; dy++) {\n if (mat[i + dx][j + dy]) trees++;\n }\n }\n minn = min(minn, trees);\n }\n }\n return minn;\n}", "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nint n, m;\nint[][] mat;\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n n = cin.readInt;\n m = cin.readInt;\n mat = new int[][](n, m);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n mat[i][j] = cin.readInt;\n }\n }\n int a, b;\n a = cin.readInt;\n b = cin.readInt;\n writeln(min(solve(a, b), solve(b, a)));\n } \n}\n\nint solve(int a, int b) {\n int minn = 99999999;\n for (int i = 0; i < n - b + 1; i++) {\n for (int j = 0; j < m - a + 1; j++) {\n int trees = 0;\n for (int dx = 0; dx < b; dx++) {\n for (int dy = 0; dy < a; dy++) {\n if (mat[i + dx][j + dy]) trees++;\n }\n }\n minn = min(minn, trees);\n }\n }\n return minn;\n}\n"}], "negative_code": [], "src_uid": "1771741663a5236a0aa0551548f4aadd"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.format;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nstring solve (int n, int k)\r\n{\r\n\tint c = 0;\r\n\tauto board = new char [] [] (n, n);\r\n\tforeach (ref line; board)\r\n\t{\r\n\t\tline[] = '.';\r\n\t}\r\n\twhile (k > 0 && c < n)\r\n\t{\r\n\t\tboard[c][c] = 'R';\r\n\t\tk -= 1;\r\n\t\tc += 2;\r\n\t}\r\n\tif (k == 0)\r\n\t{\r\n\t\treturn format !(\"%-(%s\\n%)\") (board);\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn \"-1\";\r\n\t}\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\twriteln (solve (n, k));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n int n, k;\n read(n, k);\n if (k * 2 - 1 > n) {\n writeln(-1);\n continue;\n }\n\n auto board = new char[][](n, n);\n foreach (ref c; board) c[] = '.';\n\n foreach (i; 0 .. k) {\n board[i * 2][i * 2] = 'R';\n }\n\n foreach (c; board) writeln(c);\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\r\n\t\tif (k > (n+1)/2) continue;\r\n\t\tans[ti].length = n;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (i/2 < k && i % 2 != 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i == j)\r\n\t\t\t\t\t\tans[ti][i] ~= \"R\";\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tans[ti][i] ~= \".\";\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tans[ti][i] ~= \".\";\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tif (e.empty)\r\n\t\t\twriteln(-1);\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (ee; e)\r\n\t\t\t\twriteln(ee);\r\n\t\t}\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s \"(n); return n; }();\n immutable k = (){ uint k; readf!\"%s\\n\"(k); return k; }();\n\n auto r = iota(0, n, 2).take(k);\n\n if (r.length < k) {\n writeln(\"-1\");\n continue;\n }\n\n foreach (i; 0 .. n) {\n foreach (j; 0 .. n)\n if (!r.empty && r.front == i && r.front == j) {\n write('R');\n r.popFront();\n } else\n write('.');\n writeln();\n }\n }\n}\n// \"\"\n"}], "negative_code": [], "src_uid": "d5549c0627c236d82541a67ccbe7977d"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1430/problem/A\n// brute force\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\n int n;\n while(t--) {\n readf(\"%s\\n\", &n);\n bool found = false;\n for(int x = 0; 3*x <= n; x += 1) {\n if(found)\n break;\n for(int y = 0; 5*y <= n; y += 1) {\n int z = (n - 3*x - 5*y)/7;\n if(z >= 0 && (3*x + 5*y + 7*z == n)) {\n writefln(\"%s %s %s\", x, y, z);\n found = true;\n break;\n }\n }\n }\n if(!found)\n \"-1\".writeln;\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main()\n{\n auto t = stdin.readln.strip.to!int;\ntestcase:\n while (t-- > 0) {\n // a * 3 + b * 5 + c * 7 = n\n auto n = stdin.readln.strip.to!int;\n int result = 0;\n for (int a = 0; a * 3 <= n; ++a) {\n for (int b = 0; a * 3 + b * 5 <= n; ++b) {\n for (int c = 0; a * 3 + b * 5 + c * 7 <= n; ++c) {\n if (a * 3 + b * 5 + c * 7 == n) {\n writeln(a, ' ', b, ' ', c);\n continue testcase;\n }\n }\n }\n }\n writeln(\"-1\");\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\t(){\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto n1 = n - i * 3;\n\t\t\tif (n1 < 0) break;\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tauto n2 = n1 - j * 5;\n\t\t\t\tif (n2 < 0) break;\n\t\t\t\tforeach (k; 0..n)\n\t\t\t\t{\n\t\t\t\t\tauto n3 = n2 - k * 7;\n\t\t\t\t\tif (n3 < 0) break;\n\t\t\t\t\telse if (n3 == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tans[ti] = [i, j, k];\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}}();\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1430/problem/A\n// brute force\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\n int n;\n while(t--) {\n readf(\"%s\\n\", &n);\n bool found = false;\n for(int x = 0; 3*x <= n; x += 1) {\n if(found)\n break;\n for(int y = 0; 5*y <= n; y += 1) {\n int z = (n - 3*x - 5*y)/7;\n if(z >= 0 && (3*x + 5*y + 7*z == n)) {\n writefln(\"%s %s %s\", x, y, z);\n found = true;\n }\n }\n }\n if(!found)\n \"-1\".writeln;\n }\n}\n\n"}], "src_uid": "b43dee2f223c869a35b1b11ceb9d2b6b"} {"source_code": "import std;\n\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\treadln;\n\t\tauto c=readln.strip.split.to!(int[]);\n\t\tauto a=c.map!(x=>x?1:0).array~1;\n\t\tforeach(i,x;c) a[x+i*!a[i]]=0;\n\t\ta[0..$-1].map!text.join(\" \").writeln;\n\t}\n}\n", "positive_code": [{"source_code": "import std;\n\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto c=readln.strip.split.to!(int[]);\n\t\tauto a=(-1).repeat(n).array;\n\t\tauto j=0, iz=n.repeat(n).array, z=0;\n\t\tiz[0]=c[0];\n\t\twhile(j<n&&c[j]==0) a[j++]=0;\n\t\tif(j<n) a[j++]=1;\n\t\tforeach(i;j-1..n){\n\t\t\tif(a[i]==0) iz[++z]=i;\n\t\t\tint p=c[i]-i*a[i]+min(i,iz[i]);\n\t\t\twhile(j<p) a[j++]=1;\n\t\t\tif(j<n) a[j++]=0;\n\t\t}\n\t\ta.map!text.join(\" \").writeln;\n\t}\n}\n"}, {"source_code": "import std;\n\nvoid main(){\n\tauto t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto c=readln.strip.split.to!(int[]);\n\t\tauto a=c.map!(x=>x?1:0).array~1;\n\t\tforeach(i,x;c) a[x+i*!a[i]]=0;\n\t\ta[0..n].map!text.join(\" \").writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "import std;\n\nvoid main(){\n\tint t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto n=readln.strip.to!int;\n\t\tauto c=readln.strip.split.to!(int[]);\n\t\tauto a=(-1).repeat(n).array;\n\t\tint z=0,j=0;\n\t\tauto iz=0.repeat(n).array;\n\t\tiz[0]=c[0];\n\t\twhile(j<n&&c[j]==0) a[j++]=0;\n\t\tif(j<n) a[j++]=1;\n\t\tforeach(i;j-1..n){\n\t\t\tif(a[i]==0) iz[++z]=i;\n\t\t\tint p=c[i]-i*a[i]+min(i,iz[i]);\n\t\t\twhile(j<p) a[j++]=1;\n\t\t\tif(j<n) a[j++]=0;\n\t\t}\n\t\ta.map!text.join(\" \").writeln;\n\t}\n}\n"}], "src_uid": "9dc1bee4e53ced89d827826f2d83dabf"} {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nlong MOD = 998244353;\n\nvoid main() {\n GC.disable();\n\n // \n\n\n uint n;\n readf(\" %s\", n);\n auto a = new long [n];\n foreach(i; 0 .. n) readf(\" %s\", a[i]);\n auto b = new long [n];\n foreach(i; 0 .. n) readf(\" %s\", b[i]);\n\n sort!\"a>b\"(b);\n\n long[] vv;\n foreach(i; 0..n) {\n // a\n long t = i+1;\n long mul = ( t*(n - t + 1) ); // % MOD;\n mul = (mul *a[i]);// % MOD;\n vv ~= mul;\n }\n\n sort!\"a<b\"(vv);\n\n long tt = 0;\n \n foreach(i; 0 .. n) {\n tt += ( (vv[i]%MOD) * b[i] ) % MOD;\n tt = (tt % MOD);\n }\n\n writeln(tt);\n\n\n\n //\n\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\tprint!1(\"as:\", as);\n\t\n\tlong[] bs;\n\tforeach(i; 0 .. n) bs ~= read.to!long;\n\tprint!1(\"bs:\", bs);\n\t\n\tlong[] cs;\n\tforeach(i; 0 .. n){\n\t\tlong k = i + 1; k *= n - i;\n\t\tcs ~= k * as[i];\n\t}\n\tprint!1(\"cs:\", cs);\n\t\n\tcs.sort();\n\tbs.sort();\n\t\n\tprint!1(\"cs:\", cs);\n\tprint!1(\"bs:\", bs);\n\t\n\tlong ans;\n\tforeach(i; 0 .. n) ans += (bs[i] * (cs[n - 1 - i] % mod)) % mod, ans %= mod;\n\t\n\tans.writeln;\n}\n\nconst long mod = 998244353;\n\n/*\ns = sum(r; 0 .. n) sum(l; 0 .. r) sum(i; l .. r + 1) a[i] b[i]\n\nhow many times the term a[i] b[i] appears?\n= how many pair (l, r) exist such that l <= i and i <= r ?\n= (i + 1)(n - i).\n\ns = sum(i; 0 .. n) (i + 1)(n - i) a[i] b[i].\n\nlet k[i] = (i + 1)(n - i) a[i].\narrange smaller b[i] for smaller k[i].\n\n*/\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 998244353 ;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array;\n B.sort!\"a > b\";\n\n foreach (i; 0..N) {\n long tmp = 1L * (i + 1) * (N - i);\n A[i] = A[i] * tmp;\n }\n A.sort();\n \n long ans = 0;\n\n foreach (i; 0..N) {\n (ans += A[i] % MOD * B[i] % MOD) %= MOD;\n }\n\n ans.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\tprint!1(\"as:\", as);\n\t\n\tlong[] bs;\n\tforeach(i; 0 .. n) bs ~= read.to!long;\n\tprint!1(\"bs:\", bs);\n\t\n\tlong[] cs;\n\tforeach(i; 0 .. n) cs ~= (i + 1) * (n - i) * as[i];\n\tprint!1(\"cs:\", cs);\n\t\n\tcs.sort();\n\tbs.sort();\n\t\n\tprint!1(\"cs:\", cs);\n\tprint!1(\"bs:\", bs);\n\t\n\tlong ans;\n\tforeach(i; 0 .. n) ans += (bs[i] * (cs[n - 1 - i] % mod)) % mod, ans %= mod;\n\t\n\tans.writeln;\n}\n\nconst long mod = 998244353;\n\n/*\ns = sum(r; 0 .. n) sum(l; 0 .. r) sum(i; l .. r + 1) a[i] b[i]\n\nhow many times the term a[i] b[i] appears?\n= how many pair (l, r) exist such that l <= i and i <= r ?\n= (i + 1)(n - i).\n\ns = sum(i; 0 .. n) (i + 1)(n - i) a[i] b[i].\n\nlet k[i] = (i + 1)(n - i) a[i].\narrange smaller b[i] for smaller k[i].\n\n*/\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\tprint!1(\"as:\", as);\n\t\n\tlong[] bs;\n\tforeach(i; 0 .. n) bs ~= read.to!long;\n\tprint!1(\"bs:\", bs);\n\t\n\tlong[] cs;\n\tforeach(i; 0 .. n) cs ~= (i + 1) * (n - i) * as[i];\n\tprint!1(\"cs:\", cs);\n\t\n\tcs.sort();\n\tbs.sort();\n\t\n\tprint!1(\"cs:\", cs);\n\tprint!1(\"bs:\", bs);\n\t\n\tlong ans;\n\tforeach(i; 0 .. n) ans += (bs[i] * cs[n - 1 - i]) % mod, ans %= mod;\n\t\n\tans.writeln;\n}\n\nconst long mod = 998244353;\n\n/*\ns = sum(r; 0 .. n) sum(l; 0 .. r) sum(i; l .. r + 1) a[i] b[i]\n\nhow many times the term a[i] b[i] appears?\n= how many pair (l, r) exist such that l <= i and i <= r ?\n= (i + 1)(n - i).\n\ns = sum(i; 0 .. n) (i + 1)(n - i) a[i] b[i].\n\nlet k[i] = (i + 1)(n - i) a[i].\narrange smaller b[i] for smaller k[i].\n\n*/\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nlong MOD = 998244353;\n\nvoid main() {\n GC.disable();\n\n // \n\n\n uint n;\n readf(\" %s\", n);\n auto a = new long [n];\n foreach(i; 0 .. n) readf(\" %s\", a[i]);\n auto b = new long [n];\n foreach(i; 0 .. n) readf(\" %s\", b[i]);\n\n sort!\"a>b\"(b);\n\n long[] vv;\n foreach(i; 0..n) {\n // a\n long t = i+1;\n long mul = ( t*(n - t + 1) ); // % MOD;\n mul = (mul *a[i]);// % MOD;\n vv ~= mul;\n }\n\n sort!\"a>b\"(vv);\n\n long tt = 0;\n \n foreach(i; 0 .. n) {\n tt += (vv[i] * b[i] ) % MOD;\n tt = (tt % MOD);\n }\n\n writeln(tt);\n\n\n\n //\n\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nlong MOD = 998244353;\n\nvoid main() {\n GC.disable();\n\n // \n\n\n uint n;\n readf(\" %s\", n);\n auto a = new long [n];\n foreach(i; 0 .. n) readf(\" %s\", a[i]);\n auto b = new long [n];\n foreach(i; 0 .. n) readf(\" %s\", b[i]);\n\n sort!\"a>b\"(b);\n\n long[] vv;\n foreach(i; 0..n) {\n // a\n long t = i+1;\n long mul = ( t*(n - t + 1) ); // % MOD;\n mul = (mul *a[i]);// % MOD;\n vv ~= mul;\n }\n\n sort!\"a<b\"(vv);\n\n long tt = 0;\n \n foreach(i; 0 .. n) {\n tt += (vv[i] * b[i] ) % MOD;\n tt = (tt % MOD);\n }\n\n writeln(tt);\n\n\n\n //\n\n}\n"}], "src_uid": "93431bdae447bb96a2f0f5fa0c6e11e0"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nint calc_weight(int node, int[] b, int[] ans, int[] cumulative)\n{\n int w = 0;\n while (b[node] != node) {\n if (cumulative[node] != 0)\n return w + cumulative[node];\n w += ans[node];\n node = b[node];\n }\n return w;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto b = readln.splitter.map!(x => x.to!int - 1).array;\n auto p = readln.splitter.map!(x => x.to!int - 1).array;\n bool[int][] adj = new bool[int][](n);\n int root = -1;\n foreach (i ; 0 .. cast(int)b.length) {\n if (b[i] == i) {\n root = i;\n continue;\n }\n adj[i][b[i]] = true;\n adj[b[i]][i] = true;\n }\n if (p[0] != root) {\n writeln(-1);\n continue;\n }\n// writefln(\"root=%d, adj=%s\", root, adj);\n bool good = true;\n int[] ans = new int[](n);\n int[] cumulative = new int[](n);\n int w = n + 1;\n foreach_reverse (node ; p) {\n if (node == root)\n break;\n if (adj[node].length != 1) {\n// writefln(\"bad node %d\", node);\n good = false;\n break;\n }\n int ancestor = adj[node].keys[0];\n adj[ancestor].remove(node);\n// writefln(\"remove %d from %d, adj=%s\", node, ancestor, adj);\n ans[node] = w--;\n }\n\n int prev_w = 0;\n foreach (i ; 1 .. cast(int)p.length) {\n w = calc_weight(p[i], b, ans, cumulative);\n if (w <= prev_w) {\n ans[p[i]] += prev_w - w + 1;\n w += prev_w - w + 1;\n cumulative[p[i]] = w;\n }\n prev_w = w;\n }\n\n if (good)\n writefln(\"%(%s %)\", ans);\n else\n writeln(-1);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tb[] -= 1;\r\n\t\tauto p = readln.splitter.map !(to !(int)).array;\r\n\t\tp[] -= 1;\r\n\r\n\t\tauto dist = new int [n];\r\n\t\tforeach (int i, ref v; p)\r\n\t\t{\r\n\t\t\tdist[v] = i;\r\n\t\t}\r\n\r\n\t\tauto vis = new bool [n];\r\n\t\tauto a = new int [n];\r\n\t\tbool ok = (b[p[0]] == p[0]);\r\n\t\tforeach (int i, ref v; p)\r\n\t\t{\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tok &= (b[v] == v);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tok &= vis[b[v]];\r\n\t\t\t}\r\n\t\t\tvis[v] = true;\r\n\t\t\ta[v] = dist[v] - dist[b[v]];\r\n\t\t}\r\n\r\n\t\tif (ok)\r\n\t\t{\r\n\t\t\twritefln !(\"%(%s %)\") (a);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "4b512c39e71e34064c820958dde9f4a1"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nlong egcd(long a, long b, ref long x, ref long y)\n{\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1, y1;\n long d = egcd(b, a % b, x1, y1);\n x = y1;\n y = x1 - y1 * (a / b);\n return d;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!long;\n auto a = next!long(n);\n\n if (n == 1)\n {\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(-a[0]);\n return;\n }\n long x, y;\n egcd(n, n - 1, x, y);\n assert(n * x + (n - 1) * y == 1);\n writeln(1, \" \", n);\n foreach(i, ai; a)\n {\n write(- ai * x * n, \" \");\n }\n writeln;\n writeln(1, \" \", n - 1);\n foreach(i, ai; a[0 .. $ - 1])\n {\n write(- ai * y * (n - 1), \" \");\n }\n writeln;\n writeln(2, \" \", n);\n foreach(ai; a[1 .. $ - 1])\n {\n write(0, \" \");\n }\n writeln(- a[$ - 1] * y * (n - 1));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byChunk;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tif (n == 1)\n\t\t{\n\t\t\twriteln (\"1 1\");\n\t\t\twriteln (-a.front);\n\t\t\twriteln (\"1 1\");\n\t\t\twriteln (\"0\");\n\t\t\twriteln (\"1 1\");\n\t\t\twriteln (\"0\");\n\t\t\tcontinue;\n\t\t}\n\n\t\twriteln (1, \" \", n - 1);\n\t\tlong [] ans;\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tauto rem = ((-a[i] % n) + n) % n;\n\t\t\tauto delta = (-(n - 1) * rem);\n\t\t\ta[i] += delta;\n\t\t\tans ~= delta;\n\t\t}\n\t\twritefln !(\"%(%s %)\") (ans);\n\n\t\twriteln (n, \" \", n);\n\t\tauto deltaLast = -a.back;\n\t\twriteln (deltaLast);\n\t\ta.back += deltaLast;\n\n\t\twriteln (1, \" \", n);\n\t\twritefln !(\"%(%s %)\") (a.map !(q{-a}));\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nlong egcd(long a, long b, ref long x, ref long y)\n{\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1, y1;\n long d = egcd(b, a % b, x1, y1);\n x = y1;\n y = x1 - y1 * (a / b);\n return d;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!long;\n auto a = next!long(n);\n\n if (n == 1)\n {\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(-a[0]);\n return;\n }\n long x, y;\n egcd(n, n - 1, x, y);\n assert(n * x + (n - 1) * y == 1);\n writeln(1, \" \", n);\n foreach(i, ai; a)\n {\n write(- ai * x * n, \" \");\n }\n writeln;\n writeln(1, \" \", n - 1);\n foreach(i, ai; a[0 .. $ - 1])\n {\n write(- ai * y * (n - 1), \" \");\n }\n writeln;\n writeln(2, \" \", n);\n foreach(ai; a[1 .. $ - 1])\n {\n write(0, \" \");\n }\n writeln(- a[$ - 1] * y * (n - 1));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nlong egcd(long a, long b, ref long x, ref long y)\n{\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1, y1;\n long d = egcd(b, a % b, x1, y1);\n x = y1;\n y = x1 - y1 * (a / b);\n return d;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!long;\n auto a = next!long(n);\n\n if (n == 1)\n {\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(-a[0]);\n return;\n }\n long x, y;\n egcd(n, n - 1, x, y);\n assert(n * x + (n - 1) * y == 1);\n writeln(1, \" \", n);\n foreach(i, ai; a)\n {\n write(- ai * x * n, \" \");\n }\n writeln;\n writeln(1, \" \", n - 1);\n foreach(i, ai; a[0 .. $ - 1])\n {\n write(- ai * y * (n - 1), \" \");\n }\n writeln;\n writeln(2, \" \", n);\n foreach(ai; a[1 .. $ - 1])\n {\n write(0, \" \");\n }\n writeln(- a[$ - 1] * y * (n - 1));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byChunk;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nlong egcd(long a, long b, ref long x, ref long y)\n{\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1, y1;\n long d = egcd(b, a % b, x1, y1);\n x = y1;\n y = x1 - y1 * (a / b);\n return d;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!long;\n auto a = next!long(n);\n\n if (n == 1)\n {\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(-a[0]);\n return;\n }\n long x, y;\n egcd(n, n - 1, x, y);\n assert(n * x + (n - 1) * y == 1);\n writeln(1, \" \", n);\n foreach(i, ai; a)\n {\n write(- ai * x * n, \" \");\n }\n writeln;\n writeln(1, \" \", n - 1);\n foreach(i, ai; a[0 .. $ - 1])\n {\n write(- ai * y * (n - 1), \" \");\n }\n writeln;\n writeln(2, \" \", n);\n foreach(ai; a[1 .. $ - 1])\n {\n write(0, \" \");\n }\n writeln(- a[$ - 1] * y * (n - 1));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byChunk;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 8 * 1024 * 1024;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\n\nlong egcd(long a, long b, ref long x, ref long y)\n{\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1, y1;\n long d = egcd(b, a % b, x1, y1);\n x = y1;\n y = x1 - y1 * (a / b);\n return d;\n}\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n int n;\n @Dim(q{n}) long[] a;\n\n void solve(long tc = -1)\n {\n if (n == 1)\n {\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(-a[0]);\n return;\n }\n long x, y;\n egcd(n, n - 1, x, y);\n assert(n * x + (n - 1) * y == 1);\n writeln(1, \" \", n);\n foreach(i, ai; a)\n {\n write(- ai * x * n, \" \");\n }\n writeln;\n writeln(1, \" \", n - 1);\n foreach(i, ai; a[0 .. $ - 1])\n {\n write(- ai * y * (n - 1), \" \");\n }\n writeln;\n writeln(2, \" \", n);\n foreach(ai; a[1 .. $ - 1])\n {\n write(0, \" \");\n }\n writeln(- a[$ - 1] * y * (n - 1));\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main(string[] args)\n{\n debug stdin = File(args[1]);\n type;\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nlong egcd(long a, long b, ref long x, ref long y)\n{\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1, y1;\n long d = egcd(b, a % b, x1, y1);\n x = y1;\n y = x1 - y1 * (a / b);\n return d;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!long;\n auto a = next!long(n);\n\n if (n == 1)\n {\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(-a[0]);\n return;\n }\n long x, y;\n egcd(n, n - 1, x, y);\n assert(n * x + (n - 1) * y == 1);\n writeln(1, \" \", n);\n foreach(i, ai; a)\n {\n write(- ai * x * n, \" \");\n }\n writeln;\n writeln(1, \" \", n - 1);\n foreach(i, ai; a[0 .. $ - 1])\n {\n write(- ai * y * (n - 1), \" \");\n }\n writeln;\n writeln(2, \" \", n);\n foreach(ai; a[1 .. $ - 1])\n {\n write(0, \" \");\n }\n writeln(- a[$ - 1] * y * (n - 1));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byChunk;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 4 * 1024 * 1024;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nlong egcd(long a, long b, ref long x, ref long y)\n{\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n\n long x1, y1;\n long d = egcd(b, a % b, x1, y1);\n x = y1;\n y = x1 - y1 * (a / b);\n return d;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!long;\n auto a = next!long(n);\n\n if (n == 1)\n {\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(0);\n writeln(1, \" \", 1);\n writeln(-a[0]);\n return;\n }\n long x, y;\n egcd(n, n - 1, x, y);\n assert(n * x + (n - 1) * y == 1);\n writeln(1, \" \", n);\n foreach(i, ai; a)\n {\n write(- ai * x * n, \" \");\n }\n writeln;\n writeln(1, \" \", n - 1);\n foreach(i, ai; a[0 .. $ - 1])\n {\n write(- ai * y * (n - 1), \" \");\n }\n writeln;\n writeln(2, \" \", n);\n foreach(ai; a[1 .. $ - 1])\n {\n write(0, \" \");\n }\n writeln(- a[$ - 1] * y * (n - 1));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byChunk;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tauto ans1 = new long[](n);\n\tforeach (i; 0..n-1)\n\t{\n\t\tans1[i] = -n * a[i];\n\t}\n\tauto ans2 = new long[](n-1);\n\tforeach (i; 0..n-1)\n\t{\n\t\tans2[i] = (n-1) * a[i];\n\t}\n\n\tif (n == 1)\n\t{\n\t\twriteln(\"1 1\");\n\t\twriteln(0);\n\t\twriteln(\"1 1\");\n\t\twriteln(0);\n\t\twriteln(\"1 1\");\n\t\twriteln(-a[0]);\n\t}\n\telse\n\t{\n\t\twriteln(\"1 \", n);\n\t\tans1.map!(to!string).join(\" \").writeln;\n\t\twriteln(\"1 \", n-1);\n\t\tans2.map!(to!string).join(\" \").writeln;\n\t\twriteln(n, \" \", n);\n\t\twriteln(-a[$-1]);\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tauto ans1 = new long[](n);\n\tforeach (i; 0..n-1)\n\t{\n\t\tans1[i] = -n * a[i];\n\t}\n\tauto ans2 = new long[](n-1);\n\tforeach (i; 0..n-1)\n\t{\n\t\tans2[i] = (n-1) * a[i];\n\t}\n\n\twriteln(\"1 \", n);\n\tans1.map!(to!string).join(\" \").writeln;\n\twriteln(\"1 \", n-1);\n\tans2.map!(to!string).join(\" \").writeln;\n\twriteln(n, \" \", n);\n\twriteln(-a[$-1]);\n\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "d15a758cfdd7a627822fe8be7db4f60b"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 8 * 3 + 1;\n\nvoid main()\n{\n readln;\n auto s = readln.chomp.split.map!(to!int).array;\n auto c = readln.chomp.split.map!(to!int).array;\n \n int ans = INF;\n foreach (i, fs, cst; lockstep(s, c)) {\n int getMin(int[] s, int[]c, bool delegate(int) valsFilter) {\n auto vals = zip(s,c).filter!(t => valsFilter(t[0])).map!(t => t[1]);\n return vals.empty() ? INF : vals.minElement;\n }\n auto prev = getMin(s[0..i], c[0..i], x => x < fs);\n auto nxt = getMin(s[i+1..$], c[i+1..$], x => x > fs);\n if (prev != INF && nxt != INF) ans = min(ans, cst + prev + nxt);\n }\n \n writeln(ans == INF ? -1 : ans);\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 8 + 1;\n\nvoid main()\n{\n readln;\n auto s = readln.chomp.split.map!(to!int).array;\n auto c = readln.chomp.split.map!(to!int).array;\n \n int ans = INF + INF + INF;\n foreach (i, fs, cst; lockstep(s, c)) {\n int prev = INF;\n foreach (j; 0..i) {\n if (s[j] < fs) prev = min(prev, c[j]);\n }\n int nxt = INF;\n foreach (j; i+1..s.length) {\n if (fs < s[j]) nxt = min(nxt, c[j]);\n }\n if (prev != INF && nxt != INF) ans = min(ans, cst + prev + nxt);\n }\n \n writeln(ans == INF + INF + INF ? -1 : ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 8 * 3 + 1;\n\nvoid main()\n{\n readln;\n auto s = readln.chomp.split.map!(to!int).array;\n auto c = readln.chomp.split.map!(to!int).array;\n \n int ans = INF;\n foreach (i, fs, cst; lockstep(s, c)) {\n int getMin(int[] s, int[]c, bool delegate(int) valsFilter) {\n int ret = INF;\n foreach (_, fs, cst; lockstep(s,c)) {\n if (valsFilter(fs)) ret = min(cst, ret);\n }\n return ret;\n }\n auto prev = getMin(s[0..i], c[0..i], x => x < fs);\n auto nxt = getMin(s[i+1..$], c[i+1..$], x => x > fs);\n if (prev != INF && nxt != INF) ans = min(ans, cst + prev + nxt);\n }\n \n writeln(ans == INF ? -1 : ans);\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n auto s=readln.split.to!(int[]);\n auto c=readln.split.to!(int[]);\n\n auto tmp=s.dup;\n sort(tmp);\n int[int] map;\n foreach(e; tmp){\n if((e in map)==null) map[e]=map.length.to!(int);\n }\n foreach(i; 0..n) s[i]=map[s[i]];\n\n auto best=new int[][](n+1, n+1);\n const int inf=1_000_000_000;\n foreach(i; 0..(n+1)) fill(best[i], inf);\n foreach(i; 0..n){\n chmin(best[i][s[i]], c[i]);\n for(int j=s[i]; j>0; j--) chmin(best[i][j-1], best[i][j]);\n }\n for(int i=n-1; i>0; i--){\n foreach(j; 0..n){\n chmin(best[i-1][j], best[i][j]);\n }\n }\n\n int mn=inf;\n foreach(i; 0..n)foreach(j; (i+1)..n)if(s[i]<s[j]){\n mn=min(mn, c[i]+c[j]+best[j+1][s[j]+1]);\n }\n\n if(mn==inf) writeln(-1);\n else writeln(mn);\n}\n\nvoid chmin(T)(ref T l, T r){if(l>r)l=r;}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\nimport std.bigint;\nimport core.checkedint;\n\nvoid main()\n{\n\tint n = readln.chomp.to!int;\n\tlong[] s = readln.chomp.split.map!(to!long).array;\n\tint[] c = readln.chomp.split.map!(to!int).array;\n\tlong[] sub = new long[](n);\n\tforeach (i; 0..n) {\n\t\tint v = int.max;\n\t\tforeach (j; i + 1 .. n) {\n\t\t\tif (s[i] >= s[j]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tv = min(v, c[j]);\n\t\t}\n\t\tsub[i] = v;\n\t}\n\tlong ans = int.max;\n\tforeach (i; 0..n) {\n\t\tforeach (j; i + 1 .. n) {\n\t\t\tif (s[i] >= s[j]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdebug verbose(i, j, sub[j], c[i] + c[j] + sub[j]);\n\t\t\tans = min(ans, c[i] + c[j] + sub[j]);\n\t\t}\n\t}\n\tif (ans >= int.max) {\n\t\twriteln = -1;\n\t} else {\n\t\tans.writeln;\n\t}\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 8 * 3 + 1;\n\nvoid main()\n{\n readln;\n auto s = readln.chomp.split.map!(to!int).array;\n auto c = readln.chomp.split.map!(to!int).array;\n \n int ans = INF;\n foreach (i, fs, cst; lockstep(s, c)) {\n int getMin(int[] s, int[]c, bool delegate(int) valsFilter) {\n auto vals = zip(s,c).filter!(t => valsFilter(t[0])).map!(t => t[1]);\n return vals.empty() ? INF : vals.front();\n }\n auto prev = getMin(s[0..i], c[0..i], x => x < fs);\n auto nxt = getMin(s[i+1..$], c[i+1..$], x => x > fs);\n if (prev != INF && nxt != INF) ans = min(ans, cst + prev + nxt);\n }\n \n writeln(ans == INF ? -1 : ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 8 * 3;\n\nvoid main()\n{\n readln;\n auto s = readln.chomp.split.map!(to!int).array;\n auto c = readln.chomp.split.map!(to!int).array;\n \n int ans = INF;\n foreach (i, fs, cst; lockstep(s, c)) {\n int getMin(int[] s, int[]c, bool delegate(int) valsFilter) {\n int ret = INF;\n foreach (_, fs, cst; lockstep(s,c)) {\n if (valsFilter(fs)) ret = min(cst, ret);\n }\n return ret;\n }\n auto prev = getMin(s[0..i], c[0..i], x => x < fs);\n auto nxt = getMin(s[i+1..$], c[i+1..$], x => x > fs);\n if (prev != INF && nxt != INF) ans = min(ans, cst + prev + nxt);\n }\n \n writeln(ans == INF ? -1 : ans);\n}"}], "src_uid": "4a48b828e35efa065668703edc22bf9b"} {"source_code": "import std;\r\n\r\nint t,n;\r\n\r\nint U(int cur) {\r\n return cur == 9 ? 0 : cur + 1;\r\n}\r\n\r\nint D(int cur) {\r\n return cur == 0 ? 9 : cur - 1;\r\n}\r\n\r\nvoid main()\r\n{\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n scanf(\"%d\", &n);\r\n getchar();\r\n auto fin = readln.split.to!(int[]);\r\n foreach (w; 0 .. n) {\r\n auto l = readln.split.to!(string[]);\r\n foreach (com; l[1].array.reverse)\r\n if (com == 'U')\r\n fin[w] = D(fin[w]);\r\n else\r\n fin[w] = U(fin[w]);\r\n }\r\n writefln(\"%(%s %)\", fin);\r\n }\r\n \r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto temp = readln.split;\r\n\t\t\tforeach (ref c; temp[1])\r\n\t\t\t{\r\n\t\t\t\ta[i] = (a[i] + ((c == 'U') ? 9 : 1)) % 10;\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (a);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "fd47f1eb701077abc5ec67163ad4fcc5"} {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int x, d; readV(x, d);\n\n auto e = 1L;\n long[] a;\n while (x > 0) {\n auto i = (x+1).bsr;\n foreach (j; 0..i) a ~= e;\n e += d;\n x -= (1<<i)-1;\n }\n\n writeln(a.length);\n foreach (i, ai; a) {\n write(ai);\n if (i < a.length-1) write(\" \");\n }\n writeln;\n}\n\npragma(inline) {\n pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }\n pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }\n pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }\n pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }\n\n pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }\n pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }\n pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }\n\n import core.bitop;\n pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }\n pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }\n pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const X = readLong();\n const D = readLong();\n \n int[] es;\n for (long x = X; x > 0; ) {\n // 2^e - 1 <= x\n const e = bsr(x + 1);\n es ~= e;\n x -= ((1L << e) - 1);\n }\n debug {\n writeln(\"es = \", es);\n }\n \n long[] ans;\n long val = 1;\n foreach (e; es) {\n ans ~= repeat(val, e).array;\n val += D;\n }\n writeln(ans.length);\n foreach (i, a; ans) {\n if (i > 0) write(\" \");\n write(a);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"C\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n long B = 10L^^10;\n\n long x, d;\n sc.read(x, d);\n long U = 1;\n long[] res;\n foreach_reverse (ph; 1..40) {\n long y = (1L << ph) - 1;\n long z = x / y; x %= y;\n foreach (_; 0..z) {\n U += B;\n foreach (i; 0..ph) {\n res ~= U;\n }\n }\n }\n writeln(res.length);\n writeln(res.map!(to!string).join(\" \"));\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}], "negative_code": [{"source_code": "/+ dub.sdl:\n name \"C\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n long B = 10L^^10;\n\n long x, d;\n sc.read(x, d);\n long U = 1;\n long[] res;\n foreach_reverse (ph; 1..40) {\n long y = (1L << ph) - 1;\n long z = x / y; x %= y;\n foreach (_; 0..z) {\n U += B;\n foreach (i; 0..ph) {\n res ~= U;\n }\n }\n }\n writeln(res.map!(to!string).join(\" \"));\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int x, d; readV(x, d);\n\n auto e = 1;\n long[] a;\n while (x > 0) {\n auto i = (x+1).bsr;\n foreach (j; 0..i) a ~= e;\n e += d;\n x -= (1<<i)-1;\n }\n\n writeln(a.length);\n foreach (i, ai; a) {\n write(ai);\n if (i < a.length-1) write(\" \");\n }\n writeln;\n}\n\npragma(inline) {\n pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }\n pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }\n pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }\n pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }\n\n pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }\n pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }\n pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }\n\n import core.bitop;\n pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }\n pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }\n pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }\n}\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int x, d; readV(x, d);\n\n auto e = 1;\n long[] a;\n while (x > 0) {\n auto i = (x+1).bsr;\n foreach (j; 0..i) a ~= e;\n e += d;\n x -= (1<<i)-1;\n }\n\n foreach (i, ai; a) {\n write(ai);\n if (i < a.length-1) write(\" \");\n }\n writeln;\n}\n\npragma(inline) {\n pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }\n pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }\n pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }\n pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }\n\n pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }\n pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }\n pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }\n\n import core.bitop;\n pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }\n pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }\n pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const X = readLong();\n const D = readLong();\n \n int[] es;\n for (long x = X; x > 0; ) {\n // 2^e - 1 <= x\n const e = bsr(x + 1);\n es ~= e;\n x -= ((1L << e) - 1);\n }\n debug {\n writeln(\"es = \", es);\n }\n \n long[] ans;\n long val;\n foreach (e; es) {\n ans ~= repeat(val, e).array;\n val += D;\n }\n writeln(ans.length);\n foreach (i, a; ans) {\n if (i > 0) write(\" \");\n write(a);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const X = readLong();\n const D = readLong();\n \n int[] es;\n for (long x = X; x > 0; ) {\n // 2^e - 1 <= x\n const e = bsr(x + 1);\n es ~= e;\n x -= ((1L << e) - 1);\n }\n debug {\n writeln(\"es = \", es);\n }\n \n long[] ans;\n long val;\n foreach (e; es) {\n ans ~= repeat(val, e).array;\n val += D;\n }\n writeln(ans.length);\n foreach (i, a; ans) {\n if (i > 0) write(\" \");\n write(a);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "f5588694b1d800271ccdcf14b0ba8f67"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nauto cnt = new int[](26);\n\nvoid solve() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto S = readln.chomp;\n\n int ans = 0;\n\n foreach (i; 0..K/2+K%2) {\n cnt[] = 0;\n if (K % 2 && i == K / 2) {\n foreach (j; 0..N/K) {\n int a = j * K + i;\n cnt[S[a]-'a'] += 1;\n ans += 1;\n }\n } else {\n foreach (j; 0..N/K) {\n int a = j * K + i;\n int b = (j + 1) * K - i - 1;\n cnt[S[a]-'a'] += 1;\n cnt[S[b]-'a'] += 1;\n ans += 2;\n }\n }\n ans -= cnt.reduce!max;\n }\n\n ans.writeln;\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n solve();\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = RD!string;\n\t\t\n\t\tint len = n / k;\n\t\tint l, r = k-1;\n\t\twhile (l <= r)\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..len)\n\t\t\t{\n\t\t\t\tauto c1 = s[i*k+l] - 'a';\n\t\t\t\tauto c2 = s[i*k+r] - 'a';\n\t\t\t\t++cnt[c1];\n\t\t\t\t++cnt[c2];\n\t\t\t}\n\t\t\tint x;\n\t\t\tforeach (i; 0..26)\n\t\t\t{\n\t\t\t\tx.chmax(cnt[i]);\n\t\t\t}\n\t\t\tif (l == r)\n\t\t\t\tans[ti] += len - x / 2;\n\t\t\telse\n\t\t\t\tans[ti] += len * 2 - x;\n\t\t\tdebug writeln(\"ans:\", ans[ti]);\n\t\t\t++l;\n\t\t\t--r;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "22f90afe503267ff2c832430d3ffb3b4"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto s = RD!string;\n\tint[] ans1, ans2;\n\tint l, r = cast(int)s.length-1;\n\tforeach (i; 0..s.length)\n\t{\n\t\tif (s[i] == '(') break;\n\t\t++l;\n\t}\n\tforeach_reverse (i; 0..s.length)\n\t{\n\t\tif (s[i] == ')') break;\n\t\t--r;\n\t}\n\twhile (l < r)\n\t{\n\t\tans1 ~= l+1;\n\t\tans2 ~= r+1;\n\t\t++l; --r;\n\t\tforeach (i; l..s.length)\n\t\t{\n\t\t\tif (s[i] == '(') break;\n\t\t\t++l;\n\t\t}\n\t\tforeach_reverse (i; 0..r+1)\n\t\t{\n\t\t\tif (s[i] == ')') break;\n\t\t\t--r;\n\t\t}\n\t}\n\tans2.sort();\n\n\tif (ans1.empty && ans2.empty)\n\t{\n\t\twriteln(0);\n\t}\n\telse\n\t{\n\t\twriteln(1);\n\t\twriteln(ans1.length + ans2.length);\n\t\t(ans1~ans2).map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.container.dlist;\n\nvoid main() {\n auto s = readln.stripRight;\n const l = s.length.to!int;\n auto b = new bool[l];\n int[][] ans;\n while (true) {\n int i = 0, j = l - 1;\n int[] u, v;\n while (true) {\n while (i < l && (b[i] || s[i] != '(')) ++i;\n while (j >= 0 && (b[j] || s[j] != ')')) --j;\n if (i > j) break;\n u ~= i + 1;\n v ~= j + 1;\n b[i] = b[j] = true;\n }\n reverse (v);\n u ~= v;\n if (u.empty) break;\n ans ~= u;\n }\n writeln (ans.length);\n foreach (p; ans) {\n writeln (p.length);\n writefln (\"%(%s %)\", p);\n }\n\n}\n\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const S = readToken();\n const L = cast(int)(S.length);\n \n auto sums = new int[][](2, L + 1);\n foreach (i; 0 .. L) {\n sums[0][i + 1] = sums[0][i] + ((S[i] == '(') ? 1 : 0);\n sums[1][i + 1] = sums[1][i] + ((S[i] == ')') ? 1 : 0);\n }\n int mn = L + 1;\n int km = -1;\n foreach (k; 0 .. L + 1) {\n if (sums[0][k] == sums[1][L] - sums[1][k]) {\n if (chmin(mn, sums[0][k])) {\n km = k;\n }\n }\n }\n assert(km != -1);\n if (mn == 0) {\n writeln(0);\n } else {\n int[] ans;\n foreach (i; 0 .. km) if (S[i] == '(') ans ~= i;\n foreach (i; km .. L) if (S[i] == ')') ans ~= i;\n writeln(1);\n writeln(ans.length);\n foreach (index, i; ans) {\n if (index > 0) write(\" \");\n write(i + 1);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tint i = 0;\n\t\tint j = s.length.to !(int) - 1;\n\t\tint [] ans;\n\t\twhile (true)\n\t\t{\n\t\t\twhile (i < j && s[i] != '(')\n\t\t\t{\n\t\t\t\ti += 1;\n\t\t\t}\n\t\t\twhile (i < j && s[j] != ')')\n\t\t\t{\n\t\t\t\tj -= 1;\n\t\t\t}\n\t\t\tif (i >= j)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans ~= i;\n\t\t\tans ~= j;\n\t\t\ti += 1;\n\t\t\tj -= 1;\n\t\t}\n\t\tans[] += 1;\n\t\tsort (ans);\n\t\twritefln !(\"%d\") (ans.length > 0);\n\t\tif (!ans.empty)\n\t\t{\n\t\t\twriteln (ans.length);\n\t\t\twritefln !(\"%(%s %)\") (ans);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "f78d04f699fc94103e5b08023949854d"} {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int[] r;\n int n=readln.chomp.to!int;\n char[] s=readln.strip.to!(char[]),\n t=readln.strip.to!(char[]);\n if(s==t)\n puts(\"0\");\n else if(s.dup.array.sort!=t.dup.array.sort)\n puts(\"-1\");\n else{\n foreach(i;0..n){\n if(s[i]==t[i]) continue;\n int j=i+1;\n while(j<n && s[j]!=t[i])\n j++;\n while(j>i){\n s.swapAt(j,j-1);\n j--;\n r~=j+1;\n }\n }\n writeln(r.length);\n write(r[0]);\n foreach(i;1..r.length)\n write(\" \",r[i]);\n writeln;\n }\n}\n\n", "positive_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int[] r;\n int n=readln.chomp.to!int;\n char[] s=readln.strip.to!(char[]),\n t=readln.strip.to!(char[]);\n if(s==t)\n puts(\"0\");\n else if(s.dup.array.sort!=t.dup.array.sort)\n puts(\"-1\");\n else{\n foreach(i;0..n){\n if(s[i]==t[i]) continue;\n int j=i+1;\n while(j<n && s[j]!=t[i])\n j++;\n while(j>i){\n s.swapAt(j,j-1);\n j--;\n r~=j+1;\n }\n }\n writeln(r.length);\n writefln!\"%(%d %)\"(r);\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip.dup;\n\t\tauto t = readln.strip;\n\t\tint [] ans;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i..n)\n\t\t\t{\n\t\t\t\tif (s[j] == t[i])\n\t\t\t\t{\n\t\t\t\t\tforeach_reverse (p; i..j)\n\t\t\t\t\t{\n\t\t\t\t\t\tans ~= p + 1;\n\t\t\t\t\t\tswap (s[p], s[p + 1]);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (s != t)\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto s = readln.chomp.to!(dchar[]).array;\n auto t = readln.chomp;\n \n int[] ans;\n foreach (int i, e; t) {\n debug { writeln(i, ' ', e); }\n \n if (!s.drop(i).canFind(e)) {\n writeln(-1);\n return;\n }\n \n int p = n - cast(int) s.drop(i).find(e).length - 1;\n \n debug { writeln(s.drop(i), ' ', s.drop(i).find(e), ' ', s.drop(i).find(e).array.length); p.writeln; }\n \n while (i <= p) {\n swap(s[p], s[p+1]);\n ans ~= p;\n --p;\n }\n }\n \n ans.length.writeln;\n ans.map!(x => x+1).writefln!(\"%(%s %)\");\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto s = readln.chomp.to!(dchar[]).array;\n auto t = readln.chomp;\n \n int[] ans;\n foreach (int i, e; t) {\n debug { writeln(i, ' ', e); }\n \n if (!s.drop(i).canFind(e)) {\n writeln(-1);\n return;\n }\n \n int p = n - cast(int) s.drop(i).find(e).length - 1;\n \n debug { writeln(s.drop(i), ' ', s.drop(i).find(e), ' ', s.drop(i).find(e).array.length); p.writeln; }\n \n while (i <= p) {\n swap(s[p], s[p+1]);\n ans ~= p;\n --p;\n }\n }\n \n ans.map!(x => x+1).writefln!(\"%(%s %)\");\n}"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int[] r;\n int n=readln.chomp.to!int;\n char[] s=readln.strip.to!(char[]),\n t=readln.strip.to!(char[]); \n if(s.dup.array.sort!=t.dup.array.sort)\n puts(\"-1\");\n else{\n foreach(i;0..n){\n if(s[i]==t[i]) continue;\n int j=0;\n while(j<n && s[j]!=t[i])\n j++;\n while(j>i){\n s.swapAt(j,j-1);\n j--;\n r~=j;\n }\n }\n writeln(r.length);\n write(r[0]);\n foreach(i;1..r.length)\n write(\" \",r[i]);\n }\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int[] r;\n int n=readln.chomp.to!int;\n char[] s=readln.strip.to!(char[]),\n t=readln.strip.to!(char[]); \n if(s.dup.array.sort!=t.dup.array.sort)\n puts(\"-1\");\n else{\n foreach(i;0..n){\n if(s[i]==t[i]) continue;\n int j=0;\n while(j<n && s[j]!=t[i])\n j++;\n while(j>i){\n s.swapAt(j,j-1);\n j--;\n r~=j;\n }\n }\n write(r[0]);\n foreach(i;1..r.length)\n write(\" \",r[i]);\n writeln;\n debug writeln(s,\" \",t);\n }\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int[] r;\n int n=readln.chomp.to!int;\n char[] s=readln.strip.to!(char[]),\n t=readln.strip.to!(char[]); \n if(s.dup.array.sort!=t.dup.array.sort)\n puts(\"-1\");\n else{\n foreach(i;0..n){\n if(s[i]==t[i]) continue;\n int j=0;\n while(j<n && s[j]!=t[i])\n j++;\n while(j>i){\n s.swapAt(j,j-1);\n j--;\n r~=j+1;\n }\n }\n writeln(r.length);\n write(r[0]);\n foreach(i;1..r.length)\n write(\" \",r[i]);\n }\n}\n\n"}], "src_uid": "48e323edc41086cae52cc0e6bdd84e35"} {"source_code": "import std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n int n;\n readf(\"%d\\n\", &n);\n foreach (i; 0..n) {\n auto s = chomp(readln());\n if (s.length < 5) {\n writeln(\"OMG>.< I don't know!\");\n } else {\n bool is_freda = s[$-5..$] == \"lala.\"; \n bool is_rainbow = s[0..5] == \"miao.\";\n if (is_freda && !is_rainbow) {\n writeln(\"Freda's\");\n } else if (!is_freda && is_rainbow) {\n writeln(\"Rainbow's\");\n } else {\n writeln(\"OMG>.< I don't know!\");\n }\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.string;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n;\n readf(\" %s\\n\", &n);\n string str;\n foreach ( i ; 0 .. n ) {\n readf(\"%s\\n\", &str);\n bool f = (str.length >= 5 && str[$ - 5 .. $] == \"lala.\");\n bool r = (str.length >= 5 && str[0 .. 5] == \"miao.\");\n if (f && (f ^ r)) writeln(\"Freda's\");\n else if (r && (f ^ r)) writeln(\"Rainbow's\");\n else writeln(\"OMG>.< I don't know!\");\n }\n\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.string;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n;\n readf(\" %s\\n\", &n);\n string str;\n foreach ( i ; 0 .. n ) {\n readf(\" %s\\n\", &str);\n bool f = (str.length >= 5 && str[$ - 5 .. $] == \"lala.\");\n bool r = (str.length >= 5 && str[0 .. 5] == \"miao.\");\n if (f && (f ^ r)) writeln(\"Freda's\");\n else if (r && (f ^ r)) writeln(\"Rainbow's\");\n else writeln(\"OMG>.< I don't know!\");\n }\n\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.string;\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n int n;\n readf(\"%d \", &n);\n foreach (i; 0..n) {\n auto s = chomp(readln());\n if (s.length < 5) {\n writeln(\"OMG>.< I don't know!\");\n } else {\n bool is_freda = s[$-5..$] == \"lala.\"; \n bool is_rainbow = s[0..5] == \"miao.\";\n if (is_freda && !is_rainbow) {\n writeln(\"Freda's\");\n } else if (!is_freda && is_rainbow) {\n writeln(\"Rainbow's\");\n } else {\n writeln(\"OMG>.< I don't know!\");\n }\n }\n }\n}"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.string;\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n int n;\n readf(\"%d \", &n);\n foreach (i; 0..n) {\n auto s = strip(readln());\n if (s.length < 5) {\n writeln(\"OMG>.< I don't know!\");\n } else {\n bool is_freda = s[$-5..$] == \"lala.\"; \n bool is_rainbow = s[0..5] == \"miao.\";\n if (is_freda && !is_rainbow) {\n writeln(\"Freda's\");\n } else if (!is_freda && is_rainbow) {\n writeln(\"Rainbow's\");\n } else {\n writeln(\"OMG>.< I don't know!\");\n }\n }\n }\n}"}], "src_uid": "ee9ba877dee1a2843e885a18823cbff0"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int MED_N = 1 << 17;\nimmutable int MAX_N = MED_N << 1;\n\nint [MAX_N] t;\n\nint get (int i)\n{\n\treturn t[i + MED_N];\n}\n\nint get (int l, int r)\n{\n\tint res = 0;\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1)\n\t\t{\n\t\t\tres += t[l];\n\t\t\tl++;\n\t\t}\n\t\tif (!(r & 1))\n\t\t{\n\t\t\tres += t[r];\n\t\t\tr--;\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid put (int i, int v)\n{\n\tfor (i += MED_N; i > 0; i >>= 1)\n\t{\n\t\tt[i] += v;\n\t}\n}\n\nvoid main ()\n{\n\tint n, q;\n\twhile (readf (\" %s %s\", &n, &q) > 0)\n\t{\n\t\tt[] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tput (i, 1);\n\t\t}\n\t\tint turn = 0;\n\t\tint lo = 0;\n\t\tint hi = n - 1;\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tint qtype;\n\t\t\treadf (\" %s\", &qtype);\n\t\t\tif (qtype == 1)\n\t\t\t{\n\t\t\t\tint p;\n\t\t\t\treadf (\" %s\", &p);\n\t\t\t\tif (turn)\n\t\t\t\t{\n\t\t\t\t\tp = hi - lo + 1 - p;\n\t\t\t\t}\n\t\t\t\tint side = (p + p <= hi - lo + 1);\n\t\t\t\tif (side)\n\t\t\t\t{\n\t\t\t\t\tint c = lo + p;\n\t\t\t\t\tforeach (i; 0..p)\n\t\t\t\t\t{\n\t\t\t\t\t\tint v =\n\t\t\t\t\t\t get (c - i - 1);\n\t\t\t\t\t\tput (c - i - 1, -v);\n\t\t\t\t\t\tput (c + i, +v);\n\t\t\t\t\t}\n\t\t\t\t\tlo = c;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tp = hi - lo + 1 - p;\n\t\t\t\t\tint c = hi - p;\n\t\t\t\t\tforeach (i; 0..p)\n\t\t\t\t\t{\n\t\t\t\t\t\tint v =\n\t\t\t\t\t\t get (c + i + 1);\n\t\t\t\t\t\tput (c + i + 1, -v);\n\t\t\t\t\t\tput (c - i, +v);\n\t\t\t\t\t}\n\t\t\t\t\thi = c;\n\t\t\t\t}\n\t\t\t\tif (!side ^ turn)\n\t\t\t\t{\n\t\t\t\t\tturn ^= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (qtype == 2)\n\t\t\t{\n\t\t\t\tint x, y;\n\t\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\t\tif (!turn)\n\t\t\t\t{\n\t\t\t\t\tx = lo + x;\n\t\t\t\t\ty = lo + y - 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tswap (x, y);\n\t\t\t\t\tx = hi - x + 1;\n\t\t\t\t\ty = hi - y;\n\t\t\t\t}\n\t\t\t\twriteln (get (x, y));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tenforce (false);\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nvoid bitAdd(long[] bit, int pos, long val) {\n\tfor (int x = pos; x < bit.length; x |= x + 1) bit[x] += val;\n}\nlong bitSum(long[] bit, int pos) {\n\tlong ret;\n\tfor (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) ret += bit[x];\n\treturn ret;\n}\n\nint N, Q;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tQ = readInt;\n\t\t\n\t\tlong[] a = new long[N];\n\t\ta[] = 1;\n\t\tlong[] bit = new long[N];\n\t\tforeach (x; 0 .. N) {\n\t\t\tbit.bitAdd(x, +1);\n\t\t}\n\t\tbool rev = false;\n\t\tint head = 0, tail = N;\n\t\t\n\t\tvoid foldL(int p) {\ndebug{\nwriteln(\" L \",p);\n}\n\t\t\tforeach (x; head .. head + p) {\n\t\t\t\tconst y = (head + p) + (head + p - 1) - x;\n\t\t\t\ta[y] += a[x];\n\t\t\t\tbit.bitAdd(y, a[x]);\n\t\t\t}\n\t\t\thead += p;\n\t\t}\n\t\tvoid foldR(int p) {\ndebug{\nwriteln(\" R \",p);\n}\n\t\t\tforeach (x; tail - p .. tail) {\n\t\t\t\tconst y = (tail - p) + (tail - p - 1) - x;\n\t\t\t\ta[y] += a[x];\n\t\t\t\tbit.bitAdd(y, a[x]);\n\t\t\t}\n\t\t\ttail -= p;\n\t\t}\n\t\t\n\t\tforeach (q; 0 .. Q) {\ndebug{\nwriteln(a[head..tail],\" \",rev);\n}\n\t\t\tswitch (readInt) {\n\t\t\t\tcase 1: {\n\t\t\t\t\tconst p = readInt;\n\t\t\t\t\tconst pp = (tail - head) - p;\n\t\t\t\t\tif (rev) {\n\t\t\t\t\t\tif (p <= pp) {\n\t\t\t\t\t\t\tfoldR(p);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfoldL(pp);\n\t\t\t\t\t\t\trev = !rev;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (p <= pp) {\n\t\t\t\t\t\t\tfoldL(p);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfoldR(pp);\n\t\t\t\t\t\t\trev = !rev;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} break;\n\t\t\t\tcase 2: {\n\t\t\t\t\tconst l = readInt;\n\t\t\t\t\tconst r = readInt;\n\t\t\t\t\tlong res;\n\t\t\t\t\tif (rev) {\n\t\t\t\t\t\tres = bit.bitSum(tail - l) - bit.bitSum(tail - r);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tres = bit.bitSum(head + r) - bit.bitSum(head + l);\n\t\t\t\t\t}\n\t\t\t\t\twriteln(res);\n\t\t\t\t} break;\n\t\t\t\tdefault: assert(false);\n\t\t\t}\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int MED_N = 1 << 17;\nimmutable int MAX_N = MED_N << 1;\n\nint [MAX_N] t;\n\nint get (int i)\n{\n\treturn t[i + MED_N];\n}\n\nint get (int l, int r)\n{\n\tint res = 0;\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1)\n\t\t{\n\t\t\tres += t[l];\n\t\t\tl++;\n\t\t}\n\t\tif (!(r & 1))\n\t\t{\n\t\t\tres += t[r];\n\t\t\tr--;\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid put (int i, int v)\n{\n\tfor (i += MED_N; i > 0; i >>= 1)\n\t{\n\t\tt[i] += v;\n\t}\n}\n\nvoid main ()\n{\n\tint n, q;\n\twhile (readf (\" %s %s\", &n, &q) > 0)\n\t{\n\t\tt[] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tput (i, 1);\n\t\t}\n\t\tint lo = 0;\n\t\tint hi = n - 1;\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tint qtype;\n\t\t\treadf (\" %s\", &qtype);\n\t\t\tif (qtype == 1)\n\t\t\t{\n\t\t\t\tint p;\n\t\t\t\treadf (\" %s\", &p);\n\t\t\t\tint side = (p + p <= hi - lo + 1);\n\t\t\t\tif (side)\n\t\t\t\t{\n\t\t\t\t\tint c = lo + p;\n\t\t\t\t\tforeach (i; 0..p)\n\t\t\t\t\t{\n\t\t\t\t\t\tint v =\n\t\t\t\t\t\t get (c - i - 1);\n\t\t\t\t\t\tput (c - i - 1, -v);\n\t\t\t\t\t\tput (c + i, +v);\n\t\t\t\t\t}\n\t\t\t\t\tlo = c;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tp = hi - lo + 1 - p;\n\t\t\t\t\tint c = hi - p;\n\t\t\t\t\tforeach (i; 0..p)\n\t\t\t\t\t{\n\t\t\t\t\t\tint v =\n\t\t\t\t\t\t get (c + i + 1);\n\t\t\t\t\t\tput (c + i + 1, -v);\n\t\t\t\t\t\tput (c - i, +v);\n\t\t\t\t\t}\n\t\t\t\t\thi = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (qtype == 2)\n\t\t\t{\n\t\t\t\tint x, y;\n\t\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\t\twriteln (get (lo + x, lo + y - 1));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tenforce (false);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "src_uid": "19d9a438bf6353638b08252b030c407b"} {"source_code": "import core.bitop;\r\nimport std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, q;\r\n\t\treadf !(\" %s %s\") (n, q);\r\n\t\treadln;\r\n\t\tauto s = readln.strip.map !(q{a == '1'}).array;\r\n\t\tauto f = readln.strip.map !(q{a == '1'}).array;\r\n\t\talias Segment = Tuple !(int, q{lo}, int, q{hi});\r\n\t\tauto a = new Segment [q];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s\") (c.lo, c.hi);\r\n\t\t\tc.lo -= 1;\r\n\t\t}\r\n\t\treadln;\r\n\r\n\t\tauto half = 1 << bsr (n * 2 - 1);\r\n\t\thalf = max (half, 2);\r\n\t\tauto limit = half << 1;\r\n\t\tdebug {writeln (half, \" \", limit);}\r\n\t\tauto t = new int [limit];\r\n\t\tauto u = new int [limit];\r\n\t\tauto z = new int [limit];\r\n\t\tu[] = -1;\r\n\r\n\t\tvoid relax (int pos)\r\n\t\t{\r\n\t\t\tif (u[pos] != -1)\r\n\t\t\t{\r\n\t\t\t\tdebug {writeln (\"relax \", pos);}\r\n\t\t\t\tt[pos] = u[pos] * z[pos];\r\n\t\t\t\tif (pos < half)\r\n\t\t\t\t{\r\n\t\t\t\t\tu[pos * 2 + 0] = u[pos];\r\n\t\t\t\t\tu[pos * 2 + 1] = u[pos];\r\n\t\t\t\t}\r\n\t\t\t\tu[pos] = -1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid recalc (int pos)\r\n\t\t{\r\n\t\t\tif (pos < half)\r\n\t\t\t{\r\n\t\t\t\trelax (pos * 2 + 0);\r\n\t\t\t\trelax (pos * 2 + 1);\r\n\t\t\t\tt[pos] = t[pos * 2 + 0] + t[pos * 2 + 1];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tt[i + half] = f[i];\r\n\t\t\tz[i + half] = 1;\r\n\t\t}\r\n\t\tforeach_reverse (i; 1..half)\r\n\t\t{\r\n\t\t\trecalc (i);\r\n\t\t\tz[i] = z[i * 2 + 0] + z[i * 2 + 1];\r\n\t\t}\r\n\r\n\t\tint calc (int pos, int tlo, int thi, int slo, int shi)\r\n\t\t{\r\n\t\t\tif (shi <= tlo || thi <= slo)\r\n\t\t\t{\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\trelax (pos);\r\n\t\t\tif (slo <= tlo && thi <= shi)\r\n\t\t\t{\r\n\t\t\t\treturn t[pos];\r\n\t\t\t}\r\n\t\t\tint tme = (tlo + thi) >> 1;\r\n\t\t\tauto res = calc (pos * 2 + 0, tlo, tme, slo, shi) +\r\n\t\t\t calc (pos * 2 + 1, tme, thi, slo, shi);\r\n\t\t\trecalc (pos);\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tvoid mark (int pos, int tlo, int thi, int slo, int shi, int v)\r\n\t\t{\r\n\t\t\tif (shi <= tlo || thi <= slo)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\trelax (pos);\r\n\t\t\tif (slo <= tlo && thi <= shi)\r\n\t\t\t{\r\n\t\t\t\tu[pos] = v;\r\n\t\t\t\trelax (pos);\r\n\t\t\t\trecalc (pos);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tint tme = (tlo + thi) >> 1;\r\n\t\t\tmark (pos * 2 + 0, tlo, tme, slo, shi, v);\r\n\t\t\tmark (pos * 2 + 1, tme, thi, slo, shi, v);\r\n\t\t\trecalc (pos);\r\n\t\t}\r\n\r\n\t\tdebug {writefln !(\"%(%3s%)\") (z);}\r\n\t\tbool ok = true;\r\n\t\tforeach_reverse (ref c; a)\r\n\t\t{\r\n\t\t\tauto d = calc (1, 0, half, c.lo, c.hi);\r\n\t\t\tdebug {writeln (c.lo, \" \", c.hi, \" \", d);}\r\n\t\t\tdebug {writeln (\"after calc:\");}\r\n\t\t\tdebug {writefln !(\"%(%3s%)\") (t);}\r\n\t\t\tdebug {writefln !(\"%(%3s%)\") (u);}\r\n\t\t\tint v = -1;\r\n\t\t\tif (d * 2 < c.hi - c.lo)\r\n\t\t\t{\r\n\t\t\t\tv = 0;\r\n\t\t\t}\r\n\t\t\telse if (d * 2 > c.hi - c.lo)\r\n\t\t\t{\r\n\t\t\t\tv = 1;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tmark (1, 0, half, c.lo, c.hi, v);\r\n\t\t\tdebug {writeln (\"after mark:\");}\r\n\t\t\tdebug {writefln !(\"%(%3s%)\") (t);}\r\n\t\t\tdebug {writefln !(\"%(%3s%)\") (u);}\r\n\t\t}\r\n\r\n\t\tforeach (i; 1..half + n)\r\n\t\t{\r\n\t\t\trelax (i);\r\n\t\t}\r\n\t\tdebug {writefln !(\"%(%3s%)\") (t);}\r\n\t\tdebug {writefln !(\"%(%3s%)\") (u);}\r\n\t\tdebug {writefln !(\"%(%d%)\") (s);}\r\n\t\tdebug {writefln !(\"%(%d%)\") (t[half..half + n]);}\r\n\t\tok &= equal (s, t[half..half + n]);\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.traits;\nimport core.bitop;\nimport std.typecons;\n\nclass LazyPropagationSegmentTree(T = int, D = int, D init = D.init) {\n immutable size_t n;\n immutable int h;\n T[] t;\n D[] d;\n\n abstract void calc (size_t p, int k);\n abstract void apply (size_t p, D value, int k);\n\n final void build (size_t l, size_t r) {\n int k = 2;\n for (l += n, r += n - 1; l > 1; k <<= 1) {\n l >>= 1;\n r >>= 1;\n foreach_reverse (i; l .. r + 1) {\n calc (i, k);\n }\n }\n }\n\n final void push (size_t l, size_t r) {\n int s = h, k = 1 << (h-1);\n for (l += n, r += n - 1; s > 0; --s, k >>= 1) {\n foreach (i; l >> s .. (r >> s) + 1) {\n immutable delta = d[i];\n if (delta != init) {\n apply (i << 1, delta, k);\n apply ((i << 1) | 1, delta, k);\n d[i] = init;\n }\n }\n }\n }\n\n this (const T[] a) {\n n = a.length;\n h = bsr (n);\n t = uninitializedArray!(T[])(n);\n t ~= a;\n d = uninitializedArray!(D[])(n);\n d[] = init;\n build (0, n);\n }\n}\n\nclass AssignSumLazyPropagationSegmentTree (T = int) : LazyPropagationSegmentTree!(T, T, T.min) {\n override void calc (size_t p, int k) {\n if (d[p] == T.min) t[p] = t[p<<1] + t[(p << 1) | 1];\n else t[p] = d[p] * k;\n }\n\n override void apply (size_t p, T value, int k) {\n t[p] = value * k;\n if (p < n) d[p] = value;\n }\n\n final void assign (size_t l, size_t r, T value) {\n debug stderr.writefln (\"assign (l:%d, r:%d, value:%d)\", l, r, value);\n push (l, l + 1);\n push (r - 1, r);\n immutable l0 = l, r0 = r;\n int k = 1;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {\n if (l & 1) {\n apply (l++, value, k);\n }\n if (r & 1) {\n apply (--r, value, k);\n }\n }\n build (l0, l0 + 1);\n build (r0 - 1, r0);\n }\n\n final T sum (size_t l, size_t r) {\n push (l, l + 1);\n push (r - 1, r);\n T res;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n if (l & 1) {\n res += t[l++];\n }\n if (r & 1) {\n res += t[--r];\n }\n }\n return res;\n }\n this (T[] a) {\n super (a);\n }\n}\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nalias Q = Tuple!(int, int);\n\nvoid main() {\n auto r = new InputReader ();\n const nt = r.next!uint();\n foreach (tid; 0 .. nt) {\n const n = r.next!uint();\n const nq = r.next!uint();\n r.seekByte(48);\n int[] a, b;\n foreach (i; 0 .. n) {\n const c = r.nextByte!false();\n a ~= c.to!int - 48;\n }\n r.seekByte(48);\n foreach (i; 0 .. n) {\n const c = r.nextByte!false();\n b ~= c.to!int - 48;\n }\n debug stderr.writeln(a);\n debug stderr.writeln(b);\n auto st = new AssignSumLazyPropagationSegmentTree!int(b);\n Q[] q;\n foreach (i; 0 .. nq) {\n const u = r.next!int - 1;\n const v = r.next!int;\n q ~= Q(u, v);\n }\n bool res = true;\n foreach_reverse (k, const w; q) {\n const l = w[1] - w[0];\n const h = (l - 1) / 2;\n int t = st.sum(w[0], w[1]);\n debug stderr.writefln(\"l = %d, r = %d, sum = %d, h = %d, l = %d\", w[0], w[1], t, h, l);\n if (t <= h) {\n st.assign(w[0], w[1], 0);\n } else if (t + h >= l) {\n st.assign(w[0], w[1], 1);\n } else {\n debug stderr.writefln(\"FAILED: l = %d, r = %d\", w[0], w[1]);\n res = false;\n break;\n }\n }\n if (res) {\n foreach (i; 0 .. n) {\n if (st.sum(i, i + 1) != a[i]) {\n res = false;\n break;\n }\n }\n }\n if (res) write(\"YES\\n\"); else write(\"NO\\n\");\n }\n}\n\n"}], "negative_code": [{"source_code": "import core.bitop;\r\nimport std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, q;\r\n\t\treadf !(\" %s %s\") (n, q);\r\n\t\treadln;\r\n\t\tauto s = readln.strip.map !(q{a == '1'}).array;\r\n\t\tauto f = readln.strip.map !(q{a == '1'}).array;\r\n\t\talias Segment = Tuple !(int, q{lo}, int, q{hi});\r\n\t\tauto a = new Segment [q];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s\") (c.lo, c.hi);\r\n\t\t\tc.lo -= 1;\r\n\t\t}\r\n\t\treadln;\r\n\r\n\t\tauto half = 1 << bsr (n * 2 - 1);\r\n\t\tauto limit = half << 1;\r\n\t\tauto t = new int [limit];\r\n\t\tauto u = new int [limit];\r\n\t\tauto z = new int [limit];\r\n\t\tu[] = -1;\r\n\r\n\t\tvoid relax (int pos)\r\n\t\t{\r\n\t\t\tif (u[pos] != -1)\r\n\t\t\t{\r\n\t\t\t\tt[pos] = u[pos] * z[pos];\r\n\t\t\t\tif (pos < half)\r\n\t\t\t\t{\r\n\t\t\t\t\tu[pos * 2 + 0] = u[pos];\r\n\t\t\t\t\tu[pos * 2 + 1] = u[pos];\r\n\t\t\t\t}\r\n\t\t\t\tu[pos] = -1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid recalc (int pos)\r\n\t\t{\r\n\t\t\tif (pos < half)\r\n\t\t\t{\r\n\t\t\t\tt[pos] = t[pos * 2 + 0] + t[pos * 2 + 1];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tt[i + half] = f[i];\r\n\t\t\tz[i + half] = 1;\r\n\t\t}\r\n\t\tforeach_reverse (i; 1..half)\r\n\t\t{\r\n\t\t\trecalc (i);\r\n\t\t\tz[i] = z[i * 2 + 0] + z[i * 2 + 1];\r\n\t\t}\r\n\r\n\t\tint calc (int pos, int tlo, int thi, int slo, int shi)\r\n\t\t{\r\n\t\t\tif (shi <= tlo || thi <= slo)\r\n\t\t\t{\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\trelax (pos);\r\n\t\t\tif (slo <= tlo && thi <= shi)\r\n\t\t\t{\r\n\t\t\t\treturn t[pos];\r\n\t\t\t}\r\n\t\t\tint tme = (tlo + thi) >> 1;\r\n\t\t\treturn calc (pos * 2 + 0, tlo, tme, slo, shi) +\r\n\t\t\t calc (pos * 2 + 1, tme, thi, slo, shi);\r\n\t\t}\r\n\r\n\t\tvoid mark (int pos, int tlo, int thi, int slo, int shi, int v)\r\n\t\t{\r\n\t\t\tif (shi <= tlo || thi <= slo)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\trelax (pos);\r\n\t\t\tif (slo <= tlo && thi <= shi)\r\n\t\t\t{\r\n\t\t\t\tu[pos] = v;\r\n\t\t\t\trelax (pos);\r\n\t\t\t\trecalc (pos);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tint tme = (tlo + thi) >> 1;\r\n\t\t\tmark (pos * 2 + 0, tlo, tme, slo, shi, v);\r\n\t\t\tmark (pos * 2 + 1, tme, thi, slo, shi, v);\r\n\t\t\trecalc (pos);\r\n\t\t}\r\n\r\n\t\tdebug {writefln !(\"%(%3s%)\") (z);}\r\n\t\tbool ok = true;\r\n\t\tforeach_reverse (ref c; a)\r\n\t\t{\r\n\t\t\tauto d = calc (1, 0, half, c.lo, c.hi);\r\n\t\t\tdebug {writeln (c.lo, \" \", c.hi, \" \", d);}\r\n\t\t\tint v = -1;\r\n\t\t\tif (d * 2 < c.hi - c.lo)\r\n\t\t\t{\r\n\t\t\t\tv = 0;\r\n\t\t\t}\r\n\t\t\telse if (d * 2 > c.hi - c.lo)\r\n\t\t\t{\r\n\t\t\t\tv = 1;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tmark (1, 0, half, c.lo, c.hi, v);\r\n\t\t\tdebug {writefln !(\"%(%3s%)\") (t);}\r\n\t\t\tdebug {writefln !(\"%(%3s%)\") (u);}\r\n\t\t}\r\n\r\n\t\tforeach (i; 1..half + n)\r\n\t\t{\r\n\t\t\trelax (i);\r\n\t\t}\r\n\t\tdebug {writefln !(\"%(%3s%)\") (t);}\r\n\t\tdebug {writefln !(\"%(%3s%)\") (u);}\r\n\t\tdebug {writefln !(\"%(%d%)\") (s);}\r\n\t\tdebug {writefln !(\"%(%d%)\") (t[half..half + n]);}\r\n\t\tok &= equal (s, t[half..half + n]);\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "src_uid": "1bacc1a9f8b2d586ee8d59e3c46cfcf3"} {"source_code": "import std.stdio;\n\nT read(T)()\n{\n T t;\n readf(\" %s\", &t);\n return t;\n}\n\nT sign(T)(T x)\n{\n return x < 0 ? -1 : 1;\n}\n\nint main(string[] args)\n{\n long x1 = read!long;\n long y1 = read!long;\n long x2 = read!long;\n long y2 = read!long;\n long n = read!long;\n\n long ans = 0;\n foreach (i; 0..n)\n {\n long a = read!long;\n long b = read!long;\n long c = read!long;\n\n if (sign(a * x1 + b * y1 + c) *\n sign(a * x2 + b * y2 + c) < 0)\n {\n ans++;\n }\n }\n\n writeln(ans);\n\n return 0;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tlong x1, y1;\n\twhile (readf (\" %s %s\", &x1, &y1) > 0)\n\t{\n\t\tlong x2, y2;\n\t\treadf (\" %s %s\", &x2, &y2);\n\t\tint n;\n\t\treadf (\" %s\", &n);\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlong a, b, c;\n\t\t\treadf (\" %s %s %s\", &a, &b, &c);\n\t\t\tlong d1 = a * x1 + b * y1 + c;\n\t\t\tlong d2 = a * x2 + b * y2 + c;\n\t\t\tif ((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0))\n\t\t\t{\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nT read(T)()\n{\n T t;\n readf(\" %s\", &t);\n return t;\n}\n\nT sign(T)(T x)\n{\n return -x;\n}\n\nint main(string[] args)\n{\n int x1 = read!int;\n int y1 = read!int;\n int x2 = read!int;\n int y2 = read!int;\n int n = read!int;\n\n int ans = 0;\n foreach (i; 0..n)\n {\n int a = read!int;\n int b = read!int;\n int c = read!int;\n\n if (sign(a * x1 + b * y1 + c) *\n sign(a * x2 + b * y2 + c) < 0)\n {\n ans++;\n }\n }\n\n writeln(ans);\n\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nT read(T)()\n{\n T t;\n readf(\" %s\", &t);\n return t;\n}\n\nT sign(T)(T x)\n{\n return -x;\n}\n\nint main(string[] args)\n{\n long x1 = read!long;\n long y1 = read!long;\n long x2 = read!long;\n long y2 = read!long;\n long n = read!long;\n\n long ans = 0;\n foreach (i; 0..n)\n {\n long a = read!long;\n long b = read!long;\n long c = read!long;\n\n if (sign(a * x1 + b * y1 + c) *\n sign(a * x2 + b * y2 + c) < 0)\n {\n ans++;\n }\n }\n\n writeln(ans);\n\n return 0;\n}\n"}], "src_uid": "783df1df183bf182bf9acbb99208cdb7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto nk = new long[2][](t);\n\tforeach (i; 0..t)\n\t{\n\t\tnk[i] = [RD, RD];\n\t}\n\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = nk[i][0];\n\t\tauto k = nk[i][1];\n\t\tlong ans;\n\t\twhile (n != 0)\n\t\t{\n\t\t\tauto x = n % k;\n\t\t\tif (x == 0)\n\t\t\t{\n\t\t\t\tn /= k;\n\t\t\t\t++ans;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tn -= x;\n\t\t\t\tans += x;\n\t\t\t}\n\t\t}\n\t\twriteln(ans);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable int INF = 1 << 29;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n auto s = readln.split.map!(to!long);\n auto N = s[0];\n auto K = s[1];\n long cnt = 0;\n while (N > 0) {\n long m = N % K;\n if (m == 0) {\n N /= K;\n cnt += 1;\n } else {\n N -= m;\n cnt += m;\n }\n }\n cnt.writeln;\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tlong n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\tlong res = 0;\n\t\twhile (n > 0)\n\t\t{\n\t\t\tres += n % k;\n\t\t\tn -= n % k;\n\t\t\tif (n > 0)\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t\tn /= k;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nvoid main() {\n long nt;\n readf!\" %d\" (nt);\n while (--nt >= 0) {\n long n, k;\n readf!\" %d %d\" (n, k);\n long res;\n while (n >= k) {\n res += 1 + (n % k);\n debug stderr.writeln (res);\n n /= k;\n }\n res += n;\n writeln (res);\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\t\n\tint t = read.to!int;\n\tforeach(_; 0 .. t){\n\t\t\n\t\tlong n = read.to!long;\n\t\tlong k = read.to!long;\n\t\t\n\t\tlong ans;\n\t\twhile(n > 0){\n\t\t\tif(n % k == 0) ans += 1, n /= k;\n\t\t\telse ans += n % k, n -= (n % k);\n\t\t}\n\t\t\n\t\tans.writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tlong n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\tlong res = 0;\n\t\twhile (n > 0)\n\t\t{\n\t\t\tres += n % k;\n\t\t\tn /= k;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "00b1e45e9395d23e850ce1a0751b8378"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!T(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\n\nvoid main()\n{\n int t;\n read(t);\n foreach(i; 0 .. t)\n {\n long n;\n read(n);\n if (n % 4 == 0)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tans[ti] = n % 4 == 0;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\twriteln (n % 4 == 0 ? \"YES\" : \"NO\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "07e56d4031bcb119d2f684203f7ed133"} {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\nunittest{\n assert(solve(10,\"DZFDFZDFDDDDDDF\") == 82, \"Teste 1\");\n assert(solve(4,\"YJSNPI\") == 4, \"Teste 1\");\n}\n\nulong solve(ulong k, string s){\n ulong sum = 0;\n\n ulong[immutable(char)] h;\n ulong[26] hi;\n\n foreach(c;s){\n ++h[c];\n }\n\n foreach(cc;h.keys){\n hi[cc-65] = h[cc];\n }\n\n while(k > 0){\n size_t max = 0;\n for(size_t i = 0; i < hi.length; i++){\n if(hi[i] > hi[max]){\n max = i;\n }\n }\n auto pts = min(k,hi[max]);\n k -= pts;\n\n sum += pts*pts;\n hi[max] = 0;\n }\n\n debug(1) writeln(sum);\n return sum;\n}\n\nvoid main(){\n size_t n;\n ulong k;\n string s;\n readf(\"%s %s\\n\",&n,&k);\n readf(\"%s\\n\",&s);\n\n writeln(solve(k,s));\n}\n", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N, K;\nstring A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = readInt;\n\t\tA = readToken;\n\t\t\n\t\tlong[] cnt = new long[26];\n\t\tforeach (a; A) {\n\t\t\t++cnt[a - 'A'];\n\t\t}\n\t\t\n\t\tcnt.sort!\"a > b\";\n\t\tlong ans;\n\t\tlong k = K;\n\t\tforeach (c; cnt) {\n\t\t\tconst tmp = min(c, k);\n\t\t\tans += tmp * tmp;\n\t\t\tk -= tmp;\n\t\t}\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\nunittest{\n assert(solve(10,\"DZFDFZDFDDDDDDF\") == 82, \"Teste 1\");\n assert(solve(4,\"YJSNPI\") == 4, \"Teste 1\");\n}\n\nulong solve(ulong k, string s){\n auto sum = 0;\n\n ulong[immutable(char)] h;\n ulong[26] hi;\n\n foreach(c;s){\n ++h[c];\n }\n\n foreach(cc;h.keys){\n hi[cc-65] = h[cc];\n }\n\n while(k > 0){\n size_t max = 0;\n for(size_t i = 0; i < hi.length; i++){\n if(hi[i] > hi[max]){\n max = i;\n }\n }\n auto pts = min(k,hi[max]);\n k -= pts;\n\n sum += pts*pts;\n hi[max] = 0;\n }\n\n debug(1) writeln(sum);\n return sum;\n}\n\nvoid main(){\n size_t n;\n ulong k;\n string s;\n readf(\"%s %s\\n\",&n,&k);\n readf(\"%s\\n\",&s);\n\n writeln(solve(k,s));\n}\n"}], "src_uid": "480defc596ee5bc800ea569fd76dc584"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = new string[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] = RD!string;\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i][$-1] == 'R')\n\t\t\t\t++ans[ti];\n\t\t}\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tif (a[$-1][i] == 'D')\n\t\t\t\t++ans[ti];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint rows, cols;\n\t\treadf !(\" %s %s\") (rows, cols);\n\t\treadln;\n\t\tauto board = rows.iota.map !(_ => readln.strip).array;\n\t\tint res = 0;\n\t\tforeach (row; 0..rows - 1)\n\t\t{\n\t\t\tres += (board[row][cols - 1] != 'D');\n\t\t}\n\t\tforeach (col; 0..cols - 1)\n\t\t{\n\t\t\tres += (board[rows - 1][col] != 'R');\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "409073ef839a7d0cdb900c06ee4a841c"} {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\nimport std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int n;\r\n while(readf!\"%s\\n\"(n)> 0) {\r\n auto adj = new bool[int][n];\r\n int[] ask(int v) {\r\n writefln!\"? %s\"(v + 1);\r\n stdout.flush();\r\n auto input = readln.splitter.map!(to!int).array;\r\n foreach(i; 0 .. n) {\r\n if (input[i] == 1) {\r\n adj[v][i] = true;\r\n adj[i][v] = true;\r\n }\r\n }\r\n return input;\r\n }\r\n auto d = ask(0);\r\n auto odds = iota(1, n).filter!(i => (d[i] & 1) == 1).array;\r\n auto evens = iota(1, n).filter!(i => (d[i] & 1) == 0).array;\r\n auto list = (odds.length < evens.length) ? odds : evens;\r\n foreach (ref v; list) {\r\n ask(v);\r\n }\r\n writeln(\"!\");\r\n foreach(i; 0 .. n) {\r\n foreach(j, _; adj[i]) {\r\n if(j > i) {\r\n writefln!\"%s %s\\n\"(i + 1, j + 1);\r\n }\r\n }\r\n }\r\n stdout.flush();\r\n }\r\n\r\n} // main", "positive_code": [{"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport std.container;\n\nvoid main()\n{\n\tint n = readInt!int;\n\tauto edges = new RedBlackTree!(Tuple!(int, int))();\n\tint[] query(int r)\n\t{\n\t\tdebug writeln(\"asking for \", r);\n\t\tr += 1;\n\t\twriteln(\"? \", r);\n\t\tstdout.flush;\n\t\tint[] ans = new int[](n);\n\t\tforeach(ref ansi; ans) ansi = readInt!int;\n\t\treturn ans;\n\t}\n\tvoid addEdges(int r, int[] dist)\n\t{\n\t\tforeach(i, disti; dist) \n\t\t\tif (disti == 1) \n\t\t\t{\n\t\t\t\tdebug writeln(\"dist \", r, \" -> \", i);\n\t\t\t\tauto mn = min(cast(int)i, r);\n\t\t\t\tauto mx = max(cast(int)i, r);\n\t\t\t\tedges.insert(tuple(mn, mx));\n\n\t\t\t}\n\t}\n\tauto dist0 = query(0);\n\taddEdges(0, dist0);\n\tint[2] cnt;\n\tforeach(di; dist0)\n\t{\n\t\tif (di >= 1)\n\t\t{\n\t\t\tcnt[di%2]++;\n\t\t}\n\t}\n\tint s = 0;\n\tif (cnt[1] < cnt[0]) s = 1;\n\tforeach(i, di; dist0)\n\t{\n\t\tif (di >= 1 && di % 2 == s)\n\t\t{\n\t\t\taddEdges(cast(int)i, query(cast(int)i));\n\t\t}\n\t}\n\twriteln(\"!\");\n\tforeach(edge; edges)\n\t{\n\t\twriteln(edge[0] + 1, \" \", edge[1] + 1);\n\t}\n\twriteln;\n\tstdout.flush;\n}\n\n/* INPUT ROUTINES */\nstatic import core.stdc.stdio;\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = core.stdc.stdio.getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\r\n\t\tauto adj = new bool [int] [n];\r\n\r\n\t\tint [] ask (int v)\r\n\t\t{\r\n\t\t\twriteln (\"? \", v + 1);\r\n\t\t\tstdout.flush ();\r\n\r\n\t\t\tauto res = readln.splitter.map !(to !(int)).array;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (res[i] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tadj[v][i] = true;\r\n\t\t\t\t\tadj[i][v] = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tauto d = ask (0);\r\n\t\tauto odds = iota (1, n).filter !(i => (d[i] & 1) == 1).array;\r\n\t\tauto evens = iota (1, n).filter !(i => (d[i] & 1) == 0).array;\r\n\t\tauto list = (odds.length < evens.length) ? odds : evens;\r\n\t\tforeach (ref v; list)\r\n\t\t{\r\n\t\t\task (v);\r\n\t\t}\r\n\r\n\t\twriteln (\"!\");\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j, _; adj[i])\r\n\t\t\t{\r\n\t\t\t\tif (j > i)\r\n\t\t\t\t{\r\n\t\t\t\t\twriteln (i + 1, \" \", j + 1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "5dbafdd7c4e93b2c01122fa80ef42f0e"} {"source_code": "// cheese-cracker [2022-05-03]\n\nint[] pals;\nlong[] dp;\nconst long MOD = 1_000_000_007;\n\nbool check_pal(int m){\n int[] wval;\n while(m > 0){\n wval ~= (m % 10);\n m /= 10;\n }\n int[] rev = wval.dup.reverse;\n return (wval == rev);\n}\n\n\nvoid preprocess(){\n int N = 50_000;\n for(int m = 1; m < N; ++m){\n if(check_pal(m)){\n pals ~= m;\n }\n }\n dp = new long[](N); \n dp[0] = 1;\n foreach(k; pals){\n for(int m = k; m < N; ++m){\n dp[m] += dp[m - k];\n dp[m] %= MOD;\n }\n }\n}\n\nvoid solve(){\n writeln(dp[scan!int]);\n}\n\nvoid main(){\n preprocess;\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n enum MAX = 4 * 10^^4 + 10;\r\n\r\n auto solve() {\r\n int[] palindromicNumbers(int limit) {\r\n int [] ret;\r\n foreach(i; 1..limit) {\r\n auto s = i.to!string;\r\n auto r = (cast(char[])s.dup).reverse.array.to!string;\r\n if (s == r) ret ~= i;\r\n }\r\n\r\n return ret;\r\n }\r\n\r\n auto dp = new MInt1[](MAX + 1);\r\n dp[0] = 1;\r\n foreach(p; palindromicNumbers(MAX)) {\r\n foreach(from; 0..MAX - p + 1) {\r\n dp[from + p] += dp[from];\r\n }\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n auto N = scan!int;\r\n dp[N].writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "negative_code": [], "src_uid": "529d4ab0bdbb29d8b7f3d3eed19eca63"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable LIM = 2_000_000;\n\nint N;\nlong K;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = readInt;\n\t\t\n\t\twriteln(K * (6 * N - 1));\n\t\tforeach (i; 0 .. N) {\n\t\t\twriteln(\n\t\t\t\tK * (6 * i + 1), \" \", \n\t\t\t\tK * (6 * i + 2), \" \", \n\t\t\t\tK * (6 * i + 3), \" \", \n\t\t\t\tK * (6 * i + 5)\n\t\t\t);\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nint fun (int i, int x, int k) {return (i * 6 + x) * k;}\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\twriteln ((n * 6 - 1) * k);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twriteln ((i * 6 + 1) * k, ' ',\n\t\t\t(i * 6 + 2) * k, ' ',\n\t\t\t(i * 6 + 3) * k, ' ',\n\t\t\t(i * 6 + 5) * k);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "5e7b4d1e11628152e33d3e18e30f4530"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nauto vp (const ref Point a, const ref Point b,\n const ref Point c, const ref Point d)\n{\n\treturn (b.x - a.x) * 1L * (d.y - c.y) - (b.y - a.y) * 1L * (d.x - c.x);\n}\n\nauto rho2 (const ref Point a, const ref Point b)\n{\n\treturn (b.x - a.x) * 1L * (b.x - a.x) + (b.y - a.y) * 1L * (b.y - a.y);\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto p = new Point [n];\n\t\tforeach (ref c; p)\n\t\t{\n\t\t\treadf !(\" %s %s\") (c.x, c.y);\n\t\t}\n\t\tp ~= p;\n\n\t\tbool ok = true;\n\t\tint j = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tj = max (j, i + 1);\n\t\t\twhile (j < i + n &&\n\t\t\t vp (p[i], p[i + 1], p[j], p[j + 1]) > 0)\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\tif (!(j < i + n &&\n\t\t\t vp (p[i], p[i + 1], p[j], p[j + 1]) == 0 &&\n\t\t\t rho2 (p[i], p[i + 1]) == rho2 (p[j], p[j + 1])))\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto xy = new int[][](n);\n\tforeach (i; 0..n)\n\t{\n\t\txy[i] = [RD!int, RD!int];\n\t}\n\n\tif (n % 2 == 1)\n\t{\n\t\twriteln(\"NO\");\n\t}\n\telse\n\t{\n\t\tint[][] vec;\n\t\tforeach (i; 1..n/2+1)\n\t\t{\n\t\t\tint[] t = xy[i].dup;\n\t\t\tt[] -= xy[i-1][];\n\t\t\tvec ~= t;\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (i; n/2..n)\n\t\t{\n\t\t\tint[] t = xy[(i+1)%n].dup;\n\t\t\tt[] -= xy[i][];\n\t\t\tt = [-t[0], -t[1]];\n\t\t\tif ((vec[i-n/2][0] != t[0]) || (vec[i-n/2][1] != t[1]))\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\twriteln(ok ? \"YES\" : \"NO\");\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tP[] ps;\n\tforeach(i; 0 .. n) ps ~= P(rlong, rlong);\n\t\n\tif(n % 2 != 0){\n\t\t\"NO\".writeln;\n\t\treturn;\n\t}\n\n\tP[] vs;\n\tforeach(i; 0 .. n - 1) vs ~= P(ps[i].x - ps[i + 1].x, ps[i].y - ps[i + 1].y);\n\tvs ~= P(ps[n - 1].x - ps[0].x, ps[n - 1].y - ps[0].y);\n\n\tforeach(i; 0 .. n / 2){\n\t\tP u = vs[i], v = vs[i + n / 2];\n\t\tif(u.x + v.x != 0 || u.y + v.y != 0){\n\t\t\t\"NO\".writeln;\n\t\t\treturn;\n\t\t}\n\t}\n\n\t\"YES\".writeln;\n\treturn;\n\n}\nstruct P{\n\tlong x, y;\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto X = new long[N];\n auto Y = new long[N];\n foreach (i; 0 .. N) {\n X[i] = readLong();\n Y[i] = readLong();\n }\n \n bool ans;\n if (N % 2 == 0) {\n auto dx = new long[N];\n auto dy = new long[N];\n foreach (i; 0 .. N) {\n dx[i] = X[(i + 1) % N] - X[i];\n dy[i] = Y[(i + 1) % N] - Y[i];\n }\n ans = true;\n foreach (i; 0 .. N / 2) {\n ans = ans && (-dx[i] == dx[i + N / 2]);\n ans = ans && (-dy[i] == dy[i + N / 2]);\n }\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "424f37abd0e19208e6b0cb8b670e7187"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tif (a[n-1] == 0)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n+1)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (a[0] == 1)\r\n\t\t{\r\n\t\t\tans[ti] ~= n+1;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tint pos = -1;\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tif (a[i] == 0 && a[i+1] == 1)\r\n\t\t\t{\r\n\t\t\t\tpos = i;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (pos == -1)\r\n\t\t\tcontinue;\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (i; 0..pos+1)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t\tans[ti] ~= n+1;\r\n\t\t\tforeach (i; pos+1..n)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tif (e.empty)\r\n\t\t\twriteln(-1);\r\n\t\telse\r\n\t\t\te.map!(to!string).join(\" \").writeln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "\nimmutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto a = ma(n, readInt!int);\n\tif (a[0] == 1)\n\t{\n\t\twrite(n + 1, \" \");\n\t\tforeach(i; 1 .. n + 1) write(i, \" \");\n\t\twriteln;\n\t\treturn;\n\t}\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (a[i] == 0)\n\t\t{\n\t\t\tif (i+1 >= n || a[i+1] == 1)\n\t\t\t{\n\t\t\t\tforeach(j; 1 .. i + 2)\n\t\t\t\t{\n\t\t\t\t\twrite(j, \" \");\n\t\t\t\t}\n\t\t\t\twrite(n + 1, \" \");\n\t\t\t\tforeach(j; i + 2 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\twrite(j, \" \");\n\t\t\t\t}\n\t\t\t\twriteln;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\twriteln(-1);\n\treturn;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tif (a[n-1] == 0)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n+1)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tint pos = -1;\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tif (a[i] == 0 && a[i+1] == 1)\r\n\t\t\t{\r\n\t\t\t\tpos = i;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (pos == -1)\r\n\t\t\tcontinue;\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (i; 0..pos+1)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t\tans[ti] ~= n+1;\r\n\t\t\tforeach (i; pos+1..n)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tif (e.empty)\r\n\t\t\twriteln(-1);\r\n\t\telse\r\n\t\t\te.map!(to!string).join(\" \").writeln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tif (a[n-1] == 0)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n+1)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tint pos = -1;\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tif (a[i] == 0 && a[i+1] == 1)\r\n\t\t\t{\r\n\t\t\t\tpos = i;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (pos == -1)\r\n\t\t\tcontinue;\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (i; 0..pos+1)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t\tans[ti] ~= n+1;\r\n\t\t\tforeach (i; pos+1..n)\r\n\t\t\t\tans[ti] ~= i+1;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "3f9525d74f4934eb9dca1b16c53662bf"} {"source_code": "import std.stdio, std.math, std.algorithm;\n\nvoid main()\n{\n int n, a;\n readf(\"%d %d\", &n, &a);\n \n writeln(2, \" \", 1, \" \", min(n, max(3, 2+round(a*n/180.))));\n}", "positive_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^9 + 7;\n\nint n, a;\n\nvoid main() {\n scan(n, a);\n\n int dif = inf;\n int mk;\n\n foreach (k ; 1 .. n - 1) {\n if (dif > abs(a*n - 180*k)) {\n dif = abs(a*n - 180*k);\n mk = k;\n }\n }\n\n writefln(\"%s %s %s\", 1, 2, n + 1 - mk);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.math, std.algorithm;\n\nvoid main()\n{\n int n, a;\n readf(\"%d %d\", &n, &a);\n \n writeln(2, \" \", 1, \" \", 2+max(1, round(a*n/180.)));\n}"}], "src_uid": "3cdd85f86c77afd1d3b0d1e951a83635"} {"source_code": "module _;\n\timport std.stdio;\nauto gfilter(R)(int a, int b, int exp, R i) {\n\tdebug writeln(i, i[a]*i[b],\" \",exp);\n\treturn i[a] * i[b] == exp;\n}\n\nvoid main() {\n\timport std.algorithm : permutations, map, fold, maxElement, filter;\n\timport std.array : array;\n\tauto cand = [4, 8, 16, 15, 23, 42].permutations.map!\"a.array\".array;\n\tforeach(it; 0..4) {\n\t\tint best = int.max, ba, bb;\n\t\tforeach(a; 0..6) {\n\t\t\tforeach(b; a..6) {\n\t\t\t\tauto res = cand.map!(i => i[a] * i[b]);\n\t\t\t\tint[int] cnt;\n\t\t\t\tforeach(r; res){\n\t\t\t\t\tcnt[r]++;\n\t\t\t\t}\n\t\t\t\tint m = cnt.byValue.maxElement;\n\t\t\t\tif (m < best) {\n\t\t\t\t\tbest = m;\n\t\t\t\t\tba = a;\n\t\t\t\t\tbb = b;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twritefln(\"? %s %s\", ba+1, bb+1);\n\t\tstdout.flush();\n\t\tint exp;\n\t\treadf(\" %s\", &exp);\n\t\tif (!exp) {\n\t\t\treturn;\n\t\t}\n\t\tcand = cand.filter!(a => gfilter(ba, bb, exp, a)).array;\n\t\tdebug writeln(cand);\n\t}\n\tif (cand.length != 1) {\n\t\tassert(false);\n\t}\n\twritefln(\"! %(%s %)\", cand[0]);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tbool[long] numbers = [4:true, 8:true, 15:true, 16:true, 23:true, 42:true];\n\tlong[] ans;\n\tforeach (i; 0..2)\n\t{\n\t\twriteln(\"? \", i*3+1, \" \", i*3+2);\n\t\tstdout.flush();\n\t\tauto x1 = RD;\n\t\twriteln(\"? \", i*3+2, \" \", i*3+3);\n\t\tstdout.flush();\n\t\tauto x2 = RD;\n\n\t\tforeach (num; numbers.keys)\n\t\t{\n\t\t\tif (x1 % num == 0 && x2 % num == 0)\n\t\t\t{\n\t\t\t\tauto y1 = x1 / num;\n\t\t\t\tauto y2 = x2 / num;\n\t\t\t\tbool ok1, ok2;\n\t\t\t\tforeach (num2; numbers.keys)\n\t\t\t\t{\n\t\t\t\t\tif (num2 == num) continue;\n\t\t\t\t\tif (num2 == y1)\n\t\t\t\t\t\tok1 = true;\n\t\t\t\t\tif (num2 == y2)\n\t\t\t\t\t\tok2 = true;\n\t\t\t\t}\n\t\t\t\tif (ok1 && ok2)\n\t\t\t\t{\n\t\t\t\t\tans ~= [y1, num, y2];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\twrite(\"! \");\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto X = new int[](6);\n foreach (i; 0..4) {\n writeln(\"? \", i+1, \" \", i+2);\n stdout.flush;\n X[i] = readln.chomp.to!int;\n }\n\n int[] A = [4, 8, 15, 16, 23, 42];\n do {\n bool ok = true;\n foreach (i; 0..4) {\n if (A[i] * A[i+1] != X[i]) {\n ok = false;\n break;\n }\n }\n if (ok) {\n writeln(\"! \", A.map!(to!string).join(\" \"));\n return;\n }\n } while (nextPermutation(A));\n}"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\twriteln(\"? 1 2\");\n\tstdout.flush;\n\tlong a12 = read.to!long;\n\t\n\twriteln(\"? 1 3\");\n\tstdout.flush;\n\tlong a13 = read.to!long;\n\t\n\twriteln(\"? 1 4\");\n\tstdout.flush;\n\tlong a14 = read.to!long;\n\t\n\twriteln(\"? 1 5\");\n\tstdout.flush;\n\tlong a15 = read.to!long;\n\t\n\tlong a1 = -1, a2 = -1, a3 = -1, a4 = -1, a5 = -1, a6 = -1;\n\t\n\tif(a12 % 23 == 0){\n\t\tif(a13 % 23 == 0) a1 = 23;\n\t\telse a2 = 23;\n\t}\n\telse if(a13 % 23 == 0) a3 = 23;\n\telse if(a14 % 23 == 0) a4 = 23;\n\telse if(a15 % 23 == 0) a5 = 23;\n\telse a6 = 23;\n\t\n\tif(a12 % 5 == 0){\n\t\tif(a13 % 5 == 0) a1 = 15;\n\t\telse a2 = 15;\n\t}\n\telse if(a13 % 5 == 0) a3 = 15;\n\telse if(a14 % 5 == 0) a4 = 15;\n\telse if(a15 % 5 == 0) a5 = 15;\n\telse a6 = 15;\n\t\n\tif(a2 > 0) a1 = a12 / a2;\n\tif(a3 > 0) a1 = a13 / a3;\n\tif(a4 > 0) a1 = a14 / a4;\n\tif(a5 > 0) a1 = a15 / a5;\n\t\n\tif(a2 < 0) a2 = a12 / a1;\n\tif(a3 < 0) a3 = a13 / a1;\n\tif(a4 < 0) a4 = a14 / a1;\n\tif(a5 < 0) a5 = a15 / a1;\n\ta6 = (4 + 8 + 15 + 16 + 23 + 42) - (a1 + a2 + a3 + a4 + a5);\n\t\n\twriteln(\"! \", a1, \" \", a2, \" \", a3, \" \", a4, \" \", a5, \" \", a6);\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tbool[long] numbers = [4:true, 8:true, 15:true, 16:true, 23:true, 42:true];\n\tlong[] ans;\n\tforeach (i; 0..2)\n\t{\n\t\twriteln(\"? \", i*3+1, \" \", i*3+2);\n\t\tstdout.flush();\n\t\tauto x1 = RD;\n\t\twriteln(\"? \", i*3+2, \" \", i*3+3);\n\t\tstdout.flush();\n\t\tauto x2 = RD;\n\t\tlong[2] pair;\n\t\t(){\n\t\tforeach (num; numbers.keys)\n\t\t{\n\t\t\tif (x1 % num == 0)\n\t\t\t{\n\t\t\t\tauto y = x1 / num;\n\t\t\t\tforeach (num2; numbers.keys)\n\t\t\t\t{\n\t\t\t\t\tif (num2 == y)\n\t\t\t\t\t{\n\t\t\t\t\t\tpair = [num, num2];\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}}();\n\n\t\tif (x2 % pair[0] == 0 && numbers.get(x2/pair[0], false))\n\t\t{\n\t\t\tans ~= [pair[1], pair[0], x2/pair[0]];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans ~= [pair[0], pair[1], x2/pair[1]];\n\t\t}\n\t}\n\n\twrite(\"! \");\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tbool[long] numbers = [4:true, 8:true, 15:true, 16:true, 23:true, 42:true];\n\tlong[] ans;\n\tforeach (i; 0..2)\n\t{\n\t\twriteln(\"? \", i*3+1, \" \", i*3+2);\n\t\tstdout.flush();\n\t\tauto x1 = RD;\n\t\twriteln(\"? \", i*3+2, \" \", i*3+3);\n\t\tstdout.flush();\n\t\tauto x2 = RD;\n\n\t\tforeach (num; numbers.keys)\n\t\t{\n\t\t\tif (x1 % num == 0 && x2 % num == 0)\n\t\t\t{\n\t\t\t\tauto y1 = x1 / num;\n\t\t\t\tauto y2 = x2 / num;\n\t\t\t\tbool ok1, ok2;\n\t\t\t\tforeach (num2; numbers.keys)\n\t\t\t\t{\n\t\t\t\t\tif (num2 == y1)\n\t\t\t\t\t\tok1 = true;\n\t\t\t\t\tif (num2 == y2)\n\t\t\t\t\t\tok2 = true;\n\t\t\t\t}\n\t\t\t\tif (ok1 && ok2)\n\t\t\t\t{\n\t\t\t\t\tans ~= [y1, num, y2];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\twrite(\"! \");\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tlong[] numbers = [4, 8, 15, 16, 23, 42];\n\tlong[] ans;\n\tforeach (i; 0..2)\n\t{\n\t\twriteln(\"? \", i*3+1, \" \", i*3+2);\n\t\tstdout.flush();\n\t\tauto x1 = RD;\n\t\twriteln(\"? \", i*3+2, \" \", i*3+3);\n\t\tstdout.flush();\n\t\tauto x2 = RD;\n\t\tlong[2] pair;\n\t\t(){\n\t\tforeach (num; numbers)\n\t\t{\n\t\t\tif (x1 % num == 0)\n\t\t\t{\n\t\t\t\tauto y = x1 / num;\n\t\t\t\tforeach (num2; numbers)\n\t\t\t\t{\n\t\t\t\t\tif (num2 == y)\n\t\t\t\t\t{\n\t\t\t\t\t\tpair = [num, num2];\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}}();\n\n\t\tif (x2 % pair[0] == 0)\n\t\t{\n\t\t\tans ~= [pair[1], pair[0], x2/pair[0]];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans ~= [pair[0], pair[1], x2/pair[1]];\n\t\t}\n\t}\n\n\twrite(\"! \");\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "c0f79d7ebcecc4eb7d07c372ba9be802"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tauto adj = new int [] [n];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tadj[u] ~= v;\n\t\t\tadj[v] ~= u;\n\t\t}\n\t\treadln;\n\t\tauto t = readln.splitter.map !(to !(int)).array;\n\n\t\tauto p = n.iota.array;\n\t\tp.schwartzSort !(x => t[x]);\n\n\t\tbool ok = true;\n\t\tforeach (i, v; p)\n\t\t{\n\t\t\tbool [int] used;\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tif (t[u] == t[v])\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t\telse if (t[u] < t[v])\n\t\t\t\t{\n\t\t\t\t\tused[t[u]] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tok &= (used.length == t[v] - 1);\n\t\t}\n\n\t\tif (ok)\n\t\t{\n\t\t\twritefln !(\"%(%s %)\") (p.map !(q{a + 1}));\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto g = new int[][] (n+1);\n \n foreach (_; m.iota) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto groups = new int[][] (n+1);\n \n foreach (i, e; arr) { groups[e] ~= i.to!int; }\n \n int[] ans;\n int[] need;\n foreach (gridx, gr; groups.dropOne.enumerate(1)) {\n foreach (e; gr) {\n auto connected = g[e]\n .map!(v => arr[v]).filter!(v => v <= gridx).array\n .sort.uniq.array;\n \n bool isOk = connected == need;\n \n if (!isOk) {\n debug { writeln(gridx, ' ', e, ' ', ' ', g[e], ' ', connected); }\n writeln(-1);\n return;\n }\n \n ans ~= e;\n }\n \n need ~= gridx;\n }\n \n ans.map!(x => x+1).map!(to!string).join(\" \").writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto g = new int[][] (n+1);\n \n foreach (_; m.iota) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto groups = new int[][] (n+1);\n \n foreach (i, e; arr) { groups[e] ~= i.to!int; }\n \n int[] ans;\n foreach (gridx, gr; groups.dropOne.enumerate(1)) {\n foreach (e; gr) {\n bool isOk = true;\n \n auto vals = g[e].map!(v => arr[v]).array;\n auto connected = make!(RedBlackTree!int)(vals);\n \n isOk &= (gridx.to!int !in connected);\n \n foreach (i; 1 .. gridx) { isOk &= i.to!int in connected; }\n \n if (!isOk) {\n debug { writeln(gridx, ' ', e, ' ', ' ', g[e], ' ', connected); }\n writeln(-1);\n return;\n }\n \n ans ~= e;\n }\n }\n \n ans.map!(x => x+1).map!(to!string).join(\" \").writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto g = new int[][] (n+1);\n \n foreach (_; m.iota) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto groups = new int[][] (n+1);\n \n foreach (i, e; arr) { groups[e] ~= i.to!int; }\n \n int[] ans;\n foreach (gridx, gr; groups.dropOne.enumerate(1)) {\n foreach (e; gr) {\n auto vals = g[e].map!(v => arr[v]).filter!(v => v <= gridx).array;\n auto connected = make!(RedBlackTree!int)(vals);\n \n bool isOk = connected[].array == gridx.iota.dropOne.array;\n \n if (!isOk) {\n debug { writeln(gridx, ' ', e, ' ', ' ', g[e], ' ', connected); }\n writeln(-1);\n return;\n }\n \n ans ~= e;\n }\n }\n \n ans.map!(x => x+1).map!(to!string).join(\" \").writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto g = new int[][] (n+1);\n \n foreach (_; m.iota) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto groups = new int[][] (n+1);\n \n foreach (i, e; arr) { groups[e] ~= i.to!int; }\n \n int[] ans;\n foreach (gridx, gr; groups.dropOne.enumerate(1)) {\n foreach (e; gr) {\n auto connected = g[e]\n .map!(v => arr[v]).filter!(v => v <= gridx).array\n .sort.uniq.array;\n \n bool isOk = connected == gridx.iota.dropOne.array;\n \n if (!isOk) {\n debug { writeln(gridx, ' ', e, ' ', ' ', g[e], ' ', connected); }\n writeln(-1);\n return;\n }\n \n ans ~= e;\n }\n }\n \n ans.map!(x => x+1).map!(to!string).join(\" \").writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto edges = new int[][](n);\n\tforeach (i; 0..m)\n\t{\n\t\tauto a = RD!int-1;\n\t\tauto b = RD!int-1;\n\t\tedges[a] ~= b;\n\t\tedges[b] ~= a;\n\t}\n\tauto p = RDA!int;\n\n\tauto ans = new int[](n);\n\tauto index = p.MAKE_IDX();\n\tforeach (ii, i; index)\n\t{\n\t\tauto num = p[i];\n\t\tauto used = new bool[](num);\n\t\tforeach (to; edges[i])\n\t\t{\n\t\t\tauto num2 = p[to];\n\t\t\tif (num2 > num) continue;\n\t\t\tused[num2-1] = true;\n\t\t}\n\t\tbool ok = used[$-1] == false;\n\t\tif (ok)\n\t\t{\n\t\t\tforeach (j; 0..num-1)\n\t\t\t{\n\t\t\t\tif (!used[j])\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (ok)\n\t\t{\n\t\t\tans[ii] = cast(int)(i+1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans.length = 0;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (ans.empty)\n\t\twriteln(-1);\n\telse\n\t\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto g = new int[][] (n+1);\n \n foreach (_; m.iota) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto groups = new int[][] (n+1);\n \n foreach (i, e; arr) { groups[e] ~= i.to!int; }\n \n int[] ans;\n foreach (gridx, gr; groups.dropOne.enumerate(1)) {\n foreach (e; gr) {\n bool isOk = true;\n \n auto vals = g[e].map!(v => arr[v]).array;\n auto connected = make!(RedBlackTree!int)(vals);\n \n foreach (i, c; connected[].enumerate(1)) {\n if (c == gridx + 1) { break; }\n \n if (i != c) { isOk = false; }\n if (c == gridx) { isOk = false; }\n }\n \n if (!isOk) {\n debug { writeln(gridx, ' ', e, ' ', ' ', g[e], ' ', connected); }\n writeln(-1);\n return;\n }\n \n ans ~= e;\n }\n }\n \n ans.map!(x => x+1).map!(to!string).join(\" \").writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto g = new int[][] (n+1);\n \n foreach (_; m.iota) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto groups = new int[][] (n+1);\n \n foreach (i, e; arr) { groups[e] ~= i.to!int; }\n \n int[] ans;\n foreach (gridx, gr; groups.dropOne.enumerate(1)) {\n foreach (e; gr) {\n bool isOk = true;\n \n auto vals = g[e].map!(v => arr[v]).filter!(v => v <= gridx).array;\n auto connected = make!(RedBlackTree!int)(vals);\n \n foreach (i, c; connected[].enumerate(1)) {\n if (i != c) { isOk = false; }\n if (c == gridx) { isOk = false; }\n }\n \n if (!isOk) {\n debug { writeln(gridx, ' ', e, ' ', ' ', g[e], ' ', connected); }\n writeln(-1);\n return;\n }\n \n ans ~= e;\n }\n }\n \n ans.map!(x => x+1).map!(to!string).join(\" \").writeln;\n}"}], "src_uid": "f9c6ef39752d1da779e07c27dff918a9"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint, k = rint;\n\n\tint[int] cnt;\n\tlong[int] vm;\n\tforeach(i; 0 .. k + 1){\n\t\tint[] js;\n\t\tforeach(j; 0 .. k + 1) if(j != i) js ~= j;\n\t\tS s = ask(js);\n\t\tvm[s.pos] = s.value;\n\t\tif(s.pos !in cnt) cnt[s.pos] = 0;\n\t\tcnt[s.pos] += 1;\n\t}\n\n\tint[] ks = cnt.keys;\n\tint a = ks[0], b = ks[1];\n\tif(vm[a] < vm[b]) answer(cnt[b]);\n\telse answer(cnt[a]);\n\n}\nstruct S{\n\tint pos;\n\tlong value;\n}\nS ask(int[] js){\n\twriteln(\"? \", js.map!(x => (x + 1).to!string).array.join(\" \"));\n\tstdout.flush;\n\treturn S(rint, rlong);\n}\nvoid answer(int ans){\n\twriteln(\"! \", ans);\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.range : iota;\n\nvoid main() {\n int n, k;\n readf!\"%d %d\\n\"(n, k);\n\n auto a = iota(1, k+2).array;\n\n auto b1 = -1, b2 = -1;\n auto c1 = 0, c2 = 0;\n\n // make k+1 queries, omitting i in each\n foreach (i; 0..k+1) {\n auto x = a[0..i] ~ a[i+1..$];\n\n // write query string\n write(\"? \");\n foreach (e; x) {\n writef(\"%d \", e);\n }\n writeln;\n stdout.flush;\n\n // read response\n int pos, b;\n readf!\"%d %d\\n\"(pos, b);\n\n if (b1 == -1) {\n b1 = b;\n } else if (b2 == -1 && b1 != b) {\n b2 = b;\n }\n\n if (b1 == b) {\n c1++;\n } else {\n c2++;\n }\n }\n\n // there'll be m occurrences of the larger element\n // and k + 1 - m of the smaller\n writefln(\"! %d\\n\", b1 > b2 ? c1 : c2);\n}\n"}], "negative_code": [], "src_uid": "712bef1b0f737cb9c2b35a96498d50bc"} {"source_code": "import std.stdio, std.string;\r\nimport std.random, std.algorithm;\r\nimport std.numeric, std.math;\r\nimport std.range, std.array;\r\nimport std.typecons, std.conv;\r\n \r\nint[] solve(int[] a)\r\n{\r\n auto n = to!int(a.length);\r\n const int m = 512;\r\n auto pdp = new bool[m];\r\n auto ndp = new bool[m];\r\n auto mi = new int[m];\r\n fill(mi, int.max);\r\n mi[0] = 0;\r\n pdp[0] = true;\r\n foreach (i; 0 .. n)\r\n {\r\n fill(ndp, false);\r\n foreach (j; 0 .. m) if (pdp[j])\r\n {\r\n ndp[j] = true;\r\n if (mi[j] < a[i])\r\n {\r\n ndp[j ^ a[i]] = true;\r\n mi[j ^ a[i]] = min(mi[j ^ a[i]], a[i]);\r\n }\r\n }\r\n ndp.copy(pdp);\r\n }\r\n int[] res;\r\n foreach (i; 0 .. m) if (pdp[i]) res ~= i;\r\n return res;\r\n}\r\n\r\nint main(string[] args)\r\n{\r\n readln;\r\n auto a = map!(to!int)(readln.strip.split(\" \")).array;\r\n auto ret = solve(a);\r\n writeln(ret.length);\r\n writeln(join(map!(to!string)(ret), \" \"));\r\n return 0;\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\n\tauto dp = new long[](2^^9);\n\tdp[] = long.max;\n\tdp[0] = 0;\n\tforeach (i; 0..n)\n\t{\n\t\tauto ndp = dp.dup;\n\t\tforeach (j; 0..2^^9)\n\t\t{\n\t\t\tif (dp[j] >= a[i]) continue;\n\t\t\tauto nj = j ^ a[i];\n\t\t\tndp[nj].chmin(a[i]);\n\t\t\tdebug writeln(\"j:\", j, \" nj:\", nj);\n\t\t}\n\t\tdp = ndp;\n\t\tdebug\n\t\t{\n\t\t\tforeach (j; 0..20)\n\t\t\t{\n\t\t\t\tif (dp[j])\n\t\t\t\t\twrite(\" \", j);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t}\n\n\tlong[] ans;\n\tforeach (i; 0..2^^9)\n\t{\n\t\tif (dp[i] != long.max)\n\t\t\tans ~= i;\n\t}\n\n\twriteln(ans.length);\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\r\nimport std.random, std.algorithm;\r\nimport std.numeric, std.math;\r\nimport std.range, std.array;\r\nimport std.typecons, std.conv;\r\n \r\nint[] solve(int[] a)\r\n{\r\n auto n = to!int(a.length);\r\n const int m = 512;\r\n auto pdp = new bool[m];\r\n auto ndp = new bool[m];\r\n auto mi = new int[m];\r\n fill(mi, int.max);\r\n mi[0] = 0;\r\n pdp[0] = true;\r\n foreach (i; 0 .. n)\r\n {\r\n fill(ndp, false);\r\n foreach (j; 0 .. m) if (pdp[j])\r\n {\r\n ndp[j] = true;\r\n if (mi[j] < a[i])\r\n {\r\n ndp[j ^ a[i]] = true;\r\n mi[j ^ a[i]] = min(mi[j ^ a[i]], a[i]);\r\n }\r\n }\r\n ndp.copy(pdp);\r\n }\r\n int[] res;\r\n foreach (i; 0 .. m) if (pdp[i]) res ~= i;\r\n return res;\r\n}\r\n\r\nint main(string[] args)\r\n{\r\n readln;\r\n auto a = map!(to!int)(readln.strip.split(\" \")).array;\r\n auto ret = solve(a);\r\n writeln(join(map!(to!string)(ret), \" \"));\r\n return 0;\r\n}"}], "src_uid": "6057052f1eb001da04e3415001cce228"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\nimport std.regex;\n\nvoid main() {\n readln;\n\n int ans = 0;\n\n foreach (string line; stdin.lines) {\n if (!match(line, regex(`\\+\\+`)).empty) {\n ans++;\n } else {\n ans--;\n }\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int x=0;\n int n=readln.chomp.to!int;\n string s;\n while(n--){\n s=readln.strip;\n if(s[0]=='+'||s[2]=='+')\n x++;\n else x--;\n }\n writeln(x);\n}\n\n"}, {"source_code": "module Solution;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n immutable n = readln.chomp.to!int;\n immutable p = stdin.byLine.take(n).count! (s => s[1] == '+').to!int;\n writeln (p - (n - p));\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.conv:to;\nimport std.string:chomp, countchars;\n\nvoid main() {\n int num = to!int(chomp(stdin.readln()));\n int res;\n foreach (a; 0..num) {\n string buf = chomp(stdin.readln());\n res += buf.countchars(\"+\");\n }\n writeln(res-num);\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\nvoid main(){\n int X;\n int n = readln.chomp.to!int;\n foreach(i; 0..n){\n if(readln.chomp.find(\"+\").length) X++;\n else X--;\n }\n X.writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main()\n{\n readln;\n int x;\n foreach(line; stdin.byLine)\n {\n if(line.any!(a => a=='-')) --x;\n else ++x;\n }\n \n x.writeln;\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n;\n readf(\"%d\\n\", &n);\n\n int result = 0;\n for (int i = 0; i < n; ++i) {\n string s = readln();\n\n if (s[0] == '+' || s[1] == '+') {\n result++;\n } else {\n result--;\n }\n }\n\n writefln(\"%d\", result);\n}"}, {"source_code": "import std.stdio, std.string;\n\nvoid main()\n{\n int n, x = 0;\n \n readf(\"%s\\n\", &n);\n \n while(--n >= 0) {\n string str;\n readf(\"%s\\n\", &str);\n if(str.indexOf(\"+\") != -1){ ++x; } else { --x; }\n }\n \n writeln(x);\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\tint count;\n\tint x;\n\treadf(\"%s\",&count);\n\treadln();\n\t\n\tstring[] ops;\n\tfor (int i=0; i<count; i++){\n\t\tops ~= readln();\n\t}\n\n\tfor (int i=0; i<count; i++){\n\t\tif (ops[i].canFind(\"++\")) {\n\t\t\tx++;\n\t\t}\n\t\tif (ops[i].canFind(\"--\")) {\n\t\t\tx--;\n\t\t}\n\t}\n\n\t/* for (int i=0; i<count; i++){ */\n\t/* \twriteln(\"$$\" ~ ops[i]); */\n\t/* } */\n\twriteln(x);\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport core.stdc.stdio;\nimport std.string;\n\nint main(string[] argv)\n{\n\tint n;\n\tstring line;\n\tint x = 0;\n\tscanf(\"%d\", &n);\n\tline = std.stdio.stdin.readln();\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tline = std.stdio.stdin.readln();\n\t\tif (indexOf(line, \"++\") != -1)\n\t\t{\n\t\t\tx++;\n\t\t} else\n\t\tif (indexOf(line, \"--\") != -1)\n\t\t{\n\t\t\tx--;\n\t\t}\n\t}\n\tprintf(\"%d\", x);\n\treturn 0;\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/282/A \nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n readln;\n int answer = 0;\n foreach(line; stdin.byLine)\n if(canFind(line,\"++\"))\n answer++;\n else\n answer--;\n answer.writeln;\n}\n\n"}], "negative_code": [{"source_code": "module Solution;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n immutable n = readln.chomp.to!int;\n immutable p = stdin.byLine.take(n).count! (s => s[1] == '+');\n writeln (p - (n - p));\n}\n\n"}, {"source_code": "import std.stdio, std.string;\n\nvoid main()\n{\n int n, x = 0;\n \n readf(\"%s\", &n);\n \n while(--n >= 0) {\n string str;\n readf(\"%s\\n\", &str);\n if(str.indexOf(\"+\") != -1){ ++x; } else { --x; }\n }\n \n writeln(x);\n}"}, {"source_code": "import std.stdio, std.string;\n\nvoid main()\n{\n int n, x = 0;\n \n stdin.readf(\"%s\", &n);\n \n while(n > 0) {\n string str;\n readf(\"%s\", &str);\n if(str.indexOf(\"+\") != -1){ ++x; } else { --x; }\n --n;\n }\n \n write(\"\", x);\n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport core.stdc.stdio;\nimport std.string;\n\nint main(string[] argv)\n{\n\tint n;\n\tstring line;\n\tint x = 0;\n\tscanf(\"%d\", &n);\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tline = readln();\n\t\tif (indexOf(line, \"++\") != -1)\n\t\t{\n\t\t\tx++;\n\t\t} else\n\t\tif (indexOf(line, \"--\") != -1)\n\t\t{\n\t\t\tx--;\n\t\t}\n\t}\n\tprintf(\"%d\", x);\n\treturn 0;\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/282/A \nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n readln;\n int answer = 0;\n foreach(line; stdin.byLine)\n if(!canFind(line,\"++\"))\n answer++;\n else\n answer--;\n answer.writeln;\n}\n\n"}], "src_uid": "f3cf7726739290b280230b562cac7a74"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint res = a[0] + a[2];\r\n\t\tif (max (a[0], a[2]) <= min (a[1], a[3]))\r\n\t\t{\r\n\t\t\tres = min (res, max (a[0], a[2]));\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto L1 = scan!int;\r\n auto R1 = scan!int;\r\n auto L2 = scan!int;\r\n auto R2 = scan!int;\r\n\r\n if (R1 >= L2 && L2 >= L1) {\r\n return L2;\r\n }\r\n if (R2 >= L1 && L1 >= L2) {\r\n return L1;\r\n }\r\n \r\n return L1 + L2;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "negative_code": [], "src_uid": "c783eaf1bf7e4e7321406431030d5aab"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint u, v;\r\n\t\treadf !(\" %s %s\") (u, v);\r\n\t\tint cur = 0;\r\n\t\tbool ok = (u <= v);\r\n\t\tforeach (d; 0..30)\r\n\t\t{\r\n\t\t\tauto x = (u >> d) & 1;\r\n\t\t\tauto y = (v >> d) & 1;\r\n\t\t\tcur += x - y;\r\n\t\t\tok &= (cur >= 0);\r\n\t\t}\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nbool solve(const(long) A, const(long) B) {\r\n if (!(A <= B)) {\r\n return false;\r\n }\r\n int[] xs, ys;\r\n foreach (e; 0 .. bsr(A)) if ((A >> e) & 1) xs ~= e;\r\n foreach (e; 0 .. bsr(B)) if ((B >> e) & 1) ys ~= e;\r\n const xsLen = cast(int)(xs.length);\r\n const ysLen = cast(int)(ys.length);\r\n if (!(xsLen >= ysLen)) {\r\n return false;\r\n }\r\n foreach (i; 0 .. ysLen) {\r\n if (!(xs[i] <= ys[i])) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nvoid main() {\r\n debug {\r\n enum V = 1 << 8;\r\n auto d = new bool[][](V, V);\r\n foreach (u; 1 .. V) {\r\n d[u][u] = true;\r\n }\r\n foreach (u; 1 .. V) {\r\n foreach (v; 1 .. V - u) {\r\n if ((u & v) == v) {\r\n d[u][u + v] = true;\r\n }\r\n }\r\n }\r\n foreach (w; 1 .. V) foreach (u; 1 .. V) if (d[u][w]) foreach (v; 1 .. V) if (d[w][v]) {\r\n d[u][v] = true;\r\n }\r\n foreach (u; 1 .. V) foreach (v; 1 .. V) {\r\n const res = solve(u, v);\r\n assert(d[u][v] == res, format(\"%s %s: %s %s\", u, v, d[u][v], res));\r\n }\r\n }\r\n \r\n try {\r\n for (; ; ) {\r\n const numCases = readInt();\r\n foreach (caseId; 0 .. numCases) {\r\n const A = readLong();\r\n const B = readLong();\r\n const ans = solve(A, B);\r\n writeln(ans ? \"YES\" : \"NO\");\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto q = RD!int;\r\n\tauto ans = new long[](q);\r\n\tforeach (qi; 0..q)\r\n\t{\r\n\t\tauto u = RD;\r\n\t\tauto v = RD;\r\n\r\n\t\tauto uc = popcnt(u);\r\n\t\tauto vc = popcnt(v);\r\n\t\tif (v >= u && vc <= uc)\r\n\t\t{\r\n\t\t\tint c1, c2;\r\n\t\t\tbool ok = true;\r\n\t\t\tforeach (i; 0..32)\r\n\t\t\t{\r\n\t\t\t\tauto bit = 1L << i;\r\n\t\t\t\tif (u & bit)\r\n\t\t\t\t\t++c1;\r\n\t\t\t\tif (v & bit)\r\n\t\t\t\t\t++c2;\r\n\t\t\t\tif (c2 > c1)\r\n\t\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t\tans[qi] = ok;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto q = RD!int;\r\n\tauto ans = new long[](q);\r\n\tforeach (qi; 0..q)\r\n\t{\r\n\t\tauto u = RD!int;\r\n\t\tauto v = RD!int;\r\n\r\n\t\tauto uc = popcnt(u);\r\n\t\tauto vc = popcnt(v);\r\n\t\tif (v >= u && vc <= uc)\r\n\t\t\tans[qi] = true;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "a4e605859608d0c730ecbbee9ffc92d7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = RD!string;\n\tint l, cnt, ans;\n\tforeach (i; 0..n)\n\t{\n\t\tif (s[i] == ')')\n\t\t\t--cnt;\n\t\telse\n\t\t{\n\t\t\tif (cnt == -1)\n\t\t\t{\n\t\t\t\tans += i - l + 1;\n\t\t\t}\n\t\t\t++cnt;\n\t\t}\n\t\tif (cnt == 0)\n\t\t{\n\t\t\tl = i+1;\n\t\t}\n\t}\n\tif (cnt != 0)\n\t\twriteln(-1);\n\telse\n\t\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\tif (s.count ('(') != s.count (')'))\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\n\t\tint balance = 0;\n\t\tint res = 0;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tbool ok = (balance >= 0);\n\t\t\tbalance += (c == '(') ? +1 : -1;\n\t\t\tok &= (balance >= 0);\n\t\t\tres += !ok;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "e3275cd360d8f46cbbae03dfa86b924a"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tforeach (test; 0..readln.strip.to !(int)) {\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tauto ar = a.retro, br = b.retro;\n\t\tint [int [2]] x, y;\n\t\tforeach (i; 0..n) {\n\t\t\tx[[a[i], ar[i]]] += 1;\n\t\t\ty[[b[i], br[i]]] += 1;\n\t\t}\n\t\twriteln (x == y ? \"Yes\" : \"No\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nalias i = () => readln.strip.to!int, z = () => readln.split.map!(to!int).array;\nvoid main() {\n\tforeach (t; 0..i()) {\n\t\tauto n = i(), a = z(), b = z(), p = a.retro, q = b.retro;\n\t\tint [int [2]] x, y;\n\t\tforeach (i; 0..n) x[[a[i], p[i]]]++, y[[b[i], q[i]]]++;\n\t\twriteln (x == y ? \"Yes\" : \"No\");\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tforeach (test; 0..readln.strip.to !(int))\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tauto ar = a.retro;\n\t\tauto br = b.retro;\n\t\tint [int [2]] x;\n\t\tint [int [2]] y;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tx[[min (a[i], ar[i]), max (a[i], ar[i])]] += 1;\n\t\t\ty[[min (b[i], br[i]), max (b[i], br[i])]] += 1;\n\t\t}\n\t\twriteln (x == y ? \"Yes\" : \"No\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "eb0841b6722c46ba714ea61b2519aaca"} {"source_code": "import std;\n\nenum operation:bool { add, map };\nunion data_t {\n int a;\n struct {\n int x, y;\n }\n}\n\nstruct query {\n operation t;\n data_t data;\n}\n\nint[500_010] ans;\n\nvoid main () {\n int q;\n readf(\"%s\\n\", q);\n\n query[] vec = new query[q];\n\n foreach (ref e; vec) {\n char t;\n readf(\"%s \", t);\n if (t == '1') {\n readf(\"%s\\n\", e.data.a);\n e.t = operation.add;\n } else if (t == '2') {\n readf(\"%s %s\\n\", e.data.x, e.data.y);\n e.t = operation.map;\n } else\n assert(0);\n }\n\n\n foreach (int i, _; ans)\n ans[i] = i;\n\n\n int[] ret;\n ret.reserve(q);\n for (int i = q - 1; i > -1; -- i) {\n if (vec[i].t == operation.add)\n ret ~= ans[vec[i].data.a];\n else\n ans[vec[i].data.x] = ans[vec[i].data.y];\n }\n\n writefln(\"%(%s %)\", ret.retro);\n}\n\n// \"\"\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nenum int MAX = 500_000;\r\n\r\nclass Node(T) {\r\n Node prev, next;\r\n T value;\r\n this(T x) {\r\n this.value = x;\r\n this.prev = null;\r\n this.next = null;\r\n }\r\n}\r\nstruct List(T) {\r\n Node!T first = null, last = null;\r\n int len = 0;\r\n void insert(Node!T n) {\r\n if (len == 0) {\r\n first = n;\r\n last = n;\r\n n.prev = null;\r\n n.next = null;\r\n } else {\r\n last.next = n;\r\n n.prev = last;\r\n last = n;\r\n }\r\n len++;\r\n }\r\n void insert(List rhs) {\r\n if (rhs.len == 0) return;\r\n if (len == 0) {\r\n first = rhs.first;\r\n last = rhs.last;\r\n len = rhs.len;\r\n } else {\r\n last.next = rhs.first;\r\n rhs.first.prev = last;\r\n last = rhs.last;\r\n len += rhs.len;\r\n }\r\n }\r\n}\r\n\r\nvoid main() {\r\n int Q; readf(\"%d\\n\", &Q);\r\n auto es = new int[3][Q];\r\n foreach (q; 0 .. Q) {\r\n readf(\"%d\", &es[q][0]);\r\n if (es[q][0] == 1) {\r\n readf(\" %d\\n\", &es[q][1]);\r\n } else {\r\n readf(\" %d %d\\n\", &es[q][1], &es[q][2]);\r\n }\r\n }\r\n\r\n auto I = new List!int[MAX+1];\r\n int k = 0;\r\n for (int q = 0; q < Q; q++) {\r\n auto e = es[q];\r\n if (e[0] == 1) {\r\n int x = e[1];\r\n I[x].insert(new Node!int(k++));\r\n } else {\r\n int x = e[1];\r\n int y = e[2];\r\n if (x == y) continue;\r\n I[y].insert(I[x]);\r\n I[x] = List!int();\r\n }\r\n }\r\n int[] A = new int[k];\r\n for (int x = 0; x <= MAX; x++) {\r\n auto n = I[x].first;\r\n while (n !is null) {\r\n int i = n.value;\r\n A[i] = x;\r\n n = n.next;\r\n }\r\n }\r\n writefln(\"%(%s %)\", A);\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int q;\n readf!\" %d \"(q);\n int[] a;\n int[][] qlist;\n int[int] subst;\n while (q--) {\n qlist ~= readln.splitter.map!(to!int).array;\n }\n foreach_reverse (req ; qlist) {\n if (req[0] == 1) {\n int val = req[1];\n if (val in subst)\n val = subst[val];\n a ~= val;\n }\n else if (req[0] == 2) {\n if (req[2] in subst)\n req[2] = subst[req[2]];\n subst[req[1]] = req[2];\n }\n }\n writeln(a.retro.map!text.joiner(\" \"));\n}\n"}], "negative_code": [{"source_code": "import std;\n\nenum operation:bool { add, map };\nunion data_t {\n int a;\n struct {\n int x, y;\n }\n}\n\nstruct query {\n operation t;\n data_t data;\n}\n\nint[500_010] jumpback;\nint[500_010] ans;\n\nint\nroot (in int value) {\n if (jumpback[value] != value)\n jumpback[value] = root(jumpback[value]);\n return jumpback[value];\n}\n\nvoid\nmap (int what, int to) {\n jumpback[what] = ans[what] = root(to);\n}\n\nvoid main () {\n int q;\n readf(\"%s\\n\", q);\n\n query[] vec = new query[q];\n\n foreach (ref e; vec) {\n char t;\n readf(\"%s \", t);\n if (t == '1') {\n readf(\"%s\\n\", e.data.a);\n e.t = operation.add;\n } else if (t == '2') {\n readf(\"%s %s\\n\", e.data.x, e.data.y);\n e.t = operation.map;\n } else\n assert(0);\n }\n\n\n foreach (int i, _; jumpback)\n ans[i] = jumpback[i] = i;\n\n\n int[] ret;\n ret.reserve(q);\n for (int i = q - 1; i > -1; -- i) {\n if (vec[i].t == operation.add)\n ret ~= ans[vec[i].data.a];\n else\n map(vec[i].data.x, vec[i].data.y);\n }\n\n writefln(\"%(%s %)\", ret.retro);\n}\n\n// \"\"\n"}, {"source_code": "import std;\n\nenum operation:bool { add, map };\nunion data_t {\n int a;\n struct {\n int x, y;\n }\n}\n\nstruct query {\n operation t;\n data_t data;\n}\n\nint[500_010] jumpback;\n\nint\nroot (in int value) {\n if (jumpback[value] != value)\n jumpback[value] = root(jumpback[value]);\n return jumpback[value];\n}\n\nvoid\nmap (int what, int to) {\n jumpback[what] = root(to);\n}\n\nvoid main () {\n int q;\n readf(\"%s\\n\", q);\n\n query[] vec = new query[q];\n\n foreach (ref e; vec) {\n char t;\n readf(\"%s \", t);\n if (t == '1') {\n readf(\"%s\\n\", e.data.a);\n e.t = operation.add;\n } else if (t == '2') {\n readf(\"%s %s\\n\", e.data.x, e.data.y);\n e.t = operation.map;\n } else\n assert(0);\n }\n\n\n foreach (int i, _; jumpback)\n jumpback[i] = i;\n\n\n int[] ret;\n ret.reserve(q);\n for (int i = q - 1; i > -1; -- i) {\n if (vec[i].t == operation.add)\n ret ~= root(vec[i].data.a);\n else\n map(vec[i].data.x, vec[i].data.y);\n }\n\n writefln(\"%(%s %)\", ret.retro);\n}\n\n// \"\"\n"}], "src_uid": "cb86d0b26ee542fc75e274fcfe3f3660"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const KA = readLong();\n const KB = readLong();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n auto B = new long[N];\n foreach (i; 0 .. N) {\n B[i] = readLong();\n }\n \n auto ds = new long[N];\n foreach (i; 0 .. N) {\n ds[i] = abs(B[i] - A[i]);\n }\n const dsSum = ds.sum;\n long ans;\n if (KA + KB >= dsSum) {\n ans = (KA + KB - dsSum) % 2;\n } else {\n foreach (k; 0 .. KA + KB) {\n const im = ds.maxIndex;\n --ds[im];\n }\n foreach (i; 0 .. N) {\n ans += ds[i]^^2;\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv, std.math;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n, k1, k2;\n sc.read(n, k1, k2);\n long[] a, b;\n sc.read(a, b);\n foreach (i; 0..n) a[i] = abs(a[i]-b[i]);\n\n foreach (ph; 0..k1+k2) {\n int i = a.maxIndex.to!int;\n a[i] = abs(a[i]-1);\n }\n\n writeln(a.map!\"a*a\".sum);\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, k1, k2; readV(n, k1, k2);\n int[] a; readA(n, a);\n int[] b; readA(n, b);\n\n auto c = new int[](n);\n foreach (i; 0..n) c[i] = (a[i]-b[i]).abs;\n auto h = c.heapify;\n\n foreach (_; 0..k1+k2) {\n auto hi = h.front;\n h.replaceFront((hi-1).abs);\n }\n\n auto ans = 0L;\n foreach (hi; h)\n ans += hi.to!long ^^ 2;\n\n writeln(ans);\n}\n"}], "negative_code": [{"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv, std.math;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n, k1, k2;\n sc.read(n, k1, k2);\n int[] a, b;\n sc.read(a, b);\n foreach (i; 0..n) a[i] = abs(a[i]-b[i]);\n\n foreach (ph; 0..k1+k2) {\n int i = a.maxIndex.to!int;\n a[i] = abs(a[i]-1);\n }\n\n writeln(a.map!\"a*a\".sum);\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}], "src_uid": "88d54818fd8bab2f5d0bd8d95ec860db"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nclass TreeNode\n{\n TreeNode[2] children = [null, null];\n int noChildren()\n {\n return (children[0] !is null) + (children[1] !is null);\n }\n void insert(string str)\n {\n if (str.length == 0) return;\n size_t i = str[0] == '0'? 0 : 1;\n if (children[i] is null)\n children[i] = new TreeNode();\n children[i].insert(str[1 .. $]);\n }\n}\n\nint minans = int.max;\nvoid dfs(TreeNode treeNode, int digit, int accans)\n{\n int noChildren = treeNode.noChildren;\n if (noChildren == 0)\n {\n minans = min(accans, minans);\n }\n else if (noChildren == 1)\n {\n if (treeNode.children[0] !is null)\n dfs(treeNode.children[0], digit - 1, accans);\n else\n dfs(treeNode.children[1], digit - 1, accans);\n }\n else\n {\n dfs(treeNode.children[0], digit - 1, accans | (1 << digit));\n dfs(treeNode.children[1], digit - 1, accans | (1 << digit));\n }\n}\n\nvoid main()\n{\n int n;\n read(n);\n string toString(int n)\n {\n char[] res = new char[30];\n foreach(i; 0 .. 30)\n {\n res[i] = ((n & (1 << (29 - i))) == 0)? '0' : '1';\n }\n return res.idup;\n }\n auto a = makeArray!string(n, toString(next!int));\n TreeNode root = new TreeNode();\n foreach(ai; a)\n root.insert(ai);\n dfs(root, 29, 0);\n writeln(minans);\n}\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto rd = new InputReader ();\n immutable n = rd.next!uint ();\n auto a = rd.nextA!uint (n);\n sort (a);\n a.length -= a.uniq.copy (a).length;\n immutable m = a.length.to!int;\n uint f (int l, int r, int k, uint start) {\n if (k < 0) return 0;\n debug stderr.writefln (\"f %d %d %d %d\",l, r, k, start);\n immutable uint mask = 1 << k;\n auto e = assumeSorted (a[l .. r]);\n immutable int mid = l + e.lowerBound (start + mask).length.to!int;\n debug stderr.writeln (\"mid = \", mid);\n if (l < mid && mid < r) {\n return mask + min (f (l, mid, k - 1, start), f (mid, r, k - 1, start + mask)); \n }\n return f (l, r, k - 1, (r == mid) ? start : (start + mask));\n }\n writeln (f (0, m, 29, 0U));\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\t\n\tbool[long][32] set;\n\n\tforeach (i; 0..32)\n\t{\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tauto x = a[j] >> (31 - i);\n\t\t\tset[i][x] = true;\n\t\t}\n\t}\n\n\tlong ans = long.max;\n\tforeach (i; 0..n)\n\t{\n\t\tlong tmp;\n\t\tforeach (j; 0..32)\n\t\t{\n\t\t\tauto x = a[i] >> (31 - j);\n\t\t\tx ^= 1;\n\t\t\tif (set[j].get(x, false))\n\t\t\t{\n\t\t\t\ttmp += 1L << (31 - j);\n\t\t\t}\n\t\t}\n\t\tdebug writeln(tmp);\n\t\tans.chmin(tmp);\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto tr = new int[int][] (1);\n int sz = 0;\n \n void add(int x) {\n debug { tr[0].writeln; }\n int nd = 0;\n foreach_reverse (b; 0 .. 30) {\n int dir = (x & (1 << b)) ? 1 : 0;\n if (dir !in tr[nd]) {\n int[int] dict;\n tr ~= dict;\n tr[nd][dir] = ++sz;\n }\n\n nd = tr[nd][dir];\n }\n }\n\n\n foreach (e; arr) {\n add(e);\n }\n \n debug { tr.writeln; }\n \n int dfs(int v, int lvl) {\n if (tr[v].empty()) { return 0; }\n \n if (tr[v].length == 1) { \n auto k = tr[v].keys[0];\n return dfs(tr[v][k], lvl-1);\n }\n \n return (1 << lvl) \n + min(dfs(tr[v][0], lvl-1), dfs(tr[v][1], lvl-1));\n }\n \n auto ans = dfs(0, 29);\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto rd = new InputReader ();\n immutable n = rd.next!uint ();\n auto a = rd.nextA!uint (n);\n sort (a);\n a.length -= a.uniq.copy (a).length;\n immutable m = a.length.to!int;\n uint f (int l, int r, int k, uint start) {\n if (k == 0) return 0;\n debug stderr.writefln (\"f %d %d %d %d\",l, r, k, start);\n immutable uint mask = 1 << k;\n auto e = assumeSorted (a[l .. r]);\n immutable int mid = l + e.lowerBound (start + mask).length.to!int;\n debug stderr.writeln (\"mid = \", mid);\n if (l < mid && mid < r) {\n return mask + min (f (l, mid, k - 1, start), f (mid, r, k - 1, start + mask)); \n }\n return f (l, r, k - 1, (r == mid) ? start : (start + mask));\n }\n writeln (f (0, m, 29, 0U));\n}\n\n"}], "src_uid": "d17d2fcfb088bf51e9c1f3fce4133a94"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nclass SegmentTree(T = int, alias op) {\n private:\n T [] t;\n size_t n;\n final void build () pure nothrow @nogc {\n foreach_reverse (i; 1 .. n) {\n immutable k = i << 1;\n t[i] = op (t[k], t[k+1]);\n }\n }\n public:\n final void update (size_t p, T v) pure nothrow @nogc {\n for (t[p += n] = v; p > 1; p >>= 1) {\n t[p>>1] = op (t[p], t[p ^ 1]);\n }\n }\n final T reduce (size_t l, size_t r) const pure nothrow @nogc {\n T res;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n if (l & 1) {\n res = op (res, t[l++]);\n }\n if (r & 1) {\n res = op (t[--r], res);\n }\n }\n return res;\n }\n this (const T[] a) pure nothrow {\n n = a.length;\n t = new T[n];\n t ~= a;\n build ();\n }\n}\n\nvoid main() {\n int n, m;\n readf (\" %d %d\", &n, &m);\n auto a = new uint[1<<n];\n foreach (t; 0 .. 1<<n) {\n readf (\" %d\", &a[t]);\n }\n enum uint q = 0x8000_0000;\n auto st = new SegmentTree!(uint, (x, y) => (x & q) ? (x ^ y) & (q - 1) : (x | y | q)) (a);\n foreach (t; 0 .. m) {\n int i;\n uint v;\n readf (\" %d %d\", &i, v);\n --i;\n st.update (i, v);\n writeln (st.reduce (0, 1 << n) & (q - 1));\n }\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nclass SegmentTree(T = int, alias op) {\n private:\n T [] t;\n size_t n;\n final void build () pure nothrow @nogc {\n foreach_reverse (i; 1 .. n) {\n immutable k = i << 1;\n t[i] = op (t[k], t[k+1]);\n }\n }\n public:\n final T opIndexAssign (T value, size_t index) {\n for (t[index += n] = value; index > 1; index >>= 1) {\n t[index>>1] = op (t[index], t[index ^ 1]);\n }\n return value;\n }\n final T reduce (size_t l, size_t r) const pure nothrow @nogc {\n T res;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n if (l & 1) {\n res = op (res, t[l++]);\n }\n if (r & 1) {\n res = op (t[--r], res);\n }\n }\n return res;\n }\n this (const T[] a) pure nothrow {\n n = a.length;\n t = new T[n];\n t ~= a;\n build ();\n }\n}\n\nvoid main() {\n int n, m;\n readf (\" %d %d\", &n, &m);\n auto a = new uint[1<<n];\n foreach (t; 0 .. 1<<n) {\n readf (\" %d\", &a[t]);\n }\n enum uint q = 0x8000_0000;\n auto st = new SegmentTree!(uint, (x, y) => (x & q) ? (x ^ y) & (q - 1) : (x | y | q)) (a);\n foreach (t; 0 .. m) {\n int i;\n uint v;\n readf (\" %d %d\", &i, v);\n st[i-1] = v;\n writeln (st.reduce (0, 1 << n) & (q - 1));\n }\n}\n\n"}], "negative_code": [], "src_uid": "40d1ea98aa69865143d44432aed4dd7e"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n auto cs = new long[](25820);\n cs[1] = 2;\n foreach (i; 2..25820) {\n cs[i] = cs[i-1] + (i-1) * 3 + 2;\n }\n\n foreach (_; 0..T) {\n auto N = readln.chomp.to!int;\n\n int res;\n while (N >= 2) {\n ++res;\n if (N >= cs[$-1]) {\n N -= cs[$-1];\n } else {\n int l = 1, r = cs.length.to!int-1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n if (N >= cs[m]) {\n l = m;\n } else {\n r = m;\n }\n }\n N -= cs[l];\n }\n }\n writeln(res);\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint tri (int n)\n{\n\treturn n * (n + 1) / 2;\n}\n\nint f (int n)\n{\n\treturn tri (n) * 3 - n;\n}\n\nvoid main ()\n{\n\treadln;\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tint k = 0;\n\t\twhile (f (k) <= n)\n\t\t{\n\t\t\tk += 1;\n\t\t}\n\t\tint res = 0;\n\t\twhile (k > 0)\n\t\t{\n\t\t\twhile (f (k) <= n)\n\t\t\t{\n\t\t\t\tn -= f (k);\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\tk -= 1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\n\t\twhile (true)\n\t\t{\n\t\t\tauto r = binarySearch!((long a) => a*(a+1) + a*(a-1)/2 <= n)(0L, 10L^^9);\n\t\t\tif (r == 0) break;\n\t\t\t++ans[ti];\n\t\t\tn -= r*(r+1) + r*(r-1)/2;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint tri (int n)\n{\n\treturn n * (n + 1) / 2;\n}\n\nint f (int n)\n{\n\treturn tri (n) * 3 - n;\n}\n\nvoid main ()\n{\n\treadln;\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tint k = 0;\n\t\twhile (f (k) <= n)\n\t\t{\n\t\t\tk += 1;\n\t\t}\n\t\tint res = 0;\n\t\twhile (k > 0)\n\t\t{\n\t\t\tif (f (k) <= n)\n\t\t\t{\n\t\t\t\tn -= f (k);\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\tk -= 1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "02062d1afe85e3639edddedceac304f4"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (readf (\" %s %s %s \", &n, &m, &k) > 0)\n\t{\n\t\tstring [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta ~= readln ().strip ();\n\t\t}\n\n\t\tbool ask (int row, int col, char ch)\n\t\t{\n\t\t\tif (row < 0 || row >= n || col < 0 || col >= m)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn a[row][col] == ch;\n\t\t}\n\n\t\tint [] ans;\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 1..n)\n\t\t\t{\n\t\t\t\tcur += ask (i * 2, j, 'U');\n\t\t\t\tcur += ask (i, j - i, 'R');\n\t\t\t\tcur += ask (i, j + i, 'L');\n\t\t\t}\n\t\t\tans ~= cur;\n\t\t}\n\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.traits;\n\nvoid main(){\n size_t n,m,k;\n readf(\"%s %s %s\\n\",&n,&m,&k);\n\n char[][] table = new char[][](n,m);\n\n string tmp;\n readf(\"%s\\n\",&tmp);\n for(int i = 1; i < n; i++){\n readf(\"%s\\n\",&tmp);\n\n for(int j = 0; j < m; j++){\n if (tmp[j] != '.'){\n table[i][j] = tmp[j];\n }\n }\n }\n\n // for(int i = 0; i < n; i++){\n // for(int j = 0; j < m; j++){\n // write(table[i][j]);\n // }\n // writeln();\n // }\n\n int[] hits = new int[m];\n for(int t = 0; t < n; t++){\n for(int om = 0; om < m; om++){\n // U && D (never hits)\n if(t % 2 == 0 && table[t][om] == 'U'){\n hits[om]++;\n }\n //L\n if(om+t >= 0 && om+t < m && table[t][om+t] == 'L'){\n hits[om]++;\n }\n //R\n //writeln(om-t);\n if(om-t >= 0 && om-t < m && table[t][om-t] == 'R'){\n hits[om]++;\n }\n }\n }\n foreach(om;hits){\n writef(\"%s \",om);\n }\n writeln();\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.traits;\n\nvoid main(){\n size_t n,m,k;\n readf(\"%s %s %s\\n\",&n,&m,&k);\n\n char[][] table = new char[][](n,m);\n\n string tmp;\n readf(\"%s\\n\",&tmp);\n for(int i = 1; i < n; i++){\n readf(\"%s\\n\",&tmp);\n\n for(int j = 0; j < m; j++){\n if (tmp[j] != '.'){\n table[i][j] = tmp[j];\n }\n }\n }\n\n // for(int i = 0; i < n; i++){\n // for(int j = 0; j < m; j++){\n // write(table[i][j]);\n // }\n // writeln();\n // }\n\n int[] hits = new int[m];\n for(int t = 0; t < n-1; t++){\n for(int om = 0; om < m; om++){\n // U && D (never hits)\n if(t+2 < n && table[t+2][om] == 'U'){\n hits[om]++;\n }\n //L\n if(om+t >= 0 && om+t < m && table[t][om+t] == 'L'){\n hits[om]++;\n }\n //R\n //writeln(om-t);\n if(om-t >= 0 && om-t < m && table[t][om-t] == 'R'){\n hits[om]++;\n }\n }\n }\n foreach(om;hits){\n writef(\"%s \",om);\n }\n writeln();\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.traits;\n\nvoid main(){\n size_t n,m,k;\n readf(\"%s %s %s\\n\",&n,&m,&k);\n\n char[][] table = new char[][](n,m);\n\n string tmp;\n readf(\"%s\\n\",&tmp);\n for(int i = 1; i < n; i++){\n readf(\"%s\\n\",&tmp);\n\n for(int j = 0; j < m; j++){\n if (tmp[j] != '.'){\n table[i][j] = tmp[j];\n }\n }\n }\n\n // for(int i = 0; i < n; i++){\n // for(int j = 0; j < m; j++){\n // write(table[i][j]);\n // }\n // writeln();\n // }\n\n int[] hits = new int[m];\n for(int t = 0; t < n; t++){\n for(int om = 1; om <= m; om++){\n // U && D (never hits)\n if(table[t][om-1] == 'U'){\n hits[om-1]++;\n }\n //L\n if(om-1+t >= 0 && om-1+t < m && table[t][om+t-1] == 'L'){\n hits[om-1]++;\n }\n //R\n //writeln(om-t);\n if(om-1-t >= 0 && om-1-t < m && table[t][om-t-1] == 'R'){\n hits[om-1]++;\n }\n }\n }\n foreach(om;hits){\n writef(\"%s \",om);\n }\n writeln();\n}\n"}], "src_uid": "d8c89bb83592a1ff1b639f7d53056d67"} {"source_code": "module main;\n\nimport std.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.random;\nimport std.conv;\n\n\n\n\n\n\n\nvoid main ()\n{\n float h,d,v,e,vn,Vo;\n readf(\" %s %s %s %s\", &d, &h, &v, &e);\n e = e*(d/2)^^2 * 3.1415926;\n if (v - e < 0) writeln(\"NO\");\n else\n {\n writeln(\"YES\");\n vn = v - e;\n Vo = (d/2)^^2 * 3.1415926 * h;\n Vo = Vo / vn;\n writeln(Vo);\n\n }\n\n\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.math;\nvoid main(){\n auto dhve = readln.chomp.split.map!(to!double);\n\n double d = dhve[0];\n double h = dhve[1];\n double v = dhve[2];\n double e = dhve[3];\n\n double r = d * 0.5;\n double t = (PI * r * r * h)/(v - PI * r * r * e);\n\n if (t < -1e-8){\n writeln(\"NO\");\n }else{\n writeln(\"YES\");\n writeln(t);\n }\n\n}"}], "negative_code": [], "src_uid": "fc37ef81bb36f3ac07ce2c4c3ec10d98"} {"source_code": "import std.stdio;\n\nint main() {\n int q, l, r, d;\n\n scanf(\"%d\", &q);\n while (q--) {\n scanf(\"%d%d%d\", &l, &r, &d);\n if (d<l) printf(\"%d\\n\", d);\n else printf(\"%d\\n\", (r/d+1)*d);\n }\n\n return 0;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int q = to!int(readln.strip);\n\n foreach (i; 0 .. q) {\n int l,r,d;\n readf!\" %s %s %s\"(l,r,d);\n if (l > d) {\n writeln(d);\n } else {\n writeln((r/d+1)*d);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "091e91352973b18040e2d57c46f2bf8a"} {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{\r\n immutable int MX = 10 ^^ 7 + 23;\r\n \r\n auto d = new int[MX];\r\n d[] = 0;\r\n foreach (i; 2 .. sqrt(MX.to!real).to!int) {\r\n if (d[i] != 0) { continue; }\r\n foreach (ref p; d[i .. MX].stride(i)) { p = i; }\r\n }\r\n \r\n foreach (i; 0 .. MX) { \r\n if (d[i] == 0) { d[i] = i; } \r\n }\r\n \r\n debug { d.take(20).writeln; }\r\n \r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n \r\n while (t--) {\r\n int n, k;\r\n readf!\" %s %s\"(n, k);\r\n readln;\r\n \r\n auto a = readln.chomp.split.map!(to!int).array;\r\n\r\n auto tr = make!(RedBlackTree!(int[]));\r\n tr.insert([2, 3]);\r\n \r\n int ans = 1;\r\n foreach (e; a) {\r\n int[] odd;\r\n while (e > 1) {\r\n int curd = d[e];\r\n int cnt = 0;\r\n while (e % curd == 0) {\r\n ++cnt;\r\n e /= curd;\r\n }\r\n \r\n if (cnt % 2 == 1) { odd ~= curd; }\r\n }\r\n \r\n if (odd in tr) {\r\n ans += 1;\r\n tr.clear();\r\n }\r\n \r\n tr.insert(odd);\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{\r\n immutable int MX = 10 ^^ 7 + 23;\r\n \r\n auto d = new int[MX];\r\n d[] = 0;\r\n foreach (i; 2 .. sqrt(MX.to!real).to!int) {\r\n if (d[i] != 0) { continue; }\r\n foreach (ref p; d[i .. MX].stride(i)) { p = i; }\r\n }\r\n \r\n foreach (i; 0 .. MX) { \r\n if (d[i] == 0) { d[i] = i; } \r\n }\r\n \r\n debug { d.take(20).writeln; }\r\n \r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n \r\n while (t--) {\r\n int n, k;\r\n readf!\" %s %s\"(n, k);\r\n readln;\r\n \r\n auto a = readln.chomp.split.map!(to!int).array;\r\n\r\n auto tr = make!(RedBlackTree!(int[]));\r\n \r\n int ans = 1;\r\n foreach (e; a) {\r\n int[] odd;\r\n while (e > 1) {\r\n int curd = d[e];\r\n int cnt = 0;\r\n while (e % curd == 0) {\r\n ++cnt;\r\n e /= curd;\r\n }\r\n \r\n if (cnt % 2 == 1) { odd ~= curd; }\r\n }\r\n \r\n if (odd in tr) {\r\n ans += 1;\r\n tr.clear();\r\n }\r\n \r\n tr.insert(odd);\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}"}], "negative_code": [], "src_uid": "878c2e57a396187ccef51d0f941386cf"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimport std.container;\n\nvoid main() {\n int n, m;\n readf (\" %d %d\", &n, &m);\n auto a = new int[n];\n auto rbt = new RedBlackTree!int (iota (0, n));\n auto c = new int[n];\n a[] = -1;\n foreach (t; 0 .. m) {\n int l, r, x;\n readf (\" %d %d %d\", &l, &r, &x);\n --l; --r; --x;\n auto d = rbt.lowerBound (x);\n int k;\n foreach_reverse (i; d) {\n if (i < l) break;\n a[i] = x;\n c[k++] = i;\n }\n d = rbt.upperBound (x);\n foreach (i; d) {\n if (i > r) break;\n a[i] = x;\n c[k++] = i;\n }\n foreach (i; 0 .. k) {\n rbt.removeKey (c[i]);\n }\n }\n a.map! (i => (i+1).text).join(\" \").writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto tree = redBlackTree(iota(1, N + 1, 1).array);\n auto ans = new int[N];\n foreach (i; 0 .. M) {\n int L, R, W; scanf(\"%d %d %d\\n\", &L, &R, &W);\n auto xs = tree.upperBound(L - 1);\n int[] rs;\n foreach (x; xs) {\n if (x > R) break;\n if (x == W) continue;\n ans[x - 1] = W;\n rs ~= x;\n }\n foreach (r; rs) tree.removeKey(r);\n }\n writefln(\"%(%s %)\", ans);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nclass SegmentTree {\n // root\u306eindex\u306f1\n int N;\n int[] L;\n static int FindPow2(int x) {\n int x1 = 1;\n while (x1 < x) x1 *= 2;\n return x1;\n }\n this(int N_) {\n N = FindPow2(N_);\n L = new int[N * 2];\n L[] = -1;\n }\n /* [s, t)\u3092x\u306b\u66f4\u65b0 */\n void update(int x, int s, int t) { update(x, s, t, 0, N, 1); }\n void update(int x, int s, int t, int a, int b, int k) {\n if (t <= a || b <= s) return;\n if (s <= a && b <= t) {\n L[k] = x;\n } else if (s < b || a < t) {\n int m = (a + b) / 2;\n update(x, s, t, a, m, k * 2);\n update(x, s, t, m, b, k * 2 + 1);\n }\n }\n /* i\u306e\u5024 */\n int query(int i) { return query(i, 0, N, 1); }\n int query(int i, int a, int b, int k) {\n if (i < a || b <= i) return -1;\n if (a <= i && i < b && L[k] >= 0) return L[k];\n int m = (a + b) / 2;\n return max( query(i, a, m, k * 2), query(i, m, b, k * 2 + 1) );\n }\n};\n\n\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto L = new int[M],\n R = new int[M],\n W = new int[M];\n foreach (i; 0 .. M) {\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n L[i] = xs[0]; L[i]--;\n R[i] = xs[1];\n W[i] = xs[2];\n }\n\n const MAX = 300001; const Z = 550;\n auto ans = new int[N]; ans[] = -1;\n auto seg = new int[N]; seg[] = -1;\n auto segp = new int[N];\n auto child_prior = new int[N];\n L.reverse; R.reverse; W.reverse;\n foreach (m; 0 .. M) {\n int s = L[m], t = R[m], v = W[m]; // [s, t]\u3092v\u306b\u66f4\u65b0\n int p;\n if (child_prior[(v - 1) / Z] == 1) {\n p = seg[v - 1];\n } else {\n p = segp[(v - 1) / Z];\n }\n //writeln([s, t, v]);\n int from_parent = s / Z;\n if (child_prior[from_parent] == -1) {\n for (int i = from_parent * Z; i < from_parent * Z + Z; i++) seg[i] = segp[from_parent];\n }\n for (int i = s; i < min(t, from_parent * Z + Z); i++) {\n seg[i] = v;\n }\n child_prior[from_parent] = 1;\n int to_parent = t / Z;\n if (child_prior[to_parent] == -1) {\n for (int i = to_parent * Z - Z; i < to_parent * Z; i++) seg[i] = segp[to_parent];\n }\n for (int i = max(s, to_parent * Z - Z); i < t; i++) {\n seg[i] = v;\n }\n child_prior[to_parent] = 1;\n for (int i = from_parent + 1; i <= to_parent - 1; i++) {\n segp[i] = v;\n child_prior[i] = -1;\n }\n ans[v - 1] = p;\n static if (false) {\n writeln(seg);\n writeln(segp);\n writeln;\n }\n }\n foreach (i; 0 .. N) {\n if (ans[i] >= 0) continue;\n if (child_prior[i / Z] == 1) {\n ans[i] = seg[i];\n } else if (child_prior[i / Z] == -1) {\n ans[i] = segp[i];\n } else {\n writeln(\"FOO\");\n }\n }\n writefln(\"%(%s %)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nclass SegmentTree {\n // root\u306eindex\u306f1\n int N;\n int[] L;\n static int FindPow2(int x) {\n int x1 = 1;\n while (x1 < x) x1 *= 2;\n return x1;\n }\n this(int N_) {\n N = FindPow2(N_);\n L = new int[N * 2];\n L[] = -1;\n }\n /* [s, t)\u3092x\u306b\u66f4\u65b0 */\n void update(int x, int s, int t) { update(x, s, t, 0, N, 1); }\n void update(int x, int s, int t, int a, int b, int k) {\n if (t <= a || b <= s) return;\n if (s <= a && b <= t) {\n L[k] = x;\n } else if (s < b || a < t) {\n int m = (a + b) / 2;\n update(x, s, t, a, m, k * 2);\n update(x, s, t, m, b, k * 2 + 1);\n }\n }\n /* i\u306e\u5024 */\n int query(int i) { return query(i, 0, N, 1); }\n int query(int i, int a, int b, int k) {\n if (i < a || b <= i) return -1;\n if (a <= i && i < b && L[k] >= 0) return L[k];\n int m = (a + b) / 2;\n return max( query(i, a, m, k * 2), query(i, m, b, k * 2 + 1) );\n }\n};\n\n\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto L = new int[M],\n R = new int[M],\n W = new int[M];\n foreach (i; 0 .. M) {\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n L[i] = xs[0]; L[i]--;\n R[i] = xs[1];\n W[i] = xs[2];\n }\n\n const MAX = 300001; const Z = 550;\n auto ans = new int[N]; ans[] = -1;\n auto seg = new int[N]; seg[] = -1;\n auto segp = new int[N];\n auto child_prior = new int[N];\n L.reverse; R.reverse; W.reverse;\n foreach (m; 0 .. M) {\n int s = L[m], t = R[m], v = W[m]; // [s, t]\u3092v\u306b\u66f4\u65b0\n int p;\n if (child_prior[(v - 1) / Z] == 1) {\n p = seg[v - 1];\n } else {\n p = segp[(v - 1) / Z];\n }\n //writeln([s, t, v]);\n int from_parent = s / Z;\n if (child_prior[from_parent] == -1) {\n for (int i = from_parent * Z; i < from_parent * Z + Z; i++) seg[i] = segp[from_parent];\n }\n for (int i = s; i < min(t, from_parent * Z + Z); i++) {\n seg[i] = v;\n }\n child_prior[from_parent] = 1;\n int to_parent = t / Z;\n if (child_prior[to_parent] == -1) {\n for (int i = to_parent * Z - Z; i < to_parent * Z; i++) seg[i] = segp[to_parent];\n }\n for (int i = max(s, to_parent * Z - Z); i < t; i++) {\n seg[i] = v;\n }\n child_prior[to_parent] = 1;\n for (int i = from_parent + 1; i <= to_parent - 1; i++) {\n segp[i] = v;\n child_prior[i] = -1;\n }\n ans[v - 1] = p;\n static if (false) {\n writeln(seg);\n writeln(segp);\n writeln;\n }\n }\n foreach (i; 0 .. N) {\n if (ans[i] >= 0) continue;\n if (child_prior[i / Z] == 1) {\n ans[i] = seg[i];\n } else if (child_prior[i / Z] == -1) {\n ans[i] = segp[i];\n } else {\n assert(0);\n }\n }\n writefln(\"%(%s %)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nclass SegmentTree {\n // root\u306eindex\u306f1\n int N;\n int[] L;\n static int FindPow2(int x) {\n int x1 = 1;\n while (x1 < x) x1 *= 2;\n return x1;\n }\n this(int N_) {\n N = FindPow2(N_);\n L = new int[N * 2];\n L[] = -1;\n }\n /* [s, t)\u3092x\u306b\u66f4\u65b0 */\n void update(int x, int s, int t) { update(x, s, t, 0, N, 1); }\n void update(int x, int s, int t, int a, int b, int k) {\n if (t <= a || b <= s) return;\n if (s <= a && b <= t) {\n L[k] = x;\n } else if (s < b || a < t) {\n int m = (a + b) / 2;\n update(x, s, t, a, m, k * 2);\n update(x, s, t, m, b, k * 2 + 1);\n }\n }\n /* i\u306e\u5024 */\n int query(int i) { return query(i, 0, N, 1); }\n int query(int i, int a, int b, int k) {\n if (i < a || b <= i) return -1;\n if (a <= i && i < b && L[k] >= 0) return L[k];\n int m = (a + b) / 2;\n return max( query(i, a, m, k * 2), query(i, m, b, k * 2 + 1) );\n }\n};\n\n\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto L = new int[M],\n R = new int[M],\n W = new int[M];\n foreach (i; 0 .. M) {\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n L[i] = xs[0]; L[i]--;\n R[i] = xs[1];\n W[i] = xs[2];\n }\n\n const MAX = 300001; const Z = 550;\n auto ans = new int[N]; ans[] = -1;\n auto seg = new int[N]; seg[] = -1;\n auto segp = new int[N];\n auto child_prior = new bool[N];\n L.reverse; R.reverse; W.reverse;\n foreach (m; 0 .. M) {\n int s = L[m], t = R[m], v = W[m]; // [s, t]\u3092v\u306b\u66f4\u65b0\n int p = seg[v - 1];\n //writeln([s, t, v]);\n int from_parent = s / Z;\n for (int i = s; i < min(t, from_parent * Z + Z); i++) {\n seg[i] = v;\n }\n child_prior[from_parent] = true;\n int to_parent = t / Z;\n for (int i = max(s, to_parent * Z - Z); i < t; i++) {\n seg[i] = v;\n }\n child_prior[to_parent] = true;\n for (int i = from_parent + 1; i <= to_parent - 1; i++) {\n segp[i] = v;\n child_prior[i] = false;\n }\n ans[v - 1] = p;\n }\n foreach (i; 0 .. N) {\n if (ans[i] >= 0) continue;\n if (child_prior[i / Z]) {\n ans[i] = seg[i];\n } else {\n ans[i] = segp[i];\n }\n }\n foreach (i; 0 .. N) if (ans[i] == i + 1) ans[i] = 0;\n writefln(\"%(%s %)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nclass SegmentTree {\n // root\u306eindex\u306f1\n int N;\n int[] L;\n static int FindPow2(int x) {\n int x1 = 1;\n while (x1 < x) x1 *= 2;\n return x1;\n }\n this(int N_) {\n N = FindPow2(N_);\n L = new int[N * 2];\n L[] = -1;\n }\n /* [s, t)\u3092x\u306b\u66f4\u65b0 */\n void update(int x, int s, int t) { update(x, s, t, 0, N, 1); }\n void update(int x, int s, int t, int a, int b, int k) {\n if (t <= a || b <= s) return;\n if (s <= a && b <= t) {\n L[k] = x;\n } else if (s < b || a < t) {\n int m = (a + b) / 2;\n update(x, s, t, a, m, k * 2);\n update(x, s, t, m, b, k * 2 + 1);\n }\n }\n /* i\u306e\u5024 */\n int query(int i) { return query(i, 0, N, 1); }\n int query(int i, int a, int b, int k) {\n if (i < a || b <= i) return -1;\n if (a <= i && i < b && L[k] >= 0) return L[k];\n int m = (a + b) / 2;\n return max( query(i, a, m, k * 2), query(i, m, b, k * 2 + 1) );\n }\n};\n\n\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto L = new int[M],\n R = new int[M],\n W = new int[M];\n foreach (i; 0 .. M) {\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n L[i] = xs[0]; L[i]--;\n R[i] = xs[1];\n W[i] = xs[2];\n }\n\n const MAX = 300001; const Z = 550;\n auto ans = new int[N]; ans[] = -1;\n auto seg = new int[N]; seg[] = -1;\n auto segp = new int[N];\n auto child_prior = new int[N];\n L.reverse; R.reverse; W.reverse;\n foreach (m; 0 .. M) {\n int s = L[m], t = R[m], v = W[m]; // [s, t]\u3092v\u306b\u66f4\u65b0\n int p;\n if (ans[v - 1] >= 0) {\n p = ans[v - 1];\n } else if (child_prior[(v - 1) / Z] == 1) {\n p = seg[v - 1];\n } else {\n p = segp[(v - 1) / Z];\n }\n //writeln([s, t, v]);\n int from_parent = s / Z;\n if (child_prior[from_parent] == -1) {\n for (int i = from_parent * Z; i < from_parent * Z + Z; i++) seg[i] = segp[from_parent];\n }\n for (int i = s; i < min(t, from_parent * Z + Z); i++) {\n seg[i] = v;\n }\n child_prior[from_parent] = 1;\n int to_parent = t / Z;\n if (child_prior[to_parent] == -1) {\n for (int i = to_parent * Z - Z; i < to_parent * Z; i++) seg[i] = segp[to_parent];\n }\n for (int i = max(s, to_parent * Z - Z); i < t; i++) {\n seg[i] = v;\n }\n child_prior[to_parent] = 1;\n for (int i = from_parent + 1; i <= to_parent - 1; i++) {\n segp[i] = v;\n child_prior[i] = -1;\n }\n ans[v - 1] = p;\n static if (false) {\n writeln(seg);\n writeln(segp);\n writeln(ans);\n writeln;\n }\n }\n foreach (i; 0 .. N) {\n if (ans[i] >= 0) continue;\n if (child_prior[i / Z] == 1) {\n ans[i] = seg[i];\n } else if (child_prior[i / Z] == -1) {\n ans[i] = segp[i];\n } else {\n assert(0);\n }\n }\n //foreach (i; 0 .. N) if (ans[i] == i + 1) ans[i] = 0;\n writefln(\"%(%s %)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nclass SegmentTree {\n // root\u306eindex\u306f1\n int N;\n int[] L;\n static int FindPow2(int x) {\n int x1 = 1;\n while (x1 < x) x1 *= 2;\n return x1;\n }\n this(int N_) {\n N = FindPow2(N_);\n L = new int[N * 2];\n L[] = -1;\n }\n /* [s, t)\u3092x\u306b\u66f4\u65b0 */\n void update(int x, int s, int t) { update(x, s, t, 0, N, 1); }\n void update(int x, int s, int t, int a, int b, int k) {\n if (t <= a || b <= s) return;\n if (s <= a && b <= t) {\n L[k] = x;\n } else if (s < b || a < t) {\n int m = (a + b) / 2;\n update(x, s, t, a, m, k * 2);\n update(x, s, t, m, b, k * 2 + 1);\n }\n }\n /* i\u306e\u5024 */\n int query(int i) { return query(i, 0, N, 1); }\n int query(int i, int a, int b, int k) {\n if (i < a || b <= i) return -1;\n if (a <= i && i < b && L[k] >= 0) return L[k];\n int m = (a + b) / 2;\n return max( query(i, a, m, k * 2), query(i, m, b, k * 2 + 1) );\n }\n};\n\n\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto L = new int[M],\n R = new int[M],\n W = new int[M];\n foreach (i; 0 .. M) {\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n L[i] = xs[0]; L[i]--;\n R[i] = xs[1];\n W[i] = xs[2];\n }\n\n const MAX = 300001; const Z = 550;\n auto ans = new int[N]; ans[] = -1;\n auto seg = new int[N]; seg[] = -1;\n auto segp = new int[N];\n auto child_prior = new int[N];\n L.reverse; R.reverse; W.reverse;\n foreach (m; 0 .. M) {\n int s = L[m], t = R[m], v = W[m]; // [s, t]\u3092v\u306b\u66f4\u65b0\n int p;\n if (ans[v - 1] >= 0) {\n p = ans[v - 1];\n } else if (child_prior[(v - 1) / Z] == 1) {\n p = seg[v - 1];\n } else {\n p = segp[(v - 1) / Z];\n }\n //writeln([s, t, v]);\n int from_parent = s / Z;\n if (child_prior[from_parent] == -1) {\n for (int i = from_parent * Z; i < from_parent * Z + Z; i++) seg[i] = segp[from_parent];\n }\n for (int i = s; i < min(t, from_parent * Z + Z); i++) {\n seg[i] = v;\n }\n child_prior[from_parent] = 1;\n int to_parent = (t - 1) / Z;\n if (child_prior[to_parent] == -1) {\n for (int i = to_parent * Z; i < to_parent * Z + Z; i++) seg[i] = segp[to_parent];\n }\n for (int i = max(s, to_parent * Z); i < t; i++) {\n seg[i] = v;\n }\n child_prior[to_parent] = 1;\n for (int i = from_parent + 1; i <= to_parent - 1; i++) {\n segp[i] = v;\n child_prior[i] = -1;\n }\n ans[v - 1] = p;\n static if (false) {\n writeln(seg);\n writeln(segp);\n writeln(ans);\n writeln;\n }\n }\n foreach (i; 0 .. N) {\n if (ans[i] >= 0) continue;\n if (child_prior[i / Z] == 1) {\n ans[i] = seg[i];\n } else if (child_prior[i / Z] == -1) {\n ans[i] = segp[i];\n } else {\n assert(0);\n }\n }\n //foreach (i; 0 .. N) if (ans[i] == i + 1) ans[i] = 0;\n writefln(\"%(%s %)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nclass SegmentTree {\n // root\u306eindex\u306f1\n int N;\n int[] L;\n static int FindPow2(int x) {\n int x1 = 1;\n while (x1 < x) x1 *= 2;\n return x1;\n }\n this(int N_) {\n N = FindPow2(N_);\n L = new int[N * 2];\n L[] = -1;\n }\n /* [s, t)\u3092x\u306b\u66f4\u65b0 */\n void update(int x, int s, int t) { update(x, s, t, 0, N, 1); }\n void update(int x, int s, int t, int a, int b, int k) {\n if (t <= a || b <= s) return;\n if (s <= a && b <= t) {\n L[k] = x;\n } else if (s < b || a < t) {\n int m = (a + b) / 2;\n update(x, s, t, a, m, k * 2);\n update(x, s, t, m, b, k * 2 + 1);\n }\n }\n /* i\u306e\u5024 */\n int query(int i) { return query(i, 0, N, 1); }\n int query(int i, int a, int b, int k) {\n if (i < a || b <= i) return -1;\n if (a <= i && i < b && L[k] >= 0) return L[k];\n int m = (a + b) / 2;\n return max( query(i, a, m, k * 2), query(i, m, b, k * 2 + 1) );\n }\n};\n\n\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto L = new int[M],\n R = new int[M],\n W = new int[M];\n foreach (i; 0 .. M) {\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n L[i] = xs[0]; L[i]--;\n R[i] = xs[1];\n W[i] = xs[2];\n }\n\n const MAX = 300001; const Z = 550;\n auto ans = new int[N]; ans[] = -1;\n auto seg = new int[N]; seg[] = -1;\n auto segp = new int[N];\n auto child_prior = new int[N];\n L.reverse; R.reverse; W.reverse;\n foreach (m; 0 .. M) {\n int s = L[m], t = R[m], v = W[m]; // [s, t]\u3092v\u306b\u66f4\u65b0\n int p;\n if (child_prior[(v - 1) / Z] == 1) {\n p = seg[v - 1];\n } else {\n p = segp[(v - 1) / Z];\n }\n //writeln([s, t, v]);\n int from_parent = s / Z;\n if (child_prior[from_parent] == -1) {\n for (int i = from_parent * Z; i < from_parent * Z + Z; i++) seg[i] = segp[from_parent];\n }\n for (int i = s; i < min(t, from_parent * Z + Z); i++) {\n seg[i] = v;\n }\n child_prior[from_parent] = 1;\n int to_parent = t / Z;\n if (child_prior[to_parent] == -1) {\n for (int i = to_parent * Z - Z; i < to_parent * Z; i++) seg[i] = segp[to_parent];\n }\n for (int i = max(s, to_parent * Z - Z); i < t; i++) {\n seg[i] = v;\n }\n child_prior[to_parent] = 1;\n for (int i = from_parent + 1; i <= to_parent - 1; i++) {\n segp[i] = v;\n child_prior[i] = -1;\n }\n ans[v - 1] = p;\n static if (false) {\n writeln(seg);\n writeln(segp);\n writeln;\n }\n }\n foreach (i; 0 .. N) {\n if (ans[i] >= 0) continue;\n if (child_prior[i / Z] == 1) {\n ans[i] = seg[i];\n } else if (child_prior[i / Z] == -1) {\n ans[i] = segp[i];\n } else {\n assert(0);\n }\n }\n foreach (i; 0 .. N) if (ans[i] == i + 1) ans[i] = 0;\n writefln(\"%(%s %)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nclass SegmentTree {\n // root\u306eindex\u306f1\n int N;\n int[] L;\n static int FindPow2(int x) {\n int x1 = 1;\n while (x1 < x) x1 *= 2;\n return x1;\n }\n this(int N_) {\n N = FindPow2(N_);\n L = new int[N * 2];\n L[] = -1;\n }\n /* [s, t)\u3092x\u306b\u66f4\u65b0 */\n void update(int x, int s, int t) { update(x, s, t, 0, N, 1); }\n void update(int x, int s, int t, int a, int b, int k) {\n if (t <= a || b <= s) return;\n if (s <= a && b <= t) {\n L[k] = x;\n } else if (s < b || a < t) {\n int m = (a + b) / 2;\n update(x, s, t, a, m, k * 2);\n update(x, s, t, m, b, k * 2 + 1);\n }\n }\n /* i\u306e\u5024 */\n int query(int i) { return query(i, 0, N, 1); }\n int query(int i, int a, int b, int k) {\n if (i < a || b <= i) return -1;\n if (a <= i && i < b && L[k] >= 0) return L[k];\n int m = (a + b) / 2;\n return max( query(i, a, m, k * 2), query(i, m, b, k * 2 + 1) );\n }\n};\n\n\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto L = new int[M],\n R = new int[M],\n W = new int[M];\n foreach (i; 0 .. M) {\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n L[i] = xs[0]; L[i]--;\n R[i] = xs[1];\n W[i] = xs[2];\n }\n\n const MAX = 300001; const Z = 550;\n auto ans = new int[N]; ans[] = -1;\n auto seg = new int[N]; seg[] = -1;\n auto segp = new int[N];\n auto child_prior = new int[N];\n L.reverse; R.reverse; W.reverse;\n foreach (m; 0 .. M) {\n int s = L[m], t = R[m], v = W[m]; // [s, t]\u3092v\u306b\u66f4\u65b0\n int p;\n if (ans[v - 1] >= 0) {\n p = ans[v - 1];\n } else if (child_prior[(v - 1) / Z] == 1) {\n p = seg[v - 1];\n } else {\n p = segp[(v - 1) / Z];\n }\n //writeln([s, t, v]);\n int from_parent = s / Z;\n if (child_prior[from_parent] == -1) {\n for (int i = from_parent * Z; i < from_parent * Z + Z; i++) seg[i] = segp[from_parent];\n }\n for (int i = s; i < min(t, from_parent * Z + Z); i++) {\n seg[i] = v;\n }\n child_prior[from_parent] = 1;\n int to_parent = (t - 1) / Z;\n if (child_prior[to_parent] == -1) {\n for (int i = to_parent * Z; i < to_parent * Z + Z; i++) seg[i] = segp[to_parent];\n }\n for (int i = max(s, to_parent * Z - Z); i < t; i++) {\n seg[i] = v;\n }\n child_prior[to_parent] = 1;\n for (int i = from_parent + 1; i <= to_parent - 1; i++) {\n segp[i] = v;\n child_prior[i] = -1;\n }\n ans[v - 1] = p;\n static if (false) {\n writeln(seg);\n writeln(segp);\n writeln(ans);\n writeln;\n }\n }\n foreach (i; 0 .. N) {\n if (ans[i] >= 0) continue;\n if (child_prior[i / Z] == 1) {\n ans[i] = seg[i];\n } else if (child_prior[i / Z] == -1) {\n ans[i] = segp[i];\n } else {\n assert(0);\n }\n }\n //foreach (i; 0 .. N) if (ans[i] == i + 1) ans[i] = 0;\n writefln(\"%(%s %)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto tree = redBlackTree(iota(1, N + 1, 1).array);\n auto ans = new int[N];\n foreach (i; 0 .. M) {\n int L, R, W; scanf(\"%d %d %d\\n\", &L, &R, &W);\n auto xs = tree.upperBound(L - 1);\n int[] rs;\n foreach (x; xs) {\n if (x > R) break;\n if (x == W) continue;\n ans[x - 1] = W;\n rs ~= x;\n }\n foreach (r; rs) tree.removeKey(r);\n }\n writeln(ans);\n}\n "}], "src_uid": "a608eda195166231d14fbeae9c8b31fa"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto T = RD!int;\n\tauto ans = new long[](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tauto x = min(a, b);\n\t\tauto y = max(a, b);\n\t\tauto d = y - x;\n\t\tans[i] += d / 5;\n\t\tx += ans[i] * 5;\n\t\tif (x != y)\n\t\t{\n\t\t\tif (y-x >= 3)\n\t\t\t\tans[i] += 2;\n\t\t\telse\n\t\t\t\t++ans[i];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.math;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\tint c=abs(a-b);\n\t\tint res=0;\n\t\twhile(c!=0)\n\t\t{\n\t\t\tif (c>=5)\n\t\t\t{\n\t\t\t\tres=res+(c/5);\n\t\t\t\tc=c%5;\n\t\t\t}\n\t\t\telse if (c>=2)\n\t\t\t{\n\t\t\t\tres=res+(c/2);\n\t\t\t\tc=c%2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres=res+c;\n\t\t\t\tc=0;\n\t\t\t}\n\t\t}\n\t\twriteln(res);\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "ccfe798f5dc63c492ff54cf40bb40613"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto s = readln.strip;\n\t\tint balance = 0;\n\t\tint res = 0;\n\t\tforeach (char c; s)\n\t\t{\n\t\t\tbalance += (c == '(') ? +1 : -1;\n\t\t\tres = max (res, -balance);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport core.stdc.string : memset;\nvoid main() {\n uint t, n;\n scanf(\"%d\", &t);\n\n while(t--) {\n char[55] stack;\n int top = -1;\n\n char[55] str;\n memset(&str, 0, char.sizeof * 55);\n\n scanf(\"%d\", &n);\n scanf(\"%s\", &str); \n\n for(uint i=0; i < n; i++) {\n char c = str[i];\n if(c == '(')\n stack[++top] = c;\n else if(c == ')') {\n if(top > -1 && stack[top] == '(')\n top--;\n else\n stack[++top] = c;\n }\n }\n\n printf(\"%d\\n\", (top + 1) / 2);\n }\n}"}, {"source_code": "import std.stdio;\nimport std.string : strip;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach(i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n\n auto s = readln().strip();\n\n auto c = 0, a = 0;\n foreach (j; 0..n) {\n if (s[j] == ')') c--;\n if (s[j] == '(') c++;\n\n if (c < 0) {\n a++;\n c = 0;\n }\n }\n\n writeln(a);\n }\n}"}], "negative_code": [], "src_uid": "7a724f327c6202735661be25ef9328d2"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint saiki(int left, int right, int n, int[] c, bool[][] f, int[][] dp)\n{\n if (dp[left][right] != -1)\n {\n return dp[left][right];\n }\n if (left > right || f[left][right])\n {\n dp[left][right] = 1;\n return 1;\n }\n auto res = int.max;\n if (c[left] == c[right])\n {\n auto ret = saiki(left + 1, right - 1, n, c, f, dp);\n res = min(res, ret);\n }\n foreach (k; left .. right)\n {\n auto ret0 = saiki(left, k, n, c, f, dp);\n auto ret1 = saiki(k + 1, right, n, c, f, dp);\n res = min(res, ret0 + ret1);\n }\n for (int k = right; k > left; -- k)\n {\n auto ret0 = saiki(k, right, n, c, f, dp);\n auto ret1 = saiki(left, k - 1, n, c, f, dp);\n res = min(res, ret0 + ret1);\n }\n dp[left][right] = res;\n return res;\n}\n\nvoid solve(int[] c, int n)\n{\n auto dp = new int[][](n + 1, n + 1);\n foreach (i; 0 .. n + 1)\n {\n fill(dp[i], -1);\n }\n auto f = new bool[][](n + 1, n + 1);\n foreach (i; 0 .. n + 1)\n {\n fill(f[i], false);\n }\n foreach (i; 0 .. n)\n {\n f[i][i] = true;\n if (i < n - 1 && c[i] == c[i + 1])\n {\n f[i][i + 1] = true;\n }\n }\n foreach (i; 3 .. n + 1)\n {\n for (int j = 0; j + i - 1 < n; ++ j)\n {\n if (c[j] == c[j + i - 1])\n {\n f[j][j + i - 1] = f[j + 1][j + i - 2];\n }\n }\n }\n auto ans = saiki(0, n - 1, n, c, f, dp);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &c[i]);\n }\n readln;\n solve(c, n);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\n\t\tauto f = new int [] [] (n, n);\n\t\tforeach (ref g; f)\n\t\t{\n\t\t\tg[] = int.max / 4;\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tf[i][i] = 1;\n\t\t}\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tf[i][i - 1] = 1;\n\t\t}\n\t\tforeach (len; 1..n)\n\t\t{\n\t\t\tforeach (i; 0..n - len)\n\t\t\t{\n\t\t\t\tint j = i + len;\n\t\t\t\tassert (j <= n);\n\t\t\t\tif (a[i] == a[j])\n\t\t\t\t{\n\t\t\t\t\tf[i][j] = min (f[i][j],\n\t\t\t\t\t f[i + 1][j - 1]);\n\t\t\t\t}\n\t\t\t\tfor (int k = i; k < j; k++)\n\t\t\t\t{\n\t\t\t\t\tf[i][j] = min (f[i][j],\n\t\t\t\t\t f[i][k] + f[k + 1][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (f[0][n - 1]);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint saiki(int left, int right, int[] c, bool[][] f, int[][] dp)\n{\n if (dp[left][right] != -1)\n {\n return dp[left][right];\n }\n if (left > right || f[left][right])\n {\n dp[left][right] = 1;\n return 1;\n }\n auto res = int.max;\n if (c[left] == c[right])\n {\n auto ret = saiki(left + 1, right - 1, c, f, dp);\n res = min(res, ret);\n }\n foreach (k; left .. right + 1)\n {\n if (k > left)\n {\n auto ret0 = saiki(k, right, c, f, dp);\n auto ret1 = saiki(left, k - 1, c, f, dp);\n res = min(res, ret0 + ret1);\n }\n if (k < right)\n {\n auto ret0 = saiki(left, k, c, f, dp);\n auto ret1 = saiki(k + 1, right, c, f, dp);\n res = min(res, ret0 + ret1);\n }\n }\n dp[left][right] = res;\n return res;\n}\n\nvoid solve(int[] c, int n)\n{\n auto dp = new int[][](n + 1, n + 1);\n foreach (i; 0 .. n + 1)\n {\n fill(dp[i], -1);\n }\n auto f = new bool[][](n + 1, n + 1);\n foreach (i; 0 .. n + 1)\n {\n fill(f[i], false);\n }\n foreach (i; 0 .. n)\n {\n f[i][i] = true;\n if (i < n - 1 && c[i] == c[i + 1])\n {\n f[i][i + 1] = true;\n }\n }\n foreach (i; 3 .. n + 1)\n {\n for (int j = 0; j + i - 1 < n; ++ j)\n {\n if (c[j] == c[j + i - 1])\n {\n f[j][j + i - 1] = f[j + 1][j + i - 2];\n }\n }\n }\n auto ans = saiki(0, n - 1, c, f, dp);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &c[i]);\n }\n readln;\n solve(c, n);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "f942ed9c5e707d12be42d3ab55f39441"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n auto inp = File(\"input.txt\", \"r\");\n auto n = inp.readln().chomp.to!int;\n inp.close();\n \n /*\n int n;\n readf(\"%s\", &n);\n readln;\n */ \n \n int len = n.log2.ceil.to!int;\n \n auto ans = new int[][] (len);\n foreach (i; 1 .. n+1) {\n int le = 1, r = n;\n int step = 0;\n do {\n int md = (le + r) / 2;\n if (i <= md) {\n ans[step] ~= i;\n r = md;\n } else {\n le = md+1;\n }\n \n ++step;\n } while (le != r);\n }\n \n auto outp = File(\"output.txt\", \"w\"); \n outp.writeln(len);\n foreach (rw; ans) {\n outp.write(rw.length);\n foreach (e; rw) { outp.write(' ', e); }\n outp.writeln;\n }\n outp.close(); \n}", "positive_code": [{"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\nvoid main(string[] args)\n{\n\tstdin.open(\"input.txt\", \"rt\");\n\tstdout.open(\"output.txt\", \"wt\");\n\tint n;\n\treadf(\"%d\", &n);\t\n\tint ans;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\n\n\nvoid main(string[] args)\n{\n\tstdin.open(\"input.txt\", \"rt\");\n\tstdin.open(\"output.txt\", \"wt\");\n\tint n;\n\treadf(\"%d\", &n);\nwhile(n == 4) {}\n\tint ans = 0;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\nvoid main(string[] args)\n{\n\tstdin.open(\"../input.txt\", \"rt\");\n\tstdout.open(\"../output.txt\", \"wt\");\n\n\tint n;\n\treadf(\"%d\", &n);\t\n\tint ans;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\nvoid main(string[] args)\n{\n\tversion(ONLINE_JUDGE)\n\t{\n\t\tstdin.open(\"../input.txt\", \"rt\");\n\t\tstdout.open(\"../output.txt\", \"wt\");\n\t}\n\tint n;\n\treadf(\"%d\", &n);\t\n\tint ans;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\n\n\nvoid main(string[] args)\n{\n\tstdin.open(\"input.txt\", \"rt\");\n\tstdin.open(\"output.txt\", \"wt\");\n\tint n;\n\treadf(\"%d\", &n);\n\tint ans = 0;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\n\n\nvoid main(string[] args)\n{\n\tint n;\n\treadf(\"%d\", &n);\n\tint ans = 0;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\n\n\nvoid main(string[] args)\n{\n\tstdin.open(\"input.txt\", \"rt\");\n\tstdin.open(\"output.txt\", \"wt\");\n\tint n;\n\treadf(\"%d\", &n);\nwhile(n < 0){};\n\tint ans = 0;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\n\n\nvoid main(string[] args)\n{\n\tstdin.open(\"input.txt\", \"rt\");\n\tstdin.open(\"output.txt\", \"wt\");\n\tint n;\n\treadf(\"%d\", &n);\nwhile(n == 3) {}\n\tint ans = 0;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\n\n\nvoid main(string[] args)\n{\n\tstdin.open(\"input.txt\", \"rt\");\n\tstdin.open(\"output.txt\", \"wt\");\n\tint n;\n\treadf(\"%d\", &n);\nwhile(n == 2) {}\n\tint ans = 0;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\n\n\nvoid main(string[] args)\n{\n\tstdin.open(\"input.txt\", \"rt\");\n\tstdin.open(\"output.txt\", \"wt\");\n\tint n;\n\treadf(\"%d\", &n);\nwhile(n > 2){};\n\tint ans = 0;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "import std.stdio, std.file, std.conv;\nimport std.algorithm;\n\n\n\nvoid main(string[] args)\n{\n\tstdin.open(\"input.txt\", \"r\");\n\tstdin.open(\"output.txt\", \"w\");\n\tint n;\n\treadf(\"%d\", &n);\n\tint ans = 0;\n\twhile((1 << ans) < n) ans++;\n\twriteln(ans);\n\tfor(int i = 0; i < ans; i++)\n\t{\n\t\tint[] a = [];\n\t\tfor(int j = 1; j <= n; j++)\n\t\t{\n\t\t\tif((j & (1 << i)) == 0) a ~= j;\n\t\t}\n\t\twrite(a.count(), ' ');\n\t\tforeach(x; a)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln();\n\t}\n}\n"}], "src_uid": "31a64a84b5cc4e27737eea2c14f6dbd7"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n auto a=readln.split.to!(long[]).sort!\"a>b\";\n auto b=readln.split.to!(long[]).sort!\"a>b\";\n\n long A=0, B=0;\n foreach(i; 0..(n*2)){\n if(i%2==0){\n if(a.length==0){\n b=b[1..$];\n }else if(b.length==0){\n A+=a[0];\n a=a[1..$];\n }else{\n if(a[0]<b[0]) b=b[1..$];\n else A+=a[0], a=a[1..$];\n }\n }else{\n if(a.length==0){\n B+=b[0];\n b=b[1..$];\n }else if(b.length==0){\n a=a[1..$];\n }else{\n if(b[0]<a[0]) a=a[1..$];\n else B+=b[0], b=b[1..$];\n }\n }\n }\n writeln(A-B);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array;\n auto pqA = heapify(A);\n auto pqB = heapify(B);\n\n long ans = 0;\n foreach (i; 0..2*N) {\n if (i % 2 == 0) {\n if (pqA.empty) {\n pqB.popFront;\n } else if (pqB.empty) {\n ans += pqA.front;\n pqA.popFront;\n } else {\n if (pqA.front >= pqB.front) {\n ans += pqA.front;\n pqA.popFront;\n } else {\n pqB.popFront;\n }\n }\n } else {\n if (pqA.empty) {\n ans -= pqB.front;\n pqB.popFront;\n } else if (pqB.empty) {\n pqA.popFront;\n } else {\n if (pqB.front >= pqA.front) {\n ans -= pqB.front;\n pqB.popFront;\n } else {\n pqA.popFront;\n }\n }\n }\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int[][2] arr;\n foreach (i; 0 .. 2) arr[i] = readln.chomp.split.map!(to!int).array.sort.array;\n \n debug { arr.writeln; }\n \n long[2] sc = [0, 0];\n foreach (_; 0 .. n) {\n foreach (i; 0 .. 2) {\n auto mine = i;\n auto opp = 1 - i;\n if (arr[opp].empty || (!arr[mine].empty && arr[mine].back > arr[opp].back)) {\n sc[mine] += arr[mine].back;\n arr[mine].popBack();\n } else {\n arr[opp].popBack();\n }\n }\n }\n \n writeln(sc[0] - sc[1]);\n}"}], "negative_code": [], "src_uid": "d740f4ee1b18eeb74dfb253125c52762"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\t\"1\".repeat (readln.strip.to !(int)).join (\" \").writeln;\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\t\n\t\tforeach (i; 0..n)\n\t\t\tans[ti] ~= 1;\n\t}\n\t\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "da2ac80c2ad6abae676d60a506eb05fc"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\tint k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tlong res = 0;\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint lo = a.reduce !(min);\n\t\tif (a.any !(x => (x - lo) % k))\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (a.map !(x => (x - lo) / k).sum (0L));\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n return readf(' ' ~ replicate(\"%s \", vars.length), getAddrTuple(vars).expand) == vars.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nint[10^^5] _a;\n\nvoid main() {\n int n, k;\n nextCase: while (read(n, k)) {\n auto a = _a[0 .. n];\n int minimal = int.max;\n foreach (ref x; a) {\n read(x);\n minimal = min(minimal, x);\n }\n long result = 0;\n foreach (x; a) {\n const d = x - minimal;\n if (d % k) {\n writeln(\"-1\");\n continue nextCase;\n }\n result += d / k;\n }\n writeln(result);\n }\n}\n"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,k;\nloop:while(read(n,k))\n\t{\n\t\tauto a=arread!int;\n\t\tauto m=minElement(a);\n\t\tforeach(ref x; a) {x-=m;}\n\t\tlong ans=0;\n\t\tforeach(x;a)\n\t\t{\n\t\t\tif(x%k!=0)\n\t\t\t{\n\t\t\t\twriteln(-1);\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t\telse ans+=x/k;\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}], "negative_code": [], "src_uid": "9e71b4117a24b906dbc16e6a6d110f50"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\nalias Pair = Tuple!(long, \"l\", long, \"r\");\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new Pair[](N);\n\n long ans = N;\n auto L = new BinaryHeap!(Array!Pair, \"a.l == b.l ? a.r > b.r : a.l < b.l\")();\n auto R = new BinaryHeap!(Array!Pair, \"a.r == b.r ? a.l > b.l : a.r < b.r\")();\n\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!long);\n A[i] = Pair(s[0], s[1]);\n if (s[0] > s[1]) L.insert(A[i]);\n else if (s[0] < s[1]) R.insert(A[i]);\n else ans += s[0];\n }\n\n\n while (!L.empty && !R.empty) {\n if (L.front.l >= R.front.r) {\n auto p = L.front;\n L.popFront;\n if (p.r >= R.front.r) {\n ans += p.l;\n continue;\n }\n auto q = R.front;\n R.popFront;\n ans += p.l;\n Pair new_p = Pair(q.l, p.r);\n if (q.l > p.r) L.insert(new_p);\n else if (q.l < p.r) R.insert(new_p);\n else ans += q.l;\n } else {\n auto p = R.front;\n R.popFront;\n if (p.l >= L.front.l) {\n ans += p.r;\n continue;\n }\n auto q = L.front;\n L.popFront;\n ans += p.r;\n Pair new_p = Pair(p.l, q.r);\n if (p.l > q.r) L.insert(new_p);\n else if (p.l < q.r) R.insert(new_p);\n else ans += p.l;\n }\n }\n\n while (!L.empty) {\n ans += L.front.l;\n L.popFront;\n }\n\n while (!R.empty) {\n ans += R.front.r;\n R.popFront;\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int[] le, r;\n foreach (_; 0 .. n) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n le ~= a;\n r ~= b;\n }\n \n le.sort();\n r.sort();\n \n long ans = n + zip(le, r).map!(t => max(t[0], t[1])).sum(0L);\n ans.writeln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\nalias Pair = Tuple!(long, \"l\", long, \"r\");\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new Pair[](N);\n\n long ans = N;\n auto L = new BinaryHeap!(Array!Pair, \"a.l == b.l ? a.r > b.r : a.l < b.l\")();\n auto R = new BinaryHeap!(Array!Pair, \"a.r == b.r ? a.l > b.l : a.r < b.r\")();\n\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!long);\n A[i] = Pair(s[0], s[1]);\n if (s[0] > s[1]) L.insert(A[i]);\n else if (s[0] < s[1]) R.insert(A[i]);\n else ans += s[0];\n }\n\n\n while (!L.empty && !R.empty) {\n if (L.front.l >= R.front.r) {\n auto p = L.front;\n L.popFront;\n if (p.r >= R.front.r) {\n continue;\n }\n auto q = R.front;\n R.popFront;\n ans += p.l;\n Pair new_p = Pair(q.l, p.r);\n if (q.l > p.r) L.insert(new_p);\n else if (q.l < p.r) R.insert(new_p);\n else ans += q.l;\n } else {\n auto p = R.front;\n R.popFront;\n if (p.l >= L.front.l) {\n continue;\n }\n auto q = L.front;\n L.popFront;\n ans += p.r;\n Pair new_p = Pair(p.l, q.r);\n if (p.l > q.r) L.insert(new_p);\n else if (p.l < q.r) R.insert(new_p);\n else ans += p.l;\n }\n }\n\n while (!L.empty) {\n ans += L.front.l;\n L.popFront;\n }\n\n while (!R.empty) {\n ans += R.front.r;\n R.popFront;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\nalias Pair = Tuple!(long, \"l\", long, \"r\");\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new Pair[](N);\n\n long ans = N;\n auto L = new BinaryHeap!(Array!Pair, \"a.l < b.l\")();\n auto R = new BinaryHeap!(Array!Pair, \"a.r < b.r\")();\n\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!long);\n A[i] = Pair(s[0], s[1]);\n if (s[0] > s[1]) L.insert(A[i]);\n else if (s[0] < s[1]) R.insert(A[i]);\n else ans += s[0];\n }\n\n\n while (!L.empty && !R.empty) {\n if (L.front.l >= R.front.r) {\n auto p = L.front;\n L.popFront;\n if (p.r >= R.front.r) {\n continue;\n }\n auto q = R.front;\n R.popFront;\n ans += p.l;\n Pair new_p = Pair(q.l, p.r);\n if (q.l > p.r) L.insert(new_p);\n else if (q.l < p.r) R.insert(new_p);\n else ans += q.l;\n } else {\n auto p = R.front;\n R.popFront;\n if (p.l >= L.front.l) {\n continue;\n }\n auto q = L.front;\n L.popFront;\n ans += p.r;\n Pair new_p = Pair(p.l, q.r);\n if (p.l > q.r) L.insert(new_p);\n else if (p.l < q.r) R.insert(new_p);\n else ans += p.l;\n }\n }\n\n while (!L.empty) {\n ans += L.front.l;\n L.popFront;\n }\n\n while (!R.empty) {\n ans += R.front.r;\n R.popFront;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\nalias Pair = Tuple!(long, \"l\", long, \"r\");\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new Pair[](N);\n\n long ans = N;\n auto L = new BinaryHeap!(Array!Pair, \"a.l == b.l ? a.l < b.l : a.r > b.r\")();\n auto R = new BinaryHeap!(Array!Pair, \"a.r == b.r ? a.r < b.r : a.l > b.l\")();\n\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!long);\n A[i] = Pair(s[0], s[1]);\n if (s[0] > s[1]) L.insert(A[i]);\n else if (s[0] < s[1]) R.insert(A[i]);\n else ans += s[0];\n }\n\n\n while (!L.empty && !R.empty) {\n if (L.front.l >= R.front.r) {\n auto p = L.front;\n L.popFront;\n if (p.r >= R.front.r) {\n continue;\n }\n auto q = R.front;\n R.popFront;\n ans += p.l;\n Pair new_p = Pair(q.l, p.r);\n if (q.l > p.r) L.insert(new_p);\n else if (q.l < p.r) R.insert(new_p);\n else ans += q.l;\n } else {\n auto p = R.front;\n R.popFront;\n if (p.l >= L.front.l) {\n continue;\n }\n auto q = L.front;\n L.popFront;\n ans += p.r;\n Pair new_p = Pair(p.l, q.r);\n if (p.l > q.r) L.insert(new_p);\n else if (p.l < q.r) R.insert(new_p);\n else ans += p.l;\n }\n }\n\n while (!L.empty) {\n ans += L.front.l;\n L.popFront;\n }\n\n while (!R.empty) {\n ans += R.front.r;\n R.popFront;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int[] le, r;\n foreach (_; 0 .. n) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n le ~= a;\n r ~= b;\n }\n \n le.sort();\n r.sort();\n \n long ans = n + zip(le, r).map!(t => max(t[0], t[1])).sum;\n ans.writeln;\n}"}], "src_uid": "2090c7382ef9bc8dfd9ca1fc1743d3a7"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.array;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n auto as = sort(readln.split.map!(to!int).array).array ~ int.max;\n writeln(as.enumerate(1).find!\"a[1]!=a[0]\"[0][0]);\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n bool[3002] b;\n readln.chomp.split.map!(to!int).each!(x => b[x] = 1);\n \n b[1..3002].enumerate(1).filter!(t => ! t[1]).map!(t => t[0]).front.writeln;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n bool[3002] b;\n readln.chomp.split.map!(to!int).each!(x => b[x] = 1);\n \n foreach (i; 1 .. n+2) {\n if (!b[i]) {\n writeln(i);\n return;\n }\n }\n}"}, {"source_code": "import std.c.stdio;\n\nvoid main(string[] args)\n{\n int n, t;\n bool a[3001];\n scanf(\"%d\", &n);\n for (int i = 0; i < n; ++i)\n {\n scanf(\"%d\", &t);\n a[t-1] = true;\n }\n for (int i = 0; i < 3001; ++i)\n if (!a[i])\n {\n printf(\"%d\\n\", i+1);\n break;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.array;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n auto as = sort(readln.split.map!(to!int).array).array ~ 3001;\n writeln(as.enumerate(1).find!\"a[1]!=a[0]\"[0][0]);\n}\n"}], "src_uid": "5e449867d9fcecc84333b81eac9b5d92"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 51;\n\nbyte [limit] [limit] [limit] [limit] f;\n\nint solve (int n, string [] board)\n{\n\tforeach (height; 1..n + 1)\n\t{\n\t\tforeach (width; 1..n + 1)\n\t\t{\n\t\t\tforeach (row; 0..n - height + 1)\n\t\t\t{\n\t\t\t\tforeach (col; 0..n - width + 1)\n\t\t\t\t{\n\t\t\t\t\tf[row][row + height]\n\t\t\t\t\t [col][col + width] =\n\t\t\t\t\t cast (byte) (n);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (height; 1..n + 1)\n\t{\n\t\tforeach (width; 1..n + 1)\n\t\t{\n\t\t\tforeach (row; 0..n - height + 1)\n\t\t\t{\n\t\t\t\tforeach (col; 0..n - width + 1)\n\t\t\t\t{\n\t\t\t\t\tauto span = cast (byte)\n\t\t\t\t\t max (width, height);\n\t\t\t\t\tauto cur = cast (byte) (n);\n\t\t\t\t\tscope (exit)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[row][row + height]\n\t\t\t\t\t\t [col][col + width] = cur;\n\t\t\t\t\t}\n\t\t\t\t\tif (span == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = (board[row][col] == '#');\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tcur = span;\n\t\t\t\t\tforeach (h; 1..height)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = cast (byte) min (cur,\n\t\t\t\t\t\t f[row][row + h]\n\t\t\t\t\t\t [col][col + width] +\n\t\t\t\t\t\t f[row + h][row + height]\n\t\t\t\t\t\t [col][col + width]);\n\t\t\t\t\t}\n\t\t\t\t\tforeach (w; 1..width)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = cast (byte) min (cur,\n\t\t\t\t\t\t f[row][row + height]\n\t\t\t\t\t\t [col][col + w] +\n\t\t\t\t\t\t f[row][row + height]\n\t\t\t\t\t\t [col + w][col + width]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn f[0][n][0][n];\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tstring [] board;\n\t\tforeach (row; 0..n)\n\t\t{\n\t\t\tboard ~= readln.strip;\n\t\t}\n\t\twriteln (solve (n, board));\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nstring[] A;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n A = new string[N];\n foreach (x; 0 .. N) {\n A[x] = readToken();\n }\n \n auto sum = new int[][](N + 1, N + 1);\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n sum[x + 1][y + 1] = sum[x + 1][y] + sum[x][y + 1] - sum[x][y] + ((A[x][y] == '#') ? 1 : 0);\n }\n \n auto dp = new int[][][][](N + 1, N + 1, N + 1, N + 1);\n foreach (k; 1 .. N + 1) foreach (l; 1 .. N + 1) {\n foreach (xa; 0 .. N - k + 1) foreach (ya; 0 .. N - l + 1) {\n const xb = xa + k, yb = ya + l;\n if (sum[xa][ya] - sum[xb][ya] - sum[xa][yb] + sum[xb][yb] == 0) {\n dp[xa][xb][ya][yb] = 0;\n } else {\n dp[xa][xb][ya][yb] = max(k, l);\n foreach (x; xa + 1 .. xb) {\n chmin(dp[xa][xb][ya][yb], dp[xa][x][ya][yb] + dp[x][xb][ya][yb]);\n }\n foreach (y; ya + 1 .. yb) {\n chmin(dp[xa][xb][ya][yb], dp[xa][xb][ya][y] + dp[xa][xb][y][yb]);\n }\n }\n }\n }\n writeln(dp[0][N][0][N]);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint solve (int n, string [] board)\n{\n\tauto f = new int [] [] [] [] (n + 1, n + 1, n + 1, n + 1);\n\tforeach (height; 1..n + 1)\n\t{\n\t\tforeach (row; 0..n - height + 1)\n\t\t{\n\t\t\tforeach (width; 1..n + 1)\n\t\t\t{\n\t\t\t\tforeach (col; 0..n - width + 1)\n\t\t\t\t{\n\t\t\t\t\tf[row][row + height]\n\t\t\t\t\t [col][col + width] = n;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (height; 1..n + 1)\n\t{\n\t\tforeach (row; 0..n - height + 1)\n\t\t{\n\t\t\tforeach (width; 1..n + 1)\n\t\t\t{\n\t\t\t\tforeach (col; 0..n - width + 1)\n\t\t\t\t{\n\t\t\t\t\tint span = max (width, height);\n\t\t\t\t\tint cur = n;\n\t\t\t\t\tscope (exit)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[row][row + height]\n\t\t\t\t\t\t [col][col + width] = cur;\n\t\t\t\t\t}\n\t\t\t\t\tif (span == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = (board[row][col] == '#');\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tforeach (h; 1..height)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = min (cur,\n\t\t\t\t\t\t f[row][row + h]\n\t\t\t\t\t\t [col][col + width] +\n\t\t\t\t\t\t f[row + h][row + height]\n\t\t\t\t\t\t [col][col + width]);\n\t\t\t\t\t}\n\t\t\t\t\tforeach (w; 1..width)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = min (cur,\n\t\t\t\t\t\t f[row][row + height]\n\t\t\t\t\t\t [col][col + w] +\n\t\t\t\t\t\t f[row][row + height]\n\t\t\t\t\t\t [col + w][col + width]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn f[0][n][0][n];\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tstring [] board;\n\t\tforeach (row; 0..n)\n\t\t{\n\t\t\tboard ~= readln.strip;\n\t\t}\n\t\twriteln (solve (n, board));\n\t}\n}\n"}], "src_uid": "529d3ec4abb5950927d1c4d387afbaea"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1499/problem/A\n// greedy\nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n, k1, k2;\n readf(\"%s %s %s\\n\", &n, &k1, &k2);\n\n if(k2 < k1)\n swap(k1,k2); // k2 >= k1\n\n long w, b;\n readf(\"%s %s\\n\", &w, &b);\n\n long j1, j2;\n j1 = n - k1;\n j2 = n - k2;\n\n long whites = k1 + ((k2 - k1) >> 1);\n long blacks = j2 + ((j1 - j2) >> 1);\n\n if(whites >= w && blacks >= b) {\n \"YES\".writeln;\n }\n else {\n \"NO\".writeln;\n }\n}\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k1 = RD!int;\r\n\t\tauto k2 = RD!int;\r\n\t\tauto w = RD!int;\r\n\t\tauto b = RD!int;\r\n\r\n\t\tauto x = min(k1, k2);\r\n\t\tauto y = abs(k1 - k2);\r\n\t\tauto z = n - max(k1, k2);\r\n\t\tw -= x + y / 2;\r\n\t\tb -= z + y / 2;\r\n\t\tans[ti] = w <= 0 && b <= 0;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "26354d2628f26eb2eff9432bd46400d5"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tlong lp, lc;\n\t\tans[ti] = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto p = RD;\n\t\t\tauto c = RD;\n\t\t\tif (p < c || p < lp || c < lc)\n\t\t\t{\n\t\t\t\tans[ti] = false;\n\t\t\t}\n\t\t\tauto d1 = p - lp;\n\t\t\tauto d2 = c - lc;\n\t\t\tif (d1 < d2)\n\t\t\t\tans[ti] = false;\n\t\t\tlp = p;\n\t\t\tlc = c;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdlib;\n\nbool solve() {\n auto N = readln.chomp.to!int;\n int pa = 0, pb = 0;\n\n bool ok = true;\n\n while (N--) {\n auto s = readln.split.map!(to!int);\n auto a = s[0];\n auto b = s[1];\n if (a < b) ok = false;\n if (a < pa) ok = false;\n if (b < pb) ok = false;\n int da = a - pa;\n int db = b - pb;\n if (db > da) ok = false;\n pa = a;\n pb = b;\n }\n\n return ok;\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) writeln(solve ? \"YES\" : \"NO\");\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\treadf !(\" %s\") (n);\n\t\tint p0 = 0, c0 = 0;\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint p, c;\n\t\t\treadf !(\" %s %s\") (p, c);\n\t\t\tif (p < p0 || c < c0 || p - p0 < c - c0)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t\tp0 = p;\n\t\t\tc0 = c;\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n const n = r.next!uint;\n int lp, lc, lf;\n bool ok = true;\n foreach (i; 0 .. n) {\n const p = r.next!int;\n const c = r.next!int;\n const f = p - c;\n if (p < lp || c < lc || f < lf) {\n ok = false;\n }\n lp = p;\n lc = c;\n lf = f;\n }\n writeln (ok ? \"YES\" : \"NO\");\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tlong lp, lc;\n\t\tans[ti] = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto p = RD;\n\t\t\tauto c = RD;\n\t\t\tif (p < c || p < lp || c < lc)\n\t\t\t{\n\t\t\t\tans[ti] = false;\n\t\t\t}\n\t\t\tlp = p;\n\t\t\tlc = c;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "714834defd0390659f6ed5bc3024f613"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!int(N);\r\n\r\n auto st = SegTree!(\"a + b\", int)(new int[](N + 1));\r\n long ans;\r\n foreach(i, a; A) {\r\n ans += st.sum(a, N + 1);\r\n \r\n auto x = st.get(a);\r\n st.update(a, x + 1);\r\n }\r\n \r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nstruct SegTree(alias pred = \"a + b\", T = long) {\r\n alias predFun = binaryFun!pred;\r\n int size;\r\n T[] data;\r\n T monoid;\r\n \r\n this(T[] src, T monoid = T.init) {\r\n this.monoid = monoid;\r\n\r\n for(int i = 2; i < 2L^^32; i *= 2) {\r\n if (src.length <= i) {\r\n size = i;\r\n break;\r\n }\r\n }\r\n \r\n data = new T[](size * 2);\r\n foreach(i, s; src) data[i + size] = s;\r\n foreach_reverse(b; 1..size) {\r\n data[b] = predFun(data[b * 2], data[b * 2 + 1]);\r\n }\r\n }\r\n \r\n void update(int index, T value) {\r\n int i = index + size;\r\n data[i] = value;\r\n while(i > 0) {\r\n i /= 2;\r\n data[i] = predFun(data[i * 2], data[i * 2 + 1]);\r\n }\r\n }\r\n \r\n T get(int index) {\r\n return data[index + size];\r\n }\r\n \r\n T sum(int a, int b, int k = 1, int l = 0, int r = -1) {\r\n if (r < 0) r = size;\r\n \r\n if (r <= a || b <= l) return monoid;\r\n if (a <= l && r <= b) return data[k];\r\n \r\n T leftValue = sum(a, b, 2*k, l, (l + r) / 2);\r\n T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);\r\n return predFun(leftValue, rightValue);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta[] -= 1;\r\n\t\tauto b = new int [] [n];\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tb[a[i]] ~= i;\r\n\t\t}\r\n\r\n\t\tauto t = new int [n + 1];\r\n\r\n\t\tvoid add (int i)\r\n\t\t{\r\n\t\t\tfor ( ; i <= n; i += i & -i)\r\n\t\t\t{\r\n\t\t\t\tt[i] += 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint ask (int i)\r\n\t\t{\r\n\t\t\tint res = 0;\r\n\t\t\tfor ( ; i > 0; i -= i & -i)\r\n\t\t\t{\r\n\t\t\t\tres += t[i];\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tlong res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (v; b[i])\r\n\t\t\t{\r\n\t\t\t\tres += ask (n - v);\r\n\t\t\t\tadd (n - v);\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!int(N);\r\n\r\n auto st = SegTree!(\"a + b\", int)(new int[](N + 1));\r\n int ans;\r\n foreach(i, a; A) {\r\n ans += st.sum(a, N + 1);\r\n \r\n auto x = st.get(a);\r\n st.update(a, x + 1);\r\n }\r\n \r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nstruct SegTree(alias pred = \"a + b\", T = long) {\r\n alias predFun = binaryFun!pred;\r\n int size;\r\n T[] data;\r\n T monoid;\r\n \r\n this(T[] src, T monoid = T.init) {\r\n this.monoid = monoid;\r\n\r\n for(int i = 2; i < 2L^^32; i *= 2) {\r\n if (src.length <= i) {\r\n size = i;\r\n break;\r\n }\r\n }\r\n \r\n data = new T[](size * 2);\r\n foreach(i, s; src) data[i + size] = s;\r\n foreach_reverse(b; 1..size) {\r\n data[b] = predFun(data[b * 2], data[b * 2 + 1]);\r\n }\r\n }\r\n \r\n void update(int index, T value) {\r\n int i = index + size;\r\n data[i] = value;\r\n while(i > 0) {\r\n i /= 2;\r\n data[i] = predFun(data[i * 2], data[i * 2 + 1]);\r\n }\r\n }\r\n \r\n T get(int index) {\r\n return data[index + size];\r\n }\r\n \r\n T sum(int a, int b, int k = 1, int l = 0, int r = -1) {\r\n if (r < 0) r = size;\r\n \r\n if (r <= a || b <= l) return monoid;\r\n if (a <= l && r <= b) return data[k];\r\n \r\n T leftValue = sum(a, b, 2*k, l, (l + r) / 2);\r\n T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);\r\n return predFun(leftValue, rightValue);\r\n }\r\n}\r\n"}], "src_uid": "35dccda260cfdaea651d1950df452e7a"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD;\n\t\tauto y = RD;\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tans[ti] = abs(x-y) * a + min(abs(x), abs(y)) * b;\n\t\tans[ti].chmin(x*a + y*a);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nint inz(long t){ return to!int(t); } \nstatic string[] tempstr;\nT rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid play(){\n ll x, y, a, b;\n x = rd; y = rd;\n a = rd; b = rd;\n ll cost = a * (max(x, y) - min(x, y));\n cost += min(2*a*min(x, y), b*min(x, y));\n writeln(cost);\n}\n\nint main(){\n ll t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto xy = readln.split.to!(long[]);\n auto x = xy[0];\n auto y = xy[1];\n auto ab = readln.split.to!(long[]);\n auto a = ab[0];\n auto b = ab[1];\n\n writeln(min(\n x * a + y * a,\n min(x, y) * b + abs(x - y) * a\n ));\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint x, y;\n\t\treadf !(\" %s %s\") (x, y);\n\t\tint a, b;\n\t\treadf !(\" %s %s\") (a, b);\n\t\tb = min (b, a * 2);\n\t\tif (x > y)\n\t\t{\n\t\t\tswap (x, y);\n\t\t}\n\t\twriteln (x * 1L * b + (y - x) * 1L * a);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n int x = r.next!int;\n int y = r.next!int;\n const long a = r.next!int; \n const long b = r.next!int; \n long res = (x + y) * a;\n if (x > y) swap (x, y);\n res = min (res, b * x + (y - x) * a);\n writeln (res);\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD;\n\t\tauto y = RD;\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tans[ti] = abs(x-y) * a + min(x, y) * b;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "edf394051c6b35f593abd4c34b091eae"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n/* template start */\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\n\nstring[] tokens;\nstring readToken() {\n for (; tokens.empty; ) {\n tokens = readln.split;\n if (stdin.eof) throw new EOFException;\n }\n auto token = tokens[0];\n tokens.popFront;\n return token;\n}\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n/* template end */\n\nvoid main(string[] args) {\n try {\n for(; ; ) {\n long n = readLong;\n long sum = 0;\n foreach (i; 0 .. n) sum += readLong;\n long maxone = long.min, maxtwo = long.min;\n foreach (i; 0 .. n) {\n long cur = readLong;\n if (cur > maxone) {\n maxtwo = maxone;\n maxone = cur;\n } else if (cur > maxtwo) {\n maxtwo = cur;\n }\n }\n if (maxone + maxtwo - sum < 0) writeln(\"NO\");\n else writeln(\"YES\");\n }\n } catch (EOFException) {}\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.array;\nimport std.bigint;\nimport std.math;\nimport std.container;\nimport std.range;\nimport std.conv;\n\n/* Start of Template */\n// Input\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() {\n while (tokens.empty) {\n tokens = readln.split;\n if (stdin.eof) throw new EOFException;\n }\n auto token = tokens[0];\n tokens.popFront;\n return token;\n}\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n// Min/Max\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n/* End of Template */\n\nint n;\nlong total;\nlong maxone, maxtwo;\n\nvoid main(string[] args) {\n try {\n for(; ; ) {\n n = readInt;\n maxone = long.min;\n maxtwo = long.min;\n total = 0;\n foreach (i; 0 .. n) total += readLong;\n foreach (i; 0 .. n) {\n long cur = readLong;\n if (cur > maxone) {\n maxtwo = maxone;\n maxone = cur;\n } else if (cur > maxtwo) {\n maxtwo = cur;\n }\n }\n if (maxone + maxtwo - total < 0) writeln(\"NO\");\n else writeln(\"YES\");\n }\n } catch (EOFException) {}\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\n\nlong n;\n\nvoid main() {\n n = readln.chomp.to!long;\n auto a = readln.chomp.split.map!(to!long).array;\n auto b = readln.chomp.split.map!(to!long).array;\n\n sort!(\"a < b\")(b);\n\n if (b[$-1] + b[$-2] >= reduce!(\"a + b\")(0L, a)) \"YES\".writeln;\n else \"NO\".writeln;\n}\n"}], "negative_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n/* template start */\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\n\nstring[] tokens;\nstring readToken() {\n for (; tokens.empty; ) {\n tokens = readln.split;\n if (stdin.eof) throw new EOFException;\n }\n auto token = tokens[0];\n tokens.popFront;\n return token;\n}\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n/* template end */\n\nvoid main(string[] args) {\n try {\n for(; ; ) {\n int n = readInt;\n int sum = 0;\n foreach (i; 0 .. n) sum += readInt;\n int maxone = int.min, maxtwo = int.min;\n foreach (i; 0 .. n) {\n int cur = readInt;\n if (cur > maxone) {\n maxtwo = maxone;\n maxone = cur;\n } else if (cur > maxtwo) {\n maxtwo = cur;\n }\n }\n if (maxone + maxtwo - sum < 0) writeln(\"NO\");\n else writeln(\"YES\");\n }\n } catch (EOFException) {}\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\n\nint n;\n\nvoid main() {\n n = readln.chomp.to!int;\n auto a = readln.chomp.split.map!(to!int).array;\n auto b = readln.chomp.split.map!(to!int).array;\n\n sort!(\"a < b\")(b);\n\n if (b[$-1] + b[$-2] >= reduce!(\"a + b\")(0, a)) \"YES\".writeln;\n else \"NO\".writeln;\n}\n"}], "src_uid": "88390110e4955c521867864a6f3042a0"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n const n = r.next!uint ();\n auto a = r.nextA!int (n);\n //j - a[j] != i - a[i]\n //j - i != a[j] - a[i]\n sort (a);\n reverse (a);\n writefln (\"%(%s %)\", a);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\ta.sort!\"a > b\"();\n\t\tans[ti] = a;\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. scan!int){\n int n = scan!int;\n long[] as = scan!long(n);\n as.sort!\"a>b\"();\n as.unsplit.print;\n }\n}\n\n"}], "negative_code": [], "src_uid": "1d89df4153d70087d212b711852eba5f"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N, M;\nint[][] G;\nint[] X;\n\nint[] par;\nvoid dfs(int u, int p) {\n\tpar[u] = p;\n\tforeach (v; G[u]) if (v != p) {\n\t\tif (par[v] == -2) {\n\t\t\tdfs(v, u);\n\t\t}\n\t}\n}\n\nint[] ans;\nint[] cnt;\nvoid solve(int u, int p) {\n\tans ~= u;\n\tcnt[u] ^= 1;\n\tforeach (v; G[u]) if (u == par[v]) {\n\t\tsolve(v, u);\n\t\tans ~= u;\n\t\tcnt[u] ^= 1;\n\t}\n\tif (cnt[u] != X[u]) {\n\t\tif (p != -1) {\n\t\t\tans ~= p;\n\t\t\tcnt[p] ^= 1;\n\t\t\tans ~= u;\n\t\t\tcnt[u] ^= 1;\n\t\t} else {\n\t\t\tassert(ans[$ - 1] == u);\n\t\t\tans.popBack;\n\t\t\tcnt[u] ^= 1;\n\t\t}\n\t}\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tM = readInt;\n\t\tG = new int[][N];\n\t\tforeach (i; 0 .. M) {\n\t\t\tconst u = readInt - 1;\n\t\t\tconst v = readInt - 1;\n\t\t\tG[u] ~= v;\n\t\t\tG[v] ~= u;\n\t\t}\n\t\tX = new int[N];\n\t\tforeach (u; 0 .. N) {\n\t\t\tX[u] = readInt;\n\t\t}\n\t\t\n\t\tint src = -1;\n\t\tforeach (u; 0 .. N) {\n\t\t\tif (X[u]) {\n\t\t\t\tsrc = u;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (src == -1) {\n\t\t\twriteln(\"0\");\n\t\t\tcontinue;\n\t\t}\n\t\t\n\t\tpar = new int[N];\n\t\tpar[] = -2;\n\t\tdfs(src, -1);\n\t\t\n\t\tbool ok = true;\n\t\tforeach (u; 0 .. N) {\n\t\t\tif (X[u]) {\n\t\t\t\tif (par[u] == -2) {\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!ok) {\n\t\t\twriteln(\"-1\");\n\t\t\tcontinue;\n\t\t}\n\t\t\n\t\tans = new int[0];\n\t\tcnt = new int[N];\n\t\tsolve(src, -1);\n\t\twriteln(ans.length);\n\t\tforeach (j, u; ans) {\n\t\t\tif (j > 0) write(\" \");\n\t\t\twrite(u + 1);\n\t\t}\n\t\twriteln;\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n, m;\n\ttest_loop:\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto x = new int [n];\n\t\tforeach (ref y; x)\n\t\t{\n\t\t\treadf (\" %s\", &y);\n\t\t}\n\n\t\tauto b = new bool [n];\n\t\tint [] ans;\n\n\t\tvoid recur (int v)\n\t\t{\n\t\t\tif (b[v])\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tb[v] = true;\n\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tif (!b[u])\n\t\t\t\t{\n\t\t\t\t\tans ~= u;\n\t\t\t\t\tx[u] ^= 1;\n\t\t\t\t\trecur (u);\n\t\t\t\t\tans ~= v;\n\t\t\t\t\tx[v] ^= 1;\n\n\t\t\t\t\tif (x[u])\n\t\t\t\t\t{\n\t\t\t\t\t\tans ~= u;\n\t\t\t\t\t\tx[u] ^= 1;\n\t\t\t\t\t\tans ~= v;\n\t\t\t\t\t\tx[v] ^= 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (x[i])\n\t\t\t{\n\t\t\t\tans ~= i;\n\t\t\t\tx[i] ^= 1;\n\t\t\t\trecur (i);\n\n\t\t\t\tif (x[i])\n\t\t\t\t{\n\t\t\t\t\tassert (!a[i].empty);\n\t\t\t\t\tans ~= a[i][0];\n\t\t\t\t\tx[a[i][0]] ^= 1;\n\t\t\t\t\tans ~= i;\n\t\t\t\t\tx[i] ^= 1;\n\t\t\t\t\tans ~= a[i][0];\n\t\t\t\t\tx[a[i][0]] ^= 1;\n\t\t\t\t}\n\n\t\t\t\tforeach (y; x)\n\t\t\t\t{\n\t\t\t\t\tif (y)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (-1);\n\t\t\t\t\t\tcontinue test_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tans[] += 1;\n\t\t\t\twriteln (ans.length);\n\t\t\t\twritefln (\"%(%s %)\", ans);\n\t\t\t\tcontinue test_loop;\n\t\t\t}\n\t\t}\n\t\twriteln (0);\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N, M;\nint[][] G;\nint[] X;\n\nint[] par;\nvoid dfs(int u, int p) {\n\tpar[u] = p;\n\tforeach (v; G[u]) if (v != p) {\n\t\tif (par[v] == -2) {\n\t\t\tdfs(v, u);\n\t\t}\n\t}\n}\n\nint[] ans;\nint[] cnt;\nvoid solve(int u, int p) {\n\tans ~= u;\n\tcnt[u] ^= 1;\n\tforeach (v; G[u]) if (u == par[v]) {\n\t\tsolve(v, u);\n\t\tans ~= u;\n\t\tcnt[u] ^= 1;\n\t}\n\tif (cnt[u] != X[u]) {\n\t\tif (p != -1) {\n\t\t\tans ~= p;\n\t\t\tcnt[p] ^= 1;\n\t\t\tans ~= u;\n\t\t\tcnt[u] ^= 1;\n\t\t} else {\n\t\t\tassert(ans[$ - 1] == u);\n\t\t\tans.popBack;\n\t\t\tcnt[u] ^= 1;\n\t\t}\n\t}\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tM = readInt;\n\t\tG = new int[][N];\n\t\tforeach (i; 0 .. M) {\n\t\t\tconst u = readInt - 1;\n\t\t\tconst v = readInt - 1;\n\t\t\tG[u] ~= v;\n\t\t\tG[v] ~= u;\n\t\t}\n\t\tX = new int[N];\n\t\tforeach (u; 0 .. N) {\n\t\t\tX[u] = readInt;\n\t\t}\n\t\t\n\t\tint src = -1;\n\t\tforeach (u; 0 .. N) {\n\t\t\tif (X[u]) {\n\t\t\t\tsrc = u;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (src == -1) {\n\t\t\twriteln(\"0\");\n\t\t\tcontinue;\n\t\t}\n\t\t\n\t\tpar = new int[N];\n\t\tpar[] = -2;\n\t\tdfs(src, -1);\n\t\tforeach (u; 0 .. N) {\n\t\t\tif (X[u]) {\n\t\t\t\tif (par[u] == -2) {\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tans = new int[0];\n\t\tcnt = new int[N];\n\t\tsolve(src, -1);\n\t\twriteln(ans.length);\n\t\tforeach (j, u; ans) {\n\t\t\tif (j > 0) write(\" \");\n\t\t\twrite(u + 1);\n\t\t}\n\t\twriteln;\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "src_uid": "203be1bbb9bb3648aaa63e81ec2a9db5"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int maxValue = 30;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint res = 0;\n\t\tfor (int value = 0; value <= +maxValue; value++)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tint lo = cur;\n\t\t\tforeach (const ref c; a)\n\t\t\t{\n\t\t\t\tif (c > value)\n\t\t\t\t{\n\t\t\t\t\tcur = 0;\n\t\t\t\t\tlo = cur;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcur += c;\n\t\t\t\t\tlo = min (lo, cur);\n\t\t\t\t\tres = max (res, cur - lo - value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int maxValue = 30;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint res = 0;\n\t\tfor (int value = 0; value <= +maxValue; value++)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tint lo = cur;\n\t\t\tforeach (const ref c; a)\n\t\t\t{\n\t\t\t\tif (c > value)\n\t\t\t\t{\n\t\t\t\t\tcur = 0;\n\t\t\t\t\tlo = cur;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcur += c;\n\t\t\t\t\tlo = min (lo, cur);\n\t\t\t\t\tres = max (res, cur - lo - value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "b2d77fa3e0c2dad9c316249a0feeb4c6"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int m, n;\n readf(\"%s %s\", &m, &n);\n readln;\n \n auto seq = new int[] (n);\n \n foreach (ref e; seq) {\n writeln(1);\n stdout.flush();\n \n readf(\"%s\", &e);\n readln;\n \n if (e == 0) {\n return;\n }\n }\n \n int ans = 0, le = 1, r = m, i = 0;\n do {\n int mid = (le + r) / 2;\n writeln(mid);\n stdout.flush();\n \n readf(\"%s\", &ans);\n readln;\n \n if (ans == 0) {\n return;\n }\n \n if (ans * seq[i] == 1) le = mid + 1;\n else r = mid - 1;\n \n i = (i+1) % n;\n \n } while (ans != 0);\n}", "positive_code": [{"source_code": "import std.range, std.stdio;\nint f (int x) {\n\tx.writeln;\n\tstdout.flush;\n\tint r;\n\treadf (\" %s\", &r);\n\treturn r;\n}\nvoid main () {\n\tint m, n;\n\treadf (\" %s %s\", &m, &n);\n\tauto p = new int [n];\n\tint k = 1;\n\tforeach (i; 0..99) {\n\t\tint v, x = (k + m) / 2;\n\t\tif (i < n) {\n\t\t\tv = f (1);\n\t\t\tp[i] = v;\n\t\t} else {\n\t\t\tv = f (x) * p[i % n];\n\t\t\tif (v < 0) m = x - 1;\n\t\t\telse k = x + 1;\n\t\t}\n\t\tif (!v) return;\n\t}\n}\n"}, {"source_code": "import std.stdio;\nint f (int x) {\n\tx.writeln;\n\tstdout.flush;\n\tint r;\n\treadf (\" %s\", r);\n\treturn r;\n}\nvoid main () {\n\tint m, n, k, i, v = 1, x;\n\treadf (\" %s %s\", m, n);\n\tauto p = new int [n];\n\tfor (; v; i++)\n\t\tif (i < n) p[i] = v = f (1);\n\t\telse {\n\t\t\tx = (k + m + 1) / 2;\n\t\t\tv = f (x) * p[i % n];\n\t\t\tif (v < 0) m = x;\n\t\t\telse k = x;\n\t\t}\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto M = s[0].to!long;\n auto N = s[1];\n auto P = new int[](N);\n long x;\n int[] Q;\n int debug_cnt = 0;\n\n debug {\n x = readln.chomp.to!long;\n Q = N.iota.map!(_ => readln.chomp.to!int).array;\n }\n\n\n int ask(long y) {\n writeln(y);\n stdout.flush;\n debug {\n if (x < y) return -1 * Q[debug_cnt];\n else if (x > y) return 1 * Q[debug_cnt];\n else return 0;\n ++debug_cnt;\n }\n return readln.chomp.to!int;\n }\n\n foreach (i; 0..N) {\n P[i] = ask(1);\n if (P[i] == 0)\n return;\n }\n\n long hi = M+1;\n long lo = 0;\n int cnt = 0;\n\n while (hi - lo > 1) {\n long mid = (hi + lo) / 2;\n int ret = ask(mid) * P[cnt%N];\n if (ret == 1) {\n lo = mid;\n } else if (ret == -1) {\n hi = mid;\n } else {\n return;\n }\n ++cnt;\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint ask (int x)\n{\n\twriteln (x);\n\tstdout.flush ();\n\tint res;\n\treadf (\" %s\", &res);\n\treturn res;\n}\n\nvoid solve (int m, int n)\n{\n\tauto p = new int [n];\n\tforeach (ref c; p)\n\t{\n\t\tauto cur = ask (1);\n\t\tif (cur == 0)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tc = (cur == +1);\n\t}\n\n\tint lo = 1;\n\tint hi = m;\n\tfor (int step = 0; ; step++)\n\t{\n\t\tint me = (lo + hi) / 2;\n\t\tauto cur = ask (me);\n\t\tif (cur == 0)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tcur *= (p[step % n] ? +1 : -1);\n\t\tif (cur < 0)\n\t\t{\n\t\t\thi = me - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlo = me + 1;\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\tint m, n;\n\twhile (readf (\" %s %s\", &m, &n) > 0)\n\t{\n\t\tsolve (m, n);\n\t}\n}\n"}], "negative_code": [], "src_uid": "f06dff83491772f8879e45b90b61dc88"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tlong n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\tk = max (k, (n + k - 1) / k * k);\r\n\t\twriteln ((k + n - 1) / n);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto k = RD;\n\n\t\tif (n >= k)\n\t\t{\n\t\t\tauto rem = k - (n % k);\n\t\t\tif (rem == k)\n\t\t\t\tans[ti] = 1;\n\t\t\telse\n\t\t\t\tans[ti] = 2;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[ti] = (k+n-1) / n;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "module main;\r\nimport std.stdio;\r\n\r\nauto read(T)()\r\n{\r\n T value;\r\n readf!\" %s\"(value);\r\n return value;\r\n}\r\n\r\nvoid main()\r\n{\r\n int t = read!int();\r\n foreach (_; 0 .. t)\r\n {\r\n int n = read!int(), k = read!int();\r\n writeln(n < k ? (k + n - 1) / n : n % k ? 2 : 1);\r\n }\r\n}"}, {"source_code": "module main;\r\nimport std.stdio;\r\n\r\nauto readInt()\r\n{\r\n int value;\r\n readf!\" %d\"(value);\r\n return value;\r\n}\r\n\r\nvoid main()\r\n{\r\n int t = readInt();\r\n foreach (_; 0 .. t)\r\n {\r\n int n = readInt(), k = readInt();\r\n writeln(n < k ? (k + n - 1) / n : n % k ? 2 : 1);\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n long n, k;\r\n readf!\"%d %d\\n\"(n, k);\r\n k *= (n + k - 1) / k;\r\n writeln((k + n - 1) / n);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, K; get(N, K);\r\n writeln(N % K == 0 ? 1 : N > K ? 2 : (K + N - 1) / N);\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, K; get(N, K);\r\n writeln((K == 1 || N == K) ? 1 : N > K ? 2 : (K + N - 1) / N);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, K; get(N, K);\r\n writeln(N == K ? 1 : N > K ? 2 : (K + N - 1) / N);\r\n }\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\tk = max (k, (n + k - 1) / k * k);\r\n\t\twriteln ((k + n - 1) / n);\r\n\t}\r\n}\r\n"}], "src_uid": "a28b84c9d1a54e322ab2d54bd5ab45c8"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long INF = 1L << 59;\n\nlong f(long n) {\n return n * (n + 1) / 2;\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n int[int] cnt1, cnt2;\n foreach (a; A) cnt1[a] += 1;\n foreach (a; cnt1.values) cnt2[a] += 1;\n auto B = cnt2.keys.array;\n B.sort!\"a > b\";\n long ans = 0;\n long lo = INF;\n foreach (b; B) {\n long v = min(b.to!long, lo);\n long n = min(cnt2[b].to!long, v);\n ans += f(v) - f(v - n);\n lo = v - n;\n }\n ans.writeln;\n }\n}\n", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int q;\n rd(q);\n\n while (q--) {\n int n;\n rd(n);\n auto a = readln.split.to!(int[]);\n auto freq = new int[](n);\n foreach (el; a) {\n freq[el - 1] += 1;\n }\n int[] b;\n foreach (f; freq) {\n if (f > 0) {\n b ~= f;\n }\n }\n b.sort!\"a>b\";\n int last = b[0] + 1;\n long ans = 0;\n foreach (el; b) {\n ans += min(last - 1, el);\n last = min(last - 1, el);\n if (last == 0) {\n break;\n }\n }\n writeln(ans);\n }\n\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "a00d831da539c69d571d9720fd94eee1"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nalias Entry = Tuple!(long, \"val\", long, \"num\");\n\nEntry[] solve(long[] A, long M) {\n const N = cast(int)(A.length);\n auto es = new Entry[N];\n foreach (i; 0 .. N) {\n auto e = Entry(A[i], 1);\n for (; e.val % M == 0; ) {\n e.val /= M;\n e.num *= M;\n }\n es[i] = e;\n }\n Entry[] ans;\n for (int i = 0, j; i < N; i = j) {\n long sum;\n for (j = i; j < N && es[i].val == es[j].val; ++j) {\n sum += es[j].num;\n }\n ans ~= Entry(es[i].val, sum);\n }\n debug {\n writeln(ans);\n }\n return ans;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const ALen = readInt;\n const M = readLong;\n auto A = new long[ALen];\n foreach (i; 0 .. ALen) {\n A[i] = readLong;\n }\n const BLen = readInt;\n auto B = new long[BLen];\n foreach (i; 0 .. BLen) {\n B[i] = readLong;\n }\n \n const resA = solve(A, M);\n const resB = solve(B, M);\n writeln((resA == resB) ? \"Yes\" : \"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std;\n\nvoid main(){\n\tint t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto m=readln.strip.split.to!(int[])[1];\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\treadln();\n\t\tauto b=readln.strip.split.to!(int[]);\n\t\tauto rle(int[] x){\n\t\t\tauto canonicalize(int value){\n\t\t\t\tlong repetitions=1;\n\t\t\t\twhile(value%m==0){\n\t\t\t\t\tvalue/=m;\n\t\t\t\t\trepetitions*=m;\n\t\t\t\t}\n\t\t\t\treturn tuple(value,repetitions);\n\t\t\t}\n\t\t\treturn x.map!canonicalize.chunkBy!(a=>a[0]).map!(x=>tuple(x[0],x[1].map!(y=>y[1]).sum));\n\t\t}\n\t\twriteln(equal(rle(a),rle(b))?\"Yes\":\"No\");\n\t}\n}\n"}, {"source_code": "import std;\n\nvoid main(){\n\tint t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto m=readln.strip.split.to!(int[])[1];\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\treadln();\n\t\tauto b=readln.strip.split.to!(int[]);\n\t\tauto rle(int[] x){\n\t\t\tauto canonicalize(int value){\n\t\t\t\tlong repetitions=1;\n\t\t\t\twhile(value%m==0){\n\t\t\t\t\tvalue/=m;\n\t\t\t\t\trepetitions*=m;\n\t\t\t\t}\n\t\t\t\treturn q(value,repetitions);\n\t\t\t}\n\t\t\treturn x.map!canonicalize.chunkBy!(a=>a[0]).map!(x=>q(x[0],x[1].map!(y=>y[1]).sum));\n\t\t}\n\t\twriteln(equal(rle(a),rle(b))?\"Yes\":\"No\");\n\t}\n}\n\n\n\n\nauto q(T...)(T args){\n\tstruct Q{\n\t\tT expand;\n\t\talias expand this;\n\t\tstring toString(){\n\t\t\tauto r=\"(\";\n\t\t\tforeach(i,alias x;expand)\n\t\t\t\tr~=(i!=0?\",\":\"\")~text(x);\n\t\t\tr~=\")\";\n\t\t\treturn r;\n\t\t}\n\t}\n\treturn Q(args);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid solve()\n{\n ulong n, m;\n auto cmp = (ulong x) {\n auto count = 0;\n while (x % m == 0)\n {\n x /= m;\n count++;\n }\n return tuple(x, m^^count);\n };\n readf!(\" %s %s\")(n, m);\n readln;\n auto A = readln.splitter\n .map!(to!ulong)\n .map!(cmp)\n .chunkBy!(x => x[0])\n .map!(x => tuple(x[0], x[1].map!(y => y[1]).sum()));\n readln;\n auto B = readln.splitter\n .map!(to!ulong)\n .map!(cmp)\n .chunkBy!(x => x[0])\n .map!(x => tuple(x[0], x[1].map!(y => y[1]).sum()));\n writeln(A.equal(B) ? \"Yes\" : \"No\");\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n solve();\n}\n"}], "negative_code": [{"source_code": "import std;\n\nvoid main(){\n\tint t=readln.strip.to!int;\n\tforeach(_;0..t){\n\t\tauto m=readln.strip.split.to!(int[])[1];\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\treadln();\n\t\tauto b=readln.strip.split.to!(int[]);\n\t\tauto rle(int[] x){\n\t\t\tauto canonicalize(int value){\n\t\t\t\tint repetitions=1;\n\t\t\t\twhile(value%m==0){\n\t\t\t\t\tvalue/=m;\n\t\t\t\t\trepetitions*=m;\n\t\t\t\t}\n\t\t\t\treturn tuple(value,repetitions);\n\t\t\t}\n\t\t\treturn x.map!canonicalize.chunkBy!(a=>a[0]).map!(x=>tuple(x[0],x[1].map!(y=>y[1]).sum));\n\t\t}\n\t\twriteln(equal(rle(a),rle(b))?\"Yes\":\"No\");\n\t}\n}\n"}], "src_uid": "2ff40423619cefd8c2fb35a18549c411"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1512/problem/D\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n long n = readln.chomp.to!long;\n long[] b = readln.split.map!(to!long).array;\n\n b.sort;\n\n long maxima = b[$ - 1];\n long cum = sum(b[0..$ - 1]);\n\n long x = -1L;\n for(uint i = 0L; i < n + 1L; ++i) {\n if(cum - b[i] == maxima) {\n x = b[i];\n b[i] = -1;\n break;\n }\n }\n\n if(x != -1L) {\n for(uint i = 0; i < n + 1L; ++i) {\n if(b[i] == -1L) {\n continue;\n }\n writef(\"%s \", b[i]);\n }\n \"\".writeln;\n continue;\n }\n\n maxima = b[$ - 2];\n cum = sum(b[0..$ - 2]);\n if(cum == maxima) {\n for(uint i = 0; i < n; i++) {\n writef(\"%s \", b[i]);\n }\n \"\".writeln;\n } else {\n \"-1\".writeln;\n }\n}\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\n while(t--) {\n long n = readln.chomp.to!long;\n long[] b = readln.split.map!(to!long).array;\n\n b.sort;\n\n long maxima = b[$-1];\n long cum = sum(b[0 .. $-1]);\n\n int x = -1;\n for(int i = 0; i < n + 1; ++i) {\n if(cum - b[i] == maxima) {\n x = i;\n break;\n }\n }\n\n if(x != -1) {\n b = b.remove(x);\n writef(\"%(%d %)\\n\", b[0 .. $-1]);\n continue;\n }\n\n cum = sum(b[0 .. $-2]);\n if(cum == b[$-2])\n writef(\"%(%d %)\\n\", b[0 .. $-2]);\n else\n writeln(\"-1\");\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\n while(t--) {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n\n b.sort;\n\n int maxima = b[$-1];\n int cum = sum(b[0 .. $-1]);\n\n int x = -1;\n for(int i = 0; i < n + 1; ++i) {\n if(cum - b[i] == maxima) {\n x = i;\n break;\n }\n }\n\n if(x != -1) {\n b = b.remove(x);\n writef(\"%(%d %)\\n\", b[0 .. $-1]);\n continue;\n }\n\n cum = sum(b[0 .. $-2]);\n if(cum == b[$-2])\n writef(\"%(%d %)\\n\", b[0 .. $-2]);\n else\n writeln(\"-1\");\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\n while(t--) {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n\n b.sort;\n\n int maxima = b[$-1];\n int cum = sum(b[0 .. $-1]);\n\n int x = -1;\n for(int i = 0; i < n - 1; ++i) {\n if(cum - b[i] == maxima) {\n x = i;\n break;\n }\n }\n\n if(x != -1) {\n b = b.remove(x);\n writef(\"%(%d %)\\n\", b[0 .. $-1]);\n continue;\n }\n\n cum = sum(b[0 .. $-2]);\n if(cum == b[$-2])\n writef(\"%(%d %)\\n\", b[0 .. $-2]);\n else\n writeln(\"-1\");\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\n while(t--) {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n\n b.sort;\n\n int maxima = b[$-1];\n int cum = sum(b[0 .. $-1]);\n\n int x = -1;\n for(int i = 0; i < n - 1; ++i) {\n if(cum - b[i] == maxima) {\n x = i;\n break;\n }\n }\n\n if(x != -1) {\n b = b.remove(x);\n writef(\"%(%d %)\\n\", b[0 .. $-1]);\n continue;\n }\n\n cum = sum(b[0 .. $-2]);\n if(cum + b[$-1] == b[$-2])\n writef(\"%(%d %)\\n\", b[0 .. $-2]);\n else\n writeln(\"-1\");\n }\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1512/problem/D\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n\n b.sort;\n\n int maxima = b[$ - 1];\n int cum = sum(b[0..$ - 1]);\n\n int x = -1;\n for(int i = 0; i < n + 1; ++i) {\n if(cum - b[i] == maxima) {\n x = b[i];\n b[i] = -1;\n break;\n }\n }\n\n if(x != -1) {\n for(int i = 0; i < n + 1; ++i) {\n if(b[i] == -1) {\n continue;\n }\n writef(\"%s \", b[i]);\n }\n \"\".writeln;\n continue;\n }\n\n maxima = b[$ - 2];\n cum = sum(b[0..$ - 2]);\n if(cum == maxima) {\n for(int i = 0; i < n; i++) {\n writef(\"%s \", b[i]);\n }\n \"\".writeln;\n } else {\n \"-1\".writeln;\n }\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1512/problem/D\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n\n b.sort;\n\n int maxima = b[$ - 1];\n int cum = sum(b[0..$ - 1]);\n\n int x = -1;\n for(int i = 0; i < n - 1; ++i) {\n if(cum - b[i] == maxima) {\n x = b[i];\n b[i] = -1;\n break;\n }\n }\n\n if(x != -1) {\n for(int i = 0; i < n + 1; ++i) {\n if(b[i] == -1) {\n continue;\n }\n writef(\"%s \", b[i]);\n }\n \"\".writeln;\n continue;\n }\n\n maxima = b[$ - 2];\n cum = sum(b[0..$ - 2]);\n if(cum == maxima) {\n for(int i = 0; i < n; i++) {\n writef(\"%s \", b[i]);\n }\n \"\".writeln;\n } else {\n \"-1\".writeln;\n }\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1512/problem/D\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n\n b.sort;\n\n int maxima = b[$ - 1];\n int cum = sum(b[0..$ - 1]);\n\n int x = -1;\n for(int i = 0; i < n - 1; ++i) {\n if(cum - b[i] == maxima) {\n x = b[i];\n b[i] = -1;\n break;\n }\n }\n\n if(x != -1) {\n for(int i = 0; i < n + 1; ++i) {\n if(b[i] == -1) {\n continue;\n }\n writef(\"%s \", b[i]);\n }\n \"\".writeln;\n continue;\n }\n\n maxima = b[$ - 2];\n cum = sum(b[0..$ - 2]);\n if(cum == maxima) {\n b[0.. $ - 2].writeln;\n } else {\n \"-1\".writeln;\n }\n}\n}\n\n"}], "src_uid": "ce667a8fb60841c994aebedb35a3b0d8"} {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\n\nunittest{\n assert(solve(1) == [1], \"Teste 1\");\n}\n\nlong[] solve(long a){\n debug(1) writefln(\"%s\",a);\n return [1];\n}\n\nclass Candy{\n struct CandyV{\n int id;\n int t;\n int h;\n int m;\n bool ate;\n }\n CandyV cv;\n\n this(int i, int t, int h, int m, bool ate){\n cv = CandyV(i,t,h,m,ate);\n }\n\n bool canEat(int j, int t){\n return (cv.t == t && cv.ate == false && cv.h <= j);\n }\n\n override string toString(){\n return text(cv);\n }\n}\n\nvoid main(){\n int c,j;\n readf(\"%s %s\\n\",&c,&j);\n immutable int fj = j;\n\n Candy[] cnds;\n for(int i = 0; i < c; i++){\n int t,h,m;\n readf(\"%s %s %s\\n\",&t,&h,&m);\n Candy cc = new Candy(i,t,h,m,false);\n cnds ~= cc;\n }\n\n Candy[] byMaxM = cnds.dup;\n sort!((a,b){return a.cv.m > b.cv.m;})(byMaxM);\n //writeln(byMaxM);\n\n //Candy[] byMinH = cnds.dup;\n //sort!((a,b){return a.cv.h < b.cv.h;})(byMinH);\n //writeln(byMinH);\n\n //start with 1\n\n //start with 0\n int type = 0;\n int cnt0 = 0;\n for(int i = 0; i < c; i++){\n if(byMaxM[i].canEat(j,type % 2)){\n //writeln(j);\n j += byMaxM[i].cv.m;\n byMaxM[i].cv.ate = true;\n type += 1;\n cnt0++;\n i = -1;\n }\n }\n\n foreach(ccc;cnds){\n ccc.cv.ate = false;\n }\n j = fj;\n //writeln();\n\n type = 1;\n int cnt1 = 0;\n for(int i = 0; i < c; i++){\n if(byMaxM[i].canEat(j,type % 2)){\n //writeln(j);\n j += byMaxM[i].cv.m;\n byMaxM[i].cv.ate = true;\n type += 1;\n cnt1++;\n i = -1;\n }\n }\n\n // writeln(cnt0);\n // writeln(cnt1);\n writeln(max(cnt0,cnt1));\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n, x;\n\twhile (readf (\" %s %s\", &n, &x) > 0)\n\t{\n\t\talias pair = Tuple !(int, \"h\", int, \"m\");\n\t\tpair [] [2] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint t, h, m;\n\t\t\treadf (\" %s %s %s\", &t, &h, &m);\n\t\t\ta[t] ~= pair (h, m);\n\t\t}\n\t\tsort (a[0]);\n\t\tsort (a[1]);\n\n\t\tlong res = 0;\n\t\tforeach (s; 0..2)\n\t\t{\n\t\t\tpair [] [2] b;\n\t\t\tb[0] = a[0].dup;\n\t\t\tb[1] = a[1].dup;\n\t\t\tlong cur = 0;\n\t\t\tint cx = x;\n\t\t\tint t = s;\n\t\t\tint j;\n\t\t\tint m;\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tm = NA;\n\t\t\t\tj = NA;\n\t\t\t\tforeach (i, p; b[t])\n\t\t\t\t{\n\t\t\t\t\tif (p != pair (NA, NA) &&\n\t\t\t\t\t p.h <= cx &&\n\t\t\t\t\t m < p.m)\n\t\t\t\t\t{\n\t\t\t\t\t\tm = p.m;\n\t\t\t\t\t\tj = i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (j == NA)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcx += b[t][j].m;\n\t\t\t\tb[t][j] = pair (NA, NA);\n\t\t\t\tcur++;\n\t\t\t\tt ^= 1;\n\t\t\t}\n\t\t\tres = max (res, cur);\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n, x;\n\twhile (readf (\" %s %s\", &n, &x) > 0)\n\t{\n\t\talias pair = Tuple !(int, \"h\", int, \"m\");\n\t\tpair [] [2] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint t, h, m;\n\t\t\treadf (\" %s %s %s\", &t, &h, &m);\n\t\t\ta[t] ~= pair (h, m);\n\t\t}\n\t\tsort (a[0]);\n\t\tsort (a[1]);\n\n\t\tlong res = 0;\n\t\tforeach (s; 0..2)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tint cx = x;\n\t\t\tint p = 0;\n\t\t\tint t = s;\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tif (a[t].length <= p || a[t][p].h > cx)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcx += a[t][p].m;\n\t\t\t\tcur++;\n\t\t\t\tt ^= 1;\n\t\t\t\tif (a[t].length <= p || a[t][p].h > cx)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcx += a[t][p].m;\n\t\t\t\tcur++;\n\t\t\t\tt ^= 1;\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tres = max (res, cur);\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\n\nunittest{\n assert(solve(1) == [1], \"Teste 1\");\n}\n\nlong[] solve(long a){\n debug(1) writefln(\"%s\",a);\n return [1];\n}\n\nclass Candy{\n struct CandyV{\n int id;\n int t;\n int h;\n int m;\n bool ate;\n }\n CandyV cv;\n\n this(int i, int t, int h, int m, bool ate){\n cv = CandyV(i,t,h,m,ate);\n }\n\n bool canEat(int j, int t){\n return (cv.t == t && cv.ate == false && cv.h <= j);\n }\n\n override string toString(){\n return text(cv);\n }\n}\n\nvoid main(){\n int c,j;\n readf(\"%s %s\\n\",&c,&j);\n\n Candy[] cnds;\n for(int i = 0; i < c; i++){\n int t,h,m;\n readf(\"%s %s %s\\n\",&t,&h,&m);\n Candy cc = new Candy(i,t,h,m,false);\n cnds ~= cc;\n }\n\n Candy[] byMaxM = cnds.dup;\n sort!((a,b){return a.cv.m > b.cv.m;})(byMaxM);\n //writeln(byMaxM);\n\n Candy[] byMinH = cnds.dup;\n sort!((a,b){return a.cv.h < b.cv.h;})(byMinH);\n //writeln(byMinH);\n\n //start with 1\n\n //start with 0\n int type = 0;\n int cnt0 = 0;\n for(int i = 0; i < c; i++){\n if(cnds[i].canEat(j,type % 2)){\n j += cnds[i].cv.m;\n type += 1;\n cnt0++;\n }\n }\n\n foreach(ccc;cnds){\n ccc.cv.ate = false;\n }\n\n type = 1;\n int cnt1 = 0;\n for(int i = 0; i < c; i++){\n if(cnds[i].canEat(j,type % 2)){\n j += cnds[i].cv.m;\n type += 1;\n cnt1++;\n }\n }\n\n writeln(max(cnt0,cnt1));\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\n\nunittest{\n assert(solve(1) == [1], \"Teste 1\");\n}\n\nlong[] solve(long a){\n debug(1) writefln(\"%s\",a);\n return [1];\n}\n\nclass Candy{\n struct CandyV{\n int id;\n int t;\n int h;\n int m;\n bool ate;\n }\n CandyV cv;\n\n this(int i, int t, int h, int m, bool ate){\n cv = CandyV(i,t,h,m,ate);\n }\n\n bool canEat(int j, int t){\n return (cv.t == t && cv.ate == false && cv.h <= j);\n }\n\n override string toString(){\n return text(cv);\n }\n}\n\nvoid main(){\n int c,j;\n readf(\"%s %s\\n\",&c,&j);\n immutable int fj = j;\n\n Candy[] cnds;\n for(int i = 0; i < c; i++){\n int t,h,m;\n readf(\"%s %s %s\\n\",&t,&h,&m);\n Candy cc = new Candy(i,t,h,m,false);\n cnds ~= cc;\n }\n\n Candy[] byMaxM = cnds.dup;\n sort!((a,b){return a.cv.m > b.cv.m;})(byMaxM);\n //writeln(byMaxM);\n\n //Candy[] byMinH = cnds.dup;\n //sort!((a,b){return a.cv.h < b.cv.h;})(byMinH);\n //writeln(byMinH);\n\n //start with 1\n\n //start with 0\n int type = 0;\n int cnt0 = 0;\n for(int i = 0; i < c; i++){\n if(byMaxM[i].canEat(j,type % 2)){\n //writeln(j);\n j += byMaxM[i].cv.m;\n byMaxM[i].cv.ate = true;\n type += 1;\n cnt0++;\n i = 0;\n }\n }\n\n foreach(ccc;cnds){\n ccc.cv.ate = false;\n }\n j = fj;\n //writeln();\n\n type = 1;\n int cnt1 = 0;\n for(int i = 0; i < c; i++){\n if(byMaxM[i].canEat(j,type % 2)){\n //writeln(j);\n j += byMaxM[i].cv.m;\n byMaxM[i].cv.ate = true;\n type += 1;\n cnt1++;\n i = 0;\n }\n }\n\n // writeln(cnt0);\n // writeln(cnt1);\n writeln(max(cnt0,cnt1));\n}\n"}], "src_uid": "6253f6217c58a66573b1ddc6962c372c"} {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto n = readln().chomp.to!int;\r\n auto arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n auto m = arr.minElement;\r\n double avg = arr.mean;\r\n int res = 0;\r\n foreach(i; arr)\r\n {\r\n if(i > m)\r\n {\r\n res++;\r\n }\r\n }\r\n \r\n writeln(res);\r\n }\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1529/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n int[] a = readln.split.map!(to!int).array;\n int minima = a.minElement;\n int ans = 0;\n foreach(i; a) {\n if(i != minima) {\n ans += 1;\n }\n }\n ans.writeln;\n}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.strip)) {\r\n int n = to!int(readln.strip);\r\n auto ar = readln.split.map!(to!int).array.sort.group;\r\n writeln(n-ar.array[0][1]);\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tauto x = a.minElement;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] > x)\r\n\t\t\t\t++ans[ti];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto n = readln().chomp.to!int;\r\n auto arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n auto m = arr.minElement;\r\n \r\n writeln(arr.filter!(i => i > m).count());\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto n = readln().chomp.to!int;\r\n auto arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n \r\n double avg = arr.mean;\r\n int res = 0;\r\n foreach(i; arr)\r\n {\r\n if(i > avg)\r\n {\r\n res++;\r\n }\r\n }\r\n \r\n writeln(res);\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto n = readln().chomp.to!int;\r\n auto arr = readln().chomp.splitter(\" \").map!(to!int).array.sort.array;\r\n \r\n int res = 0;\r\n int cur = 0;\r\n \r\n foreach(i; arr)\r\n {\r\n if(i != cur)\r\n {\r\n cur = i;\r\n res++;\r\n }\r\n }\r\n \r\n if(res > 1)\r\n writeln(res);\r\n else writeln(0);\r\n }\r\n}"}], "src_uid": "d5627b9fe5f6c5a7247e1f9d9e9b0c6a"} {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nstruct CI { int c, i; }\n\nvoid main()\n{\n int n, x1, x2; readV(n, x1, x2);\n int[] c; readA(n, c);\n\n auto ci = new CI[](n);\n foreach (i; 0..n) ci[i] = CI(c[i], i+1);\n auto cis = ci.sort!\"a.c < b.c\";\n\n auto r1 = calc(n, x1, x2, cis);\n if (r1[0] > 0) {\n put(r1[0], r1[1], r1[2], r1[3]);\n return;\n }\n\n auto r2 = calc(n, x2, x1, cis);\n if (r2[0] > 0) {\n put(r2[1], r2[0], r2[3], r2[2]);\n return;\n }\n\n writeln(\"No\");\n}\n\nauto calc(R)(int n, int x1, int x2, R cis)\n{\n auto calcK2()\n {\n foreach (k2; 1..n) {\n if (cis[$-k2].c >= (x2+k2-1)/k2) return k2;\n }\n return 0;\n }\n\n auto k2 = calcK2;\n if (k2 == 0) return tuple(0, 0, cast(int[])[], cast(int[])[]);\n\n foreach (k1; 1..n) {\n auto r = cis.upperBound(CI((x1+k1-1)/k1-1, 0));\n if (r.length >= k1+k2) {\n auto s = r.map!\"a.i\".array;\n return tuple(k1, k2, s[0..k1], s[$-k2..$]);\n }\n }\n\n return tuple(0, 0, cast(int[])[], cast(int[])[]);\n}\n\nauto put(int k1, int k2, int[] r1, int[] r2)\n{\n writeln(\"Yes\");\n writeln(k1, \" \", k2);\n\n foreach (i; 0..k1) {\n write(r1[i]);\n if (i < k1-1) write(\" \");\n }\n writeln;\n\n foreach (i; 0..k2) {\n write(r2[i]);\n if (i < k2-1) write(\" \");\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n int[2] x;\n readf(\"%s %s %s\", &n, &x[0], &x[1]);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).enumerate(1).array;\n arr.sort!\"a[1] > b[1]\";\n \n debug { arr.writeln; }\n \n auto ans = new int[][] (2);\n \n bool go(int idx, int x1, int x2) {\n int need = (x[x1] + arr[idx].value - 1) / arr[idx].value;\n \n int lft = idx - need;\n if (lft < 0) { return false; }\n \n long totalLeft = arr[lft].value.to!long * (lft + 1);\n \n if (totalLeft < x[x2]) { return false; }\n \n foreach (i; 0 .. lft+1) { ans[x2] ~= arr[i].index; }\n foreach (i; lft+1 .. idx+1) { ans[x1] ~= arr[i].index; }\n \n return true;\n }\n \n bool found = false;\n foreach (i; 1 .. n) {\n found = go(i, 0, 1) || go(i, 1, 0);\n if (found) { break; }\n }\n \n if (!found) {\n writeln(\"No\");\n return;\n }\n \n writeln(\"Yes\");\n writeln(ans[0].length, ' ', ans[1].length);\n foreach (i; 0 .. 2) {\n ans[i].writefln!\"%(%s %)\";\n }\n}"}], "negative_code": [], "src_uid": "aa312ddd875b82eab84fdc92ceec37e5"} {"source_code": "import std.conv, std.functional, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum K = 5;\n\nint N;\nreal[] X, Y;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n X = new real[N];\n Y = new real[N];\n foreach (i; 0 .. N) {\n X[i] = readReal();\n Y[i] = readReal();\n }\n \n Tuple!(real, int, int)[] edges;\n foreach (i; 0 .. N) foreach (j; 0 .. N) {\n if (i != j) {\n edges ~= tuple(atan2(Y[j] - Y[i], X[j] - X[i]), i, j);\n }\n }\n edges.sort;\n \n auto dp = new long[][][](K + 1, N, N);\n foreach (i; 0 .. N) {\n dp[0][i][i] = 1;\n }\n foreach (const ref edge; edges) {\n const j = edge[1], k = edge[2];\n foreach (t; 0 .. K) {\n foreach (i; 0 .. N) {\n dp[t + 1][i][k] += dp[t][i][j];\n }\n }\n }\n long ans;\n foreach (i; 0 .. N) {\n ans += dp[K][i][i];\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/*\n\tXmas Contest 2012\n\tProblem G: Galaxy View\n\tSolution\n\tO(N^3 log N)\n*/\n\nimport std.stdio, std.string, std.conv;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\nimport core.thread;\n\n//\tInput\nstring[] tokens;\nint tokenId = 0;\nstring readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) {\n\tint low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp;\n}\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a){ return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a){ return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs == null || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\n\nvoid prepare() {\n\t\n}\n\nclass Solver : Thread {\n\tint caseId;\n\tthis(int caseId) {\n\t\tthis.caseId = caseId;\n\t\tsuper(&main);\n\t}\n\tvoid main() {\n\t\ttry {\n\t\t\trun;\n\t\t\tstderr.writeln(\"DONE Case #\", caseId);\n\t\t} catch (Throwable e) {\n\t\t\tstderr.writeln(\"ERROR Case #\", caseId, \": \", e.msg);\n\t\t} finally {\n\t\t\tstderr.flush;\n\t\t}\n\t}\n\t\n\tstruct Pt {\n\t\tlong x, y;\n\t}\n\tstruct Entry {\n\t\tlong x, y;\n\t\tint id;\n\t}\n\t\n\tint N;\n\tPt[] P;\n\tlong ans;\n\t\n\tvoid run() {\n\t\tlong cnt1, cnt2;\n\t\tP.sort!\"(a.x != b.x) ? (a.x < b.x) : (a.y < b.y)\";\n\t\tforeach (i; 0 .. N) {\n\t\t\tPt[] ps;\n\t\t\tforeach (j; i + 1 .. N) {\n\t\t\t\tps ~= Pt(P[j].x - P[i].x, P[j].y - P[i].y);\n\t\t\t}\n\t\t\tps.sort!\"(a.x * b.y > a.y * b.x)\";\n\t\t\tforeach (j; 0 .. ps.length) {\n\t\t\t\tEntry[] es;\n\t\t\t\tforeach (k; j + 1 .. ps.length) {\n\t\t\t\t\tes ~= Entry(ps[k].x - ps[j].x, ps[k].y - ps[j].y, k - j - 1);\n\t\t\t\t}\n\t\t\t\tes.sort!\"(a.x * b.y < a.y * b.x)\";\n\t\t\t\tint[] as = new int[es.length];\n\t\t\t\tforeach (k, e; es) {\n\t\t\t\t\tas[e.id] = k;\n\t\t\t\t}\n\t\t\t\tint[] bit = new int[es.length];\n\t\t\t\tvoid add(int pos) {\n\t\t\t\t\tfor (int x = pos; x < es.length; x |= x + 1) {\n\t\t\t\t\t\t++bit[x];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint cal(int pos) {\n\t\t\t\t\tint ret;\n\t\t\t\t\tfor (int x = pos - 1; x >= 0; x = (x & x + 1) - 1) {\n\t\t\t\t\t\tret += bit[x];\n\t\t\t\t\t}\n\t\t\t\t\treturn ret;\n\t\t\t\t}\n\t\t\t\tforeach (a; as) {\n\t\t\t\t\tlong m = cal(a);\n\t\t\t\t\tcnt1 += m;\n\t\t\t\t\tcnt2 += m * (m - 1) / 2;\n\t\t\t\t\tadd(a);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong n = N;\n\t\tans = n * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 120 - (cnt1 * (n - 4) - cnt2 * 4) / 2 - cnt2;\n\t}\n\t\n\tvoid input() {\n\t\tN = readInt;\n\t\tP = new Pt[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tP[i].x = readLong;\n\t\t\tP[i].y = readLong;\n\t\t}\n\t}\n\t\n\tvoid output() {\n\t\twrite(ans);\n\t\tstdout.rawWrite(\"\\n\");\n\t\tstdout.flush;\n\t}\n}\n\nvoid main(string[] args) {\n\tbool parallel = false;\n\tforeach (arg; args) if (arg == \"-p\") parallel = true;\n\tprepare;\n\t// auto solvers = new Solver[readInt];\n\tauto solvers = new Solver[1];\n\tforeach (caseId, ref solver; solvers) solver = new Solver(caseId + 1);\n\tif (parallel) {\n\t\tforeach (solver; solvers) solver.input, solver.start;\n\t\tforeach (solver; solvers) solver.join, solver.output;\n\t} else {\n\t\tforeach (caseId, solver; solvers) {\n\t\t\tsolver.input;\n\t\t\tsolver.run;\n\t\t\tsolver.output;\n\t\t\tstderr.writeln(\"DONE Case #\", caseId + 1);\n\t\t\tstderr.flush;\n\t\t}\n\t}\n}\n\n"}, {"source_code": "import std.conv, std.functional, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum K = 5;\n\nint N;\nreal[] X, Y;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n X = new real[N];\n Y = new real[N];\n foreach (i; 0 .. N) {\n X[i] = readReal();\n Y[i] = readReal();\n }\n \n Tuple!(real, int, int)[] edges;\n foreach (i; 0 .. N) foreach (j; 0 .. N) {\n if (i != j) {\n edges ~= tuple(atan2(Y[j] - Y[i], X[j] - X[i]), i, j);\n }\n }\n edges.sort;\n \n auto dp = new long[][][](K + 1, N, N);\n foreach (i; 0 .. N) {\n dp[0][i][i] = 1;\n }\n foreach (edge; edges) {\n foreach (k; 0 .. K) {\n foreach (i; 0 .. N) {\n dp[k + 1][i][edge[2]] += dp[k][i][edge[1]];\n }\n }\n }\n long ans;\n foreach (i; 0 .. N) {\n ans += dp[K][i][i];\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "de6514afc96da147bd4c4346457d143f"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto a = readln.split.to!(int[]);\n auto g = new int[][](n);\n foreach (_; 1 .. n) {\n int u, v;\n rd(u, v);\n g[u - 1] ~= v - 1;\n g[v - 1] ~= u - 1;\n }\n auto num_r = new int[](n), num_b = new int[](n);\n void f(int i, int p) {\n if (a[i] == 1) {\n num_r[i] = 1;\n } else if (a[i] == 2) {\n num_b[i] = 1;\n }\n foreach (j; g[i]) {\n if (j != p) {\n f(j, i);\n num_r[i] += num_r[j];\n num_b[i] += num_b[j];\n }\n }\n }\n\n f(0, -1);\n int bad = 0;\n void f2(int i, int p) {\n foreach (j; g[i]) {\n if (j != p) {\n if (num_r[j] > 0 && num_b[j]) {\n bad++;\n } else if (num_r[0] - num_r[j] > 0 && num_b[0] - num_b[j] > 0) {\n bad++;\n }\n f2(j, i);\n }\n }\n }\n\n f2(0, -1);\n writeln(n - 1 - bad);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto c = readln.chomp.split.map!(to!int).array;\n \n auto g = new int[][] (n);\n foreach (_; 0 .. n-1) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n g[u] ~= v;\n g[v] ~= u;\n }\n \n int[2] tot;\n foreach (i; 0 .. 2) { tot[i] = c.count!(x => x == i+1).to!int; }\n \n Tuple!(int, int) dfs(int v, int fr, ref int ans) {\n auto cnt = tuple(0, 0);\n foreach (u; g[v]) {\n if (u == fr) { continue; }\n \n auto res = dfs(u, v, ans);\n cnt[0] += res[0];\n cnt[1] += res[1];\n }\n \n cnt[0] += c[v] == 1;\n cnt[1] += c[v] == 2;\n \n if (v != 0) {\n if (cnt[0] == 0 && cnt[1] == tot[1]) { ans += 1; }\n else if (cnt[0] == tot[0] && cnt[1] == 0) { ans += 1; }\n }\n \n debug { writeln(v, ' ', cnt, ' ', ans); }\n \n return cnt;\n }\n \n int ans = 0;\n dfs(0, -1, ans);\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "0d95c84e73aa9b6567eadeb16acfda41"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT read(T)(){ return read.to!T; }\nT[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }\nT[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\n/*\nIf you find s_i > s_(i + 1), swap them.\nOthewise, NO.\n*/\n\nvoid solve(){\n\tint n = read!int;\n\tstring s = readln.chomp;\n\t\n\tint i1;\n\tbool f = 0;\n\tforeach(i; 0 .. n - 1){\n\t\tif(s[i] > s[i + 1]){\n\t\t\ti1 = i;\n\t\t\tf = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(f == 0) writeln(\"NO\");\n\telse writeln(\"YES\"), writeln(i1 + 1, \" \", i1 + 2);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!int;\n\tauto s = RD!string;\n\n\tlong[2] ans;\n\tforeach (i; 1..N)\n\t{\n\t\tif (s[i-1] > s[i])\n\t\t{\n\t\t\tans = [i-1, i];\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (ans == [0, 0])\n\t\twriteln(\"NO\");\n\telse\n\t{\n\t\twriteln(\"YES\");\n\t\twriteln(ans[0]+1, \" \", ans[1]+1);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n\n foreach (i; 0..N-1) {\n if (S[i] > S[i+1]) {\n writeln(\"YES\");\n writeln(i+1, \" \", i+2);\n return;\n }\n }\n\n writeln(\"NO\");\n}"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.range;\nimport std.file;\nimport std.datetime;\n\n\n\n\n\nvoid main() \n{\n\tint elemanSay\u0131s\u0131 = stdin.readln.strip.to!int;\n\tstring harfler = stdin.readln.strip.to!string;\n\t\n\t\n\tint enB\u00fcy\u00fckIndeksi = 0;\n\tchar enB\u00fcy\u00fckHarf = 'a';\n\tfor ( int i = 0; i < harfler.length; i++ )\n\t{\n\t\tif ( harfler[i] >= enB\u00fcy\u00fckHarf )\n\t\t{\n\t\t\tenB\u00fcy\u00fckIndeksi = i;\n\t\t\tenB\u00fcy\u00fckHarf = harfler[i]; \n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\treturn writeln( enB\u00fcy\u00fckIndeksi+1, \" \", i+1 );\n\t\t}\n\t\t\t\n\t}\n\twriteln(\"NO\");\n\t\n}\n\n\n\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nvoid main() {\n auto n = readln.strip.to!int;\n auto s = readln.strip[0 .. n];\n foreach (i; 1 .. n) {\n if (s[i-1] > s[i]) {\n debug stderr.writeln (i);\n writeln (\"YES\");\n writeln (i, ' ', i + 1);\n return;\n }\n }\n writeln (\"NO\");\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n\n foreach (i; 0..N-1) {\n if (S[i] > S[i-1]) {\n writeln(\"YES\");\n writeln(i+1, \" \", i+2);\n return;\n }\n }\n\n writeln(\"NO\");\n}"}], "src_uid": "d45f775613e701bbdaa4e457e6e189e2"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.conv;\nimport std.string;\n\nT readNum(T)(){\n return readStr.to!T;\n}\n\nT[] readNums(T)(){\n return readStr.split.to!(T[]);\n}\n\nstring readStr(){\n return readln.chomp;\n}\n\nvoid main(){\n auto t = readNum!int;\n\n foreach(i; 0 .. t){\n int ret;\n auto n = readNum!int;\n auto a = readNums!int;\n\n auto csum = new int[](n+1);\n foreach(j; 1 .. n+1){\n csum[j] = csum[j-1] + a[j-1];\n }\n\n foreach(j; 0 .. n){\n int l = 0, r = 2;\n\n while(r <= n){\n int sum = csum[r] - csum[l];\n if(sum < a[j] || l == r-1){\n r++;\n } else if(sum > a[j]){\n l++;\n } else {\n ret++;\n break;\n }\n }\n }\n\n writeln(ret);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport core.stdc.stdlib;\nimport core.stdc.stdio;\nimport core.stdc.string;\n\nvoid main() @nogc {\n\t// int tt = 1000;\n\tint tt;\n\tscanf(\"%d\", &tt);\n\tforeach (t; 0 .. tt) {\n\t\t// int n = 8000;\n\t\tint n;\n\t\tscanf(\"%d\", &n);\n\t\tint[] arr = (cast(int*)malloc(int.sizeof * n))[0 .. n];\n\t\tforeach (i; 0 .. arr.length) {\n\t\t\tscanf(\"%d\", &arr[i]);\n\t\t\t// arr[i] = rand() % n + 1;\n\t\t}\n\t\tbool[] specials = (cast(bool*)malloc(bool.sizeof * (n + 2)))[0 .. n + 2];\n\t\tmemset(specials.ptr, 0, bool.sizeof * (n + 2));\n\t\tforeach (i; 0 .. arr.length) {\n\t\t\tint sum = arr[i];\n\t\t\tforeach (j; i + 1 .. arr.length) {\n\t\t\t\tsum += arr[j];\n\t\t\t\tif (sum < n + 2) {\n\t\t\t\t\tspecials[sum] = true;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint res;\n\t\tforeach (i; arr) {\n\t\t\tif (specials[i]) {\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t\tprintf(\"%d\\n\", res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tauto b = new int[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb[i+1] += b[i] + a[i];\n\t\t}\n\n\t\tauto set = new int[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\t++set[a[i]];\n\t\t}\n\t\tdebug writeln(set);\n\n\t\tauto hit = new bool[](n+1);\n\t\tforeach (l; 0..n)\n\t\t{\n\t\t\tforeach (r; l+2..n+1)\n\t\t\t{\n\t\t\t\tauto x = b[r] - b[l];\n\t\t\t\tif (x > n) continue;\n\t\t\t\thit[x] = true;\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n+1)\n\t\t{\n\t\t\tif (hit[i])\n\t\t\t{\n\t\t\t\tans[ti] += set[i];\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "void main() {\n\tauto t = ri;\n\tforeach(T; 0..t) {\n\t\tauto n = ri;\n\t\tauto a = readAs!(int[]);\n\t\tauto arr = new int[](n);\n\t\tarr[0] = a[0];\n\t\tforeach(i; 1..n) arr[i] = arr[i-1] + a[i];\n\t\tint[int] ms, me;\n\n\t\tforeach(v; a) me[v]++;\n\t\tforeach(i; 1..n) ms[arr[i]]++;\n\t\tforeach(i; 0..n) foreach(j; i..n) {\n\t\t\tif(j - i < 2) continue;\n\t\t\tauto s = arr[j] - arr[i];\n\t\t\tdebug writefln(\"%d, %d => %d\", j, i, s);\n\t\t\tif(s <= n) ms[s]++;\n\t\t}\n\t\tlong res;\n\t\tdebug \"=====\".writeln;\n\t\tdebug me.writeln;\n\t\tdebug ms.writeln;\n\t\tforeach(i, v; me) {\n\t\t\tif(i in ms) {\n\t\t\t\tres += v;\n\t\t\t}\n\t\t}\n\t\tres.writeln;\n\t}\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\nlong rl() {\n\treturn readAs!long;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(int[]);\n if (N == 1) {\n writeln(0);\n continue;\n }\n int r;\n foreach (a; as) {\n int s = as[0] + as[1];\n size_t i, j = 2;\n while (i < N-1) {\n if (s == a) {\n goto ok;\n } else if (s < a && j < N) {\n s += as[j++];\n } else if (i < j-2) {\n s -= as[i++];\n } else if (j < N) {\n s += as[j++];\n } else {\n break;\n }\n }\n continue;\n ok:\n ++r;\n }\n writeln(r);\n }\n}"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto marks = new bool [n + 1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint cur = a[i];\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tcur += a[j];\n\t\t\t\tif (cur > n)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tmarks[cur] = true;\n\t\t\t}\n\t\t}\n\t\twriteln (a.count !(x => marks[x]));\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.conv;\nimport std.string;\n\nT readNum(T)(){\n return readStr.to!T;\n}\n\nT[] readNums(T)(){\n return readStr.split.to!(T[]);\n}\n\nstring readStr(){\n return readln.chomp;\n}\n\nvoid main(){\n auto t = readNum!int;\n\n foreach(i; 0 .. t){\n int ret;\n auto n = readNum!int;\n auto a = readNums!int;\n\n auto csum = new int[](n+1);\n foreach(j; 1 .. n+1){\n csum[j] = csum[j-1] + a[j-1];\n }\n\n foreach(j; 1 .. n){\n int l = 0, r = 2;\n\n while(r <= n){\n int sum = csum[r] - csum[l];\n if(sum < a[j] || l == r-1){\n r++;\n } else if(sum > a[j]){\n l++;\n } else {\n ret++;\n break;\n }\n }\n }\n\n writeln(ret);\n }\n}\n"}], "src_uid": "2326470337301e0f4b0d1b1a6195e398"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto l = RD;\r\n\t\tauto r = RD;\r\n\t\tauto k = RD;\r\n\t\tauto a = RDA;\r\n\r\n\t\ta.sort;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] < l || a[i] > r) continue;\r\n\t\t\tif (k < a[i]) break;\r\n\t\t\tk -= a[i];\r\n\t\t\t++ans[ti];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n long n = scan;\n long l = scan;\n long r = scan;\n long k = scan;\n auto arr = scanArray;\n arr.sort;\n long cnt = 0;\n for(int i = 0; i < n; ++i){\n if(arr[i] >= l && arr[i] <= r){\n if(k >= arr[i]){\n ++cnt;\n k -= arr[i];\n }\n }\n }\n writeln(cnt);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto l = readInt!int;\n\tauto r = readInt!int;\n\tauto k = readInt!int;\n\tauto a = ma(n, readInt!int);\n\ta = a.filter!(ai => ai >= l && ai <= r).array;\n\tsort(a);\n\tdebug writeln(\"after filter \", a);\n\tint count = 0;\n\twhile (!a.empty && k >= a.front)\n\t{\n\t\tcount++;\n\t\tk -= a.front;\n\t\ta.popFront;\n\t}\n\tcount.writeln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "f577695d39a11e8507681f307677c883"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.format;\n\nvoid test (string s) {\n if (s.all!\"a=='0'\" || s.all!\"a == '1'\") {\n writeln (s);\n return;\n }\n foreach (i; 0 .. s.length) {\n write (\"01\");\n }\n writeln;\n}\n\nvoid main() {\n auto s = readln;\n int nt;\n formattedRead (s, \" %d\", nt);\n foreach (tid; 0 .. nt) {\n s = readln.stripRight;\n test (s);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto T = RD!int;\n\tauto ans = new string[](T);\n\tforeach (ti; 0..T)\n\t{\n\t\tauto t = RD!string;\n\t\tbool[char] set;\n\t\tforeach (c; t)\n\t\t{\n\t\t\tset[c] = true;\n\t\t}\n\t\tif (set.keys.length == 1)\n\t\t{\n\t\t\tans[ti] = t;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tchar last;\n\t\t\tforeach (i; 0..t.length)\n\t\t\t{\n\t\t\t\tif (t[i] == last)\n\t\t\t\t{\n\t\t\t\t\tif (t[i] == '0')\n\t\t\t\t\t\tans[ti] ~= \"10\";\n\t\t\t\t\telse\n\t\t\t\t\t\tans[ti] ~= \"01\";\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= t[i];\n\t\t\t\t}\n\t\t\t\tlast = t[i];\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nint inz(long t){ return to!int(t); } \nstatic string[] tempstr;\nT rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid play(){\n char[] s;\n s = rd!(char[]);\n int[] nums;\n int[int] seen;\n seen[0] = 0; seen[1] = 0;\n foreach(cr; s){ \n nums ~= cr - '0'; \n ++seen[cr - '0'];\n }\n if(!(seen[0] && seen[1])){\n writeln(s);\n }else{\n int[] res;\n res ~= nums[0];\n foreach(i; 1..nums.length){\n if(nums[i] == nums[i-1]){\n res ~= !nums[i];\n }\n res ~= nums[i];\n }\n foreach(cr; res){\n write(cr);\n }\n writeln;\n }\n}\n\nint main(){\n ll t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto t = readln.chomp;\n int o, z;\n foreach (c; t) {\n if (c == '0') ++z;\n if (c == '1') ++o;\n }\n if (o == 0 || z == 0) {\n writeln(t);\n continue;\n }\n\n char[] s;\n foreach (i; 0..t.length-1) {\n s ~= t[i];\n if (t[i] == t[i+1]) {\n if (t[i] == '0') {\n s ~= '1';\n } else {\n s ~= '0';\n }\n }\n }\n s ~= t[$-1];\n writeln(s);\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\t\tauto n = s.length;\n\t\tstring res;\n\t\tforeach (char part; \"01\")\n\t\t{\n\t\t\tif (s.canFind (part))\n\t\t\t{\n\t\t\t\tres ~= part;\n\t\t\t}\n\t\t}\n\t\twriteln (res.repeat (n).joiner);\n\t}\n}\n"}], "negative_code": [], "src_uid": "679a1e455073d3ea3856aa16516ba8ba"} {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nint n, k;\nchar[ ] s;\n\nint solve(char c) {\n int a = 0, b = 0;\n int left = k;\n for (; b < n; b++)\n if (s[b] != c && !left--)\n break;\n int result = b - a;\n while (b < n) {\n while (a != b && s[a] == c)\n a++;\n a++;\n while (++b < n)\n if (s[b] != c)\n break;\n result = max(result, b - a);\n }\n return result;\n}\n\nvoid main() {\n static char[100_001] storage;\n while (read(&n, &k)) {\n s = storage[ ];\n readln(s);\n writeln(max(solve('a'), solve('b')));\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto S = readln.chomp.to!string;\n\n auto ac = new int[](N+1);\n auto bc = new int[](N+1);\n foreach (i; 1..N+1) {\n ac[i] = ac[i-1] + (S[i-1] == 'a');\n bc[i] = bc[i-1] + (S[i-1] == 'b');\n }\n\n int ans = 0;\n int r = 0;\n foreach (l; 0..N) {\n while (r < N-1 && bc[r+2] - bc[l] <= K)\n r++;\n ans = max(ans, r-l+1);\n }\n r = 0;\n foreach (l; 0..N) {\n while (r < N-1 && ac[r+2] - ac[l] <= K)\n r++;\n ans = max(ans, r-l+1);\n }\n\n writeln(ans);\n}\n"}], "negative_code": [], "src_uid": "0151a87d0f82a9044a0ac8731d369bb9"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint a, b;\r\n\t\treadf !(\" %s %s\") (a, b);\r\n\t\tint res = int.max;\r\n\t\tfor (int step = 0; step <= 100; step++)\r\n\t\t{\r\n\t\t\tint num = step;\r\n\t\t\tint c = a;\r\n\t\t\tint d = b + step;\r\n\t\t\tif (d == 1)\r\n\t\t\t{\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\twhile (c > 0)\r\n\t\t\t{\r\n\t\t\t\tc /= d;\r\n\t\t\t\tnum += 1;\r\n\t\t\t}\r\n\t\t\tres = min (res, num);\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int a, b; get(a, b);\r\n int base;\r\n if (b == 1) {\r\n b = 2;\r\n base = 1;\r\n }\r\n\r\n auto r = int.max;\r\n for (;;) {\r\n int res = base;\r\n auto aa = a;\r\n while (aa) {\r\n aa /= b;\r\n res += 1;\r\n }\r\n if (res <= r) {\r\n r = res;\r\n b += 1;\r\n base += 1;\r\n } else {\r\n break;\r\n }\r\n }\r\n writeln(r);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\r\n\t\tlong bb;\r\n\t\tif (b == 1)\r\n\t\t{\r\n\t\t\t++bb;\r\n\t\t}\r\n\r\n\t\tans[ti] = long.max;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tlong tmp;\r\n\t\t\tauto x = a;\r\n\t\t\tauto y = b + bb;\r\n\t\t\twhile (x)\r\n\t\t\t{\r\n\t\t\t\tx /= y;\r\n\t\t\t\t++tmp;\r\n\t\t\t}\r\n\t\t\ttmp += bb;\r\n\t\t\tif (tmp <= ans[ti])\r\n\t\t\t\tans[ti] = tmp;\r\n\t\t\telse\r\n\t\t\t\tbreak;\r\n\t\t\t++bb;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "2b757fa66ce89046fe18cdfdeafa6660"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n long ans = 0;\n\n for (int i = 0, j = 0; i < N; ++i) {\n if (j < i) j = i;\n while (j < N && A[j] - A[i] <= 5) ++j;\n ans = max(ans, j - i);\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n;\n readf!\" %s\"(n);\n\n int[] a = new int[](n);\n foreach (i; 0 .. n) {\n readf!\" %s\"(a[i]);\n }\n\n a.sort;\n\n debug {\n writeln(a);\n }\n\n int ans = 0;\n int l = 0, r = 0;\n for (; l < n; l++) {\n while (r < n && a[r] - a[l] <= 5) {\n r++;\n }\n ans = max(ans, r - l);\n }\n\n writeln(ans);\n}\n"}, {"source_code": "import std.functional,\n std.algorithm,\n std.container,\n std.typetuple,\n std.typecons,\n std.bigint,\n std.string,\n std.traits,\n std.array,\n std.range,\n std.stdio,\n std.conv;\n\nbool chmax(t)(ref t a, t b) {\n if (a < b) {\n a = b;\n return true;\n } else {\n return false;\n }\n}\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] ns = readln.chomp.split.to!(int[]);\n sort!\"a>b\"(ns);\n int[int] hs;\n\n foreach (e; ns) {\n if (e in hs) {\n hs[e]++;\n } else {\n hs[e] = 1;\n }\n }\n\n int ans = 0;\n int len;\n\n foreach (e; ns) {\n foreach (i; 0..6) {\n if ((e - i) in hs) {\n len += hs[e - i];\n }\n }\n\n chmax(ans, len);\n len = 0;\n }\n\n writeln(ans);\n}\n"}], "negative_code": [], "src_uid": "8b075d96b3c0172d756109b4801d68de"} {"source_code": "//prewritten code: https://github.com/antma/algo\nmodule Solution;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\n//Kadane's algorithm\nlong maximumSubArraySum(R) (R range) if (isInputRange!R && isIntegral!(ElementType!R)) {\n alias T = ElementType!R;\n alias S = Tuple! (long, \"best\", long, \"cur\");\n S next (in S s, in T x) {\n S t;\n t.cur = s.cur + x;\n t.best = max (s.best, t.cur);\n if (t.cur < 0) t.cur = 0;\n return t;\n }\n return reduce!next (tuple!(\"best\", \"cur\") (long.min, 0L), range).best;\n}\n\nbool test (in long[] a) {\n long y = sum (a);\n long b = max (maximumSubArraySum (a[1 .. $]), maximumSubArraySum (a[0 .. $ - 1])); \n return y > b;\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n immutable n = r.next!uint ();\n auto a = r.nextA!(long)(n);\n debug stderr.writeln (a);\n auto b = a.dup;\n b.reverse ();\n writeln ((test (a) && test (b)) ? \"YES\" : \"NO\");\n }\n}\n\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\n//Kadane's algorithm\nlong maximumSubArraySum(R) (R range) if (isInputRange!R && isIntegral!(ElementType!R)) {\n alias T = ElementType!R;\n alias S = Tuple! (long, \"best\", long, \"cur\");\n S next (in S s, in T x) {\n S t;\n t.cur = s.cur + x;\n t.best = max (s.best, t.cur);\n if (t.cur < 0) t.cur = 0;\n return t;\n }\n return reduce!next (tuple!(\"best\", \"cur\") (long.min, 0L), range).best;\n}\n\nbool test (in long[] a) {\n long y = sum (a);\n long best = y;\n long cur = 0;\n int l = 0;\n foreach (x; a) {\n cur += x;\n ++l;\n if (best <= cur && l < a.length) {\n return false;\n }\n if (cur < 0) {\n cur = 0;\n l = 0;\n }\n }\n return true;\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n immutable n = r.next!uint ();\n auto a = r.nextA!(long)(n);\n debug stderr.writeln (a);\n auto b = a.dup;\n b.reverse ();\n writeln ((test (a) && test (b)) ? \"YES\" : \"NO\");\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tforeach(_; 0 .. rint){\n\t\tint n = rint;\n\t\tlong[] as = rlong(n);\n\n\t\tlong inf = 1_00000_000_000_000 + 999;\n\n\t\tlong x = as.sum;\n\t\tlong y = -inf;\n\t\tlong tmp;\n\t\tforeach(a; as[0 .. $ - 1]){\n\t\t\tif(tmp + a > 0) tmp += a, y.chmax(tmp);\n\t\t\telse tmp = 0;\n\t\t}\n\t\ttmp = 0;\n\t\tforeach(a; as[1 .. $]){\n\t\t\tif(tmp + a > 0) tmp += a, y.chmax(tmp);\n\t\t\telse tmp = 0;\n\t\t}\n\t\tforeach(a; as) y.chmax(a);\n\t\tlog(\"x:\", x, \"y:\", y);\n\n\t\tif(x > y) \"YES\".writeln;\n\t\telse \"NO\".writeln;\n\n\t}\n\n}"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n int t;\n read(t);\n foreach(tc; 0 .. t)\n {\n long n;\n read(n);\n auto a = makeArray!long(n, next!long);\n long bestsum = 0;\n long totalbest = long.min;\n foreach(i; 0 .. n - 1)\n {\n bestsum = max(a[i.ind] + bestsum, a[i.ind]);\n totalbest = max(bestsum, totalbest);\n }\n long suffixsum = 0;\n long maxsuffixsum = long.min;\n foreach_reverse(i; 1 .. n)\n {\n suffixsum += a[i.ind];\n totalbest = max(suffixsum, totalbest);\n }\n writeln(a[].sum > totalbest? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto x = a.sum;\n\t\tauto b = new long[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb[i+1] = b[i] + a[i];\n\t\t}\n\t\tlong y = long.min;\n\t\tint l;\n\t\tforeach (r; 1..n+1)\n\t\t{\n\t\t\tif (l == 0 && r == n)\n\t\t\t{\n\t\t\t\tforeach (i; 2..n+1)\n\t\t\t\t\ty.chmax(b[i] - b[1]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tauto tmp = b[r] - b[l];\n\t\t\tif (tmp <= 0)\n\t\t\t{\n\t\t\t\tl = r;\n\t\t\t}\n\t\t\ty.chmax(tmp);\n\t\t}\n\t\tans[ti] = x > y;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\n//Kadane's algorithm\nlong maximumSubArraySum(R) (R range) if (isInputRange!R && isIntegral!(ElementType!R)) {\n alias T = ElementType!R;\n alias S = Tuple! (long, \"best\", long, \"cur\");\n S next (in S s, in T x) {\n S t;\n t.cur = s.cur + x;\n t.best = max (s.best, t.cur);\n if (t.cur < 0) t.cur = 0;\n return t;\n }\n return reduce!next (tuple!(\"best\", \"cur\") (long.min, 0L), range).best;\n}\n\nbool test (in long[] a) {\n long y = sum (a);\n long best = y;\n long cur = 0;\n int l = 0;\n foreach (x; a) {\n cur += x;\n ++l;\n if (best <= cur && l < a.length) {\n return false;\n }\n if (cur < 0) {\n cur = 0;\n l = 0;\n }\n }\n return true;\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n immutable n = r.next!uint ();\n auto a = r.nextA!(long)(n);\n debug stderr.writeln (a);\n writeln (test (a) ? \"YES\" : \"NO\");\n }\n}\n\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n int t;\n read(t);\n foreach(tc; 0 .. t)\n {\n int n;\n read(n);\n auto a = makeArray!int(n, next!int);\n int bestsum = 0;\n int totalbest = int.min;\n int totalbesti = -1;\n foreach(i; 0 .. n - 1)\n {\n bestsum = max(a[i] + bestsum, a[i]);\n if (bestsum > totalbest)\n {\n totalbest = bestsum;\n }\n }\n int suffixsum = 0;\n int maxsuffixsum = int.min;\n foreach_reverse(i; 1 .. n)\n {\n suffixsum += a[i];\n maxsuffixsum = max(suffixsum, maxsuffixsum);\n }\n totalbest = max(totalbest, maxsuffixsum);\n writeln(a[].sum > totalbest? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n int t;\n read(t);\n foreach(tc; 0 .. t)\n {\n int n;\n read(n);\n auto a = makeArray!int(n, next!int);\n int bestsum = 0;\n int totalbest = int.min;\n foreach(i; 0 .. n - 1)\n {\n bestsum = max(a[i] + bestsum, a[i]);\n totalbest = max(bestsum, totalbest);\n }\n int suffixsum = 0;\n int maxsuffixsum = int.min;\n foreach_reverse(i; 1 .. n)\n {\n suffixsum += a[i];\n totalbest = max(suffixsum, totalbest);\n }\n writeln(a[].sum > totalbest? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto x = a.sum;\n\t\tauto b = new long[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb[i+1] = b[i] + a[i];\n\t\t}\n\t\tlong y;\n\t\tint l;\n\t\tforeach (r; 1..n+1)\n\t\t{\n\t\t\tif (l == 0 && r == n) break;\n\t\t\tauto tmp = b[r] - b[l];\n\t\t\tif (tmp < 0)\n\t\t\t{\n\t\t\t\tl = r+1;\n\t\t\t}\n\t\t\ty.chmax(tmp);\n\t\t}\n\t\tans[ti] = x > y;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto x = a.sum;\n\t\tauto b = new long[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb[i+1] = b[i] + a[i];\n\t\t}\n\t\tlong y = long.min;\n\t\tint l;\n\t\tforeach (r; 1..n+1)\n\t\t{\n\t\t\tif (l == 0 && r == n) break;\n\t\t\tauto tmp = b[r] - b[l];\n\t\t\tif (tmp < 0)\n\t\t\t{\n\t\t\t\tl = r+1;\n\t\t\t}\n\t\t\ty.chmax(tmp);\n\t\t}\n\t\tans[ti] = x > y;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "6e5b4d43e64645cf26d5eac31437b1a9"} {"source_code": "import std;\n\n// From: https://rosettacode.org/wiki/Prime_decomposition#D\nUnqual!T[] decompose(T)(in T number)\n{\n typeof(return) result;\n Unqual!T n = number;\n \n for (Unqual!T i = 2; n % i == 0; n /= i)\n result ~= i;\n for (Unqual!T i = 3; n >= i * i; i += 2)\n for (; n % i == 0; n /= i)\n result ~= i;\n \n if (n != 1)\n result ~= n;\n return result;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n, m;\n readf!\" %d %d \"(n, m);\n auto tmp = decompose(n);\n auto cnt2 = tmp.count(2);\n auto cnt5 = tmp.count(5);\n long xm = 1;\n if (cnt2 < cnt5) {\n while (cnt2 < cnt5 && xm * 2 <= m) {\n cnt2++;\n xm *= 2;\n }\n while (xm * 10 <= m) {\n xm *= 10;\n }\n if (m / xm > 0)\n xm *= m / xm;\n } else {\n while (cnt5 < cnt2 && xm * 5 <= m) {\n cnt5++;\n xm *= 5;\n }\n while (xm * 10 <= m) {\n xm *= 10;\n }\n if (m / xm > 0)\n xm *= m / xm;\n }\n writeln(xm == 1 ? n * m : n * xm);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nint zeroes (long n)\r\n{\r\n\tint res = 0;\r\n\twhile (n % 10 == 0)\r\n\t{\r\n\t\tres += 1;\r\n\t\tn /= 10;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tlong n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\r\n\t\tforeach (c; [2, 5, 10])\r\n\t\t{\r\n\t\t\twhile (c <= m && zeroes (n) < zeroes (n * c))\r\n\t\t\t{\r\n\t\t\t\tn *= c;\r\n\t\t\t\tm /= c;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (n * m);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "83af7209bb8a81cde303af5d207c2749"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n immutable int MX = 2750131;\n auto div = new int[] (MX + 1);\n div[] = 1;\n int nxtIdx = 1;\n int[int] prsIdx;\n \n foreach (i; 2 .. MX + 1) {\n if (div[i] != 1) { continue; }\n \n foreach (j; (MX+1).iota.drop(i+i).stride(i)) { \n if (div[j] == 1) { div[j] = i; }\n }\n \n prsIdx[i] = nxtIdx;\n nxtIdx += 1;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto rbt = make!(RedBlackTree!(int, \"a > b\", true))(arr);\n \n int[] ans;\n while (!rbt.empty()) {\n auto x = rbt.front();\n rbt.removeFront();\n \n if (x in prsIdx) {\n auto v = prsIdx[x];\n rbt.removeKey(v);\n ans ~= v;\n } else {\n auto v = x / div[x];\n rbt.removeKey(v);\n ans ~= x;\n }\n }\n \n ans.map!(to!string).join(\" \").writeln;\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n immutable int MX = 2750131;\n auto div = new int[] (MX + 1);\n div[] = 1;\n int[] prs;\n int[int] prsIdx;\n \n foreach (i; 2 .. MX + 1) {\n if (div[i] != 1) { continue; }\n \n foreach (j; (MX+1).iota.drop(i+i).stride(i)) { \n if (div[j] == 1) { div[j] = i; }\n }\n \n prs ~= i;\n prsIdx[i] = prs.length.to!int;\n }\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto rbt = make!(RedBlackTree!(int, \"a > b\", true))(arr);\n \n int[] ans;\n while (!rbt.empty()) {\n auto x = rbt.front();\n rbt.removeFront();\n \n if (x in prsIdx) {\n auto v = prsIdx[x];\n rbt.removeKey(v);\n ans ~= v;\n } else {\n auto v = x / div[x];\n rbt.removeKey(v);\n ans ~= x;\n }\n }\n \n ans.map!(to!string).join(\" \").writeln;\n}"}], "negative_code": [], "src_uid": "07484b6a6915c5cb5fdf1921355f2a6a"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int INF = int.max / 2;\nimmutable int NA = -1;\n\nbool solve (int [] [] a)\n{\n int n = a.length;\n foreach (i, c; a)\n {\n foreach (j, x; c)\n {\n if ((x == 0) != (i == j) || x != a[j][i])\n {\n return false;\n }\n }\n }\n\n auto d = new int [n];\n d[] = INF;\n auto p = new int [n];\n p[] = NA;\n auto b = new bool [n];\n alias edge = Tuple !(int, \"v\", int, \"w\");\n auto g = new edge [] [n];\n int cur = 0;\n foreach (k; 1..n)\n {\n b[cur] = true;\n foreach (i; 0..n)\n {\n if (d[i] > a[cur][i])\n {\n d[i] = a[cur][i];\n p[i] = cur;\n }\n }\n int next = cur;\n int w = INF;\n foreach (i; 0..n)\n {\n if (!b[i])\n {\n if (w > d[i])\n {\n w = d[i];\n next = i;\n }\n }\n }\n g[next] ~= edge (p[next], w);\n g[p[next]] ~= edge (next, w);\n cur = next;\n }\n debug {writeln (g);}\n\n foreach (i; 0..n)\n {\n auto e = new long [n];\n\n void recur (int v, int q, long z)\n {\n e[v] = z;\n foreach (h; g[v])\n {\n if (h.v != q)\n {\n recur (h.v, v, z + h.w);\n }\n }\n }\n\n recur (i, NA, 0);\n debug {writeln (e[], ' ', a[i][]);}\n if (e[] != a[i][])\n {\n return false;\n }\n }\n return true;\n}\n\nvoid main ()\n{\n int n;\n while (readf (\" %s\", &n) > 0)\n {\n auto a = new int [] [] (n, n);\n foreach (ref c; a)\n {\n foreach (ref x; c)\n {\n readf (\" %s\", &x);\n }\n }\n writeln (solve (a) ? \"YES\" : \"NO\");\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int INF = int.max / 2;\nimmutable int NA = -1;\n\nbool solve (int [] [] a)\n{\n\tint n = a.length;\n\tforeach (i, c; a)\n\t{\n\t\tforeach (j, x; c)\n\t\t{\n\t\t\tif ((x == 0) != (i == j) || x != a[j][i])\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\tauto d = new int [n];\n\td[] = INF;\n\tauto p = new int [n];\n\tp[] = NA;\n\tauto b = new bool [n];\n\talias edge = Tuple !(int, \"v\", int, \"w\");\n\tauto g = new edge [] [n];\n\tint cur = 0;\n\tforeach (k; 1..n)\n\t{\n\t\tb[cur] = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (d[i] > a[cur][i])\n\t\t\t{\n\t\t\t\td[i] = a[cur][i];\n\t\t\t\tp[i] = cur;\n\t\t\t}\n\t\t}\n\t\tint next = cur;\n\t\tint w = INF;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (!b[i])\n\t\t\t{\n\t\t\t\tif (w > d[i])\n\t\t\t\t{\n\t\t\t\t\tw = d[i];\n\t\t\t\t\tnext = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tg[next] ~= edge (p[next], w);\n\t\tg[p[next]] ~= edge (next, w);\n\t\tcur = next;\n\t}\n\tdebug {writeln (g);}\n\n\tforeach (i; 0..n)\n\t{\n\t\tauto e = new long [n];\n\n\t\tvoid recur (int v, int q, long z)\n\t\t{\n\t\t\te[v] = z;\n\t\t\tforeach (h; g[v])\n\t\t\t{\n\t\t\t\tif (h.v != q)\n\t\t\t\t{\n\t\t\t\t\trecur (h.v, v, z + h.w);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (i, NA, 0);\n\t\tdebug {writeln (e[], ' ', a[i][]);}\n\t\tif (e[] != a[i][])\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tauto a = new int [] [] (n, n);\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tauto r = readln.split ();\n\t\t\tforeach (ref x; c)\n\t\t\t{\n\t\t\t\tx = to !(int) (r.front);\n\t\t\t\tr.popFront ();\n//\t\t\t\treadf (\" %s\", &x);\n\t\t\t}\n\t\t}\n\t\twriteln (solve (a) ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nlong[][] D;\n\nPair!(long, Pair!(int, int))[] edges;\n\nvoid doIt(int[] us) {\ndebug{\nwriteln(\"doIt \",us);\n}\n\tif (us.length <= 1) {\n\t\treturn;\n\t}\n\tint a = us[0];\n\tint b = -1;\n\tforeach (u; us[1 .. $]) {\n\t\tif (b == -1 || D[a][b] > D[a][u]) {\n\t\t\tb = u;\n\t\t}\n\t}\n\tedges ~= pair(D[a][b], pair(a, b));\n\tint[] usA, usB;\n\tforeach (u; us) {\n\t\tif (D[a][u] < D[b][u]) {\n\t\t\tusA ~= u;\n\t\t} else {\n\t\t\tusB ~= u;\n\t\t}\n\t}\n\tif (usA.empty || usB.empty) {\n\t\treturn;\n\t}\n\tusA.doIt;\n\tusB.doIt;\n}\n\nbool solve() {\n\tforeach (u; 0 .. N) {\n\t\tif (D[u][u] != 0) {\n\t\t\treturn false;\n\t\t}\n\t}\n\tforeach (u; 0 .. N) foreach (v; 0 .. N) {\n\t\tif (D[u][v] != D[v][u]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\t\n\tedges = new Pair!(long, Pair!(int, int))[0];\n\tint[] us = new int[N];\n\tforeach (u; 0 .. N) {\n\t\tus[u] = u;\n\t}\n\tus.doIt;\ndebug{\nwriteln(edges);\n}\n\tif (edges.length != N - 1) {\n\t\treturn false;\n\t}\n\tforeach (edge; edges) {\n\t\tif (edge.x <= 0) {\n\t\t\treturn false;\n\t\t}\n\t}\n\tauto G = new Pair!(long, int)[][N];\n\tforeach (edge; edges) {\n\t\tG[edge.y.x] ~= pair(edge.x, edge.y.y);\n\t\tG[edge.y.y] ~= pair(edge.x, edge.y.x);\n\t}\n\tforeach (s; 0 .. N) {\n\t\tlong[] ds = new long[N];\n\t\tvoid dfs(int u, int p, long d) {\n\t\t\tds[u] = d;\n\t\t\tforeach (inci; G[u]) {\n\t\t\t\tconst v = inci.y;\n\t\t\t\tif (v != p) {\n\t\t\t\t\tdfs(v, u, d + inci.x);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdfs(s, -1, 0);\ndebug{\nwriteln(s,\" : \",ds);\n}\n\t\tforeach (u; 0 .. N) {\n\t\t\tif (D[s][u] != ds[u]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tD = new long[][](N, N);\n\t\tforeach (u; 0 .. N) foreach (v; 0 .. N) {\n\t\t\tD[u][v] = readLong;\n\t\t}\n\t\t\n\t\twriteln(solve ? \"YES\" : \"NO\");\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "a5363163c1c2dfed91947a582ac28bda"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, r;\n rd(n, r);\n auto as = readln.split.to!(int[]);\n\n auto bs = new int[](n);\n foreach (int i, a; as) {\n if (a) {\n foreach (int j; max(0, i - r + 1) .. min(n, i + r)) {\n bs[j]++;\n }\n }\n }\n if (bs.find(0).length > 0) {\n writeln(-1);\n return;\n }\n int num = reduce!\"a+b\"(as);\n foreach (int i, b; bs) {\n if (as[i]) {\n if (b >= 2) {\n bool ok = true;\n foreach (int j; max(0, i - r + 1) .. min(n, i + r)) {\n ok &= bs[j] >= 2;\n }\n if (ok) {\n num--;\n foreach (int j; max(0, i - r + 1) .. min(n, i + r)) {\n bs[j]--;\n }\n }\n }\n }\n }\n writeln(num);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\nenum inf = 10^^6;\n\nvoid main() {\n int n, r;\n scan(n, r);\n auto a = readln.split.to!(int[]);\n a = a ~ repeat(0, r).array;\n\n int lt = -1;\n auto b = new int[](n + r);\n foreach (i ; 0 .. r) {\n if (a[i]) {\n lt = i;\n }\n }\n foreach (i ; r .. n + r) {\n b[i - r] = lt;\n if (lt == i - r) {\n lt = -1;\n }\n if (a[i]) {\n lt = i;\n }\n }\n\n \n\n auto c = new int[](n);\n c[0] = a[0] ? 0 : inf + 1;\n foreach (i ; 1 .. n) {\n if (a[i] == 1) {\n c[i] = 0;\n }\n else {\n c[i] = c[i-1] + 1;\n }\n }\n\n debug {\n writeln(b);\n writeln(c);\n }\n\n\n int ans;\n\n\n for (int pos; pos < n;) {\n ans++;\n if (b[pos] != -1) {\n pos = b[pos] + r;\n }\n else if (c[pos] < r) {\n pos = pos - c[pos] + r;\n }\n else {\n writeln(-1);\n return;\n }\n }\n\n writeln(ans);\n}\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, r;\n rd(n, r);\n auto as = readln.split.to!(int[]);\n\n auto bs = new int[](n);\n int num = 0;\n foreach (int i, b; bs) {\n if (b == 0) {\n num++;\n bool found = false;\n foreach (int j; i .. n) {\n if (as[j]) {\n found = true;\n for (int k = max(0, j - r + 1); k < min(n, j + r - 1); k++) {\n bs[k] = 1;\n }\n break;\n }\n }\n if (!found) {\n writeln(-1);\n return;\n }\n }\n }\n\n writeln(num);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, r;\n rd(n, r);\n auto as = readln.split.to!(int[]);\n\n auto bs = new int[](n);\n int num = 0;\n foreach (int i, b; bs) {\n if (b == 0) {\n num++;\n bool found = false;\n int idx;\n foreach (int j; i .. n) {\n if (as[j]) {\n if (i < j - r + 1) {\n break;\n }\n found = true;\n idx = j;\n }\n }\n if (!found) {\n writeln(-1);\n return;\n }\n for (int k = max(0, idx - r + 1); k < min(n, idx + r); k++) {\n bs[k] = 1;\n }\n }\n }\n\n writeln(num);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "src_uid": "001d8aca7c8421c3e54863f3fb706f0d"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto g = new int[][] (n+1);\n foreach (_ ; 0 .. n-1) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto d = new int[][] (n+1, k+1);\n \n long dfs(int v, int fr) {\n long ret = 0;\n foreach (u; g[v]) {\n if (u == fr) continue;\n \n ret += dfs(u, v);\n foreach (le; 1 .. k) {\n ret += d[v][le].to!long * d[u][k - le - 1];\n }\n foreach (le; 1 .. k+1) {\n d[v][le] += d[u][le-1];\n }\n }\n \n ret += d[v][k];\n d[v][0] += 1;\n \n debug { writeln(v, ' ', d[v], ' ', ret); }\n \n return ret;\n }\n \n auto ans = dfs(1, -1);\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto g = new int[][] (n+1);\n foreach (_ ; 0 .. n-1) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto mxh = new int[] (n+1);\n int dfsmxh(int v, int fr) {\n int h = 0;\n foreach (u; g[v]) {\n if (u == fr) continue;\n h = max(h, dfsmxh(u, v) + 1);\n }\n \n return mxh[v] = h;\n }\n \n dfsmxh(1, -1);\n foreach (ref r; g) {\n r = r.sort!((a, b) => mxh[a] < mxh[b]).array;\n }\n \n long dfs(int v, int fr, int h, ref int[int] cnt) {\n long ret = 0;\n \n while (! g[v].empty() && g[v].back == fr) { g[v].popBack(); }\n \n int[int] ncnt;\n if (! g[v].empty()) {\n ret += dfs(g[v].back, v, h+1, cnt);\n \n foreach (u; g[v][0 .. $-1]) {\n if (u == fr) continue;\n \n ncnt.clear();\n ret += dfs(u, v, h+1, ncnt);\n foreach (le; 1 .. k) {\n debug { writeln(\"mid \", v, ' ' , u, ' ', cnt, ' ', ncnt, ' ', h); }\n ret += cnt.get(h + le, 0).to!long * ncnt.get(h + k - le, 0);\n }\n \n foreach (d; 1 .. k+1) {\n if (! ncnt.get(h + d, 0) == 0) {\n cnt[h + d] += ncnt.get(h + d, 0);\n }\n }\n }\n \n debug { writeln(\"start \", v, ' ', h+k, ' ', cnt.get(h + k, 0)); }\n ret += cnt.get(h + k, 0);\n }\n \n cnt[h] += 1;\n \n debug { writeln(\"ret \", v, ' ', ret); }\n \n return ret;\n }\n \n int[int] cnt;\n auto ans = dfs(1, -1, 0, cnt);\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "2fc19c3c9604e746a17a63758060c5d7"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nint[][] scc(in int[][] G, in int[][] rG) {\r\n // calculate scc\r\n int N = cast(int)(G.length);\r\n auto used = new bool[N];\r\n int[] postorder;\r\n void vis_forward(int v) {\r\n used[v] = true;\r\n foreach (u; G[v]) {\r\n if (used[u]) continue;\r\n vis_forward(u);\r\n }\r\n postorder ~= v;\r\n }\r\n for (int v = 0; v < N; v++) {\r\n if (used[v]) continue;\r\n vis_forward(v);\r\n }\r\n auto cid = new int[N]; cid[] = -1; // i = cid[v]: vertex `v` belongs to the `i`-th component\r\n void vis_backward(int v, int k) {\r\n cid[v] = k;\r\n foreach (u; rG[v]) {\r\n if (cid[u] >= 0) continue;\r\n vis_backward(u, k);\r\n }\r\n }\r\n int k = 0;\r\n foreach_reverse (v; postorder) {\r\n if (cid[v] >= 0) continue;\r\n vis_backward(v, k++);\r\n }\r\n auto ret = new int[][k];\r\n foreach (v; 0 .. N) {\r\n ret[ cid[v] ] ~= v;\r\n }\r\n return ret;\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias Edge = Tuple!(int, \"to\", int, \"cost\");\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto xG = new int[][N];\r\n auto rG = new int[][N];\r\n auto G = new Edge[][N];\r\n foreach (i; 0 .. N) {\r\n auto rs = readarray!int[1 .. $];\r\n foreach (r; rs) {\r\n int j = r - 1;\r\n xG[i] ~= j;\r\n rG[j] ~= i;\r\n if (j < i) {\r\n G[i] ~= Edge(j, 0);\r\n } else {\r\n G[i] ~= Edge(j, 1);\r\n }\r\n }\r\n }\r\n auto grs = scc(xG, rG);\r\n if (grs.length == xG.length) {\r\n // ok. there's no scc\r\n auto ord = new int[N]; ord[] = -1;\r\n int f(int v) {\r\n if (ord[v] >= 0) return ord[v];\r\n int ret = 0;\r\n foreach (e; G[v]) {\r\n int x = e.cost + f(e.to);\r\n ret.chmax(x);\r\n }\r\n return ord[v] = ret;\r\n }\r\n int ans = 0;\r\n for (int v = 0; v < N; v++) {\r\n ans.chmax(f(v));\r\n }\r\n writeln(ans + 1);\r\n } else {\r\n writeln(-1);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto requires = new int[][](n);\n\tauto requiredBy = new int[][](n);\n\tauto requirements = new int[](n);\n\tauto understandable = redBlackTree!int;\n\tauto processed = new bool[](n);\n\tint size = n;\n\tforeach(i; 0 .. n)\n\t{\n\t\tauto k = readInt!int;\n\t\trequires[i] = ma(k, readInt!int - 1);\n\t\trequirements[i] = cast(int)requires[i].length;\n\t\tforeach(j; requires[i])\n\t\t\trequiredBy[j] ~= i;\n\t\tif (requires[i].length == 0)\n\t\t{\n\t\t\tunderstandable.insert(i);\n\t\t}\n\t}\n\tint passes = 0;\n\twhile (!understandable.empty)\n\t{\n\t\tpasses++;\n\t\tauto range = understandable.upperBound(-1);\n\t\twhile (!range.empty)\n\t\t{\n\t\t\tauto current = range.front;\n\t\t\tunderstandable.removeKey(current);\n\t\t\tprocessed[current] = true;\n\t\t\tforeach(dependents; requiredBy[current])\n\t\t\t{\n\t\t\t\trequirements[dependents]--;\n\t\t\t\tassert(requirements[dependents] >= 0);\n\t\t\t\tif (requirements[dependents] == 0)\n\t\t\t\t{\n\t\t\t\t\tunderstandable.insert(dependents);\n\t\t\t\t}\n\t\t\t}\n\t\t\trange = understandable.upperBound(current);\n\t\t}\n\t}\n\tbool remain = false;\n\tforeach(ins;processed) if (!ins) remain = true;\n\tif (remain)\n\t{\n\t\twriteln(-1);\n\t}\n\telse\n\t{\n\t\twriteln(passes);\n\t}\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] K;\nint[][] A;\n\nint[] vis;\nint[] dp;\n\nbool dfs(int u) {\n vis[u] = 1;\n dp[u] = 1;\n foreach (v; A[u]) {\n if (vis[v] == 0) {\n if (!dfs(v)) {\n return false;\n }\n } else if (vis[v] == 1) {\n return false;\n }\n chmax(dp[u], ((u < v) ? 1 : 0) + dp[v]);\n }\n vis[u] = 2;\n return true;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n N = readInt();\n K = new int[N];\n A = new int[][N];\n foreach (u; 0 .. N) {\n K[u] = readInt();\n A[u] = new int[K[u]];\n foreach (k; 0 .. K[u]) {\n A[u][k] = readInt() - 1;\n }\n }\n \n vis = new int[N];\n dp = new int[N];\n bool ok = true;\n foreach (u; 0 .. N) {\n if (vis[u] == 0) {\n if (!dfs(u)) {\n ok = false;\n break;\n }\n }\n }\n \n int ans;\n if (ok) {\n ans = dp.maxElement;\n } else {\n ans = -1;\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto requires = new int[][](n);\n\tauto requiredBy = new int[][](n);\n\tauto requirements = new int[](n);\n\tauto understandable = redBlackTree!int;\n\tauto processed = new bool[](n);\n\tint size = n;\n\tforeach(i; 0 .. n)\n\t{\n\t\tauto k = readInt!int;\n\t\trequires[i] = ma(k, readInt!int - 1);\n\t\trequirements[i] = cast(int)requires[i].length;\n\t\tforeach(j; requires[i])\n\t\t\trequiredBy[j] ~= i;\n\t\tif (requires[i].length == 0)\n\t\t{\n\t\t\tunderstandable.insert(i);\n\t\t}\n\t}\n\tint passes = 0;\n\twhile (!understandable.empty)\n\t{\n\t\tpasses++;\n\t\tauto range = understandable.upperBound(-1);\n\t\twhile (!range.empty)\n\t\t{\n\t\t\tauto current = range.front;\n\t\t\tunderstandable.removeKey(current);\n\t\t\tprocessed[current] = true;\n\t\t\tforeach(dependents; requiredBy[current])\n\t\t\t{\n\t\t\t\trequirements[dependents]--;\n\t\t\t\tassert(requirements[dependents] >= 0);\n\t\t\t\tif (requirements[dependents] == 0)\n\t\t\t\t{\n\t\t\t\t\tunderstandable.insert(dependents);\n\t\t\t\t}\n\t\t\t}\n\t\t\trange = understandable.upperBound(current);\n\t\t}\n\t}\n\tif (!all(processed))\n\t{\n\t\twriteln(-1);\n\t}\n\telse\n\t{\n\t\twriteln(passes);\n\t}\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] K;\nint[][] A;\n\nint[] vis;\nint[] dp;\n\nbool dfs(int u) {\n vis[u] = 1;\n dp[u] = 1;\n foreach (v; A[u]) {\n if (vis[v] == 0) {\n if (!dfs(v)) {\n return false;\n }\n chmax(dp[u], ((u < v) ? 1 : 0) + dp[v]);\n } else if (vis[v] == 1) {\n return false;\n }\n }\n vis[u] = 2;\n return true;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n N = readInt();\n K = new int[N];\n A = new int[][N];\n foreach (u; 0 .. N) {\n K[u] = readInt();\n A[u] = new int[K[u]];\n foreach (k; 0 .. K[u]) {\n A[u][k] = readInt() - 1;\n }\n }\n \n vis = new int[N];\n dp = new int[N];\n bool ok = true;\n foreach (u; 0 .. N) {\n if (vis[u] == 0) {\n if (!dfs(u)) {\n ok = false;\n break;\n }\n }\n }\n \n int ans;\n if (ok) {\n ans = dp.maxElement;\n } else {\n ans = -1;\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "af40a0de6d3c0ff7bcd2c1b077b05d6e"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, s;\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i <= n / 2)\n\t\t\t{\n\t\t\t\tres += max (0, a[i] - s);\n\t\t\t}\n\t\t\tif (i >= n / 2)\n\t\t\t{\n\t\t\t\tres += max (0, s - a[i]);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, s;\n readf(\"%s %s\", &n, &s);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr.sort();\n \n auto ans = 0L;\n if (arr[n/2] < s) {\n foreach (e; arr[n/2 .. $]) {\n if (e < s) ans += s - e;\n }\n } else if (arr[n/2] > s) {\n foreach (e; arr[0 .. n/2 + 1]) {\n if (e > s) ans += e - s;\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto S = s[1].to!long;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n\n int i = N / 2;\n long ans = 0;\n\n if (A[i] > S) {\n while (i >= 0 && A[i] > S) {\n ans += A[i] - S;\n i -= 1;\n }\n } else if (A[i] < S) {\n while (i < N && A[i] < S) {\n ans += S - A[i];\n i += 1;\n }\n }\n\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "0df33cd53575471b1cc20702bf777059"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!int;\n\tauto s = RD!string;\n\n\tauto m = N - 11 + 1;\n\tlong cnt;\n\tforeach (i; 0..m)\n\t{\n\t\tif (s[i] == '8')\n\t\t{\n\t\t\t++cnt;\n\t\t}\n\t}\n\n\twriteln(cnt > m / 2 ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto used = new bool[](N);\n\n for (int i = 0, j = 0, t = 0, rest = N; rest > 11; t ^= 1, --rest) {\n if (t == 0) {\n while (i < N && (used[i] || S[i] == '8')) ++i;\n if (i >= N) {\n writeln(\"YES\");\n return;\n }\n used[i] = true;\n } else {\n while (j < N && (used[j] || S[j] != '8')) ++j;\n if (j >= N) {\n writeln(\"NO\");\n return;\n }\n used[j] = true;\n }\n }\n\n foreach (i; 0..N) {\n if (!used[i]) {\n writeln(S[i] == '8' ? \"YES\" : \"NO\");\n return;\n }\n }\n}"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nvoid main() {\n auto n = readln.strip.to!int;\n auto s = readln.strip[0 .. n];\n auto psteps = (n - 11) >> 1;\n auto t = s[0 .. n - 10];\n int e;\n foreach (i; 0 .. t.length) {\n if (t[i] == '8') {\n ++e;\n }\n }\n writeln (e > psteps ? \"YES\" : \"NO\");\n}\n\n"}], "negative_code": [], "src_uid": "99f37936b243907bf4ac1822dc547a61"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n auto n = 2 * r.next!int;\n auto a = r.nextA!int(n);\n auto idx = new size_t[n];\n a.sort();\n if (a[0] == a[n-1]) {\n writeln (-1);\n } else {\n writefln (\"%(%s %)\", a);\n }\n}\n\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr.sort();\n \n if (arr.front == arr.back) {\n writeln(-1);\n return;\n }\n \n arr.writefln!\"%(%s %)\";\n}"}, {"source_code": "import core.stdc.stdio;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\n\nvoid main()\n{\n uint n;\n scanf(\"%ud\", &n);\n int[] a = new int[2 * n];\n for (int i = 0; i < 2 * n; i++)\n {\n scanf(\"%d\", &a[i]);\n }\n\n sort(a);\n\n auto t1 = sum(a[0 .. n]);\n auto t2 = sum(a[n .. 2 * n]);\n if (t1 == t2)\n writeln(-1);\n else\n writefln(\"%(%d %)\", a);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto N = RD!int;\n\tauto A = RDR.ARR;\n\tA.sort();\n\tlong sum1, sum2;\n\tforeach (i; 0..N*2)\n\t{\n\t\tif (i < N)\n\t\t\tsum1 += A[i];\n\t\telse\n\t\t\tsum2 += A[i];\n\t}\n\n\tif (sum1 == sum2)\n\t\twriteln(-1);\n\telse\n\t\tA.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "1f4c057dff45f229b4dca49cd4e0438d"} {"source_code": "import std.stdio;\n\nimmutable int limit = 1 << 20;\nint [limit] t;\n\nvoid add (int v, int delta = 1)\n{\n\tfor ( ; v < limit; v += v & -v)\n\t{\n\t\tt[v] += delta;\n\t}\n}\n\nint pop (int k)\n{\n\tint pos = limit >> 1;\n\tfor (int x = limit >> 2; x > 0; x >>= 1)\n\t{\n\t\tif (k > t[pos])\n\t\t{\n\t\t\tk -= t[pos];\n\t\t\tpos += x;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpos -= x;\n\t\t}\n\t}\n\tpos += (k > t[pos]);\n\tadd (pos, -1);\n\treturn pos;\n}\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tt[] = 0;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v;\n\t\t\treadf !(\" %s\") (v);\n\t\t\tadd (v);\n\t\t}\n\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint k;\n\t\t\treadf !(\" %s\") (k);\n\t\t\tif (k > 0)\n\t\t\t{\n\t\t\t\tadd (k);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpop (-k);\n\t\t\t}\n\t\t}\n\n\t\tauto res = pop (1);\n\t\twriteln (res < limit ? res : 0);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;\n\nstruct BITree(alias _fun, alias E, T)\nif (is(typeof(E) : T))\n{\n import std.functional : binaryFun;\n alias OP = binaryFun!_fun;\n\n ///\n this(size_t n, T[] ts) {\n this.n = n;\n this.tree.length = n+1;\n foreach (ref e; this.tree) e = E;\n foreach (i, t; ts) this.update(i, t);\n }\n\n void update(size_t i, T e) {\n i += 1;\n while (i <= this.n) {\n this.tree[i] = OP(this.tree[i], e);\n i += i & -i;\n }\n }\n\n ///\n T query(size_t i) {\n auto r = E;\n while (i > 0) {\n r = OP(r, this.tree[i]);\n i -= i & -i;\n }\n return r;\n }\n\nprivate:\n size_t n;\n T[] tree;\n}\n\nauto bitree(alias fun, alias init, T)(size_t n, T[] ts = [])\n{\n return BITree!(fun, init, T)(n, ts);\n}\n\n///\nauto bitree(alias fun, alias init, T)(T[] ts)\n{\n return BITree!(fun, init, T)(ts.length, ts);\n}\n\nauto sum_bitree(T)(size_t n, T[] ts = [])\n{\n return bitree!(\"a + b\", 0, T)(n, ts);\n}\n\nauto sum_bitree(T)(T[] ts)\n{\n return sum_bitree!T(ts.length, ts);\n}\n\nvoid main()\n{\n auto nq = readln.split.to!(int[]);\n auto N = nq[0];\n auto Q = nq[1];\n auto bit = sum_bitree!int(N+1);\n foreach (_; 0..N) {\n int a;\n readf(\" %d\", &a);\n bit.update(a, 1);\n }\n foreach (_; 0..Q) {\n int q;\n readf(\" %d\", &q);\n if (q < 0) {\n q = -q;\n size_t l = 1, r = N+1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n if (bit.query(m) < q) {\n l = m;\n } else {\n r = m;\n }\n }\n bit.update(l, -1);\n } else {\n bit.update(q, 1);\n }\n }\n foreach (i; 1..N+1) if (bit.query(i+1) > 0) {\n writeln(i);\n return;\n }\n writeln(0);\n}"}, {"source_code": "import std.stdio;\n\nimmutable int limit = (1 << 20) + 1;\nint [limit] t;\n\nvoid add (int v, int delta = 1)\n{\n\tfor ( ; v < limit; v += v & -v)\n\t{\n\t\tt[v] += delta;\n\t}\n}\n\nint pop (int k)\n{\n\tint pos = limit >> 1;\n\tfor (int x = limit >> 2; x > 0; x >>= 1)\n\t{\n\t\tif (k > t[pos])\n\t\t{\n\t\t\tk -= t[pos];\n\t\t\tpos += x;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpos -= x;\n\t\t}\n\t}\n\tpos += (k > t[pos]);\n\tadd (pos, -1);\n\treturn pos;\n}\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tt[] = 0;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v;\n\t\t\treadf !(\" %s\") (v);\n\t\t\tadd (v);\n\t\t}\n\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint k;\n\t\t\treadf !(\" %s\") (k);\n\t\t\tif (k > 0)\n\t\t\t{\n\t\t\t\tadd (k);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpop (-k);\n\t\t\t}\n\t\t}\n\n\t\tauto res = pop (1);\n\t\twriteln (t[res] >= 0 ? res : 0);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimmutable int z = 1 << 20;\nint [z] t;\nvoid a (int v, int d = 1) {\n\tfor ( ; v < z; v += v & -v) t[v] += d;\n}\nint p (int k) {\n\tint v = z >> 1;\n\tfor (int b = z >> 2; b > 0; b >>= 1)\n\t\tif (k > t[v]) k -= t[v], v += b;\n\t\telse v -= b;\n\tv += (k > t[v]);\n\ta (v, -1);\n\treturn v;\n}\nvoid main () {\n\tint n, m, x, r;\n\treadf !(\" %d %d\") (n, m);\n\tforeach (i; 0..n) readf !(\" %d\") (x), a (x);\n\tforeach (j; 0..m) {\n\t\treadf !(\" %d\") (x);\n\t\tif (x > 0) a (x);\n\t\telse p (-x);\n\t}\n\tr = p (1);\n\twriteln (r < z ? r : 0);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int limit = 1 << 20;\n__gshared int [limit] t;\n\nvoid add (int v, int delta = 1)\n{\n\tfor ( ; v < limit; v += v & -v)\n\t{\n\t\tt[v] += delta;\n\t}\n}\n\nint pop (int k)\n{\n\tint pos = limit >> 1;\n\tfor (int x = limit >> 2; x > 0; x >>= 1)\n\t{\n\t\tif (k > t[pos])\n\t\t{\n\t\t\tk -= t[pos];\n\t\t\tpos += x;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpos -= x;\n\t\t}\n\t}\n\tpos += (k > t[pos]);\n\tadd (pos, -1);\n\treturn pos;\n}\n\nvoid main ()\n{\n\tint n, m, v, k;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tt[] = 0;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %s\") (v);\n\t\t\tadd (v);\n\t\t}\n\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\treadf !(\" %s\") (k);\n\t\t\tif (k > 0)\n\t\t\t{\n\t\t\t\tadd (k);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpop (-k);\n\t\t\t}\n\t\t}\n\n\t\tauto res = pop (1);\n\t\twriteln (res < limit ? res : 0);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int limit = 1 << 20;\nint [limit] t;\n\nvoid add (int v, int delta = 1) {\n\tfor ( ; v < limit; v += v & -v) t[v] += delta;\n}\n\nint pop (int k) {\n\tint pos = limit >> 1;\n\tfor (int x = limit >> 2; x > 0; x >>= 1)\n\t\tif (k > t[pos]) k -= t[pos], pos += x;\n\t\telse pos -= x;\n\tpos += (k > t[pos]);\n\tadd (pos, -1);\n\treturn pos;\n}\n\nvoid main () {\n\tint n, m, v, k;\n\treadf !(\" %d %d\") (n, m);\n\tforeach (i; 0..n) readf !(\" %d\") (v), add (v);\n\tforeach (j; 0..m) {\n\t\treadf !(\" %d\") (k);\n\t\tif (k > 0) add (k);\n\t\telse pop (-k);\n\t}\n\n\tauto res = pop (1);\n\twriteln (res < limit ? res : 0);\n}\n"}, {"source_code": "import core.bitop, std.stdio;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tauto z = 1 << bsr (n);\n\t\tauto t = new int [z * 2 + 1];\n\n\t\tvoid add (int v, int delta = 1)\n\t\t{\n\t\t\tfor ( ; v <= z * 2; v += v & -v)\n\t\t\t{\n\t\t\t\tt[v] += delta;\n\t\t\t}\n\t\t}\n\n\t\tint pop (int k)\n\t\t{\n\t\t\tint pos = z;\n\t\t\tfor (int x = z >> 1; x > 0; x >>= 1)\n\t\t\t{\n\t\t\t\tif (k > t[pos])\n\t\t\t\t{\n\t\t\t\t\tk -= t[pos];\n\t\t\t\t\tpos += x;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpos -= x;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpos += (k > t[pos]);\n\t\t\tadd (pos, -1);\n\t\t\treturn pos;\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v;\n\t\t\treadf !(\" %s\") (v);\n\t\t\tadd (v);\n\t\t}\n\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint k;\n\t\t\treadf !(\" %s\") (k);\n\t\t\tif (k > 0)\n\t\t\t{\n\t\t\t\tadd (k);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpop (-k);\n\t\t\t}\n\t\t}\n\n\t\tauto res = pop (1);\n\t\twriteln (t[res] >= 0 ? res : 0);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int limit = 1 << 20;\n__gshared int [limit] t;\n\nvoid add (int v, int delta = 1)\n{\n\tfor ( ; v < limit; v += v & -v)\n\t{\n\t\tt[v] += delta;\n\t}\n}\n\nint pop (int k)\n{\n\tint pos = limit >> 1;\n\tfor (int x = limit >> 2; x > 0; x >>= 1)\n\t{\n\t\tif (k > t[pos])\n\t\t{\n\t\t\tk -= t[pos];\n\t\t\tpos += x;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpos -= x;\n\t\t}\n\t}\n\tpos += (k > t[pos]);\n\tadd (pos, -1);\n\treturn pos;\n}\n\nvoid main ()\n{\n\tint n, m, v, k;\n\twhile (readf !(\" %d %d\") (n, m) > 0)\n\t{\n\t\tt[] = 0;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %d\") (v);\n\t\t\tadd (v);\n\t\t}\n\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\treadf !(\" %d\") (k);\n\t\t\tif (k > 0)\n\t\t\t{\n\t\t\t\tadd (k);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpop (-k);\n\t\t\t}\n\t\t}\n\n\t\tauto res = pop (1);\n\t\twriteln (res < limit ? res : 0);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int limit = 1 << 20;\nint [] t;\n\nvoid add (int v, int delta = 1)\n{\n\tfor ( ; v < limit; v += v & -v)\n\t{\n\t\tt[v] += delta;\n\t}\n}\n\nint pop (int k)\n{\n\tint pos = limit >> 1;\n\tfor (int x = limit >> 2; x > 0; x >>= 1)\n\t{\n\t\tif (k > t[pos])\n\t\t{\n\t\t\tk -= t[pos];\n\t\t\tpos += x;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpos -= x;\n\t\t}\n\t}\n\tpos += (k > t[pos]);\n\tadd (pos, -1);\n\treturn pos;\n}\n\nvoid main ()\n{\n\tt = new int [limit];\n\tint n, m, v, k;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tt[] = 0;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %s\") (v);\n\t\t\tadd (v);\n\t\t}\n\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\treadf !(\" %s\") (k);\n\t\t\tif (k > 0)\n\t\t\t{\n\t\t\t\tadd (k);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpop (-k);\n\t\t\t}\n\t\t}\n\n\t\tauto res = pop (1);\n\t\twriteln (res < limit ? res : 0);\n\t}\n}\n"}], "negative_code": [], "src_uid": "bbbd29774742636a2282dd433ed77b8c"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip.map !(x => x - '0').array;\n\t\tauto f = 0 ~ readln.splitter.map !(to !(int)).array;\n\t\tint pos = 0;\n\t\twhile (pos < n && f[s[pos]] <= s[pos])\n\t\t{\n\t\t\tpos += 1;\n\t\t}\n\t\twhile (pos < n && f[s[pos]] >= s[pos])\n\t\t{\n\t\t\ts[pos] = f[s[pos]];\n\t\t\tpos += 1;\n\t\t}\n\t\twritefln (\"%(%s%)\", s);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT read(T)(){ return read.to!T; }\nT[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }\nT[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\t\n\tint n = read.to!int;\n\tchar[] a = readln.chomp.to!(char[]);\n\t\n\tchar[char] y;\n\tforeach(c; \"123456789\") y[c] = '0', y[c] += read.to!int.to!char;\n\t\n\tint f = 0;\n\tforeach(i, c; a){\n\t\tif(f == 0){\n\t\t\tif(y[c] <= c) continue;\n\t\t\telse{\n\t\t\t\tf = 1;\n\t\t\t\ta[i] = y[c];\n\t\t\t}\n\t\t}\n\t\telse if(f == 1){\n\t\t\tif(y[c] < c){\n\t\t\t\tf = 2;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse{\n\t\t\t\ta[i] = y[c];\n\t\t\t}\n\t\t}\n\t}\n\t\n\ta.to!string.writeln;\n\t\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD;\n\tauto s = RD!string;\n\tauto a = RDR.ARR;\n\t\n\tauto use = new bool[](9);\n\tforeach (i; 0..9)\n\t{\n\t\tif (a[i] > i+1) use[i] = true;\n\t}\n\tdebug writeln(use);\n\n\tstring ans;\n\tlong mode;\n\tforeach (c; s)\n\t{\n\t\tuint x = c - '0';\n\t\tif (mode == 0 && a[x-1] > x)\n\t\t{\n\t\t\tans ~= to!string(a[x-1]);\n\t\t\tmode = 1;\n\t\t}\n\t\telse if (mode == 1 && a[x-1] >= x)\n\t\t{\n\t\t\tans ~= to!string(a[x-1]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans ~= c;\n\t\t\tif (mode == 1)\n\t\t\t\tmode = 2;\n\t\t}\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/1157/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n\n string a = readln.chomp;\n\n int[] f = [-1];\n f ~= readln.split.map!(to!int).array;\n\n int idx = 0;\n while(idx < n && f[a[idx]-'0'] <= a[idx]-'0') {\n a[idx].write;\n idx += 1;\n }\n\n while(idx < n && f[a[idx]-'0'] >= a[idx]-'0') {\n f[a[idx]-'0'].write;\n idx += 1;\n }\n\n while(idx < n) {\n a[idx].write;\n idx += 1;\n }\n writeln;\n}\n\n"}], "negative_code": [{"source_code": "// https://codeforces.com/problemset/problem/1157/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n\n string a = readln.chomp;\n\n int[] f = [-1];\n f ~= readln.split.map!(to!int).array;\n\n bool change = true;\n foreach(ch; a) {\n int digit = ch-'0';\n if(f[digit] < digit)\n change = false;\n if(f[digit] > digit && change)\n f[digit].write;\n else\n digit.write;\n } writeln;\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1157/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n\n string a = readln.chomp;\n\n int[] f = [-1];\n f ~= readln.split.map!(to!int).array;\n\n foreach(ch; a) {\n int digit = ch-'0';\n if(f[digit] > digit)\n f[digit].write;\n else\n digit.write;\n } writeln;\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1157/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n\n string a = readln.chomp;\n\n int[] f = [-1];\n f ~= readln.split.map!(to!int).array;\n\n int idx = 0;\n while(idx < n && f[idx] <= a[idx]) {\n a[idx].write;\n idx += 1;\n }\n\n while(idx < n && f[idx] >= a[idx]) {\n f[idx].write;\n idx += 1;\n }\n\n while(idx < n) {\n a[idx].write;\n idx += 1;\n }\n writeln;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD;\n\tauto s = RD!string;\n\tauto a = RDR.ARR;\n\t\n\tauto use = new bool[](9);\n\tforeach (i; 0..9)\n\t{\n\t\tif (a[i] > i) use[i] = true;\n\t}\n\n\tstring ans;\n\tforeach (i, c; s)\n\t{\n\t\tuint x = c - '0';\n\t\tif (use[x-1])\n\t\t\tans ~= to!string(a[x-1]);\n\t\telse\n\t\t\tans ~= c;\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD;\n\tauto s = RD!string;\n\tauto a = RDR.ARR;\n\t\n\tauto use = new bool[](9);\n\tforeach (i; 0..9)\n\t{\n\t\tif (a[i] > i+1) use[i] = true;\n\t}\n\tdebug writeln(use);\n\n\tstring ans;\n\tlong mode;\n\tforeach (c; s)\n\t{\n\t\tuint x = c - '0';\n\t\tif (mode == 0 && a[x-1] > x)\n\t\t{\n\t\t\tans ~= to!string(a[x-1]);\n\t\t\tmode = 1;\n\t\t}\n\t\tif (mode == 1 && a[x-1] >= x)\n\t\t{\n\t\t\tans ~= to!string(a[x-1]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans ~= c;\n\t\t\tif (mode == 1)\n\t\t\t\tmode = 2;\n\t\t}\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD;\n\tauto s = RD!string;\n\tauto a = RDR.ARR;\n\t\n\tauto use = new bool[](9);\n\tforeach (i; 0..9)\n\t{\n\t\tif (a[i] > i) use[i] = true;\n\t}\n\n\tlong ans;\n\tforeach (i, c; s)\n\t{\n\t\tlong d = s.length - i - 1;\n\t\tuint x = c - '0';\n\t\tif (use[x-1])\n\t\t\tans += a[x-1] * (10^^d);\n\t\telse\n\t\t\tans += x * (10^^d);\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD;\n\tauto s = RD!string;\n\tauto a = RDR.ARR;\n\t\n\tauto use = new bool[](9);\n\tforeach (i; 0..9)\n\t{\n\t\tif (a[i] > i+1) use[i] = true;\n\t}\n\tdebug writeln(use);\n\n\tstring ans;\n\tlong mode;\n\tforeach (c; s)\n\t{\n\t\tuint x = c - '0';\n\t\tif ((mode == 0 || mode == 1) && use[x-1])\n\t\t{\n\t\t\tans ~= to!string(a[x-1]);\n\t\t\tmode = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans ~= c;\n\t\t\tif (mode == 1)\n\t\t\t\tmode = 2;\n\t\t}\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "378a9ab7ad891d60f23645106d24f314"} {"source_code": "//\u0414\u0430, \u044f \u0443\u043f\u043e\u0440\u043e\u043b\u0441\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 Splay-\u0434\u0435\u0440\u0435\u0432\u043e\u043c)\nimport core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n return readf(' ' ~ replicate(\"%s \", vars.length), getAddrTuple(vars).expand) == vars.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Node {\n int value, firstValue, lastValue;\n bool sorted = true;\n Splay left, right, parent;\n\n invariant {\n assert(firstValue == (left !is null ? left.firstValue : value));\n assert(lastValue == (right !is null ? right.lastValue : value));\n assert(sorted == (\n left.sorted && right.sorted &&\n value >= (left !is null ? left.lastValue : value) &&\n value <= (right !is null ? right.firstValue : value)\n ));\n }\n\n enum { L, R }\n\n this(int x) {\n value = firstValue = lastValue = x;\n }\n\n Splay splayLeft() return\n out (result) {\n assert(result.parent is null);\n assert(result.left is null);\n }\n body {\n if (left !is null)\n return left.splayLeft();\n splay();\n return Splay(&this);\n }\n\n Splay splayRight() return\n out (result) {\n assert(result.parent is null);\n assert(result.right is null);\n }\n body {\n if (right !is null)\n return right.splayRight();\n splay();\n return Splay(&this);\n }\n\n void splay()\n out {\n assert(parent is null);\n }\n body {\n while (true) {\n auto parent = parent;\n if (parent is null)\n return;\n if (parent.parent is null) {\n rotate();\n return;\n }\n if (side == parent.side)\n parent.rotate();\n else\n rotate();\n rotate();\n }\n }\n\n void rotate()\n in {\n assert(parent !is null);\n }\n body {\n auto parent = parent;\n auto gparent = parent.parent;\n auto side = side;\n auto parentSide = gparent !is null ? parent.side : 0;\n unlink();\n parent.unlink();\n if (side == L) {\n if (auto right = right) {\n right.unlink();\n right.link(L, parent);\n }\n parent.link(R, Splay(&this));\n } else {\n if (auto left = left) {\n left.unlink();\n left.link(R, parent);\n }\n parent.link(L, Splay(&this));\n }\n link(parentSide, gparent);\n }\n\nprivate:\n void recalc() {\n firstValue = left !is null ? left.firstValue : value;\n lastValue = right !is null ? right.lastValue : value;\n sorted = left.sorted && right.sorted;\n if (left !is null)\n sorted &= value >= left.lastValue;\n if (right !is null)\n sorted &= value <= right.firstValue;\n }\n\n @property int side() const\n in {\n assert(parent !is null);\n }\n body {\n return &this is parent.left ? L : R;\n }\n\n void link(int c, Splay newParent)\n in {\n assert(parent is null);\n if (newParent !is null)\n assert((c == L ? newParent.left : newParent.right) is null);\n }\n out {\n assert(parent is newParent);\n }\n body {\n if (!newParent)\n return;\n parent = newParent;\n if (c == L)\n newParent.left = &this;\n else\n newParent.right = &this;\n newParent.recalc();\n }\n\n void unlink()\n out {\n assert(parent is null);\n }\n body {\n if (parent is null)\n return;\n if (side == L)\n parent.left = null;\n else\n parent.right = null;\n parent.recalc();\n parent = null;\n }\n}\n\nstruct Splay {\n Node* _node;\n\n alias _node this;\n\n @property int firstValue() const { return _node !is null ? _node.firstValue : int.min; }\n @property int lastValue() const { return _node !is null ? _node.lastValue : int.max; }\n @property bool sorted() const { return _node !is null ? _node.sorted : true; }\n\n void append(Splay t) {\n if (_node)\n link(L, t);\n this = t;\n }\n\n void shift() {\n auto item = splayRight();\n this = item.left;\n unlink();\n this = splayLeft();\n link(R, item);\n this = item;\n }\n}\n\nNode[10^^5] _nodes;\n\nvoid main() {\n int n;\nnextCase:\n while (scanf(\"%d\", &n) == 1) {\n version (LocalProject)\n _nodes[ ] = Node.init;\n Splay t;\n foreach (ref node; _nodes[0 .. n]) {\n int x;\n scanf(\"%d\", &x);\n node = Node(x);\n t.append(Splay(&node));\n }\n\n foreach (i; 0 .. n) {\n if (t.sorted) {\n printf(\"%d\\n\", i);\n continue nextCase;\n }\n t.shift();\n }\n puts(\"-1\");\n }\n}\n", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nint[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tint[] pos;\n\t\tforeach (i; 0 .. N) {\n\t\t\tif (A[i] > A[(i + 1) % N]) {\n\t\t\t\tpos ~= i;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (pos.length == 0) {\n\t\t\twriteln(0);\n\t\t} else if (pos.length == 1) {\n\t\t\twriteln(N - 1 - pos[0]);\n\t\t} else {\n\t\t\twriteln(-1);\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "c647e36495fb931ac72702a12c6bfe58"} {"source_code": "import std.stdio,std.typecons;\nint n,t;\nbool[int] s;\nauto ans=[tuple(1,0)];\nvoid main()\n{\n\tscanf(\" %d\",&n);\n\tforeach(i;0..n)\n\t{\n\t\tscanf(\" %d\",&t);\n\t\tif(t in s)\n\t\t{\n\t\t\tans[$-1][1]=i+1;\n\t\t\tans~=tuple(i+2,0);\n\t\t\ts=s.init;\n\t\t}else{\n\t\t\ts[t]=true;\n\t\t}\n\t}\n\tif(ans.length==1)\n\t{\n\t\twriteln(-1);\n\t\treturn;\n\t}\n\twriteln(--ans.length);\n\tans[$-1][1]=n;\n\tforeach(i;ans) writeln(i[0],' ',i[1]);\n\ts=s.init;\n}", "positive_code": [{"source_code": "import std.stdio,std.typecons;\nint n,t;\nbool[int] s;\nauto ans=[tuple(1,0)];\nvoid main()\n{\n\tscanf(\" %d\",&n);\n\tforeach(i;0..n)\n\t{\n\t\tscanf(\" %d\",&t);\n\t\tif(t in s)\n\t\t{\n\t\t\tans[$-1][1]=i+1;\n\t\t\tans~=tuple(i+2,0);\n\t\t\ts=s.init;\n\t\t}else{\n\t\t\ts[t]=true;\n\t\t}\n\t}\n\tif(ans.length==1)\n\t{\n\t\twriteln(-1);\n\t\treturn;\n\t}\n\twriteln(--ans.length);\n\tans[$-1][1]=n;\n\tforeach(i;ans) writeln(i[0],' ',i[1]);\n}"}], "negative_code": [], "src_uid": "4cacec219e4577b255ddf6d39d308e10"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = new long[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] = RDA;\n\t\t}\n\n\t\tauto h = (n+1)/2;\n\t\tauto w = (m+1)/2;\n\t\tforeach (i; 0..h)\n\t\t{\n\t\t\tforeach (j; 0..w)\n\t\t\t{\n\t\t\t\tlong[] arr;\n\t\t\t\tauto k = n-i-1;\n\t\t\t\tauto l = m-j-1;\n\t\t\t\tarr ~= a[i][j];\n\t\t\t\tif (i != k)\n\t\t\t\t\tarr ~= a[k][j];\n\t\t\t\tif (j != l)\n\t\t\t\t\tarr ~= a[i][l];\n\t\t\t\tif (i != k && j != l)\n\t\t\t\t\tarr ~= a[k][l];\n\t\t\t\tif (arr.length == 1) continue;\n\t\t\t\tarr.sort();\n\t\t\t\tauto x = arr[1];\n\t\t\t\tforeach (e; arr)\n\t\t\t\t{\n\t\t\t\t\tans[ti] += abs(e - x);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, m;\n\t\treadf !(\" %s %s\") (n, m);\n\t\tauto a = new long [] [] (n, m);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\treadf !(\" %s\") (a[i][j]);\n\t\t\t}\n\t\t}\n\t\tlong res = 0;\n\t\tforeach (i; 0..(n + 1) / 2)\n\t\t{\n\t\t\tforeach (j; 0..(m + 1) / 2)\n\t\t\t{\n\t\t\t\tint [] [] c;\n\t\t\t\tc ~= [i, j];\n\t\t\t\tc ~= [n - i - 1, j];\n\t\t\t\tc ~= [i, m - j - 1];\n\t\t\t\tc ~= [n - i - 1, m - j - 1];\n\t\t\t\tsort (c);\n\t\t\t\tc = c.uniq.array;\n\t\t\t\tauto f = c.map !(d => a[d[0]][d[1]]).array;\n\t\t\t\tsort (f);\n\t\t\t\tauto mid = f[f.length / 2];\n\t\t\t\tres += f.map !(x => abs (x - mid)).sum;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.math;\n\nvoid main(string[] args)\n{\n long[100][100] mat;\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto m = next!int;\n foreach(i; 0 .. n)\n\tforeach(j; 0 .. m)\n\t mat[i][j] = next!int;\n long cost = 0;\n foreach(i; 0 .. n)\n\t{\n\t foreach(j; 0 .. m)\n\t {\n\t int si = n - 1 - i;\n\t int sj = m - 1 - j;\n\t long localcost = 0;\n\t if (si == i)\n\t\t{\n\t\t if (sj == j)\n\t\t {\n\t\t localcost = 0;\n\t\t }\n\t\t else\n\t\t {\n\t\t localcost = abs(mat[i][j] - mat[i][sj]);\n\t\t mat[i][j] = mat[i][sj];\n\t\t }\n\t\t}\n\t else\n\t\t{\n\t\t if (sj == j)\n\t\t {\n\t\t localcost = abs(mat[i][j] - mat[si][j]);\n\t\t mat[i][j] = mat[si][j];\n\t\t }\n\t\t else\n\t\t {\n\t\t localcost = int.max;\n\t\t long[] vals = [mat[i][j], mat[i][sj], mat[si][j], mat[si][sj]];\n\t\t auto svals = sort(vals);\n\t\t long usedval = vals[1];\n\t\t localcost = abs(mat[i][j] - usedval) + abs(mat[i][sj] - usedval)\n\t\t\t+ abs(mat[si][j] - usedval) + abs(mat[si][sj] - usedval);\n\t\t mat[i][j] = usedval;\n\t\t mat[i][sj] = usedval;\n\t\t mat[si][j] = usedval;\n\t\t mat[si][sj] = usedval;\n\t\t }\n\t\t}\n\t cost += localcost;\n\t }\n\t}\n cost.writeln;\n }\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n, m;\n n = rd!int;\n m = rd!int;\n ll[][] mat;\n foreach(i; 0..n){\n mat ~= rdarr;\n }\n ll oper = 0;\n foreach(i; 0..(n/2 + (n % 2 != 0))){\n foreach(j; 0..(m/2 + (m % 2 != 0))){\n ll[] vals;\n vals ~= mat[i][j];\n vals ~= mat[n - i - 1][j];\n vals ~= mat[i][m - j - 1];\n vals ~= mat[n - i - 1][m - j - 1];\n ll minval = to!ll(1e12);\n foreach(v; vals){\n ll cursum = 0;\n foreach(u; vals){\n cursum += abs(u - v);\n }\n minval = min(cursum, minval);\n }\n if(i == n/2){\n minval /= 2L;\n }\n if(j == m/2){\n minval /= 2;\n }\n oper += minval;\n }\n }\n writeln(oper);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n ll a = rd;\n ll b = rd;\n ll c = rd;\n writeln(a + b + c - 1);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, m;\n\t\treadf !(\" %s %s\") (n, m);\n\t\tauto a = new int [] [] (n, m);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\treadf !(\" %s\") (a[i][j]);\n\t\t\t}\n\t\t}\n\t\tint res = 0;\n\t\tforeach (i; 0..(n + 1) / 2)\n\t\t{\n\t\t\tforeach (j; 0..(m + 1) / 2)\n\t\t\t{\n\t\t\t\tint [] [] c;\n\t\t\t\tc ~= [i, j];\n\t\t\t\tc ~= [n - i - 1, j];\n\t\t\t\tc ~= [i, m - j - 1];\n\t\t\t\tc ~= [n - i - 1, m - j - 1];\n\t\t\t\tsort (c);\n\t\t\t\tc = c.uniq.array;\n\t\t\t\tauto f = c.map !(d => a[d[0]][d[1]]).array;\n\t\t\t\tsort (f);\n\t\t\t\tauto mid = f[f.length / 2];\n\t\t\t\tres += f.map !(x => abs (x - mid)).sum;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = new long[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] = RDA;\n\t\t}\n\n\t\tauto h = (n+1)/2;\n\t\tauto w = (m+1)/2;\n\t\tforeach (i; 0..h)\n\t\t{\n\t\t\tforeach (j; 0..w)\n\t\t\t{\n\t\t\t\tlong[] arr;\n\t\t\t\tauto k = n-i-1;\n\t\t\t\tauto l = m-j-1;\n\t\t\t\tarr ~= a[i][j];\n\t\t\t\tif (i != k)\n\t\t\t\t\tarr ~= a[k][j];\n\t\t\t\tif (j != l)\n\t\t\t\t\tarr ~= a[i][l];\n\t\t\t\tarr ~= a[k][l];\n\t\t\t\tarr.sort();\n\t\t\t\tauto x = arr[1];\n\t\t\t\tforeach (e; arr)\n\t\t\t\t{\n\t\t\t\t\tans[ti] += abs(e - x);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = new long[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] = RDA;\n\t\t}\n\n\t\tauto h = (n+1)/2;\n\t\tauto w = (m+1)/2;\n\t\tforeach (i; 0..h)\n\t\t{\n\t\t\tforeach (j; 0..w)\n\t\t\t{\n\t\t\t\tlong[] arr;\n\t\t\t\tauto k = n-i-1;\n\t\t\t\tauto l = m-j-1;\n\t\t\t\tarr ~= a[i][j];\n\t\t\t\tif (i != k)\n\t\t\t\t\tarr ~= a[k][j];\n\t\t\t\tif (j != l)\n\t\t\t\t\tarr ~= a[i][l];\n\t\t\t\tif (i != k && j != l)\n\t\t\t\t\tarr ~= a[k][l];\n\t\t\t\tif (arr.length == 1) continue;\n\t\t\t\tarr.sort();\n\t\t\t\tauto x = arr[1];\n\t\t\t\tforeach (e; arr)\n\t\t\t\t{\n\t\t\t\t\tans[ti] += abs(e - x);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "5aa709f292f266799f177b174c8bc14b"} {"source_code": "module main;\n\nimport std.stdio, std.string;\n\nauto init(int n)\n{\n int[] x;\n int prev = 0;\n foreach (int i; 0 .. n)\n {\n prev ^= i;\n x ~= prev;\n //printf(\"%d \", prev);\n }\n //printf(\"\\n\");\n return x;\n}\n\nvoid solve(int[] p)\n{\n auto x = init(p.length);\n int ans = 0;\n int n = p.length;\n foreach (int i; 1 .. n + 1)\n {\n ans ^= x[i - 1];\n int cnt = (n - (i - 1)) / i;\n int left = (n - (i - 1)) % i;\n //printf(\"%d %d\\n\", cnt, left);\n if (cnt & 1)\n {\n ans ^= x[i - 1];\n }\n if (left != 0)\n {\n ans ^= x[left - 1];\n }\n ans ^= p[i - 1];\n }\n writefln(\"%d\", ans);\n //printf(\"%d\\n\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n int[] p = new int[n];\n foreach (int i; 0 .. n)\n {\n scanf(\"%d\", &p[i]);\n }\n solve(p);\n }\n return 0;\n}", "positive_code": [{"source_code": "module main;\n\nimport std.stdio, std.string;\n\nauto init(int n)\n{\n int[] x = new int[n];\n int prev = 0;\n foreach (int i; 0 .. n)\n {\n prev ^= i;\n \n x[i] = prev;\n //x ~= prev;\n //printf(\"%d \", prev);\n }\n //printf(\"\\n\");\n return x;\n}\n\nvoid solve(int[] p)\n{\n auto x = init(p.length);\n int ans = 0;\n int n = p.length;\n foreach (int i; 1 .. n + 1)\n {\n ans ^= x[i - 1];\n int cnt = (n - (i - 1)) / i;\n int left = (n - (i - 1)) % i;\n //printf(\"%d %d\\n\", cnt, left);\n if (cnt & 1)\n {\n ans ^= x[i - 1];\n }\n if (left != 0)\n {\n ans ^= x[left - 1];\n }\n ans ^= p[i - 1];\n }\n writefln(\"%d\", ans);\n //printf(\"%d\\n\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n int[] p = new int[n];\n foreach (int i; 0 .. n)\n {\n scanf(\"%d\", &p[i]);\n }\n solve(p);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "35d68cc84b4c0025f03f857779f540d7"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10^^9;\nenum W = 1;\n\nalias Result = Tuple!(int, \"cost\", int, \"a0\", int, \"b0\");\nResult[long] cache;\nResult calc(int a, int b) {\n const key = cast(long)(a) << 20 | b;\n auto ptr = key in cache;\n if (ptr) return *ptr;\n Result ret = Result(INF, -1, -1);\n \n if (a + b <= 2) {\n ret.cost = 0;\n } else if (b == 0) {\n // ask a0\n foreach (a0; (a / 2 - W) .. (a / 2 + W) + 1) if (0 < a0 && a0 < a) {\n const a1 = a - a0;\n if (chmin(ret.cost, 1 + max(calc(a0, a1).cost, calc(a1, a0).cost))) {\n ret.a0 = a0;\n }\n }\n } else if (b == 1) {\n // ask b\n ret.cost = 1 + max(calc(b, a).cost, calc(a, 0).cost);\n } else {\n // ask a0, b0\n foreach (a0; (a / 2 - W) .. (a / 2 + W) + 1) if (0 <= a0 && a0 <= a) {\n foreach (b0; (b / 2 - W) .. (b / 2 + W) + 1) if (0 < b0 && b0 < b) {\n const a1 = a - a0;\n const b1 = b - b0;\n if (chmin(ret.cost, 1 + max(calc(a0 + b0, a1).cost, calc(a1 + b1, a0).cost))) {\n ret.a0 = a0;\n ret.b0 = b0;\n }\n }\n }\n }\n debug {\n if (a + b <= 5) {\n writeln(a, \" \", b, \": \", ret);\n }\n }\n \n return cache[key] = ret;\n}\n\n\nbool Ask(const(int[]) xs) {\n writef(\"? %s\", xs.length);\n foreach (x; xs) {\n write(\" \", x);\n }\n writeln;\n stdout.flush;\n const res = readToken;\n return (res == \"YES\");\n}\nvoid Answer(const(int[]) xs) {\n foreach (x; xs) {\n writefln(\"! %s\", x);\n stdout.flush;\n const res = readToken;\n if (res == \":)\") {\n return;\n }\n }\n assert(false);\n}\n\nvoid main() {\n debug {\n foreach (e; 1 .. 5 + 1) {\n const n = 10^^e;\n const res = calc(n, 0);\n writefln(\"n = %s: |cache| = %s; %s\", n, cache.length, res);\n stdout.flush;\n }\n }\n \n const N = readInt;\n int[] xs = iota(1, N + 1).array, ys;\n for (; ; ) {\n debug {\n writeln(xs, \" \", ys);\n }\n const a = cast(int)(xs.length);\n const b = cast(int)(ys.length);\n const res = calc(a, b);\n if (a + b <= 2) {\n break;\n } else if (b == 0) {\n int[] xs0 = xs[0 .. res.a0], xs1 = xs[res.a0 .. a];\n if (Ask(xs0)) {\n xs = xs0;\n ys = xs1;\n } else {\n xs = xs1;\n ys = xs0;\n }\n } else if (b == 1) {\n if (Ask(ys)) {\n swap(xs, ys);\n } else {\n ys = [];\n }\n } else {\n int[] xs0 = xs[0 .. res.a0], xs1 = xs[res.a0 .. a];\n int[] ys0 = ys[0 .. res.b0], ys1 = ys[res.b0 .. b];\n if (Ask(xs0 ~ ys0)) {\n xs = xs0 ~ ys0;\n ys = xs1;\n } else {\n xs = xs1 ~ ys1;\n ys = xs0;\n }\n }\n }\n Answer(xs ~ ys);\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n \r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n \r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n \r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\n \r\nenum INF = 10^^9;\r\nenum W = 1;\r\n \r\nalias Result = Tuple!(int, \"cost\", int, \"a0\", int, \"b0\");\r\nResult[long] cache;\r\nResult calc(int a, int b) {\r\n const key = cast(long)(a) << 20 | b;\r\n auto ptr = key in cache;\r\n if (ptr) return *ptr;\r\n Result ret = Result(INF, -1, -1);\r\n \r\n if (a + b <= 2) {\r\n ret.cost = 0;\r\n } else if (b == 0) {\r\n // ask a0\r\n foreach (a0; (a / 2 - W) .. (a / 2 + W) + 1) if (0 < a0 && a0 < a) {\r\n const a1 = a - a0;\r\n if (chmin(ret.cost, 1 + max(calc(a0, a1).cost, calc(a1, a0).cost))) {\r\n ret.a0 = a0;\r\n }\r\n }\r\n } else if (b == 1) {\r\n // ask b\r\n ret.cost = 1 + max(calc(b, a).cost, calc(a, 0).cost);\r\n } else {\r\n // ask a0, b0\r\n foreach (a0; (a / 2 - W) .. (a / 2 + W) + 1) if (0 <= a0 && a0 <= a) {\r\n foreach (b0; (b / 2 - W) .. (b / 2 + W) + 1) if (0 < b0 && b0 < b) {\r\n const a1 = a - a0;\r\n const b1 = b - b0;\r\n if (chmin(ret.cost, 1 + max(calc(a0 + b0, a1).cost, calc(a1 + b1, a0).cost))) {\r\n ret.a0 = a0;\r\n ret.b0 = b0;\r\n }\r\n }\r\n }\r\n }\r\n debug {\r\n if (a + b <= 5) {\r\n writeln(a, \" \", b, \": \", ret);\r\n }\r\n }\r\n \r\n return cache[key] = ret;\r\n}\r\n \r\n \r\nbool Ask(const(int[]) xs) {\r\n writef(\"? %s\", xs.length);\r\n foreach (x; xs) {\r\n write(\" \", x);\r\n }\r\n writeln;\r\n stdout.flush;\r\n const res = readToken;\r\n return (res == \"YES\");\r\n}\r\nvoid Answer(const(int[]) xs) {\r\n foreach (x; xs) {\r\n writefln(\"! %s\", x);\r\n stdout.flush;\r\n const res = readToken;\r\n if (res == \":)\") {\r\n return;\r\n }\r\n }\r\n assert(false);\r\n}\r\n \r\nvoid main() {\r\n debug {\r\n foreach (e; 1 .. 5 + 1) {\r\n const n = 10^^e;\r\n const res = calc(n, 0);\r\n writefln(\"n = %s: |cache| = %s; %s\", n, cache.length, res);\r\n stdout.flush;\r\n }\r\n }\r\n \r\n const N = readInt;\r\n int[] xs = iota(1, N + 1).array, ys;\r\n for (; ; ) {\r\n debug {\r\n writeln(xs, \" \", ys);\r\n }\r\n const a = cast(int)(xs.length);\r\n const b = cast(int)(ys.length);\r\n const res = calc(a, b);\r\n if (a + b <= 2) {\r\n break;\r\n } else if (b == 0) {\r\n int[] xs0 = xs[0 .. res.a0], xs1 = xs[res.a0 .. a];\r\n if (Ask(xs0)) {\r\n xs = xs0;\r\n ys = xs1;\r\n } else {\r\n xs = xs1;\r\n ys = xs0;\r\n }\r\n } else if (b == 1) {\r\n if (Ask(ys)) {\r\n swap(xs, ys);\r\n } else {\r\n ys = [];\r\n }\r\n } else {\r\n int[] xs0 = xs[0 .. res.a0], xs1 = xs[res.a0 .. a];\r\n int[] ys0 = ys[0 .. res.b0], ys1 = ys[res.b0 .. b];\r\n if (Ask(xs0 ~ ys0)) {\r\n xs = xs0 ~ ys0;\r\n ys = xs1;\r\n } else {\r\n xs = xs1 ~ ys1;\r\n ys = xs0;\r\n }\r\n }\r\n }\r\n Answer(xs ~ ys);\r\n}"}], "negative_code": [], "src_uid": "a8334846b495efbded9bb0641d6a1964"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid solve(){\n\tint n = read.to!int;\n\t\n\tNode[] nodes;\n\tforeach(i; 0 .. n) nodes ~= new Node(i);\n\t\n\tforeach(i; 0 .. n - 1){\n\t\tint u = read.to!int - 1;\n\t\tint v = read.to!int - 1;\n\t\tnodes[u].nodes ~= nodes[v];\n\t\tnodes[v].nodes ~= nodes[u];\n\t}\n\t\n\tint f = 0;\n\tforeach(nd; nodes){\n\t\tif(nd.nodes.length == 2) f = 1;\n\t}\n\t\n\tif(f == 1) \"NO\".writeln;\n\telse \"YES\".writeln;\n\t\n}\n/*\nA1: YES if and only if there are no vertex with degree 2.\n\n\n\n*/\n\nclass Node{\n\tint id;\n\tNode[] nodes;\n\tthis(int id){\n\t\tthis.id = id;\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] U, V;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n U = new int[N - 1];\n V = new int[N - 1];\n foreach (i; 0 .. N - 1) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto deg = new int[N];\n foreach (i; 0 .. N - 1) {\n ++deg[U[i]];\n ++deg[V[i]];\n }\n const ans = (deg.count(2) == 0);\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto edges = new long[][](n);\n\tforeach (i; 0..n-1)\n\t{\n\t\tauto u = RD!int-1;\n\t\tauto v = RD!int-1;\n\t\tedges[u] ~= v;\n\t\tedges[v] ~= u;\n\t}\n\n\tdebug writeln(edges);\n\tbool ans = true;\n\tforeach (i; 0..n)\n\t{\n\t\tif (edges[i].length == 2)\n\t\t{\n\t\t\tans = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\twriteln(ans ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] U, V;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n U = new int[N - 1];\n V = new int[N - 1];\n foreach (i; 0 .. N - 1) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto deg = new int[N];\n foreach (i; 0 .. N - 1) {\n ++deg[U[i]];\n ++deg[V[i]];\n }\n const long cnt = deg.count(1);\n const ans = (cnt * (cnt - 1) / 2 >= N - 1);\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "ba47e6eea45d32cba660eb6d66a9adbb"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\tint res = 5;\n\t\tstring ans = \"?????\";\n\t\tforeach (c; 0..10_000)\n\t\t{\n\t\t\tint h = c / 100;\n\t\t\tif (n == 12 && !(1 <= h && h <= 12))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (n == 24 && !(0 <= h && h <= 23))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint m = c % 100;\n\t\t\tif (!(0 <= m && m <= 59))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto t = format (\"%02d:%02d\", h, m);\n\t\t\tauto cur = t.length.iota.map !(x => s[x] != t[x]).sum;\n\t\t\tif (res > cur)\n\t\t\t{\n\t\t\t\tres = cur;\n\t\t\t\tans = t;\n\t\t\t}\n\t\t}\n\t\twriteln (ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\npure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow X binpow(X,Y)(X base,Y exp)\nif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\"~'\\n', ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\npure nothrow V foldr(R,V,T)(R range,T arg,V nach) if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n{\n\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\treturn nach;\n}\npure nothrow size_t countr(R,T)(R range,T fun) if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n{\n\tsize_t nach;\n\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\treturn nach;\n}\npure nothrow T orient_square(T)(pair!(T,T)[] figure...) if(figure.length>2 && is(typeof(figure.front*figure.front)==T))\n{\n\tauto n=figure.front,t=figure.front;\n\tfigure.popFront();\n\tT ans=0;\n\tfor(;!figure.empty;figure.popFront())\n\t{\n\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\tt=figure.front;\n\t}\n\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n}\npure nothrow real square(T)(pair!(T,T)[] figure...) if(figure.length>2 && is(typeof(figure.front*figure.front)==T))\n{\n\treturn abs(orient_square(figure))/2.00000000000;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\twhile(input(&n))\n\t{\n\t\tauto s=readln.strip.split(':').map!(to!int).array;\n\t\tint ans;\n\t\tif(s[1]>59) {s[1]%=10;}\n\t\tif(n==12)\n\t\t{\n\t\t\tif(s[0]==0){s[0]=10;}\n\t\t\telse if(s[0]>12)\n\t\t\t{\n\t\t\t\tif(s[0]%10<=2)s[0]=s[0]%10+10;\n\t\t\t\telse s[0]%=10;\n\t\t\t}\n\t\t}\n\t\telse if(s[0]>23){s[0]%=10;ans++;}\n\t\twritefln(\"%02d:%02d\",s[0],s[1]);\n\n\t}\n\tdebug system(\"pause\");\n}"}], "negative_code": [], "src_uid": "88d56c1e3a7ffa94354ce0c70d8e958f"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto T = readln.chomp;\n\n int s, t, c, max_c, d, max_d;\n foreach (i; 0..N) {\n auto s1 = S[i] == '1';\n auto t1 = T[i] == '1';\n if (s1) ++s;\n if (t1) ++t;\n\n if (s1 && !t1) {\n ++c;\n if (d > 0) --d;\n } else if (!s1 && t1) {\n ++d;\n if (c > 0) --c;\n }\n max_c = max(max_c, c);\n max_d = max(max_d, d);\n }\n\n if (s != t) {\n writeln(-1);\n } else {\n writeln(max(max_c, max_d));\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip.map !(to !(byte)).array;\n\t\tauto t = readln.strip.map !(to !(byte)).array;\n\t\tif (sum (s) != sum (t))\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\n\t\tint balance = 0;\n\t\tint lo = 0;\n\t\tint hi = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tbalance += s[i] - t[i];\n\t\t\tlo = min (lo, balance);\n\t\t\thi = max (hi, balance);\n\t\t}\n\t\twriteln (hi - lo);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto T = readln.chomp;\n\n int s, t, c, max_c;\n foreach (i; 0..N) {\n auto s1 = S[i] == '1';\n auto t1 = T[i] == '1';\n if (s1) ++s;\n if (t1) ++t;\n\n if (s1 && !t1) {\n ++c;\n } else if (!s1 && t1) {\n --c;\n }\n max_c = max(max_c, abs(c));\n }\n\n if (s != t) {\n writeln(-1);\n } else {\n writeln(max_c);\n }\n}"}], "src_uid": "f6ad39fba01389799fddc2bd7a287138"} {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\n\nint[101] a;\n\nvoid main() {\n GC.disable();\n\n int t;\n readf(\" %s\", t);\n\n foreach(q;0..t) {\n int n;\n readf(\" %s\", n);\n int[3] c;\n foreach(i;0..n) {\n int ai;\n readf(\" %s\", ai);\n c[ai%3]++;\n }\n\n auto tt = min(c[1], c[2]);\n c[1] -= tt;\n c[2] -= tt;\n\n writeln( c[0] + c[1]/3 + c[2]/3 + tt);\n }\n\n\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDR.ARR;\n\t\tauto cnt = new long[](3);\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tauto x = a[j] % 3;\n\t\t\t++cnt[cast(size_t)x];\n\t\t}\n\t\tauto x = min(cnt[1], cnt[2]);\n\t\tans[i] = cnt[0] + x + (cnt[1]-x)/3 + (cnt[2]-x)/3;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDR.ARR;\n\t\tauto cnt = new long[](3);\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tauto x = a[j] % 3;\n\t\t\t++cnt[cast(size_t)x];\n\t\t}\n\t\tauto x = min(cnt[1], cnt[2]);\n\t\tans[i] = cnt[0] + x + (cnt[1]-x)/3;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "e59cddb6c941b1d7556ee9c020701007"} {"source_code": "import core.checkedint;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n ulong n, H;\n readf( \"%s %s\", &n, &H );\n \n ulong sqr = cast( ulong ) sqrt( cast( real )( 2*n ) );\n ulong seqlen = sqr * ( sqr+1 ) <= 2*n ? sqr : sqr - 1;\n \n ulong ans;\n if ( seqlen <= H ) {\n n -= seqlen * ( seqlen+1 ) / 2;\n ans = seqlen;\n if ( n > 0 ) ans += 1;\n } else {\n ulong lo = H, hi = 2 * 10 ^^ 9;\n debug { writeln(hi); }\n while ( lo < hi ) {\n ulong m = ( lo + hi + 1 ) / 2;\n \n bool over = false;\n ulong up = mulu( ( H+m ), ( m-H+1 ), over ) / 2;\n //ulong up = ( H+m ) * ( m - H+1 ) / 2;\n bool over2 = false;\n ulong down = mulu( m, ( m-1 ), over2 ) / 2;\n //ulong down = m * ( m-1 ) / 2;\n \n debug{ if ( over || over2 ) writeln(\"dassad\"); }\n \n if ( up > n || n - up < down ) hi = m - 1;\n else lo = m;\n }\n \n debug { writeln(hi, ' ', hi - H, ' ', hi*(hi-1)/2 ); }\n \n ans = hi - ( H-1 );\n n -= ( H + hi ) * ( hi - H + 1 ) / 2;\n ans += hi - 1;\n n -= ( hi - 1 + 1 ) * ( hi - 1 ) / 2;\n ans += ( n + hi - 1 ) / hi;\n }\n \n writeln( ans );\n}", "positive_code": [{"source_code": "import core.checkedint;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n ulong n, H;\n readf( \"%s %s\", &n, &H );\n \n ulong sqr = cast( ulong ) sqrt( cast( real )( 2*n ) );\n ulong seqlen = sqr * ( sqr+1 ) <= 2*n ? sqr : sqr - 1;\n \n ulong ans;\n if ( seqlen <= H ) {\n n -= seqlen * ( seqlen+1 ) / 2;\n ans = seqlen;\n if ( n > 0 ) ans += 1;\n } else {\n ulong lo = H, hi = 2 * 10 ^^ 9;\n debug { writeln(hi); }\n while ( lo < hi ) {\n ulong m = ( lo + hi + 1 ) / 2;\n \n //bool over = false;\n //ulong up = mulu( ( H+m ), ( m-H+1 ), over ) / 2;\n ulong up = ( H+m ) * ( m - H+1 ) / 2;\n //bool over2 = false;\n //ulong down = mulu( m, ( m-1 ), over2 ) / 2;\n ulong down = m * ( m-1 ) / 2;\n \n //debug{ if ( over || over2 ) writeln(\"dassad\"); }\n \n if ( up > n || n - up < down ) hi = m - 1;\n else lo = m;\n }\n \n debug { writeln(hi, ' ', hi - H, ' ', hi*(hi-1)/2 ); }\n \n ans = hi - ( H-1 );\n n -= ( H + hi ) * ( hi - H + 1 ) / 2;\n ans += hi - 1;\n n -= ( hi - 1 + 1 ) * ( hi - 1 ) / 2;\n ans += ( n + hi - 1 ) / hi;\n }\n \n writeln( ans );\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n ulong n, H;\n readf( \"%s %s\", &n, &H );\n \n ulong sqr = cast( ulong ) sqrt( cast( real )( 2*n ) );\n \n ulong seqlen = sqr * ( sqr+1 ) <= 2*n ? sqr : sqr - 1;\n \n ulong ans;\n if ( seqlen <= H ) {\n n -= seqlen * ( seqlen+1 ) / 2;\n ans = seqlen + cast(int)( n > 0 );\n } else {\n n -= H * ( H+1 ) / 2;\n ans = H;\n ans += ( n + H-1 ) / H;\n }\n \n writeln( ans );\n}"}], "src_uid": "c35102fa418cbfdcb150b52d216040d9"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto X = new int[][](N, 5);\n foreach (u; 0 .. N) foreach (j; 0 .. 5) {\n X[u][j] = readInt();\n }\n \n int cmp(int u, int v) {\n int cnt;\n foreach (j; 0 .. 5) {\n if (X[u][j] < X[v][j]) {\n ++cnt;\n }\n }\n return (2 * cnt - 5);\n }\n \n int um = 0;\n foreach (v; 1 .. N) {\n if (cmp(um, v) < 0) {\n um = v;\n }\n }\n bool ok = true;\n foreach (v; 0 .. N) {\n if (um != v) {\n ok = ok && (cmp(um, v) > 0);\n }\n }\n writeln(ok ? (um + 1) : -1);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint, std.string;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n assert(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nalias Ath = int[];\n\nbool sup(Ath a, Ath b) {\n int t = 0;\n foreach (i; 0 .. 5) {\n if (a[i] < b[i]) t++;\n }\n \n return t >= 3;\n}\n\nvoid main() {\n int T;\n read(T);\n\n while (T--) {\n int n;\n read(n);\n Ath[] arr;\n foreach (i; 0 .. n) {\n arr ~= list!int;\n }\n \n auto rem = iota(n).array;\n \n while (rem.length != 1) {\n int[] rem2;\n \n for (int i = 0; i < rem.length; i += 2) {\n if (i == rem.length - 1) {\n rem2 ~= rem[i];\n } else {\n if (sup(arr[rem[i]], arr[rem[i + 1]])) {\n rem2 ~= rem[i];\n } else {\n rem2 ~= rem[i + 1];\n }\n }\n }\n \n rem = rem2;\n }\n \n int target = rem.front;\n bool yes = true;\n foreach (i, a; arr) {\n if (i != target && !sup(arr[target], a)) {\n yes = false;\n }\n }\n \n if (!yes) {\n writeln(-1);\n } else {\n writeln(target + 1);\n }\n }\n}\n\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool is_better_than(int[] a, int[] b)\n{\n int cnt;\n foreach (i ; 0 .. a.length) {\n if (a[i] < b[i])\n cnt++;\n }\n return (cnt >= 3);\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n int[][] a;\n foreach (i ; 0 .. n) {\n a ~= readln.strip.split.map!(to!int).array;\n }\n int best_i = 0;\n foreach (i ; 1 .. n) {\n if (a[i].is_better_than(a[best_i])) {\n best_i = i;\n }\n }\n bool good = true;\n foreach (i ; 0 .. n) {\n if (best_i != i && !a[best_i].is_better_than(a[i]))\n good = false;\n }\n writeln(good ? best_i + 1 : -1);\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool less (int [] u, int [] v)\r\n{\r\n\treturn zip (u, v).count !(q{a[0] < a[1]}) * 2 > u.length;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto r = new int [] [n];\r\n\t\tforeach (ref c; r)\r\n\t\t{\r\n\t\t\tc = readln.splitter.map !(to !(int)).array;\r\n\t\t}\r\n\t\tauto p = r.minPos !(less);\r\n\t\tif (r.count !(q => less (p.front, q)) == n - 1)\r\n\t\t{\r\n\t\t\twriteln (r.length - p.length + 1);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\r\n\t\tauto r = new long[][](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tr[i] = RDA;\r\n\t\t}\r\n\r\n\t\tint x;\r\n\t\tforeach (int i; 1..n)\r\n\t\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (j; 0..5)\r\n\t\t\t{\r\n\t\t\t\tif (r[x][j] < r[i][j])\r\n\t\t\t\t\t++cnt;\r\n\t\t\t}\r\n\t\t\tif (cnt >= 3) continue;\r\n\t\t\tx = i;\r\n\t\t}\r\n\t\tauto cnt = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (i == x) continue;\r\n\t\t\tforeach (j; 0..5)\r\n\t\t\t{\r\n\t\t\t\tif (r[x][j] < r[i][j])\r\n\t\t\t\t\t++cnt[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = x+1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (i == x) continue;\r\n\t\t\tif (cnt[i] < 3)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = -1;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "8d9fc054fb1541b70991661592ae70b1"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\treverse (a);\n\t\twriteln (a.isStrictlyMonotonic ? \"NO\" : \"YES\");\n\t}\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n foreach(i; 0..n-1){\n if(arr[i] <= arr[i+1]){\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\n\nvoid get(Args...)(ref Args args)\n{\n import std.traits, std.meta, std.typecons;\n\n static if (Args.length == 1) {\n alias Arg = Args[0];\n \n static if (isArray!Arg) {\n args[0] = readln.split.to!Arg;\n } else static if (isTuple!Arg) {\n auto input = readln.split;\n static foreach (i; 0..Fields!Arg.length) {\n args[0][i] = input[i].to!(Fields!Arg[i]);\n }\n } else {\n args[0] = readln.chomp.to!Arg;\n }\n } else {\n auto input = readln.split;\n assert(input.length == Args.length);\n\n static foreach (i; 0..Args.length) {\n args[i] = input[i].to!(Args[i]);\n }\n }\n}\n\nvoid get_lines(Args...)(size_t N, ref Args args)\n{\n import std.traits, std.range;\n\n static foreach (i; 0..Args.length) {\n static assert(isArray!(Args[i]));\n args[i].length = N;\n }\n\n foreach (i; 0..N) {\n static if (Args.length == 1) {\n get(args[0][i]);\n } else {\n auto input = readln.split;\n static foreach (j; 0..Args.length) {\n args[j][i] = input[j].to!(ElementType!(Args[j]));\n }\n }\n }\n}\n\nvoid solve()\n{\n int N; get(N);\n int[] AS; get(AS);\n foreach (i; 1..N) if (AS[i-1] <= AS[i]) {\n writeln(\"YES\");\n return;\n }\n writeln(\"NO\");\n}\n\nvoid main()\n{\n int T; get(T);\n foreach (_; 0..T) solve();\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto a = new int[](n);\n foreach(ref ai; a) ai = next!int;\n if (iota(0, n - 1).all!(i => a[i] > a[i + 1]))\n\twriteln(\"NO\");\n else\n\twriteln(\"YES\");\n }\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto next(T)()\n{\n static if (is(T == int) || is(T == long) || is(T == short))\n {\n import std.ascii: isDigit;\n T res;\n while(!frontChar.isDigit)\n\tpopChar;\n while(frontChar.isDigit)\n\t{\n\t res *= 10;\n\t res += frontChar - '0';\n\t popChar;\n\t}\n return res;\n }\n else static if (is(T == string))\n {\n import std.ascii: isWhite;\n string res;\n while(frontChar.isWhite)\n\tpopChar;\n while(!frontChar.isWhite)\n\t{\n\t res ~= frontChar;\n\t popChar;\n\t}\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto a = next!int(n);\n if (iota(0, n - 1).all!(i => a[i] > a[i + 1]))\n\twriteln(\"NO\");\n else\n\twriteln(\"YES\");\n }\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tbool ok;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] >= a[i-1])\n\t\t\t{\n\t\t\t\tok = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n dchar[] arr = rd!(dchar[]);\n int isodd = 0;\n if(n % 2){\n foreach(i; 0..n){\n // Odds\n if(i % 2 == 0 && (arr[i] - '0') % 2){\n isodd = 1;\n break;\n }\n }\n if(isodd){\n writeln(1);\n }else{\n writeln(2);\n }\n }else{\n foreach(i; 0..n){\n // Even\n if(i % 2 == 1 && (arr[i] - '0') % 2 == 0){\n isodd = 1;\n break;\n }\n }\n if(isodd){\n writeln(2);\n }else{\n writeln(1);\n }\n }\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto a = next!int(n);\n if (n >= 3)\n\t{\n\t writeln(\"YES\");\n\t continue;\n\t}\n if (n == 1) { writeln(\"YES\"); continue; }\n if (n == 2) { if (a[0] <= a[1]) writeln(\"YES\"); else writeln(\"NO\"); continue; }\n assert(0);\n }\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "src_uid": "b34f29e6fb586c22fa1b9e559c5a6c50"} {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[501][501] dp = 0;\n foreach ( j; 0 .. 501 ) dp[0][j] = 1;\n\n int n, m, b, mod, a;\n readf(\" %s %s %s %s\\n\", &n, &m, &b, &mod);\n foreach ( l; 0 .. n ) {\n readf(\" %s\", &a);\n foreach ( i; 1 .. m + 1 ) {\n foreach ( j; a .. b + 1 ) {\n dp[i][j] += dp[i - 1][j - a];\n dp[i][j] %= mod;\n }\n }\n }\n writeln(dp[m][b]);\n\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[501][501] dp = 0;\n foreach ( j; 0 .. 501 ) dp[0][j] = 1;\n\n int n, m, b, mod, a;\n readf(\" %s %s %s %s\\n\", &n, &m, &b, &mod);\n foreach ( l; 0 .. n ) {\n readf(\" %s\", &a);\n foreach ( i; 1 .. m + 1 ) {\n foreach ( j; a .. b + 1 ) {\n dp[i][j] += dp[i - 1][j - a];\n dp[i][j] %= mod;\n }\n }\n }\n writeln(dp[m][b]);\n\n return 0;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, m, b, v;\n\twhile (readf (\" %s %s %s %s \", &n, &m, &b, &v) > 0)\n\t{\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tauto f = new int [] [] [] (2, m + 1, b + 1);\n\t\tint z = 0;\n\t\tforeach (ref g; f[z])\n\t\t{\n\t\t\tg[] = 0;\n\t\t}\n\t\tf[z][0][0] = 1 % v;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tz ^= 1;\n\t\t\tforeach (j; 0..m + 1)\n\t\t\t{\n\t\t\t\tf[z][] = f[!z][];\n\t\t\t}\n\t\t\tforeach (j; 1..m + 1)\n\t\t\t{\n\t\t\t\tforeach (k; a[i]..b + 1)\n\t\t\t\t{\n\t\t\t\t\tf[z][j][k] += f[!z][j - 1][k - a[i]];\n\t\t\t\t\tif (f[z][j][k] >= v)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[z][j][k] -= v;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint res = 0;\n\t\tforeach (k; 0..b + 1)\n\t\t{\n\t\t\tres += f[z][m][k];\n\t\t\tif (res >= v)\n\t\t\t{\n\t\t\t\tres -= v;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "139febdb9c01bf0e6598fdf65a1a522c"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string, core.stdc.stdlib;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n auto N = readln.chomp.to!int;\n auto s = readln.split.map!(to!int);\n auto A = s[0];\n auto B = s[1];\n auto C = s[2];\n auto S = readln.chomp;\n int win = 0;\n auto ans = new dchar[](N);\n ans[] = '*';\n foreach (i, v; S) {\n if (v == 'R' && B > 0) {\n win += 1;\n B -= 1;\n ans[i] = 'P';\n } else if (v == 'P' && C > 0) {\n win += 1;\n C -= 1;\n ans[i] = 'S';\n } else if (v == 'S' && A > 0) {\n win += 1;\n A -= 1;\n ans[i] = 'R';\n }\n }\n foreach (i; 0..N) if (ans[i] == '*') {\n if (A > 0) {\n ans[i] = 'R';\n A -= 1;\n } else if (B > 0) {\n ans[i] = 'P';\n B -= 1;\n } else {\n ans[i] = 'S';\n C -= 1;\n }\n }\n if (win >= (N + 1) / 2) {\n writeln(\"YES\");\n ans.writeln;\n } else {\n writeln(\"NO\");\n }\n }\n}\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nimmutable names = \"RPS\";\n\nvoid main() {\n auto r = new InputReader;\n foreach (t; 0 .. r.next!uint) {\n immutable n = r.next!uint;\n auto cnt = r.nextA!uint(3);\n auto a = new char[n];\n auto b = new int[n];\n foreach (i; 0 .. n) {\n char c;\n int k = -1;\n do {\n c = r.nextByte ().to!char;\n foreach (o; 0 .. 3) {\n if (names[o] == c) {\n k = o;\n }\n }\n } while (k < 0);\n b[i] = (k + 1) % 3;\n }\n debug stderr.writeln (\"b = \", b);\n int wins;\n foreach (k; 0 .. 3) {\n foreach (j; 0 .. n) {\n if (cnt[k] > 0 && b[j] == k) {\n --cnt[k];\n a[j] = names[k];\n ++wins;\n }\n }\n }\n debug stderr.writeln (\"wins = \", wins);\n foreach (i; 0 .. n) {\n if (a[i] == char.init) {\n foreach (k; 0 .. 3) {\n if (cnt[k] > 0) {\n a[i] = names[k];\n --cnt[k];\n break;\n }\n }\n }\n }\n int req = n / 2;\n if (n & 1) ++req;\n if (wins >= req) {\n writeln (\"YES\");\n writeln (a);\n } else {\n writeln (\"NO\");\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new char[][](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tauto c = RD!int;\n\t\tauto s = RD!string;\n\t\tint cnt;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (s[j] == 'R')\n\t\t\t{\n\t\t\t\tif (b == 0)\n\t\t\t\t\tans[i] ~= '?';\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[i] ~= 'P';\n\t\t\t\t\t--b;\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (s[j] == 'P')\n\t\t\t{\n\t\t\t\tif (c == 0)\n\t\t\t\t\tans[i] ~= '?';\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[i] ~= 'S';\n\t\t\t\t\t--c;\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a == 0)\n\t\t\t\t\tans[i] ~= '?';\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[i] ~= 'R';\n\t\t\t\t\t--a;\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (cnt*2 < n)\n\t\t{\n\t\t\tans[i].length = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tif (ans[i][j] == '?')\n\t\t\t\t{\n\t\t\t\t\tif (a != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t--a;\n\t\t\t\t\t\tans[i][j] = 'R';\n\t\t\t\t\t}\n\t\t\t\t\telse if (b != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t--b;\n\t\t\t\t\t\tans[i][j] = 'P';\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t--c;\n\t\t\t\t\t\tans[i][j] = 'S';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.length == 0)\n\t\t{\n\t\t\twriteln(\"NO\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(e);\n\t\t}\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new char[][](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tauto c = RD!int;\n\t\tauto s = RD!string;\n\t\tint cnt;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (s[j] == 'R')\n\t\t\t{\n\t\t\t\tif (b == 0)\n\t\t\t\t\tans[i] ~= '?';\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[i] ~= 'P';\n\t\t\t\t\t--b;\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (s[j] == 'P')\n\t\t\t{\n\t\t\t\tif (c == 0)\n\t\t\t\t\tans[i] ~= '?';\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[i] ~= 'S';\n\t\t\t\t\t--c;\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a == 0)\n\t\t\t\t\tans[i] ~= '?';\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[i] ~= 'R';\n\t\t\t\t\t--a;\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (cnt*2 <= n)\n\t\t{\n\t\t\tans[i].length = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tif (ans[i][j] == '?')\n\t\t\t\t{\n\t\t\t\t\tif (a != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t--a;\n\t\t\t\t\t\tans[i][j] = 'R';\n\t\t\t\t\t}\n\t\t\t\t\telse if (b != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t--b;\n\t\t\t\t\t\tans[i][j] = 'P';\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t--c;\n\t\t\t\t\t\tans[i][j] = 'S';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.length == 0)\n\t\t{\n\t\t\twriteln(\"NO\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(e);\n\t\t}\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "bee33afb70e4c3e062ec7980b44cc0dd"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt(int M_) {\n import std.conv : to;\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n if (a < 0) return (this = inv()^^(-a));\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e > 0; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op: \"-\")() const { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const {\n return mixin(\"ModInt(this) \" ~ op ~ \"= a\");\n }\n ModInt opBinaryRight(string op)(long a) const {\n return mixin(\"ModInt(a) \" ~ op ~ \"= this\");\n }\n bool opCast(T: bool)() const { return (x != 0); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 7;\nalias Mint = ModInt!MO;\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto X = new long[N];\n foreach (i; 0 .. N) {\n X[i] = readLong();\n }\n X.sort;\n \n auto two = new Mint[N + 1];\n two[0] = 1;\n foreach (i; 1 .. N + 1) {\n two[i] = two[i - 1] * 2;\n }\n \n Mint ans;\n foreach (i; 0 .. N - 1) {\n ans += (two[i + 1] - 1) * (two[N - (i + 1)] - 1) * Mint(X[i + 1] - X[i]);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nimmutable long MOD = 10^^9 + 7;\n\nlong powmod(long a, long x, long m) {\n long ret = 1;\n while (x) {\n if (x % 2) ret = ret * a % m;\n a = a * a % m;\n x /= 2;\n }\n return ret;\n}\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n\n long ans = 0;\n foreach (i; 0..N) {\n ans -= A[i] * (powmod(2, N - i - 1, MOD) - 1) % MOD;\n ans = (ans % MOD + MOD) % MOD;\n ans += A[i] * (powmod(2, i, MOD) - 1) % MOD;\n ans = (ans % MOD + MOD) % MOD;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable int mod = 10^^9 + 7;\nint n;\nint[] x;\n\nvoid main() {\n scan(n);\n x = readln.split.to!(int[]);\n\n x.sort();\n\n auto p2 = new int[](n + 1);\n p2[0] = 1;\n foreach (i ; 1 .. n + 1) {\n p2[i] = (2 * p2[i - 1]) % mod;\n }\n\n long ans;\n\n foreach (i ; 0 .. n) {\n ans += (1L * x[i] * p2[i]) % mod;\n ans %= mod;\n ans -= (1L * x[i] * p2[n - 1 - i]) % mod;\n ans %= mod;\n if (ans < 0) ans += mod;\n }\n\n writeln(ans);\n}\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1_000_000_007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))\n{foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))\n{\n\tforeach(ref const i;a)\n\t{\n\t\tforeach(ref const j;i)write(j,' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n;\nloop:while(read(n))\n\t{\n\t\tauto a=arread!long;\n\t\tsort(a);\n\t\tlong p=1,ans=0,d=a.back-a.front;\n\t\tforeach(i;1..n)\n\t\t{\n\t\t\tans=(ans+d*p)%mod;\n\t\t\tp=(p*2)%mod;\n\t\t\td+=a[n-1-i]-a[i];\n\t\t\td=(d%mod+mod)%mod;\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}], "negative_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1_000_000_007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))\n{foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))\n{\n\tforeach(ref const i;a)\n\t{\n\t\tforeach(ref const j;i)write(j,' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n;\nloop:while(read(n))\n\t{\n\t\tauto a=arread!long;\n\t\tsort(a);\n\t\tlong p=1,ans=0,d=a.back-a.front;\n\t\tforeach(i;1..n)\n\t\t{\n\t\t\tans=(ans+d*p)%mod;\n\t\t\tp=(p*2)%mod;\n\t\t\td+=a[n-1-i]-a[i];\n\t\t\td%=mod;\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))\n{foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))\n{\n\tforeach(ref const i;a)\n\t{\n\t\tforeach(ref const j;i)write(j,' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n;\nloop:while(read(n))\n\t{\n\t\tauto a=arread!long;\n\t\tsort(a);\n\t\tlong p=1,ans=0,d=a.back-a.front;\n\t\tforeach(i;1..n)\n\t\t{\n\t\t\tans=(ans+d*p)%mod;\n\t\t\tp=(p*2)%mod;\n\t\t\td+=a[n-1-i]-a[i];\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable int mod = 10^^9 + 7;\nint n;\nint[] x;\n\nvoid main() {\n scan(n);\n x = readln.split.to!(int[]);\n\n x.sort();\n\n auto p2 = new int[](n + 1);\n p2[0] = 1;\n foreach (i ; 1 .. n + 1) {\n p2[i] = (2 * p2[i - 1]) % mod;\n }\n\n long ans;\n\n foreach (i ; 0 .. n) {\n ans += (1L * x[i] * p2[i]) % mod;\n ans %= mod;\n ans -= (1L * x[i] * p2[n - 1 - i]) % mod;\n ans %= mod;\n }\n\n writeln(ans);\n}\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}"}], "src_uid": "acff03fe274e819a74b5e9350a859471"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\t\n\t\tif (n == 1) continue;\n\t\telse if (n == 2)\n\t\t\tans[ti] = m;\n\t\telse\n\t\t\tans[ti] = m * 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, m;\n\t\treadf !(\" %s %s\") (n, m);\n\t\twriteln (n == 1 ? 0 : n == 2 ? m : 2 * m);\n\t}\n}\n"}], "negative_code": [], "src_uid": "905cc16ecbbb3305416f9aa6e4412642"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum L = 9;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new string[N];\n foreach (i; 0 .. N) {\n A[i] = readToken();\n }\n \n alias Entry = Tuple!(int, \"val\", int, \"i\");\n auto ess = new Entry[][L + 1];\n foreach (i; 0 .. N) {\n foreach (x; 0 .. L) {\n int val;\n foreach (y; x .. L) {\n val = val * 10 + (A[i][y] - '0');\n ess[y + 1 - x] ~= Entry(val, i);\n }\n }\n }\n \n auto opt = new int[N];\n opt[] = L + 1;\n auto ans = new int[N];\n foreach (l; 1 .. L + 1) {\n auto es = ess[l];\n es.sort;\n const esLen = cast(int)(es.length);\n for (int j = 0, k; j < esLen; j = k) {\n for (k = j; k < esLen && es[j].val == es[k].val; ++k) {}\n if (es[j].i == es[k - 1].i) {\n const i = es[j].i;\n if (chmin(opt[i], l)) {\n ans[i] = es[j].val;\n }\n }\n }\n }\n \n foreach (i; 0 .. N) {\n writefln(\"%0*d\", opt[i], ans[i]);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int letters = 10;\n\nstruct Node\n{\n\tstring mark;\n\tint p;\n\tint visits;\n\tint [letters] next;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = new string [n];\n\t\tforeach (ref c; s)\n\t\t{\n\t\t\tc = readln.strip;\n\t\t}\n\n\t\tNode [] t;\n\t\tt.reserve (1 + n * 9);\n\t\tt ~= Node ();\n\t\tforeach (int i, b; s)\n\t\t{\n\t\t\tforeach (int j; 0..b.length)\n\t\t\t{\n\t\t\t\tauto c = b[j..$];\n\t\t\t\tint v = 0;\n\t\t\t\twhile (!c.empty)\n\t\t\t\t{\n\t\t\t\t\tint d = c.front - '0';\n\t\t\t\t\tc.popFront ();\n\t\t\t\t\tif (!t[v].next[d])\n\t\t\t\t\t{\n\t\t\t\t\t\tt[v].next[d] =\n\t\t\t\t\t\t t.length.to !(int);\n\t\t\t\t\t\tt ~= Node (s[i][j..$ -\n\t\t\t\t\t\t c.length], i, 1);\n\t\t\t\t\t}\n\t\t\t\t\tv = t[v].next[d];\n\t\t\t\t\tt[v].visits += (t[v].p != i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (ref w; t)\n\t\t{\n\t\t\tdebug {writeln (w);}\n\t\t\tif (w.visits == 1 &&\n\t\t\t s[w.p].length > w.mark.length)\n\t\t\t{\n\t\t\t\ts[w.p] = w.mark;\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%-(%s\\n%)\", s);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = N.iota.map!(_ => readln.chomp).array;\n int[string] cnt;\n\n foreach (s; S) {\n bool[string] used;\n foreach (i; 0..9) {\n foreach (j; i..10) {\n if (s[i..j] in used)\n continue;\n cnt[s[i..j]] += 1;\n used[s[i..j]] = true;\n }\n }\n }\n\n void solve(int ind) {\n foreach (len; 1..10)\n foreach (i; 0..10-len)\n if (cnt[S[ind][i..i+len]] == 1) {\n writeln(S[ind][i..i+len]);\n return;\n }\n }\n\n foreach (i; 0..N)\n solve(i);\n\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = N.iota.map!(_ => readln.chomp).array;\n int[string] cnt;\n foreach (s; S)\n foreach (i; 0..9)\n foreach (j; i..10)\n cnt[s[i..j]] += 1;\n\n void solve(int ind) {\n foreach (len; 1..10)\n foreach (i; 0..10-len)\n if (cnt[S[ind][i..i+len]] == 1) {\n writeln(S[ind][i..i+len]);\n return;\n }\n }\n\n foreach (i; 0..N)\n solve(i);\n}\n"}], "src_uid": "37d906de85f173aca2a9a3559cbcf7a3"} {"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dcomp\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n\nimport std.typecons;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n int n;\n sc.read(n);\n int[] a = [1];\n int[] b = [];\n foreach (_; 0..n) {\n swap(a, b);\n auto c = [0] ~ b.dup;\n foreach (i; 0..a.length) {\n c[i] += a[i]; c[i] %= 2; \n }\n a = c;\n }\n writeln(a.length - 1);\n writeln(a.map!(to!string).join(\" \"));\n writeln(b.length - 1);\n writeln(b.map!(to!string).join(\" \"));\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */\n \n// module dcomp.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n// import dcomp.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/stackpayload.d */\n// module dcomp.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n\n/*\nThis source code generated by dcomp and include dcomp's source code.\ndcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)\ndcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)\n*/\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n int[] fs = [0, 1];\n int[] gs = [1];\n foreach (i; 1 .. N) {\n // g + X f\n auto hs = gs.dup;\n hs ~= [0, 0];\n hs[1 .. $] += fs[];\n if (hs.any!\"abs(a) > 1\") {\n hs[1 .. $] -= fs[];\n hs[1 .. $] -= fs[];\n }\n if (hs.any!\"abs(a) > 1\") {\n assert(false);\n }\n gs = fs;\n fs = hs;\n }\n \n if (fs[$ - 1] < 0) {\n fs[] *= -1;\n }\n if (gs[$ - 1] < 0) {\n gs[] *= -1;\n }\n \n writeln(N);\n foreach (j; 0 .. N) {\n write(fs[j], \" \");\n }\n writeln(fs[N]);\n writeln(N - 1);\n foreach (j; 0 .. N - 1) {\n write(gs[j], \" \");\n }\n writeln(gs[N - 1]);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "c2362d3254aefe30da99c4aeb4e1a894"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int DIRS = 4;\nimmutable int [DIRS] DROW = [-1, 0, +1, 0];\nimmutable int [DIRS] DCOL = [ 0, -1, 0, +1];\nimmutable char [DIRS] DNAME = ['^', '<', 'v', '>'];\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s \", &n, &m) > 0)\n\t{\n\t\tchar [] [] a;\n\t\ta ~= '*'.repeat (m + 2).array ();\n\t\tforeach (row; 1..n + 1)\n\t\t{\n\t\t\ta ~= '*' ~ readln ().strip ().dup ~ '*';\n\t\t}\n\t\ta ~= '*'.repeat (m + 2).array ();\n\t\tdebug {writeln (a);}\n\n\t\talias Coord = Tuple !(int, \"row\", int, \"col\");\n\t\tCoord [] q;\n\t\tq.reserve ((n + 2) * (m + 2) + 1);\n\n\t\tauto g = new int [] [] (n + 2, m + 2);\n\t\tforeach (row; 1..n + 1)\n\t\t{\n\t\t\tforeach (col; 1..m + 1)\n\t\t\t{\n\t\t\t\tif (a[row][col] == '.')\n\t\t\t\t{\n\t\t\t\t\tg[row][col] = sum (DIRS.iota.map\n\t\t\t\t\t !(dir => a[row + DROW[dir]]\n\t\t\t\t\t [col + DCOL[dir]] == '.'));\n\t\t\t\t\tif (g[row][col] == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tq ~= Coord (row, col);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (q);}\n\n\t\tvoid recalc (int row, int col)\n\t\t{\n\t\t\tforeach (dir; 0..DIRS)\n\t\t\t{\n\t\t\t\tint nrow = row + DROW[dir];\n\t\t\t\tint ncol = col + DCOL[dir];\n\t\t\t\tif (a[nrow][ncol] == '.')\n\t\t\t\t{\n\t\t\t\t\tg[nrow][ncol]--;\n\t\t\t\t\tif (g[nrow][ncol] == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tq ~= Coord (nrow, ncol);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twhile (q.length > 0)\n\t\t{\n\t\t\tint row = q.front.row;\n\t\t\tint col = q.front.col;\n\t\t\tq.popFront ();\n\t\t\tq.assumeSafeAppend ();\n\t\t\tif (g[row][col] != 1 || a[row][col] != '.')\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tforeach (dir; 0..DIRS)\n\t\t\t{\n\t\t\t\tint nrow = row + DROW[dir];\n\t\t\t\tint ncol = col + DCOL[dir];\n\t\t\t\tif (a[nrow][ncol] == '.')\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = DNAME[dir ^ 2];\n\t\t\t\t\ta[nrow][ncol] = DNAME[dir ^ 0];\n\t\t\t\t\trecalc (row, col);\n\t\t\t\t\trecalc (nrow, ncol);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (any !(b => b.find ('.').length > 0) (a))\n\t\t{\n\t\t\twriteln (\"Not unique\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"%-(%-(%s%)\\n%)\",\n\t\t\t a[1..n + 1].map !(b => b[1..m + 1]));\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable DX = [ +1, 0, -1, 0, ];\nimmutable DY = [ 0, +1, 0, -1, ];\n\nint M, N;\nchar[][] A;\n\nbool solve() {\n\tint[][] deg = new int[][](M, N);\n\tforeach (x; 0 .. M) foreach (y; 0 .. N) if (A[x][y] == '.') {\n\t\tforeach (dir; 0 .. 4) {\n\t\t\tconst xx = x + DX[dir];\n\t\t\tconst yy = y + DY[dir];\n\t\t\tif (0 <= xx && xx < M && 0 <= yy && yy < N) {\n\t\t\t\tif (A[xx][yy] == '.') {\n\t\t\t\t\t++deg[x][y];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tPair!(int, int)[] q;\n\tforeach (x; 0 .. M) foreach (y; 0 .. N) if (A[x][y] == '.') {\n\t\tif (deg[x][y] == 1) {\n\t\t\tq ~= pair(x, y);\n\t\t}\n\t}\n\tfor (; !q.empty; ) {\ndebug{\nwriteln;\nforeach(x;0..M)writeln(A[x].to!string);\n}\n\t\tconst x = q.front.x;\n\t\tconst y = q.front.y;\n\t\tq.popFront;\n\t\tif (A[x][y] == '.' && deg[x][y] == 1) {\ndebug{\nwriteln(x,\" \",y);\n}\n\t\t\tforeach (dir; 0 .. 4) {\n\t\t\t\tconst xx = x + DX[dir];\n\t\t\t\tconst yy = y + DY[dir];\n\t\t\t\tif (0 <= xx && xx < M && 0 <= yy && yy < N) {\n\t\t\t\t\tif (A[xx][yy] == '.') {\n\t\t\t\t\t\tA[x][y] = \"^<v>\"[dir];\n\t\t\t\t\t\tA[xx][yy] = \"v>^<\"[dir];\n\t\t\t\t\t\tforeach (dir1; 0 .. 4) {\n\t\t\t\t\t\t\tconst xxx = xx + DX[dir1];\n\t\t\t\t\t\t\tconst yyy = yy + DY[dir1];\n\t\t\t\t\t\t\tif (0 <= xxx && xxx < M && 0 <= yyy && yyy < N) {\n\t\t\t\t\t\t\t\tif (A[xxx][yyy] == '.') {\n\t\t\t\t\t\t\t\t\tif (--deg[xxx][yyy] == 1) {\n\t\t\t\t\t\t\t\t\t\tq ~= pair(xxx, yyy);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tforeach (x; 0 .. M) foreach (y; 0 .. N) {\n\t\tif (A[x][y] == '.') {\n\t\t\treturn false;\n\t\t}\n\t}\n\tforeach (x; 0 .. M) {\n\t\twriteln(A[x].to!string);\n\t}\n\treturn true;\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tA = new char[][M];\n\t\tforeach (x; 0 .. M) {\n\t\t\tA[x] = readToken.to!(char[]);\n\t\t}\n\t\t\n\t\tconst res = solve;\n\t\tif (!res) {\n\t\t\twriteln(\"Not unique\");\n\t\t}\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "9465c37b6f948da14e71cc96ac24bb2e"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\t\tauto c = RD;\r\n\t\t\r\n\t\tans[ti].length = 2;\r\n\t\tif (a >= b)\r\n\t\t{\r\n\t\t\tans[ti][0] ~= '1';\r\n\t\t\tforeach (i; 0..a-1)\r\n\t\t\t\tans[ti][0] ~= '0';\r\n\t\t\tif (b == c)\r\n\t\t\t{\r\n\t\t\t\tans[ti][1] ~= '1';\r\n\t\t\t\tforeach (i; 0..b-1)\r\n\t\t\t\t\tans[ti][1] ~= '0';\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tans[ti][1] ~= '1';\r\n\t\t\t\tforeach (i; 1..b)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i == b-c)\r\n\t\t\t\t\t\tans[ti][1] ~= '1';\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tans[ti][1] ~= '0';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tans[ti][1] ~= '1';\r\n\t\t\tforeach (i; 0..b-1)\r\n\t\t\t\tans[ti][1] ~= '0';\r\n\t\t\tif (a == c)\r\n\t\t\t{\r\n\t\t\t\tans[ti][0] ~= '1';\r\n\t\t\t\tforeach (i; 0..a-1)\r\n\t\t\t\t\tans[ti][0] ~= '0';\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tans[ti][0] ~= '1';\r\n\t\t\t\tforeach (i; 1..a)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i == a-c)\r\n\t\t\t\t\t\tans[ti][0] ~= '1';\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tans[ti][0] ~= '0';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tdebug writeln(\"gcd:\", gcd(ans[ti][0].to!long, ans[ti][1].to!long));\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e[0], \" \", e[1]);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio;\r\n\r\nvoid main() {\r\n int t;\r\n readf(\"%d\\n\", &t);\r\n\r\n for(int k = 0; k < t; ++k) {\r\n int a, b, c;\r\n readf(\"%d %d %d\\n\", &a, &b, &c);\r\n\r\n write(\"1\");\r\n for(int i = 0; i < a-1; ++i) write(\"0\");\r\n write(\" \");\r\n for(int i = 0; i < b-c+1; ++i) write(\"1\");\r\n for(int i = 0; i < c-1; ++i) write(\"0\");\r\n writeln();\r\n }\r\n}\r\n\r\n// Yo lo quiero m\u00e1s r\u00e1pido"}, {"source_code": "import std.stdio;\r\n\r\nvoid main() {\r\n int t;\r\n readf(\"%d\\n\", &t);\r\n\r\n for(int k = 0; k < t; ++k) {\r\n int a, b, c;\r\n readf(\"%d %d %d\\n\", &a, &b, &c);\r\n\r\n write(\"1\");\r\n for(int i = 0; i < a-1; ++i) write(\"0\");\r\n write(\" \");\r\n for(int i = 0; i < b-c+1; ++i) write(\"1\");\r\n for(int i = 0; i < c-1; ++i) write(\"0\");\r\n writeln();\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio;\r\n\r\nvoid main() {\r\n int t;\r\n readf(\"%d\\n\", &t);\r\n\r\n for(int k = 0; k < t; ++k) {\r\n int a, b, c;\r\n readf(\"%d %d %d\\n\", &a, &b, &c);\r\n\r\n if(a > b) {\r\n write(\"1\");\r\n for(int i = 0; i < a-1; ++i) write(\"0\");\r\n write(\" \");\r\n for(int i = 0; i < b-c+1; ++i) write(\"1\");\r\n for(int i = 0; i < b-(b-c+1); ++i) write(\"0\");\r\n writeln();\r\n } else {\r\n for(int i = 0; i < a-c+1; ++i) write(\"1\");\r\n for(int i = 0; i < a-(a-c+1); ++i) write(\"0\");\r\n write(\" \");\r\n write(\"1\");\r\n for(int i = 0; i < b-1; ++i) write(\"0\");\r\n writeln();\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\n\r\nvoid main() {\r\n int t;\r\n readf(\"%d\\n\", &t);\r\n\r\n for(int k = 0; k < t; ++k) {\r\n int a, b, c;\r\n readf(\"%d %d %d\\n\", &a, &b, &c);\r\n\r\n if(a > b) {\r\n write(\"1\");\r\n for(int i = 0; i < a-1; ++i) write(\"0\");\r\n write(\" \");\r\n for(int i = 0; i < b-c+1; ++i) write(\"1\");\r\n for(int i = 0; i < b-(b-c+1); ++i) write(\"0\");\r\n writeln();\r\n } else {\r\n for(int i = 0; i < b-c+1; ++i) write(\"1\");\r\n for(int i = 0; i < b-(b-c+1); ++i) write(\"0\");\r\n write(\" \");\r\n write(\"1\");\r\n for(int i = 0; i < a-1; ++i) write(\"0\");\r\n writeln();\r\n }\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\t\tauto c = RD;\r\n\t\t\r\n\t\tans[ti].length = 2;\r\n\t\tif (a >= b)\r\n\t\t{\r\n\t\t\tans[ti][0] ~= '1';\r\n\t\t\tforeach (i; 0..a-1)\r\n\t\t\t\tans[ti][0] ~= '0';\r\n\t\t\tif (b == c)\r\n\t\t\t\tans[ti][1] = ans[ti][0];\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tans[ti][1] ~= '1';\r\n\t\t\t\tforeach (i; 1..b)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i == b-c)\r\n\t\t\t\t\t\tans[ti][1] ~= '1';\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tans[ti][1] ~= '0';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tans[ti][1] ~= '1';\r\n\t\t\tforeach (i; 0..b-1)\r\n\t\t\t\tans[ti][1] ~= '0';\r\n\t\t\tif (a == c)\r\n\t\t\t\tans[ti][0] = ans[ti][1];\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tans[ti][0] ~= '1';\r\n\t\t\t\tforeach (i; 1..a)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i == a-c)\r\n\t\t\t\t\t\tans[ti][0] ~= '1';\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tans[ti][0] ~= '0';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tdebug writeln(\"gcd:\", gcd(ans[ti][0].to!long, ans[ti][1].to!long));\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e[0], \" \", e[1]);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\twriteln(gcd(1010, 1111));\r\n\tauto t = RD!int;\r\n\tauto ans = new string[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\t\tauto c = RD;\r\n\t\t\r\n\t\tans[ti].length = 2;\r\n\t\tif (a >= b)\r\n\t\t{\r\n\t\t\tforeach (i; 0..a)\r\n\t\t\t\tans[ti][0] ~= '1';\r\n\t\t\tif (b == c)\r\n\t\t\t\tans[ti][1] = ans[ti][0];\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tforeach (i; 0..b)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i == b-c)\r\n\t\t\t\t\t\tans[ti][1] ~= '0';\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tans[ti][1] ~= '1';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (i; 0..b)\r\n\t\t\t\tans[ti][1] ~= '1';\r\n\t\t\tif (a == c)\r\n\t\t\t\tans[ti][0] = ans[ti][1];\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tforeach (i; 0..a)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i == a-c)\r\n\t\t\t\t\t\tans[ti][0] ~= '0';\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tans[ti][0] ~= '1';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e[0], \" \", e[1]);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "04330cb392bcfd51d1acffd72c8004cb"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!long).array;\n auto B = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!long).array;\n\n long X = 0;\n B %= 2;\n\n foreach (i, a; A) {\n if (i != K - 1) {\n X += B * a % 2;\n X %= 2;\n } else {\n X += a % 2;\n X %= 2;\n }\n }\n\n writeln(X ? \"odd\" : \"even\");\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint b, k;\n\twhile (readf (\" %s %s\", &b, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\ta[0..$ - 1] *= b;\n\t\tauto res = sum (a, 0L);\n\t\twriteln (res % 2 == 0 ? \"even\" : \"odd\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "ee105b664099808143a94a374d6d5daa"} {"source_code": "import std.stdio;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nint[] permutationMatch(T)(in T[] A, in T[] B) {\r\n // given array A and its permutation B, returns index array I.\r\n // I[i] == j means A[i] == B[j];\r\n assert(A.length == B.length);\r\n int N = cast(int)(A.length);\r\n int[] ans = new int[N];\r\n DList!(int)[T] index;\r\n for (int i = 0; i < N; i++) {\r\n int a = A[i];\r\n if (a !in index) index[a] = DList!int();\r\n index[A[i]] ~= i;\r\n }\r\n for (int j = 0; j < N; j++) {\r\n int b = B[j];\r\n int i = index[b].front; index[b].removeFront;\r\n ans[i] = j;\r\n }\r\n return ans;\r\n}\r\n\r\nalias P = Tuple!(int,int);\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto A = readln.chomp.split(\" \").map!(to!int).array;\r\n auto B = readln.chomp.split(\" \").map!(to!int).array;\r\n bool C() {\r\n int i = N-1, j = N-1;\r\n auto s = new RedBlackTree!(int, \"a<b\", true)();\r\n while (true) {\r\n if (j >= 1 && B[j] == B[j-1]) {\r\n s.insert(B[j]);\r\n j--;\r\n } else if (i >= 0 && j >= 0 && A[i] == B[j]) {\r\n i--;\r\n j--;\r\n } else {\r\n if (i < 0 || A[i] !in s) return false;\r\n s.removeKey(A[i]);\r\n i--;\r\n }\r\n if (i == -1 && j == -1) break;\r\n }\r\n return true;\r\n }\r\n writeln(C() ? \"YES\" : \"NO\");\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (int [] a, int [] b, int n)\r\n{\r\n\tint [int] saved;\r\n\tint j = 0;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tif (a[i] == b[j])\r\n\t\t{\r\n\t\t\tj++;\r\n\t\t\twhile (j < n && b[j] == b[j - 1] &&\r\n\t\t\t saved.get (b[j], 0) > 0)\r\n\t\t\t{\r\n\t\t\t\tsaved[b[j]] -= 1;\r\n\t\t\t\tj++;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tsaved[a[i]] += 1;\r\n\t\t}\r\n\t\tdebug {writeln (i, \" \", j, \" \", saved);}\r\n\t}\r\n\treturn saved.byValue.sum == 0;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (a, b, n) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] A, B;\n\nbool solve() {\n auto nxt = new int[N];\n {\n auto app = new int[N + 1];\n app[] = N;\n foreach_reverse (i; 0 .. N) {\n nxt[i] = app[A[i]];\n app[A[i]] = i;\n }\n }\n \n {\n auto cnt = new int[N];\n cnt[] = 1;\n int i;\n foreach (j; 0 .. N) {\n for (; ; ) {\n if (i >= N) {\n return false;\n }\n if (A[i] == B[j]) {\n if (--cnt[i] == 0) {\n ++i;\n }\n break;\n }\n if (nxt[i] >= N) {\n return false;\n }\n cnt[nxt[i]] += cnt[i];\n cnt[i] = 0;\n ++i;\n }\n }\n }\n return true;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n N = readInt;\n A = new int[N]; foreach (i; 0 .. N) A[i] = readInt;\n B = new int[N]; foreach (i; 0 .. N) B[i] = readInt;\n \n const ans = solve;\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nint[] permutationMatch(T)(in T[] A, in T[] B) {\r\n // given array A and its permutation B, returns index array I.\r\n // I[i] == j means A[i] == B[j];\r\n assert(A.length == B.length);\r\n int N = cast(int)(A.length);\r\n int[] ans = new int[N];\r\n DList!(int)[T] index;\r\n for (int i = 0; i < N; i++) {\r\n int a = A[i];\r\n if (a !in index) index[a] = DList!int();\r\n index[A[i]] ~= i;\r\n }\r\n for (int j = 0; j < N; j++) {\r\n int b = B[j];\r\n int i = index[b].front; index[b].removeFront;\r\n ans[i] = j;\r\n }\r\n return ans;\r\n}\r\n\r\nalias P = Tuple!(int,int);\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto A = readln.chomp.split(\" \").map!(to!int).array;\r\n auto B = readln.chomp.split(\" \").map!(to!int).array;\r\n bool C() {\r\n int i = N-1;\r\n auto s = new RedBlackTree!(int, \"a<b\", true)();\r\n for (int j = N-1; j >= 0; j--) {\r\n if (j >= 1 && B[j] == B[j-1]) {\r\n s.insert(B[j]);\r\n continue;\r\n }\r\n if (A[i] == B[j]) {\r\n i--;\r\n } else {\r\n if (A[i] in s) {\r\n s.removeKey(A[i]);\r\n i--;\r\n } else {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n writeln(C() ? \"YES\" : \"NO\");\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nint[] permutationMatch(T)(in T[] A, in T[] B) {\r\n // given array A and its permutation B, returns index array I.\r\n // I[i] == j means A[i] == B[j];\r\n assert(A.length == B.length);\r\n int N = cast(int)(A.length);\r\n int[] ans = new int[N];\r\n DList!(int)[T] index;\r\n for (int i = 0; i < N; i++) {\r\n int a = A[i];\r\n if (a !in index) index[a] = DList!int();\r\n index[A[i]] ~= i;\r\n }\r\n for (int j = 0; j < N; j++) {\r\n int b = B[j];\r\n int i = index[b].front; index[b].removeFront;\r\n ans[i] = j;\r\n }\r\n return ans;\r\n}\r\n\r\nalias P = Tuple!(int,int);\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto A = readln.chomp.split(\" \").map!(to!int).array;\r\n auto B = readln.chomp.split(\" \").map!(to!int).array;\r\n bool C() {\r\n int i = N-1;\r\n auto s = new RedBlackTree!(int, \"a<b\", true)();\r\n for (int j = N-1; j >= 0; j--) {\r\n if (j >= 1 && B[j] == B[j-1]) {\r\n s.insert(B[j]);\r\n continue;\r\n }\r\n if (i >= 0 && A[i] == B[j]) {\r\n i--;\r\n } else {\r\n if (A[i] in s) {\r\n s.removeKey(A[i]);\r\n } else {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n writeln(C() ? \"YES\" : \"NO\");\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (int [] a, int [] b, int n)\r\n{\r\n\tint [int] asks;\r\n\tfor (int i = n - 1, j = n - 1; i > 0 || j > 0; )\r\n\t{\r\n\t\tif (j >= 0 && a[j] in asks && asks[a[j]] > 0)\r\n\t\t{\r\n\t\t\tasks[a[j]] -= 1;\r\n\t\t\tj--;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (a[j] == b[i])\r\n\t\t{\r\n\t\t\ti--;\r\n\t\t\tj--;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (i + 1 < n && b[i] == b[i + 1])\r\n\t\t{\r\n\t\t\tasks[b[i]] += 1;\r\n\t\t\ti--;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\treturn true;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (a, b, n) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "src_uid": "158bd0ab8f4319f5fd1e6062caddad4e"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree set;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\n\tif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\tif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\twhile(input(&n))\n\t{\n\t\treadln;\n\t\tauto m=new int[n];\n\t\tfill(m,int.max);\n\t\tforeach(i;0..10)\n\t\t{\n\t\t\tif((1<<i)>n)break;\n\n\t\t\tforeach(j;0..2)\n\t\t\t{\n\t\t\t\tint[] z;\n\t\t\t\tforeach(f;1..n+1)\n\t\t\t\t{\n\t\t\t\t\tif(((f>>i)&1)==j)z~=f;\n\t\t\t\t}\n\t\t\t\twriteln(z.length);\n\t\t\t\tputarr(z);\n\n\t\t\t\tstdout.flush;\n\t\t\t\twriteln;\n\t\t\t\tauto ans=arread!int;\n\t\t\t\tdebug writeln(ans.length);\n\t\t\t\tforeach(p,y;ans)\n\t\t\t\t{\n\t\t\t\t\tdebug writeln(p);\n\t\t\t\t\tif((((p+1)>>i)&1)!=j)m[p]=min(m[p],y);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln(-1);\n\t\tputarr(m);\n\t\tstdout.flush;\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto ans = new int [n];\n\t\tans[] = int.max;\n\t\tforeach (d; 0..10)\n\t\t{\n\t\t\tforeach (g; 0..2)\n\t\t\t{\n\t\t\t\tauto p = n.iota.filter\n\t\t\t\t !(x => ((x >> d) & 1) == g).array;\n\t\t\t\tp[] += 1;\n\t\t\t\tif (p.length == 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\twritefln (\"%s\\n%(%s %)\", p.length, p);\n\t\t\t\tstdout.flush ();\n\t\t\t\tauto cur = readln.split.map !(to !(int)).array;\n\t\t\t\tforeach (i; 0..n)\n\t\t\t\t{\n\t\t\t\t\tif ((i >> d & 1) != g)\n\t\t\t\t\t{\n\t\t\t\t\t\tans[i] = min (ans[i], cur[i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (-1);\n\t\twritefln (\"%(%s %)\", ans);\n\t\tstdout.flush ();\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree set;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\n\tif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\tif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\twhile(input(&n))\n\t{\n\t\treadln;\n\t\tauto m=new int[n];\n\t\tfill(m,int.max);\n\t\tforeach(i;0..10)\n\t\t{\n\t\t\tif((1<<i)>n)break;\n\n\t\t\tforeach(j;0..2)\n\t\t\t{\n\t\t\t\tint[] z;\n\t\t\t\tforeach(f;1..n+1)\n\t\t\t\t{\n\t\t\t\t\tif(((f>>i)&1)==j)z~=f;\n\t\t\t\t}\n\t\t\t\twriteln(z.length);\n\t\t\t\tputarr(z);\n\n\t\t\t\tstdout.flush;\n\t\t\t\twriteln;\n\t\t\t\tauto ans=arread!int;\n\t\t\t\tforeach(y,p;ans)\n\t\t\t\t{\n\t\t\t\t\tif((((p+1)>>i)&1)!=j)m[p]=min(m[p],y);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln(-1);\n\t\tputarr(m);\n\t\tstdout.flush;\n\t}\n}\n"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree set;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\n\tif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\tif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\twhile(input(&n))\n\t{\n\t\tauto m=new int[n];\n\t\tfill(m,int.max);\n\t\tforeach(i;0..10)\n\t\t{\n\t\t\tif((1<<i)>n)break;\n\n\t\t\tforeach(j;0..2)\n\t\t\t{\n\t\t\t\tint[] z;\n\t\t\t\tforeach(f;1..n+1)\n\t\t\t\t{\n\t\t\t\t\tif(((f>>i)&1)==j)z~=f;\n\t\t\t\t}\n\t\t\t\twriteln(z.length);\n\t\t\t\tputarr(z);\n\t\t\t\twriteln;\n\t\t\t\tstdout.flush;\n\t\t\t\tauto ans=arread!int;\n\t\t\t\tforeach(y,p;ans)\n\t\t\t\t{\n\t\t\t\t\tif((((p+1)>>i)&1)!=j)m[p]=min(m[p],y);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln(-1);\n\t\tputarr(m);\n\t\tstdout.flush;\n\t}\n}\n"}], "src_uid": "0f43df0d2560e55af524e2657f0b2af0"} {"source_code": "import std.algorithm, std.array, std.range, std.stdio, std.typecons;\nalias Point = Tuple !(int, q{x}, int, q{y});\nlong sp (Point a, Point b, Point c) {return (b.x - a.x) * 1L * (c.x - a.x) + (b.y - a.y) * 1L * (c.y - a.y);}\nlong vp (Point a, Point b, Point c) {return (b.x - a.x) * 1L * (c.y - a.y) - (b.y - a.y) * 1L * (c.x - a.x);}\nvoid main () {\n\tint k, n, res;\n\treadf (\" %s %s\", &k, &n);\n\tauto a = new Point [k], b = new Point [n], s = new int [] [] [] (k, n);\n\tforeach (ref p; a) readf (\" %s %s\", &p.x, &p.y);\n\tforeach (ref q; b) readf (\" %s %s\", &q.x, &q.y);\n\tforeach (p; 0..k) foreach (q; 0..n) s[p][q] = n.iota.filter !(r => vp (b[r], a[p], b[q]) == 0 && sp (b[r], a[p], b[q]) < 0).take (k).array;\n\tbool go (int mask, int depth, int [] t) {\n\t\tif (t.empty) return true;\n\t\tif (depth < t.length) return false;\n\t\tforeach (p; 0..k) if (mask & (1 << p)) foreach (i, q; t) {\n\t\t\tauto next = t[0..i] ~ t[i + 1..$] ~ s[p][q];\n\t\t\tif (go (mask ^ (1 << p), depth - 1, next.sort ().uniq.array)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\tforeach (q; 0..n) res += go (-1, k, [q]);\n\twriteln (res);\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nlong sp (Point a, Point b, Point c)\n{\n\treturn (b.x - a.x) * 1L * (c.x - a.x) + (b.y - a.y) * 1L * (c.y - a.y);\n}\n\nlong vp (Point a, Point b, Point c)\n{\n\treturn (b.x - a.x) * 1L * (c.y - a.y) - (b.y - a.y) * 1L * (c.x - a.x);\n}\n\nvoid main ()\n{\n\tint k;\n\tint n;\n\twhile (readf (\" %s %s\", &k, &n) > 0)\n\t{\n\t\tauto a = new Point [k];\n\t\tforeach (ref p; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &p.x, &p.y);\n\t\t}\n\t\tauto b = new Point [n];\n\t\tforeach (ref q; b)\n\t\t{\n\t\t\treadf (\" %s %s\", &q.x, &q.y);\n\t\t}\n\t\tauto s = new int [] [] [] (k, n);\n\t\tforeach (p; 0..k)\n\t\t{\n\t\t\tforeach (q; 0..n)\n\t\t\t{\n\t\t\t\ts[p][q] = n.iota.filter\n\t\t\t\t !(r => vp (b[r], a[p], b[q]) == 0 &&\n\t\t\t\t sp (b[r], a[p], b[q]) < 0).take (k).array;\n\t\t\t}\n\t\t}\n\n\t\tbool go (int mask, int depth, int [] t)\n\t\t{\n\t\t\tif (t.empty)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (depth < t.length)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tforeach (p; 0..k)\n\t\t\t{\n\t\t\t\tif (mask & (1 << p))\n\t\t\t\t{\n\t\t\t\t\tforeach (i, q; t)\n\t\t\t\t\t{\n\t\t\t\t\t\tint [] next = t[0..i] ~\n\t\t\t\t\t\t t[i + 1..$] ~ s[p][q];\n\t\t\t\t\t\tnext = next.sort ().uniq.array;\n\t\t\t\t\t\tif (go (mask ^ (1 << p),\n\t\t\t\t\t\t depth - 1,\n\t\t\t\t\t\t next))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tlong res = 0;\n\t\tint m = (1 << k) - 1;\n\t\tforeach (q; 0..n)\n\t\t{\n\t\t\tres += k.iota.any\n\t\t\t !(p => go (m ^ (1 << p), k - 1, s[p][q]));\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.range, std.stdio, std.typecons;\nalias Point = Tuple !(int, q{x}, int, q{y});\nlong sp (Point a, Point b, Point c) {return (b.x - a.x) * 1L * (c.x - a.x) + (b.y - a.y) * 1L * (c.y - a.y);}\nlong vp (Point a, Point b, Point c) {return (b.x - a.x) * 1L * (c.y - a.y) - (b.y - a.y) * 1L * (c.x - a.x);}\nvoid main () {\n\tint k, n, res;\n\treadf (\" %s %s\", &k, &n);\n\tauto a = new Point [k], b = new Point [n], s = new int [] [] [] (k, n);\n\tforeach (ref p; a) readf (\" %s %s\", &p.x, &p.y);\n\tforeach (ref q; b) readf (\" %s %s\", &q.x, &q.y);\n\tforeach (p; 0..k) foreach (q; 0..n) s[p][q] = n.iota.filter !(r => vp (b[r], a[p], b[q]) == 0 && sp (b[r], a[p], b[q]) < 0).take (k).array;\n\tbool go (int mask, int depth, int [] t) {\n\t\tif (t.empty) return true;\n\t\tif (depth < t.length) return false;\n\t\tforeach (p; 0..k) if (mask & (1 << p)) foreach (i, q; t) {\n\t\t\tauto next = t[0..i] ~ t[i + 1..$] ~ s[p][q];\n\t\t\tif (go (mask ^ (1 << p), depth - 1, next.sort ().uniq.array)) return true;\n\t\t}\n\t\treturn false;\n\t}\n\tforeach (q; 0..n) res += k.iota.any !(p => go (-1, k, [p]));\n\twriteln (res);\n}\n"}], "src_uid": "05650a9c31b0ec5ca6643c95340ed5ee"} {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\r\n std.container, std.typecons, std.conv, std.random, std.bigint;\r\n\r\nvoid read(S...)(ref S args) {\r\n auto input = readln.split;\r\n enforce(input.length == args.length);\r\n foreach (i, ref arg; args) {\r\n arg = input[i].to!(S[i]);\r\n }\r\n}\r\n\r\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\r\n\r\nvoid main() {\r\n int t;\r\n read(t);\r\n \r\n while (t--) {\r\n int n;\r\n read(n);\r\n auto arr = list!int;\r\n \r\n int[] pos = new int[2 * n + 2];\r\n pos.fill(-1);\r\n \r\n int total = 0;\r\n \r\n foreach (int i, e; arr) {\r\n int q = (2 * i + 1) / e;\r\n foreach (j; 1 .. q + 1) {\r\n if (pos[j] != -1 && j * e == i + 1 + pos[j]) {\r\n total++;\r\n }\r\n }\r\n \r\n pos[e] = i + 1;\r\n }\r\n \r\n writeln(total);\r\n }\r\n}\r\n\r\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1541/problem/B\n//\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n long[] a = readln.split.map!(to!long).array;\n int[long] index;\n for(int i = 1; i <= n; ++i) {\n index[a[i - 1]] = i;\n }\n a.sort;\n long count = 0L;\n for(int i = 0; i < n; ++i) {\n for(int j = i + 1; j < n; ++j) {\n if(a[i] * a[j] > n * 2) {\n break;\n }\n if(a[i] * a[j] == index[a[i]] + index[a[j]]) {\n count += 1L;\n }\n }\n }\n count.writeln;\n}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array;\n auto b = zip(a, iota(0L, n)).array.sort!((a, b) => a[0] < b[0]).array;\n long result = 0;\n foreach (i ; 0 .. b.length) {\n long maxaj = (4 * n + b[i][0] - 1) / b[i][0];\n foreach (j ; 0 .. b.length) {\n if (b[j][0] > maxaj)\n break;\n if (b[i][1] < b[j][1]) {\n long x = b[i][0] * b[j][0];\n long y = b[i][1] + 1 + b[j][1] + 1;\n if (x == y) {\n result++;\n }\n }\n }\n }\n writeln(result);\n }\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n = scan!int;\n auto arr = scanArray!int;\n auto ix = new int[2*n+1];\n ix[] = -1000_000_0;\n for(int i = 0; i < n; ++i){\n ix[arr[i]] = i+1;\n }\n int cnt = 0;\n for(int k = 2; k <= 2*n; ++k){\n for(int i = 1; i * i < k; ++i){\n if(k % i == 0 && ix[k/i] + ix[i] == k){\n ++cnt;\n }\n }\n }\n writeln(cnt);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array;\n auto b = zip(a, iota(0, n)).array.sort!((a, b) => a[0] < b[0]);\n// writeln(a);\n// writeln(b);\n size_t maxn = b.length;\n foreach (i ; 1 .. b.length) {\n// long x = b[i - 1][0];\n// long y = b[i - i][0];\n// writefln(\"%d * %d = %d\", x, y, x * y);\n if (b[i - 1][0] * b[i][0] > 4 * n) {\n maxn = i + 1;\n break;\n }\n }\n// writeln(maxn);\n long result = 0;\n foreach (i ; 0 .. maxn) {\n foreach (j ; 0 .. maxn) {\n if (b[i][1] < b[j][1]) {\n long x = b[i][0] * b[j][0];\n long y = b[i][1] + 1 + b[j][1] + 1;\n if (x == y) {\n result++;\n }\n }\n }\n }\n writeln(result);\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array;\n auto b = zip(a, iota(0, n)).array.sort!((a, b) => a[0] < b[0]);\n// writeln(a);\n// writeln(b);\n size_t maxn = a.length;\n foreach (i ; 1 .. a.length) {\n if (a[i - i] * a[i] > 4 * n) {\n maxn = i + 1;\n break;\n }\n }\n long result = 0;\n foreach (i ; 0 .. maxn) {\n foreach (j ; i + 1 .. maxn) {\n long x = b[i][0] * b[j][0];\n long y = b[i][1] + 1 + b[j][1] + 1;\n if (x == y) {\n result++;\n }\n }\n }\n writeln(result);\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array;\n auto b = zip(a, iota(0, n)).array.sort!((a, b) => a[0] < b[0]);\n writeln(a);\n writeln(b);\n size_t maxn = a.length;\n foreach (i ; 1 .. a.length) {\n if (a[i - i] * a[i] > 4 * n) {\n maxn = i + 1;\n break;\n }\n }\n long result = 0;\n foreach (i ; 0 .. maxn) {\n foreach (j ; i + 1 .. maxn) {\n long x = b[i][0] * b[j][0];\n long y = b[i][1] + 1 + b[j][1] + 1;\n if (x == y) {\n result++;\n }\n }\n }\n writeln(result);\n }\n}\n"}], "src_uid": "0ce05499cd28f0825580ff48dae9e7a9"} {"source_code": "import std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tforeach (test; 0..readln.strip.to !(int))\n\t\t1.repeat (readln.strip.to !(int)).writefln !(\"%(%s %)\");\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto arr = new int[](n);\n\t\tarr[] = 1;\n\t\tans[ti] = arr;\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\n while(t--) {\n int n;\n readf(\"%s\\n\", &n);\n foreach(_; 0..n)\n writef(\"1 \");\n writeln;\n }\n}\n"}], "negative_code": [], "src_uid": "f82058f6ba3ce0da15a5ce059674af35"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto c1 = a.count (1);\n\t\tauto c2 = a.count (2);\n\t\tauto total = sum (a) + 1;\n\n\t\tauto s = new bool [total];\n\t\ts[2..$] = true;\n\t\tfor (int d = 0; d * d < total; d++)\n\t\t{\n\t\t\tif (s[d])\n\t\t\t{\n\t\t\t\tfor (int e = d * d; e < total; e += d)\n\t\t\t\t{\n\t\t\t\t\ts[e] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint [] answer;\n\t\tint cur = 0;\n\t\tforeach (d; 0..total)\n\t\t{\n\t\t\tif (s[d])\n\t\t\t{\n\t\t\t\twhile (cur + 2 <= d && c2 > 0)\n\t\t\t\t{\n\t\t\t\t\tcur += 2;\n\t\t\t\t\tc2 -= 1;\n\t\t\t\t\tanswer ~= 2;\n\t\t\t\t}\n\t\t\t\twhile (cur + 1 <= d && c1 > 0)\n\t\t\t\t{\n\t\t\t\t\tcur += 1;\n\t\t\t\t\tc1 -= 1;\n\t\t\t\t\tanswer ~= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twhile (c2 > 0)\n\t\t{\n\t\t\tc2 -= 1;\n\t\t\tanswer ~= 2;\n\t\t}\n\t\twhile (c1 > 0)\n\t\t{\n\t\t\tc1 -= 1;\n\t\t\tanswer ~= 1;\n\t\t}\n\n\t\twritefln (\"%(%s %)\", answer);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT read(T)(){ return read.to!T; }\nT[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }\nT[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\tint[] as = readln.chomp.split.to!(int[]);\n\t\n\tint[] acount = [0, 0, 0];\n\tforeach(a; as) acount[a] += 1;\n\t\n\tint[] ans;\n\tif(acount[1] > 0 && acount[2] > 0){\n\t\tacount[2] -= 1, ans ~= 2;\n\t\tacount[1] -= 1, ans ~= 1;\n\t}\n\twhile(acount[2] > 0){\n\t\tacount[2] -= 1, ans ~= 2;\n\t}\n\twhile(acount[1] > 0){\n\t\tacount[1] -= 1, ans ~= 1;\n\t}\n\t\n\tans.map!(to!string).array.join(\" \").writeln;\n\t\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto a = readln.split.to!(int[]);\n\n int one = 0, two = 0;\n foreach (el; a) {\n if (el == 1) {\n one += 1;\n } else {\n two += 1;\n }\n }\n if (one == 0 || two == 0) {\n writefln(\"%(%s %)\", a);\n return;\n }\n int[] b;\n b ~= [2, 1];\n foreach (_; 0 .. (two - 1)) {\n b ~= 2;\n }\n foreach (_; 0 .. (one - 1)) {\n b ~= 1;\n }\n writefln(\"%(%s %)\", b);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison : equal;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\n\nalias Tree = RBT!int;\n\nvoid main()\n{\n GC.disable();\n\n uint n;\n readf(\" %s\\n\", n);\n\n auto a = new int[n];\n foreach (i; 0 .. n)\n readf(\" %s\", a[i]);\n\n sort!\"a>b\"(a);\n if (a[$ - 1] == 1 && a[0] == 2)\n {\n writefln(\"2 1 %(%s %)\", a[1 .. $ - 1]);\n }\n else\n writefln(\"%(%s %)\", a);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!uint;\n\tauto a = RDR.ARR!uint;\n\n\tlong[2] cnt;\n\tforeach (i; 0..N)\n\t{\n\t\tauto j = a[i] - 1;\n\t\t++cnt[j];\n\t}\n\n\tlong x;\n\tif (cnt[1] != 0)\n\t{\n\t\t--cnt[1];\n\t\tx = 2;\n\t\twrite(2);\n\t}\n\telse\n\t{\n\t\t--cnt[0];\n\t\tx = 1;\n\t\twrite(1);\n\t}\n\n\tforeach (i; 1..N)\n\t{\n\t\tif (x % 2 == 1 && cnt[1] != 0)\n\t\t{\n\t\t\t--cnt[1];\n\t\t\tx += 2;\n\t\t\twrite(\" 2\");\n\t\t}\n\t\telse if (cnt[0] != 0)\n\t\t{\n\t\t\t--cnt[0];\n\t\t\tx += 1;\n\t\t\twrite(\" 1\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\t--cnt[1];\n\t\t\tx += 2;\n\t\t\twrite(\" 2\");\n\t\t}\n\t}\n\n\twriteln();\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio;\nimport std.array: array, split;\nimport std.algorithm: map, count;\nimport std.conv: to;\n\nvoid main() {\n\treadln();\n\tint[] a = readln.split.map!(to!int).array;\n\tif (a.count(1) == 0 || a.count(2) == 0) {\n\t\twritefln(\"%(%s %)\", a);\n\t} else {\n\t\twrite(\"2 1 \");\n\t\tforeach (ulong i; 0..(a.count(2)-1)) {\n\t\t\twrite(\"2 \");\n\t\t}\n\t\tforeach (ulong i; 0..(a.count(1)-1)) {\n\t\t\twrite(\"1 \");\n\t\t}\n\t\twriteln();\n\t}\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1149/A\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n readln;\n int[] a = readln.split.map!(to!int).array;\n long ones = a.count(1);\n long twos = a.count(2);\n if(ones == 0) {\n foreach(two; 0..twos) {\n writefln(\"%s \", 2);\n }\n return;\n }\n if(twos == 0) {\n foreach(one; 0..ones) {\n writefln(\"%s \", 1);\n }\n return;\n }\n writef(\"2 1 \");\n ones -= 1;\n twos -= 1;\n for(long i = 0; i < twos; i++)\n writef(\"%s \", 2);\n for(long i = 0; i < ones; i++)\n writef(\"%s \", 1);\n writeln();\n}\n\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n auto a = r.nextA!int (n);\n int[3] c;\n foreach (i; a) {\n c[i]++;\n }\n int[] b;\n debug stderr.writeln (c);\n void o (int k) {\n if (c[k] > 0) {\n --c[k];\n b ~= k;\n }\n }\n o (2);\n o (1);\n while (c[2] > 0) {\n o (2);\n }\n while (c[1] > 0) {\n o (1);\n }\n writefln (\"%(%s %)\", b);\n}\n\n"}], "negative_code": [{"source_code": "// https://codeforces.com/problemset/problem/1149/A\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n readln;\n int[] a = readln.split.map!(to!int).array;\n long ones = a.count(1);\n long twos = a.count(2);\n if(ones == 0)\n foreach(two; 0..twos) {\n writefln(\"%s \", 2);\n return;\n }\n if(twos == 0)\n foreach(one; 0..ones) {\n writefln(\"%s \", 1);\n return;\n }\n writef(\"2 1 \");\n ones -= 1;\n twos -= 1;\n foreach(two; 0..twos)\n writef(\"%s \", 2);\n foreach(one; 0..ones)\n writef(\"%s \", 1);\n writeln();\n}\n\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n auto a = r.nextA!int (n);\n int[3] c;\n foreach (i; a) {\n c[a[i]]++;\n }\n int[] b;\n void o (int k) {\n if (c[k] > 0) {\n --c[k];\n b ~= k;\n }\n }\n o (2);\n o (1);\n while (c[2] > 0) {\n o (2);\n }\n while (c[1] > 0) {\n o (1);\n }\n writefln (\"%(%s %)\", b);\n}\n\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison : equal;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\n\nalias Tree = RBT!int;\n\nvoid main()\n{\n GC.disable();\n\n uint n;\n readf(\" %s\\n\", n);\n\n auto a = new int[n];\n foreach (i; 0 .. n)\n readf(\" %s\", a[i]);\n\n sort!\"a>b\"(a);\n if (a[$ - 1] == 1 && a[0] == 2)\n {\n writefln(\"2 1 %(%s %)\", a[1 .. $ - 1]);\n }\n else\n writeln(a);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!uint;\n\tauto a = RDR.ARR!uint;\n\n\tlong[2] cnt;\n\tforeach (i; 0..N)\n\t{\n\t\tauto j = a[i] - 1;\n\t\t++cnt[j];\n\t}\n\n\tif (cnt[1] != 0)\n\t{\n\t\t--cnt[1];\n\t\twrite(2);\n\t}\n\telse\n\t{\n\t\t--cnt[0];\n\t\twrite(1);\n\t}\n\n\tforeach (i; 1..N)\n\t{\n\t\tif (i % 2 == 0 && cnt[1] != 0)\n\t\t{\n\t\t\t--cnt[1];\n\t\t\twrite(\" 2\");\n\t\t}\n\t\telse if (cnt[0] != 0)\n\t\t{\n\t\t\t--cnt[0];\n\t\t\twrite(\" 1\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\t--cnt[1];\n\t\t\twrite(\" 2\");\n\t\t}\n\t}\n\n\twriteln();\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "14593b565193607dff8b6b25bf51a661"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr[] -= 1;\n \n auto ans = new int[] (n);\n auto vis = new int[] (n);\n void dfs(int v) {\n if (vis[v] == 2) return;\n \n if (arr[v] == v) {\n vis[v] = 2;\n ans[v] = v;\n return;\n }\n \n if (vis[v] == 1) {\n vis[v] = 2;\n ans[v] = v;\n dfs(arr[v]);\n return;\n }\n \n vis[v] = 1;\n dfs(arr[v]);\n if (vis[v] != 2) {\n vis[v] = 2;\n ans[v] = ans[arr[v]];\n }\n }\n \n foreach (i; 0 .. n) {\n dfs(i);\n }\n \n debug { ans.writeln; }\n \n ans[] += 1;\n \n ans.writefln!(\"%(%s %)\");\n}", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int[] ans;\n foreach (i; 0 .. n) {\n auto vis = new int[] (n);\n vis[] = false;\n \n int j = i;\n do {\n vis[j] = true;\n j = arr[j] - 1;\n } while (!vis[j]);\n \n ans ~= j;\n }\n \n ans[] += 1;\n \n ans.writefln!(\"%(%s %)\");\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.array;\n\n int n; rd(n);\n auto g=readln.split.to!(int[]).map!((e)=>(e-1)).array;\n\n int f(int i, bool[] vis){\n if(vis[i]) return i;\n vis[i]=true;\n return f(g[i], vis);\n }\n\n foreach(i; 0..n){\n auto vis=new bool[](n);\n writeln(f(i, vis)+1);\n }\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr[] -= 1;\n \n auto start = new bool[] (n);\n start[] = true;\n foreach (i, e; arr) {\n if (i != e) start[e] = false;\n }\n \n auto ans = new int[] (n);\n auto vis = new int[] (n);\n void dfs(int v) {\n if (vis[v] == 2) return;\n \n if (arr[v] == v) {\n vis[v] = 2;\n ans[v] = v;\n return;\n }\n \n if (vis[v] == 1) {\n vis[v] = 2;\n ans[v] = v;\n dfs(arr[v]);\n return;\n }\n \n vis[v] = 1;\n dfs(arr[v]);\n if (vis[v] != 2) {\n vis[v] = 2;\n ans[v] = ans[arr[v]];\n }\n }\n \n foreach (i; 0 .. n) {\n if (start[i]) {\n dfs(i);\n }\n }\n \n debug { ans.writeln; }\n \n ans[] += 1;\n \n ans.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr[] -= 1;\n \n auto start = new bool[] (n);\n start[] = true;\n foreach (i, e; arr) {\n if (i != e) start[e] = false;\n }\n \n auto ans = new int[] (n);\n auto vis = new int[] (n);\n int dfs(int v) {\n if (arr[v] == v) {\n vis[v] = 2;\n ans[v] = v;\n return v;\n }\n \n if (vis[v] == 1) {\n vis[v] = 2;\n ans[v] = v;\n dfs(arr[v]);\n return v;\n }\n \n if (vis[v] == 2) {\n return ans[v];\n }\n \n vis[v] = 1;\n ans[v] = dfs(arr[v]);\n vis[v] = 2;\n return ans[v];\n }\n \n foreach (i; 0 .. n) {\n if (start[i]) {\n dfs(i);\n }\n }\n \n ans[] += 1;\n \n ans.writefln!(\"%(%s %)\");\n}"}], "src_uid": "c0abbbf1cf6c8ec11e942cdaaf01ad7c"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint k;\n\twhile (readf (\" %s\", &k) > 0)\n\t{\n\t\tint [long] boxByNum;\n\t\tlong [] [] boxes;\n\t\tlong [] boxSums;\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tint len;\n\t\t\treadf (\" %s\", &len);\n\t\t\tauto line = readln.splitter.map !(to !(long)).array;\n\t\t\tforeach (ref c; line)\n\t\t\t{\n\t\t\t\tboxByNum[c] = j;\n\t\t\t}\n\t\t\tboxes ~= line;\n\t\t\tboxSums ~= line.sum;\n\t\t}\n\n\t\tlong total = boxSums.sum;\n\t\tif (total % k != 0)\n\t\t{\n\t\t\twriteln (\"No\");\n\t\t\tcontinue;\n\t\t}\n\t\tlong target = total / k;\n\n\t\tauto p2k = 1 << k;\n\t\tauto answer = new long [] [p2k];\n\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tforeach (ref c; boxes[j])\n\t\t\t{\n\t\t\t\tlong [] cur;\n\t\t\t\tcur.reserve (k + 1);\n\t\t\t\tint maskUsed = 0;\n\t\t\t\tint box = j;\n\t\t\t\tlong num = c;\n\t\t\t\tbool ok = false;\n\n\t\t\t\twhile (true)\n\t\t\t\t{\n\t\t\t\t\tmaskUsed |= 1 << box;\n\t\t\t\t\tcur ~= num;\n\n\t\t\t\t\tlong desired =\n\t\t\t\t\t target - boxSums[box] + num;\n\t\t\t\t\tif (desired !in boxByNum)\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tbox = boxByNum[desired];\n\t\t\t\t\tnum = desired;\n\t\t\t\t\tif (num == cur.front)\n\t\t\t\t\t{\n\t\t\t\t\t\tok = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (maskUsed & (1 << box))\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (ok)\n\t\t\t\t{\n\t\t\t\t\tanswer[maskUsed] = cur.dup;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tauto f = new int [p2k];\n\t\tf[0] = -1;\n\t\tfor (int s = 0; s < p2k; s++)\n\t\t{\n\t\t\tfor (int t = s; t > 0; t = (t - 1) & s)\n\t\t\t{\n\t\t\t\tif ((f[s ^ t] != 0) && (answer[t] !is null))\n\t\t\t\t{\n\t\t\t\t\tf[s] = t;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (f[p2k - 1])\n\t\t{\n\t\t\twriteln (\"Yes\");\n\t\t\tauto numById = new long [k];\n\t\t\tauto toById = new int [k];\n\t\t\tint s = p2k - 1;\n\t\t\twhile (s != 0)\n\t\t\t{\n\t\t\t\tauto t = f[s];\n\t\t\t\tforeach (i; 0..answer[t].length)\n\t\t\t\t{\n\t\t\t\t\tlong num = answer[t][i];\n\t\t\t\t\tint box = boxByNum[num];\n\t\t\t\t\tlong numNext = answer[t][(i + 1) % $];\n\t\t\t\t\tint boxNext = boxByNum[numNext];\n\t\t\t\t\tnumById[boxNext] = numNext;\n\t\t\t\t\ttoById[boxNext] = box;\n\t\t\t\t}\n\t\t\t\ts ^= t;\n\t\t\t}\n\t\t\tforeach (j; 0..k)\n\t\t\t{\n\t\t\t\twriteln (numById[j], \" \", toById[j] + 1);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"No\");\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const K = readInt();\n auto N = new int[K];\n auto A = new long[][K];\n foreach (u; 0 .. K) {\n N[u] = readInt();\n A[u] = new long[N[u]];\n foreach (j; 0 .. N[u]) {\n A[u][j] = readLong();\n }\n }\n \n Tuple!(int, \"u\", int, \"j\")[long] pos;\n foreach (u; 0 .. K) {\n foreach (j; 0 .. N[u]) {\n pos[A[u][j]] = tuple!(\"u\", \"j\")(u, j);\n }\n }\n \n auto ss = new long[K];\n foreach (u; 0 .. K) {\n ss[u] = A[u].sum;\n }\n long s = ss.sum;\n if (s % K != 0) {\n writeln(\"No\");\n continue;\n }\n s /= K;\n debug {\n writeln(\"s = \", s);\n }\n \n auto cycs = new Tuple!(int[], long[])[1 << K];\n foreach (t; 0 .. K) {\n foreach (i; 0 .. N[t]) {\n int used;\n int[] us;\n long[] as;\n for (int u = t, j = i; ; ) {\n used |= 1 << u;\n us ~= u;\n as ~= A[u][j];\n // ss[u] - A[u][j] + A[v][k] = s\n const a = s - ss[u] + A[u][j];\n if (!(a in pos)) {\n goto failed;\n }\n const vk = pos[a];\n const v = vk.u;\n const k = vk.j;\n if (used & 1 << v) {\n if (!(t == v && i == k)) {\n goto failed;\n }\n debug {\n writeln(\"cyc \", used, \" \", us, \" \", as);\n }\n cycs[used] = tuple(us, as);\n break;\n }\n u = v;\n j = k;\n }\n failed:\n }\n }\n \n auto prev = new int[1 << K];\n prev[0] = -1;\n foreach (p; 1 .. 1 << K) {\n for (int q = p; q; --q &= p) {\n if (cycs[q][0] && prev[p ^ q]) {\n prev[p] = q;\n }\n }\n }\n if (prev[$ - 1]) {\n auto ansC = new long[K];\n auto ansP = new int[K];\n for (int p = (1 << K) - 1; p; ) {\n const q = prev[p];\n const us = cycs[q][0];\n const as = cycs[q][1];\n const len = cast(int)(us.length);\n foreach (h; 0 .. len) {\n ansC[us[h]] = as[h];\n ansP[us[(h + 1) % len]] = us[h];\n }\n p ^= q;\n }\n writeln(\"Yes\");\n foreach (u; 0 .. K) {\n writeln(ansC[u], \" \", ansP[u] + 1);\n }\n } else {\n writeln(\"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "f9fd4b42aa1ea3a44a1d05b068a959ba"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nstring S;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tS = readToken;\n\t\t\n\t\tchar[] cs = S.to!(char[]);\n\t\tchar[] ans;\n\t\tforeach (x; \"02468\") {\n\t\t\tforeach (i, c; cs) if (c == x) {\n\t\t\t\tswap(cs[i], cs[$ - 1]);\n\t\t\t\tif (ans < cs) {\n\t\t\t\t\tans = cs.dup;\n\t\t\t\t}\n\t\t\t\tswap(cs[i], cs[$ - 1]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tforeach_reverse (i, c; cs) if (c == x) {\n\t\t\t\tswap(cs[i], cs[$ - 1]);\n\t\t\t\tif (ans < cs) {\n\t\t\t\t\tans = cs.dup;\n\t\t\t\t}\n\t\t\t\tswap(cs[i], cs[$ - 1]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ans == \"\") {\n\t\t\twriteln(-1);\n\t\t} else {\n\t\t\twriteln(ans);\n\t\t}\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "\ufeffimport std.stdio, std.string, std.algorithm;\n\nvoid main() {\n\n\tstring snum = readln.strip;\n\n\tint nomore = -1;\n\tforeach (idx, sdigit; snum) {\n\t\tif ((sdigit - '0') % 2 == 0) {\n\t\t\tif (sdigit < snum[$ - 1]) {\n\t\t\t\tauto s = snum.dup;\n\t\t\t\tswap(s[idx], s[$ - 1]);\n\t\t\t\twriteln(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse\n\t\t\t\tnomore = idx;\n\t\t}\n\t}\n\n\tif (nomore != -1) {\n\t\tauto s = snum.dup;\n\t\tswap(s[nomore], s[$ - 1]);\n\t\twriteln(s);\n\t}\n\telse\n\t\twriteln(\"-1\");\n}"}], "negative_code": [{"source_code": "\ufeffimport std.stdio, std.string, std.algorithm;\n\nvoid main() {\n\n\tstring snum = readln.strip;\n\n\tint nomore = -1;\n\tforeach (idx, sdigit; snum) {\n\t\tif ((sdigit - '0') % 2 == 0) {\n\t\t\tif (sdigit < snum[$ - 1]) {\n\t\t\t\tauto s = snum.dup;\n\t\t\t\tswap(s[idx], s[$ - 1]);\n\t\t\t\twriteln(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse\n\t\t\t\tnomore = idx;\n\t\t}\n\t}\n\n\tif (nomore != -1) {\n\t\tauto s = snum.dup;\n\t\tswap(s[nomore], s[$ - 1]);\n\t\twriteln(snum);\n\t}\n\telse\n\t\twriteln(\"-1\");\n}"}, {"source_code": "\ufeffimport std.stdio, std.string, std.algorithm;\n\nvoid main() {\n\n\tstring snum = readln.strip;\n\n\tstring max = \"0\";\n\tforeach (idx, sdigit; snum) {\n\t\tif ((sdigit - '0') % 2 == 0) {\n\t\t\tauto s = snum.dup;\n\t\t\tswap(s[idx], s[$ - 1]);\n\t\t\tif (s > max)\n\t\t\t\tmax = s.dup;\n\t\t\tif (s[idx] < s[$ - 1])\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\twriteln((max == \"0\") ? \"-1\" : max);\n}"}], "src_uid": "bc375e27bd52f413216aaecc674366f8"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct Point\n{\n\tint x;\n\tint y;\n\n\tauto opCmp () (const auto ref Point that)\n\t{\n\t\tif (this.x != that.x)\n\t\t{\n\t\t\treturn this.x - that.x;\n\t\t}\n\t\treturn this.y - that.y;\n\t}\n\n\tPoint opBinary (string op) (const auto ref Point that)\n\t if (op == \"+\" || op == \"-\")\n\t{\n\t\tPoint res;\n\t\tres.x = mixin (\"this.x \" ~ op ~ \" that.x\");\n\t\tres.y = mixin (\"this.y \" ~ op ~ \" that.y\");\n\t\treturn res;\n\t}\n\n\tref Point opOpAssign (string op) (const auto ref Point that)\n\t if (op == \"+\" || op == \"-\")\n\t{\n\t\tmixin (\"this.x \" ~ op ~ \"= that.x;\");\n\t\tmixin (\"this.y \" ~ op ~ \"= that.y;\");\n\t\treturn this;\n\t}\n}\n\nauto vp () (const auto ref Point a, const auto ref Point b)\n{\n\treturn a.x * 1L * b.y - a.y * 1L * b.x;\n}\n\nauto sp () (const auto ref Point a, const auto ref Point b)\n{\n\treturn a.x * 1L * b.x + a.y * 1L * b.y;\n}\n\nauto norm2 () (const auto ref Point a)\n{\n\treturn a.x * 1L * a.x + a.y * 1L * a.y;\n}\n\nPoint [] getConvexHull (Point [] p)\n{\n\tauto s = p.minElement;\n\n\tauto q = p.filter !(c => c != s).array;\n\tforeach (ref c; q)\n\t{\n\t\tc -= s;\n\t}\n\n\tq.sort !((a, b) => vp (a, b) < 0 ||\n\t (vp (a, b) == 0 && norm2 (a) < norm2 (b)));\n\n\tPoint [] res;\n\tres ~= Point (0, 0);\n\tres ~= q.front;\n\tq.popFront ();\n\tforeach (ref c; q)\n\t{\n\t\twhile (res.length > 1 && vp (res[$ - 1] - res[$ - 2],\n\t\t c - res[$ - 2]) >= 0)\n\t\t{\n\t\t\tres.length -= 1;\n\t\t}\n\t\tres.assumeSafeAppend ();\n\t\tres ~= c;\n\t}\n\n\tdebug {writeln (res);}\n\tforeach (ref c; q)\n\t{\n\t\tc += s;\n\t}\n\treturn res;\n}\n\nalias Record = Tuple !(long, q{sp}, long, q{norm2});\n\nRecord [] getSignature (Point [] p)\n{\n\tauto h = getConvexHull (p);\n\tRecord [] res;\n\tauto n = h.length;\n\tforeach (i; 0..n)\n\t{\n\t\tauto j = i + 1;\n\t\tif (j >= n)\n\t\t{\n\t\t\tj -= n;\n\t\t}\n\t\tauto k = j + 1;\n\t\tif (k >= n)\n\t\t{\n\t\t\tk -= n;\n\t\t}\n\t\tres ~= Record (sp (h[j] - h[i], h[k] - h[i]),\n\t\t norm2 (h[j] - h[i]));\n\t}\n\tdebug {writeln (res);}\n\treturn res;\n}\n\nauto getPrefixFunction (R) (R r)\n if (isRandomAccessRange !(R))\n{\n\tint [] p;\n\tp ~= -1;\n\tint k = -1;\n\tforeach (c; r)\n\t{\n\t\twhile (k >= 0 && c != r[k])\n\t\t{\n\t\t\tk = p[k];\n\t\t}\n\t\tk += 1;\n\t\tp ~= k;\n\t}\n\treturn p;\n}\n\nunittest\n{\n\tassert (getPrefixFunction (\"abacaba\".representation) ==\n\t [-1, 0, 0, 1, 0, 1, 2, 3]);\n}\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto p = new Point [n];\n\t\tforeach (ref c; p)\n\t\t{\n\t\t\treadf (\" %s %s\", &c.x, &c.y);\n\t\t}\n\t\tauto q = new Point [m];\n\t\tforeach (ref c; q)\n\t\t{\n\t\t\treadf (\" %s %s\", &c.x, &c.y);\n\t\t}\n\t\tauto sigP = getSignature (p);\n\t\tauto sigQ = getSignature (q);\n\t\tauto ok = sigP.length == sigQ.length;\n\t\tif (ok)\n\t\t{\n\t\t\tauto pFun = getPrefixFunction (chain (sigP,\n\t\t\t only (Record (0, 0)), sigQ, sigQ));\n\t\t\tok = pFun.maxElement >= sigP.length;\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct Point\n{\n\tint x;\n\tint y;\n\n\tauto opCmp () (const auto ref Point that)\n\t{\n\t\tif (this.x != that.x)\n\t\t{\n\t\t\treturn this.x - that.x;\n\t\t}\n\t\treturn this.y - that.y;\n\t}\n\n\tPoint opBinary (string op) (const auto ref Point that)\n\t if (op == \"+\" || op == \"-\")\n\t{\n\t\tPoint res;\n\t\tres.x = mixin (\"this.x \" ~ op ~ \" that.x\");\n\t\tres.y = mixin (\"this.y \" ~ op ~ \" that.y\");\n\t\treturn res;\n\t}\n\n\tref Point opOpAssign (string op) (const auto ref Point that)\n\t if (op == \"+\" || op == \"-\")\n\t{\n\t\tmixin (\"this.x \" ~ op ~ \"= that.x;\");\n\t\tmixin (\"this.y \" ~ op ~ \"= that.y;\");\n\t\treturn this;\n\t}\n}\n\nauto vp () (const auto ref Point a, const auto ref Point b)\n{\n\treturn a.x * 1L * b.y - a.y * 1L * b.x;\n}\n\nauto norm2 () (const auto ref Point a)\n{\n\treturn a.x * 1L * a.x + a.y * 1L * a.y;\n}\n\nPoint [] getConvexHull (Point [] p)\n{\n\tauto s = p.minElement;\n\n\tauto q = p.filter !(c => c != s).array;\n\tforeach (ref c; q)\n\t{\n\t\tc -= s;\n\t}\n\n\tq.sort !((a, b) => vp (a, b) < 0 ||\n\t (vp (a, b) == 0 && norm2 (a) < norm2 (b)));\n\n\tPoint [] res;\n\tres ~= Point (0, 0);\n\tres ~= q.front;\n\tq.popFront ();\n\tforeach (ref c; q)\n\t{\n\t\twhile (res.length > 1 && vp (res[$ - 1] - res[$ - 2],\n\t\t c - res[$ - 2]) >= 0)\n\t\t{\n\t\t\tres.length -= 1;\n\t\t}\n\t\tres.assumeSafeAppend ();\n\t\tres ~= c;\n\t}\n\n\tdebug {writeln (res);}\n\tforeach (ref c; q)\n\t{\n\t\tc += s;\n\t}\n\treturn res;\n}\n\nalias Record = Tuple !(long, q{vp}, long, q{norm2});\n\nRecord [] getSignature (Point [] p)\n{\n\tauto h = getConvexHull (p);\n\tRecord [] res;\n\tauto n = h.length;\n\tforeach (i; 0..n)\n\t{\n\t\tauto j = i + 1;\n\t\tif (j >= n)\n\t\t{\n\t\t\tj -= n;\n\t\t}\n\t\tauto k = j + 1;\n\t\tif (k >= n)\n\t\t{\n\t\t\tk -= n;\n\t\t}\n\t\tres ~= Record (vp (h[j] - h[i], h[k] - h[i]),\n\t\t norm2 (h[j] - h[i]));\n\t}\n\tdebug {writeln (res);}\n\treturn res;\n}\n\nauto getPrefixFunction (R) (R r)\n if (isRandomAccessRange !(R))\n{\n\tint [] p;\n\tp ~= -1;\n\tint k = -1;\n\tforeach (c; r)\n\t{\n\t\twhile (k >= 0 && c != r[k])\n\t\t{\n\t\t\tk = p[k];\n\t\t}\n\t\tk += 1;\n\t\tp ~= k;\n\t}\n\treturn p;\n}\n\nunittest\n{\n\tassert (getPrefixFunction (\"abacaba\".representation) ==\n\t [-1, 0, 0, 1, 0, 1, 2, 3]);\n}\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto p = new Point [n];\n\t\tforeach (ref c; p)\n\t\t{\n\t\t\treadf (\" %s %s\", &c.x, &c.y);\n\t\t}\n\t\tauto q = new Point [m];\n\t\tforeach (ref c; q)\n\t\t{\n\t\t\treadf (\" %s %s\", &c.x, &c.y);\n\t\t}\n\t\tauto sigP = getSignature (p);\n\t\tauto sigQ = getSignature (q);\n\t\tauto ok = sigP.length == sigQ.length;\n\t\tif (ok)\n\t\t{\n\t\t\tauto pFun = getPrefixFunction (chain (sigP,\n\t\t\t only (Record (0, 0)), sigQ, sigQ));\n\t\t\tok = pFun.maxElement >= sigP.length;\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 403;\nalias Mint = ModInt!MO;\n\n\nstruct Point(T) {\n T x, y;\n Pt opBinary(string op)(Pt a) const {\n static if (op == \"+\") return Pt(x + a.x, y + a.y);\n else static if (op == \"-\") return Pt(x - a.x, y - a.y);\n else static assert(false);\n }\n Pt opBinary(string op)(T k) const {\n static if (op == \"*\") return Pt(x * k, y * k);\n else static if (op == \"/\") return Pt(x / k, y / k);\n else static assert(false);\n }\n T dot(Pt a) const { return x * a.x + y * a.y; }\n T det(Pt a) const { return x * a.y - y * a.x; }\n int opCmp(Pt a) const { return (x < a.x) ? -1 : (x > a.x) ? +1 : (y < a.y) ? -1 : (y > a.y) ? +1 : 0; }\n string toString() const { return \"(\" ~ x.to!string ~ \", \" ~ y.to!string ~ \")\"; }\n}\n\nalias Pt = Point!long;\nlong tri(Pt a, Pt b, Pt c) {\n return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);\n}\n\nPt[] convexHull(Pt[] ps) {\n auto qs = new Pt[ps.length + 1];\n ps.sort!((a, b) => ((a.x != b.x) ? (a.x < b.x) : (a.y < b.y)));\n int m = 0;\n foreach (p; ps) {\n for (; m > 1 && sgn(tri(qs[m - 2], qs[m - 1], p)) <= 0; --m) {}\n qs[m++] = p;\n }\n const r = m;\n foreach_reverse (p; ps) {\n for (; m > r && sgn(tri(qs[m - 2], qs[m - 1], p)) <= 0; --m) {}\n qs[m++] = p;\n }\n return qs[0 .. m - 1];\n}\n\n\nenum BASES = [20209, 1209, 21479];\n\nvoid main() {\n try {\n for (; ; ) {\n auto N = new int[2];\n foreach (h; 0 .. 2) {\n N[h] = readInt();\n }\n auto P = new Pt[][2];\n foreach (h; 0 .. 2) {\n P[h] = new Pt[N[h]];\n foreach (i; 0 .. N[h]) {\n P[h][i].x = readLong();\n P[h][i].y = readLong();\n }\n }\n \n auto seqs = new long[][2];\n foreach (h; 0 .. 2) {\n const qs = convexHull(P[h]);\n const qsLen = cast(int)(qs.length);\n auto edges = new Pt[qsLen];\n foreach (j; 0 .. qsLen) {\n edges[j] = qs[(j + 1) % qsLen] - qs[j];\n }\n foreach (j; 0 .. qsLen) {\n seqs[h] ~= edges[j].dot(edges[j]);\n seqs[h] ~= edges[j].dot(edges[(j + 1) % qsLen]);\n }\n debug {\n writeln(\"P[h] = \", P);\n writeln(\"qs = \", qs);\n writeln(\"seqs[h] = \", seqs[h]);\n }\n }\n \n bool ans;\n const len = cast(int)(seqs[0].length);\n if (len == seqs[1].length) {\n auto bb = new Mint[][](BASES.length, len + 1);\n foreach (g; 0 .. BASES.length) {\n bb[g][0] = 1;\n foreach (j; 1 .. len + 1) {\n bb[g][j] = bb[g][j - 1] * BASES[g];\n }\n }\n auto ss = new Mint[][][](2, BASES.length, len + 1);\n foreach (h; 0 .. 2) foreach (g; 0 .. BASES.length) {\n foreach (j; 0 .. len) {\n ss[h][g][j + 1] = ss[h][g][j] + bb[g][j] * seqs[h][j];\n }\n }\n debug {\n writeln(\"ss = \", ss);\n }\n foreach (shift; 0 .. len) {\n if (shift % 2 == 0) {\n bool ok = true;\n foreach (g; 0 .. BASES.length) {\n ok = ok && ((bb[g][shift] * ss[0][g][len]).x == (ss[1][g][len] + (bb[g][len] - 1) * ss[1][g][shift]).x);\n }\n if (ok) {\n debug {\n writeln(\"shift = \", shift);\n }\n foreach (j; 0 .. len) {\n if (seqs[0][j] != seqs[1][(j + shift) % len]) {\n ok = false;\n break;\n }\n }\n if (ok) {\n ans = true;\n break;\n }\n }\n }\n }\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 403;\nalias Mint = ModInt!MO;\n\n\nstruct Point(T) {\n T x, y;\n Pt opBinary(string op)(Pt a) const {\n static if (op == \"+\") return Pt(x + a.x, y + a.y);\n else static if (op == \"-\") return Pt(x - a.x, y - a.y);\n else static assert(false);\n }\n Pt opBinary(string op)(T k) const {\n static if (op == \"*\") return Pt(x * k, y * k);\n else static if (op == \"/\") return Pt(x / k, y / k);\n else static assert(false);\n }\n T dot(Pt a) const { return x * a.x + y * a.y; }\n T det(Pt a) const { return x * a.y - y * a.x; }\n int opCmp(Pt a) const { return (x < a.x) ? -1 : (x > a.x) ? +1 : (y < a.y) ? -1 : (y > a.y) ? +1 : 0; }\n string toString() const { return \"(\" ~ x.to!string ~ \", \" ~ y.to!string ~ \")\"; }\n}\n\nalias Pt = Point!long;\nlong tri(Pt a, Pt b, Pt c) {\n return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);\n}\n\nPt[] convexHull(Pt[] ps) {\n auto qs = new Pt[ps.length + 1];\n ps.sort!((a, b) => (a.x < b.x));\n int m = 0;\n foreach (p; ps) {\n for (; m > 1 && sgn(tri(qs[m - 2], qs[m - 1], p)) <= 0; --m) {}\n qs[m++] = p;\n }\n const r = m;\n foreach_reverse (p; ps) {\n for (; m > r && sgn(tri(qs[m - 2], qs[m - 1], p)) <= 0; --m) {}\n qs[m++] = p;\n }\n return qs[0 .. m - 1];\n}\n\n\nenum BASES = [2020, 120, 2147];\n\nvoid main() {\n try {\n for (; ; ) {\n auto N = new int[2];\n foreach (h; 0 .. 2) {\n N[h] = readInt();\n }\n auto P = new Pt[][2];\n foreach (h; 0 .. 2) {\n P[h] = new Pt[N[h]];\n foreach (i; 0 .. N[h]) {\n P[h][i].x = readLong();\n P[h][i].y = readLong();\n }\n }\n \n auto seqs = new long[][2];\n foreach (h; 0 .. 2) {\n const qs = convexHull(P[h]);\n const qsLen = cast(int)(qs.length);\n auto edges = new Pt[qsLen];\n foreach (j; 0 .. qsLen) {\n edges[j] = qs[(j + 1) % qsLen] - qs[j];\n }\n foreach (j; 0 .. qsLen) {\n seqs[h] ~= edges[j].dot(edges[j]);\n seqs[h] ~= edges[j].dot(edges[(j + 1) % qsLen]);\n seqs[h] ~= edges[j].det(edges[(j + 1) % qsLen]);\n }\n debug {\n writeln(\"qs = \", qs);\n writeln(\"seqs[h] = \", seqs[h]);\n }\n }\n \n bool ans;\n const len = cast(int)(seqs[0].length);\n if (len == seqs[1].length) {\n auto bb = new Mint[][](BASES.length, len + 1);\n foreach (g; 0 .. BASES.length) {\n bb[g][0] = 1;\n foreach (j; 1 .. len + 1) {\n bb[g][j] = bb[g][j - 1] * BASES[g];\n }\n }\n auto ss = new Mint[][][](2, BASES.length, len + 1);\n foreach (h; 0 .. 2) foreach (g; 0 .. BASES.length) {\n foreach (j; 0 .. len) {\n ss[h][g][j + 1] = ss[h][g][j] + bb[g][j] * seqs[h][j];\n }\n }\n debug {\n writeln(\"ss = \", ss);\n }\n foreach (shift; 0 .. len) {\n if (shift % 3 == 0) {\n bool ok = true;\n foreach (g; 0 .. BASES.length) {\n ok = ok && ((bb[g][shift] * ss[0][g][len]).x == (ss[1][g][len] + (bb[g][len] - 1) * ss[1][g][shift]).x);\n }\n if (ok) {\n debug {\n writeln(\"shift = \", shift);\n }\n ans = true;\n }\n }\n }\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum LIM = 105;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const Q = readInt();\n auto W = new int[N];\n foreach (i; 0 .. N) {\n W[i] = readInt();\n }\n \n int readIt() {\n const str = readToken();\n int ret;\n foreach (i; 0 .. N) {\n ret |= (str[i] - '0') << i;\n }\n return ret;\n }\n \n auto S = new int[M];\n foreach (j; 0 .. M) {\n S[j] = readIt();\n }\n auto T = new int[Q];\n auto K = new int[Q];\n foreach (q; 0 .. Q) {\n T[q] = readIt();\n K[q] = readInt();\n }\n \n auto WSum = new int[1 << N];\n foreach (i; 0 .. N) {\n foreach (h; 0 .. 1 << i) {\n WSum[h | 1 << i] = WSum[h] + W[i];\n }\n }\n \n auto cnt = new int[1 << N];\n foreach (j; 0 .. M) {\n ++cnt[S[j]];\n }\n auto anss = new int[][](1 << N, LIM);\n foreach (t; 0 .. 1 << N) {\n foreach (s; 0 .. 1 << N) {\n const w = WSum[((1 << N) - 1) ^ s ^ t];\n if (w < LIM) {\n anss[t][w] += cnt[s];\n }\n }\n foreach (k; 1 .. LIM) {\n anss[t][k] += anss[t][k - 1];\n }\n }\n \n foreach (q; 0 .. Q) {\n writeln(anss[T[q]][K[q]]);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 403;\nalias Mint = ModInt!MO;\n\n\nstruct Point(T) {\n T x, y;\n Pt opBinary(string op)(Pt a) const {\n static if (op == \"+\") return Pt(x + a.x, y + a.y);\n else static if (op == \"-\") return Pt(x - a.x, y - a.y);\n else static assert(false);\n }\n Pt opBinary(string op)(T k) const {\n static if (op == \"*\") return Pt(x * k, y * k);\n else static if (op == \"/\") return Pt(x / k, y / k);\n else static assert(false);\n }\n T dot(Pt a) const { return x * a.x + y * a.y; }\n T det(Pt a) const { return x * a.y - y * a.x; }\n int opCmp(Pt a) const { return (x < a.x) ? -1 : (x > a.x) ? +1 : (y < a.y) ? -1 : (y > a.y) ? +1 : 0; }\n string toString() const { return \"(\" ~ x.to!string ~ \", \" ~ y.to!string ~ \")\"; }\n}\n\nalias Pt = Point!long;\nlong tri(Pt a, Pt b, Pt c) {\n return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);\n}\n\nPt[] convexHull(Pt[] ps) {\n auto qs = new Pt[ps.length + 1];\n ps.sort!((a, b) => (a.x < b.x));\n int m = 0;\n foreach (p; ps) {\n for (; m > 1 && sgn(tri(qs[m - 2], qs[m - 1], p)) <= 0; --m) {}\n qs[m++] = p;\n }\n const r = m;\n foreach_reverse (p; ps) {\n for (; m > r && sgn(tri(qs[m - 2], qs[m - 1], p)) <= 0; --m) {}\n qs[m++] = p;\n }\n return qs[0 .. m - 1];\n}\n\n\nenum BASES = [20209, 1209, 21479];\n\nvoid main() {\n try {\n for (; ; ) {\n auto N = new int[2];\n foreach (h; 0 .. 2) {\n N[h] = readInt();\n }\n auto P = new Pt[][2];\n foreach (h; 0 .. 2) {\n P[h] = new Pt[N[h]];\n foreach (i; 0 .. N[h]) {\n P[h][i].x = readLong();\n P[h][i].y = readLong();\n }\n }\n \n auto seqs = new long[][2];\n foreach (h; 0 .. 2) {\n const qs = convexHull(P[h]);\n const qsLen = cast(int)(qs.length);\n auto edges = new Pt[qsLen];\n foreach (j; 0 .. qsLen) {\n edges[j] = qs[(j + 1) % qsLen] - qs[j];\n }\n foreach (j; 0 .. qsLen) {\n seqs[h] ~= edges[j].dot(edges[j]);\n seqs[h] ~= edges[j].dot(edges[(j + 1) % qsLen]);\n }\n debug {\n writeln(\"qs = \", qs);\n writeln(\"seqs[h] = \", seqs[h]);\n }\n }\n \n bool ans;\n const len = cast(int)(seqs[0].length);\n if (len == seqs[1].length) {\n auto bb = new Mint[][](BASES.length, len + 1);\n foreach (g; 0 .. BASES.length) {\n bb[g][0] = 1;\n foreach (j; 1 .. len + 1) {\n bb[g][j] = bb[g][j - 1] * BASES[g];\n }\n }\n auto ss = new Mint[][][](2, BASES.length, len + 1);\n foreach (h; 0 .. 2) foreach (g; 0 .. BASES.length) {\n foreach (j; 0 .. len) {\n ss[h][g][j + 1] = ss[h][g][j] + bb[g][j] * seqs[h][j];\n }\n }\n debug {\n writeln(\"ss = \", ss);\n }\n foreach (shift; 0 .. len) {\n if (shift % 2 == 0) {\n bool ok = true;\n foreach (g; 0 .. BASES.length) {\n ok = ok && ((bb[g][shift] * ss[0][g][len]).x == (ss[1][g][len] + (bb[g][len] - 1) * ss[1][g][shift]).x);\n }\n if (ok) {\n debug {\n writeln(\"shift = \", shift);\n }\n foreach (j; 0 .. len) {\n ok = ok && (seqs[0][j] == seqs[1][(j + shift) % len]);\n }\n if (ok) {\n ans = true;\n debug {\n } else {\n break;\n }\n }\n }\n }\n }\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 403;\nalias Mint = ModInt!MO;\n\n\nstruct Point(T) {\n T x, y;\n Pt opBinary(string op)(Pt a) const {\n static if (op == \"+\") return Pt(x + a.x, y + a.y);\n else static if (op == \"-\") return Pt(x - a.x, y - a.y);\n else static assert(false);\n }\n Pt opBinary(string op)(T k) const {\n static if (op == \"*\") return Pt(x * k, y * k);\n else static if (op == \"/\") return Pt(x / k, y / k);\n else static assert(false);\n }\n T dot(Pt a) const { return x * a.x + y * a.y; }\n T det(Pt a) const { return x * a.y - y * a.x; }\n int opCmp(Pt a) const { return (x < a.x) ? -1 : (x > a.x) ? +1 : (y < a.y) ? -1 : (y > a.y) ? +1 : 0; }\n string toString() const { return \"(\" ~ x.to!string ~ \", \" ~ y.to!string ~ \")\"; }\n}\n\nalias Pt = Point!long;\nlong tri(Pt a, Pt b, Pt c) {\n return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);\n}\n\nPt[] convexHull(Pt[] ps) {\n auto qs = new Pt[ps.length + 1];\n ps.sort!((a, b) => (a.x < b.x));\n int m = 0;\n foreach (p; ps) {\n for (; m > 1 && sgn(tri(qs[m - 2], qs[m - 1], p)) <= 0; --m) {}\n qs[m++] = p;\n }\n const r = m;\n foreach_reverse (p; ps) {\n for (; m > r && sgn(tri(qs[m - 2], qs[m - 1], p)) <= 0; --m) {}\n qs[m++] = p;\n }\n return qs[0 .. m - 1];\n}\n\n\nenum BASES = [2020, 120, 2147];\n\nvoid main() {\n try {\n for (; ; ) {\n auto N = new int[2];\n foreach (h; 0 .. 2) {\n N[h] = readInt();\n }\n auto P = new Pt[][2];\n foreach (h; 0 .. 2) {\n P[h] = new Pt[N[h]];\n foreach (i; 0 .. N[h]) {\n P[h][i].x = readLong();\n P[h][i].y = readLong();\n }\n }\n \n auto seqs = new long[][2];\n foreach (h; 0 .. 2) {\n const qs = convexHull(P[h]);\n const qsLen = cast(int)(qs.length);\n auto edges = new Pt[qsLen];\n foreach (j; 0 .. qsLen) {\n edges[j] = qs[(j + 1) % qsLen] - qs[j];\n }\n foreach (j; 0 .. qsLen) {\n seqs[h] ~= edges[j].dot(edges[j]);\n seqs[h] ~= edges[j].dot(edges[(j + 1) % qsLen]);\n }\n debug {\n writeln(\"qs = \", qs);\n writeln(\"seqs[h] = \", seqs[h]);\n }\n }\n \n bool ans;\n const len = cast(int)(seqs[0].length);\n if (len == seqs[1].length) {\n auto bb = new Mint[][](BASES.length, len + 1);\n foreach (g; 0 .. BASES.length) {\n bb[g][0] = 1;\n foreach (j; 1 .. len + 1) {\n bb[g][j] = bb[g][j - 1] * BASES[g];\n }\n }\n auto ss = new Mint[][][](2, BASES.length, len + 1);\n foreach (h; 0 .. 2) foreach (g; 0 .. BASES.length) {\n foreach (j; 0 .. len) {\n ss[h][g][j + 1] = ss[h][g][j] + bb[g][j] * seqs[h][j];\n }\n }\n debug {\n writeln(\"ss = \", ss);\n }\n foreach (shift; 0 .. len) {\n if (shift % 2 == 0) {\n bool ok = true;\n foreach (g; 0 .. BASES.length) {\n ok = ok && ((bb[g][shift] * ss[0][g][len]).x == (ss[1][g][len] + (bb[g][len] - 1) * ss[1][g][shift]).x);\n }\n if (ok) {\n debug {\n writeln(\"shift = \", shift);\n }\n ans = true;\n }\n }\n }\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "aeda11f32911d256fb6263635b738e99"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact;\nM[300_000 + 1] preInvFact;\nM[300_000 + 1] preNoSubsets;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n auto events = new Tuple!(int, int, int)[](0);\n auto n = next!int;\n auto k = next!int;\n \n foreach(i; 0 .. n + 1)\n preNoSubsets[i] = noSubsets(i, k);\n \n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events ~= tuple(l, -1, seg);\n events ~= tuple(r, +1, seg);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res = res + preNoSubsets[cnt];\n\t if (cnt != 0)\n\t res = res - preNoSubsets[cnt - 1];\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nll[] factorial = [1];\n\nll modinv(ll num){\n ll x = num;\n ll y = PRIME - 2;\n ll res = 1;\n while(y > 0){\n if(y % 2){\n res *= x;\n res %= PRIME;\n }\n y >>= 1;\n x *= x;\n x %= PRIME;\n }\n return res;\n}\n\nll combis(ll N, ll K){\n int n = to!int(N), k = to!int(K);\n ll num = factorial[n];\n ll den = modinv((factorial[k] * factorial[n-k]) % PRIME);\n ll sol = num*den;\n sol %= PRIME;\n return sol;\n}\n\n\n\nconst ll PRIME = 998244353;\n\nvoid play(){\n int n, k;\n n = rd!int;\n k = rd!int;\n tup[] arr;\n ll l, r;\n foreach(i; 0..n){\n l = rd; r = rd;\n arr ~= tup(l, 0);\n arr ~= tup(r, 1);\n }\n\n sort(arr);\n /* writeln(arr); */\n ll res = 0;\n ll op = 0;\n foreach(el; arr){\n if(!el[1]) ++op;\n if(op >= k && el[1]){\n ll dist = 1;\n res += dist * combis(op, k);\n res %= PRIME;\n // ALWAYS REMOVE PREVIOUS FIRST\n if(op > k){\n res = (res - combis(op-1, k) + PRIME) % PRIME;\n }\n }\n if(el[1]) --op;\n }\n writeln(res);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n // Preprocess\n foreach(i; 1..4*10^^5){\n factorial ~= (factorial.back * i) % PRIME;\n }\n\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int mod = 998_244_353;\n\nauto powMod (int a, int p)\n{\n\tint res = 1 % mod;\n\twhile (p > 0)\n\t{\n\t\tif (p & 1)\n\t\t{\n\t\t\tres = (res * 1L * a) % mod;\n\t\t}\n\t\ta = (a * 1L * a) % mod;\n\t\tp >>= 1;\n\t}\n\treturn res;\n}\n\nalias invMod = x => powMod (x, mod - 2);\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\talias Segment = Tuple !(int, q{l}, int, q{r});\n\t\tauto s = new Segment [n];\n\t\tforeach (ref c; s)\n\t\t{\n\t\t\treadf !(\" %s %s\") (c.l, c.r);\n\t\t}\n\n\t\talias Event = Tuple !(int, q{moment}, int, q{type});\n\t\tEvent [] e;\n\t\tforeach (ref c; s)\n\t\t{\n\t\t\te ~= Event (c.l, -1);\n\t\t\te ~= Event (c.r, +1);\n\t\t}\n\t\tsort (e);\n\n\t\tauto add = new int [n + 1];\n\t\tadd[k - 1] = 1;\n\t\tforeach (i; k..n + 1)\n\t\t{\n\t\t\tadd[i] = (add[i - 1] * 1L * i) % mod;\n\t\t\tadd[i] = (add[i] * 1L * invMod (i - k + 1)) % mod;\n\t\t}\n\n\t\tint res = 0;\n\t\tint balance = 0;\n\t\tforeach (ref d; e)\n\t\t{\n\t\t\tif (d.type == -1)\n\t\t\t{\n\t\t\t\tres = (res + add[balance]) % mod;\n\t\t\t}\n\t\t\tbalance -= d.type;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact = void;\nM[300_000 + 1] preInvFact = void;\nM[300_000 + 1] preNoSubsets = void;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n\n auto n = next!int;\n auto k = next!int;\n Tuple!(int, int)[600_000] eventBucket = void;\n auto events = eventBucket[0 .. 2 * n];\n foreach(i; 0 .. n + 1)\n preNoSubsets[i] = noSubsets(i, k);\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events[2 * seg] = tuple(l, -1);\n events[2 * seg + 1] = tuple(r, +1);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res += preNoSubsets[cnt];\n\t if (cnt != 0)\n\t res -= preNoSubsets[cnt - 1];\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.stdio;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact = void;\nM[300_000 + 1] preInvFact = void;\nM[300_000 + 1] preNoSubsets = void;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n\n auto n = next!int;\n auto k = next!int;\n Tuple!(int, int)[600_000] eventBucket = void;\n auto events = eventBucket[0 .. 2 * n];\n foreach(i; 0 .. n + 1)\n preNoSubsets[i] = noSubsets(i, k);\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events[2 * seg] = tuple(l, -1);\n events[2 * seg + 1] = tuple(r, +1);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res += preNoSubsets[cnt];\n\t if (cnt != 0)\n\t res -= preNoSubsets[cnt - 1];\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto next(T)()\n{\n static if (is(T == int) || is(T == long) || is(T == short))\n {\n import std.ascii: isDigit;\n T res;\n while(!frontChar.isDigit)\n\tpopChar;\n while(frontChar.isDigit)\n\t{\n\t res *= 10;\n\t res += frontChar - '0';\n\t popChar;\n\t}\n return res;\n }\n else static if (is(T == string))\n {\n \n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * (prefact[n - k] * prefact[k])^^(mod - 2);\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n prefact[i] = M(i) * prefact[i - 1];\n auto events = new Tuple!(int, int, int)[](0);\n auto n = next!int;\n auto k = next!int;\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events ~= tuple(l, -1, seg);\n events ~= tuple(r, +1, seg);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res = res + (noSubsets(cnt, k) - noSubsets(cnt - 1, k));\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.stdio;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact = void;\nM[300_000 + 1] preInvFact = void;\nM[300_000 + 1] preNoSubsets = void;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n\n auto n = next!int;\n auto k = next!int;\n Tuple!(int, int)[600_000] eventBucket = void;\n auto events = eventBucket[0 .. 2 * n];\n foreach(i; 0 .. n + 1)\n preNoSubsets[i] = noSubsets(i, k);\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events[2 * seg] = tuple(l, -1);\n events[2 * seg + 1] = tuple(r, +1);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res += preNoSubsets[cnt];\n\t if (cnt != 0)\n\t res -= preNoSubsets[cnt - 1];\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n}\nauto next(T)()\n{\n static if (is(T == int) || is(T == long) || is(T == short))\n {\n import std.ascii: isDigit;\n T res;\n while(!frontChar.isDigit)\n\tpopChar;\n while(frontChar.isDigit)\n\t{\n\t res *= 10;\n\t res += frontChar - '0';\n\t popChar;\n\t}\n return res;\n }\n else\n {\n static assert(0);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * (prefact[n - k] * prefact[k])^^(mod - 2);\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n prefact[i] = M(i) * prefact[i - 1];\n auto events = new Tuple!(int, int, int)[](0);\n auto n = next!int;\n auto k = next!int;\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events ~= tuple(l, -1, seg);\n events ~= tuple(r, +1, seg);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res = res + (noSubsets(cnt, k) - noSubsets(cnt - 1, k));\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact;\nM[300_000 + 1] preInvFact;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n auto events = new Tuple!(int, int, int)[](0);\n auto n = next!int;\n auto k = next!int;\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events ~= tuple(l, -1, seg);\n events ~= tuple(r, +1, seg);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res = res + (noSubsets(cnt, k) - noSubsets(cnt - 1, k));\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact;\nM[300_000 + 1] preInvFact;\nM[300_000 + 1] preNoSubsets;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n\n auto n = next!int;\n auto k = next!int;\n auto events = new Tuple!(int, int)[](2 * n);\n foreach(i; 0 .. n + 1)\n preNoSubsets[i] = noSubsets(i, k);\n M[300_000 + 1] preDelta;\n preDelta[0] = preNoSubsets[0];\n foreach(i; 1 .. n + 1)\n preDelta[i] = preNoSubsets[i] - preNoSubsets[i - 1];\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events[2 * seg] = tuple(l, -1);\n events[2 * seg + 1] = tuple(r, +1);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res = res + preDelta[cnt];\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact;\nM[300_000 + 1] preInvFact;\nM[300_000 + 1] preNoSubsets;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n\n auto n = next!int;\n auto k = next!int;\n auto events = new Tuple!(int, int)[](2 * n);\n foreach(i; 0 .. n + 1)\n preNoSubsets[i] = noSubsets(i, k);\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events[2 * seg] = tuple(l, -1);\n events[2 * seg + 1] = tuple(r, +1);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res = res + preNoSubsets[cnt];\n\t if (cnt != 0)\n\t res = res - preNoSubsets[cnt - 1];\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact;\nM[300_000 + 1] preInvFact;\nM[300_000 + 1] preNoSubsets;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n\n auto n = next!int;\n auto k = next!int;\n auto events = new Tuple!(int, int)[](2 * n);\n foreach(i; 0 .. n + 1)\n preNoSubsets[i] = noSubsets(i, k);\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events[2 * seg] = tuple(l, -1);\n events[2 * seg + 1] = tuple(r, +1);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res += preNoSubsets[cnt];\n\t if (cnt != 0)\n\t res -= preNoSubsets[cnt - 1];\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[300_000 + 1] prefact;\nM[300_000 + 1] preInvFact;\nM[300_000 + 1] preNoSubsets;\nM noSubsets(int n, int k)\n{\n if (n == 0) return M(0);\n if (k > n || k < 0) return M(0);\n // k <= n && k >= 0\n return prefact[n] * preInvFact[n - k] * preInvFact[k];\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n prefact[0] = M(1);\n preInvFact[0] = M(1);\n foreach(i; 1 .. prefact.length)\n {\n prefact[i] = M(i) * prefact[i - 1];\n preInvFact[i] = prefact[i] ^^ (mod - 2);\n }\n auto events = new Tuple!(int, int)[](0);\n auto n = next!int;\n auto k = next!int;\n foreach(i; 0 .. n + 1)\n preNoSubsets[i] = noSubsets(i, k);\n foreach(seg; 0 .. n)\n {\n auto l = next!int;\n auto r = next!int;\n events ~= tuple(l, -1);\n events ~= tuple(r, +1);\n }\n auto sevents = sort(events);\n int cnt = 0;\n M res = M(0);\n foreach(event; sevents)\n {\n cnt -= event[1];\n if (event[1] == -1)\n\t{\n\t res = res + preNoSubsets[cnt];\n\t if (cnt != 0)\n\t res = res - preNoSubsets[cnt - 1];\n\t}\n }\n res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod)(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opBinary(string op)(ulong exp)\n if (op == \"^^\")\n\t {\n\t return pow(This(1), exp);\n\t }\n mixin interiorBinPow;\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [], "src_uid": "64b1a4a9a474a0ee7baeb63596102c5a"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tint[] list;\n\t\tchar last = s[0];\n\t\tint cnt;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] != last)\n\t\t\t{\n\t\t\t\tlist ~= cnt;\n\t\t\t\tcnt = 0;\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tlast = s[i];\n\t\t}\n\t\tif (!list.empty && s[0] == s[$-1])\n\t\t{\n\t\t\tlist[0] += cnt;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlist ~= cnt;\n\t\t}\n\n\t\tif (list.length == 1)\n\t\t{\n\t\t\tans[ti] += (list[0] + 2) / 3;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (e; list)\n\t\t\t\tans[ti] += e / 3;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto s = readln.strip.map !(q{a == 'R'}).array;\n\t\tauto t = s ~ s ~ s;\n\t\timmutable int [] toFind = [0, 1];\n\t\tauto pos = t.countUntil (toFind).to !(int);\n\t\tif (pos == -1)\n\t\t{\n\t\t\twriteln ((n + 2) / 3);\n\t\t\tcontinue;\n\t\t}\n\n\t\tpos += 1;\n\t\twriteln (t[pos..pos + n].group.map !(q{(a[1] + 0) / 3}).sum);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10^^9;\n\nbool isOk(int s, int t, int u) {\n if (s == 0 && u == 0) return (t == 1);\n if (s == 1 && u == 1) return (t == 0);\n return true;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const S = readToken();\n \n int cost(int i, int s) {\n return (S[i] != \"LR\"[s]) ? 1 : 0;\n }\n \n int ans = INF;\n foreach (a0; 0 .. 2) foreach (a1; 0 .. 2) {\n auto dp = new int[][][](N + 1, 2, 2);\n foreach (i; 0 .. N + 1) {\n foreach (s; 0 .. 2) foreach (t; 0 .. 2) {\n dp[i][s][t] = INF;\n }\n }\n dp[2][a0][a1] = cost(0, a0) + cost(1, a1);\n foreach (i; 2 .. N) {\n foreach (s; 0 .. 2) foreach (t; 0 .. 2) {\n if (dp[i][s][t] < INF) {\n foreach (u; 0 .. 2) {\n if (isOk(s, t, u)) {\n chmin(dp[i + 1][t][u], dp[i][s][t] + cost(i, u));\n }\n }\n }\n }\n }\n foreach (s; 0 .. 2) foreach (t; 0 .. 2) {\n if (isOk(s, t, a0) && isOk(t, a0, a1)) {\n chmin(ans, dp[N][s][t]);\n }\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n string attacks;\n\n void solve(long tc = -1)\n {\n auto sol = makeSlice!long(n, 2, 2, 2, 2);\n auto done = makeSlice!bool(n, 2, 2, 2, 2);\n long getSol(long i, byte dir0, byte dirn, byte pdir, byte pset)\n {\n long solution(long val)\n {\n done.at(i).at(dir0).at(dirn).at(pdir).at(pset) = true;\n sol.at(i).at(dir0).at(dirn).at(pdir).at(pset) = val;\n return val;\n }\n if (done.at(i).at(dir0).at(dirn).at(pdir).at(pset))\n return sol.at(i).at(dir0).at(dirn).at(pdir).at(pset);\n long setCost;\n if (pset)\n setCost = attacks.at(i) != 'R';\n else\n setCost = attacks.at(i) != 'L';\n if (i == n - 1)\n {\n if (pset != dirn)\n return solution(long.max);\n if (pdir == 1 && dir0 == 0)\n return solution(setCost);\n if (pdir == 1)\n {\n if (pset != 0)\n return solution(long.max);\n return solution(setCost);\n }\n if (dir0 == 0)\n {\n if (pset != 1)\n return solution(long.max);\n return solution(setCost);\n }\n return solution(setCost);\n }\n assert(i != 0);\n long c0, c1;\n void calc0()\n {\n c0 = getSol(i + 1, dir0, dirn, pset, 0);\n if (c0 != long.max)\n {\n c0 += setCost;\n }\n }\n void calc1()\n {\n c1 = getSol(i + 1, dir0, dirn, pset, 1);\n if (c1 != long.max)\n {\n c1 += setCost;\n }\n }\n if (pdir)\n {\n if (pset)\n {\n calc0();\n return solution(c0);\n }\n calc0(), calc1();\n return solution(min(c0, c1));\n }\n else // pdir = 0\n {\n if (pset)\n {\n calc0(), calc1();\n return solution(min(c0, c1));\n }\n calc1();\n return solution(c1);\n }\n }\n long ans = long.max;\n foreach(dir0; 0 .. long(2))\n foreach(dirn; 0 .. long(2))\n {\n long cost0;\n if (dir0)\n {\n cost0 = attacks.at(0) != 'R';\n }\n else\n {\n cost0 = attacks.at(0) != 'L';\n }\n if (dir0)\n {\n if (dirn)\n {\n ans = min(ans, cost0 + getSol(1, cast(byte)dir0, cast(byte)dirn, cast(byte)dir0, 0));\n }\n else\n {\n ans = min(ans, cost0 + getSol(1, cast(byte)dir0, cast(byte)dirn, cast(byte)dir0, 0)\n , cost0 + getSol(1, cast(byte)dir0, cast(byte)dirn, cast(byte)dir0, 1));\n }\n }\n else\n {\n if (dirn)\n {\n ans = min(ans, cost0 + getSol(1, cast(byte)dir0, cast(byte)dirn, cast(byte)dir0, 0)\n , cost0 + getSol(1, cast(byte)dir0, cast(byte)dirn, cast(byte)dir0, 1));\n }\n else\n {\n ans = min(ans, cost0 + getSol(1, cast(byte)dir0, cast(byte)dirn, cast(byte)dir0, 1));\n }\n }\n }\n writeln(ans);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [], "src_uid": "b06d5b48525cd386a0141bdf44579a5c"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n int[] arr = new int[n];\n foreach (ref i; arr) {\n i = cin.read_int;\n }\n sort(arr);\n int ans = 1;\n for (int i = 1; i < n; i++) {\n if (abs(arr[i] - arr[i - 1]) == 1) {\n ans = 2;\n }\n }\n writeln(ans);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\ta.sort();\n\t\tforeach (j; 1..n)\n\t\t{\n\t\t\tif (a[j]-1 == a[j-1])\n\t\t\t{\n\t\t\t\tans[i] = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e+1);\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n int even = 0;\n int odd = 0;\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = cin.read_int;\n if (arr[i] % 2 == 0) even++;\n else odd++;\n }\n if (even == 1 && odd == 1) writeln(1);\n else if (even && !odd) writeln(1);\n else if (odd && !even) writeln(1);\n else writeln(2);\n } \n}\n\n"}], "src_uid": "dd2cd365d7afad9c2b5bdbbd45d87c8a"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Record = Tuple !(int, q{value}, int, q{num});\n\nvoid main ()\n{\n\tint n;\nmultitest_loop:\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tRecord [] p;\n\t\tp.reserve (n);\n\t\tforeach (i, x; a)\n\t\t{\n\t\t\tp ~= Record (x, i.to !(int) + 1);\n\t\t}\n\t\tsort (p);\n\t\tsort (b);\n\n\t\tint [] [] ans;\n\t\tint j = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint left = b[i] - p[i].value;\n\t\t\twhile (left > 0)\n\t\t\t{\n\t\t\t\twhile (j < i)\n\t\t\t\t{\n\t\t\t\t\tj += 1;\n\t\t\t\t}\n\t\t\t\twhile (j < n && p[j].value <= b[j])\n\t\t\t\t{\n\t\t\t\t\tj += 1;\n\t\t\t\t}\n\t\t\t\tif (j >= n)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tint add = min (left, p[j].value - b[j]);\n\t\t\t\tleft -= add;\n\t\t\t\tp[i].value += add;\n\t\t\t\tp[j].value -= add;\n\t\t\t\tans ~= [p[i].num, p[j].num, add];\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (p[i].value != b[i])\n\t\t\t{\n\t\t\t\twriteln (\"NO\");\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\n\t\twriteln (\"YES\");\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%(%s %)\\n%)\", ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\t\n\tX[] ss;\n\tforeach(i; 0 .. n) ss ~= new X(i, read.to!long, 0);\n\tss.sort!\"a.v<b.v\"();\n\tprint!1(\"ss:\", ss);\n\t\n\tlong[] ts;\n\tforeach(i; 0 .. n) ts ~= read.to!long;\n\tts.sort!\"a<b\"();\n\tprint!1(\"ts:\", ts);\n\t\n\tforeach(i, s; ss) s.d = ts[i] - s.v;\n\tprint!1(\"ss:\", ss);\n\t\n\tlong tmp;\n\tforeach(s; ss){\n\t\ttmp += s.d;\n\t\tif(tmp < 0){\n\t\t\t\"NO\".writeln;\n\t\t\treturn;\n\t\t}\n\t}\n\tif(tmp > 0){\n\t\t\"NO\".writeln;\n\t\treturn;\n\t}\n\t\n\tX[] ps, qs;\n\tforeach(s; ss){\n\t\tif(s.d > 0) ps ~= s;\n\t\tif(s.d < 0) qs ~= s;\n\t}\n\tprint!1(\"ps:\", ps);\n\tprint!1(\"qs:\", qs);\n\t\n\tA[] ans;\n\tint j;\n\tforeach(p; ps){\n\t\tprint!1(\"p:\", p);\n\t\twhile(p.d > 0){\n\t\t\tX q = qs[j];\n\t\t\tif(!(q.d < 0)){\n\t\t\t\tj += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(p.d + q.d > 0){\n\t\t\t\tans ~= A(p.id + 1, q.id + 1, -q.d);\n\t\t\t\tp.d += q.d;\n\t\t\t\tq.d = 0;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tans ~= A(p.id + 1, q.id + 1, p.d);\n\t\t\t\tq.d += p.d;\n\t\t\t\tp.d = 0;\n\t\t\t}\n\t\t}\n\t\tprint!1(\"ans:\", ans);\n\t}\n\t\n\t\"YES\".writeln;\n\tans.length.writeln;\n\tforeach(an; ans){\n\t\twriteln(an.i, \" \", an.j, \" \", an.d);\n\t}\n\t\n}\n\nclass X{\n\tint id;\n\tlong v;\n\tlong d;\n\tthis(int id, long v, long d){\n\t\tthis.id = id;\n\t\tthis.v = v;\n\t\tthis.d = d;\n\t}\n\toverride string toString(){\n\t\treturn id.to!string ~ \" \" ~ v.to!string ~ \" \" ~ d.to!string;\n\t}\n}\n\nstruct A{\n\tint i, j;\n\tlong d;\n}\n"}], "negative_code": [], "src_uid": "f236c4110a973d1c9f63cbbcc74b9e0b"} {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nstruct r {\r\n int h, w, idx;\r\n};\r\n\r\nvoid main()\r\n{\r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n int n;\r\n readf(\"%s\", &n);\r\n readln;\r\n \r\n auto a = new r[] (n);\r\n foreach (i; 0 .. n) {\r\n readf(\"%s %s\", &a[i].h, &a[i].w);\r\n readln;\r\n \r\n a[i].idx = i;\r\n }\r\n \r\n foreach (i; 0 .. n) {\r\n if (a[i].h > a[i].w) { swap(a[i].h, a[i].w); }\r\n }\r\n \r\n a.schwartzSort!(x => x.h);\r\n int mn = -1, nxtmn = 0;\r\n \r\n auto ans = new int[] (n);\r\n ans[a[0].idx] = -1;\r\n \r\n foreach (i; 1 .. n) {\r\n if (a[i].h > a[i-1].h) { mn = nxtmn; }\r\n \r\n ans[a[i].idx] = mn != -1 && a[mn].w < a[i].w ? a[mn].idx : -1;\r\n \r\n if (a[i].w < a[nxtmn].w) { nxtmn = i; }\r\n }\r\n \r\n ans.map!(x => x != -1 ? x+1 : -1).map!(to!string).join(\" \").writeln;\r\n }\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n;\r\n\t\treadf !(\" %s\") (n);\r\n\t\talias Friend = Tuple !(int, q{w}, int, q{h}, int, q{id});\r\n\t\tauto f = new Friend [n * 2];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tint w, h;\r\n\t\t\treadf !(\" %s %s\") (w, h);\r\n\t\t\tf[i * 2 + 0] = Friend (w, h, i);\r\n\t\t\tf[i * 2 + 1] = Friend (h, w, i);\r\n\t\t}\r\n\t\tsort (f);\r\n\t\tauto lo = f.front;\r\n\t\tauto answer = (-1).repeat (n).array;\r\n\t\tint j = 0;\r\n\t\tforeach (ref c; f)\r\n\t\t{\r\n\t\t\twhile (f[j].w < c.w)\r\n\t\t\t{\r\n\t\t\t\tif (lo.h > f[j].h)\r\n\t\t\t\t{\r\n\t\t\t\t\tlo = f[j];\r\n\t\t\t\t}\r\n\t\t\t\tj += 1;\r\n\t\t\t}\r\n\t\t\tif (lo.w < c.w && lo.h < c.h)\r\n\t\t\t{\r\n\t\t\t\tanswer[c.id] = lo.id + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (answer);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto h = new long[](n);\r\n\t\tauto w = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\th[i] = RD;\r\n\t\t\tw[i] = RD;\r\n\t\t}\r\n\t\t\r\n\t\tauto tmp = new int[](n);\r\n\t\ttmp[] = -1;\r\n\r\n\t\tauto list = new long[][](n*2);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tlist[i*2] = [h[i], w[i], i];\r\n\t\t\tlist[i*2+1] = [w[i], h[i], i];\r\n\t\t}\r\n\t\tauto index = list.MAKE_IDX!\"a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]\";\r\n\t\tlong minW = long.max;\r\n\t\tint posW;\r\n\t\tforeach (i; index)\r\n\t\t{\r\n\t\t\tauto hh = list[i][0];\r\n\t\t\tauto ww = list[i][1];\r\n\t\t\tauto jj = cast(int)list[i][2];\r\n\t\t\tif (minW < ww)\r\n\t\t\t{\r\n\t\t\t\ttmp[jj] = posW+1;\r\n\t\t\t}\r\n\t\t\tif (ww < minW)\r\n\t\t\t{\r\n\t\t\t\tminW = ww;\r\n\t\t\t\tposW = jj;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans[ti] = tmp;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nstruct r {\r\n int h, w, idx;\r\n};\r\n\r\nvoid main()\r\n{\r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n int n;\r\n readf(\"%s\", &n);\r\n readln;\r\n \r\n auto a = new r[] (n);\r\n foreach (i; 0 .. n) {\r\n readf(\"%s %s\", &a[i].h, &a[i].w);\r\n readln;\r\n a[i].idx = i;\r\n }\r\n \r\n a.schwartzSort!(x => x.h);\r\n int mn = -1, nxtmn = 0;\r\n \r\n auto ans = new int[] (n);\r\n ans[a[0].idx] = -1;\r\n \r\n foreach (i; 1 .. n) {\r\n if (a[i].h > a[i-1].h) { mn = nxtmn; }\r\n \r\n ans[a[i].idx] = mn != -1 && a[mn].w < a[i].w ? a[mn].idx : -1;\r\n \r\n if (a[i].w < a[nxtmn].w) { nxtmn = i; }\r\n }\r\n \r\n ans.map!(x => x != -1 ? x+1 : -1).map!(to!string).join(\" \").writeln;\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto h = new long[](n);\r\n\t\tauto w = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\th[i] = RD;\r\n\t\t\tw[i] = RD;\r\n\t\t}\r\n\t\t\r\n\t\tauto tmp = new int[](n);\r\n\t\ttmp[] = -1;\r\n\r\n\t\tauto list = new long[][](n*2);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tlist[i*2] = [h[i], w[i], i];\r\n\t\t\tlist[i*2+1] = [w[i], h[i], i];\r\n\t\t}\r\n\t\tauto index = list.MAKE_IDX!\"a[0] < b[0]\";\r\n\t\tlong minW = long.max;\r\n\t\tint posW;\r\n\t\tforeach (i; index)\r\n\t\t{\r\n\t\t\tauto hh = list[i][0];\r\n\t\t\tauto ww = list[i][1];\r\n\t\t\tauto jj = cast(int)list[i][2];\r\n\t\t\tif (minW < ww)\r\n\t\t\t{\r\n\t\t\t\ttmp[jj] = posW+1;\r\n\t\t\t}\r\n\t\t\tif (ww < minW)\r\n\t\t\t{\r\n\t\t\t\tminW = ww;\r\n\t\t\t\tposW = jj;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans[ti] = tmp;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n;\r\n\t\treadf !(\" %s\") (n);\r\n\t\talias Friend = Tuple !(int, q{w}, int, q{h}, int, q{id});\r\n\t\tauto f = new Friend [n * 2];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tint w, h;\r\n\t\t\treadf !(\" %s %s\") (w, h);\r\n\t\t\tf[i * 2 + 0] = Friend (w, h, i);\r\n\t\t\tf[i * 2 + 1] = Friend (h, w, i);\r\n\t\t}\r\n\t\tsort (f);\r\n\t\tauto lo = f.front;\r\n\t\tauto answer = (-1).repeat (n).array;\r\n\t\tforeach (ref c; f)\r\n\t\t{\r\n\t\t\tif (lo.h > c.h)\r\n\t\t\t{\r\n\t\t\t\tlo = c;\r\n\t\t\t}\r\n\t\t\tif (lo.w < c.w && lo.h < c.h)\r\n\t\t\t{\r\n\t\t\t\tanswer[c.id] = lo.id + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (answer);\r\n\t}\r\n}\r\n"}], "src_uid": "f15df307d67d5754a3a322a66de1338c"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int N; get(N);\r\n int a, b, c;\r\n int[] aa; get(aa);\r\n foreach (i, x; aa) {\r\n if (a == x && b == x) {\r\n continue;\r\n } else if (a != x && b != x) {\r\n if (i+1 < aa.length) {\r\n auto y = aa[i+1];\r\n if (a == y) {\r\n a = x;\r\n } else {\r\n b = x;\r\n }\r\n }\r\n } else if (a != x) {\r\n a = x;\r\n } else if (b != x) {\r\n b = x;\r\n }\r\n ++c;\r\n }\r\n writeln(c);\r\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const N = readInt();\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt();\r\n }\r\n \r\n const gs = A.group.array;\r\n const gsLen = cast(int)(gs.length);\r\n debug {\r\n writeln(\"A = \", A);\r\n writeln(\"gs = \", gs);\r\n }\r\n \r\n int ans;\r\n for (int j = 0, k; j < gsLen; j = k) {\r\n for (k = j; k < gsLen && (gs[j][1] == 1) == (gs[k][1] == 1); ++k) {}\r\n if (gs[j][1] == 1) {\r\n ans += (k - j);\r\n if (0 < j && k < gsLen && gs[j - 1][0] == gs[k][0]) {\r\n if ((k - j) % 2 != 0) {\r\n bool bad = true;\r\n for (int l = j + 1; l < k; l += 2) {\r\n bad = bad && (gs[j - 1][0] == gs[l][0]);\r\n }\r\n if (bad) {\r\n debug {\r\n writeln(\"bad \", gs[j .. k]);\r\n }\r\n ans -= 1;\r\n }\r\n }\r\n }\r\n } else {\r\n ans += 2 * (k - j);\r\n }\r\n }\r\n writeln(ans);\r\n \r\n debug {\r\n int brt = 0;\r\n foreach (p; 0 .. 1 << N) {\r\n int cost;\r\n int[2] bs = [-1, -1];\r\n foreach (i; 0 .. N) {\r\n const s = (p >> i) & 1;\r\n if (bs[s] != A[i]) {\r\n ++cost;\r\n bs[s] = A[i];\r\n }\r\n }\r\n chmax(brt, cost);\r\n }\r\n writeln(\"brt = \", brt);\r\n assert(brt == ans);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\tauto a = RDA(-1);\r\n\r\n\tauto pos = new int[][](n+1);\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tpos[a[i]] ~= i;\r\n\t}\r\n\r\n\tint[] a0 = [n], a1 = [n];\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tpos[a[i]].popFront;\r\n\t\tif (a0.back == a[i])\r\n\t\t\ta1 ~= a[i];\r\n\t\telse if (a1.back == a[i])\r\n\t\t\ta0 ~= a[i];\r\n\t\telse\r\n\t\t{\r\n\t\t\tint x = n, y = n;\r\n\t\t\tif (!pos[a0.back].empty)\r\n\t\t\t\tx = pos[a0.back].front;\r\n\t\t\tif (!pos[a1.back].empty)\r\n\t\t\t\ty = pos[a1.back].front;\r\n\t\t\tif (x < y)\r\n\t\t\t\ta0 ~= a[i];\r\n\t\t\telse\r\n\t\t\t\ta1 ~= a[i];\r\n\t\t}\r\n\t}\r\n\r\n\tdebug writeln(\"a0:\", a0);\r\n\tdebug writeln(\"a1:\", a1);\r\n\ta0.popFront;\r\n\ta1.popFront;\r\n\tlong ans;\r\n\tif (!a0.empty)\r\n\t{\r\n\t\t++ans;\r\n\r\n\t\tforeach (i; 1..a0.length)\r\n\t\t{\r\n\t\t\tif (a0[i-1] != a0[i])\r\n\t\t\t\t++ans;\r\n\t\t}\r\n\t}\r\n\tif (!a1.empty)\r\n\t{\r\n\t\t++ans;\r\n\t\tforeach (i; 1..a1.length)\r\n\t\t{\r\n\t\t\tif (a1[i-1] != a1[i])\r\n\t\t\t\t++ans;\r\n\t\t}\r\n\t}\r\n\r\n\twriteln(ans);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint res = 0;\r\n\t\tint [2] [] p = [[-1, -1]];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tint [2] [] [2] q;\r\n\t\t\tint next = res;\r\n\t\t\tforeach (ref prev; p)\r\n\t\t\t{\r\n\t\t\t\tforeach (j; 0..2)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto good = (prev[j] != c);\r\n\t\t\t\t\tq[good] ~= [c, prev[!j]];\r\n\t \t}\r\n\t\t\t}\r\n\t\t\tforeach (j; 0..2)\r\n\t\t\t{\r\n\t\t\t\tif (!q[j].empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tres = next + j;\r\n\t\t\t\t\tp = q[j];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tforeach (ref prev; p)\r\n\t\t\t{\r\n\t\t\t\tsort (prev[]);\r\n\t\t\t}\r\n\t\t\tp = p.sort.uniq.take (4).array;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const N = readInt();\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt();\r\n }\r\n \r\n const gs = A.group.array;\r\n const gsLen = cast(int)(gs.length);\r\n debug {\r\n writeln(\"gs = \", gs);\r\n }\r\n \r\n int ans;\r\n for (int j = 0, k; j < gsLen; j = k) {\r\n for (k = j; k < gsLen && (gs[j][1] == 1) == (gs[k][1] == 1); ++k) {}\r\n if (gs[j][1] == 1) {\r\n ans += (k - j);\r\n if (0 < j && k < gsLen) {\r\n if ((k - j) % 2 != 0) {\r\n bool bad = true;\r\n for (int l = j + 1; l < k; l += 2) {\r\n bad = bad && (gs[j - 1][0] == gs[l][0] && gs[l][0] == gs[k][0]);\r\n }\r\n if (bad) {\r\n debug {\r\n writeln(\"bad \", gs[j .. k]);\r\n }\r\n ans -= 1;\r\n }\r\n }\r\n }\r\n } else {\r\n ans += 2 * (k - j);\r\n }\r\n }\r\n writeln(ans);\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const N = readInt();\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt();\r\n }\r\n \r\n auto nxt = new int[N + 1];\r\n nxt[N] = -1;\r\n foreach_reverse (i; 0 .. N) {\r\n nxt[i] = (i + 1 < N && A[i] != A[i + 1]) ? A[i + 1] : nxt[i + 1];\r\n }\r\n debug {\r\n writeln(\"nxt = \", nxt);\r\n }\r\n \r\n int ans;\r\n int[2] bs = [-1, -1];\r\n foreach (i; 0 .. N) {\r\n void add(int s) {\r\n if (bs[s] != A[i]) {\r\n ++ans;\r\n }\r\n bs[s] = A[i];\r\n }\r\n add(i % 2);\r\n }\r\n writeln(ans);\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const N = readInt();\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt();\r\n }\r\n \r\n auto nxt = new int[N + 1];\r\n nxt[N] = -1;\r\n foreach_reverse (i; 0 .. N) {\r\n nxt[i] = (i + 1 < N && A[i] != A[i + 1]) ? A[i + 1] : nxt[i + 1];\r\n }\r\n debug {\r\n writeln(\"nxt = \", nxt);\r\n }\r\n \r\n int ans;\r\n int[2] bs = [-1, -1];\r\n foreach (i; 0 .. N) {\r\n void add(int s) {\r\n if (bs[s] != A[i]) {\r\n ++ans;\r\n }\r\n bs[s] = A[i];\r\n }\r\n if (bs[0] == A[i]) {\r\n add(1);\r\n } else if (bs[1] == A[i]) {\r\n add(0);\r\n } else if (bs[0] == nxt[i]) {\r\n add(1);\r\n } else if (bs[1] == nxt[i]) {\r\n add(0);\r\n } else {\r\n add(0);\r\n }\r\n }\r\n writeln(ans);\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const N = readInt();\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt();\r\n }\r\n \r\n int ans;\r\n foreach (g; A.group) {\r\n ans += (g[1] >= 2) ? 2 : 1;\r\n }\r\n writeln(ans);\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\tauto a = RDA;\r\n\r\n\tlong[] a0 = [a[0]], a1;\r\n\tforeach (i; 1..n)\r\n\t{\r\n\t\tif (a0.back == a[i])\r\n\t\t\ta1 ~= a[i];\r\n\t\telse\r\n\t\t\ta0 ~= a[i];\r\n\t}\r\n\r\n\tlong ans = 1;\r\n\tforeach (i; 1..a0.length)\r\n\t{\r\n\t\tif (a0[i-1] != a0[i])\r\n\t\t\t++ans;\r\n\t}\r\n\tif (!a1.empty)\r\n\t{\r\n\t\t++ans;\r\n\t\tforeach (i; 1..a1.length)\r\n\t\t{\r\n\t\t\tif (a1[i-1] != a1[i])\r\n\t\t\t\t++ans;\r\n\t\t}\r\n\t}\r\n\r\n\twriteln(ans);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int N; get(N);\r\n int a, b, c;\r\n foreach (x; readln.split.to!(int[])) {\r\n if (a != x) {\r\n a = x;\r\n ++c;\r\n } else if (b != x) {\r\n b = x;\r\n ++c;\r\n }\r\n }\r\n writeln(c);\r\n}"}], "src_uid": "55f0ecc597e6e40256a14debcad1b878"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.typecons, std.string;\nvoid main () {\n\tint n, x, r, res, cur = int.min;\n\tstring s;\n\treadf (\" %s%s\", &n, &s);\n\tauto a = s.split.map!(to!int).chunks (2)\n\t\t.map!\"tuple(a[0]+a[1],a[0]-a[1])\".array.sort;\n\tforeach (c; a) if (cur <= c[1]) res++, cur = c[0];\n\tres.writeln;\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.stdio, std.typecons;\nvoid main () {\n\tint n, x, r, res, cur = int.min;\n\treadf (\" %s\", &n);\n\tTuple !(int, int) [] a;\n\tforeach (i; 0..n) readf (\" %s %s\", &x, &r), a ~= tuple (x + r, x - r);\n\ta.sort;\n\tforeach (c; a) if (cur <= c[1]) res++, cur = c[0];\n\tres.writeln;\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.range,std.stdio;void main(){int v=int.min;readln;stdin.byLine.map!(split).map!(map!(to!int)).map!\"[a[0]+a[1],a[0]-a[1]]\".array.sort.map!(x=>v<=x[1]?v=x[0],1:0).sum.writeln;}"}, {"source_code": "import std.algorithm, std.stdio, std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Pair = Tuple !(int, q{hi}, int, q{lo});\n\t\tPair [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x, r;\n\t\t\treadf (\" %s %s\", &x, &r);\n\t\t\ta ~= Pair (x + r, x - r);\n\t\t}\n\t\tsort (a);\n\t\tlong res = 0;\n\t\tint cur = int.min;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tif (cur <= c.lo)\n\t\t\t{\n\t\t\t\tres++;\n\t\t\t\tcur = c.hi;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.range,std.stdio;void main(){int v=int.min;readln;stdin.byLine.map!(split).map!(map!(to!int)).map!\"[a[0]+a[1],a[0]-a[1]]\".array.sort.map!(x=>v<=x[1]?v=x[0],1:0).sum.writeln;}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nalias XW = Tuple!(long, \"x\", long, \"w\");\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n XW[] xws;\n foreach (_; 0..N) {\n auto xw = readln.split.to!(long[]);\n xws ~= XW(xw[0], xw[1]);\n }\n sort!\"a.x + a.w < b.x + b.w\"(xws);\n int r;\n long last = long.min;\n foreach (xw; xws) {\n if (last <= xw.x - xw.w) {\n ++r;\n last = xw.x + xw.w;\n }\n }\n writeln(r);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto x = new int [n];\n\t\tauto r = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &x[i], &r[i]);\n\t\t}\n\n\t\talias Pair = Tuple !(int, q{lo}, int, q{hi});\n\t\tPair [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta ~= Pair (x[i] - r[i], x[i] + r[i]);\n\t\t}\n\t\ta.sort !(q{a.hi < b.hi}, SwapStrategy.stable);\n\t\tlong res = 0;\n\t\tint cur = int.min;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tif (cur <= c.lo)\n\t\t\t{\n\t\t\t\tres++;\n\t\t\t\tcur = c.hi;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "c5d15bbebfe57bc7cddb443229fb7d61"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int n, k; get(n, k);\r\n int[] hs; get(hs);\r\n\r\n int p;\r\n while (k--) {\r\n foreach (i, ref h; hs) {\r\n if (i == hs.length - 1) goto ng;\r\n if (h >= hs[i+1]) continue;\r\n p = i.to!int;\r\n ++h;\r\n break;\r\n }\r\n }\r\n writeln(p + 1);\r\n continue;\r\n\r\n ng:\r\n writeln(-1);\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD;\r\n\t\tauto h = RDA;\r\n\t\t\r\n\t\twhile (k > 0)\r\n\t\t{\r\n\t\t\tbool ok;\r\n\t\t\tforeach (i; 0..n-1)\r\n\t\t\t{\r\n\t\t\t\tif (h[i] < h[i+1])\r\n\t\t\t\t{\r\n\t\t\t\t\t--k;\r\n\t\t\t\t\t++h[i];\r\n\t\t\t\t\tans[ti] = i+1;\r\n\t\t\t\t\tok = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (!ok)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = -1;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nlong solve (int n, int k, int [] h)\r\n{\r\n\twhile (true)\r\n\t{\r\n\t\tint i = 0;\r\n\t\twhile (i < n - 1 && h[i + 1] <= h[i])\r\n\t\t{\r\n\t\t\ti += 1;\r\n\t\t}\r\n\t\tif (i == n - 1)\r\n\t\t{\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\th[i] += 1;\r\n\t\tk -= 1;\r\n\t\tif (k <= 0)\r\n\t\t{\r\n\t\t\treturn i + 1;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto h = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (n, k, h));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD;\r\n\t\tauto h = RDA;\r\n\r\n\t\tans[ti] = -1;\r\n\t\tlong[][] s;\r\n\t\t(){\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (s.empty)\r\n\t\t\t\ts ~= [h[i], i];\r\n\t\t\telse if (h[i] <= s[$-1][0])\r\n\t\t\t\ts ~= [h[i], i];\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tauto x = h[i];\r\n\t\t\t\twhile (!s.empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s[$-1][0] > x)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ts ~= [x, s[$-1][1]+1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tauto nd = s.back; s.popBack;\r\n\t\t\t\t\tauto y = nd[0];\r\n\t\t\t\t\tauto p = nd[1];\r\n\t\t\t\t\tk -= (x - y) * (i - p);\r\n\t\t\t\t\tdebug writeln(\"i:\", i, \" p:\", p, \" x:\", x, \" y:\", y, \" k:\", k);\r\n\t\t\t\t\tif (k <= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdebug writeln(\"i:\", i, \" p:\", p, \" k:\", k);\r\n\t\t\t\t\t\tans[ti] = p + 1 - k;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}}();\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nlong solve (int n, long k, int [] h)\r\n{\r\n\twhile (true)\r\n\t{\r\n\t\tif (isSorted !(q{a > b}) (h))\r\n\t\t{\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\tint i = 1;\r\n\t\twhile (h[i] <= h[i - 1])\r\n {\r\n \ti += 1;\r\n }\r\n int j = i - 1;\r\n while (j > 0 && h[j - 1] == h[j])\r\n {\r\n \tj -= 1;\r\n }\r\n int len = i - j;\r\n\t\tint cur = h[i] - h[j];\r\n\t\tk -= cur * 1L * (i - j);\r\n\t\tif (k <= 0)\r\n\t\t{\r\n\t\t\treturn i - (k + cur * 1L * (i - j) - 1) % len;\r\n\t\t}\r\n\t\th[j..i] += cur;\r\n\t}\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto h = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (n, k, h));\r\n\t}\r\n}\r\n"}], "src_uid": "32855bb8ba33973178fde7c3d0beb2ce"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto s = [0];\r\n\t\tforeach (ref x; a)\r\n\t\t{\r\n\t\t\ts ~= s.back ^ x;\r\n\t\t}\r\n\r\n\t\tbool [int] v;\r\n\t\tint cur = 0;\r\n\t\tv[cur] = true;\r\n\t\tint res = 0;\r\n\t\tforeach (ref x; a)\r\n\t\t{\r\n\t\t\tif ((x ^ cur) in v)\r\n\t\t\t{\r\n\t\t\t\tv = null;\r\n\t\t\t\tcur = 0;\r\n\t\t\t\tv[cur] = true;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tres += 1;\r\n\t\t\tcur ^= x;\r\n\t\t\tv[cur] = true;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nalias Tuple!(int,int) K;\r\nenum int INF = 1<<29;\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto A = readln.chomp.split(\" \").map!(to!int).array;\r\n\r\n /*\r\n int[K] cache;\r\n int f(int k, int s) {\r\n // turn [k, N) into 0\r\n if (k == N) return 0;\r\n auto key = K(k, s);\r\n if (key in cache) return cache[key];\r\n int ans = int.max;\r\n // don't use s\r\n ans = min(ans, f(k + 1, A[k]) + (A[k] > 0));\r\n // use s\r\n ans = min(ans, f(k + 1, A[k] ^ s) + ((A[k] ^ s) > 0));\r\n return cache[key] = ans;\r\n }\r\n */\r\n\r\n int L = 8191;\r\n auto f = new int[][](N + 1, L + 1);\r\n foreach (ref l; f) l[] = INF;\r\n f[0][0] = 0;\r\n for (int k = 0; k < N; k++) {\r\n for (int s = 0; s <= L; s++) {\r\n // use x = A[k]\r\n f[k + 1][A[k]] = min(f[k + 1][A[k]], f[k][s] + (A[k] > 0));\r\n // use x = A[k] ^ s\r\n int x = A[k] ^ s;\r\n f[k + 1][x] = min(f[k + 1][x], f[k][s] + (x > 0));\r\n }\r\n }\r\n writeln(f[N].reduce!min);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nalias Tuple!(int,int) K;\r\nenum int INF = 1<<29;\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto A = readln.chomp.split(\" \").map!(to!int).array;\r\n\r\n /*\r\n int[K] cache;\r\n int f(int k, int s) {\r\n // turn [k, N) into 0\r\n if (k == N) return 0;\r\n auto key = K(k, s);\r\n if (key in cache) return cache[key];\r\n int ans = int.max;\r\n // don't use s\r\n ans = min(ans, f(k + 1, A[k]) + (A[k] > 0));\r\n // use s\r\n ans = min(ans, f(k + 1, A[k] ^ s) + ((A[k] ^ s) > 0));\r\n return cache[key] = ans;\r\n }\r\n */\r\n\r\n int L = 8191;\r\n auto f = new int[][](N + 1, L + 1);\r\n foreach (ref l; f) l[] = INF;\r\n f[0][] = 0;\r\n for (int k = 0; k < N; k++) {\r\n for (int s = 0; s <= L; s++) {\r\n // use x = A[k]\r\n f[k + 1][A[k]] = min(f[k + 1][A[k]], f[k][s] + (A[k] > 0));\r\n // use x = A[k] ^ s\r\n int x = A[k] ^ s;\r\n f[k + 1][x] = min(f[k + 1][x], f[k][s] + (x > 0));\r\n }\r\n }\r\n writeln(f[N].reduce!min);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint cur = 0;\r\n\t\tint res = 0;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tif (c == 0)\r\n\t\t\t{\r\n\t\t\t\tcur = 0;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tres += 1;\r\n\t\t\tcur ^= c;\r\n\t\t\tif (cur == 0)\r\n\t\t\t{\r\n\t\t\t\tres -= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "src_uid": "4d9b6b5eb97c14bfa433efa11af0e5c8"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tbool s = false;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tint t;\n\t\t\t\tscanf (\" %d\", &t);\n\t\t\t\tif (i == j)\n\t\t\t\t{\n\t\t\t\t\tif (t)\n\t\t\t\t\t{\n\t\t\t\t\t\ts ^= true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint q;\n\t\tscanf (\" %d\", &q);\n\t\tstring res;\n\t\tforeach (k; 0..q)\n\t\t{\n\t\t\tint t, i;\n\t\t\tscanf (\" %d\", &t);\n\t\t\tswitch (t)\n\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\tcase 2:\n\t\t\t\t\tscanf (\" %d\", &i);\n\t\t\t\t\ts ^= true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 3:\n\t\t\t\t\tres ~= s ? '1' : '0';\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "/// https://codeforces.com/contest/405/problem/C\n/// PS> dmd cf.d; if($?) {cat in.txt | .\\cf.exe}\nimport std.stdio : stdin, write, writeln;\n\nvoid main()\n{\n int n, q, sum = 0;\n stdin.readf!\"%d\\n\"(n);\n\n for (int i=0; i<n; i++)\n sum += stdin.readln()[i << 1];\n\n stdin.readf!\"%d\\n\"(q);\n for (int i=0; i<q; i++) {\n int cmd = stdin.readln()[0];\n if (cmd == '3')\n write(sum & 1);\n else\n sum++;\n }\n writeln();\n}"}, {"source_code": "/// https://codeforces.com/contest/405/problem/C\n/// PS> dmd cf.d; if($?) {cat in.txt | .\\cf.exe}\nimport std.stdio : stdin, writeln;\n\nvoid main()\n{\n int n, q, sum = 0;\n stdin.readf!\"%d\\n\"(n);\n\n for (int i=0; i<n<<1; i+=2)\n sum += stdin.readln()[i];\n stdin.readf!\"%d\\n\"(q);\n\n char[] res; res.reserve(q);\n for (int i=0; i<q; i++)\n if (stdin.readln()[0] == '3')\n res ~= '0' + (sum & 1);\n else\n sum++;\n writeln(res);\n}"}], "negative_code": [], "src_uid": "332902284154faeaf06d5d05455b7eb6"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport core.stdc.stdio;\nimport std.algorithm;\n\nint main()\n{\n int n = readInt!int;\n auto a = new long[](n);\n foreach(ref ai; a) ai = readInt!long;\n int pos = cast(int) a.count!(ai => ai >= 0);\n long[][] maxSum = new long[][](n + 1, n + 1);\n maxSum[0][0] = (a[0] < 0)? 0 : a[0];\n foreach(i; 1 .. n)\n {\n maxSum[i][0] = (a[i] < 0)? maxSum[i-1][0] : (maxSum[i-1][0] + a[i]);\n }\n foreach(p; 1 .. n)\n {\n foreach(i; 0 .. n)\n {\n if (a[i] < 0)\n {\n if (i == 0)\n {\n maxSum[i][p] = -1;\n }\n else\n {\n maxSum[i][p] = max(maxSum[i-1][p], maxSum[i-1][p-1] + a[i]);\n }\n }\n else\n {\n if (i == 0)\n {\n maxSum[i][p] = -1;\n }\n else\n {\n maxSum[i][p] = (maxSum[i-1][p] >= 0)? (maxSum[i-1][p] + a[i]) : maxSum[i-1][p];\n }\n }\n }\n }\n int p = 0;\n while (p + 1 < n && maxSum[n-1][p + 1] >= 0)\n {\n p++;\n }\n writeln(pos + p);\n return 0;\n}\n\n\n\n\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv;\r\nimport std.string, std.array;\r\nimport std.typecons, std.range;\r\nimport std.math, std.algorithm;\r\n \r\nint solve(int[] a)\r\n{\r\n auto n = to!int(a.length);\r\n auto pdp = new long[n + 1];\r\n auto ndp = new long[n + 1];\r\n fill(pdp, -1);\r\n pdp[0] = 0;\r\n foreach (i; 0 .. n)\r\n {\r\n ndp[0] = pdp[0];\r\n foreach (j; 1 .. i + 2)\r\n {\r\n ndp[j] = pdp[j];\r\n if (pdp[j - 1] >= 0 && pdp[j - 1] + a[i] >= 0)\r\n {\r\n ndp[j] = max(ndp[j], pdp[j - 1] + a[i]);\r\n }\r\n }\r\n ndp[0 .. i + 2].copy(pdp);\r\n }\r\n auto res = 0;\r\n foreach_reverse (i; 0 .. n + 1) if (pdp[i] >= 0)\r\n {\r\n res = i;\r\n break;\r\n }\r\n return res;\r\n}\r\n \r\nint main(string[] args)\r\n{\r\n readln;\r\n auto a = map!(to!int)(readln.strip.split(\" \")).array;\r\n auto ret = solve(a);\r\n writeln(ret);\r\n return 0;\r\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport core.stdc.stdio;\nimport std.algorithm;\n\nint main()\n{\n int n = readInt!int;\n auto a = new int[](n);\n foreach(ref ai; a) ai = readInt!int;\n int pos = cast(int) a.count!(ai => ai >= 0);\n int[][] maxSum = new int[][](n + 1, n + 1);\n maxSum[0][0] = (a[0] < 0)? 0 : a[0];\n foreach(i; 1 .. n)\n {\n maxSum[i][0] = (a[i] < 0)? maxSum[i-1][0] : (maxSum[i-1][0] + a[i]);\n }\n foreach(p; 1 .. n)\n {\n foreach(i; 0 .. n)\n {\n if (a[i] < 0)\n {\n if (i == 0)\n {\n maxSum[i][p] = a[i];\n }\n else\n {\n maxSum[i][p] = max(maxSum[i-1][p], maxSum[i-1][p-1] + a[i]);\n }\n }\n else\n {\n if (i == 0)\n {\n maxSum[i][p] = -1;\n }\n else\n {\n maxSum[i][p] = (maxSum[i-1][p] >= 0)? (maxSum[i-1][p] + a[i]) : maxSum[i-1][p];\n }\n }\n }\n }\n int p = 0;\n while (p + 1 < n && maxSum[n-1][p + 1] >= 0)\n {\n p++;\n }\n writeln(pos + p);\n return 0;\n}\n\n\n\n\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n"}], "src_uid": "affef141c51bbfd881a90d49ec34ceea"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bigint;\nimport std.conv;\nimport std.numeric;\nimport std.stdio;\nimport std.string;\n\nimmutable int BASE = 10;\nimmutable int MOD = 1_000_000_007;\nimmutable int NA = -1;\n\nstruct ModInt\n{\n\tint contents;\n//\talias contents this;\n\n\tinvariant\n\t{\n\t\tassert (0 <= contents && contents < MOD);\n\t}\n\n\tthis (int newContents)\n\tin\n\t{\n\t\tassert (0 <= newContents && newContents < MOD);\n\t}\n\tbody\n\t{\n\t\tcontents = newContents;\n\t}\n\n\tref ModInt opOpAssign (string op) (const ModInt rhs)\n\tin\n\t{\n\t\tassert (0 <= rhs.contents && rhs.contents < MOD);\n\t}\n\tbody\n\t{\n\t\tstatic if (op == \"+\")\n\t\t{\n\t\t\tcontents += rhs.contents;\n\t\t\tif (contents >= MOD)\n\t\t\t{\n\t\t\t\tcontents -= MOD;\n\t\t\t}\n\t\t}\n\t\telse static if (op == \"-\")\n\t\t{\n\t\t\tcontents -= rhs.contents;\n\t\t\tif (contents < 0)\n\t\t\t{\n\t\t\t\tcontents += MOD;\n\t\t\t}\n\t\t}\n\t\telse static if (op == \"*\")\n\t\t{\n\t\t\tcontents = (contents * 1L * rhs.contents) % MOD;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tstatic assert (false);\n\t\t}\n\t\treturn this;\n\t}\n\n\tref ModInt opOpAssign (string op) (const int rhs)\n\tin\n\t{\n\t\tassert (0 <= rhs && rhs < MOD);\n\t}\n\tbody\n\t{\n\t\tmixin (q{this } ~ op ~ q{= ModInt (rhs);});\n\t\treturn this;\n\t}\n\n\tModInt opBinary (string op) (const ModInt rhs)\n\tin\n\t{\n\t\tassert (0 <= rhs.contents && rhs.contents < MOD);\n\t}\n\tbody\n\t{\n\t\tModInt res = this;\n\t\tmixin (q{res } ~ op ~ q{= rhs;});\n\t\treturn res;\n\t}\n\n\tModInt opBinary (string op) (const int rhs)\n\tin\n\t{\n\t\tassert (0 <= rhs && rhs < MOD);\n\t}\n\tbody\n\t{\n\t\tModInt res = this;\n\t\tmixin (q{res } ~ op ~ q{= ModInt (rhs);});\n\t\treturn res;\n\t}\n\n\tstring toString () const\n\t{\n\t\treturn text (contents);\n\t}\n}\n\nvoid main ()\n{\n\tint m, d;\n\twhile (readf (\" %s %s\", &m, &d) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.strip;\n\t\tint n = a.length;\n\t\ta = format (\"%0*d\", n, BigInt (a) - 1);\n\t\tauto b = readln.strip;\n\t\tassert (n == b.length);\n\n\t\tauto fun (string s)\n\t\t{\n\t\t\tauto z = s.map !(x => x - '0').array;\n\t\t\tauto f = new ModInt [] [] (2, m);\n\t\t\tint t = 0;\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tt ^= 1;\n\t\t\t\tf[t][] = ModInt (0);\n\n\t\t\t\tif (cur != NA)\n\t\t\t\t{\n\t\t\t\t\tcur = (cur * BASE) % m;\n\t\t\t\t\tforeach (e; 0..z[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((i & 1) == (e == d))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[t][cur] += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcur = (cur + 1) % m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ((i & 1) != (z[i] == d))\n\t\t\t\t{\n\t\t\t\t\tcur = NA;\n\t\t\t\t}\n\n\t\t\t\tforeach (r; 0..m)\n\t\t\t\t{\n\t\t\t\t\tint nr = (r * BASE) % m;\n\t\t\t\t\tforeach (e; 0..BASE)\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((i & 1) == (e == d))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[t][nr] += f[!t][r];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnr = (nr + 1) % m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (cur, \" \", f[t]);}\n\t\t\t}\n\n\t\t\tModInt res = (cur == 0);\n\t\t\tres += f[t][0];\n\t\t\treturn res;\n\t\t}\n\n\t\twriteln (fun (b) - fun (a));\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bigint;\nimport std.conv;\nimport std.numeric;\nimport std.stdio;\nimport std.string;\n\nimmutable int BASE = 10;\nimmutable int MOD = 1_000_000_007;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint m, d;\n\twhile (readf (\" %s %s\", &m, &d) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.strip;\n\t\tint n = a.length;\n\t\ta = format (\"%0*d\", n, BigInt (a) - 1);\n\t\tauto b = readln.strip;\n\t\tassert (n == b.length);\n\n\t\tauto fun (string s)\n\t\t{\n\t\t\tauto z = s.map !(x => x - '0').array;\n\t\t\tauto f = new int [] [] (2, m);\n\t\t\tint t = 0;\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tt ^= 1;\n\t\t\t\tf[t][] = 0;\n\n\t\t\t\tif (cur != NA)\n\t\t\t\t{\n\t\t\t\t\tcur = (cur * BASE) % m;\n\t\t\t\t\tforeach (e; 0..z[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((i & 1) == (e == d))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[t][cur] += 1;\n\t\t\t\t\t\t\tif (f[t][cur] >= MOD)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tf[t][cur] -=\n\t\t\t\t\t\t\t\t MOD;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcur = (cur + 1) % m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ((i & 1) != (z[i] == d))\n\t\t\t\t{\n\t\t\t\t\tcur = NA;\n\t\t\t\t}\n\n\t\t\t\tforeach (r; 0..m)\n\t\t\t\t{\n\t\t\t\t\tint nr = (r * BASE) % m;\n\t\t\t\t\tforeach (e; 0..BASE)\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((i & 1) == (e == d))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[t][nr] += f[!t][r];\n\t\t\t\t\t\t\tif (f[t][nr] >= MOD)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tf[t][nr] -=\n\t\t\t\t\t\t\t\t MOD;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnr = (nr + 1) % m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (cur, \" \", f[t]);}\n\t\t\t}\n\n\t\t\tint res = (cur == 0) + f[t][0];\n\t\t\tif (res >= MOD)\n\t\t\t{\n\t\t\t\tres -= MOD;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\twriteln ((fun (b) - fun (a) + MOD) % MOD);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bigint;\nimport std.conv;\nimport std.numeric;\nimport std.stdio;\nimport std.string;\n\nimmutable int BASE = 10;\nimmutable int MOD = 1_000_000_007;\nimmutable int NA = -1;\n\nstruct ModInt\n{\n\tint contents;\n\talias contents this;\n\n\tinvariant\n\t{\n\t\tassert (0 <= contents && contents < MOD);\n\t}\n\n\tthis (int newContents)\n\tin\n\t{\n\t\tassert (0 <= newContents && newContents < MOD);\n\t}\n\tbody\n\t{\n\t\tcontents = newContents;\n\t}\n\n\tref ModInt opOpBinary (string op, T) (const T rhs)\n\tin\n\t{\n\t\tassert (0 <= rhs && rhs < MOD);\n\t}\n\tbody\n\t{\n\t\tstatic if (op == \"+\")\n\t\t{\n\t\t\tcontents += rhs;\n\t\t\tif (contents >= MOD)\n\t\t\t{\n\t\t\t\tcontents -= MOD;\n\t\t\t}\n\t\t}\n\t\telse if (op == \"-\")\n\t\t{\n\t\t\tcontents -= rhs;\n\t\t\tif (contents < 0)\n\t\t\t{\n\t\t\t\tcontents += MOD;\n\t\t\t}\n\t\t}\n\t\telse if (op == \"*\")\n\t\t{\n\t\t\tcontents = (contents * 1L * rhs) % MOD;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tstatic assert (false);\n\t\t}\n\t\treturn this;\n\t}\n\n\tModInt opBinary (string op, T) (const T rhs)\n\tin\n\t{\n\t\tassert (0 <= rhs && rhs < MOD);\n\t}\n\tbody\n\t{\n\t\tModInt res = this;\n\t\tmixin (q{res} ~ op ~ q{= rhs;});\n\t\treturn res;\n\t}\n}\n\nvoid main ()\n{\n\tint m, d;\n\twhile (readf (\" %s %s\", &m, &d) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.strip;\n\t\tint n = a.length;\n\t\ta = format (\"%0*d\", n, BigInt (a) - 1);\n\t\tauto b = readln.strip;\n\t\tassert (n == b.length);\n\n\t\tauto fun (string s)\n\t\t{\n\t\t\tauto z = s.map !(x => x - '0').array;\n\t\t\tauto f = new ModInt [] [] (2, m);\n\t\t\tint t = 0;\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tt ^= 1;\n\t\t\t\tf[t][] = ModInt (0);\n\n\t\t\t\tif (cur != NA)\n\t\t\t\t{\n\t\t\t\t\tcur = (cur * BASE) % m;\n\t\t\t\t\tforeach (e; 0..z[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((i & 1) == (e == d))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[t][cur] += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcur = (cur + 1) % m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ((i & 1) != (z[i] == d))\n\t\t\t\t{\n\t\t\t\t\tcur = NA;\n\t\t\t\t}\n\n\t\t\t\tforeach (r; 0..m)\n\t\t\t\t{\n\t\t\t\t\tint nr = (r * BASE) % m;\n\t\t\t\t\tforeach (e; 0..BASE)\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((i & 1) == (e == d))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[t][nr] += f[!t][r];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnr = (nr + 1) % m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (cur, \" \", f[t]);}\n\t\t\t}\n\n\t\t\tModInt res = (cur == 0);\n\t\t\tres += f[t][0];\n\t\t\treturn res;\n\t\t}\n\n\t\twriteln (fun (b) - fun (a));\n\t}\n}\n"}], "src_uid": "19564d66e0de78780f4a61c69f2c8e27"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong solve(long l, long a, long b)\n{\n if (l == 0)\n return 0;\n long x1 = (a + b) * l;\n long x2 = b + l * a;\n return max(x1, x2);\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n, a, b;\n readf!\" %d %d %d \"(n, a, b);\n auto s = readln.strip.split(\"\").map!(to!int).array;\n long l = 1;\n int i = 1;\n int prev = s[0];\n long[] x;\n long result = 0;\n while (i < n) {\n while (i < n && s[i] == prev) {\n l++;\n i++;\n }\n x ~= l;\n l = 0;\n prev = !prev;\n }\n if (l != 0)\n x ~= l;\n long firstodd = 0;\n long sumodd = 0;\n long firsteven = 0;\n long sumeven = 0;\n foreach (j ; 0 .. x.length) {\n if (j % 2 == 1) {\n firstodd += solve(x[j], a, b);\n sumodd += x[j];\n } else {\n firsteven += solve(x[j], a, b);\n sumeven += x[j];\n }\n }\n firstodd += solve(sumeven, a, b);\n firsteven += solve(sumodd, a, b);\n// writeln(firstodd);\n// writeln(firsteven);\n writeln(max(firstodd, firsteven));\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\t\tauto s = RD!string;\r\n\t\t\r\n\t\tif (b >= 0)\r\n\t\t\tans[ti] = (a+b) * n;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 1..n)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] != s[i-1])\r\n\t\t\t\t\t++cnt;\r\n\t\t\t}\r\n\t\t\tcnt = (cnt+1) / 2 + 1;\r\n\r\n\t\t\tans[ti] = a * n + b * cnt;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong solve(long l, long a, long b)\n{\n long x1 = (a + b) * l;\n long x2 = b + l * a;\n return max(x1, x2);\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n, a, b;\n readf!\" %d %d %d \"(n, a, b);\n auto s = readln.strip.split(\"\").map!(to!int).array;\n long l = 1;\n int i = 1;\n int prev = s[0];\n long[] x;\n long result = 0;\n while (i < n) {\n while (i < n && s[i] == prev) {\n l++;\n i++;\n }\n x ~= l;\n l = 0;\n prev = !prev;\n }\n if (l != 0)\n x ~= l;\n// writeln(x);\n long firstodd = 0;\n long sumodd = 0;\n long firsteven = 0;\n long sumeven = 0;\n foreach (j ; 0 .. x.length) {\n if (j % 2 == 1) {\n firstodd += solve(x[j], a, b);\n sumodd += x[j];\n } else {\n firsteven += solve(x[j], a, b);\n sumeven += x[j];\n }\n }\n firstodd += solve(sumeven, a, b);\n firsteven += solve(sumodd, a, b);\n// writeln(firstodd);\n// writeln(firsteven);\n writeln(max(firstodd, firsteven));\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong solve(long l, long a, long b)\n{\n long x1 = (a + b) * l;\n long x2 = b + l * a;\n return max(x1, x2);\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n, a, b;\n readf!\" %d %d %d \"(n, a, b);\n auto s = readln.strip.split(\"\").map!(to!int).array;\n long l = 1;\n int i = 1;\n int prev = s[0];\n long[] x;\n long result = 0;\n while (i < n) {\n while (i < n && s[i] == prev) {\n l++;\n i++;\n }\n x ~= l;\n l = 0;\n prev = !prev;\n }\n long firstodd = 0;\n long sumodd = 0;\n long firsteven = 0;\n long sumeven = 0;\n foreach (j ; 0 .. x.length) {\n if (j % 2 == 1) {\n firstodd += solve(x[j], a, b);\n sumodd += x[j];\n } else {\n firsteven += solve(x[j], a, b);\n sumeven += x[j];\n }\n }\n firstodd += solve(sumeven, a, b);\n firsteven += solve(sumodd, a, b);\n writeln(max(firstodd, firsteven));\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\t\tauto s = RD!string;\r\n\t\t\r\n\t\tif (b >= 0)\r\n\t\t\tans[ti] = (a+b) * n;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 1..n)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] != s[i-1])\r\n\t\t\t\t\t++cnt;\r\n\t\t\t}\r\n\t\t\tif (cnt <= 1)\r\n\t\t\t\t++cnt;\r\n\r\n\t\t\tans[ti] = a * n + b * cnt;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\t\tauto s = RD!string;\r\n\t\t\r\n\t\tif (b >= 0)\r\n\t\t\tans[ti] = (a+b) * n;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 1..n)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] != s[i-1])\r\n\t\t\t\t\t++cnt;\r\n\t\t\t}\r\n\t\t\tcnt.chmax(1);\r\n\r\n\t\t\tans[ti] = a * n + b * cnt;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "93fb13c40ab03700ef9a827796bd3d9d"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\treal [] m;\n\t\tm ~= 1;\n\t\treal res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto command = readln.split;\n\t\t\tif (command[0] == \"add\")\n\t\t\t{\n\t\t\t\tres += m.back;\n\t\t\t}\n\t\t\telse if (command[0] == \"for\")\n\t\t\t{\n\t\t\t\tm ~= m.back * command[1].to !(int);\n\t\t\t}\n\t\t\telse if (command[0] == \"end\")\n\t\t\t{\n\t\t\t\tm.popBack ();\n\t\t\t\tm.assumeSafeAppend ();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n }\n\t\t}\n\t\tif (res >= (1L << 32))\n\t\t{\n\t\t\twriteln (\"OVERFLOW!!!\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"%.0f\", res);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nalias T = Tuple!(int, ulong);\n\nvoid overflow () {\n writeln (\"OVERFLOW!!!\");\n}\n\nvoid main() {\n string s;\n readf!\" %s\" (s);\n auto z = s.splitter;\n string rs () {\n auto r = z.front;\n z.popFront ();\n return r;\n }\n immutable ulong m = 1L << 32;\n\n immutable l = rs().strip().to!int;\n auto st = new T[5 * l];\n int k;\n foreach (qid; 0 .. l) {\n auto t = rs ();\n if (t[0] == 'a') {\n st[k++] = tuple (1, 1);\n } else if (t[0] == 'f') {\n st[k++] = tuple (2, rs().strip().to!ulong);\n } else if (t[0] == 'e') {\n ulong x;\n while (st[k-1][0] != 2) {\n x += st[k-1][1];\n if (x >= m) {\n overflow ();\n return;\n }\n --k;\n }\n x *= st[k-1][1];\n if (x >= m) {\n overflow ();\n return;\n }\n st[k-1] = tuple (1, x);\n }\n }\n ulong y;\n foreach (i; 0 .. k) {\n y += st[i][1];\n if (y >= m) {\n overflow ();\n return;\n }\n }\n writeln (y);\n}\n\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\t\n\tint l = read.to!int;\n\t\n\tlong infty = 1L<<32;\n\t\n\tlong[] depths = [1];\n\tlong ans;\n\tforeach(_; 0 .. l){\n\t\t\n\t\tstring cmd = read;\n\t\tif(cmd == \"for\"){\n\t\t\tlong val = read.to!long;\n\t\t\tlong d = depths[$ - 1] * val;\n\t\t\tif(d >= infty) d = infty;\n\t\t\t\n\t\t\tdepths ~= d;\n\t\t}\n\t\telse if(cmd == \"add\"){\n\t\t\tlong d = depths[$ - 1];\n\t\t\tans += d;\n\t\t\tif(ans >= infty){\n\t\t\t\t\"OVERFLOW!!!\".writeln;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\telse if(cmd == \"end\"){\n\t\t\tdepths.length -= 1;\n\t\t}\n\t\t\n\t}\n\tans.writeln;\n}\n"}, {"source_code": "import std.typecons;\n\nimport core.stdc.stdio : scanf;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.bigint;\n\nalias PII = Tuple!(int, int);\nalias PLL = Tuple!(long, long);\n\nvoid main() {\n\n long n;\n\n scanf(\"%d\\n\", &n);\n\n long x = 0;\n\n long[] stack;\n\n stack ~= 1L;\n\n long INF = (1L << 32);\n\n foreach (cmd; 0 .. n) {\n char[100] c;\n scanf(\"%s\", &c);\n if (c[0] == 'a') {\n x = x + stack.back;\n if (x >= INF) {\n writeln(\"OVERFLOW!!!\");\n return;\n }\n }\n\n if (c[0] == 'f') {\n long tt;\n scanf(\"%lld\\n\", &tt);\n stack ~= stack.back * tt;\n if (stack.back >= INF)\n stack.back = INF;\n\n }\n\n if (c[0] == 'e') {\n stack.popBack();\n }\n }\n\n writeln(x);\n}\n"}], "negative_code": [{"source_code": "import std.typecons;\n\n// import core.stdc.stdio;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.bigint;\n\nalias PII = Tuple!(int, int);\nalias PLL = Tuple!(long, long);\n\nvoid main() {\n\n long n;\n\n stdin.readf(\"%d\", n);\n\n BigInt x;\n\n BigInt[] stack;\n\n stack ~= BigInt(1);\n\n foreach (cmd; 0 .. n) {\n string c = stdin.readln();\n if (c[0] == 'a') {\n x = x + stack.back;\n if (x > (1L << 32) - 1) {\n writeln(\"OVERFLOW!!!\");\n return;\n }\n }\n\n if (c[0] == 'f') {\n auto t = BigInt(c.split[1]);\n // writeln(t);\n stack ~= stack.back * t;\n }\n\n if (c[0] == 'e') {\n stack.popBack();\n }\n }\n\n writeln(x);\n}\n"}], "src_uid": "70f67dc28f9f6076255df97fc58ba2d6"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\n\nvoid main() {\n auto s = readln.split.map!(to!long);\n auto R = s[0];\n auto D = s[1];\n auto C = R - D;\n auto N = readln.chomp.to!int;\n\n bool ok1(long x, long y, long r) {\n return x * x + y * y >= (r + C) * (r + C);\n }\n\n bool ok2(long x, long y, long r) {\n return x * x + y * y <= (r - R) * (r - R);\n }\n\n int ans = 0;\n while (N--) {\n s = readln.split.map!(to!long);\n auto x = s[0];\n auto y = s[1];\n auto r = s[2];\n ans += ok1(x, y, r) && ok2(x, y, r);\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.array : split;\nimport std.string : chomp;\nimport std.conv : to;\nimport std.math : sqrt;\n\nauto gets() { return readln.chomp; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n auto rd = getVals!double;\n auto r = rd[0], d = rd[1];\n auto n = gets.to!int;\n auto ans = 0;\n for (auto i = 0; i < n; i++) {\n auto xyr = getVals!double;\n auto xi = xyr[0], yi = xyr[1], ri = xyr[2];\n auto di = sqrt(xi * xi + yi * yi);\n if (di + ri <= r && di - ri >= r - d) {\n ans++;\n }\n }\n writeln(ans);\n}"}], "negative_code": [], "src_uid": "fce9d78ad7d4ea01be1704f588e42d37"} {"source_code": "import std;\r\n\r\nint t,n;\r\nuint k;\r\nstatic const uint N = 500007;\r\n\r\nstruct node {\r\n uint l, r, id;\r\n int opCmp(ref const node rhs) const {\r\n if (r == rhs.r)\r\n return l > rhs.l ? -1 : 1;\r\n return r < rhs.r ? -1 : 1;\r\n }\r\n}\r\n\r\nnode[N] q;\r\nuint[N] a, ans, f;\r\nbool[N] st;\r\n\r\nuint find(uint x) {\r\n if (x == f[x])\r\n return f[x];\r\n return f[x] = find(f[x]);\r\n}\r\n\r\nvoid main()\r\n{\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n scanf(\"%d\", &n);\r\n getchar();\r\n foreach(i; 1 .. (n + 1)) {\r\n f[i] = i;\r\n st[i] = false;\r\n scanf(\"%u\", &k);\r\n a[i] = k;\r\n }\r\n foreach(i; 1 .. (n + 1)) {\r\n if (a[i] == 0)\r\n q[i] = node(i+1,n,i);\r\n else\r\n q[i] = node(i/(a[i]+1)+1,i/a[i],i);\r\n }\r\n sort!\"a < b\"(q[1..n+1]).array;\r\n foreach(i;1 .. (n + 1)) {\r\n uint l = find(q[i].l);\r\n while(st[l]) {\r\n f[l] = find(l + 1);\r\n l = find(q[i].l);\r\n }\r\n ans[q[i].id] = l;\r\n st[l] = true;\r\n }\r\n writefln(\"%(%s %)\", ans[1..n+1]);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std;\r\n\r\nint t,n;\r\nuint k;\r\nstatic const uint N = 500007;\r\n\r\nstruct node {\r\n uint l, r, id;\r\n int opCmp(ref const node rhs) const {\r\n if (r == rhs.r)\r\n return l > rhs.l ? -1 : 1;\r\n return r < rhs.r ? -1 : 1;\r\n }\r\n}\r\n\r\nnode[N] q;\r\nuint[N] a, ans, f;\r\nbool[N] st;\r\n\r\nuint find(uint x) {\r\n if (x == f[x])\r\n return f[x];\r\n return f[x] = find(f[x]);\r\n}\r\n\r\nvoid main()\r\n{\r\n import core.stdc.stdio;\r\n\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n scanf(\"%d\", &n);\r\n getchar();\r\n foreach(i; 1 .. (n + 1)) {\r\n f[i] = i;\r\n st[i] = false;\r\n scanf(\"%u\", &k);\r\n a[i] = k;\r\n }\r\n foreach(i; 1 .. (n + 1)) {\r\n if (a[i] == 0)\r\n q[i] = node(i+1,n,i);\r\n else\r\n q[i] = node(i/(a[i]+1)+1,i/a[i],i);\r\n }\r\n sort!\"a < b\"(q[1..n+1]).array;\r\n foreach(i;1 .. (n + 1)) {\r\n uint l = find(q[i].l);\r\n while(st[l]) {\r\n f[l] = find(l + 1);\r\n l = find(q[i].l);\r\n }\r\n ans[q[i].id] = l;\r\n st[l] = true;\r\n }\r\n for(int i = 1;i<=n;i++)\r\n printf(\"%d \", ans[i]);\r\n printf(\"\\n\");\r\n //writefln(\"%(%s %)\", ans[1..n+1]);\r\n }\r\n}\r\n"}, {"source_code": "import std;\r\n\r\nint t,n;\r\nuint k;\r\nstatic const uint N = 500007;\r\n\r\nstruct node {\r\n uint l, r, id;\r\n int opCmp(ref const node rhs) const {\r\n if (r == rhs.r)\r\n return l > rhs.l ? -1 : 1;\r\n return r < rhs.r ? -1 : 1;\r\n }\r\n}\r\n\r\nnode[N] q;\r\nuint[N] a, ans, f;\r\nbool[N] st;\r\n\r\nuint find(uint x) {\r\n if (x == f[x])\r\n return f[x];\r\n return f[x] = find(f[x]);\r\n}\r\n\r\nvoid main()\r\n{\r\n import std.outbuffer: OutBuffer;\r\n\r\n OutBuffer buf = new OutBuffer();\r\n\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n scanf(\"%d\", &n);\r\n getchar();\r\n foreach(i; 1 .. (n + 1)) {\r\n f[i] = i;\r\n st[i] = false;\r\n scanf(\"%u\", &k);\r\n a[i] = k;\r\n }\r\n foreach(i; 1 .. (n + 1)) {\r\n if (a[i] == 0)\r\n q[i] = node(i+1,n,i);\r\n else\r\n q[i] = node(i/(a[i]+1)+1,i/a[i],i);\r\n }\r\n sort!\"a < b\"(q[1..n+1]).array;\r\n foreach(i;1 .. (n + 1)) {\r\n uint l = find(q[i].l);\r\n while(st[l]) {\r\n f[l] = find(l + 1);\r\n l = find(q[i].l);\r\n }\r\n ans[q[i].id] = l;\r\n st[l] = true;\r\n }\r\n buf.writefln(\"%(%s %)\", ans[1..n+1]);\r\n }\r\n write(buf.toString());\r\n}\r\n"}], "negative_code": [{"source_code": "import std;\r\n\r\nint t,n;\r\nuint k;\r\nstatic const uint N = 500007;\r\n\r\nstruct node {\r\n uint l, r, id;\r\n bool opCmp(node rhs) const {\r\n if (r == rhs.r)\r\n return l > rhs.l;\r\n return r < rhs.r;\r\n }\r\n}\r\n\r\nnode[N] q;\r\nuint[N] a, ans, f;\r\nbool[N] st;\r\n\r\nuint find(uint x) {\r\n if (x == f[x])\r\n return f[x];\r\n f[x] = find(f[x]);\r\n return f[x];\r\n}\r\n\r\nvoid main()\r\n{\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n scanf(\"%d\", &n);\r\n getchar();\r\n foreach(i; 1 .. (n + 1)) {\r\n f[i] = i;\r\n st[i] = false;\r\n scanf(\"%u\", &k);\r\n a[i] = k;\r\n }\r\n foreach(i; 1 .. (n + 1))\r\n if (a[i] == 0L)\r\n q[i] = node(i+1,n,i);\r\n else\r\n q[i] = node(i/(a[i]+1)+1,i/a[i],i);\r\n q[1..n+1].sort();\r\n foreach(i;1 .. (n + 1)) {\r\n uint l = find(q[i].l);\r\n while(st[l]) {\r\n f[l] = find(l + 1);\r\n l = find(q[i].l);\r\n }\r\n ans[q[i].id] = l;\r\n st[l] = true;\r\n }\r\n writefln(\"%(%s %)\", ans[1..n+1]);\r\n }\r\n}\r\n"}], "src_uid": "5481863fd03c37cdcb7d6ee40f973cb9"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\n\nint n;\nint[] a;\n\nvoid main() {\n scan(n);\n a = readln.split.to!(int[]);\n\n int[] leftmin = new int[](n);\n auto st = Stack!int(n + 10);\n\n foreach (i ; 0 .. n) {\n while (!st.empty && a[st.top] > a[i]) st.pop;\n\n leftmin[i] = (st.empty ? -1 : st.top);\n st.push(i);\n }\n\n st.clear;\n\n int[] rightmin = new int[](n);\n\n foreach_reverse (i ; 0 .. n) {\n while (!st.empty && a[st.top] >= a[i]) st.pop;\n\n rightmin[i] = (st.empty ? n : st.top);\n st.push(i);\n }\n\n st.clear;\n\n int[] leftmax = new int[](n);\n\n foreach (i ; 0 .. n) {\n while (!st.empty && a[st.top] < a[i]) st.pop;\n\n leftmax[i] = (st.empty ? -1 : st.top);\n st.push(i);\n }\n\n st.clear;\n\n int[] rightmax = new int[](n);\n\n foreach_reverse (i ; 0 .. n) {\n while (!st.empty && a[st.top] <= a[i]) st.pop;\n\n rightmax[i] = (st.empty ? n : st.top);\n st.push(i);\n }\n\n long ans;\n\n foreach (i ; 0 .. n) {\n ans += 1L * (i - leftmax[i]) * (rightmax[i] - i) * a[i];\n ans -= 1L * (i - leftmin[i]) * (rightmin[i] - i) * a[i];\n }\n\n writeln(ans);\n}\n\nvoid scan(T...)(ref T args) {\n auto line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n assert(line.empty);\n}\n\nstruct Stack(T) {\nprivate:\n int N, peek;\n T[] data;\n\npublic:\n this(int size) \n {\n N = size;\n data = new T[](N);\n }\n\n bool empty() @property\n {\n return peek == 0;\n }\n\n bool full() @property\n {\n return peek == N;\n }\n\n void push(T x) @property\n {\n assert(!full);\n data[peek++] = x;\n }\n\n void pop() @property\n {\n assert(!empty);\n --peek;\n }\n\n T top() @property\n {\n return data[peek - 1];\n }\n\n void clear() @property\n {\n peek = 0;\n }\n\n int length() @property\n {\n return peek;\n }\n\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math;\n\nimmutable int mod = 10^^9 + 7;\n\nint n;\nint[] a;\n\nvoid main() {\n n = readln.chomp.to!int;\n a = readln.split.to!(int[]);\n\n auto leftmin = new int[](n);\n auto rightmin = new int[](n);\n auto stack = new Stack!int(n + 10);\n\n //debug stack.empty.writeln;\n\n foreach (i ; 0 .. n) {\n while (!stack.empty && a[stack.top] > a[i]) {\n //debug {writeln(\"i:\", i, \" \", \"stack top:\", stack.front);}\n stack.pop;\n }\n\n if (stack.empty) {\n leftmin[i] = -1;\n }\n else {\n //debug {writeln(\"i:\", i, \" \", \"stack top:\", stack.front);}\n leftmin[i] = stack.top;\n }\n\n debug {\n //writeln(\"leftmin:\", leftmin);\n }\n stack.push(i);\n }\n\n stack.clear;\n //debug stack.empty.writeln;\n\n foreach_reverse (i ; 0 .. n) {\n while (!stack.empty && a[stack.top] >= a[i]) {\n stack.pop;\n }\n\n if (stack.empty) rightmin[i] = n;\n else rightmin[i] = stack.top;\n\n stack.push(i);\n }\n\n stack.clear;\n\n debug {\n writeln(\"leftmin:\", leftmin);\n writeln(\"rightmin\", rightmin);\n }\n\n auto leftmax = new int[](n);\n auto rightmax = new int[](n);\n stack.clear;\n\n foreach (i ; 0 .. n) {\n while (!stack.empty && a[stack.top] < a[i]) stack.pop;\n\n leftmax[i] = (stack.empty ? -1 : stack.top);\n stack.push(i);\n }\n\n stack.clear;\n\n foreach_reverse (i ; 0 .. n) {\n while (!stack.empty && a[stack.top] <= a[i]) stack.pop;\n\n rightmax[i] = (stack.empty ? n : stack.top);\n stack.push(i);\n }\n\n debug {\n writeln(\"leftmax:\", leftmax);\n writeln(\"rightmax:\", rightmax);\n }\n\n long ans, v;\n\n foreach (i ; 0 .. n) {\n v = (i - leftmin[i]).to!long * (rightmin[i] - i) * a[i];\n ans -= v;\n v = (i - leftmax[i]).to!long * (rightmax[i] - i) * a[i];\n ans += v;\n }\n\n writeln(ans);\n}\n\nclass Stack(T) {\n private:\n int N, peek;\n T[] data;\n\n public:\n this(int size) {\n N = size;\n data = new T[](N);\n }\n\n bool empty() @property {\n return peek == 0;\n }\n\n bool full() @property {\n return peek == N;\n }\n\n void push(T x) {\n if (full) throw new Exception(\"Stack is Full.\");\n data[peek++] = x;\n }\n\n void pop() @property {\n if (empty) throw new Exception(\"Stack is Empty.\");\n --peek;\n }\n\n T top() @property {\n if (empty) throw new Exception(\"Stack is Empty.\");\n return data[peek - 1];\n }\n\n void clear() @property\n {\n peek = 0;\n }\n}\n\nunittest {\n auto st = new Stack!int(5);\n assert(st.empty);\n st.push(3);\n st.push(1);\n st.push(4);\n st.push(1);\n st.push(5);\n assert(st.full);\n assert(st.top == 5);\n st.pop;\n assert(st.top == 1);\n st.pop;\n assert(st.top == 4);\n st.pop;\n st.pop;\n assert(st.top == 3);\n st.pop;\n assert(st.empty);\n\n st.push(3);\n st.push(5);\n st.push(100);\n\n assert(!st.empty);\n\n st.clear;\n\n assert(st.empty);\n\n st.push(5);\n st.push(1);\n\n assert(st.top == 1);\n st.pop;\n assert(st.top == 5);\n st.pop;\n\n assert(st.empty);\n\n stderr.writeln(\"Unittest has passed.\");\n}\n\n\n\nvoid readVariables(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg ; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if (!line.empty) {\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math;\n\nimmutable int mod = 10^^9 + 7;\n\nint n;\nint[] a;\n\nvoid main() {\n n = readln.chomp.to!int;\n a = readln.split.to!(int[]);\n\n auto leftmin = new int[](n);\n auto rightmin = new int[](n);\n auto stack = new SList!(int)();\n\n //debug stack.empty.writeln;\n\n foreach (i ; 0 .. n) {\n while (!stack.empty && a[stack.front] > a[i]) {\n //debug {writeln(\"i:\", i, \" \", \"stack top:\", stack.front);}\n stack.removeFront;\n }\n\n if (stack.empty) {\n leftmin[i] = -1;\n }\n else {\n //debug {writeln(\"i:\", i, \" \", \"stack top:\", stack.front);}\n leftmin[i] = stack.front;\n }\n\n debug {\n //writeln(\"leftmin:\", leftmin);\n }\n stack.insert(i);\n }\n\n stack.clear;\n //debug stack.empty.writeln;\n\n foreach_reverse (i ; 0 .. n) {\n while (!stack.empty && a[stack.front] >= a[i]) {\n stack.removeFront;\n }\n\n if (stack.empty) rightmin[i] = n;\n else rightmin[i] = stack.front;\n\n stack.insert(i);\n }\n\n stack.clear;\n\n debug {\n writeln(\"leftmin:\", leftmin);\n writeln(\"rightmin\", rightmin);\n }\n\n auto leftmax = new int[](n);\n auto rightmax = new int[](n);\n stack.clear;\n\n foreach (i ; 0 .. n) {\n while (!stack.empty && a[stack.front] < a[i]) stack.removeFront;\n\n leftmax[i] = (stack.empty ? -1 : stack.front);\n stack.insert(i);\n }\n\n stack.clear;\n\n foreach_reverse (i ; 0 .. n) {\n while (!stack.empty && a[stack.front] <= a[i]) stack.removeFront;\n\n rightmax[i] = (stack.empty ? n : stack.front);\n stack.insert(i);\n }\n\n debug {\n writeln(\"leftmax:\", leftmax);\n writeln(\"rightmax:\", rightmax);\n }\n\n long ans, v;\n\n foreach (i ; 0 .. n) {\n v = (i - leftmin[i]).to!long * (rightmin[i] - i) * a[i];\n ans -= v;\n v = (i - leftmax[i]).to!long * (rightmax[i] - i) * a[i];\n ans += v;\n }\n\n writeln(ans);\n}\n\n\nvoid readVariables(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg ; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if (!line.empty) {\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math;\n\nimmutable int mod = 10^^9 + 7;\n\nint n;\nint[] a;\n\nvoid main() {\n n = readln.chomp.to!int;\n a = readln.split.to!(int[]);\n\n Stack!int st = Stack!int(n + 10);\n\n auto leftmin = new int[](n);\n\n foreach (i ; 0 .. n) {\n while (!st.empty && a[st.top] > a[i]) st.pop;\n\n leftmin[i] = (st.empty ? -1 : st.top);\n st.push(i);\n }\n\n st.clear;\n\n auto rightmin = new int[](n);\n\n foreach_reverse (i ; 0 .. n) {\n while (!st.empty && a[st.top] >= a[i]) st.pop;\n\n rightmin[i] = (st.empty ? n : st.top);\n st.push(i);\n }\n\n st.clear;\n\n auto leftmax = new int[](n);\n\n foreach (i ; 0 .. n) {\n while (!st.empty && a[st.top] < a[i]) st.pop;\n\n leftmax[i] = (st.empty ? -1 : st.top);\n st.push(i);\n }\n\n st.clear;\n\n auto rightmax = new int[](n);\n\n foreach_reverse (i ; 0 .. n) {\n while (!st.empty && a[st.top] <= a[i]) st.pop;\n\n rightmax[i] = (st.empty ? n : st.top);\n st.push(i);\n }\n\n long ans;\n\n foreach (i ; 0 .. n) {\n ans += 1L * (i - leftmax[i]) * (rightmax[i] - i) * a[i];\n ans -= 1L * (i - leftmin[i]) * (rightmin[i] - i) * a[i];\n }\n\n writeln(ans);\n}\n\nstruct Stack(T) {\nprivate:\n int N, peek;\n T[] data;\n\npublic:\n this(int size) \n {\n N = size;\n data = new T[](N);\n }\n\n bool empty() @property\n {\n return peek == 0;\n }\n\n bool full() @property\n {\n return peek == N;\n }\n\n void push(T x) @property\n {\n assert(!full);\n data[peek++] = x;\n }\n\n void pop() @property\n {\n assert(!empty);\n --peek;\n }\n\n T top() @property\n {\n return data[peek - 1];\n }\n\n void clear() @property\n {\n peek = 0;\n }\n\n}\n\n\nvoid readVariables(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg ; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if (!line.empty) {\n throw new Exception(\"args num < input num\");\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math;\n\nimmutable int mod = 10^^9 + 7;\n\nint n;\nint[] a;\n\nvoid main() {\n n = readln.chomp.to!int;\n a = readln.split.to!(int[]);\n\n auto pmini = new int[](n);\n auto pmaxi = new int[](n);\n\n int maxa = a[0], mina = a[0];\n\n foreach (i ; 1 .. n) {\n pmini[i] = pmini[i - 1];\n pmaxi[i] = pmaxi[i - 1];\n\n if (a[i] > maxa) {\n maxa = a[i];\n pmaxi[i] = i;\n }\n\n if (a[i] < mina) {\n mina = a[i];\n pmini[i] = i;\n }\n }\n\n debug {\n writeln(\"pmini:\",pmini);\n writeln(\"pmaxi:\",pmaxi);\n }\n\n auto smini = new int[](n);\n auto smaxi = new int[](n);\n\n smini[n - 1] = n - 1;\n smaxi[n - 1] = n - 1;\n\n maxa = a[n - 1], mina = a[n - 1];\n\n foreach_reverse (i ; 0 .. n - 1) {\n smini[i] = smini[i + 1];\n smaxi[i] = smaxi[i + 1];\n\n if (a[i] >= maxa) {\n maxa = a[i];\n smaxi[i] = i;\n }\n\n if (a[i] <= mina) {\n mina = a[i];\n smini[i] = i;\n }\n }\n\n debug {\n writeln(\"smini:\", smini);\n writeln(\"smaxi:\", smaxi);\n }\n\n long ans, v;\n\n int j, k;\n\n foreach (i ; 0 .. n) {\n\n if (i == pmaxi[i])\n j = binsearch1(smaxi, i);\n else\n j = i;\n\n if (i == pmaxi[i])\n k = binsearch2(pmaxi, i);\n else\n k = i;\n\n debug {\n //writeln(j, \" \", i, \" \", k);\n }\n\n ans += (i - j + 1).to!long * (k - i + 1) * a[i];\n\n if (i == smini[i])\n j = binsearch1(smini, i);\n else\n j = i;\n\n if (i == pmini[i])\n k = binsearch2(pmini, i);\n else\n k = i;\n\n ans -= (i - j + 1).to!long * (k - i + 1) * a[i];\n }\n\n assert(ans >= 0);\n\n writeln(ans);\n}\n\nint binsearch1(int[] s, int i) {\n int btm, top, mid;\n btm = -1;\n top = i;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (s[mid] == s[i]) {\n top = mid;\n }\n else {\n btm = mid;\n }\n }\n\n return top;\n}\n\nint binsearch2(int[] s, int i) {\n int btm, top, mid;\n btm = i;\n top = n;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (s[mid] == s[i]) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n return btm;\n}\n\nvoid readVariables(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg ; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if (!line.empty) {\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math;\n\nimmutable int mod = 10^^9 + 7;\n\nint n;\nint[] a;\n\nvoid main() {\n n = readln.chomp.to!int;\n a = readln.split.to!(int[]);\n\n auto pmini = new int[](n);\n auto pmaxi = new int[](n);\n\n int maxa = a[0], mina = a[0];\n\n foreach (i ; 1 .. n) {\n pmini[i] = pmini[i - 1];\n pmaxi[i] = pmaxi[i - 1];\n\n if (a[i] > maxa) {\n maxa = a[i];\n pmaxi[i] = i;\n }\n\n if (a[i] < mina) {\n mina = a[i];\n pmini[i] = i;\n }\n }\n\n debug {\n writeln(\"pmini:\",pmini);\n writeln(\"pmaxi:\",pmaxi);\n }\n\n auto smini = new int[](n);\n auto smaxi = new int[](n);\n\n smini[n - 1] = n - 1;\n smaxi[n - 1] = n - 1;\n\n maxa = a[n - 1], mina = a[n - 1];\n\n foreach_reverse (i ; 0 .. n - 1) {\n smini[i] = smini[i + 1];\n smaxi[i] = smaxi[i + 1];\n\n if (a[i] >= maxa) {\n maxa = a[i];\n smaxi[i] = i;\n }\n\n if (a[i] <= mina) {\n mina = a[i];\n smini[i] = i;\n }\n }\n\n debug {\n writeln(\"smini:\", smini);\n writeln(\"smaxi:\", smaxi);\n }\n\n long ans, v;\n\n int j, k;\n\n foreach (i ; 0 .. n) {\n\n if (i == pmaxi[i])\n j = binsearch1(smaxi, i);\n else\n j = i;\n\n if (i == pmaxi[i])\n k = binsearch2(pmaxi, i);\n else\n k = i;\n\n debug {\n writeln(j, \" \", i, \" \", k);\n }\n\n ans += (i - j + 1).to!long * (k - i + 1) * a[i];\n\n if (i == smini[i])\n j = binsearch1(smini, i);\n else\n j = i;\n\n if (i == pmini[i])\n k = binsearch2(pmini, i);\n else\n k = i;\n\n debug {\n \n }\n\n ans -= (i - j + 1).to!long * (k - i + 1) * a[i];\n }\n\n writeln(ans);\n}\n\nint binsearch1(int[] s, int i) {\n int btm, top, mid;\n btm = -1;\n top = i;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (s[mid] == s[i]) {\n top = mid;\n }\n else {\n btm = mid;\n }\n }\n\n return top;\n}\n\nint binsearch2(int[] s, int i) {\n int btm, top, mid;\n btm = i;\n top = n;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (s[mid] == s[i]) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n return btm;\n}\n\nvoid readVariables(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg ; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if (!line.empty) {\n throw new Exception(\"args num < input num\");\n }\n}"}], "src_uid": "38210a3dcb16ce2bbc81aa1d39d23112"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = readln.strip;\r\n\t\tauto res = s.count ('0') * 1L * s.count ('1');\r\n\t\tres = max (res,\r\n\t\t s.group.map !(c => c[1]).maxElement.to !(long) ^^ 2);\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop, std.functional;\n\n// Lengths of sequences satisfying the condition (moving to the right)\nint[] seq_length_right(alias less = \"a < b\", T)(T[] a)\n{\n if (a.length == 0)\n return new int[](0);\n auto tmp = new int[](a.length);\n int count = 1;\n tmp[$ - 1] = count;\n foreach_reverse (i ; 0 .. a.length - 1) {\n if (binaryFun!less(a[i], a[i + 1]))\n count++;\n else\n count = 1;\n tmp[i] = count;\n }\n return tmp;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!long;\n auto s = readln.strip;\n auto a = s.seq_length_right!\"a==b\";\n long x = s.count('0');\n long y = s.count('1');\n long z = a.maxElement;\n writeln(max(x * y, z * z));\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop, std.functional;\n\n// Lengths of sequences satisfying the condition (moving to the right)\nint[] seq_length_right(alias less = \"a < b\", T)(T[] a)\n{\n if (a.length == 0)\n return new int[](0);\n auto tmp = new int[](a.length);\n int count = 1;\n tmp[$ - 1] = count;\n foreach_reverse (i ; 0 .. a.length - 1) {\n if (binaryFun!less(a[i], a[i + 1]))\n count++;\n else\n count = 1;\n tmp[i] = count;\n }\n return tmp;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!long;\n auto s = readln.strip;\n auto a = s.seq_length_right!\"a==b\";\n auto x = s.count('0');\n auto y = s.count('1');\n writeln(max(cast(long)x * y, cast(long)a.maxElement * a.maxElement));\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop, std.functional;\n\n// Lengths of sequences satisfying the condition (moving to the right)\nint[] seq_length_right(alias less = \"a < b\", T)(T[] a)\n{\n if (a.length == 0)\n return new int[](0);\n auto tmp = new int[](a.length);\n int count = 1;\n tmp[$ - 1] = count;\n foreach_reverse (i ; 0 .. a.length - 1) {\n if (binaryFun!less(a[i], a[i + 1]))\n count++;\n else\n count = 1;\n tmp[i] = count;\n }\n return tmp;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!long;\n auto s = readln.strip;\n auto a = s.seq_length_right!\"a==b\";\n auto x = s.count('0');\n auto y = s.count('1');\n writeln(max(x * y, a.maxElement * a.maxElement));\n }\n}\n"}], "src_uid": "9070e0d4f8071d1ee8df5189b7c17bfa"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n, x;\n n = rd!int; x = rd!int;\n ll[] a = rdarr;\n ll[] b = rdarr;\n a.sort;\n b.sort;\n b.reverse;\n foreach(i; 0..n){\n if(a[i] + b[i] > x){\n writeln(\"No\");\n return;\n }\n }\n writeln(\"Yes\");\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, \"x\", long, \"y\");\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\n\nvoid main () {\n int t;\n\treadf(\"%d\\n\", &t);\n\twhile(t--) {\n\t\tint n, x;\n\t\treadf(\"%d %d\\n\", &n, &x);\n\t\tauto a = readln.split.to!(int[]);\n\t\tauto b = readln.split.to!(int[]);\n\t\tsort(a);\n\t\tsort(b);\n\t\tauto result = true;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(a[i] + b[n-i-1] > x) {\n\t\t\t\tresult = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(result)\n\t\t\twriteln(\"Yes\");\n\t\telse\n\t\t\twriteln(\"No\");\n\t\t\n\t\tif(t)\n\t\t\treadln();\n\t}\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x;\n\t\treadf !(\" %s %s\") (n, x);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tsort !(q{a < b}) (a);\n\t\tsort !(q{a > b}) (b);\n\t\tauto res = zip (a, b).all !(p => p[0] + p[1] <= x);\n\t\twriteln (res ? \"Yes\" : \"No\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "7e765c1b0e3f3e9c44de825a79bc1da2"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto Q = s[1];\n auto C = s[2];\n auto X = new int[](N);\n auto Y = new int[](N);\n auto S = new int[](N);\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n X[i] = s[0];\n Y[i] = s[1];\n S[i] = s[2];\n }\n\n auto A = new int[][][](C + 1, 110, 110);\n foreach (t; 0..C+1) {\n foreach (i; 0..N) {\n A[t][X[i] + 1][Y[i] + 1] += (S[i] + t) % (C + 1);\n }\n }\n\n foreach (t; 0..C+1)\n foreach (i; 0..102)\n foreach (j; 0..102)\n A[t][i][j + 1] += A[t][i][j];\n foreach (t; 0..C+1)\n foreach (j; 0..102)\n foreach (i; 0..102)\n A[t][i + 1][j] += A[t][i][j];\n\n int cumsum(int t, int x1, int y1, int x2, int y2) {\n return A[t][x2 + 1][y2 + 1] - A[t][x2 + 1][y1] - A[t][x1][y2 + 1] + A[t][x1][y1];\n }\n\n while (Q--) {\n s = readln.split.map!(to!int);\n auto t = s[0] % (C + 1);\n auto x1 = s[1];\n auto y1 = s[2];\n auto x2 = s[3];\n auto y2 = s[4];\n cumsum(t, x1, y1, x2, y2).writeln;\n }\n}\n", "positive_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nimmutable lim = 110;\nint n, q, c;\n\n\nvoid main() {\n scan(n, q, c);\n\n auto star = new int[][][](c + 1, lim, lim);\n\n int xi, yi, si;\n\n foreach (i ; 0 .. n) {\n scan(xi, yi, si);\n star[si][xi][yi]++;\n }\n\n foreach (k ; 0 .. c + 1) {\n foreach (i ; 1 .. lim) {\n foreach (j ; 1 .. lim) {\n star[k][i][j] += star[k][i - 1][j] + star[k][i][j - 1] - star[k][i - 1][j - 1];\n }\n }\n }\n\n int acc2d(int k, int x1, int y1, int x2, int y2) {\n return star[k][x2][y2] - star[k][x2][y1 - 1] - star[k][x1 - 1][y2] + star[k][x1 - 1][y1 - 1];\n }\n\n int ti, x1i, y1i, x2i, y2i;\n\n foreach (qi ; 0 .. q) {\n scan(ti, x1i, y1i, x2i, y2i);\n\n int ans;\n\n foreach (k ; 0 .. c + 1) {\n int p = (k + ti) % (c + 1);\n ans += acc2d(k, x1i, y1i, x2i, y2i) * p;\n }\n\n writeln(ans);\n }\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto Q = s[1];\n auto C = s[2];\n auto X = new int[](N);\n auto Y = new int[](N);\n auto S = new int[](N);\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n X[i] = s[0];\n Y[i] = s[1];\n S[i] = s[2];\n }\n\n auto A = new int[][][](C + 1, 110, 110);\n foreach (t; 0..C+1) {\n foreach (i; 0..N) {\n A[t][X[i] + 1][Y[i] + 1] += (S[i] + t) % (C + 1);\n }\n }\n\n foreach (t; 0..C+1)\n foreach (i; 0..102)\n foreach (j; 0..102)\n A[t][i][j + 1] += A[t][i][j];\n foreach (t; 0..C+1)\n foreach (j; 0..102)\n foreach (i; 0..102)\n A[t][i + 1][j] += A[t][i][j];\n\n int cumsum(int t, int x1, int y1, int x2, int y2) {\n return A[t][x2 + 1][y2 + 1] - A[t][x2 + 1][y1] - A[t][x1][y2 - 1] + A[t][x1][y1];\n }\n\n while (Q--) {\n s = readln.split.map!(to!int);\n auto t = s[0] % (C + 1);\n auto x1 = s[1];\n auto y1 = s[2];\n auto x2 = s[3];\n auto y2 = s[4];\n cumsum(t, x1, y1, x2, y2).writeln;\n }\n}\n"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nimmutable lim = 110;\n\nint n, q, c;\n\nvoid main() {\n scan(n, q, c);\n\n auto kido = new int[][][](c + 1, lim, lim);\n auto exst = new bool[][](lim, lim);\n\n int xi, yi, si;\n\n foreach (i ; 0 .. n) {\n scan(xi, yi, si);\n kido[0][xi][yi] = si;\n exst[xi][yi] = true;\n }\n\n foreach (k ; 0 .. c) {\n foreach (i ; 0 .. lim) {\n foreach (j ; 0 .. lim) {\n if (exst[i][j]) {\n kido[k + 1][i][j] = (kido[k][i][j] + 1) % (c + 1);\n }\n }\n }\n }\n\n foreach (k; 0 .. c + 1) {\n foreach (i ; 0 .. lim) {\n foreach (j ; 0 .. lim - 1) {\n kido[k][i][j + 1] += kido[k][i][j];\n }\n }\n\n foreach (j ; 0 .. lim) {\n foreach (i ; 0 .. lim - 1) {\n kido[k][i + 1][j] += kido[k][i][j];\n }\n }\n }\n\n int ti, x1i, y1i, x2i, y2i;\n\n foreach (qi ; 0 .. q) {\n scan(ti, x1i, y1i, x2i, y2i);\n ti %= (c + 1);\n\n int ans;\n ans += kido[ti][x2i][y2i];\n ans -= kido[ti][x2i][y1i - 1];\n ans -= kido[ti][x1i - 1][y2i];\n ans += kido[ti][x1i - 1][y1i - 1];\n\n writeln(ans);\n }\n}\n\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nimmutable lim = 110;\n\nint n, q, c;\n\nvoid main() {\n scan(n, q, c);\n\n auto kido = new int[][][](c + 1, lim, lim);\n auto exst = new bool[][](lim, lim);\n\n int xi, yi, si;\n\n foreach (i ; 0 .. n) {\n scan(xi, yi, si);\n\n if (exst[xi][yi]) {\n writeln(\"Error\");\n return;\n }\n\n kido[0][xi][yi] = si;\n exst[xi][yi] = true;\n }\n\n foreach (k ; 0 .. c) {\n foreach (i ; 0 .. lim) {\n foreach (j ; 0 .. lim) {\n if (exst[i][j]) {\n kido[k + 1][i][j] = (kido[k][i][j] + 1) % (c + 1);\n }\n }\n }\n }\n\n debug {\n foreach (k ; 0 .. c + 1) {\n writefln(\"%(%(%s %)\\n%)\", kido[k]);\n writeln;\n }\n }\n\n foreach (k; 0 .. c + 1) {\n foreach (i ; 0 .. lim) {\n foreach (j ; 0 .. lim - 1) {\n kido[k][i][j + 1] += kido[k][i][j];\n }\n }\n\n foreach (j ; 0 .. lim) {\n foreach (i ; 0 .. lim - 1) {\n kido[k][i + 1][j] += kido[k][i][j];\n }\n }\n }\n\n int ti, x1i, y1i, x2i, y2i;\n\n foreach (qi ; 0 .. q) {\n scan(ti, x1i, y1i, x2i, y2i);\n ti %= (c + 1);\n\n int ans;\n ans += kido[ti][x2i][y2i];\n ans -= kido[ti][x2i][y1i - 1];\n ans -= kido[ti][x1i - 1][y2i];\n ans += kido[ti][x1i - 1][y1i - 1];\n\n writeln(ans);\n }\n}\n\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nimmutable lim = 10;\n\nint n, q, c;\n\nvoid main() {\n scan(n, q, c);\n\n auto kido = new int[][][](c + 1, lim, lim);\n auto exst = new bool[][](lim, lim);\n\n int xi, yi, si;\n\n foreach (i ; 0 .. n) {\n scan(xi, yi, si);\n\n if (exst[xi][yi]) {\n writeln(\"Error\");\n return;\n }\n \n kido[0][xi][yi] = si;\n exst[xi][yi] = true;\n }\n\n foreach (k ; 0 .. c) {\n foreach (i ; 0 .. lim) {\n foreach (j ; 0 .. lim) {\n if (exst[i][j]) {\n kido[k + 1][i][j] = (kido[k][i][j] + 1) % (c + 1);\n }\n }\n }\n }\n\n debug {\n foreach (k ; 0 .. c + 1) {\n writefln(\"%(%(%s %)\\n%)\", kido[k]);\n writeln;\n }\n }\n\n foreach (k; 0 .. c + 1) {\n foreach (i ; 0 .. lim) {\n foreach (j ; 0 .. lim - 1) {\n kido[k][i][j + 1] += kido[k][i][j];\n }\n }\n\n foreach (j ; 0 .. lim) {\n foreach (i ; 0 .. lim - 1) {\n kido[k][i + 1][j] += kido[k][i][j];\n }\n }\n }\n\n int ti, x1i, y1i, x2i, y2i;\n\n foreach (qi ; 0 .. q) {\n scan(ti, x1i, y1i, x2i, y2i);\n ti %= (c + 1);\n\n int ans;\n ans += kido[ti][x2i][y2i];\n ans -= kido[ti][x2i][y1i - 1];\n ans -= kido[ti][x1i - 1][y2i];\n ans += kido[ti][x1i - 1][y1i - 1];\n\n writeln(ans);\n }\n}\n\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "src_uid": "4efb7bc87bdba2b7fd33ce1734754a50"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.container.rbtree;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nalias T = RedBlackTree!(int, \"a < b\", true);\n\nfinal class DisjointSet {\n int [] p, h, s;\n int n;\n T t;\n public:\n int bs () {\n if (t.empty) return 0;\n int u = findSet (n - 1);\n int v = t.back;\n if (s[u] == v) {\n t.removeBack ();\n int r = t.empty ? 0 : t.back;\n t.insert (v);\n return r;\n }\n return t.back;\n }\n this (in int _n) {\n n = _n;\n p = iota (0, n).array;\n h = new int[n];\n s = new int[n];\n //s[] = 0;\n t = new T ();\n }\n pure nothrow @nogc\n int findSet (in int x) {\n if (p[x] == x) {\n return x;\n }\n return p[x] = findSet (p[x]);\n }\n bool merge (int i, int j) {\n i = findSet (i);\n j = findSet (j);\n if (i != j) {\n if (s[i] > 0) t.removeKey (s[i]);\n if (s[j] > 0) t.removeKey (s[j]);\n if (h[i] < h[j]) {\n p[i] = j;\n s[j] += s[i];\n t.insert (s[j]);\n } else if (h[i] > h[j]) {\n p[j] = i;\n s[i] += s[j];\n t.insert (s[i]);\n } else {\n p[i] = j;\n s[j] += s[i];\n t.insert (s[j]);\n ++h[j];\n }\n return true;\n }\n return false;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n bool test () {\n const n = r.next!uint;\n auto a = r.nextA!uint (n);\n a[] -= 1;\n auto rank = new int[n];\n foreach (i; 0 .. n) {\n rank[a[i]] = i;\n }\n auto ds = new DisjointSet (n);\n foreach (i; 0 .. n) {\n int pos = rank[i];\n int t;\n if (pos > 0) {\n int x = ds.findSet (pos - 1);\n t = ds.s[x];\n }\n debug stderr.writefln!(\"pos = %d, i = %d, t = %d, bs = %d\")(pos, i, t, ds.bs());\n if (t != ds.bs ()) {\n return false;\n }\n int u = ds.findSet (pos);\n ds.t.insert(++ds.s[u]);\n if (pos > 0 && a[pos-1] < a[pos]) ds.merge (pos - 1, pos);\n if (pos + 1 < n && a[pos+1] < a[pos]) ds.merge (pos, pos + 1); \n }\n return true;\n }\n foreach (tid; 0 .. nt) {\n writeln (test () ? \"Yes\" : \"No\");\n }\n}\n\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto P = new int[N];\n foreach (i; 0 .. N) {\n P[i] = readInt() - 1;\n }\n P.reverse;\n \n bool ans = true;\n for (int i = 0, j; i < N; i = j) {\n j = P[i] + 1;\n foreach (k; i .. j) {\n ans = ans && (P[i] + i == P[k] + k);\n }\n if (!ans) {\n break;\n }\n }\n writeln(ans ? \"Yes\" : \"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto p = RDA(-1);\n\n\t\tauto rbt = new RedBlackTree!int;\n\t\tforeach (e; p)\n\t\t\trbt.insert(e);\n\n\t\tauto tmp = new int[](n);\n\t\ttmp[] = 1;\n\t\tauto heap = heapify(tmp);\n\n\t\tauto cnt = new int[](n);\n\t\tcnt[] = 1;\n\n\t\tbool ok = true;\n\t\tauto index = p.MAKE_IDX;\n\t\tforeach (_i; index)\n\t\t{\n\t\t\tauto i = cast(int)_i;\n\t\t\tauto c = heap.front; heap.removeFront;\n\t\t\tif (cnt[i] != c)\n\t\t\t{\n\t\t\t\tdebug writeln(\"i:\", i);\n\t\t\t\tdebug writeln(cnt);\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tauto r = rbt.upperBound(i);\n\t\t\tif (!r.empty)\n\t\t\t{\n\t\t\t\tauto num = r.front;\n\t\t\t\tcnt[num] += cnt[i];\n\t\t\t\theap.insert(cnt[num]);\n\t\t\t}\n\t\t\tcnt[i] = 0;\n\t\t\trbt.remove(rbt.equalRange(i));\n\t\t}\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Yes\" : \"No\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid solve()\n{\n auto N = readln.chomp.to!int;\n auto ps = readln.split.to!(int[]);\n\n auto ii = new size_t[](N);\n foreach (i, ref p; ps) {\n p -= 1;\n ii[p] = i;\n }\n\n auto bs = new bool[](N);\n size_t i = ii[0];\n int n;\n for (;;) {\n bs[i] = true;\n ++i;\n ++n;\n if (n == N) break;\n if (i == N || bs[i]) {\n i = ii[n];\n continue;\n }\n if (ps[i] != n) {\n writeln(\"No\");\n return;\n }\n }\n writeln(\"Yes\");\n}\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n solve();\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\treadln;\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\tauto q = new int [n];\n\t\tforeach (i, c; p)\n\t\t{\n\t\t\tq[c] = i;\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tok &= (q[i] == q[i - 1] + 1) || (q[i] < q[i - 1]);\n\t\t}\n\t\twriteln (ok ? \"Yes\" : \"No\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "dc03b66a4c6aac69372d594784f3f083"} {"source_code": "import std.algorithm.comparison : min;\nimport std.algorithm.sorting : sort;\nimport std.stdio;\n\nvoid main()\n{\n char c;\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (q; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n auto a = new int[n];\n foreach(i; 0..n) readf!\"%d%c\"(a[i], c);\n a.sort!\"a > b\";\n\n writeln(min(a[1] - 1, n - 2));\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint t = read.to!int;\n\tforeach(q; 0 .. t){\n\t\tint n = read.to!int;\n\t\tlong[] as;\n\t\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\t\n\t\tas.sort!\"a>b\"();\n\t\tlong ans = min(as[1] - 1, as.length - 2);\n\t\tans.writeln;\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto T = RD!int;\n\tforeach (i; 0..T)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\ta.sort();\n\t\tauto len = min(a[$-1], a[$-2]);\n\t\tauto ans = min(a.length - 2, len - 1);\n\t\twriteln(ans);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "130fd7f40d879e25b0bff886046bf699"} {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nint m, k;\nint n;\nint[] a;\nvoid main() {\n readf(\"%d %d %d\\n\", &n, &m, &k);\n int um, uk;\n a = stdin.readln.chop.split(\" \").map!(to!int).array;\n foreach (x; a) {\n if (x == 1) {\n um++;\n } else {\n if (uk < k) {\n uk++;\n } else {\n um++;\n }\n }\n }\n writeln(max(um - m, 0) + max(uk - k, 0));\n}\n", "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n int b = cin.readInt;\n int p = cin.readInt;\n int w = 0;\n for (int i = 0; i < n; i++) {\n int x = cin.readInt;\n if (x == 1) {\n (b == 0) ? w++ : b--;\n }\n if (x == 2) {\n if (b == 0 && p == 0) w++;\n else if (b == 0 && p > 0) p--;\n else if (p == 0 && b > 0) b--;\n else p--;\n }\n }\n writeln(w);\n } \n}"}, {"source_code": "import std.stdio, std.array, std.algorithm, std.conv, std.range, std.string;\n\nvoid main() {\n auto input = readln.chomp.split.map!(to!int).array;\n auto n = input[0];\n auto m = input[1];\n auto k = input[2];\n auto a = readln.chomp.split.map!(to!int).array;\n\n foreach (e; a) {\n switch (e) {\n case 1:\n m--;\n break;\n case 2:\n if (k > 0) { k--; } else { m--; }\n break;\n default:\n break;\n }\n }\n\n auto answer = 0;\n if (m < 0) { answer += -m; }\n if (k < 0) { answer += -k; }\n\n answer.writeln;\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main() {\n debug stdin = File(\"input.txt\", \"r\");\n int n, m, k;\n readf(\" %s %s %s\", &n, &m, &k);\n\n int[] a = new int[n];\n int ans = 0;\n foreach (i; 0 .. n) {\n int x;\n readf(\" %s\", &x);\n\n if (x == 1) {\n if (m == 0) {\n ++ans;\n } else {\n --m;\n }\n\n } else {\n if (k > 0) {\n --k;\n } else if (m > 0) {\n --m;\n } else\n ++ans;\n }\n }\n\n writeln(ans);\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nint m, k;\nint n;\nint[] a;\nvoid main() {\n readf(\"%d %d %d\\n\", &n, &m, &k);\n int um, uk;\n a = stdin.readln.chop.split(\" \").map!(to!int).array;\n foreach (x; a) {\n if (x == 1) {\n um++;\n } else {\n if (uk < k) {\n uk++;\n } else {\n um++;\n }\n }\n }\n (uk + um - k - m).writeln;\n}\n"}], "src_uid": "4ed5b8055ce48b5ad4e43ed4b06d1b07"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n auto B = new long[N];\n foreach (i; 0 .. N) {\n B[i] = readLong();\n }\n \n auto sel = new bool[N];\n auto as = A.dup;\n sort(as);\n foreach (k; 0 .. N - 1) {\n if (as[k] == as[k + 1]) {\n foreach (i; 0 .. N) {\n if ((as[k] | A[i]) == as[k]) {\n sel[i] = true;\n }\n }\n }\n }\n long ans;\n foreach (i; 0 .. N) {\n if (sel[i]) {\n ans += B[i];\n }\n }\n writeln(ans);\n \n debug {\n long brt;\n foreach (h; 0 .. 1 << N) {\n if (popcnt(h) >= 2) {\n bool ok = true;\n foreach (i; 0 .. N) if (h & 1 << i) {\n bool every = true;\n foreach (j; 0 .. N) if (h & 1 << j) {\n if (i != j) {\n every = every && ((A[i] & ~A[j]) != 0);\n }\n }\n ok = ok && !every;\n }\n if (ok) {\n long sum;\n foreach (i; 0 .. N) if (h & 1 << i) {\n sum += B[i];\n }\n writeln(h, \" \", sum);\n chmax(brt, sum);\n }\n }\n }\n assert(brt == ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n \n auto a = readln.chomp.split.map!(to!long).array;\n \n auto b = readln.chomp.split.map!(to!int).array;\n \n bool isBetter(long x, long y) {\n return (x & (x ^ y)) > 0;\n }\n \n auto inleaders = make!(RedBlackTree!long);\n int[] leaders;\n foreach (i; 0 .. n) {\n if (a[i] in inleaders) { continue; }\n \n bool same = false;\n foreach (j; 0 .. n) {\n if (i == j) { continue; }\n \n if (a[j] == a[i]) {\n same = true;\n }\n }\n \n if (same) {\n inleaders.insert(a[i]);\n leaders ~= i;\n }\n }\n \n auto added = new bool[] (n);\n added[] = false;\n foreach (p; leaders) {\n added[p] = true;\n foreach (j; 0 .. n) {\n if (added[j]) { continue; }\n \n if (a[j] == a[p] || !isBetter(a[j], a[p])) {\n added[j] = true;\n }\n }\n }\n \n long ans = 0;\n foreach (i; 0 .. n) {\n if (added[i]) { ans += b[i]; }\n }\n ans.writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tlong[] as = rlong(n);\n\tlong[] bs = rlong(n);\n\t\n\tX[] xs;\n\tforeach(i; 0 .. n) xs ~= X(as[i], bs[i]);\n\tlog(\"xs:\", xs);\n\t\n\tint[long] xc;\n\tforeach(x; xs){\n\t\tif(x.a !in xc) xc[x.a] = 0;\n\t\txc[x.a] += 1;\n\t}\n\tlog(\"xc:\", xc);\n\t\n\tlong[] xas = xc.keys;\n\tlong[] topas = [];\n\tforeach(a; xas) if(xc[a] > 1) topas ~= a;\n\tlog(\"xas:\", xas, \"topas:\", topas);\n\t\n\tlong ans;\n\tforeach(x; xs){\n\t\tforeach(a; topas){\n\t\t\tlog(\"x:\", x, \"a:\", a, \"x.a & a:\", x.a & a);\n\t\t\tif((x.a & a) == x.a){\n\t\t\t\tans += x.b;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tlog(\"x:\", x, \"ans:\", ans);\n\t}\n\t\n\tans.writeln;\n}\nstruct X{\n\tlong a, b;\n}\n\n/*\n- \"Top team\": two or more students with same ability.\n (there may be more than one top teams)\n- \"Sub team\" of a top team: students strictly weaker than the top team student\n\nUnion of all top teams and their sub teams are the solution.\n*/\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n auto B = new long[N];\n foreach (i; 0 .. N) {\n B[i] = readLong();\n }\n \n long ans;\n foreach (i; 0 .. N) {\n bool ok;\n long sum = B[i];\n foreach (j; 0 .. N) {\n if (i != j) {\n if ((A[i] | A[j]) == A[i]) {\n ok = ok || (A[i] == A[j]);\n sum += B[j];\n }\n }\n }\n debug {\n writeln(i, \" \", A[i], \": \", ok, \" \", sum);\n }\n if (ok) {\n chmax(ans, sum);\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "9404ec14922a69082f3573bbaf78ccf0"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nconst long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto dp = new long[](1 << 3);\n fill(dp, INF);\n dp[0] = 0;\n\n foreach (_; 0..N) {\n auto s = readln.split;\n auto c = s[0].to!long;\n auto S = s[1];\n int mask = 0;\n if (S.canFind('A')) mask |= 1;\n if (S.canFind('B')) mask |= (1 << 1);\n if (S.canFind('C')) mask |= (1 << 2);\n foreach (nmask; 0..8) {\n dp[mask | nmask] = min(dp[mask | nmask], dp[nmask] + c);\n }\n }\n\n writeln( dp[7] == INF ? -1 : dp[7] );\n}\n", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n auto mns=new int[](8);\n fill(mns, 1000000000);\n foreach(_; 0..n){\n auto args=readln.split.to!(char[][]);\n int kind=0;\n foreach(c; args[1]){\n kind^=(1<<(c-'A'));\n }\n mns[kind]=min(mns[kind], args[0].to!(int));\n }\n struct T{int kind, price;}\n T[] as, bs, cs;\n foreach(bit; 1..(1<<3)){\n if(mns[bit]==1000000000) continue;\n if(bit&(1<<0)) as~=T(bit, mns[bit]);\n if(bit&(1<<1)) bs~=T(bit, mns[bit]);\n if(bit&(1<<2)) cs~=T(bit, mns[bit]);\n }\n as~=T(0, 0); bs~=T(0, 0); cs~=T(0, 0);\n int mincost=1000000000;\n foreach(a; as){\n foreach(b; bs){\n foreach(c; cs){\n int bit=a.kind|b.kind|c.kind;\n if(bit==((1<<3)-1)){\n mincost=min(mincost, a.price+b.price+c.price);\n }\n }\n }\n }\n if(mincost<1000000000){\n writeln(mincost);\n }else{\n writeln(-1);\n }\n\n\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "02d62bb1eb4cc0e373b862a980d6b29c"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = RD!string;\n\tlong cnt;\n\tbool ans = true;\n\tforeach (i; 0..n)\n\t{\n\t\tif (s[i] == '(')\n\t\t\t++cnt;\n\t\telse\n\t\t\t--cnt;\n\n\t\tif (cnt < -1)\n\t\t{\n\t\t\tans = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\twriteln(ans && cnt == 0 ? \"Yes\" : \"No\");\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n;\n string s;\n readf!\" %s %s\"(n,s);\n s = s.strip;\n\n int a = 0;\n int mn = 0;\n foreach (c; s) {\n if (c == '(') a++;\n else a--;\n mn = min(mn, a);\n }\n\n if (a == 0 && mn >= -1) {\n writeln(\"Yes\");\n } else {\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nstring S;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n S = readToken();\n \n auto as = new int[N + 1];\n auto ls = new int[N + 1];\n auto rs = new int[N + 1];\n foreach (i; 0 .. N) {\n as[i + 1] = as[i] + ((S[i] == '(') ? +1 : -1);\n }\n foreach (i; 0 .. N) {\n ls[i + 1] = min(ls[i], as[i + 1]);\n }\n foreach_reverse (i; 0 .. N) {\n rs[i] = min(rs[i + 1], as[i]);\n }\n \n bool ans;\n if (as[N] == 0) {\n debug {\n writeln(\"as = \", as);\n writeln(\"ls = \", ls);\n writeln(\"rs = \", rs);\n }\n ans = false;\n foreach (i; 0 .. N) {\n if (S[i] == '(') {\n if (1 + ls[i] >= 0 && rs[i + 1] >= 0) {\n ans = true;\n }\n } else {\n if (ls[i] >= 0 && 1 + rs[i + 1] >= 0) {\n ans = true;\n }\n }\n }\n } else {\n ans = false;\n }\n writeln(ans ? \"Yes\" : \"No\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "e30085b163c820cff68fb24b94088ec1"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nint test () {\n auto s = readln.strip;\n auto t = readln.strip;\n immutable l = s.length.to!int;\n auto next = new int[26][l+1];\n next[l][] = l;\n foreach_reverse (i; 0 .. l) {\n next[i][] = next[i+1][];\n immutable k = s[i].to!int - 97;\n next[i][k] = i;\n }\n foreach (c; t) {\n immutable k = c.to!int - 97;\n if (next[0][k] >= l) return -1;\n }\n int i, res;\n foreach (c; t) {\n immutable k = c.to!int - 97;\n while (true) {\n i = next[i][k];\n if (i >= l) {\n ++res;\n i = 0;\n } else {\n break;\n }\n }\n ++i;\n }\n res++;\n return res;\n}\n\n\nvoid main() {\n immutable nt = readln.strip.to!int; \n foreach (tid; 0 .. nt) {\n writeln (test ());\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto T = RD!int;\n\tauto ans = new int[](T);\n\tforeach (ti; 0..T)\n\t{\n\t\tauto s = RD!string;\n\t\tauto t = RD!string;\n\t\tauto arr = new int[][](26);\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tarr[s[i]-'a'] ~= cast(int)i;\n\t\t}\n\t\n\t\tans[ti] = 1;\n\t\tint pos = -1;\n\t\tforeach (i; 0..t.length)\n\t\t{\n\t\t\tauto c = t[i]-'a';\n\t\t\tbool f(int x)\n\t\t\t{\n\t\t\t\treturn arr[c][x] > pos;\n\t\t\t}\n\t\t\tauto r = binarySearch!(f)(cast(int)arr[c].length, -1);\n\t\t\tif (r == arr[c].length)\n\t\t\t{\n\t\t\t\t++ans[ti];\n\t\t\t\tpos = -1;\n\t\t\t\tr = binarySearch!(f)(cast(int)arr[c].length, -1);\n\t\t\t\tif (r == arr[c].length)\n\t\t\t\t{\n\t\t\t\t\tans[ti] = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpos = arr[c][r];\n\t\t\tdebug writeln(\"pos:\", pos);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "d132158607bbd0541f2232a300e4a1b1"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto a = ma(n, readInt!int);\n\tauto viA = new int[2][](n);\n\tforeach(i, ai; a) viA[i] = [ai, cast(int)i];\n\tsort!((a, b) => a > b)(viA);\n\tlong minTime = 0;\n\tlong currentX = 1;\n\tvoid pop()\n\t{\n\t\tif (currentX > 0) currentX = -currentX;\n\t\telse currentX = -currentX + 1;\n\t}\n\tauto xs = new long[](n);\n\tforeach(viAi; viA)\n\t{\n\t\tauto value = viAi[0];\n\t\tauto index = viAi[1];\n\t\tminTime += 2 * abs(currentX * value);\n\t\txs[index] = currentX;\n\t\tpop;\n\t}\n\twriteln(minTime);\n\twrite(\"0 \");\n\tforeach(x; xs) write(x, \" \");\n\twriteln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n tup[] zipp;\n for(int i = 0; i < n; ++i){\n zipp ~= tup(arr[i], i);\n }\n zipp.sort;\n ll sol = 0;\n auto res = new ll[](n);\n long cnt = 1;\n for(int i = n-1; i >= 0; i -= 2){\n res[zipp[i][1]] = cnt;\n sol += cnt * zipp[i][0];\n ++cnt;\n }\n cnt = -1;\n for(int i = n-2; i >= 0; i -= 2){\n res[zipp[i][1]] = cnt;\n sol += (- cnt) * zipp[i][0];\n --cnt;\n }\n writeln(2*sol);\n write(0, \" \");\n res.each!((a) => write(a, \" \"));\n writeln;\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", int, \"y\");\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans1 = new long[](t);\r\n\tauto ans2 = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tans2[ti].length = n+1;\r\n\t\tauto index = a.MAKE_IDX!\"a > b\";\r\n\t\tforeach (ii, i; index)\r\n\t\t{\r\n\t\t\tauto cnt = ii / 2 + 1;\r\n\t\t\tans1[ti] += cnt * a[i] * 2;\r\n\t\t\tans2[ti][i+1] = cnt;\r\n\t\t\tif (ii % 2)\r\n\t\t\t\tans2[ti][i+1] *= -1;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\twriteln(ans1[ti]);\r\n\t\tans2[ti].map!(to!string).join(\" \").writeln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "17c3fad605bc50c0e7cb4c0718cde57f"} {"source_code": "import std.stdio;\n\nvoid main() {\n auto s = readln()[0 .. $ - 1];//Strip trailing '\\n'.\n auto t = readln()[0 .. $ - 1];\n int[26] m;\n foreach (c; s)\n m[c - 'a']++;\n\n void writeRest() {\n foreach (i, cnt; m)\n foreach (j; 0 .. cnt)\n write(cast(char)(i + 'a'));\n writeln();\n }\n\n int i = 0;\n foreach (c; t) {\n if (!m[c - 'a'])\n break;\n m[c - 'a']--;\n i++;\n }\n\n if (i == t.length) {\n if (s.length > i) {\n write(t);\n writeRest();\n return;\n }\n m[t[--i] - 'a']++;\n }\n while (i >= 0) {\n debug writeln(m);\n foreach (j; t[i] - 'a' + 1 .. 26)\n if (m[j]) {\n write(t[0 .. i]);\n write(cast(char)(j + 'a'));\n m[j]--;\n writeRest();\n return;\n }\n if (i--)\n m[t[i] - 'a']++;\n }\n writeln(\"-1\");\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n auto s = readln()[0 .. $ - 1];//Strip trailing '\\n'.\n auto t = readln()[0 .. $ - 1];\n int[26] m;\n foreach (c; s)\n m[c - 'a']++;\n\n void writeRest() {\n foreach (i, cnt; m)\n foreach (j; 0 .. cnt)\n write(cast(char)(i + 'a'));\n writeln();\n }\n\n int i = 0;\n foreach (c; t) {\n if (!m[c - 'a'])\n break;\n m[c - 'a']--;\n i++;\n }\n\n if (i == t.length && s.length > i) {\n write(t);\n writeRest();\n } else {\n if (i == t.length)\n m[t[--i] - 'a']++;\n for (; i >= 0; ) {\n debug writeln(m);\n foreach (j; t[i] - 'a' + 1 .. 26)\n if (m[j]) {\n write(t[0 .. i]);\n write(cast(char)(j + 'a'));\n m[j]--;\n writeRest();\n return;\n }\n if (i--)\n m[t[i] - 'a']++;\n }\n writeln(\"-1\");\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n auto s = readln()[0 .. $ - 1];//Strip trailing '\\n'.\n auto t = readln()[0 .. $ - 1];\n int[26] m;\n foreach (c; s)\n m[c - 'a']++;\n int i = 0;\n foreach (c; t[0 .. $ - 1]) {\n if (!m[c - 'a'])\n break;\n m[c - 'a']--;\n i++;\n }\n for (; i >= 0; i--) {\n foreach (j; t[i] - 'a' + 1 .. 26)\n if (m[j]) {\n write(t[0 .. i]);\n write(cast(char)(j + 'a'));\n m[j]--;\n foreach (c, cnt; m)\n foreach (k; 0 .. cnt)\n write(cast(char)(c + 'a'));\n writeln();\n return;\n }\n m[s[i] - 'a']++;\n }\n writeln(\"-1\");\n}\n"}], "src_uid": "a1739619b5ee88e22ae31f4d72bed90a"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int _Q, D; get(_Q, D);\r\n int[] dd;\r\n foreach (i; 0..10) dd ~= [i * 10 + D, D * 10 + i];\r\n sort(dd);\r\n auto DP = new int[](100);\r\n DP[0] = 1;\r\n foreach (i; 0..100) if (DP[i] == 0) {\r\n int solve(int i) {\r\n if (DP[i] != 0) return DP[i];\r\n foreach (d; dd) {\r\n if (i - d < 0) break;\r\n if (solve(i - d) == 1) return DP[i] = 1;\r\n }\r\n return DP[i] = -1;\r\n }\r\n solve(i);\r\n }\r\n foreach (Q; readln.split.to!(int[])) {\r\n if (Q >= 100) goto ok;\r\n if (DP[Q] == 1) goto ok;\r\n writeln(\"NO\");\r\n continue;\r\n ok:\r\n writeln(\"YES\");\r\n }\r\n }\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint q, d;\r\n\t\treadf !(\" %s %s\") (q, d);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\timmutable int limit = 100;\r\n\t\tauto f = new bool [limit];\r\n\t\tf[0] = true;\r\n\t\tf[d * 10..$] = true;\r\n\t\tforeach (x; 0..10)\r\n\t\t{\r\n\t\t\tauto y = x * 10 + d;\r\n\t\t\tforeach (z; y..limit)\r\n\t\t\t{\r\n\t\t\t\tf[z] |= f[z - y];\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\twriteln ((c >= limit || f[c]) ? \"YES\" : \"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto q = RD!int;\r\n\t\tauto d = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tforeach (e; a)\r\n\t\t{\r\n\t\t\tif (e >= d*10 || e % d == 0)\r\n\t\t\t{\r\n\t\t\t\tans[ti] ~= true;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tauto cnt = e / d;\r\n\t\t\t\tbool ok;\r\n\t\t\t\tforeach (i; 0..cnt)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto x = e - i * d;\r\n\t\t\t\t\tif ((x % 10) == d)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tok = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tans[ti] ~= ok;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tforeach (ee; e)\r\n\t\t\twriteln(ee ? \"YES\" : \"NO\");\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int q;\n q = scan!int;\n ll d = scan;\n bool[100] check;\n for(int el = 1; el < 100; ++el){\n if(el % d == 0){\n check[el] = 1; continue;\n }\n ll tim = 1;\n ll num = el;\n while(num > 0){\n num /= tim;\n ll dig = num % 10;\n if(dig == d){\n check[el] = 1;\n break;\n }\n tim *= 10;\n }\n if(check[el]){\n for(int i = el; i < 100; i += d){\n check[i] = 1;\n }\n }\n }\n auto arr = scanArray;\n foreach(el; arr){\n bool f = 0;\n for(ll i = 1; i < 100; ++i){\n if(el < i){ break; }\n if(el % d == i % d){\n f |= check[to!int(i)];\n }\n }\n if(f){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\n }\n }\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int q;\n q = scan!int;\n ll d = scan;\n ll[] arr;\n for(int i = 0; i <= d; ++i){\n ll fnum = i*10 + d;\n if(fnum % d != 0){\n for(int j = 0; j < 14; ++j){\n arr ~= j*d + fnum;\n }\n }\n }\n arr.sort;\n auto seeq = scanArray;\n foreach(el; seeq){\n show(el);\n bool f = 0;\n if(el % d == 0){\n writeln(\"YES\");\n f = 1;\n }\n if(!f){\n foreach(a; arr){\n if(el < a){ break; }\n if(el % d == a % d){\n writeln(\"YES\");\n f = 1;\n break;\n }\n }\n }\n if(!f){\n ll tim = 1;\n ll num = el;\n while(num > 0){\n num /= tim;\n ll dig = num % 10;\n if(dig == d){\n writeln(\"YES\");\n f = 1;\n break;\n }\n tim *= 10;\n }\n }\n if(!f){\n writeln(\"NO\");\n }\n }\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int q;\n q = scan!int;\n ll d = scan;\n auto arr = iota(0L, 10L).map!(a => (10*a + d) % d).array;\n show(arr);\n auto seeq = scanArray;\n foreach(el; seeq){\n show(el);\n bool f = 0;\n for(int i = 0; i <= d; ++i){\n if(el < 10*i + arr[i]){ break; }\n if(el % d == arr[i]){\n writeln(\"YES\");\n f = 1;\n break;\n }\n }\n if(!f){\n ll tim = 1;\n ll num = el;\n while(num > 0){\n num /= tim;\n ll dig = num % 10;\n if(dig == d){\n writeln(\"YES\");\n f = 1;\n break;\n }\n tim *= 10;\n }\n }\n if(!f){\n writeln(\"NO\");\n }\n }\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int _Q, D; get(_Q, D);\r\n foreach (Q; readln.split.to!(int[])) {\r\n if (Q >= 100) goto ok;\r\n foreach (i; 1..10) if (Q >= D * i && (Q - D * i) % 10 == 0) goto ok;\r\n if (Q / 10 >= D && Q % 10 >= D) goto ok;\r\n writeln(\"NO\");\r\n continue;\r\n ok:\r\n writeln(\"YES\");\r\n }\r\n }\r\n}"}], "src_uid": "7975af65a23bad6a0997921c7e31d3ca"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint rows, cols;\n\twhile (readf (\" %s %s\", &rows, &cols) > 0)\n\t{\n\t\tint sRow, sCol;\n\t\treadf (\" %s %s\", &sRow, &sCol);\n\t\tint lLimit, rLimit;\n\t\treadf (\" %s %s\", &lLimit, &rLimit);\n\t\tauto board = new char [] [] (rows + 2, cols + 2);\n\t\tforeach (ref line; board)\n\t\t{\n\t\t\tline[] = '#';\n\t\t}\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\treadf (\" %s\", &board[row + 1][col + 1]);\n\t\t\t}\n\t\t}\n\n\t\talias Coord = Tuple !(int, q{row}, int, q{col});\n\t\tauto deque = new Coord [rows * cols * 4 + 1];\n\t\tint qb = rows * cols * 2;\n\t\tint qe = rows * cols * 2;\n\t\tauto f = new int [] [] (rows + 2, cols + 2);\n\n\t\tvoid go (int row, int col, int extra, int add)\n\t\t{\n\t\t\tdebug {writeln (extra, \" \", add, \" \", row, \" \", col);}\n\t\t\tif (board[row][col] != '.')\n\t\t\t{\n\t\t\t\tif (board[row][col] != '+' ||\n\t\t\t\t f[row][col] <= extra + add)\n\t\t\t\t{\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (add)\n\t\t\t{\n\t\t\t\tdeque[qe] = Coord (row, col);\n\t\t\t\tqe += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tqb -= 1;\n\t\t\t\tdeque[qb] = Coord (row, col);\n\t\t\t}\n\t\t\tboard[row][col] = '+';\n\t\t\tf[row][col] = extra + add;\n\t\t}\n\n\t\tgo (sRow, sCol, 0, 0);\n\n\t\twhile (qb < qe)\n\t\t{\n\t\t\tint row = deque[qb].row;\n\t\t\tint col = deque[qb].col;\n\t\t\tint extra = f[row][col];\n\t\t\tqb += 1;\n\n\t\t\tgo (row - 1, col, extra, 0);\n\t\t\tgo (row + 1, col, extra, 0);\n\n\t\t\t{\n\t\t\t\tint nRow = row;\n\t\t\t\tint nCol = col + 1;\n\t\t\t\tint add = (nCol <= sCol);\n\t\t\t\tint rSteps = max (0, nCol - sCol) +\n\t\t\t\t extra + add;\n\t\t\t\tif (rSteps <= rLimit)\n\t\t\t\t{\n\t\t\t\t\tgo (nRow, nCol, extra, add);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tint nRow = row;\n\t\t\t\tint nCol = col - 1;\n\t\t\t\tint add = (sCol <= nCol);\n\t\t\t\tint lSteps = max (0, sCol - nCol) +\n\t\t\t\t extra + add;\n\t\t\t\tif (lSteps <= lLimit)\n\t\t\t\t{\n\t\t\t\t\tgo (nRow, nCol, extra, add);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdebug {writefln (\"%-(%s\\n%)\", board);}\n\t\twriteln (board.map !(line => line.count ('+')).sum);\n\t\tbreak;\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n int r, c;\n readf(\"%s %s\", &r, &c);\n readln;\n --r, --c;\n \n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n string[] arr;\n foreach (_; 0 .. n) { arr ~= readln.chomp; }\n \n auto vis = new int[][][] (n, m, 2);\n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n vis[i][j].fill([-1, -1]);\n }\n }\n \n int bfs(int sx, int sy, int mvle, int mvr) {\n auto q = make!(DList!(Tuple!(int, int)));\n \n vis[sx][sy] = [mvle, mvr];\n q.insertFront(tuple(sx, sy));\n \n auto dirs = [[-1, 0], [1, 0], [0, -1], [0, 1]];\n auto qback = (int a, int b) => q.insertBack(tuple(a, b));\n auto qfront = (int a, int b) => q.insertFront(tuple(a, b));\n auto qfunc = [qfront, qfront, qback, qback];\n auto rcchg = [(int a, int b) => [a, b], (int a, int b) => [a, b], \n (int a, int b) => [a-1, b], (int a, int b) => [a, b-1]];\n \n int ans = 0;\n while (! q.empty()) {\n auto t = q.front;\n q.removeFront();\n \n debug { writeln(t, ' ', vis[t[0]][t[1]]); }\n ++ans;\n auto cx = t[0], cy = t[1];\n auto cle = vis[cx][cy][0], cr = vis[cx][cy][1];\n \n \n foreach (i; 0 .. 4) {\n int nx = cx + dirs[i][0], ny = cy + dirs[i][1];\n if (nx < 0 || nx >= n || ny < 0 || ny >= m) { continue; }\n if (arr[nx][ny] == '*') { continue; }\n \n if (vis[nx][ny][0] != -1) { continue; }\n \n auto nchg = rcchg[i](cle, cr);\n if (nchg[0] < 0 || nchg[1] < 0) { continue; }\n \n vis[nx][ny] = nchg;\n qfunc[i](nx, ny);\n }\n }\n \n return ans;\n }\n \n bfs(r, c, x, y).writeln;\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint rows, cols;\n\twhile (readf (\" %s %s\", &rows, &cols) > 0)\n\t{\n\t\tint sRow, sCol;\n\t\treadf (\" %s %s\", &sRow, &sCol);\n\t\tint lLimit, rLimit;\n\t\treadf (\" %s %s\", &lLimit, &rLimit);\n\t\tauto board = new char [] [] (rows + 2, cols + 2);\n\t\tforeach (ref line; board)\n\t\t{\n\t\t\tline[] = '#';\n\t\t}\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\treadf (\" %s\", &board[row + 1][col + 1]);\n\t\t\t}\n\t\t}\n\n\t\talias Coord = Tuple !(int, q{row}, int, q{col});\n\t\tauto deque = new Coord [rows * cols * 2 + 1];\n\t\tint qb = rows * cols;\n\t\tint qe = rows * cols;\n\t\tauto f = new int [] [] (rows + 2, cols + 2);\n\n\t\tvoid go (int row, int col, int extra, int add)\n\t\t{\n\t\t\tif (board[row][col] != '.')\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (add)\n\t\t\t{\n\t\t\t\tdeque[qe] = Coord (row, col);\n\t\t\t\tqe += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tqb -= 1;\n\t\t\t\tdeque[qb] = Coord (row, col);\n\t\t\t}\n\t\t\tboard[row][col] = '+';\n\t\t\tf[row][col] = extra + add;\n\t\t}\n\n\t\tqb -= 1;\n\t\tdeque[qb] = Coord (sRow, sCol);\n\t\tboard[sRow][sCol] = '+';\n\n\t\twhile (qb < qe)\n\t\t{\n\t\t\tint row = deque[qb].row;\n\t\t\tint col = deque[qb].col;\n\t\t\tint extra = f[row][col];\n\t\t\tqb += 1;\n\n\t\t\tgo (row - 1, col, extra, 0);\n\t\t\tgo (row + 1, col, extra, 0);\n\n\t\t\t{\n\t\t\t\tint nRow = row;\n\t\t\t\tint nCol = col + 1;\n\t\t\t\tint add = (nCol <= sCol);\n\t\t\t\tint rSteps = max (0, nCol - sCol) +\n\t\t\t\t extra + add;\n\t\t\t\tif (rSteps <= rLimit)\n\t\t\t\t{\n\t\t\t\t\tgo (nRow, nCol, extra, add);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tint nRow = row;\n\t\t\t\tint nCol = col - 1;\n\t\t\t\tint add = (sCol <= nCol);\n\t\t\t\tint lSteps = max (0, sCol - nCol) +\n\t\t\t\t extra + add;\n\t\t\t\tif (lSteps <= lLimit)\n\t\t\t\t{\n\t\t\t\t\tgo (nRow, nCol, extra, add);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdebug {writefln (\"%-(%s\\n%)\", board);}\n\t\twriteln (board.map !(line => line.count ('+')).sum);\n\t}\n}\n"}], "src_uid": "cfdbe4bd1c9438de2d871768c546a580"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 7;\nalias Mint = ModInt!MO;\n\nint N;\nMint[] A;\nint[] U, V;\n\nint[][] G;\nint[] par;\nMint[][] dp, DP;\n\nvoid dfs(int u, int p) {\n par[u] = p;\n foreach (v; G[u]) {\n if (v != p) {\n dfs(v, u);\n }\n }\n auto sums = new Mint[2];\n foreach (v; G[u]) {\n if (v != p) {\n // add dp[v]\n sums[] += dp[v][];\n }\n }\n // calc dp[u]\n dp[u][0] = sums[1];\n dp[u][1] = 1 + sums[0];\n}\n\nvoid DFS(int u, int p) {\n auto sums = new Mint[2];\n foreach (v; G[u]) {\n if (v != p) {\n // add dp[v]\n sums[] += dp[v][];\n }\n }\n if (p != -1) {\n // add DP[u]\n sums[] += DP[u][];\n }\n foreach (v; G[u]) {\n if (v != p) {\n // calc DP[v], removing dp[v]\n sums[] -= dp[v][];\n DP[v][0] = sums[1];\n DP[v][1] = 1 + sums[0];\n sums[] += dp[v][];\n }\n }\n foreach (v; G[u]) {\n if (v != p) {\n DFS(v, u);\n }\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n A = new Mint[N];\n foreach (u; 0 .. N) {\n A[u] = Mint(readLong());\n }\n U = new int[N - 1];\n V = new int[N - 1];\n foreach (i; 0 .. N - 1) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n G = new int[][N];\n foreach (i; 0 .. N - 1) {\n G[U[i]] ~= V[i];\n G[V[i]] ~= U[i];\n }\n par = new int[N];\n dp = new Mint[][](N, 2);\n DP = new Mint[][](N, 2);\n const rt = 0;\n dfs(rt, -1);\n DFS(rt, -1);\n debug {\n writeln(\"rt = \", rt);\n writeln(\"dp = \", dp);\n writeln(\"DP = \", DP);\n }\n \n Mint ans;\n foreach (u; 0 .. N) {\n auto sums = new Mint[2];\n Mint[][] seq;\n foreach (v; G[u]) {\n if (v != par[u]) {\n // add dp[v]\n sums[] += dp[v][];\n seq ~= dp[v];\n }\n }\n if (u != rt) {\n // add DP[u]\n sums[] += DP[u][];\n seq ~= DP[u];\n }\n // rooted at u\n Mint sum;\n sum += 1 * 1;\n sum += 1 * sums[0];\n sum += 1 * sums[1];\n foreach (j; 0 .. seq.length) {\n sum += seq[j][0] * 1;\n sum -= seq[j][1] * 1;\n sum += seq[j][0] * (sums[0] - seq[j][0]);\n sum += seq[j][0] * (sums[1] - seq[j][1]);\n sum -= seq[j][1] * (sums[0] - seq[j][0]);\n sum -= seq[j][1] * (sums[1] - seq[j][1]);\n }\n debug {\n writeln(u, \": \", sum);\n }\n ans += A[u] * sum;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nconst mod = 10^^9+7;\nalias mint = FactorRing!mod;\n\nvoid main()\n{\n int n; readV(n);\n int[] w; readA(n, w);\n\n auto g = Graph!int(n);\n foreach (_; 0..n-1) {\n int u, v; readV(u, v);\n g.addEdgeB(--u, --v);\n }\n auto t = makeTree(g).rootify(0);\n\n auto ei = new int[int][](n);\n foreach (u; 0..n)\n foreach (int i, v; g[u]) ei[u][v] = i;\n\n auto vc = new VC[][](n), vct = new VC[](n);\n foreach (u; 0..n) vc[u] = new VC[](g[u].length);\n\n auto q = DList!int([0]), rt = new int[](0);\n while (!q.empty) {\n auto u = q.front; q.removeFront();\n rt ~= u;\n foreach (v; t[u])\n if (v != t.parent[u])\n q.insertBack(v);\n }\n rt = rt[1..$];\n\n foreach_reverse (u; rt) {\n auto p = t.parent[u];\n auto vci = VC(1, 0);\n foreach (i, v; g[u])\n if (v != p)\n vci = vci + vc[u][i].inv;\n vc[p][ei[p][u]] = vci;\n }\n\n foreach (u; 0..n)\n foreach (vci; vc[u])\n vct[u] = vct[u] + vci;\n\n foreach (u; rt) {\n auto p = t.parent[u];\n vc[u][ei[u][p]] = VC(1, 0) + (vct[p] - vc[p][ei[p][u]]).inv;\n vct[u] = vct[u] + vc[u][ei[u][p]];\n }\n\n auto ans = mint(0);\n foreach (u; 0..n) {\n auto vcti = vct[u];\n auto eo = mint(1);\n eo += vcti.o + vcti.e;\n eo += vcti.o - vcti.e;\n foreach (i, v; g[u]) {\n auto vci = vc[u][i], rvci = vcti - vci;\n eo += (mint(vci.o) - vci.e) * (rvci.o + rvci.e);\n }\n ans += eo * w[u];\n }\n\n writeln(ans);\n}\n\nstruct VC\n{\n int e, o;\n auto inv() { return VC(o, e); }\n auto opBinary(string op: \"+\")(VC a) { return VC(e+a.e, o+a.o); }\n auto opBinary(string op: \"-\")(VC a) { return VC(e-a.e, o-a.o); }\n}\n\nstruct Graph(N = int)\n{\n alias Node = N;\n Node n;\n Node[][] g;\n alias g this;\n this(Node n) { this.n = n; g = new Node[][](n); }\n void addEdge(Node u, Node v) { g[u] ~= v; }\n void addEdgeB(Node u, Node v) { g[u] ~= v; g[v] ~= u; }\n}\n\nstruct Tree(Graph)\n{\n import std.algorithm, std.container;\n alias Node = Graph.Node;\n Graph g;\n alias g this;\n Node root;\n Node[] parent;\n int[] size, depth;\n\n this(ref Graph g) { this.g = g; this.n = g.n; }\n\n ref auto rootify(Node r)\n {\n this.root = r;\n\n parent = new Node[](g.n);\n depth = new int[](g.n);\n depth[] = -1;\n\n struct UP { Node u, p; }\n auto st1 = SList!UP(UP(r, r));\n auto st2 = SList!UP();\n while (!st1.empty) {\n auto up = st1.front, u = up.u, p = up.p; st1.removeFront();\n\n parent[u] = p;\n depth[u] = depth[p] + 1;\n\n foreach (v; g[u])\n if (v != p) {\n st1.insertFront(UP(v, u));\n st2.insertFront(UP(v, u));\n }\n }\n\n size = new int[](g.n);\n size[] = 1;\n\n while (!st2.empty) {\n auto up = st2.front, u = up.u, p = up.p; st2.removeFront();\n size[p] += size[u];\n }\n\n return this;\n }\n\n auto children(Node u) { return g[u].filter!(v => v != parent[u]); }\n}\nref auto makeTree(Graph)(ref Graph g) { return Tree!Graph(g); }\n\nstruct FactorRing(int m, bool pos = false)\n{\n version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }\n alias FR = FactorRing!(m, pos);\n @property static init() { return FR(0); }\n @property int value() { return vi; }\n @property void value(int v) { vi = mod(v); }\n alias value this;\n\n this(int v) { vi = v; }\n this(int v, bool runMod) { vi = runMod ? mod(v) : v; }\n this(long v) { vi = mod(v); }\n\n ref auto opAssign(int v) { vi = v; return this; }\n\n pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }\n pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }\n\n static if (!pos) pure ref auto opUnary(string op: \"-\")() { return FR(mod(-vi)); }\n\n static if (m < int.max / 2) {\n pure ref auto opBinary(string op)(int r) if (op == \"+\" || op == \"-\") { return FR(mod(mixin(\"vi\"~op~\"r\"))); }\n ref auto opOpAssign(string op)(int r) if (op == \"+\" || op == \"-\") { vi = mod(mixin(\"vi\"~op~\"r\")); return this; }\n } else {\n pure ref auto opBinary(string op)(int r) if (op == \"+\" || op == \"-\") { return FR(mod(mixin(\"vl\"~op~\"r\"))); }\n ref auto opOpAssign(string op)(int r) if (op == \"+\" || op == \"-\") { vi = mod(mixin(\"vl\"~op~\"r\")); return this; }\n }\n pure ref auto opBinary(string op: \"*\")(int r) { return FR(mod(vl*r)); }\n ref auto opOpAssign(string op: \"*\")(int r) { vi = mod(vl*r); return this; }\n\n pure ref auto opBinary(string op)(ref FR r) if (op == \"+\" || op == \"-\" || op == \"*\") { return opBinary!op(r.vi); }\n ref auto opOpAssign(string op)(ref FR r) if (op == \"+\" || op == \"-\" || op == \"*\") { return opOpAssign!op(r.vi); }\n}\n"}], "negative_code": [], "src_uid": "4357300b397ad91bfb5ce81a29abfdd6"} {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\treadln;\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tfor (int w = 3; ; w += w + 1)\n\t\t{\n\t\t\tif (n % w == 0)\n\t\t\t{\n\t\t\t\twriteln (n / w);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!long;\n long x = 1;\n foreach (k; 1..34) {\n x += 1L<<k;\n if (N%x == 0) {\n writeln(N/x);\n break;\n }\n }\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tlong a = 3;\n\t\twhile (true)\n\t\t{\n\t\t\tif (n % a == 0)\n\t\t\t{\n\t\t\t\tans[ti] = n / a;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ta <<= 1;\n\t\t\t++a;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "d04cbe78b836e53b51292401c8c969b2"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint P;\nint N;\nint[] X;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tP = readInt;\n\t\tN = readInt;\n\t\tX = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tX[i] = readInt;\n\t\t}\n\t\t\n\t\tint ans = -1;\n\t\tbool[] app = new bool[P];\n\t\tforeach (i; 0 .. N) {\n\t\t\tconst key = X[i] % P;\n\t\t\tif (app[key]) {\n\t\t\t\tans = i + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tapp[key] = true;\n\t\t}\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.bigint;\nimport std.array;\nimport std.ascii;\nimport std.math;\nimport std.numeric;\nimport std.algorithm;\nimport std.container;\nimport core.bitop;\nimport std.conv;\n\nalias Int = long;\n\nvoid main() {\n int p, n;\n readf(\" %s\", &p);\n readf(\" %s\", &n);\n auto list = new bool[300 + 1];\n list[] = false;\n foreach ( i; 0 .. n ) {\n Int x;\n readf(\" %s\", &x);\n if ( list[x % p] ) {\n writeln(i + 1);\n return;\n }\n list[x % p] = true;\n }\n writeln(-1);\n}\n"}, {"source_code": "//http://codeforces.com/contest/447/problem/A\n\nimport std.stdio;\n\nvoid main(){\n uint p,n;\n readf(\"%s \",&p);\n readf(\"%s \",&n);\n uint[] l = new uint[n];\n for(uint i = 0; i < n; i++){\n readf(\"%s \",&l[i]);\n }\n writefln(\"%s\",run(p,l));\n}\n\nlong run(uint n, uint[] l){\n bool[] mt = new bool[n];\n for(uint i = 0; i < n; i++){\n mt[i] = false;\n }\n\n uint j = 0;\n foreach(uint x; l){\n uint h = x % n;\n if (mt[h] == false) {\n mt[h] = true;\n } else {\n return j + 1;\n }\n j++;\n }\n\n return -1;\n}\n\n\n// TEST CASE AREA\n// void test_case(){\n// uint[][] rs;\n// rs ~= [run(10,[0,21,53,41,53]),4];\n// rs ~= [run(5,[0,1,2,3,4]),-1];\n//\n// array_assert(rs);\n// }\n//\n// void array_assert(uint[][] rs){\n// uint i = 1;\n// bool failed = false;\n// foreach(uint[] r;rs){\n// if(r[0] != r[1]){\n// failed = true;\n// writefln(\"%s Failed %s is NOT %s\",i,r[0],r[1]);\n// }\n// i++;\n// }\n//\n// if(!failed){\n// writefln(\"OK\");\n// }\n// }\n"}, {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nint P, N;\nint[] X;\nvoid main() {\n scanf(\"%d %d\\n\", &P, &N);\n\n int h(int x) {\n return x % P;\n }\n\n X = new int[P];\n X[] = -1;\n foreach (i; 0 .. N) {\n int x;\n scanf(\"%d\\n\", &x);\n int y = h(x);\n if (X[y] >= 0) {\n writeln(i + 1);\n return;\n } else {\n X[y] = x;\n }\n }\n writeln(-1);\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.container, std.conv, std.typecons, std.range, std.string;\n\nvoid main() {\n int p, n;\n readf(\"%s %s\\n\", &p, &n);\n auto s = redBlackTree!int();\n int x, i, c=1;\n for (i=0; i<n; i++) {\n x = (readln.strip.to!int) % p;\n if (!(x in s)) {\n c++;\n } else break;\n s.insert(x);\n }\n if (i==n)\n writeln(-1);\n else\n writeln(c);\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.container, std.conv, std.typecons, std.range, std.string;\n\nvoid main() {\n int p, n;\n readf(\"%s %s\\n\", &p, &n);\n auto s = redBlackTree!int();\n int x, i;\n for (i=0; i<n; i++) {\n x = (readln.strip.to!int) % p;\n if (x in s) {\n i++;\n break;\n }\n s.insert(x);\n }\n if (i==n)\n writeln(-1);\n else\n writeln(i);\n}\n"}], "src_uid": "5d5dfa4f129bda46055fb636ef33515f"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto ad = readln.split.to!(long[]);\n auto A = ad[0];\n auto B = ad[1];\n auto C = ad[2];\n auto D = ad[3];\n\n if (A <= B) {\n writeln(B);\n continue;\n }\n\n auto e = C - D;\n if (e <= 0) {\n writeln(-1);\n continue;\n }\n\n A -= B;\n auto f = (A + e - 1) / e;\n writeln(B + C * f);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto c = RD;\n\t\tauto d = RD;\n\n\t\ta -= b;\n\t\tans[ti] = b;\n\t\tif (a <= 0) continue;\n\n\t\tauto e = c - d;\n\t\tif (e <= 0)\n\t\t{\n\t\t\tans[ti] = -1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tans[ti] += c * ((a+e-1) / e);\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "1ab174688ba76168ca047ed2b06b0670"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n\n auto dp = new int[][](N, 3);\n dp[0][0] = dp[0][1] = 1;\n\n foreach (i; 1..N) {\n bool same = (S[i] == S[i-1]);\n dp[i][0] = dp[i-1][0] + !same;\n dp[i][1] = max(dp[i-1][0]+same, dp[i-1][1]+!same);\n dp[i][2] = max(dp[i-1][1]+same, dp[i-1][2]+!same);\n }\n\n int ans = 0;\n foreach (i; 0..N) foreach (j; 0..3) ans = max(ans, dp[i][j]);\n writeln(ans);\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.range, std.stdio;\nvoid main () {\n\treadln;\n\tauto s = readln, n = s.length - 1, res = (n - 1).iota.map !(i => s[i] != s[i + 1]).sum;\n\tn.min (res + 3).writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln ();\n\t\tauto s = readln.strip;\n\t\tauto res = (n - 1).iota.map !(i => s[i] != s[i + 1]).sum;\n\t\tres = min (res + 3, n);\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "7b56edf7cc71a1b3e39b3057a4387cad"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (sum (a, 0L) + sum (b, 0L) - maxElement (b));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n = readln.strip.to!long;\n auto a = readln.splitter.map!(to!long).array;\n auto b = readln.splitter.map!(to!long).array;\n writeln(a.sum + b.sum - b.maxElement);\n }\n}\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!long;\r\n auto B = readarray!long;\r\n\r\n auto r = B.reduce!max;\r\n writeln(A.reduce!\"a+b\" + B.reduce!\"a+b\" - r);\r\n}\r\n"}], "negative_code": [], "src_uid": "5c75658faf6dda4d7e21e1dcf39b350a"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto D = readln.chomp.split(\" \").map!(to!int).array;\n auto X = new int[N];\n foreach (int i, j; D) {\n X[j - 1] = i + 1;\n }\n writefln(\"%(%s %)\", X);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n auto p = readln.chomp.split.map!(to!int);\n\n auto ans = new int[n];\n\n for (int i = 0; i < n; i++) {\n ans[p[i]-1] = i + 1;\n }\n\n ans.map!(to!string).join(\" \").writeln;\n}\n"}, {"source_code": "import std.stdio;\n\n/*\n * pi: numero della persona che ha dato il regalo alla persona\n * i. Potrebbe essere che pi == i e inoltre si sa che pi != pk per\n * ogni i != k.\n */\nint[] gifters(int[] pis, int n) {\n int[] gifters;\n gifters.length = n;\n for (int i=0; i < n; i++) {\n gifters[(pis[i] - 1)] = i + 1;\n }\n return gifters;\n}\n\nvoid print_gifters(int[] gifters) {\n for (int i = 0; i < gifters.length; i++) {\n if (i == 0)\n writef(\"%s\", gifters[i]);\n else\n writef(\" %s\", gifters[i]);\n }\n}\n\nint main() {\n int n, pi;\n readf(\"%s\", &n);\n int[] pis;\n pis.length = n;\n for (int i=0; i < n; i++) {\n readf(\" %s\", &pi);\n pis[i] = pi;\n }\n print_gifters(gifters(pis, n));\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.math;\nimport std.algorithm;\n\nclass Friend\n{\n\tpublic int f;\n\tpublic int p;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tFriend[] friends;\n\tfriends.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tfriends[i] = new Friend();\n\t\tscanf(\"%d\", &(friends[i].f));\n\t\tfriends[i].p = i;\n\t}\n\tsort!(\"a.f < b.f\", SwapStrategy.stable)(friends);\n\tforeach (int i; 0..n)\n\t{\n\t\tprintf((i < n-1) ? \"%d \" : \"%d\", (friends[i].p + 1));\n\t}\n\treturn 0;\n}\n"}], "negative_code": [], "src_uid": "48bb148e2c4d003cad9d57e7b1ab78fb"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.splitter.map !(to !(long)).array;\n\t\tsort (s);\n\n\t\tlong [] v;\n\t\tv.reserve (n - 1);\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tv ~= s[i] - s[i - 1];\n\t\t}\n\t\tsort (v);\n\t\tdebug {writeln (v);}\n\n\t\tlong [] c;\n\t\tc.reserve (n);\n\t\tc ~= 0;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tc ~= c[$ - 1] + v[i - 1];\n\t\t}\n\t\tdebug {writeln (c);}\n\n\t\tlong solve (long d)\n\t\t{\n\t\t\tint lo = 0;\n\t\t\tint hi = n - 1;\n\t\t\twhile (lo < hi)\n\t\t\t{\n\t\t\t\tint me = (lo + hi) / 2;\n\t\t\t\tif (v[me] <= d)\n\t\t\t\t{\n\t\t\t\t\tlo = me + 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\thi = me;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (lo, \" \", d, \" \", n - 1 - lo);}\n\t\t\treturn c[lo] + (d + 1) * (n - lo);\n\t\t}\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tlong [] res;\n\t\tres.reserve (q);\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tlong l, r;\n\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\tlong d = r - l;\n\t\t\tres ~= solve (d);\n\t\t}\n\t\twritefln (\"%(%s %)\", res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 3 * 10L^^18;\n\nint N;\nlong[] S;\nint Q;\nlong[] L, R;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n S = new long[N];\n foreach (i; 0 .. N) {\n S[i] = readLong();\n }\n Q = readInt();\n L = new long[Q];\n R = new long[Q];\n foreach (q; 0 .. Q) {\n L[q] = readLong();\n R[q] = readLong();\n }\n \n S.sort;\n \n auto ds = new long[N];\n foreach (i; 0 .. N - 1) {\n ds[i] = S[i + 1] - S[i];\n }\n ds[N - 1] = INF;\n ds.sort;\n \n auto dsSum = new long[N + 1];\n foreach (i; 0 .. N) {\n dsSum[i + 1] = dsSum[i] + ds[i];\n }\n \n auto ans = new long[Q];\n foreach (q; 0 .. Q) {\n const pos = ds.lowerBound(R[q] - L[q] + 1);\n ans[q] = dsSum[pos] + (R[q] - L[q] + 1) * (N - pos);\n }\n foreach (q; 0 .. Q) {\n if (q > 0) {\n write(\" \");\n }\n write(ans[q]);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "536a582f3620a733d09cf80662488590"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nconst long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n auto zero = N.iota.filter!(i => A[i] == 0).map!(i => tuple(i+1, A[i])).array;\n auto minus = N.iota.filter!(i => A[i] < 0).map!(i => tuple(i+1, A[i])).array;\n auto plus = N.iota.filter!(i => A[i] > 0).map!(i => tuple(i+1, A[i])).array;\n minus.sort!(\"a[1] < b[1]\")();\n int cnt = N - 1;\n bool nozero = false;\n\n if (minus.length % 2 == 1) {\n if (zero.length > 0) {\n zero ~= minus.back;\n minus.popBack;\n foreach (i; 0..zero.length.to!int-1) {\n writeln(1, \" \", zero[i][0], \" \", zero[i+1][0]);\n cnt--;\n }\n if (cnt > 0) {\n writeln(2, \" \", zero.back[0]);\n --cnt;\n }\n nozero = true;\n } else {\n writeln(2, \" \", minus.back[0]);\n minus.popBack;\n --cnt;\n }\n } else if (zero.length > 0) {\n foreach (i; 0..zero.length.to!int-1) {\n writeln(1, \" \", zero[i][0], \" \", zero[i+1][0]);\n cnt--;\n }\n if (cnt > 0) {\n writeln(2, \" \", zero.back[0]);\n --cnt;\n }\n nozero = true;\n }\n\n auto rest = minus ~ plus;\n int len = rest.length.to!int;\n\n while (cnt > 0) {\n int x = rest.back[0];\n rest.popBack;\n int y = rest.back[0];\n writeln(1, \" \", x, \" \", y);\n cnt--;\n }\n}\n", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n auto a=readln.split.to!(int[]);\n\n auto count=reduce!((r, e)=>r+(e==0 ? 1 : 0))(0, a);\n auto minus=reduce!((r, e)=>r+(e<0 ? 1 : 0))(0, a);\n int[][] ans;\n if(count==0){\n if(minus%2==0){\n for(int i=1; i<n; i++){\n ans~=[1, i, i+1];\n }\n }else{\n int pos=-1;\n foreach(int i, e; a){\n if(e<0){\n if(pos==-1){\n pos=i;\n }else{\n if(a[pos]<e){\n pos=i;\n }\n }\n }\n }\n writeln(2, \" \", pos+1);\n if(pos==0){\n for(int i=2; i<n; i++){\n ans~=[1, i, i+1];\n }\n }else if(pos==n-1){\n for(int i=1; i+1<n; i++){\n ans~=[1, i, i+1];\n }\n }else{\n for(int i=1; i<n; i++){\n if(i+1==pos+1){\n ans~=[1, i, i+2];\n i++;\n }else{\n ans~=[1, i, i+1];\n }\n }\n }\n }\n }else{\n int cnt=0;\n int zeropos=-1;\n if(count>=2){\n int last=-1;\n foreach(int i, e; a){ // \u6700\u53f3\u306e0\u306b\u5bc4\u305b\u308b\n if(e==0){\n if(last>=0){\n writeln(1, \" \", last+1, \" \", i+1);\n cnt++;\n }\n last=i;\n zeropos=i;\n }\n }\n }\n for(int i=n-1; i>=0; i--){\n if(a[i]==0){\n zeropos=i;\n break;\n }\n }\n int pos=-1;\n if(minus&1){\n foreach(int i, e; a){\n if(e<0){\n if(pos==-1){\n pos=i;\n }else{\n if(a[pos]<e){\n pos=i;\n }\n }\n }\n }\n writeln(1, \" \", pos+1, \" \", zeropos+1);\n cnt++;\n }\n if(cnt+1<n){\n writeln(2, \" \", zeropos+1);\n }\n int last=-1;\n foreach(int i, e; a){\n if(e==0 || i==pos || i==zeropos) continue;\n if(last>=0){\n ans~=[1, last+1, i+1];\n }\n last=i;\n }\n }\n\n foreach(aa; ans){\n writefln(\"%(%s %)\", aa);\n }\n\n}\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nconst long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n auto zero = N.iota.filter!(i => A[i] == 0).map!(i => tuple(i+1, A[i])).array;\n auto minus = N.iota.filter!(i => A[i] < 0).map!(i => tuple(i+1, A[i])).array;\n auto plus = N.iota.filter!(i => A[i] > 0).map!(i => tuple(i+1, A[i])).array;\n minus.sort!(\"a[1] < b[1]\")();\n int cnt = N - 1;\n bool nozero = false;\n\n if (minus.length % 2 == 1) {\n writeln(2, \" \", minus.back[0]);\n minus.popBack;\n cnt--;\n } else if (zero.length > 0) {\n foreach (i; 0..zero.length.to!int-1) {\n writeln(1, \" \", zero[i][0], \" \", zero[i+1][0]);\n cnt--;\n }\n if (cnt > 0) {\n writeln(2, \" \", zero.back[0]);\n --cnt;\n }\n nozero = true;\n }\n\n auto rest = minus ~ plus;\n if (!nozero) rest ~= zero;\n\n foreach (i; 0..rest.length.to!int-1) {\n int x = rest.back[0];\n rest.popBack;\n int y = rest.back[0];\n writeln(1, \" \", x, \" \", y);\n cnt--;\n }\n}\n"}], "src_uid": "f09b435a20a415d65803a80d57152832"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n int N; get(N);\r\n int[] AA; get(AA);\r\n\r\n auto res = new int[](N);\r\n void solve(int l, int r, int d) {\r\n if (l == r) return;\r\n\r\n int p, max_a;\r\n foreach (i; l..r) if (AA[i] > max_a) {\r\n max_a = AA[i];\r\n p = i;\r\n }\r\n res[p] = d;\r\n solve(l, p, d + 1);\r\n solve(p + 1, r, d + 1);\r\n }\r\n solve(0, N, 0);\r\n writefln!\"%(%d %)\"(res);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto d = new int [n];\r\n\r\n\t\tvoid build (int lo, int hi, int depth)\r\n\t\t{\r\n\t\t\tif (lo >= hi)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tauto me = hi - maxPos (a[lo..hi]).length.to !(int);\r\n\t\t\td[me] = depth;\r\n\t\t\tbuild (lo, me, depth + 1);\r\n\t\t\tbuild (me + 1, hi, depth + 1);\r\n\t\t}\r\n\r\n\t\tbuild (0, n, 0);\r\n\t\twritefln !(\"%(%s %)\") (d);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA!int;\r\n\r\n\t\tans[ti].length = n;\r\n\t\tvoid dfs(int pos, int depth)\r\n\t\t{\r\n\t\t\tans[ti][pos] = depth;\r\n\t\t\tauto x = a[pos];\r\n\t\t\t{\r\n\t\t\t\tint j = -1, y;\r\n\t\t\t\tforeach_reverse (i; 0..pos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (a[i] > x) break;\r\n\t\t\t\t\tif (a[i] > y)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tj = i;\r\n\t\t\t\t\t\ty = a[j];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (j != -1)\r\n\t\t\t\t\tdfs(j, depth+1);\r\n\t\t\t}\r\n\t\t\t{\r\n\t\t\t\tint j = -1, y;\r\n\t\t\t\tforeach (i; pos+1..n)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (a[i] > x) break;\r\n\t\t\t\t\tif (a[i] > y)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tj = i;\r\n\t\t\t\t\t\ty = a[j];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (j != -1)\r\n\t\t\t\t\tdfs(j, depth+1);\r\n\t\t\t}\r\n\t\t}\r\n\t\tint p;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] > a[p])\r\n\t\t\t\tp = i;\r\n\t\t}\r\n\t\tdfs(p, 0);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "a564017f9c411b39f8d4b69e629ae3bc"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.array;\n\nvoid main() {\n uint n, q; readf(\"%d %d\\n\", &n, &q);\n ulong[] a = stdin.readln.split.map!(to!ulong).array;\n ulong[] c = new ulong[a.length + 1]; c.fill(0);\n foreach (i; 0 .. q) {\n int f, t; readf(\"%d %d\\n\", &f, &t); f--; t--;\n c[f]++;\n c[t + 1]--;\n }\n ulong acc = 0;\n foreach (ref e; c) {\n acc += e;\n e = acc;\n }\n auto o = c[0 .. $ - 1].sort;\n auto x = a.sort;\n ulong ans = 0;\n foreach (i; 0 .. o.length) {\n ans += o[i] * x[i];\n }\n writeln(ans);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.array;\n\nvoid main() {\n uint n, q; readf(\"%d %d\\n\", &n, &q);\n ulong[] a = stdin.readln.split.map!(to!ulong).array;\n ulong[] c = new ulong[a.length + 1]; c.fill(0);\n foreach (i; 0 .. q) {\n int f, t; readf(\"%d %d\\n\", &f, &t); f--; t--;\n c[f]++;\n c[t + 1]--;\n }\n ulong acc = 0;\n foreach (ref e; c) {\n acc += e;\n e = acc;\n }\n ulong[] o = c[0 .. $ - 1].sort!(\"a > b\").array;\n ulong[] x = a.sort!(\"a > b\").array;\n ulong ans = 0;\n foreach (i; 0 .. o.length) {\n ans += o[i] * x[i];\n }\n writeln(ans);\n}\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,q;\n readf!\"%d %d\"(n,q);\n readln;\n int[] a=readln.splitter\n .map!(to!int)\n .array;\n long[] d=new long[n];\n int l,r;\n while(q--){\n readf!\"%d %d\"(l,r);\n readln;\n l--;\n d[l]++;\n if(r<n) d[r]--;\n }\n foreach(i;1..n)\n d[i]+=d[i-1];\n sort!\"a>b\"(d);\n sort!\"a>b\"(a); \n ulong ans=0;\n foreach(i;0..n)\n ans+=a[i]*d[i];\n writeln(ans);\n}\n\n"}], "negative_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,q;\n readf!\"%d %d\"(n,q);\n readln;\n int[] a=readln.splitter\n .map!(to!int)\n .array,\n d=new int[n];\n int l,r;\n while(q--){\n readf!\"%d %d\"(l,r);\n readln;\n l--;\n d[l]++;\n if(r<n) d[r]--;\n }\n foreach(i;1..n)\n d[i]+=d[i-1];\n sort!\"a>b\"(d);\n sort!\"a>b\"(a); \n ulong ans=0;\n foreach(i;0..n)\n ans+=a[i]*d[i];\n writeln(ans);\n}\n\n"}], "src_uid": "926ec28d1c80e7cbe0bb6d209e664f48"} {"source_code": "import std.stdio;\nimport std.string : split, strip;\nimport std.algorithm : chunkBy, map, maxElement, sum;\nimport std.conv : to;\n\nvoid main() {\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n\n auto s = readln.strip.split\n .map!(to!long)\n .chunkBy!((a, b) => (a > 0) == (b > 0))\n .map!maxElement\n .sum;\n writeln(s);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!long;\n long[][] as = [[]];\n size_t i;\n long last = 0;\n foreach (a; readln.split.to!(long[])) {\n if (last*a < 0) {\n sort!\"a > b\"(as[i]);\n ++i;\n as ~= [[]];\n }\n as[i] ~= a;\n last = a;\n }\n sort!\"a > b\"(as[i]);\n long s;\n foreach (a; as) s += a[0];\n writeln(s);\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\treadln;\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\treadln\n\t\t .splitter\n\t\t .map !(to !(int))\n\t\t .chunkBy !(q{(a > 0) == (b > 0)})\n\t\t .map !(maxElement)\n\t\t .sum (0L)\n\t\t .writeln;\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tlong m = a[0];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] * a[i-1] < 0)\n\t\t\t{\n\t\t\t\tans[ti] += m;\n\t\t\t\tm = long.min;\n\t\t\t}\n\t\t\tm.chmax(a[i]);\n\t\t}\n\t\tans[ti] += m;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "39480cdf697fc9743dc9665f989077d7"} {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.math, std.numeric, std.stdio, std.typecons;\nimmutable int MUCH = 70;\nvoid main ()\n{\n int n;\n while (readf (\" %s\", &n) > 0)\n {\n alias Point = Tuple !(int, \"x\", int, \"y\");\n auto a = new Point [n];\n foreach (ref p; a)\n readf (\" %s %s\", &p.x, &p.y);\n a ~= a;\n\n int d = min (MUCH, n - 2);\n auto mult = new real [d];\n foreach (i; 0..d)\n mult[i] = pow (2.0, d - i) - 1.0;\n mult[] /= (d < MUCH) ?\n pow (2.0, n) - 1 - n - n * 0.5 * (n - 1) :\n sum (mult) * 2;\n\n real res = 0;\n foreach (i; 0..n)\n foreach (k; 0..d)\n {\n int j = i + k + 1;\n real s = a[i].x - a[j].x;\n s *= a[j].y + a[i].y;\n s -= gcd (abs (a[j].x - a[i].x),\n abs (a[j].y - a[i].y));\n res += mult[k] * s;\n }\n writefln (\"%.20f\", res / 2 + 1);\n }\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.numeric, std.range, std.stdio;\nvoid main ()\n{\n int n, d, j;\n readf (\" %s \", &n);\n auto a = n.iota.map !(_ => readln.split.map !(to !(int)).array).array;\n a ~= a;\n d = min (50, n - 2);\n auto mult = d.iota.map !(i => pow (2.0, d - i) - 1.0).array;\n mult[] /= (d < 50) ? pow (2.0, n) - 1 - n - n * 0.5 * (n - 1) : sum (mult) * 2;\n real res = 0;\n res = sum (n.iota.map !(i => sum (iota (i + 1, i + d + 1).map !(j => mult[j - i - 1] *\n ((a[i][0] - a[j][0]) * 1.0 * (a[i][1] + a[j][1]) - gcd (abs (a[i][0] - a[j][0]), abs (a[i][1] - a[j][1])))))));\n writefln (\"%.20f\", res / 2 + 1);\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int MUCH = 70;\n\nint euclid (int a, int b)\n{\n\ta = abs (a);\n\tb = abs (b);\n\twhile (a && b)\n\t{\n\t\ta %= b;\n\t\tif (a)\n\t\t{\n\t\t\tb %= a;\n\t\t}\n\t}\n\treturn a + b;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Point = Tuple !(int, \"x\", int, \"y\");\n\t\tauto a = new Point [n];\n\t\tforeach (ref p; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &p.x, &p.y);\n\t\t}\n\t\ta ~= a;\n\n\t\tint d = min (MUCH, n - 2);\n\t\tauto mult = new real [d];\n\t\tforeach (i; 0..d)\n\t\t{\n\t\t\treal k = d - i;\n\t\t\tmult[i] = pow (2.0, k) - 1.0;\n\t\t}\n\t\treal ts;\n\t\tif (d < MUCH)\n\t\t{\n\t\t\treal total = pow (2.0, n);\n\t\t\treal skip = 1;\n\t\t\tskip += n;\n\t\t\tskip += n * 0.5 * (n - 1);\n\t\t\tts = total - skip;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tts = sum (mult) * 2;\n\t\t}\n\t\tdebug {writeln (\"ts = \", ts);}\n\t\tmult[] /= ts;\n\n\t\treal res = 0.0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (k; 0..d)\n\t\t\t{\n\t\t\t\tint j = i + k + 1;\n\t\t\t\treal s = (a[i].x - a[j].x);\n\t\t\t\ts *= (a[j].y + a[i].y);\n\t\t\t\tint t = euclid (a[j].x - a[i].x,\n\t\t\t\t a[j].y - a[i].y);\n//\t\t\t\tdebug {writeln (s, ' ', t, ' ', mult[k], ' ',\n//\t\t\t\t (s - t) * mult[k]);}\n\t\t\t\ts -= t;\n\t\t\t\tres += mult[k] * s;\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (\"raw res = \", res);}\n\t\tres /= 2;\n\t\tres += 1;\n\t\twritefln (\"%.20f\", res);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.numeric, std.range, std.stdio;\nvoid main()\n{\n int n, d;\n readf(\" %s \", &n);\n d = min(50, n - 2);\n auto a = n.iota.map!(_ => readln.split.map!(to!int).array).array, mult = d.iota.map!(i => pow(2.0, d - i) - 1).array;\n a ~= a;\n mult[] /= (d < 50) ? pow (2.0, n) - 1 - n - n * .5 * (n - 1) : mult.sum * 2;\n writef(\"%.9f\", sum(n.iota.map!(i => sum(iota(i + 1, i + d + 1).map!(j => mult[j - i - 1] * ((a[i][0] - a[j][0]) * 1. * (a[i][1] + a[j][1]) - gcd(abs(a[i][0] - a[j][0]), abs(a[i][1] - a[j][1]))))))) / 2 + 1);\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.numeric, std.range, std.stdio, std.string;\nvoid main ()\n{\n int n, d, j;\n readf (\" %s \", &n);\n int [] [] a;\n foreach (i; 0..n)\n a ~= readln.split.map !(to !(int)).array;\n a ~= a;\n d = min (70, n - 2);\n auto mult = d.iota.map !(i => pow (2.0, d - i) - 1.0).array;\n mult[] /= (d < 70) ? pow (2.0, n) - 1 - n - n * 0.5 * (n - 1) : sum (mult) * 2;\n real res = 0;\n foreach (i; 0..n)\n foreach (k; 0..d)\n {\n j = i + k + 1;\n real s = a[i][0] - a[j][0];\n s *= a[i][1] + a[j][1];\n s -= gcd (abs (a[i][0] - a[j][0]), abs (a[i][1] - a[j][1]));\n res += mult[k] * s;\n }\n writefln (\"%.20f\", res / 2 + 1);\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.math,std.numeric,std.range,std.stdio;\nvoid main()\n{\n int n,d;\n readf(\"%s \",&n);\n d=min(50,n-2);\n auto a=n.iota.map!(_=>readln.split.map!(to!int).array).array,m=d.iota.map!(i=>pow(2.,d-i)-1).array;\n a~=a,m[]/=(d<50)?pow(2.,n)-1-n-n*.5*(n-1):m.sum*2;\n writef(\"%.9f\",sum(n.iota.map!(i=>sum(iota(i+1,i+d+1).map!(j=>m[j-i-1]*((a[i][0]-a[j][0])*1.*(a[i][1]+a[j][1])-gcd(abs(a[i][0]-a[j][0]),abs(a[i][1]-a[j][1])))))))/2+1);\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int MUCH = 100;\n\nint euclid (int a, int b)\n{\n\ta = abs (a);\n\tb = abs (b);\n\twhile (a && b)\n\t{\n\t\ta %= b;\n\t\tif (a)\n\t\t{\n\t\t\tb %= a;\n\t\t}\n\t}\n\treturn a + b;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Point = Tuple !(int, \"x\", int, \"y\");\n\t\tauto a = new Point [n];\n\t\tforeach (ref p; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &p.x, &p.y);\n\t\t}\n\t\ta ~= a;\n\n\t\tint d = min (MUCH, n - 2);\n\t\tauto mult = new real [d];\n\t\tforeach (i; 0..d)\n\t\t{\n\t\t\treal k = d - i;\n\t\t\tmult[i] = pow (2.0, k) - 1.0;\n\t\t}\n\t\treal ts;\n\t\tif (d < MUCH)\n\t\t{\n\t\t\treal total = pow (2.0, n);\n\t\t\treal skip = 1;\n\t\t\tskip += n;\n\t\t\tskip += n * 0.5 * (n - 1);\n\t\t\tts = total - skip;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tts = sum (mult);\n\t\t}\n\t\tdebug {writeln (\"ts = \", ts);}\n\t\tmult[] /= ts;\n\n\t\treal res = 0.0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (k; 0..d)\n\t\t\t{\n\t\t\t\tint j = i + k + 1;\n\t\t\t\treal s = (a[i].x - a[j].x);\n\t\t\t\ts *= (a[j].y + a[i].y);\n\t\t\t\tint t = euclid (a[j].x - a[i].x,\n\t\t\t\t a[j].y - a[i].y);\n//\t\t\t\tdebug {writeln (s, ' ', t, ' ', mult[k], ' ',\n//\t\t\t\t (s - t) * mult[k]);}\n\t\t\t\ts -= t;\n\t\t\t\tres += mult[k] * s;\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (\"raw res = \", res);}\n\t\tres /= 2;\n\t\tres += 1;\n\t\twritefln (\"%.20f\", res);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.numeric, std.range, std.stdio;\nvoid main()\n{\n int n, d;\n readf(\" %s \", &n);\n auto a = n.iota.map!(_ => readln.split.map!(to!int).array).array;\n a ~= a;\n d = min (50, n - 2);\n auto mult = d.iota.map !(i => pow (2.0, d - i) - 1).array;\n mult[] /= (d < 50) ? pow (2.0, n) - 1 - n - n * .5 * (n - 1) : 2;\n writef(\"%.9f\", sum(n.iota.map!(i => sum(iota(i + 1, i + d + 1).map!(j => mult[j - i - 1] * ((a[i][0] - a[j][0]) * 1. * (a[i][1] + a[j][1]) - gcd(abs(a[i][0] - a[j][0]), abs(a[i][1] - a[j][1]))))))) / 2 + 1);\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int MUCH = 50;\n\nint euclid (int a, int b)\n{\n\ta = abs (a);\n\tb = abs (b);\n\twhile (a && b)\n\t{\n\t\ta %= b;\n\t\tif (a)\n\t\t{\n\t\t\tb %= a;\n\t\t}\n\t}\n\treturn a + b;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Point = Tuple !(int, \"x\", int, \"y\");\n\t\tauto a = new Point [n];\n\t\tforeach (ref p; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &p.x, &p.y);\n\t\t}\n\t\ta ~= a;\n\n\t\tint d = min (MUCH, n - 2);\n\t\tauto mult = new real [d];\n\t\tforeach (i; 0..d)\n\t\t{\n\t\t\treal k = d - i;\n\t\t\tmult[i] = pow (2.0, k) - 1.0;\n\t\t}\n\t\treal ts;\n\t\tif (d < MUCH)\n\t\t{\n\t\t\treal total = pow (2.0, n);\n\t\t\treal skip = 1;\n\t\t\tskip += n;\n\t\t\tskip += n * 0.5 * (n - 1);\n\t\t\tts = total - skip;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tts = sum (mult);\n\t\t}\n\t\tdebug {writeln (\"ts = \", ts);}\n\t\tmult[] /= ts;\n\n\t\treal res = 0.0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (k; 0..d)\n\t\t\t{\n\t\t\t\tint j = i + k + 1;\n\t\t\t\treal s = (a[i].x - a[j].x);\n\t\t\t\ts *= (a[j].y + a[i].y);\n\t\t\t\tint t = euclid (a[j].x - a[i].x,\n\t\t\t\t a[j].y - a[i].y);\n//\t\t\t\tdebug {writeln (s, ' ', t, ' ', mult[k], ' ',\n//\t\t\t\t (s - t) * mult[k]);}\n\t\t\t\ts -= t;\n\t\t\t\tres += mult[k] * s;\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (\"raw res = \", res);}\n\t\tres /= 2;\n\t\tres += 1;\n\t\twritefln (\"%.20f\", res);\n\t}\n}\n"}], "src_uid": "26506591fc15f23b0436473cd2712166"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, k, d;\n readf( \"%s %s %s\", &n, &k, &d );\n readln;\n \n auto a = -(10^^9) ~ readln.split.map!( to!int ).array;\n a.sort();\n debug { writeln(a); }\n \n auto vs = DList!int(0);\n \n auto idxleft = 0;\n foreach ( i; k..n+1 ) {\n debug { write(i, ' '); }\n \n while ( a[ idxleft+1 ] < a[ i ] - d ) ++idxleft;\n while ( !vs.empty() && vs.front() < idxleft ) vs.removeFront();\n bool ok = !vs.empty() && vs.front() <= i - k;\n \n if ( ok ) vs ~= i;\n \n debug { writeln( idxleft, ' ', i - k, ' ', ok, ' ', vs.array ); }\n }\n \n writeln( !vs.empty() && vs.back() == n ? \"YES\" : \"NO\" );\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, k, d;\n readf( \"%s %s %s\", &n, &k, &d );\n readln;\n \n auto a = -(10^^9) ~ readln.split.map!( to!int ).array;\n auto sorted = a.sort();\n auto vs = [0];\n \n foreach ( i; k..n+1 ) {\n auto reach = sorted.lowerBound( a[ i ] - d );\n auto idxleft = reach.length - 1;\n auto vsRange = vs.assumeSorted();\n auto idcs = vsRange.equalRange( idxleft ).chain( vsRange.upperBound( idxleft ) );\n \n bool ok = !idcs.empty() && idcs.front() <= i - k;\n \n debug { write( idxleft, ' ', idcs, ' ', i - k, ' ', ok ); }\n \n if ( ok ) vs ~= i;\n }\n \n debug { writeln( vs ); }\n writeln( vs.back() == n ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, k, d;\n readf( \"%s %s %s\", &n, &k, &d );\n readln;\n \n auto a = readln.split.map!( to!int ).array;\n a = -(10^^9) ~ a;\n auto sorted = a.sort();\n debug { writeln( sorted ); }\n \n auto vs = [0];\n \n foreach ( i; k..n+1 ) {\n debug { write(i, ' '); }\n \n auto reach = sorted.lowerBound( a[ i ] - d );\n auto idxleft = reach.length - 1;\n auto idcs = vs.assumeSorted().equalRange( idxleft ).chain( vs.assumeSorted().upperBound( idxleft ) );\n \n debug { write( idxleft, ' ', idcs, ' ' ); }\n \n bool ok = !idcs.empty() && idcs.front() <= i - k;\n \n debug { writeln( i - k, ' ', ok ); }\n \n if ( ok ) vs ~= i;\n }\n debug { writeln( vs ); }\n writeln( vs.back() == n ? \"YES\" : \"NO\" );\n}"}], "negative_code": [], "src_uid": "c25549c415a78b7f6b6db1299daa0b50"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint a, b, c, x, y;\r\n\t\treadf !(\" %s %s %s %s %s\") (a, b, c, x, y);\r\n\t\tbool ok = (a + c >= x && b + c >= y && a + b + c >= x + y);\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// cheese-cracker [2022-05-05]\n\nvoid solve(){\n long a = scan; \n long b = scan; \n long c = scan; \n long x = scan; \n long y = scan; \n long left = max(x - a, 0L) + max(y - b, 0);\n if(c >= left){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm;\nimport std.container, std.math, std.numeric, std.functional;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}], "negative_code": [], "src_uid": "7ac27da2546a50d453f7bb6cacef1068"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\nimport std.math;\n\n\nvoid main() {\n int cases = to!int(strip(readln()));\n\n // per testcase\n for (int t = 0; t < cases; t++) {\n int n;\n readf!\"%d\\n\"(n);\n\n string a;\n readf!\"%s\\n\"(a);\n\n int zeros = 0;\n for (int i = 0; i < n; i++) {\n if (a[i] == '0') zeros ++;\n }\n\n if (zeros == 0 || zeros == a.length) {\n writeln(0);\n continue;\n }\n\n int[] indices = new int[0];\n int last_one = 0;\n for (int i = 0; i < n; i++) {\n if (a[i] == '0') {\n zeros --;\n } else {\n last_one = i;\n zeros --;\n indices ~= [i];\n }\n if (zeros <= 0) {\n // add the next indices.length zeros\n int to_add = cast(int) indices.length;\n for (int j = i+1; j < n; j++) {\n if (a[j] == '0') {\n indices ~= [j];\n to_add --;\n }\n if (to_add <= 0) break;\n }\n\n break;\n }\n }\n\n if (indices.length != 0) writeln(1);\n write(indices.length);\n write(' ');\n for (int i = 0; i < indices.length; i++) {\n write(indices[i] + 1);\n write(' ');\n }\n writeln();\n\n }\n}\n\n/*\n100001101010111100011000000000000000011\n| || | | |||| ||\n000000000000111111111111\n\n1001010100100010101010111111111010101110011\n| | | | | | |\n0000000000000000011111111111111111111111111\n\n11111111111111111111111111111111111111111111000\n\n101\n|\n011\n\n\n11111111111111111101\n|\n01111111111111111111*/\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto s = readString;\n\tint[] p0, p1;\n\tforeach(i, ch; s)\n\t{\n\t\tif (ch == '0')\n\t\t{\n\t\t\tp0 ~= cast(int) i;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tp1 ~= cast(int) i;\n\t\t}\n\t}\n\tint j = 0;\n\tint[] ans;\n\tdebug writeln(p0, p1);\n\twhile (p0.length>0 && p1.length>0\n\t && p0[$-1] > p1[0])\n\t{\n\t\tans ~= p0[$-1];\n\t\tans ~= p1[0];\n\t\tp0 = p0[0 .. $ - 1];\n\t\tp1 = p1[1 .. $];\n\t}\n\tif (ans.length == 0) return writeln(0);\n\twriteln(1);\n\tsort(ans);\n\tans.length.write(\" \");\n\tforeach(v; ans) write(v+1, \" \");\n\twriteln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n int n = scan!int;\n auto arr = new long[](n);\n auto word = scan!(dchar[]);\n long cnt = 0;\n for(int i = 0; i < n; ++i){\n if(word[i] == '1'){\n ++cnt;\n ++arr[i];\n }\n }\n for(int i = n-1; i >= n - cnt; --i){\n arr[i] = !arr[i];\n }\n ll[] res;\n for(int i = 0; i < n; ++i){\n if(arr[i]){\n res ~= i;\n }\n }\n if(res.length){\n writeln(1);\n write(res.length, \" \");\n res.each!((k) => write(k+1, \" \"));\n writeln;\n }else{\n writeln(0);\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\nimport std.math;\n\n\nvoid main() {\n int cases = to!int(strip(readln()));\n\n // per testcase\n for (int t = 0; t < cases; t++) {\n int n;\n readf!\"%d\\n\"(n);\n\n string a;\n readf!\"%s\\n\"(a);\n\n int zeros = 0;\n for (int i = 0; i < n; i++) {\n if (a[i] == '0') zeros ++;\n }\n\n if (zeros == 0 || zeros == a.length) {\n writeln(0);\n continue;\n }\n\n int[] indices = new int[0];\n int last_one = 0;\n for (int i = 0; i < n; i++) {\n if (a[i] == '0') {\n zeros --;\n } else {\n last_one = i;\n zeros --;\n indices ~= [i];\n }\n if (zeros <= 0) {\n // add the next indices.length zeros\n int to_add = cast(int) indices.length;\n for (int j = last_one+1; j < n; j++) {\n if (a[j] == '0') {\n indices ~= [j];\n to_add --;\n }\n if (to_add <= 0) break;\n }\n\n break;\n }\n }\n\n if (indices.length != 0) writeln(1);\n write(indices.length);\n write(' ');\n for (int i = 0; i < indices.length; i++) {\n write(indices[i] + 1);\n write(' ');\n }\n writeln();\n\n }\n}\n\n/*\n100001101010111100011000000000000000011\n| || | | |||| ||\n000000000000111111111111\n\n1001010100100010101010111111111010101110011\n| | | | | | |\n0000000000000000011111111111111111111111111\n\n11111111111111111111111111111111111111111111000\n\n101\n|\n011\n\n\n11111111111111111101\n|\n01111111111111111111*/\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\nimport std.math;\n\n\nvoid main() {\n int cases = to!int(strip(readln()));\n\n // per testcase\n for (int t = 0; t < cases; t++) {\n int n;\n readf!\"%d\\n\"(n);\n\n string a;\n readf!\"%s\\n\"(a);\n\n int zeros = 0;\n for (int i = 0; i < n; i++) {\n if (a[i] == '0') zeros ++;\n }\n\n int[] indices = new int[0];\n\n for (int i = 0; i < n; i++) {\n if (a[i] == '0') {\n zeros --;\n } else {\n zeros --;\n indices ~= [i];\n }\n if (zeros <= 0) {\n // add the next indices.length zeros\n int to_add = cast(int) indices.length;\n for (int j = i+1; j < n; j++) {\n if (a[j] == '0') {\n indices ~= [j];\n to_add --;\n }\n if (to_add <= 0) break;\n }\n\n break;\n }\n }\n\n if (indices.length != 0) writeln(1);\n write(indices.length);\n write(' ');\n for (int i = 0; i < indices.length; i++) {\n write(indices[i] + 1);\n write(' ');\n }\n writeln();\n\n }\n}\n\n/*\n100001010101111000110011\n| | | | | ||| ||\n000000000000111111111111\n\n1001010100100010101010111111111010101110011\n| | | | | | |\n0000000000000000011111111111111111111111111\n\n101\n|\n011\n\n\n11111111111111111101\n|\n01111111111111111111*/\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\nimport std.math;\n\n\nvoid main() {\n int cases = to!int(strip(readln()));\n\n // per testcase\n for (int t = 0; t < cases; t++) {\n int n;\n readf!\"%d\\n\"(n);\n\n string a;\n readf!\"%s\\n\"(a);\n\n int zeros = 0;\n for (int i = 0; i < n; i++) {\n if (a[i] == '0') zeros ++;\n }\n\n int[] indices = new int[0];\n\n for (int i = 0; i < n; i++) {\n if (a[i] == '0') {\n zeros --;\n } else {\n zeros --;\n indices ~= [i];\n }\n if (zeros <= 0) {\n // add the next indices.length zeros\n int to_add = cast(int) indices.length;\n for (int j = i+1; j < n; j++) {\n if (a[j] == '0') {\n indices ~= [j];\n }\n to_add --;\n if (to_add <= 0) break;\n }\n\n break;\n }\n }\n\n if (indices.length != 0) writeln(1);\n write(indices.length);\n write(' ');\n for (int i = 0; i < indices.length; i++) {\n write(indices[i] + 1);\n write(' ');\n }\n writeln();\n\n }\n}\n\n/*\n100001010101111000110011\n| | | | | ||| ||\n000000000000111111111111\n\n1001010100100010101010111111111010101110011\n| | | | | | |\n0000000000000000011111111111111111111111111\n\n101\n|\n011\n\n\n11111111111111111101\n|\n01111111111111111111*/\n"}], "src_uid": "f472f9df8b4d588c67b39df6865507ca"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const S = readToken();\n \n auto cs = S.dup;\n foreach (_; 0 .. N - 1) foreach (i; 0 .. N - 1) {\n if (cs[i] > cs[i + 1]) {\n swap(cs[i], cs[i + 1]);\n }\n }\n int ans;\n foreach (i; 0 .. N) {\n if (S[i] != cs[i]) {\n ++ans;\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--)\n\t{\n\t\tsolve();\n\t}\n}\n\nvoid solve()\n{\n\tint n = readInt!int;\n\tchar[] s = cast(char[])readString;\n\tint[] si = s.map!(c => cast(int)c).array;\n\tint[] ssi = si.dup; sort(ssi);\n\tiota(0, n).count!(i => si[i] != ssi[i]).writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint, std.string;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n assert(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nvoid main() {\n int T;\n read(T);\n \n while (T--) {\n int n;\n read(n);\n auto s = readln.strip.array();\n auto cp = s.dup;\n sort(s);\n \n int t = 0;\n \n foreach (i; 0 .. n) {\n if (s[i] != cp[i]) t++;\n }\n \n writeln(t);\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tlong[] a;\r\n\t\tforeach (c; s)\r\n\t\t{\r\n\t\t\ta ~= c - 'a';\r\n\t\t}\r\n\t\ta.sort;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = s[i]-'a';\r\n\t\t\tif (a[i] != x)\r\n\t\t\t\t++ans[ti];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.split(\"\");\n auto sa = a.dup.sort;\n int result;\n foreach (i ; 0 .. a.length) {\n if (a[i] != sa[i])\n result++;\n }\n writeln(result);\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.utf;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = readln.strip;\r\n\t\tauto t = s.dup;\r\n\t\tsort (t.byChar);\r\n\t\twriteln (zip (s, t).count !(q{a[0] != a[1]}));\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "58ee86d4913787582ccdb54073656dc0"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nauto length(T)(T t) {return t.length;}\nalias len = length;\nalias nt = next;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = nt!int;\n auto op = nt!int(n);\n auto ch = new int[][](n);\n foreach(i; 1 .. n) ch[nt!int - 1] ~= i;\n int mins(int v)\n {\n if (ch[v].len == 0)\n return 0;\n auto cr = ch[v].map!mins;\n final switch(op[v])\n {\n case 0:\n return cast(int)(cr.sum + ch[v].len - 1);\n case 1:\n return cast(int)(cr.fold!min);\n }\n }\n writeln(cast(int)ch.map!len.count(0) - mins(0));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nauto length(T)(T t) {return t.length;}\nalias len = length;\nalias nt = next;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = nt!int;\n auto op = nt!int(n);\n auto ch = new int[][](n);\n foreach(i; 1 .. n) ch[nt!int - 1] ~= i;\n int nl = 0;\n int mins(int v)\n {\n if (ch[v].len == 0)\n {\n nl++;\n return 0;\n }\n final switch(op[v])\n {\n case 0:\n int res = ch[v].length - 1;\n foreach(c; ch[v])\n res += mins(c);\n return res;\n case 1:\n int res = int.max;\n foreach(c; ch[v])\n res = min(res, mins(c));\n return res;\n }\n }\n auto pres = mins(0);\n writeln(nl - pres);\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto operation = next!int(n);\n debug writeln(operation);\n auto children = new int[][](n);\n foreach(i; 1 .. n)\n children[next!int - 1] ~= i;\n debug writeln(children);\n auto noleafs = cast(int) children.count!(child => child.length == 0);\n int dfs(int node)\n {\n if (children[node].length == 0)\n return 0;\n if (operation[node] == 0) // min\n return cast(int)(children[node].map!(child => dfs(child)).sum + children[node].length - 1);\n else // max\n return cast(int)(children[node].map!(child => dfs(child)).fold!min);\n }\n writeln(noleafs - dfs(0));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nauto length(T)(T t) {return t.length;}\nalias len = length;\nalias nt = next;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = nt!int;\n auto op = nt!int(n);\n auto ch = new int[][](n);\n foreach(i; 1 .. n) ch[nt!int - 1] ~= i;\n int mins(int v)\n {\n if (ch[v].len == 0)\n return 0;\n final switch(op[v])\n {\n case 0:\n int res = ch[v].length - 1;\n foreach(c; ch[v])\n res += mins(c);\n return res;\n case 1:\n int res = int.max;\n foreach(c; ch[v])\n res = min(res, mins(c));\n return res;\n }\n }\n writeln(cast(int)ch.map!len.count(0) - mins(0));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nauto length(T)(T t) {return t.length;}\nalias len = length;\nalias nt = next;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n int[300_000] sop;\n int[][300_000] sch;\n auto n = nt!int;\n auto op = sop[0 .. n];\n foreach(i; 0 .. n)\n op[i] = nt!int;\n auto ch = sch[0 .. n];\n foreach(i; 1 .. n) ch[nt!int - 1] ~= i;\n int nl = 0;\n int mins(int v)\n {\n if (ch[v].len == 0)\n {\n nl++;\n return 0;\n }\n final switch(op[v])\n {\n case 0:\n int res = ch[v].length - 1;\n foreach(c; ch[v])\n res += mins(c);\n return res;\n case 1:\n int res = int.max;\n foreach(c; ch[v])\n res = min(res, mins(c));\n return res;\n }\n }\n auto pres = mins(0);\n writeln(nl - pres);\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto operation = next!int(n);\n debug writeln(operation);\n auto children = new int[][](n);\n foreach(i; 1 .. n)\n children[next!int - 1] ~= i;\n debug writeln(children);\n auto noleafs = cast(int) children.count!(child => child.length == 0);\n int dfs(int node)\n {\n if (children[node].length == 0)\n {\n return 0;\n }\n if (operation[node] == 0) // min\n {\n int acc = 0;\n foreach(child; children[node])\n acc += dfs(child);\n acc += children[node].length - 1;\n return acc;\n }\n else // max\n {\n int m = int.max;\n foreach(child; children[node])\n m = min(m, dfs(child));\n return m;\n }\n }\n writeln(noleafs - dfs(0));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto P = -1 ~ readln.split.map!(a => a.to!int - 1).array;\n\n auto G = new int[][](N);\n foreach (i; 1..N) G[i] ~= P[i], G[P[i]] ~= i;\n int k = 0;\n\n int dfs(int n, int p) {\n if (p != -1 && G[n].length == 1) {\n k += 1;\n return 0;\n } else if (A[n] == 0) {\n int res = 0;\n foreach (m; G[n]) {\n if (m == p) continue;\n res += max(1, dfs(m, n));\n }\n return res;\n } else {\n int res = 1 << 29;\n foreach (m; G[n]) {\n if (m == p) continue;\n res = min(res, dfs(m, n));\n }\n return res;\n }\n }\n \n int ans = dfs(0, -1);\n if (ans == 0) {\n k.writeln;\n } else {\n (k - ans + 1).writeln;\n }\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto mnmx = readln.chomp.split.map!(to!int).array;\n \n auto f = readln.chomp.split.map!(to!int).map!(x => x-1).array;\n \n auto g = new int[][] (n);\n foreach (i; 1 .. n) {\n g[f[i-1]] ~= i; \n }\n \n debug { g.writeln; }\n \n int leaves = 0;\n int dfs(int v) {\n if (g[v].empty()) { \n leaves += 1;\n return 1;\n }\n \n int ans = dfs(g[v].front);\n foreach (u; g[v].dropOne) {\n int res = dfs(u);\n if (mnmx[v] == 0) { ans += res; }\n else { ans = min(ans, res); }\n }\n \n debug { writeln(v, ' ', ans); }\n \n return ans;\n }\n \n int ans = dfs(0);\n \n ans = leaves - ans + 1;\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto mnmx = readln.chomp.split.map!(to!int).array;\n \n auto f = readln.chomp.split.map!(to!int).map!(x => x-1).array;\n \n auto g = new int[][] (n);\n foreach (i; 1 .. n) {\n g[f[i-1]] ~= i; \n }\n \n debug { g.writeln; }\n \n int leaves = 0;\n int dfs(int v, ref int leaves) {\n if (g[v].empty()) { \n leaves += 1;\n return 1;\n }\n \n int ans = dfs(g[v].front, leaves);\n foreach (u; g[v].dropOne) {\n int res = dfs(u, leaves);\n if (mnmx[v] == 0) { ans += res; }\n else { ans = min(ans, res); }\n }\n \n debug { writeln(v, ' ', ans); }\n \n return ans;\n }\n \n int ans = dfs(0, leaves);\n \n ans = leaves - ans + 1;\n \n ans.writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\t\n\tNode[] nodes;\n\tforeach(i; 0 .. n){\n\t\tbool isMax = read.to!int.to!bool;\n\t\tnodes ~= new Node(i, isMax);\n\t}\n\t\n\tforeach(i; 1 .. n){\n\t\tint j = read.to!int - 1;\n\t\tnodes[i].parent = nodes[j];\n\t\tnodes[j].kids ~= nodes[i];\n\t}\n\t\n\tint v = nodes[0].solve;\n\t\n\tauto leafcount = nodes.count!(x => x.kids.length == 0);\n\t(leafcount + 1 - v).writeln;\n\t\n\tprint!1(nodes.map!(x => x.solve()));\n\n}\n\n/*\n\nTree DP.\nEach node holds \"min of at least how many leaves comes here?\".\nFor example, if a node has only \"max\" descenders its value will be 1.\n\nIf a node is max node, its value is the min of its direct sons.\nIf a node is min node, its value is the sum of its direct sons.\n\n*/\n\nclass Node{\n\tbool isMax;\n\tlong _b, _w;\n\tint id;\n\tNode[] nodes;\n\tNode[] kids;\n\tNode parent;\n\tbool isVisited;\n\tthis(int id, bool isMax){\n\t\tthis.id = id;\n\t\tthis.isMax = isMax;\n\t}\n\tint solve(){\n\t\tint res;\n\t\tif(kids.length == 0) return 1;\n\t\telse if(isMax){\n\t\t\tres = 900_000;\n\t\t\tforeach(nd; kids) res = min(res, nd.solve);\n\t\t}\n\t\telse{\n\t\t\tres = 0;\n\t\t\tforeach(nd; kids) res += nd.solve;\n\t\t}\n\t\treturn res;\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nauto length(T)(T t) {return t.length;}\nalias len = length;\nalias nt = next;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = nt!int;\n auto op = nt!int(n);\n auto ch = new int[][](n);\n foreach(i; 1 .. n) ch[nt!int - 1] ~= i;\n int mins(int v)\n {\n if (ch[v].len == 0)\n return 0;\n final switch(op[v])\n {\n case 0:\n int res = ch[v].length - 1;\n foreach(c; ch[v])\n res += mins(c);\n return res;\n case 1:\n int res = int.max;\n foreach(c; ch[v])\n res = min(res, mins(c));\n return res;\n }\n }\n writeln(cast(int)ch.map!len.count(0) - mins(0));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byChunk;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [], "src_uid": "3b6814b6753f307ec6f3a68179274caa"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\nstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\nstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias gcd=std.numeric.gcd;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n\t{\n\t\tpair!(X,Y) pp;\n\t\tpp.fi=x_;\n\t\tpp.se=y_;\n\t\treturn pp;\n\t}\n\tbig gcd(big a,big b)\n\t{\n\t\twhile(b)\n\t\t{\n\t\t\ta%=b;\n\t\t\tswap(a,b);\n\t\t}\n\t\treturn a;\n\t}\n\tX binpow(X,Y)(X base,Y exp)if(is(typeof(exp>>1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)if(is(typeof(exp>>1)) && is(typeof(base%mm)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~\"\\n\", ptrs)==ptrs.length;}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\tloop:while(read(&n))\n\t{\n\t\tauto a=arread!int;\n\t\t\n\t\tsort(a);int m=int.max,k=0;\n\t\tforeach(i;0..a.length-1)\n\t\t{\n\t\t\tif(a[i+1]-a[i]<m)\n\t\t\t{\n\t\t\t\tm=a[i+1]-a[i];\n\t\t\t\tk=1;\n\t\t\t}\n\t\t\telse if(a[i+1]-a[i]==m)k++;\n\t\t}\n\t\twriteln(m,' ',k);\n\t}\n\tdebug system(\"pause\");\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tsort (a);\n\t\tauto b = (n - 1).iota.map !(i => a[i + 1] - a[i]).array;\n\t\tauto m = b.reduce !(min);\n\t\twriteln (m, \" \", b.count (m));\n\t}\n}\n"}], "negative_code": [], "src_uid": "5f89678ae1deb1d9eaafaab55a64197f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA;\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] > a[i-1])\n\t\t\t\t++ans[ti];\n\t\t}\n\t\tif (k == 1)\n\t\t{\n\t\t\tif (ans[ti] != 0)\n\t\t\t\tans[ti] = -1;\n\t\t\telse\n\t\t\t\tans[ti] = 1;\n\t\t\tcontinue;\n\t\t}\n\t\telse if (ans[ti] == 0)\n\t\t\tans[ti] = 1;\n\t\tans[ti] = (ans[ti]+k-2) / (k-1);\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const K = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int ans;\n if (N == 1) {\n ans = 1;\n } else {\n int num;\n foreach (i; 0 .. N - 1) {\n if (A[i] < A[i + 1]) {\n ++num;\n }\n }\n if (K == 1) {\n if (num == 0) {\n ans = 1;\n } else {\n ans = -1;\n }\n } else {\n ans = (num + (K - 1) - 1) / (K - 1);\n chmax(ans, 1);\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const K = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int ans;\n if (N == 1) {\n ans = 0;\n } else {\n int num;\n foreach (i; 0 .. N - 1) {\n if (A[i] < A[i + 1]) {\n ++num;\n }\n }\n if (K == 1) {\n if (num == 0) {\n ans = 1;\n } else {\n ans = -1;\n }\n } else {\n ans = (num + (K - 1) - 1) / (K - 1);\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const K = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int ans;\n if (N == 1) {\n ans = 0;\n } else {\n int num;\n foreach (i; 0 .. N - 1) {\n if (A[i] < A[i + 1]) {\n ++num;\n }\n }\n if (K == 1) {\n if (num == 0) {\n ans = 1;\n } else {\n ans = -1;\n }\n } else {\n ans = (num + (K - 1) - 1) / (K - 1);\n chmax(ans, 1);\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA;\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] > a[i-1])\n\t\t\t\t++ans[ti];\n\t\t}\n\t\tif (k == 1)\n\t\t{\n\t\t\tif (ans[ti] != 0)\n\t\t\t\tans[ti] = -1;\n\t\t\telse\n\t\t\t\tans[ti] = 1;\n\t\t\tcontinue;\n\t\t}\n\t\tans[ti] = (ans[ti]+k-2) / (k-1);\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "3dc5850220458dec9876560150b612c4"} {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport core.bitop;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nstruct FindAncestor {\r\n int[][] G;\r\n int N;\r\n int root;\r\n int[] parent;\r\n int[] depth; // depth[v]: distance from root\r\n int[][] ancestor; // ancestor[v][i]: v's {2^i}-th ancestor\r\n\r\n void init_parent() {\r\n void dfs(int v, int prev, int d) {\r\n parent[v] = prev;\r\n depth[v] = d;\r\n foreach (next; G[v]) {\r\n if (next == prev) continue;\r\n dfs(next, v, d + 1);\r\n }\r\n }\r\n dfs(root, -1, 0);\r\n }\r\n\r\n void init_ancestor() {\r\n int L = bsr(N) + 1;\r\n this.ancestor = new int[][](N, L);\r\n foreach (ref e; ancestor) e[] = -1;\r\n for (int v = 0; v < N; v++) {\r\n ancestor[v][0] = parent[v];\r\n }\r\n for (int i = 1; i < L; i++) {\r\n for (int v = 0; v < N; v++) {\r\n if (ancestor[v][i-1] == -1) continue;\r\n ancestor[v][i] = ancestor[ ancestor[v][i-1] ][i-1];\r\n }\r\n }\r\n }\r\n\r\n this(int[][] G, int root) {\r\n this.N = cast(int)G.length;\r\n this.G = G;\r\n this.root = root;\r\n this.depth = new int[N];\r\n this.parent = new int[N];\r\n init_parent();\r\n init_ancestor();\r\n }\r\n\r\n int query(int v, int k) {\r\n // return v's k-th ancestor\r\n for (int i = 0; i <= bsr(N); i++) {\r\n if (k & (1<<i)) {\r\n v = ancestor[v][i];\r\n if (v == -1) return v;\r\n }\r\n }\r\n return v;\r\n }\r\n}\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n int[][] G = new int[][N];\r\n int[][] A = new int[][N];\r\n int[][] B = new int[][N];\r\n int[] P = new int[N]; P[] = -1;\r\n for (int j = 1; j < N; j++) {\r\n int p, a, b; readf(\"%d %d %d\\n\", &p, &a, &b);\r\n p--;\r\n G[p] ~= j;\r\n A[p] ~= a;\r\n B[p] ~= b;\r\n P[j] = p;\r\n }\r\n long[] Sa = new long[N];\r\n long[] Sb = new long[N];\r\n void dfs(int v, int[][] c, long[] Sc, long s) {\r\n Sc[v] = s;\r\n foreach (i, n; G[v]) {\r\n auto cost = c[v][i];\r\n dfs(n, c, Sc, s + cost);\r\n }\r\n }\r\n dfs(0, A, Sa, 0);\r\n dfs(0, B, Sb, 0);\r\n\r\n auto ancestor = FindAncestor(G, 0);\r\n int[] ans = new int[N];\r\n for (int v = 0; v < N; v++) {\r\n long L = Sa[v];\r\n int lb = 0, ub = N;\r\n\r\n bool C(int x) {\r\n int nv = ancestor.query(v, x);\r\n return nv < 0 || L >= Sb[nv];\r\n }\r\n\r\n if (C(lb)) {\r\n ans[v] = ancestor.depth[v];\r\n } else {\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n ans[v] = ancestor.depth[ancestor.query(v, ub)];\r\n }\r\n }\r\n writefln(\"%(%s %)\", ans[1..$]);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport core.bitop;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nstruct Tree {\r\n int[][] G;\r\n int N;\r\n int root;\r\n int[] parent;\r\n int[] depth; // depth[v]: distance from root\r\n int[][] ancestor; // ancestor[v][i]: v's {2^i}-th ancestor\r\n\r\n void init_parent() {\r\n void dfs(int v, int prev, int d) {\r\n parent[v] = prev;\r\n depth[v] = d;\r\n foreach (next; G[v]) {\r\n if (next == prev) continue;\r\n dfs(next, v, d + 1);\r\n }\r\n }\r\n dfs(root, -1, 0);\r\n }\r\n\r\n void init_ancestor() {\r\n int L = bsr(N) + 1;\r\n this.ancestor = new int[][](N, L);\r\n foreach (ref e; ancestor) e[] = -1;\r\n for (int v = 0; v < N; v++) {\r\n ancestor[v][0] = parent[v];\r\n }\r\n for (int i = 1; i < L; i++) {\r\n for (int v = 0; v < N; v++) {\r\n if (ancestor[v][i-1] == -1) continue;\r\n ancestor[v][i] = ancestor[ ancestor[v][i-1] ][i-1];\r\n }\r\n }\r\n }\r\n\r\n this(int[][] G, int root) {\r\n this.N = cast(int)G.length;\r\n this.G = G;\r\n this.root = root;\r\n this.depth = new int[N];\r\n this.parent = new int[N];\r\n init_parent();\r\n init_ancestor();\r\n }\r\n\r\n int kth_ancestor(int v, int k) {\r\n // return v's k-th ancestor\r\n for (int i = 0; i <= bsr(N); i++) {\r\n if (k & (1<<i)) {\r\n v = ancestor[v][i];\r\n if (v == -1) return v;\r\n }\r\n }\r\n return v;\r\n }\r\n}\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n int[][] G = new int[][N];\r\n int[][] A = new int[][N];\r\n int[][] B = new int[][N];\r\n int[] P = new int[N]; P[] = -1;\r\n for (int j = 1; j < N; j++) {\r\n int p, a, b; readf(\"%d %d %d\\n\", &p, &a, &b);\r\n p--;\r\n G[p] ~= j;\r\n A[p] ~= a;\r\n B[p] ~= b;\r\n P[j] = p;\r\n }\r\n long[] Sa = new long[N];\r\n long[] Sb = new long[N];\r\n void dfs(int v, int[][] c, long[] Sc, long s) {\r\n Sc[v] = s;\r\n foreach (i, n; G[v]) {\r\n auto cost = c[v][i];\r\n dfs(n, c, Sc, s + cost);\r\n }\r\n }\r\n dfs(0, A, Sa, 0);\r\n dfs(0, B, Sb, 0);\r\n\r\n auto ancestor = Tree(G, 0);\r\n int[] ans = new int[N];\r\n for (int v = 0; v < N; v++) {\r\n long L = Sa[v];\r\n int lb = 0, ub = N;\r\n\r\n bool C(int x) {\r\n int nv = ancestor.kth_ancestor(v, x);\r\n return nv < 0 || L >= Sb[nv];\r\n }\r\n\r\n if (C(lb)) {\r\n ans[v] = ancestor.depth[v];\r\n } else {\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n ans[v] = ancestor.depth[ancestor.kth_ancestor(v, ub)];\r\n }\r\n }\r\n writefln(\"%(%s %)\", ans[1..$]);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [], "src_uid": "8629aa74df60537987611c6c1ef1a140"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n const long mod = 998244353;\n\n long powmod(long b, long e) {\n if (e == 0)\n return 1;\n else if (e == 1)\n return b % mod;\n else if (e & 1)\n return b * powmod(b, e - 1) % mod;\n else\n return powmod(b * b % mod, e / 2);\n }\n\n auto fac = new long[](n + 1), inv = new long[](n + 1);\n fac[0] = inv[0] = 1;\n for (int i = 1; i <= n; i++) {\n fac[i] = fac[i - 1] * i % mod;\n inv[i] = powmod(fac[i], mod - 2);\n }\n long ans = n * fac[n] % mod;\n foreach (i; 1 .. n) {\n ans -= fac[n] * inv[i] % mod;\n if (ans < 0) {\n ans += mod;\n }\n }\n writeln(ans);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 998_244_353;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint res = 0;\n\t\tint cur = n % mod;\n\t\tint prev = cur;\n\t\tint k = 0;\n\t\tforeach_reverse (i; 2..n)\n\t\t{\n\t\t\tk += 1;\n\t\t\tcur = (cur * 1L * i) % mod;\n\t\t\tdebug {writeln (k, \" * (\", cur, \" - \", prev, \")\");}\n\t\t\tres = (res + (cur - prev + mod) * 1L * k) % mod;\n//\t\t\tres = (res + (cur - prev) * 1L * k) % mod;\n\t\t\tprev = cur;\n\t\t}\n\t\tres = (res + cur) % mod;\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\nenum mod = 998244353L;\n\nvoid main() {\n int n;\n scan(n);\n\n auto f = new long[](n + 1);\n f[0] = f[1] = 1;\n foreach (i ; 2 .. n + 1) {\n f[i] = f[i-1] * i % mod;\n }\n auto rf = new long[](n + 1);\n rf[n] = powmod(f[n], mod - 2, mod);\n foreach_reverse (i ; 1 .. n) {\n rf[i] = rf[i+1] * (i + 1) % mod;\n }\n\n long comb(int n, int k) {\n return f[n] * rf[k] % mod * rf[n-k] % mod;\n }\n\n long ans = f[n];\n\n foreach (i ; 2 .. n) {\n long t = comb(n, i) * (f[i] - 1 + mod) % mod * f[n - i] % mod;\n ans += t;\n ans %= mod;\n }\n\n writeln(ans);\n}\n\nlong powmod(long x, long y, long mod) {\n return y > 0 ? powmod(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 1;\n}\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n const long mod = 998244353;\n\n long powmod(long b, long e) {\n if (e == 0)\n return 1;\n else if (e == 1)\n return b % mod;\n else if (e & 1)\n return b * powmod(b, e - 1) % mod;\n else\n return powmod(b * b % mod, e / 2);\n }\n\n auto fac = new long[](n + 1), inv = new long[](n + 1);\n fac[0] = inv[0] = 1;\n for (int i = 1; i <= n; i++) {\n fac[i] = fac[i - 1] * i % mod;\n inv[i] = powmod(fac[i], mod - 2);\n }\n long ans = n * fac[n] % mod;\n foreach (i; 1 .. n) {\n ans -= fac[n] * inv[i] % mod;\n ((ans %= mod) += mod) %= mod;\n }\n writeln(ans);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\nenum mod = 998244353L;\n\nvoid main() {\n int n;\n scan(n);\n\n auto f = new long[](n + 1);\n f[0] = f[1] = 1;\n foreach (i ; 2 .. n + 1) {\n f[i] = f[i-1] * i % mod;\n }\n auto rf = new long[](n + 1);\n rf[n] = powmod(f[n], mod - 2, mod);\n foreach_reverse (i ; 1 .. n) {\n rf[i] = rf[i+1] * (i + 1) % mod;\n }\n\n long comb(int n, int k) {\n return f[n] * rf[k] % mod * rf[n-k] % mod;\n }\n\n long ans = f[n];\n\n foreach (i ; 2 .. n) {\n long t = comb(n, i) * (f[i] - 1 + mod) % mod * f[n - i] % mod;\n ans += t;\n }\n\n writeln(ans);\n}\n\nlong powmod(long x, long y, long mod) {\n return y > 0 ? powmod(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 1;\n}\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "src_uid": "9d4caff95ab182055f83c79dd88e599a"} {"source_code": "import std.stdio, std.algorithm, std.array, std.string, std.format, std.range, std.bigint, std.conv;\r\n \r\n\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n foreach(_; 0..t)\r\n {\r\n long n, k;\r\n scanf(\"%lld %lld\", &n, &k);\r\n getchar();\r\n auto s = format(\"%b\", k);\r\n BigInt res;\r\n long i = 0;\r\n foreach(el; s.retro)\r\n {\r\n if (el == '1')\r\n res += (to!BigInt(n) ^^ i) % (10^^9 + 7);\r\n i++;\r\n }\r\n writeln(res % (10^^9 + 7));\r\n }\r\n}", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n ll n = scan;\n ll k = scan;\n ll MOD = to!long(1e9) + 7L;\n ll num = 0;\n ll add = 1;\n for(ll st = 0; st < 31; ++st){\n ll msk = 1L<<st;\n if(k & msk){\n num += add;\n num %= MOD;\n }\n add *= n;\n add %= MOD;\n }\n writeln(num);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [], "src_uid": "2cc35227174e6a4d48e0839cba211724"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!long;\r\n\r\n if (N < 4 || N % 2 == 1) return \"-1\";\r\n \r\n long ans1, ans2;\r\n long t = N;\r\n while(t % 6 != 0) {\r\n t -= 4;\r\n ans1++;\r\n }\r\n ans1 += t / 6;\r\n\r\n t = N;\r\n while(t % 4 != 0) {\r\n t -= 6;\r\n ans2++;\r\n }\r\n ans2 += t / 4;\r\n\r\n return [ans1, ans2].toAnswerString;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n long n;\r\n foreach(_; 0..t)\r\n {\r\n n = readln.strip.to!(long);\r\n long amin, amax;\r\n if (n % 2 != 0 || n < 4) {\r\n writeln(-1);\r\n continue;\r\n }\r\n else {\r\n if (n % 4 == 0)\r\n amax = n / 4;\r\n else {\r\n auto tmp = n;\r\n while (tmp > 0) {\r\n amax++;\r\n tmp -= 6;\r\n if (tmp % 4 == 0) {\r\n amax += tmp / 4;\r\n break;\r\n }\r\n }\r\n }\r\n if (n % 6 == 0)\r\n amin = n / 6;\r\n else {\r\n auto tmp2 = n;\r\n while (tmp2 > 0) {\r\n amin++;\r\n tmp2 -= 4;\r\n if (tmp2 % 6 == 0) {\r\n amin += tmp2 / 6;\r\n break;\r\n }\r\n }\r\n }\r\n writeln(max(1,amin),\" \", amax);\r\n }\r\n }\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n long n;\r\n foreach(_; 0..t)\r\n {\r\n n = readln.strip.to!(long);\r\n long amin, amax;\r\n if (n % 2 != 0 || n < 4) {\r\n writeln(-1);\r\n continue;\r\n }\r\n else {\r\n if (n % 4 == 0)\r\n amax = n / 4;\r\n else {\r\n auto tmp = n;\r\n while (tmp > 3) {\r\n amax++;\r\n tmp -= 6;\r\n if (tmp % 4 == 0) {\r\n amax += tmp / 4;\r\n break;\r\n }\r\n }\r\n }\r\n if (n % 6 == 0)\r\n amin = n / 6;\r\n else {\r\n auto tmp2 = n;\r\n while (tmp2 > 5) {\r\n amin++;\r\n tmp2 -= 4;\r\n if (tmp2 % 6 == 0) {\r\n amin += tmp2 / 6;\r\n break;\r\n }\r\n }\r\n }\r\n writeln(max(1,amin),\" \", amax);\r\n }\r\n }\r\n}\r\n\r\n"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n long n;\r\n foreach(_; 0..t)\r\n {\r\n n = readln.strip.to!(long);\r\n long amin, amax;\r\n if (n % 2 != 0) {\r\n writeln(-1);\r\n continue;\r\n }\r\n else {\r\n if (n % 4 == 0)\r\n amax = n / 4;\r\n else {\r\n auto tmp = n;\r\n while (tmp > 3) {\r\n amax++;\r\n tmp -= 6;\r\n if (tmp % 4 == 0) {\r\n amax += tmp / 4;\r\n break;\r\n }\r\n }\r\n }\r\n if (n % 6 == 0)\r\n amin = n / 6;\r\n else {\r\n auto tmp2 = n;\r\n while (tmp2 > 5) {\r\n amin++;\r\n tmp2 -= 4;\r\n if (tmp2 % 6 == 0) {\r\n amin += tmp2 / 6;\r\n break;\r\n }\r\n }\r\n }\r\n writeln(max(1,amin),\" \", amax);\r\n }\r\n }\r\n}\r\n\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!long;\r\n long ans1, ans2;\r\n \r\n long p6 = N / 6;\r\n N -= p6 * 6;\r\n if (N % 4 == 0) {\r\n ans1 = p6 + N / 4;\r\n ans2 = (p6*6 + N) / 4;\r\n } else if(N % 4 == 2 && p6 > 0) {\r\n p6--;\r\n N += 6;\r\n ans1 = p6 + N / 4;\r\n ans2 = (p6 / 2)*3 + N / 4;\r\n } else {\r\n return \"-1\";\r\n }\r\n\r\n\r\n return [ans1, ans2].toAnswerString;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!long;\r\n \r\n long ans1, ans2;\r\n\r\n long t = N;\r\n if (t % 6 == 0) {\r\n ans1 += t / 6;\r\n t -= ans1 * 6;\r\n }\r\n if (t % 4 > 0) {\r\n return \"-1\";\r\n }\r\n\r\n ans1 += t / 4;\r\n\r\n ans2 = N / 4;\r\n N -= ans2 * 4;\r\n ans2 += N / 6;\r\n\r\n return [ans1, ans2].toAnswerString;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "src_uid": "1cc628b4e03c8b8e0c5086dc4e0e3254"} {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n; readV(n);\n dchar[][] s; readA(n, s);\n\n foreach (i; 0..n)\n s[i] = s[i].sort().uniq.array;\n\n s = s.sort().uniq.array;\n\n writeln(s.length);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main()\n{\n\tint n = readln.chomp.to!int;\n\tstring[] ss = readln.chomp.split;\n\tbool[bool[char]] roots;\n\tforeach (s; ss) {\n\t\tbool[char] root;\n\t\tforeach (c; s) {\n\t\t\troot[c] = true;\n\t\t}\n\t\troots[root] = true;\n\t}\n\troots.length.writeln;\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in ref Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.splitter.map!(to!(dchar[])).array;\n \n auto toRoot = (dchar[] s) => s.sort.uniq.to!(dchar[]);\n \n auto ans = a.map!toRoot.redBlackTree.length;\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.splitter.map!(to!(dchar[])).array;\n \n auto toRoot = (dchar[] s) => s.sort.uniq.to!(dchar[]);\n \n auto ans = a.map!(toRoot).redBlackTree.length;\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.split.map!(to!string).array;\n \n auto rbt = make!(RedBlackTree!string);\n \n auto toRoot = (string s) => s.representation.dup.sort.uniq.to!string;\n \n a.each!(s => rbt.insert(toRoot(s)));\n \n debug { writeln(rbt); }\n \n writeln (rbt.length);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.split.map!(to!(dchar[])).array;\n \n auto rbt = make!(RedBlackTree!(dchar[]));\n \n auto toRoot = (dchar[] s) => s.sort.uniq.to!(dchar[]);\n \n a.each!(s => rbt.insert(toRoot(s)));\n \n debug { writeln(rbt); }\n \n writeln (rbt.length);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.splitter.map!(to!(dchar[]));\n \n auto toRoot = (dchar[] s) => s.sort.uniq.array;\n \n auto ans = a.map!toRoot.redBlackTree.length;\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.split.map!(to!(dchar[])).array;\n \n auto toRoot = (dchar[] s) => s.sort.uniq.to!(dchar[]);\n \n auto ans = a.map!(toRoot).redBlackTree.length;\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.splitter;\n \n auto toRoot = (string s) => s.array.sort.uniq.to!string;\n \n auto ans = a.map!toRoot.redBlackTree.length;\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.splitter.map!(to!(dchar[]));\n \n auto toRoot = (dchar[] s) => s.sort.uniq.to!(dchar[]);\n \n auto ans = a.map!toRoot.redBlackTree.length;\n \n writeln (ans);\n}"}], "negative_code": [], "src_uid": "cf1eb164c4c970fd398ef9e98b4c07b1"} {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\n\nvoid main(){\n double a,b,n,x,y,v,ans=double.max;\n readf!\"%f %f\"(a,b);\n readln;\n n=readln.chomp.to!int;\n while(n--){\n readf!\"%f %f %f\"(x,y,v);\n readln;\n ans=min(ans,sqrt((a-x)^^2+(b-y)^^2)/v);\n }\n writefln!\"%.10f\"(ans);\n}\n\n", "positive_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\n\nvoid main(){\n double a,b,x,y,v,ans=double.max;\n readf!\"%f %f\"(a,b);\n readln;\n int n=readln.chomp.to!int;\n while(n--){\n readf!\"%f %f %f\"(x,y,v);\n readln;\n ans=min(ans,sqrt((a-x)^^2+(b-y)^^2)/v);\n }\n writefln!\"%.10f\"(ans);\n}\n\n"}], "negative_code": [], "src_uid": "a74c65acd41ff9bb845062222135c60a"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\talias Segment = Tuple !(int, q{l}, int, q{r});\n\t\tauto s = new Segment [n];\n\t\tforeach (ref c; s)\n\t\t{\n\t\t\treadf (\" %s %s\", &c.l, &c.r);\n\t\t}\n\t\tauto r = iota (1, m + 1)\n\t\t .filter !(x => s.all !(c => x < c.l || c.r < x)).array;\n\t\twriteln (r.length);\n\t\twritefln (\"%(%s %)\", r);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\tint b=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\tbool[] m = new bool[b+1];\n\tfor (int i=0; i<b+1; i++)\n\t{\n\t\tm[i]=true;\n\t}\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tint c=0;\n\t\tint d=0;\n\t\treadf(\" %d\", &c);\n\t\treadf(\" %d\", &d);\n\t\tfor (int j=c; j<d+1; j++)\n\t\t{\n\t\t\tm[j]=false;\n\t\t}\n\t}\n\tint count=0;\n\tfor (int i=0; i<b+1; i++)\n\t{\n\t\tif (m[i]==true)\n\t\t{\n\t\t\tcount=count+1;\n\t\t}\n\t}\n\twriteln(count-1);\n\tfor (int i=1; i<b+1; i++)\n\t{\n\t\tif (m[i]==true)\n\t\t{\n\t\t\twriteln(i);\n\t\t}\n\t}\n\treturn 0;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto cnt = new int[] (m+2);\n foreach (_; 0 .. n) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n ++cnt[a];\n --cnt[b+1];\n }\n \n cnt = cnt.cumulativeFold!((a, b) => a + b).array;\n \n auto ans = cnt.dropOne.dropBackOne.enumerate(1).filter!(t => t[1] == 0).map!(t => t[0]).array;\n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\n}"}], "negative_code": [], "src_uid": "f336b622fdaf5960032268641320bb53"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tP[] ps;\n\tforeach(i; 0 .. n){\n\t\tps ~= P(i, i + 1, rlong, rlong, rlong);\n\t}\n\t\n\tP[][long][long] pm;\n\tforeach(p; ps){\n\t\tif(p.x !in pm){\n\t\t\tP[][long] tmp;\n\t\t\tpm[p.x] = tmp;\n\t\t}\n\t\tif(p.y !in pm[p.x]) pm[p.x][p.y] = [];\n\t\tpm[p.x][p.y] ~= p;\n\t}\n\t\n\tint[][] ans;\n\t\n\tlong[] xs = pm.keys;\n\txs.sort();\n\tP superleft;\n\tbool hasSuperleft;\n\tforeach(x; xs){\n\t\tlong[] ys = pm[x].keys;\n\t\tys.sort();\n\t\tP left;\n\t\tbool hasLeft;\n\t\tforeach(y; ys){\n\t\t\tP[] pq = pm[x][y];\n\t\t\tpq.sort!isLess();\n\t\t\tforeach(i; 0 .. pq.length / 2){\n\t\t\t\tans ~= [pq[i * 2].name, pq[i * 2 + 1].name];\n\t\t\t}\n\t\t\tif(pq.length % 2){\n\t\t\t\tif(hasLeft){\n\t\t\t\t\tans ~= [pq[$ - 1].name, left.name];\n\t\t\t\t\thasLeft = 0;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tleft = pq[$ - 1];\n\t\t\t\t\thasLeft = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(hasLeft){\n\t\t\tif(hasSuperleft){\n\t\t\t\tans ~= [left.name, superleft.name];\n\t\t\t\thasLeft = 0, hasSuperleft = 0;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tsuperleft = left;\n\t\t\t\thasLeft = 0, hasSuperleft = 1;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tforeach(an; ans) writeln(an[0], \" \", an[1]);\n}\n\nstruct P{\n\tint id, name;\n\tlong x, y, z;\n}\nbool isLess(P a, P b){\n\tif(a.x != b.x) return a.x < b.x;\n\tif(a.y != b.y) return a.y < b.y;\n\treturn a.z < b.z;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tlong[3][int] list;\n\tforeach (i; 0..n)\n\t{\n\t\tlist[i] = [RD, RD, RD];\n\t}\n\n\tint[2][] ans;\n\twhile (true)\n\t{\n\t\tauto keys = list.keys;\n\t\tif (keys.length == 0) break;\n\t\tauto k1 = keys[0];\n\t\tint pos;\n\t\tlong best = long.max;\n\t\tforeach (k2; keys[1..$])\n\t\t{\n\t\t\tauto lhs = list[k1].dup;\n\t\t\tauto rhs = list[k2];\n\t\t\tlhs[] -= rhs[];\n\t\t\tlhs[] *= lhs[];\n\t\t\tlong d;\n\t\t\tforeach (e; lhs)\n\t\t\t\td += e;\n\t\t\tif (d < best)\n\t\t\t{\n\t\t\t\tpos = k2;\n\t\t\t\tbest = d;\n\t\t\t}\n\t\t}\n\t\tans ~= [k1, pos];\n\t\tlist.remove(k1);\n\t\tlist.remove(pos);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0]+1, \" \", e[1]+1);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n \n Tuple!(int, int)[][int][int] mp;\n foreach (int i; 1 .. n+1) {\n auto v = readln.chomp.split.map!(to!int);\n auto x = v[0], y = v[1], z = v[2];\n \n mp[x][y] ~= tuple(z, i);\n }\n \n debug { mp.writeln; }\n \n Tuple!(int, int)[] ans;\n \n void takePairs(ref int[] arr, ref int[] leftOvers) {\n while (arr.length > 1) {\n auto idx1 = arr.back;\n arr.popBack();\n auto idx2 = arr.back;\n arr.popBack();\n ans ~= tuple(idx1, idx2);\n }\n \n if (arr.length == 1) {\n leftOvers ~= arr.back;\n arr.popBack();\n }\n }\n \n int[] lftx;\n foreach (xx; mp.keys.sort()) {\n int[] lfty;\n foreach (yy; mp[xx].keys.sort()) {\n auto values = mp[xx][yy].sort().map!(t => t[1]).array;\n takePairs(values, lfty);\n }\n \n takePairs(lfty, lftx);\n }\n \n int[] dummy;\n takePairs(lftx, dummy);\n \n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nstruct Point\n{\n\tint x;\n\tint y;\n\tint z;\n\tint num;\n}\n\nlong dist2 () (const auto ref Point p, const auto ref Point q)\n{\n\treturn (p.x - 0L - q.x) ^^ 2 + (p.y - 0L - q.y) ^^ 2 +\n\t (p.z - 0L - q.z) ^^ 2;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto p = new Point [n];\n\t\tforeach (i, ref q; p)\n\t\t{\n\t\t\treadf (\" %s %s %s\", &q.x, &q.y, &q.z);\n\t\t\tq.num = i + 1;\n\t\t}\n\n\t\tint [] [] res;\n\t\twhile (!p.empty)\n\t\t{\n\t\t\tauto i = 0;\n\t\t\tauto j = 1;\n\t\t\tforeach (k; 2..p.length)\n\t\t\t{\n\t\t\t\tif (dist2 (p[i], p[j]) > dist2 (p[i], p[k]))\n\t\t\t\t{\n\t\t\t\t\tj = k;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres ~= [p[i].num, p[j].num];\n\t\t\tp = p[1..j] ~ p[j + 1..$];\n\t\t}\n\t\twritefln (\"%(%(%s %)\\n%)\", res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nalias Pt = Tuple!(int, \"x\", int, \"y\", int, \"z\", int, \"id\");\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new Pt[N];\n foreach (i; 0 .. N) {\n P[i].x = readInt();\n P[i].y = readInt();\n P[i].z = readInt();\n P[i].id = i;\n }\n \n sort(P);\n \n int[] ans;\n \n int[] as;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && P[i].x == P[j].x; ++j) {}\n int[] bs;\n for (int k = i, l; k < j; k = l) {\n for (l = k; l < j && P[k].y == P[l].y; ++l) {}\n foreach (m; k .. k + (l - k) / 2 * 2) {\n ans ~= P[m].id;\n }\n if ((l - k) % 2 != 0) {\n bs ~= P[l - 1].id;\n }\n }\n const bsLen = cast(int)(bs.length);\n foreach (m; 0 .. bsLen / 2 * 2) {\n ans ~= bs[m];\n }\n if (bsLen % 2 != 0) {\n as ~= bs[$ - 1];\n }\n }\n assert(as.length % 2 == 0);\n ans ~= as;\n \n for (int i = 0; i < N; i += 2) {\n writeln(ans[i] + 1, \" \", ans[i + 1] + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n \n Tuple!(int, int)[][int][int] mp;\n foreach (int i; 1 .. n+1) {\n auto v = readln.chomp.split.map!(to!int);\n auto x = v[0], y = v[1], z = v[2];\n \n mp[x][y] ~= tuple(z, i);\n }\n \n debug { mp.writeln; }\n \n Tuple!(int, int)[] ans;\n \n void takePairs(ref int[] arr, ref int[] leftOvers) {\n while (arr.length > 1) {\n auto idx1 = arr.back;\n arr.popBack();\n auto idx2 = arr.back;\n arr.popBack();\n ans ~= tuple(idx1, idx2);\n }\n \n if (arr.length == 1) {\n leftOvers ~= arr.back;\n arr.popBack();\n }\n }\n \n int[] lftx;\n foreach (xx; mp.keys) {\n int[] lfty;\n foreach (yy; mp[xx].keys) {\n auto values = mp[xx][yy].map!(t => t[1]).array;\n takePairs(values, lfty);\n }\n \n takePairs(lfty, lftx);\n }\n \n int[] dummy;\n takePairs(lftx, dummy);\n \n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n \n Tuple!(int, int)[][int][int] mp;\n foreach (int i; 1 .. n+1) {\n auto v = readln.chomp.split.map!(to!int);\n auto x = v[0], y = v[1], z = v[2];\n \n mp[x][y] ~= tuple(z, i);\n }\n \n debug { mp.writeln; }\n \n Tuple!(int, int)[] ans;\n \n void takePairs(ref int[] arr, ref int[] leftOvers) {\n while (arr.length > 1) {\n auto idx1 = arr.back;\n arr.popBack();\n auto idx2 = arr.back;\n arr.popBack();\n ans ~= tuple(idx1, idx2);\n }\n \n if (arr.length == 1) {\n leftOvers ~= arr.back;\n arr.popBack();\n }\n }\n \n int[] lftx;\n foreach (xx; mp.keys) {\n int[] lfty;\n foreach (yy; mp[xx].keys) {\n auto values = mp[xx][yy]\n .schwartzSort!(t => t[0])\n .map!(t => t[1]).array;\n takePairs(values, lfty);\n }\n \n takePairs(lfty, lftx);\n }\n \n int[] dummy;\n takePairs(lftx, dummy);\n \n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nalias Pt = Tuple!(int, \"x\", int, \"y\", int, \"z\", int, \"id\");\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new Pt[N];\n foreach (i; 0 .. N) {\n P[i].x = readInt();\n P[i].y = readInt();\n P[i].z = readInt();\n P[i].id = i;\n }\n \n sort(P);\n for (int a = 0, i = 0, j; i < N; i = j) {\n for (j = i; j < N && P[i].x == P[j].x; ++j) {}\n if (a++ % 2 != 0) {\n reverse(P[i .. j]);\n }\n for (int b = 0, k = i, l; k < j; k = l) {\n for (l = k; l < j && P[k].y == P[l].y; ++l) {}\n if (b++ % 2 != 0) {\n reverse(P[k .. l]);\n }\n }\n }\n debug {\n writeln(\"P = \", P);\n }\n \n for (int i = 0; i < N; i += 2) {\n writeln(P[i].id + 1, \" \", P[i + 1].id + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nalias Pt = Tuple!(int, \"x\", int, \"y\", int, \"z\", int, \"id\");\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new Pt[N];\n foreach (i; 0 .. N) {\n P[i].x = readInt();\n P[i].y = readInt();\n P[i].z = readInt();\n P[i].id = i;\n }\n \n sort(P);\n for (int a = 0, i = 0, j; i < N; i = j) {\n for (j = i; j < N && P[i].x == P[j].x; ++j) {}\n for (int b = 0, k = i, l; k < j; k = l) {\n for (l = k; l < j && P[k].y == P[l].y; ++l) {}\n if (b++ % 2 != 0) {\n reverse(P[k .. l]);\n }\n }\n if (a++ % 2 != 0) {\n reverse(P[i .. j]);\n }\n }\n debug {\n writeln(\"P = \", P);\n }\n \n for (int i = 0; i < N; i += 2) {\n writeln(P[i].id + 1, \" \", P[i + 1].id + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "47a9d72651f1407de89e28fb4b142367"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^9 + 7;\n\nvoid main() {\n int n, d;\n scan(n, d);\n auto a = readln.split.to!(int[]);\n\n auto rw = new long[](n + 1);\n foreach (i ; 1 .. n + 1) {\n rw[i] = rw[i-1] + a[i-1];\n }\n\n auto rm = new long[](n + 1);\n rm[n] = rw[n];\n\n foreach_reverse (i ; 1 .. n) {\n rm[i] = max(rm[i + 1], rw[i]);\n }\n\n debug {\n writeln(rm);\n }\n\n int ans;\n long bank;\n\n foreach (i ; 0 .. n) {\n if (a[i] == 0 && bank < 0) {\n ans++;\n bank = d - (rm[i] - rw[i]);\n\n if (bank < 0) {\n writeln(-1);\n return;\n }\n }\n\n bank += a[i];\n\n debug {\n writeln(bank);\n }\n\n if (bank > d) {\n writeln(-1);\n return;\n }\n }\n\n writeln(ans);\n}\n\n\nstruct UnionFind {\n private {\n int N;\n int[] p;\n int[] rank;\n }\n\n this (int n) {\n N = n;\n p = iota(N).array;\n rank = new int[](N);\n }\n\n int find_root(int x) {\n if (p[x] != x) {\n p[x] = find_root(p[x]);\n }\n\n return p[x];\n }\n\n bool same(int x, int y) {\n return find_root(x) == find_root(y);\n }\n\n void unite(int x, int y) {\n int u = find_root(x), v = find_root(y);\n\n if (u == v) return;\n\n if (rank[u] < rank[v]) {\n p[u] = v;\n }\n else {\n p[v] = u;\n\n if (rank[u] == rank[v]) {\n rank[u]++;\n }\n }\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\n\nstruct Queue(T) {\n private {\n int N, head, tail;\n T[] data;\n }\n\n this(int n) {\n N = n + 1;\n data = new T[](N);\n }\n\n bool empty() {\n return head == tail;\n }\n\n bool full() {\n return (tail + 1) % N == head;\n }\n\n T front() {\n return data[head];\n }\n\n void push(T x) {\n assert(!full);\n data[tail++] = x;\n tail %= N;\n }\n\n void pop() {\n assert(!empty);\n head = (head + 1) % N;\n }\n\n void clear() {\n head = tail = 0;\n }\n}", "positive_code": [{"source_code": "#!/usr/bin/env dub\n/+ dub.sdl:\n name \"D\"\n+/\n\nimport std.array;\nimport std.algorithm;\nimport std.algorithm.iteration;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int N;\n long D;\n readf(\" %s %s \", N, D);\n\n long[] A = new long[N];\n foreach (i;0..N) readf(\" %s \", A[i]);\n\n long[] cum = [0];\n foreach(a; A) cum ~= cum[$-1] + a;\n\n long[] cmax = new long[N+1];\n cmax[N] = cum[N];\n for (int i=N-1;i>=0;i--) {\n cmax[i] = max(cum[i], cmax[i+1]);\n }\n\n long off = 0;\n int ans = 0;\n foreach(i; 0..N) {\n if (A[i] == 0 && cum[i+1] + off < 0) {\n // add as much as possible\n off = D - cmax[i];\n ++ans;\n if (cum[i+1] + off < 0) {\n writeln(-1);\n return;\n }\n }\n\n if (cum[i+1] > D) {\n writeln(-1);\n return;\n }\n }\n\n writeln(ans);\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, d;\n readf(\"%s %s\", &n, &d);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n long csum = 0;\n int mxval = 0, ans = 0;\n foreach (e; arr) {\n if (e != 0) {\n csum += e;\n mxval = max(e, mxval);\n if (csum > d) {\n ans = -1;\n break;\n }\n } else {\n if (csum >= 0) { continue; }\n \n long need = -csum;\n if (ans != 0 && mxval + need <= d) { \n mxval += need;\n } else {\n ans += 1;\n mxval = 0;\n }\n \n csum = 0;\n }\n }\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "#!/usr/bin/env dub\n/+ dub.sdl:\n name \"D\"\n+/\n\nimport std.array;\nimport std.algorithm;\nimport std.algorithm.iteration;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int N;\n long D;\n readf(\" %s %s \", N, D);\n\n long[] A = new long[N];\n foreach (i;0..N) readf(\" %s \", A[i]);\n\n long[] cum = [0];\n foreach(a; A) cum ~= cum[$-1] + a;\n\n long[] cmax = new long[N+1];\n cmax[N] = cum[N];\n for (int i=N-1;i>=0;i--) {\n cmax[i] = max(cum[i], cmax[i+1]);\n }\n\n long off = 0;\n int ans = 0;\n foreach(i; 0..N) {\n if (A[i] == 0 && cum[i+1] + off < 0) {\n // add as much as possible\n off = D - cmax[i];\n ++ans;\n if (cum[i+1] + off < 0) {\n writeln(-1);\n return;\n }\n }\n\n if (cum[i+1] >= D) {\n writeln(-1);\n return;\n }\n }\n\n writeln(ans);\n}"}, {"source_code": "#!/usr/bin/env dub\n/+ dub.sdl:\n name \"D\"\n+/\n\nimport std.array;\nimport std.algorithm;\nimport std.algorithm.iteration;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int N;\n long D;\n readf(\" %s %s \", N, D);\n\n long[] A = new long[N];\n foreach (i;0..N) readf(\" %s \", A[i]);\n\n long[] cum = [0];\n foreach(a; A) cum ~= cum[$-1] + a;\n\n long[] cmax = new long[N+1];\n cmax[N] = cum[N];\n for (int i=N-1;i>=0;i--) {\n cmax[i] = max(cum[i], cmax[i+1]);\n }\n\n long off = 0;\n int ans = 0;\n foreach(i; 0..N) {\n if (A[i] == 0 && cum[i+1] + off < 0) {\n // add as much as possible\n off = D - cmax[i];\n ++ans;\n if (cum[i+1] + off < 0) {\n writeln(-1);\n return;\n }\n }\n }\n\n writeln(ans);\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, d;\n readf(\"%s %s\", &n, &d);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n long csum = 0;\n int mxval = 0, ans = 0;\n foreach (e; arr) {\n if (e != 0) {\n csum += e;\n mxval = max(e, mxval);\n if (mxval > d) {\n ans = -1;\n break;\n }\n } else {\n if (csum >= 0) { continue; }\n \n long need = -csum;\n if (ans != 0 && mxval + need <= d) { \n mxval += need;\n } else {\n ans += 1;\n mxval = 0;\n }\n \n csum = 0;\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^9 + 7;\n\nvoid main() {\n int n, d;\n scan(n, d);\n auto a = readln.split.to!(int[]);\n\n long bank;\n int ans;\n\n foreach (i ; 0 .. n) {\n if (a[i] == 0) {\n if (bank < 0) {\n ans++;\n bank = 0;\n }\n }\n\n bank += a[i];\n\n debug {\n writeln(bank);\n }\n\n if (bank > d) {\n writeln(-1);\n return;\n }\n }\n\n writeln(ans);\n}\n\n\nstruct UnionFind {\n private {\n int N;\n int[] p;\n int[] rank;\n }\n\n this (int n) {\n N = n;\n p = iota(N).array;\n rank = new int[](N);\n }\n\n int find_root(int x) {\n if (p[x] != x) {\n p[x] = find_root(p[x]);\n }\n\n return p[x];\n }\n\n bool same(int x, int y) {\n return find_root(x) == find_root(y);\n }\n\n void unite(int x, int y) {\n int u = find_root(x), v = find_root(y);\n\n if (u == v) return;\n\n if (rank[u] < rank[v]) {\n p[u] = v;\n }\n else {\n p[v] = u;\n\n if (rank[u] == rank[v]) {\n rank[u]++;\n }\n }\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\n\nstruct Queue(T) {\n private {\n int N, head, tail;\n T[] data;\n }\n\n this(int n) {\n N = n + 1;\n data = new T[](N);\n }\n\n bool empty() {\n return head == tail;\n }\n\n bool full() {\n return (tail + 1) % N == head;\n }\n\n T front() {\n return data[head];\n }\n\n void push(T x) {\n assert(!full);\n data[tail++] = x;\n tail %= N;\n }\n\n void pop() {\n assert(!empty);\n head = (head + 1) % N;\n }\n\n void clear() {\n head = tail = 0;\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^9 + 7;\n\nvoid main() {\n int n, d;\n scan(n, d);\n auto a = readln.split.to!(int[]);\n\n auto rw = new long[](n + 1);\n foreach (i ; 1 .. n + 1) {\n rw[i] = rw[i-1] + a[i-1];\n }\n\n auto rm = new long[](n + 1);\n rm[n] = a[n-1];\n\n foreach_reverse (i ; 1 .. n) {\n rm[i] = max(rm[i + 1], a[i-1]);\n }\n\n debug {\n writeln(rw);\n writeln(rm);\n }\n\n int ans;\n long bank;\n\n foreach (i ; 0 .. n) {\n if (a[i] == 0 && bank < 0) {\n ans++;\n bank = d - rm[i+1];\n\n if (bank < 0) {\n writeln(-1);\n return;\n }\n }\n\n bank += a[i];\n\n debug {\n writeln(bank);\n }\n\n if (bank > d) {\n writeln(-1);\n return;\n }\n }\n\n writeln(ans);\n}\n\n\nstruct UnionFind {\n private {\n int N;\n int[] p;\n int[] rank;\n }\n\n this (int n) {\n N = n;\n p = iota(N).array;\n rank = new int[](N);\n }\n\n int find_root(int x) {\n if (p[x] != x) {\n p[x] = find_root(p[x]);\n }\n\n return p[x];\n }\n\n bool same(int x, int y) {\n return find_root(x) == find_root(y);\n }\n\n void unite(int x, int y) {\n int u = find_root(x), v = find_root(y);\n\n if (u == v) return;\n\n if (rank[u] < rank[v]) {\n p[u] = v;\n }\n else {\n p[v] = u;\n\n if (rank[u] == rank[v]) {\n rank[u]++;\n }\n }\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\n\nstruct Queue(T) {\n private {\n int N, head, tail;\n T[] data;\n }\n\n this(int n) {\n N = n + 1;\n data = new T[](N);\n }\n\n bool empty() {\n return head == tail;\n }\n\n bool full() {\n return (tail + 1) % N == head;\n }\n\n T front() {\n return data[head];\n }\n\n void push(T x) {\n assert(!full);\n data[tail++] = x;\n tail %= N;\n }\n\n void pop() {\n assert(!empty);\n head = (head + 1) % N;\n }\n\n void clear() {\n head = tail = 0;\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^9 + 7;\n\nvoid main() {\n int n, d;\n scan(n, d);\n auto a = readln.split.to!(int[]);\n\n auto rw = new long[](n + 1);\n foreach (i ; 1 .. n + 1) {\n rw[i] = rw[i-1] + a[i-1];\n }\n\n auto rm = new long[](n + 1);\n rm[n] = a[n-1];\n\n foreach_reverse (i ; 1 .. n) {\n rm[i] = max(rm[i + 1], a[i-1]);\n }\n\n debug {\n writeln(rw);\n writeln(rm);\n }\n\n int ans;\n long bank;\n\n foreach (i ; 0 .. n) {\n if (a[i] == 0 && bank < 0) {\n ans++;\n bank = d - rm[i];\n\n if (bank < 0) {\n writeln(-1);\n return;\n }\n }\n\n bank += a[i];\n\n debug {\n writeln(bank);\n }\n\n if (bank > d) {\n writeln(-1);\n return;\n }\n }\n\n writeln(ans);\n}\n\n\nstruct UnionFind {\n private {\n int N;\n int[] p;\n int[] rank;\n }\n\n this (int n) {\n N = n;\n p = iota(N).array;\n rank = new int[](N);\n }\n\n int find_root(int x) {\n if (p[x] != x) {\n p[x] = find_root(p[x]);\n }\n\n return p[x];\n }\n\n bool same(int x, int y) {\n return find_root(x) == find_root(y);\n }\n\n void unite(int x, int y) {\n int u = find_root(x), v = find_root(y);\n\n if (u == v) return;\n\n if (rank[u] < rank[v]) {\n p[u] = v;\n }\n else {\n p[v] = u;\n\n if (rank[u] == rank[v]) {\n rank[u]++;\n }\n }\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\n\nstruct Queue(T) {\n private {\n int N, head, tail;\n T[] data;\n }\n\n this(int n) {\n N = n + 1;\n data = new T[](N);\n }\n\n bool empty() {\n return head == tail;\n }\n\n bool full() {\n return (tail + 1) % N == head;\n }\n\n T front() {\n return data[head];\n }\n\n void push(T x) {\n assert(!full);\n data[tail++] = x;\n tail %= N;\n }\n\n void pop() {\n assert(!empty);\n head = (head + 1) % N;\n }\n\n void clear() {\n head = tail = 0;\n }\n}"}], "src_uid": "c112321ea5e5603fd0c95c4f01808db1"} {"source_code": "import std.stdio;\n\nstatic immutable N = 5000;\nint n, m, sum, ans;\nint[][N + 1] f;\nchar[][N + 1] s;\n\nint get_sum(int x1, int y1, int x2, int y2) {\n return f[x2][y2] + f[x1][y1] - f[x1][y2] - f[x2][y1];\n}\n\nint main() {\n readf(\" %d %d\", &n, &m);\n readln(s[0]);\n for (int i = 0; i < n; ++ i) readln(s[i]);\n f[0].length = N + 1;\n for (int i = 1; i <= 5000; ++ i) {\n f[i].length = N + 1;\n for (int j = 1; j <= 5000; ++ j)\n f[i][j] = f[i][j - 1] + (i <= n && j <= m ? (s[i - 1][j - 1] == '1') : 0);\n }\n for (int i = 2; i <= 5000; ++ i)\n for (int j = 1; j <= 5000; ++ j)\n f[i][j] += f[i - 1][j];\n ans = 1000000000;\n for (int k = 2; k <= 2500; ++ k) {\n int tmp = 0;\n for (int i = 1; (i - 1) * k < n; ++ i) {\n for (int j = 1; (j - 1) * k < m; ++ j) {\n int sum = get_sum((i - 1) * k, (j - 1) * k, i * k, j * k);\n tmp += (sum < k * k - sum ? sum : k * k - sum);\n }\n }\n if (ans > tmp) ans = tmp;\n }\n writeln(ans);\n return 0;\n}\n", "positive_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nint n, m;\nint[][] a;\n\nvoid main() {\n scan(n, m);\n int lim = 2 * max(n, m);\n a = new int[][](lim + 1, lim + 1);\n iota(1, n + 1).each!(i => a[i][1 .. m + 1] = readln.chomp.map!(b => (b - '0').to!int).array);\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", a);\n writeln();\n }\n\n foreach (i ; 1 .. lim + 1) {\n foreach (j ; 1 .. lim + 1) {\n a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];\n }\n }\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", a);\n writeln();\n }\n\n long ans = 4L * n * m;\n\n foreach (k ; 2 .. max(n, m) + 1) {\n long anst = 0;\n\n foreach (i ; 1 .. (n + k - 1) / k + 1) {\n foreach (j ; 1 .. (m + k - 1) / k + 1) {\n long x = a[i*k][j*k] - a[(i-1)*k][j*k] - a[i*k][(j-1)*k] + a[(i-1)*k][(j-1)*k];\n anst += min(x, k*k - x);\n }\n }\n\n ans = min(ans, anst);\n\n debug {\n writefln(\"k:%d, anst:%d\", k, anst);\n }\n }\n\n writeln(ans);\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "9e7f977b4761fcc2d0791cdb34583ba6"} {"source_code": "import std.stdio;\nimport std.random;\nimport std.range;\nimport std.string;\n\nint[26] dsu_arr;\nbool[26] seen;\n\nint leader(int i) {\n if (dsu_arr[i] == i) return i;\n return dsu_arr[i] = leader(dsu_arr[i]);\n}\n\nvoid unite(int a, int b) {\n dsu_arr[leader(a)] = leader(b);\n}\n\nvoid main() {\n for (int i = 0; i < 26; i++) dsu_arr[i] = i;\n auto strings = stdin.byLine;\n strings.popFront();\n foreach (line; strings) {\n for (int i = 1; i < line.length; i++) {\n unite(line[i - 1] - 'a', line[i] - 'a');\n }\n foreach (c; line) seen[c - 'a'] = true;\n }\n\n int t = 0;\n for (int i = 0; i < 26; i++) {\n if (seen[i] && leader(i) == i) t++;\n }\n\n writeln(t);\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = new string [n];\n\t\tforeach (ref line; s)\n\t\t{\n\t\t\tline = readln.strip;\n\t\t}\n\t\tint [char] pos;\n\t\tforeach (i, ref line; s)\n\t\t{\n\t\t\tforeach (const ref char c; line)\n\t\t\t{\n\t\t\t\tpos[c] = i;\n\t\t\t}\n\t\t}\n\n\t\tauto p = n.iota.array;\n\t\tauto r = new int [n];\n\n\t\tint root (int v)\n\t\t{\n\t\t\tif (p[v] == v)\n\t\t\t{\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\treturn p[v] = root (p[v]);\n\t\t}\n\n\t\tbool unite (int u, int v)\n\t\t{\n\t\t\tu = root (u);\n\t\t\tv = root (v);\n\t\t\tif (u == v)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (r[u] > r[v])\n\t\t\t{\n\t\t\t\tswap (u, v);\n\t\t\t}\n\t\t\tp[u] = v;\n\t\t\tif (r[u] == r[v])\n\t\t\t{\n\t\t\t\tr[v] += 1;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint res = n;\n\t\tforeach (i, ref line; s)\n\t\t{\n\t\t\tforeach (const ref char c; line)\n\t\t\t{\n\t\t\t\tif (unite (i, pos[c]))\n\t\t\t\t{\n\t\t\t\t\tres -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tstring[] ps;\n\tforeach(i; 0 .. n) ps ~= rstring;\n\n\tNode[] nodes;\n\tNode[int] letternodes;\n\tforeach(i; 0 .. 26){\n\t\tNode nd = new Node(i, 1);\n\t\tnodes ~= nd;\n\t\tletternodes['a' + i] = nd;\n\t}\n\n\tEdge[] edges;\n\tforeach(i, p; ps){\n\t\tNode nd = new Node(26 + i, 0);\n\t\tnodes ~= nd;\n\t\tforeach(c; p) edges ~= new Edge(nd, letternodes[c], 0);\n\t}\n\n\tforeach(ed; edges) ed.node1.group.eat(ed.node2.group);\n\t\n\tint ans;\n\tforeach(nd; nodes) if(nd.value == 0 && nd.group.id == nd.id) ans += 1;\n\n\tans.writeln;\n}\nclass Edge{\n\tNode node1;\n\tNode node2;\n\tlong value;\n\tthis(Node node1, Node node2, long value){\n\t\tthis.node1 = node1, this.node2 = node2;\n\t\tthis.value = value;\n\t}\n}\n\nclass Node{\n\tlong id;\n\tlong value;\n\tGroup group;\n\tthis(long id, long value){\n\t\tthis.id = id;\n\t\tthis.value = value;\n\t\tthis.group = new Group(this);\n\t}\n}\n\nclass Group{\n\tlong value;\n\tlong id;\n\tNode[] nodes;\n\tthis(Node node){\n\t\tthis.id = node.id;\n\t\tthis.nodes = [node];\n\t\tthis.value = node.value;\n\t}\n\tvoid eat(Group gp){\n\t\tif(this.id == gp.id) return;\n\t\tif(gp.nodes.length > this.nodes.length) gp.eat(this);\n\t\telse{\n\t\t\tforeach(nd; gp.nodes){\n\t\t\t\tthis.nodes ~= nd;\n\t\t\t\tnd.group = this;\n\t\t\t\tthis.value += nd.value;\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nstruct UnionFind\n{\n\tvoid init(int n) { par = new int[](n); foreach (i; 0..n) par[i] = i; cnt = new int[](n); fill(cnt, 1); }\n\tint root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }\n\tbool same(int i, int j) { return root(i) == root(j); }\n\tvoid unite(int i, int j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; cnt[j] += cnt[i]; }\n\tint size(int i) { return cnt[root(i)]; }\n\tint[] par, cnt;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\n\tUnionFind uf;\n\tuf.init(26);\n\tauto used = new bool[](26);\n\tforeach (i; 0..n)\n\t{\n\t\tauto s = RD!string;\n\t\tforeach (j; 0..s.length)\n\t\t{\n\t\t\tauto u = s[j]-'a';\n\t\t\tused[u] = true;\n\t\t\tforeach (k; j+1..s.length)\n\t\t\t{\n\t\t\t\tauto v = s[k]-'a';\n\t\t\t\tused[v] = true;\n\t\t\t\tuf.unite(u, v);\n\t\t\t}\n\t\t}\n\t}\n\n\tbool[int] set;\n\tforeach (i; 0..26)\n\t{\n\t\tif (!used[i]) continue;\n\t\tauto p = uf.root(i);\n\t\tset[p] = true;\n\t}\n\twriteln(set.keys.length);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "00db0111fd80ce1820da2af07a6cb8f1"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto ans = new char[][](n, n);\n\tans[0][0] = 'W';\n\tans[0][1] = 'B';\n\tans[0][2] = 'W';\n\tans[1][0] = 'B';\n\tans[2][0] = 'W';\n\tans[1][1] = 'W';\n\n\tbool visit(int y, int x, int c)\n\t{\n\t\tbool ok;\n\t\tif (inside(y, 0, n) && inside(x, 0, n))\n\t\t{\n\t\t\tif (ans[y][x] == char.init)\n\t\t\t{\n\t\t\t\tans[y][x] = c == 0 ? 'B' : 'W';\n\t\t\t\tok = true;\n\t\t\t}\n\t\t}\n\t\treturn ok;\n\t}\n\n\tint[3][] open = [[0,0,0], [0,1,1], [0,2,0], [1,0,1], [2,0,0], [1,1,0]];\n\twhile (!open.empty)\n\t{\n\t\tauto node = open.front; open.popFront;\n\t\tauto y = node[0];\n\t\tauto x = node[1];\n\t\tauto c = node[2];\n\t\tif (visit (y-1, x-2, c))\n\t\t\topen ~= [y-1, x-2, c^1];\n\t\tif (visit (y+1, x-2, c))\n\t\t\topen ~= [y+1, x-2, c^1];\n\t\tif (visit (y-1, x+2, c))\n\t\t\topen ~= [y-1, x+2, c^1];\n\t\tif (visit (y+1, x+2, c))\n\t\t\topen ~= [y+1, x+2, c^1];\n\t\tif (visit (y-2, x-1, c))\n\t\t\topen ~= [y-2, x-1, c^1];\n\t\tif (visit (y-2, x+1, c))\n\t\t\topen ~= [y-2, x+1, c^1];\n\t\tif (visit (y+2, x-1, c))\n\t\t\topen ~= [y+2, x-1, c^1];\n\t\tif (visit (y+2, x+1, c))\n\t\t\topen ~= [y+2, x+1, c^1];\n\t}\n\t\n\tforeach (y; 0..n)\n\t{\n\t\twriteln(ans[y]);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tforeach(i; 0 .. n){\n\t\tforeach(j; 0 .. n){\n\t\t\tif((i + j) % 2) \"B\".write;\n\t\t\telse \"W\".write;\n\t\t}\n\t\t\"\".writeln;\n\t}\n}\n"}], "negative_code": [], "src_uid": "09991e8e16cd395c7ce459817a385988"} {"source_code": "@safe:\nimport std;\n\nT read (alias T, string ending = \"\", string preface = \"\") () @trusted {\n scope T x;\n readf!(preface ~ \"%s\" ~ ending)(x);\n return x;\n}\n\nvoid main () {\n immutable tests = read!(uint, \"\\n\");\n\n foreach (test_index; 0 .. tests) {\n immutable l = read!(uint, \" \");\n immutable r = read!(uint, \" \");\n immutable k = read!(uint, \"\\n\");\n\n if (r == l) {\n if (r == 1) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n }\n continue;\n }\n\n immutable count_div_by_2 = (){\n static assert(true);\n if (r % 2 == l % 2) {\n if (r % 2 == 0) {\n return (r - l) / 2 + 1;\n } else {\n return (r - l) / 2;\n }\n }\n return (r - l + 1) / 2;\n }();\n\n immutable count_not_div_by_2 = r - l + 1 - count_div_by_2;\n\n if (k >= count_not_div_by_2) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n}\n// \"\"\n", "positive_code": [{"source_code": "import std;\n\nT read (alias T, string ending = \"\", string preface = \"\") () {\n scope T x;\n readf!(preface ~ \"%s\" ~ ending)(x);\n return x;\n}\n\nvoid main () {\n immutable tests = read!(uint, \"\\n\");\n\n foreach (test_index; 0 .. tests) {\n immutable l = read!(uint, \" \");\n immutable r = read!(uint, \" \");\n immutable k = read!(uint, \"\\n\");\n\n if (r == l) {\n if (r == 1) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n }\n continue;\n }\n\n immutable count_div_by_2 = (){\n static assert(true);\n if (r % 2 == l % 2) {\n if (r % 2 == 0) {\n return (r - l) / 2 + 1;\n } else {\n return (r - l) / 2;\n }\n }\n return (r - l + 1) / 2;\n }();\n\n immutable count_not_div_by_2 = r - l + 1 - count_div_by_2;\n\n if (k >= count_not_div_by_2) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n}\n// \"\"\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto L = scan!int;\r\n auto R = scan!int;\r\n auto K = scan!int;\r\n\r\n const evens = R/2 - (L-1)/2;\r\n const odds = R - L + 1 - evens;\r\n // [evens, odds].deb;\r\n\r\n if (R == L && L == 1) return \"NO\";\r\n if (R == L && L > 1) return \"YES\";\r\n\r\n return evens > 0 && odds <= K ? \"YES\" : \"NO\";\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nstruct GridPoint {\r\n static enum ZERO = GridPoint(0, 0);\r\n long x, y;\r\n \r\n static GridPoint reversed(long y, long x) {\r\n return GridPoint(x, y);\r\n }\r\n \r\n this(long x, long y) {\r\n this.x = x;\r\n this.y = y;\r\n }\r\n \r\n inout GridPoint left() { return GridPoint(x - 1, y); }\r\n inout GridPoint right() { return GridPoint(x + 1, y); }\r\n inout GridPoint up() { return GridPoint(x, y - 1); }\r\n inout GridPoint down() { return GridPoint(x, y + 1); }\r\n inout GridPoint leftUp() { return GridPoint(x - 1, y - 1); }\r\n inout GridPoint leftDown() { return GridPoint(x - 1, y + 1); }\r\n inout GridPoint rightUp() { return GridPoint(x + 1, y - 1); }\r\n inout GridPoint rightDown() { return GridPoint(x + 1, y + 1); }\r\n inout GridPoint[] around() { return [left(), up(), right(), down()]; }\r\n inout GridPoint[] around(GridPoint max) { GridPoint[] ret; if (x > 0) ret ~= left; if(x < max.x-1) ret ~= right; if(y > 0) ret ~= up; if(y < max.y-1) ret ~= down; return ret; }\r\n inout T of(T)(inout ref T[][] grid) { return grid[cast(int)y][cast(int)x]; }\r\n}"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n long l = scan; long r = scan; long k = scan;\n long len = r - l + 1;\n if(len == 1){\n writeln( (l == 1) ? \"NO\" : \"YES\");\n return;\n }\n\n long tim = len / 2;\n if(r % 2 == 1 && l % 2 == 1){ tim += 1; }\n writeln( (k >= tim) ? \"YES\" : \"NO\");\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [], "src_uid": "9363df0735005832573ef4d17b6a8302"} {"source_code": "import std.stdio;\nimport std.range;\nimport std.typecons;\nimport std.algorithm;\n\nvoid main()\n{\n\tbyte n, m;\n\n\treadf(\" %s %s\", &n, &m);\n\n\tforeach (i; 0..n) {\n\t\tforeach (j; 0..m)\n\t\t\tif (i % 2) {\n\t\t\t\tforeach (k; 0..m - 1) {\n\t\t\t\t\tstatic byte tmp = 3;\n\t\t\t\t\tauto temp = i;\n\t\t\t\t\tif (temp == tmp) {\n\t\t\t\t\t\twrite('#');\n\t\t\t\t\t\tforeach (l; 0..m - 1)\n\t\t\t\t\t\t\twrite('.');\n\t\t\t\t\t\ttmp += 4;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\twrite('.');\n\t\t\t\t\t\tif (k == m - 2)\n\t\t\t\t\t\t\twrite('#');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t\twrite('#');\n\t\twriteln();\n\t}\n}", "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n, m;\n n = cin.read_int;\n m = cin.read_int;\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (i % 2 == 0) {\n write(\"#\");\n } else {\n if (i % 4 == 1) {\n if (j < m - 1) write(\".\");\n else write(\"#\");\n } else {\n if (j == 0) write(\"#\");\n else write(\".\");\n }\n }\n }\n writeln();\n }\n } \n}"}, {"source_code": "import std.stdio, std.array, std.conv;\n\nvoid main(string[] args)\n{\n\tint n, m;\n\treadf(\" %s %s\", &n, &m);\n\n\tchar ch = '#';\n\tstring snake = to!string(ch).replicate(m);\n\tstring points = \".\".replicate(m-1);\n\n\tforeach(row; 1..n+1)\n\t\tif(row % 2)\n\t\t\twriteln(snake);\n\t\telse if(row % 4)\n\t\t\twriteln(points ~ ch);\n\t\telse\n\t\t\twriteln(ch ~ points);\n}"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip;\nimport std.algorithm.iteration : map;\nimport std.regex;\nimport std.range;\nimport std.conv;\n\nvoid main()\n{\n auto nm = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto n=nm[0], m=nm[1];\n auto p1 = '#'.repeat().take(m).to!string;\n auto p23 = '.'.repeat().take(m-1).to!string;\n auto p2 = \"#\"~p23;\n auto p3 = p23~\"#\";\n \n for(int i = 1; i <= n; i++) {\n writeln( (i%2!=0) ? p1\n :(i/2)%2==0 ? p2 \n : p3);\n }\n}"}, {"source_code": "import std.stdio;\n\nint main()\n{\n\tint n, m;\n\treadf(\"%d %d\", &n, &m);\n\tchar[] ol = new char[m];\n\tchar[] el = new char[m];\n\tforeach (int i; 0..m)\n\t{\n\t\tol[i] = '#';\n\t\tel[i] = '.';\n\t}\n\tforeach (int i; 0..n)\n\t{\n\t\tint idx = (i / 2) % 2 == 0 ? m-1 : 0;\n\t\tel[idx] = '#';\n\t\twrite((i % 2 == 0 ? ol : el) ~ \"\\n\");\n\t\tel[idx] = '.';\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n\n for (int i = 0; i < n; i++) {\n if (i % 2 == 0) {\n for (int j = 0; j < m; j++) {\n write(\"#\");\n }\n } else if (i % 4 == 1) {\n for (int j = 0; j < m - 1; j++) {\n write(\".\");\n }\n write(\"#\");\n } else {\n write(\"#\");\n for (int j = 0; j < m - 1; j++) {\n write(\".\");\n }\n }\n\n writeln;\n }\n}"}], "negative_code": [], "src_uid": "2a770c32d741b3440e7f78cd5670d54d"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n debug { a.writeln; }\n \n bool [int] v;\n a.each!(x => v[x] = true);\n \n int[] getAns(int x) {\n int ans = 0;\n auto powersOf2 = recurrence!((a, n) => a[n-1] * 2)(1U);\n foreach (p; powersOf2.until!(x => x > 10^^9 * 2)) {\n auto left = x - cast(int)p in v;\n auto right = x + cast(int)p in v;\n if (left && right) {\n ans = p;\n break;\n }\n if (left || right) ans = p;\n }\n \n if (ans == 0) return [x];\n \n auto ret = [x];\n if (x - ans in v) ret ~= x - ans;\n if (x + ans in v) ret ~= x + ans;\n return ret;\n }\n \n auto ans = a.map!(e => getAns(e)).maxElement!(e => e.length);\n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n\n bool[long] D;\n foreach (i; 0..N) {\n D[A[i]] = true;\n }\n\n int max_v = 1;\n long[] ans = [A[0]];\n\n\n foreach (a; A) {\n for (long d = 1; d < 10L^^10; d *= 2) {\n if ((a + d) in D && (a + 2*d) in D) {\n writeln(3);\n writeln(a, \" \", a+d, \" \", a+2*d);\n return;\n } else if (max_v == 1 && (a + d) in D) {\n max_v = 2;\n ans = [a, a+d];\n }\n }\n }\n\n max_v.writeln;\n ans.map!(to!string).join(\" \").writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n debug { a.writeln; }\n \n bool [int] v;\n a.each!(x => v[x] = true);\n \n int[] getAns(int x) {\n int ans = 0;\n uint p = 1;\n while (p <= 10^^9 * 2) {\n auto left = x - cast(int)p in v;\n auto right = x + cast(int)p in v;\n if (left && right) {\n ans = p; \n break;\n }\n if (left || right) ans = p;\n \n p *= 2;\n }\n \n if (ans == 0) return [x];\n \n auto ret = [x];\n if (x - ans in v) ret ~= x - ans;\n if (x + ans in v) ret ~= x + ans;\n return ret;\n }\n \n auto ans = a.map!(e => getAns(e)).maxElement!(e => e.length);\n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n debug { a.writeln; }\n \n bool [int] v;\n a.each!(x => v[x] = true);\n \n int[] getAns(int x) {\n int ans = 0;\n auto powersOf2 = recurrence!(q{ a[n-1] * 2 })(1U);\n foreach (p; powersOf2.until!(x => x > 10^^9 * 2)) {\n auto left = x - cast(int)p in v;\n auto right = x + cast(int)p in v;\n if (left && right) {\n ans = p;\n break;\n }\n if (left || right) ans = p;\n }\n \n if (ans == 0) return [x];\n \n auto ret = [x];\n if (x - ans in v) ret ~= x - ans;\n if (x + ans in v) ret ~= x + ans;\n return ret;\n }\n \n auto ans = a.map!(e => getAns(e)).maxElement!(e => e.length);\n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n debug { a.writeln; }\n \n bool [int] v;\n a.each!(x => v[x] = true);\n \n int[] getAns(int x) {\n int ans = 0;\n uint p = 1;\n while (p <= 10^^9 * 2) {\n auto left = (x - cast(int)p) in v;\n auto right = (x + cast(int)p) in v;\n if (left && right) {\n ans = p; \n break;\n }\n if (left || right) ans = cast(int)p;\n \n p *= 2;\n }\n \n if (ans == 0) return [x];\n \n auto ret = [x];\n if (x - ans in v) ret ~= x - ans;\n if (x + ans in v) ret ~= x + ans;\n return ret;\n }\n \n int[] ans = []; \n foreach (e; a) {\n auto cur = getAns(e);\n if (cur.length > ans.length) ans = cur;\n }\n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.container.rbtree;\nimport std.algorithm.comparison : equal;\n\nint main()\n{\n\tint n;\n\tscanf(\"%d\",&n);\n\n\tauto arr = new long[n];\n\n\tfor(int i = 0; i < n; i++)\n\t\tscanf(\"%lld\", &arr[i]);\n\n\tauto rbt = redBlackTree(arr);\n\n\tlong[] subset = [arr[0]];\n\n\tfor(int i = 0; i < n; i++)\n\t{\n\t\tfor(long d = 1; d < (1L << 31); d*= 2)\n\t\t{\n\t\t\tif(!rbt.equalRange(arr[i] + d).empty()) {\n\t\t\t\tif (!rbt.equalRange(arr[i] + d * 2).empty()) {\n\t\t\t\t\tprintf(\"3\\n\");\n\t\t\t\t\tprintf(\"%lld %lld %lld\\n\",arr[i], arr[i] + d, arr[i] + 2 * d);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\n\t\t\t\tsubset = [arr[i], arr[i] + d];\n\t\t\t}\n\t\t}\n\t}\n\n\tprintf(\"%d\\n\",subset.length);\n\t\n\tfor(int i =0; i < subset.length;i++)\n\t\tprintf(\"%lld \",subset[i]);\n\n\treturn 0;\n}\n"}, {"source_code": "void main(){\n import std.stdio, std.algorithm, std.string, std.conv;\n\n int n; rd(n);\n auto a=readln.split.to!(long[]);\n\n sort(a);\n import std.range;\n auto p=a.assumeSorted;\n long[] ans;\n foreach(b; 0..31){\n long d=1L<<b;\n auto used=new bool[](n);\n foreach(int i; 0..n){\n if(used[i]) continue;\n used[i]=true;\n int j=i;\n long[] beta=[a[j]];\n while(j<n){\n auto tri=p.trisect(a[j]+d);\n if(tri[1].empty){\n break;\n }else{\n j=tri[0].length.to!(int);\n beta~=a[j];\n used[j]=true;\n }\n if(beta.length==3) break;\n }\n if(ans.length<beta.length) ans=beta.dup;\n }\n }\n writeln(ans.length);\n writefln(\"%(%s %)\", ans); \n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n debug { a.writeln; }\n \n bool [int] v;\n a.each!(x => v[x] = true);\n \n int[] getAns(int x) {\n int ans = 0;\n auto powersOf2 = recurrence!(q{ a[n-1] * 2 })(1U);\n foreach (p; powersOf2.until!(x => x <= 10^^9 * 2)) {\n auto left = x - cast(int)p in v;\n auto right = x + cast(int)p in v;\n if (left && right) {\n ans = p;\n break;\n }\n if (left || right) ans = p;\n }\n \n if (ans == 0) return [x];\n \n auto ret = [x];\n if (x - ans in v) ret ~= x - ans;\n if (x + ans in v) ret ~= x + ans;\n return ret;\n }\n \n auto ans = a.map!(e => getAns(e)).maxElement!(e => e.length);\n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\n}"}, {"source_code": "void main(){\n import std.stdio, std.algorithm, std.string, std.conv;\n\n int n; rd(n);\n auto a=readln.split.to!(long[]);\n sort(a);\n\n import std.range;\n auto p=a.assumeSorted;\n long[] ans;\n foreach(b; 0..31){\n long d=1L<<b;\n auto used=new bool[](n);\n foreach(i; 0..n){\n if(used[i]) continue;\n used[i]=true;\n int j=i, cnt=1;\n long[] beta=[a[i]]; \n while(j<n){\n auto tri=p.trisect(a[j]+d);\n if(tri[1].empty){\n break;\n }else{\n cnt++;\n j=tri[0].length.to!(int);\n used[j]=true;\n beta~=a[j];\n }\n }\n if(ans.length<beta.length) ans=beta.dup;\n }\n }\n\n writeln(ans.length);\n writefln(\"%(%s %)\", ans);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "void main(){\n import std.stdio, std.algorithm, std.string, std.conv;\n\n int n; rd(n);\n auto a=readln.split.to!(long[]);\n\n sort(a);\n import std.range;\n auto p=a.assumeSorted;\n long[] ans;\n foreach(b; 0..31){\n long d=1L<<b;\n auto used=new bool[](n);\n foreach(int i; 0..n){\n if(used[i]) continue;\n used[i]=true;\n int j=i;\n long[] beta=[a[j]];\n while(j<n){\n auto tri=p.trisect(a[j]+d);\n if(tri[1].empty){\n break;\n }else{\n j=tri[0].length.to!(int);\n beta~=a[j];\n used[j]=true;\n }\n }\n if(ans.length<beta.length){\n ans=beta.dup;\n if(ans.length==3){\n writeln(ans.length);\n writefln(\"%(%s %)\", ans);\n return;\n }\n }\n }\n }\n writeln(ans.length);\n writefln(\"%(%s %)\", ans); \n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "void main(){\n import std.stdio, std.algorithm, std.string, std.conv;\n import std.random;\n\n int n; rd(n);\n auto a=readln.split.to!(long[]);\n\n // int n=15;\n // long[] a;\n // bool[long] h;\n // foreach(_; 0..n){\n // long e=uniform(-100, 100);\n // while(e in h){\n // e=uniform(-100, 100);\n // }\n // a~=e;\n // h[e]=true;\n // }\n\n sort(a);\n // writeln(a);\n\n import std.range;\n import core.bitop;\n auto p=a.assumeSorted;\n long[] ans;\n foreach(b; 0..32){\n long d=1L<<b;\n auto used=new bool[](n);\n foreach(i; 0..n){\n if(used[i]) continue;\n used[i]=true;\n int j=i;\n long[] beta=[a[i]]; \n while(j<n){\n auto tri=p.trisect(a[j]+d);\n if(tri[1].empty){\n break;\n }else{\n j=tri[0].length.to!(int);\n used[j]=true;\n beta~=a[j];\n }\n }\n if(ans.length<beta.length){\n if(b==0){\n if(popcnt(beta.length)==1) ans=beta.dup;\n }else{\n ans=beta.dup;\n }\n }\n }\n }\n\n writeln(ans.length);\n writefln(\"%(%s %)\", ans);\n\n // solve(a);\n}\n\nvoid solve(long[] a){\n import core.bitop, std.conv, std.math, std.algorithm;\n import std.stdio;\n int n=a.length.to!(int);\n long[] ret;\n foreach(bit; 0..(1<<n)){\n long[] cord;\n foreach(i; 0..n)if(bit&(1<<i)) cord~=a[i];\n int m=cord.length.to!(int);\n foreach(i; 0..m)foreach(j; 0..i){\n long dif=(cord[i]-cord[j]).abs;\n if(popcnt(dif)>1) goto hell;\n }\n if(ret.length<cord.length) ret=cord.dup;\n hell:;\n }\n writeln(ret.length);\n writeln(ret);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "src_uid": "f413556df7dc980ca7e7bd1168d700d2"} {"source_code": "import std.algorithm;\nimport std.c.stdio;\nimport std.stdio;\nimport std.conv;\nimport std.math;\nimport std.array;\nimport std.container;\n\nint curc;\nbool eof = false;\n\nvoid sb()\n{\n do\n {\n curc = getchar ();\n }\n while (0 <= curc && curc <= 32);\n if (curc == EOF)\n {\n eof = true;\n }\n}\n\nchar rc ()\n{\n sb ();\n return cast (char) curc;\n}\n\nint ni ()\n{\n sb ();\n int res = 0;\n do\n {\n res = res * 10 + cast (int) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nlong nl ()\n{\n sb ();\n long res = 0;\n do\n {\n res = res * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nchar[] ns ()\n{\n sb ();\n char[] res = [];\n do\n {\n res ~= to!char(curc);\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nvoid CFBETA142D()\n{\n import std.array;\n alias immutable int[] tuple;\n alias int[int] setint;\n alias long[long] setlong;\n long inf = (1L << 63) - 1;\n auto n = ni(), m = ni();\n int[][] g = new int[][](n, 0);\n int[tuple] weights; \n for (int i=0; i<m; ++i)\n {\n auto a = ni() - 1, b = ni() - 1, w = ni();\n weights[cast(tuple)[a,b]] = w;\n weights[cast(tuple)[b,a]] = w;\n g[a] ~= b;\n g[b] ~= a;\n }\n setlong[] t = new setlong[n];\n for (int i=0; i<n-1; ++i)\n {\n auto k = ni();\n int[] tmp = new int[k];\n for (int j = 0; j < k; ++j)\n tmp[j] = ni();\n for (int j = k - 1; j >= 0; --j)\n {\n auto p = (tmp[j] + 1) in t[i];\n if (p is null)\n t[i][tmp[j]] = tmp[j] + 1;\n else\n t[i][tmp[j]] = t[i][tmp[j] + 1];\n }\n }\n long get(long i, long time)\n {\n if ((time in t[cast(uint)i]) is null) return time;\n else return t[cast(uint)i][time];\n }\n long[] planets = new long[n];\n for (auto i=0; i<n; ++i) planets[i] = inf;\n planets[0] = get(0, 0);\n struct S\n {\n int v;\n int opCmp(ref const S s) const\n {\n if (planets[v] == planets[s.v])\n return v - s.v;\n else\n return planets[v] > planets[s.v] ? 1 : -1;\n }\n }\n auto q = redBlackTree!(\"a < b\", true)(cast(S)0);\n while (!q.empty())\n {\n auto v = q.front().v;\n q.removeFront();\n foreach (int to; g[v])\n {\n auto len = weights[cast(tuple)[v, to]];\n if (get(to, planets[v] + len) < planets[to])\n {\n q.removeKey(cast(S)to);\n planets[to] = get(to, planets[v] + len);\n q.insert(cast(S)to);\n }\n }\n }\n writeln(planets[n - 1] == inf ? -1 : planets[n - 1]);\n}\n\nvoid main()\n{\n CFBETA142D();\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.c.stdio;\nimport std.stdio;\nimport std.conv;\nimport std.math;\nimport std.array;\nimport std.container;\n\nint curc;\nbool eof = false;\n\nvoid sb()\n{\n do\n {\n curc = getchar ();\n }\n while (0 <= curc && curc <= 32);\n if (curc == EOF)\n {\n eof = true;\n }\n}\n\nchar rc ()\n{\n sb ();\n return cast (char) curc;\n}\n\nint ni ()\n{\n sb ();\n int res = 0;\n do\n {\n res = res * 10 + cast (int) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nlong nl ()\n{\n sb ();\n long res = 0;\n do\n {\n res = res * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nchar[] ns ()\n{\n sb ();\n char[] res = [];\n do\n {\n res ~= to!char(curc);\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nvoid CFBETA142D()\n{\n import std.array;\n alias immutable int[] tuple;\n alias int[int] setint;\n alias long[long] setlong;\n long inf = (1L << 63) - 1;\n auto n = ni(), m = ni();\n int[][] g = new int[][](n, 0);\n int[tuple] weights; \n for (int i=0; i<m; ++i)\n {\n auto a = ni() - 1, b = ni() - 1, w = ni();\n weights[cast(tuple)[a,b]] = w;\n weights[cast(tuple)[b,a]] = w;\n g[a] ~= b;\n g[b] ~= a;\n }\n setlong[] t = new setlong[n];\n for (int i=0; i<n-1; ++i)\n {\n auto k = ni();\n int[] tmp = new int[k];\n for (int j = 0; j < k; ++j)\n tmp[j] = ni();\n for (int j = k - 1; j >= 0; --j)\n {\n auto p = (tmp[j] + 1) in t[i];\n if (p is null)\n t[i][tmp[j]] = tmp[j] + 1;\n else\n t[i][tmp[j]] = t[i][tmp[j] + 1];\n }\n }\n long get(long i, long time)\n {\n if ((time in t[cast(uint)i]) is null) return time;\n else return t[cast(uint)i][time];\n }\n long[] planets = new long[n];\n for (auto i=0; i<n; ++i) planets[i] = inf;\n planets[0] = get(0, 0);\n struct S\n {\n int v;\n int opCmp(ref const S s) const\n {\n if (planets[v] == planets[s.v])\n return v - s.v;\n else\n return planets[v] > planets[s.v] ? 1 : -1;\n }\n }\n auto q = redBlackTree!(\"a < b\", false)(cast(S)0);\n while (!q.empty())\n {\n auto v = q.front().v;\n q.removeFront();\n foreach (int to; g[v])\n {\n auto len = weights[cast(tuple)[v, to]];\n if (get(to, planets[v] + len) < planets[to])\n {\n q.removeKey(cast(S)to);\n planets[to] = get(to, planets[v] + len);\n q.insert(cast(S)to);\n }\n }\n }\n writeln(planets[n - 1] == inf ? -1 : planets[n - 1]);\n}\n\nvoid main()\n{\n CFBETA142D();\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.c.stdio;\nimport std.stdio;\nimport std.conv;\nimport std.math;\nimport std.array;\nimport std.container;\n\nint curc;\nbool eof = false;\n\nvoid sb()\n{\n do\n {\n curc = getchar ();\n }\n while (0 <= curc && curc <= 32);\n if (curc == EOF)\n {\n eof = true;\n }\n}\n\nchar rc ()\n{\n sb ();\n return cast (char) curc;\n}\n\nint ni ()\n{\n sb ();\n int res = 0;\n do\n {\n res = res * 10 + cast (int) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nlong nl ()\n{\n sb ();\n long res = 0;\n do\n {\n res = res * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nchar[] ns ()\n{\n sb ();\n char[] res = [];\n do\n {\n res ~= to!char(curc);\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nvoid CFBETA142D()\n{\n import std.array;\n alias immutable int[] tuple;\n alias int[int] setint;\n alias long[long] setlong;\n long inf = (1L << 63) - 1;\n auto n = ni(), m = ni();\n int[][] g = new int[][](n, 0);\n int[tuple] weights; \n for (int i=0; i<m; ++i)\n {\n auto a = ni() - 1, b = ni() - 1, w = ni();\n weights[cast(tuple)[a,b]] = w;\n weights[cast(tuple)[b,a]] = w;\n g[a] ~= b;\n g[b] ~= a;\n }\n setlong[] t = new setlong[n];\n for (int i=0; i<n; ++i)\n {\n auto k = ni();\n int[] tmp = new int[k];\n for (int j = 0; j < k; ++j)\n tmp[j] = ni();\n for (int j = k - 1; j >= 0; --j)\n {\n auto p = (tmp[j] + 1) in t[i];\n if (p is null)\n t[i][tmp[j]] = tmp[j] + 1;\n else\n t[i][tmp[j]] = t[i][tmp[j] + 1];\n }\n }\n long get(long i, long time)\n {\n if ((time in t[cast(uint)i]) is null) return time;\n else return t[cast(uint)i][time];\n }\n long[] planets = new long[n];\n for (auto i=0; i<n; ++i) planets[i] = inf;\n planets[0] = t[0] !is null ? t[0][0] : 0;\n struct S\n {\n int v;\n int opCmp(ref const S s) const\n {\n if (planets[v] == planets[s.v])\n return v - s.v;\n else\n return planets[v] > planets[s.v] ? 1 : -1;\n }\n }\n auto q = redBlackTree!(\"a < b\", true)(cast(S)0);\n while (!q.empty())\n {\n auto v = q.front().v;\n q.removeFront();\n foreach (int to; g[v])\n {\n auto len = weights[cast(tuple)[v, to]];\n if (get(to, planets[v] + len) < planets[to])\n {\n q.removeKey(cast(S)to);\n planets[to] = get(to, planets[v] + len);\n q.insert(cast(S)to);\n }\n }\n }\n writeln(planets[n - 1] == inf ? -1 : planets[n - 1]);\n}\n\nvoid main()\n{\n CFBETA142D();\n}"}], "src_uid": "d5fbb3033bd7508fd468edb9bb995d6c"} {"source_code": "import std.stdio, std.string;\r\nimport std.conv, std.array;\r\nimport std.math, std.algorithm;\r\n \r\nint main(string[] args)\r\n{\r\n auto ret = readln.strip.split(\" \").map!(to!int).array;\r\n auto n = ret[0];\r\n auto k = to!int(readln.strip);\r\n auto res = 0;\r\n auto left = 1, right = n;\r\n while (left <= right)\r\n {\r\n auto mid = (left + right) >> 1;\r\n writeln(\"? 1 \", mid);\r\n stdout.flush;\r\n auto sum = to!int(readln.strip);\r\n if (mid - sum < k)\r\n {\r\n left = mid + 1;\r\n }\r\n else\r\n {\r\n right = mid - 1;\r\n res = mid;\r\n }\r\n }\r\n writeln(\"! \", res);\r\n return 0;\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\tauto t = RD!int;\r\n\tauto k = RD!int;\r\n\r\n\tbool f(int x)\r\n\t{\r\n\t\twriteln(\"? 1 \", x);\r\n\t\tstdout.flush;\r\n\t\tauto r = RD;\r\n\t\tauto zero = x - r;\r\n\t\treturn zero >= k;\r\n\t}\r\n\r\n\tauto ans = binarySearch!(f)(n+1, 0);\r\n\r\n\twriteln(\"! \", ans);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\tauto t = RD!int;\r\n\tauto k = RD!int;\r\n\r\n\tbool f(int x)\r\n\t{\r\n\t\twriteln(\"? 1 \", x);\r\n\t\tstdout.flush;\r\n\t\tauto r = RD;\r\n\t\tauto zero = x - r;\r\n\t\treturn zero >= k;\r\n\t}\r\n\r\n\tauto ans = binarySearch!(f)(n+1, 1);\r\n\r\n\twriteln(\"! \", ans);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "3cd1dac814fc53c094cc56dcd14d8ce9"} {"source_code": "import std.stdio, std.string, std.algorithm;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n;\r\n readf!\"%d\\n\"(n);\r\n char[][] s;\r\n int[][] p;\r\n foreach (i; 0 .. n)\r\n {\r\n s ~= cast(char[]) readln.strip;\r\n foreach (j; 0 .. n)\r\n if (s[i][j] == '*')\r\n p ~= [i, j];\r\n }\r\n p ~= p[0];\r\n p ~= p[1];\r\n if (p[0][0] == p[1][0])\r\n foreach (i; 2 .. 4)\r\n p[i][0] = (p[i][0] + 1) % n;\r\n else if (p[0][1] == p[1][1])\r\n foreach (i; 2 .. 4)\r\n p[i][1] = (p[i][1] + 1) % n;\r\n else\r\n swap(p[2][0], p[3][0]);\r\n s[p[2][0]][p[2][1]] = '*';\r\n s[p[3][0]][p[3][1]] = '*';\r\n foreach (it; s)\r\n writeln(it);\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio: readln, readf, writef;\nimport std.typecons;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n int T;\n readf(\"%d\\n\", &T);\n\n int N;\n for(int t = 0; t < T; ++t) {\n readf(\"%d\\n\", &N);\n char[][] a = new char[][](N, N);\n for(int n = 0; n < N; ++n)\n a[n] = readln.chomp.to!(char[]);\n \n Tuple!(int, \"y\", int, \"x\")[] p;\n for(int i = 0; i < N; ++i)\n for(int j = 0; j < N; ++j)\n if(a[i][j] == '*')\n p ~= tuple!(int, \"y\", int, \"x\")(i, j);\n\n if(p[0].x == p[1].x) {\n int x = 0;\n if(p[0].x == 0) ++x;\n\n a[p[0].y][x] = '*';\n a[p[1].y][x] = '*';\n } else if(p[0].y == p[1].y) {\n int y = 0;\n if(p[0].y == 0) ++y;\n\n a[y][p[0].x] = '*';\n a[y][p[1].x] = '*';\n } else {\n a[p[0].y][p[1].x] = '*';\n a[p[1].y][p[0].x] = '*';\n }\n\n writef(\"%(%(%c%)\\n%)\\n\", a);\n }\n}\n"}], "negative_code": [], "src_uid": "d8fb3822b983b8a8ffab341aee74f56f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tans[ti] = n / 2 + 1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.stdio, std.string;\n\nvoid main () {\n\tforeach (t; 0..readln.strip.to !(int))\n\t\twriteln (readln.strip.to !(int) / 2 + 1);\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n\n void solve(long tc = -1)\n {\n writeln(n / 2 + 1);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [{"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n\n void solve(long tc = -1)\n {\n if (n % 2 == 0)\n {\n writeln(n / 2 + 1);\n }\n else\n {\n writeln(n - 1);\n }\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "src_uid": "eb39ac8d703516c7f81f95a989791b21"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\n\tlong[] list = [1];\n\twhile (true)\n\t{\n\t\tauto x = list[$-1] * 3;\n\t\tif (x < list[$-1])\n\t\t\tbreak;\n\t\tlist ~= x;\n\t}\n\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tint pos;\n\t\twhile (list[pos] < n)\n\t\t{\n\t\t\t++pos;\n\t\t}\n\t\tif (pos != 0)\n\t\t\t--pos;\n\t\tauto l = 2L^^pos;\n\t\tauto r = 2L^^(list.length);\n\t\tforeach (j; l..r)\n\t\t{\n\t\t\tlong x;\n\t\t\tforeach (k; 0..32)\n\t\t\t{\n\t\t\t\tauto bit = 1L << k;\n\t\t\t\tif (j & bit)\n\t\t\t\t{\n\t\t\t\t\tx += list[k];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x >= n)\n\t\t\t{\n\t\t\t\tans[i] = x;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "// https://codeforces.com/problemset/problem/1249/C1\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int[] good;\n for(int mask = 1; mask < (1<<10); mask++) {\n int m = 0;\n for(int bit = 0; bit < 10; bit++) {\n if(mask&(1<<bit)) {\n m += 3^^bit;\n }\n }\n good ~= m;\n }\n foreach(line; stdin.byLine.dropOne) {\n int q = line.chomp.to!int;\n foreach(m; good) {\n if(m >= q) {\n m.writeln;\n break;\n }\n }\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\n\tlong[] list = [1];\n\twhile (true)\n\t{\n\t\tauto x = list[$-1] * 3;\n\t\tif (x < list[$-1])\n\t\t\tbreak;\n\t\tlist ~= x;\n\t}\n\tlist.reverse;\n\tdebug writeln(\"a\");\n\n\tforeach (loop; 0..q)\n\t{\n\t\tauto n = RD;\n\t\tlong[] x;\n\t\tauto dp = new long[][](list.length+1);\n\t\tdp[0] = [0];\n\t\tforeach (i; 0..list.length)\n\t\t{\n\t\t\tforeach (j; 0..dp[i].length)\n\t\t\t{\n\t\t\t\tauto tmp = dp[i][j] + list[i];\n\t\t\t\tif (tmp >= n)\n\t\t\t\t{\n\t\t\t\t\tx ~= tmp;\n\t\t\t\t\tdp[i+1] ~= dp[i][j];\n\t\t\t\t}\n\t\t\t\telse if (dp[i][j] + list[i]*2 >= n)\n\t\t\t\t{\n\t\t\t\t\tdp[i+1] ~= tmp;\n\t\t\t\t\tdp[i+1] ~= dp[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug writeln(x);\n\t\tdebug writeln(dp);\n\t\tans[loop] = x[x.MIN_POS];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\n\tlong[] list = [1];\n\twhile (true)\n\t{\n\t\tauto x = list[$-1] * 3;\n\t\tif (x < list[$-1])\n\t\t\tbreak;\n\t\tlist ~= x;\n\t}\n\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tint pos;\n\t\twhile (list[pos] < n)\n\t\t{\n\t\t\t++pos;\n\t\t}\n\t\tif (pos != 0)\n\t\t\t--pos;\n\t\tforeach (j; 2^^pos..2^^(list.length))\n\t\t{\n\t\t\tlong x;\n\t\t\tforeach (k; 0..32)\n\t\t\t{\n\t\t\t\tauto bit = 1L << k;\n\t\t\t\tif (j & bit)\n\t\t\t\t{\n\t\t\t\t\tx += list[k];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x >= n)\n\t\t\t{\n\t\t\t\tans[i] = x;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\n\tlong[] list = [1];\n\twhile (true)\n\t{\n\t\tauto x = list[$-1] * 3;\n\t\tif (x < list[$-1])\n\t\t\tbreak;\n\t\tlist ~= x;\n\t}\n\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tint pos;\n\t\twhile (list[pos] < n)\n\t\t{\n\t\t\t++pos;\n\t\t}\n\t\tif (pos != 0)\n\t\t\t--pos;\n\t\tforeach (long j; 2^^pos..2^^(list.length))\n\t\t{\n\t\t\tlong x;\n\t\t\tforeach (k; 0..32)\n\t\t\t{\n\t\t\t\tauto bit = 1L << k;\n\t\t\t\tif (j & bit)\n\t\t\t\t{\n\t\t\t\t\tx += list[k];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x >= n)\n\t\t\t{\n\t\t\t\tans[i] = x;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "5953b898995a82edfbd42b6c0f7138af"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln ()) != \"\")\n\t{\n\t\ts = s.strip ();\n\t\tint [] x, y, z;\n\t\tx = [0];\n\t\ty = [0];\n\t\tz = [0];\n\t\tforeach (c; s)\n\t\t{\n\t\t\tx ~= x[$ - 1] + (c == 'x');\n\t\t\ty ~= y[$ - 1] + (c == 'y');\n\t\t\tz ~= z[$ - 1] + (c == 'z');\n\t\t}\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (i; 0..q)\n\t\t{\n\t\t\tint l, r;\n\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\tint nx = x[r] - x[l - 1];\n\t\t\tint ny = y[r] - y[l - 1];\n\t\t\tint nz = z[r] - z[l - 1];\n\t\t\tint lo = min (nx, min (ny, nz));\n\t\t\tint hi = max (nx, max (ny, nz));\n\t\t\twriteln ((r - l < 2 || hi - lo <= 1) ? \"YES\" : \"NO\");\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\nimport core.thread;\n\n// Input\nstring[] tokens;\nint tokenId = 0;\nstring readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }\n\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n// chmin/chmax\nvoid chmin(T)(ref T t, T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, T f) { if (t < f) t = f; }\n\nimmutable int MAXN = 100005;\n\nint M;\nstring S;\n\nint[100005][5] dp;\n\nvoid main () {\n S = readToken();\n M = readInt();\n\n int A, B;\n\n foreach(int i; 0 .. to!int(S.length)) {\n dp[to!int(S[i] - 'x')][i + 1] += 1;\n\n foreach(int j; 0 .. 3) {\n dp[j][i + 1] += dp[j][i];\n }\n }\n\n foreach (int i; 0 .. M) {\n A = readInt();\n B = readInt();\n\n if (B - A < 2) {\n writeln(\"YES\");\n } else {\n int[3] buff;\n\n foreach(int j; 0 .. 3) { \n buff[j] = dp[j][B] - dp[j][A - 1];\n }\n\n buff.sort;\n\n if (buff[2] <= buff[0] + 1) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n }\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln ()) != \"\")\n\t{\n\t\ts = s.strip ();\n\t\tint [] x, y, z;\n\t\tx = [0];\n\t\ty = [0];\n\t\tz = [0];\n\t\tforeach (c; s)\n\t\t{\n\t\t\tx ~= x[$ - 1] + (c == 'x');\n\t\t\ty ~= y[$ - 1] + (c == 'y');\n\t\t\tz ~= z[$ - 1] + (c == 'z');\n\t\t}\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (i; 0..q)\n\t\t{\n\t\t\tint l, r;\n\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\tint nx = x[r] - x[l - 1];\n\t\t\tint ny = y[r] - y[l - 1];\n\t\t\tint nz = z[r] - z[l - 1];\n\t\t\tint lo = min (nx, min (ny, nz));\n\t\t\tint hi = max (nx, max (ny, nz));\n\t\t\twriteln ((hi - lo <= 1) ? \"YES\" : \"NO\");\n\t\t}\n\t}\n}\n"}], "src_uid": "4868cbb812d222ffababb4103210a3f1"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n writeln(\"\");\n auto x = solve(4,3,[10,20,30,40],[[1,4],[1,2],[2,3]]);\n assert(x == 40, \"Teste 1\");\n\n x = solve(4,4,[100,100,100,100],[[1,2],[2,3],[2,4],[3,4]]);\n assert(x == 400, \"Teste 2\");\n\n x = solve(7,10,[40,10,20,10,20,80,40],[[1,5],[4,7],[4,5],[5,2],[5,7],[6,4],[1,6],[1,3],[4,3],[1,4]]);\n assert(x == 160, \"Teste 3\");\n\n writeln(\"OK\");\n}\n\nvoid main(){\n uint v;\n uint e;\n uint[] w;\n uint[][] b;\n readf(\" %s \",&v);\n readf(\" %s \",&e);\n for(uint i = 0; i < v; i++){\n uint tmp;\n readf(\" %s \",&tmp);\n w ~= tmp;\n }\n\n for(uint i = 0; i < e; i++){\n uint tmp1,tmp2;\n readf(\" %s %s \",&tmp1,&tmp2);\n b ~= [tmp1,tmp2];\n }\n\n solve(v,e,w,b);\n}\n\nuint solve(uint v, uint e, uint[] w, uint[][] b){\n uint[][] g = new uint[][v];\n for(uint i = 0; i < v; i++){\n g[i] = new uint[v];\n }\n foreach(lnk;b){\n uint s = lnk[0]-1;\n uint d = lnk[1]-1;\n //writefln(\"%s,%s\",s+1,d+1);\n g[d][s] = 1;\n g[s][d] = 1;\n }\n\n uint[][] nw;\n foreach(uint i,x;w){ nw ~= [x,i+1]; }\n sort!(\"a > b\")(nw);\n //writeln(nw);\n\n uint rem = 0;\n uint cst = 0;\n while(rem < v){\n //writeln(nw,rem)\n uint vtx = nw[rem][1]-1;\n\n foreach(uint dtx,uint conn;g[vtx]){\n if(conn){\n// writefln(\"%s,%s\",dtx+1,vtx+1);\n if(g[vtx][dtx] == 1){\n g[vtx][dtx] = 0;\n g[dtx][vtx] = 0;\n //writefln(\"!|%s\",w[dtx]);\n cst += w[dtx];\n }\n }\n }\n rem++;\n }\n\n writeln(cst);\n return cst;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\tint m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto v = new int [n];\n\t\tforeach (ref x; v)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tauto a = new int [] [n];\n\t\tforeach (k; 0..m)\n\t\t{\n\t\t\tint i;\n\t\t\tint j;\n\t\t\treadf (\" %s %s\", &i, &j);\n\t\t\ti--;\n\t\t\tj--;\n\t\t\ta[i] ~= j;\n\t\t\ta[j] ~= i;\n\t\t}\n\n\t\tauto d = n.iota.array;\n\t\tsort !((a, b) => v[a] > v[b], SwapStrategy.stable) (d);\n\t\tlong res = 0;\n\t\tforeach (x; d)\n\t\t{\n\t\t\tforeach (i; a[x])\n\t\t\t{\n\t\t\t\tres += v[i];\n\t\t\t}\n\t\t\tv[x] = 0;\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n writeln(\"\");\n auto x = solve(4,3,[10,20,30,40],[[1,4],[1,2],[2,3]]);\n assert(x == 40, \"Teste 1\");\n\n x = solve(4,4,[100,100,100,100],[[1,2],[2,3],[2,4],[3,4]]);\n assert(x == 400, \"Teste 2\");\n\n x = solve(7,10,[40,10,20,10,20,80,40],[[1,5],[4,7],[4,5],[5,2],[5,7],[6,4],[1,6],[1,3],[4,3],[1,4]]);\n assert(x == 160, \"Teste 3\");\n\n writeln(\"OK\");\n}\n\nvoid main(){\n int v;\n int e;\n int[] w;\n int[][] b;\n readf(\" %s \",&v);\n readf(\" %s \",&e);\n for(int i = 0; i < v; i++){\n int tmp;\n readf(\" %s \",&tmp);\n w ~= tmp;\n }\n\n for(int i = 0; i < e; i++){\n int tmp1,tmp2;\n readf(\" %s %s \",&tmp1,&tmp2);\n b ~= [tmp1,tmp2];\n }\n\n solve(v,e,w,b);\n}\n\nint solve(int v, int e, int[] w, int[][] b){\n int[][] g = new int[][v];\n for(int i = 0; i < v; i++){\n g[i] = new int[v];\n }\n foreach(lnk;b){\n auto s = lnk[0]-1;\n auto d = lnk[1]-1;\n //writefln(\"%s,%s\",s+1,d+1);\n g[d][s] = 1;\n g[s][d] = 1;\n }\n\n int[][] nw;\n foreach(i,x;w){ nw ~= [x,i+1]; }\n sort!(\"a > b\")(nw);\n //writeln(nw);\n\n int rem = 0;\n auto cst = 0;\n while(rem < v){\n //writeln(nw,rem)\n uint vtx = nw[rem][1];\n\n foreach(dtx,conn;g[vtx]){\n if(conn){\n// writefln(\"%s,%s\",dtx+1,vtx+1);\n if(g[vtx][dtx] == 1){\n g[vtx][dtx] = 0;\n g[dtx][vtx] = 0;\n //writefln(\"!|%s\",w[dtx]);\n cst += w[dtx];\n }\n }\n }\n rem++;\n }\n\n writeln(cst);\n return cst;\n}\n"}], "src_uid": "2e6bf9154d9da6ac134b52144d5322ca"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n if (n % 3 < 2) {\n writeln(1, \" \", 1, \" \", n - 2);\n } else {\n writeln(1, \" \", 2, \" \", n - 3);\n }\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio, std.string, std.conv;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\treadf(\" %s\", &a);\n\tfor (int i=0; i<a+1; i++)\n\t{\n\t\tif (i%3!=0)\n\t\t{\n\t\t\tint b=a-i;\n\t\t\tfor (int j=0; j<b+1; j++)\n\t\t\t{\n\t\t\t\tif (j%3!=0)\n\t\t\t\t{\n\t\t\t\t\tif ((a-i-j)%3!=0)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln(i);\n\t\t\t\t\t\twriteln(j);\n\t\t\t\t\t\twriteln(a-i-j);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "91d5147fb602298e08cbdd9f86d833f8"} {"source_code": "\ufeffimport std.stdio, std.algorithm, std.string;\n\nstring[string] map;\n\nvoid main() {\n\n\tshort n;\n\n\tscanf(\"%hd\", &n);\n\n\tforeach (i; 0 .. n) {\n\t\tstring a, b, c;\n\t\ta = readln(' ').strip();\n\t\tb = readln().strip();\n\t\tif (a !in map)\n\t\t\tmap[a] = a;\n\t\tmap[b] = map[a];\n\t\tmap.remove(a);\n\t}\n\n\twriteln(map.length);\n\n\tforeach (i; map.keys)\n\t\twriteln(map[i], ' ', i);\n}", "positive_code": [{"source_code": "import std.string;\nimport std.stdio;\nimport std.array;\nvoid main() {\n\tint n;\n\tstdin.readf(\"%s\\n\", &n);\n\tint[string] map;\n\tstring[1001] orig;\n\tstring[1001] rmap;\n\tint count = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tstring line = stdin.readln();\n\t\tline = line.stripRight();\n\t\tstring[] names = line.split();\n\t\tint *p = (names[0] in map);\n\t\tif (p is null) {\n\t\t\t//New name\n\t\t\tmap[names[0]] = count++;\n\t\t\torig[map[names[0]]] = names[0];\n\t\t}\n\t\tmap[names[1]] = map[names[0]];\n\t\trmap[map[names[0]]] = names[1];\n\t}\n\tstdout.writefln(\"%s\", count);\n\tfor (int i = 0; i < count; i++)\n\t\tstdout.writefln(\"%s %s\", orig[i], rmap[i]);\n}\n"}], "negative_code": [], "src_uid": "bdd98d17ff0d804d88d662cba6a61e8f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\tauto q = RD!int;\n\t\tauto x = new int[](q);\n\t\tauto k = new long[](q);\n\t\tforeach (i; 0..q)\n\t\t{\n\t\t\tx[i] = RD!int-1;\n\t\t\tk[i] = RD;\n\t\t}\n\t\tauto index = k.MAKE_IDX;\n\n\t\tans[ti].length = q;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twhile (!index.empty)\n\t\t\t{\n\t\t\t\tauto j = index.front;\n\t\t\t\tif (k[j] > i) break;\n\t\t\t\tans[ti][j] = a[x[j]];\n\t\t\t\tindex.popFront;\n\t\t\t}\n\t\t\tauto cnt = new int[](n);\n\t\t\tforeach (e; a)\n\t\t\t\t++cnt[e-1];\n\t\t\tforeach (j; 0..n)\n\t\t\t\ta[j] = cnt[a[j]-1];\n\t\t}\n\t\twhile (!index.empty)\n\t\t{\n\t\t\tauto j = index.front;\n\t\t\tans[ti][j] = a[x[j]];\n\t\t\tindex.popFront;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\tforeach (ee; e)\n\t\t\twriteln(ee);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.functional, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool transform(int[] a, int[] freq)\n{\n freq[] = 0;\n bool changed = false;\n foreach (i ; 0 .. a.length) {\n freq[a[i]]++;\n }\n foreach (i ; 0 .. a.length) {\n int new_ai = freq[a[i]];\n if (new_ai != a[i])\n changed = true;\n a[i] = new_ai;\n }\n return changed;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = readln.strip.split.map!(to!int).array;\n auto q = readln.strip.to!int;\n Tuple!(int, int, int, int)[] queries;\n foreach (i ; 0 .. q) {\n int xi, ki;\n readf!\" %d %d \"(xi, ki);\n queries ~= tuple(xi, ki, i, 0);\n }\n queries.sort!((x, y) => x[1] < y[1]);\n auto freq = new int[](n + 1);\n\n int curk = 0;\n bool done = false;\n foreach (ref tmp ; queries) {\n int nextk = tmp[1];\n while (curk < nextk && !done) {\n if (!transform(a, freq))\n done = true;\n curk++;\n }\n tmp[3] = a[tmp[0] - 1];\n }\n\n queries.sort!((x, y) => x[2] < y[2]);\n foreach (ref tmp ; queries) {\n writeln(tmp[3]);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "43009fe44c2b5905c8160ac7ae9c595a"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\tint m;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\talias Chord = Tuple !(int, q{a}, int, q{b});\n\t\tauto s = new Chord [m];\n\t\tbool [Chord] v;\n\t\tforeach (ref c; s)\n\t\t{\n\t\t\treadf (\" %s %s\", &c.a, &c.b);\n\t\t\tc.a -= 1;\n\t\t\tc.b -= 1;\n\t\t\tv[c] = true;\n\t\t\tswap (c.a, c.b);\n\t\t\tv[c] = true;\n\t\t}\n\n\t\tforeach (d; 1..n)\n\t\t{\n\t\t\tif (n % d != 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tbool ok = true;\n\t\t\tforeach (ref c; s)\n\t\t\t{\n\t\t\t\tauto e = Chord ((c.a + d) % n, (c.b + d) % n);\n\t\t\t\tif (e !in v)\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t{\n\t\t\t\twriteln (\"Yes\");\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\t\twriteln (\"No\");\n\t}\n}\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.random;\nimport std.typecons;\nimport std.datetime.systime : Clock;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nalias T = Tuple!(uint, uint);\n\nvoid main() {\n rndGen.seed ((Clock.currTime.toHash & 0xffffffffU).to!uint); \n auto r = new InputReader;\n immutable n = r.next!uint, m = r.next!uint;\n auto a = uninitializedArray!(T[]) (m);\n bool[ulong] h;\n foreach (i; 0 .. m) {\n uint u = r.next!uint - 1, v = r.next!uint - 1;\n if (u > v) swap (u, v);\n a[i] = tuple (u, v);\n h[(u.to!ulong << 32) + v] = true;\n }\n randomShuffle (a);\n bool check (int k) {\n foreach (const p; a) {\n uint u = (p[0] + k) % n, v = (p[1] + k) % n;\n if (u > v) swap (u, v);\n if (! (((u.to!ulong << 32) + v) in h)) return false;\n }\n return true;\n }\n foreach (k; 1 .. n) {\n if (check (k)) {\n writeln (\"Yes\");\n return;\n }\n }\n writeln (\"No\");\n}\n\n"}], "negative_code": [], "src_uid": "dd7a7a4e5feb50ab6abb93d90c559c2b"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, d;\r\n\t\treadf !(\" %s %s\") (n, d);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\twriteln ((a[$ - 1] <= d || a[0] + a[1] <= d) ? \"Yes\" : \"No\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, D; get(N, D);\r\n int[] AS; get(AS);\r\n sort(AS);\r\n writeln(AS[$-1] <= D || (AS[0] + AS[1] <= D) ? \"YES\" : \"NO\");\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto d = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\ta.sort();\r\n\t\tauto x = a[0] + a[1];\r\n\t\tans[ti] = x <= d || a[$-1] <= d;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int d;\r\n readf!\"%d %d\\n\"(_, d);\r\n int[] a = readln.split.map!(to!int).array;\r\n a.sort();\r\n writeln(a[$ - 1] <= d || a[0] + a[1] <= d ? \"YES\" : \"NO\");\r\n }\r\n}"}], "negative_code": [], "src_uid": "044c2a3bafe4f47036ee81f2e40f639a"} {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\nvoid main() {\n int n;\n scan(n);\n\n auto a = readln.split.to!(int[]);\n auto b = readln.split.to!(int[]);\n\n int[int] r;\n\n foreach (i ; 0 .. n) {\n r[a[i]] = i;\n }\n\n int p = -1;\n int[] ans;\n\n foreach (i ; 0 .. n) {\n if (r[b[i]] < p) {\n ans ~= 0;\n }\n else {\n ans ~= r[b[i]] - p;\n p = r[b[i]];\n }\n }\n\n writefln(\"%(%s %)\", ans);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(a => a.to!int-1).array;\n auto B = readln.split.map!(a => a.to!int-1).array;\n auto used = new bool[](N);\n auto ans = new int[](N);\n\n for (int i = 0, j = 0; i < N; ++i) {\n if (used[B[i]]) continue;\n while (A[j] != B[i]) {\n ans[i] += 1;\n used[A[j]] = true;\n j += 1;\n }\n ans[i] += 1;\n used[A[j]] = true;\n j += 1;\n }\n\n ans.map!(to!string).join(\" \").writeln;\n}\n"}], "negative_code": [], "src_uid": "82176739a1dd4fe85ec059058a00fbb9"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto ans = 1, cur = 1;\n foreach (a, b; lockstep(arr, arr.dropOne)) {\n if (a*2 >= b) ++cur;\n else {\n ans = max(ans, cur);\n cur = 1;\n }\n }\n ans = max(ans, cur);\n \n ans.writeln;\n}", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n auto a=readln.split.to!(long[]);\n\n auto dp=new int[](n);\n dp[0]=1;\n foreach(i; 1..n){\n dp[i]=1;\n if(a[i]<=a[i-1]*2){\n dp[i]=max(dp[i], dp[i-1]+1);\n }\n }\n writeln(dp.reduce!(max));\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "5088d1d358508ea3684902c8e32443a3"} {"source_code": "import std.stdio;\nimport std.container;\nimport std.random;\nimport std.range;\nimport std.algorithm;\nimport std.typecons;\nimport std.conv;\nimport std.format;\n\nint[] par;\nlong[] smallest;\n\nint find_set(int v) {\n\tif (v == par[v]) return v;\n\treturn par[v] = find_set(par[v]);\n}\n\nMt19937 rng;\n\nvoid unite(int a, int b) {\n\ta = find_set(a);\n\tb = find_set(b);\n\tif (rng.front % 2) swap(a, b);\n\trng.popFront();\n\tpar[b] = a;\n\tsmallest[a] = min(smallest[a], smallest[b]);\n}\n\nvoid main() \n{\n\tint n, m;\n\tstdin.byLine.front.formattedRead!\"%d %d\"(n, m);\n\n\tpar = iota(n + 1).array;\n\tsmallest = stdin.byLine.front.split(\" \").map!`parse!long(a)`.array;\n\n\tauto S = redBlackTree!(Tuple!(long, int));\n\tauto offers = redBlackTree!(Tuple!(long, int, int));\n\n\tforeach (i, e; smallest) {\n\t\tS.insert(tuple(e, i.to!int));\n\t}\n\n\tfor (int i = 0; i < m; i++) {\n\t\tint a, b;\n\t\tlong w;\n\t\tstdin.byLine.front.formattedRead!\"%d %d %d\"(a, b, w);\n\n\t\ta--; b--;\n\t\toffers.insert(tuple(w, a, b));\n\t}\n\n\tlong totalCost = 0;\n\twhile (true) {\n\t\tif (S.length == 1) {\n\t\t\twriteln(totalCost);\n\t\t\treturn;\n\t\t}\n\n\t\twhile (offers.length > 0 && find_set(offers.front[1]) == find_set(offers.front[2]))\n\t\t\toffers.removeFront();\n\n\t\tauto c1 = S.front; S.removeFront();\n\t\tauto c2 = S.front; S.removeFront();\n\t\tauto cost = c1[0] + c2[0];\n\n\t\tif (offers.length > 0 && offers.front[0] < cost) {\n\t\t\tS.insert([c1, c2]);\n\t\t\ttotalCost += offers.front[0];\n\t\t\tint x = offers.front[1];\n\t\t\tint y = offers.front[2];\n\n\t\t\tint setx = find_set(x);\n\t\t\tint sety = find_set(y);\n\n\t\t\tS.removeKey(tuple(smallest[setx], setx));\n\t\t\tS.removeKey(tuple(smallest[sety], sety));\n\t\t\tunite(x, y);\n\t\t\tint setxy = find_set(x);\n\t\t\tS.insert(tuple(smallest[setxy], setxy));\n\t\t} else {\n\t\t\ttotalCost += cost;\n\t\t\tint x = c1[1];\n\t\t\tint y = c2[1];\n\t\t\tunite(x, y);\n\n\t\t\tint setxy = find_set(x);\n\t\t\tS.insert(tuple(smallest[setxy], setxy));\n\t\t}\n\t}\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.container;\nimport std.random;\nimport std.range;\nimport std.algorithm;\nimport std.typecons;\n\nint[] par;\nlong[] smallest;\n\nint find_set(int v) {\n\tif (v == par[v]) return v;\n\treturn par[v] = find_set(par[v]);\n}\n\nMt19937 rng;\n\nvoid unite(int a, int b) {\n\ta = find_set(a);\n\tb = find_set(b);\n\tif (rng.front % 2) swap(a, b);\n\trng.popFront();\n\tpar[b] = a;\n\tsmallest[a] = min(smallest[a], smallest[b]);\n}\n\nvoid main() \n{\n\tpar = iota(200000).array;\n\tsmallest = new long[200000];\n\n\tint n, m;\n\tscanf(\"%d%d\", &n, &m);\t\n\n\tauto S = redBlackTree!(Tuple!(long, int));\n\tauto offers = redBlackTree!(Tuple!(long, int, int));\n\n\tfor (int i = 0; i < n; i++) {\n\t\tlong x;\n\t\tscanf(\"%lld\", &x);\n\t\tsmallest[i] = x;\n\n\t\tS.insert(tuple(x, i));\n\t}\n\n\tfor (int i = 0; i < m; i++) {\n\t\tint a, b;\n\t\tlong w;\n\t\tscanf(\"%d%d%lld\", &a, &b, &w);\n\t\ta--; b--;\n\t\toffers.insert(tuple(w, a, b));\n\t}\n\n\tlong totalCost = 0;\n\twhile (true) {\n\t\tif (S.length == 1) {\n\t\t\twriteln(totalCost);\n\t\t\treturn;\n\t\t}\n\n\t\twhile (offers.length > 0 && find_set(offers.front[1]) == find_set(offers.front[2]))\n\t\t\toffers.removeFront();\n\n\t\tauto c1 = S.front; S.removeFront();\n\t\tauto c2 = S.front; S.removeFront();\n\t\tauto cost = c1[0] + c2[0];\n\n\t\tif (offers.length > 0 && offers.front[0] < cost) {\n\t\t\tS.insert([c1, c2]);\n\t\t\ttotalCost += offers.front[0];\n\t\t\tint x = offers.front[1];\n\t\t\tint y = offers.front[2];\n\n\t\t\tint setx = find_set(x);\n\t\t\tint sety = find_set(y);\n\n\t\t\tS.removeKey(tuple(smallest[setx], setx));\n\t\t\tS.removeKey(tuple(smallest[sety], sety));\n\t\t\tunite(x, y);\n\t\t\tint setxy = find_set(x);\n\t\t\tS.insert(tuple(smallest[setxy], setxy));\n\t\t} else {\n\t\t\ttotalCost += cost;\n\t\t\tint x = c1[1];\n\t\t\tint y = c2[1];\n\t\t\tunite(x, y);\n\n\t\t\tint setxy = find_set(x);\n\t\t\tS.insert(tuple(smallest[setxy], setxy));\n\t\t}\n\t}\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!long).array;\n auto X = new Tuple!(int, long)[][](N);\n foreach (i; 0..M) {\n auto t = readln.split;\n auto u = t[0].to!int - 1;\n auto v = t[1].to!int - 1;\n auto w = t[2].to!long;\n X[u] ~= tuple(v, w);\n X[v] ~= tuple(u, w);\n }\n\n long ans = 0;\n int S = A.minIndex.to!int;\n auto pq = new BinaryHeap!(Array!(Tuple!(int, long)), \"a[1] > b[1]\")();\n auto used = new bool[](N);\n used[S] = true;\n\n foreach (i; 0..N) {\n if (i == S) continue;\n pq.insert(tuple(i, A[S] + A[i]));\n }\n\n foreach (t; X[S]) {\n pq.insert(tuple(t[0], t[1]));\n }\n\n while (!pq.empty) {\n auto t = pq.front;\n pq.removeFront;\n auto u = t[0];\n auto w = t[1];\n if (used[u]) continue;\n ans += w;\n used[u] = true;\n foreach (v; X[u]) {\n if (used[v[0]]) continue;\n pq.insert(tuple(v[0], v[1]));\n }\n }\n\n ans.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!long).array;\n auto X = new Tuple!(int, long)[][](N);\n foreach (i; 0..M) {\n auto t = readln.split;\n auto u = t[0].to!int - 1;\n auto v = t[1].to!int - 1;\n auto w = t[2].to!long;\n X[u] ~= tuple(v, w);\n X[v] ~= tuple(u, w);\n }\n\n long ans = 0;\n int S = A.minIndex.to!int;\n auto pq = new BinaryHeap!(Array!(Tuple!(int, long)), \"a[1] > b[1]\")();\n auto used = new bool[](N);\n used[S] = true;\n\n foreach (i; 0..N) {\n if (i == S) continue;\n pq.insert(tuple(i, A[S] + A[i]));\n }\n\n foreach (t; X[0]) {\n pq.insert(tuple(t[0], t[1]));\n }\n\n while (!pq.empty) {\n auto t = pq.front;\n pq.removeFront;\n auto u = t[0];\n auto w = t[1];\n if (used[u]) continue;\n ans += w;\n used[u] = true;\n foreach (v; X[u]) {\n if (used[v[0]]) continue;\n pq.insert(tuple(v[0], v[1]));\n }\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.container;\nimport std.random;\nimport std.range;\nimport std.algorithm;\nimport std.typecons;\nimport std.conv;\nimport std.format;\n\nint[] par;\nlong[] smallest;\n\nint find_set(int v) {\n\tif (v == par[v]) return v;\n\treturn par[v] = find_set(par[v]);\n}\n\nMt19937 rng;\n\nvoid unite(int a, int b) {\n\ta = find_set(a);\n\tb = find_set(b);\n\tif (rng.front % 2) swap(a, b);\n\trng.popFront();\n\tpar[b] = a;\n\tsmallest[a] = min(smallest[a], smallest[b]);\n}\n\nvoid main() \n{\n\tpar = iota(200000).array;\n\n\tint n, m;\n\tstdin.byLine.front.formattedRead!\"%d %d\"(n, m);\n\n\tauto S = redBlackTree!(Tuple!(long, int));\n\tauto offers = redBlackTree!(Tuple!(long, int, int));\n\n\tsmallest = stdin.byLine.front.split(\" \").map!`parse!long(a)`.array;\n\n\tsmallest.writeln;\n\n\tforeach (i, e; smallest) {\n\t\tS.insert(tuple(e, i.to!int));\n\t}\n\n\tfor (int i = 0; i < m; i++) {\n\t\tint a, b;\n\t\tlong w;\n\t\tstdin.byLine.front.formattedRead!\"%d %d %d\"(a, b, w);\n\n\t\ta--; b--;\n\t\toffers.insert(tuple(w, a, b));\n\t}\n\n\tlong totalCost = 0;\n\twhile (true) {\n\t\tif (S.length == 1) {\n\t\t\twriteln(totalCost);\n\t\t\treturn;\n\t\t}\n\n\t\twhile (offers.length > 0 && find_set(offers.front[1]) == find_set(offers.front[2]))\n\t\t\toffers.removeFront();\n\n\t\tauto c1 = S.front; S.removeFront();\n\t\tauto c2 = S.front; S.removeFront();\n\t\tauto cost = c1[0] + c2[0];\n\n\t\tif (offers.length > 0 && offers.front[0] < cost) {\n\t\t\tS.insert([c1, c2]);\n\t\t\ttotalCost += offers.front[0];\n\t\t\tint x = offers.front[1];\n\t\t\tint y = offers.front[2];\n\n\t\t\tint setx = find_set(x);\n\t\t\tint sety = find_set(y);\n\n\t\t\tS.removeKey(tuple(smallest[setx], setx));\n\t\t\tS.removeKey(tuple(smallest[sety], sety));\n\t\t\tunite(x, y);\n\t\t\tint setxy = find_set(x);\n\t\t\tS.insert(tuple(smallest[setxy], setxy));\n\t\t} else {\n\t\t\ttotalCost += cost;\n\t\t\tint x = c1[1];\n\t\t\tint y = c2[1];\n\t\t\tunite(x, y);\n\n\t\t\tint setxy = find_set(x);\n\t\t\tS.insert(tuple(smallest[setxy], setxy));\n\t\t}\n\t}\n}"}], "src_uid": "e52ec2fa5bcf5d2027d57b0694b4e15a"} {"source_code": "import std.stdio;\nimport std.array: array, split;\nimport std.string: chomp;\nimport std.conv: to;\nimport std.algorithm: copy, sort, reverse, map, maxElement, minElement;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tint[] b = readln.split.map!(to!int).array;\n\tint[] a = new int[n];\n\tb.copy(a);\n\tb.sort;\n\n\tif (a == b) {\n\t\twriteln(\"yes\\n1 1\");\n\t} else {\n\t\tint[] c;\n\t\tforeach(int i; 0..n) {\n\t\t\tif (a[i] != b[i]) {\n\t\t\t\tc ~= [i];\n\t\t\t}\n\t\t}\n\t\tint x = minElement(c);\n\t\tint y = maxElement(c);\n\t\tif (a[0..x] ~ a[x..y+1].reverse ~ a[y+1..n] == b) {\n\t\t\twritefln(\"yes\\n%s %s\", x+1, y+1);\n\t\t} else {\n\t\t\twriteln(\"no\");\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.array: array;\nimport std.conv: to;\nimport std.algorithm: reverse, map, max, isSorted;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tlong[] a = readln.split.map!(to!long).array;\n\n\tint from;\n\tint to;\n\n\tlong last_max = a[0];\n\tlong last = a[0];\n\tbool x = false;\n\tbool y = false;\n\tbool no = false;\n\tbool z = false;\n\n\tif (a.isSorted) {\n\t\twriteln(\"yes\");\n\t\twriteln(\"1 1\");\n\t} else if (a.reverse.isSorted) {\n\t\twriteln(\"yes\");\n\t\twritefln(\"1 %s\", a.count);\n\t} else {\n\ta.reverse;\n\tforeach (int i; 0..n) {\n\t\tif (a[i] < last && !y) {\n\t\t\tfrom = i-1;\n\t\t\ty = true;\n\t\t} else if (y && !z && a[i] > last) {\n\t\t\tif (a[i] < last_max) {\n\t\t\t\twriteln(\"no\");\n\t\t\t\tno = true;\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tto = i-1;\n\t\t\t}\n\t\t\tz = true;\n\t\t} else if (z && a[i] < last) {\n\t\t\twriteln(\"no\");\n\t\t\tno = true;\n\t\t\tbreak;\n\t\t}\n\t\tlast = a[i];\n\t\tlast_max = max(a[i], last_max);\n\t}\n\tif (!no) {\n\t\tif (to != 0) {\n\t\t\twriteln(\"yes\");\n\t\t\twritefln(\"%s %s\", from + 1, to + 1);\n\t\t} else if (a[$-1] >= a[from - 1]) {\n\t\t\twriteln(\"yes\");\n\t\t\twritefln(\"%s %s\", from + 1, a.count);\n\t\t} else {\n\t\t\twriteln(\"no\");\n\t\t}\n\t}\n\t}\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/451/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(to!int).array;\n\n int inversions = 0;\n int[] idx;\n\n foreach(i; 1..n-1) {\n int last = a[i]-a[i-1];\n int now = a[i+1]-a[i];\n\n last = last/abs(last);\n now = now/abs(now);\n\n if(last != now) {\n inversions += 1;\n idx ~= i;\n //writefln(\"una inversion en %d\", i);\n }\n }\n\n\n if(inversions > 2) {\n writeln(\"no\");\n return;\n }\n\n if(inversions == 0) {\n if(a.isSorted) {\n writeln(\"yes\");\n writeln(\"1 1\");\n }\n else {\n writeln(\"yes\");\n writefln(\"1 %d\", n);\n }\n } else if (inversions == 1) {\n int[] firsttry;\n for(int i = 0; i <= idx[0]; i++) {\n firsttry ~= a[i];\n }\n firsttry.sort;\n for(int i = idx[0]+1; i < n; i++) {\n firsttry ~= a[i];\n }\n if(firsttry.isSorted) {\n writeln(\"yes\");\n writefln(\"1 %d\", idx[0]+1);\n return;\n }\n int[] secondtry;\n for(int i = 0; i < idx[0]; i++) {\n secondtry ~= a[i];\n }\n int[] lastpart;\n for(int i = idx[0]; i < n; i++) {\n lastpart ~= a[i];\n }\n lastpart.sort;\n foreach(item; lastpart) {\n secondtry ~= item;\n }\n if(secondtry.isSorted) {\n writeln(\"yes\");\n writefln(\"%d %d\", idx[0]+1, n);\n return;\n } else {\n writeln(\"no\");\n return;\n }\n } else {\n int idx1 = idx[0];\n int idx2 = idx[1];\n int[] test;\n int[] fin;\n for(int i = 0; i < idx[0]; i++)\n fin ~= a[i];\n for(int i = idx[0]; i <= idx[1]; i++)\n test ~= a[i];\n test.sort;\n foreach(item; test)\n fin ~= item;\n for(int i = idx[1]+1; i < n; i++)\n fin ~= a[i];\n if(fin.isSorted) {\n writeln(\"yes\");\n writefln(\"%d %d\", idx[0]+1, idx[1]+1);\n }\n else\n writeln(\"no\");\n }\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n=readln.chomp.to!int;\n auto a=readln.splitter\n .map!(to!int)\n .array;\n if(isStrictlyMonotonic(a)){\n writefln!\"yes \\n1 1\";\n }else{\n int l=0,r=n-1;\n while(l<=n && a[l+1]>a[l])\n l++;\n while(r>=1 && a[r-1]<a[r])\n r--;\n if(a[l..r+1].isStrictlyMonotonic!\"a>b\"){\n if((l==0 || a[l-1]<a[r])\n && (r==n-1 || a[r+1]>a[l]))\n writefln!\"yes\\n%d %d\"(l+1,r+1);\n else writeln(\"no\");\n }\n else writeln(\"no\");\n }\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n=readln.chomp.to!int;\n auto a=readln.splitter\n .map!(to!int)\n .array;\n if(isStrictlyMonotonic(a)){\n writefln!\"yes\\n1 1\";\n }else{\n int l=0,r=n-1;\n while(l<=n && a[l+1]>a[l])\n l++;\n while(r>=1 && a[r-1]<a[r])\n r--;\n if(a[l..r+1].isStrictlyMonotonic!\"a>b\"){\n if((l==0 || a[l-1]<a[r])\n && (r==n-1 || a[r+1]>a[l]))\n writefln!\"yes\\n%d %d\"(l+1,r+1);\n else writeln(\"no\");\n }\n else writeln(\"no\");\n }\n}\n\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nint[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\tint[] sorted = A.dup;\n\t\tsorted.sort();\n\t\tint minPos = N, maxPos = -1;\n\t\tforeach (i; 0 .. N) {\n\t\t\tif (A[i] != sorted[i]) {\n\t\t\t\tchmin(minPos, i);\n\t\t\t\tchmax(maxPos, i);\n\t\t\t}\n\t\t}\n\t\tif (minPos <= maxPos) {\n\t\t\tA[minPos .. maxPos + 1].reverse;\n\t\t\tbool ok = true;\n\t\t\tforeach (i; 0 .. N) {\n\t\t\t\tif (A[i] != sorted[i]) {\n\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\twriteln(\"yes\");\n\t\t\t\twriteln(minPos + 1, \" \", maxPos + 1);\n\t\t\t} else {\n\t\t\t\twriteln(\"no\");\n\t\t\t}\n\t\t} else {\n\t\t\twriteln(\"yes\");\n\t\t\twriteln(\"1 1\");\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.array: array;\nimport std.conv: to;\nimport std.algorithm: reverse, map, max, isSorted;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tint[] a = readln.split.map!(to!int).array;\n\n\tint from;\n\tint to;\n\n\tint last_max = a[0];\n\tint last = a[0];\n\tbyte x = 0;\n\tbool y = false;\n\tbool no = false;\n\n\tif (a.reverse.isSorted) {\n\t\twriteln(\"yes\");\n\t\twritefln(\"1 %s\", a.count);\n\t} else {\n\n\tforeach (int i; 0..n) {\n\t\tif ((x == 0 && a[0] > a[1] || x == 1 && a[0] < a[1]) && a[i] < last && !y) {\n\t\t\tfrom = i-1;\n\t\t\ty = true;\n\t\t}\n\t\tif ((x == 0 && a[0] > a[1] || x == 1 && a[0] < a[1]) && a[i] > last) {\n\t\t\tif (a[i] < last_max) {\n\t\t\t\twriteln(\"no\");\n\t\t\t\tno = true;\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tto = i;\n\t\t\t}\n\t\t\tx++;\n\t\t} else if (x && a[i] < last) {\n\t\t\twriteln(\"no\");\n\t\t\tno = true;\n\t\t\tbreak;\n\t\t}\n\t\tlast = i;\n\t\tlast_max = max(i, last_max);\n\t}\n\tif (!no) {\n\t\twriteln(\"yes\");\n\t\twritefln(\"%s %s\", from + 1, to + 1);\n\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.array: array;\nimport std.conv: to;\nimport std.algorithm: reverse, map, max, isSorted;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tint[] a = readln.split.map!(to!int).array;\n\n\tint from;\n\tint to;\n\n\tint last_max = a[0];\n\tint last = a[0];\n\tbool x = false;\n\tbool y = false;\n\tbool no = false;\n\tbool z = false;\n\n\tif (a.isSorted) {\n\t\twriteln(\"yes\");\n\t\twriteln(\"1 1\");\n\t} else if (a.reverse.isSorted) {\n\t\twriteln(\"yes\");\n\t\twritefln(\"1 %s\", a.count);\n\t} else {\n\ta.reverse;\n\tforeach (int i; 0..n) {\n\t\tif (a[i] < last && !y) {\n\t\t\tfrom = i-1;\n\t\t\ty = true;\n\t\t} else if (y && !z && a[i] > last) {\n\t\t\tif (a[i] < last_max) {\n\t\t\t\twriteln(\"no\");\n\t\t\t\tno = true;\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tto = i-1;\n\t\t\t}\n\t\t\tz = true;\n\t\t} else if (z && a[i] < last) {\n\t\t\twriteln(\"no\");\n\t\t\tno = true;\n\t\t\tbreak;\n\t\t}\n\t\tlast = a[i];\n\t\tlast_max = max(a[i], last_max);\n\t}\n\tif (!no) {\n\t\twriteln(\"yes\");\n\t\twritefln(\"%s %s\", from + 1, to + 1);\n\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.array: array;\nimport std.conv: to;\nimport std.algorithm: reverse, map, max, isSorted;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tlong[] a = readln.split.map!(to!long).array;\n\n\tint from;\n\tint to;\n\n\tlong last_max = a[0];\n\tlong last = a[0];\n\tbool x = false;\n\tbool y = false;\n\tbool no = false;\n\tbool z = false;\n\n\tif (a.isSorted) {\n\t\twriteln(\"yes\");\n\t\twriteln(\"1 1\");\n\t} else if (a.reverse.isSorted) {\n\t\twriteln(\"yes\");\n\t\twritefln(\"1 %s\", a.count);\n\t} else {\n\ta.reverse;\n\tforeach (int i; 0..n) {\n\t\tif (a[i] < last && !y) {\n\t\t\tfrom = i-1;\n\t\t\ty = true;\n\t\t} else if (y && !z && a[i] > last) {\n\t\t\tif (a[i] < last_max) {\n\t\t\t\twriteln(\"no\");\n\t\t\t\tno = true;\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tto = i-1;\n\t\t\t}\n\t\t\tz = true;\n\t\t} else if (z && a[i] < last) {\n\t\t\twriteln(\"no\");\n\t\t\tno = true;\n\t\t\tbreak;\n\t\t}\n\t\tlast = a[i];\n\t\tlast_max = max(a[i], last_max);\n\t}\n\tif (!no) {\n\t\twriteln(\"yes\");\n\t\tif (to != 0) {\n\t\t\twritefln(\"%s %s\", from + 1, to + 1);\n\t\t} else {\n\t\t\twritefln(\"%s %s\", from + 1, a.count);\n\t\t}\n\t}\n\t}\n}\n"}], "src_uid": "c9744e25f92bae784c3a4833c15d03f4"} {"source_code": "import std.c.stdio;\nimport std.stdio;\n\nvoid main() {\n int n; scanf(\"%d\", &n);\n int a;\n int f = 0, z = 0;\n for (int i = 0; i < n; i++) {\n scanf(\"%d\", &a);\n if (a == 5) { f++; }\n else { z++; }\n }\n if (z == 0) {\n printf(\"-1\\n\");\n return;\n }\n if (f < 9) {\n printf(\"0\\n\");\n return;\n } \n int x = f / 9 * 9;\n for (int i = 0; i < x; i++) {\n printf(\"5\");\n }\n for (int i = 0; i < z; i++) {\n printf(\"0\");\n }\n printf(\"\\n\");\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n int n;\n scanf(\"%u\", &n);\n\n int a5, a0;\n while(n--) {\n\t\tint t;\n\t\tscanf(\"%u\", &t);\n\n\t\tif(t == 5) a5++;\n\t\telse a0++;\n }\n\n\tif(a0 == 0) {\n\t\twrite(-1);\n\t\treturn;\n\t}\n\n\tint m, c;\n\n\tforeach(i; 0..a5)\n\t\tif((m += 5) % 9 == 0) c = i + 1;\n\n\tif(!c)\n\t\ta0 = 1;\n\n\twhile(c--) write(5);\n\twhile(a0--) write(0);\n}\n"}], "negative_code": [{"source_code": "import std.c.stdio;\nimport std.stdio;\n\nvoid main() {\n int n; scanf(\"%d\", &n);\n int a;\n int f = 0, z = 0;\n for (int i = 0; i < n; i++) {\n scanf(\"%d\", &a);\n if (a == 5) { f++; }\n else { z++; }\n }\n if (f < 9 || z == 0) {\n printf(\"0\\n\");\n return;\n } \n int x = f / 9 * 9;\n for (int i = 0; i < x; i++) {\n printf(\"5\");\n }\n for (int i = 0; i < z; i++) {\n printf(\"0\");\n }\n printf(\"\\n\");\n}\n"}], "src_uid": "409b27044d5ec97b5315c92d4112376f"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.format;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint [] [] a;\nbool [] b;\nint [] d;\nint n, m;\n\nvoid recur (int w)\n{\n\tif (b[w])\n\t{\n\t\treturn;\n\t}\n\tb[w] = true;\n\tforeach (c; a[w])\n\t{\n\t\trecur (c);\n\t}\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\ta = new int [] [n];\n\t\td = new int [n];\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t\td[u]++;\n\t\t\td[v]++;\n\t\t}\n\n\t\tb = new bool [n];\n\t\trecur (0);\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tok &= b[i];\n\t\t}\n\n\t\tauto s = new int [n + m + 1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts[d[i]]++;\n\t\t}\n\t\tdebug {writeln (ok);}\n\n\t\tif (ok && s[1] == 2 && s[2] == n - 2)\n\t\t{\n\t\t\twriteln (\"bus topology\");\n\t\t}\n\t\telse if (ok && s[2] == n)\n\t\t{\n\t\t\twriteln (\"ring topology\");\n\t\t}\n\t\telse if (ok && s[1] == n - 1 && s[n - 1] == 1)\n\t\t{\n\t\t\twriteln (\"star topology\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"unknown topology\");\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\n\nvoid main() {\n int m, n; readf(\"%d %d\\n\", &m, &n);\n int[] c = new int[m];\n foreach (i; 0 .. n) {\n int x, y; readf(\"%d %d\\n\", &x, &y); x--, y--;\n c[x]++, c[y]++;\n }\n if (!c.find(n).empty) {\n writeln(\"star topology\");\n } else if (c.count(1) == 2 && c.count(2) == m - 2) {\n writeln(\"bus topology\");\n } else if (c.count(2) == m) {\n writeln(\"ring topology\");\n } else {\n writeln(\"unknown topology\");\n }\n}\n"}, {"source_code": "module sigod.codeforces.p292B;\n\nimport std.algorithm;\nimport std.stdio;\nimport std.typecons;\n\nprivate {\n\tenum BUS = \"bus topology\";\n\tenum RING = \"ring topology\";\n\tenum STAR = \"star topology\";\n\tenum UNKNOWN = \"unknown topology\";\n}\n\nvoid main()\n{\n\tint n, m;\n\tstdin.readf(\" %s %s\", &n, &m);\n\n\tint[] vertex = new int[n];\n\n\tforeach (i; 0 .. m) {\n\t\tint x, y;\n\t\tstdin.readf(\" %s %s\", &x, &y);\n\n\t\t++vertex[x - 1];\n\t\t++vertex[y - 1];\n\t}\n\n\tvertex.sort();\n\n\tauto g = vertex.group();\n\n\tif (n == m + 1) {\n\t\tif (equal(g, [tuple(1, 2u), tuple(2, cast(uint) n - 2)][])) {\n\t\t\tstdout.writeln(BUS);\n\t\t}\n\t\telse if (equal(g, [tuple(1, n - 1), tuple(n - 1, 1)][])) {\n\t\t\tstdout.writeln(STAR);\n\t\t}\n\t\telse {\n\t\t\tstdout.writeln(UNKNOWN);\n\t\t}\n\t}\n\telse if (n == m && equal(g, [tuple(2, n)][])) {\n\t\tstdout.writeln(RING);\n\t}\n\telse {\n\t\tstdout.writeln(UNKNOWN);\n\t}\n}"}], "negative_code": [{"source_code": "module sigod.codeforces.p292B;\n\nimport std.algorithm;\nimport std.stdio;\nimport std.typecons;\n\nprivate {\n\tenum BUS = \"bus topology\";\n\tenum RING = \"ring topology\";\n\tenum STAR = \"star topology\";\n\tenum UNKNOWN = \"unknown topology\";\n}\n\nvoid main()\n{\n\tint n, m;\n\tstdin.readf(\" %s %s\", &n, &m);\n\n\tbyte[] vertex = new byte[n];\n\n\tforeach (i; 0 .. m) {\n\t\tint x, y;\n\t\tstdin.readf(\" %s %s\", &x, &y);\n\n\t\t++vertex[x - 1];\n\t\t++vertex[y - 1];\n\t}\n\n\tvertex.sort();\n\n\tauto g = vertex.group();\n\n\tif (n == m + 1) {\n\t\tif (equal(g, [tuple(1, 2u), tuple(2, cast(uint) n - 2)][])) {\n\t\t\tstdout.writeln(BUS);\n\t\t}\n\t\telse if (equal(g, [tuple(1, n - 1), tuple(n - 1, 1)][])) {\n\t\t\tstdout.writeln(STAR);\n\t\t}\n\t\telse {\n\t\t\tstdout.writeln(UNKNOWN);\n\t\t}\n\t}\n\telse if (n == m && equal(g, [tuple(2, n)][])) {\n\t\tstdout.writeln(RING);\n\t}\n\telse {\n\t\tstdout.writeln(UNKNOWN);\n\t}\n}"}], "src_uid": "7bb088ce5e4e2101221c706ff87841e4"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto T = RD!int;\n\tforeach (i; 0..T)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!int;\n\t\tauto t = RD!int;\n\t\tauto x = min(s, t);\n\t\twriteln(n - x + 1);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable nt = r.next!int;\n foreach (tid; 0 .. nt) {\n immutable n = r.next!int;\n immutable s = r.next!int;\n immutable t = r.next!int;\n auto y = n - s;\n auto x = n - t;\n auto z = s - x;\n debug stderr.writefln (\"x = %d, y = %d, z = %d\", x, y, z);\n writeln (max (x, y) + 1);\n }\n}\n\n"}], "negative_code": [], "src_uid": "fb0a4c8f737c36596c2d8c1ae0d1e34e"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n long a = scan;\n long b = scan;\n long c = scan;\n long res = (a + c - 2*b) % 3;\n if(res != 0){\n writeln(1);\n }else{\n writeln(0);\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\nimport std.math;\n\n\nvoid main() {\n int cases = to!int(strip(readln()));\n\n // per testcase\n for (int t = 0; t < cases; t++) {\n int a, b, c;\n readf!\"%d %d %d\\n\"(a, b, c);\n\n int da = a - b;\n int dc = c - b;\n\n // writeln(to!string(da) ~ \" 0 \" ~ to!string(dc));\n\n if ((dc + da) % 3 == 0) writeln(0);\n else writeln(1);\n\n }\n}\n/*\ndist\n\nabs(dc - da)\n-1 -> 2\n-2 -> 4\n-3 -> 6\n\n\n2 0 -2 -> yes\n\n1 0 -1 -> yes\n\n0 0 0 -> yes\n\ndc + abs(da) % 3 == 0\n\n-1 0 -2 -> yes\n-1 0 -1 -> no\n-1 0 0 -> no\n-1 0 1 -> yes\n-1 0 2 -> no\n-1 0 3 -> no\n-1 0 4 -> yes\n\n-2 0 0 -> no\n-2 0 1 -> no\n-2 0 2 -> yes\n-2 0 3 -> no\n-2 0 4 -> no\n-2 0 5 -> yes\n\n-3 0 0 -> yes\n-3 0 1 -> no\n-3 0 2 -> no\n-3 0 3 -> yes\n\n\n-4 0 0 -> no\n-5 0 0 -> no\n-6 0 0 -> yes\n\n0, 0, 4\n-2, 0, 3\n-1, 0, -1\n\n0, 4\n\n-5 0 -1\n-3 0 0\n-1 0 1\n\n-1 0 3\n-2 0 1\n-3 0 2*/\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tint sum = readInt!int + readInt!int + readInt!int;\n\tswitch (sum % 3)\n\t{\n\tcase 0: return writeln(0);\n\tdefault: return writeln(1);\n\t}\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "5bffe38e3ac9511a30ee02b4ec5cb1d5"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n dchar[][] s;\n auto r = () => readln.chomp.to!(dchar[]);\n s ~= r();\n s ~= r();\n \n auto ans = 0;\n foreach (i; 0 .. n / 2) {\n auto c = [ s[0][i], s[1][i], s[0][n-1-i], s[1][n-1-i] ].sort();\n \n debug { c.writeln; }\n \n if (c[0] == c[1] && c[2] == c[3]) continue;\n \n auto s0arr = [s[0][i], s[0][n-1-i]].sort();\n auto s1arr = [s[1][i], s[1][n-1-i]].sort();\n \n debug { writeln(i, \": \", setIntersection(s0arr, s1arr)); }\n \n if (s[1][i] == s[1][n-1-i] || !setIntersection(s0arr, s1arr).empty()) ans += 1;\n else ans += 2;\n }\n \n if (n % 2 == 1 && s[0][n/2] != s[1][n/2]) ++ans;\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n dchar[][] s;\n auto r = () => readln.chomp.to!(dchar[]);\n s ~= r();\n s ~= r();\n \n auto ans = 0;\n foreach (i; 0 .. n / 2) {\n auto c = [ s[0][i], s[1][i], s[0][n-1-i], s[1][n-1-i] ].sort();\n \n debug { c.writeln; }\n \n if (c[0] == c[1] && c[2] == c[3]) continue;\n \n if (s[0][i] == s[1][i] || s[0][i] == s[1][n-1-i]\n || s[0][n-1-i] == s[1][i] || s[0][n-1-i] == s[1][n-1-i]\n || s[1][i] == s[1][n-1-i]) ans += 1;\n else ans += 2;\n }\n \n if (n % 2 == 1 && s[0][n/2] != s[1][n/2]) ++ans;\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n dchar[][] s;\n auto r = () => readln.chomp.to!(dchar[]);\n s ~= r();\n s ~= r();\n \n auto ans = 0;\n foreach (i; 0 .. n / 2) {\n auto c = [ s[0][i], s[1][i], s[0][n-1-i], s[1][n-1-i] ].sort();\n \n debug { c.writeln; }\n \n if (c[0] == c[1] && c[2] == c[3]) continue;\n \n ans += min(2, cast(int)(c[0] != c[1]) + cast(int)(c[1] != c[2]) + cast(int)(c[2] != c[3]));\n }\n \n if (n % 2 == 1 && s[0][n/2] != s[1][n/2]) ++ans;\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n dchar[][] s;\n auto r = () => readln.chomp.to!(dchar[]);\n s ~= r();\n s ~= r();\n \n auto ans = 0;\n foreach (i; 0 .. n / 2) {\n auto c = [ s[0][i], s[1][i], s[0][n-1-i], s[1][n-1-i] ].sort();\n \n debug { c.writeln; }\n \n if (c[0] == c[1] && c[2] == c[3]) continue;\n \n if (s[0][i] == s[1][i] || s[0][i] == s[1][n-1-i]\n || s[0][n-1-i] == s[1][i] || s[0][n-1-i] == s[1][n-1-i]) ans += 1;\n else ans += 2;\n }\n \n if (n % 2 == 1 && s[0][n/2] != s[1][n/2]) ++ans;\n \n ans.writeln;\n}"}], "src_uid": "259b4b538743608227bb6d22453b0833"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %d\", &x);\n\t\t}\n\t\tsort !(\"a < b\", SwapStrategy.stable) (a);\n\t\tlong res;\n\t\tforeach (i, c; a)\n\t\t{\n\t\t\tres += cast (long) (i + 2) * c;\n\t\t}\n\t\tres -= a[$ - 1];\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main() {\n int n;\n readf(\" %s\", n);\n\n auto a = new long[n];\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n a.sort();\n\n long result = 0;\n foreach(i; 0..n) {\n result += a[i];\n }\n foreach(i; 0..n-1) {\n result += a[i] * (i+1); \n }\n result += a[n-1] * (n-1);\n writeln(result);\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\nunittest{\n assert(solve([3,1,5]) == 26, \"Teste 1\");\n assert(solve([10]) == 10, \"Teste 1\");\n}\n\nulong solve(ulong[] l){\n sort!(\"a > b\")(l);\n\n auto sum = l.length*l[0];\n foreach(i,x; l[1..$]){\n sum += (l.length-i)*x;\n }\n\n debug(1) writeln(l[1..$]);\n debug(1) writeln(sum);\n return sum;\n}\n\nvoid main(){\n size_t n;\n readf(\"%s\\n\",&n);\n\n ulong[] l = new ulong[n];\n for(ulong i = 0; i < n; i++){\n readf(\"%s \",l.ptr+i);\n }\n writeln(solve(l));\n}\n"}, {"source_code": "module main;\n\nimport std.stdio, std.string, std.algorithm;\n\nvoid solve(int[] a)\n{\n sort(a);\n long ans = 0, sum = 0;\n for (int i = a.length - 1; i >= 0; -- i)\n {\n sum += a[i];\n ans += sum;\n }\n ans -= a[$ - 1];\n ans += sum;\n writefln(\"%d\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i, ref v; a)\n {\n scanf(\"%d\", &v);\n }\n solve(a);\n }\n return 0;\n}"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nlong[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new long[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readLong;\n\t\t}\n\t\t\n\t\tlong ans;\n\t\tauto q = BinaryHeap!(Array!long)();\n\t\tforeach (a; A) {\n\t\t\tans += a;\n\t\t\tq.insert(a);\n\t\t}\n\t\tfor (; ; ) {\n\t\t\tconst a = q.front; q.removeFront;\n\t\t\tif (q.empty) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst b = q.front; q.removeFront;\n\t\t\tans += a + b;\n\t\t\tq.insert(a + b);\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main() {\n int n;\n readf(\" %s\", n);\n\n auto a = new int[n];\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n a.sort();\n\n long result = 0;\n foreach(i; 0..n) {\n result += a[i];\n }\n foreach(i; 0..n-1) {\n result += a[i] * (i+1); \n }\n result += a[n-1] * (n-1);\n writeln(result);\n}\n"}], "src_uid": "4266948a2e793b4b461156af226e98fd"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1437/problem/B\n// string manipulation, greedy\nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\n long n;\n string s;\n while(t--) {\n readf(\"%s\\n%s\\n\", &n, &s);\n long ans = n - s.count(\"10\") - s.count(\"01\");\n (ans/2).writeln;\n }\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto s = readln.strip;\n\t\tint cur = 1;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tcur += (s[i - 1] == s[i]);\n\t\t}\n\t\twriteln (cur / 2);\n\t}\n}\n"}], "negative_code": [], "src_uid": "fd1e3368fbfbc3792831623398c94d80"} {"source_code": "module p268C;\n\nimport std.algorithm : min;\nimport std.array : split;\nimport std.conv : to;\nimport std.stdio;\nimport std.string : strip;\n\nvoid main() {\n\tread();\n\n\tint n = get!int(0);\n\tint m = get!int(1);\n\n\tsolve(n, m);\n}\n\nvoid solve(int n, int m) {\n\tint min = min(n, m);\n\n\tstdout.writeln(min + 1);\n\n\tforeach (i; 0 .. min + 1) {\n\t\tstdout.writeln(i, \" \", min - i);\n\t}\n}\n\nprivate {\n\tstring[] temp;\n\n\tvoid read() {\n\t\ttemp = split(strip(stdin.readln()));\n\t}\n\n\tT get(T)(int p) {\n\t\treturn to!(T)(temp[p]);\n\t}\n}", "positive_code": [{"source_code": "module sigod.codeforces.p268C;\n\nimport std.algorithm : min;\nimport std.stdio;\n\nvoid main() {\n\tint n, m;\n\tstdin.readf(\"%s %s\", &n, &m);\n\n\tsolve(n, m);\n}\n\nvoid solve(int n, int m) {\n\tint min = min(n, m);\n\n\tstdout.writeln(min + 1);\n\n\tforeach (i; 0 .. min + 1) {\n\t\tstdout.writeln(i, \" \", min - i);\n\t}\n}"}], "negative_code": [{"source_code": "import std.array : split;\nimport std.conv : to;\nimport std.math : abs, sqrt, pow, trunc;\nimport std.stdio;\nimport std.string : strip;\n\nprivate {\n\tstring[] temp;\n\tint N, M;\n}\n\nvoid main() {\n\tread();\n\n\tN = get!int(0);\n\tM = get!int(1);\n\n\tint[][] max;\n\t\n\tforeach (x; 0 .. N + 1) {\n\t\tforeach (y; 0 .. M + 1) {\n\t\t\tif (x + y == 0) continue;\n\n\t\t\tauto current = p(x, y);\n\n\t\t\tversion (unittest) {\n\t\t\t\tstdout.writeln(\"current: \", current);\n\t\t\t}\n\n\t\t\tif (current.length > max.length) {\n\t\t\t\tmax = current.dup;\n\t\t\t}\n\t\t}\n\t}\n\n\tstdout.writeln(max.length);\n\tforeach (point; max) {\n\t\tstdout.writeln(point[0], \" \", point[1]);\n\t}\n}\n\nint[][] p(int start_x, int start_y) {\n\tint x = start_x,\n\t\ty = start_y + 1;\n\n\tint[][] result = [[start_x, start_y]];\n\n\twhile (x <= N) {\n\t\tif (x != start_x) y = 0;\n\n\t\twhile (y <= N) {\n\t\t\tif (isValid(result, x, y)) {\n\t\t\t\tresult ~= [x, y];\n\t\t\t}\n\n\t\t\t++y;\n\t\t}\n\n\t\t++x;\n\t}\n\n\tif (result.length == 1) {\n\t\tresult.length = 0;\n\t}\n\n\treturn result;\n}\n\nbool isValid(int[][] array, int x, int y) {\n\tforeach (point; array) {\n\t\tif (!isValidLength(point[0], point[1], x, y))\n\t\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nbool isValidLength(int x1, int y1, int x2, int y2) {\n\tauto length = sqrt(cast(float) (pow(x2 - x1, 2) + pow(y2 - y1, 2)));\n\n\tversion (unittest) {\n\t\tstdout.writeln(\"isValidLength: [\", x1, \", \", y1, \"], [\", x2, \", \", y2, \"] = \", length);\n\t}\n\n\treturn abs(length - trunc(length)) > 0.000000001;\n}\n\nvoid read() {\n\ttemp = split(strip(stdin.readln()));\n}\n\nT get(T)(int p) {\n\treturn to!(T)(temp[p]);\n}"}, {"source_code": "import std.array : split;\nimport std.conv : to;\nimport std.math : abs, sqrt, pow, trunc;\nimport std.stdio;\nimport std.string : strip;\n\nprivate {\n\tstring[] temp;\n\tint N, M;\n}\n\nvoid main() {\n\tread();\n\n\tN = get!int(0);\n\tM = get!int(1);\n\n\tint[][] max;\n\t\n\tforeach (x; 0 .. N + 1) {\n\t\tforeach (y; 0 .. M + 1) {\n\t\t\tif (x + y == 0) continue;\n\n\t\t\tauto current = p(x, y);\n\n\t\t\tversion (unittest) {\n\t\t\t\tstdout.writeln(\"current: \", current);\n\t\t\t}\n\n\t\t\tif (current.length > max.length) {\n\t\t\t\tmax = current.dup;\n\t\t\t}\n\t\t}\n\t}\n\n\tstdout.writeln(max.length);\n\tforeach (point; max) {\n\t\tstdout.writeln(point[0], \" \", point[1]);\n\t}\n}\n\nint[][] p(int start_x, int start_y) {\n\tint x = start_x,\n\t\ty = start_y + 1;\n\n\tint[][] result = [[start_x, start_y]];\n\n\twhile (x <= N) {\n\t\tif (x != start_x) y = 0;\n\n\t\twhile (y <= N) {\n\t\t\tif (isValid(result, x, y)) {\n\t\t\t\tresult ~= [x, y];\n\t\t\t}\n\n\t\t\t++y;\n\t\t}\n\n\t\t++x;\n\t}\n\n\treturn result;\n}\n\nbool isValid(int[][] array, int x, int y) {\n\tforeach (point; array) {\n\t\tif (!isValidLength(point[0], point[1], x, y))\n\t\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nbool isValidLength(int x1, int y1, int x2, int y2) {\n\tauto length = sqrt(cast(float) (pow(x2 - x1, 2) + pow(y2 - y1, 2)));\n\n\tversion (unittest) {\n\t\tstdout.writeln(\"isValidLength: [\", x1, \", \", y1, \"], [\", x2, \", \", y2, \"] = \", length);\n\t}\n\n\treturn abs(length - trunc(length)) > 0.000000001;\n}\n\nvoid read() {\n\ttemp = split(strip(stdin.readln()));\n}\n\nT get(T)(int p) {\n\treturn to!(T)(temp[p]);\n}"}], "src_uid": "0e99f4a49b408cc8874a6d5ec4167acb"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.variant;\nimport std.concurrency;\n\nvoid main(string[] args)\n{\n auto q = next!int;\n foreach(qi; q.iota)\n {\n auto n = next!int;\n auto badCnt = new int[](n);\n auto goodCnt = new int[](n);\n auto cnt = new int[](n);\n foreach(i; n.iota)\n\t{\n\t auto ai = next!int - 1;\n\t auto fi = next!int;\n\t if (fi)\n\t goodCnt[ai]++;\n\t else\n\t badCnt[ai]++;\n\t cnt[ai]++;\n\t}\n auto orderedTypes = iota(n).array.sort!((i, j) => cnt[i] > cnt[j]);\n int[] addSeq;\n auto prev = int.max;\n foreach(type; orderedTypes)\n\t{\n\t prev = min(prev - 1, cnt[type]);\n\t if (prev <= 0) break;\n\t addSeq ~= prev;\n\t}\n debug writeln(\"addSeq = \", addSeq);\n auto avTypes = redBlackTree!((a, b) => a > b, true, Tuple!(int, int))();\n int noBadChosen = 0;\n foreach(add; addSeq)\n\t{\n\t while(!orderedTypes.empty &&\n\t\tcnt[orderedTypes.front] >= add)\n\t {\n\t avTypes.insert(tuple(goodCnt[orderedTypes.front], badCnt[orderedTypes.front]));\n\t orderedTypes = orderedTypes[1 .. $];\n\t }\n\t debug writeln(\"Trying to add \", add,\n\t\t\t\" with avTypes = \", avTypes[]);\n\t auto best = avTypes.front;\n\t avTypes.removeFront;\n\t add -= min(add, best[0]);\n\t noBadChosen += min(add, best[1]);\n\t add -= min(add, best[1]);\n\t assert(add == 0);\n\t}\n auto res = addSeq.sum;\n writeln(res, \" \", res - noBadChosen);\n }\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.container.rbtree;\n\n int q;\n rd(q);\n\n struct P {\n int f, c;\n }\n\n while (q--) {\n int n;\n rd(n);\n auto freq = new int[](n), cnt1s = new int[](n);\n foreach (i; 0 .. n) {\n int a, t;\n rd(a, t);\n freq[a - 1] += 1;\n if (t == 1) {\n cnt1s[a - 1] += 1;\n }\n }\n auto list = new int[][](n + 1);\n foreach (i; 0 .. n) {\n if (freq[i] > 0) {\n list[freq[i]] ~= cnt1s[i];\n }\n }\n int[] b;\n foreach (i; 0 .. n) {\n if (freq[i] > 0) {\n b ~= freq[i];\n }\n }\n b.sort!\"a > b\";\n int last = b[0] + 1;\n long ans = 0, sum1s = 0;\n auto rbt = new RedBlackTree!(int, \"a>b\", true);\n foreach (el; b) {\n auto cur = min(last - 1, el);\n ans += cur;\n foreach (cnt; list[cur]) {\n rbt.insert(cnt);\n }\n auto mx1 = rbt.front;\n sum1s += min(mx1, cur);\n rbt.removeKey(mx1);\n last = cur;\n if (last == 0) {\n break;\n }\n }\n writeln(ans, \" \", sum1s);\n }\n\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.variant;\nimport std.concurrency;\n\nvoid main(string[] args)\n{\n auto q = next!int;\n foreach(qi; q.iota)\n {\n auto n = next!int;\n auto badCnt = new int[](n);\n auto goodCnt = new int[](n);\n auto cnt = new int[](n);\n foreach(i; n.iota)\n\t{\n\t auto ai = next!int - 1;\n\t auto fi = next!int;\n\t if (fi)\n\t goodCnt[ai]++;\n\t else\n\t badCnt[ai]++;\n\t cnt[ai]++;\n\t}\n auto orderedTypes = iota(n).array.sort!((i, j) => cnt[i] > cnt[j]);\n int[] addSeq;\n auto prev = int.max;\n foreach(type; orderedTypes)\n\t{\n\t prev = min(prev - 1, cnt[type]);\n\t if (prev <= 0) break;\n\t addSeq ~= prev;\n\t}\n debug writeln(\"addSeq = \", addSeq);\n auto avTypes = redBlackTree!((a, b) => a > b, true, Tuple!(int, int))();\n int noBadChosen = 0;\n foreach(add; addSeq)\n\t{\n\t while(!orderedTypes.empty &&\n\t\tcnt[orderedTypes.front] >= add)\n\t {\n\t avTypes.insert(tuple(goodCnt[orderedTypes.front], badCnt[orderedTypes.front]));\n\t orderedTypes = orderedTypes[1 .. $];\n\t }\n\t debug writeln(\"Trying to add \", add,\n\t\t\t\" with avTypes = \", avTypes[]);\n\t auto best = avTypes.front;\n\t avTypes.removeFront;\n\t add -= min(add, best[0]);\n\t noBadChosen += max(add, best[1]);\n\t add -= min(add, best[1]);\n\t assert(add == 0);\n\t}\n auto res = addSeq.sum;\n writeln(res, \" \", res - noBadChosen);\n }\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}], "src_uid": "bcde53a1671a66eb16a37139380f4ae5"} {"source_code": "import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;\nimport std.algorithm, std.container;\n\nconst ML = 700;\ndouble[][] dp;\nbool[][] used;\nint k;\ndouble solve(int l, int n) {\n if (n < 0) return 0;\n if (l >= ML) return 0;\n if (used[l][n]) return dp[l][n];\n used[l][n] = true;\n double res = 0;\n double hp = 1.0/(l+1);\n res += hp*(l + solve(l+1, n-1));\n res += (1-hp)*((l+1.0)/2 + solve(l, n-1));\n res /= k;\n res += (1-1.0/k)*solve(l, n-1);\n return (dp[l][n] = res);\n}\n\nint main() {\n int n;\n readf(\"%d %d\\n\", &n, &k);\n auto dp = new double[ML+1];\n dp[] = 0;\n foreach (i; 1..n+1) {\n foreach (j; 1..ML) {\n double res = 0;\n double hp = 1.0/(j+1);\n res += hp*(j + dp[j+1]);\n res += (1-hp)*((j+1.0)/2 + dp[j]);\n res /= k;\n res += (1-1.0/k)*dp[j];\n dp[j] = res;\n }\n }\n writef(\"%.20f\\n\", dp[1]*k);\n\treturn 0;\n}", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable LIM = 1000;\n\nint N, K;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = readInt;\n\t\t\n\t\treal[] pa = new real[LIM];\n\t\treal[] pb = new real[LIM];\n\t\treal[] pc = new real[LIM];\n\t\tforeach (j; 1 .. LIM - 1) {\n\t\t\tpa[j] = 1.0 - 1.0 / K / (j + 1);\n\t\t\tpb[j] = 1.0 / K - 1.0 / K / (j + 1);\n\t\t\tpc[j] = 1.0 / K / (j + 1);\n\t\t}\n\t\t\n\t\treal[] dp = new real[LIM];\n\t\tdp[] = 0.0;\n\t\tforeach (i; 0 .. N) {\n\t\t\tforeach (j; 1 .. LIM - 1) {\n\t\t\t\t// dp[j] = (1.0 - 1.0 / K) * dp[j] + (1.0 / K - 1.0 / K / (j + 1)) * ((j + 1) / 2.0 + dp[j]) + (1.0 / K / (j + 1)) * (j + dp[j + 1]);\n\t\t\t\tdp[j] = pa[j] * dp[j] + pb[j] * ((j + 1) / 2.0) + pc[j] * (j + dp[j + 1]);\n\t\t\t}\n\t\t}\ndebug{\nwriteln(dp);\n}\n\t\tconst ans = dp[1] * K;\n\t\twritefln(\"%.10f\", ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "548d23de92208b5ea62330022d05ce01"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint a, b;\nmain_loop:\n\twhile (readf (\" %s %s\", &a, &b) > 0)\n\t{\n\t\tforeach (p; 1..a)\n\t\t{\n\t\t\tint q = a * a - p * p;\n\t\t\tif (q <= 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tq = to !(int) (sqrt (to !(double) (q)));\n\t\t\tif (p * p + q * q != a * a)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint u = p * b;\n\t\t\tint v = q * b;\n\t\t\tif (u % a != 0 || v % a != 0 || p * a == v)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tu /= a;\n\t\t\tv /= a;\n\t\t\twriteln (\"YES\");\n\t\t\twriteln (0, ' ', 0);\n\t\t\twriteln (p, ' ', q);\n\t\t\twriteln (v, ' ', -u);\n\t\t\tcontinue main_loop;\n\t\t}\n\t\twriteln (\"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.math;\nimport std.conv;\n\nstruct Point\n{\n\tint x;\n\tint y;\n\tthis(int _x, int _y)\n\t{\n\t\tthis.x = _x;\n\t\tthis.y = _y;\n\t}\n};\n\nauto search(int len, int bound)\n{\n\tPoint[] ret;\n\tforeach (int i; 1 .. bound)\n\t{\n\t\tforeach (int j; i .. bound)\n\t\t{\n\t\t\tdouble d = i * i + j * j;\n\t\t\tdouble s = sqrt(d);\n\t\t\tif (s == len)\n\t\t\t{\n\t\t\t\tret ~= Point(i, j);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (s > len)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (ret.length == 0)\n\t{\n\t\tret ~= Point(1 << 30, 1 << 30);\n\t}\n\treturn ret;\n}\n\nint cross(ref Point p0, ref Point p1)\n{\n\treturn (p0.x * p1.x + p0.y * p1.y);\n}\n\nvoid change(ref Point p)\n{\n\tp.x ^= p.y;\n\tp.y ^= p.x;\n\tp.x ^= p.y;\n}\n\nvoid output(ref Point pa, ref Point pb)\n{\n\tprintf(\"YES\\n\");\n\tprintf(\"0 0\\n\");\n\tprintf(\"%d %d\\n\", pa.x, pa.y);\n\tprintf(\"%d %d\\n\", pb.x, pb.y);\n}\n\nbool check(Point[] arr)\n{\n\tif (arr.length == 0 || arr[0].x == 1 << 30)\n\t{\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nvoid print(Point[] arr)\n{\n\tprintf(\"%d\\n\", arr);\n\tforeach (ref Point p; arr)\n\t{\n\t\tprintf(\"%d %d\\n\", p.x, p.y);\n\t}\n}\n\nbool judge(ref Point p0, Point[] arr)\n{\n\tforeach (ref Point p1; arr)\n\t{\n\t\t//printf(\"try (%d %d) (%d %d)\\n\", p0.x, p0.y, p1.x, p1.y);\n\t\tif (p0.x * p1.x == p0.y * p1.y)\n\t\t{\n\t\t\tif (-p0.x != p1.x && p0.y != p1.y)\n\t\t\t{\n\t\t\t\tp0.x *= -1;\n\t\t\t\toutput(p0, p1);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (-p0.y != p1.y && p0.x != p1.x)\n\t\t\t{\n\t\t\t\tp0.y *= -1;\n\t\t\t\toutput(p0, p1);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid solve(int a, int b)\n{\n\tauto bound = a > b ? a : b;\n\tauto pa = search(a, bound);\n\tif (check(pa) == false)\n\t{\n\t\tprintf(\"NO\\n\");\n\t\treturn;\n\t}\n\tauto pb = search(b, bound);\n\tif (check(pb) == false)\n\t{\n\t\tprintf(\"NO\\n\");\n\t\treturn;\n\t}\n\t//print(pa);\n\t//print(pb);\n\tforeach (ref Point p0; pa)\n\t{\n\t\tif (judge(p0, pb) == true)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tchange(p0);\n\t\tif (judge(p0, pb) == true)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t}\n\tprintf(\"NO\\n\");\n}\n/*\nvoid test()\n{\n\tint[] cnt = new int[1001];\n\tforeach (int i; 1 .. 1001)\n\t{\n\t\tforeach (int j; i .. 1001)\n\t\t{\n\t\t\tdouble d = i * i + j * j;\n\t\t\tdouble s = sqrt(d);\n\t\t\tif (s > 1000)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint t = to!int(s);\n\t\t\tif (t == s)\n\t\t\t{\n\t\t\t\t++ cnt[t];\n\t\t\t}\n\t\t}\n\t}\n\tforeach (int i; 1 .. 1001)\n\t{\n\t\tif (cnt[i] > 1)\n\t\t{\n\t\t\tprintf(\"%d %d\\n\", i, cnt[i]);\n\t\t}\n\t}\n}\n*/\nvoid main(string[] args)\n{\n\t//test();\n\tint a, b;\n\twhile (scanf(\"%d%d\", &a, &b) == 2)\n\t{\n\t\tsolve(a, b);\n\t}\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.math;\nimport std.conv;\n\nstruct Point\n{\n int x;\n int y;\n this(int _x, int _y)\n {\n this.x = _x;\n this.y = _y;\n }\n};\n\nauto search(int len, int bound)\n{\n Point[] ret;\n foreach (int i; 1 .. bound)\n {\n foreach (int j; i .. bound)\n {\n double d = i * i + j * j;\n double s = sqrt(d);\n if (s == len)\n {\n ret ~= Point(i, j);\n break;\n }\n else if (s > len)\n {\n break;\n }\n }\n }\n if (ret.length == 0)\n {\n ret ~= Point(1 << 30, 1 << 30);\n }\n return ret;\n}\n\nint cross(ref Point p0, ref Point p1)\n{\n return (p0.x * p1.x + p0.y * p1.y);\n}\n\nvoid change(ref Point p)\n{\n p.x ^= p.y;\n p.y ^= p.x;\n p.x ^= p.y;\n}\n\nvoid output(ref Point pa, ref Point pb)\n{\n printf(\"YES\\n\");\n printf(\"0 0\\n\");\n printf(\"%d %d\\n\", pa.x, pa.y);\n printf(\"%d %d\\n\", pb.x, pb.y);\n}\n\nbool check(Point[] arr)\n{\n if (arr.length == 0 || arr[0].x == 1 << 30)\n {\n return false;\n }\n return true;\n}\n\nvoid solve(int a, int b)\n{\n auto bound = a > b ? a : b;\n auto pa = search(a, bound);\n if (check(pa) == false)\n {\n printf(\"NO\\n\");\n return;\n }\n auto pb = search(b, bound);\n if (check(pb) == false)\n {\n printf(\"NO\\n\");\n return;\n }\n foreach (ref Point p0; pa)\n {\n p0.x = -p0.x;\n foreach (ref Point p1; pb)\n {\n if (cross(p0, p1) == 0)\n {\n output(p0, p1);\n return;\n }\n }\n change(p0);\n foreach (ref Point p1; pb)\n {\n if (cross(p0, p1) == 0)\n {\n output(p0, p1);\n return;\n }\n }\n }\n printf(\"NO\\n\");\n}\n\nvoid main(string[] args)\n{\n int a, b;\n while (scanf(\"%d%d\", &a, &b) == 2)\n {\n solve(a, b);\n }\n}"}, {"source_code": "import std.stdio, std.string, std.math;\nimport std.conv;\n\nstruct Point\n{\n\tint x;\n\tint y;\n\tthis(int _x, int _y)\n\t{\n\t\tthis.x = _x;\n\t\tthis.y = _y;\n\t}\n};\n\nauto search(int len, int bound)\n{\n\tPoint[] ret;\n\tforeach (int i; 1 .. bound)\n\t{\n\t\tforeach (int j; i .. bound)\n\t\t{\n\t\t\tdouble d = i * i + j * j;\n\t\t\tdouble s = sqrt(d);\n\t\t\tif (s == len)\n\t\t\t{\n\t\t\t\tret ~= Point(i, j);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (s > len)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (ret.length == 0)\n\t{\n\t\tret ~= Point(1 << 30, 1 << 30);\n\t}\n\treturn ret;\n}\n\nint cross(ref Point p0, ref Point p1)\n{\n\treturn (p0.x * p1.x + p0.y * p1.y);\n}\n\nvoid change(ref Point p)\n{\n\tp.x ^= p.y;\n\tp.y ^= p.x;\n\tp.x ^= p.y;\n}\n\nvoid output(ref Point pa, ref Point pb)\n{\n\tprintf(\"YES\\n\");\n\tprintf(\"0 0\\n\");\n\tprintf(\"%d %d\\n\", pa.x, pa.y);\n\tprintf(\"%d %d\\n\", pb.x, pb.y);\n}\n\nbool check(Point[] arr)\n{\n\tif (arr.length == 0 || arr[0].x == 1 << 30)\n\t{\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nvoid print(Point[] arr)\n{\n\tprintf(\"%d\\n\", arr);\n\tforeach (ref Point p; arr)\n\t{\n\t\tprintf(\"%d %d\\n\", p.x, p.y);\n\t}\n}\n\nvoid solve(int a, int b)\n{\n\tauto bound = a > b ? a : b;\n\tauto pa = search(a, bound);\n\tif (check(pa) == false)\n\t{\n\t\tprintf(\"NO\\n\");\n\t\treturn;\n\t}\n\tauto pb = search(b, bound);\n\tif (check(pb) == false)\n\t{\n\t\tprintf(\"NO\\n\");\n\t\treturn;\n\t}\n\t//print(pa);\n\t//print(pb);\n\tforeach (ref Point p0; pa)\n\t{\n\t\tp0.x = -p0.x;\n\t\tforeach (ref Point p1; pb)\n\t\t{\n\t\t\tif (p0.x != p1.x && p0.y != p1.y && cross(p0, p1) == 0)\n\t\t\t{\n\t\t\t\toutput(p0, p1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tchange(p0);\n\t\tforeach (ref Point p1; pb)\n\t\t{\n\t\t\tif (p0.x != p1.x && p0.y != p1.y && cross(p0, p1) == 0)\n\t\t\t{\n\t\t\t\toutput(p0, p1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\tprintf(\"NO\\n\");\n}\n/*\nvoid test()\n{\n\tint[] cnt = new int[1001];\n\tforeach (int i; 1 .. 1001)\n\t{\n\t\tforeach (int j; i .. 1001)\n\t\t{\n\t\t\tdouble d = i * i + j * j;\n\t\t\tdouble s = sqrt(d);\n\t\t\tif (s > 1000)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint t = to!int(s);\n\t\t\tif (t == s)\n\t\t\t{\n\t\t\t\t++ cnt[t];\n\t\t\t}\n\t\t}\n\t}\n\tforeach (int i; 1 .. 1001)\n\t{\n\t\tif (cnt[i] > 1)\n\t\t{\n\t\t\tprintf(\"%d %d\\n\", i, cnt[i]);\n\t\t}\n\t}\n}\n*/\nvoid main(string[] args)\n{\n\t//test();\n\tint a, b;\n\twhile (scanf(\"%d%d\", &a, &b) == 2)\n\t{\n\t\tsolve(a, b);\n\t}\n}"}, {"source_code": "import std.stdio, std.string, std.math;\n\nstruct Point\n{\n int x;\n int y;\n this(int _x, int _y)\n {\n this.x = _x;\n this.y = _y;\n }\n};\n\nauto search(int len, int bound)\n{\n foreach (int i; 1 .. bound)\n {\n foreach (int j; i .. bound)\n {\n double d = i * i + j * j;\n double s = sqrt(d);\n if (s == len)\n {\n return Point(i, j);\n }\n else if (s > len)\n {\n break;\n }\n }\n }\n return Point(1 << 30, 1 << 30);\n}\n\nint cross(ref Point p0, ref Point p1)\n{\n return (p0.x * p1.x + p0.y * p1.y);\n}\n\nvoid change(ref Point p)\n{\n p.x ^= p.y;\n p.y ^= p.x;\n p.x ^= p.y;\n}\n\nvoid output(ref Point pa, ref Point pb)\n{\n printf(\"YES\\n\");\n printf(\"0 0\\n\");\n printf(\"%d %d\\n\", pa.x, pa.y);\n printf(\"%d %d\\n\", pb.x, pb.y);\n}\n\nvoid solve(int a, int b)\n{\n auto bound = a > b ? a : b;\n auto pa = search(a, bound);\n if (pa.x == 1 << 30)\n {\n printf(\"NO\\n\");\n return;\n }\n auto pb = search(b, bound);\n if (pb.x == 1 << 30)\n {\n printf(\"NO\\n\");\n return;\n }\n pb.x = -pb.x;\n if (cross(pa, pb) == 0)\n {\n output(pa, pb);\n return;\n }\n change(pb);\n if (cross(pa, pb) == 0)\n {\n output(pa, pb);\n return;\n }\n printf(\"NO\\n\");\n}\n\nvoid main(string[] args)\n{\n int a, b;\n while (scanf(\"%d%d\", &a, &b) == 2)\n {\n solve(a, b);\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint a, b;\nmain_loop:\n\twhile (readf (\" %s %s\", &a, &b) > 0)\n\t{\n\t\tforeach (p; 1..a)\n\t\t{\n\t\t\tint q = a * a - p * p;\n\t\t\tif (q <= 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tq = to !(int) (sqrt (to !(double) (q)));\n\t\t\tif (p * p + q * q != a * a)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint u = p * b;\n\t\t\tint v = q * b;\n\t\t\tif (u % a != 0 || v % a != 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tu /= a;\n\t\t\tv /= a;\n\t\t\twriteln (\"YES\");\n\t\t\twriteln (0, ' ', 0);\n\t\t\twriteln (p, ' ', q);\n\t\t\twriteln (v, ' ', -u);\n\t\t\tcontinue main_loop;\n\t\t}\n\t\twriteln (\"NO\");\n\t}\n}\n"}], "src_uid": "a949ccae523731f601108d4fa919c112"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n\r\n void step(ref int[] as, ref int k) {\r\n int n = as.length;\r\n if (n == 0) return;\r\n int[] bs = k == 0 ? [] : [as[0]];\r\n if (k > 0) k--;\r\n for (int i = 1; i < n; i++) {\r\n int b = as[i] - as[i - 1];\r\n if (b > 0) {\r\n bs ~= b;\r\n } else {\r\n k++;\r\n }\r\n }\r\n sort(bs);\r\n as = bs;\r\n }\r\n\r\n int[] as;\r\n int k = 0;\r\n foreach (a; A) {\r\n if (a == 0) k++;\r\n else as ~= a;\r\n }\r\n foreach (i; 0 .. N - 1) {\r\n step(as, k);\r\n /*\r\n writeln(\"as: \", as);\r\n writeln(\"k: \", k);\r\n */\r\n }\r\n writeln(as.empty ? 0 : as.back);\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint [int] b;\r\n\t\tforeach (ref x; a)\r\n\t\t{\r\n\t\t\tb[x] += 1;\r\n\t\t}\r\n\t\tforeach (i; 0..n - 1)\r\n\t\t{\r\n\t\t\tauto v = b.byKeyValue.array;\r\n\t\t\tv.schwartzSort !(q{a.key});\r\n\t\t\tint [int] c;\r\n\t\t\tforeach (j; 0..v.length)\r\n\t\t\t{\r\n\t\t\t\tif (v[j].value > 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tc[0] += v[j].value - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tforeach (j; 0..v.length - 1)\r\n\t\t\t{\r\n\t\t\t\tc[v[j + 1].key - v[j].key] += 1;\r\n\t\t\t}\r\n\t\t\tb = c;\r\n\t\t}\r\n\t\twriteln (b.byKey.front);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tfor (n--; n >= 1 && a.length > 1; n--)\r\n\t\t{\r\n\t\t\tbool addZero = (a.length <= n);\r\n\t\t\ta = zip (a, a.drop (1)).map !(q{a[1] - a[0]}).array;\r\n\t\t\tsort (a);\r\n\t\t\tauto b = a.uniq.array;\r\n\t\t\ta = addZero ? 0 ~ b : b;\r\n\t\t\tdebug {writeln (a);}\r\n\t\t}\r\n\t\twriteln (a.front);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tbool zero = false;\r\n\t\tfor (n--; n >= 1 && a.length > 1; n--)\r\n\t\t{\r\n\t\t\ta = zip (a, a.drop (1)).map !(q{a[1] - a[0]}).array;\r\n\t\t\tsort (a);\r\n\t\t\tauto b = a.uniq.array;\r\n\t\t\tzero |= (b.length < a.length);\r\n\t\t\ta = (b.length < n) ? 0 ~ b : b;\r\n\t\t\tdebug {writeln (a);}\r\n\t\t}\r\n\t\twriteln (a.front);\r\n\t}\r\n}\r\n"}], "src_uid": "499b1440d8bb528d089724910e37e226"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = '1' ~ readln.strip ~ '0';\r\n\t\tauto n = s.length;\r\n\t\tauto p = s.countUntil ('0');\r\n\t\tauto q = n - 1 - s.retro.countUntil ('1');\r\n\t\tint res = n - 2;\r\n\t\tforeach (i; 1..n - 1)\r\n\t\t{\r\n\t\t\tres -= (p < i || q > i);\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// cheese-cracker [2022-05-05]\n\nvoid solve(){\n auto word = scan!(dchar[]); \n int last1 = -1;\n int first0 = -1;\n for(int i = 0; i < word.length; ++i){\n if(word[i] == '1'){\n last1 = i;\n }else if(word[i] == '0' && first0 == -1){\n first0 = i;\n }\n }\n if(last1 == -1 && first0 == -1){\n writeln(word.length.to!int);\n }else if(last1 == -1){\n writeln(first0 + 1);\n }else if(first0 == -1){\n writeln(word.length.to!int - last1);\n }else if(last1 < first0){\n writeln(first0 - last1 + 1);\n }else{\n long cnt0 = 0;\n for(int i = 0; i < last1; ++i){\n cnt0 += (word[i] == '0');\n }\n long cnt1 = 0;\n for(int i = first0+1; i < word.length; ++i){\n cnt1 += (word[i] == '1');\n }\n if(cnt1 > cnt0 || cnt0 < cnt1){\n writeln(1);\n }else{\n writeln(last1 - first0 + 1);\n }\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm;\nimport std.container, std.math, std.numeric, std.functional;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}], "negative_code": [], "src_uid": "0c9f2301629726870a0ab57299773fd6"} {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n char[][] F = new char[][N];\n foreach (i; 0 .. N) {\n F[i] = cast(char[])readln.chomp;\n }\n\n char flip(char x) {\n if (x == 'B') return 'W';\n if (x == 'W') return 'B';\n assert(0);\n }\n\n const dy = [1, 0, -1, 0],\n dx = [0, 1, 0, -1];\n void dfs(int y, int x, char c) {\n F[y][x] = c;\n foreach (i; 0 .. 4) {\n int ny = y + dy[i],\n nx = x + dx[i];\n if (ny < 0 || ny >= N) continue;\n if (nx < 0 || nx >= M) continue;\n if (F[ny][nx] == '.') {\n dfs(ny, nx, flip(c));\n }\n }\n }\n\n for (int y = 0; y < N; y++) {\n for (int x = 0; x < M; x++) {\n if (F[y][x] == '.') {\n dfs(y, x, 'B');\n }\n }\n }\n foreach (ref L; F) {\n writeln(L);\n }\n}\n", "positive_code": [{"source_code": "\ufeffimport std.stdio, std.string, std.container, std.conv, std.numeric, std.range;\nimport std.array, std.bigint, std.algorithm, std.math, std.typecons, std.random;\n\nvoid main() {\n\n\tbyte n, m;\n\n\treadf(\" %s %s\", &n, &m);\n\n\tbool k = (m & 1) ? 0 : 1;\n\n\tchar c;\n\tbool flag = 0;\n\tforeach (i; 0 .. n) {\n\t\tforeach (j; 0 .. m) {\n\t\t\tscanf(\" %c\", &c);\n\t\t\tif (c == '-')\n\t\t\t\twrite('-');\n\t\t\telse if (flag)\n\t\t\t\tputchar('W');\n\t\t\telse\n\t\t\t\tputchar('B');\n\t\t\tflag ^= 1;\n\t\t}\n\t\tflag ^= k;\n\t\tputchar('\\n');\n\t}\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int m,n;\n char c,r;\n char[2][2] r_or_w = [['B','W'],['W','B']];\n readf(\"%s \",&m);\n readf(\"%s \",&n);\n for(int i=0; i < m; i++){\n for(int j=0; j < n; j++){\n readf(\"%c\",&c);\n if (c == '.'){\n writef(\"%c\",r_or_w[i % 2][j % 2]);\n } else if (c == '-') {\n writef(\"%c\",'-');\n } else {\n }\n }\n writefln(\"\",i);\n readf(\"%c\",&c);\n }\n}\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint M, N;\nstring[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tA = new string[M];\n\t\tforeach (x; 0 .. M) {\n\t\t\tA[x] = readToken;\n\t\t}\n\t\t\n\t\tforeach (x; 0 .. M) {\n\t\t\tforeach (y; 0 .. N) {\n\t\t\t\twrite((A[x][y] == '-') ? '-' : ((x + y) % 2 == 0) ? 'B' : 'W');\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n char[][] F = new char[][N];\n foreach (i; 0 .. N) {\n F[i] = cast(char[])readln.chomp;\n }\n\n char flip(char x) {\n if (x == 'B') return 'W';\n if (x == 'W') return 'B';\n assert(0);\n }\n\n bool C(char x) {\n return x == 'W' || x == 'B';\n }\n\n for (int y = 0; y < N; y++) {\n for (int x = 0; x < M; x++) {\n if (F[y][x] == '-') continue;\n if (y - 1 >= 0 && C(F[y - 1][x])) {\n F[y][x] = flip(F[y - 1][x]);\n } else if (x - 1 >= 0 && C(F[y][x - 1])) {\n F[y][x] = flip(F[y][x - 1]);\n } else {\n F[y][x] = 'B';\n }\n }\n }\n foreach (ref L; F) {\n writeln(L);\n }\n}\n"}, {"source_code": "\ufeffimport std.stdio, std.string, std.container, std.conv, std.numeric, std.range;\nimport std.array, std.bigint, std.algorithm, std.math, std.typecons, std.random;\n\nchar[102][102] a;\n\nvoid main() {\n\n\tbyte n, m;\n\n\treadf(\" %s %s\", &n, &m);\n\n\tchar c;\n\tforeach (i; 1 .. n + 1)\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tscanf(\" %c\", &c);\n\t\t\tif (c == '-')\n\t\t\t\ta[i][j] = '-';\n\t\t\telse\n\t\t\t\ta[i][j] = 'W';\n\t\t}\n\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tif (a[i][j] == '-') {\n\t\t\t\twrite('-');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ((i != 1 && j != 1) && a[i][j] == 'W' && a[i - 1][j] != 'B' && a[i][j + 1] != 'B' && a[i + 1][j] != 'B' && a[i][j - 1] != 'B') {\n\t\t\t\ta[i][j] = 'B';\n\t\t\t\twrite('B');\n\t\t\t}\n\t\t\telse\n\t\t\t\twrite('W');\n\t\t}\n\t\tputchar('\\n');\n\t}\n}"}, {"source_code": "\ufeffimport std.stdio, std.string, std.container, std.conv, std.numeric, std.range;\nimport std.array, std.bigint, std.algorithm, std.math, std.typecons, std.random;\n\nchar[102][102] a;\n\nvoid main() {\n\n\tbyte n, m;\n\n\treadf(\" %s %s\", &n, &m);\n\n\tchar c;\n\tforeach (i; 1 .. n + 1)\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tscanf(\" %c\", &c);\n\t\t\tif (c == '-')\n\t\t\t\ta[i][j] = '-';\n\t\t\telse\n\t\t\t\ta[i][j] = 'W';\n\t\t}\n\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tif (a[i][j] == '-') {\n\t\t\t\twrite('-');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (i == 1 && j == 0) {\n\t\t\t\twrite('W');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( a[i][j] == 'W' && a[i - 1][j] != 'B' && a[i][j + 1] != 'B' && a[i + 1][j] != 'B' && a[i][j - 1] != 'B') {\n\t\t\t\ta[i][j] = 'B';\n\t\t\t\twrite('B');\n\t\t\t}\n\t\t\telse\n\t\t\t\twrite('W');\n\t\t}\n\t\tputchar('\\n');\n\t}\n}"}, {"source_code": "\ufeffimport std.stdio, std.string, std.container, std.conv, std.numeric, std.range;\nimport std.array, std.bigint, std.algorithm, std.math, std.typecons, std.random;\n\nchar[102][102] a;\n\nvoid main() {\n\n\tbyte n, m;\n\n\treadf(\" %s %s\", &n, &m);\n\n\tchar c;\n\tforeach (i; 1 .. n + 1)\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tscanf(\" %c\", &c);\n\t\t\tif (c == '-')\n\t\t\t\ta[i][j] = '-';\n\t\t\telse\n\t\t\t\ta[i][j] = 'W';\n\t\t}\n\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tif (a[i][j] == '-') {\n\t\t\t\twrite('-');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (a[i][j] == 'W' && a[i - 1][j] != 'B' && a[i][j + 1] != 'B' && a[i + 1][j] != 'B' && a[i][j - 1] != 'B') {\n\t\t\t\ta[i][j] = 'B';\n\t\t\t\twrite('B');\n\t\t\t}\n\t\t\telse\n\t\t\t\twrite('W');\n\t\t}\n\t\tputchar('\\n');\n\t}\n}"}, {"source_code": "\ufeffimport std.stdio, std.string, std.container, std.conv, std.numeric, std.range;\nimport std.array, std.bigint, std.algorithm, std.math, std.typecons, std.random;\n\nchar[102][102] a;\n\nvoid main() {\n\n\tbyte n, m;\n\n\treadf(\" %s %s\", &n, &m);\n\n\tchar c;\n\tforeach (i; 1 .. n + 1)\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tscanf(\" %c\", &c);\n\t\t\tif (c == '-')\n\t\t\t\ta[i][j] = '-';\n\t\t\telse\n\t\t\t\ta[i][j] = 'W';\n\t\t}\n\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tif (a[i][j] == '-') {\n\t\t\t\twrite('-');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (i == 1 && j == 1) {\n\t\t\t\twrite('W');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( a[i][j] == 'W' && a[i - 1][j] != 'B' && a[i][j + 1] != 'B' && a[i + 1][j] != 'B' && a[i][j - 1] != 'B') {\n\t\t\t\ta[i][j] = 'B';\n\t\t\t\twrite('B');\n\t\t\t}\n\t\t\telse\n\t\t\t\twrite('W');\n\t\t}\n\t\tputchar('\\n');\n\t}\n}"}, {"source_code": "\ufeffimport std.stdio, std.string, std.container, std.conv, std.numeric, std.range;\nimport std.array, std.bigint, std.algorithm, std.math, std.typecons, std.random;\n\nvoid main() {\n\n\tbyte n, m;\n\n\treadf(\" %s %s\", &n, &m);\n\n\tchar c;\n\tbool flag;\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\tscanf(\" %c\", &c);\n\t\t\tif (c == '-')\n\t\t\t\twrite('-');\n\t\t\telse if (flag)\n\t\t\t\tputchar('W');\n\t\t\telse\n\t\t\t\tputchar('B');\n\t\t\tflag ^= 1;\n\t\t}\n\t\tflag ^= 1;\n\t\tputchar('\\n');\n\t}\n}"}, {"source_code": "\ufeffimport std.stdio, std.string, std.container, std.conv, std.numeric, std.range;\nimport std.array, std.bigint, std.algorithm, std.math, std.typecons, std.random;\n\nchar[100][100] a;\n\nvoid main() {\n\n\tbyte n, m;\n\n\treadf(\" %s %s\", &n, &m);\n\n\tchar c;\n\tforeach (i; 0 .. n)\n\t\tforeach (j; 0 .. m) {\n\t\t\tscanf(\" %c\", &c);\n\t\t\tif (c == '-')\n\t\t\t\ta[i][j] = '-';\n\t\t\telse\n\t\t\t\ta[i][j] = 'W';\n\t\t}\n\n\tforeach (i; 0 .. n) {\n\t\tforeach (j; 0 .. m)\n\t\t\tif (a[i][j] == '-')\n\t\t\t\twrite('-');\n\t\t\telse if (a[i][j] == 'W') {\n\t\t\t\tif (j + 1 <= m - 1 && i + 1 <= n - 1 && a[i][j + 1] == 'W' && a[i + 1][j] == 'W' ||\n\t\t\t\t\ti - 1 >= 0 && j - 1 >= 0 && a[i - 1][j] == 'W' && a[i][j - 1] == 'W') {\n\t\t\t\t\twrite('B');\n\t\t\t\t\ta[i][j] = 'B';\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\twrite('W');\n\t\t\t}\n\t\tputchar('\\n');\n\t}\n}"}], "src_uid": "dc31adef80f06897ea2f5ef76854bcf1"} {"source_code": "immutable multi = true;\n\nimmutable int maxAi = 1_000_000;\nbool[maxAi+1] isPrime = true;\n\nstatic this()\n{\n isPrime[0] = isPrime[1] = false;\n foreach(n; 2 .. maxAi+1)\n {\n if (isPrime[n])\n\t{\n\t for(int m = 2*n;\n\t m <= maxAi;\n\t m += n) isPrime[m] = false;\n\t}\n }\n}\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto e = readInt!int;\n debug writeln(\"solving case \", e, \" \", n);\n auto a = ma(n, readInt!int);\n auto cnt1 = new int[](n);\n foreach_reverse(i; 0 .. n)\n {\n if (i + e < n)\n\t{\n\t if (a[i] == 1)\n\t {\n\t cnt1[i] = 1 + cnt1[i + e];\n\t }\n\t else\n\t {\n\t cnt1[i] = 0;\n\t }\n\t}\n else\n\t{\n\t cnt1[i] = int(a[i] == 1);\n\t}\n }\n debug writeln(cnt1);\n long ans = 0;\n foreach_reverse(i; 0 .. n)\n {\n if (isPrime[a[i]])\n\t{\n\t ans += i + e < n? cnt1[i + e] : 0;\n\t}\n else if (a[i] == 1)\n\t{\n\t auto nxt = i + e * cnt1[i];\n\t debug writeln(\"for \", i, \" next is \", nxt);\n\t if (nxt < n)\n\t {\n\t auto aNxt = a[nxt];\n\t if (isPrime[aNxt])\n\t\t{ \n\t\t ans += 1 + (nxt + e < n? cnt1[nxt + e] : 0);\n\t\t}\n\t }\n\t}\n }\n ans.writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\n// From: https://rosettacode.org/wiki/Sieve_of_Eratosthenes#D\n\n/// Extensible Sieve of Eratosthenes.\nstruct Prime {\n uint[] a = [2];\n private void grow() pure nothrow @safe {\n immutable p0 = a[$ - 1] + 1;\n auto b = new bool[p0];\n\n foreach (immutable di; a) {\n immutable uint i0 = p0 / di * di;\n uint i = (i0 < p0) ? i0 + di - p0 : i0 - p0;\n for (; i < b.length; i += di)\n b[i] = true;\n }\n foreach (immutable uint i, immutable bi; b)\n if (!b[i])\n a ~= p0 + i;\n }\n uint opCall(in uint n) pure nothrow @safe {\n while (n >= a.length)\n grow;\n return a[n];\n }\n}\n\nint get_ones_l(int[] a, int i, int e, int[] ones_l)\n{\n if (ones_l[i] != -1)\n return ones_l[i];\n if (i - e < 0 || a[i - e] != 1) {\n ones_l[i] = 0;\n } else {\n ones_l[i] = 1 + get_ones_l(a, i - e, e, ones_l);\n }\n return ones_l[i];\n}\n\nint get_ones_r(int[] a, int i, int e, int[] ones_r)\n{\n if (ones_r[i] != -1)\n return ones_r[i];\n if (i + e >= a.length || a[i + e] != 1) {\n ones_r[i] = 0;\n } else {\n ones_r[i] = 1 + get_ones_r(a, i + e, e, ones_r);\n }\n return ones_r[i];\n}\n\nvoid main()\n{\n Prime prime;\n bool[int] primes;\n foreach (prime_num ; int.max.iota.map!prime.until!q{a > 1000001})\n primes[prime_num] = true;\n\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n, e;\n readf!\" %d %d \"(n, e);\n auto a = readln.splitter.map!(to!int).array;\n foreach (ref x ; a) {\n if (x == 1)\n continue;\n if (x in primes)\n x = 2;\n else\n x = 0;\n }\n\n auto ones_l = new int[](n);\n auto ones_r = new int[](n);\n ones_l[] = -1;\n ones_r[] = -1;\n\n long ans;\n foreach (i ; 0 .. n) {\n if (a[i] != 2)\n continue;\n long l = get_ones_l(a, i, e, ones_l);\n long r = get_ones_r(a, i, e, ones_r);\n if (l != 0 || r != 0) {\n ans += (l + 1) * (r + 1) - 1;\n }\n }\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int limit = 10 ^^ 6 + 3;\r\n\r\nvoid main ()\r\n{\r\n\tauto s = new bool [limit];\r\n\ts[2..$] = true;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (s[d])\r\n\t\t{\r\n\t\t\tfor (int e = d; e * d < limit; e++)\r\n\t\t\t{\r\n\t\t\t\ts[e * d] = false;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, e;\r\n\t\treadf !(\" %s %s\") (n, e);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tlong res = 0;\r\n\t\tint primes = 0;\r\n\t\tforeach (start; 0..e)\r\n\t\t{\r\n\t\t\tint lo = 0;\r\n\t\t\tint hi = 0;\r\n\t\t\tforeach (c; a.drop (start).stride (e))\r\n\t\t\t{\r\n\t\t\t\tif (c == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\thi += 1;\r\n\t\t\t\t\tres += lo;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s[c])\r\n\t\t\t\t{\r\n\t\t\t\t\tlo = hi + 1;\r\n\t\t\t\t\thi = 0;\r\n\t\t\t\t\tres += lo;\r\n\t\t\t\t\tprimes += 1;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlo = 0;\r\n\t\t\t\t\thi = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res - primes);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int limit = 10 ^^ 6 + 3;\r\n\r\nvoid main ()\r\n{\r\n\tauto s = new bool [limit];\r\n\ts[2..$] = true;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (s[d])\r\n\t\t{\r\n\t\t\tfor (int e = d; e * d < limit; e += d)\r\n\t\t\t{\r\n\t\t\t\ts[e * d] = false;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, e;\r\n\t\treadf !(\" %s %s\") (n, e);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tlong res = 0;\r\n\t\tint primes = 0;\r\n\t\tforeach (start; 0..e)\r\n\t\t{\r\n\t\t\tint lo = 0;\r\n\t\t\tint hi = 0;\r\n\t\t\tforeach (c; a.drop (start).stride (e))\r\n\t\t\t{\r\n\t\t\t\tif (c == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\thi += 1;\r\n\t\t\t\t\tres += lo;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s[c])\r\n\t\t\t\t{\r\n\t\t\t\t\tlo = hi + 1;\r\n\t\t\t\t\thi = 0;\r\n\t\t\t\t\tres += lo;\r\n\t\t\t\t\tprimes += 1;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlo = 0;\r\n\t\t\t\t\thi = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res - primes);\r\n\t}\r\n}\r\n"}], "src_uid": "32130f939336bb6f2deb4dfa5402867d"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nbool solve (int [] x, string s)\r\n{\r\n\tauto a = x[0];\r\n\tauto b = x[1];\r\n\tauto ab = x[2];\r\n\tauto ba = x[3];\r\n\tauto n = s.length.to !(int);\r\n\r\n\tauto ra = s.count (\"A\");\r\n\tauto rb = s.count (\"B\");\r\n\tif (ra != a + ab + ba || rb != b + ab + ba)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\talias Record = Tuple !(int, q{a}, int, q{b}, char, q{start});\r\n\tRecord [] r;\r\n\tint ca = 0;\r\n\tint cb = 0;\r\n\tchar start;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tif (ca == 0 && cb == 0)\r\n\t\t{\r\n\t\t\tstart = s[i];\r\n\t\t}\r\n\t\tif (s[i] == 'A')\r\n\t\t{\r\n\t\t\tca += 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tcb += 1;\r\n\t\t}\r\n\t\tif (i + 1 == n || s[i] == s[i + 1])\r\n\t\t{\r\n\t\t\tr ~= Record (ca, cb, start);\r\n\t\t\tca = 0;\r\n\t\t\tcb = 0;\r\n\t\t}\r\n\t}\r\n\tr.schwartzSort !(t => t.a + t.b);\r\n\treverse (r);\r\n\r\n\tint wildcard = 0;\r\n\tforeach (ref t; r)\r\n\t{\r\n\t\tif (t.a != t.b)\r\n\t\t{\r\n\t\t\twildcard += min (t.a, t.b);\r\n\t\t}\r\n\t}\r\n\r\n\tint pab = 0;\r\n\tint pba = 0;\r\n\tforeach (ref t; r)\r\n\t{\r\n\t\tif (t.a == t.b)\r\n\t\t{\r\n\t\t\tif (t.start == 'A')\r\n\t\t\t{\r\n\t\t\t\tpab += t.a;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tpba += t.b;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (ref t; r)\r\n\t{\r\n\t\tif (t.a == t.b)\r\n\t\t{\r\n\t\t\tif (t.start == 'A')\r\n\t\t\t{\r\n\t\t\t\tif (pba + wildcard < ba)\r\n\t\t\t\t{\r\n\t\t\t\t\tint cur = t.b - 1;\r\n\t\t\t\t\tpab -= 1;\r\n\t\t\t\t\twhile (pba + wildcard < ba && cur > 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcur -= 1;\r\n\t\t\t\t\t\tpab -= 1;\r\n\t\t\t\t\t\tpba += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (pab + wildcard < ab)\r\n\t\t\t\t{\r\n\t\t\t\t\tint cur = t.a - 1;\r\n\t\t\t\t\tpba -= 1;\r\n\t\t\t\t\twhile (pab + wildcard < ab && cur > 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcur -= 1;\r\n\t\t\t\t\t\tpba -= 1;\r\n\t\t\t\t\t\tpab += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tif (pab + wildcard >= ab && pba + wildcard >= ba &&\r\n\t pab + pba + wildcard >= ab + ba)\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n\treturn false;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto x = readln.splitter.map !(to !(int)).array;\r\n\t\tauto s = readln.strip;\r\n\t\twriteln (solve (x, s) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint solve(int A, int B, int C, int D, string S) {\n debug {\n writeln(\" \", [A, B, C, D], \" \", S);\n }\n const N = cast(int)(S.length);\n const cntA = cast(int)(S.count('A'));\n const cntB = cast(int)(S.count('B'));\n if (cntA != A + C + D) return 1;\n if (cntB != B + C + D) return 2;\n \n int odd;\n int[][2] fss;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && ((S[i] == S[j]) == ((i & 1) == (j & 1))); ++j) {}\n debug {\n writeln(\" \", S[i .. j]);\n }\n if ((j - i) % 2 != 0) {\n odd += (j - i) / 2;\n } else {\n fss[S[i] - 'A'] ~= (j - i) / 2;\n }\n }\n foreach (h; 0 .. 2) {\n fss[h].sort;\n }\n debug {\n writeln(\" odd = \", odd);\n writeln(\" fss = \", fss);\n }\n \n int[2] cs = [C, D];\n foreach (h; 0 .. 2) {\n foreach (ref f; fss[h]) {\n const t = min(f, cs[h]);\n f -= t;\n cs[h] -= t;\n }\n }\n debug {\n writeln(\" \", fss, \" \", cs);\n }\n foreach (h; 0 .. 2) {\n foreach (ref f; fss[h ^ 1]) if (f >= 1) {\n const t = min(f - 1, cs[h]);\n cs[h] -= t;\n }\n }\n if (cs[0] + cs[1] > odd) {\n return 3;\n }\n \n return 0;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const A = readInt;\n const B = readInt;\n const C = readInt;\n const D = readInt;\n const S = readToken;\n \n const ans = solve(A, B, C, D, S);\n writeln((ans == 0) ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "bd61ae3c19274f47b981b8bd5e786375"} {"source_code": "import std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;\nimport core.bitop, core.thread;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return readToken().to!int; }\nlong readLong() { return readToken().to!long; }\nreal readReal() { return readToken().to!real; }\n\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }\n\n\nint N;\nint[] P;\nlong[] S;\n\nlong solve() {\n auto h = new int[N];\n h[0] = 1;\n foreach (u; 1 .. N) {\n h[u] = h[P[u]] + 1;\n }\n debug {\n writefln(\"h = %s\", h);\n }\n foreach (u; 0 .. N) {\n if ((S[u] == -1) != (h[u] % 2 == 0)) {\n debug {\n writeln(\"incorrectly erased\");\n }\n return -1;\n }\n }\n \n auto graph = new int[][N];\n foreach (u; 1 .. N) {\n graph[P[u]] ~= u;\n }\n \n auto a = new long[N];\n a[0] = S[0];\n foreach (u; 1 .. N) {\n if (S[u] == -1) {\n if (graph[u].empty) {\n a[u] = 0;\n } else {\n a[u] = graph[u].map!(v => S[v]).minElement - S[P[u]];\n }\n } else {\n a[u] = S[u] - S[P[P[u]]] - a[P[u]];\n }\n if (a[u] < 0) {\n debug {\n writeln(\"negative value needed\");\n }\n return -1;\n }\n }\n debug {\n writefln(\"a = %s\", a);\n }\n return a.sum;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n P = new int[N];\n S = new long[N];\n foreach (u; 1 .. N) {\n P[u] = readInt() - 1;\n }\n foreach (u; 0 .. N) {\n S[u] = readInt();\n }\n const ans = solve();\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto P = readln.split.map!(to!int).array;\n auto S = readln.split.map!(to!long).array;\n auto X = new long[](N);\n auto G = new int[][](N);\n foreach (i; 0..N-1) {\n G[P[i]-1] ~= i+1;\n G[i+1] ~= P[i]-1;\n }\n\n bool ok = true;\n long ans = 0;\n\n long dfs(int n, int p) {\n long ret = S[n];\n if (ret == -1) ret = INF;\n foreach (m; G[n]) {\n if (m == p) continue;\n auto v = dfs(m, n);\n if (v < S[n]) ok = false;\n ret = min(ret, v);\n }\n X[n] = ret;\n return ret;\n }\n\n void dfs2(int n, int p, long s) {\n if (X[n] == INF) return;\n long a = X[n] - s;\n ans += a;\n foreach (m; G[n]) {\n if (m == p) continue;\n dfs2(m, n, X[n]);\n }\n }\n\n dfs(0, -1);\n\n if (!ok) {\n writeln(-1);\n return;\n }\n\n dfs2(0, -1, 0);\n\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "7d5ecacc037c9b0e6de2e86b20638674"} {"source_code": "import std.stdio;\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n long[100_001] arr;\n long runtot = 0;\n int n, m;\n readf(\" %s %s\\n\", &n, &m);\n foreach (i; 1 .. n + 1) {\n readf(\" %s\", &arr[i]);\n }\n foreach (i; 0 .. m) {\n int q, a, b; readf(\" %s\", &q);\n switch (q) {\n case 1:\n readf(\" %s %s\\n\", &a, &b);\n arr[a] = b - runtot;\n break;\n case 2:\n readf(\" %s\\n\", &a);\n runtot += a;\n break;\n case 3:\n readf(\" %s\\n\", &a);\n writeln(arr[a] + runtot);\n break;\n default:\n assert(0);\n }\n }\n \n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n\n long[100_001] arr;\n long runtot = 0;\n int n, m;\n readf(\" %d %d\\n\", &n, &m);\n foreach (i; 1 .. n + 1) {\n readf(\" %d\", &arr[i]);\n }\n foreach (i; 0 .. m) {\n int q, a, b; readf(\" %d\", &q);\n switch (q) {\n case 1:\n readf(\" %d %d\\n\", &a, &b);\n arr[a] = b - runtot;\n break;\n case 2:\n readf(\" %d\\n\", &a);\n runtot += a;\n break;\n case 3:\n readf(\" %d\\n\", &a);\n writeln(arr[a] + runtot);\n break;\n default:\n assert(0);\n }\n }\n \n return 0;\n}"}], "negative_code": [], "src_uid": "48f3ff32a11770f3b168d6e15c0df813"} {"source_code": "import std.stdio, std.string;\nimport std.random, std.algorithm;\n\nclass Treap(T)\n{\n protected class Node\n {\n Node left;\n Node right;\n T val;\n int priority;\n int size;\n\n this()\n {\n left = right = null;\n size = 1;\n }\n\n //int opCmp(Node node)\n //{\n //return this.priority - node.priority;\n //}\n\n int cmpPriority(int priority)\n {\n if (this.priority == priority) return 0;\n return this.priority < priority ? -1 : 1;\n }\n\n int cmpVal(T val)\n {\n if (this.val == val) return 0;\n return this.val < val ? -1 : 1;\n }\n }\n\n protected Node root;\n protected Xorshift rnd;\n protected int _size;\n protected T minimal;\n protected T maximal;\n\n this()\n {\n root = null;\n rnd = Xorshift(1234567891);\n _size = 0;\n minimal = T.max;\n maximal = T.min;\n }\n\n protected void leftRotate(ref Node node)\n {\n auto rightNode = node.right;\n if (rightNode)\n {\n node.size = 1;\n if (node.left) node.size += node.left.size;\n if (rightNode.left) node.size += rightNode.left.size;\n rightNode.size = 1 + node.size;\n if (rightNode.right) rightNode.size += rightNode.right.size;\n node.right = rightNode.left;\n rightNode.left = node;\n node = rightNode;\n }\n }\n\n protected void rightRotate(ref Node node)\n {\n auto leftNode = node.left;\n if (leftNode)\n {\n node.size = 1;\n if (node.right) node.size += node.right.size;\n if (leftNode.right) node.size += leftNode.right.size;\n leftNode.size = 1 + node.size;\n if (leftNode.left) leftNode.size += leftNode.left.size;\n node.left = leftNode.right;\n leftNode.right = node;\n node = leftNode;\n }\n }\n\n protected Node find(T val)\n {\n return _find(root, val);\n }\n\n protected Node _find(Node node, T val)\n {\n if (!node) return null;\n auto ret = node.cmpVal(val);\n if (ret == 0) return node;\n if (ret == -1) return _find(node.right, val);\n return _find(node.left, val);\n }\n\n public void insert(T val)\n {\n auto ret = _insert(root, val);\n if (ret)\n {\n ++ _size;\n }\n }\n\n protected bool _insert(ref Node node, T val)\n {\n if (!node)\n {\n node = new Node();\n node.val = val;\n node.priority = this.rnd.front;\n this.rnd.seed(unpredictableSeed);\n return true;\n }\n auto ret = node.cmpVal(val);\n if (ret == 0) return false;\n bool res;\n if (ret == 1)\n {\n res = _insert(node.left, val);\n if (res)\n {\n if (node.left.priority > node.priority)\n {\n rightRotate(node);\n }\n else\n {\n ++ node.size;\n }\n }\n }\n else if (ret == -1)\n {\n res = _insert(node.right, val);\n if (res)\n {\n if (node.right.priority > node.priority)\n {\n leftRotate(node);\n }\n else\n {\n ++ node.size;\n }\n }\n }\n return res;\n }\n\n public void remove(T val)\n {\n auto ret = _remove(root, val);\n if (ret)\n {\n -- _size;\n }\n }\n\n protected bool _remove(ref Node node, T val)\n {\n if (!node) return false;\n auto ret = node.cmpVal(val);\n if (ret == -1)\n {\n return _remove(node.right, val);\n }\n else if (ret == 1)\n {\n return _remove(node.left, val);\n }\n if (!node.left && !node.right)\n {\n node = null;\n return true;\n }\n if (!node.left)\n {\n node = node.right;\n return true;\n }\n if (!node.right)\n {\n node = node.left;\n return true;\n }\n bool res;\n if (node.left.cmpPriority(node.right.priority) == 1) \n {\n rightRotate(node);\n res = _remove(node.right, val);\n }\n else\n {\n leftRotate(node);\n res = _remove(node.left, val);\n }\n if (res)\n {\n -- node.size;\n }\n return res;\n }\n\n protected int _countLess(Node node, T val)\n {\n if (!node) return 0;\n if (node.val == val)\n {\n if (node.left)\n {\n return node.left.size;\n }\n return 0;\n }\n if (node.val < val)\n {\n auto res = _countLess(node.right, val);\n ++ res;\n if (node.left)\n {\n res += node.left.size;\n }\n return res;\n }\n return _countLess(node.left, val);\n }\n\n public int countLess(T val)\n {\n return _countLess(root, val);\n }\n\n protected int _countGreater(Node node, T val)\n {\n if (!node) return 0;\n if (node.val == val)\n {\n if (node.right)\n {\n return node.right.size;\n }\n return 0;\n }\n if (node.val > val)\n {\n auto res = _countGreater(node.left, val);\n ++ res;\n if (node.right)\n {\n res += node.right.size;\n }\n return res;\n }\n return _countGreater(node.right, val);\n }\n\n public int countGreater(T val)\n {\n return _countGreater(root, val);\n }\n\n protected T _getMinimal(Node node)\n {\n if (!node) return minimal; \n if (!node.left) return node.val;\n return _getMinimal(node.left);\n }\n\n public T getMinimal()\n {\n return _getMinimal(root);\n }\n\n protected T _getMaximal(Node node)\n {\n if (!node) return maximal;\n if (!node.right) return node.val;\n return _getMaximal(node.right);\n }\n\n public T getMaximal()\n {\n return _getMaximal(root);\n }\n\n public void travel()\n {\n _travel(root);\n }\n\n protected void _travel(Node node)\n {\n if (!node) return;\n _travel(node.left);\n writeln(node.val);\n writeln(node.priority);\n writeln(node.size);\n _travel(node.right);\n }\n\n public void clear()\n {\n while (root)\n {\n remove(root.val);\n }\n }\n\n @property public int size()\n {\n return _size;\n }\n}\n\nvoid solve(int[] a)\n{\n auto n = cast(int)a.length;\n auto treap = new Treap!int();\n auto lc = new int[n];\n foreach (i; 0 .. n)\n {\n lc[i] = treap.countGreater(a[i]);\n treap.insert(a[i]);\n }\n treap.clear();\n auto rc = new int[n];\n for (int i = n - 1; i >= 0; -- i)\n {\n rc[i] = treap.countLess(a[i]);\n treap.insert(a[i]);\n }\n long ans = 0;\n foreach (i; 0 .. n)\n {\n ans += cast(long)lc[i] * rc[i];\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto a = next!long(n);\n auto lsThan = St(new long[](n));\n auto rightLessThan = new long[](n);\n auto si = iota(0, n).array.sort!((i, j) => a[i] < a[j]);\n debug writeln(si);\n foreach(i; si)\n {\n lsThan.set(i, 1);\n debug\n\t{\n\t foreach(k; 0 .. n)\n\t write(lsThan.getSum(k, k), \" \");\n\t writeln;\n\t}\n if (i < n - 1) rightLessThan[i] = lsThan.getSum(i + 1, n - 1);\n }\n debug writeln(rightLessThan);\n auto pairs = St(new long[](n));\n auto sol = new long[](n);\n foreach(i; si)\n {\n pairs.set(i, rightLessThan[i]);\n if (i < n - 1) sol[i] = pairs.getSum(i + 1, n - 1);\n }\n sol.sum.writeln;\n}\n\nstruct St\n{\n class Node\n {\n this(int s, int e)\n {\n this.s = s;\n this.e = e;\n this.sum = 0;\n }\n int s, e;\n int len() {return e - s + 1;}\n long sum;\n long query(int i, int j)\n {\n debug writeln(\"querying \", s, \" \", e, \" for \", i, \" \", j);\n if (i <= s && e <= j) return sum;\n if (s > j || i > e) return 0;\n return leftChild.query(i, j) + rightChild.query(i, j);\n }\n void set(int i, long val)\n {\n if (s <= i && i <= e)\n\t{\n\t if (len == 1) { debug writeln(\"setting \"); sum = val; return; }\n\t leftChild.set(i, val);\n\t rightChild.set(i, val);\n\t sum = leftChild.sum + rightChild.sum;\n\t}\n }\n Node leftChild, rightChild;\n }\n Node _root;\n this(long[] arr)\n {\n Node construct(int s, int e)\n {\n auto node = new Node(s, e);\n auto len = e - s + 1;\n if (len == 1)\n\t{\n\t node.sum = arr[s];\n\t return node;\n\t}\n int llen = len / 2;\n node.leftChild = construct(s, s + llen - 1);\n node.rightChild = construct(s + llen, e);\n assert(node.leftChild.len == llen);\n assert(node.rightChild.len == len - llen);\n node.sum = node.leftChild.sum + node.rightChild.sum;\n return node;\n }\n _root = construct(0, cast(int)arr.length - 1);\n }\n long getSum(int i, int j)\n {\n return _root.query(i, j);\n }\n void set(int i, long val)\n {\n return _root.set(i, val);\n }\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio, std.string;\nimport std.random, std.algorithm;\n\nclass Treap(T)\n{\n protected class Node\n {\n Node left;\n Node right;\n T val;\n int priority;\n int size;\n\n this()\n {\n left = right = null;\n size = 1;\n }\n\n //int opCmp(Node node)\n //{\n //return this.priority - node.priority;\n //}\n\n int cmpPriority(int priority)\n {\n if (this.priority == priority) return 0;\n return this.priority < priority ? -1 : 1;\n }\n\n int cmpVal(T val)\n {\n if (this.val == val) return 0;\n return this.val < val ? -1 : 1;\n }\n }\n\n protected Node root;\n protected Xorshift rnd;\n protected int _size;\n protected T minimal;\n protected T maximal;\n\n this()\n {\n root = null;\n rnd = Xorshift(1234567891);\n _size = 0;\n minimal = T.max;\n maximal = T.min;\n }\n\n protected void leftRotate(ref Node node)\n {\n auto rightNode = node.right;\n if (rightNode)\n {\n node.size = 1;\n if (node.left) node.size += node.left.size;\n if (rightNode.left) node.size += rightNode.left.size;\n rightNode.size = 1 + node.size;\n if (rightNode.right) rightNode.size += rightNode.right.size;\n node.right = rightNode.left;\n rightNode.left = node;\n node = rightNode;\n }\n }\n\n protected void rightRotate(ref Node node)\n {\n auto leftNode = node.left;\n if (leftNode)\n {\n node.size = 1;\n if (node.right) node.size += node.right.size;\n if (leftNode.right) node.size += leftNode.right.size;\n leftNode.size = 1 + node.size;\n if (leftNode.left) leftNode.size += leftNode.left.size;\n node.left = leftNode.right;\n leftNode.right = node;\n node = leftNode;\n }\n }\n\n protected Node find(T val)\n {\n return _find(root, val);\n }\n\n protected Node _find(Node node, T val)\n {\n if (!node) return null;\n auto ret = node.cmpVal(val);\n if (ret == 0) return node;\n if (ret == -1) return _find(node.right, val);\n return _find(node.left, val);\n }\n\n public void insert(T val)\n {\n auto ret = _insert(root, val);\n if (ret)\n {\n ++ _size;\n }\n }\n\n protected bool _insert(ref Node node, T val)\n {\n if (!node)\n {\n node = new Node();\n node.val = val;\n node.priority = this.rnd.front;\n this.rnd.seed(unpredictableSeed);\n return true;\n }\n auto ret = node.cmpVal(val);\n if (ret == 0) return false;\n bool res;\n if (ret == 1)\n {\n res = _insert(node.left, val);\n if (res)\n {\n if (node.left.priority > node.priority)\n {\n rightRotate(node);\n }\n else\n {\n ++ node.size;\n }\n }\n }\n else if (ret == -1)\n {\n res = _insert(node.right, val);\n if (res)\n {\n if (node.right.priority > node.priority)\n {\n leftRotate(node);\n }\n else\n {\n ++ node.size;\n }\n }\n }\n return res;\n }\n\n public void remove(T val)\n {\n auto ret = _remove(root, val);\n if (ret)\n {\n -- _size;\n }\n }\n\n protected bool _remove(ref Node node, T val)\n {\n if (!node) return false;\n auto ret = node.cmpVal(val);\n if (ret == -1)\n {\n return _remove(node.right, val);\n }\n else if (ret == 1)\n {\n return _remove(node.left, val);\n }\n if (!node.left && !node.right)\n {\n node = null;\n return true;\n }\n if (!node.left)\n {\n node = node.right;\n return true;\n }\n if (!node.right)\n {\n node = node.left;\n return true;\n }\n bool res;\n if (node.left.cmpPriority(node.right.priority) == 1) \n {\n rightRotate(node);\n res = _remove(node.right, val);\n }\n else\n {\n leftRotate(node);\n res = _remove(node.left, val);\n }\n if (res)\n {\n -- node.size;\n }\n return res;\n }\n\n protected int _countLess(Node node, T val)\n {\n if (!node) return 0;\n if (node.val == val)\n {\n if (node.left)\n {\n return node.left.size;\n }\n return 0;\n }\n if (node.val < val)\n {\n auto res = _countLess(node.right, val);\n ++ res;\n if (node.left)\n {\n res += node.left.size;\n }\n return res;\n }\n return _countLess(node.left, val);\n }\n\n public int countLess(T val)\n {\n return _countLess(root, val);\n }\n\n protected int _countGreater(Node node, T val)\n {\n if (!node) return 0;\n if (node.val == val)\n {\n if (node.right)\n {\n return node.right.size;\n }\n return 0;\n }\n if (node.val > val)\n {\n auto res = _countGreater(node.left, val);\n ++ res;\n if (node.right)\n {\n res += node.right.size;\n }\n return res;\n }\n return _countGreater(node.right, val);\n }\n\n public int countGreater(T val)\n {\n return _countGreater(root, val);\n }\n\n protected T _getMinimal(Node node)\n {\n if (!node) return minimal; \n if (!node.left) return node.val;\n return _getMinimal(node.left);\n }\n\n public T getMinimal()\n {\n return _getMinimal(root);\n }\n\n protected T _getMaximal(Node node)\n {\n if (!node) return maximal;\n if (!node.right) return node.val;\n return _getMaximal(node.right);\n }\n\n public T getMaximal()\n {\n return _getMaximal(root);\n }\n\n public void travel()\n {\n _travel(root);\n }\n\n protected void _travel(Node node)\n {\n if (!node) return;\n _travel(node.left);\n writeln(node.val);\n writeln(node.priority);\n writeln(node.size);\n _travel(node.right);\n }\n\n public void clear()\n {\n while (root)\n {\n remove(root.val);\n }\n }\n\n @property public int size()\n {\n return _size;\n }\n}\n\nvoid solve(int[] a)\n{\n auto n = cast(int)a.length;\n auto treap = new Treap!int();\n auto lc = new int[n];\n foreach (i; 0 .. n)\n {\n lc[i] = treap.countGreater(a[i]);\n treap.insert(a[i]);\n }\n treap = new Treap!int();\n //treap.clear();\n auto rc = new int[n];\n for (int i = n - 1; i >= 0; -- i)\n {\n rc[i] = treap.countLess(a[i]);\n treap.insert(a[i]);\n }\n long ans = 0;\n foreach (i; 0 .. n)\n {\n ans += cast(long)lc[i] * rc[i];\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "463d4e6badd3aa110cc87ae7049214b4"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1409/problem/A\n// \nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n \n while(t--) {\n long a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n\n real diff = (a - b)/10.0;\n long moves = cast(long)ceil(abs(diff));\n moves.writeln;\n }\n}\n\n", "positive_code": [{"source_code": "import std.math;\nimport std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nlong pmod(long a, long m)\n{\n return (a%m +m)%m;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto a = next!long;\n auto b = next!long;\n auto diff = abs(a - b);\n long ops = diff / 10;\n if (diff % 10 != 0)\n ops++;\n writeln(ops);\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto d = abs(a - b);\n\t\tans[ti] = (d+9) / 10;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "d67a97a3b69d599b03d3fce988980646"} {"source_code": "module main;\r\nimport std.stdio, std.conv, std.string, std.array;\r\n\r\nT read(T)()\r\n{\r\n static string[] tokens;\r\n while (!tokens.length)\r\n tokens = stdin.readln.split;\r\n auto result = tokens[0].to!T;\r\n tokens = tokens[1 .. $];\r\n return result;\r\n}\r\n\r\nvoid main()\r\n{\r\n auto T = read!int;\r\n foreach (case_index; 0 .. T)\r\n {\r\n auto n = read!int, k = read!int;\r\n auto result_builder = appender!(int[]);\r\n foreach (i; 1 .. n + 1)\r\n {\r\n if (i >= (k + 1) / 2 && i != k)\r\n result_builder ~= i;\r\n }\r\n auto result = result_builder[];\r\n writeln(result.length);\r\n writefln!\"%(%s %)\"(result);\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\r\n\t\tforeach_reverse (i; 1..n+1)\r\n\t\t{\r\n\t\t\tif (i == k || i*2 < k) continue;\r\n\t\t\telse\r\n\t\t\t\tans[ti] ~= i;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e.length);\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\tauto a = iota (1, n + 1).array;\r\n\t\ta = a.filter !(x => x * 2 >= k && x != k).array;\r\n\t\twriteln (a.length);\r\n\t\twritefln !(\"%(%s %)\") (a);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n, k;\r\n readf!\"%d %d\\n\"(n, k);\r\n writeln(n - k + k / 2);\r\n foreach (i; k + 1 .. n + 1)\r\n write(i, ' ');\r\n foreach (i; (k + 1) / 2 .. k)\r\n write(i, ' ');\r\n writeln;\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\tint m = (k + 1) / 2 + 1;\r\n\t\twriteln (n - m + 1);\r\n\t\twritefln !(\"%(%s %)\") (iota (m, n + 1));\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n, k;\r\n readf!\"%d %d\\n\"(n, k);\r\n foreach (i; k + 1 .. n + 1)\r\n write(i, ' ');\r\n foreach (i; (k + 1) / 2 .. k)\r\n write(i, ' ');\r\n writeln;\r\n }\r\n}"}], "src_uid": "d08e39db62215d7817113aaa384e3f59"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\tlong k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\talias Segment = Tuple !(long, q{lo}, long, q{hi});\n\t\tSegment [2] s;\n\t\tforeach (i; 0..2)\n\t\t{\n\t\t\treadf !(\" %s %s\") (s[i].lo, s[i].hi);\n\t\t}\n\t\tauto hi = min (s[0].hi, s[1].hi);\n\t\tauto lo = max (s[0].lo, s[1].lo);\n\t\tauto common = max (0, hi - lo);\n\t\tk = max (0L, k - n * 1L * common);\n\t\tauto gap = max (0, s[0].lo - s[1].hi, s[1].lo - s[0].hi);\n\t\tauto d1 = abs (s[1].hi - s[0].hi);\n\t\tauto d2 = abs (s[1].lo - s[0].lo);\n\t\tlong len = d1 + d2 - gap;\n\t\tdebug {writeln (\"gap = \", gap, \", len = \", len);}\n\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (k <= 0)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t/// \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c gap + cur\n\t\t\t/// \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c + cur \u043a \u043e\u0442\u0432\u0435\u0442\u0443\n\t\t\t/// 0 <= cur <= len\n\t\t\tauto cur = min (k, len);\n\t\t\tauto pay = gap + cur;\n\t\t\tif (i > 0 && pay > cur * 2)\n\t\t\t{\n\t\t\t\tres += k * 2;\n\t\t\t\tk = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres += pay;\n\t\t\t\tk -= cur;\n\t\t\t}\n\t\t}\n\t\twriteln (res + k * 2);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\tlong k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\talias Segment = Tuple !(long, q{lo}, long, q{hi});\n\t\tSegment [2] s;\n\t\tforeach (i; 0..2)\n\t\t{\n\t\t\treadf !(\" %s %s\") (s[i].lo, s[i].hi);\n\t\t}\n\t\tauto hi = min (s[0].hi, s[1].hi);\n\t\tauto lo = max (s[0].lo, s[1].lo);\n\t\tauto common = max (0, hi - lo);\n\t\tk = max (0L, k - n * 1L * common);\n\t\tauto gap = max (0, s[0].lo - s[1].hi, s[1].lo - s[0].hi);\n\t\tauto d1 = abs (s[1].hi - s[0].hi);\n\t\tauto d2 = abs (s[1].lo - s[0].lo);\n\t\tlong len = d1 + d2 - gap;\n\t\tdebug {writeln (\"gap = \", gap, \", len = \", len);}\n\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (k <= 0)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tauto cur = min (k, len);\n\t\t\tauto pay = gap + cur;\n\t\t\tif (i > 0 && pay > k * 2)\n\t\t\t{\n\t\t\t\tres += k * 2;\n\t\t\t\tk = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres += pay;\n\t\t\t\tk -= cur;\n\t\t\t}\n\t\t}\n\t\twriteln (res + k * 2);\n\t}\n}\n"}], "negative_code": [], "src_uid": "c8da5d7debf5d7a6fc04bb3a68cda2f0"} {"source_code": "/+ dub.sdl:\n name \"C\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n int n;\n sc.read(n);\n int[][] g = new int[][n];\n foreach (i; 0..n-1) {\n int a, b;\n sc.read(a, b); a--; b--;\n g[a] ~= b; g[b] ~= a;\n }\n if (g.count!\"a.length>=3\" >= 2) {\n writeln(\"No\");\n return 0;\n }\n int[] leafs;\n void dfs(int p, int b) {\n bool haveCh = false;\n foreach (d; g[p]) {\n if (d == b) continue;\n haveCh = true;\n dfs(d, p);\n }\n if (!haveCh) leafs ~= p;\n }\n foreach (i; 0..n) {\n if (i == n-1 || g[i].length >= 3) {\n dfs(i, -1);\n writeln(\"Yes\");\n writeln(leafs.length);\n foreach (d; leafs) {\n writeln(i+1, \" \", d+1);\n }\n break;\n }\n }\n return 0;\n}\n/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto d = new int [n];\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t\td[u] += 1;\n\t\t\td[v] += 1;\n\t\t}\n\t\tauto p = n.iota.array;\n\t\tmakeIndex (d, p);\n\t\tif (d[p[$ - 2]] > 2)\n\t\t{\n\t\t\twriteln (\"No\");\n\t\t\tcontinue;\n\t\t}\n\t\twriteln (\"Yes\");\n\t\tauto r = p[$ - 1];\n\t\twriteln (n.iota.count !(x => x != r && d[x] == 1));\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\tif (v != r && d[v] == 1)\n\t\t\t{\n\t\t\t\twriteln (v + 1, \" \", r + 1);\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.datetime;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto G = new int[][](N);\n foreach (_; 0..N-1) {\n auto s = readln.split.map!(to!int);\n G[s[0]-1] ~= s[1]-1;\n G[s[1]-1] ~= s[0]-1;\n }\n\n if (G.map!(g => g.length >= 3).sum >= 2) {\n writeln(\"No\");\n return;\n }\n\n writeln(\"Yes\");\n\n int[] root1;\n int root3 = -1;\n foreach (i; 0..N) if (G[i].length == 1) root1 ~= i;\n foreach (i; 0..N) if (G[i].length >= 3) root3 = i;\n\n if (root3 == -1) {\n writeln(1);\n writeln(root1[0]+1, \" \", root1[1]+1);\n } else {\n writeln(root1.length);\n foreach (r; root1)\n writeln(r+1, \" \", root3+1);\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf( \"%s\", &n );\n readln;\n \n auto g = new int [][] ( n+1 );\n foreach ( _; 0..n-1 ) {\n auto t = readln.splitter.map!( to!int ).array;\n (2).iota.each!( i => g[ t[ i ] ] ~= t[ 1-i ] );\n }\n \n debug { writeln( g ); }\n \n bool ok = g.count!(adj => adj.length > 2) <= 1;\n \n if ( !ok ) {\n writeln( \"No\" );\n return;\n }\n \n int v = cast(int) g.maxIndex!( q{ a.length < b.length });\n \n int[] ans;\n foreach ( u; g[v] ) {\n int lst = v;\n int cur = u;\n while ( true ) {\n if ( g[ cur ].length == 1 ) break;\n \n auto nxt = g[ cur ][ 0 ] != lst ? g[ cur ][ 0 ] : g[ cur ][ 1 ];\n lst = cur;\n cur = nxt;\n }\n ans ~= cur;\n }\n \n writeln( \"Yes\" );\n writeln( ans.length );\n ans.each!( lst => writeln( v, ' ', lst ) );\n}"}], "negative_code": [], "src_uid": "0a476638c2122bfb236b53742cf8a89d"} {"source_code": "import std.stdio;\nimport std.string: chomp, split;\nimport std.conv: to;\n\n\nvoid main()\n{\n\tint n; readf(\"%s\\n\", &n);\n\tauto ar = readln.chomp.split.to!(int[]);\n\t//writeln(ar);\n\t\n\tint state = -1, sol = 0;\n\t\n\tforeach (a; ar) {\n\t\t//writefln(\"%d %d\", a, state);\n\t\tif (a == 0) {\n\t\t\tif (state != -1) {\n\t\t\t\tstate = 1;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (state == -1) {\n\t\t\tstate = 0;\n\t\t}\n\t\tsol++;\n\t\tif (state == 1) {\n\t\t\tsol++;\n\t\t\tstate = 0;\n\t\t}\n\t}\n\n\twriteln(sol);\n}\n", "positive_code": [{"source_code": "\ufeffimport std.stdio;\n\nvoid main() {\n\n\tint n, ni, num, flag;\n\n\tscanf(\"%d\", &n);\n\n\tforeach (i; 0 .. n) {\n\t\tscanf(\"%d\", &ni);\n\t\tif (!ni && flag) {\n\t\t\tflag = 0;\n\t\t\tnum++;\n\t\t}\n\t\telse\n\t\t\tif (ni == 1) {\n\t\t\t\tnum++;\n\t\t\t\tflag = 1;\n\t\t\t}\n\t}\n\n\tif (num > 0 && !ni)\n\t\tnum--;\n\n\tprintf(\"%d\\n\", num);\n}"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.functional;\nimport std.traits;\nimport std.string;\nimport std.container;\n\nunittest{\n assert(solve([1,1,0,0,1]) == 4, \"Teste 1\");\n assert(solve([0,1,0,1,0]) == 3, \"Teste 2\");\n assert(solve([0,0]) == 0, \"Teste 3\");\n assert(solve([0,0,1,0,0,0,0,0]) == 1, \"Teste 4\");\n assert(solve([0,0,0,0,0,0,0,1]) == 1, \"Teste 5\");\n assert(solve([1,0,0,0,0,0,0,0]) == 1, \"Teste 6\");\n assert(solve([1,0,1,0,0,1,1,0]) == 6, \"Teste 7\");\n}\n\nlong solve(long[] ls){\n long c = 0;\n int state = 0;\n foreach(i,l;ls){\n if(state == 0 && l == 1){\n c++;\n state = 1;\n //writefln(\"%s open\",i);\n } else if(state == 1){\n if(l == 0){\n if(ls[i-1] == 0){\n state = 0;\n //writefln(\"%s back\",i-1);\n } else {\n c++;\n //writefln(\"%s next\",i);\n }\n } else {\n //writefln(\"%s next\",i);\n c++;\n }\n }\n }\n if(ls[$-1] == 0 && c != 0){\n c--;\n }\n //writeln(c);\n return c;\n}\n\nvoid main(){\n size_t n;\n readf(\"%s\\n\",&n);\n\n long[] l = new long[n];\n for(size_t i = 0; i < n; i++){\n readf(\"%s \",l.ptr+i);\n }\n writeln(solve(l));\n}\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nint[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tint ans;\n\t\tfor (int i = 0, j; i < N; i = j) {\n\t\t\tfor (; j < N && A[i] == A[j]; ++j) {}\n\t\t\tif (A[i] == 1) {\n\t\t\t\tans += (j - i + 1);\n\t\t\t}\n\t\t}\n\t\tif (ans > 0) {\n\t\t\t--ans;\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "0fbc306d919d7ffc3cb02239cb9c2ab0"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1430/problem/C\n// math, greedy\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\n int n;\n while(t--) {\n readf(\"%s\\n\", &n);\n\n \"2\".writeln;\n\n int x = n - 2;\n int y = n;\n writefln(\"%s %s\", n - 1, n);\n\n for(int i = 0; i < n - 2; ++i) {\n writefln(\"%s %s\", x, y);\n x -= 1;\n y -= 1;\n }\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][][](t);\n\tauto ans2 = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\n\t\tBinaryHeap!(Array!int, \"a < b\") heap;\n\t\tforeach (i; 1..n+1)\n\t\t{\n\t\t\theap.insert(i);\n\t\t}\n\n\t\twhile (heap.length > 1)\n\t\t{\n\t\t\tauto x = heap.front; heap.removeFront;\n\t\t\tauto y = heap.front; heap.removeFront;\n\t\t\tans[ti] ~= [x, y];\n\t\t\theap.insert((x+y+1)/2);\n\t\t}\n\t\tans2[ti] = heap.front;\n\t}\n\n\tforeach (ti; 0..t)\n\t{\n\t\twriteln(ans2[ti]);\n\t\tforeach (e; ans[ti])\n\t\t{\n\t\t\twriteln(e[0], \" \", e[1]);\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "591372383cf3624f69793c41370022de"} {"source_code": "import std.algorithm, std.conv, std.stdio, std.string;\nvoid main () {\n\treadln;\n\tstdin.byLine.each !(x => writeln ((x.strip.to!int + 1) / 2));\n}\n", "positive_code": [{"source_code": "import std.container: DList;\nimport std.algorithm: all, map, count, filter;\nimport std.range: iota;\nimport std.array: array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n long n;\n read(n);\n writeln((n + n % 2)/2);\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tans[ti] = (n-1) / 2 + 1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "ec89860dacb5a11b3a2273d2341b07a1"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tbool [int] b;\n\n\t\tvoid go (int v)\n\t\t{\n\t\t\tauto d = gcd (v, n);\n\t\t\tb[d] = true;\n\t\t}\n\n\t\tfor (int d = 1; d * d <= n; d++)\n\t\t{\n\t\t\tgo (d);\n\t\t\tgo (n / d);\n\t\t}\n\n\t\tauto p = b.keys;\n\t\tbool [long] c;\n\n\t\tforeach (int q; p)\n\t\t{\n\t\t\tlong res = n / q;\n\t\t\tres *= n - q;\n\t\t\tres /= 2;\n\t\t\tres += n / q;\n\t\t\tc[res] = true;\n\t\t}\n\n\t\tauto ans = c.keys;\n\t\tsort (ans);\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\nvoid main() {\n long n;\n scan(n);\n\n long[] ans;\n\n for (int d = 1; d*d <= n; d++) {\n if (n % d != 0) {\n continue;\n }\n ans ~= 1L * n * (n / d - 1) / 2 + n / d;\n auto c = n / d;\n ans ~= 1L * n * (n / c - 1) / 2 + n / c;\n }\n\n auto anss = ans.sort().uniq();\n\n writefln(\"%(%s %)\", anss);\n}\n\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.range;\n\n // for (int n = 2; n <= 20; n++) {\n // auto ids = iota(n);\n // int[] ans;\n // for (int k = 1; k <= n; k++) {\n // int cur = k, s = 1;\n // while (cur % n) {\n // s += (cur + 1);\n // cur += k;\n // cur %= n;\n // }\n // ans ~= s;\n // }\n // ans = ans.sort.uniq.array;\n // writeln(n, \" \", ans);\n // }\n\n long n;\n rd(n);\n long[] ans;\n for (long i = 1; i * i <= n; i++) {\n if (n % i == 0) {\n auto j = n / i;\n ans ~= i * (2 + (i - 1) * j) / 2;\n ans ~= j * (2 + (j - 1) * i) / 2;\n }\n }\n ans = ans.sort.uniq.array;\n writefln(\"%(%s %)\", ans);\n}\n\n// 16\n// 1 10 28 64 136\n// 1 2 4 8 16\n// 1 = 1\n// 10 = 1 + 9\n// 28 = 1 + 5 + 9 + 13\n// 64 = 1 + 3 + 5 + 7 + 9 + 11 + 13 + 15\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "2ae1a4d4f2e58b359c898d1ff38edb9e"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint rows, cols;\r\n\twhile (readf !(\" %s %s\") (rows, cols) > 0)\r\n\t{\r\n\t\tint [] [] board;\r\n\t\treadln;\r\n\t\tforeach (row; 0..rows)\r\n\t\t{\r\n\t\t\tboard ~= readln.splitter.map !(to !(int)).array;\r\n\t\t}\r\n\t\tauto answer = new int [] [] (rows, cols);\r\n\t\tforeach (row; 0..rows)\r\n\t\t{\r\n\t\t\tforeach (col; 0..cols)\r\n\t\t\t{\r\n\t\t\t\tint value = 720_720;\r\n\t\t\t\tif ((row ^ col) & 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tvalue -= board[row][col] ^^ 4;\r\n\t\t\t\t}\r\n\t\t\t\tanswer[row][col] = value;\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%(%s %)\\n%)\") (answer);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid main(){\n int n = scan!int;\n int m = scan!int;\n int[][] mat;\n for(int i = 0; i < n; ++i){\n mat ~= scanArray!int;\n }\n\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n int colr = (i & 1) ^ (j & 1);\n if(!colr){\n mat[i][j] = 720720;\n }else{\n mat[i][j] *= mat[i][j];\n mat[i][j] *= mat[i][j];\n mat[i][j] += 720720;\n }\n }\n }\n foreach(row; mat){\n row.each!(cell => write(cell, \" \"));\n writeln;\n }\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nenum X = 720720;\r\nenum PP = [0, 13439, 106064, 189279, 106064, 330095, 388944, 106064, 106064, 189279, 560720, 486464, 388944, 263744, 106064, 670095, 106064];\r\n\r\nvoid main()\r\n{\r\n int N, M; get(N, M);\r\n int[][] aa; get_lines(N, aa);\r\n\r\n auto bb = new int[][](N, M);\r\n foreach (i; 0..N) foreach (j; 0..M) {\r\n if ((i + j) % 2 == 0) {\r\n bb[i][j] = X;\r\n } else {\r\n bb[i][j] = PP[aa[i][j]];\r\n }\r\n }\r\n writefln!\"%(%(%d %)\\n%)\"(bb);\r\n}"}], "negative_code": [], "src_uid": "5f0b8e6175113142be15ac960e4e9c4c"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\n\t\tif (n <= 3) continue;\n\t\tif (n % 2)\n\t\t{\n\t\t\tforeach (i; 0..n/2-2)\n\t\t\t{\n\t\t\t\tans[ti] ~= (i+1)*2;\n\t\t\t}\n\t\t\tans[ti] ~= [n-1, n-3];\n\t\t\twhile (n > 0)\n\t\t\t{\n\t\t\t\tans[ti] ~= n;\n\t\t\t\tn -= 2;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 0..n/2-2)\n\t\t\t{\n\t\t\t\tans[ti] ~= i*2+1;\n\t\t\t}\n\t\t\tans[ti] ~= [n-1, n-3];\n\t\t\twhile (n > 0)\n\t\t\t{\n\t\t\t\tans[ti] ~= n;\n\t\t\t\tn -= 2;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!int;\n if (N <= 3) {\n writeln(-1);\n continue;\n }\n\n auto rs = new int[](N);\n auto i = (N-1)/2;\n rs[i] = N;\n rs[i-1] = N-2;\n rs[i+1] = N-3;\n rs[i+2] = N-1;\n size_t l = i-2, r = i+3;\n auto n = N-4;\n for (;;) {\n if (n <= 0) break;\n rs[l--] = n--;\n if (n <= 0) break;\n rs[r++] = n--;\n }\n writeln(rs.to!(string[]).join(\" \"));\n }\n}"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint [] [int] loops;\n\tloops[4] = [2, 4, 1, 3];\n\tloops[5] = [2, 5, 3, 1, 4];\n\tloops[6] = [2, 6, 4, 1, 3, 5];\n\tloops[7] = [2, 5, 7, 3, 1, 4, 6];\n\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tif (n < 4)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint [] res;\n\t\t\twhile (n > 0)\n\t\t\t{\n\t\t\t\tint k = (n >= 8) ? 4 : n;\n\t\t\t\tauto cur = loops[k].dup;\n\t\t\t\tcur[] += res.length.to !(int);\n\t\t\t\tres ~= cur;\n\t\t\t\tn -= k;\n\t\t\t}\n\t\t\twritefln !(\"%(%s %)\") (res);\n\t\t}\n\t}\n}\n"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\n// permute at the center\nimport std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto p = iota (1, n + 1).array;\n\t\tp = p.stride (2).array ~ p.drop (1).stride (2).retro.array;\n\t\tint lo = max (0, n / 2 - 2);\n\t\tint hi = min (n, n / 2 + 2);\n\t\tsort (p[lo..hi]);\n\t\tdo\n\t\t{\n\t\t\tif (iota (1, n).all !(i =>\n\t\t\t abs (p[i] - p[i - 1]) >= 2 &&\n\t\t\t abs (p[i] - p[i - 1]) <= 4))\n\t\t\t{\n\t\t\t\twritefln !(\"%(%s %)\") (p);\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\t\twhile (nextPermutation (p[lo..hi]));\n\t\twriteln (-1);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.meta;\nimport std.random;\n\n\nvoid main() {\n\tint t = readln.chomp.to!int;\n\tforeach (tt; 0 .. t) {\n\t\tint n = readln.chomp.to!int;\n\t\tif (n <= 3) {\n\t\t\twriteln(-1);\n\t\t\tcontinue;\n\t\t}\n\t\tint[] res;\n\t\tres.assumeSafeAppend ~= iota((n + 1) / 2 + 1)[1 .. $]\n\t\t\t.map!(x => x * 2 - n % 2).array;\n\t\tres.assumeSafeAppend ~= [n - 3, n - 1];\n\t\tres.assumeSafeAppend ~= iota((n + 1) / 2 - 2, -1, -1)[1 .. $]\n\t\t\t.map!(x => x * 2 - n % 2 + 1).array;\n\t\tif (res[$ - 1] == 0) {\n\t\t\tres = res[0 .. $ - 1];\n\t\t}\n\t\twriteln(res.map!(to!string).join(\" \"));\n\t}\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n\n void solve(long tc = -1)\n {\n if (n <= 3)\n return writeln(-1);\n long k = n % 2 == 1? 1 : 2;\n while(k <= n)\n {\n write(k, \" \");\n k += 2;\n }\n k = n - 3;\n auto walk = chain([long(+2), long(-4)], repeat(long(-2)));\n while(k >= 1)\n {\n write(k, \" \");\n k += walk.front;\n walk.popFront;\n }\n writeln;\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [], "src_uid": "9b8a5d9a6cfd6b3b5d0839eeece6f777"} {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nint n, shipCount, shipLen, k;\nchar[200_003] _s;\n\nvoid main() {\n while (read(&n, &shipCount, &shipLen, &k)) {\n auto s = _s[ ];\n readln(s);\n s = s[0 .. $ - 1];\n int possible = 0;\n int cur = 0;\n foreach (c; s)\n if (c == '0') {\n if (++cur == shipLen) {\n possible++;\n cur = 0;\n }\n } else\n cur = 0;\n assert(possible >= shipCount);\n int need = possible - shipCount + 1;\n writeln(need);\n cur = 0;\n foreach (i, c; s)\n if (c == '0') {\n if (++cur == shipLen) {\n write(i + 1, ' ');\n cur = 0;\n if (!--need)\n break;\n }\n } else\n cur = 0;\n writeln();\n }\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias to!int isz;\nalias rbt = redBlackTree;\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nalias pair = Tuple!(int, int);\n/*******************************It's a Me, Mario!**********************************************/\n\n\n\nvoid play(){\n int n, a, b, k;\n n = rd!int; a = rd!int; b = rd!int; k = rd!int; \n dchar[] shots = rd!(dchar[]);\n int cnt = 0;\n int boatmax = 0;\n foreach(i; 0..n){\n if(shots[i] == '1'){\n boatmax += (cnt/b);\n cnt = 0;\n }else{\n ++cnt;\n }\n }\n boatmax += cnt/b;\n debug writeln(\"boatmax: \", boatmax);\n auto meep = rbt!(true, pair);\n\n int[] shoot;\n int[int] breaks;\n foreach(i; 0..b-1){\n meep.insert(pair(shots[i]-'0', i));\n }\n foreach(i; b-1..n){\n meep.insert(pair(shots[i]-'0', i));\n\n if(meep.back[0] != 1){\n meep.removeKey(pair(0, i));\n meep.insert(pair(1, i));\n shots[i] = '1';\n shoot ~= i;\n /* ++breaks[shoot.back]; */\n }else if(shoot.length && meep.back[1] == shoot.back){\n /* breaks[shoot.back] = breaks.get(shoot.back, 0) + 1; */\n /* ++breaks[shoot.back]; */\n }\n meep.removeKey(pair(shots[i-b+1]-'0', i-b+1));\n if(boatmax - shoot.length < a) break;\n }\n writeln(shoot.length);\n foreach(cr; shoot){\n write(cr+1, \" \");\n }\n writeln;\n}\n\nint main(){\n ll t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias to!int isz;\nalias rbt = redBlackTree;\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n/*******************************It's a Me, Mario!**********************************************/\n\nvoid play(){\n int n, a, b, k;\n n = rd!int; a = rd!int; b = rd!int; k = rd!int; \n dchar[] shots = rd!(dchar[]);\n auto meep = rbt!(true, Tuple!(int, int, int));\n int cnt = 0, firsti = 1, lasti = 1;\n int boatmax = 0;\n foreach(i; 0..n){\n if(shots[i] == '1'){\n if(cnt/b) meep.insert(tuple(cnt, firsti, lasti));\n boatmax += cnt/b;\n firsti = i+2;\n cnt = 0;\n }else{\n ++cnt;\n lasti = i+1;\n }\n }\n if(cnt/b) meep.insert(tuple(cnt, firsti, lasti));\n boatmax += cnt/b;\n int part1, part2;\n int[] shoot;\n while(boatmax >= a && shoot.length < 20){\n // Select Max Broken\n int maxbreak = 0;\n Tuple!(int, int, int) shootout;\n foreach(tup; meep){\n part1 = tup[0]/2;\n part2 = tup[0] - part1 - 1;\n int breaks = (tup[0]/b) - (part1/b) - (part2/b);\n /* debug writeln(\"Parts: \", part1, \" \", part2, \" \", breaks); */\n if(breaks >= maxbreak){\n maxbreak = breaks;\n shootout = tup;\n }\n }\n\n // Break Interval\n meep.removeKey(shootout);\n part1 = shootout[0]/2;\n part2 = shootout[0] - part1 - 1;\n if(part1 >= b) meep.insert(tuple(part1, shootout[1], shootout[1] + part1 - 1));\n if(part2 >= b) meep.insert(tuple(part2, shootout[2] - part2 + 1, shootout[2]));\n // Take the shot\n shoot ~= shootout[2] - part2;\n // Update boatmax\n boatmax -= maxbreak;\n debug writeln(meep);\n }\n writeln(shoot.length);\n foreach(cr; shoot){\n write(cr, \" \");\n }\n writeln;\n}\n\nint main(){\n ll t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}], "src_uid": "d50bb59298e109b4ac5f808d24fef5a1"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto n = RD;\n\t\tauto m = RD;\n\t\t\n\t\tif (a+b < n+m) continue;\n\t\tif (min(a, b) >= m)\n\t\t\tans[ti] = true;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"Yes\" : \"No\");\n\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.stdio, std.string;\nvoid main () {\n\treadln;\n\tlong a, b, n, m;\n\twhile (readf !(\" %s %s %s %s\") (a, b, n, m) > 0) {\n\t\twriteln (min (a, b) >= m && a + b >= n + m ? \"Yes\" : \"No\");\n\t}\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n testCase:while(t--)\n {\n long[2] a;\n long n, m;\n read(a[0]), read(a[1]), read(n), read(m);\n sort(a[]);\n if (a[0] >= m)\n {\n long rem = a[0] - m + a[1];\n if (rem >= n)\n {\n writeln(\"Yes\");\n continue testCase;\n }\n }\n writeln(\"No\");\n }\n}\n"}], "negative_code": [], "src_uid": "0f960d19e576b7421a7c7a7166a884ea"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto p = RD;\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\t\tauto c = RD;\r\n\r\n\t\tauto ap = (a - (p % a)) % a;\r\n\t\tauto bp = (b - (p % b)) % b;\r\n\t\tauto cp = (c - (p % c)) % c;\r\n\t\tans[ti] = min(ap, bp, cp);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n long P, A, B, C; get(P, A, B, C);\r\n writeln([A, B, C].map!(x => P <= x ? x - P : P % x == 0 ? 0 : x - P % x).minElement());\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n long P, A, B, C; get(P, A, B, C);\r\n writeln([A, B, C].map!(x => P <= x ? x - P : x - P % x).minElement());\r\n }\r\n}\r\n"}], "src_uid": "293f9b996eee9f76d4bfdeda85685baa"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\tlong [] b;\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tb ~= abs (a[i] - a[i - 1]);\r\n\t\t}\r\n\r\n\t\tint res = 1;\r\n\t\tint lo = 0;\r\n\t\tlong cur = 0;\r\n\t\tfor (int hi = 0; hi < n - 1; hi++)\r\n\t\t{\r\n\t\t\tlong next = gcd (cur, b[hi]);\r\n\t\t\tif (next == 1)\r\n\t\t\t{\r\n\t\t\t\tnext = 0;\r\n\t\t\t\tlo = hi + 1;\r\n\t\t\t\twhile (lo > 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tlong temp = gcd (next, b[lo - 1]);\r\n\t\t\t\t\tif (temp == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tlo -= 1;\r\n\t\t\t\t\tnext = temp;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tcur = next;\r\n\t\t\tres = max (res, hi - lo + 2);\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.numeric;\nimport std.math;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tint n = readInt!int;\n\tauto a = new long[](n);\n\tforeach(ref ai; a) ai = readInt!long;\n\tauto da = new long[](n - 1);\n\tforeach(i; 0 .. n - 1)\n\t{\n\t\tda[i] = abs(a[i + 1] - a[i]);\n\t}\n\tint mxp2 = cast(int)log2(n);\n\tauto gcdTable = new long[][](mxp2 + 1, n - 1);\n\tgcdTable[0][] = da[];\n\tforeach(p; 1 .. mxp2 + 1)\n\t{\n\t\tforeach(i; 0 .. n - 1)\n\t\t{\n\t\t\tif (i + (1 << p) <= n - 1)\n\t\t\t\tgcdTable[p][i] = gcd(gcdTable[p-1][i], gcdTable[p-1][i+(1<<(p-1))]);\n\t\t}\n\t}\n\tlong getGcd(int s, int e)\n\t{\n\t\tif (s > e) return 0;\n\t\tint len = e - s + 1;\n\t\tint mxp = cast(int)log2(len);\n\t\tint mxpn = (1 << mxp);\n\t\tlong p1 = gcdTable[mxp][s];\n\t\tlong p2 = gcdTable[mxp][e + 1 - mxpn];\n\t\treturn gcd(p1, p2);\n\t}\n\tdebug\n\t{\n\t\tforeach(i; 0 .. n - 1)\n\t\t{\n\t\t\tforeach(j; i .. n - 1)\n\t\t\t{\n\t\t\t\tassert(getGcd(i, j) == da[i .. j + 1].fold!gcd(0L));\n\t\t\t}\n\t\t}\n\t}\n\tint j = 0;\n\tint maxlen = 1;\n\tforeach(i; 0 .. n - 1)\n\t{\n\t\twhile (j <= i && getGcd(j, i) == 1) j++;\n\t\tmaxlen = max(maxlen, i - j + 2);\n\t}\n\tmaxlen.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.numeric;\nimport std.math;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tint n = readInt!int;\n\tauto a = new long[](n);\n\tforeach(ref ai; a) ai = readInt!long;\n\tauto da = new long[](n - 1);\n\tforeach(i; 0 .. n - 1)\n\t{\n\t\tda[i] = abs(a[i + 1] - a[i]);\n\t}\n\tint mxp2 = cast(int)log2(n);\n\tauto gcdTable = new long[][](mxp2 + 1, n - 1);\n\tgcdTable[0][] = da[];\n\tforeach(p; 1 .. mxp2 + 1)\n\t{\n\t\tforeach(i; 0 .. n - 1)\n\t\t{\n\t\t\tif (i + (1 << p) <= n - 1)\n\t\t\t\tgcdTable[p][i] = gcd(gcdTable[p-1][i], gcdTable[p-1][i+(1<<(p-1))]);\n\t\t}\n\t}\n\tlong getGcd(int s, int e)\n\t{\n\t\tif (s > e) return 0;\n\t\tint len = e - s + 1;\n\t\tint mxp = cast(int)log2(len);\n\t\tint mxpn = (1 << mxp);\n\t\tlong p1 = gcdTable[mxp][s];\n\t\tlong p2 = gcdTable[mxp][e + 1 - mxpn];\n\t\treturn gcd(p1, p2);\n\t}\n\tint j = 0;\n\tint maxlen = int.min;\n\tforeach(i; 0 .. n - 1)\n\t{\n\t\twhile (j <= i && getGcd(j, i) == 1) j++;\n\t\tmaxlen = max(maxlen, i - j + 1);\n\t}\n\t(maxlen + 1).writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}], "src_uid": "2f0cdacc14ac81249f30c8c231003a73"} {"source_code": "import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;\nimport std.algorithm, std.container, std.datetime, std.typecons;\n\nconst MD = 10^^9+7;\n\nalias Tl = Tuple!(long, long);\n\nlong powMod(long x, long n, long md) {\n long r = 1;\n while (n) {\n if (n & 1) r *= x; r %= md;\n x *= x; x %= md;\n n >>= 1;\n }\n return r;\n}\n\n//-------------------------------------------------------//\n\nint n;\nint[] d;\nstring[] t;\n\nTl[][] dp;\nbool[][] used;\nTl calc(int ad, int c) {\n\tif (ad == n) return Tl(c, 1);\n\tif (d[ad] != c) return calc(ad+1, c);\n\tif (used[ad][c]) return dp[ad][c];\n\tused[ad][c] = true;\n\tTl res = [0,0];\n\tforeach_reverse (u; t[ad]) {\n\t\tauto r = calc(ad+1, u-'0');\n\t\tres[0] += r[0]*powMod(10, res[1], MD) % MD;\n\t\tres[1] += r[1];\n\t\tres[0] %= MD;\n\t\tres[1] %= MD-1;\n\t}\n\tdp[ad][c] = res;\n\treturn res;\n}\n\nlong solve() {\n\tauto s = readln().strip();\n\treadf(\"%d\\n\", &n); n++;\n\td = new int[n]; t = new string[n];\n\td[0] = 0; t[0] = s;\n\tforeach (i; 1..n) {\n//\t\treadf(\"%d\", &d[i]);\n\t\treadf(\"%d->%s\\n\", &d[i], &t[i]);\n\t}\n\n\tdp = new Tl[][](n, 10);\n\tused = new bool[][](n, 10);\n\treturn calc(0, 0)[0]%MD;\n}\n\nint main() {\n writeln(solve());\n return 0;\n}", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable long MO = 1000000007;\nimmutable L = 10;\n\nstring S;\nint N;\nstring[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tS = readToken;\n\t\tN = readInt;\n\t\tA = new string[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readToken;\n\t\t}\n\t\t\n\t\tlong[][] vals = new long[][](N + 1, L);\n\t\tlong[][] muls = new long[][](N + 1, L);\n\t\tforeach (x; 0 .. L) {\n\t\t\tvals[N][x] = x;\n\t\t\tmuls[N][x] = L;\n\t\t}\n\t\t\n\t\tforeach_reverse (i; 0 .. N) {\n\t\t\tforeach (x; 0 .. L) {\n\t\t\t\tif (x == A[i][0] - '0') {\n\t\t\t\t\tvals[i][x] = 0;\n\t\t\t\t\tmuls[i][x] = 1;\n\t\t\t\t\tforeach (c; A[i][3 .. $]) {\n\t\t\t\t\t\tconst int y = c - '0';\n\t\t\t\t\t\tvals[i][x] = (vals[i][x] * muls[i + 1][y] + vals[i + 1][y]) % MO;\n\t\t\t\t\t\tmuls[i][x] = (muls[i][x] * muls[i + 1][y]) % MO;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tvals[i][x] = vals[i + 1][x];\n\t\t\t\t\tmuls[i][x] = muls[i + 1][x];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong ans;\n\t\tforeach (c; S) {\n\t\t\tconst int y = c - '0';\n\t\t\tans = (ans * muls[0][y] + vals[0][y]) % MO;\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;\nimport std.algorithm, std.container, std.datetime, std.typecons;\n\nconst MD = 10^^9+7;\n\nalias Tl = Tuple!(long, long);\n\nlong powMod(long x, long n, long md) {\n long r = 1;\n while (n) {\n if (n & 1) r *= x; r %= md;\n x *= x; x %= md;\n n >>= 1;\n }\n return r;\n}\n\nvoid powModTable(long[] d, long b, long md) {\n\tassert(d.length > 0);\n\td[0] = 1;\n\tforeach (i; 1..d.length) {\n\t\td[i] = (d[i-1]*b)%md;\n\t}\n}\n//-------------------------------------------------------//\n\nint n;\nint[] d;\nstring[] t;\n\nTl[][] dp;\nbool[][] used;\nTl calc(int ad, int c) {\n\tif (ad == n) return Tl(c, 1);\n\tif (d[ad] != c) return calc(ad+1, c);\n\tif (used[ad][c]) return dp[ad][c];\n\tTl res = [0,0];\n\tforeach_reverse (u; t[ad]) {\n\t\tauto r = calc(ad+1, u-'0');\n\t\tres[0] += r[0]*powMod(10, res[1], MD);\n\t\tres[1] += r[1];\n\t}\n\tdp[ad][c] = res;\n\treturn res;\n}\n\nlong solve() {\n\tauto s = readln().strip();\n\treadf(\"%d\\n\", &n); n++;\n\td = new int[n]; t = new string[n];\n\td[0] = 0; t[0] = s;\n\tforeach (i; 1..n) {\n//\t\treadf(\"%d\", &d[i]);\n\t\treadf(\"%d->%s\\n\", &d[i], &t[i]);\n\t}\n\n\tdp = new Tl[][](n, 10);\n\tused = new bool[][](n, 10);\n\treturn calc(0, 0)[0]%MD;\n}\n\nint main() {\n writeln(solve());\n return 0;\n}"}, {"source_code": "import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;\nimport std.algorithm, std.container, std.datetime, std.typecons;\n\nconst MD = 10^^9+7;\n\nalias Tl = Tuple!(long, long);\n\nlong powMod(long x, long n, long md) {\n long r = 1;\n while (n) {\n if (n & 1) r *= x; r %= md;\n x *= x; x %= md;\n n >>= 1;\n }\n return r;\n}\n\n//-------------------------------------------------------//\n\nint n;\nint[] d;\nstring[] t;\n\nTl[][] dp;\nbool[][] used;\nTl calc(int ad, int c) {\n\tif (ad == n) return Tl(c, 1);\n\tif (d[ad] != c) return calc(ad+1, c);\n\tif (used[ad][c]) return dp[ad][c];\n\tused[ad][c] = true;\n\tTl res = [0,0];\n\tforeach_reverse (u; t[ad]) {\n\t\tauto r = calc(ad+1, u-'0');\n\t\tres[0] += r[0]*powMod(10, res[1], MD) % MD;\n\t\tres[1] += r[1];\n\t\tres[0] %= MD;\n\t\tres[1] %= MD;\n\t}\n\tdp[ad][c] = res;\n\treturn res;\n}\n\nlong solve() {\n\tauto s = readln().strip();\n\treadf(\"%d\\n\", &n); n++;\n\td = new int[n]; t = new string[n];\n\td[0] = 0; t[0] = s;\n\tforeach (i; 1..n) {\n//\t\treadf(\"%d\", &d[i]);\n\t\treadf(\"%d->%s\\n\", &d[i], &t[i]);\n\t}\n\n\tdp = new Tl[][](n, 10);\n\tused = new bool[][](n, 10);\n\treturn calc(0, 0)[0]%MD;\n}\n\nint main() {\n writeln(solve());\n return 0;\n}"}], "src_uid": "c315870f5798dfd75ddfc76c7e3f6fa5"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1516/problem/B\n//\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(to!int).array;\n a = 0 ~ a;\n\n int[] cum = new int[n + 1];\n for(int i = 1; i <= n; ++i) {\n cum[i] = cum[i - 1] ^ a[i];\n }\n\n bool found = !cum[n];\n for(int i = 1; i <= n; ++i) {\n for(int j = i + 1; j < n; ++j) {\n found |= (cum[i] == (cum[j]^cum[i]) &&\n cum[i] == (cum[n]^cum[j]));\n }\n }\n if(found)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tlong tot;\r\n\t\tforeach (i; 0..n)\r\n\t\t\ttot ^= a[i];\r\n\t\tif (tot == 0)\r\n\t\t{\r\n\t\t\tans[ti] = true;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tlong x, y;\r\n\t\t\tlong cx, cy;\r\n\t\t\tforeach (j; 0..i)\r\n\t\t\t{\r\n\t\t\t\tx ^= a[j];\r\n\t\t\t\tif (x == tot)\r\n\t\t\t\t{\r\n\t\t\t\t\t++cx;\r\n\t\t\t\t\tx = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tforeach (j; i..n)\r\n\t\t\t{\r\n\t\t\t\ty ^= a[j];\r\n\t\t\t\tif (y == tot)\r\n\t\t\t\t{\r\n\t\t\t\t\t++cy;\r\n\t\t\t\t\ty = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (x == 0 && y == 0 && (cx != 0 && cy != 0))\r\n\t\t\t{\r\n\t\t\t\tans[ti] = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.string;\r\nimport std.math, std.algorithm;\r\nimport std.numeric, std.bigint;\r\nimport std.container, std.array;\r\nimport std.typecons, std.range;\r\nimport std.conv, std.random;\r\n \r\nstring solve(int[] a)\r\n{\r\n auto n = to!int(a.length);\r\n int tmask;\r\n foreach (i; 0 .. n - 1)\r\n {\r\n tmask ^= a[i];\r\n int mask;\r\n bool matched, occured;\r\n foreach (j; i + 1 .. n)\r\n {\r\n mask ^= a[j];\r\n if (mask != tmask) matched = false;\r\n else mask = 0, matched = occured = true;\r\n }\r\n if (matched || occured && mask == 0) return \"YES\";\r\n }\r\n return \"NO\";\r\n}\r\n \r\nint main(string[] args)\r\n{\r\n auto t = to!int(readln.strip);\r\n foreach (_; 0 .. t)\r\n {\r\n readln;\r\n auto a = map!(to!int)(readln.strip.split(\" \")).array;\r\n auto ret = solve(a);\r\n writeln(ret);\r\n }\r\n return 0;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tlong tot;\r\n\t\tforeach (i; 0..n)\r\n\t\t\ttot ^= a[i];\r\n\t\tif (tot == 0)\r\n\t\t{\r\n\t\t\tans[ti] = true;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tlong x, y;\r\n\t\t\tforeach (j; 0..i)\r\n\t\t\t\tx ^= a[j];\r\n\t\t\tforeach (j; i..n)\r\n\t\t\t\ty ^= a[j];\r\n\t\t\tif (x == y)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tlong x, y;\r\n\t\t\tforeach (j; 0..i)\r\n\t\t\t\tx ^= a[j];\r\n\t\t\tforeach (j; i..n)\r\n\t\t\t\ty ^= a[j];\r\n\t\t\tif (x == y)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.string;\r\nimport std.math, std.algorithm;\r\nimport std.numeric, std.bigint;\r\nimport std.container, std.array;\r\nimport std.typecons, std.range;\r\nimport std.conv, std.random;\r\n \r\nstring solve(int[] a)\r\n{\r\n auto n = to!int(a.length);\r\n int tmask;\r\n foreach (i; 0 .. n - 1)\r\n {\r\n tmask ^= a[i];\r\n int mask;\r\n bool f;\r\n foreach (j; i + 1 .. n)\r\n {\r\n mask ^= a[j];\r\n if (mask != tmask) f = false;\r\n else mask = 0, f = true;\r\n }\r\n if (f) return \"YES\";\r\n }\r\n return \"NO\";\r\n}\r\n \r\nint main(string[] args)\r\n{\r\n auto t = to!int(readln.strip);\r\n foreach (_; 0 .. t)\r\n {\r\n readln;\r\n auto a = map!(to!int)(readln.strip.split(\" \")).array;\r\n auto ret = solve(a);\r\n writeln(ret);\r\n }\r\n return 0;\r\n}"}], "src_uid": "4004c77b77076bf450cbe751e025a71f"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int q1 = 987_654_319;\nimmutable int q2 = 987_654_299;\nimmutable int maxN = 1_000_007;\n\nvoid main ()\n{\n\tint p1 = uniform (123_456_789, 444_333_222) * 2 + 1;\n\tint p2 = uniform (123_456_789, 444_333_222) * 2 + 1;\n\tint [] p1pow = [1];\n\tp1pow.reserve (maxN + 1);\n\tint [] p2pow = [1];\n\tp2pow.reserve (maxN + 1);\n\tforeach (i; 0..maxN)\n\t{\n\t\tp1pow ~= (p1pow.back * 1L * p1) % q1;\n\t\tp2pow ~= (p2pow.back * 1L * p2) % q2;\n\t}\n\n\tint tests;\n\treadf !(\" %s\") (tests);\n\treadln;\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\n\t\tstring lo = \"\";\n\t\twhile (s.length >= 2 && s[0] == s[$ - 1])\n\t\t{\n\t\t\tlo ~= s[0];\n\t\t\ts = s[1..$ - 1];\n\t\t}\n\t\tstring hi = lo.retro.text;\n\n\t\tauto n = s.length.to !(int);\n\n\t\tvoid calc (ref int [] h1, ref int [] h2, const ref string r)\n\t\t{\n\t\t\th1[0] = 0;\n\t\t\th2[0] = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\th1[i + 1] = (h1[i] * 1L * p1 + r[i]) % q1;\n\t\t\t\th2[i + 1] = (h2[i] * 1L * p2 + r[i]) % q2;\n\t\t\t}\n\t\t}\n\n\t\tauto h1lo = new int [n + 1];\n\t\tauto h2lo = new int [n + 1];\n\t\tcalc (h1lo, h2lo, s);\n\n\t\tauto t = s.retro.text;\n\t\tauto h1hi = new int [n + 1];\n\t\tauto h2hi = new int [n + 1];\n\t\tcalc (h1hi, h2hi, t);\n\t\treverse (h1hi);\n\t\treverse (h2hi);\n\n\t\tint bestLo = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tif ((h1hi[0] - h1hi[i] * 1L * p1pow[i] -\n\t\t\t h1lo[i]) % q1 == 0 &&\n\t\t\t (h2hi[0] - h2hi[i] * 1L * p2pow[i] -\n\t\t\t h2lo[i]) % q2 == 0)\n\t\t\t{\n\t\t\t\tbestLo = i;\n\t\t\t}\n\t\t}\n\n\t\treverse (h1lo);\n\t\treverse (h2lo);\n\t\treverse (h1hi);\n\t\treverse (h2hi);\n\t\tswap (h1lo, h1hi);\n\t\tswap (h2lo, h2hi);\n\t\tint bestHi = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tif ((h1hi[0] - h1hi[i] * 1L * p1pow[i] -\n\t\t\t h1lo[i]) % q1 == 0 &&\n\t\t\t (h2hi[0] - h2hi[i] * 1L * p2pow[i] -\n\t\t\t h2lo[i]) % q2 == 0)\n\t\t\t{\n\t\t\t\tbestHi = i;\n\t\t\t}\n\t\t}\n\n\t\tif (bestLo > bestHi)\n\t\t{\n\t\t\tlo ~= s[0..bestLo];\n\t\t}\n\t\telse\n\t\t{\n\t\t\thi = s[$ - bestHi..$] ~ hi;\n\t\t}\n\t\twriteln (lo, hi);\n\t}\n}\n", "positive_code": [{"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport std.stdio, std.array, std.string, std.math, std.uni, std.format, std.bigint;\nimport std.algorithm, std.conv, std.container, std.range, std.functional;\nimport std.random, std.typecons;\n\n// FIXME\nint[] buildZ(in string s) {\n int n = cast(int)(s.length);\n int[] z; z.length = n;\n for (int i = 1, l = 0, r = 0; i < n; ++i) {\n if (i <= r) z[i] = (z[i - l] < r - i + 1 ? z[i - l] : r - i + 1);\n while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];\n if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;\n }\n return z;\n}\n\nvoid solve(in int testcase) {\n string s, t;\n s.read;\n int n = cast(int)(s.length), m;\n for (int i = 0; i < n; ++i)\n t ~= s[n - i - 1];\n if (s == t) {\n s.writeln;\n return ;\n }\n int[] z = buildZ(s ~ '$' ~ t);\n int x = z[n + 1];\n string ans1 = s[0 .. x];\n string ans2 = \"\";\n int mx = 0;\n string p = s[x .. n - x];\n string o;\n {\n n = cast(int)(p.length), m = n * 2 + 1;\n t = \"\";\n for (int i = 0; i < n; ++i)\n t ~= p[n - i - 1];\n o = p ~ '$' ~ t;\n z = buildZ(o);\n for (int i = m - 1; i >= 0; --i) {\n if (z[i] == m - i && mx < m - i) {\n mx = m - i;\n ans2 = o[i .. $];\n }\n }\n }\n p = t;\n {\n n = cast(int)(p.length), m = n * 2 + 1;\n t = \"\";\n for (int i = 0; i < n; ++i)\n t ~= p[n - i - 1];\n o = p ~ '$' ~ t;\n z = buildZ(o);\n for (int i = m - 1; i >= 0; --i) {\n if (z[i] == m - i && mx < m - i) {\n mx = m - i;\n ans2 = o[i .. $];\n }\n }\n }\n string ans3;\n for (int i = 0; i < x; ++i)\n ans3 ~= ans1[x - i - 1];\n (ans1 ~ ans2 ~ ans3).writeln;\n}\n\n// ************************************************************\n\nT reader(T)() { return readToken().to!T; }\nvoid read(T)(ref T t) { t = reader!T; }\nT[] readarray(T)() { return readln.splitter.map!(to!T).array; }\nvoid chmax(T)(ref T a, T b) { a = max(a, b); }\nvoid chmin(T)(ref T a, T b) { a = min(a, b); }\nalias less = (a, b) => a < b;\nalias greater = (a, b) => a > b;\nT min_element(T)(in T[] a) { return a.element!less; }\nT max_element(T)(in T[] a) { return a.element!greater; }\nalias unique = uniq;\n\n// constant or some variables\nimmutable int inf = 0x3f3f3f3f;\nimmutable long lnf = 0x3f3f3f3f3f3f3f3f;\nimmutable typeof(null) NULL = null;\nstring[] _tokens;\n\n// functions\nT element(alias pred, T)(in T[] a) {\n int pos = 0;\n for (int i = 1; i < cast(int)(a.length); ++i)\n if (binaryFun!pred(a[i], a[pos])) pos = i;\n return a[pos];\n}\nstring readToken() {\n for (; _tokens.empty; ) {\n if (stdin.eof) return \"\";\n _tokens = readln.split;\n }\n auto token = _tokens.front;\n _tokens.popFront;\n return token;\n}\nint binary_bearch(alias pred, T)(in T[] as) {\n int l = -1, h = cast(int)(as.length), mid;\n for (; l + 1 < h; ) {\n mid = (l + h) >> 1;\n (unaryFun!pred(as[mid]) ? h : l) = mid;\n }\n return h;\n}\nint lower_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => a == val || pred(val, a));\n}\nint upper_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => pred(val, a));\n}\n\nvoid main(string[] args) {\n int tests = 1;\n tests.read();\n foreach(test; 1 .. tests + 1) solve(test);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n A: foreach(_; 0 .. scan!int){\n string s = scan;\n int n = s.length.to!int;\n\n int a = 0, b = n - 1;\n while(a < b){\n log(\"a:\", a, \"b:\", b, \"s[a]:\", s[a], \"s[b]:\", s[b]);\n if(s[a] != s[b]) break;\n a ++, b --;\n }\n if(a >= b){\n s.writeln;\n continue A;\n }\n log(\"a:\", a, \"b:\", b);\n \n bool isPalin(int u, int v){ // s[u .. v] is palin.\n log(\"u:\", u, \"v:\", v, \"s[u..v]:\", s[u .. v]);\n int i = u, j = v - 1;\n while(i < j){\n if(s[i] != s[j]) return 0;\n i ++, j --;\n }\n return 1;\n }\n\n foreach_reverse(i; 0 .. b - a + 1){\n if(isPalin(a, a + i)){\n (s[0 .. a + i] ~ s[b + 1 .. $]).writeln;\n continue A;\n }\n if(isPalin(b - i + 1, b + 1)){\n (s[0 .. a] ~ s[b - i + 1 .. $]).writeln;\n continue A;\n }\n }\n }\n}\n\n\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nint[] manacher(T)(T a) {\n const n = cast(int)(a.length);\n auto r = new int[n * 2];\n for (int i = 0, j = 0, k; i < n * 2; i += k, j = max(j - k, 0)) {\n for (; 0 <= i - j && i + j + 1 < n * 2 && a[(i - j) / 2] == a[(i + j + 1) / 2]; ++j) {}\n r[i] = j;\n for (k = 1; 0 <= i - k && 0 <= j - k && r[i - k] != j - k; ++k) {\n r[i + k] = min(r[i - k], j - k);\n }\n }\n return r;\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const S = readToken();\n const L = cast(int)(S.length);\n \n const rads = manacher(S);\n debug {\n writeln(\"rads = \", rads);\n }\n \n auto ls = new int[L + 1];\n ls[] = -1;\n foreach (x; 0 .. L) {\n // x - rads[x] <= 2 k\n chmax(ls[(x - rads[x] + 1) / 2], x);\n }\n foreach (k; 1 .. L + 1) {\n chmax(ls[k], ls[k - 1]);\n }\n auto rs = new int[L + 1];\n rs[] = 2 * L;\n foreach (x; L - 1 .. 2 * L - 1) {\n // 2 (L - 1 - k) <= x + rads[x]\n chmin(rs[(2 * (L - 1) - x - rads[x] + 1) / 2], x);\n }\n foreach (k; 1 .. L + 1) {\n chmin(rs[k], rs[k - 1]);\n }\n debug {\n writeln(\"ls = \", ls);\n writeln(\"rs = \", rs);\n }\n \n int ansA, ansB;\n void check(int a, int b) {\n if (ansA + ansB < a + b) {\n ansA = a;\n ansB = b;\n }\n }\n foreach (k; 0 .. L + 1) {\n check(k, k);\n if (ls[k] != -1) {\n const i = k;\n const j = ls[k] - i;\n check(k + (j - i + 1), k);\n }\n if (rs[k] != 2 * L) {\n const i = L - 1 - k;\n const j = rs[k] - i;\n check(k, (i - j + 1) + k);\n }\n if ((k + 1) + (k + 1) > L) {\n break;\n }\n if (S[k] != S[L - 1 - k]) {\n break;\n }\n }\n writeln(S[0 .. ansA] ~ S[L - ansB .. L]);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "042008e186c5a7265fbe382b0bdfc9bc"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = cin.read_int;\n }\n int[] alice = new int[n];\n int[] bob = new int[n];\n\n alice[0] = arr[0];\n for (int i = 1; i < n; i++) {\n alice[i] = alice[i - 1] + arr[i];\n }\n \n reverse(arr);\n \n bob[0] = arr[0];\n for (int i = 1; i < n; i++) {\n bob[i] = bob[i - 1] + arr[i];\n }\n\n reverse(arr);\n\n int total_time = sum(arr[0..$]);\n bool[] eaten = new bool[n];\n\n int alice_a = 0;\n int bob_a = 0;\n int curr_a = 0;\n int curr_b = 0;\n\n for (int i = 0; i <= total_time; i++) {\n if (i == alice[curr_a] && eaten[curr_a] == false) {\n eaten[curr_a] = true;\n alice_a++;\n curr_a++;\n } \n if (i == bob[curr_b] && eaten[n - 1 - curr_b] == false) {\n eaten[n - 1 - curr_b] = true;\n bob_a++;\n curr_b++;\n }\n }\n writeln(alice_a, \" \", bob_a);\n } \n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.range;\nimport std.conv;\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n\n int n;\n readf(\" %s\\n\", &n);\n int[] bar = new int[n + 2];\n int[] cumbar = new int[n + 2];\n foreach (i ; 1 .. n + 1) {\n readf(\" %s\", &bar[i]);\n cumbar[i] = bar[i] + cumbar[i - 1];\n }\n int cumrev;\n int alice, bob;\n foreach_reverse (i ; 2 .. n + 2) {\n cumrev += bar[i];\n if (cumbar[i - 2] - cumrev <= bar[i - 1]) {\n if (cumrev < cumbar[i - 2]) alice = i - 2;\n else alice = i - 1; \n bob = n - alice;\n break;\n }\n }\n writeln(alice, \" \", bob);\n\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.array;\n\n\nvoid main(char[][] args)\n{\n version(MY_SUPER_PUPER_ONLINE_JUDGE)\n {\n stdin.open(\"src/input.txt\", \"rt\"); \n stdout.open(\"src/output.txt\",\"wt\");\n }\n int n;\n readf(\"%d\\n\", &n);\n int[] a = new int[n], sum = new int[n + 1];\n sum[0] = 0;\n for(int i = 0; i < n; ++i)\n {\n readf(\"%d \", &a[i]);\n }\n int sum1 = 0, sum2 = 0, x = 0, y = n - 1;\n while(y >= x)\n {\n if(sum1 < sum2)\n {\n sum1 += a[x];\n x++;\n }\n else\n if(sum1 > sum2)\n {\n sum2 += a[y];\n y--;\n }\n else\n {\n sum1 += a[x];\n x++;\n if(y >= x) \n {\n sum2 += a[y];\n y--;\n }\n }\n }\n write(x, \" \", n - y - 1);\n}\n"}], "negative_code": [], "src_uid": "8f0172f742b058f5905c0a02d79000dc"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tauto n = readln.strip.to!int;\n\tstring [] [string] d, e;\n\tforeach (i; 0..n)\n\t{\n\t\tauto t = readln.strip.split ('/');\n\t\td[t[2]] ~= t[3..$].map !(x => \"/\" ~ x).join;\n\t}\n\tforeach (k, v; d)\n\t\te[v.sort ().uniq.join (' ')] ~= k;\n\tauto r = e.byValue.filter !(x => x.length > 1);\n\twritefln (\"%s\\n%(%-(http://%s %)\\n%)\", r.walkLength, r);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tstring [] [string] d;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto s = readln.strip;\n\t\t\tauto t = s.split ('/');\n\t\t\td[t[2]] ~= t.drop (3).map !(x => \"/\" ~ x).join ();\n\t\t}\n\n\t\tstring [] [string] e;\n\t\tforeach (k, v; d)\n\t\t{\n\t\t\te[v.sort ().uniq ().join (' ')] ~= k;\n\t\t}\n\t\twriteln (e.byKeyValue.count !(x => x.value.length > 1));\n\t\tforeach (k, v; e)\n\t\t{\n\t\t\tif (v.length > 1)\n\t\t\t{\n\t\t\t\tv.map !(x => \"http://\" ~ x).join (' ').writeln;\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "9b35f7df9e21162858a8fac8ee2837a4"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto s = readln.chomp;\n \n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n if (abs(x) + abs(y) > n || (abs(x) + abs(y)) % 2 != n % 2) {\n writeln(-1);\n return;\n }\n \n auto p = new int[][] (n+1, 2);\n p[] = [0, 0];\n foreach (i, e; s) {\n int xstep = 0, ystep = 0;\n if (e == 'U') { ystep = 1; }\n if (e == 'R') { xstep = 1; }\n if (e == 'D') { ystep = -1; }\n if (e == 'L') { xstep = -1; }\n \n p[i+1] = [p[i][0] + xstep, p[i][1] + ystep];\n }\n \n int chk(ref string s, int x, int y) {\n if (abs(x) + abs(y) > s.length) { return -1; }\n \n bool reachable(int m) {\n int cx = p[m][0], cy = p[m][1];\n int len = s.length.to!int - m;\n return abs(x - cx) + abs(y - cy) <= len;\n }\n \n int le = 0, r = s.length.to!int;\n while (le < r) {\n int m = (le + r) / 2 + 1;\n if (reachable(m)) { le = m; }\n else { r = m-1; }\n }\n \n return s.length.to!int - r;\n }\n \n auto ans = chk(s, x, y);\n while (! s.empty()) {\n auto e = s.back;\n s.popBack();\n \n if (e == 'U') { y -= 1; }\n if (e == 'R') { x -= 1; }\n if (e == 'D') { y += 1; }\n if (e == 'L') { x += 1; }\n \n auto cur = chk(s, x, y);\n \n if (cur == -1) { continue; }\n if (cur < ans) { ans = cur; }\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto s = readln.split.map!(to!long);\n auto X = s[0];\n auto Y = s[1];\n\n bool check(int len, long x, long y) {\n return (len >= abs(x) + abs(y)) && (len % 2 == (abs(x) + abs(y)) % 2);\n }\n\n if (!check(N, X, Y)) {\n writeln(-1);\n return;\n }\n\n auto A = new long[](N+1);\n auto B = new long[](N+1);\n\n foreach (i; 0..N) {\n A[i+1] = A[i];\n B[i+1] = B[i];\n if (S[i] == 'R') A[i+1] += 1;\n else if (S[i] == 'L') A[i+1] -= 1;\n else if (S[i] == 'U') B[i+1] += 1;\n else if (S[i] == 'D') B[i+1] -= 1;\n }\n\n if (A[N] == X && B[N] == Y) {\n writeln(0);\n return;\n }\n\n int hi = N;\n int lo = -1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n bool ok = false;\n foreach (l; 0..N-mid+1) {\n int r = l + mid - 1;\n long x1 = A[r+1] - A[l];\n long y1 = B[r+1] - B[l];\n long x2 = A[N] - x1;\n long y2 = B[N] - y1;\n long x = X - x2;\n long y = Y - y2;\n if (check(mid, x, y)) {\n ok = true;\n break;\n }\n }\n (ok ? hi : lo) = mid;\n }\n\n hi.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto s = readln.split.map!(to!long);\n auto X = s[0];\n auto Y = s[1];\n\n bool check(int len, long x, long y) {\n return (len >= abs(x) + abs(y)) && (len % 2 == (abs(x) + abs(y)) % 2);\n }\n\n if (check(0, X, Y)) {\n writeln(0);\n return;\n }\n\n if (!check(N, X, Y)) {\n writeln(-1);\n return;\n }\n\n auto A = new long[](N+1);\n auto B = new long[](N+1);\n\n foreach (i; 0..N) {\n A[i+1] = A[i];\n B[i+1] = B[i];\n if (S[i] == 'R') A[i+1] += 1;\n else if (S[i] == 'L') A[i+1] -= 1;\n else if (S[i] == 'U') B[i+1] += 1;\n else if (S[i] == 'D') B[i+1] -= 1;\n }\n\n int hi = N;\n int lo = -1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n bool ok = false;\n foreach (l; 0..N-mid+1) {\n int r = l + mid - 1;\n long x1 = A[r+1] - A[l];\n long y1 = B[r+1] - B[l];\n long x2 = A[N] - x1;\n long y2 = B[N] - y1;\n long x = X - x2;\n long y = Y - y2;\n if (check(mid, x, y)) {\n ok = true;\n break;\n }\n }\n (ok ? hi : lo) = mid;\n }\n\n hi.writeln;\n}\n"}], "src_uid": "44cf7e01a72d7d8182b05678a7e5b5d3"} {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main(string[ ] args) {\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n\r\n while (t--) {\r\n readln;\r\n\r\n int n, k;\r\n readf!\"%s %s\"(n, k);\r\n readln;\r\n\r\n auto f = readln.chomp.split.map!(to!int).array;\r\n\r\n auto g = new int[][] (n+1);\r\n foreach (i; 0 .. n-1) {\r\n int x, y;\r\n readf!\"%s %s\"(x, y);\r\n readln;\r\n\r\n g[x] ~= y;\r\n g[y] ~= x;\r\n }\r\n\r\n auto pos = new bool[n+1];\r\n pos[] = true;\r\n f.each!(v => pos[v] = false);\r\n\r\n alias r = Tuple!(bool, \"good\", int, \"enemyDepth\");\r\n\r\n immutable int INF = 10 ^^ 6;\r\n\r\n r dfs(int v, int fr, int d) {\r\n if (!pos[v]) {\r\n return r(false, d);\r\n }\r\n\r\n if (d != 0 && g[v].length == 1) {\r\n return r(true, INF);\r\n }\r\n\r\n int minEnemyDepth = INF;\r\n bool pathExists = false;\r\n foreach (u; g[v]) {\r\n if (u == fr) { continue; }\r\n\r\n auto res = dfs(u, v, d + 1);\r\n pathExists |= res.good;\r\n minEnemyDepth = min(minEnemyDepth, res.enemyDepth);\r\n }\r\n\r\n auto enemyStepsToReach = minEnemyDepth - d;\r\n\r\n return r(pathExists && enemyStepsToReach > d, minEnemyDepth);\r\n }\r\n\r\n auto ans = dfs(1, 0, 0);\r\n\r\n writeln(ans.good ? \"YES\" : \"NO\");\r\n }\r\n}", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nstruct node { int vlad_dist = -1, friend_dist = -1; };\nalias PairII = Tuple!(int, int);\n\nvoid dfs(int s, int[][] adj, node[] a, int dist)\n{\n a[s].vlad_dist = dist;\n foreach (d ; adj[s]) {\n if (a[d].vlad_dist != -1)\n continue;\n dfs(d, adj, a, dist + 1);\n }\n}\n\nvoid bfs(int[] friends, int[][] adj, node[] a)\n{\n auto queue = new DList!PairII;\n foreach (friend ; friends) {\n a[friend].friend_dist = 0;\n queue.insertBack(tuple(friend, 0));\n }\n while (!queue.empty) {\n auto x = queue.front;\n queue.removeFront;\n int s = x[0];\n int dist = x[1];\n foreach (d ; adj[s]) {\n if (a[d].friend_dist != -1)\n continue;\n a[d].friend_dist = dist + 1;\n queue.insertBack(tuple(d, dist + 1));\n }\n }\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n, k;\n readf!\" %d %d \"(n, k);\n auto friends = readln.splitter.map!(x => x.to!int - 1).array;\n node[] a = new node[](n);\n int[][] adj = new int[][](n);\n foreach (i ; 0 .. n - 1) {\n int v, u;\n readf!\" %d %d \"(v, u);\n v--;\n u--;\n adj[v] ~= u;\n adj[u] ~= v;\n }\n dfs(0, adj, a, 0);\n bfs(friends, adj, a);\n bool vlad_wins = false;\n foreach (i ; 1 .. n) {\n if (adj[i].length != 1)\n continue;\n if (a[i].vlad_dist < a[i].friend_dist) {\n vlad_wins = true;\n break;\n }\n }\n writeln(vlad_wins ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\r\n\t\tauto x = readln.splitter.map !(to !(int)).array;\r\n\t\tx[] -= 1;\r\n\t\tauto b = new bool [n];\r\n\t\tforeach (ref c; x)\r\n\t\t{\r\n\t\t\tb[c] = true;\r\n\t\t}\r\n\r\n\t\tauto g = new int [] [n];\r\n\t\tforeach (j; 0..n - 1)\r\n\t\t{\r\n\t\t\tint u, v;\r\n\t\t\treadf !(\" %s %s\") (u, v);\r\n\t\t\tu -= 1;\r\n\t\t\tv -= 1;\r\n\t\t\tg[u] ~= v;\r\n\t\t\tg[v] ~= u;\r\n\t\t}\r\n\r\n\t\tauto depth = new int [n];\r\n\r\n\t\tvoid recurDepth (int v, int p, int cur)\r\n\t\t{\r\n\t\t\tdepth[v] = cur;\r\n\t\t\tforeach (u; g[v])\r\n\t\t\t{\r\n\t\t\t\tif (u == p)\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\trecurDepth (u, v, cur + 1);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecurDepth (0, -1, 0);\r\n\r\n\t\tauto friend = new int [n];\r\n\r\n\t\tvoid recurFriend (int v, int p)\r\n\t\t{\r\n\t\t\tint res = n;\r\n\t\t\tif (b[v])\r\n\t\t\t{\r\n\t\t\t\tres = 0;\r\n\t\t\t}\r\n\t\t\tforeach (u; g[v])\r\n\t\t\t{\r\n\t\t\t\tif (u == p)\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\trecurFriend (u, v);\r\n\t\t\t\tres = min (res, friend[u] + 1);\r\n\t\t\t}\r\n\t\t\tfriend[v] = res;\r\n\t\t}\r\n\r\n\t\trecurFriend (0, -1);\r\n\r\n\t\tbool recurVisit (int v, int p)\r\n\t\t{\r\n\t\t\tif (friend[v] <= depth[v])\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\tif (v != 0 && g[v].length == 1)\r\n\t\t\t{\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\tforeach (u; g[v])\r\n\t\t\t{\r\n\t\t\t\tif (u == p)\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tif (recurVisit (u, v))\r\n\t\t\t\t{\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tauto res = recurVisit (0, -1);\r\n\r\n\t\twriteln (res ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nenum int INF = 1<<29;\r\n\r\nvoid solve() {\r\n readln;\r\n int N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto X = readarray!int;\r\n foreach (ref x; X) x--;\r\n auto G = new int[][N];\r\n foreach (i; 0 .. N - 1) {\r\n int U, V; readf(\"%d %d\\n\", &U, &V);\r\n U--; V--;\r\n G[U] ~= V;\r\n G[V] ~= U;\r\n }\r\n\r\n void bfs(in int[] ss, ref int[] d) {\r\n d[] = INF;\r\n DList!int Q;\r\n foreach (s; ss) {\r\n Q.insert(s);\r\n d[s] = 0;\r\n }\r\n while (! Q.empty) {\r\n auto c = Q.front; Q.removeFront;\r\n foreach (next; G[c]) {\r\n if (d[next] <= d[c] + 1) continue;\r\n d[next] = d[c] + 1;\r\n Q.insert(next);\r\n }\r\n }\r\n }\r\n int[] fromR = new int[N];\r\n int[] fromF = new int[N];\r\n bfs([0], fromR);\r\n bfs(X, fromF);\r\n bool f() {\r\n foreach (v; 1 .. N) {\r\n if (G[v].length != 1) continue;\r\n if (fromR[v] < fromF[v]) return true;\r\n }\r\n return false;\r\n }\r\n writeln(f() ? \"YES\" : \"NO\");\r\n}\r\n"}], "negative_code": [], "src_uid": "bf89bc12320f635cc121eba99c542444"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto l = RD!int;\n\t\tauto r = RD!int;\n\n\t\tif (l*2 > r)\n\t\t\tans[ti] = [-1, -1];\n\t\telse\n\t\t\tans[ti] = [l, l*2];\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0], \" \", e[1]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint a, b;\n\t\treadf !(\" %s %s\") (a, b);\n\t\tif (a * 2 <= b)\n\t\t{\n\t\t\twriteln (a, \" \", a * 2);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1, \" \", -1);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "e8ba3fb95800806465386ecbfbe924e9"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1426/problem/B\n// greedy\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\n int n, m;\n int a, b, c, d;\n while(t--) {\n readf(\"%s %s\\n\", &n, &m);\n bool found = false;\n for(int i = 0; i < n; ++i) {\n readf(\"%s %s\\n%s %s\\n\", &a, &b, &c, &d);\n if(b == c)\n found = true;\n }\n if(m%2 == 1)\n found = false;\n if(found)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n }\n}\n\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nvoid play(){\n int n, m;\n n = rd!int;\n m = rd!int;\n bool sym = 0, sym2 = 0;\n ll a, b, c, d;\n foreach(i; 0..n){\n a = rd;\n b = rd;\n c = rd;\n d = rd;\n if(b == c){ sym = 1; }\n }\n if(sym && m % 2 == 0){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\n }\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nvoid play(){\n int n, m;\n n = rd!int;\n m = rd!int;\n bool sym = 0, sym2 = 0;\n ll a, b, c, d;\n foreach(i; 0..n){\n a = rd;\n b = rd;\n c = rd;\n d = rd;\n if(b == c){ sym = 1; }\n if(a == d && b == c){ sym2 = 1; }\n }\n if(sym && m % 2 == 0){\n if(m == 2 && !sym2){\n writeln(\"NO\");\n }else{\n writeln(\"YES\");\n }\n }else{\n writeln(\"NO\");\n }\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nvoid play(){\n int n, m;\n n = rd!int;\n m = rd!int;\n bool sym = 0, sym2 = 0;\n ll a, b, c, d;\n foreach(i; 0..n){\n a = rd;\n b = rd;\n c = rd;\n d = rd;\n if(a == d){ sym = 1; }\n if(a == d && b == c){ sym2 = 1; }\n }\n if(sym && m % 2 == 0){\n if(m == 2 && !sym2){\n writeln(\"NO\");\n }else{\n writeln(\"YES\");\n }\n }else{\n writeln(\"NO\");\n }\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}], "src_uid": "f46f6fa28d0a7023da3bad0d222ce393"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a.stride (2));\r\n\t\tsort (a.drop (1).stride (2));\r\n\t\twriteln (a.isSorted ? \"YES\" : \"NO\");\r\n\t}\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tlong[][long] cnt;\r\n\t\tforeach (e; a)\r\n\t\t\tcnt[e] = [0, 0];\r\n\r\n\t\tauto index = a.MAKE_IDX;\r\n\t\tforeach (ii, i; index)\r\n\t\t{\r\n\t\t\tauto j = ii % 2;\r\n\t\t\t++cnt[a[i]][j];\r\n\t\t}\r\n\r\n\t\tans[ti] = true;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto j = i % 2;\r\n\t\t\tif (cnt[a[i]][j] == 0)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\t--cnt[a[i]][j];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\nimport std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n while(tests--) {\r\n immutable(int) Maxn = 10 ^^ 5 + 5;\r\n int n; readf!\"%s\\n\"(n);\r\n auto a = readln.splitter.map!(to!int).array;\r\n auto b = a.dup.sort;\r\n int[Maxn][2] c;\r\n foreach(i; 0 .. n) {\r\n c[i % 2][b[i]]++;\r\n }\r\n bool ok = true;\r\n foreach(i; 0 .. n) {\r\n if (c[i % 2][a[i]] == 0) {\r\n ok = false;\r\n break;\r\n }\r\n c[i % 2][a[i]]--;\r\n }\r\n writefln!\"%s\"(ok ? \"YES\" : \"NO\");\r\n }\r\n\r\n} // main\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n, i, j, k;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n auto b = zip(a, iota(0, n)).array.sort!((x, y) => x[0] < y[0]).array;\n bool good = true;\n i = 0;\n while (i < n) {\n j = i;\n while (j < n && b[i][0] == b[j][0])\n j++;\n int[2] tmp = [0, 0];\n for (k = i; k < j; k++) {\n tmp[k % 2] += abs(b[k][1] - k) % 2;\n }\n if (tmp[0] != tmp[1]) {\n good = false;\n break;\n }\n i = j;\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a.stride (2));\r\n\t\tsort (a.drop (1).stride (2));\r\n\t\twriteln (a.isSorted ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n, i, j, k;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n auto b = zip(a, iota(0, n)).array.sort!((x, y) => x[0] < y[0]).array;\n bool good = true;\n i = 0;\n while (i < n) {\n if (abs(b[i][1] - i) % 2 != 0) {\n if (i + 1 < n && b[i][0] == b[i + 1][0] && abs(b[i + 1][1] - (i + 1)) % 2 != 0) {\n // L L pattern (we can change it to R R)\n swap(b[i], b[i + 1]);\n continue;\n } else if (i + 2 < n && b[i][0] == b[i + 2][0] && abs(b[i + 2][1] - (i + 2)) % 2 == 0) {\n // L R R pattern (we can change it to L L L)\n swap(b[i + 1], b[i + 2]);\n continue;\n } else {\n good = false;\n break;\n }\n }\n i++;\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n, i, j, k;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n auto b = zip(a, iota(0, n)).array.sort!((x, y) => x[0] < y[0]).array;\n bool good = true;\n i = 0;\n while (i < n) {\n if (abs(b[i][1] - i) % 2 != 0) {\n if (i + 1 < n && b[i][0] == b[i + 1][0] && abs(b[i + 1][1] - (i + 1)) % 2 != 0)\n i++;\n else\n good = false;\n }\n i++;\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n, i, j, k;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n auto b = zip(a, iota(0, n)).array.sort!((x, y) => x[0] < y[0]).array;\n bool good = true;\n i = 0;\n while (i < n) {\n if (abs(b[i][1] - i) % 2 != 0) {\n if (i + 1 < n && b[i][0] == b[i + 1][0] && abs(b[i + 1][1] - (i + i)) % 2 != 0)\n i++;\n else\n good = false;\n }\n i++;\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n, i, j, k;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n auto b = zip(a, iota(0, n)).array.sort!((x, y) => x[0] < y[0]).array;\n bool good = true;\n i = 0;\n while (i < n) {\n j = i;\n while (j < n && b[i][0] == b[j][0])\n j++;\n int tmp = 0;\n for (k = i; k < j; k++) {\n tmp += abs(b[k][1] - k) % 2;\n }\n if (tmp % 2 != 0) {\n good = false;\n break;\n }\n i = j;\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}], "src_uid": "1d27d6d736d891b03b7476f8a7209291"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable long infinity = long.max / 4;\n\nvoid main ()\n{\n\tint n;\n\tlong r1, r2, r3, d;\n\twhile (readf !(\" %s %s %s %s %s\") (n, r1, r2, r3, d) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tauto b = a.map !(x => r1 * x + r3).array;\n\t\tdebug {writeln (b);}\n\t\tauto c = a.map !(x => min (r1 * (x + 1), r2) + r1).array;\n\t\tdebug {writeln (c);}\n\t\tauto e = new long [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\te[i] = min (b[i], c[i]);\n\t\t}\n\t\tdebug {writeln (e);}\n\n\t\tauto f = [0L];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto cur = f[i] + b[i] + d;\n\t\t\tif (i > 0)\n\t\t\t{\n\t\t\t\tcur = min (cur, f[i - 1] +\n\t\t\t\t e[i - 1] + e[i] + d * 4);\n\t\t\t}\n\t\t\tif (i > 1)\n\t\t\t{\n\t\t\t\tcur = min (cur, f[i - 2] +\n\t\t\t\t e[i - 2] + e[i - 1] + e[i] + d * 7);\n\t\t\t}\n\t\t\tf ~= cur;\n\t\t}\n\t\tdebug {writeln (f);}\n\n\t\tlong res = min (f[n] - d,\n\t\t f[n - 2] + e[n - 2] + b[n - 1] + d * 2);\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\tint n;\n\tlong r1, r2, r3, d;\n\twhile (readf !(\" %s %s %s %s %s\") (n, r1, r2, r3, d) > 0) {\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tauto b = a.map !(x => r1 * x + r3).array;\n\t\tauto c = a.map !(x => min (r1 * (x + 1), r2) + r1).array;\n\t\tauto e = n.iota.map !(i => min (b[i], c[i])).array;\n\t\tauto f = [0L];\n\t\tforeach (i; 0..n) {\n\t\t\tauto cur = f[i] + b[i] + d;\n\t\t\tif (i > 0) cur = min (cur, f[i - 1] + e[i - 1] + e[i] + d * 4);\n\t\t\tif (i > 1) cur = min (cur, f[i - 2] + e[i - 2] + e[i - 1] + e[i] + d * 7);\n\t\t\tf ~= cur;\n\t\t}\n\t\twriteln (min (f[n] - d, f[n - 2] + e[n - 2] + b[n - 1] + d * 2));\n\t}\n}\n"}], "negative_code": [], "src_uid": "b532deda90a4edc6e97b207cb05d3843"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\ta = 0 ~ a ~ 0;\n\t\tauto p = readln.split.map !(to !(int)).array;\n\n\t\tauto r = new int [n + 2];\n\t\tr[] = -1;\n\t\tauto w = new long [n + 2];\n\n\t\tlong [] ans;\n\t\tlong cur = 0;\n\n\t\tint root (int v)\n\t\t{\n\t\t\tif (r[v] != -1 && r[v] != v)\n\t\t\t{\n\t\t\t\tr[v] = root (r[v]);\n\t\t\t}\n\t\t\treturn r[v];\n\t\t}\n\n\t\tvoid unite (int q)\n\t\t{\n\t\t\tlong temp = a[q];\n\t\t\tr[q] = q;\n\t\t\tint u = root (q - 1);\n\t\t\tif (u != -1)\n\t\t\t{\n\t\t\t\tr[u] = q;\n\t\t\t\ttemp += w[u];\n\t\t\t}\n\t\t\tint v = root (q + 1);\n\t\t\tif (v != -1)\n\t\t\t{\n\t\t\t\tr[v] = q;\n\t\t\t\ttemp += w[v];\n\t\t\t}\n\t\t\tw[q] = temp;\n\t\t\tcur = max (cur, temp);\n\t\t}\n\n\t\tforeach_reverse (q; p)\n\t\t{\n\t\t\tans ~= cur;\n\t\t\tunite (q);\n\t\t}\n\t\twritefln (\"%(%s\\n%)\", ans.retro);\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdio;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\n//import std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n return readf(' ' ~ replicate(\"%s \", vars.length), getAddrTuple(vars).expand) == vars.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Node {\n private {\n mixin(bitfields!(\n uint, `index`, 31,\n bool, `delayed`, 1,\n ));\n }\n int size = 1;\n Splay left, right, parent;\n\n invariant {\n foreach (child; AliasSeq!(left, right))\n if (child !is null)\n assert(child.parent is &this);\n assert(size == left.size + right.size + 1);\n }\n\n void assign(int id) {\n index = id;\n delayed = true;\n }\n\n static void split(Splay t, ref Splay l, ref Splay r, int x)\n in {\n assert(x <= t.size);\n }\n out {\n assert(l.size == x);\n }\n body {\n if (x == t.size) {\n l = t;\n r = null;\n } else {\n r = t.splayByKey(x);\n l = r.left;\n l.unlink();\n }\n }\n\n static Splay merge(/+return+/ Splay l, /+return+/ Splay r)\n in {\n if (l !is null) {\n assert(l.parent is null);\n assert(l !is r);\n }\n if (r !is null)\n assert(r.parent is null);\n }\n out (result) {\n assert(result.parent is null);\n }\n body {\n if (l is null)\n return r;\n if (r is null)\n return l;\n auto t = r.splayLeft();\n l.link(L, t);\n return t;\n }\n\n Splay splayLeft() return\n out (result) {\n assert(result.parent is null);\n assert(result.left is null);\n }\n body {\n push();\n if (left !is null)\n return left.splayLeft();\n splay();\n return Splay(&this);\n }\n\n Splay splayByKey(int x) return\n in {\n assert(x < size);\n }\n out (result) {\n assert(result.left.size == x);\n assert(result.parent is null);\n }\n body {\n return _splayByKey(x);\n }\n\n private Splay _splayByKey(int x) return\n in {\n assert(x < size);\n }\n body {\n push();\n if (x == left.size) {\n splay();\n return Splay(&this);\n } else if (x < left.size)\n return left._splayByKey(x);\n else\n return right._splayByKey(x - left.size - 1);\n }\n\n void splay()\n out {\n assert(parent is null);\n }\n body {\n while (true) {\n auto parent = parent;\n if (parent is null)\n return;\n if (parent.parent is null) {\n rotate();\n return;\n }\n if (side == parent.side)\n parent.rotate();\n else\n rotate();\n rotate();\n }\n }\n\n void rotate()\n in {\n assert(parent !is null);\n }\n body {\n auto parent = parent;\n auto gparent = parent.parent;\n auto side = side;\n auto parentSide = gparent ? parent.side : 0;\n unlink();\n parent.unlink();\n if (side == L) {\n if (auto right = right) {\n right.unlink();\n right.link(L, parent);\n }\n parent.link(R, Splay(&this));\n } else {\n if (auto left = left) {\n left.unlink();\n left.link(R, parent);\n }\n parent.link(L, Splay(&this));\n }\n link(parentSide, gparent);\n }\n\nprivate:\n void push()\n out {\n assert(!delayed);\n }\n body {\n if (!delayed)\n return;\n foreach (child; AliasSeq!(left, right))\n if (child !is null)\n child.assign(index);\n delayed = false;\n }\n\n void recalc() {\n size = left.size + right.size + 1;\n }\n\n enum { L, R }\n\n @property bool side() const\n in {\n assert(parent !is null);\n }\n body {\n return &this is parent.left ? L : R;\n }\n\n void link(int c, Splay newParent)\n in {\n assert(parent is null);\n if (newParent !is null)\n assert((c == L ? newParent.left : newParent.right) is null);\n }\n out {\n assert(parent is newParent);\n }\n body {\n if (newParent is null)\n return;\n parent = newParent;\n if (c == L)\n parent.left = &this;\n else\n parent.right = &this;\n parent.recalc();\n }\n\n void unlink()\n out {\n assert(parent is null);\n }\n body {\n if (parent is null)\n return;\n if (side == L)\n parent.left = null;\n else\n parent.right = null;\n parent.recalc();\n parent = null;\n }\n}\n\nstruct Splay {\n Node* _node;\n\n alias _node this;\n\n @property int size() const { return _node ? _node.size : 0; }\n\n static Splay build(int n) {\n Splay t;\n foreach (ref node; _nodes[0 .. n])\n t = Node.merge(t, Splay(&node));\n return t;\n }\n\n int getIndex(int i) {\n this = splayByKey(i);\n return index;\n }\n\n void update(int i, int j, int value) {\n Splay prefix, suffix;\n Node.split(this, this, suffix, j);\n Node.split(this, prefix, this, i);\n if (_node !is null)\n assign(value);\n this = Node.merge(Node.merge(prefix, this), suffix);\n }\n}\n\nalias Interval = Tuple!(int, `left`, int, `right`);\n\nint[10^^5] _arr;\nlong[10^^5 + 1] psum;\nInterval[10^^5 + 1] intervals;\nNode[10^^5] _nodes;\n\nlong getSum(int i, int j) {\n return psum[j] - psum[i];\n}\n\nvoid main() {\n int n;\n while (scanf(\"%d\", &n) == 1) {\n auto arr = _arr[0 .. n];\n version (LocalProject)\n _nodes[ ] = Node.init;\n //psum[0] = 0;\n foreach (i, ref x; arr) {\n scanf(\"%d\", &x);\n psum[i + 1] = psum[i] + x;\n }\n int intervalCount = 1;\n intervals[0] = Interval(0, n);\n auto intervalSums = redBlackTree!true(psum[n]);\n auto t = Splay.build(n);\n foreach (i; 0 .. n) {\n int x;\n scanf(\"%d\", &x);\n x--;\n\n const id = t.getIndex(x);\n intervalSums.removeKey(getSum(intervals[id].left, intervals[id].right));\n intervals[intervalCount] = Interval(x + 1, intervals[id].right);\n intervals[id].right = x;\n intervalSums.insert(getSum(intervals[id].left, x));\n intervalSums.insert(getSum(x + 1, intervals[intervalCount].right));\n t.update(x + 1, intervals[intervalCount].right, intervalCount);\n intervalCount++;\n\n printf(\"%lld\\n\", intervalSums.back);\n }\n debug putchar('\\n');\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdio;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\n//import std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n return readf(' ' ~ replicate(\"%s \", vars.length), getAddrTuple(vars).expand) == vars.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Node {\n private {\n mixin(bitfields!(\n uint, `index`, 31,\n bool, `delayed`, 1,\n ));\n }\n int size = 1;\n Splay left, right, parent;\n\n invariant {\n foreach (child; AliasSeq!(left, right))\n if (child !is null)\n assert(child.parent is &this);\n assert(size == left.size + right.size + 1);\n }\n\n void assign(int id) {\n index = id;\n delayed = true;\n }\n\n static void split(Splay t, ref Splay l, ref Splay r, int x)\n in {\n assert(x <= t.size);\n }\n out {\n assert(l.size == x);\n }\n body {\n if (x == t.size) {\n l = t;\n r = null;\n } else {\n r = t.splayByKey(x);\n l = r.left;\n l.unlink();\n }\n }\n\n static Splay merge(/+return+/ Splay l, /+return+/ Splay r)\n in {\n if (l !is null) {\n assert(l.parent is null);\n assert(l !is r);\n }\n if (r !is null)\n assert(r.parent is null);\n }\n out (result) {\n assert(result.parent is null);\n }\n body {\n if (l is null)\n return r;\n if (r is null)\n return l;\n auto t = r.splayLeft();\n l.link(L, t);\n return t;\n }\n\n Splay splayLeft() return\n out (result) {\n assert(result.parent is null);\n assert(result.left is null);\n }\n body {\n push();\n if (left !is null)\n return left.splayLeft();\n splay();\n return Splay(&this);\n }\n\n Splay splayByKey(int x) return\n in {\n assert(x < size);\n }\n out (result) {\n assert(result.left.size == x);\n assert(result.parent is null);\n }\n body {\n return _splayByKey(x);\n }\n\n private Splay _splayByKey(int x) return\n in {\n assert(x < size);\n }\n body {\n push();\n if (x == left.size) {\n splay();\n return Splay(&this);\n } else if (x < left.size)\n return left._splayByKey(x);\n else\n return right._splayByKey(x - left.size - 1);\n }\n\n void splay()\n out {\n assert(parent is null);\n }\n body {\n while (true) {\n auto parent = parent;\n if (parent is null)\n return;\n if (parent.parent is null) {\n rotate();\n return;\n }\n if (side == parent.side)\n parent.rotate();\n else\n rotate();\n rotate();\n }\n }\n\n void rotate()\n in {\n assert(parent !is null);\n }\n body {\n auto parent = parent;\n auto gparent = parent.parent;\n auto side = side;\n auto parentSide = gparent ? parent.side : 0;\n unlink();\n parent.unlink();\n if (side == L) {\n if (auto right = right) {\n right.unlink();\n right.link(L, parent);\n }\n parent.link(R, Splay(&this));\n } else {\n if (auto left = left) {\n left.unlink();\n left.link(R, parent);\n }\n parent.link(L, Splay(&this));\n }\n link(parentSide, gparent);\n }\n\nprivate:\n void push()\n out {\n assert(!delayed);\n }\n body {\n if (!delayed)\n return;\n foreach (child; AliasSeq!(left, right))\n if (child !is null)\n child.assign(index);\n delayed = false;\n }\n\n void recalc() {\n size = left.size + right.size + 1;\n }\n\n enum { L, R }\n\n @property bool side() const\n in {\n assert(parent !is null);\n }\n body {\n return &this is parent.left ? L : R;\n }\n\n void link(int c, Splay newParent)\n in {\n assert(parent is null);\n if (newParent !is null)\n assert((c == L ? newParent.left : newParent.right) is null);\n }\n out {\n assert(parent is newParent);\n }\n body {\n if (newParent is null)\n return;\n parent = newParent;\n if (c == L)\n parent.left = &this;\n else\n parent.right = &this;\n parent.recalc();\n }\n\n void unlink()\n out {\n assert(parent is null);\n }\n body {\n if (parent is null)\n return;\n if (side == L)\n parent.left = null;\n else\n parent.right = null;\n parent.recalc();\n parent = null;\n }\n}\n\nstruct Splay {\n Node* _node;\n\n alias _node this;\n\n @property int size() const { return _node ? _node.size : 0; }\n\n static Splay build(int n) {\n Splay t;\n foreach (ref node; _nodes[0 .. n])\n t = Node.merge(t, Splay(&node));\n return t;\n }\n\n int getIndex(int i) {\n this = splayByKey(i);\n return index;\n }\n\n void update(int i, int j, int value) {\n Splay prefix, suffix;\n Node.split(this, this, suffix, j);\n Node.split(this, prefix, this, i);\n if (_node !is null)\n assign(value);\n this = Node.merge(Node.merge(prefix, this), suffix);\n }\n}\n\nalias Interval = Tuple!(int, `left`, int, `right`);\n\nint[10^^5] _arr;\nlong[10^^5 + 1] psum;\nInterval[10^^5 + 1] intervals;\nNode[10^^5] _nodes;\n\nlong getSum(int i, int j) {\n return psum[j] - psum[i];\n}\n\nvoid main() {\n int n;\n while (scanf(\"%d\", &n) == 1) {\n auto arr = _arr[0 .. n];\n version (LocalProject)\n _nodes[ ] = Node.init;\n //psum[0] = 0;\n foreach (i, ref x; arr) {\n scanf(\"%d\", &x);\n psum[i + 1] = psum[i] + x;\n }\n int intervalCount = 1;\n intervals[0] = Interval(0, n);\n auto intervalSums = redBlackTree!true(psum[n]);\n auto t = Splay.build(n);\n foreach (i; 0 .. n) {\n int x;\n scanf(\"%d\", &x);\n x--;\n int id = t.getIndex(x);\n intervalSums.removeKey(getSum(intervals[id].left, intervals[id].right));\n intervals[intervalCount] = Interval(x + 1, intervals[id].right);\n intervals[id].right = x;\n intervalSums.insert(getSum(intervals[id].left, x));\n intervalSums.insert(getSum(x + 1, intervals[intervalCount].right));\n t.update(x + 1, intervals[intervalCount].right, intervalCount);\n intervalCount++;\n printf(\"%d\\n\", intervalSums.back);\n }\n debug putchar('\\n');\n }\n}\n"}], "src_uid": "0553ab01447ab88bee70d07c433f0654"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main ()\n{\n\treadln;\n\tint m = readln.strip.to!int;\n\tauto c = (readln ~ readln).split.map !(\"1 - 1 / a.to!real\").fold !\"a * b\" (1.0);\n\twritefln (\"%.10f\", c ? m / c - m : -1); \n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nint main ()\n{\n\tint n, m, i;\n\tdouble c = 1.0, x;\n\tscanf (\"%d%d\", &n, &m);\n\tfor (i = 0; i < n * 2; i++)\n\t{\n\t\tscanf (\"%lf\", &x);\n\t\tc *= 1 - 1 / x;\n\t}\n\tprintf (\"%.10lf\", c > 0 ? m / c - m : -1);\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.stdio;\n\nvoid main ()\n{\n\tint n, m;\n\treadf (\" %s %s \", n, m);\n\tauto c = (readln ~ readln)\n\t .splitter\n\t .map !(to!double)\n\t .map !(x => 1 - 1 / x)\n\t .fold !\"a * b\";\n\twritefln (\"%.10f\", c > 0 ? m / c - m : -1);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\n\t\tif (chain (a, b).any !(q{a == 1}))\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlong res = 0;\n\t\treal lo = 0;\n\t\treal hi = 1E10;\n\t\tforeach (step; 0..200)\n\t\t{\n\t\t\treal me = (lo + hi) * 0.5;\n\t\t\treal cur = m + me;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tcur *= 1.0L - 1.0L / a[i];\n\t\t\t\tcur *= 1.0L - 1.0L / b[i];\n\t\t\t}\n\t\t\tif (cur >= m)\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo = me;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%.10f\", lo);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.stdio;\n\nvoid main ()\n{\n\tint n, m;\n\treadf !\" %s %s \" (n, m);\n\tauto c = (readln ~ readln)\n\t .splitter\n\t .map !(to!double)\n\t .map !(x => 1 - 1 / x)\n\t .fold !\"a * b\";\n\twritefln !\"%.10f\" (c > 0 ? m / c - m : -1);\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s\", &n);\n readln;\n readf(\"%s\", &m);\n readln;\n \n auto r = () => readln.chomp.split.map!(to!int).array;\n auto a = r();\n auto b = r();\n \n int[] arr;\n foreach (e1, e2; lockstep(a, b)) {\n arr ~= e1;\n arr ~= e2;\n }\n \n double ans = 0, curm = m;\n foreach_reverse (e; arr) {\n if (e == 1) {\n writeln(-1);\n return;\n }\n \n debug { writeln(e, ' ', curm); }\n \n double curf = curm / (e - 1);\n ans += curf;\n curm += curf;\n }\n \n ans.writefln!(\"%.10f\");\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto M = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array;\n\n bool ok(real fuel) {\n foreach (i; 0..N-1) {\n real x = (M + fuel) / A[i];\n fuel -= x;\n if (fuel < 0) return false;\n x = (M + fuel) / B[i+1];\n fuel -= x;\n if (fuel < 0) return false;\n }\n real x = (M + fuel) / A[N-1];\n fuel -= x;\n if (fuel < 0) return false;\n x = (M + fuel) / B[0];\n fuel -= x;\n if (fuel < 0) return false;\n return true;\n }\n\n real hi = 10L^^10;\n real lo = 0;\n\n foreach (_; 0..100) {\n real mid = (hi + lo) / 2;\n (ok(mid) ? hi : lo) = mid;\n }\n\n if (hi > 10^^9+100)\n writeln(-1);\n else\n writefln(\"%.9f\", hi);\n}\n"}, {"source_code": "import std.stdio, std.range, std.string, std.algorithm, std.conv;\n\nvoid main() {\n int n; double m;\n readf(\"%d\\n%f\\n\", &n, &m);\n double[] a = readln.strip.split.map!(to!double).array;\n double[] b = readln.strip.split.map!(to!double).array; \n bool check(double fuel) {\n foreach (p; zip(a, b)) {\n double now_a = p[0], now_b = p[1];\n fuel -= (m + fuel) / now_a;\n if (fuel < 0) return false;\n fuel -= (m + fuel) / now_b;\n if (fuel < 0) return false;\n }\n return true;\n }\n if (!check(1e10)) {\n writeln(-1);\n return;\n }\n double min_x = 0, max_x = 1e9;\n foreach (phase; 0..200) {\n double mid = (min_x + max_x) / 2;\n if (!check(mid)) min_x = mid;\n else max_x = mid;\n }\n writefln(\"%.20f\", max_x);\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\treadln;\n\tint m = readln.split[0].to!int;\n\tauto c = (readln ~ readln).split.map !(\"1 - 1 / a.to!real\").fold!\"a * b\";\n\twritef (\"%.9f\", c ? m / c - m : -1); \n}\n"}, {"source_code": "import std.stdio;\n\nint main ()\n{\n\tint n, m, i;\n\tdouble c = 1.0, x;\n\tscanf (\"%d%d\", &n, &m);\n\tfor (i = 0; i < n * 2; i++)\n\t{\n\t\tscanf (\"%lf\", &x);\n\t\tc *= 1 - 1 / x;\n\t}\n\tprintf (\"%.10lf\\n\", c > 0 ? m / c - m : -1);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\n\nint main ()\n{\n\tint n, m, i;\n\tdouble c = 1.0, x;\n\tscanf (\"%d%d\", &n, &m);\n\tfor (i = 0; i < n * 2; i++)\n\t{\n\t\tscanf (\"%lf\", &x);\n\t\tc *= 1 - 1 / x;\n\t}\n\tprintf (\"%.10f\\n\", c > 0 ? m / c - m : -1);\n\treturn 0;\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main ()\n{\n\treadln;\n\tint m = readln.strip.to!int;\n\tauto c = (readln ~ readln).split.map !(\"1 - 1 / a.to!real\").fold !\"a * b\" (1.0);\n\twriteln (c ? m / c - m : -1); \n}\n"}], "src_uid": "d9bd63e03bf51ed87ba73cd15e8ce58d"} {"source_code": "import std.string, std.stdio, std.conv, std.algorithm, std.range, std.array;\n\nvoid main()\n{\n auto nm = readln.split.map!(to!int);\n auto n = nm[0], m = nm[1];\n auto flag = m.iota.map!(_ => readln.chomp).array;\n auto hasSameColorInRow = flag.map!(a=>a.all!(b=>b==a[0])).all!\"a==true\";\n auto hasAdjacentColorInColumn = n.iota.array.map!(i=>flag.transversal(i).chunkBy!\"a==b\".all!(a=>a.array.length==1)).fold!\"a&&b\"(true);\n writeln(!(hasSameColorInRow && hasAdjacentColorInColumn)?\"NO\":\"YES\");\n}", "positive_code": [{"source_code": "import std.string, std.stdio, std.conv, std.algorithm, std.range, std.array;\n\nvoid main()\n{\n auto nm = readln.split.map!(to!int);\n auto n = nm[0], m = nm[1];\n auto flag = m.iota.map!(_ => readln.chomp).array;\n auto hasSameColorInRow = flag.map!(a=>a.all!(b=>b==a[0])).all!\"a==true\";\n auto hasAdjacentColorInColumn = true;\n foreach(i; 0..n)\n hasAdjacentColorInColumn = hasAdjacentColorInColumn && flag.transversal(i).array.chunkBy!\"a==b\".all!(a=>a.array.length==1);\n writeln(!(hasSameColorInRow && hasAdjacentColorInColumn)?\"NO\":\"YES\");\n}"}], "negative_code": [], "src_uid": "80d3da5aba371f4d572ea928025c5bbd"} {"source_code": "import std;\r\nvoid main () {\r\n\tint n = readln.strip.to!int, r = n - (n % 3 != 1), c = 1;\r\n\tauto a = [[r, c]];\r\n\tforeach (i; 0..n) {\r\n\t\tr -= 1 + (i & 1);\r\n\t\tc += 1 + !(i & 1);\r\n\t\tif (r < 1 || c > n) break;\r\n\t\ta ~= [r, c];\r\n\t}\r\n\twritefln!\"%s\\n%(%(%s %)\\n%)\" (a.length, a);\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\tint [2] [] answer;\r\n\t\tint row = n - (n % 3 != 1);\r\n\t\tint col = 1;\r\n\t\tanswer ~= [row, col];\r\n\t\tforeach (step; 0..n)\r\n\t\t{\r\n\t\t\trow -= 1 + (step & 1);\r\n\t\t\tcol += 1 + !(step & 1);\r\n\t\t\tif (row < 1 || col > n)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tanswer ~= [row, col];\r\n\t\t}\r\n\t\twriteln (answer.length);\r\n\t\tforeach (ref line; answer)\r\n\t\t{\r\n\t\t\twritefln !(\"%(%s %)\") (line);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nbool experiment(int N, int M) {\n bool found;\n void check(int[] zs) {\n auto a = new char[][](N, N);\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n a[x][y] = '?';\n }\n foreach (z; zs) {\n const x = z / N, y = z % N;\n foreach (xx; 0 .. N) foreach (yy; 0 .. N) {\n if (x == xx || y == yy || x - y == xx - yy) {\n a[xx][yy] = '.';\n }\n }\n }\n foreach (z; zs) {\n const x = z / N, y = z % N;\n a[x][y] = '#';\n }\n bool ok = true;\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n ok = ok && (a[x][y] != '?');\n }\n if (ok) {\n found = true;\n foreach (x; 0 .. N) {\n writeln(a[x]);\n }\n writeln;\n stdout.flush;\n }\n }\n void dfs(int[] zs) {\n if (zs.length == M) {\n check(zs);\n } else {\n foreach (z; (zs.empty ? 0 : (zs[$ - 1] + 1)) .. N^^2) {\n dfs(zs ~ z);\n }\n }\n }\n dfs([]);\n return found;\n}\n\nalias Pt = Tuple!(int, \"x\", int, \"y\");\n\nPt[] solve(int N) {\n Pt[] ans;\n const a = (N - 1) / 3;\n foreach (i; 0 .. a + 1) {\n ans ~= Pt(i, a - i);\n }\n foreach (i; 0 .. a) {\n ans ~= Pt(N - 1 - i, N - 1 - (a - 1 - i));\n }\n if (N % 3 == 0) {\n ans ~= Pt(N - 1 - a, N - 1 - a);\n }\n return ans;\n}\n\nvoid judge(int N, const(Pt[]) P) {\n foreach (p; P) {\n assert(0 <= p.x); assert(p.x < N);\n assert(0 <= p.y); assert(p.y < N);\n }\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n bool ok;\n foreach (p; P) {\n ok = ok || (x == p.x || y == p.y || x - y == p.x - p.y);\n }\n assert(ok);\n }\n}\n\nvoid main() {\n /*\n debug {\n foreach (n; 1 .. 9 + 1) {\n for (int m = 1; ; ++m) {\n const res = experiment(n, m);\n if (res) {\n stderr.writeln(n, \": \", m);\n stderr.flush;\n break;\n }\n }\n }\n return;\n }\n //*/\n \n debug {\n foreach (n; 1 .. 20 + 1) {\n const ans = solve(n);\n // writeln(n, \": \", ans.length, \" \", ans);\n writeln(n, \": \", ans.length);\n judge(n, ans);\n }\n }\n \n try {\n for (; ; ) {\n const N = readInt;\n \n auto ans = solve(N);\n writeln(ans.length);\n foreach (p; ans) {\n writeln(p.x + 1, \" \", p.y + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "e40774a2c34251eec2df869611731a48"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\tint[][] arr;\n\tint begin;\n\tforeach (i; 1..n)\n\t{\n\t\tif (a[i] <= a[i-1])\n\t\t{\n\t\t\tarr ~= [begin, i];\n\t\t\tbegin = i;\n\t\t}\n\t}\n\tarr ~= [begin, n];\n\n\tif (arr.length == 1)\n\t\twriteln(n);\n\telse\n\t{\n\t\tint ans = arr[0][1] - arr[0][0];\n\t\tforeach (i; 1..arr.length)\n\t\t{\n\t\t\tauto len1 = arr[i-1][1] - arr[i-1][0];\n\t\t\tauto len2 = arr[i][1] - arr[i][0];\n\t\t\tans.chmax(len2);\n\t\t\tif (len1 != 1 && len2 != 1)\n\t\t\t{\n\t\t\t\t{\n\t\t\t\t\tauto r = arr[i-1][1]-2;\n\t\t\t\t\tauto l = arr[i][0];\n\t\t\t\t\tif (a[r] < a[l])\n\t\t\t\t\t\tans.chmax(len2 + len1 - 1);\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tauto r = arr[i-1][1]-1;\n\t\t\t\t\tauto l = arr[i][0]+1;\n\t\t\t\t\tif (a[r] < a[l])\n\t\t\t\t\t\tans.chmax(len2 + len1 - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln(ans);\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.array, std.conv;\nimport std.algorithm;\n\nint solve(int[] a)\n{\n auto n = to!int(a.length);\n auto fdp = new int[n];\n auto bdp = new int[n];\n auto res = 0;\n foreach_reverse (i; 0 .. n)\n {\n fdp[i] = 1;\n if (i < n - 1 && a[i] < a[i + 1]) fdp[i] = fdp[i + 1] + 1;\n res = max(res, fdp[i]);\n }\n foreach (i; 0 .. n)\n {\n bdp[i] = 1;\n if (i > 0 && a[i - 1] < a[i]) bdp[i] = bdp[i - 1] + 1;\n }\n foreach (i; 1 .. n - 1)\n {\n if (a[i - 1] < a[i + 1]) res = max(res, bdp[i - 1] + fdp[i + 1]);\n }\n return res;\n}\n\nint main(string[] args)\n{\n readln;\n auto a = map!(x => to!int(x))(readln.strip.split(\" \")).array;\n auto ret = solve(a);\n writeln(ret);\n return 0;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tlong[] as = rlong(n);\n\n\tint[] xs = new int[](n);\n\tint[] ys = new int[](n); // xs[i]: best using i without skip; ys[i]: best using i and skipped one before\n\tforeach(i; 0 .. n){\n\t\txs[i] = 1, ys[i] = 0;\n\t\tif(i > 0 && as[i - 1] < as[i]) xs[i].chmax(xs[i - 1] + 1);\n\t\tif(i > 0 && as[i - 1] < as[i]) ys[i].chmax(ys[i - 1] + 1);\n\t\tif(i > 1 && as[i - 2] < as[i]) ys[i].chmax(xs[i - 2] + 1);\n\t}\n\tlong ans;\n\tforeach(x; xs) ans.chmax(x);\n\tforeach(y; ys) ans.chmax(y);\n\tans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\nvoid main()\n{\n int n; get(n);\n auto a = new int[n]; get(a);\n int[2][] ps;\n int i = 0;\n int res = 0;\n for(; i < n;)\n {\n int si = i, fi = i;\n while(fi + 1 < n && a[fi + 1] > a[fi])\n\t{\n\t fi++;\n\t}\n ps ~= [si, fi];\n res = max(res, fi - si + 1);\n i = fi + 1;\n }\n for(int j = 1; j < ps.length; j++)\n {\n auto curr = ps[j];\n auto prev = ps[j - 1];\n int comb = 0;\n if (prev[0] < prev[1])\n\t{\n\t if(a[prev[1] - 1] < a[curr[0]])\n\t {\n\t comb = max(comb, curr[1] - curr[0] + 1 + prev[1] - prev[0]);\n\t }\n\t}\n if (curr[0] < curr[1])\n\t{\n\t if(a[prev[1]] < a[curr[0] + 1])\n\t {\n\t comb = max(comb, curr[1] - curr[0] + prev[1] - prev[0] + 1);\n\t }\n\t}\n res = max(res, comb);\n }\n ans(res);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nimmutable int INF = 1 << 29;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n auto dp = new int[][][](N, 2, 2);\n foreach (i; 0..N) foreach (j; 0..2) foreach (k; 0..2) dp[i][j][k] = j + k == 0 ? 1 : 0;\n dp[0][0][0] = 1;\n dp[0][1][1] = 0;\n\n foreach (i; 1..N) {\n if (A[i] > A[i-1]) {\n dp[i][0][0] = max(dp[i][0][0], dp[i-1][0][0] + 1);\n dp[i][1][0] = max(dp[i][1][0], dp[i-1][1][0] + 1);\n }\n if (i > 1 && A[i] > A[i-2]) {\n dp[i][1][0] = max(dp[i][1][0], dp[i-1][1][1] + 1);\n }\n dp[i][1][1] = max(dp[i][1][1], dp[i-1][0][0]);\n }\n\n int ans = 0;\n foreach (i; 0..N) foreach (j; 0..2) foreach (k; 0..2) ans = max(ans, dp[i][j][k]);\n ans.writeln;\n}\n\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\tint l1, l2, ans = 1;\n\tint last;\n\tforeach (i; 1..n)\n\t{\n\t\tif (a[i] <= last)\n\t\t{\n\t\t\tauto len = i - l1 - 1;\n\t\t\tans.chmax(len);\n\t\t\tl1 = l2;\n\t\t\tl2 = i;\n\t\t\tif (i < 2)\n\t\t\t\tlast = a[i];\n\t\t\telse if (a[i] > a[i-2])\n\t\t\t\tlast = a[i];\n\t\t\telse\n\t\t\t\tlast = a[i-1];\n\t\t}\n\t\telse\n\t\t\tlast = a[i];\n\t}\n\tans.chmax(n - l1 - 1);\n\tans.chmax(n - l2);\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\t/*while (true)\n\t{\n\tauto n = uniform(5, 10);\n\tauto a = new int[](n);\n\tforeach (i; 0..n)\n\t{\n\t\ta[i] = uniform(1, 10);\n\t}\n\twriteln(n);\n\twriteln(a);*/\n\tlong ans = 1;\n\tauto dp = new int[][][](n+1, 2, 2);\n\tforeach (i; 0..n)\n\t{\n\t\tif (a[i] <= dp[i][1][0])\n\t\t{\n\t\t\tans.chmax(dp[i][1][1]);\n\t\t\tdp[i+1][0] = [a[i], 1];\n\t\t}\n\t\telse\n\t\t\tdp[i+1][1] = [a[i], dp[i][1][1]+1];\n\n\t\tif (a[i] <= dp[i][0][0])\n\t\t{\n\t\t\tif (dp[i][0][1] > dp[i+1][1][1])\n\t\t\t\tdp[i+1][1] = [a[i], dp[i][0][1]];\n\t\t}\n\t\telse\n\t\t\tdp[i+1][0] = [a[i], dp[i][0][1]+1];\n\t}\n\tans.chmax(dp[n][0][1]);\n\tans.chmax(dp[n][1][1]);\n\t\n\twriteln(ans);\n\tstdout.flush;\n\t//readln;\n\t//}\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\tint l1, l2, ans = 1;\n\tforeach (i; 1..n)\n\t{\n\t\tif (a[i] <= a[i-1])\n\t\t{\n\t\t\tauto len = i - l1 - 1;\n\t\t\tans.chmax(len);\n\t\t\tl1 = l2;\n\t\t\tl2 = i;\n\t\t}\n\t}\n\tans.chmax(n - l1 - 1);\n\tans.chmax(n - l2);\n\t\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\tint l1, l2, ans;\n\tforeach (i; 1..n)\n\t{\n\t\tif (a[i] <= a[i-1])\n\t\t{\n\t\t\tauto len = i - l1 - 1;\n\t\t\tans.chmax(len);\n\t\t\tl1 = l2;\n\t\t\tl2 = i;\n\t\t}\n\t}\n\tans.chmax(n - l1 - 1);\n\tans.chmax(n - l2);\n\t\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "87b8dccfc0e5a63cd209c37cf8aebef0"} {"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport std.stdio, std.array, std.string, std.math, std.uni, std.format, std.bigint;\nimport std.algorithm, std.conv, std.container, std.range, std.functional;\nimport std.random, std.typecons;\n\nimmutable Maxn = 500005;\n\nint n, k, m;\nmodint ans;\nint[Maxn] l, r, x, prf, mx;\nmodint[Maxn] dp, pre;\n\nvoid solve(in int testcase) {\n n.read, k.read, m.read;\n foreach(i; 0 .. m) {\n l[i].read, r[i].read, x[i].read;\n }\n ans = 1;\n foreach(b; 0 .. k) {\n debug{writefln!\"b = %s\"(b);}\n prf[] = 0;\n mx[] = 0;\n foreach(i; 0 .. m) {\n int cur = (x[i] >> b) & 1;\n if (cur == 1) {\n prf[l[i]]++;\n prf[r[i] + 1]--;\n }\n else {\n mx[r[i]] = max(mx[r[i]], l[i]);\n }\n }\n foreach(i; 1 .. n + 1) {\n mx[i] = max(mx[i], mx[i - 1]);\n prf[i] += prf[i - 1];\n }\n dp[] = modint(0L);\n dp[0] = 1;\n pre[0] = 1;\n debug{writefln!\"i = %s, dp = %s, pre = %s\"(0, dp[0].to!int, pre[0].to!int);}\n foreach(i; 1 .. n + 2) {\n debug{writefln!\"i = %s\"(i);}\n if (prf[i] > 0) {\n dp[i] = 0;\n pre[i] = pre[i - 1];\n continue;\n }\n debug{writefln!\"mx[%s] = %s\"(i - 1, mx[i - 1]);}\n dp[i] = pre[i - 1];\n if (mx[i - 1] != 0) {\n dp[i] -= pre[mx[i - 1] - 1];\n }\n pre[i] = pre[i - 1] + dp[i];\n debug{writefln!\"dp = %s, pre = %s\"(dp[i].to!int, pre[i].to!int);}\n }\n debug{writefln!\"ans = %s\"(dp[n + 1].to!int);}\n ans *= dp[n + 1];\n }\n ans.to!int.writeln;\n}\n\n// ************************************************************\n\nT reader(T)() { return readToken().to!T; }\nvoid read(T)(ref T t) { t = reader!T; }\nT[] readarray(T)() { return readln.splitter.map!(to!T).array; }\nvoid chmax(T)(ref T a, T b) { a = max(a, b); }\nvoid chmin(T)(ref T a, T b) { a = min(a, b); }\nalias less = (a, b) => a < b;\nalias greater = (a, b) => a > b;\nT min_element(T)(in T[] a) { return a.element!less; }\nT max_element(T)(in T[] a) { return a.element!greater; }\nalias unique = uniq;\n\n// constant or some variables\nimmutable int inf = 0x3f3f3f3f;\nimmutable long lnf = 0x3f3f3f3f3f3f3f3f;\nimmutable typeof(null) NULL = null;\nstring[] _tokens;\n\n// functions\nT element(alias pred, T)(in T[] a) {\n int pos = 0;\n for (int i = 1; i < cast(int)(a.length); ++i)\n if (binaryFun!pred(a[i], a[pos])) pos = i;\n return a[pos];\n}\nstring readToken() {\n for (; _tokens.empty; ) {\n if (stdin.eof) return \"\";\n _tokens = readln.split;\n }\n auto token = _tokens.front;\n _tokens.popFront;\n return token;\n}\nint binary_bearch(alias pred, T)(in T[] as) {\n int l = -1, h = cast(int)(as.length), mid;\n for (; l + 1 < h; ) {\n mid = (l + h) >> 1;\n (unaryFun!pred(as[mid]) ? h : l) = mid;\n }\n return h;\n}\nint lower_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => a == val || pred(val, a));\n}\nint upper_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => pred(val, a));\n}\nint countbit(T)(T x) {\n int res = 0;\n while (x) {\n res++;\n x &= x - 1;\n }\n return res;\n}\n\nvoid main(string[] args) {\n int tests = 1;\n// tests.read();\n foreach(test; 1 .. tests + 1) solve(test);\n}\n\nstruct modular_int(uint M_) {\n alias M = M_;\n uint x;\n modular_int inv() const {\n uint a = M, b = x;\n long u = 0, v = 1;\n while (b) {\n uint t = a / b;\n a -= t * b; swap(a, b);\n u -= t * v; swap(u, v);\n }\n if (u < 0) u += M;\n return modular_int(u);\n }\n this(modular_int a) { x = a.x; }\n this(long a) { a %= M; if (a < 0) a += M; x = cast(int)a; }\n ref modular_int opAssign(long a) { return (this = modular_int(a)); }\n ref modular_int opOpAssign(string op)(modular_int a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x & (1U << 31)) x += M; }\n else static if (op == \"*\") { x = cast(uint)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref modular_int opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n modular_int t2 = this, te = modular_int(1);\n if (a < 0) a = -a, t2 = t2.inv();\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = te.x;\n return this;\n }\n else return mixin(\"this \" ~ op ~ \"= modular_int(a)\");\n }\n modular_int opUnary(string op)() const if (op == \"-\") {\n return modular_int(M - x);\n }\n modular_int opBinary(string op, T)(T a) const {\n return mixin(\"modular_int(this) \" ~ op ~ \"= a\");\n }\n modular_int opBinaryRight(string op)(long a) const {\n return mixin(\"modular_int(a) \" ~ op ~ \"= this\");\n }\n T to(T)() const {\n return x.to!T;\n }\n}\nalias modint = modular_int!998244353;\n", "positive_code": [{"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport std.stdio, std.array, std.string, std.math, std.uni, std.format, std.bigint;\nimport std.algorithm, std.conv, std.container, std.range, std.functional;\nimport std.random, std.typecons;\n\nimmutable Maxn = 500005;\n\nint n, k, m;\nmodint ans;\nint[Maxn] l, r, x, prf, mx;\nmodint[Maxn] dp, pre;\n\nvoid solve(in int testcase) {\n n.read, k.read, m.read;\n foreach(i; 0 .. m) {\n l[i].read, r[i].read, x[i].read;\n }\n ans = 1;\n foreach(b; 0 .. k) {\n prf[] = 0;\n mx[] = 0;\n foreach(i; 0 .. m) {\n int cur = (x[i] >> b) & 1;\n if (cur == 1) {\n prf[l[i]]++;\n prf[r[i] + 1]--;\n }\n else {\n mx[r[i]] = max(mx[r[i]], l[i]);\n }\n }\n foreach(i; 1 .. n + 1) {\n mx[i] = max(mx[i], mx[i - 1]);\n prf[i] += prf[i - 1];\n }\n dp[] = modint(0L);\n dp[0] = 1;\n pre[0] = 1;\n foreach(i; 1 .. n + 2) {\n if (prf[i] > 0) {\n dp[i] = 0;\n pre[i] = pre[i - 1];\n continue;\n }\n dp[i] = pre[i - 1];\n if (mx[i - 1] != 0) {\n dp[i] -= pre[mx[i - 1] - 1];\n }\n pre[i] = pre[i - 1] + dp[i];\n }\n ans *= dp[n + 1];\n }\n ans.to!int.writeln;\n}\n\n// ************************************************************\n\nT reader(T)() { return readToken().to!T; }\nvoid read(T)(ref T t) { t = reader!T; }\nT[] readarray(T)() { return readln.splitter.map!(to!T).array; }\nvoid chmax(T)(ref T a, T b) { a = max(a, b); }\nvoid chmin(T)(ref T a, T b) { a = min(a, b); }\nalias less = (a, b) => a < b;\nalias greater = (a, b) => a > b;\nT min_element(T)(in T[] a) { return a.element!less; }\nT max_element(T)(in T[] a) { return a.element!greater; }\nalias unique = uniq;\n\n// constant or some variables\nimmutable int inf = 0x3f3f3f3f;\nimmutable long lnf = 0x3f3f3f3f3f3f3f3f;\nimmutable typeof(null) NULL = null;\nstring[] _tokens;\n\n// functions\nT element(alias pred, T)(in T[] a) {\n int pos = 0;\n for (int i = 1; i < cast(int)(a.length); ++i)\n if (binaryFun!pred(a[i], a[pos])) pos = i;\n return a[pos];\n}\nstring readToken() {\n for (; _tokens.empty; ) {\n if (stdin.eof) return \"\";\n _tokens = readln.split;\n }\n auto token = _tokens.front;\n _tokens.popFront;\n return token;\n}\nint binary_bearch(alias pred, T)(in T[] as) {\n int l = -1, h = cast(int)(as.length), mid;\n for (; l + 1 < h; ) {\n mid = (l + h) >> 1;\n (unaryFun!pred(as[mid]) ? h : l) = mid;\n }\n return h;\n}\nint lower_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => a == val || pred(val, a));\n}\nint upper_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => pred(val, a));\n}\nint countbit(T)(T x) {\n int res = 0;\n while (x) {\n res++;\n x &= x - 1;\n }\n return res;\n}\n\nvoid main(string[] args) {\n int tests = 1;\n// tests.read();\n foreach(test; 1 .. tests + 1) solve(test);\n}\n\nstruct modular_int(uint M_) {\n alias M = M_;\n uint x;\n modular_int inv() const {\n uint a = M, b = x;\n long u = 0, v = 1;\n while (b) {\n uint t = a / b;\n a -= t * b; swap(a, b);\n u -= t * v; swap(u, v);\n }\n if (u < 0) u += M;\n return modular_int(u);\n }\n this(modular_int a) { x = a.x; }\n this(long a) { a %= M; if (a < 0) a += M; x = cast(int)a; }\n ref modular_int opAssign(long a) { return (this = modular_int(a)); }\n ref modular_int opOpAssign(string op)(modular_int a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x & (1U << 31)) x += M; }\n else static if (op == \"*\") { x = cast(uint)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref modular_int opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n modular_int t2 = this, te = modular_int(1);\n if (a < 0) a = -a, t2 = t2.inv();\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = te.x;\n return this;\n }\n else return mixin(\"this \" ~ op ~ \"= modular_int(a)\");\n }\n modular_int opUnary(string op)() const if (op == \"-\") {\n return modular_int(M - x);\n }\n modular_int opBinary(string op, T)(T a) const {\n return mixin(\"modular_int(this) \" ~ op ~ \"= a\");\n }\n modular_int opBinaryRight(string op)(long a) const {\n return mixin(\"modular_int(a) \" ~ op ~ \"= this\");\n }\n T to(T)() const {\n return x.to!T;\n }\n}\nalias modint = modular_int!998244353;\n"}], "negative_code": [], "src_uid": "d3bc9c1889dbc4c8486804dc4b68a9b9"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nenum INF = 10^^9;\n\nint segN;\nTuple!(int, int)[] seg;\n\nvoid update(int a, int val) {\n seg[a += segN][0] += val;\n for (; a >>= 1; ) {\n seg[a] = min(seg[a << 1], seg[a << 1 | 1]);\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n auto G = new int[][N];\n foreach (i; 0 .. M) {\n G[A[i]] ~= B[i];\n G[B[i]] ~= A[i];\n }\n \n for (segN = 1; segN < N; segN <<= 1) {}\n seg.length = segN << 1;\n seg[] = tuple(INF, -1);\n foreach (u; 0 .. N) {\n seg[segN + u] = tuple(0, u);\n }\n foreach_reverse (a; 1 .. segN) {\n seg[a] = min(seg[a << 1], seg[a << 1 | 1]);\n }\n \n int ans;\n foreach (h; 0 .. N) {\n const u = seg[1][1];\n debug {\n writeln(\"u = \", u);\n }\n if (seg[1][0] == h) {\n debug {\n writeln(\" new comp\");\n }\n ++ans;\n }\n update(u, INF);\n foreach (v; G[u]) {\n update(v, 1);\n }\n }\n --ans;\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto adj = new bool [int] [n];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tadj[u][v] = true;\n\t\t\tadj[v][u] = true;\n\t\t}\n\n\t\tlong res = -1;\n\t\tauto p = n.iota.array;\n\t\tint [] q;\n\n\t\twhile (!p.empty)\n\t\t{\n\t\t\tif (q.empty)\n\t\t\t{\n\t\t\t\tint u = p[$ - 1];\n\t\t\t\tq ~= u;\n\t\t\t\tp.length -= 1;\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint v = q[0];\n\t\t\t\tq = q[1..$];\n\t\t\t\tq.assumeSafeAppend ();\n\n\t\t\t\tfor (int i = 0; i < p.length; i++)\n\t\t\t\t{\n\t\t\t\t\tint u = p[i];\n\t\t\t\t\tif (u !in adj[v])\n\t\t\t\t\t{\n\t\t\t\t\t\tq ~= u;\n\t\t\t\t\t\tswap (p[i], p[$ - 1]);\n\t\t\t\t\t\tp.length -= 1;\n\t\t\t\t\t\ti -= 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "852e1d776c560a8720d4e9f1762b255f"} {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutralV;\n\t\t_onComps!(c => value = f(value, _getNodeF(c)))(l, r);\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\t_onComps!(c => _addU(c, u))(l, r);\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\nvoid _onComps(alias act)(size_t l, size_t r)\n{\n\tfor(; l < r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1) act(l++); \n\t\tif (r & 1) act(--r);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value;\n\t\tbool isSet = false;\n\t\t_onComps!((c) \n\t\t\t{ value = isSet? f(value, _getNodeF(c)) : _getNodeF(c); isSet = true; }) (l, r);\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\t_onComps!(c => _addU(c, u))(l, r);\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\nvoid _onComps(alias act)(size_t l, size_t r)\n{\n\tfor(; l < r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1) act(l++); \n\t\tif (r & 1) act(--r);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value;\n\t\tbool isSet = false;\n\t\t_onComps!((c) \n\t\t\t\t{\n\t\t\t\t\tif (isSet) \n\t\t\t\t\t{ \n\t\t\t\t\t\tvalue = f(value, _getNodeF(c)); \n\t\t\t\t\t} \n\t\t\t\t\telse \n\t\t\t\t\t{ \n\t\t\t\t\t\tvalue = _getNodeF(c); \n\t\t\t\t\t\tisSet = true; \n\t\t\t\t\t}\n\t\t\t\t})(l, r);\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\t_onComps!(c => _addU(c, u))(l, r);\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\nvoid _onComps(alias act)(size_t l, size_t r)\n{\n\tfor(; l < r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1) act(l++); \n\t\tif (r & 1) act(--r);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value;\n\t\tvoid delegate(V) add;\n\t\tvoid delegate(V) combine = (V v) { value = f(value, v); };\n\t\tvoid delegate(V) set = (V v) { value = v; add = combine; };\n\t\tadd = set;\n\t\t_onComps!(c => add(_getNodeF(c)))(l, r);\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\t_onComps!(c => _addU(c, u))(l, r);\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\nvoid _onComps(alias act)(size_t l, size_t r)\n{\n\tfor(; l < r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1) act(l++); \n\t\tif (r & 1) act(--r);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value;\n\t\tvoid delegate(V) add;\n\t\tvoid delegate(V) combine = (V v) { value = f(value, v); };\n\t\tvoid delegate(V) set = (V v) { value = v; add = combine; };\n\t\tadd = set;\n\t\t_onComps!(c => add(_getNodeF(c)))(l, r);\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\t_onComps!(c => _addU(c, u))(l, r);\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\nvoid _onComps(alias act)(size_t l, size_t r)\n{\n\tfor(; l < r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1) act(l++); \n\t\tif (r & 1) act(--r);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value;\n\t\tvoid delegate(V) add;\n\t\tvoid delegate(V) combine = (V v) { value = f(value, v); };\n\t\tvoid delegate(V) set = (V v) { value = v; add = combine; };\n\t\tadd = set;\n\t\t_onComps!(c => add(_getNodeF(c)))(l, r);\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\t_onComps!(c => _addU(c, u))(l, r);\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\nvoid _onComps(alias act)(size_t l, size_t r)\n{\n\tfor(; l < r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1) act(l++); \n\t\tif (r & 1) act(--r);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutralV;\n\t\t_onComps!(c => value = f(value, _getNodeF(c)))(l, r);\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\t_onComps!(c => _addU(c, u))(l, r);\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\nvoid _onComps(alias act)(size_t l, size_t r)\n{\n\tfor(; l < r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1) act(l++); \n\t\tif (r & 1) act(--r);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\tdecomp.components = new size_t[](2 * layers);\n\t\tdecomp.affected = new size_t[](2 * layers);\n\t}\n\tstruct Decomp\n\t{\n\t\tsize_t[] components;\n\t\tsize_t noComponents;\n\t\tsize_t[] affected;\n\t\tsize_t noAffected;\n\t}\n\tDecomp decomp;\n\tvoid _getDecomp(size_t l, size_t r)\n\t{\n\t\tdecomp.noAffected = 0, decomp.noComponents = 0;\n\t\tl += length, r += length;\n\t\tsize_t ol = l, or = r - 1;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tdecomp.components[decomp.noComponents++] = l++;\n\t\t\tif (r & 1)\n\t\t\t\tdecomp.components[decomp.noComponents++] = --r;\n\t\t}\n\t\tol >>= 1; or >>= 1;\n\t\twhile (ol != or)\n\t\t{\n\t\t\tdecomp.affected[decomp.noAffected++] = ol;\n\t\t\tdecomp.affected[decomp.noAffected++] = or;\n\t\t\tol >>= 1, or >>= 1;\n\t\t}\n\t\twhile (ol)\n\t\t{\n\t\t\tdecomp.affected[decomp.noAffected++] = ol;\n\t\t\tol >>= 1; \n\t\t}\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\t_getDecomp(l, r);\n\t\tdecomp.affected[0 .. decomp.noAffected].retro.each!(i => _clearU(i));\n\t\treturn decomp.components[0 .. decomp.noComponents].map!(i => _getNodeF(i)).fold!f;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) _addU(i, u);\n\t\tforeach(i; decomp.affected[0 .. decomp.noAffected]) _nF[i] = f(_getNodeF(i << 1), _getNodeF((i << 1)+1));\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\tdecomp.components = new size_t[](2 * layers);\n\t\tdecomp.affected = new size_t[](2 * layers);\n\t}\n\tstruct Decomp\n\t{\n\t\tsize_t[] components;\n\t\tsize_t noComponents;\n\t\tsize_t[] affected;\n\t\tsize_t noAffected;\n\t}\n\tDecomp decomp;\n\tvoid _getDecomp(size_t l, size_t r)\n\t{\n\t\tdecomp.noAffected = 0, decomp.noComponents = 0;\n\t\tl += length, r += length;\n\t\tsize_t ol = l, or = r - 1;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tdecomp.components[decomp.noComponents++] = l++;\n\t\t\tif (r & 1)\n\t\t\t\tdecomp.components[decomp.noComponents++] = --r;\n\t\t}\n\t\tol >>= 1; or >>= 1;\n\t\twhile (ol != or)\n\t\t{\n\t\t\tdecomp.affected[decomp.noAffected++] = ol;\n\t\t\tdecomp.affected[decomp.noAffected++] = or;\n\t\t\tol >>= 1, or >>= 1;\n\t\t}\n\t\twhile (ol)\n\t\t{\n\t\t\tdecomp.affected[decomp.noAffected++] = ol;\n\t\t\tol >>= 1; \n\t\t}\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach_reverse(i; decomp.affected[0 .. decomp.noAffected]) _clearU(i);\n\t\tV value = neutralV;\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) value = f(value, _getNodeF(i));\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) _addU(i, u);\n\t\tforeach(i; decomp.affected[0 .. decomp.noAffected]) _nF[i] = f(_getNodeF(i << 1), _getNodeF((i << 1)+1));\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = -1;\n\tint j = 0;\n\twhile (i + 1 < n && st.rangeF(0, m - 1) == 0) { i++; st.rangeU(segs[i][1], segs[i][2], 1); }\n\tif (st.rangeF(0, m - 1) == 0) assert(0);\n\twhile (i < n)\n\t{\n\t\twhile (st.rangeF(0, m - 1) > 0) remove(j++);\n\t\tadd(--j);\n\t\tans = min(ans, segs[i][0] - segs[j][0]);\n\t\tif (++i < n) add(i);\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\tdecomp.components = new size_t[](2 * layers);\n\t\tdecomp.affected = new size_t[](2 * layers);\n\t}\n\tstruct Decomp\n\t{\n\t\tsize_t[] components;\n\t\tsize_t noComponents;\n\t\tsize_t[] affected;\n\t\tsize_t noAffected;\n\t}\n\tDecomp decomp;\n\tvoid _getDecomp(size_t l, size_t r)\n\t{\n\t\tdecomp.noAffected = 0, decomp.noComponents = 0;\n\t\tl += length, r += length;\n\t\tsize_t ol = l, or = r - 1;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tdecomp.components[decomp.noComponents++] = l++;\n\t\t\tif (r & 1)\n\t\t\t\tdecomp.components[decomp.noComponents++] = --r;\n\t\t}\n\t\tol >>= 1; or >>= 1;\n\t\twhile (ol != or)\n\t\t{\n\t\t\tdecomp.affected[decomp.noAffected++] = ol;\n\t\t\tdecomp.affected[decomp.noAffected++] = or;\n\t\t\tol >>= 1, or >>= 1;\n\t\t}\n\t\twhile (ol)\n\t\t{\n\t\t\tdecomp.affected[decomp.noAffected++] = ol;\n\t\t\tol >>= 1; \n\t\t}\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach_reverse(i; decomp.affected[0 .. decomp.noAffected]) _clearU(i);\n\t\tV value = neutralV;\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) value = f(value, _getNodeF(i));\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) _addU(i, u);\n\t\tforeach(i; decomp.affected[0 .. decomp.noAffected]) _nF[i] = f(_getNodeF(i << 1), _getNodeF((i << 1)+1));\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = -1;\n\tint j = 0;\n\twhile (i + 1 < n && st.rangeF(0, m - 1) == 0) { i++; st.rangeU(segs[i][1], segs[i][2], 1); }\n\tif (st.rangeF(0, m - 1) == 0) assert(0);\n\twhile (i < n)\n\t{\n\t\twhile (st.rangeF(0, m - 1) > 0) remove(j++);\n\t\tadd(--j);\n\t\tans = min(ans, segs[i][0] - segs[j][0]);\n\t\tif (++i < n) add(i);\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\tdecomp.components = new size_t[](2 * layers);\n\t\tdecomp.affected = new size_t[](2 * layers);\n\t}\n\tstruct Decomp\n\t{\n\t\tsize_t[] components;\n\t\tsize_t noComponents;\n\t\tsize_t[] affected;\n\t\tsize_t noAffected;\n\t}\n\tDecomp decomp;\n\tvoid _getDecomp(size_t l, size_t r)\n\t{\n\t\tdecomp.noAffected = 0, decomp.noComponents = 0;\n\t\tl += length, r += length;\n\t\tsize_t ol = l, or = r - 1;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t{\n\t\t\t\tdecomp.components[decomp.noComponents++] = l;\n\t\t\t\tl++;\n\t\t\t}\n\t\t\tif (r & 1)\n\t\t\t{\n\t\t\t\tdecomp.components[decomp.noComponents++] = r - 1;\n\t\t\t\tr--;\n\t\t\t}\n\t\t}\n\t\tol >>= 1; or >>= 1;\n\t\twhile (ol > 0 && or > 0)\n\t\t{\n\t\t\tif (ol != or)\n\t\t\t{\n\t\t\t\tdecomp.affected[decomp.noAffected++] = ol;\n\t\t\t\tdecomp.affected[decomp.noAffected++] = or;\n\t\t\t}\n\t\t\telse decomp.affected[decomp.noAffected++] = ol;\n\t\t\tol >>= 1; or >>= 1;\n\t\t}\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach_reverse(i; decomp.affected[0 .. decomp.noAffected]) _clearU(i);\n\t\tV value = neutralV;\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) value = f(value, _getNodeF(i));\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) _addU(i, u);\n\t\tforeach(i; decomp.affected[0 .. decomp.noAffected]) _nF[i] = f(_getNodeF(i << 1), _getNodeF((i << 1)+1));\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = -1;\n\tint j = 0;\n\twhile (i + 1 < n && st.rangeF(0, m - 1) == 0) { i++; st.rangeU(segs[i][1], segs[i][2], 1); }\n\tif (st.rangeF(0, m - 1) == 0) assert(0);\n\twhile (i < n)\n\t{\n\t\twhile (st.rangeF(0, m - 1) > 0) remove(j++);\n\t\tadd(--j);\n\t\tans = min(ans, segs[i][0] - segs[j][0]);\n\t\tif (++i < n) add(i);\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\tdecomp.components = new size_t[](2 * layers);\n\t\tdecomp.affected = new size_t[](2 * layers);\n\t}\n\tstruct Decomp\n\t{\n\t\tsize_t[] components;\n\t\tsize_t noComponents;\n\t\tsize_t[] affected;\n\t\tsize_t noAffected;\n\t}\n\tDecomp decomp;\n\tvoid _getDecomp(size_t l, size_t r)\n\t{\n\t\tdecomp.noAffected = 0, decomp.noComponents = 0;\n\t\tl += length, r += length;\n\t\tsize_t ol = l, or = r - 1;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t{\n\t\t\t\tdecomp.components[decomp.noComponents++] = l;\n\t\t\t\tl++;\n\t\t\t}\n\t\t\tif (r & 1)\n\t\t\t{\n\t\t\t\tdecomp.components[decomp.noComponents++] = r - 1;\n\t\t\t\tr--;\n\t\t\t}\n\t\t}\n\t\tol >>= 1; or >>= 1;\n\t\twhile (ol > 0 && or > 0)\n\t\t{\n\t\t\tif (ol != or)\n\t\t\t{\n\t\t\t\tdecomp.affected[decomp.noAffected++] = ol;\n\t\t\t\tdecomp.affected[decomp.noAffected++] = or;\n\t\t\t}\n\t\t\telse decomp.affected[decomp.noAffected++] = ol;\n\t\t\tol >>= 1; or >>= 1;\n\t\t}\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach_reverse(i; decomp.affected[0 .. decomp.noAffected]) _clearU(i);\n\t\tV value = neutralV;\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) value = f(value, _getNodeF(i));\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\t_getDecomp(l, r);\n\t\tforeach_reverse(i; decomp.affected[0 .. decomp.noAffected]) _clearU(i);\n\t\tforeach(i; decomp.components[0 .. decomp.noComponents]) _addU(i, u);\n\t\tforeach(i; decomp.affected[0 .. decomp.noAffected]) _nF[i] = f(_getNodeF(i << 1), _getNodeF((i << 1)+1));\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = SegmentTreeLazy!(int, int,\n\t\t\t(a, b) => min(a, b),\n\t\t\t(mn, u) => mn + u,\n\t\t\t(u1, u2) => u1 + u2,\n\t\t\t\"min\",\n\t\t\t\"+\")(m - 1, 0);\n\talias add = i => st[segs[i][1] .. segs[i][2]] += 1;\n\talias remove = i => st[segs[i][1] .. segs[i][2]] += -1;\n\tint ans = int.max;\n\tint i = -1;\n\tint j = 0;\n\tdebug writeln(segs);\n\twhile (st[0 .. m - 1].min == 0)\n\t{\n\t\tadd(i + 1);\n\t\ti++;\n\t}\n\twhile (i < n)\n\t{\n\t\twhile (st[0 .. m - 1].min > 0) remove(j++);\n\t\tadd(--j);\n\t\tans = min(ans, segs[i][0] - segs[j][0]);\n\t\tif (++i < n) add(i);\n\t}\n\tans.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n\nimport std.algorithm;\nimport std.random;\n\n\n\nstruct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)\n{\n\talias This = typeof(this);\n\tsize_t length;\n\tsize_t realLength = 0;\n\tV[] _nodeFValue; \n\tU[] _nodeUpdate;\n\tbool[] _nodeHasUpdate;\n\tsize_t[] _nodeRangeEnd;\n\tsize_t[] _nodeRangeStart;\n\tV[] _cookedFCache;\n\tstring toString()\n\t{\n\t\timport std.conv;\n\t\tstring str;\n\t\tforeach(i; 0 .. realLength)\n\t\t\tif (_nodeHasUpdate[i])\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \"(\", _nodeUpdate[i], \"), \");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \", \");\n\t\t\t}\n\t\treturn str;\n\t}\n\tthis(size_t length, V initialValue)\n\t{\n\t\tthis.length = length;\n\t\tsize_t noNodes = 4 * length;\n\t\t_nodeFValue = new V[](noNodes);\n\t\t_nodeUpdate = new U[](noNodes);\n\t\t_nodeHasUpdate = new bool[](noNodes);\n\t\t_nodeRangeEnd = new size_t[](noNodes);\n\t\t_nodeRangeStart = new size_t[](noNodes);\n\t\t_cookedFCache = new V[](noNodes);\n\t\tvoid fill(size_t i, size_t rangeStart, size_t rangeEnd)\n\t\t{\n\t\t\trealLength = max(realLength, i + 1);\n\t\t\t_nodeRangeStart[i] = rangeStart;\n\t\t\t_nodeRangeEnd[i] = rangeEnd;\n\t\t\tif (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }\n\t\t\tsize_t l = i<<1;\n\t\t\tsize_t r = l+1;\n\t\t\tsize_t m = (rangeStart + rangeEnd) / 2;\n\t\t\tfill(l, rangeStart, m), fill(r, m + 1, rangeEnd);\n\t\t\t_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);\n\t\t\t_cookedFCache[i] = _nodeFValue[i];\n\t\t}\n\t\tfill(1, 0, length - 1);\n\t}\n\n\tsize_t _qStart, _qEnd;\n\tbool _set = false;\n\tV _result;\n\tV rangeF(size_t start, size_t end)\n\t{\n\t\tpragma(inline, true);\n\t\t_set = false;\n\t\t_qStart = start;\n\t\t_qEnd = end;\n\t\tvisitF(1);\n\t\treturn _result;\n\t}\n\tvoid visitF(size_t i) in(_hasFragments(i))\n\t{\n\t\tif (_isFragment(i))\n\t\t{\n\t\t\tif (!_set) { _result = _cookedFCache[i]; _set = true; }\n\t\t\telse { _result = f(_result, _cookedFCache[i]); }\n\t\t\treturn;\n\t\t}\n\t\t_clearUpdate(i);\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\tif (_qEnd <= _nodeRangeEnd[l]) {visitF(l);return;}\n\t\tif (_qStart >= _nodeRangeStart[r]) {visitF(r);return;}\n\t\tvisitF(l), visitF(r);\n\t}\n\t\n\tU _qU;\n\tvoid rangeU(size_t start, size_t end, U u)\n\t{\n\t\tpragma(inline, true);\n\t\t_qStart = start;\n\t\t_qEnd = end;\n\t\t_qU = u;\n\t\tvisitU(1);\n\t}\n\tvoid visitU(size_t i) in(_hasFragments(i))\n\t{\n\t\tif (_isFragment(i))\n\t\t{\n\t\t\t_addUpdate(i, _qU);\n\t\t\treturn;\n\t\t}\n\t\t_clearUpdate(i);\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\tif (_qEnd <= _nodeRangeEnd[l]) {visitU(l);goto end;}\n\t\tif (_qStart >= _nodeRangeStart[r]) {visitU(r);goto end;}\n\t\tvisitU(l), visitU(r);\nend:\n\t\tassert(!_nodeHasUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedFCache[l], _cookedFCache[r]);\n\t\t_cookedFCache[i] = _nodeFValue[i];\n\t}\n\tV _cookedF(size_t i) in(_nodeHasUpdate[i])\n\t{\n\t\tpragma(inline, true);\n\t\timport std.traits;\n\t\treturn fou(_nodeFValue[i], \n\t\t\t _nodeUpdate[i]);\n\t}\n\tvoid _clearUpdate(size_t i) out(;!_nodeHasUpdate[i])\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nodeHasUpdate[i]) return;\n\t\tif (_isLeaf(i)) { _nodeFValue[i] = _cookedFCache[i]; _nodeHasUpdate[i] = false; return;}\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedFCache[l], _cookedFCache[r]);\n\t\t_cookedFCache[i] = _nodeFValue[i];\n\t\t_nodeHasUpdate[i] = false;\n\t}\n\tvoid _addUpdate(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; _cookedFCache[i] = _cookedF(i); return; }\n\t\t_nodeUpdate[i] = uou(_nodeUpdate[i], u);\n\t\t_cookedFCache[i] = _cookedF(i);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _nodeRangeStart[i] == _nodeRangeEnd[i];\n\t}\n\tbool _isFragment(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _qStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= _qEnd;\n\t}\n\tbool _hasFragments(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _nodeRangeStart[i] <= _qEnd && _qStart <= _nodeRangeEnd[i];\n\t}\n\t// prettifiers\n\tstruct Handle\n\t{\n\t\timport std.ascii;\n\t\tsize_t _start, _end;\n\t\tThis* _parent;\n\t\tauto f()\n\t\t{\n\t\t\treturn _parent.rangeF(_start, _end);\n\t\t}\n\t\tauto u(U v)\n\t\t{\n\t\t\t_parent.rangeU(_start, _end, v);\n\t\t}\n\t\tstatic if (fName !is null)\n\t\t{\n\t\t\tmixin(q{alias }, fName, q{ = f;});\n\t\t}\n\t\tstatic if (uName !is null)\n\t\t{\n\t\t\tstatic if (uName[0].isAlphaNum)\n\t\t\t{\n\t\t\t\tmixin(q{alias }, uName, q{ = u;});\n\t\t\t}\n\t\t\telse static if (uName[0] != ' ')\n\t\t\t{\n\t\t\t\tref Handle opOpAssign(string operator)(U v) \n\t\t\t\tif (operator == uName)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tref Handle opAssign(U v)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)\n\t{\n\t\treturn [s, e-1];\n\t}\n\tauto opIndex(size_t[2] slice)\n\t{\n\t\treturn Handle(slice[0], slice[1], &this);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = SegmentTreeLazy!(int, int,\n\t\t\t(a, b) => min(a, b),\n\t\t\t(mn, u) => mn + u,\n\t\t\t(u1, u2) => u1 + u2,\n\t\t\t\"min\",\n\t\t\t\"+\")(m, 0);\n\tint ans = int.max;\n\tint i = -1;\n\tint j = 0;\n\tdebug writeln(segs);\n\twhile (st[0 .. m - 1] == 0)\n\t{\n\t\tdebug writeln(\"adding segment \", segs[i+1]);\n\t\tst[segs[i+1][1] .. segs[i+1][2]] = +1;\n\t\tdebug foreach(k; 0 .. m) st[k .. k + 1].write(\" \");\n\t\tdebug writeln;\n\t\ti++;\n\t}\n\twhile (i < n)\n\t{\n\t\twhile (st[0 .. m - 1] > 0)\n\t\t{\n\t\t\tst[segs[j][1] .. segs[j][2]] = -1;\n\t\t\tj++;\n\t\t}\n\t\tst[segs[j-1][1] .. segs[j-1][2]] = +1;\n\t\tj--;\n\t\tassert(st[0 .. m - 1] > 0);\n\t\tans = min(ans, segs[i][0] - segs[j][0]);\n\t\tif (i + 1 < n) \n\t\t\tst[segs[i + 1][1] .. segs[i + 1][2]] = +1;\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n\nimport std.algorithm;\nimport std.random;\n\n\n\nstruct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)\n{\n\talias This = typeof(this);\n\tsize_t length;\n\tsize_t realLength = 0;\n\tV[] _nodeFValue; \n\tU[] _nodeUpdate;\n\tbool[] _nodeHasUpdate;\n\tsize_t[] _nodeRangeEnd;\n\tsize_t[] _nodeRangeStart;\n\tV[] _cookedFCache;\n\tstring toString()\n\t{\n\t\timport std.conv;\n\t\tstring str;\n\t\tforeach(i; 0 .. realLength)\n\t\t\tif (_nodeHasUpdate[i])\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \"(\", _nodeUpdate[i], \"), \");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \", \");\n\t\t\t}\n\t\treturn str;\n\t}\n\tthis(size_t length, V initialValue)\n\t{\n\t\tthis.length = length;\n\t\tsize_t noNodes = 4 * length;\n\t\t_nodeFValue = new V[](noNodes);\n\t\t_nodeUpdate = new U[](noNodes);\n\t\t_nodeHasUpdate = new bool[](noNodes);\n\t\t_nodeRangeEnd = new size_t[](noNodes);\n\t\t_nodeRangeStart = new size_t[](noNodes);\n\t\t_cookedFCache = new V[](noNodes);\n\t\tvoid fill(size_t i, size_t rangeStart, size_t rangeEnd)\n\t\t{\n\t\t\trealLength = max(realLength, i + 1);\n\t\t\t_nodeRangeStart[i] = rangeStart;\n\t\t\t_nodeRangeEnd[i] = rangeEnd;\n\t\t\tif (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }\n\t\t\tsize_t l = i<<1;\n\t\t\tsize_t r = l+1;\n\t\t\tsize_t m = (rangeStart + rangeEnd) / 2;\n\t\t\tfill(l, rangeStart, m), fill(r, m + 1, rangeEnd);\n\t\t\t_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);\n\t\t\t_cookedFCache[i] = _nodeFValue[i];\n\t\t}\n\t\tfill(1, 0, length - 1);\n\t}\n\n\tsize_t _qStart, _qEnd;\n\tbool _set = false;\n\tV _result;\n\tV rangeF(size_t start, size_t end)\n\t{\n\t\tpragma(inline, true);\n\t\t_set = false;\n\t\t_qStart = start;\n\t\t_qEnd = end;\n\t\tvisitF(1);\n\t\treturn _result;\n\t}\n\tvoid visitF(size_t i) in(_hasFragments(i))\n\t{\n\t\tif (_isFragment(i))\n\t\t{\n\t\t\tif (!_set) { _result = _cookedFCache[i]; _set = true; }\n\t\t\telse { _result = f(_result, _cookedFCache[i]); }\n\t\t\treturn;\n\t\t}\n\t\t_clearUpdate(i);\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\tif (_qEnd <= _nodeRangeEnd[l]) {visitF(l);return;}\n\t\tif (_qStart >= _nodeRangeStart[r]) {visitF(r);return;}\n\t\tvisitF(l), visitF(r);\n\t}\n\t\n\tU _qU;\n\tvoid rangeU(size_t start, size_t end, U u)\n\t{\n\t\tpragma(inline, true);\n\t\t_qStart = start;\n\t\t_qEnd = end;\n\t\t_qU = u;\n\t\tvisitU(1);\n\t}\n\tvoid visitU(size_t i) in(_hasFragments(i))\n\t{\n\t\tif (_isFragment(i))\n\t\t{\n\t\t\t_addUpdate(i, _qU);\n\t\t\treturn;\n\t\t}\n\t\t_clearUpdate(i);\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\tif (_qEnd <= _nodeRangeEnd[l]) {visitU(l);goto end;}\n\t\tif (_qStart >= _nodeRangeStart[r]) {visitU(r);goto end;}\n\t\tvisitU(l), visitU(r);\nend:\n\t\tassert(!_nodeHasUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedFCache[l], _cookedFCache[r]);\n\t\t_cookedFCache[i] = _nodeFValue[i];\n\t}\n\tV _cookedF(size_t i) in(_nodeHasUpdate[i])\n\t{\n\t\tpragma(inline, true);\n\t\timport std.traits;\n\t\treturn fou(_nodeFValue[i], \n\t\t\t _nodeUpdate[i]);\n\t}\n\tvoid _clearUpdate(size_t i) out(;!_nodeHasUpdate[i])\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nodeHasUpdate[i]) return;\n\t\tif (_isLeaf(i)) { _nodeFValue[i] = _cookedFCache[i]; _nodeHasUpdate[i] = false; return;}\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedFCache[l], _cookedFCache[r]);\n\t\t_cookedFCache[i] = _nodeFValue[i];\n\t\t_nodeHasUpdate[i] = false;\n\t}\n\tvoid _addUpdate(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; _cookedFCache[i] = _cookedF(i); return; }\n\t\t_nodeUpdate[i] = uou(_nodeUpdate[i], u);\n\t\t_cookedFCache[i] = _cookedF(i);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _nodeRangeStart[i] == _nodeRangeEnd[i];\n\t}\n\tbool _isFragment(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _qStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= _qEnd;\n\t}\n\tbool _hasFragments(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _nodeRangeStart[i] <= _qEnd && _qStart <= _nodeRangeEnd[i];\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)\n\t{\n\t\treturn [s, e-1];\n\t}\n\tauto opIndex(size_t[2] slice)\n\t{\n\t\treturn rangeF(slice[0], slice[1]);\n\t}\n\tvoid opIndexAssign(U u, size_t[2] slice)\n\t{\n\t\treturn rangeU(slice[0], slice[1], u);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = SegmentTreeLazy!(int, int,\n\t\t\t(a, b) => min(a, b),\n\t\t\t(mn, u) => mn + u,\n\t\t\t(u1, u2) => u1 + u2,\n\t\t\t\"min\",\n\t\t\t\"+\")(m, 0);\n\tint ans = int.max;\n\tint i = -1;\n\tint j = 0;\n\tdebug writeln(segs);\n\twhile (st[0 .. m - 1].min == 0)\n\t{\n\t\tdebug writeln(\"adding segment \", segs[i+1]);\n\t\tst[segs[i+1][1] .. segs[i+1][2]] += +1;\n\t\tdebug foreach(k; 0 .. m) st[k .. k + 1].min.write(\" \");\n\t\tdebug writeln;\n\t\ti++;\n\t}\n\twhile (i < n)\n\t{\n\t\twhile (st[0 .. m - 1].min > 0)\n\t\t{\n\t\t\tst[segs[j][1] .. segs[j][2]] += -1;\n\t\t\tj++;\n\t\t}\n\t\tst[segs[j-1][1] .. segs[j-1][2]] += +1;\n\t\tj--;\n\t\tassert(st[0 .. m - 1].min > 0);\n\t\tans = min(ans, segs[i][0] - segs[j][0]);\n\t\tif (i + 1 < n) \n\t\t\tst[segs[i + 1][1] .. segs[i + 1][2]] += +1;\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n\nimport std.algorithm;\nimport std.random;\n\n\n\nstruct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)\n{\n\talias This = typeof(this);\n\tsize_t length;\n\tsize_t realLength = 0;\n\tV[] _nodeFValue; \n\tU[] _nodeUpdate;\n\tbool[] _nodeHasUpdate;\n\tsize_t[] _nodeRangeEnd;\n\tsize_t[] _nodeRangeStart;\n\tV[] _cookedFCache;\n\tstring toString()\n\t{\n\t\timport std.conv;\n\t\tstring str;\n\t\tforeach(i; 0 .. realLength)\n\t\t\tif (_nodeHasUpdate[i])\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \"(\", _nodeUpdate[i], \"), \");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \", \");\n\t\t\t}\n\t\treturn str;\n\t}\n\tthis(size_t length, V initialValue)\n\t{\n\t\tthis.length = length;\n\t\tsize_t noNodes = 4 * length;\n\t\t_nodeFValue = new V[](noNodes);\n\t\t_nodeUpdate = new U[](noNodes);\n\t\t_nodeHasUpdate = new bool[](noNodes);\n\t\t_nodeRangeEnd = new size_t[](noNodes);\n\t\t_nodeRangeStart = new size_t[](noNodes);\n\t\t_cookedFCache = new V[](noNodes);\n\t\tvoid fill(size_t i, size_t rangeStart, size_t rangeEnd)\n\t\t{\n\t\t\trealLength = max(realLength, i + 1);\n\t\t\t_nodeRangeStart[i] = rangeStart;\n\t\t\t_nodeRangeEnd[i] = rangeEnd;\n\t\t\tif (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }\n\t\t\tsize_t l = i<<1;\n\t\t\tsize_t r = l+1;\n\t\t\tsize_t m = (rangeStart + rangeEnd) / 2;\n\t\t\tfill(l, rangeStart, m), fill(r, m + 1, rangeEnd);\n\t\t\t_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);\n\t\t\t_cookedFCache[i] = _nodeFValue[i];\n\t\t}\n\t\tfill(1, 0, length - 1);\n\t}\n\n\tsize_t _qStart, _qEnd;\n\tbool _set = false;\n\tV _result;\n\tV rangeF(size_t start, size_t end)\n\t{\n\t\tpragma(inline, true);\n\t\t_set = false;\n\t\t_qStart = start;\n\t\t_qEnd = end;\n\t\tvisitF(1);\n\t\treturn _result;\n\t}\n\tvoid visitF(size_t i) in(_hasFragments(i))\n\t{\n\t\tif (_isFragment(i))\n\t\t{\n\t\t\tif (!_set) { _result = _cookedFCache[i]; _set = true; }\n\t\t\telse { _result = f(_result, _cookedFCache[i]); }\n\t\t\treturn;\n\t\t}\n\t\t_clearUpdate(i);\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\tif (_qEnd <= _nodeRangeEnd[l]) {visitF(l);return;}\n\t\tif (_qStart >= _nodeRangeStart[r]) {visitF(r);return;}\n\t\tvisitF(l), visitF(r);\n\t}\n\t\n\tU _qU;\n\tvoid rangeU(size_t start, size_t end, U u)\n\t{\n\t\tpragma(inline, true);\n\t\t_qStart = start;\n\t\t_qEnd = end;\n\t\t_qU = u;\n\t\tvisitU(1);\n\t}\n\tvoid visitU(size_t i) in(_hasFragments(i))\n\t{\n\t\tif (_isFragment(i))\n\t\t{\n\t\t\t_addUpdate(i, _qU);\n\t\t\treturn;\n\t\t}\n\t\t_clearUpdate(i);\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\tif (_qEnd <= _nodeRangeEnd[l]) {visitU(l);goto end;}\n\t\tif (_qStart >= _nodeRangeStart[r]) {visitU(r);goto end;}\n\t\tvisitU(l), visitU(r);\nend:\n\t\tassert(!_nodeHasUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedFCache[l], _cookedFCache[r]);\n\t\t_cookedFCache[i] = _nodeFValue[i];\n\t}\n\tV _cookedF(size_t i) in(_nodeHasUpdate[i])\n\t{\n\t\tpragma(inline, true);\n\t\timport std.traits;\n\t\treturn fou(_nodeFValue[i], \n\t\t\t _nodeUpdate[i]);\n\t}\n\tvoid _clearUpdate(size_t i) out(;!_nodeHasUpdate[i])\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nodeHasUpdate[i]) return;\n\t\tif (_isLeaf(i)) { _nodeFValue[i] = _cookedFCache[i]; _nodeHasUpdate[i] = false; return;}\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedFCache[l], _cookedFCache[r]);\n\t\t_cookedFCache[i] = _nodeFValue[i];\n\t\t_nodeHasUpdate[i] = false;\n\t}\n\tvoid _addUpdate(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; _cookedFCache[i] = _cookedF(i); return; }\n\t\t_nodeUpdate[i] = uou(_nodeUpdate[i], u);\n\t\t_cookedFCache[i] = _cookedF(i);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _nodeRangeStart[i] == _nodeRangeEnd[i];\n\t}\n\tbool _isFragment(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _qStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= _qEnd;\n\t}\n\tbool _hasFragments(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn _nodeRangeStart[i] <= _qEnd && _qStart <= _nodeRangeEnd[i];\n\t}\n\t// prettifiers\n\tstruct Handle\n\t{\n\t\timport std.ascii;\n\t\tsize_t _start, _end;\n\t\tThis* _parent;\n\t\tauto f()\n\t\t{\n\t\t\treturn _parent.rangeF(_start, _end);\n\t\t}\n\t\tauto u(U v)\n\t\t{\n\t\t\t_parent.rangeU(_start, _end, v);\n\t\t}\n\t\tstatic if (fName !is null)\n\t\t{\n\t\t\tmixin(q{alias }, fName, q{ = f;});\n\t\t}\n\t\tstatic if (uName !is null)\n\t\t{\n\t\t\tstatic if (uName[0].isAlphaNum)\n\t\t\t{\n\t\t\t\tmixin(q{alias }, uName, q{ = u;});\n\t\t\t}\n\t\t\telse static if (uName[0] != ' ')\n\t\t\t{\n\t\t\t\tref Handle opOpAssign(string operator)(U v) \n\t\t\t\tif (operator == uName)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tref Handle opAssign(U v)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)\n\t{\n\t\treturn [s, e-1];\n\t}\n\tauto opIndex(size_t[2] slice)\n\t{\n\t\treturn Handle(slice[0], slice[1], &this);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nlong nextPow2(long n)\n{\n\tint i = 0;\n\twhile (n) \n\t{\n\t\tn >>= 1;\n\t\ti++;\n\t}\n\tif ((1L << i) >= n) return 1L << i;\n\treturn (1L << (i + 1));\n}\n\nversion(none) void main()\n{\n\tauto st = STL!(int, 0, int, (a, b) => a + b, (s, i, len) => s + i * len, (nu, ou) => nu + ou)(100000, 0);\n\tauto brute = new int[](st.length);\n\tforeach(i; 0 .. 100000)\n\t{\n\t\tint l = uniform!\"[]\"(0, cast(int)st.length - 1);\n\t\tint r = uniform!\"[]\"(l + 1, cast(int)st.length);\n\t\tif (i & 1)\n\t\t{\n\t\t\tint u = uniform!\"[]\"(-100, 100);\n\t\t\tbrute[l .. r] += u;\n\t\t\tst.rangeU(l, r, u);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"answer is \", st.rangeF(l, r));\n\t\t\tassert(brute[l .. r].sum == st.rangeF(l, r));\n\t\t}\n\t}\n}\n\nversion(all) void main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new Tuple!(int, int, int)[](n);\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[1] = readInt!int - 1;\n\t\tsegi[2] = readInt!int - 1;\n\t\tsegi[0] = readInt!int;\n\t}\n\tsort(segs);\n\tauto st = STL!(long, long.max, long, min, (mn, u, sz) => mn + u, (nu, ou) => nu + ou)(m - 1, 0);\n\talias add = i => st.rangeU(segs[i][1], segs[i][2], 1);\n\talias remove = i => st.rangeU(segs[i][1], segs[i][2], -1);\n\tint ans = int.max;\n\tint i = 0;\n\tint j = -1;\n\twhile (i < n)\n\t{\n\t\twhile (j+1 < n && st.rangeF(0, m - 1) == 0) add(++j);\n\t\tif (st.rangeF(0, m - 1)) ans = min(ans, segs[j][0] - segs[i][0]);\n\t\tremove(i);\n\t\ti++;\n\t}\n\tans.writeln;\n}\n\nstruct STL(V, V neutralV, U, alias f, alias fou, alias uou)\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[] = neutralV;\n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nHasU[] = false;\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value;\n\t\tvoid delegate(V) add;\n\t\tvoid delegate(V) combine = (V v) { value = f(value, v); };\n\t\tvoid delegate(V) set = (V v) { value = v; add = combine; };\n\t\tadd = set;\n\t\t_onComps!(c => set(_getNodeF(c)))(l, r);\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\t_onComps!(c => _addU(c, u))(l, r);\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) \n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n}\nvoid _onComps(alias act)(size_t l, size_t r)\n{\n\tfor(; l < r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1) act(l++); \n\t\tif (r & 1) act(--r);\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto segs = new int[2][](n);\n\tauto segPerW = new int[][](1_000_000 + 1);\n\tauto maxW = long.min;\n\tforeach(i, ref segi; segs)\n\t{\n\t\tsegi[0] = readInt!int - 1;\n\t\tsegi[1] = readInt!int - 1;\n\t\tauto w = readInt!long;\n\t\tmaxW = max(maxW, w);\n\t\tsegPerW[cast(int)w] ~= cast(int)i;\n\t}\n// struct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)\n\tbool can(int diff)\n\t{ \n\t\tauto st = SegmentTreeLazy!(long, long,\n\t\t\t\t(a, b) => min(a, b),\n\t\t\t\t(mn, u, i, f) => mn + u,\n\t\t\t\t(u1, u2) => u1 + u2,\n\t\t\t\t\"min\",\n\t\t\t\t\"+\")(m, 0);\n\t\tdebug writeln(\"dif = \", diff);\n\t\tforeach(i; 0 .. diff)\n\t\t\tforeach(segi; segPerW[i])\n\t\t\t{\n\t\t\t\tst[segs[segi][0] .. segs[segi][1]] += 1;\n\t\t\t}\n\t\tdebug\n\t\t{\n\t\t\tforeach(i; 0 .. m)\n\t\t\t\tst[i .. i + 1].min.write(\" \");\n\t\t\twriteln;\n\t\t}\n\n\t\tforeach(i; diff .. 1_000_000 + 1)\n\t\t{\n\t\t\tforeach(seg; segPerW[i]) \n\t\t\t{\n\t\t\t\tdebug writeln(\"adding segment = \", segs[seg][0] + 1, \" \",\n\t\t\t\t\t\tsegs[seg][1] + 1);\n\t\t\t\tst.rangeU(segs[seg][0], segs[seg][1] - 1, 1);\n\t\t\t}\n\t\t\tdebug\n\t\t\t{\n\t\t\t\tforeach(j; 0 .. m)\n\t\t\t\t\tst[j .. j + 1].min.write(\" \");\n\t\t\t\twriteln;\n\t\t\t}\n\t\t\tif (st.rangeF(0, m - 1) > 0) return true;\n\t\t\tforeach(seg; segPerW[i - diff]) \n\t\t\t{\n\t\t\t\tdebug writeln(\"removing segment = \", segs[seg][0] + 1, \" \",\n\t\t\t\t\t\tsegs[seg][1] + 1);\n\t\t\t\tst.rangeU(segs[seg][0], segs[seg][1] - 1, -1);\n\t\t\t}\n\t\t\tdebug\n\t\t\t{\n\t\t\t\tforeach(j; 0 .. m)\n\t\t\t\t\tst[j .. j + 1].min.write(\" \");\n\t\t\t\twriteln;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tint hi = 1_000_000;\n\tint lo = 0;\n\tint ans = -1;\n\twhile (lo <= hi)\n\t{\n\t\tauto mid = (lo + hi) / 2;\n\t\tif (can(mid))\n\t\t{\n\t\t\tans = mid;\n\t\t\thi = mid - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlo = mid + 1;\n\t\t}\n\t}\n\tans.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n\nimport std.algorithm;\nimport std.random;\n\n\n\nstruct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)\n{\n\talias This = typeof(this);\n\tsize_t length;\n\tsize_t realLength = 0;\n\tV[] _nodeFValue; \n\tU[] _nodeUpdate;\n\tbool[] _nodeHasUpdate;\n\tsize_t[] _nodeRangeEnd;\n\tsize_t[] _nodeRangeStart;\n\tstring toString()\n\t{\n\t\timport std.conv;\n\t\tstring str;\n\t\tforeach(i; 0 .. realLength)\n\t\t\tif (_nodeHasUpdate[i])\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \"(\", _nodeUpdate[i], \"), \");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \", \");\n\t\t\t}\n\t\treturn str;\n\t}\n\tthis(size_t length, V initialValue)\n\t{\n\t\tthis.length = length;\n\t\tsize_t noNodes = 4 * length;\n\t\t_nodeFValue = new V[](noNodes);\n\t\t_nodeUpdate = new U[](noNodes);\n\t\t_nodeHasUpdate = new bool[](noNodes);\n\t\t_nodeRangeEnd = new size_t[](noNodes);\n\t\t_nodeRangeStart = new size_t[](noNodes);\n\t\tvoid fill(size_t i, size_t rangeStart, size_t rangeEnd)\n\t\t{\n\t\t\trealLength = max(realLength, i + 1);\n\t\t\t_nodeRangeStart[i] = rangeStart;\n\t\t\t_nodeRangeEnd[i] = rangeEnd;\n\t\t\tif (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }\n\t\t\tsize_t l = i<<1;\n\t\t\tsize_t r = l+1;\n\t\t\tsize_t m = (rangeStart + rangeEnd) / 2;\n\t\t\tfill(l, rangeStart, m), fill(r, m + 1, rangeEnd);\n\t\t\t_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);\n\t\t}\n\t\tfill(1, 0, length - 1);\n\t}\n\tV rangeF(size_t start, size_t end)\n\t{\n\t\tbool set = false;\n\t\tV result;\n\t\tvoid visit(size_t i) in(_hasFragments(i, start, end))\n\t\t{\n\t\t\tif (_isFragment(i, start, end))\n\t\t\t{\n\t\t\t\tif (!set) { result = _cookedF(i); set = true; }\n\t\t\t\telse { result = f(result, _cookedF(i)); }\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_clearUpdate(i);\n\t\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t\tif (_hasFragments(l, start, end)) visit(l);\n\t\t\tif (_hasFragments(r, start, end)) visit(r);\n\t\t}\n\t\tvisit(1);\n\t\treturn result;\n\t}\n\tvoid rangeU(size_t start, size_t end, U u)\n\t{\n\t\tvoid visit(size_t i) in(_hasFragments(i, start, end))\n\t\t{\n\t\t\tif (_isFragment(i, start, end))\n\t\t\t{\n\t\t\t\t_addUpdate(i, u);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_clearUpdate(i);\n\t\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t\tif (_hasFragments(l, start, end)) visit(l);\n\t\t\tif (_hasFragments(r, start, end)) visit(r);\n\t\t\t_nodeFValue[i] = f(_cookedF(l), _cookedF(r));\n\t\t}\n\t\tvisit(1);\n\t}\n\tV _cookedF(size_t i)\n\t{\n\t\tif (_nodeHasUpdate[i]) { return fou(_nodeFValue[i], \n\t\t\t\t\t\t _nodeUpdate[i],\n\t\t\t\t\t\t _nodeRangeStart[i],\n\t\t\t\t\t\t _nodeRangeEnd[i]); }\n\t\treturn _nodeFValue[i];\n\t}\n\tvoid _clearUpdate(size_t i)\n\t{\n\t\tif (!_nodeHasUpdate[i]) return;\n\t\tif (_isLeaf(i)) { _nodeFValue[i] = _cookedF(i); _nodeHasUpdate[i] = false; return;}\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedF(l), _cookedF(r));\n\t\t_nodeHasUpdate[i] = false;\n\t}\n\tvoid _addUpdate(size_t i, U u)\n\t{\n\t\tif (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; return; }\n\t\t_nodeUpdate[i] = uou(_nodeUpdate[i], u);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn _nodeRangeStart[i] == _nodeRangeEnd[i];\n\t}\n\tbool _isFragment(size_t i, size_t rangeStart, size_t rangeEnd)\n\t{\n\t\treturn rangeStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= rangeEnd;\n\t}\n\tbool _hasFragments(size_t i, size_t rangeStart, size_t rangeEnd)\n\t{\n\t\treturn _nodeRangeStart[i] <= rangeEnd && rangeStart <= _nodeRangeEnd[i];\n\t}\n\t// prettifiers\n\tstruct Handle\n\t{\n\t\timport std.ascii;\n\t\tsize_t _start, _end;\n\t\tThis* _parent;\n\t\tauto f()\n\t\t{\n\t\t\treturn _parent.rangeF(_start, _end);\n\t\t}\n\t\tauto u(U v)\n\t\t{\n\t\t\t_parent.rangeU(_start, _end, v);\n\t\t}\n\t\tstatic if (fName !is null)\n\t\t{\n\t\t\tmixin(q{alias }, fName, q{ = f;});\n\t\t}\n\t\tstatic if (uName !is null)\n\t\t{\n\t\t\tstatic if (uName[0].isAlphaNum)\n\t\t\t{\n\t\t\t\tmixin(q{alias }, uName, q{ = u;});\n\t\t\t}\n\t\t\telse static if (uName[0] != ' ')\n\t\t\t{\n\t\t\t\tref Handle opOpAssign(string operator)(U v) \n\t\t\t\tif (operator == uName)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tref Handle opAssign(U v)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)\n\t{\n\t\treturn [s, e-1];\n\t}\n\tauto opIndex(size_t[2] slice)\n\t{\n\t\treturn Handle(slice[0], slice[1], &this);\n\t}\n}\n"}], "src_uid": "3dc14d8d19938d9a5ed8323fe608f581"} {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main(string[ ] args) {\r\n immutable int N = ceil(sqrt((10 ^^ 9).to!double)).to!int;\r\n \r\n int[] ps;\r\n bool[N] isPr; isPr[] = true;\r\n for (int i = 2; i < N; ++i) {\r\n if (!isPr[i]) { continue; }\r\n ps ~= i;\r\n for (int j = i + i; j < N; j += i) { isPr[j] = false; }\r\n }\r\n\r\n debug { ps.length.writeln; }\r\n\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n\r\n while (t--) {\r\n int a, b, k;\r\n readf!\"%s %s %s\"(a, b, k);\r\n readln;\r\n\r\n if (k == 1) {\r\n writeln(a != b && (a % b == 0 || b % a == 0) ? \"YES\" : \"NO\");\r\n continue;\r\n }\r\n\r\n int countDivs(int x) {\r\n int res = 0;\r\n foreach (p; ps) {\r\n if (p > x / p) { break; }\r\n\r\n while (x % p == 0) {\r\n ++res;\r\n x /= p;\r\n }\r\n }\r\n\r\n if (x > 1) { ++res; }\r\n\r\n return res;\r\n }\r\n\r\n int resa = countDivs(a);\r\n int resb = countDivs(b);\r\n\r\n auto mx = resa + resb;\r\n\r\n writeln(k <= mx ? \"YES\" : \"NO\");\r\n }\r\n}", "positive_code": [{"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n immutable PRIME_MAX = 10 ^^ 6;\r\n int[] primes;\r\n bool[] isprime = new bool[PRIME_MAX];\r\n isprime[] = true;\r\n isprime[0] = isprime[1] = false;\r\n for (int i = 2; i < PRIME_MAX; ++i) {\r\n if (isprime[i]) {\r\n primes ~= i;\r\n for (int j = 2; i * j < PRIME_MAX; ++j)\r\n isprime[j * i] = false;\r\n }\r\n }\r\n int[] decomposition(int x) {\r\n int[] f;\r\n foreach(p; primes) {\r\n if (p * p > x) break;\r\n while (x % p == 0) {\r\n f ~= p;\r\n x /= p;\r\n }\r\n }\r\n if (x != 1) f ~= x;\r\n return f;\r\n }\r\n\r\n int tests;\r\n readf!\"%s\\n\"(tests);\r\n foreach(per_test; 0 .. tests) {\r\n int x, y, k;\r\n readf!\"%s %s %s\\n\"(x, y, k);\r\n int[] fx = decomposition(x);\r\n int[] fy = decomposition(y);\r\n if (k > fx.length + fy.length) \"NO\".writeln;\r\n else if (k >= 2 || (k == 1 && (x % y == 0 || y % x == 0) && x != y)) \"YES\".writeln;\r\n else \"NO\".writeln;\r\n }\r\n\r\n} // main"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n auto primes = primesUnder(1_000_000);\r\n void solve() {\r\n long a, b, k; readf(\"%d %d %d\\n\", &a, &b, &k);\r\n long minC, maxC;\r\n if (a != b && (a % b == 0 || b % a == 0)) {\r\n minC = 1;\r\n } else {\r\n minC = 2;\r\n }\r\n auto fa = factor(a, primes);\r\n auto fb = factor(b, primes);\r\n maxC = fa.values.sum + fb.values.sum;\r\n writeln(minC <= k && k <= maxC ? \"YES\" : \"NO\");\r\n }\r\n foreach (t; 0 .. T) solve();\r\n\r\n}\r\n\r\nlong[] primesUnder(int M) {\r\n auto isPrime = new bool[M+1]; {\r\n isPrime[] = true;\r\n isPrime[0] = isPrime[1] = false;\r\n }\r\n long[] primes;\r\n for (int x = 2; x <= M; x++) {\r\n if (isPrime[x]) {\r\n primes ~= x;\r\n for (int y = x+x; y <= M; y += x) {\r\n isPrime[y] = false;\r\n }\r\n }\r\n }\r\n return primes;\r\n}\r\n\r\nlong[long] factor(long x, long[] primes) {\r\n long[long] ret;\r\n foreach (p; primes) {\r\n if (p * p > x) break;\r\n int c = 0;\r\n while (x % p == 0) {\r\n c++;\r\n x /= p;\r\n }\r\n if (c > 0) {\r\n ret[p] = c;\r\n }\r\n }\r\n if (x > 1) {\r\n ret[x] = 1;\r\n }\r\n return ret;\r\n}\r\n"}, {"source_code": "import std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main(string[ ] args) {\r\n immutable int N = 10 ^^ 5;\r\n \r\n int[] ps;\r\n bool[N] isPr; isPr[] = true;\r\n for (int i = 2; i < N; ++i) {\r\n if (!isPr[i]) { continue; }\r\n ps ~= i;\r\n for (int j = i + i; j < N; j += i) { isPr[j] = false; }\r\n }\r\n\r\n debug { ps.length.writeln; }\r\n\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n\r\n while (t--) {\r\n int a, b, k;\r\n readf!\"%s %s %s\"(a, b, k);\r\n readln;\r\n\r\n if (k == 1) {\r\n writeln(a != b && (a % b == 0 || b % a == 0) ? \"YES\" : \"NO\");\r\n continue;\r\n }\r\n\r\n int countDivs(int x) {\r\n int res = 0;\r\n foreach (p; ps) {\r\n if (p > x / p) { break; }\r\n\r\n while (x % p == 0) {\r\n ++res;\r\n x /= p;\r\n }\r\n }\r\n\r\n if (x > 1) { ++res; }\r\n\r\n return res;\r\n }\r\n\r\n int resa = countDivs(a);\r\n int resb = countDivs(b);\r\n\r\n auto mx = resa + resb;\r\n\r\n writeln(k <= mx ? \"YES\" : \"NO\");\r\n }\r\n}"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main(string[ ] args) {\r\n immutable int N = ceil(sqrt((10 ^^ 9).to!double)).to!int;\r\n \r\n int[] ps;\r\n bool[N] isPr; isPr[] = true;\r\n for (int i = 2; i < N; ++i) {\r\n if (!isPr[i]) { continue; }\r\n ps ~= i;\r\n for (int j = i + i; j < N; j += i) { isPr[j] = false; }\r\n }\r\n\r\n debug { ps.length.writeln; }\r\n\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n\r\n while (t--) {\r\n int a, b, k;\r\n readf!\"%s %s %s\"(a, b, k);\r\n readln;\r\n\r\n if (k == 1) {\r\n writeln(a != b && (a % b == 0 || b % a == 0) ? \"YES\" : \"NO\");\r\n continue;\r\n }\r\n\r\n int countDivs(int x) {\r\n int res = 0;\r\n foreach (p; ps) {\r\n // if (p > x / p) { break; }\r\n\r\n while (x % p == 0) {\r\n ++res;\r\n x /= p;\r\n }\r\n }\r\n\r\n if (x > 1) { ++res; }\r\n\r\n return res;\r\n }\r\n\r\n int resa = countDivs(a);\r\n int resb = countDivs(b);\r\n\r\n auto mx = resa + resb;\r\n\r\n writeln(k <= mx ? \"YES\" : \"NO\");\r\n }\r\n}"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main(string[ ] args) {\r\n immutable int N = 10 ^^ 6;\r\n \r\n int[] ps;\r\n bool[N] isPr; isPr[] = true;\r\n for (int i = 2; i < N; ++i) {\r\n if (!isPr[i]) { continue; }\r\n ps ~= i;\r\n for (int j = i + i; j < N; j += i) { isPr[j] = false; }\r\n }\r\n\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n\r\n while (t--) {\r\n int a, b, k;\r\n readf!\"%s %s %s\"(a, b, k);\r\n readln;\r\n\r\n if (k == 1) {\r\n writeln(a != b && (a % b == 0 || b % a == 0) ? \"YES\" : \"NO\");\r\n continue;\r\n }\r\n\r\n int countDivs(int x) {\r\n int res = 0;\r\n foreach (p; ps) {\r\n if (p > x / p) { break; }\r\n\r\n while (x % p == 0) {\r\n ++res;\r\n x /= p;\r\n }\r\n }\r\n\r\n if (x > 1) { ++res; }\r\n\r\n return res;\r\n }\r\n\r\n int resa = countDivs(a);\r\n int resb = countDivs(b);\r\n\r\n auto mx = resa + resb;\r\n\r\n writeln(k <= mx ? \"YES\" : \"NO\");\r\n }\r\n}"}], "negative_code": [{"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n immutable PRIME_MAX = 10 ^^ 6;\r\n int[] primes;\r\n bool[] isprime = new bool[PRIME_MAX];\r\n isprime[] = true;\r\n isprime[0] = isprime[1] = false;\r\n for (int i = 2; i < PRIME_MAX; ++i) {\r\n if (isprime[i]) {\r\n primes ~= i;\r\n for (int j = 2; i * j < PRIME_MAX; ++j)\r\n isprime[j] = false;\r\n }\r\n }\r\n int[] decomposition(int x) {\r\n int[] f;\r\n foreach(p; primes) {\r\n if (p * p > x) break;\r\n while (x % p == 0) {\r\n f ~= p;\r\n x /= p;\r\n }\r\n }\r\n if (x != 1) f ~= x;\r\n return f;\r\n }\r\n\r\n int tests;\r\n readf!\"%s\\n\"(tests);\r\n foreach(per_test; 0 .. tests) {\r\n int x, y, k;\r\n readf!\"%s %s %s\\n\"(x, y, k);\r\n int[] fx = decomposition(x);\r\n int[] fy = decomposition(y);\r\n if (k > fx.length + fy.length) \"NO\".writeln;\r\n else if (k >= 2 || (k == 1 && (x % y == 0 || y % x == 0) && x != y)) \"YES\".writeln;\r\n else \"NO\".writeln;\r\n }\r\n\r\n} // main"}], "src_uid": "b58a18119ac8375f9ad21a282292a76c"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nreal solve (int n)\n{\n\tauto alpha = PI / n;\n\treal x = 0.0;\n\treal y = 0.0;\n\treal phi = 0.0;\n\tforeach (i; 0..n)\n\t{\n\t\tx += cos (phi);\n\t\ty += sin (phi);\n\t\tphi += alpha;\n\t}\n\treturn cos (alpha / 2) * hypot (y, x);\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\treadln.strip.to !(int).solve.writefln !(\"%.20f\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto n = readln.chomp.to!double * 2;\n auto t = 180 * (n - 2) / 2 / n * PI / 180.0;\n writefln(\"%.12f\", 0.5 * tan(t) * 2);\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tdouble PI = 3.14159265359;\n\tauto t = RD!int;\n\tauto ans = new double[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto rad = PI / n;\n\t\tans[ti] = 1.0;\n\t\tforeach (i; 0..n/2-1)\n\t\t{\n\t\t\tans[ti] += cos(rad*(i+1)) * 2;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twritefln(FMT_F, e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nreal solve (int n)\n{\n\tauto alpha = PI / n;\n\twriteln (alpha * 180.0 / PI);\n\treal x = 0.0;\n\treal y = 0.0;\n\treal phi = 0.0;\n\tforeach (i; 0..n)\n\t{\n\t\tx += cos (phi);\n\t\ty += sin (phi);\n\t\tphi += alpha;\n\t}\n\treturn cos (alpha / 2) * hypot (y, x);\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\treadln.strip.to !(int).solve.writefln !(\"%.20f\");\n\t}\n}\n"}], "src_uid": "0c7a476716445c535a61f4e81edc7f75"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n string s;\n\n void solve(long tc = -1)\n {\n RedBlackTree!long[2] subs = [redBlackTree!long(), redBlackTree!long()];\n auto sub = new long[cast(size_t) n];\n foreach(i, c; s)\n {\n long d = c == '0'? 0 : 1;\n if (subs.at(d).empty)\n {\n sub.at(i) = subs.at(0).length + subs.at(1).length + 1;\n subs.at(d ^ 1).insert(sub.at(i));\n }\n else\n {\n sub.at(i) = subs.at(d).front;\n subs.at(d).removeFront;\n subs.at(d^1).insert(sub.at(i));\n }\n }\n writeln(sub.fold!max);\n foreach(s; sub)\n write(s, \" \");\n writeln;\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans0 = new int[](t);\n\tauto ans1 = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tans1[ti].length = n;\n\n\t\tBinaryHeap!(Array!int, \"a > b\")[2] heap;\n\t\theap[s[0]-'0'].insert(1);\n\t\tans0[ti] = 1;\n\t\tans1[ti][0] = 1;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tauto x = s[i] - '0';\n\t\t\tint num;\n\t\t\tif (!heap[x^1].empty)\n\t\t\t{\n\t\t\t\tnum = heap[x^1].front; heap[x^1].removeFront;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t++ans0[ti];\n\t\t\t\tnum = ans0[ti];\n\t\t\t}\n\t\t\tans1[ti][i] = num;\n\t\t\theap[x].insert(num);\n\t\t}\n\t}\n\n\tforeach (ti; 0..t)\n\t{\n\t\twriteln(ans0[ti]);\n\t\tans1[ti].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio;\nimport std.string : strip;\nimport std.range : enumerate;\nimport std.container : DList;\nimport std.algorithm : joiner, map;\nimport std.conv : text;\n\nvoid main()\n{\n int t;\n readf!(\"%d\\n\")(t);\n\n foreach (i; 0..t) {\n int n;\n readf!(\"%d\\n\")(n);\n uint j = 1; // sequence index\n auto ones = DList!uint();\n auto zeros = DList!uint();\n auto a = new uint[n];\n\n foreach (idx, c; readln.strip.enumerate) {\n if (c == '1') {\n\tif (zeros.empty) {\n\t // assign a new subseq\n\t ones.insertBack(j);\n\t a[idx] = j;\n\t j++;\n\t} else {\n\t // add to sequence of zeros\n\t auto k = zeros.back;\n\t zeros.removeBack;\n\t a[idx] = k;\n\t ones.insertBack(k);\n\t}\n } else if (c == '0') {\n\tif (ones.empty) {\n\t zeros.insertBack(j);\n\t a[idx] = j;\n\t j++;\n\t} else {\n\t auto k = ones.back;\n\t ones.removeBack;\n\t a[idx] = k;\n\t zeros.insertBack(k);\n\t}\n }\n }\n\n writeln(j - 1);\n writeln(a.map!text.joiner(\" \"));\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans0 = new int[](t);\n\tauto ans1 = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tans1[ti].length = n;\n\n\t\tint cnt0, cnt1;\n\t\tint start = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (start == -1)\n\t\t\t\tstart = s[i] - '0';\n\t\t\tif (s[i] == '0')\n\t\t\t\t++cnt0;\n\t\t\telse\n\t\t\t\t++cnt1;\n\n\t\t\tint d;\n\t\t\tif (start == 0)\n\t\t\t\td = abs(cnt0 - cnt1);\n\t\t\telse\n\t\t\t\td = abs(cnt1 - cnt0);\n\n\t\t\tif (start != s[i]-'0')\n\t\t\t\t++d;\n\t\t\tauto x = d;\n\t\t\tans0[ti].chmax(x);\n\t\t\tans1[ti][i] = x;\n\t\t}\n\t}\n\n\tforeach (ti; 0..t)\n\t{\n\t\twriteln(ans0[ti]);\n\t\tans1[ti].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "de57b6b1aa2b6ec4686d1348988c0c63"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int limit = 2000;\r\n\r\nvoid main ()\r\n{\r\n\tint [int] answer;\r\n\r\n\tint ask (int w)\r\n\t{\r\n\t\tif (w !in answer)\r\n\t\t{\r\n\t\t\twriteln (\"? \", w);\r\n\t\t\tstdout.flush ();\r\n\t\t\tanswer[w] = readln.strip.to !(int);\r\n\t\t}\r\n\t\treturn answer[w];\r\n\t}\r\n\r\n\tauto n = readln.strip.to !(int);\r\n\tauto lo = n * 1 + (n - 1);\r\n\tauto hi = n * limit + (n - 1);\r\n\twhile (lo < hi)\r\n\t{\r\n\t\tauto me = (lo + hi) / 2;\r\n\t\tauto cur = ask (me);\r\n\t\tif (cur == 1)\r\n\t\t{\r\n\t\t\thi = me;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlo = me + 1;\r\n\t\t}\r\n\t}\r\n\r\n\tint res = lo;\r\n\tint total = res - (n - 1);\r\n\tdebug {writeln (\"total = \", lo);}\r\n\tfor (int h = 2; h <= n; h++)\r\n\t{\r\n\t\tint ideal = total + n - h;\r\n\t\tfor (int w = (ideal + h - 1) / h; w * h < res; w++)\r\n\t\t{\r\n\t\t\tdebug {writeln (\"h = \", h, \", w = \", w);}\r\n\t\t\tif (ask (w) == h)\r\n\t\t\t{\r\n\t\t\t\tres = w * h;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\twriteln (\"! \", res);\r\n\tstdout.flush ();\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10L^^9;\n\nlong Ask(long w) {\n writeln(\"? \", w);\n stdout.flush;\n long res = readLong;\n if (res == 0) {\n res = INF;\n }\n return res;\n}\n\nvoid main() {\n const N = readInt;\n \n long lo = 0, hi = 2010L * N;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n const res = Ask(mid);\n ((res == 1) ? hi : lo) = mid;\n }\n \n long ans = hi;\n foreach (h; 2 .. N + 1) {\n // check [hi - (h - 1), hi]\n const w = hi / h;\n const res = Ask(w);\n chmin(ans, w * res);\n }\n \n writeln(\"! \", ans);\n stdout.flush;\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10L^^9;\n\nlong Ask(long w) {\n writeln(\"? \", w);\n stdout.flush;\n int res = readInt;\n if (res == 0) {\n res = INF;\n }\n return res;\n}\n\nlong ans;\n\nvoid solve(long a, long b, long fa, long fb) {\n if (fa == fb) {\n return;\n }\n if (a + 1 == b) {\n debug {\n writeln(\"waf \", a, \" \", b, \" \", fa, \" \", fb);\n }\n if (a) chmin(ans, a * fa);\n if (b) chmin(ans, b * fb);\n return;\n }\n const mid = (a + b) / 2;\n const res = Ask(mid);\n solve(a, mid, fa, res);\n solve(mid, b, res, fb);\n}\n\nvoid main() {\n const N = readInt;\n ans = long.max;\n solve(0, 2010L * N, INF, 1);\n writeln(\"! \", ans);\n stdout.flush;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10L^^9;\n\nlong Ask(long w) {\n writeln(\"? \", w);\n stdout.flush;\n int res = readInt;\n if (res == 0) {\n res = INF;\n }\n return res;\n}\n\nlong ans;\n\nvoid solve(long a, long b, long fa, long fb) {\n if (fa == fb) {\n return;\n }\n if (a + 1 == b) {\n debug {\n writeln(\"waf \", a, \" \", b, \" \", fa, \" \", fb);\n }\n chmin(ans, a * fa);\n chmin(ans, b * fb);\n return;\n }\n const mid = (a + b) / 2;\n const res = Ask(mid);\n solve(a, mid, fa, res);\n solve(mid, b, res, fb);\n}\n\nvoid main() {\n const N = readInt;\n ans = long.max;\n solve(0, 2010L * N, INF, 1);\n writeln(\"! \", ans);\n stdout.flush;\n}\n"}], "src_uid": "8eb4ce3fb9f6220ab6dbc12819680c1e"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\ndchar[] getPath(long x, int mxb) {\n dchar[] ans;\n foreach_reverse (b; 0 .. mxb+1) {\n if (x == 0) { break; }\n \n if (x & (1L << b)) {\n x -= (1L << b);\n ans ~= 'R';\n } else { ans ~= 'L'; }\n }\n \n ans.popBack();\n \n return ans;\n}\n\ndchar[] toRealPath(dchar[] path, int mxb) { \n dchar[] realPath;\n \n foreach (e; path) {\n if (e == 'U' && !realPath.empty) { realPath.popBack(); }\n else if ((e == 'L' || e == 'R') && realPath.length < mxb) { realPath ~= e; }\n }\n \n return realPath;\n}\n\nlong getVal(dchar[] path, int mxb) {\n int lvl = mxb;\n long ans = (1L << mxb);\n foreach (e; path) {\n debug { writeln(ans, ' ', lvl,' ' , e); }\n \n lvl -= 1;\n long mv = (1L << lvl);\n if (e == 'L') { ans -= mv; }\n else { ans += mv; }\n }\n \n return ans;\n}\n\nvoid main()\n{\n long n;\n int q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n int mxb = bsr(n+1) - 1;\n \n debug { mxb.writeln; }\n \n while (q--) {\n long x;\n readf(\"%s\", &x);\n readln;\n \n auto path = getPath(x, mxb);\n \n auto s = readln.chomp;\n \n auto ans = path.chain(s).array.to!(dchar[]).toRealPath(mxb).getVal(mxb);\n \n ans.writeln;\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tlong n;\n\tint q;\n\twhile (readf (\" %s %s\", &n, &q) > 0)\n\t{\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tlong v;\n\t\t\treadf (\" %s\", &v);\n\t\t\treadln;\n\t\t\tauto s = readln.strip;\n\t\t\tforeach (c; s)\n\t\t\t{\n\t\t\t\tif (c == 'U')\n\t\t\t\t{\n\t\t\t\t\tif (v * 2 == n + 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlong u = v;\n\t\t\t\t\tlong p = 1;\n\t\t\t\t\twhile (!(u & 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tu >>= 1;\n\t\t\t\t\t\tp <<= 1;\n\t\t\t\t\t}\n\t\t\t\t\tu >>= 1;\n\t\t\t\t\tif (u & 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tv -= p;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tv += p;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (v & 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlong u = v;\n\t\t\t\t\tlong p = 1;\n\t\t\t\t\twhile (!(u & 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tu >>= 1;\n\t\t\t\t\t\tp <<= 1;\n\t\t\t\t\t}\n\t\t\t\t\tp >>= 1;\n\t\t\t\t\tif (c == 'L')\n\t\t\t\t\t{\n\t\t\t\t\t\tv -= p;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tv += p;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteln (v);\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\ndchar[] getPath(long x, int mxb) {\n dchar[] ans;\n foreach_reverse (b; 0 .. mxb+1) {\n if (x == 0) { break; }\n \n if (x & (1L << b)) {\n x -= (1L << b);\n ans ~= 'R';\n } else { ans ~= 'L'; }\n }\n \n ans.popBack();\n \n return ans;\n}\n\nlong getVal(dchar[] path, int mxb) {\n int lvl = mxb;\n long ans = (1L << mxb);\n foreach (e; path) {\n debug { writeln(ans, ' ', lvl,' ' , e); }\n \n if (lvl == mxb && e == 'U') { continue; }\n if (lvl == 0 && (e == 'L' || e == 'R')) { continue; }\n \n if (e == 'U') {\n ans += (1L << lvl);\n lvl += 1;\n } else {\n lvl -= 1;\n long mv = (1L << lvl);\n if (e == 'L') { ans -= mv; }\n else { ans += mv; }\n }\n }\n \n return ans;\n}\n\nvoid main()\n{\n long n;\n int q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n int mxb = bsr(n+1) - 1;\n \n debug { mxb.writeln; }\n \n while (q--) {\n long x;\n readf(\"%s\", &x);\n readln;\n \n auto path = getPath(x, mxb);\n \n debug { path.writeln; }\n \n auto s = readln.chomp;\n \n auto ans = getVal(path.chain(s).array.to!(dchar[]), mxb);\n \n ans.writeln;\n }\n}"}], "src_uid": "dc35bdf56bb0ac341895e543b001b801"} {"source_code": "module sigod.codeforces.p285A;\n\nimport std.stdio;\n\nvoid main()\n{\n\tint n, k;\n\tstdin.readf(\"%s %s\", &n, &k);\n\n\tforeach (ki; 1 .. k + 1) {\n\t\tstdout.write(n - ki + 1, \" \");\n\t}\n\n\tforeach (ni; 1 .. n - k) {\n\t\tstdout.write(ni, \" \");\n\t}\n\n\tstdout.write(n - k);\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tint [] a;\n\t\tforeach (i; 0..n - k)\n\t\t{\n\t\t\ta ~= k + i + 1;\n\t\t}\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\ta ~= k - i;\n\t\t}\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tint [] a;\n\t\tforeach (i; 0..n - k)\n\t\t{\n\t\t\ta ~= k + i + 1;\n\t\t}\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\ta ~= k - i;\n\t\t}\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n, k;\n int[] ans;\n readf(\"%d %d\", &n, &k);\n for (int i = k + 1 ; i >= 1 ; --i) {\n ans ~= i;\n }\n for (int i = k + 2 ; i <= n ; ++i) {\n ans ~= i;\n }\n foreach (v ; ans) {\n write(v);\n write(\" \");\n }\n write(\"\\n\");\n}\n"}], "negative_code": [], "src_uid": "75cc5b55c51217966cbdd639a68f0724"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int N; get(N);\r\n if (N < 100) {\r\n foreach (i; 1..N+1) {\r\n writefln!\"? %d\"(i);\r\n stdout.flush();\r\n int k; get(k);\r\n if (k == 1) return writefln!\"! %d\"(i);\r\n }\r\n }\r\n int l, r;\r\n\r\n writeln(\"? 1\"); stdout.flush(); get(l);\r\n writeln(\"? 2\"); stdout.flush(); get(r);\r\n if (l < r) return writeln(\"! 1\");\r\n\r\n writefln!\"? %d\"(N - 1); stdout.flush(); get(l);\r\n writefln!\"? %d\"(N); stdout.flush(); get(r);\r\n if (l > r) return writefln!\"! %d\"(N);\r\n\r\n // Left: l > r, Right: l < r\r\n l = 1; r = N-1;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n int ll, rr;\r\n writefln!\"? %d\"(m); stdout.flush(); get(ll);\r\n writefln!\"? %d\"(m + 1); stdout.flush(); get(rr);\r\n if (ll > rr) {\r\n l = m;\r\n } else {\r\n r = m;\r\n }\r\n }\r\n writefln!\"! %d\"(r);\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = new int [n + 2];\r\n\t\ta[] = -1;\r\n\t\ta[0] = int.max;\r\n\t\ta[$ - 1] = int.max;\r\n\r\n\t\tvoid ask (int pos)\r\n\t\t{\r\n\t\t\tif (a[pos] < 0)\r\n\t\t\t{\r\n\t\t\t\twriteln (\"? \", pos);\r\n\t\t\t\tstdout.flush ();\r\n\t\t\t\ta[pos] = readln.strip.to !(int);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint solve ()\r\n\t\t{\r\n\t\t\task (1);\r\n\t\t\task (2);\r\n\t\t\tif (a[1] < a[2])\r\n\t\t\t{\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\t\t\task (n);\r\n\t\t\task (n - 1);\r\n\t\t\tif (a[n] < a[n - 1])\r\n\t\t\t{\r\n\t\t\t\treturn n;\r\n\t\t\t}\r\n\r\n\t\t\tint lo = 1;\r\n\t\t\tint hi = n;\r\n\t\t\twhile (hi - lo > 2)\r\n\t\t\t{\r\n\t\t\t\tint me = (lo + hi) / 2;\r\n\t\t\t\task (me);\r\n\t\t\t\task (me + 1);\r\n\t\t\t\tif (a[me] < a[me + 1])\r\n\t\t\t\t{\r\n\t\t\t\t\thi = me + 1;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlo = me;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tforeach (i; 1..n + 1)\r\n\t\t\t{\r\n\t\t\t\tif (a[i] >= 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (a[i] < a[i - 1] && a[i] < a[i + 1])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tassert (false);\r\n\t\t}\r\n\r\n\t\tauto res = solve ();\r\n\t\twriteln (\"! \", res);\r\n\t\tstdout.flush ();\r\n\t\tbreak;\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nint N;\r\nint[] A;\r\n\r\nint[] cache;\r\n\r\nint Ask(int i) {\r\n if (cache[i] == -1) {\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n debug {\r\n cache[i] = A[i];\r\n } else {\r\n cache[i] = readInt();\r\n }\r\n }\r\n return cache[i];\r\n}\r\n\r\nvoid Answer(int i) {\r\n writefln(\"! %s\", i);\r\n stdout.flush;\r\n}\r\n\r\nvoid main() {\r\n N = readInt();\r\n debug {\r\n A = new int[N + 2];\r\n A[0] = A[N + 1] = N + 1;\r\n foreach (i; 1 .. N + 1) {\r\n A[i] = readInt();\r\n }\r\n }\r\n \r\n cache = new int[N + 2];\r\n cache[] = -1;\r\n cache[0] = cache[N + 1] = N + 1;\r\n \r\n int lo = 0, hi = N + 1;\r\n for (; lo + 2 < hi; ) {\r\n const mid = (lo + hi) / 2;\r\n const a = Ask(mid);\r\n const b = Ask(mid + 1);\r\n (a < b) ? (hi = mid + 1) : (lo = mid);\r\n }\r\n assert(lo + 2 == hi);\r\n Answer(lo + 1);\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nint[int] cache;\r\nint ask(int i) {\r\n if (i in cache) return cache[i];\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n return cache[i] = read!int;\r\n}\r\n\r\nvoid main() {\r\n int N = read!int;\r\n int l = 1, r = N;\r\n while (l < r) {\r\n int m = (l + r) / 2;\r\n int x = ask(m);\r\n int y = ask(m + 1);\r\n if (x < y) {\r\n r = m;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n writefln(\"! %s\", l);\r\n stdout.flush;\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nint[int] cache;\r\nint ask(int i) {\r\n if (i in cache) return cache[i];\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n return cache[i] = read!int;\r\n}\r\n\r\nvoid main() {\r\n int N = read!int;\r\n if (N == 1) {\r\n writeln(\"! 1\");\r\n stdout.flush;\r\n return;\r\n }\r\n if (N == 2) {\r\n int l = ask(1);\r\n if (l == 1) {\r\n writeln(\"! 1\");\r\n } else {\r\n writeln(\"! 2\");\r\n }\r\n stdout.flush;\r\n return;\r\n }\r\n int l = 1, r = N;\r\n int al = ask(l);\r\n int ar = ask(r);\r\n while (l + 2 < r) {\r\n //writeln([l, r]);\r\n int mli = (2*l + r) / 3;\r\n int mri = (l + 2*r) / 3;\r\n int aml = ask(mli);\r\n int amr = ask(mri);\r\n if (aml > amr) {\r\n l = mli;\r\n al = aml;\r\n } else {\r\n r = mri;\r\n ar = amr;\r\n }\r\n }\r\n //writeln([l, r]);\r\n //writeln(\"--\");\r\n int[] ks;\r\n int[] xs;\r\n for (int i = max(1, l-1); i <= min(N, r+1); i++) {\r\n ks ~= i;\r\n xs ~= ask(i);\r\n }\r\n int INF = 1<<28;\r\n for (int i = 1; i+1 < xs.length; i++) {\r\n //if ( (i-1 >= 0 ? xs[i-1] : INF) > xs[i] && xs[i] < (i+1<xs.length ? xs[i+1] : INF) ) {\r\n if (xs[i-1] > xs[i] && xs[i] < xs[i+1]) {\r\n writefln(\"! %s\", ks[i]);\r\n stdout.flush;\r\n return;\r\n }\r\n }\r\n if (xs[0] > xs.back) {\r\n writefln(\"! %s\", ks.back);\r\n } else {\r\n writefln(\"! %s\", ks[0]);\r\n }\r\n stdout.flush;\r\n return;\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nint[int] cache;\r\nint ask(int i) {\r\n if (i in cache) return cache[i];\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n return cache[i] = read!int;\r\n}\r\n\r\nvoid main() {\r\n int N = read!int;\r\n if (N == 1) {\r\n writeln(\"! 1\");\r\n return;\r\n }\r\n int l = 1, r = N;\r\n int al = ask(l);\r\n int ar = ask(r);\r\n while (l + 2 < r) {\r\n //writeln([l, r]);\r\n int mli = (2*l + r) / 3;\r\n int mri = (l + 2*r) / 3;\r\n int aml = ask(mli);\r\n int amr = ask(mri);\r\n if (aml > amr) {\r\n l = mli;\r\n al = aml;\r\n } else {\r\n r = mri;\r\n ar = amr;\r\n }\r\n }\r\n //writeln([l, r]);\r\n //writeln(\"--\");\r\n int INF = 1<<28;\r\n int[] ks = [0];\r\n int[] xs = [INF];\r\n for (int i = max(1, l-1); i <= min(N, r+1); i++) {\r\n ks ~= i;\r\n xs ~= ask(i);\r\n }\r\n ks ~= N+1;\r\n ks ~= INF;\r\n for (int i = 1; i+1 < xs.length; i++) {\r\n //if ( (i-1 >= 0 ? xs[i-1] : INF) > xs[i] && xs[i] < (i+1<xs.length ? xs[i+1] : INF) ) {\r\n if (xs[i-1] > xs[i] && xs[i] < xs[i+1]) {\r\n writefln(\"! %s\", ks[i]);\r\n stdout.flush;\r\n return;\r\n }\r\n }\r\n assert(false);\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nint[int] cache;\r\nint ask(int i) {\r\n if (i in cache) return cache[i];\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n return cache[i] = read!int;\r\n}\r\n\r\nenum int INF = 1<<28;\r\n\r\nvoid main() {\r\n int N = read!int;\r\n if (N == 1) {\r\n writeln(\"! 1\");\r\n stdout.flush;\r\n return;\r\n }\r\n int l = 1, r = N;\r\n int al = ask(l);\r\n int ar = ask(r);\r\n while (l + 2 < r) {\r\n //writeln([l, r]);\r\n int mli = (2*l + r) / 3;\r\n int mri = (l + 2*r) / 3;\r\n int aml = ask(mli);\r\n int amr = ask(mri);\r\n if (aml > amr) {\r\n l = mli;\r\n al = aml;\r\n } else {\r\n r = mri;\r\n ar = amr;\r\n }\r\n }\r\n //writeln([l, r]);\r\n //writeln(\"--\");\r\n int[] ks;\r\n int[] xs;\r\n for (int i = max(1, l-1); i <= min(N, r+1); i++) {\r\n ks ~= i;\r\n xs ~= ask(i);\r\n }\r\n for (int i = 0; i < xs.length; i++) {\r\n if ( (i-1 >= 0 ? xs[i-1] : INF) > xs[i] && xs[i] < (i+1<xs.length ? xs[i+1] : INF) ) {\r\n writefln(\"! %s\", ks[i]);\r\n stdout.flush;\r\n return;\r\n }\r\n }\r\n assert(false);\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nint[int] cache;\r\nint ask(int i) {\r\n if (i in cache) return cache[i];\r\n writefln(\"? %s\", i);\r\n stdout.flush;\r\n return cache[i] = read!int;\r\n}\r\n\r\nenum int INF = 1<<28;\r\n\r\nvoid main() {\r\n int N = read!int;\r\n if (N == 1) {\r\n writeln(\"! 1\");\r\n return;\r\n }\r\n int l = 1, r = N;\r\n int al = ask(l);\r\n int ar = ask(r);\r\n while (l + 2 < r) {\r\n //writeln([l, r]);\r\n int mli = (2*l + r) / 3;\r\n int mri = (l + 2*r) / 3;\r\n int aml = ask(mli);\r\n int amr = ask(mri);\r\n if (aml > amr) {\r\n l = mli;\r\n al = aml;\r\n } else {\r\n r = mri;\r\n ar = amr;\r\n }\r\n }\r\n //writeln([l, r]);\r\n //writeln(\"--\");\r\n int[] ks;\r\n int[] xs;\r\n for (int i = max(1, l-1); i <= min(N, r+1); i++) {\r\n ks ~= i;\r\n xs ~= ask(i);\r\n }\r\n for (int i = 0; i < xs.length; i++) {\r\n if ( (i-1 >= 0 ? xs[i-1] : INF) > xs[i] && xs[i] < (i+1<xs.length ? xs[i+1] : INF) ) {\r\n writefln(\"! %s\", ks[i]);\r\n stdout.flush;\r\n return;\r\n }\r\n }\r\n assert(false);\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int N; get(N);\r\n if (N < 100) {\r\n foreach (i; 1..N+1) {\r\n writefln!\"? %d\"(i);\r\n stdout.flush();\r\n int k; get(k);\r\n if (k == 1) return writefln!\"! %d\"(k);\r\n }\r\n }\r\n int l, r;\r\n\r\n writeln(\"? 1\"); stdout.flush(); get(l);\r\n writeln(\"? 2\"); stdout.flush(); get(r);\r\n if (l < r) return writeln(\"! 1\");\r\n\r\n writefln!\"? %d\"(N - 1); stdout.flush(); get(l);\r\n writefln!\"? %d\"(N); stdout.flush(); get(r);\r\n if (l > r) return writefln!\"! %d\"(N);\r\n\r\n // Left: l > r, Right: l < r\r\n l = 1; r = N-1;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n int ll, rr;\r\n writefln!\"? %d\"(m); stdout.flush(); get(ll);\r\n writefln!\"? %d\"(m + 1); stdout.flush(); get(rr);\r\n if (ll > rr) {\r\n l = m;\r\n } else {\r\n r = m;\r\n }\r\n }\r\n writefln!\"! %d\"(r);\r\n}"}], "src_uid": "c091ca39dd5708f391b52de63faac6b9"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n enum long mod = 1_000_000_000 + 7;\n long t;\n read(t);\n auto dp = new long[2_000_000 + 1];\n dp[1 .. 3] = [0, 0];\n foreach(i; 3 .. 2_000_000 + 1)\n {\n dp[i] = 2 * dp[i - 2] + dp[i - 1] + (i%3 == 0? 4 : 0);\n dp[i] %= mod;\n }\n while(t--)\n {\n long n;\n read(n);\n writeln(dp.at(n));\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 10 ^^ 9 + 7;\n\nvoid main ()\n{\n\tlong [] f = [0, 0, 0, 1, 1];\n\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\twhile (f.length <= n)\n\t\t{\n\t\t\tf ~= (f[$ - 1] + f[$ - 2] * 2 + !(f.length % 3)) % mod;\n\t\t}\n\t\twriteln ((f[n] * 4L) % mod);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tlong[] add = [0, 0, 0, 4, -4, 4];\n\tauto list = new long[](2*(10^^6));\n\tlist[2] = 4;\n\tlist[3] = 4;\n\tlist[4] = 12;\n\tforeach (i; 5..list.length)\n\t{\n\t\tauto x = add[(i-5)%6];\n\t\tlist[i] = list[i-1];\n\t\tlist[i].modm(2);\n\t\tlist[i].moda(x);\n\t}\n\t\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int-1;\n\t\tans[ti] = list[n];\n\t\t/*int[][] edges;\n\t\tedges.length = 1;\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tforeach (u; 0..edges.length)\n\t\t\t{\n\t\t\t\tif (edges[u].length == 3) continue;\n\t\t\t\tif (edges[u].length == 0)\n\t\t\t\t{\n\t\t\t\t\t++edges.length;\n\t\t\t\t\tedges[u] ~= cast(int)edges.length - 1;\n\t\t\t\t}\n\t\t\t\telse if (edges[u].length == 1)\n\t\t\t\t{\n\t\t\t\t\t++edges.length;\n\t\t\t\t\t++edges.length;\n\t\t\t\t\tedges[u] ~= cast(int)edges.length - 2;\n\t\t\t\t\tedges[u] ~= cast(int)edges.length - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint[] dfs(int u, int par)\n\t\t{\n\t\t\tint res;\n\t\t\tbool used;\n\t\t\tforeach (v; edges[u])\n\t\t\t{\n\t\t\t\tif (v == par) continue;\n\t\t\t\tauto r = dfs(v, u);\n\t\t\t\tif (r[1])\n\t\t\t\t\tused = true;\n\t\t\t\tres += r[0];\n\t\t\t}\n\t\t\tif (!used && edges[u].length == 3)\n\t\t\t{\n\t\t\t\t++res;\n\t\t\t\tused = true;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tused = false;\n\t\t\t}\n\t\t\treturn [res, used ? 1 : 0];\n\t\t}\n\t\twriteln(dfs(0, -1));*/\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "43ace9254c5d879d11e3484eacb0bcc4"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong solve(long[] a)\n{\n assert(a.length >= 3);\n long ans = a[$ - 1] - a[0];\n return max(ans + a[1] - a[0], ans + (a[$ - 1] - a[$ - 2]));\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = readln.splitter.map!(to!long).array.sort.array;\n long best = solve(a);\n foreach (cut ; 0 .. n - 3 + 1) {\n best = max(best, solve(a[0 .. $ - cut]));\n best = max(best, solve(a[cut .. $]));\n }\n writeln(best);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n = read!int;\r\n auto a = readarray!long;\r\n a.sort!(\"a > b\");\r\n long res1, res2;\r\n int minI = n - 1;\r\n foreach(i; 0 .. minI - 1) {\r\n if (abs(a[minI] - a[i]) + abs(a[i] - a[i+1]) > res1)\r\n res1 = abs(a[minI] - a[i]) + abs(a[i] - a[i+1]);\r\n }\r\n foreach(i; iota(n-1,1,-1).array) {\r\n if (abs(a[0] - a[i]) + abs(a[i] - a[i-1]) > res2)\r\n res2 = abs(a[0] - a[i]) + abs(a[i] - a[i-1]);\r\n }\r\n writeln(max(res1, res2));\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\tint res = 0;\r\n\t\tforeach (i; 2..n)\r\n\t\t{\r\n\t\t\tres = max (res, +(a[i] - a[i - 1] + a[i] - a[0]));\r\n\t\t}\r\n\t\treverse (a);\r\n\t\tforeach (i; 2..n)\r\n\t\t{\r\n\t\t\tres = max (res, -(a[i] - a[i - 1] + a[i] - a[0]));\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = readln.splitter.map!(to!long).array.sort.array;\n long ans = a[$ - 1] - a[0];\n ans = max(ans + a[1] - a[0], ans + (a[$ - 1] - a[$ - 2]));\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n = read!int;\r\n auto a = readarray!long;\r\n a.sort!(\"a > b\");\r\n long res;\r\n int minI = n - 1;\r\n foreach(i; 0 .. minI - 1) {\r\n if (abs(a[minI] - a[i]) + abs(a[i] - a[i+1]) > res)\r\n res = abs(a[minI] - a[i]) + abs(a[i] - a[i+1]);\r\n }\r\n writeln(res);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\twriteln (a[$ - 1] - a[0] + max (a[$ - 1] - a[$ - 2],\r\n\t\t a[1] - a[0]));\r\n\t}\r\n}\r\n"}], "src_uid": "7421b2392cb40f1cf0b7fd93c287f1eb"} {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{\r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n int n;\r\n readf(\"%s\", &n);\r\n readln;\r\n \r\n auto a = readln.splitter.map!(to!int).array;\r\n \r\n debug { a.writeln; }\r\n \r\n auto incoming = new int[] (a.length + 1);\r\n incoming[] = 0;\r\n \r\n long ans = 0;\r\n foreach (i, e; a) {\r\n int mx = min(i + e, a.length.to!int - 1);\r\n foreach (step; i + 2 .. mx + 1) {\r\n ++incoming[step];\r\n }\r\n \r\n int starts = max(0, e - 1 - incoming[i]);\r\n ans += starts;\r\n \r\n int carryover = max(0, incoming[i] - (e-1));\r\n incoming[i+1] += carryover;\r\n \r\n debug { ans.writeln; }\r\n }\r\n \r\n debug { incoming.writeln; }\r\n \r\n ans.writeln;\r\n }\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = readln.splitter.map !(to !(int)).array;\r\n\t\ts ~= 0;\r\n\t\tlong res = 0;\r\n\t\tauto p = iota (n + 1).array;\r\n\t\tfor (int i = 0; i < n; i++)\r\n\t\t{\r\n\t\t\tint add = max (0, s[i] - n + i);\r\n\t\t\tres += add;\r\n\t\t\ts[i] = max (0, s[i] - add);\r\n\t\t\twhile (s[i] > 1)\r\n\t\t\t{\r\n\t\t\t\tfor (int j = i; j < n; j += s[j] + 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s[j] <= 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tp[j] = p[j + 1];\r\n\t\t\t\t\t}\r\n\t\t\t\t\tj = p[j];\r\n\t\t\t\t\ts[j] = max (0, s[j] - 1);\r\n\t\t\t\t}\r\n\t\t\t\tres += 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const numCases = readInt();\r\n foreach (caseId; 0 .. numCases) {\r\n const N = readInt();\r\n auto S = new long[N];\r\n foreach (i; 0 .. N) {\r\n S[i] = readLong();\r\n }\r\n \r\n auto dp = new long[N];\r\n long ans;\r\n foreach (i; 0 .. N) {\r\n long now = dp[i];\r\n if (S[i] - 1 >= now) {\r\n ans += (S[i] - 1) - now;\r\n now = S[i] - 1;\r\n }\r\n if (i + 1 < N) {\r\n dp[i + 1] += now - (S[i] - 1);\r\n }\r\n foreach (j; i + 2 .. N) {\r\n if (j <= i + S[i]) {\r\n dp[j] += 1;\r\n }\r\n }\r\n }\r\n writeln(ans);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto S = RDA;\r\n\r\n\t\tauto imos = new long[](n+1);\r\n\t\tauto a = new long[](n+1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto d = S[i] - imos[i] - a[i];\r\n\t\t\tif (d >= 1)\r\n\t\t\t\tans[ti] += d - 1;\r\n\t\t\telse\r\n\t\t\t\ta[i+1] += (-d) + 1;\r\n\t\t\tauto l = cast(int)(i + 2);\r\n\t\t\tauto r = cast(int)(i + S[i] + 1);\r\n\t\t\tif (l <= n)\r\n\t\t\t\t++imos[l];\r\n\t\t\tif (r <= n)\r\n\t\t\t\t--imos[r];\r\n\t\t\timos[i+1] = min(imos[i+1] + imos[i], 10^^10);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto S = RDA;\r\n\r\n\t\tauto imos = new long[](n+1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto d = S[i] - imos[i];\r\n\t\t\tif (d >= 1)\r\n\t\t\t\tans[ti] += d - 1;\r\n\t\t\telse\r\n\t\t\t\timos[i+1] += (-d) + 1;\r\n\t\t\tauto l = cast(int)(i + 2);\r\n\t\t\tauto r = cast(int)(i + S[i] + 1);\r\n\t\t\tif (l <= n)\r\n\t\t\t\t++imos[l];\r\n\t\t\tif (r <= n)\r\n\t\t\t\t--imos[r];\r\n\t\t\timos[i+1] = min(imos[i+1] + imos[i], 10^^10);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto S = RDA;\r\n\r\n\t\tauto imos = new long[](n+1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto d = S[i] - imos[i];\r\n\t\t\tif (d > 1)\r\n\t\t\t\tans[ti] += d - 1;\r\n\t\t\telse\r\n\t\t\t\timos[i+1] += (-d) + 1;\r\n\t\t\tauto l = cast(int)(i + 2);\r\n\t\t\tauto r = cast(int)(i + S[i] + 1);\r\n\t\t\tif (l <= n)\r\n\t\t\t\t++imos[l];\r\n\t\t\tif (r <= n)\r\n\t\t\t\t--imos[r];\r\n\t\t\timos[i+1] = min(imos[i+1] + imos[i], 10^^10);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto S = RDA;\r\n\r\n\t\tauto imos = new long[](n+1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto d = S[i] - imos[i];\r\n\t\t\tif (d > 1)\r\n\t\t\t\tans[ti] += d - 1;\r\n\t\t\telse\r\n\t\t\t\timos[i+1] += (-d) + 1;\r\n\t\t\tauto l = cast(int)(i + 2);\r\n\t\t\tauto r = cast(int)(i + S[i] + 1);\r\n\t\t\tif (l <= n)\r\n\t\t\t\t++imos[l];\r\n\t\t\tif (r <= n)\r\n\t\t\t\t--imos[r];\r\n\t\t\timos[i+1] = min(imos[i+1] + imos[i], 10^^9);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto S = RDA;\r\n\r\n\t\tauto imos = new long[](n+1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto d = S[i] - imos[i];\r\n\t\t\tif (d > 1)\r\n\t\t\t\tans[ti] += d - 1;\r\n\t\t\telse\r\n\t\t\t\timos[i+1] += (-d) + 1;\r\n\t\t\tauto l = cast(int)(i + 2);\r\n\t\t\tauto r = cast(int)(i + S[i] + 1);\r\n\t\t\tif (l <= n)\r\n\t\t\t\t++imos[l];\r\n\t\t\tif (r <= n)\r\n\t\t\t\t--imos[r];\r\n\t\t\timos[i+1] += imos[i];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tint sn = 0;\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tsn += n;\r\n\t\tif (sn > 5000)\r\n\t\t{\r\n\t\t\tassert (false);\r\n\t\t}\r\n\t\tauto s = readln.splitter.map !(to !(int)).array;\r\n\t\tif (s.length != n)\r\n\t\t{\r\n\t\t\tassert (false);\r\n\t\t}\r\n\t\tlong res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tint add = max (0, s[i] - n + i);\r\n\t\t\tres += add;\r\n\t\t\ts[i] -= add;\r\n\t\t\twhile (s[i] > 1)\r\n\t\t\t{\r\n\t\t\t\tfor (int j = i; j < n; j += s[j] + 1)\r\n\t\t\t\t{\r\n\t\t\t\t\ts[j] = max (0, s[j] - 1);\r\n\t\t\t\t}\r\n\t\t\t\tres += 1;\r\n\t\t\t\twhile (n > 0 && s[n - 1] <= 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tn -= 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{\r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n int n;\r\n readf(\"%s\", &n);\r\n readln;\r\n \r\n auto a = readln.splitter.map!(to!int).array;\r\n \r\n debug { a.writeln; }\r\n \r\n auto incoming = new int[] (a.length + 1);\r\n \r\n long ans = 0;\r\n foreach (i, e; a) {\r\n int inside = min(e, a.length - i - 1);\r\n foreach (step; (inside+1).iota.drop(2)) {\r\n ++incoming[i + step];\r\n }\r\n \r\n auto additional = max(0, e - 1 - incoming[i]);\r\n ans += additional;\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}"}], "src_uid": "ac12faea4962613651afdc0b29537ef5"} {"source_code": "import std.stdio, std.string, std.conv, std.typecons;\nimport std.algorithm, std.range, std.array, std.container;\nimport std.math, std.numeric;\n\nalias Tuple!(int, \"l\", int, \"r\") Query;\n\nclass BIT {\n int n;\n int[] t;\n\n this(int n) {\n this.n = n;\n t = new int[n];\n }\n\n void inc(int x) {\n for (++x; x <= n; x += x & -x)\n ++t[x - 1];\n }\n\n int get(int x) {\n int res = 0;\n for (; x; x -= x & -x)\n res += t[x - 1];\n return res;\n }\n}\n\nvoid main() {\n int n, m;\n int[] p;\n Query[] q;\n\n scanf(\" %d %d\", &n, &m);\n p = new int[n];\n foreach (i; 0..n) scanf(\" %d\", &p[i]);\n q = new Query[m];\n foreach (i; 0..m) scanf(\" %d %d\", &q[i].l, &q[i].r), --q[i].l;\n\n int ma = reduce!max(p);\n \n int[] loc = new int[ma + 1];\n loc[] = -1;\n foreach (i; 0..n) loc[p[i]] = i;\n\n int[][] adj = new int[][n + 1];\n foreach (d; 1..ma + 1) {\n for (int dd = d; dd <= ma; dd += d) {\n int x = loc[d], y = loc[dd];\n if (x == -1 || y == -1) continue;\n if (x < y) swap(x, y);\n adj[x] ~= y;\n }\n }\n\n int[][] ln = new int[][n + 1];\n foreach (i; 0..m) {\n ln[q[i].r] ~= i;\n }\n\n int[] ans = new int[m];\n BIT t = new BIT(n);\n foreach (r; 0..n + 1) {\n foreach (i; ln[r]) ans[i] = t.get(r) - t.get(q[i].l);\n foreach (y; adj[r]) t.inc(y);\n }\n\n foreach (a; ans) printf(\"%d\\n\", a);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.typecons;\nimport std.algorithm, std.range, std.array, std.container;\nimport std.math, std.numeric;\n\nalias Tuple!(int, \"l\", int, \"r\") Query;\n\nclass BIT {\n int n;\n int[] t;\n\n this(int n) {\n this.n = n;\n t = new int[n];\n }\n\n void inc(int x) {\n for (++x; x <= n; x += x & -x)\n ++t[x - 1];\n }\n\n int get(int x) {\n int res = 0;\n for (; x; x -= x & -x)\n res += t[x - 1];\n return res;\n }\n}\n\nvoid main() {\n int n, m;\n scanf(\" %d %d\", &n, &m);\n auto p = new int[n];\n foreach (i; 0..n) scanf(\" %d\", &p[i]);\n auto q = new Query[m];\n foreach (i; 0..m) scanf(\" %d %d\", &q[i].l, &q[i].r), --q[i].l;\n\n int ma = reduce!max(p);\n \n auto loc = new int[ma + 1];\n loc[] = -1;\n foreach (i; 0..n) loc[p[i]] = i;\n\n auto adj = new int[][n + 1];\n foreach (d; p) {\n int x = loc[d];\n for (int dd = d; dd <= ma; dd += d) {\n int y = loc[dd]; if (y == -1) continue;\n if (x < y) adj[y] ~= x;\n else adj[x] ~= y;\n }\n }\n\n auto ln = new int[][n + 1];\n foreach (i; 0..m) ln[q[i].r] ~= i;\n\n auto ans = new int[m];\n BIT t = new BIT(n);\n foreach (r; 0..n + 1) {\n foreach (i; ln[r]) ans[i] = t.get(r) - t.get(q[i].l);\n foreach (y; adj[r]) t.inc(y);\n }\n\n foreach (a; ans) printf(\"%d\\n\", a);\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.typecons;\nimport std.algorithm, std.range, std.array, std.container;\nimport std.math, std.numeric;\n\nalias Tuple!(int, \"l\", int, \"r\") Query;\n\nclass BIT {\n int n;\n long[] t;\n\n this(int n) {\n this.n = n;\n t = new long[n];\n }\n\n void inc(int x) {\n for (++x; x <= n; x += x & -x)\n ++t[x - 1];\n }\n\n long get(int x) {\n long res = 0;\n for (; x; x -= x & -x)\n res += t[x - 1];\n return res;\n }\n}\n\nvoid main() {\n int n, m;\n int[] p;\n Query[] q;\n\n scanf(\" %d %d\", &n, &m);\n p = new int[n];\n foreach (i; 0..n) scanf(\" %d\", &p[i]);\n q = new Query[m];\n foreach (i; 0..m) scanf(\" %d %d\", &q[i].l, &q[i].r), --q[i].l;\n\n int ma = reduce!max(p);\n \n int[] loc = new int[ma + 1];\n loc[] = -1;\n foreach (i; 0..n) loc[p[i]] = i;\n\n int[][] adj = new int[][n + 1];\n foreach (d; 1..ma + 1) {\n for (int dd = d; dd <= ma; dd += d) {\n int x = loc[d], y = loc[dd];\n if (x == -1 || y == -1) continue;\n if (x < y) swap(x, y);\n adj[x] ~= y;\n }\n }\n\n int[][] ln = new int[][n + 1];\n foreach (i; 0..m) {\n ln[q[i].r] ~= i;\n }\n\n long[] ans = new long[m];\n BIT t = new BIT(n);\n foreach (r; 0..n + 1) {\n foreach (i; ln[r]) ans[i] = t.get(r) - t.get(q[i].l);\n foreach (y; adj[r]) t.inc(y);\n }\n\n foreach (a; ans) writeln(a);\n}\n"}], "negative_code": [], "src_uid": "213c24f8932d466b91f5c24142f56e5e"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = Mat!(M, 2);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),n, n)^^(k - 1))[];\n values.sum.writeln;\n}\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n pragma(inline, true);\n auto res = Mat!(T, dimension)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _slice = new T[](requiredSize);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tpragma(inline, true);\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t pragma(inline, true);\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t T mul;\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1)) if ((mul = this[i, k]) != T(0))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t pragma(inline, true);\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t pragma(inline, true);\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = Mat!(M, 2);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),n, n)^^(k - 1))[];\n values.sum.writeln;\n}\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n pragma(inline, true);\n auto res = Mat!(T, dimension)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _slice = new T[](requiredSize);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tpragma(inline, true);\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t pragma(inline, true);\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t pragma(inline, true);\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t pragma(inline, true);\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = StaticMat!(M, 100, 100);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = Mx.def(n, n, (i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0))^^(k - 1);\n auto sum = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n sum += values[i][j];\n return sum.writeln;\n}\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct StaticMat(T, maxSizes...)\n{\n enum dimension = maxSizes.length;\n size_t[dimension] size;\n this(S...)(S s)\n {\n static assert(s.length == dimension);\n size[] = [s];\n }\n StaticArray!(T, maxSizes) at;\n alias at this;\n static if (dimension == 2)\n {\n static auto def(size_t s0, size_t s1, T delegate(size_t, size_t) elem)\n {\n\tauto mat = StaticMat!(T, maxSizes)(s0, s1);\n\tforeach(i; 0 .. s0)\n\t foreach(j; 0 .. s1)\n\t mat[i][j] = elem(i, j);\n\treturn mat;\n }\n auto identity()\n {\n\treturn StaticMat!(T, maxSizes).def(size[0], size[1], (i, j) => T(cast(int)i == j));\n }\n auto opOpAssign(string op)(StaticMat!(T, maxSizes) b)\n\tif (op == \"*\")\n {\n\tdebug assert(this.size[1] == b.size[0]);\n\tauto n = this.size[0];\n\tauto m = this.size[1];\n\tauto r = b.size[1];\n\tauto res = StaticMat!(T, maxSizes)(n, r);\n\tforeach(i; 0 .. n) foreach(j; 0 .. r) res[i][j] = T(0);\n\tT mul;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. m)\n\t if ((mul = this[i][k]) != T(0))\n\t foreach(j; 0 .. r)\n\t\tres[i][j] += mul * b[k][j];\n\tversion(none)\n\t {\n\t this.size = res.size;\n\t foreach(i; 0 .. n) foreach(j; 0 .. r) this[i][j] = res[i][j];\n\t }\n\tthis = res;\n }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t pragma(inline, true);\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\ntemplate StaticArray(T, sizes...)\n{\n static if (sizes.length == 1)\n alias StaticArray = T[sizes[0]];\n else\n alias StaticArray = StaticArray!(T, sizes[1 .. $])[sizes[0]];\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byChunk;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = StaticMat!(M, 100, 100);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = Mx.def(n, n, (i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0))^^(k - 1);\n auto sum = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n sum += values[i][j];\n return sum.writeln;\n}\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct StaticMat(T, maxSizes...)\n{\n enum dimension = maxSizes.length;\n size_t[dimension] size;\n this(S...)(S s)\n {\n static assert(s.length == dimension);\n size[] = [s];\n }\n StaticArray!(T, maxSizes) at;\n alias at this;\n static if (dimension == 2)\n {\n static auto def(size_t s0, size_t s1, T delegate(size_t, size_t) elem)\n {\n\tauto mat = StaticMat!(T, maxSizes)(s0, s1);\n\tforeach(i; 0 .. s0)\n\t foreach(j; 0 .. s1)\n\t mat[i][j] = elem(i, j);\n\treturn mat;\n }\n auto identity()\n {\n\treturn StaticMat!(T, maxSizes).def(size[0], size[1], (i, j) => T(cast(int)i == j));\n }\n auto opOpAssign(string op)(StaticMat!(T, maxSizes) b)\n\tif (op == \"*\")\n {\n\tdebug assert(this.size[1] == b.size[0]);\n\tauto n = this.size[0];\n\tauto m = this.size[1];\n\tauto r = b.size[1];\n\tauto res = StaticMat!(T, maxSizes)(n, r);\n\tforeach(i; 0 .. n) foreach(j; 0 .. r) res[i][j] = T(0);\n\tT mul;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. m)\n\t if ((mul = this[i][k]) != T(0))\n\t foreach(j; 0 .. r)\n\t\tres[i][j] += mul * b[k][j];\n\tversion(none)\n\t {\n\t this.size = res.size;\n\t foreach(i; 0 .. n) foreach(j; 0 .. r) this[i][j] = res[i][j];\n\t }\n\tthis = res;\n }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t pragma(inline, true);\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\ntemplate StaticArray(T, sizes...)\n{\n static if (sizes.length == 1)\n alias StaticArray = T[sizes[0]];\n else\n alias StaticArray = StaticArray!(T, sizes[1 .. $])[sizes[0]];\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nenum mod = 1_000_000_000 + 7;\nint n;\nlong k;\nlong[] a;\nalias M = Mod!(long, mod);\nalias Mx = Matrix!(M, n, n);\n\nvoid main(string[] args)\n{\n n = next!int;\n k = next!long;\n a = next!long(n);\n auto mx = Mx(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n mx[i][j] = M((a[i] ^ a[j]).bitCnt % 3 == 0);\n auto pow = mx.pow(k - 1);\n auto res = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n res += pow[i][j];\n res.writeln;\n}\n\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = this[i][j] + other[i][j];\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t if ((factor = this[i][k]) != T(0))\n\t\tforeach(j; 0 .. n)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 1_000_000_000 + 7;\nvoid mul(T, size_t s)(out T[s][s] res, ref T[s][s] a, ref T[s][s] b)\n{\n foreach(i; 0 .. s) foreach(j; 0 .. s) res[i][j] = T(0);\n foreach(i; 0 .. s)\n foreach(k; 0 .. s)\n foreach(j; 0 .. s)\n\tres[i][j] = (res[i][j] + (a[i][k] * b[k][j])%mod)%mod;\n}\n\nvoid main(string[] args)\n{\n alias M = long;\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n debug writeln(n, k, a);\n M[100][100] pow, tmp, res;\n foreach(i, ai; a)\n foreach(j, aj; a)\n pow[i][j] = M((ai ^ aj).bitCnt % 3 == 0);\n foreach(i; 0 .. n) res[i][i] = M(1);\n k--;\n while(k)\n {\n if (k & 1)\n\t{\n\t mul(tmp, res, pow);\n\t res = tmp;\n\t}\n mul(tmp, pow, pow);\n pow = tmp;\n k >>= 1;\n }\n auto sum = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n sum = (sum + res[i][j]) % mod;\n sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(baseArray.length >= requiredSize);\n _slice = baseArray[0 .. requiredSize];\n }\n version(none) this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n static bool identitySet = false;\n static Mat!(T, 2) _identity;\n static T[100 * 100] _identityBuff;\n auto identity()\n {\n\tif (identitySet) return _identity;\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\t_identity = Mat!(T, 2)(_identityBuff, [n, n]);\n\tforeach(k; 0 .. n)\n\t _identity[k, k] = T(1);\n\tidentitySet = true;\n\treturn _identity;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nenum mod = 1_000_000_000 + 7;\nint n;\nlong k;\nlong[] a;\nalias M = Mod!(long, mod);\nalias Mx = Matrix!(M, n, n);\n\nvoid main(string[] args)\n{\n n = next!int;\n k = next!long;\n a = next!long(n);\n auto mx = Mx(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n mx[i][j] = M((a[i] ^ a[j]).bitCnt % 3 == 0);\n auto pow = mx.pow(k - 1);\n auto res = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n res += pow[i][j];\n res.writeln;\n}\n\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = this[i][j] + other[i][j];\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = StaticMat!(M, 100, 100);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.def(n, n, (i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0))^^(k - 1))[].sum.writeln;\n}\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct StaticMat(T, maxSizes...)\n{\n enum dimension = maxSizes.length;\n size_t[dimension] size;\n this(S...)(S s)\n {\n static assert(s.length == dimension);\n size[] = [s];\n this[][] = T(0);\n }\n StaticArray!(T, maxSizes) at;\n auto opSlice()\n {\n return (cast(T*)at.ptr)[0 .. arrSize!(maxSizes)][];\n }\n alias at this;\n static if (dimension == 2)\n {\n static auto def(size_t s0, size_t s1, T delegate(size_t, size_t) elem)\n {\n\tauto mat = StaticMat!(T, maxSizes)(s0, s1);\n\tforeach(i; 0 .. s0)\n\t foreach(j; 0 .. s1)\n\t mat[i][j] = elem(i, j);\n\treturn mat;\n }\n auto identity()\n {\n\treturn StaticMat!(T, maxSizes).def(size[0], size[1], (i, j) => T(cast(int)i == j));\n }\n auto opOpAssign(string op)(StaticMat!(T, maxSizes) b)\n\tif (op == \"*\")\n {\n\tdebug assert(this.size[1] == b.size[0]);\n\tauto n = this.size[0];\n\tauto m = this.size[1];\n\tauto r = b.size[1];\n\tauto res = StaticMat!(T, maxSizes)(n, r);\n\tres[][] = T(0);\n\tT mul;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. m)\n\t if ((mul = this[i][k]) != T(0))\n\t foreach(j; 0 .. r)\n\t\tres[i][j] += mul * b[k][j];\n\tthis = res;\n }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t pragma(inline, true);\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\ntemplate StaticArray(T, sizes...)\n{\n static if (sizes.length == 1)\n alias StaticArray = T[sizes[0]];\n else\n alias StaticArray = StaticArray!(T, sizes[1 .. $])[sizes[0]];\n}\n\ntemplate arrSize(S...)\n{\n static if (S.length == 1) enum arrSize = S[0];\n else enum arrSize = S[0] * arrSize!(S[1 .. $]);\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n this(FreeList!T next)\n {\n this.next = next;\n }\n}\nlong totalUse = 0;\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n totalUse++;\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t n, n)^^(k - 1))[]\n .sum\n .writeln;\n if(totalUse > 2)\n {\n a[-1] = 0;\n }\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2, allocator).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n size_t size;\n this(FreeList!T next)\n {\n this.next = next;\n this.size = 1 + (next is null? 0 : next.size);\n assert(this.size <= 3);\n }\n}\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t n, n)^^(k - 1))[]\n .sum\n .writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2, allocator).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nvoid main(string[] args)\n{\n GC.disable;\n alias M = Mod!(long, mod);\n alias Mx = Mat!(M, 2);\n M[100 * 100] basePow;\n long[100] baseA;\n auto n = next!int;\n auto k = next!long;\n auto a = Arr!long(baseA, [n]);\n foreach(ref ai; a[]) ai = next!long;\n (Mx.make((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t basePow,\n\t [n, n])^^(k - 1))[]\n .sum\n .writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension) make(T delegate(size_t, size_t) F, T[] baseArray, size_t[dimension] sizes)\n {\n auto res = Mat!(T, dimension)(baseArray, sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\t{\n\t auto row = res[i];\n\t foreach(j; 0 .. sizes[1])\n\t row[j] = F(i, j);\n\t}\n return res;\n }\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(baseArray.length >= requiredSize);\n _slice = baseArray[0 .. requiredSize];\n }\n version(none) this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n static bool identitySet = false;\n static Mat!(T, 2) _identity;\n static T[100 * 100] _identityBuff;\n auto identity()\n {\n\tif (identitySet) return _identity;\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\t_identity = Mat!(T, 2)(_identityBuff, [n, n]);\n\tforeach(k; 0 .. n)\n\t _identity[k, k] = T(1);\n\tidentitySet = true;\n\treturn _identity;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n size_t size;\n this(FreeList!T next)\n {\n this.next = next;\n this.size = 1 + (next is null? 0 : next.size);\n assert(this.size <= 5);\n }\n}\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t n, n)^^(k - 1))[]\n .sum\n .writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2, allocator).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = StaticMat!(M, 100, 100);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = Mx.def(n, n, (i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0))^^(k - 1);\n auto sum = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n sum += values[i][j];\n return sum.writeln;\n}\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct StaticMat(T, maxSizes...)\n{\n enum dimension = maxSizes.length;\n size_t[dimension] size;\n this(S...)(S s)\n {\n static assert(s.length == dimension);\n size[] = [s];\n }\n StaticArray!(T, maxSizes) at;\n alias at this;\n static if (dimension == 2)\n {\n static auto def(size_t s0, size_t s1, T delegate(size_t, size_t) elem)\n {\n\tauto mat = StaticMat!(T, maxSizes)(s0, s1);\n\tforeach(i; 0 .. s0)\n\t foreach(j; 0 .. s1)\n\t mat[i][j] = elem(i, j);\n\treturn mat;\n }\n auto identity()\n {\n\treturn StaticMat!(T, maxSizes).def(size[0], size[1], (i, j) => T(cast(int)i == j));\n }\n auto opOpAssign(string op)(StaticMat!(T, maxSizes) b)\n\tif (op == \"*\")\n {\n\tdebug assert(this.size[1] == b.size[0]);\n\tauto n = this.size[0];\n\tauto m = this.size[1];\n\tauto r = b.size[1];\n\tauto res = StaticMat!(T, maxSizes)(n, r);\n\tforeach(i; 0 .. n) foreach(j; 0 .. r) res[i][j] = T(0);\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. m)\n\t foreach(j; 0 .. r)\n\t res[i][j] += this[i][k] * b[k][j];\n\tthis.size = res.size;\n\tforeach(i; 0 .. n) foreach(j; 0 .. r) this[i][j] = res[i][j];\n }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t pragma(inline, true);\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\ntemplate StaticArray(T, sizes...)\n{\n static if (sizes.length == 1)\n alias StaticArray = T[sizes[0]];\n else\n alias StaticArray = StaticArray!(T, sizes[1 .. $])[sizes[0]];\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 1_000_000_000 + 7;\nvoid mul(T, size_t s)(out T[s][s] res, ref T[s][s] a, ref T[s][s] b)\n{\n foreach(i; 0 .. s) foreach(j; 0 .. s) res[i][j] = T(0);\n foreach(i; 0 .. s)\n foreach(k; 0 .. s)\n foreach(j; 0 .. s)\n\tres[i][j] = res[i][j] + a[i][k] * b[k][j];\n}\n\nvoid main(string[] args)\n{\n alias M = Mod!(long, mod);\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n debug writeln(n, k, a);\n M[100][100] pow, tmp, res;\n foreach(i, ai; a)\n foreach(j, aj; a)\n pow[i][j] = M((ai ^ aj).bitCnt % 3 == 0);\n foreach(i; 0 .. n) res[i][i] = M(1);\n k--;\n while(k)\n {\n if (k & 1)\n\t{\n\t mul(tmp, res, pow);\n\t res = tmp;\n\t}\n mul(tmp, pow, pow);\n pow = tmp;\n k >>= 1;\n }\n auto sum = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n sum = sum + res[i][j];\n sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(baseArray.length >= requiredSize);\n _slice = baseArray[0 .. requiredSize];\n }\n version(none) this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n static bool identitySet = false;\n static Mat!(T, 2) _identity;\n static T[100 * 100] _identityBuff;\n auto identity()\n {\n\tif (identitySet) return _identity;\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\t_identity = Mat!(T, 2)(_identityBuff, [n, n]);\n\tforeach(k; 0 .. n)\n\t _identity[k, k] = T(1);\n\tidentitySet = true;\n\treturn _identity;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(rep >= 0 && rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = Mat!(M, 2);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),n, n)^^(k - 1))[];\n values.sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _slice = new T[](requiredSize);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n this(FreeList!T next)\n {\n this.next = next;\n }\n}\nlong totalUse = 0;\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n totalUse++;\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t n, n)^^(k - 1))[]\n .sum\n .writeln;\n assert(totalUse <= 3);\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2, allocator).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n size_t size;\n this(FreeList!T next)\n {\n this.next = next;\n this.size = 1 + (next is null? 0 : next.size);\n assert(this.size <= 4);\n }\n}\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t n, n)^^(k - 1))[]\n .sum\n .writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2, allocator).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n this(FreeList!T next)\n {\n this.next = next;\n }\n}\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.make((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t n, n)^^(k - 1))[]\n .sum\n .writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) make(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto _identity = Mat!(T, 2, allocator)(n, n);\n\tforeach(i; 0 .. n)\n\t foreach(j; 0 .. n)\n\t _identity[i, j] = T(i == j);\n\treturn _identity;\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nvoid main(string[] args)\n{\n GC.disable;\n alias M = Mod!(long, mod);\n alias Mx = Mat!(M, 2);\n M[100 * 100] basePow;\n long[100] baseA;\n auto n = next!int;\n auto k = next!long;\n auto a = Arr!long(baseA, [n]);\n foreach(ref ai; a[]) ai = next!long;\n Mx mx = Mx(basePow, [n, n]);\n foreach(i, ai; a)\n foreach(j, aj; a)\n mx[i, j] = M((ai ^ aj).bitCnt % 3 == 0);\n (mx^^(k-1))[].sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(baseArray.length >= requiredSize);\n _slice = baseArray[0 .. requiredSize];\n }\n version(none) this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n static bool identitySet = false;\n static Mat!(T, 2) _identity;\n static T[100 * 100] _identityBuff;\n auto identity()\n {\n\tif (identitySet) return _identity;\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\t_identity = Mat!(T, 2)(_identityBuff, [n, n]);\n\tforeach(k; 0 .. n)\n\t _identity[k, k] = T(1);\n\tidentitySet = true;\n\treturn _identity;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(rep >= 0 && rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byChunk;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n this(FreeList!T next)\n {\n this.next = next;\n }\n}\nlong totalUse = 0;\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n totalUse++;\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t n, n)^^(k - 1))[]\n .sum\n .writeln;\n assert(totalUse <= 2);\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2, allocator).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n this(FreeList!T next)\n {\n this.next = next;\n }\n}\nlong totalUse = 0;\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n totalUse++;\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),n, n)^^(k - 1))[];\n if(totalUse > 3)\n {\n throw new Error(\"\");\n }\n values.sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2, allocator).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 1_000_000_000 + 7;\nvoid mul(T, size_t s)(out T[s][s] res, ref T[s][s] a, ref T[s][s] b)\n{\n foreach(i; 0 .. s) foreach(j; 0 .. s) res[i][j] = T(0);\n foreach(i; 0 .. s)\n foreach(k; 0 .. s)\n foreach(j; 0 .. s)\n\tres[i][j] += a[i][k] * b[k][j];\n}\n\nvoid main(string[] args)\n{\n alias M = Mod!(long, mod);\n alias Mx = Mat!(M, 2);\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n debug writeln(n, k, a);\n M[100 * 100] basePow, baseRes;\n Mx mx = Mx(basePow, [n, n]);\n Mx res = Mx(baseRes, [n, n]);\n foreach(i, ai; a)\n foreach(j, aj; a)\n mx[i, j] = M((ai ^ aj).bitCnt % 3 == 0);\n res = mx^^(k - 1);\n res[].sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(baseArray.length >= requiredSize);\n _slice = baseArray[0 .. requiredSize];\n }\n version(none) this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n static bool identitySet = false;\n static Mat!(T, 2) _identity;\n static T[100 * 100] _identityBuff;\n auto identity()\n {\n\tif (identitySet) return _identity;\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\t_identity = Mat!(T, 2)(_identityBuff, [n, n]);\n\tforeach(k; 0 .. n)\n\t _identity[k, k] = T(1);\n\tidentitySet = true;\n\treturn _identity;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(rep >= 0 && rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = StaticMat!(M, 100, 100);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = Mx.def(n, n, (i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0))^^(k - 1);\n auto sum = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n sum += values[i][j];\n return sum.writeln;\n}\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct StaticMat(T, maxSizes...)\n{\n enum dimension = maxSizes.length;\n size_t[dimension] size;\n this(S...)(S s)\n {\n static assert(s.length == dimension);\n size[] = [s];\n }\n StaticArray!(T, maxSizes) at;\n alias at this;\n static if (dimension == 2)\n {\n static auto def(size_t s0, size_t s1, T delegate(size_t, size_t) elem)\n {\n\tauto mat = StaticMat!(T, maxSizes)(s0, s1);\n\tforeach(i; 0 .. s0)\n\t foreach(j; 0 .. s1)\n\t mat[i][j] = elem(i, j);\n\treturn mat;\n }\n auto identity()\n {\n\treturn StaticMat!(T, maxSizes).def(size[0], size[1], (i, j) => T(cast(int)i == j));\n }\n auto opOpAssign(string op)(StaticMat!(T, maxSizes) b)\n\tif (op == \"*\")\n {\n\tdebug assert(this.size[1] == b.size[0]);\n\tauto n = this.size[0];\n\tauto m = this.size[1];\n\tauto r = b.size[1];\n\tauto res = StaticMat!(T, maxSizes)(n, r);\n\tforeach(i; 0 .. n) foreach(j; 0 .. r) res[i][j] = T(0);\n\tT mul;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. m)\n\t if ((mul = this[i][k]) != T(0))\n\t foreach(j; 0 .. r)\n\t\tres[i][j] += mul * b[k][j];\n\tthis.size = res.size;\n\tforeach(i; 0 .. n) foreach(j; 0 .. r) this[i][j] = res[i][j];\n }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t pragma(inline, true);\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\ntemplate StaticArray(T, sizes...)\n{\n static if (sizes.length == 1)\n alias StaticArray = T[sizes[0]];\n else\n alias StaticArray = StaticArray!(T, sizes[1 .. $])[sizes[0]];\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\n\nalias M = Mod!(long, mod);\nalias Mx = Mat!(M, 2);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto values = (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),n, n)^^(k - 1))[];\n values.sum.writeln;\n}\nulong bitCnt(long x)\n{\n pragma(inline, true);\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n pragma(inline, true);\n auto res = Mat!(T, dimension)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _slice = new T[](requiredSize);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tpragma(inline, true);\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t pragma(inline, true);\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t T mul;\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1)) if ((mul = this[i, k]) != T(0))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t pragma(inline, true);\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t T mul;\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tif ((mul = this[i, k]) != T(0))\n\t\t foreach(j; 0 .. res.dim(1))\n\t\t res[i, j] += mul * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t pragma(inline, true);\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\nenum mod = 1_000_000_000 + 7;\nclass FreeList(T)\n{\n T allocated;\n FreeList!T next = null;\n this(FreeList!T next)\n {\n this.next = next;\n }\n}\nlong totalUse = 0;\nFreeList!T alloc(T)(ref FreeList!T freeList)\n{\n if (freeList is null)\n {\n totalUse++;\n return new FreeList!T(null);\n }\n else\n {\n auto ret = freeList;\n freeList = freeList.next;\n ret.next = null;\n return ret;\n }\n}\nvoid free(T)(ref FreeList!T freeList, FreeList!T t)\n{\n debug assert(t.next is null);\n t.next = freeList;\n freeList = t;\n}\n\nalias M = Mod!(long, mod);\nFreeList!(M[100 * 100]) mAlloc;\nalias Mx = Mat!(M, 2, mAlloc);\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n (Mx.define((i, j) => M((a[i] ^ a[j]).bitCnt % 3 == 0),\n\t n, n)^^(k - 1))[]\n .sum\n .writeln;\n assert(totalUse <= 5);\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nstruct Mat(T, size_t dimension, alias allocator)\n{\n typeof(allocator) _allocatedNode;\n T[] _slice;\n size_t[dimension] _sizes;\n size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n static if (dimension == 2)\n static Mat!(T, dimension, allocator) define(S...)(T delegate(size_t, size_t) F, S sizes)\n {\n auto res = Mat!(T, dimension, allocator)(sizes);\n with(res)\n foreach(i; 0 .. sizes[0])\n\tforeach(j; 0 .. sizes[1])\n\t res[i, j] = F(i, j);\n return res;\n }\n this(S...)(S sizes)\n {\n static assert(sizes.length == dimension);\n _sizes[] = [sizes];\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n _allocatedNode = allocator.alloc;\n _slice = _allocatedNode.allocated[0 .. requiredSize];\n }\n void free()\n {\n allocator.free(_allocatedNode);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else \n {\n\tstatic assert(0);\n\tversion(none)\n\t {\n\t enum sliceDimension = dimension - i.length;\n\t size_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\t auto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n\t return Mat!(T, sliceDimension, allocator)(basePortion, remSizes);\n\t }\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\treturn Mat!(T, 2, allocator).define((i, j) => T(i == j), n, n);\n }\n bool canMultiply(alias alloc)(Mat!(T, 2, alloc) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2, allocator) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2, allocator)(this.dim(0), b.dim(1));\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t res.free;\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n static auto makeSafe(T t)\n {\n if (t >= 0) return Mod!(T, mod)(t % mod);\n return Mod!(T, mod)(t % mod + mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport core.memory;\n\nenum mod = 1_000_000_000 + 7;\nvoid mul(T, size_t s)(out T[s][s] res, ref T[s][s] a, ref T[s][s] b)\n{\n foreach(i; 0 .. s) foreach(j; 0 .. s) res[i][j] = T(0);\n foreach(i; 0 .. s)\n foreach(k; 0 .. s)\n foreach(j; 0 .. s)\n\tres[i][j] += a[i][k] * b[k][j];\n}\n\nvoid main(string[] args)\n{\n GC.disable;\n alias M = Mod!(long, mod);\n alias Mx = Mat!(M, 2);\n M[100 * 100] basePow;\n long[100] baseA;\n auto n = next!int;\n auto k = next!long;\n auto a = Arr!long(baseA, [n]);\n foreach(ref ai; a[]) ai = next!long;\n Mx mx = Mx(basePow, [n, n]);\n foreach(i, ai; a)\n foreach(j, aj; a)\n mx[i, j] = M((ai ^ aj).bitCnt % 3 == 0);\n (mx^^(k-1))[].sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(baseArray.length >= requiredSize);\n _slice = baseArray[0 .. requiredSize];\n }\n version(none) this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n static bool identitySet = false;\n static Mat!(T, 2) _identity;\n static T[100 * 100] _identityBuff;\n auto identity()\n {\n\tif (identitySet) return _identity;\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\t_identity = Mat!(T, 2)(_identityBuff, [n, n]);\n\tforeach(k; 0 .. n)\n\t _identity[k, k] = T(1);\n\tidentitySet = true;\n\treturn _identity;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(rep >= 0 && rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 1_000_000_000 + 7;\nvoid mul(T, size_t s)(out T[s][s] res, ref T[s][s] a, ref T[s][s] b)\n{\n foreach(i; 0 .. s) foreach(j; 0 .. s) res[i][j] = T(0);\n foreach(i; 0 .. s)\n foreach(k; 0 .. s)\n foreach(j; 0 .. s)\n\tres[i][j] += a[i][k] * b[k][j];\n}\n\nvoid main(string[] args)\n{\n alias M = Mod!(long, mod);\n alias Mx = Mat!(M, 2);\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n debug writeln(n, k, a);\n M[100 * 100] basePow, baseRes;\n Mx pow = Mx(basePow, [n, n]);\n Mx res = Mx(baseRes, [n, n]);\n foreach(i, ai; a)\n foreach(j, aj; a)\n pow[i, j] = M((ai ^ aj).bitCnt % 3 == 0);\n foreach(i; 0 .. n) res[i][i] = M(1);\n k--;\n while(k)\n {\n if (k & 1)\n\tres *= pow;\n pow *= pow;\n k >>= 1;\n }\n auto sum = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n sum += res[i][j];\n sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(baseArray.length >= requiredSize);\n _slice = baseArray[0 .. requiredSize];\n }\n version(none) this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n static bool identitySet = false;\n static Mat!(T, 2) _identity;\n static T[100 * 100] _identityBuff;\n auto identity()\n {\n\tif (identitySet) return _identity;\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\t_identity = Mat!(T, 2)(_identityBuff, [n, n]);\n\tforeach(k; 0 .. n)\n\t _identity[k, k] = T(1);\n\tidentitySet = true;\n\treturn _identity;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] += this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, long mod)\n{\n alias This = Mod!(T, mod);\n T rep;\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(rep >= 0 && rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = rep + b.rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = rep - b.rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This((rep * b.rep)%mod);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tthis.rep += b.rep;\n\tif (this.rep >= mod) this.rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tthis.rep -= b.rep;\n\tif (this.rep < 0) this.rep += mod;\n }\n else static if (op == \"*\")\n {\n\tthis.rep *= b.rep;\n\tthis.rep %= mod;\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n alias M = Mod!(long, 1_000_000_000 + 7);\n alias Mx = Mat!(M, 2);\n inputFile = stdin;\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n auto mx = Mx([n, n]);\n foreach(i, ai; a)\n foreach(j, aj; a)\n mx[i, j] = M((ai ^ aj).bitCnt % 3 == 0);\n debug foreach(i; 0 .. n) mx[i][].writeln;\n auto pmx = mx^^(k - 1);\n debug foreach(i; 0 .. n) pmx[i][].writeln;\n auto sum = M(0);\n foreach(i; 0 .. n)\n sum = sum + pmx[i][].sum;\n sum.rep.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nenum mod = 1_000_000_000 + 7;\nvoid mul(T, size_t s)(out T[s][s] res, ref T[s][s] a, ref T[s][s] b)\n{\n foreach(i; 0 .. s) foreach(j; 0 .. s) res[i][j] = T(0);\n foreach(i; 0 .. s)\n foreach(k; 0 .. s)\n foreach(j; 0 .. s)\n\tres[i][j] = (res[i][j] + (a[i][k] * b[k][j])%mod)%mod;\n}\n\nvoid main(string[] args)\n{\n alias M = long;\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n debug writeln(n, k, a);\n M[100][100] pow, tmp, res;\n foreach(i, ai; a)\n foreach(j, aj; a)\n pow[i][j] = M((ai ^ aj).bitCnt % 3 == 0);\n foreach(i; 0 .. n) res[i][i] = M(1);\n k--;\n while(k)\n {\n if (k & 1)\n\t{\n\t mul(tmp, res, pow);\n\t res = tmp;\n\t}\n mul(tmp, pow, pow);\n pow = tmp;\n k >>= 1;\n }\n auto sum = M(0);\n foreach(i; 0 .. n)\n foreach(j; 0 .. n)\n sum = sum + res[i][j];\n sum.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(baseArray.length >= requiredSize);\n _slice = baseArray[0 .. requiredSize];\n }\n version(none) this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n static bool identitySet = false;\n static Mat!(T, 2) _identity;\n static T[100 * 100] _identityBuff;\n auto identity()\n {\n\tif (identitySet) return _identity;\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\t_identity = Mat!(T, 2)(_identityBuff, [n, n]);\n\tforeach(k; 0 .. n)\n\t _identity[k, k] = T(1);\n\tidentitySet = true;\n\treturn _identity;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n version(none) auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n \n auto opOpAssign(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t static T[100 * 100] resBuff;\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)(resBuff, [this.dim(0), b.dim(1)]);\n\t res[][] = T(0);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t this[][] = res[][];\n\t return this;\n\t }\n \n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n pragma(inline, true);\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 8;\n const wordSize = 24;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (stdin.eof)\n currChunk = null;\n else\n currChunk = stdin.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n pragma(inline, true);\n while (_words.empty)\n {\n foreach(w; stdin.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n pragma(inline, true);\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "src_uid": "27126a9ab8fcbc25a2a521dbfd5ee6e1"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n Tuple!(int, int)[] arr;\n foreach (_; 0 .. n-1) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n arr ~= tuple(a, b);\n }\n \n if (arr.map!(t => t[1]).any!(x => x != n)) {\n writeln(\"NO\");\n return;\n }\n \n auto mn = arr.map!(t => t[0]).array;\n \n mn.sort();\n \n debug { mn.writeln; }\n \n if (mn.enumerate(1).any!(t => t[0] > t[1])) {\n writeln(\"NO\");\n return;\n }\n \n auto isFree = new bool[] (n+1);\n isFree[] = true;\n int nxt = 1;\n \n auto grouped = mn.group.array;\n \n Tuple!(int, int)[] ans;\n foreach (t; grouped) {\n int e = t[0], cnt = t[1];\n \n int[] cur;\n foreach (_; 1 .. cnt) {\n while (!isFree[nxt]) { ++nxt; }\n cur ~= nxt;\n isFree[nxt] = false;\n }\n \n cur ~= e;\n isFree[e] = false;\n \n foreach (a, b; lockstep(cur, cur.dropOne)) { ans ~= tuple(a, b); }\n \n ans ~= tuple(n, cur.front);\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto E = (N-1).iota.map!(_ => readln.split.map!(to!int).array).array;\n\n if (E.map!(e => e[1] != N).any) {\n writeln(\"NO\");\n return;\n }\n\n auto A = E.map!(e => e[0]).array;\n A.sort();\n\n foreach (i; 0..N-1) {\n if (A[i] < i + 1) {\n writeln(\"NO\");\n return;\n }\n }\n\n auto used = new int[](N+1);\n foreach (a; A) used[a] = true;\n auto ans = new int[](N-1);\n int start = 0;\n int x = 1;\n\n foreach (i; 0..N-1) {\n if (i == N - 2 || A[i] != A[i+1]) {\n ans[start] = A[i];\n foreach (j; start+1..i+1) {\n while (used[x]) ++x;\n used[x] = true;\n ans[j] = x;\n }\n start = i + 1;\n }\n }\n\n writeln(\"YES\");\n foreach (i; 0..ans.length.to!int - 1) {\n writeln(ans[i], \" \", ans[i+1]);\n }\n writeln(ans.back, \" \", N);\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto E = (N-1).iota.map!(_ => readln.split.map!(to!int).array).array;\n\n if (E.map!(e => e[1] != N).any) {\n writeln(\"NO\");\n return;\n }\n\n auto A = E.map!(e => e[0]).array;\n A.sort();\n\n foreach (i; 0..N-1) {\n if (A[i] < i + 1) {\n writeln(\"No\");\n return;\n }\n }\n\n auto used = new int[](N+1);\n foreach (a; A) used[a] = true;\n auto ans = new int[](N-1);\n int start = 0;\n int x = 1;\n\n foreach (i; 0..N-1) {\n if (i == N - 2 || A[i] != A[i+1]) {\n ans[start] = A[i];\n foreach (j; start+1..i+1) {\n while (used[x]) ++x;\n used[x] = true;\n ans[j] = x;\n }\n start = i + 1;\n }\n }\n\n writeln(\"YES\");\n foreach (i; 0..ans.length.to!int - 1) {\n writeln(ans[i], \" \", ans[i+1]);\n }\n writeln(ans.back, \" \", N);\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n Tuple!(int, int)[] arr;\n foreach (_; 0 .. n-1) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n arr ~= tuple(a, b);\n }\n \n if (arr.map!(t => t[1]).any!(x => x != n)) {\n writeln(\"NO\");\n return;\n }\n \n auto mn = arr.map!(t => t[0]).array;\n \n mn.sort();\n \n debug { mn.writeln; }\n \n if (mn.enumerate(1).any!(t => t[0] > t[1])) {\n writeln(\"NO\");\n return;\n }\n \n auto isFree = new bool[] (n+1);\n isFree[] = true;\n int nxt = 1;\n \n auto grouped = mn.group.array;\n \n Tuple!(int, int)[] ans;\n foreach (t; grouped) {\n int e = t[0], cnt = t[1];\n \n int[] cur;\n foreach (_; 1 .. cnt) {\n while (!isFree[nxt]) { ++nxt; }\n cur ~= nxt;\n }\n \n isFree[e] = false;\n cur ~= e;\n \n foreach (a, b; lockstep(cur, cur.dropOne)) { ans ~= tuple(a, b); }\n \n ans ~= tuple(n, cur.front);\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int[] arr;\n foreach (_; 0 .. n-1) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n arr ~= a;\n }\n \n debug { arr.writeln; }\n \n arr.sort();\n \n Tuple!(int, int)[] ans;\n auto lst = 1;\n foreach (i, e; arr) {\n if (e < i+1) {\n writeln(\"NO\");\n return;\n }\n \n if (i+1 < e) { continue; }\n \n foreach (v; lst .. e) {\n ans ~= tuple(v, v+1);\n }\n \n ans ~= tuple(lst, n);\n \n lst = e+1;\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n Tuple!(int, int)[] arr;\n foreach (_; 0 .. n-1) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n arr ~= tuple(a, b);\n }\n \n if (arr.map!(t => t[1]).any!(x => x != n)) {\n writeln(\"NO\");\n return;\n }\n \n auto mn = arr.map!(t => t[0]).array;\n \n mn.sort();\n \n debug { mn.writeln; }\n \n arr.sort();\n \n Tuple!(int, int)[] ans;\n auto lst = 1;\n foreach (i, e; mn) {\n if (e < i+1) {\n writeln(\"NO\");\n return;\n }\n \n if (i+1 < e) { continue; }\n \n foreach (v; lst .. e) {\n ans ~= tuple(v, v+1);\n }\n \n ans ~= tuple(lst, n);\n \n lst = e+1;\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n Tuple!(int, int)[] arr;\n foreach (_; 0 .. n-1) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n arr ~= tuple(a, b);\n }\n \n if (arr.map!(t => t[1]).any!(x => x != n)) {\n writeln(\"NO\");\n return;\n }\n \n auto mn = arr.map!(t => t[1]).array;\n \n mn.sort();\n \n debug { mn.writeln; }\n \n arr.sort();\n \n Tuple!(int, int)[] ans;\n auto lst = 1;\n foreach (i, e; mn) {\n if (e < i+1) {\n writeln(\"NO\");\n return;\n }\n \n if (i+1 < e) { continue; }\n \n foreach (v; lst .. e) {\n ans ~= tuple(v, v+1);\n }\n \n ans ~= tuple(lst, n);\n \n lst = e+1;\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}], "src_uid": "531746ba8d93a76d5bdf4bab67d9ba19"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto T = RD!int;\n\tauto ans = new long[](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDR.ARR;\n\t\tauto diff = new long[](n-k);\n\t\tforeach (j; k..n)\n\t\t{\n\t\t\tdiff[j-k] = a[j] - a[j-k];\n\t\t}\n\t\tauto pos = MIN_POS(diff);\n\t\tans[i] = (a[pos+k] + a[pos]) / 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint d = int.max;\n\t\tint x;\n\t\tforeach (i; 0..n - k)\n\t\t{\n\t\t\tint cur = a[i + k] - a[i];\n\t\t\tif (d > cur)\n\t\t\t{\n\t\t\t\td = cur;\n\t\t\t\tx = (a[i + k] + a[i]) / 2;\n\t\t\t}\n\t\t}\n\t\twriteln (x);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable nt = r.next!uint;\n foreach (tid; 0 .. nt) {\n immutable n = r.next!uint;\n immutable k = r.next!uint;\n auto a = r.nextA!int (n);\n long res = int.max;\n int x = int.max; \n foreach (i; k .. n) {\n int d = a[i] - a[i - k];\n if (res > d) {\n res = d;\n x = (a[i] + a[i - k]) / 2;\n }\n }\n writeln (x);\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\t\n\tint t = read.to!int;\n\tforeach(_; 0 .. t){\n\t\tint n = read.to!int;\n\t\tint k = read.to!int;\n\t\t\n\t\tlong[] as;\n\t\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\t\n\t\tlong best = as[k] - as[0];\n\t\tint bestleft = 0;\n\t\tforeach(i; 0 .. n - k){\n\t\t\tlong tmp = as[i + k] - as[i];\n\t\t\tif(tmp < best) best = tmp, bestleft = i;\n\t\t}\n\t\t\n\t\tlong ans = as[bestleft] + best / 2;\n\t\tans.writeln;\n\t\t\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\t\n\tint t = read.to!int;\n\tforeach(_; 0 .. t){\n\t\tint n = read.to!int;\n\t\tint k = read.to!int;\n\t\t\n\t\tlong[] as;\n\t\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\t\n\t\tlong best = as[k] - as[0];\n\t\tint bestleft = 0;\n\t\t{\n\t\t\tlong tmp = as[n - 1] - as[n - 1 - k];\n\t\t\tif(tmp < best) best = tmp, bestleft = n - 1 - k;\n\t\t}\n\t\tforeach(i; 0 .. n - k - 1){\n\t\t\tlong tmp = as[i + (k + 1)] - as[i];\n\t\t\tif(tmp < best) best = tmp, bestleft = i;\n\t\t}\n\t\t\n\t\tlong ans = as[bestleft] + best / 2;\n\t\tans.writeln;\n\t\t\n\t}\n}\n"}], "src_uid": "87e39e14d6e33427148c284b16a7fb13"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint a, b;\n\t\treadf !(\" %s %s\") (a, b);\n\t\twriteln ((a * b + 1) / 2);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tif (n % 2 == 0)\n\t\t\tans[ti] = (n/2) * m;\n\t\telse if (m % 2 == 0)\n\t\t\tans[ti] = (m/2) * n;\n\t\telse\n\t\t{\n\t\t\tans[ti] = (n/2) * m;\n\t\t\tans[ti] += (m+1)/2;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "19df5f3b8b31b763162c5331c1499529"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint [] [] a;\ndouble res;\n\nvoid recur (int v, int p, int d)\n{\n\tres += 1.0 / d;\n\tforeach (u; a[v])\n\t{\n\t\tif (u != p)\n\t\t{\n\t\t\trecur (u, v, d + 1);\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\ta = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\tscanf (\" %d %d\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tres = 0;\n\t\trecur (0, -1, 1);\n\t\twritefln (\"%.10f\", res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nint [] [] a;\ndouble res;\nint n;\n\nvoid recur (int v, int p, int d)\n{\n\tres += 1.0 / d;\n\tforeach (u; a[v])\n\t\tif (u != p)\n\t\t\trecur (u, v, d + 1);\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s\", &n))\n\t{\n\t\ta = new int [] [n + 1];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tres = 0;\n\t\trecur (1, 0, 1);\n\t\twritefln (\"%.7f\", res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "85b78251160db9d7ca1786e90e5d6f21"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto s = [0] ~ (cast(char[])readString).map!(c => c == 'a'? 1 : -1).array;\n\tauto ss = s.cumulativeFold!((a, b) => a + b).array;\n\tforeach(i; 1 .. n+1)\n\t\tforeach(j; i+1 .. n+1)\n\t\t{\n\t\t\tif (ss[i-1] == ss[j])\n\t\t\t{\n\t\t\t\treturn writeln(i, \" \", j);\n\t\t\t}\n\t\t}\n\treturn writeln(\"-1 -1\");\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.array, std.string, std.conv;\r\n \r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n foreach(_; 0..t)\r\n {\r\n int str_len;\r\n scanf(\"%d\", &str_len);\r\n getchar();\r\n auto str = readln.strip();\r\n // writeln(str);\r\n int[] check = new int[str_len];\r\n bool flag = true;\r\n for(int i = 0; i < str_len; i++)\r\n {\r\n if (flag == false)\r\n break;\r\n if (str[i] == 'a')\r\n {\r\n for (int j = i; j >= 0; j--)\r\n {\r\n check[j] += 1;\r\n if (check[j] == 0)\r\n {\r\n writeln(j + 1,' ', i + 1);\r\n flag = false;\r\n }\r\n }\r\n }\r\n else\r\n {\r\n for (int j = i; j >= 0; j--)\r\n {\r\n check[j] -= 1;\r\n if (check[j] == 0)\r\n {\r\n writeln(j + 1,' ', i + 1);\r\n flag = false;\r\n }\r\n }\r\n }\r\n }\r\n if (flag)\r\n writeln(\"-1 -1\");\r\n }\r\n}"}], "negative_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto s = [0] ~ (cast(char[])readString).map!(c => c == 'a'? 1 : -1).array;\n\tauto ss = s.cumulativeFold!((a, b) => a + b).array;\n\tforeach(i; 1 .. n)\n\t\tforeach(j; i+1 .. n)\n\t\t{\n\t\t\tif (ss[i-1] == ss[j])\n\t\t\t{\n\t\t\t\treturn writeln(i, \" \", j);\n\t\t\t}\n\t\t}\n\treturn writeln(\"-1 -1\");\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto s = [0] ~ (cast(char[])readString).map!(c => c == 'a'? 1 : -1).array;\n\tauto ss = s.cumulativeFold!((a, b) => a + b).array;\n\tforeach(i; 1 .. n)\n\t\tforeach(j; 1 .. n)\n\t\t{\n\t\t\tif (ss[i] == ss[j-1])\n\t\t\t{\n\t\t\t\treturn writeln(i, \" \", j);\n\t\t\t}\n\t\t}\n\treturn writeln(\"-1 -1\");\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "127d7f23a0ac8fcecccd687565d6f35a"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[][](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tauto p = RDA!int(-1);\n\t\tauto root = new int[](n);\n\t\troot[] = -1;\n\t\tans[i].length = n;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (root[j] != -1)\n\t\t\t{\n\t\t\t\tans[i][j] = ans[i][root[j]];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint pos = p[j];\n\t\t\troot[j] = j;\n\t\t\tint cnt = 1;\n\t\t\twhile (pos != j)\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\troot[pos] = j;\n\t\t\t\tpos = p[pos];\n\t\t\t}\n\t\t\tans[i][j] = cnt;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[][](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tauto p = RDA!int(-1);\n\t\tauto root = new int[](n);\n\t\troot[] = -1;\n\t\tans[i].length = n;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (root[j] != -1)\n\t\t\t{\n\t\t\t\tans[i][j] = ans[i][root[j]];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint pos = p[j];\n\t\t\troot[j] = j;\n\t\t\tint cnt = 1;\n\t\t\twhile (pos != j)\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\troot[pos] = j;\n\t\t\t\tpos = p[pos];\n\t\t\t}\n\t\t\tans[i][j] = cnt;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "345e76bf67ae4342e850ab248211eb0b"} {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable lim = 10^^6 + 1;\n\nint n, a;\nint[] c;\n\nvoid main() {\n scan(n, a);\n c = readln.split.to!(int[]);\n\n auto cnt = new int[](lim);\n auto ok = new bool[](lim);\n ok[] = true;\n\n foreach (ci ; c){\n cnt[ci]++;\n\n if (ci != a && cnt[ci] <= cnt[a]) {\n ok[ci] = false;\n }\n }\n\n foreach (i ; 1 .. lim) {\n if (i == a) continue;\n if (cnt[i] >= cnt[a] && ok[i]) {\n writeln(i);\n return;\n }\n }\n\n writeln(-1);\n\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\nclass SegTree(T){\nprivate:\n T[] data;\n int N;\n \npublic:\n int depth;\n \n this(int size){\n N = size;\n \n while(2^^depth < N){\n depth++;\n }\n \n data = new int[](2^^(depth + 1) - 1);\n }\n \n void update(int i, T x){\n i += 2^^depth - 1;\n data[i] = x;\n \n while(i > 0){\n i = (i - 1) / 2;\n data[i] = max(data[2*i + 1], data[2*i + 2]);\n }\n }\n \n T find(int s, int t, int k, int l, int r){\n if (r <= s || t <= l) {\n return 0;\n }\n \n if (s <= l && r <= t) {\n return data[k];\n }\n \n auto vl = find(s, t, 2*k + 1, l, (l + r) / 2);\n auto vr = find(s, t, 2*k + 2, (l + r) / 2, r);\n \n return max(vl, vr);\n }\n \n void print(){\n stderr.writefln(\"%(%s %)\", data);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto A = s[1];\n auto C = readln.split.map!(to!int).array;\n\n immutable int MAX = 10^^6 + 1;\n auto cnt = new bool[int][](MAX);\n foreach (i; 1..MAX) if (i != A) cnt[0][i] = true;\n auto cnt2 = new int[](MAX);\n\n bool[int] ans;\n foreach (i; 1..MAX) if (i != A) ans[i] = true;\n\n foreach (c; C) {\n if (c == A) {\n cnt2[c] += 1;\n int old = cnt2[c] - 1;\n foreach (i; cnt[old].keys) {\n if (i in ans) ans.remove(i);\n cnt2[i] = -1;\n }\n cnt[old].clear;\n } else if (cnt2[c] != -1) {\n cnt[cnt2[c]].remove(c);\n cnt2[c] += 1;\n cnt[cnt2[c]][c] = true;\n }\n }\n\n if (ans.keys.length == 0) writeln(-1);\n else writeln(ans.keys[0]);\n}\n"}], "negative_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable lim = 10^^6 + 1;\n\nint n, a;\nint[] c;\n\nvoid main() {\n scan(n, a);\n c = readln.split.to!(int[]);\n\n auto cnt = new int[](lim);\n auto sg = new SegTree!(int)(lim);\n\n foreach (ci ; c) {\n if (ci == a) {\n cnt[a]++;\n\n if (cnt[a] > sg.find(0, lim, 0, 0, 2^^sg.depth)) {\n writeln(-1);\n return;\n }\n }\n else {\n cnt[ci]++;\n sg.update(ci, cnt[ci]);\n }\n\n debug {\n //sg.print();\n writeln(\"cnt:\", cnt[0 .. 20]);\n }\n }\n\n foreach (i ; 1 .. lim) {\n if (i == a) continue;\n\n if (cnt[i] >= cnt[a]) {\n writeln(i);\n return;\n }\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\nclass SegTree(T){\nprivate:\n T[] data;\n int N;\n \npublic:\n int depth;\n \n this(int size){\n N = size;\n \n while(2^^depth < N){\n depth++;\n }\n \n data = new int[](2^^(depth + 1) - 1);\n }\n \n void update(int i, T x){\n i += 2^^depth - 1;\n data[i] = x;\n \n while(i > 0){\n i = (i - 1) / 2;\n data[i] = max(data[2*i + 1], data[2*i + 2]);\n }\n }\n \n T find(int s, int t, int k, int l, int r){\n if (r <= s || t <= l) {\n return 0;\n }\n \n if (s <= l && r <= t) {\n return data[k];\n }\n \n auto vl = find(s, t, 2*k + 1, l, (l + r) / 2);\n auto vr = find(s, t, 2*k + 2, (l + r) / 2, r);\n \n return max(vl, vr);\n }\n \n void print(){\n stderr.writefln(\"%(%s %)\", data);\n }\n}"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable lim = 10^^6 + 1;\n\nint n, a;\nint[] c;\n\nvoid main() {\n scan(n, a);\n c = readln.split.to!(int[]);\n\n auto cnt = new int[](lim);\n auto sg = new SegTree!(int)(lim);\n\n foreach (ci ; c) {\n if (ci == a) {\n cnt[a]++;\n\n if (cnt[a] > sg.find(0, lim, 0, 0, 2^^sg.depth)) {\n writeln(-1);\n return;\n }\n }\n else {\n cnt[ci]++;\n sg.update(ci, cnt[ci]);\n }\n\n debug {\n //sg.print();\n writeln(\"cnt:\", cnt[0 .. 20]);\n }\n }\n\n foreach (i ; 1 .. lim) {\n if (i == a) continue;\n\n if (cnt[i] > 0 && cnt[i] >= cnt[a]) {\n writeln(i);\n return;\n }\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\nclass SegTree(T){\nprivate:\n T[] data;\n int N;\n \npublic:\n int depth;\n \n this(int size){\n N = size;\n \n while(2^^depth < N){\n depth++;\n }\n \n data = new int[](2^^(depth + 1) - 1);\n }\n \n void update(int i, T x){\n i += 2^^depth - 1;\n data[i] = x;\n \n while(i > 0){\n i = (i - 1) / 2;\n data[i] = max(data[2*i + 1], data[2*i + 2]);\n }\n }\n \n T find(int s, int t, int k, int l, int r){\n if (r <= s || t <= l) {\n return 0;\n }\n \n if (s <= l && r <= t) {\n return data[k];\n }\n \n auto vl = find(s, t, 2*k + 1, l, (l + r) / 2);\n auto vr = find(s, t, 2*k + 2, (l + r) / 2, r);\n \n return max(vl, vr);\n }\n \n void print(){\n stderr.writefln(\"%(%s %)\", data);\n }\n}"}], "src_uid": "c6713175ad447b41b897a5904b7fe714"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n, m;\n readf!\" %d %d \"(n, m);\n foreach (i ; 0 .. m) {\n long x, y;\n readf!\" %d %d \"(x, y);\n }\n writeln(m < n ? \"YES\" : \"NO\");\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tforeach (i; 0..k)\r\n\t\t{\r\n\t\t\treadln;\r\n\t\t}\r\n\t\twriteln (k < n ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto usedY = new bool[N];\r\n auto usedX = new bool[N];\r\n foreach (i; 0 .. M) {\r\n int Y, X; readf(\"%d %d\\n\", &Y, &X);\r\n Y--; X--;\r\n usedY[Y] = true;\r\n usedX[X] = true;\r\n }\r\n bool f() {\r\n foreach (i; 0 .. N) {\r\n if (!usedY[i] || !usedX[i]) return true;\r\n }\r\n return false;\r\n }\r\n writeln(f() ? \"YES\" : \"NO\");\r\n}\r\n"}], "negative_code": [], "src_uid": "856b71ffb53f186bccd66c890ed0e099"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport core.stdc.stdio;\n\nint main()\n{\n int t = readInt!int;\n while (t--)\n {\n long x = readInt!long;\n long m111 = 0;\n bool can = false;\n int maxrep = 100;\n int i = 0;\n while (m111 <= x && i < maxrep)\n {\n if ((x - m111) % 11 == 0)\n {\n can = true;\n break;\n }\n m111 += 111;\n i++;\n }\n if (can) writeln(\"YES\"); else writeln(\"NO\");\n }\n return 0;\n}\n\n\n\n\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1526/problem/B\n// math\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\nwhile(t--) {\n long x;\n readf(\"%s\\n\", &x);\n if(x > 2_000) {\n \"YES\".writeln;\n continue;\n }\n bool found = false;\n for(long a = 0; a < 200; ++a) {\n for(long b = 0; b < 200; ++b) {\n if(x == a*11L + b*111L) {\n found = true;\n break;\n }\n }\n if(found) break;\n }\n if(found)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport core.stdc.stdio;\n\nint main()\n{\n int t = readInt!int;\n while (t--)\n {\n long x = readInt!long;\n long m111 = 0;\n bool can = false;\n int maxrep = 20;\n int i = 0;\n while (m111 <= x && i < maxrep)\n {\n if ((x - m111) % 11 == 0)\n {\n can = true;\n break;\n }\n m111 += 111;\n i++;\n }\n if (can) writeln(\"YES\"); else writeln(\"NO\");\n }\n return 0;\n}\n\n\n\n\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nbool check(long n)\n{\n for (long i = 0; i < 15; i++) {\n long n2 = n - i * 111L;\n if (n2 == 0)\n return true;\n if (n2 > 0 && n2 % 11L == 0)\n return true;\n }\n return false;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n\n foreach (casenum ; 0 .. t) {\n long n;\n readf!\" %d \"(n);\n if (check(n))\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1526/problem/B\n// math\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\nwhile(t--) {\n long x;\n readf(\"%s\\n\", &x);\n if(x > 2_000) {\n \"YES\".writeln;\n continue;\n }\n bool found = false;\n for(long a = 0; a < 200; ++a) {\n for(long b = 0; b < 20; ++b) {\n if(x == a*11L + b*111L) {\n found = true;\n break;\n }\n }\n if(found) break;\n }\n if(found)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1526/problem/B\n// math\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\nwhile(t--) {\n long x;\n readf(\"%s\\n\", &x);\n if(x > 2_000) {\n \"YES\".writeln;\n continue;\n }\n bool found = false;\n for(long a = 0; a < 100; ++a) {\n for(long b = 0; b < 1000; ++b) {\n if(x == a*11L + b*111L) {\n found = true;\n break;\n }\n }\n if(found) break;\n }\n if(found)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1526/problem/B\n// math\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\nwhile(t--) {\n long x;\n readf(\"%s\\n\", &x);\n if(x > 10_000) {\n \"YES\".writeln;\n continue;\n }\n bool found = false;\n for(long a = 0; a < 100; ++a) {\n for(long b = 0; b < 100; ++b) {\n if(x == a*11L + b*111L) {\n found = true;\n break;\n }\n }\n if(found) break;\n }\n if(found)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1526/problem/B\n// math\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\nwhile(t--) {\n long x;\n readf(\"%s\\n\", &x);\n bool found = false;\n for(long a = 0; a < 100; ++a) {\n for(long b = 0; b < 100; ++b) {\n if(x == a*11L + b*111L) {\n found = true;\n break;\n }\n }\n if(found) break;\n }\n if(found)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nbool check(long n)\n{\n long i, j;\n for (j = 0; j <= 11; j++) {\n long n2 = n - 111L * j;\n if (n2 > 0 && n2 % 11L == 0)\n return true;\n }\n return false;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n\n foreach (casenum ; 0 .. t) {\n long n;\n readf!\" %d \"(n);\n while (n >= 1222222221L)\n n -= 1222222221L;\n while (n >= 12222221L)\n n -= 12222221L;\n while (n >= 122221L)\n n -= 122221L;\n while (n >= 1221L)\n n -= 1221L;\n\n if (check(n))\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nbool check(long n)\n{\n auto a = [11L, 111L, 1111L, 11111L, 111111L, 1111111L, 11111111L, 111111111L, 1111111111L];\n foreach_reverse (v ; a) {\n n -= n / v * v;\n }\n return n == 0;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n\n foreach (casenum ; 0 .. t) {\n long n;\n readf!\" %d \"(n);\n if (check(n))\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n"}], "src_uid": "e5e937f080b20eaec5f12f1784ae6427"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nalias Tuple!(long, \"x\", long, \"y\", long, \"r\") Circle;\n\nbool include(Circle c1, Circle c2) {\n auto d2 = (c1.x - c2.x)^^2 + (c1.y - c2.y)^^2;\n auto r2 = (c1.r - c2.r)^^2;\n return c1.r > c2.r && d2 <= r2;\n}\n\nreal area(Circle c1) {\n return c1.r * c1.r * PI;\n}\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto C = new Circle[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!long);\n C[i] = Circle(s[0], s[1], s[2]);\n }\n C.sort!\"a.r > b.r\"();\n\n auto edges = new int[][](N);\n int[] roots;\n\n foreach (i; 0..N) {\n bool included = false;\n for (int j = i - 1; j >= 0; j--) {\n if (include(C[j], C[i])) {\n edges[j] ~= i;\n included = true;\n break;\n }\n }\n if (!included) roots ~= i;\n }\n\n real ans = 0;\n\n void dfs(int n, int p, int d) {\n if (d < 2) ans += area(C[n]);\n else if (d % 2 == 0) ans -= area(C[n]);\n else ans += area(C[n]);\n foreach (m; edges[n]) if (m != p) dfs(m, n, d+1);\n }\n\n\n foreach (i; roots) dfs(i, -1, 0);\n\n writefln(\"%.9f\", ans);\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nint[][1001] adj;\ndouble[3][1001] dp;\nbool[1001] vis;\ntup[] circles;\n\nll sqdist(tup c1, tup c2){\n return (c1[1] - c2[1])^^2 + (c1[2] - c2[2])^^2;\n}\n\ndouble area(tup c){\n double ar = PI * to!double(c[0]^^2);\n return ar;\n}\n\nvoid dfs(int cur){\n assert(!vis[cur]);\n vis[cur] = 1;\n double dp0 = 0, dp1 = 0, dp2 = 0;\n foreach(v; adj[cur]){\n dfs(v);\n dp0 += dp[v][0];\n dp1 += dp[v][1];\n dp2 += dp[v][2];\n }\n double curarea = area(circles[cur]);\n dp[cur][0] = (-curarea) + dp1;\n dp[cur][1] = max(curarea + dp0, (-curarea) + dp2);\n dp[cur][2] = curarea + dp1;\n}\n\n\nvoid play(){\n int n;\n n = rd!int;\n ll x, y, r;\n foreach(i; 0..n){\n x = rd, y = rd, r = rd;\n circles ~= tup(r, x, y);\n }\n sort(circles);\n\n // Make Trees\n foreach(i; 0..n){\n foreach(j; i+1..n){\n if(sqdist(circles[i], circles[j]) < circles[i][0]^^2 + circles[j][0]^^2){\n adj[j] ~= i;\n break;\n }\n }\n }\n\n // DFS and add DP value\n double res = 0;\n foreach_reverse(i; 0..n){\n if(!vis[i]){\n dfs(i);\n show(dp[i][1], dp[i][2]);\n res += max(dp[i][1], dp[i][2]);\n }\n }\n writefln(\"%.9f\", res);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}], "negative_code": [], "src_uid": "56a13208f0a9b2fad23756f39acd64af"} {"source_code": "import std.stdio, std.algorithm, std.string;\n\nvoid main()\n{\n int w, l;\n readf(\" %s %s\", w, l);\n\n int[] a = new int[w-1];\n\n foreach (ref t; a) readf(\" %s\", t);\n\n int[] b = new int[w-l];\n\n foreach (i; 0 .. l)\n {\n b[0] += a[i];\n }\n\n foreach (i; 1 .. b.length)\n {\n b[i] = b[i-1] - a[i-1] + a[i-1+l];\n }\n\n int mn = int.max;\n\n foreach (t; b)\n {\n mn = min(mn, t);\n }\n\n writeln(mn);\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int len, w;\n readf(\"%s %s\", &w, &len);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int ans = 10 ^^ 9 + 23;\n int cur = 0;\n foreach (i; 0 .. len-1) {\n cur += arr[i];\n }\n \n foreach (i; len-1 .. w-1) {\n cur += arr[i];\n ans = min(ans, cur);\n cur -= arr[i - (len-1)];\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int w, l; readV(w, l);\n int[] a; readA(w-1, a);\n\n auto ac = cumulativeSum(a);\n\n auto calc(int k)\n {\n foreach (i; l..w)\n if (ac[i-l..i] < k) return true;\n return false;\n }\n\n auto bs = iota(ac[0..$]+1).map!(k => tuple(k, calc(k))).assumeSorted!\"a[1] < b[1]\";\n writeln(bs.lowerBound(tuple(0, true)).back[0]);\n}\n\nclass CumulativeSum(T)\n{\n size_t n;\n T[] s;\n\n this(T[] a)\n {\n n = a.length;\n s = new T[](n+1);\n s[0] = T(0);\n foreach (i; 0..n) s[i+1] = s[i] + a[i];\n }\n\n T opSlice(size_t l, size_t r) { return s[r]-s[l]; }\n size_t opDollar() { return n; }\n}\nauto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\tint[100010] a;\n\tint n, m;\n\n\treadf(\"%s %s\", &n, &m);\n\treadln;\n\n\tfor (int i = 1; i < n - 1; ++i) readf(\"%s \", &a[i]);\n\treadf(\"%s\", &a[n - 1]);\n\treadln;\n\n\tfor (int i = 1; i < n; ++i) a[i] += a[i - 1];\n\n\tint ans = 1000000000;\n\tfor (int i = m; i < n; ++i) ans = min(ans, a[i] - a[i - m]);\n\twriteln(ans);\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int w, l; readV(w, l);\n int[] a; readA(w-1, a);\n\n auto ac = cumulativeSum(a);\n\n auto calc(int k)\n {\n foreach (i; l+1..w+1)\n if (ac[i-l+1..i] > k) return false;\n return true;\n }\n\n auto bs = iota(ac[0..$]+1).map!(k => tuple(k, calc(k))).assumeSorted!\"a[1] < b[1]\";\n writeln(bs.upperBound(tuple(0, false)).front[0]);\n}\n\nclass CumulativeSum(T)\n{\n size_t n;\n T[] s;\n\n this(T[] a)\n {\n n = a.length;\n s = new T[](n+1);\n s[0] = T(0);\n foreach (i; 0..n) s[i+1] = s[i] + a[i];\n }\n\n T opSlice(size_t l, size_t r) { return s[r]-s[l]; }\n size_t opDollar() { return n; }\n}\nauto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int w, l; readV(w, l);\n int[] a; readA(w-1, a);\n\n auto ac = cumulativeSum(a);\n\n auto calc(int k)\n {\n foreach (i; l..w+1)\n if (ac[i-l+1..i] > k) return false;\n return true;\n }\n\n auto bs = iota(ac[0..$]+1).map!(k => tuple(k, calc(k))).assumeSorted!\"a[1] < b[1]\";\n writeln(bs.upperBound(tuple(0, false)).front[0]);\n}\n\nclass CumulativeSum(T)\n{\n size_t n;\n T[] s;\n\n this(T[] a)\n {\n n = a.length;\n s = new T[](n+1);\n s[0] = T(0);\n foreach (i; 0..n) s[i+1] = s[i] + a[i];\n }\n\n T opSlice(size_t l, size_t r) { return s[r]-s[l]; }\n size_t opDollar() { return n; }\n}\nauto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }\n"}], "src_uid": "4cd68ef3dafc4d3d19629574e8315b9c"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [] [int] s;\n\t\tforeach (int i, ref c; a)\n\t\t{\n\t\t\ts[c] ~= i;\n\t\t}\n\n\t\tauto answer = new int [n];\n\t\tanswer[] = int.max;\n\t\tforeach (k, v; s)\n\t\t{\n\t\t\tint len = max (v.front, n - 1 - v.back);\n\t\t\tforeach (i; 1..v.length)\n\t\t\t{\n\t\t\t\tlen = max (len, v[i] - v[i - 1] - 1);\n\t\t\t}\n\t\t\tanswer[len] = min (answer[len], k);\n\t\t}\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tanswer[i] = min (answer[i], answer[i - 1]);\n\t\t}\n\t\tforeach (ref c; answer)\n\t\t{\n\t\t\tif (c == int.max)\n\t\t\t{\n\t\t\t\tc = -1;\n\t\t\t}\n\t\t}\n\n\t\twritefln !(\"%(%s %)\") (answer);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int(-1);\n\t\t\n\t\tauto pos = new int[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tpos[a[i]] ~= i;\n\t\t}\n\t\tauto diff = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (pos[i].empty)\n\t\t\t{\n\t\t\t\tdiff[i] = n+1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint d = pos[i][0] + 1;\n\t\t\tforeach (j; 1..pos[i].length)\n\t\t\t{\n\t\t\t\td.chmax(pos[i][j] - pos[i][j-1]);\n\t\t\t}\n\t\t\td.chmax(n-pos[i][$-1]);\n\t\t\tdiff[i] = d;\n\t\t}\n\t\tauto num = new int[](n+2);\n\t\tnum[] = int.max;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tnum[diff[i]].chmin(i);\n\t\t}\n\n\t\tans[ti].length = n;\n\t\tint last = int.max;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlast.chmin(num[i+1]);\n\t\t\tif (last == int.max)\n\t\t\t\tans[ti][i] = -1;\n\t\t\telse\n\t\t\t\tans[ti][i] = last+1;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\te.map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "b7abfb1103bb1796c8f89653c303d7dc"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long c, d;\n readln.formattedRead!\" %d %d \"(c, d);\n if (c > d)\n swap(c, d);\n if ((d - c) % 2 == 1) {\n writeln(-1);\n } else if (c == d) {\n writeln(c == 0 ? 0 : 1);\n } else {\n writeln(2);\n }\n }\n}\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto c = readInt!int;\n\tauto d = readInt!int;\n\tauto diff = abs(c - d);\n\tif (c == d && c == 0)\n\t{\n\t\treturn writeln(0);\n\t}\n\tif (diff % 2 == 0)\n\t{\n\t\twriteln(1 + int(diff != 0));\n\t}\n\telse\n\t{\n\t\twriteln(-1);\n\t}\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint c, d;\r\n\t\treadf !(\" %s %s\") (c, d);\r\n\t\tauto total = c + d;\r\n\t\tif (total % 2 != 0)\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tint res = 0;\r\n\t\tif (total != 0)\r\n\t\t{\r\n\t\t\tauto half = total / 2;\r\n\t\t\tc -= half;\r\n\t\t\td -= half;\r\n\t\t\tres += 1;\r\n\t\t}\r\n\t\tif (c != 0 || d != 0)\r\n\t\t{\r\n\t\t\tres += 1;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "8e7c0b703155dd9b90cda706d22525c9"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr.sort();\n \n auto ans = cast(long)(arr[n-1] - arr[0]) * (arr[$-1] - arr[n]);\n \n auto sz = arr[$-1] - arr[0];\n foreach (i; 1 .. n) {\n ans = min(ans, cast(long)sz * (arr[i+n-1] - arr[i]));\n }\n ans.writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tlong res = (a[n - 1] - a[0]) * 1L * (a[$ - 1] - a[$ - n]);\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tres = min (res, (a[i + n] - a[i + 1]) * 1L *\n\t\t\t (a[$ - 1] - a[0]));\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[2 * N];\n foreach (i; 0 .. 2 * N) {\n A[i] = readLong();\n }\n A.sort;\n \n long ans = (A[N - 1] - A[0]) * (A[2 * N - 1] - A[N]);\n foreach (i; 1 .. N) {\n chmin(ans, (A[i + N - 1] - A[i]) * (A[2 * N - 1] - A[0]));\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr.sort();\n \n auto ans = cast(long)(arr[n-1] - arr[0]) * (arr[$-1] - arr[n]);\n \n ans.writeln;\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[2 * N];\n foreach (i; 0 .. 2 * N) {\n A[i] = readLong();\n }\n A.sort;\n \n long ans = 1;\n ans *= (A[N - 1] - A[0]);\n ans *= (A[2 * N - 1] - A[N]);\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "cda1179c51fc69d2c64ee4707b97cbb3"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n auto g = new int[][n+1];\n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto trace = make!(DList!int);\n trace.insertBack(1);\n \n auto step = new int[n+1];\n step[] = 0;\n step[1] = 1;\n \n outer: foreach (i; 2 .. n+1) {\n auto v = trace.back;\n \n foreach (u; g[v]) {\n if (step[u] == 0) {\n step[u] = i;\n trace.insertBack(u);\n break;\n }\n \n if (i - step[u] <= k) { continue; }\n \n while (trace.front != u) { trace.removeFront(); }\n break outer;\n }\n }\n \n auto ans = trace.array;\n ans.length.writeln;\n ans.writefln!\"%(%s %)\";\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n auto g = new int[][n+1];\n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto trace = make!(DList!int);\n auto vis = new bool[n+1];\n vis[] = false;\n auto curIn = make!(RedBlackTree!int);\n auto curOrd = make!(DList!int);\n \n curIn.insert(1);\n trace.insertBack(1);\n curOrd.insertBack(1);\n vis[1] = true;\n outer: while (true) {\n auto v = curOrd.back;\n foreach (u; g[v]) {\n if (u in curIn) { continue; }\n \n debug { writeln(v, ' ', u, ' ', curIn); }\n \n if (curIn.length == k) {\n if (vis[u]) {\n while (trace.front != u) { trace.removeFront(); }\n break outer;\n }\n \n auto prev = curOrd.front;\n curOrd.removeFront();\n curIn.removeKey(prev);\n }\n \n vis[u] = true;\n curOrd.insertBack(u);\n trace.insertBack(u);\n curIn.insert(u);\n \n break;\n }\n }\n \n auto ans = trace.array;\n ans.length.writeln;\n ans.writefln!\"%(%s %)\";\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n auto g = new int[][n+1];\n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n g[v] ~= u;\n }\n \n auto vis = new bool[n+1];\n vis[] = false;\n auto curIn = make!(RedBlackTree!int);\n auto curOrd = make!(DList!int);\n \n curIn.insert(1);\n curOrd.insertBack(1);\n vis[1] = true;\n outer: while (true) {\n auto v = curOrd.back;\n foreach (u; g[v]) {\n if (u in curIn) { continue; }\n \n debug { writeln(v, ' ', u, ' ', curIn); }\n \n if (curIn.length == k) {\n if (vis[u]) {\n curOrd.insertBack(u);\n break outer;\n }\n \n auto prev = curOrd.front;\n curOrd.removeFront();\n curIn.removeKey(prev);\n }\n \n vis[u] = true;\n curOrd.insertBack(u);\n curIn.insert(u);\n \n break;\n }\n }\n \n writeln(k+1);\n curOrd.array.writefln!\"%(%s %)\";\n}"}], "src_uid": "250c0e647d0f2ff6d86db01675192c9f"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tforeach(_; 0 .. rint){\n\t\tlong n = rint, m = rint;\n\t\tlong k = m + 1;\n\t\tlong u = n - m;\n\t\tlong x = u / k, y = (u + k - 1) / k;\n\t\tlong i = k - (u % k), j = u % k;\n\t\t\n\t\tlong ans = n * (n + 1) / 2 - i * x * (x + 1) / 2 - j * y * (y + 1) / 2;\n\t\tans.writeln;\n\t}\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto mn = (n - m) / (m+1);\n auto mxcnt = (n - m) % (m+1);\n auto mncnt = m+1 - mxcnt;\n \n auto mnval = (mn+1).to!long * mn / 2;\n auto mntot = mnval * mncnt;\n \n auto mx = mn+1;\n auto mxval = (mx+1).to!long * mx / 2;\n auto mxtot = mxval * mxcnt;\n \n auto all = (n+1).to!long * n / 2;\n \n auto ans = all - mntot - mxtot;\n \n debug { writeln(all, ' ', mn, ' ', mncnt, ' ', mnval, ' ', mxtot); }\n \n ans.writeln;\n }\n}"}, {"source_code": "import std.stdio : writeln;\n\nstruct IO {\n string readToken() {\n import std.range : empty, front, popFront, split;\n import std.stdio : readln;\n\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n\n int readInt() {\n import std.conv : to;\n\n return readToken.to!int;\n }\n\n string[] tokens;\n}\n\nlong binom2(int n) {\n return n * (n + 1L) >> 1;\n}\n\nvoid main() {\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int m = io.readInt;\n int sz = (n - m) / (m + 1);\n int cnt = (n - m) % (m + 1);\n writeln(binom2(n) - (m + 1 - cnt) * binom2(sz) - cnt * binom2(sz + 1));\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m;\n\n void solve(long tc = -1)\n {\n auto z = n - m;\n auto c0 = (m + 1 - z % (m + 1));\n auto c1 = z % (m + 1);\n auto total = n * (n + 1) / 2;\n auto perbox = z / (m + 1);\n auto withz = (perbox * (perbox + 1) / 2) * c0 + ((perbox + 1) * (perbox + 2) / 2) * c1;\n writeln(total - withz);\n }\n}\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W)\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, string))\n {\n static assert(isDynamicArray!(typeOfField)\n , \" A field with dimension initialization UDA must be a dynamic array.\");\n enum uda = getUDAs!(fieldSymbol, string)[0];\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [{"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m;\n\n void solve(long tc = -1)\n {\n auto k = (m - n) / 2;\n writeln((n - k) * m - (m * (m - 1) / 2));\n }\n}\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W)\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, string))\n {\n static assert(isDynamicArray!(typeOfField)\n , \" A field with dimension initialization UDA must be a dynamic array.\");\n enum uda = getUDAs!(fieldSymbol, string)[0];\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m;\n\n void solve(long tc = -1)\n {\n if (m == 0)\n {\n writeln(0);\n return;\n }\n auto k = (n - m) / 2;\n writeln((n - k) * (m + k) - (m * (m - 1) / 2));\n }\n}\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W)\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, string))\n {\n static assert(isDynamicArray!(typeOfField)\n , \" A field with dimension initialization UDA must be a dynamic array.\");\n enum uda = getUDAs!(fieldSymbol, string)[0];\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "src_uid": "7458f44802c134de6fed7b4de84ea68c"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong n, k, x;\n\nlong xorp(long x, long y, long param)\n{\n long ans = 0;\n long ansmul = 1;\n while (x > 0 || y > 0) {\n long digitx = x % k;\n long digity = y % k;\n long ansdigit;\n switch (param & 7) {\n case 0:\n ansdigit = 0;\n break;\n case 1:\n ansdigit = k - 1;\n break;\n case 2:\n ansdigit = digitx;\n break;\n case 3:\n ansdigit = (k + digity - digitx) % k;\n break;\n case 4:\n ansdigit = (k + digitx - digity) % k;\n break;\n case 5:\n ansdigit = (digity + digitx) % k;\n break;\n case 6:\n ansdigit = (2 * k - digity - digitx) % k;\n break;\n default:\n ansdigit = digity;\n break;\n }\n ans += ansdigit * ansmul;\n x /= k;\n y /= k;\n ansmul *= k;\n }\n return ans;\n}\n\nbool solve(long param, bool function(long) judge)\n{\n long param1 = param & 7;\n param >>= 3;\n long param2 = param & 7;\n param >>= 3;\n long param3 = param & 7;\n param >>= 3;\n long param4 = param & 7;\n param >>= 3;\n long param5 = param & 7;\n param >>= 3;\n long param6 = param & 7;\n param >>= 3;\n\n long distortion = 0;\n foreach (i ; 0 .. n) {\n if (i % 2 == 0) {\n if (judge(xorp(distortion, i, param1)))\n return true;\n distortion = xorp(distortion, xorp(distortion, i, param2), param3);\n } else {\n if (judge(xorp(distortion, i, param4)))\n return true;\n distortion = xorp(distortion, xorp(distortion, i, param5), param6);\n }\n }\n return false;\n}\n\nbool interactive_judge(long y)\n{\n writeln(y);\n stdout.flush;\n return readln.strip == \"1\";\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n auto a = readln.strip.split.map!(to!long).array;\n n = a[0];\n k = a[1];\n solve(0x0001C8ED, &interactive_judge);\n }\n}\n", "positive_code": [{"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\nimport std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n while(tests--) {\r\n int n, k, r;\r\n readf!\"%s %s\\n\"(n, k);\r\n stdout.writefln!\"0\";\r\n stdout.flush;\r\n readf!\"%s\\n\"(r);\r\n int kXor(int x, int y) {\r\n int c = 0, p = 1;\r\n while(x > 0 || y > 0) {\r\n int a = x % k; x /= k;\r\n int b = y % k; y /= k;\r\n c += ((a - b + k) % k) * p;\r\n p *= k;\r\n }\r\n return c;\r\n }\r\n if (r == 0) {\r\n foreach(i; 1 .. n) {\r\n if (i % 2 == 0) {\r\n stdout.writefln!\"%s\"(kXor(i, i - 1));\r\n stdout.flush;\r\n }\r\n else {\r\n stdout.writefln!\"%s\"(kXor(i - 1, i));\r\n stdout.flush;\r\n }\r\n readf!\"%s\\n\"(r);\r\n if (r == 1) {\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n} // main\r\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong xork(long x, long y, long k)\n{\n long ans = 0;\n long ansmul = 1;\n while (ansmul < 10000000) {\n long digitx = x % k;\n long digity = y % k;\n long ansdigit = (digitx + digity) % k;\n ans += ansdigit * ansmul;\n x /= k;\n y /= k;\n ansmul *= k;\n }\n return ans;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n, k;\n auto a = readln.strip.split.map!(to!long).array;\n n = a[0];\n k = a[1];\n long i = 0;\n long distortion = 0;\n while (true) {\n writeln(xork(i, distortion, k));\n stdout.flush;\n string ans = readln;\n if (ans.strip == \"1\") {\n break;\n }\n distortion = xork(distortion, xork(i, distortion, k), k);\n i++;\n }\n }\n}\n"}], "src_uid": "7a9b559eb3b601590e22eb128f2bf307"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n bool isBinOp(string op) { return [\"AND\", \"OR\", \"XOR\"].canFind(op); }\n \n debug { isBinOp(\"AND\").writeln; }\n \n struct node {\n int id;\n string op;\n bool value;\n int le, r;\n bool flip;\n }\n \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = new node[] (n+1);\n \n foreach (i; 1 .. n+1) {\n auto vals = readln.chomp.split;\n arr[i].id = i;\n arr[i].op = vals[0];\n if (arr[i].op == \"IN\") {\n arr[i].value = cast(bool) vals[1].to!int;\n continue;\n }\n \n arr[i].le = vals[1].to!int;\n if (isBinOp(arr[i].op)) arr[i].r = vals[2].to!int;\n }\n \n bool dfsUp(int v) {\n if (arr[v].op == \"NOT\") {\n arr[v].value = ! dfsUp(arr[v].le);\n } else if (isBinOp(arr[v].op)) {\n bool leftVal = dfsUp(arr[v].le);\n bool rightVal = dfsUp(arr[v].r);\n \n if (arr[v].op == \"AND\") arr[v].value = leftVal && rightVal;\n if (arr[v].op == \"XOR\") arr[v].value = leftVal ^ rightVal;\n if (arr[v].op == \"OR\") arr[v].value = leftVal || rightVal;\n }\n \n return arr[v].value;\n }\n \n dfsUp(1);\n \n debug { arr.each!writeln; }\n \n void dfsDown(int v) {\n if (arr[v].op == \"IN\") {\n arr[v].flip = true;\n return;\n }\n \n if (arr[v].op == \"NOT\") {\n dfsDown(arr[v].le);\n return;\n }\n \n bool le = arr[arr[v].le].value, r = arr[arr[v].r].value;\n if (arr[v].op == \"AND\") {\n if (r) {\n dfsDown(arr[v].le);\n }\n if (le) {\n dfsDown(arr[v].r);\n }\n \n return;\n }\n \n if (arr[v].op == \"OR\") {\n if (!r) {\n dfsDown(arr[v].le);\n }\n if (!le) {\n dfsDown(arr[v].r);\n }\n return;\n }\n \n //XOR\n dfsDown(arr[v].le);\n dfsDown(arr[v].r);\n }\n \n dfsDown(1);\n \n debug { arr.filter!(e => e.op == \"IN\").map!(e => e.flip).each!writeln; }\n \n auto ans = arr.filter!(e => e.op == \"IN\").map!(e => arr[1].value ^ e.flip);\n \n ans.map!(x => x ? '1' : '0').writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n enum OP {IN, NOT, AND, OR, XOR};\n auto N = readln.chomp.to!int;\n auto G = new int[][](N, 2);\n auto P = new int[](N);\n auto B = new bool[](N);\n auto V = new bool[](N);\n auto ops = new OP[](N);\n\n foreach (i; 0..N) {\n auto s = readln.split;\n string op = s[0];\n foreach (j; 1..s.length) {\n int a = s[j].to!int - 1;\n G[i][j-1] = a;\n if (op != \"IN\")\n P[a] = i;\n }\n \n if (op == \"IN\") {\n ops[i] = OP.IN;\n B[i] = s[1] == \"1\";\n } else if (op == \"NOT\") {\n ops[i] = OP.NOT;\n } else if (op == \"AND\") {\n ops[i] = OP.AND;\n } else if (op == \"OR\") {\n ops[i] = OP.OR;\n } else {\n ops[i] = OP.XOR;\n }\n }\n\n bool operate(int n) {\n bool a = G[n][0] >= 0 ? B[G[n][0]] : 0;\n bool b = G[n][1] >= 0 ? B[G[n][1]] : 0;\n if (ops[n] == OP.IN) {\n return B[n];\n } else if (ops[n] == OP.NOT) {\n return !a;\n } else if (ops[n] == OP.AND) {\n return a & b;\n } else if (ops[n] == OP.OR) {\n return a | b;\n } else if (ops[n] == OP.XOR) {\n return a ^ b;\n }\n return 0;\n }\n\n void init(int n) {\n if (ops[n] == OP.IN) {\n return;\n } else if (ops[n] == OP.NOT) {\n int a = G[n][0];\n init(a);\n } else {\n int a = G[n][0];\n int b = G[n][1];\n init(a);\n init(b);\n }\n B[n] = operate(n);\n }\n\n void dfs(int n, bool valid) {\n V[n] = valid;\n int a = G[n][0];\n int b = G[n][1];\n if (ops[n] == OP.NOT) {\n dfs(a, valid);\n } else if (ops[n] == OP.AND) {\n if (B[a] && B[b]) {\n dfs(a, valid);\n dfs(b, valid);\n } else if (B[a] && !B[b]) {\n dfs(a, false);\n dfs(b, valid);\n } else if (!B[a] && B[b]) {\n dfs(a, valid);\n dfs(b, false);\n } else {\n dfs(a, false);\n dfs(b, false);\n }\n } else if (ops[n] == OP.OR) {\n if (B[a] && B[b]) {\n dfs(a, false);\n dfs(b, false);\n } else if (B[a] && !B[b]) {\n dfs(a, valid);\n dfs(b, false);\n } else if (!B[a] && B[b]) {\n dfs(a, false);\n dfs(b, valid);\n } else {\n dfs(a, valid);\n dfs(b, valid);\n }\n } else if (ops[n] == OP.XOR) {\n dfs(a, valid);\n dfs(b, valid);\n }\n }\n\n init(0);\n dfs(0, true);\n N.iota.filter!(i => ops[i] == OP.IN).map!(i => V[i] ? !B[0] : B[0]).map!(i => i.to!int.to!string).join(\"\").writeln;\n}\n \n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nstruct C {\n\tint t, l, r, v;\n\tint [] h;\n}\n\nvoid main () {\n\tint n;\n\treadf (\" %s \", &n);\n\tauto c = new C [n];\n\tforeach (i, ref x; c) with (x) {\n\t\tauto z = readln.split;\n\t\tt = z[0][0];\n\t\tl = r = -1;\n\t\tif (t == 'I') {\n\t\t\tv = z[1].to!int;\n\t\t\th ~= i;\n\t\t} else {\n\t\t\tl = z[1].to!int - 1;\n\t\t\tif (z.length > 2) r = z[2].to!int - 1;\n\t\t}\n\t}\n\n\tauto m (int a, int b) {\n\t\tif (c[a].h.length < c[b].h.length) swap (a, b);\n\t\treturn (c[a].h ~= c[b].h);\n\t}\n\n\tvoid f (int u) {\n\t\tif (u < 0) return;\n\t\twith (c[u]) {\n\t\t\tf (l);\n\t\t\tf (r);\n\t\t\tif (t == 'I') return;\n\t\t\tif (t == 'N') {\n\t\t\t\tv = !c[l].v;\n\t\t\t\th = c[l].h;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (t == 'X') {\n\t\t\t\tv = c[l].v ^ c[r].v;\n\t\t\t\th = m (l, r);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint w = c[l].v * 2 + c[r].v;\n\t\t\tv = w == 3;\n\t\t\tif (t == 'O') {\n\t\t\t\tw = 3 - w;\n\t\t\t\tv = w != 3;\n\t\t\t}\n\t\t\th = w == 0 ? null : w == 1 ? c[l].h : w == 2 ? c[r].h : m (l, r);\n\t\t}\n\t}\n\n\tf (0);\n\tauto r = new int [n];\n\tr[] = c[0].v;\n\tforeach (i; c[0].h) r[i] ^= 1;\n\twritefln (\"%(%s%)\", n.iota.filter !(i => c[i].t == 'I').map !(i => r[i]));\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Command = Tuple !(string, q{name}, int, q{left},\n\t\t int, q{right}, int, q{value}, int [], q{inputs});\n\t\tauto commands = new Command [n];\n\n\t\treadln;\n\t\tforeach (i, ref command; commands)\n\t\t{\n\t\t\twith (command)\n\t\t\t{\n\t\t\t\tauto t = readln.split;\n\t\t\t\tname = t[0];\n\t\t\t\tleft = NA;\n\t\t\t\tright = NA;\n\t\t\t\tif (name == \"IN\")\n\t\t\t\t{\n\t\t\t\t\tvalue = t[1].to !(int);\n\t\t\t\t\tinputs ~= i;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tleft = t[1].to !(int) - 1;\n\t\t\t\t\tif (t.length > 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tright = t[2].to !(int) - 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint [] mergeInputs (int one, int two)\n\t\t{\n\t\t\tif (commands[one].inputs.length <\n\t\t\t commands[two].inputs.length)\n\t\t\t{\n\t\t\t\tswap (one, two);\n\t\t\t}\n\t\t\tint [] res = commands[one].inputs;\n\t\t\tres ~= commands[two].inputs;\n\t\t\treturn res;\n\t\t}\n\n\t\tvoid recur (int v)\n\t\t{\n\t\t\twith (commands[v])\n\t\t\t{\n\t\t\t\tif (left != NA)\n\t\t\t\t{\n\t\t\t\t\trecur (left);\n\t\t\t\t}\n\t\t\t\tif (right != NA)\n\t\t\t\t{\n\t\t\t\t\trecur (right);\n\t\t\t\t}\n\t\t\t\tif (name == \"IN\")\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if (name == \"NOT\")\n\t\t\t\t{\n\t\t\t\t\tvalue = !commands[left].value;\n\t\t\t\t\tinputs = commands[left].inputs;\n\t\t\t\t}\n\t\t\t\telse if (name == \"XOR\")\n\t\t\t\t{\n\t\t\t\t\tvalue = commands[left].value ^\n\t\t\t\t\t commands[right].value;\n\t\t\t\t\tinputs = mergeInputs (left, right);\n\t\t\t\t}\n\t\t\t\telse if (name == \"AND\")\n\t\t\t\t{\n\t\t\t\t\tauto w0 = commands[left].value;\n\t\t\t\t\tauto w1 = commands[right].value;\n\t\t\t\t\tvalue = w0 & w1;\n\t\t\t\t\tif (!w0 && !w1)\n\t\t\t\t\t{\n\t\t\t\t\t\tinputs = null;\n\t\t\t\t\t}\n\t\t\t\t\tif (!w0 && w1)\n\t\t\t\t\t{\n\t\t\t\t\t\tinputs = commands[left].inputs;\n\t\t\t\t\t}\n\t\t\t\t\tif (w0 && !w1)\n\t\t\t\t\t{\n\t\t\t\t\t\tinputs = commands[right].inputs;\n\t\t\t\t\t}\n\t\t\t\t\tif (w0 && w1)\n\t\t\t\t\t{\n\t\t\t\t\t\tinputs = mergeInputs (left, right);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if (name == \"OR\")\n\t\t\t\t{\n\t\t\t\t\tauto w0 = commands[left].value;\n\t\t\t\t\tauto w1 = commands[right].value;\n\t\t\t\t\tvalue = w0 | w1;\n\t\t\t\t\tif (w0 && w1)\n\t\t\t\t\t{\n\t\t\t\t\t\tinputs = null;\n\t\t\t\t\t}\n\t\t\t\t\tif (w0 && !w1)\n\t\t\t\t\t{\n\t\t\t\t\t\tinputs = commands[left].inputs;\n\t\t\t\t\t}\n\t\t\t\t\tif (!w0 && w1)\n\t\t\t\t\t{\n\t\t\t\t\t\tinputs = commands[right].inputs;\n\t\t\t\t\t}\n\t\t\t\t\tif (!w0 && !w1)\n\t\t\t\t\t{\n\t\t\t\t\t\tinputs = mergeInputs (left, right);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tassert (false);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0);\n\n\t\tauto res = new int [n];\n\t\tres[] = commands[0].value;\n\t\tforeach (i; commands[0].inputs)\n\t\t{\n\t\t\tres[i] ^= 1;\n\t\t}\n\n\t\twritefln (\"%(%s%)\", n.iota\n\t\t .filter !(i => commands[i].name == \"IN\")\n\t\t .map !(i => res[i]));\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nimmutable int NA = -1;\nstruct Cmd {\n\tstring name;\n\tint left, right, value;\n\tint [] inputs;\n}\n\nvoid main () {\n\tint n;\n\treadf (\" %s \", &n);\n\tauto cmds = new Cmd [n];\n\tforeach (i, ref cmd; cmds) with (cmd) {\n\t\tauto t = readln.split;\n\t\tname = t[0];\n\t\tleft = NA;\n\t\tright = NA;\n\t\tif (name == \"IN\") {\n\t\t\tvalue = t[1].to!int;\n\t\t\tinputs ~= i;\n\t\t} else {\n\t\t\tleft = t[1].to!int - 1;\n\t\t\tif (t.length > 2)\n\t\t\t\tright = t[2].to!int - 1;\n\t\t}\n\t}\n\n\tauto mergeInputs (int one, int two) {\n\t\tif (cmds[one].inputs.length < cmds[two].inputs.length)\n\t\t\tswap (one, two);\n\t\tauto res = cmds[one].inputs;\n\t\tres.assumeSafeAppend ();\n\t\tres ~= cmds[two].inputs;\n\t\treturn res;\n\t}\n\n\tvoid recur (int v) {\n\t\tif (v == NA)\n\t\t\treturn;\n\t\twith (cmds[v]) {\n\t\t\trecur (left);\n\t\t\trecur (right);\n\t\t\tif (name == \"IN\")\n\t\t\t\treturn;\n\t\t\tif (name == \"NOT\") {\n\t\t\t\tvalue = !cmds[left].value;\n\t\t\t\tinputs = cmds[left].inputs;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (name == \"XOR\") {\n\t\t\t\tvalue = cmds[left].value ^ cmds[right].value;\n\t\t\t\tinputs = mergeInputs (left, right);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint w = cmds[left].value * 2 + cmds[right].value;\n\t\t\tvalue = w == 3;\n\t\t\tif (name == \"OR\") {\n\t\t\t\tw = 3 - w;\n\t\t\t\tvalue = w != 3;\n\t\t\t}\n\t\t\tinputs = w == 0 ? null : w == 1 ? cmds[left].inputs : w == 2 ? cmds[right].inputs : mergeInputs (left, right);\n\t\t}\n\t}\n\n\trecur (0);\n\tauto res = new int [n];\n\tres[] = cmds[0].value;\n\tforeach (i; cmds[0].inputs)\n\t\tres[i] ^= 1;\n\twritefln (\"%(%s%)\", n.iota.filter !(i => cmds[i].name == \"IN\").map !(i => res[i]));\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.variant;\nimport std.concurrency;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n struct NodeInfo\n {\n enum Type\n {\n\tand, or, xor, not, input\n };\n Type type;\n int o1, o2;\n int value;\n }\n auto nodes = new NodeInfo[](n);\n nodeInput:foreach(i; 0 .. n)\n {\n auto typeString = next!string;\n final switch(typeString)\n\t{\n\tcase \"AND\":\n\t nodes[i].type = NodeInfo.Type.and;\n\t break;\n\tcase \"OR\":\n\t nodes[i].type = NodeInfo.Type.or;\n\t break;\n\tcase \"XOR\":\n\t nodes[i].type = NodeInfo.Type.xor;\n\t break;\n\tcase \"NOT\":\n\t nodes[i].type = NodeInfo.Type.not;\n\t nodes[i].o1 = next!int - 1;\n\t continue nodeInput;\n\tcase \"IN\":\n\t nodes[i].type = NodeInfo.Type.input;\n\t nodes[i].value = next!int;\n\t continue nodeInput;\n\t}\n nodes[i].o1 = next!int - 1;\n nodes[i].o2 = next!int - 1;\n }\n auto valueOf = new int[](n);\n int calcValue(int i)\n {\n auto node = nodes[i];\n int res = -1;\n final switch(node.type)\n {\n case NodeInfo.Type.and:\n\tres = calcValue(node.o1) & calcValue(node.o2);\n\tbreak;\n case NodeInfo.Type.or:\n\tres = calcValue(node.o1) | calcValue(node.o2);\n\tbreak;\n case NodeInfo.Type.xor:\n\tres = calcValue(node.o1) ^ calcValue(node.o2);\n\tbreak;\n case NodeInfo.Type.not:\n\tres = !calcValue(node.o1);\n\tbreak;\n case NodeInfo.Type.input:\n\tres = node.value;\n\tbreak;\n }\n valueOf[i] = res;\n return res;\n }\n calcValue(0);\n debug foreach(i; 0 .. n)\n {\n writeln(i + 1, \": \", valueOf[i]);\n }\n auto res = new int[](n);\n res[] = valueOf[0];\n void change(int i)\n {\n auto node = nodes[i];\n auto value = valueOf[i];\n final switch(node.type)\n {\n case NodeInfo.Type.and:\n\tif (value == 1)\n\t {\n\t change(node.o1);\n\t change(node.o2);\n\t return;\n\t }\n\tif (!valueOf[node.o1] && !valueOf[node.o2]) return;\n\tif (!valueOf[node.o1]) return change(node.o1);\n\tassert(!valueOf[node.o2]);\n\treturn change(node.o2);\n case NodeInfo.Type.or:\n\tif (value == 0)\n\t {\n\t change(node.o1);\n\t change(node.o2);\n\t return;\n\t }\n\tif (valueOf[node.o1] && valueOf[node.o2]) return;\n\tif (valueOf[node.o1]) return change(node.o1);\n\tassert(valueOf[node.o2]);\n\treturn change(node.o2);\n case NodeInfo.Type.xor:\n\tchange(node.o1);\n\treturn change(node.o2);\n case NodeInfo.Type.not:\n\treturn change(node.o1);\n case NodeInfo.Type.input:\n\tres[i] = !res[i];\n }\n }\n change(0);\n\n foreach(i; 0 .. n)\n {\n if (nodes[i].type == NodeInfo.Type.input)\n\t{\n\t write(res[i]);\n\t}\n }\n writeln;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n enum OP {IN, NOT, AND, OR, XOR};\n auto N = readln.chomp.to!int;\n auto G = new int[][](N, 2);\n auto P = new int[](N);\n auto ops = new OP[](N);\n auto bits = new bool[](N);\n auto not = new bool[](N);\n\n foreach (i; 0..N) {\n auto s = readln.split;\n string op = s[0];\n foreach (j; 1..s.length) {\n int a = s[j].to!int - 1;\n G[i][j-1] = a;\n if (op != \"IN\")\n P[a] = i;\n }\n \n if (op == \"IN\") {\n ops[i] = OP.IN;\n bits[i] = s[1] == \"1\";\n } else if (op == \"NOT\") {\n ops[i] = OP.NOT;\n not[i] = true;\n } else if (op == \"AND\") {\n ops[i] = OP.AND;\n } else if (op == \"OR\") {\n ops[i] = OP.OR;\n } else {\n ops[i] = OP.XOR;\n }\n }\n\n void dfs(int n, int pn) {\n if (ops[n] == OP.NOT) {\n int m = G[n][0];\n G[P[n]][pn] = m;\n P[m] = P[n];\n not[m] ^= not[n];\n dfs(m, pn);\n } else if (ops[n] != OP.IN) {\n foreach (i; 0..2) {\n dfs(G[n][i], i);\n }\n }\n }\n\n bool operate(int n) {\n bool ret;\n bool a = G[n][0] >= 0 ? bits[G[n][0]] : 0;\n bool b = G[n][1] >= 0 ? bits[G[n][1]] : 0;\n if (ops[n] == OP.IN) {\n ret = bits[n];\n } else if (ops[n] == OP.NOT) {\n ret = !a;\n } else if (ops[n] == OP.AND) {\n ret = a & b;\n } else if (ops[n] == OP.OR) {\n ret = a | b;\n } else if (ops[n] == OP.XOR) {\n ret = a ^ b;\n }\n return ret ^ not[n];\n }\n\n void init(int n) {\n int a = G[n][0];\n int b = G[n][1];\n if (ops[n] == OP.IN) {\n if (not[n]) {\n bits[n] ^= 1;\n not[n] ^= 1;\n }\n } else if (ops[n] == OP.NOT) {\n init(a);\n bits[n] = operate(n);\n } else {\n init(a);\n init(b);\n bits[n] = operate(n);\n }\n }\n\n void up(int n) {\n\n bits[n] = operate(n);\n if (n != 0) up(P[n]);\n }\n\n\n if (ops[0] == OP.NOT) {\n dfs(G[0][0], 0);\n } else {\n dfs(0, -1);\n }\n \n bool[] ans;\n init(0);\n \n foreach (i; 0..N) {\n if (ops[i] != OP.IN)\n continue;\n bits[i] ^= 1;\n up(i);\n ans ~= bits[0];\n bits[i] ^= 1;\n up(i);\n }\n\n ans.map!(a => a ? \"1\" : \"0\").join.writeln;\n}\n \n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n enum OP {IN, NOT, AND, OR, XOR};\n auto N = readln.chomp.to!int;\n auto G = new int[][](N, 2);\n auto P = new int[](N);\n auto ops = new OP[](N);\n auto bits = new bool[](N);\n auto not = new bool[](N);\n\n foreach (i; 0..N) {\n auto s = readln.split;\n string op = s[0];\n foreach (j; 1..s.length) {\n int a = s[j].to!int - 1;\n G[i][j-1] = a;\n if (op != \"IN\")\n P[a] = i;\n }\n \n if (op == \"IN\") {\n ops[i] = OP.IN;\n bits[i] = s[1] == \"1\";\n } else if (op == \"NOT\") {\n ops[i] = OP.NOT;\n } else if (op == \"AND\") {\n ops[i] = OP.AND;\n } else if (op == \"OR\") {\n ops[i] = OP.OR;\n } else {\n ops[i] = OP.XOR;\n }\n }\n\n void dfs(int n, int pn) {\n if (ops[n] == OP.NOT) {\n int m = G[n][0];\n G[P[n]][pn] = m;\n P[m] = P[n];\n not[m] ^= not[n];\n dfs(m, pn);\n } else if (ops[n] != OP.IN) {\n foreach (i; 0..2) {\n dfs(G[n][i], i);\n }\n }\n }\n\n bool operate(int n) {\n bool ret;\n bool a = G[n][0] >= 0 ? bits[G[n][0]] : 0;\n bool b = G[n][1] >= 0 ? bits[G[n][1]] : 0;\n if (ops[n] == OP.IN) {\n ret = bits[n];\n } else if (ops[n] == OP.NOT) {\n ret = !a;\n } else if (ops[n] == OP.AND) {\n ret = a & b;\n } else if (ops[n] == OP.OR) {\n ret = a | b;\n } else if (ops[n] == OP.XOR) {\n ret = a ^ b;\n }\n return ret ^ not[n];\n }\n\n void init(int n) {\n int a = G[n][0];\n int b = G[n][1];\n if (ops[n] == OP.IN) {\n if (not[n]) {\n bits[n] ^= 1;\n not[n] ^= 1;\n }\n } else if (ops[n] == OP.NOT) {\n init(a);\n bits[n] = operate(n);\n } else {\n init(a);\n init(b);\n bits[n] = operate(n);\n }\n }\n\n void up(int n) {\n bits[n] = operate(n);\n if (n != 0) up(P[n]);\n }\n\n\n if (ops[0] == OP.NOT) {\n dfs(G[0][0], 0);\n } else {\n dfs(0, -1);\n }\n \n bool[] ans;\n init(0);\n \n foreach (i; 0..N) {\n if (ops[i] != OP.IN)\n continue;\n bits[i] ^= 1;\n up(i);\n ans ~= bits[0];\n bits[i] ^= 1;\n up(i);\n }\n\n ans.map!(a => a ? \"1\" : \"0\").join.writeln;\n}\n \n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n enum OP {IN, NOT, AND, OR, XOR};\n auto N = readln.chomp.to!int;\n auto G = new int[][](N, 2);\n auto P = new int[](N);\n auto ops = new OP[](N);\n auto bits = new bool[](N);\n auto not = new bool[](N);\n\n foreach (i; 0..N) {\n auto s = readln.split;\n string op = s[0];\n foreach (j; 1..s.length) {\n int a = s[j].to!int - 1;\n G[i][j-1] = a;\n if (op != \"IN\")\n P[a] = i;\n }\n \n if (op == \"IN\") {\n ops[i] = OP.IN;\n bits[i] = s[1] == \"1\";\n } else if (op == \"NOT\") {\n ops[i] = OP.NOT;\n not[i] = true;\n } else if (op == \"AND\") {\n ops[i] = OP.AND;\n } else if (op == \"OR\") {\n ops[i] = OP.OR;\n } else {\n ops[i] = OP.XOR;\n }\n }\n\n void dfs(int start) {\n auto stack = new Tuple!(int, int)[](N);\n int p = 0;\n stack[0] = tuple(start, 0);\n while (p >= 0) {\n int n = stack[p][0];\n int pn = stack[p][1];\n --p;\n if (ops[n] == OP.NOT) {\n int m = G[n][0];\n G[P[n]][pn] = m;\n P[m] = P[n];\n not[m] ^= not[n];\n stack[++p] = tuple(m, pn);\n } else if (ops[n] != OP.IN) {\n foreach (i; 0..2) {\n stack[++p] = tuple(G[n][i], i);\n }\n }\n }\n }\n\n bool operate(int n) {\n bool ret;\n bool a = G[n][0] >= 0 ? bits[G[n][0]] : 0;\n bool b = G[n][1] >= 0 ? bits[G[n][1]] : 0;\n if (ops[n] == OP.IN) {\n ret = bits[n];\n } else if (ops[n] == OP.NOT) {\n ret = !a;\n } else if (ops[n] == OP.AND) {\n ret = a & b;\n } else if (ops[n] == OP.OR) {\n ret = a | b;\n } else if (ops[n] == OP.XOR) {\n ret = a ^ b;\n }\n return ret ^ not[n];\n }\n\n void init(int n) {\n int a = G[n][0];\n int b = G[n][1];\n if (ops[n] == OP.IN) {\n if (not[n]) {\n bits[n] ^= 1;\n not[n] ^= 1;\n }\n } else if (ops[n] == OP.NOT) {\n init(a);\n bits[n] = operate(n);\n } else {\n init(a);\n init(b);\n bits[n] = operate(n);\n }\n }\n\n void up(int n) {\n bits[n] = operate(n);\n if (n != 0) up(P[n]);\n }\n\n\n if (ops[0] == OP.NOT) {\n dfs(G[0][0]);\n } else {\n dfs(0);\n }\n \n bool[] ans;\n init(0);\n \n foreach (i; 0..N) {\n if (ops[i] != OP.IN)\n continue;\n bits[i] ^= 1;\n up(i);\n ans ~= bits[0];\n bits[i] ^= 1;\n up(i);\n }\n\n ans.map!(a => a ? \"1\" : \"0\").join.writeln;\n}\n \n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nimmutable int NA = -1;\nstruct Cmd {\n\tstring name;\n\tint left, right, value;\n\tint [] inputs;\n}\n\nvoid main () {\n\tint n;\n\treadf (\" %s \", &n);\n\tauto cmds = new Cmd [n];\n\tforeach (i, ref cmd; cmds) with (cmd) {\n\t\tauto t = readln.split;\n\t\tname = t[0];\n\t\tleft = NA;\n\t\tright = NA;\n\t\tif (name == \"IN\") {\n\t\t\tvalue = t[1].to!int;\n\t\t\tinputs ~= i;\n\t\t} else {\n\t\t\tleft = t[1].to!int - 1;\n\t\t\tif (t.length > 2)\n\t\t\t\tright = t[2].to!int - 1;\n\t\t}\n\t}\n\n\tauto mergeInputs (int one, int two) {\n\t\tif (cmds[one].inputs.length < cmds[two].inputs.length)\n\t\t\tswap (one, two);\n\t\tauto res = cmds[one].inputs;\n\t\tres.assumeSafeAppend ();\n\t\tres ~= cmds[two].inputs;\n\t\treturn res;\n\t}\n\n\tvoid recur (int v) {\n\t\tif (v == NA)\n\t\t\treturn;\n\t\twith (cmds[v]) {\n\t\t\trecur (left);\n\t\t\trecur (right);\n\t\t\tif (name == \"IN\")\n\t\t\t\treturn;\n\t\t\tif (name == \"NOT\") {\n\t\t\t\tvalue = !cmds[left].value;\n\t\t\t\tinputs = cmds[left].inputs;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (name == \"XOR\") {\n\t\t\t\tvalue = cmds[left].value ^ cmds[right].value;\n\t\t\t\tinputs = mergeInputs (left, right);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint w = cmds[left].value * 2 + cmds[right].value;\n\t\t\tvalue = w == 3;\n\t\t\tif (name == \"OR\") {\n\t\t\t\tw = 3 - w;\n\t\t\t\tvalue = w != 0;\n\t\t\t}\n\t\t\tinputs = w == 0 ? null : w == 1 ? cmds[left].inputs : w == 2 ? cmds[right].inputs : mergeInputs (left, right);\n\t\t}\n\t}\n\n\trecur (0);\n\tauto res = new int [n];\n\tres[] = cmds[0].value;\n\tforeach (i; cmds[0].inputs)\n\t\tres[i] ^= 1;\n\twritefln (\"%(%s%)\", n.iota.filter !(i => cmds[i].name == \"IN\").map !(i => res[i]));\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n bool isBinOp(string op) { return [\"AND\", \"OR\", \"XOR\"].canFind(op); }\n \n debug { isBinOp(\"AND\").writeln; }\n \n struct node {\n int id;\n string op;\n bool value;\n int le, r;\n bool flip;\n }\n \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = new node[] (n+1);\n \n foreach (i; 1 .. n+1) {\n auto vals = readln.chomp.split;\n arr[i].id = i;\n arr[i].op = vals[0];\n if (arr[i].op == \"IN\") {\n arr[i].value = cast(bool) vals[1].to!int;\n continue;\n }\n \n arr[i].le = vals[1].to!int;\n if (isBinOp(arr[i].op)) arr[i].r = vals[2].to!int;\n }\n \n bool dfsUp(int v) {\n if (arr[v].op == \"NOT\") {\n arr[v].value = ! dfsUp(arr[v].le);\n } else if (isBinOp(arr[v].op)) {\n bool leftVal = dfsUp(arr[v].le);\n bool rightVal = dfsUp(arr[v].r);\n \n if (arr[v].op == \"AND\") arr[v].value = leftVal && rightVal;\n if (arr[v].op == \"XOR\") arr[v].value = leftVal ^ rightVal;\n if (arr[v].op == \"OR\") arr[v].value = leftVal || rightVal;\n }\n \n return arr[v].value;\n }\n \n dfsUp(1);\n \n debug { arr.each!writeln; }\n \n void dfsDown(int v) {\n if (arr[v].op == \"IN\") {\n arr[v].flip = true;\n return;\n }\n \n if (arr[v].op == \"NOT\") {\n dfsDown(arr[v].le);\n return;\n }\n \n bool le = arr[arr[v].le].value, r = arr[arr[v].r].value;\n if (arr[v].op == \"AND\") {\n if (le & r) {\n dfsDown(arr[v].le);\n dfsDown(arr[v].r);\n } else if (le) {\n dfsDown(arr[v].r);\n } else if (r) {\n dfsDown(arr[v].le);\n }\n \n return;\n }\n \n if (arr[v].op == \"OR\") {\n if (!(le || r)) {\n dfsDown(arr[v].le);\n dfsDown(arr[v].r);\n } else if (le) {\n dfsDown(arr[v].le);\n } else if (r) {\n dfsDown(arr[v].r);\n }\n \n return;\n }\n \n //XOR\n dfsDown(arr[v].le);\n dfsDown(arr[v].r);\n }\n \n dfsDown(1);\n \n debug { arr.filter!(e => e.op == \"IN\").map!(e => e.flip).each!writeln; }\n \n auto ans = arr.filter!(e => e.op == \"IN\").map!(e => arr[1].value ^ e.flip);\n \n ans.map!(x => x ? '1' : '0').writeln;\n}"}], "src_uid": "3c058688183e5cd7dd91ae592ccd8048"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tans[ti] = 1;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tint l, r = n-1;\r\n\t\tbool ok = true;\r\n\t\twhile (l < r)\r\n\t\t{\r\n\t\t\tif (s[l] != s[r])\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t++l; --r;\r\n\t\t}\r\n\t\tif (ok)\r\n\t\t\tans[ti] = 1;\r\n\t\telse\r\n\t\t\tans[ti] = 2;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "// cheese-cracker [2022-02-06]\n\nvoid solve(){\n long n = scan;\n long k = scan;\n auto s = scan!(dchar[]);\n auto rs = s.dup;\n rs.reverse;\n if(s == rs || k == 0){\n writeln(1);\n }else{\n writeln(2);\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}], "negative_code": [], "src_uid": "08cd22b8ee760a9d2dacb0d050dcf37a"} {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math : abs;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n uint n;\n readf(\" %s\", n);\n\n auto a = new int[n];\n foreach(i; 0 .. n) {\n readf(\" %s\", a[i]);\n }\n\n auto aa = a.enumerate.array.sort!\"a.value < b.value\";\n int k = 1_000_000_009;\n int maxidx = -1;\n int minidx = n+n;\n for(int i = n-1; i>=0; i--) {\n if (i != n-1){\n k = min(k, aa[i].value/(abs(maxidx - to!int(aa[i].index))));\n k = min(k, aa[i].value/(abs(minidx - to!int(aa[i].index))));\n }\n\n maxidx = max(maxidx, to!int(aa[i].index));\n minidx = min(minidx, to!int(aa[i].index));\n }\n\n writeln(k);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n auto AS = readln.split.to!(int[]);\n\n auto k = int.max, x = int.max, n = N;\n size_t i, j = N-1;\n while (i <= j) {\n --n;\n x = min(x, AS[i]);\n x = min(x, AS[j]);\n k = min(k, x / n);\n ++i;\n --j;\n }\n writeln(k);\n}"}], "negative_code": [], "src_uid": "f146808eb6e0ee04d531e7222a53d275"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n,k;\n readf!\" %s %s\"(n,k);\n\n int[] d = new int[](k);\n\n foreach (i; 0 .. n) {\n int a;\n readf!\" %s\"(a);\n d[a%k]++;\n }\n\n int ans = d[0]/2*2;\n if (k % 2 == 0) {\n ans += d[k/2]/2*2;\n }\n foreach (i; 1 .. k) {\n if (i == k-i) continue;\n ans += min(d[i], d[k-i]);\n }\n\n writeln(ans);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(x => x.to!int % K).array;\n\n auto cnt = new int[](K+1);\n foreach (a; A) cnt[a] += 1;\n\n int ans = 0;\n foreach (i; 0..K) {\n if (i * 2 % K == 0) {\n ans += cnt[i] / 2;\n cnt[i] /= 2;\n } else {\n int m = min(cnt[i], cnt[K-i]);\n ans += m;\n cnt[i] -= m;\n cnt[K-i] -= m;\n }\n }\n\n ans *= 2;\n ans.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n,k;\n readf!\" %s %s\"(n,k);\n\n int[] d = new int[](k);\n\n foreach (i; 0 .. n) {\n int a;\n readf!\" %s\"(a);\n d[a%k]++;\n }\n\n int ans = d[0]/2*2;\n foreach (i; 1 .. k) {\n ans += min(d[i], d[k-i]);\n }\n\n writeln(ans);\n}\n"}], "src_uid": "3f3a013cedaaf8cbee0a74a4ed50f09d"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const U = readLong();\n auto E = new long[N];\n foreach (i; 0 .. N) {\n E[i] = readLong();\n }\n \n real ans = -1.0L;\n foreach (i; 0 .. N - 1) {\n const j = i + 1;\n const k = E.upperBound(E[i] + U) - 1;\n if (j < k) {\n chmax(ans, cast(real)(E[k] - E[j]) / (E[k] - E[i]));\n }\n }\n if (ans < 0) {\n writeln(-1);\n } else {\n writefln(\"%.10f\", ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, u; readV(n, u);\n int[] e; readA(n, e);\n auto es = e.assumeSorted;\n\n auto y = -1.0L;\n foreach (i; 0..n-2) {\n if (e[i+2]-e[i] > u) continue;\n auto ei = e[i], ej = e[i+1];\n auto ek = es.lowerBound(ei+u+1).back;\n y = max(y, (ek-ej).to!real/(ek-ei));\n }\n\n if (y < 0)\n writeln(-1);\n else\n writefln(\"%.10f\", y);\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}\nvoid readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}\nvoid readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}\n\nvoid main()\n{\n int n, u; readV(n, u);\n int[] e; readA(n, e);\n auto es = e.assumeSorted;\n\n auto y = -1.0L;\n foreach (i; 0..n-2) {\n if (e[i+2]-e[i] > u) continue;\n auto ei = e[i], ej = e[i+1];\n auto ek = es.lowerBound(ei+u+1).back;\n y = max(y, (ek-ej).to!real/(ek-ei));\n }\n\n if (y < 0)\n writeln(-1);\n else\n writefln(\"%.10f\", y);\n}\n"}], "negative_code": [], "src_uid": "74ed99af5a5ed51c73d68f7d4ff2c70e"} {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] as = readln.chomp.split(\" \").map!(to!int).array;\n int[int] x;\n foreach (a; as) {\n x[a]++;\n }\n auto bs = redBlackTree!int([]);\n foreach (a; as) {\n int b = a + 1;\n if (!x.get(b, 0)) bs.insert(b);\n }\n int[] r = as.dup;\n foreach (i, a; as) {\n if (x[a] > 1) {\n int b = bs.upperBound(a).front;\n bs.removeKey(b);\n r[i] = b;\n x[a]--;\n if (!x.get(b + 1, 0)) bs.insert(b + 1);\n }\n }\n write(r[0]);\n foreach (e; r[1 .. $]) {\n write(\" \", e);\n }\n write(\"\\n\");\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm;\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n\n auto a = new int[2][n];\n foreach(i; 0..n) {\n readf(\" %d\", &a[i][0]);\n a[i][1] = i;\n }\n sort!(\"a < b\", SwapStrategy.stable)(a);\n\n auto b = new int[n];\n foreach(i; 0..n) {\n b[a[i][1]] = max(a[i][0], i > 0 ? b[a[i-1][1]]+1 : 0);\n }\n\n writefln(\"%(%s %)\", b);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\talias Tuple !(int, \"x\", int, \"k\") pair;\n\t\tpair [] c;\n\t\tforeach (i, x; a)\n\t\t{\n\t\t\tc ~= pair (x, i);\n\t\t}\n\t\tsort !(\"a < b\", SwapStrategy.stable) (c);\n\n\t\tint [int] p;\n\t\tforeach (e; c)\n\t\t{\n\t\t\tint x = e.x;\n\t\t\twhile (x in p)\n\t\t\t{\n\t\t\t\tx = p[x];\n\t\t\t}\n\t\t\ta[e.k] = x;\n\t\t\tp[x] = x + 1;\n\t\t\tint y = e.x;\n\t\t\twhile (y in p)\n\t\t\t{\n\t\t\t\tint z = p[y];\n\t\t\t\tp[y] = x + 1;\n\t\t\t\ty = z;\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] as = readln.chomp.split(\" \").map!(to!int).array;\n int[int] x;\n foreach (a; as) {\n x[a]++;\n }\n auto bs = redBlackTree!int([]);\n foreach (a; as) {\n int b = a + 1;\n if (!x.get(b, 0)) bs.insert(b);\n }\n int[] r = as.dup;\n foreach (i, a; as) {\n if (x[a] > 1) {\n int b = bs.upperBound(a).front;\n bs.removeKey(b);\n bs.insert(b + 1);\n r[i] = b;\n x[a]--;\n }\n }\n r.map!(to!string).join(\" \").writeln;\n}\n"}], "src_uid": "d19c7a74d739c2ca0d568808862ba2bd"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.chomp)) {\r\n int n = to!int(readln.chomp);\r\n auto nums = readln.split.map!(to!int).array.sort;\r\n int mn = int.max, ans = 1;\r\n foreach(i; 1 .. n) {\r\n mn = min(mn, nums[i] - nums[i-1]);\r\n if(mn < nums[i]) break;\r\n ans++;\r\n }\r\n writeln(ans);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto n = readln().chomp.to!int;\r\n auto arr = readln().chomp.splitter(\" \").map!(to!int).array.sort;\r\n \r\n int diff = int.max;\r\n int res= 1;\r\n \r\n for(int i = 1; i < arr.length;i++)\r\n {\r\n diff = min(diff, arr[i] - arr[i-1]);\r\n if(diff < arr[i]) break;\r\n res++;\r\n }\r\n \r\n writeln(res);\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto n = readln().chomp.to!int;\r\n auto arr = readln().chomp.splitter(\" \").map!(to!int).array.sort.array;\r\n \r\n int diff = int.max;\r\n int res= 1;\r\n \r\n for(int i = 1; i < arr.length;i++)\r\n {\r\n diff = min(diff, arr[i] - arr[i-1]);\r\n if(diff < arr[i]) break;\r\n res++;\r\n }\r\n \r\n writeln(res);\r\n }\r\n}"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1529/problem/B\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(to!int).array;\n int minima = int.max;\n int ans = 1;\n a.sort;\n for(int i = 1; i < n; ++i) {\n minima = min(minima, a[i] - a[i - 1]);\n if(a[i] <= 0) {\n ans += 1;\n continue;\n } else {\n if(a[i] <= minima) {\n ans += 1;\n }\n break;\n }\n }\n ans.writeln;\n}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tlong[] b, c;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] > 0)\r\n\t\t\t\tb ~= a[i];\r\n\t\t\telse\r\n\t\t\t\tc ~= a[i];\r\n\t\t}\r\n\r\n\t\tlong rmv, x;\r\n\t\tif (!b.empty)\r\n\t\t{\r\n\t\t\trmv = b.length - 1;\r\n\t\t\tx = b.minElement;\r\n\t\t}\r\n\t\tc.sort;\r\n\t\tlong y = long.max;\r\n\t\tforeach (i; 0..cast(int)c.length-1)\r\n\t\t{\r\n\t\t\ty.chmin(c[i+1] - c[i]);\r\n\t\t}\r\n\t\tif (y < x)\r\n\t\t\t++rmv;\r\n\t\tans[ti] = n - rmv;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.chomp)) {\r\n int n = to!int(readln.chomp);\r\n auto nums = readln.split.map!(to!int).array;\r\n auto cnt = new int[3];\r\n foreach(e; nums) {\r\n if(e < 0) {\r\n cnt[0]++;\r\n } else if(!e) {\r\n cnt[1]++;\r\n } else {\r\n cnt[2] = true;\r\n }\r\n }\r\n writeln(cnt[0] + (cnt[1] > 1 ? cnt[1] : cnt[1]+cnt[2]));\r\n }\r\n}\r\n"}], "src_uid": "a4b170cc058c485a50bf18982fd96851"} {"source_code": "// c \nimport std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nalias KV = Tuple!(int, \"key\", int, \"val\");\nKV[] history;\n\nint root(int[] uf, int u) {\n // return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n if (uf[u] < 0) {\n return u;\n } else {\n const r = uf.root(uf[u]);\n history ~= KV(u, uf[u]);\n return uf[u] = r;\n }\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n history ~= KV(u, uf[u]);\n uf[u] += uf[v];\n history ~= KV(v, uf[v]);\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const K = readInt();\n auto C = new int[N];\n foreach (u; 0 .. N) {\n C[u] = readInt() - 1;\n }\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n auto uss = new int[][K];\n foreach (u; 0 .. N) {\n uss[C[u]] ~= u;\n }\n \n auto uf = new int[N * 2];\n uf[] = -1;\n \n alias Entry = Tuple!(int, \"ca\", int, \"cb\", int, \"i\");\n Entry[] es;\n foreach (i; 0 .. M) {\n if (C[A[i]] > C[B[i]]) {\n swap(A[i], B[i]);\n }\n if (C[A[i]] == C[B[i]]) {\n uf.connect(A[i] * 2 + 0, B[i] * 2 + 1);\n uf.connect(A[i] * 2 + 1, B[i] * 2 + 0);\n } else {\n es ~= Entry(C[A[i]], C[B[i]], i);\n }\n }\n es.sort;\n const esLen = cast(int)(es.length);\n \n auto good = new bool[K];\n good[] = true;\n foreach (k; 0 .. K) {\n foreach (u; uss[k]) {\n good[k] = good[k] && (uf.root(u * 2 + 0) != uf.root(u * 2 + 1));\n }\n }\n debug {\n writeln(\"good = \", good);\n }\n const numGood = cast(long)(good.count(true));\n long ans = numGood * (numGood - 1) / 2;\n \n for (int g = 0, h; g < esLen; g = h) {\n for (h = g; h < esLen && (es[g].ca == es[h].ca && es[g].cb == es[h].cb); ++h) {}\n if (good[es[g].ca] && good[es[g].cb]) {\n debug {\n writeln(es[g .. h]);\n }\n history = [];\n foreach (ref e; es[g .. h]) {\n const i = e.i;\n uf.connect(A[i] * 2 + 0, B[i] * 2 + 1);\n uf.connect(A[i] * 2 + 1, B[i] * 2 + 0);\n }\n bool ok = true;\n foreach (ref e; es[g .. h]) {\n const i = e.i;\n ok = ok && (uf.root(A[i] * 2 + 0) != uf.root(A[i] * 2 + 1));\n ok = ok && (uf.root(B[i] * 2 + 0) != uf.root(B[i] * 2 + 1));\n }\n if (!ok) {\n --ans;\n }\n foreach_reverse (ref kv; history) {\n uf[kv.key] = kv.val;\n }\n }\n }\n \n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (readf !(\" %s %s %s\") (n, m, k) > 0)\n\t{\n\t\treadln;\n\t\tauto g = readln.splitter.map !(to !(int)).array;\n\t\tg[] -= 1;\n\t\talias Edge = Tuple !(int, q{u}, int, q{v});\n\t\tEdge [] [Edge] edgesByPair;\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tEdge e;\n\t\t\treadf !(\" %s %s\") (e.u, e.v);\n\t\t\te.u -= 1;\n\t\t\te.v -= 1;\n\n\t\t\tauto pair = Edge (g[e.u], g[e.v]);\n\t\t\tif (pair.u > pair.v)\n\t\t\t{\n\t\t\t\tswap (pair.u, pair.v);\n\t\t\t}\n\t\t\tedgesByPair[pair] ~= e;\n\t\t}\n\n\t\talias Parent = Tuple !(int, q{v}, int, q{xor});\n\t\tauto p = new Parent [n];\n\t\tauto rank = new int [n];\n\t\tforeach (u; 0..n)\n\t\t{\n\t\t\tp[u] = Parent (u, 0);\n\t\t\trank[u] = 1;\n\t\t}\n\n\t\tauto root (int v)\n\t\t{\n\t\t\tauto res = Parent (v, 0);\n\t\t\twhile (res.v != p[res.v].v)\n\t\t\t{\n\t\t\t\tres.xor ^= p[res.v].xor;\n\t\t\t\tres.v = p[res.v].v;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\talias Record = Tuple !(int, q{u}, int, q{v}, int, q{xor},\n\t\t int, q{w}, int, q{rank});\n\t\tRecord [] history;\n\n\t\tauto unite (const ref Edge e, bool doRecord = false)\n\t\t{\n\t\t\tauto pu = root (e.u);\n\t\t\tauto pv = root (e.v);\n\t\t\tauto u = pu.v;\n\t\t\tauto v = pv.v;\n\t\t\tauto xor = pu.xor ^ pv.xor;\n\t\t\tdebug {writefln !(\"unite: %s %s %s\") (u, v, xor);}\n\t\t\tif (u == v)\n\t\t\t{\n\t\t\t\treturn (xor == 1);\n\t\t\t}\n\t\t\txor ^= 1;\n\t\t\tif (rank[u] > rank[v])\n\t\t\t{\n\t\t\t\tswap (u, v);\n\t\t\t}\n\t\t\tif (doRecord)\n\t\t\t{\n\t\t\t\thistory ~= Record (u, p[u].v, p[u].xor,\n\t\t\t\t v, rank[v]);\n\t\t\t}\n\t\t\tif (rank[u] == rank[v])\n\t\t\t{\n\t\t\t\trank[v] += 1;\n\t\t\t}\n\t\t\tp[u] = Parent (v, xor);\n\t\t\tdebug {writefln !(\"p[%s] = %s %s\") (u, v, xor);}\n\t\t\treturn true;\n\t\t}\n\n\t\tauto badGroup = new bool [k];\n\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tauto pair = Edge (i, i);\n\t\t\tif (pair in edgesByPair)\n\t\t\t{\n\t\t\t\tforeach (e; edgesByPair[pair])\n\t\t\t\t{\n\t\t\t\t\tif (!unite (e))\n\t\t\t\t\t{\n\t\t\t\t\t\tbadGroup[i] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tauto totalBad = sum (badGroup, 0);\n\t\tdebug {writeln (\"totalBad = \", totalBad);}\n\t\tlong res = k - totalBad;\n\t\tres = (res * (res - 1L)) / 2;\n\n\t\tforeach (pair, edges; edgesByPair)\n\t\t{\n\t\t\tif (pair.u == pair.v)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (badGroup[pair.u] || badGroup[pair.v])\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tbool badPair = false;\n\t\t\tforeach (e; edges)\n\t\t\t{\n\t\t\t\tif (!unite (e, true))\n\t\t\t\t{\n\t\t\t\t\tbadPair = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (badPair)\n\t\t\t{\n\t\t\t\tres -= 1;\n\t\t\t}\n\t\t\tforeach_reverse (r; history)\n\t\t\t{\n\t\t\t\trank[r.w] = r.rank;\n\t\t\t\tp[r.u] = Parent (r.v, r.xor);\n\t\t\t\tdebug {writefln !(\"p[%s] reverted to %s %s\")\n\t\t\t\t (r.u, r.v, r.xor);}\n\t\t\t}\n\t\t\thistory = null;\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nalias KV = Tuple!(int, \"key\", int, \"val\");\nKV[] history;\n\nint root(int[] uf, int u) {\n // return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n if (uf[u] < 0) {\n return u;\n } else {\n const r = uf.root(uf[u]);\n history ~= KV(u, uf[u]);\n return uf[u] = r;\n }\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n history ~= KV(u, uf[u]);\n uf[u] += uf[v];\n history ~= KV(v, uf[v]);\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const K = readInt();\n auto C = new int[N];\n foreach (u; 0 .. N) {\n C[u] = readInt() - 1;\n }\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n auto uss = new int[][K];\n foreach (u; 0 .. N) {\n uss[C[u]] ~= u;\n }\n \n auto uf = new int[N * 2];\n uf[] = -1;\n \n alias Entry = Tuple!(int, \"ca\", int, \"cb\", int, \"i\");\n Entry[] es;\n foreach (i; 0 .. M) {\n if (C[A[i]] > C[B[i]]) {\n swap(A[i], B[i]);\n }\n if (C[A[i]] == C[B[i]]) {\n uf.connect(A[i] * 2 + 0, B[i] * 2 + 1);\n uf.connect(A[i] * 2 + 1, B[i] * 2 + 0);\n } else {\n es ~= Entry(C[A[i]], C[B[i]], i);\n }\n }\n es.sort;\n const esLen = cast(int)(es.length);\n \n auto good = new bool[K];\n good[] = true;\n foreach (k; 0 .. K) {\n foreach (u; uss[k]) {\n good[k] = good[k] && (uf.root(u * 2 + 0) != uf.root(u * 2 + 1));\n }\n }\n debug {\n writeln(\"good = \", good);\n }\n const numGood = cast(long)(good.count(true));\n long ans = numGood * (numGood - 1) / 2;\n \n for (int g = 0, h; g < esLen; g = h) {\n for (h = g; h < esLen && (es[g].ca == es[h].ca && es[g].cb == es[h].cb); ++h) {}\n if (good[es[g].ca] && good[es[g].cb]) {\n debug {\n writeln(es[g .. h]);\n }\n history = [];\n foreach (ref e; es[g .. h]) {\n const i = e.i;\n uf.connect(A[i] * 2 + 0, B[i] * 2 + 1);\n uf.connect(A[i] * 2 + 1, B[i] * 2 + 0);\n }\n bool ok = true;\n foreach (ref e; es[g .. h]) {\n const i = e.i;\n ok = ok && (uf.root(A[i] * 2 + 0) != uf.root(A[i] * 2 + 1));\n ok = ok && (uf.root(B[i] * 2 + 0) != uf.root(B[i] * 2 + 1));\n }\n if (!ok) {\n --ans;\n }\n foreach_reverse (ref kv; history) {\n uf[kv.key] = kv.val;\n }\n }\n }\n \n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (readf !(\" %s %s %s\") (n, m, k) > 0)\n\t{\n\t\treadln;\n\t\tauto g = readln.splitter.map !(to !(int)).array;\n\t\tg[] -= 1;\n\t\talias Edge = Tuple !(int, q{u}, int, q{v});\n\t\tEdge [] [Edge] edgesByPair;\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tEdge e;\n\t\t\treadf !(\" %s %s\") (e.u, e.v);\n\t\t\te.u -= 1;\n\t\t\te.v -= 1;\n\n\t\t\tauto pair = Edge (g[e.u], g[e.v]);\n\t\t\tif (pair.u > pair.v)\n\t\t\t{\n\t\t\t\tswap (pair.u, pair.v);\n\t\t\t}\n\t\t\tedgesByPair[pair] ~= e;\n\t\t}\n\n\t\talias Parent = Tuple !(int, q{v}, int, q{xor});\n\t\tauto p = new Parent [n];\n\t\tauto rank = new int [n];\n\t\tforeach (u; 0..n)\n\t\t{\n\t\t\tp[u] = Parent (u, 0);\n\t\t\trank[u] = 1;\n\t\t}\n\n\t\tauto root (int v)\n\t\t{\n\t\t\tauto res = Parent (v, 0);\n\t\t\twhile (res.v != p[res.v].v)\n\t\t\t{\n\t\t\t\tres.xor ^= p[res.v].xor;\n\t\t\t\tres.v = p[res.v].v;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\talias Record = Tuple !(int, q{u}, int, q{v}, int, q{xor},\n\t\t int, q{w}, int, q{rank});\n\t\tRecord [] history;\n\n\t\tauto unite (const ref Edge e, bool doRecord = false)\n\t\t{\n\t\t\tauto pu = root (e.u);\n\t\t\tauto pv = root (e.v);\n\t\t\tauto u = pu.v;\n\t\t\tauto v = pv.v;\n\t\t\tauto xor = pu.xor ^ pv.xor;\n\t\t\tdebug {writefln !(\"unite: %s %s %s\") (u, v, xor);}\n\t\t\tif (u == v)\n\t\t\t{\n\t\t\t\treturn (xor == 1);\n\t\t\t}\n\t\t\txor ^= 1;\n\t\t\tif (rank[u] > rank[v])\n\t\t\t{\n\t\t\t\tswap (u, v);\n\t\t\t}\n\t\t\tif (doRecord)\n\t\t\t{\n\t\t\t\thistory ~= Record (u, p[u].v, p[u].xor,\n\t\t\t\t v, rank[v]);\n\t\t\t}\n\t\t\tif (rank[u] == rank[v])\n\t\t\t{\n\t\t\t\trank[v] += 1;\n\t\t\t}\n\t\t\tp[u] = Parent (v, xor);\n\t\t\tdebug {writefln !(\"p[%s] = %s %s\") (u, v, xor);}\n\t\t\treturn true;\n\t\t}\n\n\t\tauto badGroup = new bool [k];\n\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tauto pair = Edge (i, i);\n\t\t\tif (pair in edgesByPair)\n\t\t\t{\n\t\t\t\tforeach (e; edgesByPair[pair])\n\t\t\t\t{\n\t\t\t\t\tif (!unite (e))\n\t\t\t\t\t{\n\t\t\t\t\t\tbadGroup[i] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tauto totalBad = sum (badGroup, 0);\n\t\tdebug {writeln (\"totalBad = \", totalBad);}\n\t\tlong res = k - totalBad;\n\t\tres = (res * (res - 1L)) / 2;\n\n\t\tforeach (pair, edges; edgesByPair)\n\t\t{\n\t\t\tif (pair.u == pair.v)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tbool badPair = false;\n\t\t\tforeach (e; edges)\n\t\t\t{\n\t\t\t\tif (!unite (e, true))\n\t\t\t\t{\n\t\t\t\t\tbadPair = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (badPair)\n\t\t\t{\n\t\t\t\tres -= 1;\n\t\t\t}\n\t\t\tforeach_reverse (r; history)\n\t\t\t{\n\t\t\t\trank[r.w] = r.rank;\n\t\t\t\tp[r.u] = Parent (r.v, r.xor);\n\t\t\t\tdebug {writefln !(\"p[%s] reverted to %s %s\")\n\t\t\t\t (r.u, r.v, r.xor);}\n\t\t\t}\n\t\t\thistory = null;\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "b4332870aac6159d5aaa4ff21f8e9f7f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tans[ti] = a.front < a.back;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\twriteln (a.front < a.back ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n writeln((A[0] < A[N - 1]) ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "192f181cfc74bef5b0b5a192964d9760"} {"source_code": "import core.bitop;\nimport core.checkedint;\n//import core.stdc.stdio;\nimport core.stdc.stdlib: alloca, malloc, calloc, realloc, _Exit;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n enum spec = ' ' ~ replicate(\"%s \", vars.length);\n return readf(spec, getAddrTuple(vars).expand) == vars.length;\n}\n\nvoid memSet(T, size_t n)(ref T[n] a, ubyte value) {\n memset(a.ptr, value, a.sizeof);\n}\n\nvoid memSet(T)(T[ ] a, ubyte value) {\n memset(a.ptr, value, a.length * T.sizeof);\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Task {\n bool coproc;\n int deps;\n Task*[ ] next;\n\n void perform(ref Array!(Task*) q, bool traverseCoproc) {\n assert(!deps);\n assert(coproc == traverseCoproc);\n foreach (t; next) {\n assert(t.deps >= 1);\n if (!--t.deps) {\n if (t.coproc == traverseCoproc)\n t.perform(q, traverseCoproc);\n else\n q ~= t;\n }\n }\n }\n}\n\nTask[100_001] _tasks;\n\nvoid main() {\n int n, m;\n Array!(Task*)[2] q;\n while (read(n, m)) {\n auto tasks = _tasks[0 .. n + 1];\n version (LocalProject)\n tasks[ ] = Task.init;\n q[0].clear();\n char c;\n foreach (ref t; tasks[0 .. n]) {\n read(c);\n t.coproc = c == '1';\n }\n while (m--) {\n int a, b;\n read(a, b);\n tasks[a].deps++;\n tasks[b].next ~= &tasks[a];\n }\n foreach (ref t; tasks[0 .. n])\n if (!t.deps) {\n t.deps = 1;\n tasks[n].next ~= &t;\n }\n\n q[0] ~= &tasks[n];\n int result = 0;\n do {\n q[1].clear();\n foreach (t; q[0])\n t.perform(q[1], false);\n q[0].clear();\n result += !q[1].empty;\n foreach (t; q[1])\n t.perform(q[0], true);\n } while (!q[0].empty);\n writeln(result);\n }\n\n stdout.flush();\n _Exit(0);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nvoid main() {\n int n,m;\n scan(n,m);\n auto e = readln.split.to!(int[]);\n auto adj = new int[][](n, 0);\n foreach (i ; 0 .. m) {\n int t1,t2;\n scan(t1,t2);\n adj[t1] ~= t2;\n }\n\n auto memo = new int[](n);\n memo[] = -1;\n\n int dfs(int i) {\n if (memo[i] > -1) return memo[i];\n if (adj[i].empty) {\n memo[i] = e[i] == 1;\n return memo[i];\n }\n memo[i] = 0;\n if (e[i] == 1) {\n foreach (j ; adj[i]) {\n memo[i] = max(memo[i], dfs(j) + (e[j] == 0));\n }\n }\n else {\n foreach (j ; adj[i]) {\n memo[i] = max(memo[i], dfs(j));\n }\n }\n\n return memo[i];\n }\n\n int ans;\n\n foreach (i ; 0 .. n) {\n ans = max(ans, dfs(i));\n }\n\n debug {\n writeln(memo);\n }\n\n writeln(ans);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!int;\n auto m = next!int;\n auto noDependencies = new int[](n);\n auto dependencies = new int[][](n);\n auto dependants = new int[][](n);\n auto type = next!int(n);\n enum main = 0;\n enum copr = 1;\n foreach(dep; 0 .. m)\n {\n auto t1 = next!int;\n auto t2 = next!int;\n noDependencies[t1]++;\n dependencies[t1] ~= t2;\n dependants[t2] ~= t1;\n }\n DList!int[2] todo;\n todo[0] = DList!int();\n todo[1] = DList!int();\n foreach(i; 0 .. n)\n {\n if (noDependencies[i] == 0)\n\t{\n\t todo[type[i]].insertBack(i);\n\t}\n }\n int coprSets = 0;\n while(true)\n {\n if (todo[0].empty && todo[1].empty)\n\t{\n\t return coprSets.writeln;\n\t}\n foreach(typeToDo; 0 .. 2)\n\t{\n\t if (typeToDo == copr && !todo[typeToDo].empty)\n\t {\n\t coprSets++;\n\t }\n\t while(!todo[typeToDo].empty)\n\t {\n\t auto ntask = todo[typeToDo].front;\n\t todo[typeToDo].removeFront;\n\t foreach(dependant; dependants[ntask])\n\t\t{\n\t\t noDependencies[dependant]--;\n\t\t if (noDependencies[dependant] == 0)\n\t\t {\n\t\t todo[type[dependant]].insertBack(dependant);\n\t\t }\n\t\t}\n\t }\n\t}\n }\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\n//import core.stdc.stdio;\nimport core.stdc.stdlib: alloca, malloc, calloc, realloc, _Exit;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n enum spec = ' ' ~ replicate(\"%s \", vars.length);\n return readf(spec, getAddrTuple(vars).expand) == vars.length;\n}\n\nvoid memSet(T, size_t n)(ref T[n] a, ubyte value) {\n memset(a.ptr, value, a.sizeof);\n}\n\nvoid memSet(T)(T[ ] a, ubyte value) {\n memset(a.ptr, value, a.length * T.sizeof);\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nenum TraverseMode: ubyte {\n proc,\n coproc,\n}\n\nstruct Task {\n bool coproc;\n int deps;\n Task*[ ] next;\n\n bool perform(ref Array!(Task*) q, TraverseMode mode) {\n assert(coproc == (mode == TraverseMode.coproc));\n bool result = false;\n foreach (t; next) {\n assert(t.deps >= 1);\n if (!--t.deps) {\n if (t.coproc == (mode == TraverseMode.coproc))\n result |= t.perform(q, mode);\n else if (mode == TraverseMode.proc)\n result |= t.perform(q, TraverseMode.coproc);\n else {\n q ~= t;\n result = true;\n }\n }\n }\n return result;\n }\n}\n\nint n;\nTask[100_001] _tasks;\n\nvoid main() {\n int m;\n Array!(Task*)[2] q;\n while (read(n, m)) {\n auto tasks = _tasks[0 .. n + 1];\n version (LocalProject)\n tasks[ ] = Task.init;\n q[0].clear();\n char c;\n foreach (ref t; tasks[0 .. n]) {\n read(c);\n t.coproc = c == '1';\n }\n while (m--) {\n int a, b;\n read(a, b);\n tasks[a].deps++;\n tasks[b].next ~= &tasks[a];\n }\n foreach (ref t; tasks[0 .. n])\n if (!t.deps) {\n t.deps = 1;\n tasks[n].next ~= &t;\n }\n\n q[0] ~= &tasks[n];\n int result = 0;\n for (bool cur = 0; !q[cur].empty; cur = !cur) {\n q[!cur].clear();\n bool called = false;\n foreach (t; q[cur])\n called |= t.perform(q[!cur], TraverseMode.proc);\n result += called;\n }\n writeln(result);\n }\n\n stdout.flush();\n _Exit(0);\n}\n"}], "src_uid": "931bf7141636a7222f9043c8ba94830f"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n, m, k, w;\n\twhile (readf (\" %s %s %s %s \", &n, &m, &k, &w) > 0)\n\t{\n\t\tauto a = new string [] [k];\n\t\tforeach (u; 0..k)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\ta[u] ~= readln ().strip ();\n\t\t\t}\n\t\t}\n\n\t\tauto d = new int [] [] (k, k);\n\t\tforeach (u; 0..k)\n\t\t{\n\t\t\td[u][u] = 0;\n\t\t\tforeach (v; 0..u)\n\t\t\t{\n\t\t\t\tint cur = 0;\n\t\t\t\tforeach (i; 0..n)\n\t\t\t\t{\n\t\t\t\t\tforeach (j; 0..m)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur += (a[u][i][j] !=\n\t\t\t\t\t\t a[v][i][j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\td[u][v] = cur * w;\n\t\t\t\td[v][u] = cur * w;\n\t\t\t}\n\t\t}\n\n\t\tlong res = n * m;\n\t\tauto b = new bool [k];\n\t\talias pair = Tuple !(int, \"x\", int, \"y\");\n\t\tauto e = new pair [k];\n\t\tpair [] ans;\n\t\tint r = 0;\n\t\tb[r] = true;\n\t\tforeach (t; 0..k)\n\t\t{\n\t\t\te[t] = pair (int.max, NA);\n\t\t}\n\t\te[r] = pair (0, NA);\n\t\tans ~= pair (r, NA);\n\t\tforeach (t; 1..k)\n\t\t{\n\t\t\tauto z = pair (int.max, NA);\n\t\t\tforeach (v; 0..k)\n\t\t\t{\n\t\t\t\tif (!b[v])\n\t\t\t\t{\n\t\t\t\t\tif (e[v].x > d[r][v])\n\t\t\t\t\t{\n\t\t\t\t\t\te[v] = pair (d[r][v], r);\n\t\t\t\t\t}\n\t\t\t\t\tif (z.x > e[v].x)\n\t\t\t\t\t{\n\t\t\t\t\t\tz = pair (e[v].x, v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tassert (z.x < int.max);\n\t\t\tr = z.y;\n\t\t\tif (z.x >= n * m)\n\t\t\t{\n\t\t\t\te[r] = pair (n * m, NA);\n\t\t\t}\n\t\t\tb[r] = true;\n\t\t\tres += e[r].x;\n\t\t\tans ~= pair (r, e[r].y);\n\t\t}\n\n\t\twriteln (res);\n\t\tforeach (p; ans)\n\t\t{\n\t\t\twriteln (p.x + 1, ' ', p.y + 1);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\n// build graph\n// add a path to each other with the difference price\n// add a path to a node zero representing default costs\n// find the MST\n// print the mst starting with 0.\n\nlong cdiff(char[] a, char[] b){\n long sum = 0;\n foreach(i,c;a){\n if(b[i] != c){\n sum++;\n }\n }\n return sum;\n}\n\nclass Graph{\n char[][] original_nodes;\n long[][] edges;\n size_t vertex;\n\n void build_with(char[][] nodes, int n, int m, int k, int w){\n this.vertex = 1 + nodes.count;\n this.original_nodes ~= [[' ']];\n this.original_nodes ~= nodes;\n this.edges = new long[][](this.vertex,this.vertex);\n\n for(size_t i = 0; i < this.original_nodes.length; i++){\n for(size_t j = i; j < this.original_nodes.length; j++){\n if(i == j){\n this.edges[i][i] = -1;\n } else {\n if(i == 0){\n this.edges[0][j] = n*m;\n this.edges[j][0] = n*m;\n } else {\n auto diff = cdiff(original_nodes[i],original_nodes[j]);\n this.edges[i][j] = diff*w;\n this.edges[j][i] = diff*w;\n }\n }\n }\n }\n }\n}\n\nclass UnionFind{\n size_t[] set;\n size_t[] sz;\n this(size_t n){\n set = new size_t[n];\n sz = new size_t[n];\n for(size_t i = 0; i < n; i++){\n set[i] = i;\n sz[i] = 1;\n }\n }\n\n bool connected(size_t a,size_t b){\n return root(a) == root(b);\n }\n\n void connect(size_t a, size_t b){\n size_t ra = root(a);\n size_t rb = root(b);\n if(sz[rb] > sz[ra]){\n set[ra] = set[rb];\n sz[rb] += sz[ra];\n } else {\n set[rb] = set[ra];\n sz[ra] += sz[rb];\n }\n }\n\n size_t root(size_t a){\n size_t ra = set[a];\n while(ra != set[ra]){\n set[ra] = set[set[ra]];\n ra = set[ra];\n }\n return ra;\n }\n}\n\nclass PQueue{\n Edge[] ctn;\n size_t size;\n this(Graph g){\n ctn ~= Edge.init;\n for(size_t i = 0; i < g.vertex; i++){\n for(size_t j = 0; j < g.vertex; j++){\n long ev = g.edges[i][j];\n if(ev != -1){\n Edge e = Edge(i,j,ev);\n ctn ~= e;\n }\n }\n }\n this.size = ctn.length;\n build_heap();\n }\n\n Edge delMin(){\n Edge ret = ctn[1];\n swap(ctn[1],ctn[size-1]);\n this.size--;\n\n fix_heap(1);\n\n return ret;\n }\n\n bool empty(){\n return this.size == 1;\n }\n\n void fix_heap(size_t i){\n size_t l = 2*i;\n size_t r = 2*i+1;\n size_t smalest = i;\n if(l < this.size && ctn[l].e < ctn[i].e){\n smalest = l;\n } else {\n smalest = i;\n }\n\n if(r < this.size && ctn[r].e < ctn[smalest].e){\n smalest = r;\n }\n\n if(smalest != i){\n swap(ctn[i],ctn[smalest]);\n fix_heap(smalest);\n }\n }\n\n void build_heap(){\n for(size_t i = this.size/2; i > 0; i--){\n fix_heap(i);\n }\n }\n}\n\nstruct Edge{\n size_t v;\n size_t w;\n long e;\n}\n\nclass Mst{\n Graph graph;\n Edge[] mst;\n this(Graph g){\n this.graph = g;\n build_mst(g);\n }\n\n void build_mst(Graph g){\n PQueue pq = new PQueue(g);\n UnionFind uf = new UnionFind(g.vertex);\n while(!pq.empty() && mst.length < g.vertex - 1){\n Edge e = pq.delMin();\n //writeln(pq.ctn);\n if(!uf.connected(e.v,e.w)){\n uf.connect(e.v,e.w);\n mst ~= e;\n }\n }\n }\n\n void print_with_cost(){\n auto lmst = this.mst.dup;\n auto lvls = lmst.length;\n int[] lvl = new int[lvls+1];\n Edge[] other;\n\n int sum = 0;\n for(int i = 0; i < lvls; i++){\n sum += lmst[i].e;\n }\n\n writeln(sum);\n\n auto ptc = lmst.length;\n //writeln(lmst);\n while(ptc > 0){\n foreach(e;lmst){\n if(e.v == 0 && lvl[e.w] == 0){\n writefln(\"%s %s\",e.w,e.v);\n lvl[e.w]++;\n break;\n } else if(e.w == 0 && lvl[e.v] == 0){\n writefln(\"%s %s\",e.v,e.w);\n lvl[e.v]++;\n break;\n } else if(lvl[e.v] == 0 && lvl[e.w] == 1 && e.v != 0) {\n writefln(\"%s %s\",e.v,e.w);\n lvl[e.v]++;\n break;\n } else if(lvl[e.w] == 0 && lvl[e.v] == 1 && e.w != 0){\n writefln(\"%s %s\",e.w,e.v);\n lvl[e.w]++;\n break;\n }\n }\n ptc--;\n }\n //writeln(lvl);\n\n// writeln(sum);\n// for(int i = 0; i < lvls; i++){\n// Edge e = lmst[i];\n// if(e.v == 0 || e.w == 0){\n// if(e.v == 0){\n// writefln(\"%s %s\",e.w,e.v);\n// full ~= e.w;\n// } else {\n// writefln(\"%s %s\",e.v,e.w);\n// full ~= e.v;\n// }\n// } else {\n// other += e;\n// }\n// }\n// writeln(lmst);\n// foreach(o;other){\n// if(lvl[e.v] == 1){\n//\n// } else {\n//\n// }\n// }\n }\n}\n\nvoid main(){\n int n,m,k,w;\n readf(\"%s %s %s %s\\n\",&n,&m,&k,&w);\n\n char[][] d = new char[][](k,m*n);\n for(int i = 0; i < k; i++){\n for(int j = 0; j < m*n; j++){\n char c = '\\n';\n while(c == '\\n'){\n readf(\"%c\",&c);\n }\n d[i][j] = c;\n }\n }\n Graph g = new Graph();\n g.build_with(d,n,m,k,w);\n\n Mst mst = new Mst(g);\n\n mst.print_with_cost();\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n, m, k, w;\n\twhile (readf (\" %s %s %s %s \", &n, &m, &k, &w) > 0)\n\t{\n\t\tauto a = new string [] [k];\n\t\tforeach (u; 0..k)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\ta[u] ~= readln ().strip ();\n\t\t\t}\n\t\t}\n\n\t\tauto d = new int [] [] (k, k);\n\t\tforeach (u; 0..k)\n\t\t{\n\t\t\td[u][u] = 0;\n\t\t\tforeach (v; 0..u)\n\t\t\t{\n\t\t\t\tint cur = 0;\n\t\t\t\tforeach (i; 0..n)\n\t\t\t\t{\n\t\t\t\t\tforeach (j; 0..m)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur += (a[u][i][j] !=\n\t\t\t\t\t\t a[v][i][j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\td[u][v] = cur * w;\n\t\t\t\td[v][u] = cur * w;\n\t\t\t}\n\t\t}\n\n\t\tlong res = n * m;\n\t\tauto b = new bool [k];\n\t\talias pair = Tuple !(int, \"x\", int, \"y\");\n\t\tauto e = new pair [k];\n\t\tpair [] ans;\n\t\tint r = 0;\n\t\tb[r] = true;\n\t\tforeach (t; 0..k)\n\t\t{\n\t\t\te[t] = pair (int.max, NA);\n\t\t}\n\t\te[r] = pair (0, NA);\n\t\tans ~= pair (r, NA);\n\t\tforeach (t; 1..k)\n\t\t{\n\t\t\tauto z = pair (int.max, NA);\n\t\t\tforeach (v; 0..k)\n\t\t\t{\n\t\t\t\tif (!b[v])\n\t\t\t\t{\n\t\t\t\t\tif (e[v].x > d[r][v])\n\t\t\t\t\t{\n\t\t\t\t\t\te[v] = pair (d[r][v], r);\n\t\t\t\t\t}\n\t\t\t\t\tif (z.x > e[v].x)\n\t\t\t\t\t{\n\t\t\t\t\t\tz = pair (e[v].x, v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tassert (z.x < int.max);\n\t\t\tif (z.x >= n * m)\n\t\t\t{\n\t\t\t\te[z.y].y = NA;\n\t\t\t}\n\t\t\tr = z.y;\n\t\t\tb[r] = true;\n\t\t\tres += e[r].x;\n\t\t\tans ~= pair (r, e[r].y);\n\t\t}\n\n\t\twriteln (res);\n\t\tforeach (p; ans)\n\t\t{\n\t\t\twriteln (p.x + 1, ' ', p.y + 1);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\n// build graph\n// add a path to each other with the difference price\n// add a path to a node zero representing default costs\n// find the MST\n// print the mst starting with 0.\n\nlong cdiff(char[] a, char[] b){\n long sum = 0;\n foreach(i,c;a){\n if(b[i] != c){\n sum++;\n }\n }\n return sum;\n}\n\nclass Graph{\n char[][] original_nodes;\n long[][] edges;\n size_t vertex;\n\n void build_with(char[][] nodes, int n, int m, int k, int w){\n this.vertex = 1 + nodes.count;\n this.original_nodes ~= [[' ']];\n this.original_nodes ~= nodes;\n this.edges = new long[][](this.vertex,this.vertex);\n\n for(size_t i = 0; i < this.original_nodes.length; i++){\n for(size_t j = i; j < this.original_nodes.length; j++){\n if(i == j){\n this.edges[i][i] = -1;\n } else {\n if(i == 0){\n this.edges[0][j] = n*m;\n this.edges[j][0] = -1;\n } else {\n auto diff = cdiff(original_nodes[i],original_nodes[j]);\n this.edges[i][j] = diff*w;\n this.edges[j][i] = -1;\n }\n }\n }\n }\n }\n}\n\nclass UnionFind{\n size_t[] set;\n size_t[] sz;\n this(size_t n){\n set = new size_t[n];\n sz = new size_t[n];\n for(size_t i = 0; i < n; i++){\n set[i] = i;\n sz[i] = 1;\n }\n }\n\n bool connected(size_t a,size_t b){\n return root(a) == root(b);\n }\n\n void connect(size_t a, size_t b){\n size_t ra = root(a);\n size_t rb = root(b);\n if(sz[rb] > sz[ra]){\n set[ra] = set[rb];\n sz[rb] += sz[ra];\n } else {\n set[rb] = set[ra];\n sz[ra] += sz[rb];\n }\n }\n\n size_t root(size_t a){\n size_t ra = set[a];\n while(ra != set[ra]){\n set[ra] = set[set[ra]];\n ra = set[ra];\n }\n return ra;\n }\n}\n\nclass PQueue{\n Edge[] ctn;\n size_t size;\n this(Graph g){\n ctn ~= Edge.init;\n for(size_t i = 0; i < g.vertex; i++){\n for(size_t j = 0; j < g.vertex; j++){\n long ev = g.edges[i][j];\n if(ev != -1){\n Edge e = Edge(i,j,ev);\n ctn ~= e;\n }\n }\n }\n this.size = ctn.length;\n build_heap();\n }\n\n Edge delMin(){\n Edge ret = ctn[1];\n swap(ctn[1],ctn[size-1]);\n this.size--;\n\n fix_heap(1);\n\n return ret;\n }\n\n bool empty(){\n return this.size == 1;\n }\n\n void fix_heap(size_t i){\n size_t l = 2*i;\n size_t r = 2*i+1;\n size_t smalest = i;\n if(l < this.size && ctn[l].e < ctn[i].e){\n smalest = l;\n } else {\n smalest = i;\n }\n\n if(r < this.size && ctn[r].e < ctn[smalest].e){\n smalest = r;\n }\n\n if(smalest != i){\n swap(ctn[i],ctn[smalest]);\n fix_heap(smalest);\n }\n }\n\n void build_heap(){\n for(size_t i = this.size/2; i > 0; i--){\n fix_heap(i);\n }\n }\n}\n\nstruct Edge{\n size_t v;\n size_t w;\n long e;\n}\n\nclass Mst{\n Graph graph;\n Edge[] mst;\n this(Graph g){\n this.graph = g;\n build_mst(g);\n }\n\n void build_mst(Graph g){\n PQueue pq = new PQueue(g);\n UnionFind uf = new UnionFind(g.vertex);\n while(!pq.empty() && mst.length < g.vertex - 1){\n Edge e = pq.delMin();\n //writeln(pq.ctn);\n if(!uf.connected(e.v,e.w)){\n uf.connect(e.v,e.w);\n mst ~= e;\n }\n }\n }\n\n void print_with_cost(){\n sort!((a,b){\n size_t ax = min(a.v,a.w);\n size_t bx = min(b.v,b.w);\n return ax < bx;\n })(this.mst);\n long sum = 0;\n foreach(e;this.mst){\n sum += e.e;\n }\n size_t[] lvl = new size_t[this.mst.length+1];\n\n writeln(sum);\n foreach(e;this.mst){\n auto v = min(e.v,e.w);\n auto w = max(e.v,e.w);\n if(v == 0){\n lvl[w]++;\n writefln(\"%s %s\",w,v);\n } else {\n if(lvl[v] == 0){\n lvl[v]++;\n writefln(\"%s %s\",v,w);\n } else {\n lvl[w]++;\n writefln(\"%s %s\",w,v);\n }\n }\n }\n }\n}\n\nvoid main(){\n int n,m,k,w;\n readf(\"%s %s %s %s\\n\",&n,&m,&k,&w);\n\n char[][] d = new char[][](k,m*n);\n for(int i = 0; i < k; i++){\n for(int j = 0; j < m*n; j++){\n char c = '\\n';\n while(c == '\\n'){\n readf(\"%c\",&c);\n }\n d[i][j] = c;\n }\n }\n Graph g = new Graph();\n g.build_with(d,n,m,k,w);\n\n Mst mst = new Mst(g);\n\n mst.print_with_cost();\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\n// build graph\n// add a path to each other with the difference price\n// add a path to a node zero representing default costs\n// find the MST\n// print the mst starting with 0.\n\nlong cdiff(char[] a, char[] b){\n long sum = 0;\n foreach(i,c;a){\n if(b[i] != c){\n sum++;\n }\n }\n return sum;\n}\n\nclass Graph{\n char[][] original_nodes;\n long[][] edges;\n size_t vertex;\n\n void build_with(char[][] nodes, int n, int m, int k, int w){\n this.vertex = 1 + nodes.count;\n this.original_nodes ~= [[' ']];\n this.original_nodes ~= nodes;\n this.edges = new long[][](this.vertex,this.vertex);\n\n for(size_t i = 0; i < this.original_nodes.length; i++){\n for(size_t j = i; j < this.original_nodes.length; j++){\n if(i == j){\n this.edges[i][i] = -1;\n } else {\n if(i == 0){\n this.edges[0][j] = n*m;\n this.edges[j][0] = n*m;\n } else {\n auto diff = cdiff(original_nodes[i],original_nodes[j]);\n this.edges[i][j] = diff*w;\n this.edges[j][i] = diff*w;\n }\n }\n }\n }\n }\n}\n\nclass UnionFind{\n size_t[] set;\n size_t[] sz;\n this(size_t n){\n set = new size_t[n];\n sz = new size_t[n];\n for(size_t i = 0; i < n; i++){\n set[i] = i;\n sz[i] = 1;\n }\n }\n\n bool connected(size_t a,size_t b){\n return root(a) == root(b);\n }\n\n void connect(size_t a, size_t b){\n size_t ra = root(a);\n size_t rb = root(b);\n if(sz[rb] > sz[ra]){\n set[ra] = set[rb];\n sz[rb] += sz[ra];\n } else {\n set[rb] = set[ra];\n sz[ra] += sz[rb];\n }\n }\n\n size_t root(size_t a){\n size_t ra = set[a];\n while(ra != set[ra]){\n set[ra] = set[set[ra]];\n ra = set[ra];\n }\n return ra;\n }\n}\n\nclass PQueue{\n Edge[] ctn;\n size_t size;\n this(Graph g){\n ctn ~= Edge.init;\n for(size_t i = 0; i < g.vertex; i++){\n for(size_t j = 0; j < g.vertex; j++){\n long ev = g.edges[i][j];\n if(ev != -1){\n Edge e = Edge(i,j,ev);\n ctn ~= e;\n }\n }\n }\n this.size = ctn.length;\n build_heap();\n }\n\n Edge delMin(){\n Edge ret = ctn[1];\n swap(ctn[1],ctn[size-1]);\n this.size--;\n\n fix_heap(1);\n\n return ret;\n }\n\n bool empty(){\n return this.size == 1;\n }\n\n void fix_heap(size_t i){\n size_t l = 2*i;\n size_t r = 2*i+1;\n size_t smalest = i;\n if(l < this.size && ctn[l].e < ctn[i].e){\n smalest = l;\n } else {\n smalest = i;\n }\n\n if(r < this.size && ctn[r].e < ctn[smalest].e){\n smalest = r;\n }\n\n if(smalest != i){\n swap(ctn[i],ctn[smalest]);\n fix_heap(smalest);\n }\n }\n\n void build_heap(){\n for(size_t i = this.size/2; i > 0; i--){\n fix_heap(i);\n }\n }\n}\n\nstruct Edge{\n size_t v;\n size_t w;\n long e;\n}\n\nclass Mst{\n Graph graph;\n Edge[] mst;\n this(Graph g){\n this.graph = g;\n build_mst(g);\n }\n\n void build_mst(Graph g){\n PQueue pq = new PQueue(g);\n UnionFind uf = new UnionFind(g.vertex);\n while(!pq.empty() && mst.length < g.vertex - 1){\n Edge e = pq.delMin();\n //writeln(pq.ctn);\n if(!uf.connected(e.v,e.w)){\n uf.connect(e.v,e.w);\n mst ~= e;\n }\n }\n }\n\n void print_with_cost(){\n //writeln(this.graph.edges);\n //writeln(this.graph.original_nodes);\n //writefln(\"%s\",this.mst.length);\n long[2][] pt;\n long sum;\n\n foreach(e;this.mst){\n if(e.v == 0 || e.w == 0){\n size_t v;\n if(e.v == 0){\n v = e.w;\n } else {\n v = e.v;\n }\n pt ~= [v,0];\n sum += e.e;\n } else {\n pt ~= [e.v,e.w];\n sum += e.e;\n }\n }\n writeln(sum);\n foreach(p;pt){\n writefln(\"%s %s\",p[0],p[1]);\n }\n }\n}\n\nvoid main(){\n int n,m,k,w;\n readf(\"%s %s %s %s\\n\",&n,&m,&k,&w);\n\n char[][] d = new char[][](k,m*n);\n for(int i = 0; i < k; i++){\n for(int j = 0; j < m*n; j++){\n char c = '\\n';\n while(c == '\\n'){\n readf(\"%c\",&c);\n }\n d[i][j] = c;\n }\n }\n Graph g = new Graph();\n g.build_with(d,n,m,k,w);\n\n Mst mst = new Mst(g);\n\n mst.print_with_cost();\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\n// build graph\n// add a path to each other with the difference price\n// add a path to a node zero representing default costs\n// find the MST\n// print the mst starting with 0.\n\nlong cdiff(char[] a, char[] b){\n long sum = 0;\n foreach(i,c;a){\n if(b[i] != c){\n sum++;\n }\n }\n return sum;\n}\n\nclass Graph{\n char[][] original_nodes;\n long[][] edges;\n size_t vertex;\n\n void build_with(char[][] nodes, int n, int m, int k, int w){\n this.vertex = 1 + nodes.count;\n this.original_nodes ~= [[' ']];\n this.original_nodes ~= nodes;\n this.edges = new long[][](this.vertex,this.vertex);\n\n for(size_t i = 0; i < this.original_nodes.length; i++){\n for(size_t j = i; j < this.original_nodes.length; j++){\n if(i == j){\n this.edges[i][i] = -1;\n } else {\n if(i == 0){\n this.edges[0][j] = n*m;\n this.edges[j][0] = n*m;\n } else {\n auto diff = cdiff(original_nodes[i],original_nodes[j]);\n this.edges[i][j] = diff*w;\n this.edges[j][i] = diff*w;\n }\n }\n }\n }\n }\n}\n\nclass UnionFind{\n size_t[] set;\n size_t[] sz;\n this(size_t n){\n set = new size_t[n];\n sz = new size_t[n];\n for(size_t i = 0; i < n; i++){\n set[i] = i;\n sz[i] = 1;\n }\n }\n\n bool connected(size_t a,size_t b){\n return root(a) == root(b);\n }\n\n void connect(size_t a, size_t b){\n size_t ra = root(a);\n size_t rb = root(b);\n if(sz[rb] > sz[ra]){\n set[ra] = set[rb];\n sz[rb] += sz[ra];\n } else {\n set[rb] = set[ra];\n sz[ra] += sz[rb];\n }\n }\n\n size_t root(size_t a){\n size_t ra = set[a];\n while(ra != set[ra]){\n set[ra] = set[set[ra]];\n ra = set[ra];\n }\n return ra;\n }\n}\n\nclass PQueue{\n Edge[] ctn;\n size_t size;\n this(Graph g){\n ctn ~= Edge.init;\n for(size_t i = 0; i < g.vertex; i++){\n for(size_t j = 0; j < g.vertex; j++){\n long ev = g.edges[i][j];\n if(ev != -1){\n Edge e = Edge(i,j,ev);\n ctn ~= e;\n }\n }\n }\n this.size = ctn.length;\n build_heap();\n }\n\n Edge delMin(){\n Edge ret = ctn[1];\n swap(ctn[1],ctn[size-1]);\n this.size--;\n\n fix_heap(1);\n\n return ret;\n }\n\n bool empty(){\n return this.size == 1;\n }\n\n void fix_heap(size_t i){\n size_t l = 2*i;\n size_t r = 2*i+1;\n size_t smalest = i;\n if(l < this.size && ctn[l].e < ctn[i].e){\n smalest = l;\n } else {\n smalest = i;\n }\n\n if(r < this.size && ctn[r].e < ctn[smalest].e){\n smalest = r;\n }\n\n if(smalest != i){\n swap(ctn[i],ctn[smalest]);\n fix_heap(smalest);\n }\n }\n\n void build_heap(){\n for(size_t i = this.size/2; i > 0; i--){\n fix_heap(i);\n }\n }\n}\n\nstruct Edge{\n size_t v;\n size_t w;\n long e;\n}\n\nclass Mst{\n Graph graph;\n Edge[] mst;\n this(Graph g){\n this.graph = g;\n build_mst(g);\n }\n\n void build_mst(Graph g){\n PQueue pq = new PQueue(g);\n UnionFind uf = new UnionFind(g.vertex);\n while(!pq.empty() && mst.length < g.vertex - 1){\n Edge e = pq.delMin();\n //writeln(pq.ctn);\n if(!uf.connected(e.v,e.w)){\n uf.connect(e.v,e.w);\n mst ~= e;\n }\n }\n }\n\n void print_with_cost(){\n sort!((a,b){\n size_t ax = min(a.v,a.w);\n size_t bx = min(b.v,b.w);\n return ax < bx;\n })(this.mst);\n long sum = 0;\n foreach(e;this.mst){\n sum += e.e;\n }\n size_t[] lvl = new size_t[this.mst.length+1];\n\n writeln(sum);\n foreach(e;this.mst){\n if(lvl[e.v] == 0){\n lvl[e.v]++;\n writefln(\"%s %s\",e.v,e.w);\n } else {\n lvl[e.w]++;\n writefln(\"%s %s\",e.w,e.v);\n }\n //writeln(lvl);\n }\n }\n}\n\nvoid main(){\n int n,m,k,w;\n readf(\"%s %s %s %s\\n\",&n,&m,&k,&w);\n\n char[][] d = new char[][](k,m*n);\n for(int i = 0; i < k; i++){\n for(int j = 0; j < m*n; j++){\n char c = '\\n';\n while(c == '\\n'){\n readf(\"%c\",&c);\n }\n d[i][j] = c;\n }\n }\n Graph g = new Graph();\n g.build_with(d,n,m,k,w);\n\n Mst mst = new Mst(g);\n\n mst.print_with_cost();\n}\n"}], "src_uid": "001e4cd3ddd7780111b1371511f16916"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto rb = RD!int-1;\r\n\t\tauto cb = RD!int-1;\r\n\t\tauto rd = RD!int-1;\r\n\t\tauto cd = RD!int-1;\r\n\r\n\t\tint dr = 1, dc = 1;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (rb == rd || cb == cd) break;\r\n\t\t\tif (rb + dr >= n)\r\n\t\t\t\tdr = -1;\r\n\t\t\tif (rb + dr < 0)\r\n\t\t\t\tdr = 1;\r\n\t\t\tif (cb + dc >= m)\r\n\t\t\t\tdc = -1;\r\n\t\t\tif (cb + dc < 0)\r\n\t\t\t\tdc = 1;\r\n\t\t\trb += dr;\r\n\t\t\tcb += dc;\r\n\t\t\t++ans[ti];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n auto Q = scan!long(6 * QN).chunks(6);\r\n\r\n auto solve() {\r\n foreach(q; Q) {\r\n auto F = Point(q[0], q[1]);\r\n auto S = Point(q[2], q[3]);\r\n auto G = Point(q[4], q[5]);\r\n\r\n writeln(min(\r\n G.x < S.x ? 2*(F.x - S.x) + (S.x - G.x) : G.x - S.x,\r\n G.y < S.y ? 2*(F.y - S.y) + (S.y - G.y) : G.y - S.y,\r\n ));\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "// \u63d0\u51fa\u89e3\r\nvoid solve(){\r\n\tforeach(_; 0 .. scan!int){\r\n\t\tint n = scan!int, m = scan!int;\r\n\t\tint rb = scan!int - 1, cb = scan!int - 1;\r\n\t\tint rd = scan!int - 1, cd = scan!int - 1;\r\n\r\n\t\tint high = n + m;\r\n\t\tint ans = high;\r\n\t\tif(rd >= rb) ans.mini(rd - rb);\r\n\t\telse ans.mini(n - 1 - rb + n - 1 - rd);\r\n\t\tif(cd >= cb) ans.mini(cd - cb);\r\n\t\telse ans.mini(m - 1 - cb + m - 1 - cd);\r\n\r\n\t\tans.print;\r\n\t}\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u611a\u76f4\u89e3\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30f3\u30d7\u30ec\r\nimport std;\r\nbool DEBUG = 0;\r\nvoid main(string[] args){\r\n\tif(args.canFind(\"-debug\")) DEBUG = 1;\r\n\tif(args.canFind(\"-gen\")) gen; else if(args.canFind(\"-jury\")) jury; else solve;\r\n}\r\nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\r\nvoid print(){ writeln(\"\"); }\r\nvoid print(T)(T t){ writeln(t); }\r\nvoid print(T, A ...)(T t, A a){ stdout.write(t, \" \"), print(a); }\r\nstring unsplit(T)(T xs, string d = \" \"){ return xs.array.to!(string[]).join(d); }\r\nstring scan(){\r\n\tstatic string[] ss; while(!ss.length) ss = readln.chomp.split;\r\n\tstring res = ss[0]; ss.popFront; return res;\r\n}\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\r\nT mini(T)(ref T x, T y){ if(x > y) x = y; return x; }\r\nT maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }\r\nT mid(T)(T l, T r, bool delegate(T) f){\r\n\tT m = (l + r) / 2; (f(m)? l: r) = m; return f(l)? f(r - 1)? r: mid(l, r, f): l;\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u57fa\u672c\uff09\r\n\r\nclass UnionFind{\r\n\tthis(int n){ foreach(i; 0 .. n) R ~= i, K ~= [i]; } int[] R; int[][] K;\r\n\tvoid unite(int a, int b){\r\n\t\tint ra = R[a], rb = R[b]; if(ra == rb) return;\r\n\t\tif(K[ra].length < K[rb].length) unite(b, a);\r\n\t\telse foreach(k; K[rb]) R[k] = ra, K[ra] ~= k;\r\n\t}\r\n\tint find(int a){ return R[a]; }\r\n\tint getSize(int a){ return K[R[a]].length.to!int; }\r\n}\r\nclass Queue(T){\r\n\tprivate T[] xs; private uint i, j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j - i; }\r\n\tbool isEmpty(){ return j == i; } \r\n\tvoid enq(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT deq(){ assert(i < j); return xs[i ++]; }\r\n\tT peek(){ assert(i < j); return xs[i]; }\r\n\tvoid flush(){ i = j; }\r\n\talias empty = isEmpty, front = peek, popFront = deq, pop = deq, push = enq, top = peek;\r\n\tQueue opOpAssign(string op)(T x) if(op == \"~\"){ enq(x); return this; }\r\n\tT opIndex(uint li){ assert(i + li < j); return xs[i + li]; }\r\n\tstatic Queue!T opCall(T[] xs){ return new Queue!T(xs); }\r\n\tT[] array(){ return xs[i .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\nclass Stack(T){\r\n\tprivate T[] xs; private uint j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j; }\r\n\tbool isEmpty(){ return j == 0; }\r\n\tvoid push(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT pop(){ assert(j > 0); return xs[-- j]; }\r\n\tT peek(){ assert(j > 0); return xs[j - 1]; }\r\n\tvoid clear(){ j = 0; }\r\n\talias empty = isEmpty, front = peek, popFront = pop, top = peek;\r\n\tStack opOpAssign(string op)(T x) if(op == \"~\"){ push(x); return this; }\r\n\tT opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }\r\n\tstatic Stack!T opCall(T[] xs = []){ return new Stack!T(xs); }\r\n\tT[] array(){ return xs[0 .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u8ffd\u52a0\uff09\r\n\r\n\r\n"}, {"source_code": "import std;\n\nvoid main () {\n int tests;\n readf(\"%s\\n\", tests);\n\n foreach (test_index; 0 .. tests) {\n int n, m, rb, cb, rd, cd;\n readf(\"%s %s %s %s %s %s\\n\", n, m, rb, cb, rd, cd);\n\n int reach_line;\n int reach_column;\n\n if (rb <= rd)\n reach_line = rd - rb;\n else\n reach_line = n - rb + n - rd;\n\n if (cb <= cd)\n reach_column = cd - cb;\n else\n reach_column = m - cb + m - cd;\n\n writeln(min(reach_line, reach_column));\n }\n}\n// \"\"\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n int n, m, x, y, X, Y;\n read(n, m, x, y, X, Y);\n int dr = 1, dc = 1;\n int time = 0;\n while (x != X && y != Y) {\n // check dir \n if (x == n) dr = -1;\n if (x == 0) dr = 1;\n if (y == m) dc = -1;\n if (y == 0) dc = 1;\n\n x += dr;\n y += dc;\n\n time++;\n }\n writeln(time);\n }\n}\n\n"}], "negative_code": [{"source_code": "import std;\n\nvoid main () {\n int tests;\n readf(\"%s\\n\", tests);\n\n foreach (test_index; 0 .. tests) {\n int n, m, rb, cb, rd, cd;\n readf(\"%s %s %s %s %s %s\\n\", n, m, rb, cb, rd, cd);\n\n int reach_line;\n int reach_column;\n\n if (rb <= rd)\n reach_line = rd - rb;\n else\n reach_line = m - rb + m - rd;\n\n if (cb <= cd)\n reach_column = cd - cb;\n else\n reach_column = n - cb + n - cd;\n\n writeln(min(reach_line, reach_column));\n }\n}\n// \"\"\n"}, {"source_code": "import std;\n\nvoid main () {\n int tests;\n readf(\"%s\\n\", tests);\n\n foreach (test_index; 0 .. tests) {\n int n, m, rb, cb, rd, cd;\n readf(\"%s %s %s %s %s %s\\n\", n, m, rb, cb, rd, cd);\n\n int reach_line;\n int reach_column;\n\n if (rb <= rd)\n reach_line = rd - rb;\n else\n reach_line = m - rb + m - rd;\n\n if (cb <= cd)\n reach_column = cd - cb;\n else\n reach_column = m - cb + m - cd;\n\n writeln(min(reach_line, reach_column));\n }\n}\n// \"\"\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n int n, m, x, y, X, Y;\n read(n, m, x, y, X, Y);\n int dr = 1, dc = 1;\n int time = 0;\n while (x != X && y != Y) {\n // check dir \n if (x == n) dr = -1;\n if (x == 0) dr = 1;\n if (y == m) dc = -1;\n if (y == 0) dc = 1;\n\n x += dr;\n y += dc;\n\n time++;\n\n if (time == 20) break;\n }\n writeln(time);\n }\n}\n\n"}], "src_uid": "6f819ce1d88d5211cd475a8673edba97"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n auto a=readln.split.to!(int[]);\n\n struct Pair{\n int val, idx;\n }\n auto data=new Pair[](n);\n foreach(i; 0..n) data[i]=Pair(a[i], i);\n sort!((l, r)=>(l.val==r.val ? l.idx<r.idx : l.val<r.val))(data);\n auto b=a.dup;\n sort(b);\n int cnt=0;\n for(int i=0, j=0; i<n && j<n; i++, j++){\n while(i<n && b[i]<=a[data[j].idx]) i++;\n if(i<n) cnt++;\n }\n writeln(cnt);\n\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n\n/*\n\n7\n10 1 1 1 5 5 3\n\n1 2 3 6 4 5 0\n\n*/", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.container;\n\nvoid main() {\n alias Tree = RedBlackTree!(int,\"a<b\",true);\n immutable n = readln.strip.to!int;\n auto a = readln.strip.splitter.map! (i => i.to!int).array[0..n];\n sort (a);\n auto t = make!Tree (a);\n debug stderr.writeln (t);\n int res;\n foreach (i; a) {\n auto r = t.upperBound (i);\n if (!r.empty) {\n int v = r.front;\n debug stderr.writefln (\"%d %d\", i, v);\n ++res;\n t.removeKey (v);\n }\n }\n writeln (res);\n}\n"}], "negative_code": [], "src_uid": "eaa768dc1024df6449e89773234cc0c3"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto W = s[1];\n auto H = s[2];\n\n\n auto P = new Tuple!(int, int)[](N);\n Tuple!(int, int, int)[][int] tate;\n Tuple!(int, int, int)[][int] yoko;\n\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n if (s[0] == 1) {\n P[i] = tuple(s[1], H);\n tate[s[1] - s[2]] ~= tuple(i, s[1], -s[2]);\n } else {\n P[i] = tuple(W, s[1]);\n yoko[s[1] - s[2]] ~= tuple(i, -s[2], s[1]);\n }\n }\n\n foreach (k; tate.keys)\n tate[k].sort!\"a[1] < b[1]\";\n\n foreach (k; yoko.keys)\n yoko[k].sort!\"a[2] < b[2]\";\n\n\n auto ans = new int[](N);\n\n foreach (k; tate.keys) {\n if (!(k in yoko)) {\n foreach (v; tate[k])\n ans[v[0]] = v[0];\n continue;\n }\n\n DList!(int) queue;\n foreach (v; yoko[k])\n queue.insertFront(v[0]);\n\n foreach (v; tate[k]) {\n auto n = queue.front;\n queue.removeFront;\n ans[n] = v[0];\n queue.insertBack(v[0]);\n }\n\n for (int i = yoko[k].length.to!int - 1; !queue.empty; i--) {\n auto n = queue.front;\n queue.removeFront;\n ans[n] = yoko[k][i][0];\n }\n }\n\n\n foreach (k; yoko.keys) {\n if (!(k in tate)) {\n foreach (v; yoko[k]) {\n ans[v[0]] = v[0];\n }\n }\n }\n\n ans.each!(a => writeln(P[a][0], \" \", P[a][1]));\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct Dancer {\n int g, p, t;\n int id;\n int diff;\n}\n\nstruct Pt {\n int x, y;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const W = readInt();\n const H = readInt();\n auto D = new Dancer[N];\n foreach (i; 0 .. N) {\n D[i].g = readInt();\n D[i].p = readInt();\n D[i].t = readInt();\n D[i].id = i;\n }\n \n foreach (i; 0 .. N) {\n D[i].diff = D[i].t - D[i].p;\n }\n D.sort!((a, b) =>\n (a.diff != b.diff) ? (a.diff < b.diff)\n : (a.g != b.g) ? (a.g > b.g)\n : (a.g == 2) ? (a.p > b.p) : (a.p < b.p));\n \n auto ans = new Pt[N];\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && D[i].diff == D[j].diff; ++j) {}\n debug {\n writeln(\"D[i .. j] = \", D[i .. j]);\n }\n Pt[] ps;\n foreach (k; i .. j) {\n ps ~= (D[k].g == 1) ? Pt(D[k].p, H) : Pt(W, D[k].p);\n }\n ps.sort!((p, q) => (p.x != q.x) ? (p.x < q.x) : (p.y > q.y));\n debug {\n writeln(\"ps = \", ps);\n }\n foreach (k; i .. j) {\n ans[D[k].id] = ps[k - i];\n }\n }\n \n foreach (i; 0 .. N) {\n writeln(ans[i].x, \" \", ans[i].y);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n struct InputData\n {\n int g, p, t;\n }\n struct Point\n {\n long x, y;\n }\n auto n = next!int;\n auto w = next!int;\n auto h = next!int;\n auto idata = new InputData[](n);\n auto point = new Point[](n);\n foreach(p; 0 .. n)\n {\n idata[p].g = next!int;\n idata[p].p = next!int;\n idata[p].t = next!int;\n if (idata[p].g == 1)\n\t{\n\t point[p].x = idata[p].p;\n\t point[p].y = -idata[p].t;\n\t}\n else\n\t{\n\t point[p].y = idata[p].p;\n\t point[p].x = -idata[p].t;\n\t}\n }\n int[][long] lineids;\n foreach(i, p; point)\n {\n lineids.require(p.y + p.x, null) ~= cast(int) i;\n }\n foreach(ref line; lineids)\n {\n sort!((i, j) => point[i].x < point[j].x)(line);\n debug writeln(line);\n }\n auto endid = new int[](n);\n foreach(ref line; lineids)\n {\n int nH = 0;\n foreach(id; line)\n\t{\n\t if (idata[id].g == 1) break;\n\t nH++;\n\t}\n int nV = cast(int) line.length - nH;\n foreach(k; 0 .. nV)\n\t{\n\t endid[line[k]] = line[$ - nV + k];\n\t}\n foreach(k; 0 .. nH)\n\t{\n\t endid[line[nV + k]] = line[k];\n\t}\n }\n Point endPos(int id)\n {\n if (idata[id].g == 1)\n {\n\treturn Point(idata[id].p, h);\n }\n return Point(w, idata[id].p);\n }\n\n foreach(i; 0 .. n)\n {\n auto p = endPos(endid[i]);\n writeln(p.x, \" \", p.y);\n }\n writeln;\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [], "src_uid": "8f64c179a883047bf66ee14994364580"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto xnm = readln.split.to!(int[]);\n auto X = xnm[0];\n auto N = xnm[1];\n auto M = xnm[2];\n\n while (N > 0 && X/2 >= 10) {\n X = X/2 + 10;\n --N;\n }\n writeln(X <= M*10 ? \"YES\" : \"NO\");\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD;\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (x <= 19) break;\n\t\t\tx = x / 2 + 10;\n\t\t}\n\t\tans[ti] = x <= m*10;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n int x = r.next!uint;\n const n = r.next!uint;\n const m = r.next!uint;\n foreach (i; 0 .. n) {\n const y = (x / 2) + 10;\n if (y >= x) break;\n x = y;\n }\n x -= m * 10;\n writeln (x > 0 ? \"NO\" : \"YES\");\n }\n}\n\n"}], "negative_code": [], "src_uid": "78f25e2bc4ff22dbac94f72af68a745f"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint nR, nG, nB;\n\twhile (readf !(\" %s %s %s\") (nR, nG, nB) > 0)\n\t{\n\t\treadln;\n\t\tauto r = readln.splitter.map !(to !(int)).array;\n\t\tauto g = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tsort !(q{a > b}) (r);\n\t\tsort !(q{a > b}) (g);\n\t\tsort !(q{a > b}) (b);\n\t\tauto f = new int [] [] [] (nR + 1, nG + 1, nB + 1);\n\t\tint res = 0;\n\t\tforeach (i; 0..nR + 1)\n\t\t{\n\t\t\tforeach (j; 0..nG + 1)\n\t\t\t{\n\t\t\t\tforeach (k; 0..nB + 1)\n\t\t\t\t{\n\t\t\t\t\tif (i > 0 && j > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[i][j][k] = max (f[i][j][k],\n\t\t\t\t\t\t f[i - 1][j - 1][k] +\n\t\t\t\t\t\t r[i - 1] * g[j - 1]);\n\t\t\t\t\t}\n\t\t\t\t\tif (j > 0 && k > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[i][j][k] = max (f[i][j][k],\n\t\t\t\t\t\t f[i][j - 1][k - 1] +\n\t\t\t\t\t\t g[j - 1] * b[k - 1]);\n\t\t\t\t\t}\n\t\t\t\t\tif (i > 0 && k > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[i][j][k] = max (f[i][j][k],\n\t\t\t\t\t\t f[i - 1][j][k - 1] +\n\t\t\t\t\t\t r[i - 1] * b[k - 1]);\n\t\t\t\t\t}\n\t\t\t\t\tres = max (res, f[i][j][k]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto R = RD!int;\n\tauto G = RD!int;\n\tauto B = RD!int;\n\tauto r = RDA!int;\n\tauto g = RDA!int;\n\tauto b = RDA!int;\n\tr.sort!\"a > b\";\n\tg.sort!\"a > b\";\n\tb.sort!\"a > b\";\n\n\tlong ans;\n\tauto dp = new long[][][](R+1, G+1, B+1);\n\tforeach (i; 0..(R+G+B)+2)\n\t{\n\t\tif (i % 2 == 1) continue;\n\t\tforeach (ri; 0..i)\n\t\t{\n\t\t\tif (ri > R) break;\n\t\t\tforeach (gi; 0..i-(ri+1))\n\t\t\t{\n\t\t\t\tif (gi > G) break;\n\t\t\t\tauto bi = i-(ri+1)-(gi+1);\n\t\t\t\tif (bi > B) continue;\n\n\t\t\t\tif (ri < R && gi < G)\n\t\t\t\t{\n\t\t\t\t\tdp[ri+1][gi+1][bi].chmax(dp[ri][gi][bi] + r[ri]*g[gi]);\n\t\t\t\t\tans.chmax(dp[ri+1][gi+1][bi]);\n\t\t\t\t}\n\t\t\t\tif (ri < R && bi < B)\n\t\t\t\t{\n\t\t\t\t\tdp[ri+1][gi][bi+1].chmax(dp[ri][gi][bi] + r[ri]*b[bi]);\n\t\t\t\t\tans.chmax(dp[ri+1][gi][bi+1]);\n\t\t\t\t}\n\t\t\t\tif (gi < G && bi < B)\n\t\t\t\t{\n\t\t\t\t\tdp[ri][gi+1][bi+1].chmax(dp[ri][gi][bi] + g[gi]*b[bi]);\n\t\t\t\t\tans.chmax(dp[ri][gi+1][bi+1]);\n\t\t\t\t}\n\t\t\t\tdebug writeln(ri, \",\", gi, \",\", bi, \" ans:\", ans);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1398/problem/D\n//\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n uint R, G, B;\n readf(\"%s %s %s\", &R, &G, &B);\n readln;\n\n long[] r = readln.split.map!(to!long).array;\n long[] g = readln.split.map!(to!long).array;\n long[] b = readln.split.map!(to!long).array;\n\n r.sort!(\"a > b\");\n g.sort!(\"a > b\");\n b.sort!(\"a > b\");\n\n long[][][] dp = new long[][][](R+1, G+1, B+1);\n\n long ans = long.min;\n for(int i = 0; i <= R; i++) {\n for(int j = 0; j <= G; j++) {\n for(int k = 0; k <= B; k++) {\n if(i < R && j < G)\n dp[i + 1][j + 1][k] = max(dp[i + 1][j + 1][k], dp[i][j][k] + r[i] * g[j]);\n if(i < R && k < B)\n dp[i + 1][j][k + 1] = max(dp[i + 1][j][k + 1], dp[i][j][k] + r[i] * b[k]);\n if(j < G && k < B)\n dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + g[j] * b[k]);\n ans = max(ans, dp[i][j][k]);\n }\n }\n }\n ans.writeln;\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint nR, nG, nB;\n\twhile (readf !(\" %s %s %s\") (nR, nG, nB) > 0)\n\t{\n\t\treadln;\n\t\tauto r = readln.splitter.map !(to !(int)).array ~ 0;\n\t\tauto g = readln.splitter.map !(to !(int)).array ~ 0;\n\t\tauto b = readln.splitter.map !(to !(int)).array ~ 0;\n\t\tsort !(q{a > b}) (r);\n\t\tsort !(q{a > b}) (g);\n\t\tsort !(q{a > b}) (b);\n\t\tint res = 0;\n\t\tforeach (rg; 0..min (nR, nG) + 1)\n\t\t{\n\t\t\tforeach (gb; 0..min (nG, nB) + 1)\n\t\t\t{\n\t\t\t\tforeach (br; 0..min (nB, nR) + 1)\n\t\t\t\t{\n\t\t\t\t\tif (rg + br > nR ||\n\t\t\t\t\t rg + gb > nG ||\n\t\t\t\t\t gb + br > nB)\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tint temp = 0;\n\t\t\t\t\tint i = 0, j = 0, k = 0;\n\t\t\t\t\tint u = 0, v = 0, w = 0;\n\t\t\t\t\twhile (true)\n\t\t\t\t\t{\n\t\t\t\t\t\tint cur = 0;\n\t\t\t\t\t\tint pos = -1;\n\t\t\t\t\t\tif (u < rg &&\n\t\t\t\t\t\t cur < r[i] * g[j])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcur = r[i] * g[j];\n\t\t\t\t\t\t\tpos = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (v < gb &&\n\t\t\t\t\t\t cur < g[j] * b[k])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcur = g[j] * b[k];\n\t\t\t\t\t\t\tpos = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (w < br &&\n\t\t\t\t\t\t cur < b[k] * r[i])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcur = b[k] * r[i];\n\t\t\t\t\t\t\tpos = 2;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pos == -1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttemp += cur;\n\t\t\t\t\t\tif (pos == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tu += 1;\n\t\t\t\t\t\t\ti += 1;\n\t\t\t\t\t\t\tj += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pos == 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tv += 1;\n\t\t\t\t\t\t\tj += 1;\n\t\t\t\t\t\t\tk += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pos == 2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tw += 1;\n\t\t\t\t\t\t\tk += 1;\n\t\t\t\t\t\t\ti += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tres = max (res, temp);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto R = RD!int;\n\tauto G = RD!int;\n\tauto B = RD!int;\n\tauto r = RDA!int;\n\tauto g = RDA!int;\n\tauto b = RDA!int;\n\tr.sort!\"a > b\";\n\tg.sort!\"a > b\";\n\tb.sort!\"a > b\";\n\n\tlong ans;\n\tauto dp = new long[][][](R+1, G+1, B+1);\n\tforeach (i; 0..(R+G+B)+1)\n\t{\n\t\tif (i % 2 == 1) continue;\n\t\tforeach (ri; 0..i)\n\t\t{\n\t\t\tif (ri > R) break;\n\t\t\tforeach (gi; 0..i-(ri+1))\n\t\t\t{\n\t\t\t\tif (gi > G) break;\n\t\t\t\tauto bi = i-(ri+1)-(gi+1);\n\t\t\t\tif (bi > B) break;\n\n\t\t\t\tif (ri < R && gi < G)\n\t\t\t\t{\n\t\t\t\t\tdp[ri+1][gi+1][bi].chmax(dp[ri][gi][bi] + r[ri]*g[gi]);\n\t\t\t\t\tans.chmax(dp[ri+1][gi+1][bi]);\n\t\t\t\t}\n\t\t\t\tif (ri < R && bi < B)\n\t\t\t\t{\n\t\t\t\t\tdp[ri+1][gi][bi+1].chmax(dp[ri][gi][bi] + r[ri]*b[bi]);\n\t\t\t\t\tans.chmax(dp[ri+1][gi][bi+1]);\n\t\t\t\t}\n\t\t\t\tif (gi < G && bi < B)\n\t\t\t\t{\n\t\t\t\t\tdp[ri][gi+1][bi+1].chmax(dp[ri][gi][bi] + g[gi]*b[bi]);\n\t\t\t\t\tans.chmax(dp[ri][gi+1][bi+1]);\n\t\t\t\t}\n\t\t\t\tdebug writeln(ri, \",\", gi, \",\", bi, \" ans:\", ans);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto R = RD!int;\n\tauto G = RD!int;\n\tauto B = RD!int;\n\tauto r = RDA!int;\n\tauto g = RDA!int;\n\tauto b = RDA!int;\n\tr.sort!\"a > b\";\n\tg.sort!\"a > b\";\n\tb.sort!\"a > b\";\n\n\tlong ans;\n\tauto dp = new long[][][](R+1, G+1, B+1);\n\tforeach (i; 0..(R+G+B)+2)\n\t{\n\t\tif (i % 2 == 1) continue;\n\t\tforeach (ri; 0..i)\n\t\t{\n\t\t\tif (ri > R) break;\n\t\t\tforeach (gi; 0..i-(ri+1))\n\t\t\t{\n\t\t\t\tif (gi > G) break;\n\t\t\t\tauto bi = i-(ri+1)-(gi+1);\n\t\t\t\tif (bi > B) break;\n\n\t\t\t\tif (ri < R && gi < G)\n\t\t\t\t{\n\t\t\t\t\tdp[ri+1][gi+1][bi].chmax(dp[ri][gi][bi] + r[ri]*g[gi]);\n\t\t\t\t\tans.chmax(dp[ri+1][gi+1][bi]);\n\t\t\t\t}\n\t\t\t\tif (ri < R && bi < B)\n\t\t\t\t{\n\t\t\t\t\tdp[ri+1][gi][bi+1].chmax(dp[ri][gi][bi] + r[ri]*b[bi]);\n\t\t\t\t\tans.chmax(dp[ri+1][gi][bi+1]);\n\t\t\t\t}\n\t\t\t\tif (gi < G && bi < B)\n\t\t\t\t{\n\t\t\t\t\tdp[ri][gi+1][bi+1].chmax(dp[ri][gi][bi] + g[gi]*b[bi]);\n\t\t\t\t\tans.chmax(dp[ri][gi+1][bi+1]);\n\t\t\t\t}\n\t\t\t\tdebug writeln(ri, \",\", gi, \",\", bi, \" ans:\", ans);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "9e6cb1e8037e1d35b6c6fe43f805a22f"} {"source_code": "import std.stdio;\nvoid main() {\n int n, l, r;\n scanf(\"%d\", &n);\n foreach(_; 0..n) {\n scanf(\"%d %d\", &l, &r);\n --l;\n writeln(r/2 - r%2*r - l/2 + l%2*l);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nvoid main() {\n int n, l, r;\n readf!\"%d\\n\"(n);\n foreach(_; 0..n) {\n readf!\"%d %d\\n\"(l, r);\n --l;\n writeln(r/2 - r%2*r - l/2 + l%2*l);\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nvoid main() {\n int n, l, r;\n readf!\"%d \"(n);\n foreach(_; 0..n) {\n readf!\" %d %d\"(l, r);\n writeln(r/2 - r%2*r - (--l)/2 + l%2*l);\n }\n}\n\n"}, {"source_code": "import std.stdio;\nvoid main() {\n int n, l, r;\n scanf(\"%d\", &n);\n foreach(_; 0..n) {\n scanf(\"%d %d\", &l, &r);\n writeln(r/2 - r%2*r - (--l)/2 + l%2*l);\n }\n}\n\n"}, {"source_code": "import std.stdio;\nvoid main() {\n int n, l, r;\n readf!\"%d\\n\"(n);\n foreach(_; 0..n) {\n readf!\"%d %d\\n\"(l, r);\n writeln(r/2 - r%2*r - (--l)/2 + l%2*l);\n }\n}\n\n"}], "src_uid": "7eae40835f6e9580b985d636d5730e2d"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n char[][] A, B;\r\n get_lines(N, A);\r\n readln;\r\n get_lines(N, B);\r\n\r\n auto M = new bool[][](N, N);\r\n foreach (i; 0..N) foreach (j; 0..N) if (A[i][j] != B[i][j]) M[i][j] = true;\r\n foreach (i; 1..N) if (M[i-1][0] != M[i][0]) foreach (j; 0..N) M[i][j] = !M[i][j];\r\n foreach (j; 0..N) foreach (i; 0..N) if (M[i][j] != M[0][j]) goto ng;\r\n writeln(\"YES\");\r\n continue;\r\n ng:\r\n writeln(\"NO\");\r\n }\r\n}", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n int n = scan!int;\n dchar[][] mat;\n for(int i = 0; i < n; ++i){\n mat ~= scan!(dchar[]);\n }\n\n dchar[][] req;\n for(int i = 0; i < n; ++i){\n req ~= scan!(dchar[]);\n }\n /* show(req); */\n /* if(n == 1){ writeln(\"YES\"); return;} */\n\n int[] s1, d1;\n for(int j = 0; j < n; ++j){\n if(mat[0][j] == req[0][j]){\n s1 ~= j;\n }else{\n d1 ~= j;\n }\n }\n\n for(int i = 1; i < n; ++i){\n int[] di;\n for(int j = 0; j < n; ++j){\n if(mat[i][j] != req[i][j]){\n di ~= j;\n }\n }\n if(di != s1 && di != d1){\n writeln(\"NO\");\n return;\n }\n }\n writeln(\"YES\");\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [], "src_uid": "cc40ec9f5608650dddfe61565e610073"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nstruct SegmentTree(T, T unit, alias binop) {\r\n int n;\r\n T[] dat;\r\n this(int n_) {\r\n n = 1;\r\n while (n < n_) n *= 2;\r\n dat = new T[2*n+2];\r\n dat[] = unit;\r\n }\r\n void update(int k, in T a) {\r\n k += n - 1;\r\n dat[k] = a;\r\n while (k > 0) {\r\n k = (k - 1) / 2;\r\n dat[k] = binop(dat[k * 2 + 1], dat[k * 2 + 2]);\r\n }\r\n }\r\n T query(int a, int b) const {\r\n return query(a, b, 0, 0, n);\r\n }\r\n T query(int a, int b, int k, int l, int r) const {\r\n if (r <= a || b <= l) return unit;\r\n if (a <= l && r <= b) return dat[k];\r\n T vl = query(a, b, k * 2 + 1, l, (l + r) / 2),\r\n vr = query(a, b, k * 2 + 2, (l + r) / 2, r);\r\n return binop(vl, vr);\r\n }\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto S = read!string;\r\n auto L = new int[M];\r\n auto R = new int[M];\r\n foreach (q; 0 .. M) {\r\n readf(\"%d %d\\n\", &L[q], &R[q]);\r\n L[q]--; R[q]--;\r\n }\r\n\r\n auto T = new int[N];\r\n for (int i = 0; i < N; i++) {\r\n T[i] = (S[i] == '+' ? +1 : -1);\r\n }\r\n auto PS = new int[N+1]; {\r\n for (int i = 0; i < N; i++) {\r\n PS[i+1] = PS[i] + T[i];\r\n }\r\n }\r\n const int INF = 1<<30;\r\n auto minT = SegmentTree!(int, INF, (a, b) => min(a, b))(N+1);\r\n auto maxT = SegmentTree!(int, -INF, (a, b) => max(a, b))(N+1);\r\n for (int i = 0; i <= N; i++) {\r\n minT.update(i, PS[i]);\r\n maxT.update(i, PS[i]);\r\n }\r\n foreach (q; 0 .. M) {\r\n int l = L[q], r = R[q];\r\n auto xm = minT.query(0, l+1);\r\n auto xM = maxT.query(0, l+1);\r\n auto ym = minT.query(r+1, N+1);\r\n auto yM = maxT.query(r+1, N+1);\r\n auto p = PS[r+1] - PS[l];\r\n /*\r\n writeln(S);\r\n writeln([l, r]);\r\n writeln([xm, xM, ym, yM, p]);\r\n */\r\n auto ans = max(xM, yM - p) - min(xm, ym - p) + 1;\r\n writeln(ans);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{ \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto v = readln.splitter.map!(to!int).array;\r\n auto n = v[0], m = v[1];\r\n auto arr = readln.chomp.array;\r\n \r\n int[] top, bot, pos;\r\n top ~= 0, bot ~= 0, pos ~= 0;\r\n int cur = 0;\r\n foreach (e; arr) {\r\n if (e == '+') { cur += 1; }\r\n else { cur -= 1; }\r\n \r\n pos ~= cur;\r\n top ~= max(top.back, cur);\r\n bot ~= min(bot.back, cur);\r\n }\r\n \r\n int[] topdst, botdst;\r\n topdst ~= 0;\r\n botdst ~= 0;\r\n cur = 0;\r\n foreach_reverse (i, e; arr) {\r\n int fromtop = topdst.back;\r\n int frombot = botdst.back;\r\n if (e == '+') {\r\n frombot -= 1;\r\n fromtop += 1;\r\n } else { \r\n fromtop -= 1;\r\n frombot += 1;\r\n }\r\n \r\n fromtop = max(fromtop, 0);\r\n frombot = max(frombot, 0);\r\n \r\n topdst ~= fromtop;\r\n botdst ~= frombot;\r\n }\r\n \r\n topdst.reverse();\r\n botdst.reverse();\r\n \r\n debug { writeln(pos, top, bot); }\r\n debug { writeln(topdst, botdst); }\r\n \r\n while (m--) {\r\n v = readln.splitter.map!(to!int).array;\r\n auto x = v[0], y = v[1];\r\n \r\n int topmax = max(top[x-1], pos[x-1] + topdst[y]);\r\n int botmin = min(bot[x-1], pos[x-1] - botdst[y]);\r\n int dist = topmax - botmin + 1;\r\n \r\n dist.writeln;\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, M; get(N, M);\r\n char[] ii; get(ii);\r\n auto ps = new int[](N + 1);\r\n auto max_s = new int[](N + 1);\r\n auto min_s = new int[](N + 1);\r\n int max_p, min_p, p;\r\n foreach (i; 0..N) {\r\n p += (ii[i] == '+' ? 1 : -1);\r\n ps[i+1] = p;\r\n max_p = max(max_p, p);\r\n min_p = min(min_p, p);\r\n max_s[i+1] = max_p;\r\n min_s[i+1] = min_p;\r\n }\r\n auto max_r = new int[](N + 1);\r\n auto min_r = new int[](N + 1);\r\n p = max_p = min_p = 0;\r\n foreach_reverse (i; 0..N) {\r\n p += (ii[i] == '+' ? -1 : 1);\r\n max_p = max(max_p, p);\r\n min_p = min(min_p, p);\r\n max_r[i+1] = max_p - p;\r\n min_r[i+1] = min_p - p;\r\n }\r\n \r\n while (M--) {\r\n int l, r; get(l, r);\r\n p = ps[l-1];\r\n max_p = max_s[l-1];\r\n min_p = min_s[l-1];\r\n if (r != N) {\r\n max_p = max(max_p, max_r[r+1] + p);\r\n min_p = min(min_p, min_r[r+1] + p);\r\n }\r\n writeln(max_p - min_p + 1);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nalias State = Tuple !(int, q{lo}, int, q{hi}, int, q{cur});\r\n\r\nauto fun (S) (S s)\r\n{\r\n\tState [] res;\r\n\tauto v = State (0, 0, 0);\r\n\tres ~= v;\r\n\tforeach (ref c; s)\r\n\t{\r\n\t\tv.cur += (c == '+') ? +1 : -1;\r\n\t\tv.lo = min (v.lo, v.cur);\r\n\t\tv.hi = max (v.hi, v.cur);\r\n\t\tres ~= v;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto c = readln.strip;\r\n\t\tauto pref = fun (c);\r\n\t\tauto suff = fun (c.retro);\r\n\t\treverse (suff);\r\n\t\tforeach (q; 0..m)\r\n\t\t{\r\n\t\t\tint l, r;\r\n\t\t\treadf !(\" %s %s\") (l, r);\r\n\t\t\tl -= 1;\r\n\t\t\tauto v = pref[l];\r\n\t\t\tauto w = suff[r];\r\n\t\t\tv.lo = min (v.lo, v.cur - (w.hi - w.cur));\r\n\t\t\tv.hi = max (v.hi, v.cur - (w.lo - w.cur));\r\n\t\t\twriteln (v.hi - v.lo + 1);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "85769fb020b0d7f8e447a84a09cdddda"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint [2] total;\n\t\tint prev = 0;\n\t\tint moves = 0;\n\t\twhile (!a.empty)\n\t\t{\n\t\t\tmoves += 1;\n\t\t\tint cur = 0;\n\t\t\twhile (!a.empty && cur <= prev)\n\t\t\t{\n\t\t\t\tcur += a[0];\n\t\t\t\ta = a[1..$];\n\t\t\t}\n\t\t\ttotal[moves % 2] += cur;\n\t\t\tprev = cur;\n\t\t\treverse (a);\n\t\t}\n\t\twriteln (moves, \" \", total[1], \" \", total[0]);\n\t}\n}", "positive_code": [{"source_code": "void main() {\n\tauto t = ri;\n\tforeach(T; 0..t) {\n\t\tauto n = ri;\n\t\tauto a = readAs!(int[]);\n\t\tint last;\n\t\tbool[] visited = new bool[](n);\n\t\tlong alice, bob;\n\t\tlong lalice, lbob;\n\t\tuint pa, pb = n - 1;\n\t\tulong move;\n\t\tulong k;\n\t\tloop: foreach(i; 0..10000) {\n\t\t\tbool flag = false;\n\t\t\tdebug visited.map!(v => v+0).writeln;\n\t\t\tdebug writefln(\"%d %d\", pa, pb);\n\t\t\tif(i % 2 == 0) {\n\t\t\t\tlalice = 0;\n\t\t\t\twhile(lalice <= lbob) {\n\t\t\t\t\tif(pa < n && !visited[pa]) {\n\t\t\t\t\t\tif(!flag) { flag = true; k++; }\n\t\t\t\t\t\tvisited[pa] = true;\n\t\t\t\t\t\talice += a[pa];\n\t\t\t\t\t\tlalice += a[pa];\n\t\t\t\t\t\tpa++;\n\t\t\t\t\t} else break loop;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlbob = 0;\n\t\t\t\twhile(lbob <= lalice) {\n\t\t\t\t\tif(pb > 0 && !visited[pb]) {\n\t\t\t\t\t\tif(!flag) { flag = true; k++; }\n\t\t\t\t\t\tvisited[pb] = true;\n\t\t\t\t\t\tbob += a[pb];\n\t\t\t\t\t\tlbob += a[pb];\n\t\t\t\t\t\tpb--;\n\t\t\t\t\t} else break loop;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twritefln(\"%d %d %d\", k, alice, bob);\n\t}\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\nlong rl() {\n\treturn readAs!long;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(long[]);\n long a, sa, b, sb;\n int c;\n while (!as.empty) {\n ++c;\n long d;\n if (c%2 == 1) {\n do {\n d += as[0];\n as = as[1..$];\n } while (!as.empty && d <= b);\n a = d;\n sa += d;\n } else {\n do {\n d += as[$-1];\n as = as[0..$-1];\n } while (!as.empty && d <= a);\n b = d;\n sb += d;\n }\n }\n writeln(c, \" \", sa, \" \", sb);\n }\n}"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\n// excessive array copying on each step, should exceed ML or TL\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint moves = 0;\n\t\tint prev = 0;\n\t\tint totalA = 0;\n\t\tint totalB = 0;\n\t\twhile (!a.empty)\n\t\t{\n\t\t\tmoves += 1;\n\t\t\tint curA = 0;\n\t\t\twhile (!a.empty && curA <= prev)\n\t\t\t{\n\t\t\t\tcurA += a[0];\n\t\t\t\ta = a[1..$].dup;\n\t\t\t}\n\t\t\ttotalA += curA;\n\t\t\tprev = curA;\n\n\t\t\tif (a.empty)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tmoves += 1;\n\t\t\tint curB = 0;\n\t\t\twhile (!a.empty && curB <= prev)\n\t\t\t{\n\t\t\t\tcurB += a[$ - 1];\n\t\t\t\ta = a[0..$ - 1].dup;\n\t\t\t}\n\t\t\ttotalB += curB;\n\t\t\tprev = curB;\n\t\t}\n\t\twriteln (moves, \" \", totalA, \" \", totalB);\n\t}\n}\n"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint moves = 0;\n\t\tint prev = 0;\n\t\tint totalA = 0;\n\t\tint totalB = 0;\n\t\twhile (!a.empty)\n\t\t{\n\t\t\tmoves += 1;\n\t\t\tint curA = 0;\n\t\t\twhile (!a.empty && curA <= prev)\n\t\t\t{\n\t\t\t\tcurA += a.front;\n\t\t\t\ta.popFront ();\n\t\t\t}\n\t\t\ttotalA += curA;\n\t\t\tprev = curA;\n\n\t\t\tif (a.empty)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tmoves += 1;\n\t\t\tint curB = 0;\n\t\t\twhile (!a.empty && curB <= prev)\n\t\t\t{\n\t\t\t\tcurB += a.back;\n\t\t\t\ta.popBack ();\n\t\t\t}\n\t\t\ttotalB += curB;\n\t\t\tprev = curB;\n\t\t}\n\t\twriteln (moves, \" \", totalA, \" \", totalB);\n\t}\n}\n"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint [2] total;\n\t\tint prev = 0;\n\t\tint moves = 0;\n\t\twhile (!a.empty)\n\t\t{\n\t\t\tmoves += 1;\n\t\t\tint cur = 0;\n\t\t\twhile (!a.empty && cur <= prev)\n\t\t\t{\n\t\t\t\tcur += a[0];\n\t\t\t\ta = a[1..$];\n\t\t\t}\n\t\t\ttotal[moves % 2] += cur;\n\t\t\tprev = cur;\n\t\t\treverse (a);\n\t\t}\n\t\twriteln (moves, \" \", total[1], \" \", total[0]);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.conv;\nimport std.string;\n\nT readNum(T)(){\n return readStr.to!T;\n}\n\nT[] readNums(T)(){\n return readStr.split.to!(T[]);\n}\n\nstring readStr(){\n return readln.chomp;\n}\n\nvoid main(){\n auto t = readNum!int;\n\n foreach(i; 0 .. t){\n auto n = readNum!int;\n auto a = readNums!int;\n\n int apos = 0, bpos = n-1;\n int asum, bsum;\n int move, eaten, requirement = a[0];\n\n mainloop: while(true){\n move++;\n\n while(eaten < requirement){\n eaten += a[apos];\n asum += a[apos];\n apos++;\n\n if(bpos < apos) break mainloop;\n }\n\n requirement = eaten+1;\n eaten = 0;\n\n move++;\n\n while(eaten < requirement){\n eaten += a[bpos];\n bsum += a[bpos];\n bpos--;\n\n if(bpos < apos) break mainloop;\n }\n\n requirement = eaten+1;\n eaten = 0;\n }\n\n writeln(move, \" \", asum, \" \", bsum);\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t, 3);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto a = RDA;\n\t\t\n\t\tlong last;\n\t\twhile (true)\n\t\t{\n\t\t\tif (a.empty) break;\n\t\t\tlong x;\n\t\t\twhile (!a.empty)\n\t\t\t{\n\t\t\t\tx += a.front; a.popFront;\n\t\t\t\tif (x > last) break;\n\t\t\t}\n\t\t\t++ans[ti][0];\n\t\t\tans[ti][1] += x;\n\t\t\tlast = x;\n\n\t\t\tif (a.empty) break;\n\t\t\tlong y;\n\t\t\twhile (!a.empty)\n\t\t\t{\n\t\t\t\ty += a.back; a.popBack;\n\t\t\t\tif (y > last) break;\n\t\t\t}\n\t\t\t++ans[ti][0];\n\t\t\tans[ti][2] += y;\n\t\t\tlast = y;\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\te.map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "d70ee6d3574e0f2cac3c683729e2979d"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto s = RD!string;\n\tauto cnt = new int[][](s.length+1);\n\tcnt[0] = new int[](26);\n\tforeach (i; 0..s.length)\n\t{\n\t\tcnt[i+1] = cnt[i].dup;\n\t\tauto num = s[i]-'a';\n\t\tcnt[i+1][num] += 1;\n\t}\n\tauto q = RD!int;\n\tauto ans = new bool[](q);\n\tforeach (qi; 0..q)\n\t{\n\t\tauto l = RD!int-1;\n\t\tauto r = RD!int-1;\n\t\tif (l == r || s[l] != s[r])\n\t\t{\n\t\t\tans[qi] = true;\n\t\t\tcontinue;\n\t\t}\n\t\tlong c;\n\t\tauto tmp = cnt[r+1].dup;\n\t\ttmp[] -= cnt[l][];\n\t\tforeach (i; 0..26)\n\t\t{\n\t\t\tif (i == s[l]-'a') continue;\n\t\t\tif (tmp[i] > 0)\n\t\t\t\t++c;\n\t\t}\n\t\tans[qi] = c >= 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"Yes\" : \"No\");\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int letters = 26;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto n = s.length.to !(int);\n\t\tauto f = new int [letters] [n + 1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tf[i + 1][] = f[i][];\n\t\t\tf[i + 1][s[i] - 'a'] += 1;\n\t\t}\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tint [letters] cur;\n\t\t\tcur[] = f[v][] - f[u][];\n\t\t\tauto diff = cur[].count !(x => x != 0);\n\t\t\tbool ok = (v - u == 1) || (diff > 2) ||\n\t\t\t ((diff == 2) && (s[u] != s[v - 1]));\n\t\t\twriteln (ok ? \"Yes\" : \"No\");\n\t\t}\n\t\treadln;\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n debug {\n bool check(int[] as) {\n if (as.length == 1) {\n return true;\n }\n if (as[0] != as[$ - 1]) {\n return true;\n }\n if (as.dup.sort.group.array.length >= 3) {\n return true;\n }\n return false;\n }\n \n enum lim = 5;\n foreach (n; 1 .. lim + 1) {\n foreach (p; 0 .. lim^^n) {\n auto as = new int[n];\n foreach (i; 0 .. n) {\n as[i] = p / lim^^i % lim;\n }\n auto bs = as.dup;\n bs.sort;\n bool hasIrred;\n do {\n bool irred = true;\n foreach (i; 1 .. n) {\n irred = irred && (as[0 .. i].dup.sort != bs[0 .. i].dup.sort);\n }\n hasIrred = hasIrred || irred;\n } while (bs.nextPermutation);\n if (!hasIrred) {\n writeln(as);\n }\n assert(hasIrred == check(as));\n }\n }\n }\n \n try {\n for (; ; ) {\n const S = readToken();\n const Q = readInt();\n auto L = new int[Q];\n auto R = new int[Q];\n foreach (q; 0 .. Q) {\n L[q] = readInt() - 1;\n R[q] = readInt();\n }\n \n const N = cast(int)(S.length);\n auto cnt = new int[][](26, N + 1);\n foreach (a; 0 .. 26) {\n foreach (i; 0 .. N) {\n cnt[a][i + 1] = cnt[a][i] + ((S[i] - 'a' == a) ? 1 : 0);\n }\n }\n \n foreach (q; 0 .. Q) {\n bool ans;\n if (R[q] - L[q] == 1) {\n ans = true;\n }\n if (S[L[q]] != S[R[q] - 1]) {\n ans = true;\n }\n int num;\n foreach (a; 0 .. 26) {\n if (cnt[a][R[q]] - cnt[a][L[q]] > 0) {\n ++num;\n }\n }\n if (num >= 3) {\n ans = true;\n }\n writeln(ans ? \"Yes\" : \"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto s = RD!string;\n\tauto cnt = new int[][](s.length+1);\n\tcnt[0] = new int[](26);\n\tforeach (i; 0..s.length)\n\t{\n\t\tcnt[i+1] = cnt[i].dup;\n\t\tauto num = s[i]-'a';\n\t\tcnt[i+1][num] += 1;\n\t}\n\tauto q = RD!int;\n\tauto ans = new bool[](q);\n\tforeach (qi; 0..q)\n\t{\n\t\tauto l = RD!int;\n\t\tauto r = RD!int;\n\t\tif (l == r)\n\t\t{\n\t\t\tans[qi] = true;\n\t\t\tcontinue;\n\t\t}\n\t\tlong c;\n\t\tauto tmp = cnt[r].dup;\n\t\ttmp[] -= cnt[l-1][];\n\t\tforeach (i; 0..26)\n\t\t{\n\t\t\tif (tmp[i] > 0)\n\t\t\t\t++c;\n\t\t}\n\t\tans[qi] = c >= 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"Yes\" : \"No\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "eb5c93620709436493b2e560a63dbb02"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint k, n;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tint [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tubyte [4] v;\n\t\t\treadf (\" %d.%d.%d.%d\", &v[0], &v[1], &v[2], &v[3]);\n\t\t\tuint s = 0;\n\t\t\tforeach (j; 0..4)\n\t\t\t{\n\t\t\t\ts = (s << 8) | v[j];\n\t\t\t}\n\t\t\tdebug {writefln (\"%08X\", s);}\n\t\t\ta ~= s;\n\t\t}\n\n\t\tuint m = 0;\n\t\tlong res = -1;\n\t\tforeach (i; 1..32)\n\t\t{\n\t\t\tm |= 1u << (32 - i);\n\t\t\tdebug {writefln (\"%08X\", m);}\n\t\t\tauto b = redBlackTree !(int);\n\t\t\tforeach (c; a)\n\t\t\t{\n\t\t\t\tb.insert (c & m);\n\t\t\t}\n\t\t\tif (b.length == k)\n\t\t\t{\n\t\t\t\tres = m;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (res == -1)\n\t\t{\n\t\t\twriteln (res);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tubyte [4] v;\n\t\t\tforeach (j; 0..4)\n\t\t\t{\n\t\t\t\tv[j] = res & 0xFF;\n\t\t\t\tres >>= 8;\n\t\t\t}\n\t\t\treverse (v[]);\n\t\t\twritefln (\"%(%s.%)\", v);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nint rev(int x) {\n int res = 0;\n for (int i = 0; i < 8; i++) {\n if (x & (1 << (7 - i)))\n res |= (1 << i);\n }\n return res;\n}\n\nvoid main() {\n int n, K;\n readf(\"%d %d\\n\", &n, &K);\n\n int[][] masks;\n masks.length = n;\n\n for (int i = 0; i < n; i++) {\n masks[i].length = 4;\n readf(\"%d.%d.%d.%d\\n\", &masks[i][0], &masks[i][1], &masks[i][2], &masks[i][3]);\n }\n\n for (int i = 0; i < 4; i++) {\n for (int jj = 1; jj < 256; jj = (jj << 1) | 1) {\n int j = rev(jj);\n int[] nets;\n nets.length = n;\n\n for (int k = 0; k < n; k++) {\n for (int l = 0; l < i; l++) {\n nets[k] <<= 8;\n nets[k] |= masks[k][l];\n }\n nets[k] <<= 8;\n nets[k] |= (j & masks[k][i]);\n }\n\n sort(nets);\n\n int cnt = 1;\n for (int k = 1; k < n; k++) {\n if (nets[k] != nets[k - 1])\n ++cnt;\n }\n\n if (cnt == K) {\n for (int k = 0; k < i; k++) {\n write(\"255.\");\n }\n write(j);\n for (int k = 0; k < (4 - i - 1); k++) {\n write(\".0\");\n }\n writeln();\n return;\n }\n }\n }\n\n writeln(-1);\n}"}, {"source_code": "module sigod.codeforces.p291C;\n\nimport std.stdio;\n\nprivate\nenum MASK_INCREMENT = 0x80000000;\n\nvoid main()\n{\n\tint n, k;\n\tstdin.readf(\" %s %s\", &n, &k);\n\n\tuint[] ips = new uint[n];\n\n\tforeach (ref ip; ips) {\n\t\tubyte b1, b2, b3, b4;\n\t\tstdin.readf(\" %s.%s.%s.%s\", &b1, &b2, &b3, &b4);\n\n\t\tip = (((((b1 << 8) | b2) << 8) | b3) << 8) | b4;\n\t}\n\n\tuint mask = 0;\n\n\tforeach (x; 0 .. 32) {\n\t\tmask = (mask >> 1) | MASK_INCREMENT;\n\n\t\tbool[uint] webs;\n\n\t\tforeach (ip; ips) {\n\t\t\twebs[ip & mask] = true;\n\t\t}\n\n\t\tif (webs.length == k) {\n\t\t\tstdout.writeln(toIP(mask));\n\t\t\treturn;\n\t\t}\n\t}\n\n\tstdout.writeln(\"-1\");\n}\n\nprivate\nstring toIP(uint mask)\n{\n\tubyte b1, b2, b3, b4;\n\n\tb4 = mask & 0xFF;\n\tmask >>= 8;\n\n\tb3 = mask & 0xFF;\n\tmask >>= 8;\n\n\tb2 = mask & 0xFF;\n\tmask >>= 8;\n\n\tb1 = mask & 0xFF;\n\n\treturn std.string.format(\"%s.%s.%s.%s\", b1, b2, b3, b4);\n}"}], "negative_code": [], "src_uid": "4da4410d3b75ee87a4dfa33b437b9cfa"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() { while (solve()) {} }\n\nauto getZ(int[] s) {\n\tint n = cast(int)s.length;\n\tint lf = -1, rg = -1;\n\tauto z = new int[n];\n\tz[0] = 0;\n\tforeach (i; 1..n) {\n\t\tz[i] = 0;\n\t\tif (i < rg) z[i] = min(z[i - lf], rg - i);\n\t\twhile (i + z[i] < n && s[i + z[i]] == s[z[i]])\n\t\t\tz[i]++;\n\t\tif (i + z[i] > rg) {\n\t\t\tlf = i;\n\t\t\trg = i + z[i];\n\t\t}\n\t}\n\treturn z;\n}\n\nbool solve() {\n\tint n, w;\n\tif (!readf(\" %s %s\", &n, &w)) return false;\n\tauto a = new int[n], b = new int[w];\n\tforeach (ref x; a) readf(\" %s\", &x);\n\tforeach (ref x; b) readf(\" %s\", &x);\n\tif (w == 1) {\n\t\twriteln(n);\n\t\treturn true;\n\t}\n\tauto da = new int[n - 1];\n\tforeach (i, ref dx; da)\n\t\tdx = a[i + 1] - a[i];\n\tauto db = new int[w - 1];\n\tforeach (i, ref dx; db)\n\t\tdx = b[i + 1] - b[i];\n\tauto s = db ~ da;\n\tauto z = getZ(s);\n\tint ans = 0;\n\tforeach (val; z[db.length..$])\n\t\tif (val >= db.length) ans++;\n\twriteln(ans);\n\treturn true;\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\n\nimmutable int p = 13957;\n\nimmutable int MOD = 1000000007;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p % MOD;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p % MOD + b[i];\n h %= MOD;\n if (h < 0) {\n h += MOD;\n }\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p % MOD + a[i];\n cur %= MOD;\n if (cur < 0) {\n cur += MOD;\n }\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1] % MOD;\n if (cur < 0) {\n cur += MOD;\n }\n }\n if (i >= w - 1) {\n cur %= MOD;\n if (cur < 0) {\n cur += MOD;\n }\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint M, N;\nint[] A, B;\nint[] P, Q;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tA = new int[M];\n\t\tforeach (i; 0 .. M) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\tB = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tB[i] = readInt;\n\t\t}\n\t\t\n\t\tif (N == 1) {\n\t\t\twriteln(M);\n\t\t} else {\n\t\t\tP = new int[M - 1];\n\t\t\tforeach (i; 0 .. M - 1) {\n\t\t\t\tP[i] = A[i + 1] - A[i];\n\t\t\t}\n\t\t\tQ = new int[N - 1];\n\t\t\tforeach (i; 0 .. N - 1) {\n\t\t\t\tQ[i] = B[i + 1] - B[i];\n\t\t\t}\ndebug{\nwriteln(\"P = \",P);\nwriteln(\"Q = \",Q);\n}\n\t\t\tint[] fail = new int[Q.length + 1];\n\t\t\tint j = fail[0] = -1;\n\t\t\tforeach (i; 0 .. Q.length) {\n\t\t\t\tfor (; j >= 0 && Q[j] != Q[i]; j = fail[j]) {}\n\t\t\t\tfail[i + 1] = ++j;\n\t\t\t}\ndebug{\nwriteln(\"fail = \",fail);\n}\n\t\t\tint ans;\n\t\t\tj = 0;\n\t\t\tforeach (i; 0 .. P.length) {\n\t\t\t\tfor (; j >= 0 && Q[j] != P[i]; j = fail[j]) {}\n\t\t\t\tif (++j == Q.length) {\n\t\t\t\t\t++ans;\n\t\t\t\t\tj = fail[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteln(ans);\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() { while (solve()) {} }\n\nauto getZ(int[] s) {\n\tint n = cast(int)s.length;\n\tint lf = -1, rg = -1;\n\tauto z = new int[n];\n\tz[0] = 0;\n\tforeach (i; 1..n) {\n\t\tz[i] = 0;\n\t\tif (i < rg) z[i] = min(z[i - lf], rg - i);\n\t\twhile (i + z[i] < n && s[i + z[i]] == s[z[i]])\n\t\t\tz[i]++;\n\t\tif (i + z[i] > rg) {\n\t\t\tlf = i;\n\t\t\trg = i + z[i];\n\t\t}\n\t}\n\treturn z;\n}\n\nbool solve() {\n\tint n, w;\n\tif (!readf(\" %s %s\", &n, &w)) return false;\n\tauto a = new int[n], b = new int[w];\n\tforeach (ref x; a) readf(\" %s\", &x);\n\tforeach (ref x; b) readf(\" %s\", &x);\n\tif (w == 1) {\n\t\twriteln(n);\n\t\treturn true;\n\t}\n\tauto da = new int[n - 1];\n\tforeach (i, ref dx; da)\n\t\tdx = a[i + 1] - a[i];\n\tauto db = new int[w - 1];\n\tforeach (i, ref dx; db)\n\t\tdx = b[i + 1] - b[i];\n\tauto s = db ~ da;\n\tauto z = getZ(s);\n\tint ans = 0;\n\tforeach (val; z[db.length..$])\n\t\tif (val >= db.length) ans++;\n\twriteln(ans);\n\treturn true;\n\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nimmutable int p = 37;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n for (int i = 1; i < w; i++) {\n h = h * p + b[i];\n }\n long cur = 0;\n int ans = 0;\n a[0] = 0;\n for (int i = 1; i < n; i++) {\n cur = cur * p + a[i];\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1];\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 13957;\n\nimmutable int MOD = 1000000009;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p % MOD;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p % MOD + b[i];\n h %= MOD;\n if (h < 0) {\n h += MOD;\n }\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p % MOD + a[i];\n cur %= MOD;\n if (cur < 0) {\n cur += MOD;\n }\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1] % MOD;\n if (cur < 0) {\n cur += MOD;\n }\n }\n if (i >= w - 1) {\n cur %= MOD;\n if (cur < 0) {\n cur += MOD;\n }\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 37;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p + b[i];\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p + a[i];\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1];\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 37;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n for (int i = 1; i < w; i++) {\n h = h * p + b[i];\n }\n long cur = 0;\n int ans = 0;\n a[0] = 0;\n for (int i = 1; i <= n; i++) {\n if (i < n) { \n cur = cur * p + a[i];\n }\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1];\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 11;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p + b[i];\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p + a[i];\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1];\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 1000000007;\n\nimmutable int MOD = 1000000009;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p % MOD;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p % MOD + b[i];\n h %= MOD;\n if (h < 0) {\n h += MOD;\n }\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p % MOD + a[i];\n if (cur < 0) {\n cur += MOD;\n }\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1] % MOD;\n if (cur < 0) {\n cur += MOD;\n }\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 13579;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p + b[i];\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p + a[i];\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1];\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 1000000007;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p + b[i];\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p + a[i];\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1];\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 23719;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p + b[i];\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p + a[i];\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1];\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 1000000007;\n\nimmutable int MOD = 1000000009;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p % MOD;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p % MOD + b[i];\n h %= MOD;\n if (h < 0) {\n h += MOD;\n }\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p % MOD + a[i];\n cur %= MOD;\n if (cur < 0) {\n cur += MOD;\n }\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1] % MOD;\n if (cur < 0) {\n cur += MOD;\n }\n }\n if (i >= w - 1) {\n cur %= MOD;\n if (cur < 0) {\n cur += MOD;\n }\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 13957;\n\nimmutable int MOD = 1000000007;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p % MOD;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p % MOD + b[i];\n h %= MOD;\n if (h < 0) {\n h += MOD;\n }\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p % MOD + a[i];\n cur %= MOD;\n if (cur < 0) {\n cur += MOD;\n }\n writeln(i, ' ', cur, ' ', h);\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1] % MOD;\n if (cur < 0) {\n cur += MOD;\n }\n }\n if (i >= w - 1) {\n cur %= MOD;\n if (cur < 0) {\n cur += MOD;\n }\n ans += cur == h;\n }\n writeln(i, ' ', cur, ' ', h);\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int p = 23719;\n\nvoid main() {\n int n, w; readf(\" %s %s\", &n, &w);\n auto pw = new long[n + 10];\n pw[0] = 1;\n for (int i = 1; i < pw.length; i++) {\n pw[i] = pw[i - 1] * p;\n }\n auto a = new int[n];\n auto b = new int[w];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n }\n for (int i = n - 1; i > 0; i--) {\n a[i] -= a[i - 1];\n }\n a[0] = 0;\n long h = 0;\n long mult = 1;\n for (int i = 0; i < w; i++) {\n readf(\" %s\", &b[i]);\n }\n for (int i = w - 1; i > 0; i--) {\n b[i] -= b[i - 1];\n }\n b[0] = 0;\n for (int i = 1; i < w; i++) {\n h = h * p + b[i];\n }\n long cur = 0;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n cur = cur * p + a[i];\n if (i >= w) {\n cur -= pw[w - 1] * a[i - w + 1];\n }\n if (i >= w - 1) {\n ans += cur == h;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() { while (solve()) {} }\n\nauto getZ(int[] s) {\n\tint n = cast(int)s.length;\n\tint lf = -1, rg = -1;\n\tauto z = new int[n];\n\tz[0] = 0;\n\tforeach (i; 1..n) {\n\t\tz[i] = 0;\n\t\tif (i < rg) z[i] = min(z[i - lf], rg - i);\n\t\twhile (i + z[i] < n && s[i + z[i]] == s[z[i]])\n\t\t\tz[i]++;\n\t\tif (i + z[i] > rg) {\n\t\t\tlf = i;\n\t\t\trg = i + z[i];\n\t\t}\n\t}\n\treturn z;\n}\n\nbool solve() {\n\tint n, w;\n\tif (!readf(\" %s %s\", &n, &w)) return false;\n\tauto a = new int[n], b = new int[w];\n\tforeach (ref x; a) readf(\" %s\", &x);\n\tforeach (ref x; b) readf(\" %s\", &x);\n\tif (w == 1) {\n\t\twriteln(n);\n\t\treturn true;\n\t}\n\tauto da = new int[n - 1];\n\tforeach (i, ref dx; da)\n\t\tdx = a[i + 1] - a[i];\n\tauto db = new int[w - 1];\n\tforeach (i, ref dx; db)\n\t\tdx = b[i + 1] - b[i];\n\tauto s = db ~ da;\n\tauto z = getZ(s);\n\tint ans = 0;\n\tforeach (val; z[db.length..$])\n\t\tif (val == db.length) ans++;\n\twriteln(ans);\n\treturn true;\n}\n"}], "src_uid": "37447ade3cad88e06c1f407576e4a041"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD;\n\t\tauto a = RDA!int;\n\n\t\t{\n\t\t\tint x = int.min;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tx.chmax(a[i]);\n\t\t\t}\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\ta[i] = x - a[i];\n\t\t\t}\n\t\t}\n\t\tif (k % 2 == 0)\n\t\t{\n\t\t\tint x = int.min;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tx.chmax(a[i]);\n\t\t\t}\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\ta[i] = x - a[i];\n\t\t\t}\n\t\t}\n\t\tans[ti] = a;\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\tlong k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tk -= 1;\n\t\tauto d = a.maxElement;\n\t\ta[] = d - a[];\n\t\tk &= 1;\n\t\twhile (k > 0)\n\t\t{\n\t\t\td = a.maxElement;\n\t\t\ta[] = d - a[];\n\t\t\tk -= 1;\n\t\t}\n\t\twritefln !(\"%(%s %)\") (a);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const K = readLong();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto ans = new long[N];\n if (K % 2 == 0) {\n const AMin = A.minElement;\n foreach (i; 0 .. N) {\n ans[i] = A[i] - AMin;\n }\n } else {\n const AMax = A.maxElement;\n foreach (i; 0 .. N) {\n ans[i] = AMax - A[i];\n }\n }\n \n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, k;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n if (k % 2 == 1)\n {\n auto m = a.fold!max;\n foreach(ai; a)\n {\n write(m - ai, \" \");\n }\n writeln;\n }\n else\n {\n auto m = a.fold!min;\n foreach(ai; a)\n {\n write(ai - m, \" \");\n }\n writeln;\n }\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [], "src_uid": "f18a5fa0b2e7e96cb5994b7b2dbe0189"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n int s = a + b;\n int k = 0;\n while (((k+1).to!long * (k+2)) / 2 <= s) ++k;\n \n int[][2] nrs;\n int cur = k;\n while (cur > 0) {\n if (cur <= a) {\n nrs[0] ~= cur;\n a -= cur;\n } else {\n nrs[1] ~= cur;\n b -= cur;\n }\n --cur;\n }\n \n foreach (arr; nrs) {\n arr.length.writeln;\n arr.writefln!(\"%(%s %)\");\n }\n}", "positive_code": [{"source_code": "void main() {\n import std.range : dropExactly, retro, sequence, take;\n import std.stdio : readf, writefln;\n\n int a, b;\n readf!\" %d %d\"(a, b);\n\n int nn;\n int ns;\n foreach (n; sequence!\"n\".dropExactly(1)) {\n ns += n;\n if (ns > a + b)\n break;\n nn++;\n }\n\n int[] d1;\n d1.reserve(nn);\n int[] d2;\n d2.reserve(nn);\n\n foreach (n; sequence!\"n\".dropExactly(1).take(nn).retro) {\n if (n <= a) {\n a -= n;\n d1 ~= n;\n }\n else {\n d2 ~= n;\n }\n }\n writefln(\"%s\\n%(%s %)\\n%s\\n%(%s %)\", d1.length, d1, d2.length, d2);\n}\n"}], "negative_code": [], "src_uid": "fab438cef9eb5e9e4a4a2e3f9e4f9cec"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nconst long MOD = 1_000_000_007;\n\n// Modexp\nll modexp(ll base, ll exp){\n ll x = base % MOD;\n ll y = exp;\n ll res = 1;\n while(y > 0){\n if(y & 1){\n res *= x; res %= MOD;\n }\n x *= x; x %= MOD;\n y >>= 1;\n }\n return res;\n}\n\nvoid solve(){\n long n = scan;\n long m = scan;\n long res = 0;\n for(int i = 0; i < m; ++i){\n long l = scan;\n long r = scan;\n long x = scan;\n res |= x;\n }\n res *= modexp(2, n-1);\n res %= MOD;\n writeln(res);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "immutable multi = true;\n\nimmutable long p = 1_000_000_000L + 7;\nalias Zp = Z!p;\nlong[] p2;\n\nstatic this()\n{\n\tp2 = new long[](2_000_00 + 1);\n\tp2[0] = 1;\n\tforeach(i; 1 .. p2.length)\n\t\tp2[i] = (p2[i-1] * 2)%p;\n}\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tstruct Rel\n\t{\n\t\tint i, acc;\n\t}\n\tauto rel = new Rel[][](n + 1);\n\tauto cum = new int[](n + 1);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto l = readInt!int - 1;\n\t\tauto r = readInt!int;\n\t\tauto x = readInt!int;\n\t\trel[r] ~= Rel(l, x);\n\t\trel[l] ~= Rel(r, x);\n\t}\n\tauto filled = new bool[](n + 1);\n\tvoid dfs(int v, int fill)\n\t{\n\t\tif (filled[v])\n\t\t{\n\t\t\tassert(fill == cum[v]);\n\t\t\treturn;\n\t\t}\n\t\tcum[v] = fill;\n\t\tfilled[v] = true;\n\t\tforeach(r; rel[v])\n\t\t{\n\t\t\tauto w = r.i;\n\t\t\tauto x = r.acc;\n\t\t\tdfs(w, x ^ fill);\n\t\t}\n\t}\n\tforeach(i; 0 .. n + 1)\n\t{\n\t\tif (!filled[i])\n\t\t\tdfs(i, 0);\n\t}\n\tauto orig = new int[](n);\n\tint[30] cnt;\n\tforeach(i, ref oi; orig)\n\t{\n\t\toi = cum[i+1] ^ cum[i];\n\t\tint b = 0;\n\t\twhile (oi)\n\t\t{\n\t\t\tcnt[b] += int((oi & 1) != 0);\n\t\t\tb++;\n\t\t\toi >>= 1;\n\t\t}\n\t}\n\tlong ans = 0;\n\tforeach(i; 0 .. 30)\n\t{\n\t\tif (cnt[i] == 0) continue;\n\t\tlong term = 1;\n\t\tterm *= p2[i];\n\t\tterm *= p2[n - 1];\n\t\tterm %= p;\n\t\tans += term;\n\t\tans %= p;\n\t}\n\tans.writeln;\n}\n\n// modular {{{\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tstatic immutable bool primeModulus = isPrime(m);\n\tstatic Z!m[] fact;\n\tstatic if (primeModulus) { static Z!m[] invFact; }\n\tstatic makeFactorials(int n)\n\t{\n\t\tfact = new Z!m[](n + 1);\n\t\tfact[0] = Z!m(1);\n\t\tforeach(i; 1 .. n + 1) fact[i] = Z!m(i) * fact[i - 1];\n\t\tstatic if (primeModulus)\n\t\t{\n\t\t\tinvFact = new Z!m[](n + 1);\n\t\t\tinvFact[n] = fact[n].inv;\n\t\t\tforeach_reverse(i; 0 .. n) invFact[i] = Z!m(i + 1) * invFact[i + 1];\n\t\t}\n\t}\n\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"/\" && primeModulus)\n\t\t{\n\t\t\tassert(rhs != Z!m(0));\n\t\t\treturn this * rhs.inv;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t\t}\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic if (primeModulus)\n\t{\n\t\tZ!m inv()\n\t\t{\n\t\t\treturn this^^(m - 2);\n\t\t}\n\t\tstatic Z!m C(int n, int k)\n\t\t{\n\t\t\tif (k < 0 || k > n) return Z!m(0);\n\t\t\treturn fact[n] * invFact[k] * invFact[n - k];\n\t\t}\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\nbool isPrime(long n)\n{\n\tfor(long d = 2; d * d <= n; d++)\n\t\tif (n % d == 0) return false;\n\treturn true; \n}\nunittest\n{\n\talias Zp = Z!23;\n\tstatic assert(Zp.primeModulus);\n\tforeach(i; 1 .. 23) assert(Zp(i) * Zp(i).inv == Zp(1));\n\tZp.makeFactorials(22);\n\tforeach(i; 0 .. 23) assert(Zp.fact[i] * Zp.invFact[i] == Zp(1));\n\tassert(Zp.C(3, 2) == Zp(3));\n\tassert(Zp.C(4, 2) == Zp(6));\n}\n// }}}\n\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "c4ba92632e10b1710686930f0c4536fa"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nconst int sz = 100005;\nbool[] isPrime;\nll[] primes;\nvoid prime_sieve(){\n isPrime = new bool[](sz + 5);\n isPrime[] = 1;\n foreach(p; 2..10000){\n if(isPrime[p]){\n for(ll divi = p*p; divi <= sz; divi += p){\n isPrime[divi.to!int] = 0;\n }\n }\n }\n for(int i = 2; i <= sz; ++i){\n if(isPrime[i]) primes ~= i;\n }\n}\n\n\nvoid theCode(){\n ll d;\n d = scan;\n int lo = -1, hi = primes.length.to!int-1;\n while(hi - lo > 1){\n int mid = (hi + lo )>> 1;\n ((primes[mid] < d+1) ? lo : hi) = mid;\n }\n long p0 = primes[hi];\n lo = -1, hi = primes.length.to!int-1;\n while(hi - lo > 1){\n int mid = (hi + lo )>> 1;\n ((primes[mid] < d + p0) ? lo : hi) = mid;\n }\n long p1 = primes[hi];\n writeln(p0*p1);\n}\n\nvoid main(){\n long tests = 1;\n prime_sieve();\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nauto sieve (int limit)\r\n{\r\n\tauto res = new bool [limit];\r\n\tres[2..$] = true;\r\n\tfor (int d = 2; d * d < limit; d++)\r\n\t{\r\n\t\tif (res[d])\r\n\t\t{\r\n\t\t\tfor (int e = d; e * d < limit; e++)\r\n\t\t\t{\r\n\t\t\t\tres[e * d] = false;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nimmutable int limit = 30_000;\r\n\r\nvoid main ()\r\n{\r\n\tauto s = sieve (limit);\r\n\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto d = readln.strip.to !(int);\r\n\t\tauto x = 1;\r\n\t\tauto res = x;\r\n\t\tforeach (i; 0..2)\r\n\t\t{\r\n\t\t\tx += d;\r\n\t\t\twhile (!s[x])\r\n\t\t\t{\r\n\t\t\t\tx += 1;\r\n\t\t\t}\r\n\t\t\tres *= x;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nenum PCNT = 10^^6;\r\n\r\nbool[PCNT+1] PS;\r\n\r\nvoid prime_init()\r\n{\r\n PS[] = true;\r\n PS[0] = false;\r\n PS[1] = false;\r\n foreach (i; 2..PCNT+1) {\r\n if (PS[i]) {\r\n auto x = i*2;\r\n while (x <= PCNT) {\r\n PS[x] = false;\r\n x += i;\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n prime_init();\r\n int[] ps;\r\n foreach (i; 1..PCNT + 1) if (PS[i]) ps ~= i;\r\n\r\n int T; get(T);\r\n while (T--) {\r\n int d; get(d);\r\n if (d == 1) {\r\n writeln(6);\r\n continue;\r\n }\r\n long search(long p) {\r\n int l, r = ps.length.to!int;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n if (ps[m] >= p + d) {\r\n r = m;\r\n } else {\r\n l = m;\r\n }\r\n }\r\n return ps[r];\r\n }\r\n auto p = search(1);\r\n auto q = search(p);\r\n writeln(p * q);\r\n }\r\n}"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nconst int sz = 100005;\nbool[] isPrime;\nvoid prime_sieve(){\n isPrime = new bool[](sz + 5);\n isPrime[] = 1;\n foreach(p; 2..10000){\n if(isPrime[p]){\n for(ll divi = p*p; divi <= sz; divi += p){\n isPrime[divi.to!int] = 0;\n }\n }\n }\n}\n\n\nvoid theCode(){\n ll n;\n n = scan;\n ll fp;\n for(ll d = n+1; d < 100000 ; ++d){\n if(isPrime[d.to!int]){\n fp = d;\n ll res = (2*fp - 1) * fp;\n writeln(res);\n return;\n }\n }\n}\n\nvoid main(){\n long tests = 1;\n prime_sieve();\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll n;\n n = scan;\n ll res = (2*n + 1) * (n + 1);\n writeln(res);\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "src_uid": "648ec67565c506c3e2ffd007ad44e8c3"} {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}\n\nvoid main()\n{\n int n, k; readV(n, k);\n string[] s; readC(n, s);\n\n auto a = new int[][](n, n);\n\n auto checkH(int r, int c)\n {\n foreach (i; 0..k)\n if (s[r][c+i] == '#') return false;\n return true;\n }\n\n auto addH(int r, int c)\n {\n foreach (i; 0..k) a[r][c+i] += 1;\n }\n\n auto checkV(int r, int c)\n {\n foreach (i; 0..k)\n if (s[r+i][c] == '#') return false;\n return true;\n }\n\n auto addV(int r, int c)\n {\n foreach (i; 0..k) a[r+i][c] += 1;\n }\n\n foreach (r; 0..n)\n foreach (c; 0..n) {\n if (c <= n-k && checkH(r, c)) addH(r, c);\n if (r <= n-k && checkV(r, c)) addV(r, c);\n }\n\n auto m = a.map!(ai => ai.maxElement).maxElement;\n foreach (r; 0..n)\n foreach (c; 0..n)\n if (a[r][c] == m) {\n writeln(r+1, \" \", c+1);\n return;\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.string;\n\nint[] f(string s, int k)\n{\n int[] taken = [-1];\n\n foreach (i, c; s)\n {\n if (c == '#')\n {\n taken ~= cast(int) i;\n }\n }\n\n taken ~= cast(int) s.length;\n\n int[] result = new int[s.length];\n\n int curInTaken = 1;\n\n foreach (i, ref v; result)\n {\n while (taken[curInTaken] < i)\n {\n curInTaken++;\n }\n\n if (i == taken[curInTaken] || k >= taken[curInTaken] - taken[curInTaken - 1])\n {\n v = 0;\n }\n else\n {\n v = min(i - taken[curInTaken - 1], taken[curInTaken] - i, k, taken[curInTaken] - taken[curInTaken - 1] - k);\n }\n }\n\n return result;\n}\n\nvoid main()\n{\n int n, k;\n readf(\" %s %s\", n, k);\n\n readln();\n\n string[] field;\n int[][] a;\n\n foreach (i; 0 .. n)\n {\n auto s = readln().strip();\n a ~= f(s, k);\n field ~= s;\n }\n\n foreach (i; 0 .. n)\n {\n string s;\n \n foreach (j; 0 .. n)\n {\n s ~= field[j][i];\n }\n\n auto r = f(s, k);\n\n foreach (j; 0 .. n)\n {\n a[j][i] += r[j];\n }\n }\n\n int x = 0, y = 0, mx = 0;\n\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. n)\n {\n if (a[i][j] > mx)\n {\n mx = a[i][j];\n x = j;\n y = i;\n }\n }\n }\n\n writeln(y+1, ' ', x+1);\n}"}, {"source_code": "import std.algorithm.iteration : map;\nimport std.algorithm.searching : maxElement;\nimport std.array;\nimport std.range : enumerate;\nimport std.stdio;\n\nvoid main()\n{\n int n, k;\n readf!\"%d %d\\n\"(n, k);\n auto board = stdin.byLineCopy().array();\n int[][] count = new int[][](n, n);\n\n foreach (r; 0..n) {\n foreach (c; 0..n) {\n auto valid = true;\n\n // check horizontal\n foreach (i; 0..k) {\n\tif (c+i >= n || board[r][c+i] == '#') {\n\t valid = false;\n\t break;\n\t}\n }\n if (valid) {\n\tforeach (i; 0..k) {\n\t count[r][c+i]++;\n\t}\n }\n\n valid = true;\n // check vertical\n foreach (j; 0..k) {\n\tif (r+j >= n || board[r+j][c] == '#') {\n\t valid = false;\n\t break;\n\t}\n }\n if (valid) {\n\tforeach (j; 0..k) {\n\t count[r+j][c]++;\n\t}\n }\n }\n }\n\n auto countIdx = count.map!(a => a.enumerate.maxElement!\"a.value\");\n auto best = countIdx.enumerate.maxElement!\"a.value.value\";\n writef(\"%d %d\\n\", best.index + 1, best.value.index + 1);\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm.iteration : map;\nimport std.algorithm.searching : maxElement;\nimport std.array;\nimport std.range : enumerate;\nimport std.stdio;\n\nvoid main()\n{\n int n, k;\n readf!\"%d %d\\n\"(n, k);\n auto board = stdin.byLineCopy().array();\n int[][] count = new int[][](n, n);\n\n foreach (r; 0..n-k+1) {\n foreach (c; 0..n-k+1) {\n auto valid = true;\n\n // check horizontal\n foreach (i; 0..k) {\n\tif (board[r][c+i] == '#') {\n\t valid = false;\n\t break;\n\t}\n }\n if (valid) {\n\tforeach (i; 0..k) {\n\t count[r][c+i]++;\n\t}\n }\n\n valid = true;\n // check vertical\n foreach (j; 0..k) {\n\tif (board[r+j][c] == '#') {\n\t valid = false;\n\t break;\n\t}\n }\n if (valid) {\n\tforeach (j; 0..k) {\n\t count[r+j][c]++;\n\t}\n }\n }\n }\n\n auto countIdx = count.map!(a => a.enumerate.maxElement!\"a.value\");\n auto best = countIdx.enumerate.maxElement!\"a.value.value\";\n writef(\"%d %d\\n\", best.index + 1, best.value.index + 1);\n}\n\n"}], "src_uid": "6fb20914525715af737d81f3a5d98636"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const D = readInt();\n const E = readInt();\n \n int ans = N;\n for (int a = 0; D * a <= N; ++a) {\n const n = N - D * a;\n chmin(ans, n % (E * 5));\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n,d,e;\n readf!\" %s %s %s\"(n,d,e);\n\n int ans = n;\n\n for (int k = 0; k <= n / d; k++) {\n int rest = n - k * d;\n ans = min(ans, rest % (e*5));\n }\n\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto d = RD;\n\tauto e = RD*5;\n\n\tlong ans = long.max;\n\twhile (n >= e)\n\t{\n\t\tans = min(n % d, ans);\n\t\tn -= e;\n\t}\n\tans = min(n % d, ans);\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "8c5d9b4fd297706fac3be83fc85028a0"} {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.string;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nvoid makeKmpPrefixFunction(string pattern, int[] kmpPreFunc) {\n\tint m = pattern.length;\n\tint k = -1;\n\tint q = 0;\n\tkmpPreFunc[q] = k;\n\twhile (q < m) {\n\t\twhile (k >= 0 && pattern[k] != pattern[q])\n\t\t\tk = kmpPreFunc[k];\n\t\t++k;\n\t\t++q;\n\t\tkmpPreFunc[q] = k;\n\t}\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string answer = \"Just a legend\";\n\n string str;\n readf(\"%s\\n\", &str);\n int[] kmpPreFunc = new int[str.length + 1];\n makeKmpPrefixFunction(str, kmpPreFunc);\n int mm = kmpPreFunc[$ - 1];\n if (mm > 0) {\n bool found = false;\n foreach ( i ; 1 .. str.length ) {\n if (kmpPreFunc[i] == mm) {\n found = true;\n answer = str[0 .. mm];\n }\n }\n if (!found) {\n foreach ( i ; 0 .. mm + 1 ) kmpPreFunc[i] = 0;\n makeKmpPrefixFunction(str[0 .. mm], kmpPreFunc);\n if (kmpPreFunc[mm] > 0) answer = str[0 .. kmpPreFunc[mm]];\n }\n }\n writeln(answer);\n\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.string;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nvoid makeKmpPrefixFunction(string pattern, int[] kmpPreFunc) {\n\tint m = pattern.length;\n\tint k = -1;\n\tint q = 0;\n\tkmpPreFunc[q] = k;\n\twhile (q < m) {\n\t\twhile (k >= 0 && pattern[k] != pattern[q])\n\t\t\tk = kmpPreFunc[k];\n\t\t++k;\n\t\t++q;\n\t\tkmpPreFunc[q] = k;\n\t}\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string answer = \"Just a legend\";\n\n string str;\n readf(\"%s\\n\", &str);\n int[] kmpPreFunc = new int[str.length + 1];\n makeKmpPrefixFunction(str, kmpPreFunc);\n int mm = kmpPreFunc[str.length];\n if (mm > 0) {\n bool found = false;\n foreach ( i ; 1 .. str.length ) {\n if (kmpPreFunc[i] == mm) {\n found = true;\n answer = str[0 .. mm];\n break;\n }\n }\n if (!found) {\n foreach ( i ; 0 .. mm + 1 ) kmpPreFunc[i] = 0;\n makeKmpPrefixFunction(str[0 .. mm], kmpPreFunc);\n if (kmpPreFunc[mm] > 0) answer = str[0 .. kmpPreFunc[mm]];\n }\n }\n writeln(answer);\n\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.string;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nint matchlen(string str, int pos) {\n pragma(inline, true);\n int res = 0;\n for (int i = 0; i < pos && i*3 < str.length; ++i) {\n if (str[i] == str[i + pos]) ++res;\n }\n return res;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string str;\n readf(\"%s\\n\", &str);\n if (str.length < 3) {\n writeln(\"Just a legend\");\n return 0;\n }\n foreach_reverse ( i ; 1 .. 1 + str.length / 3 ) {\nnext: foreach ( j ; i .. 1 + i + str.length - 3 * i ) {\n foreach ( k ; 0 .. i ) {\n if (str[k] != str[k + j] || str[k + j] != str[$ - i + k])\n continue next;\n }\n writeln(str[0 .. i]);\n return 0;\n }\n }\n writeln(\"Just a legend\");\n\n return 0;\n}"}], "src_uid": "fd94aea7ca077ee2806653d22d006fb1"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto a = readln.splitter.map!(to!long).array;\n long a0 = a[1] - (a[2] - a[1]);\n if (a0 % a[0] == 0 && a0 / a[0] > 0) {\n writeln(\"YES\");\n continue;\n }\n if ((a[0] + a[2]) % 2 == 0 &&\n (((a[0] + a[2]) / 2) % a[1] == 0) &&\n (((a[0] + a[2]) / 2) / a[1] > 0)) {\n writeln(\"YES\");\n continue;\n }\n long a2 = a[1] + (a[1] - a[0]);\n if (a2 % a[2] == 0 && a2 / a[2] > 0) {\n writeln(\"YES\");\n continue;\n }\n writeln(\"NO\");\n }\n}\n", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n void subSolve(long[] nums) {\r\n bool ans;\r\n\r\n long[] candidates = [\r\n nums[1] - (nums[2] - nums[1]),\r\n (nums[0] + nums[2]) % 2 == 0 ? (nums[0] + nums[2]) / 2 : -1,\r\n nums[1] + (nums[1] - nums[0])\r\n ];\r\n \r\n // [nums, candidates].deb;\r\n foreach(i, cand; candidates) {\r\n if (cand <= 0) continue;\r\n\r\n ans |= (cand % nums[i] == 0);\r\n }\r\n\r\n writeln(ans ? \"YES\" : \"NO\");\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve(scan!long(3));\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable a = (){ int x; readf!\"%s\"(x); return x; }();\n immutable b = (){ int x; readf!\" %s\"(x); return x; }();\n immutable c = (){ int x; readf!\" %s\\n\"(x); return x; }();\n\n if ((b + b - a) % c == 0 && (b + b - a) / c > 0)\n writeln(\"YES\");\n else if ((a + c) % 2 == 0 && (a + c) / 2 % b == 0 && (a + c) / 2 / b > 0)\n writeln(\"YES\");\n else if ((b - (c - b)) % a == 0 && (b - (c - b)) / a > 0)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n// \"\"\n"}], "negative_code": [], "src_uid": "90c5058c0c7f55a567f2e036482149f9"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto edges = new int[][](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto s = RD!string;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (s[j] == '1')\n\t\t\t{\n\t\t\t\tedges[i] ~= j;\n\t\t\t}\n\t\t}\n\t}\n\tauto m = RD!int;\n\tauto p = RDA!int(-1);\n\n\tlong[int] memo;\n\tlong search(int start, int goal)\n\t{\n\t\tauto key = start * 1000 + goal;\n\t\tif (memo.get(key, -1) != -1) return memo[key];\n\n\t\tint[] open = [start];\n\t\tauto dist = new long[](n);\n\t\tdist[] = long.max;\n\t\tdist[start] = 0;\n\t\twhile (!open.empty)\n\t\t{\n\t\t\tauto from = open.front; open.popFront;\n\t\t\tforeach (to; edges[from])\n\t\t\t{\n\t\t\t\tauto d = dist[from] + 1;\n\t\t\t\tif (d < dist[to])\n\t\t\t\t{\n\t\t\t\t\tdist[to] = d;\n\t\t\t\t\tif (to == goal)\n\t\t\t\t\t{\n\t\t\t\t\t\tmemo[key] = dist[to];\n\t\t\t\t\t\treturn dist[to];\n\t\t\t\t\t}\n\t\t\t\t\topen ~= to;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n\tlong[] ans = [p[0]+1];\n\tint i, j = 1;\n\tlong last = search(p[0], p[1]);\n\twhile (j < m-1)\n\t{\n\t\tauto d1 = last + search(p[j], p[j+1]);\n\t\tauto d2 = search(p[i], p[j+1]);\n\t\tif (d2 >= d1) // \u7701\u7565\u53ef\u80fd\u306a\u5834\u5408\n\t\t{\n\t\t\t++j;\n\t\t\tlast = d1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans ~= [p[j]+1];\n\t\t\ti = j;\n\t\t\t++j;\n\t\t\tlast = d1 - last;\n\t\t}\n\t}\n\tans ~= p[$-1]+1;\n\t\n\twriteln(ans.length);\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto g = new string[] (n+1);\n foreach (i; 1 .. n+1) {\n g[i] = \"0\" ~ readln.chomp;\n }\n \n debug { g.writeln; }\n \n immutable int INF = 10 ^^ 9 + 7;\n auto fw = new int[][] (n+1, n+1);\n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n fw[i][j] = g[i][j] == '1' ? 1 : INF;\n }\n \n fw[i][i] = 0;\n }\n \n foreach (k; 1 .. n+1) {\n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n fw[i][j] = min(fw[i][j], fw[i][k] + fw[k][j]);\n }\n }\n }\n \n debug { fw.each!writeln; }\n \n int m;\n readf(\"%s\", &m);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n int[] ans;\n ans ~= a.front;\n \n foreach (p; 1 .. a.length-1) {\n if (fw[ans.back][a[p+1]] < fw[ans.back][a[p]] + fw[a[p]][a[p+1]]) {\n ans ~= a[p];\n }\n }\n \n ans ~= a.back;\n \n ans.length.writeln;\n ans.map!(to!string).join(\" \").writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto g = new string[] (n+1);\n foreach (i; 1 .. n+1) {\n g[i] = \"0\" ~ readln.chomp;\n }\n \n debug { g.writeln; }\n \n immutable int INF = 10 ^^ 9 + 7;\n auto fw = new int[][] (n+1, n+1);\n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n fw[i][j] = g[i][j] == '1' ? 1 : INF;\n }\n \n fw[i][i] = 0;\n }\n \n foreach (k; 1 .. n+1) {\n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n fw[i][j] = min(fw[i][j], fw[i][k] + fw[k][j]);\n }\n }\n }\n \n int m;\n readf(\"%s\", &m);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n int[] ans;\n ans ~= a.front;\n \n foreach (p; 1 .. a.length-1) {\n if (fw[a[p-1]][a[p+1]] < fw[a[p-1]][a[p]] + fw[a[p]][a[p+1]]) {\n ans ~= a[p];\n }\n }\n \n ans ~= a.back;\n \n ans.length.writeln;\n ans.map!(to!string).join(\" \").writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto g = new string[] (n+1);\n foreach (i; 1 .. n+1) {\n g[i] = \"0\" ~ readln.chomp;\n }\n \n debug { g.writeln; }\n \n int m;\n readf(\"%s\", &m);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n int[] ans;\n ans ~= a.front;\n \n foreach (p; 1 .. a.length-1) {\n if (a[p-1] == a[p+1] || g[a[p-1]][a[p+1]] == '1') {\n ans ~= a[p];\n }\n }\n \n ans ~= a.back;\n \n ans.length.writeln;\n ans.map!(to!string).join(\" \").writeln;\n}"}], "src_uid": "c9d07fdf0d3293d5564275ebbabbcf12"} {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto q = readInt!int;\n\tdebug writeln(n, \" \", q);\n\tauto a = ma(n, readInt!int);\n\tauto b = ma(n, readInt!int);\n\tauto d = new int[](n);\n\tforeach(i, ref di; d) di = a[i] - b[i];\n\tauto ssum = new long[](n + 1);\n\tssum[n] = 0;\n\tforeach_reverse(i; 0 .. n)\n\t{\n\t\tssum[i] = ssum[i+1] + d[i];\n\t}\n\tdebug writeln(\"ssum \", ssum);\n\tauto ssumMin = Sparse!(long, min, \"min\")(ssum);\n\tauto ssumMax = Sparse!(long, max, \"max\")(ssum);\n\tdebug writeln(\"entering queries \", q);\n\tforeach(qi; 0 .. q)\n\t{\n\t\tdebug writeln(qi);\n\t\tauto l = readInt!int - 1;\n\t\tauto r = readInt!int - 1;\n\t\tdebug writeln(\"query \", qi + 1, \" \", l, \" \", r);\n\t\tauto sumlr = ssum[l] - ssum[r+1];\n\t\tif (sumlr != 0)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue;\n\t\t}\n\t\tauto lsum = ssumMin[l .. r + 1].min - ssum[r+1];\n\t\tif (lsum < 0)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue;\n\t\t}\n\t\tauto hsum = ssumMax[l .. r + 1].max - ssum[r+1];\n\t\thsum.writeln;\n\t}\n}\n\n// sparse table V, f, fName {{{\nstruct Sparse(V, alias f, string fName = \"value\")\n{\n\timport std.math : log2;\n\tV[][] _table;\n\tint[] maxPow;\n\tthis(V[] values)\n\t{\n\t\tauto n = values.length;\n\t\tmaxPow = new int[](n + 1);\n\t\tmaxPow[0] = int.min;\n\t\tmaxPow[1] = 0;\n\t\tforeach(i; 2 .. n + 1)\n\t\t{\n\t\t\tint prev = maxPow[i - 1];\n\t\t\tmaxPow[i] = prev;\n\t\t\tprev = (1 << prev);\n\t\t\tif (prev * 2 <= i) maxPow[i]++;\n\t\t}\n\t\t_table = new V[][](maxPow[n] + 1, n);\n\t\t_table[0][] = values[];\n\n\t\tdebug writeln(\"constructing table \", maxPow[n]);\n\t\tforeach(p; 1 .. maxPow[n] + 1)\n\t\tforeach(i; 0 .. n - (1<<p) + 1)\n\t\t\t_table[p][i] = f(_table[p-1][i], _table[p-1][i+(1<<(p-1))]);\n\t\tdebug writeln(\"done \");\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\tint sliceLen = slice[1] - slice[0];\n\t\tauto x = maxPow[sliceLen];\n\t\tauto twoX = (1 << x);\n\t\tauto p1 = _table[x][slice[0]];\n\t\tauto p2 = _table[x][slice[1] - twoX];\n\t\tstruct Ans\n\t\t{\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t}\n\t\treturn Ans(f(p1, p2));\n\t}\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.stdio;\n\talias MinQ = Sparse!(int, min, \"min\");\n\twriteln(\"testing\");\n\tint[] array = [1, 2, 3, 4, -2, -2, -3, 0, 10];\n\tauto minQ = MinQ(array); \n\tforeach(i; 0 .. array.length)\n\t{\n\t\tforeach(j; i + 1 .. array.length + 1)\n\t\t{\n\t\t\tassert(minQ[i .. j].min == array[i .. j].fold!min);\n\t\t}\n\t}\n}\n// }}}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nstruct Record\r\n{\r\n\tlong diff;\r\n\tlong lo;\r\n\tlong hi;\r\n\r\n\tRecord opBinary (string op) (const auto ref Record that) const\r\n\t if (op == \"+\")\r\n\t{\r\n\t\treturn Record (this.diff + that.diff,\r\n\t\t min (this.lo, that.lo + this.diff),\r\n\t\t max (this.hi, that.hi + this.diff));\r\n\t}\r\n}\r\n\r\nimmutable int logHalf = 17;\r\nimmutable int half = 1 << logHalf;\r\nimmutable int limit = half << 1;\r\n\r\nvoid main ()\r\n{\r\n\tint n, q;\r\n\twhile (readf !(\" %s %s\") (n, q) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tauto t = new Record [limit];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tt[half + i].diff = b[i] - a[i];\r\n\t\t\tt[half + i].lo = min (0, t[half + i].diff);\r\n\t\t\tt[half + i].hi = max (0, t[half + i].diff);\r\n\t\t\tdebug {writeln (t[half + i]);}\r\n\t\t}\r\n\t\tforeach_reverse (i; 1..half)\r\n\t\t{\r\n\t\t\tt[i] = t[i * 2 + 0] + t[i * 2 + 1];\r\n\t\t}\r\n\r\n\t\tRecord tGet (int lo, int hi)\r\n\t\t{\r\n\t\t\tint [] nums1;\r\n\t\t\tint [] nums2;\r\n\t\t\tfor (lo += half, hi += half; lo < hi;\r\n\t\t\t lo >>= 1, hi >>= 1)\r\n\t\t\t{\r\n\t\t\t\tif (lo & 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tnums1 ~= lo;\r\n\t\t\t\t\tlo += 1;\r\n\t\t\t\t}\r\n\t\t\t\tif (hi & 1)\r\n\t\t\t\t{\r\n\t\t\t\t\thi -= 1;\r\n\t\t\t\t\tnums2 ~= hi;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRecord res;\r\n\t\t\tforeach (i; nums1 ~ nums2.retro.array)\r\n\t\t\t{\r\n\t\t\t\tres = res + t[i];\r\n\t\t\t}\r\n\t\t\tdebug {writeln (res);}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tforeach (j; 0..q)\r\n\t\t{\r\n\t\t\tint l, r;\r\n\t\t\treadf !(\" %s %s\") (l, r);\r\n\t\t\tl -= 1;\r\n\t\t\tr -= 0;\r\n\t\t\tauto cur = tGet (l, r);\r\n\t\t\twriteln ((cur.diff == 0 && cur.lo >= 0) ? cur.hi : -1);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "5f3022de0429cca31bab24501347eb69"} {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1, ret = -1;\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t ret = mid;\n\t left = mid + 1;\n\t //right = mid - 1;\n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n if (ret == -1) ret = left;\n return ret;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n long ansa = a.length << 1, ansb = b.length << 1;\n //auto pos = find(a[0] - 1, b);\n //long ansa = a.length * 3;\n //long ansb = pos * 2 + (b.length - pos) * 3;\n long dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\t//if (i < a.length - 1 && a[i] == a[i + 1]) continue;\n\tif (i > 0 && a[i] == a[i - 1]) continue;\n\tauto pos = find(a[i] - 1, b);\n\t//long scorea = (i + 1) * 3 + (a.length - i - 1) * 2;\n\tlong scorea = i * 2 + (a.length - i) * 3;\n\tlong scoreb;\n\tif (pos < b.length && b[pos] == a[i] - 1)\n\t{\n\t scoreb = (pos + 1) * 2 + (b.length - pos - 1) * 3;\n\t}\n\telse\n\t{\n\t scoreb = pos * 2 + (b.length - pos) * 3;\n\t}\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1, ret = -1;\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t ret = mid;\n\t left = mid + 1;\n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n if (ret == -1) ret = left;\n return ret;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n long ansa = a.length << 1, ansb = b.length << 1;\n long dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\tif (i > 0 && a[i] == a[i - 1]) continue;\n\tauto pos = find(a[i] - 1, b);\n\tlong scorea = i * 2 + (a.length - i) * 3;\n\tlong scoreb;\n\tif (pos < b.length && b[pos] == a[i] - 1)\n\t{\n\t scoreb = (pos + 1) * 2 + (b.length - pos - 1) * 3;\n\t}\n\telse\n\t{\n\t scoreb = pos * 2 + (b.length - pos) * 3;\n\t}\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint[] find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1;\n auto ret = new int[2];\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t ret[0] = mid;\n\t ret[1] = 1;\n\t return ret;\n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n ret[0] = left;\n ret[1] = 0;\n return ret;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n long ansa = a.length << 1, ansb = b.length << 1;\n long dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\tauto res = find(a[i], b);\n\tlong scorea = (i + 1) * 3 + (a.length - i - 1) * 2;\n\tlong scoreb;\n\tif (res[1] == 1)\n\t{\n\t scoreb = (res[0] + 1) * 2 + (b.length - res[0] - 1) * 3;\n\t}\n\telse\n\t{\n\t if (res[0] == 0)\n\t {\n\t\tscoreb = b.length * 3;\n\t }\n\t else\n\t {\n\t\tscoreb = res[0] * 2 + (b.length - res[0]) * 3;\n\t }\n\t}\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1, ret = -1;\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t ret = mid;\n\t //left = mid + 1;\n\t right = mid - 1;\n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n if (ret == -1) ret = left;\n return ret;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n long ansa = a.length << 1, ansb = b.length << 1;\n //auto pos = find(a[0] - 1, b);\n //long ansa = a.length * 3;\n //long ansb = pos * 2 + (b.length - pos) * 3;\n long dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\t//if (i < a.length - 1 && a[i] == a[i + 1]) continue;\n\tif (i > 0 && a[i] == a[i - 1]) continue;\n\tauto pos = find(a[i] - 1, b);\n\t//long scorea = (i + 1) * 3 + (a.length - i - 1) * 2;\n\tlong scorea = i * 2 + (a.length - i) * 3;\n\tlong scoreb;\n\tif (pos < b.length && b[pos] == a[i] - 1)\n\t{\n\t scoreb = (pos + 1) * 2 + (b.length - pos - 1) * 3;\n\t}\n\telse\n\t{\n\t scoreb = pos * 2 + (b.length - pos) * 3;\n\t}\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1, ret = -1;\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t ret = mid;\n\t //left = mid + 1;\n\t right = mid - 1;\n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n if (ret == -1) ret = left;\n return ret;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n long ansa = a.length << 1, ansb = b.length << 1;\n //auto pos = find(a[0] - 1, b);\n //long ansa = a.length * 3;\n //long ansb = pos * 2 + (b.length - pos) * 3;\n long dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\tif (i < a.length - 1 && a[i] == a[i + 1]) continue;\n\t//if (i > 0 && a[i] == a[i - 1]) continue;\n\tauto pos = find(a[i] - 1, b);\n\tlong scorea = (i + 1) * 3 + (a.length - i - 1) * 2;\n\tlong scoreb = pos * 2 + (b.length - pos) * 3;\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1, ret = -1;\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t ret = mid;\n\t left = mid + 1;\n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n if (ret == -1) ret = left;\n return ret;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n long ansa = a.length << 1, ansb = b.length << 1;\n long dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\tif (i < a.length - 1 && a[i] == a[i + 1]) continue;\n\tauto pos = find(a[i], b);\n\tlong scorea = (i + 1) * 3 + (a.length - i - 1) * 2;\n\tlong scoreb = pos * 2 + (b.length - pos) * 3;\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1, ret = -1;\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t ret = mid;\n\t //left = mid + 1;\n\t right = mid - 1;\n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n if (ret == -1) ret = left;\n return ret;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n int ansa = a.length << 1, ansb = b.length << 1;\n //auto pos = find(a[0] - 1, b);\n //int ansa = a.length * 3;\n //int ansb = pos * 2 + (b.length - pos) * 3;\n int dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\t//if (i < a.length - 1 && a[i] == a[i + 1]) continue;\n\tif (i > 0 && a[i] == a[i - 1]) continue;\n\tauto pos = find(a[i] - 1, b);\n\t//int scorea = (i + 1) * 3 + (a.length - i - 1) * 2;\n\tint scorea = i * 2 + (a.length - i) * 3;\n\tint scoreb = pos * 2 + (b.length - pos) * 3;\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint[] find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1;\n auto ret = new int[2];\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t ret[0] = mid;\n\t ret[1] = 1;\n\t return ret;\n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n ret[0] = left;\n ret[1] = 0;\n return ret;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n long ansa = a.length << 1, ansb = b.length << 1;\n long dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\tauto res = find(a[i], b);\n\tlong scorea = (i + 1) * 3 + (a.length - i - 1) * 2;\n\tlong scoreb;\n\tif (res[1] == 1)\n\t{\n\t scoreb = res[0] * 2 + (b.length - res[0]) * 3;\n\t}\n\telse\n\t{\n\t if (res[0] == 0)\n\t {\n\t\tscoreb = b.length * 3;\n\t }\n\t else\n\t {\n\t\tscoreb = res[0] * 2 + (b.length - res[0]) * 3;\n\t }\n\t}\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nint find(int tar, int[] arr)\n{\n int left = 0, right = to!int(arr.length) - 1;\n while (left <= right)\n {\n\tint mid = (left + right) >> 1;\n\tif (arr[mid] == tar)\n\t{\n\t return mid; \n\t}\n\telse if (arr[mid] < tar)\n\t{\n\t left = mid + 1;\n\t}\n\telse\n\t{\n\t right = mid - 1;\n\t}\n }\n return left;\n}\n\nvoid solve(int[] a, int[] b)\n{\n sort(a);\n sort(b);\n long ansa = a.length << 1, ansb = b.length << 1;\n long dist = ansa - ansb;\n foreach (i; 0 .. a.length)\n {\n\tauto pos = find(a[i], b);\n\tlong scorea = (i + 1) * 3 + (a.length - i - 1) * 2;\n\tlong scoreb = pos * 2 + (b.length - pos) * 3;\n\tif (scorea - scoreb > dist || scorea - scoreb == dist && scorea > ansa)\n\t{\n\t dist = scorea - scoreb;\n\t ansa = scorea;\n\t ansb = scoreb;\n\t}\n }\n writefln(\"%d:%d\", ansa, ansb);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto a = new int[n];\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tscanf(\"%d\", &m);\n\tauto b = new int[m];\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tsolve(a, b);\n }\n}\n"}], "src_uid": "a30b5ff6855dcbad142f6bcc282601a0"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/A\n// \nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(to!int).array;\n\n if(a.count!(x => x < 0) > 0) {\n \"NO\".writeln;\n } else {\n \"YES\".writeln;\n \"101\".writeln;\n for(int i = 0; i < 101; ++i)\n writef(\"%s \", i);\n \"\".writeln;\n }\n}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random, std.math;\n\nint[] solve(ref int[] a, size_t bbase, ref int[int] freq)\n{\n size_t n = a.length;\n foreach (i ; bbase .. n)\n freq[a[i]] = 1;\n\n int[int] b;\n foreach (i ; bbase .. n) {\n foreach (j ; 0 .. i) {\n int diff = abs(a[i] - a[j]);\n if (!freq.get(diff, 0)) {\n b[diff] = 1;\n }\n }\n }\n\n if (b.length == 0)\n return a;\n\n if (a.length + b.length > 300)\n return [];\n\n bbase = a.length;\n a ~= b.keys;\n return solve(a, bbase, freq);\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n foreach (casenum ; 0 .. t) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.chomp.split.map!(to!int).array;\n// writeln(a);\n int[int] freq;\n\n auto result = solve(a, 0, freq);\n if (result.length == 0) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writeln(result.length);\n writeln(result.map!text.joiner(\" \"));\n }\n }\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll n = scan;\n auto arr = scanArray;\n ll maxx = 0;\n foreach(el; arr){\n if(el < 0){\n writeln(\"NO\");\n return;\n }\n maxx = max(el, maxx);\n }\n writeln(\"YES\");\n writeln(maxx+1);\n foreach(el; 0..maxx+1){\n write(el, \" \");\n }\n writeln;\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "\nimport std.stdio;\nimport std.algorithm;\nimport std.numeric;\nvoid solve (){\n int n;\n readf!\"%d\\n\"(n);\n int [] x;\n for (int i = 0; i < n-1; i ++){\n int u;\n readf!\"%d \"(u);\n x ~= u;\n }\n int u;\n readf!\"%d\\n\"(u);\n x ~= u;\n x.sort!\"a < b\"();\n if (x[0] < 0){\n writeln(\"nO\");\n return;\n }\n int max = x[n-1];\n writeln(\"yEs\\n\", max+1);\n for(int i = 0; i <= max; i ++){\n write(i, \" \");\n }\n writeln();\n}\n\nvoid main (){\n int t;\n readf!\"%d\\n\"(t);\n while(t--){\n solve();\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.algorithm, std.array, std.range;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.strip)) {\r\n int n = to!int(readln.strip);\r\n auto nums = readln.split.map!(to!int).array.sort;\r\n if(nums[0] < 0) {\r\n writeln(\"NO\");\r\n } else {\r\n writeln(\"YES\");\r\n writeln(nums[$-1]+1);\r\n writeln(iota(nums[$-1]+1).map!(to!string).join(\" \"));\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/A\n// \nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nlong abs(long n) {\n return n < 0 ? -n : n;\n}\n\nbool contains(long[] a, long item) {\n foreach(x; a)\n if(x == item)\n return true;\n return false;\n}\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n\n while(n < 301) {\n bool found = false;\n n = cast(long)a.length;\n for(int i = 0; i < n; ++i) {\n for(int j = i + 1; j < n; ++j) {\n long x = abs(a[i] - a[j]);\n if(!a.contains(x)) {\n //writefln(\"%s no esta\", x);\n a ~= x;\n found = true;\n }\n }\n }\n if(!found) {\n break;\n }\n }\n if(n >= 301) {\n \"NO\".writeln;\n } else {\n \"YES\".writeln;\n foreach(item; a) {\n writef(\"%s \", item);\n } \"\".writeln;\n }\n}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.algorithm, std.array, std.range;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.strip)) {\r\n int n = to!int(readln.strip);\r\n auto nums = readln.split.map!(to!int).array.sort;\r\n if(nums[0] < 0) {\r\n writeln(\"NO\");\r\n } else {\r\n writeln(\"YES\");\r\n writeln(nums[$-1]-nums[0]+1);\r\n writeln(iota(nums[$-1]+1).map!(to!string).join(\" \"));\r\n }\r\n }\r\n}\r\n"}], "src_uid": "5698e6fd934b9f6b847d7e30a3d06f2b"} {"source_code": "import core.stdc.stdio;\nint n;\nint [333333] a;\nint [333333] nxt;\nint [333333] prv;\nvoid suka(int pos) {\n a[pos] += 1;\n nxt[pos] = nxt[nxt[pos]];\n if(nxt[pos] < n)\n prv[nxt[pos]] = pos;\n}\nvoid main()\n{\n\tscanf(\"%d\",&n);\n\tint len = n;\n\tfor (int i=0;i<n;i++) {\n\t scanf(\"%d\",&a[i]);\n\t nxt[i] = i + 1;\n\t prv[i] = i - 1;\n }\n\tfor (int i;i<n;) {\n\t int nx = nxt[i];\n\t if(i + 1 < n) {\n\t if(a[i] == a[nx]) {\n\t suka(i);\n\t len--;\n\t i = prv[i];\n\t continue;\n }\n\t }\n\t i = nx;\n\t}\n\tprintf(\"%d\\n\", len);\n\tfor (int i;i<n;) {\n\t int nx = nxt[i];\n\t printf(\"%d \", a[i]);\n\t i = nx;\n\t}\n\tprintf(\"\\n\");\n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n int[900100] a;\n int n;\n int it = 0, t;\n readf(\"%d\\n\", &n);\n for(int i = 0; i < n; i++, it++)\n {\n readf(\"%d \", &t);\n a[it] = t;\n if(it == 0)\n continue;\n while(a[it] == a[it - 1])\n {\n it--;\n // writef(\"add to %d\\n\", it);\n // writef(\"%d\\n\", a[it]);\n a[it] = a[it] + 1;\n // writef(\"%d\\n\", a[it]);\n }\n }\n \n // writef(\"her: %d\\n\", a[0]);\n writef(\"%d\\n\", it);\n \n for(int k = 0; k < it; k++)\n writef(\"%d \", a[k]);\n}"}, {"source_code": "import std.stdio, std.bigint, std.string;\n\nvoid main() {\n int n;\n scanf(\"%d\", &n);\n int[] a = new int[n];\n for(int i = 0; i<n; i++) {\n\t\tscanf(\"%d\", &a[i]);\n\t}\n\tint [] b= new int[n];\n\tfor (int i =0; i < n; ++i) {\n\t b[i] = -1;\n\t}\n\tb[0] = a[0];\n\tint c = 1;\n\tint i = 1;\n\twhile (i < n) {\n\t\tc +=1;\n\t\tb[c-1] = a[i];\n\t\t\n\t\twhile (c > 1 && b[c-1] == b[c-2]) {\n\t\t b[c-2] = b[c-2] +1;\n\t\t c-=1;\n\t\t}\n\t\ti += 1;\n\t}\n writeln(c);\n for (int j = 0; j < c; ++j) {\n write(b[j]);\n write(\" \");\n }\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tint l=0;\n\tfor(int i = 0; i<n; i++)\n\t{\n\t\tscanf(\"%d\", &arr[l]);\n\t\tif(l>0)\n\t\t{\n\t\t\twhile(1)\n\t\t\t{\n\t\t\t\tif(arr[l]==arr[l-1])\n\t\t\t\t{\n\t\t\t\t\tarr[l-1]++;\n\t\t\t\t\tl--;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tl++;\n\t}\n\tprintf(\"%d\\n\", l);\n\tfor(int i=0;i<l;i++)\n\t{\n\t\tprintf(\"%d \", arr[i]);\n\t}\n\treturn 0;\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n auto x=readln.split.to!(int[]);\n int[200005] val,pre,nxt;\n for(int i=1;i<=n;i++) {\n val[i]=x[i-1];\n pre[i]=i-1;\n nxt[i]=i+1;\n } \n nxt[0]=1;\n pre[n+1]=n;\n int cnt=n;\n for(int i=nxt[1];i<=n;i=nxt[i]) {\n while(val[i]==val[pre[i]]) {\n val[i]++;\n cnt--;\n nxt[pre[pre[i]]]=nxt[pre[i]];\n pre[nxt[pre[i]]]=pre[pre[i]];\n }\n }\n writeln(cnt);\n for(int i=nxt[0];i<=n;i=nxt[i])\n write(val[i]),write(' ');\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x){\n e=l[i].to!(typeof(e));\n }\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = stdin;\n\n auto n = next!int;\n auto a = next!int(n);\n auto finalA = DList!int();\n foreach(ai; a)\n {\n auto toInsert = ai;\n while (!finalA.empty && finalA.front == toInsert)\n\t{\n\t finalA.removeFront;\n\t toInsert++;\n\t}\n finalA.insertFront(toInsert);\n }\n auto finalAArray = finalA[].array;\n finalAArray.length.writeln;\n foreach_reverse(fai; finalAArray)\n write(fai, \" \");\n writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tint [] bk = new int[n];\n\tint tk = -1;\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tfor(int e = 0; e < n; e++){\n if(tk == -1){\n bk[++tk] = arr[e];\n } else {\n while(tk >= 0 && bk[tk] == arr[e]){\n tk--;\n arr[e]++;\n }\n bk[++tk] = arr[e];\n }\n }\n printf(\"%d\\n\", tk + 1);\n for(int e = 0; e <= tk; e++)\n printf(\"%d \", bk[e]);\n printf(\"\\n\");\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\n/* Hello World Program in D Programming */\nvoid main(string[ ] args)\n{\n int n;\n scanf(\"%d\", &n);\n int[211111] a;\n int a_len = 0;\n for (int i = 0; i < n; ++i) {\n scanf(\"%d\", &a[i]);\n }\n for (int i = 0; i < n; ++i) {\n a[a_len] = a[i];\n ++a_len;\n while (a_len > 1 && a[a_len - 1] == a[a_len - 2]) {\n --a_len;\n ++a[a_len - 1];\n }\n }\n printf(\"%d\\n\", a_len);\n for (int i = 0; i < a_len; ++i) {\n printf(\"%d \", a[i]);\n }\n printf(\"\\n\");\n\n return;\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n; readf(\" %s\", &n);\n auto ok = new int[n];\n int top=0;\n for (int i = 0; i < n; i++) {\n int k; readf(\" %s\", &k);\n if(top==0){ok[top]=k; top++;}\n else\n {\n if(ok[top-1]!=k){ok[top]=k; top++;}\n else\n {while(ok[top-1]==k && top>0)\n {\n ok[top-1]=k+1;\n k++;\n top--;\n }\n top++;\n }\n }\n \n }\n writeln(top);\n writeln(\"\\n\");\n int i=0;\n while(i<top) {\n writeln(ok[i]);\n i++;\n writeln(\" \");\n }\n \n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto p = [0] ~ readln.splitter.map !(to !(int)).array;\n\t\tauto a = new int [n + 1];\n\t\tauto cp = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t auto x = p[i];\n\t\t while (cp > 0 && a[cp] == x) {\n\t\t x += 1;\n\t\t cp -= 1;\n\t\t }\n\t\t cp += 1;\n\t\t a[cp] = x;\n\t\t}\n\t\twriteln(cp);\n\t\tforeach (i; 1..cp + 1)\n\t\t{\n\t\t write(a[i]);\n\t\t write(\" \");\n\t\t}\n\t}\n}"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.string;\n\nint main(string[] argv)\n{\n\tint n, j = 0; \n\tscanf(\"%d\", &n);\n int [] a = new int[n];\n for(int i = 0; i < n; i++) \n { \n scanf(\"%d\", &a[j]);\n while(j > 0 && a[j] == a[j - 1]) \n { \n a[j - 1]++; \n a[j] = 0; \n j--; \n } \n j++; \n } \n writeln(j);\n for(int i = 0; i < j; i++) \n write(a[i],\" \"); \n\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto p = [0] ~ readln.splitter.map !(to !(int)).array;\n\t\tauto a = new int [n + 1];\n\t\tauto cp = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t auto x = p[i];\n\t\t while (cp > 0 && a[cp] == x) {\n\t\t x += 1;\n\t\t cp -= 1;\n\t\t }\n\t\t cp += 1;\n\t\t a[cp] = x;\n\t\t}\n\t\tforeach (i; 1..cp + 1)\n\t\t{\n\t\t write(a[i]);\n\t\t write(\" \");\n\t\t}\n\t}\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int[101000] a;\n int n;\n int it = 0, t;\n readf(\"%d\\n\", &n);\n for(int i = 0; i < n; i++, it++)\n {\n readf(\"%d \", &t);\n a[it] = t;\n if(it == 0)\n continue;\n if(a[it] == a[it - 1])\n {\n it--;\n // writef(\"add to %d\\n\", it);\n // writef(\"%d\\n\", a[it]);\n a[it] = a[it] + 1;\n // writef(\"%d\\n\", a[it]);\n }\n }\n \n // writef(\"her: %d\\n\", a[0]);\n \n for(int k = 0; k < it; k++)\n writef(\"%d \", a[k]);\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int[101000] a;\n int n;\n int it = 0, t;\n readf(\"%d\\n\", &n);\n for(int i = 0; i < n; i++, it++)\n {\n readf(\"%d \", &t);\n a[it] = t;\n if(it == 0)\n continue;\n if(a[it] == a[it - 1])\n {\n it--;\n // writef(\"add to %d\\n\", it);\n // writef(\"%d\\n\", a[it]);\n a[it] = a[it] + 1;\n // writef(\"%d\\n\", a[it]);\n }\n }\n \n // writef(\"her: %d\\n\", a[0]);\n writef(\"%d\\n\", it);\n \n for(int k = 0; k < it; k++)\n writef(\"%d \", a[k]);\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tint l=0;\n\tfor(int i = 0; i<n; i++)\n\t{\n\t\tscanf(\"%d\", &arr[l]);\n\t\tif(l>0)\n\t\t{\n\t\t\twhile(1)\n\t\t\t{\n\t\t\t\tif(arr[l]==arr[l-1])\n\t\t\t\t{\n\t\t\t\t\tarr[l-1]++;\n\t\t\t\t\tl--;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tl++;\n\t}\n\tprintf(\"%d\", l);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tint l=0;\n\tfor(int i = 0; i<n; i++)\n\t{\n\t\tscanf(\"%d\", &arr[l]);\n\t\tif(l>0)\n\t\t{\n\t\t\twhile(1)\n\t\t\t{\n\t\t\t\tif(arr[l]==arr[l-1])\n\t\t\t\t{\n\t\t\t\t\tarr[l-1]++;\n\t\t\t\t\tl--;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tl++;\n\t}\n\tprintf(\"%d\", l);\n\tfor(int i=0;i<l;i++)\n\t{\n\t\tprintf(\"%d \", arr[i]);\n\t}\n\treturn 0;\n}"}], "src_uid": "8c715616c8fa373c95368cf4795a2e6a"} {"source_code": "void main() {\n\tauto N = ri;\n\tint[][] tree = new int[][](N+3, 0);\n\t//foreach(i; 2..N+2) tree[i] = [];\n\tforeach(i; 2..N+1) {\n\t\tauto p = ri;\n\t\ttree[p] ~= i;\n\t}\n\tulong k;\n\tint[][] que;\n\tque = [[],[]];\n\tque[0] ~= 1;\n\tbool flag = true;\n\twhile(que[k%2] != []) {\n\t\tauto p = que[k%2].front;\n\t\tque[k%2].popFront;\n\t\tulong cnt;\n\t\tbool ok = true;\n\t\tforeach(i; tree[p]) {\n\t\t\tque[(k+1)%2] ~= i;\n\t\t\tdebug writefln(\"%s %s %s\", tree[i], [], tree[i] == []);\n\t\t\tif(tree[i] == []) cnt++;\n\t\t\telse ok = false;\n\t\t}\n\t\tif((!ok && cnt == 0) || cnt != 0 && cnt < 3) flag = false;\n\t\tk++;\n\t}\n\twriteln(flag ? \"Yes\" : \"No\");\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.datetime;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto G = new int[][](N);\n foreach (i; 0..N-1) {\n auto v = readln.chomp.to!int;\n G[v-1] ~= i+1;\n }\n\n auto is_leaf = new bool[](N);\n foreach (i; 0..N) is_leaf[i] = G[i].length == 0;\n\n auto ok = new bool[](N);\n foreach (i; 0..N) {\n if (is_leaf[i]) {\n ok[i] = true;\n continue;\n }\n int cnt = 0;\n foreach (m; G[i]) {\n cnt += is_leaf[m];\n }\n ok[i] = cnt >= 3;\n }\n\n writeln(ok.all ? \"Yes\" : \"No\");\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) sc.read!true;\n\n int n;\n sc.read(n);\n int[][] g = new int[][](n);\n foreach (i; 1..n) {\n int p;\n sc.read(p); p--;\n g[p] ~= i;\n }\n\n bool ans = true;\n int dfs(int p) {\n if (g[p].length == 0) return 1;\n int u = 0;\n foreach (d; g[p]) {\n u += dfs(d);\n }\n if (u < 3) ans = false;\n return 0;\n }\n dfs(0);\n if (ans) writeln(\"Yes\");\n else writeln(\"No\");\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {\n import std.exception;\n enforce(readSingle(x));\n static if (args.length == 0) {\n enforce(enforceEOF == false || !succ());\n } else {\n read!enforceEOF(args);\n }\n }\n void read(bool enforceEOF = false, Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length == 0) {\n enforce(enforceEOF == false || !succ());\n } else {\n enforce(readSingle(args[0]));\n read!enforceEOF(args);\n }\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool solve (int [] p)\n{\n\tauto n = p.length;\n\tauto d = new int [n];\n\tforeach (i; 1..n)\n\t{\n\t\td[p[i]] += 1;\n\t}\n\tauto isLeaf = new bool [n];\n\tauto leafSons = new int [n];\n\tforeach (i; 1..n)\n\t{\n\t\tisLeaf[i] = (d[i] == 0);\n\t\tleafSons[p[i]] += isLeaf[i];\n\t}\n\tforeach (i; 0..n)\n\t{\n\t\tif (!isLeaf[i])\n\t\t{\n\t\t\tif (leafSons[i] < 3)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto p = new int [n];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\treadf (\" %s\", &p[i]);\n\t\t}\n\t\tp[] -= 1;\n\t\twriteln (solve (p) ? \"Yes\" : \"No\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.ascii;\n\nvoid main() {\n int n;\n scan(n);\n\n auto adj = new int[][](n, 0);\n\n foreach (i ; 1 .. n) {\n int pi;\n scan(pi);\n adj[pi-1] ~= i;\n }\n\n bool ans = true;\n\n void dfs(int v, int p) {\n if (adj[v].empty) return;\n\n int lc;\n\n foreach (u ; adj[v]) {\n if (u == p) continue;\n if (adj[u].empty) {\n lc++;\n }\n else {\n dfs(u, v);\n }\n }\n\n if (lc < 3) ans = false;\n\n return;\n }\n\n dfs(0,0);\n\n writeln(ans ? \"Yes\" : \"No\");\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n auto par=new int[](n);\n par[0]=-1;\n foreach(int i; 1..n){\n int p; rd(p);\n par[i]=(p-1);\n }\n\n auto leaf=new bool[](n);\n foreach(i; 0..n){\n auto c=count(par, i);\n if(c==0) leaf[i]=true;\n }\n foreach(i; 0..n)if(leaf[i]==false){\n int c=0;\n foreach(j; 0..n){\n if(par[j]==i && leaf[j]) c++;\n }\n if(c<3){writeln(\"No\"); return;}\n }\n writeln(\"Yes\");\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x){\n e=l[i].to!(typeof(e));\n }\n}\nvoid wr(T...)(T x){\n import std.stdio;\n foreach(e; x) write(e, \" \");\n writeln();\n}"}], "negative_code": [{"source_code": "void main() {\n\tauto N = ri;\n\tint[] arr;\n\tforeach(i; 0..N-1) arr ~= ri;\n\tbool[ulong] m;\n\tarr.enumerate.filter!(i => i.value == 1).map!(i => i.index).array.each!(i => m[i] = true);\n\tarr.enumerate.filter!(i => i.value != 1).each!(i => m[i.value-1] = false);\n\tif(m.values.count!(i => i) == 3) writeln(\"Yes\");\n\telse writeln(\"No\");\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}\n"}, {"source_code": "void main() {\n\tauto N = ri;\n\tint[][] tree = new int[][](N+3, 0);\n\t//foreach(i; 2..N+2) tree[i] = [];\n\tforeach(i; 2..N+1) {\n\t\tauto p = ri;\n\t\ttree[p] ~= i;\n\t}\n\tulong k;\n\tint[][] que;\n\tque = [[],[]];\n\tque[0] ~= 1;\n\tbool flag = true;\n\twhile(que[k%2] != []) {\n\t\tauto p = que[k%2].front;\n\t\tque[k%2].popFront;\n\t\tulong cnt;\n\t\tforeach(i; tree[p]) {\n\t\t\tque[(k+1)%2] ~= i;\n\t\t\tdebug writefln(\"%s %s %s\", tree[i], [], tree[i] == []);\n\t\t\tif(tree[i] == []) cnt++;\n\t\t}\n\t\tif(cnt != 0 && cnt < 3) flag = false;\n\t\tk++;\n\t}\n\twriteln(flag ? \"Yes\" : \"No\");\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}\n"}], "src_uid": "69edc72ec29d4dd56751b281085c3591"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10^^9;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const A = readInt();\n const B = readInt();\n const S = readToken();\n \n auto lcp = new int[][](N + 1, N + 1);\n foreach_reverse (i; 0 .. N) foreach_reverse (j; 0 .. N) {\n lcp[i][j] = (S[i] == S[j]) ? (1 + lcp[i + 1][j + 1]) : 0;\n }\n foreach (i; 0 .. N + 1) {\n foreach (j; 0 .. N) {\n chmax(lcp[i][j + 1], lcp[i][j]);\n }\n }\n \n auto dp = new int[N + 1];\n dp[] = INF;\n dp[0] = 0;\n foreach (i; 0 .. N) {\n chmin(dp[i + 1], dp[i] + A);\n foreach (j; i + 1 .. N + 1) {\n // lcp[i][k] >= j - i, 0 <= k <= i - (j - i)\n if (0 <= i - (j - i) && lcp[i][i - (j - i)] >= j - i) {\n chmin(dp[j], dp[i] + B);\n }\n }\n }\n writeln(dp[N]);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "int[] make_z(in char[] s) {\n import std.algorithm : max;\n import std.conv : to;\n\n int n = s.length.to!(int);\n auto z = new int[](n);\n for (int i = 1, p = 0; i < n; i++) {\n if (i + z[i - p] < p + z[p]) {\n z[i] = z[i - p];\n } else {\n auto j = max(0, p + z[p] - i);\n while (i + j < n && s[j] == s[i + j]) {\n j++;\n }\n z[i] = j;\n p = i;\n }\n }\n z[0] = n;\n return z;\n}\n\nvoid chmin(ref int l, int r) {\n if (l > r) {\n l = r;\n }\n}\n\nvoid main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, a, b;\n rd(n, a, b);\n auto s = readln.chomp.to!(char[]);\n\n auto z = new int[][](n, n);\n foreach (i; 0 .. n) {\n z[i][i .. $] = make_z(s[i .. $]);\n }\n auto dp = new int[](n + 1);\n fill(dp, 5000 * 5000);\n dp[0] = 0;\n foreach (i; 0 .. n) {\n chmin(dp[i + 1], dp[i] + a);\n foreach (j; 0 .. i) {\n if (z[j][i] > 0) {\n chmin(dp[i + min(z[j][i], i - j)], dp[i] + b);\n }\n }\n }\n writeln(dp[n]);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "09da15ac242c9a599221e205d1b92fa9"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, p, k;\n readf(\"%s %s %s\", &n, &p, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n arr.sort();\n \n auto cost = new int[] (n+1);\n cost[0] = 0;\n foreach (i, e; arr.enumerate(1)) {\n if (i < k) { cost[i.to!int] = cost[i.to!int - 1] + e; }\n else { cost[i.to!int] = cost[i.to!int - k] + e; }\n }\n \n int ans = 0;\n foreach (i, e; cost) {\n if (e <= p) { ans = i.to!int; }\n }\n \n ans.writeln;\n }\n}", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable t = r.next!uint;\n auto res = uninitializedArray!(int[]) (t);\n foreach (tid; 0 .. t) {\n immutable n = r.next!uint;\n auto p = r.next!uint;\n immutable k = r.next!uint;\n auto a = r.nextA!uint (n);\n sort (a);\n /*\n auto s = new long[n+1];\n s[0] = 0;\n foreach (i; 1 .. n + 1) s[i] = s[i-1] + a[i-1];\n */\n auto b = new long[n+1];\n b[0] = 0;\n foreach (i; 1 .. n + 1) {\n immutable val = a[i-1];\n b[i] = b[i-1] + val;\n int j = (i - (k - 1));\n if (j >= 1) {\n b[i] = min (b[i], b[j-1] + val);\n }\n }\n int ans;\n foreach_reverse (i; 1 .. n + 1) {\n if (b[i] <= p) {\n ans = i;\n break;\n }\n }\n res[tid] = ans;\n }\n writefln (\"%(%s\\n%)\", res);\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tforeach(_; 0 .. rint){\n\t\tint n = rint;\n\t\tlong p = rlong;\n\t\tint k = rint;\n\t\tlong[] as = rlong(n);\n\t\tas.sort();\n\t\tlog(\"---\");\n\t\tlog(\"n:\", n, \"p:\", p, \"k:\", k, \"as:\", as);\n\n\n\t\tint ans = 0;\n\t\tint tmp1 = 0;\n\t\tforeach(r; 0 .. k){\n\t\t\tint tmp2 = tmp1;\n\t\t\tfor(int m = 0; r + k * m <= n; m ++){\n\t\t\t\tlog(\"r:\", r, \"m:\", m, \"x:\", r + k * m, \"tmp1:\", tmp1, \"tmp2:\", tmp2, \"f:\", tmp2 <= p);\n\t\t\t\tif(tmp2 <= p) ans.chmax(r + k * m);\n\t\t\t\telse break;\n\t\t\t\tif(r + k * m + k - 1 < n) tmp2 += as[r + k * m + k - 1];\n\t\t\t\telse break;\n\t\t\t}\n\t\t\ttmp1 += as[r];\n\t\t}\n\t\tans.writeln;\n\t}\n}\n"}], "negative_code": [], "src_uid": "b9bafdc49709b4fc4b5fe786d5aa99a3"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\nif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\n\twhile(input(&n,&k))\n\t{\n\t\treadln;\n\t\tauto t=arread!int;\n\t\tint r;\n\t\tforeach(i;t)if(i<0)r++;\n\t\tdebug writeln(r);\n\t\tif(r>k){writeln(-1);return;}\n\t\tint ans;\n\t\tint[] pos;\n\t\tauto q=rbt!(true,int);\n\t\tforeach(i,p;t)\n\t\t{\n\t\t\tif(p<0)\n\t\t\t{\n\t\t\t\tk--;\n\t\t\t\tif(pos.length>0 && i-pos[$-1]>1){ q.insert(i-pos[$-1]-1);ans+=2;}\n\t\t\t\telse if(pos.length==0) ans+=2;\n\t\t\t\tpos~=i;\n\t\t\t}\n\t\t}\n\t\twhile(!q.empty && k>=q.front)\n\t\t{\n\t\t\tk-=q.front;\n\t\t\tq.removeFront;\n\t\t\tans-=2;\n\t\t}\n\t\tif(pos.length>0 && k>=n-pos[$-1]-1)ans--;\n\t\twriteln(ans);\n\t}\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nint n, k;\nbool[200_000] _winter;\n\nvoid main() {\n while (read(&n, &k)) {\n auto winter = _winter[0 .. n];\n int winterLength = 0;\n bool cur = false;\n int result = 0;\n foreach (ref x; winter) {\n int y;\n read(&y);\n x = y < 0;\n if (x) {\n if (!cur) {\n result++;\n cur = true;\n }\n winterLength++;\n } else if (cur) {\n result++;\n cur = false;\n }\n }\n if (winterLength > k)\n writeln(\"-1\");\n else {\n debug writeln(\"pre: \", result);\n\n int check(uint[ ] intervals, int cap) {\n intervals.sort();\n debug writeln(intervals);\n int result2 = result;\n debug writeln(cap);\n while (!intervals.empty && cap >= intervals[0]) {\n cap -= intervals[0];\n result2 -= 2;\n intervals.popFront();\n }\n debug writeln(\"< \", result2);\n assert(result2 >= 0);\n return result2;\n }\n\n auto intervals = group(winter).filter!`!a[0]`.map!`a[1]`.array();\n int result2 = int.max;\n if (!intervals.empty) {\n if (!winter[0])\n intervals.popFront();\n int cap = k - winterLength;\n if (!winter[$ - 1] && !intervals.empty) {\n if (cap >= intervals[$ - 1])\n result2 = check(intervals[0 .. $ - 1].dup, cap - intervals[$ - 1]) - 1;\n result2 = min(result2, check(intervals[0 .. $ - 1], cap));\n } else\n result2 = check(intervals, cap);\n } else\n result2 = 1;\n writeln(result2 >= 0 && result2 != int.max? result2 : -1);\n debug writeln();\n }\n }\n}\n"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\nif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\n\twhile(input(&n,&k))\n\t{\n\t\treadln;\n\t\tauto t=arread!int;\n\t\tauto r=t.count!\"a<0\";\n\t\tdebug writeln(r);\n\t\tif(r>k){writeln(-1);return;}\n\t\tint ans;\n\t\tint[] pos;\n\t\tauto q=rbt!(true,int);\n\t\tforeach(i,p;t)\n\t\t{\n\t\t\tif(p<0)\n\t\t\t{\n\t\t\t\tk--;\n\t\t\t\tif(pos.length>0 && i-pos[$-1]>1){ q.insert(i-pos[$-1]-1);ans+=2;}\n\t\t\t\telse if(pos.length==0) ans+=2;\n\t\t\t\tpos~=i;\n\t\t\t}\n\t\t}\n\t\twhile(!q.empty && k>=q.front)\n\t\t{\n\t\t\tk-=q.front;\n\t\t\tq.removeFront;\n\t\t\tans-=2;\n\t\t}\n\t\tif(pos.length>0 && k>=n-pos[$-1]-1)ans--;\n\t\twriteln(ans);\n\t}\n\tdebug system(\"pause\");\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nint n, k;\nbool[200_000] _winter;\n\nvoid main() {\n while (read(&n, &k)) {\n auto winter = _winter[0 .. n];\n int winterLength = 0;\n bool cur = false;\n int result = 0;\n foreach (ref x; winter) {\n int y;\n read(&y);\n x = y < 0;\n if (x) {\n if (!cur) {\n result++;\n cur = true;\n }\n winterLength++;\n } else if (cur) {\n result++;\n cur = false;\n }\n }\n if (winterLength > k)\n writeln(\"-1\");\n else {\n debug writeln(\"pre: \", result);\n\n int check(uint[ ] intervals, int cap) {\n intervals.sort();\n debug writeln(intervals);\n int result2 = result;\n debug writeln(cap);\n while (!intervals.empty && cap >= intervals[0]) {\n cap -= intervals[0];\n result2 -= 2;\n intervals.popFront();\n }\n debug writeln(\"< \", result2);\n assert(result2 >= 0);\n return result2;\n }\n\n auto intervals = group(winter).filter!`!a[0]`.map!`a[1]`.array();\n int result2 = int.max;\n if (!intervals.empty) {\n if (!winter[0])\n intervals.popFront();\n int cap = k - winterLength;\n if (!winter[$ - 1] && !intervals.empty) {\n if (cap >= intervals[$ - 1])\n result2 = check(intervals[0 .. $ - 1].dup, cap - intervals[$ - 1]) - 1;\n result2 = min(result2, check(intervals[0 .. $ - 1], cap));\n } else\n result2 = check(intervals, cap);\n }\n writeln(result2 >= 0 && result2 != int.max? result2 : -1);\n }\n }\n}\n"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\nif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\n\twhile(input(&n,&k))\n\t{\n\t\treadln;\n\t\tauto t=arread!int;\n\t\tauto r=fold!\"a+(b<0)\"(t);\n\t\tif(r>k){writeln(-1);return;}\n\t\tint ans;\n\t\tint[] pos;\n\t\tauto q=rbt!(true,int);\n\t\tforeach(i,p;t)\n\t\t{\n\t\t\tif(p<0)\n\t\t\t{\n\t\t\t\tk--;\n\t\t\t\tif(pos.length>0 && i-pos[$-1]>1){ q.insert(i-pos[$-1]-1);ans+=2;}\n\t\t\t\telse if(pos.length==0) ans+=2;\n\t\t\t\tpos~=i;\n\t\t\t}\n\t\t}\n\t\twhile(!q.empty && k>=q.front)\n\t\t{\n\t\t\tk-=q.front;\n\t\t\tq.removeFront;\n\t\t\tans-=2;\n\t\t}\n\t\tif(pos[$-1]<n-1 && k>=n-pos[$-1]-1)ans--;\n\t\twriteln(ans);\n\t}\n\tdebug readln;\n}\n"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\nif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\n\twhile(input(&n,&k))\n\t{\n\t\treadln;\n\t\tauto t=arread!int;\n\t\tint r;\n\t\tforeach(i;t)if(i<0)r++;\n\t\tdebug writeln(r);\n\t\tif(r>k){writeln(-1);return;}\n\t\tint ans;\n\t\tint[] pos;\n\t\tauto q=rbt!(true,int);\n\t\tforeach(i,p;t)\n\t\t{\n\t\t\tif(p<0)\n\t\t\t{\n\t\t\t\tk--;\n\t\t\t\tif(pos.length>0 && i-pos[$-1]>1){ q.insert(i-pos[$-1]-1);ans+=2;}\n\t\t\t\telse if(pos.length==0) ans+=2;\n\t\t\t\tpos~=i;\n\t\t\t}\n\t\t}\n\t\twhile(!q.empty && k>=q.front)\n\t\t{\n\t\t\tk-=q.front;\n\t\t\tq.removeFront;\n\t\t\tans-=2;\n\t\t}\n\t\tif(pos[$-1]<n-1 && k>=n-pos[$-1]-1)ans--;\n\t\twriteln(ans);\n\t}\n\tdebug readln;\n}\n"}], "src_uid": "18458f6ab66db560a51887c944f26f0f"} {"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint p, q;\n\tint c = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d %d\", &p, &q);\n\t\tif (q - p >= 2) c++;\n\t}\n\tprintf(\"%d\", c);\n\treturn 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n int n; readf(\" %s\", &n);\n int ans = 0;\n for (int i = 0; i < n; i++) {\n int p, q; readf(\" %s %s\", &p, &q);\n if (p + 2 <= q) {\n ans++;\n }\n }\n writeln(ans);\n}\n"}], "negative_code": [], "src_uid": "2a6c457012f7ceb589b3dea6b889f7cb"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\nimport std.bigint;\nimport std.traits;\n\nvoid main()\n{\n\tauto n = readln().chomp().to!int();\n\tauto enemy = new long[][](n, 2);\n\tlong score, kenemy;\n\n\tforeach (ref e; enemy) {\n\t\te = readln().split().map!(to!long)().array();\n\t}\n\tenemy.sort!(\"a[1] < b[1]\");\n\n\tauto t = readln().chomp().to!int();\n\tauto mag = readln().split().map!(to!long)().array();\n\tmag ~= 1e18.to!long();\n\tauto m = 1;\n\tint cur;\n\n\tforeach (ref e; enemy) {\n\t\twhile (e[0]) {\n\t\t\tif (kenemy + e[0] <= mag[cur]) {\n\t\t\t\tscore += e[0] * e[1] * m;\n\t\t\t\tkenemy += e[0];\n\t\t\t\te[0] = 0;\n\t\t\t} else {\n\t\t\t\tscore += (mag[cur] - kenemy) * e[1] * m;\n\t\t\t\te[0] -= mag[cur] - kenemy;\n\t\t\t\tkenemy += mag[cur] - kenemy;\n\t\t\t\tcur++;\n\t\t\t\tm++;\n\t\t\t}\n\t\t}\n\t}\n\n\tscore.writeln();\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\nimport std.bigint;\nimport std.traits;\n\nvoid main()\n{\n\tauto n = readln().chomp().to!int();\n\tauto enemy = new long[][](n, 2);\n\tlong score, kenemy;\n\n\tforeach (ref e; enemy) {\n\t\te = readln().split().map!(to!long)().array();\n\t}\n\tenemy.sort!(\"a[1] < b[1]\");\n\n\tauto t = readln().chomp().to!int();\n\tauto mag = readln().split().map!(to!long)().array();\n\tmag ~= 1e18.to!long();\n\tauto m = 1;\n\tint cur;\n\n\tforeach (ref e; enemy) {\n\t\twhile (e[0]) {\n\t\t\tif (kenemy + e[0] <= mag[cur]) {\n\t\t\t\tscore += e[0] * e[1] * m;\n\t\t\t\tkenemy += e[0];\n\t\t\t\te[0] = 0;\n\t\t\t} else {\n\t\t\t\tscore += (mag[cur] - kenemy) * e[1] * m;\n\t\t\t\te[0] -= mag[cur] - kenemy;\n\t\t\t\tkenemy += mag[cur] - kenemy;\n\t\t\t\tcur++;\n\t\t\t\tm++;\n\t\t\t}\n\t\t}\n\t}\n\n\tscore.writeln();\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\nimport std.bigint;\nimport std.traits;\n\nvoid main()\n{\n\tauto n = readln().chomp().to!int();\n\tauto enemy = new int[][](n, 2);\n\tlong score, kenemy;\n\n\tforeach (ref e; enemy) {\n\t\te = readln().split().map!(to!int)().array();\n\t}\n\tenemy.sort!(\"a[1] < b[1]\");\n\n\tauto t = readln().chomp().to!int();\n\tauto mag = readln().split().map!(to!long)().array();\n\tmag ~= 1e18.to!long();\n\tauto m = 1;\n\tint cur;\n\n\tforeach (ref e; enemy) {\n\t\twhile (e[0]) {\n\t\t\tif (kenemy + e[0] <= mag[cur]) {\n\t\t\t\tscore += e[0] * e[1] * m;\n\t\t\t\tkenemy += e[0];\n\t\t\t\te[0] = 0;\n\t\t\t} else {\n\t\t\t\tscore += (mag[cur] - kenemy) * e[1] * m;\n\t\t\t\te[0] -= mag[cur] - kenemy;\n\t\t\t\tkenemy += mag[cur] - kenemy;\n\t\t\t\tcur++;\n\t\t\t\tm++;\n\t\t\t}\n\t\t}\n\t}\n\n\tscore.writeln();\n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\nimport std.bigint;\nimport std.traits;\n\nvoid main()\n{\n\tauto n = readln().chomp().to!int();\n\tauto enemy = new int[][](n, 2);\n\tlong score, kenemy;\n\n\tforeach (ref e; enemy) {\n\t\te = readln().split().map!(to!int)().array();\n\t}\n\tauto t = readln().chomp().to!int();\n\tauto mag = readln().split().map!(to!long)().array();\n\tmag ~= 1e18.to!long();\n\tauto m = 1;\n\tint cur;\n\n\tforeach (ref e; enemy) {\n\t\twhile (e[0]) {\n\t\t\tif (kenemy + e[0] <= mag[cur]) {\n\t\t\t\tscore += e[0] * e[1] * m;\n\t\t\t\tkenemy += e[0];\n\t\t\t\te[0] = 0;\n\t\t\t} else {\n\t\t\t\tscore += (mag[cur] - kenemy) * e[1] * m;\n\t\t\t\te[0] -= mag[cur] - kenemy;\n\t\t\t\tkenemy += mag[cur] - kenemy;\n\t\t\t\tcur++;\n\t\t\t\tm++;\n\t\t\t}\n\t\t}\n\t}\n\n\tscore.writeln();\n}"}], "src_uid": "bfd7aabf195321249db8760c3cb6998d"} {"source_code": "import std.algorithm,std.numeric,std.stdio;\nvoid main(){\n\treadln;long m,d,w;\n\twhile(readf!(\" %s %s %s\")(m,d,w)>0){\n\t\tauto e=d-1,s=w/gcd(e,w),a=min(d,m),p=a/s;\n\t\twriteln(e?(a*2-p*s-s)*p/2:0);\n}}\n", "positive_code": [{"source_code": "import std.algorithm, std.numeric, std.stdio;\nvoid main () {\n\treadln;\n\tlong m, d, w;\n\twhile (readf !(\" %s %s %s\") (m, d, w) > 0) {\n\t\tauto e = d - 1, s = w / gcd (e, w), a = min (d, m), p = a / s;\n\t\twriteln (e ? (a * 2 - (p + 1) * s) * p / 2 : 0);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tlong m, d, w;\n\t\treadf !(\" %s %s %s\") (m, d, w);\n\t\tauto rem = (m * d) % w;\n\t\tauto dist = d - 1;\n\t\tif (dist == 0)\n\t\t{\n\t\t\twriteln (0);\n\t\t\tcontinue;\n\t\t}\n\t\tauto g = gcd (dist, w);\n\t\tauto len = dist / g * w;\n\t\tauto step = len / dist;\n\t\tlong res = 0;\n\t\tlong first = min (d, m) - step;\n\t\tlong next = min (d, m) - step * 2;\n\t\tdebug {writeln (first, \" \", next);}\n\t\tif (first <= 0)\n\t\t{\n\t\t\tres = 0;\n\t\t}\n\t\telse if (next <= 0)\n\t\t{\n\t\t\tres = first;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong num = first / (first - next);\n\t\t\tlong last = first - step * num;\n\t\t\tres = (num + 1) * (first + last) / 2;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm,std.numeric,std.stdio;\nvoid main(){\n\treadln;long m,d,w;\n\twhile(readf!(\" %s %s %s\")(m,d,w)>0){\n\t\tauto e=d-1,s=w/gcd(e,w),a=min(d,m),p=a/s;\n\t\twriteln(e?(a*2-p*s-p)*p/2:0);\n}}\n"}], "src_uid": "875851f43c7a6e09cd3d20f2a6980d40"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!int;\n\t\twhile (s >= 10)\n\t\t{\n\t\t\tauto r = s % 10;\n\t\t\tans[ti] += s - r;\n\t\t\ts /= 10;\n\t\t\ts += r;\n\t\t}\n\t\tans[ti] += s;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n ulong n;\n readf!\"%d\\n\"(n);\n ulong s = 0;\n\n while (n > 0) {\n if (n < 10) {\n s += n;\n break;\n } else {\n auto a = n - n % 10;\n s += a;\n n = a / 10 + n % 10;\n }\n }\n\n writeln(s);\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.algorithm.mutation;\nimport std.container.array;\n\nstring[] tokens;\n\nstring readToken()\n{\n while (tokens.empty)\n {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nvoid main()\n{\n int T = readInt;\n while (T--)\n {\n int n = readInt;\n int res = 0;\n while (n >= 10)\n {\n res += n - n % 10;\n n = n % 10 + n / 10;\n }\n writeln(res + n);\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nvoid main()\n{\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto s = next!long;\n auto res = long(0);\n while(s >= 10)\n {\n res += (s / 10) * 10;\n s += (s / 10) - (s / 10) * 10;\n }\n res += s;\n writeln(res);\n }\n}\n"}], "negative_code": [], "src_uid": "0beecbd62aa072a2f3aab542eeb56373"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new char[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\t\tauto x = RD!int;\n\t\tauto n = s.length;\n\n\t\tans[ti].length = s.length;\n\t\tans[ti][] = '1';\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tif (s[i] == '0')\n\t\t\t{\n\t\t\t\tif (i >= x)\n\t\t\t\t{\n\t\t\t\t\tans[ti][i-x] = '0';\n\t\t\t\t}\n\t\t\t\tif (i < n-x)\n\t\t\t\t{\n\t\t\t\t\tans[ti][i+x] = '0';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tif (s[i] == '1')\n\t\t\t{\n\t\t\t\tbool ok;\n\t\t\t\tif (i >= x)\n\t\t\t\t{\n\t\t\t\t\tok |= ans[ti][i-x] == '1';\n\t\t\t\t}\n\t\t\t\tif (i < n-x)\n\t\t\t\t{\n\t\t\t\t\tok |= ans[ti][i+x] == '1';\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tans[ti].length = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tforeach (test; 0..readln.strip.to !(int))\n\t{\n\t\tauto s = readln.strip;\n\t\tauto x = readln.strip.to !(int);\n\t\tauto n = s.length.to !(int);\n\t\tauto w = new char [n];\n\t\tw[] = '1';\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '0')\n\t\t\t{\n\t\t\t\tif (i - x >= 0)\n\t\t\t\t{\n\t\t\t\t\tw[i - x] = '0';\n\t\t\t\t}\n\t\t\t\tif (i + x < n)\n\t\t\t\t{\n\t\t\t\t\tw[i + x] = '0';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '1')\n\t\t\t{\n\t\t\t\tif (!(i - x >= 0 && w[i - x] == '1') &&\n\t\t\t\t !(i + x < n && w[i + x] == '1'))\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (ok ? w : \"-1\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "02854d98266e5b74bf105ba30ea332df"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto arr = [0] ~ readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n arr.sort();\n \n auto dp = new int[][] (n+1, k+1);\n foreach (ref rw; dp) rw.fill(0);\n \n foreach (i; 1 .. n+1) {\n int mnval = arr[i] - 5;\n auto bigger = arr[1 .. $].assumeSorted.upperBound(mnval - 1);\n \n int prev = n - (bigger.length.to!int);\n \n foreach (j; 1 .. k+1) {\n dp[i][j] = max(dp[i-1][j], dp[prev][j-1] + i - prev);\n }\n }\n \n debug { dp.each!writeln; }\n \n dp[n][k].writeln;\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto arr = [0] ~ readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n arr.sort();\n \n auto dp = new int[][] (n+1, k+1);\n foreach (ref rw; dp) rw.fill(0);\n \n int prev = 0;\n foreach (i; 1 .. n+1) {\n int mnval = arr[i] - 5;\n while (arr[prev+1] < mnval) { prev += 1; }\n \n foreach (j; 1 .. k+1) {\n dp[i][j] = max(dp[i-1][j], dp[prev][j-1] + i - prev);\n }\n }\n \n debug { dp.each!writeln; }\n \n dp[n][k].writeln;\n}"}], "negative_code": [], "src_uid": "0135818c10fae9fc9efcc724fa43181f"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() { \n int t; \n readf(\" %s\", &t);\n while(t-- > 0) {\n int n, x, a, b;\n readf(\" %s %s %s %s\", &n, &x, &a, &b);\n if(a > b) swap(a, b);\n int d = min(x, a - 1);\n a -= d;\n x -= d;\n d = min(n - b, x);\n b += d;\n x -= d;\n writef(\"%s\\n\", b - a);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.math;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tint b=0;\n\t\tint c=0;\n\t\tint d=0;\n\t\tint e=0;\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\treadf(\" %d\", &d);\n\t\treadf(\" %d\", &e);\n\t\tif (abs(d-e)+c>=b)\n\t\t{\n\t\t\twriteln(b-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(abs(d-e)+c);\n\t\t}\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto x = RD!int;\n\t\tauto a = RD!int-1;\n\t\tauto b = RD!int-1;\n\t\tauto aa = min(a, b);\n\t\tauto bb = max(a, b);\n\t\tauto cnt1 = min(aa, x);\n\t\tx -= cnt1;\n\t\taa -= cnt1;\n\t\tauto cnt2 = min(n-bb-1, x);\n\t\tbb += cnt2;\n\t\tans[i] = bb - aa;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.math;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tint b=0;\n\t\tint c=0;\n\t\tint d=0;\n\t\tint e=0;\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\treadf(\" %d\", &d);\n\t\treadf(\" %d\", &e);\n\t\tif (abs(d-e)+c>=b)\n\t\t{\n\t\t\twriteln(b-2);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(abs(d-e)+c);\n\t\t}\n\t}\n\treturn 0;\n}"}], "src_uid": "1fd2619aabf4557093a59da804fd0e7b"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n auto r = () => readln.chomp.to!(dchar[]);\n auto s = r();\n auto t = r();\n \n debug { writeln(s, ' ', t); }\n \n int n = s.length.to!int;\n auto ans = new dchar[] (n);\n auto sl = DList!dchar(s.sort().array[0 .. (n+1) / 2]);\n auto tl = DList!dchar(t.sort().array[(n+1) / 2 .. $]);\n \n debug { sl.each!write; writeln; tl.each!write; writeln; }\n \n int lft = 0, rt = n-1;\n foreach (i; 0 .. n) {\n if (i % 2 == 0) {\n if (i == n-1 || sl.front < tl.back) {\n ans[lft] = sl.front;\n sl.removeFront();\n lft += 1;\n } else {\n ans[rt] = sl.back;\n sl.removeBack();\n rt -= 1;\n }\n } else {\n if (i == n-1 || sl.front < tl.back) {\n ans[lft] = tl.back;\n tl.removeBack();\n lft += 1;\n } else {\n ans[rt] = tl.front;\n tl.removeFront();\n rt -= 1;\n }\n }\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const S = readToken();\n const T = readToken();\n const N = cast(int)(S.length);\n \n auto as = new int[N];\n auto bs = new int[N];\n foreach (i; 0 .. N) {\n as[i] = S[i] - 'a';\n bs[i] = T[i] - 'a';\n }\n as.sort;\n bs.sort;\n int al = 0, ar = (N + 1) / 2;\n int bl = N - N / 2, br = N;\n \n auto cs = new int[N];\n int cl = 0, cr = N;\n for (; ; ) {\n // min\n if (al == ar) {\n break;\n }\n if (bl == br || as[al] < bs[br - 1]) {\n cs[cl++] = as[al++];\n } else {\n cs[--cr] = as[--ar];\n }\n // max\n if (bl == br) {\n break;\n }\n if (al == ar || bs[br - 1] > as[al]) {\n cs[cl++] = bs[--br];\n } else {\n cs[--cr] = bs[bl++];\n }\n }\n \n auto ans = new char[N];\n foreach (i; 0 .. N) {\n ans[i] = cast(char)('a' + cs[i]);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n auto r = () => readln.chomp.to!(dchar[]);\n auto s = r();\n auto t = r();\n \n debug { writeln(s, ' ', t); }\n \n int n = s.length.to!int;\n auto ans = new dchar[] (n);\n auto sl = DList!dchar(s.sort().array[0 .. (n+1) / 2]);\n auto tl = DList!dchar(t.sort().array[(n+1)/2 .. $]);\n \n debug { writeln(sl.back, ' ', tl.front); }\n \n int lft = 0, rt = n-1;\n foreach (i; 0 .. n) {\n if (i % 2 == 0) {\n if (i == n-1 || sl.front < tl.back) {\n ans[lft] = sl.front;\n sl.removeFront();\n lft += 1;\n } else {\n ans[rt] = sl.back;\n sl.removeBack();\n rt -= 1;\n }\n } else {\n if (i == n-1 || sl.front < tl.back) {\n ans[lft] = tl.back;\n tl.removeBack();\n lft += 1;\n } else {\n ans[rt] = tl.front;\n tl.removeFront();\n rt -= 1;\n }\n }\n }\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n auto r = () => readln.chomp.to!(dchar[]);\n auto s = r();\n auto t = r();\n \n debug { writeln(s, ' ', t); }\n \n int n = s.length.to!int;\n auto ans = new dchar[] (n);\n auto sl = DList!dchar(s.sort().array[0 .. (n+1) / 2]);\n auto tl = DList!dchar(t.sort().array[(n+1)/2 .. $]);\n \n debug { writeln(sl.back, ' ', tl.front); }\n \n int lft = 0, rt = n-1;\n foreach (i; 0 .. n) {\n if (i % 2 == 0) {\n if (i == n-1 || sl.front <= tl.back) {\n ans[lft] = sl.front;\n sl.removeFront();\n lft += 1;\n } else {\n ans[rt] = sl.back;\n sl.removeBack();\n rt -= 1;\n }\n } else {\n if (i == n-1 || sl.front <= tl.back) {\n ans[lft] = tl.back;\n tl.removeBack();\n lft += 1;\n } else {\n ans[rt] = tl.front;\n tl.removeFront();\n rt -= 1;\n }\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\nimmutable int MX = 5000;\n\nvoid main()\n{\n auto r = () => readln.chomp.to!(dchar[]);\n auto s = r().sort();\n auto t = r().sort();\n \n debug { writeln(s, ' ', t); }\n \n string ans;\n int sidx = 0, tidx = t.length.to!int - 1;\n foreach (i; 0 .. s.length) {\n if (i % 2 == 0) {\n ans ~= s[sidx];\n sidx += 1;\n } else {\n ans ~= t[tidx];\n tidx -= 1;\n }\n }\n \n ans.writeln;\n}"}], "src_uid": "bc3d0d902ef457560e444ec0128f0688"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\r\nimport std.math, std.random, std.bigint, std.datetime, std.format;\r\nbool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }\r\nvoid main(string[] args){ if(args.canFind(\"-debug\")) DEBUG = 1;\r\nif(args.canFind(\"-gen\")) gen; else if(args.canFind(\"-jury\")) jury; else solve; }\r\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); }\r\nvoid print(T, A ...)(T t, A a){ std.stdio.write(t, \" \"), print(a); }\r\nstring unsplit(T)(T xs, string d=\" \"){ return xs.array.to!(string[]).join(d); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\r\nT mini(T)(ref T x, T y){ if(x > y) x = y; return x; } T maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }\r\nT mid(T)(T l, T r, bool delegate(T) f){ T m=(l+r)/2; (f(m)?l:r)=m; return f(l)?f(r-1)?r:mid(l,r,f):l; }\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\nvoid gen(){ // \u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\r\n\tint t = uniform(1, 5);\r\n\tt.print;\r\n\tforeach(_; 0 .. t){\r\n\t\tint n = uniform(1, 5), m = uniform(1, 5);\r\n\t\tprint(n, m);\r\n\t\tforeach(j; 0 .. m){\r\n\t\t\tint[] as;\r\n\t\t\tforeach(i; 0 .. n) if(uniform(0, 2) == 0) as ~= i;\r\n\t\t\tif(as.length == 0) as ~= uniform(0, n);\r\n\t\t\tas.randomShuffle;\r\n\t\t\tprint(as.length, as.map!(a => a + 1).unsplit);\r\n\t\t}\r\n\t}\r\n}\r\nvoid jury(){ // \u611a\u76f4\u89e3\r\n\tint q = scan!int;\r\n\tint[] ns, ms;\r\n\tint[][][] ar = new int[][][](q);\r\n\tforeach(t; 0 .. q){\r\n\t\tint n = scan!int, m = scan!int;\r\n\t\tns ~= n, ms ~= m;\r\n\t\tforeach(j; 0 .. m){\r\n\t\t\tint k = scan!int;\r\n\t\t\tint[] as = scan!int(k).map!(x => x - 1).array;\r\n\t\t\tar[t] ~= as;\r\n\t\t}\r\n\t}\r\n\tforeach(t; 0 .. q){\r\n\t\tstring yesno = scan;\r\n\t\tif(yesno == \"NO\") \"NO\".print;\r\n\t\telse{\r\n\t\t\tint[] ans = scan!int(ms[t]).map!(a => a - 1).array;\r\n\t\t\tint[] cnt = new int[](ns[t]);\r\n\t\t\tforeach(j, an; ans){\r\n\t\t\t\tif( ! ar[t][j].canFind(an)) print(\"not available\", j + 1);\r\n\t\t\t\tcnt[an] += 1;\r\n\t\t\t}\r\n\t\t\tforeach(i; 0 .. ns[t]) if(cnt[i] > (ms[t] + 1) / 2) print(\"too much\", i + 1);\r\n\t\t\t\"YES\".print;\r\n\t\t\tans.map!(a => a + 1).unsplit.print;\r\n\t\t}\r\n\t}\r\n}\r\nvoid solve(){ // \u63d0\u51fa\u89e3\r\n\tA: foreach(_; 0 .. scan!int){\r\n\t\tint n = scan!int, m = scan!int;\r\n\t\tint ceilm2 = (m + 1) / 2;\r\n\t\tint[][] ass;\r\n\t\tint[][] lones = new int[][](n);\r\n\t\tint[][] others = new int[][](n);\r\n\t\tforeach(j; 0 .. m){\r\n\t\t\tint k = scan!int;\r\n\t\t\tint[] as = scan!int(k).map!(x => x - 1).array;\r\n\t\t\tif(as.length == 1) lones[as[0]] ~= j;\r\n\t\t\telse foreach(a; as) others[a] ~= j;\r\n\t\t\tass ~= as;\r\n\t\t}\r\n\t\tlog(\"ass:\", ass);\r\n\t\tlog(\"lones:\", lones);\r\n\t\tlog(\"others:\", others);\r\n\r\n\t\tforeach(i; 0 .. n){\r\n\t\t\tif(lones[i].length > ceilm2){\r\n\t\t\t\t\"NO\".print;\r\n\t\t\t\tcontinue A;\r\n\t\t\t}\r\n\t\t}\r\n\t\tint[][] us = new int[][](n);\r\n\t\tint[] ans = new int[](m);\r\n\t\tans.fill(-1);\r\n\r\n\t\tint foundi = -1;\r\n\t\tB: foreach(i; 0 .. n){\r\n\t\t\tif(lones[i].length + others[i].length >= ceilm2){\r\n\t\t\t\t// found\r\n\t\t\t\tfoundi = i;\r\n\t\t\t\tforeach(j; lones[i]) us[i] ~= j, ans[j] = i;\r\n\t\t\t\tforeach(j; others[i]){\r\n\t\t\t\t\tif(us[i].length == ceilm2) break;\r\n\t\t\t\t\tus[i] ~= j, ans[j] = i;\r\n\t\t\t\t}\r\n\t\t\t\tlog(\"i:\", i, \"found\", \"us:\", us, \"ans:\", ans);\r\n\t\t\t\tbreak B;\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach(j; 0 .. m){\r\n\t\t\tif(ans[j] >= 0) continue;\r\n\t\t\tif(ass[j][0] == foundi) ans[j] = ass[j][1];\r\n\t\t\telse ans[j] = ass[j][0];\r\n\t\t}\r\n\r\n\t\t\"YES\".print;\r\n\t\tans.map!(a => a + 1).array.unsplit.print;\r\n\r\n\t}\r\n}\r\n/*\r\n\u4e00\u4eba\u3067\u306e\u51fa\u73fe\u56de\u6570\u304cceil(m/2)\u3092\u8d85\u3048\u3066\u3044\u308b\u4eba\u304c\u3044\u308b\u5834\u5408\r\n\t\u2192NO\r\n\u8907\u6570\u540d\u3067\u306e\u51fa\u73fe\u3092\u542b\u3081\u3066\u306a\u3089ceil(m/2)\u3092\u8d85\u3048\u3066\u3044\u308b\u4eba\u304c\u3044\u308b\u5834\u5408\r\n\t\u2192\u305d\u306e\u4eba\u306b\u3074\u3063\u305f\u308aceil(m/2)\u56de\u3092\u53d6\u3089\u305b\u308c\u3070\u3042\u3068\u306f\u3066\u304d\u3068\u3046\u3067\u3088\u3044\r\n\t\u3000\u305d\u306e\u305f\u3081\u306b\u3001\u4e00\u4eba\u3067\u306e\u51fa\u73fe\u56de\u306f\u305d\u306e\u4eba\u306b\u3068\u3089\u305b\u3001\r\n\t\u3000\u3042\u3068\u306fceil(m/2)\u306b\u306a\u308b\u307e\u3067\u3068\u3089\u305b\u308b\u3002\u305d\u306e\u4eba\u306f\u3082\u3046\u7d42\u308f\u308a\u3002\r\n\u51fa\u73fe\u56de\u6570ceil(m/2)\u3092\u8d85\u3048\u3066\u3044\u308b\u4eba\u304c\u3044\u306a\u3044\u5834\u5408\r\n\t\u2192\u7d76\u5bfe\u5b89\u5168\u306a\u306e\u3067\u3066\u304d\u3068\u3046\u306b\u53d6\u308c\u3070\u3088\u3044\r\n*/", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.container;\r\nimport std.algorithm;\r\n\r\n/*\r\na[i]-a[i-1] = c (mod m)\r\na[1] = s mod m\r\nm > a[i] for i=1,...,n\r\n\r\narbitrary s\r\nm | a[1]-s\r\nm | a[i]-(a[i-1]+c) = a[i]-a[i-1]-c\r\n\r\n1 positive, 1 negative at MAX\r\na = -b => mod is a-(-b).\r\n\r\nif only positive or only negative, m can be arbitrary large\r\nif >1 pos or >1 neg, impossible.\r\n*/\r\n\r\nvoid main() {\r\n int t; readf(\" %d\",&t);\r\n while (t--) {\r\n int n,m; readf(\" %d %d\",&n,&m);\r\n int[][] a = new int[][](m+1);\r\n int[] id = new int[m+1];\r\n foreach (int i, ref e; id) {e=i;}\r\n //writeln(\"id=\",id);\r\n foreach (i; 1..m+1) {\r\n int k_i; readf(\" %d\",&k_i);\r\n foreach(j; 0..k_i) {\r\n int x; readf(\" %d\",&x);\r\n a[i] ~= x;\r\n }\r\n sort((a[i])[0..$]);\r\n }\r\n auto cmp = delegate bool(int i, int j) {\r\n if (a[i].length != a[j].length) return a[i].length < a[j].length;\r\n return a[i]<a[j];\r\n };\r\n sort!(cmp)(id[1..$]);\r\n //writeln(id);\r\n \r\n int[] cnt = new int[n+1];\r\n bool feasible = true;\r\n int[] sol = new int[m+1];\r\n foreach (i; id[1..$]) {\r\n bool flag = false;\r\n int[] b = a[i];\r\n foreach (e; b) {\r\n if (cnt[e]<(m+1)/2) {\r\n flag = true;\r\n sol[i] = e;\r\n ++cnt[e];\r\n break;\r\n }\r\n }\r\n if (!flag) {\r\n feasible = false;\r\n break;\r\n }\r\n }\r\n if (feasible) {\r\n writeln(\"YES\");\r\n foreach (e; sol[1..$]) {\r\n write(e,\" \");\r\n }\r\n writeln();\r\n }\r\n else writeln(\"NO\");\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\r\nimport std.math, std.random, std.bigint, std.datetime, std.format;\r\nbool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }\r\nvoid main(string[] args){ if(args.canFind(\"-debug\")) DEBUG = 1;\r\nif(args.canFind(\"-gen\")) gen; else if(args.canFind(\"-jury\")) jury; else solve; }\r\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); }\r\nvoid print(T, A ...)(T t, A a){ std.stdio.write(t, \" \"), print(a); }\r\nstring unsplit(T)(T xs, string d=\" \"){ return xs.array.to!(string[]).join(d); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\r\nT mini(T)(ref T x, T y){ if(x > y) x = y; return x; } T maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }\r\nT mid(T)(T l, T r, bool delegate(T) f){ T m=(l+r)/2; (f(m)?l:r)=m; return f(l)?f(r-1)?r:mid(l,r,f):l; }\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\nvoid gen(){ // \u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\r\n}\r\nvoid jury(){ // \u611a\u76f4\u89e3\r\n}\r\nvoid solve(){ // \u63d0\u51fa\u89e3\r\n\tA: foreach(_; 0 .. scan!int){\r\n\t\tint n = scan!int, m = scan!int;\r\n\t\tint ceilm2 = (m + 1) / 2;\r\n\t\tint[][] ass;\r\n\t\tint[][] lones = new int[][](n);\r\n\t\tint[][] others = new int[][](n);\r\n\t\tforeach(j; 0 .. m){\r\n\t\t\tint k = scan!int;\r\n\t\t\tint[] as = scan!int(k).map!(x => x - 1).array;\r\n\t\t\tif(as.length == 1) lones[as[0]] ~= j;\r\n\t\t\telse foreach(a; as) others[a] ~= j;\r\n\t\t\tass ~= as;\r\n\t\t}\r\n\t\tlog(\"ass:\", ass);\r\n\t\tlog(\"lones:\", lones);\r\n\t\tlog(\"others:\", others);\r\n\r\n\t\tforeach(i; 0 .. n){\r\n\t\t\tif(lones[i].length > ceilm2){\r\n\t\t\t\t\"NO\".print;\r\n\t\t\t\tcontinue A;\r\n\t\t\t}\r\n\t\t}\r\n\t\tint[][] us = new int[][](n);\r\n\t\tint[] ans = new int[](m);\r\n\t\tans.fill(-1);\r\n\r\n\t\tB: foreach(i; 0 .. n){\r\n\t\t\tif(lones[i].length + others[i].length >= ceilm2){\r\n\t\t\t\t// found\r\n\t\t\t\tforeach(j; lones[i]) us[i] ~= j, ans[j] = i;\r\n\t\t\t\tforeach(j; others[i]){\r\n\t\t\t\t\tif(us[i].length == ceilm2) break;\r\n\t\t\t\t\tus[i] ~= j, ans[j] = i;\r\n\t\t\t\t}\r\n\t\t\t\tforeach(j; 0 .. m){\r\n\t\t\t\t\tif(ans[j] >= 0) continue;\r\n\t\t\t\t\tif(ass[j][0] == i) ans[j] = ass[j][1];\r\n\t\t\t\t\telse ans[j] = ass[j][0];\r\n\t\t\t\t}\r\n\t\t\t\tlog(\"i:\", i, \"found\", \"us:\", us, \"ans:\", ans);\r\n\t\t\t\tbreak B;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t\"YES\".print;\r\n\t\tans.map!(a => a + 1).array.unsplit.print;\r\n\r\n\t}\r\n}\r\n/*\r\n\u4e00\u4eba\u3067\u306e\u51fa\u73fe\u56de\u6570\u304cceil(m/2)\u3092\u8d85\u3048\u3066\u3044\u308b\u4eba\u304c\u3044\u308b\u5834\u5408\r\n\t\u2192NO\r\n\u8907\u6570\u540d\u3067\u306e\u51fa\u73fe\u3092\u542b\u3081\u3066\u306a\u3089ceil(m/2)\u3092\u8d85\u3048\u3066\u3044\u308b\u4eba\u304c\u3044\u308b\u5834\u5408\r\n\t\u2192\u305d\u306e\u4eba\u306b\u3074\u3063\u305f\u308aceil(m/2)\u56de\u3092\u53d6\u3089\u305b\u308c\u3070\u3042\u3068\u306f\u3066\u304d\u3068\u3046\u3067\u3088\u3044\r\n\t\u3000\u305d\u306e\u305f\u3081\u306b\u3001\u4e00\u4eba\u3067\u306e\u51fa\u73fe\u56de\u306f\u305d\u306e\u4eba\u306b\u3068\u3089\u305b\u3001\r\n\t\u3000\u3042\u3068\u306fceil(m/2)\u306b\u306a\u308b\u307e\u3067\u3068\u3089\u305b\u308b\u3002\u305d\u306e\u4eba\u306f\u3082\u3046\u7d42\u308f\u308a\u3002\r\n\u51fa\u73fe\u56de\u6570ceil(m/2)\u3092\u8d85\u3048\u3066\u3044\u308b\u4eba\u304c\u3044\u306a\u3044\u5834\u5408\r\n\t\u2192\u7d76\u5bfe\u5b89\u5168\u306a\u306e\u3067\u3066\u304d\u3068\u3046\u306b\u53d6\u308c\u3070\u3088\u3044\r\n*/"}], "src_uid": "1f6be4f0f7d3f9858b498aae1357c2c3"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int(-1);\n\t\t\n\t\tint mode;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == i)\n\t\t\t{\n\t\t\t\tif (mode == 1)\n\t\t\t\t\tmode = 2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (mode == 0)\n\t\t\t\t\tmode = 1;\n\t\t\t\telse if (mode == 2)\n\t\t\t\t\tmode = 3;\n\t\t\t}\n\t\t}\n\n\t\tif (mode == 0) continue;\n\t\telse if (mode == 1 || mode == 2)\n\t\t\tans[ti] = 1;\n\t\telse\n\t\t\tans[ti] = 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n \nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\tauto p0 = enumerate (p);\n\t\tauto p1 = p0.find !(q{a[0] != a[1]});\n\t\tauto p2 = p1.find !(q{a[0] == a[1]});\n\t\tauto p3 = p2.find !(q{a[0] != a[1]});\n\t\twriteln (p1.empty ? 0 : p3.empty ? 1 : 2);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\tauto s = n.iota.map !(i => i == p[i]).sum;\n\t\twriteln (s == n ? 0 : s == 0 ? 1 : 2);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n \nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\tauto p0 = enumerate (p);\n\t\twriteln (p0);\n\t\tauto p1 = p0.find !(q{a[0] != a[1]});\n\t\tauto p2 = p1.find !(q{a[0] == a[1]});\n\t\tauto p3 = p2.find !(q{a[0] != a[1]});\n\t\twriteln (p1.empty ? 0 : p3.empty ? 1 : 2);\n\t}\n}\n"}], "src_uid": "a98f67141b341152fcf20d803cbd5409"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n Tuple!(int, int, int)[] s;\n \n foreach (i; 0 .. m) {\n int le, r;\n readf(\"%s %s\", &le, &r);\n readln;\n \n --le, --r;\n s ~= tuple(le, r, i+1);\n }\n \n s.sort();\n \n auto rbt = make!(RedBlackTree!(int, \"a < b\", true));\n foreach (e; arr) { rbt.insert(e); }\n\n debug { rbt.writeln; }\n \n int mx = 0;\n int[] ans;\n auto curseg = make!(RedBlackTree!int);\n auto ends = new Tuple!(int, int)[][] (n);\n int sidx = 0;\n foreach (i; 0 .. n) {\n while (sidx < m && s[sidx][0] == i) {\n foreach (j; s[sidx][0] .. s[sidx][1] + 1) {\n rbt.removeKey(arr[j]);\n arr[j] -= 1;\n rbt.insert(arr[j]);\n \n curseg.insert(s[sidx][2]);\n }\n \n ends[s[sidx][1]] ~= tuple(s[sidx][0], s[sidx][2]);\n sidx += 1;\n }\n \n if (rbt.back - arr[i] > mx) {\n ans = [];\n foreach (e; curseg) { ans ~= e; }\n mx = rbt.back - arr[i];\n }\n \n foreach (t; ends[i]) {\n int end = t[0], segid = t[1];\n foreach (j; end .. i+1) {\n rbt.removeKey(arr[j]);\n arr[j] += 1;\n rbt.insert(arr[j]);\n \n curseg.removeKey(segid);\n }\n }\n }\n \n mx.writeln;\n ans.length.writeln;\n ans.writefln!\"%(%s %)\";\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!long).array;\n auto LR = new Tuple!(int, int, int)[](M);\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n LR[i] = tuple(s[0]-1, s[1]-1, i);\n }\n LR.sort();\n\n auto pq = new BinaryHeap!(Array!(Tuple!(int, int, int)), \"a[1] > b[1]\")();\n auto st = new LazySegmentTree!(long, long, min, (a,b)=>a+b, (a,b)=>a+b, (a,b)=>a, 1L<<59, 0L)(N+1);\n st.table[] = 0L;\n\n foreach (i; 0..N) st.update(i, i, A[i]);\n foreach (i; 0..M) st.update(LR[i][0], LR[i][1], -1);\n\n int p = 0;\n long maxv = 0;\n long maxi = 0;\n\n foreach (i; 0..N) {\n while (p < M && LR[p][0] == i) {\n st.update(LR[p][0], LR[p][1], 1);\n pq.insert(LR[p]);\n ++p;\n }\n while (!pq.empty && pq.front[1] < i) {\n st.update(pq.front[0], pq.front[1], -1);\n pq.removeFront;\n }\n\n long tmp = st.query(i, i) - st.query(0, N-1);\n if (tmp >= maxv) {\n maxv = tmp;\n maxi = i;\n }\n }\n\n Tuple!(int, int, int)[] seg;\n foreach (i; 0..M) {\n if (LR[i][1] < maxi || LR[i][0] > maxi) {\n seg ~= LR[i];\n }\n }\n\n maxv.writeln;\n seg.sort!\"a[2] < b[2]\";\n seg.length.writeln;\n foreach (sg; seg) {\n write(sg[2]+1, \" \");\n }\n writeln;\n}\n\n\nclass LazySegmentTree(T, L, alias opTT, alias opTL, alias opLL, alias opPrd, T eT, L eL) {\n T[] table;\n L[] lazy_;\n int n;\n int size;\n\n this(int n) {\n this.n = n;\n size = 1;\n while (size <= n) size <<= 1;\n size <<= 1;\n table = new T[](size);\n lazy_ = new L[](size);\n table[] = eT;\n lazy_[] = eL;\n }\n\n void push(int i, int a, int b) {\n if (lazy_[i] == eL) return;\n table[i] = opTL(table[i], opPrd(lazy_[i], b - a + 1));\n if (i * 2 + 1 < size) {\n lazy_[i*2] = opLL(lazy_[i*2], lazy_[i]);\n lazy_[i*2+1] = opLL(lazy_[i*2+1], lazy_[i]);\n }\n lazy_[i] = eL;\n }\n\n T query(int l, int r) {\n if (l > r) return eT;\n return query(l, r, 1, 0, n-1);\n }\n\n T query(int l, int r, int i, int a, int b) {\n if (b < l || r < a) return eT;\n push(i, a, b);\n if (l <= a && b <= r) {\n return table[i];\n } else {\n return opTT(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));\n }\n }\n\n void update(int l, int r, L val) {\n if (l > r) return;\n update(l, r, 1, 0, n-1, val);\n }\n\n void update(int l, int r, int i, int a, int b, L val) {\n if (b < l || r < a) {\n push(i, a, b);\n } else if (l <= a && b <= r) {\n lazy_[i] = opLL(lazy_[i], val);\n push(i, a, b);\n } else {\n push(i, a, b);\n update(l, r, i*2, a, (a+b)/2, val);\n update(l, r, i*2+1, (a+b)/2+1, b, val);\n table[i] = opTT(table[i*2], table[i*2+1]);\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!long).array;\n auto LR = new Tuple!(int, int, int)[](M);\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n LR[i] = tuple(s[0]-1, s[1]-1, i);\n }\n LR.sort();\n\n auto pq = new BinaryHeap!(Array!(Tuple!(int, int, int)), \"a[1] > b[1]\")();\n auto st = new LazySegmentTree!(long, long, min, (a,b)=>a+b, (a,b)=>a+b, (a,b)=>a, 1L<<59, 0L)(N+1);\n st.table[] = 0L;\n\n foreach (i; 0..N) st.update(i, i, A[i]);\n foreach (i; 0..M) st.update(LR[i][0], LR[i][1], -1);\n\n int p = 0;\n long maxv = 0;\n long maxi = 0;\n\n foreach (i; 0..N) {\n while (p < M && LR[p][0] == i) {\n st.update(LR[p][0], LR[p][1], 1);\n pq.insert(LR[p]);\n ++p;\n }\n while (!pq.empty && pq.front[1] < i) {\n st.update(pq.front[0], pq.front[1], -1);\n pq.removeFront;\n }\n\n long tmp = st.query(i, i) - st.query(0, N-1);\n if (tmp >= maxv) {\n maxv = tmp;\n maxi = i;\n }\n }\n\n Tuple!(int, int, int)[] seg;\n foreach (i; 0..M) {\n if (LR[i][1] < maxi || LR[i][0] > maxi) {\n seg ~= LR[i];\n }\n }\n\n maxv.writeln;\n seg.sort!\"a[2] < b[2]\";\n seg.length.writeln;\n foreach (sg; seg) {\n write(sg[2]+1, \" \");\n }\n writeln;\n}\n\n\nclass LazySegmentTree(T, L, alias opTT, alias opTL, alias opLL, alias opPrd, T eT, L eL) {\n T[] table;\n L[] lazy_;\n int n;\n int size;\n\n this(int n) {\n this.n = n;\n size = 1;\n while (size <= n) size <<= 1;\n size <<= 1;\n table = new T[](size);\n lazy_ = new L[](size);\n table[] = eT;\n lazy_[] = eL;\n }\n\n void push(int i, int a, int b) {\n if (lazy_[i] == eL) return;\n table[i] = opTL(table[i], opPrd(lazy_[i], b - a + 1));\n if (i * 2 + 1 < size) {\n lazy_[i*2] = opLL(lazy_[i*2], lazy_[i]);\n lazy_[i*2+1] = opLL(lazy_[i*2+1], lazy_[i]);\n }\n lazy_[i] = eL;\n }\n\n T query(int l, int r) {\n if (l > r) return eT;\n return query(l, r, 1, 0, n-1);\n }\n\n T query(int l, int r, int i, int a, int b) {\n if (b < l || r < a) return eT;\n push(i, a, b);\n if (l <= a && b <= r) {\n return table[i];\n } else {\n return opTT(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));\n }\n }\n\n void update(int l, int r, L val) {\n if (l > r) return;\n update(l, r, 1, 0, n-1, val);\n }\n\n void update(int l, int r, int i, int a, int b, L val) {\n if (b < l || r < a) {\n push(i, a, b);\n } else if (l <= a && b <= r) {\n lazy_[i] = opLL(lazy_[i], val);\n push(i, a, b);\n } else {\n push(i, a, b);\n update(l, r, i*2, a, (a+b)/2, val);\n update(l, r, i*2+1, (a+b)/2+1, b, val);\n table[i] = opTT(table[i*2], table[i*2+1]);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "2b1595ffe5d233f788c976e155fff26f"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nint sign (int x) {\n if (!x) return 0;\n if (x > 0) return 1;\n return -1;\n}\n\nlong test () {\n auto s = readln.splitter.map!(to!int);\n immutable n = s.front;\n s.popFront;\n immutable x = s.front;\n auto t = readln[0 .. n];\n auto a = new int[n+1];\n foreach (i; 0 .. n) {\n a[i+1] = a[i] + (t[i] == '1' ? -1 : 1);\n }\n debug stderr.writeln (a);\n immutable m = a.back;\n if (m == 0) {\n return (minElement (a) <= x && x <= maxElement (a)) ? -1 : 0;\n }\n long r = 0;\n foreach (i; 0 .. n) {\n int delta = x - a[i];\n if (m > 0) {\n if (delta >= 0 && !(delta % m)) ++r;\n } else {\n if (delta <= 0 && !((-delta) % (-m))) ++r;\n }\n }\n return r;\n}\n\nvoid main() {\n auto nt = readln.strip.to!int;\n foreach (tid; 0 .. nt) {\n writeln (test ());\n }\n}\n\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, x;\n readf(\"%s %s\", &n, &x);\n readln;\n \n auto s = readln.chomp;\n \n auto tot = s.count!(v => v == '0').to!int - s.count!(v => v == '1').to!int;\n \n if (tot == 0) {\n int cur = 0, mx = 0, mn = 0;\n foreach (e; s) {\n if (e == '0') { cur += 1; }\n else { cur -= 1; }\n\n mx = max(mx, cur);\n mn = min(mn, cur);\n }\n \n writeln(mn <= x && x <= mx ? -1 : 0);\n continue;\n }\n \n int ans = 0, cur = 0;\n foreach (e; s) {\n if ((x-cur) % tot == 0 && (x-cur) / tot >= 0) { ans += 1; }\n \n if (e == '0') { cur += 1; }\n else { cur -= 1; }\n }\n \n ans.writeln;\n }\n}"}], "negative_code": [], "src_uid": "389be6455476db86a8a5d9d5343ee35a"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new int[](N);\n auto B = new int[](N);\n auto AB = new Tuple!(int, int)[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!int);\n AB[i] = tuple(s[0], s[1]);\n }\n AB.sort();\n foreach (i; 0..N) {\n A[i] = AB[i][0];\n B[i] = AB[i][1];\n }\n\n auto dp = new int[](N);\n foreach (i; 0..N) {\n auto lb = A.assumeSorted.lowerBound(A[i] - B[i]).length;\n if (lb > 0) dp[i] += dp[lb-1];\n dp[i] += 1;\n }\n\n writeln(N - dp.reduce!max);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Point = Tuple !(int, q{a}, int, q{b});\n\t\tauto p = new Point [n];\n\t\tforeach (ref q; p)\n\t\t{\n\t\t\treadf (\" %s %s\", &q.a, &q.b);\n\t\t}\n\t\tsort (p);\n\t\tp = Point (int.min / 2, 0) ~ p;\n\n\t\tint res = n - 1;\n\t\tauto f = new int [n + 1];\n\t\tf[0] = 1;\n\t\tforeach (i, ref q; p)\n\t\t{\n\t\t\tint lo = 0;\n\t\t\tint hi = i - 1;\n\t\t\twhile (lo < hi)\n\t\t\t{\n\t\t\t\tint me = (lo + hi + 1) >> 1;\n\t\t\t\tif (p[me].a + q.b >= q.a)\n\t\t\t\t{\n\t\t\t\t\thi = me - 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlo = me;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (p[i].a, \": \", p[lo].a);}\n\t\t\tf[i] = f[lo] + (i - lo - 1);\n\t\t\tres = min (res, f[i] + (n - i));\n\t\t}\n\t\tdebug {writeln (f);}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = new int[](N);\n auto B = new int[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!int);\n A[i] = s[0];\n B[i] = s[1];\n }\n\n auto dp = new int[](N);\n foreach (i; 0..N) {\n auto lb = A.assumeSorted.lowerBound(A[i] - B[i]).length;\n if (lb > 0) dp[i] += dp[lb-1];\n dp[i] += 1;\n }\n\n writeln(N - dp.reduce!max);\n}\n"}], "src_uid": "bcd689387c9167c7d0d45d4ca3b0c4c7"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.regex;\nimport std.file;\nvoid main()\n{\n \n string[] inp=split(strip(readln()));\n int n=to!int(inp[0]);\n int p=to!int(inp[1]);\n int q=to!int(inp[2]);\n string s = strip(readln());\n //writeln(n);\n for(int i = 0;i <= n;i++)\n {\n for(int j = 0;j <= n ;j++)\n {\n if(i * p + j * q == n)\n {\n writeln(i + j);\n for(int k = 0;k < i;k++){\n writeln(s[k*p .. (k+1)*p]);\n }\n string res=s[i*p..$];\n for(int k = 0;k < j;k++){\n writeln(res[k*q .. (k+1)*q]);\n }\n return;\n \n\n }\n }\n }\n writeln(\"-1\");\n\n}\n\n \n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, p, q;\n\tstring buf;\n\twhile ((buf = readln).formattedRead (\" %s %s %s\", &n, &p, &q) > 0)\n\t{\n\t\tstring s = readln.strip;\n\t\tstring [] res;\n\t\twhile (true)\n\t\t{\n\t\t\tif (s.length % q == 0)\n\t\t\t{\n\t\t\t\tres ~= s.chunks (q).map !(text).array;\n\t\t\t\ts = \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (s.length < p)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tres ~= s[0..p];\n\t\t\ts = s[p..$];\n\t\t}\n\t\tif (s.empty)\n\t\t{\n\t\t\twritefln (\"%s\\n%-(%s\\n%)\", res.length, res);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.typecons;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.functional;\nimport std.container;\n\n\nint main()\n{\n int n, p, q;\n\n readf(\" %d %d %d\", &n, &p, &q);\n readln();\n\n auto s = readln().strip();\n\n if (n % p == 0) {\n writeln(n / p);\n\n for (int i = 0; i < n; i += p)\n writeln(s[i..i + p]);\n } else if (n % q == 0) {\n writeln(n / q);\n\n for (int i = 0; i < n; i += q)\n writeln(s[i..i + q]);\n } else {\n auto temp = n;\n int count;\n\n while (temp % q != 0 && temp > 0)\n temp -= p, count++;\n\n if (temp < 0)\n writeln(-1);\n else {\n writeln(count + temp / q);\n\n for (int i = 0; i < temp; i += q)\n writeln(s[i..i + q]);\n\n for (int i = temp; i < n; i += p)\n writeln(s[i..i + p]);\n }\n }\n\n\treturn 0;\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, p, q;\n\tstring buf;\n\twhile ((buf = readln).formattedRead (\" %s %s %s\", &n, &p, &q) > 0)\n\t{\n\t\tstring s = readln.strip;\n\t\tstring [] res;\n\t\twhile (s.length >= p)\n\t\t{\n\t\t\tif (s.length % q == 0)\n\t\t\t{\n\t\t\t\tres ~= s.chunks (q).map !(text).array;\n\t\t\t\ts = \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tres ~= s[0..p];\n\t\t\ts = s[p..$];\n\t\t}\n\t\tif (s.empty)\n\t\t{\n\t\t\twritefln (\"%s\\n%-(%s\\n%)\", res.length, res);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.typecons;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\nimport std.functional;\nimport std.container;\n\n\nint main()\n{\n int n, p, q;\n\n readf(\" %d %d %d\", &n, &p, &q);\n readln();\n\n auto s = readln().strip();\n\n if (n % p == 0) {\n writeln(n / p);\n\n for (int i = 0; i < n; i += p)\n writeln(s[i..i + p]);\n } else if (n % q == 0) {\n writeln(n / q);\n\n for (int i = 0; i < n; i += q)\n writeln(s[i..i + q]);\n } else {\n auto temp = n;\n\n while (temp % q != 0 && temp > 0)\n temp -= p;\n\n if (temp < 0)\n writeln(-1);\n else {\n for (int i = 0; i < temp; i += q)\n writeln(s[i..i + q]);\n\n for (int i = temp; i < n; i += p)\n writeln(s[i..i + p]);\n }\n }\n\n\treturn 0;\n}\n"}], "src_uid": "c4da69789d875853beb4f92147825ebf"} {"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;\n\nvoid main ()\n{\n\tauto n = readln.strip.to !(int);\n\tauto a = n.iota.map !(_ => readln.split.map !(to !(real)))\n\t\t.map !(c => atan2 (c[1], c[0]))\n\t\t.enumerate.map !(reverse).array;\n\tsort (a);\n\ta ~= a[0];\n\ta[n][0] += 2 * PI;\n\tauto b = n.iota.map !(i => tuple (a[i + 1][0] - a[i][0],\n\t\ta[i][1], a[i + 1][1])).array;\n\tsort (b);\n\twriteln (b[0][1] + 1, ' ', b[0][2] + 1);\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;\n\nvoid main ()\n{\n\tauto n = readln.strip.to !(int);\n\tauto a = n.iota.map !(_ => readln.split.map !(to !(real)))\n\t\t.map !(c => atan2 (c[1], c[0]))\n\t\t.enumerate.map !(reverse).array;\n\tsort (a);\n\ta ~= a[0];\n\ta[n][0] += 2 * PI;\n\tauto b = n.iota.map !(i => tuple (a[i + 1][0] - a[i][0],\n\t\ta[i][1], a[i + 1][1])).array;\n\tsort (b);\n\twriteln (b[0][1] + 1, ' ', b[0][2] + 1);\n}"}, {"source_code": "import std.algorithm, std.math, std.range, std.stdio, std.typecons;\n\nvoid main ()\n{\n int n;\n while (readf (\" %s\", &n) > 0)\n {\n alias Vector = Tuple !(real, q{alpha}, int, q{num});\n auto a = new Vector [n];\n foreach (i, ref c; a)\n {\n real x, y;\n readf (\" %s %s\", &x, &y);\n c.alpha = atan2 (y, x);\n c.num = i + 1;\n }\n a.schwartzSort !(q{a.alpha});\n a ~= Vector (a[0].alpha + 2 * PI, a[0].num);\n auto p = n.iota.minPos !((i, j) =>\n a[i + 1].alpha - a[i].alpha <\n a[j + 1].alpha - a[j].alpha).front;\n writeln (a[p].num, ' ', a[p + 1].num);\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Vector = Tuple !(real, q{x}, real, q{y},\n\t\t real, q{alpha}, int, q{num});\n\t\tauto a = new Vector [n];\n\t\tforeach (i, ref c; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &c.x, &c.y);\n\t\t\tc.alpha = atan2 (c.y, c.x);\n\t\t\tc.num = i + 1;\n\t\t}\n\t\ta.schwartzSort !(q{a.alpha});\n\t\ta ~= Vector (a[0].x, a[0].y, a[0].alpha + 2 * PI, a[0].num);\n\t\tauto p = n.iota.minPos !((i, j) =>\n\t\t a[i + 1].alpha - a[i].alpha <\n\t\t a[j + 1].alpha - a[j].alpha).front;\n\t\twriteln (a[p].num, ' ', a[p + 1].num);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.math, std.range, std.stdio, std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Vector = Tuple !(real, q{alpha}, int, q{num});\n\t\tauto a = new Vector [n];\n\t\tforeach (i, ref c; a)\n\t\t{\n\t\t\treal x, y;\n\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\tc.alpha = atan2 (y, x);\n\t\t\tc.num = i + 1;\n\t\t}\n\t\ta.schwartzSort !(q{a.alpha});\n\t\ta ~= Vector (a[0].alpha + 2 * PI, a[0].num);\n\t\tauto p = n.iota.minPos !((i, j) =>\n\t\t a[i + 1].alpha - a[i].alpha <\n\t\t a[j + 1].alpha - a[j].alpha).front;\n\t\twriteln (a[p].num, ' ', a[p + 1].num);\n\t}\n}\n"}], "negative_code": [], "src_uid": "e7ffe7a54e2403805bde98d98fa0be3a"} {"source_code": "module main;\n__gshared:\nimport core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\nalias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nenum mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt gcd(BigInt a, BigInt b)\n\t\t{\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///integer size\n\t\tint sz(T)(T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (!(a[m] < g))\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (!(a[l] < g)) ? l : r;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (g < a[m])\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (g < a[l]) ? l : r;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn binf(a, g) != a.length;\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treturn s == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treadln;\n\t\treturn s == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tfreopen(\"input.txt\", \"r\", core.stdc.stdio.stdin);\n\t\t//freopen(\"output.txt\", \"w\", core.stdc.stdio.stdout);\n\t\t/*StopWatch sw;\n\t\tsw.start;\n\t\tscope (exit)\n\t\t{\n\t\t\tsw.stop;\n\t\t\tstderr.writefln(\"\\nTime: %d ms\", sw.peek.msecs);\n\t\t}*/\n\t}\n\tint n;\n\tloop: while (read(n))\n\t{\n\t\tauto a = arread!int;\n\t\tint[][int] g;\n\t\tforeach (x; a)\n\t\t{\n\t\t\tfor (int i = 2; i * i <= x; i++)\n\t\t\t{\n\t\t\t\tif (x % i == 0)\n\t\t\t\t{\n\t\t\t\t\tint cnt;\n\t\t\t\t\twhile (x % i == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t\tx /= i;\n\t\t\t\t\t}\n\t\t\t\t\tg[i] ~= cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x > 1)\n\t\t\t\tg[x] ~= 1;\n\t\t}\n\t\tint[int[]] q;\n\t\tint grandi(int[] v)\n\t\t{\n\t\t\tif (v.empty)\n\t\t\t\treturn 0;\n\t\t\tif (v in q)\n\t\t\t\treturn q[v];\n\t\t\tint[int] mex;\n\t\t\tforeach (c; 1 .. v.back + 1)\n\t\t\t{\n\t\t\t\tint[] v1;\n\t\t\t\tforeach (x; v)\n\t\t\t\t{\n\t\t\t\t\tif (x < c)\n\t\t\t\t\t\tv1 ~= x;\n\t\t\t\t\telse if (x > c)\n\t\t\t\t\t\tv1 ~= x - c;\n\t\t\t\t}\n\t\t\t\tmex[grandi(v1.sort().uniq().array)] = 1;\n\t\t\t}\n\t\t\tfor (int x;; x++)\n\t\t\t{\n\t\t\t\tif (x !in mex)\n\t\t\t\t\treturn q[v.idup] = x;\n\t\t\t}\n\t\t\tassert(0);\n\t\t}\n\n\t\tint ans;\n\t\tforeach (z; g)\n\t\t{\n\t\t\tans ^= grandi(z.sort().uniq().array);\n\t\t}\n\t\twriteln(ans ? \"Mojtaba\" : \"Arpa\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.conv, std.functional, std.range, std.stdio;\nalias T = int, g = memoize!h;\nT [T] f, x;\nT h (T v) {\n\tT s;\n\tforeach (k; 1..30) if (v >= 1 << k) s |= 1 << g ((v >> k) | (v & ((1 << k) - 1)));\n\treturn 30.iota.countUntil !(r => !(s & (1 << r)));\n}\nvoid main () {\n\treadln;\n\tforeach (c; readln.split.map !(to!T)) {\n\t\tforeach (d; 2..8 ^^ 5) if (!(c % d)) f[d] |= 1 << (1 + 30.iota.countUntil !(k => !!((c /= d) % d)));\n\t\tif (c > 1) x[c] = 1;\n\t}\n\twriteln (f.byValue.map!g.fold!q{a ^ b} (0) - (x.length & 1) ? \"Mojtaba\" : \"Arpa\");\n}\n"}, {"source_code": "import std.algorithm, std.array, std.conv, std.functional, std.stdio, std.string;\nimmutable int limit = 1 << 16;\n\nalias g = memoize !(gImpl);\nint gImpl (int v) {\n\tint s;\n\tforeach (k; 1..30)\n\t\tif (v >= 1 << k)\n\t\t\ts |= 1 << g ((v >> k) | (v & ((1 << k) - 1)));\n\tint r = 0;\n\twhile (s & (1 << r))\n\t\tr += 1;\n\treturn r;\n}\n\nvoid main () {\n\tint n = readln.strip.to !(int);\n\tauto a = readln.splitter.map !(to !(int)).array;\n\tauto f = new int [limit];\n\tbool [int] once;\n\n\tforeach (c; a) {\n\t\tfor (int d = 2; d < limit; d++)\n\t\t\tif (c % d == 0) {\n\t\t\t\tint k = 0;\n\t\t\t\twhile (c % d == 0) {\n\t\t\t\t\tc /= d;\n\t\t\t\t\tk += 1;\n\t\t\t\t}\n\t\t\t\tf[d] |= 1 << k;\n\t\t\t}\n\t\tif (c > 1)\n\t\t\tonce[c] = true;\n\t}\n\n\tint res = once.length & 1;\n\tforeach (v; f)\n\t\tres ^= g (v);\n\twriteln (res ? \"Mojtaba\" : \"Arpa\");\n}\n"}, {"source_code": "import std.algorithm, std.array, std.conv, std.range, std.stdio;\nalias T = int;\nT [T] f, x, g;\nT h (T v) {\n\tif (v !in g) {\n\t\tT s;\n\t\tforeach (k; 1..30) if (v >= 1 << k) s |= 1 << h ((v >> k) | (v & ((1 << k) - 1)));\n\t\tg[v] = 30.iota.countUntil !(r => !(s & (1 << r)));\n\t}\n\treturn g[v];\n}\nvoid main () {\n\treadln;\n\tforeach (c; readln.split.map !(to!T)) {\n\t\tforeach (d; 2..8 ^^ 5) if (!(c % d)) f[d] |= 1 << (1 + 30.iota.countUntil !(k => !!((c /= d) % d)));\n\t\tif (c > 1) x[c] = 1;\n\t}\n\twriteln (f.byValue.map!h.fold!q{a ^ b} (0) - (x.length & 1) ? \"Mojtaba\" : \"Arpa\");\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int limit = 1 << 16;\n\nalias g = memoize !(gImpl);\n\nint gImpl (int v)\nin\n{\n\tdebug {writeln (v);}\n}\nout (res)\n{\n\tdebug {writeln (\"g (\", v, \") = \", res);}\n}\nbody\n{\n\tint s;\n\tforeach (k; 1..30)\n\t{\n\t\tif (v >= 1 << k)\n\t\t{\n\t\t\ts |= 1 << g ((v >> k) | (v & ((1 << k) - 1)));\n\t\t}\n\t}\n\n\tint r = 0;\n\twhile (s & (1 << r))\n\t{\n\t\tr += 1;\n\t}\n\treturn r;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto f = new int [limit];\n\t\tbool [int] once;\n\n\t\tforeach (c; a)\n\t\t{\n\t\t\tfor (int d = 2; d < limit; d++)\n\t\t\t{\n\t\t\t\tif (c % d == 0)\n\t\t\t\t{\n\t\t\t\t\tint k = 0;\n\t\t\t\t\twhile (c % d == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tc /= d;\n\t\t\t\t\t\tk += 1;\n\t\t\t\t\t}\n\t\t\t\t\tdebug {writeln (d, \": \", k);}\n\t\t\t\t\tf[d] |= 1 << k;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (c > 1)\n\t\t\t{\n\t\t\t\tonce[c] = true;\n\t\t\t}\n\t\t}\n\n\t\tint res = once.length & 1;\n\t\tforeach (v; f)\n\t\t{\n\t\t\tres ^= g (v);\n\t\t}\n\n\t\twriteln (res ? \"Mojtaba\" : \"Arpa\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nint [int] f, x, g;\nint h (int v) {\n\tif (v !in g) {\n\t\tint s, k;\n\t\tfor (k = 2; v >= k; k <<= 1) s |= 1 << h (v / k | (v & (k - 1)));\n\t\tg[v] = 30.iota.countUntil !(r => !(s & (1 << r)));\n\t}\n\treturn g[v];\n}\nvoid main () {\n\treadln;\n\tforeach (c; readln.split.map !(to!int)) {\n\t\tforeach (d; 2..8 ^^ 5) if (!(c % d)) f[d] |= 1 << (1 + 30.iota.countUntil !(k => !!((c /= d) % d)));\n\t\tif (c > 1) x[c] = 1;\n\t}\n\twriteln (f.byValue.map!h.fold!q{a ^ b} (x.length & 1) ? \"Mojtaba\" : \"Arpa\");\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int[int] fs;\n foreach (i; 0 .. N) {\n int a = A[i];\n for (int p = 2; p^^2 <= a; ++p) {\n if (a % p == 0) {\n int e;\n do {\n ++e;\n a /= p;\n } while (a % p == 0);\n fs[p] |= 1 << e;\n }\n }\n if (a > 1) {\n fs[a] |= 1 << 1;\n }\n }\n debug {\n writeln(\"fs = \", fs);\n }\n \n long[int] cache;\n long calc(int f) {\n long ret;\n cache.update(f, {\n long app;\n if (f) {\n foreach (e; 1 .. bsr(f) + 1) {\n const ff = ((f & ((1 << e) - 1)) | (f >> e)) & ~1;\n app |= 1L << calc(ff);\n }\n }\n ret = bsf(~app);\n debug {\n writefln(\"calc %b = %s\", f, ret);\n }\n return ret;\n }, (ref long r) {\n return ret = r;\n });\n return ret;\n }\n \n long ans;\n foreach (p, f; fs) {\n ans ^= calc(f);\n }\n writeln(ans ? \"Mojtaba\" : \"Arpa\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.conv, std.functional, std.range, std.stdio;\nalias T = int, g = memoize!h;\nT [T] f, x;\nT h (T v) {\n\tT s;\n\tforeach (k; 1..30) if (v >= 1 << k) s |= 1 << g ((v >> k) | (v & ((1 << k) - 1)));\n\treturn 30.iota.countUntil !(r => !(s & (1 << r)));\n}\nvoid main () {\n\treadln;\n\tforeach (c; readln.split.map !(to!T)) {\n\t\tforeach (d; 2..8 ^^ 5) if (!(c % d)) f[d] |= 1 << 30.iota.countUntil !(k => !!((c /= d) % d));\n\t\tif (c > 1) x[c] = 1;\n\t}\n\twriteln (f.byValue.map!g.fold!q{a ^ b} (0) - (x.length & 1) ? \"Mojtaba\" : \"Arpa\");\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int[int] fs;\n foreach (i; 0 .. N) {\n int a = A[i];\n for (int p = 2; p^^2 <= a; ++p) {\n if (a % p == 0) {\n int e;\n do {\n ++e;\n a /= p;\n } while (a % p == 0);\n fs[p] |= 1 << e;\n }\n }\n if (a > 1) {\n fs[a] |= 1 << 1;\n }\n }\n debug {\n writeln(\"fs = \", fs);\n }\n \n int[int] cache;\n int calc(int f) {\n int ret;\n cache.update(f, {\n int app;\n if (f) {\n foreach (e; 1 .. bsf(f) + 1) {\n const ff = ((f & ((1 << e) - 1)) | (f >> e)) & ~1;\n app |= 1 << calc(ff);\n }\n }\n ret = bsf(~app);\n debug {\n writefln(\"calc %b = %s\", f, ret);\n }\n return ret;\n }, (ref int r) {\n return ret = r;\n });\n return ret;\n }\n \n int ans;\n foreach (p, f; fs) {\n ans ^= calc(f);\n }\n writeln(ans ? \"Mojtaba\" : \"Arpa\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "7eb2a4cd3eeea63ed8fad0fe62942af4"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [] d;\n\t\tint i = 0;\n\t\twhile (i < n * 2)\n\t\t{\n\t\t\tint j = i;\n\t\t\tdo\n\t\t\t{\n\t\t\t\ti += 1;\n\t\t\t}\n\t\t\twhile (i < n * 2 && a[i] < a[j]);\n\t\t\td ~= i - j;\n\t\t}\n\n\t\tauto f = new bool [n * 2 + 1];\n\t\tf[0] = true;\n\t\tforeach (ref c; d)\n\t\t\tfor (int p = n * 2; p >= c; p--)\n\t\t\t\tf[p] |= f[p - c];\n\n\t\twriteln (f[n] ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto P = new int[2 * N + 1];\n foreach (i; 0 .. 2 * N) {\n P[i] = readInt();\n }\n P[2 * N] = 2 * N + 1;\n \n auto dp = new int[][](N + 1, N + 1);\n dp[0][0] = P[2 * N];\n foreach (s; 0 .. 2 * N) {\n foreach (a; 0 .. N + 1) {\n const b = s - a;\n if (0 <= b && b <= N) {\n if (dp[a][b] > 0) {\n const p = P[2 * N - (a + b) - 1];\n if (a < N && P[2 * N - (a + b) - 1] < dp[a][b]) {\n chmax(dp[a + 1][b], dp[a][b]);\n }\n if (b < N && P[2 * N - (a + b) - 1] < P[2 * N - (a + b)]) {\n chmax(dp[b + 1][a], P[2 * N - (a + b)]);\n }\n }\n }\n }\n }\n debug {\n foreach (a; 0 .. N + 1) {\n writeln(a, \": \", dp[a]);\n }\n }\n writeln((dp[N][N] > 0) ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto p = RDA!int;\n\n\t\tint[] arr;\n\t\tint num, cnt;\n\t\tforeach (i; 0..n*2)\n\t\t{\n\t\t\tif (p[i] > num)\n\t\t\t{\n\t\t\t\tif (cnt != 0)\n\t\t\t\t{\n\t\t\t\t\tarr ~= cnt;\n\t\t\t\t}\n\t\t\t\tnum = p[i];\n\t\t\t\tcnt = 0;\n\t\t\t}\n\t\t\t++cnt;\n\t\t}\n\t\tarr ~= cnt;\n\t\tdebug writeln(arr);\n\n\t\tauto dp = new bool[](n+1);\n\t\tdp[0] = true;\n\t\tforeach (e; arr)\n\t\t{\n\t\t\tforeach_reverse (i; 0..dp.length)\n\t\t\t{\n\t\t\t\tif (!dp[i]) continue;\n\t\t\t\tauto ni = i + e;\n\t\t\t\tif (ni < n+1)\n\t\t\t\t{\n\t\t\t\t\tdp[ni] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans[ti] = dp[n];\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [] d;\n\t\tint i = 0;\n\t\twhile (i < n * 2)\n\t\t{\n\t\t\tint j = i;\n\t\t\tdo\n\t\t\t{\n\t\t\t\ti += 1;\n\t\t\t}\n\t\t\twhile (i < n * 2 && a[i] < a[j]);\n\t\t\td ~= i - j;\n\t\t}\n\n\t\tauto f = new int [n * 2 + 1];\n\t\tf[] = int.max;\n\t\tf[0] = -1;\n\t\tforeach (int k, ref c; d)\n\t\t{\n\t\t\tfor (int p = c; p <= n * 2; p++)\n\t\t\t{\n\t\t\t\tif (f[p] == int.max && f[p - c] < k)\n\t\t\t\t{\n\t\t\t\t\tf[p] = k;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (f[n] < int.max ? \"YES\" : \"NO\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = 0 ~ readln.splitter.map !(to !(int)).array;\n\t\tauto f = new bool [] [] (2, n * 2 + 1);\n\t\tint b = 0;\n\t\tf[b][0] = true;\n\t\tforeach (i; 1..n * 2 + 1)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tf[b][] = false;\n\t\t\tforeach (j; 0..i)\n\t\t\t{\n/*\n\t\t\t\tif (i - j > n)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n*/\n\t\t\t\tif (f[!b][j])\n\t\t\t\t{\n\t\t\t\t\tif (a[i - 1] < a[i] && i - j <= n)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[b][j] = true;\n\t\t\t\t\t}\n\t\t\t\t\tif (a[j] < a[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tf[b][i - 1] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (f[b].any ? \"YES\" : \"NO\");\n\t}\n}\n"}], "src_uid": "2d1db83f1eb921f830cc9c709f9327fa"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\tauto c = a.group.map !(q{a[1].to !(int)}).array;\r\n\t\tsort (c);\r\n\t\tint res = n;\r\n\t\tint k = c.length.to !(int);\r\n\t\tforeach (i; 0..k)\r\n\t\t{\r\n\t\t\tres = min (res, n - (k - i) * c[i]);\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\tauto c = a.group.map !(q{a[1].to !(int)}).array;\r\n\t\tsort (c);\r\n\t\tint res = n;\r\n\t\tint i = 0;\r\n\t\tint k = c.length.to !(int);\r\n\t\tforeach (num; 1..n + 1)\r\n\t\t{\r\n\t\t\twhile (i < k && c[i] < num)\r\n\t\t\t{\r\n\t\t\t\ti += 1;\r\n\t\t\t}\r\n\t\t\tres = min (res, n - (k - i) * num);\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n int N; get(N);\r\n int[] AA; get(AA);\r\n int[int] memo;\r\n foreach (a; AA) ++memo[a];\r\n int[] ps;\r\n foreach (_, v; memo) ps ~= v;\r\n sort!\"a > b\"(ps);\r\n int res = int.max, pre, s;\r\n foreach (i, p; ps) {\r\n s += p;\r\n if (i) pre += i.to!int * (ps[i - 1] - p);\r\n res = min(res, pre + N - s);\r\n }\r\n writeln(res);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA!int;\r\n\t\t\r\n\t\tint[int] cnt;\r\n\t\tforeach (i; 0..n)\r\n\t\t\t++cnt[a[i]];\r\n\t\t\r\n\t\tint[int] cnt2;\r\n\t\tforeach (value; cnt.values)\r\n\t\t\t++cnt2[value];\r\n\t\t\r\n\t\tauto keys = cnt2.keys.sort;\r\n\t\tauto b = new long[](keys.length+1);\r\n\t\tauto c = new long[](keys.length+1);\r\n\t\tforeach (i; 0..keys.length)\r\n\t\t{\r\n\t\t\tauto key = keys[i];\r\n\t\t\tb[i+1] = b[i] + cnt2[key] * key;\r\n\t\t\tc[i+1] = c[i] + cnt2[key];\r\n\t\t}\r\n\r\n\t\tans[ti] = long.max;\r\n\t\tforeach (i; 0..keys.length)\r\n\t\t{\r\n\t\t\tauto key = keys[i];\r\n\t\t\tlong del = b[i] + b[$-1] - b[i+1];\r\n\t\t\tdel -= (c[$-1] - c[i+1]) * key;\r\n\t\t\tans[ti].chmin(del);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "aab052bf49da6528641f655342fa4848"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.functional;\n\nimmutable int MN = 2010;\nimmutable int MK = 2010;\nimmutable long MD = 10^^9+7;\n\nint main() {\n int n, k;\n string s;\n long[][] dp = new long[][](MN, MK);\n long[] sum = new long[](MK);\n readf(\"%d %d\\n\", &n, &k);\n s = chomp(readln());\n s ~= 'a';\n for (int i = 0; i <= n; i++) {\n dp[i][0] = 1;\n }\n for (int i = n; i >= 0; i--) {\n for (int u = 0; u <= k; u++) {\n sum[u] += dp[i+1][u]*(s[i]-'a');\n sum[u] %= MD;\n dp[i][u] += sum[u];\n dp[i][u] %= MD;\n for (int j = i-1; j >= 0; j--) {\n int d = u+(i-j)*(n-i+1);\n if (d > k) break;\n dp[j][d] += dp[i][u] * ('z'-s[i-1]);\n dp[j][d] %= MD;\n }\n }\n }\n writeln(dp[0][k]%MD);\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.functional;\n\nimmutable int MN = 2010;\nimmutable int MK = 2010;\nimmutable long MD = 10^^9+7;\n\nint main() {\n int n, k;\n string s;\n long[MK][] dp = new long[MK][](MN);\n long[] sum = new long[](MK);\n readf(\"%d %d\\n\", &n, &k);\n s = chomp(readln());\n s ~= 'a';\n for (int i = 0; i <= n; i++) {\n dp[i][0] = 1;\n }\n for (int i = n; i >= 0; i--) {\n for (int u = 0; u <= k; u++) {\n sum[u] += dp[i+1][u]*(s[i]-'a');\n sum[u] %= MD;\n dp[i][u] += sum[u];\n dp[i][u] %= MD;\n for (int j = i-1; j >= 0; j--) {\n int d = u+(i-j)*(n-i+1);\n if (d > k) break;\n dp[j][d] += dp[i][u] * ('z'-s[i-1]);\n dp[j][d] %= MD;\n }\n }\n }\n writeln(dp[0][k]%MD);\n return 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.functional;\nimmutable int MN = 2010;\nimmutable long MD = 1^^9+7;\nint n, k;\nstring s;\n\nlong[][] dp;\nbool[][] used;\n\nlong solve(int i, int u) {\n if (i > n) return 0;\n if (u < 0) return 0;\n if (i == n) {\n if (u) {\n return 0;\n } else {\n return 1;\n }\n }\n if (used[i][u]) return dp[i][u];\n long r = 0;\n for (int j = i; j < n; j++) {\n r += solve(j+1, u-(j-i+1)*(n-j))*('z'-s[j]);\n r += solve(j+1, u)*(s[j]-'a');\n }\n if (!u) r++;\n r %= MD;\n dp[i][u] = r;\n used[i][u] = true;\n return r;\n}\n\nint main() {\n dp = new long[][](MN, MN);\n used = new bool[][](MN, MN);\n readf(\"%d %d\\n\", &n, &k);\n s = readln();\n writeln(solve(0, k));\n return 0;\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.functional;\nimmutable int MN = 2010;\nimmutable long MD = 1^^9+7;\nint n, k;\nstring s;\n\nlong[][] dp;\nbool[][] used;\n\nlong solve(int i, int u) {\n if (i > n) return 0;\n if (u < 0) return 0;\n if (i == n) {\n if (u) {\n return 0;\n } else {\n return 1;\n }\n }\n if (used[i][u]) return dp[i][u];\n long r = 0;\n for (int j = i; j < n; j++) {\n r += solve(j+1, u-(j-i+1)*(n-j))*('z'-s[j]);\n r += solve(j+1, u)*(s[j]-'a');\n }\n if (!u) r++;\n dp[i][u] = r;\n used[i][u] = true;\n return r;\n}\n\nint main() {\n dp = new long[][](MN, MN);\n used = new bool[][](MN, MN);\n readf(\"%d %d\\n\", &n, &k);\n s = readln();\n writeln(solve(0, k));\n return 0;\n}\n"}], "src_uid": "6acc6ab9e60eceebb85f41dc0aea9cf4"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto x = RD;\n\t\tauto a = RDA;\n\n\t\tbool allX = true;\n\t\tbool hasX;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] != x)\n\t\t\t\tallX = false;\n\t\t\telse\n\t\t\t\thasX = true;\n\t\t}\n\t\tif (allX) continue;\n\n\t\tif (hasX)\n\t\t{\n\t\t\tans[ti] = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong tot;\n\t\t\tforeach (i; 0..n)\n\t\t\t\ttot += a[i];\n\t\t\tif (tot / n == x && tot % n == 0)\n\t\t\t\tans[ti] = 1;\n\t\t\telse\n\t\t\t\tans[ti] = 2;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n long n = rd;\n long x = rd;\n ll[] arr = rdarr;\n ll summ = 0;\n bool aleq = 1, oneq = 0;\n foreach(el; arr){\n summ += el;\n if(el != x) aleq = 0;\n else oneq = 1;\n }\n if(aleq){\n writeln(0);\n }else if(summ == n*x || oneq){\n writeln(1);\n }else{\n writeln(2);\n }\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\n\nvoid solve()\n{\n auto nx = readln.split.to!(int[]);\n auto N = nx[0];\n auto X = nx[1];\n int sum_a, infected;\n bool all_same = true;\n foreach (a; readln.split.to!(int[])) {\n if (a != X) all_same = false;\n if (a == X) ++infected;\n sum_a += a;\n }\n if (all_same) {\n writeln(0);\n } else if (X*N == sum_a) {\n writeln(1);\n } else if (infected == 0) {\n writeln(2);\n } else {\n writeln(1);\n }\n}\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n solve();\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n long n = rd;\n long x = rd;\n ll[] arr = rdarr;\n ll summ = 0;\n bool aleq = 1;\n foreach(el; arr){\n summ += el;\n if(el != x) aleq = 0;\n }\n if(aleq){\n writeln(0);\n }else if(summ == n*x){\n writeln(1);\n }else{\n writeln(2);\n }\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}], "src_uid": "475a24d36eab99ae4f78815ccdc5da91"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint a, b;\r\n\t\treadf !(\" %s %s\") (a, b);\r\n\t\twriteln (min (a, b, (a + b) / 4));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long a, b;\n readf!\" %d %d \"(a, b);\n if (a > b)\n swap(a, b);\n writeln(min((a + b) / 4, a));\n }\n}\n"}], "negative_code": [], "src_uid": "8a1ceac1440f7cb406f12d9fc2ca0e20"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int MAX_N = 100_005;\nimmutable int MAX_C = 0x3F3F3F3F;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t}\n\t\t\n\t\tauto h = new int [n + 2];\n\t\th[0] = -1;\n\t\th[1..$] = n + 1;\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint lo = 0;\n\t\t\tint hi = n;\n\t\t\twhile (lo < hi)\n\t\t\t{\n\t\t\t\tint me = (lo + hi + 1) >> 1;\n\t\t\t\tif (h[me] > a[i])\n\t\t\t\t{\n\t\t\t\t\thi = me - 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlo = me;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlo++;\n\t\t\tenforce (h[lo] > a[i]);\n\t\t\th[lo] = a[i];\n\t\t\tres = max (res, lo);\n\t\t\tdebug {writefln (\"%s %s\", h, lo);}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nint[100000] b;\nint c = 0;\n\nvoid main() {\n int n;\n for (readf(\"%d\", &n); n >= 1; --n) {\n int a;\n readf(\" %d\", &a);\n int l = 0;\n int r = c;\n while (l < r) {\n int m = l + r >> 1;\n if (a < b[m])\n r = m;\n else\n l = m + 1;\n }\n if (r == c)\n ++c;\n b[r] = a;\n }\n writeln(c);\n}"}], "negative_code": [], "src_uid": "e132767dd89801a237b998a410b22a44"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX_SZ = 100;\n\nint binCoef(int n, int k) {\n int ans = 1;\n foreach (i; 1 .. k+1) {\n ans *= n - i + 1;\n ans /= i;\n }\n \n return ans;\n}\n\nvoid main()\n{\n int k;\n readf(\"%s\", &k);\n readln;\n \n auto ans = new int[MX_SZ][MX_SZ];\n \n int cqSz = 3;\n while (binCoef(cqSz+1, 3) <= k) { ++cqSz; }\n \n foreach (i; 0 .. cqSz) {\n foreach (j; 0 .. cqSz) {\n if (i == j) { continue; }\n ans[i][j] = 1;\n }\n }\n \n int lft = k - binCoef(cqSz, 3);\n \n int idx = cqSz;\n while (lft > 0) {\n ans[0][idx] = ans[idx][0] = 1;\n \n debug { writeln(lft, ' ', idx); }\n \n int p = 1, cur = 1;\n while (cur <= lft && p < cqSz) { \n ans[p][idx] = ans[idx][p] = 1;\n lft -= cur;\n ++p;\n cur = p;\n \n debug { writeln(\"in \", cur, ' ', lft); }\n }\n \n ++idx;\n }\n \n writeln(MX_SZ);\n ans.each!(line => line.writefln!\"%(%s%)\");\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX_SZ = 100;\n\nint binCoef(int n, int k) {\n int ans = 1;\n foreach (i; 1 .. k+1) {\n ans *= n - i + 1;\n ans /= i;\n }\n \n return ans;\n}\n\nvoid main()\n{\n int k;\n readf(\"%s\", &k);\n readln;\n \n auto ans = new int[MX_SZ][MX_SZ];\n \n int cqSz = 3;\n while (binCoef(cqSz+1, 3) <= k) { ++cqSz; }\n \n foreach (i; 0 .. cqSz) {\n foreach (j; 0 .. cqSz) {\n if (i == j) { continue; }\n ans[i][j] = 1;\n }\n }\n \n int lft = k - binCoef(cqSz, 3);\n \n int idx = cqSz;\n while (lft > 0) {\n ans[0][idx] = ans[idx][0] = 1;\n \n debug { writeln(lft, ' ', idx); }\n \n int pos = 1;\n while (pos <= lft && pos < cqSz) { \n ans[pos][idx] = ans[idx][pos] = 1;\n lft -= pos;\n ++pos;\n }\n \n ++idx;\n }\n \n writeln(MX_SZ);\n ans.each!(line => line.writefln!\"%(%s%)\");\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nint binCoef(int n, int k) {\n int ans = 1;\n foreach (i; 1 .. k+1) {\n ans *= n - i + 1;\n ans /= i;\n }\n \n return ans;\n}\n\nvoid main()\n{\n int k;\n readf(\"%s\", &k);\n readln;\n \n auto ans = new int[100][100];\n \n int cqSz = 3;\n while (binCoef(cqSz+1, 3) <= k) { ++cqSz; }\n \n foreach (i; 0 .. cqSz) {\n foreach (j; 0 .. cqSz) {\n if (i == j) { continue; }\n ans[i][j] = 1;\n }\n }\n \n int lft = k - binCoef(cqSz, 3);\n \n int idx = cqSz;\n while (lft > 0) {\n ans[0][idx] = ans[idx][0] = 1;\n \n int p = 1, cur = 1;\n while (cur <= lft && p < cqSz) { \n ans[p][idx] = ans[idx][p] = 1;\n lft -= cur;\n ++p;\n cur = binCoef(p+1, 2); \n }\n \n ++idx;\n }\n \n writeln(100);\n ans.each!(line => line.writefln!\"%(%s%)\");\n}"}], "src_uid": "d3f4c7fedd6148c28d8780142b6594f4"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new int[N];\n foreach (i; 0 .. N) {\n P[i] = readInt() - 1;\n }\n \n long ans = long.max;\n int km = -1;\n \n long now;\n long posi, nega;\n int offset;\n auto cnt = new int[4 * N + 1];\n void add(int val) {\n now += abs(offset + val);\n (offset + val >= 0) ? ++posi : ++nega;\n ++cnt[2 * N + val];\n }\n void rem(int val) {\n now -= abs(offset + val);\n (offset + val >= 0) ? --posi : --nega;\n --cnt[2 * N + val];\n }\n \n foreach (i; 0 .. N) {\n add(P[i] - i);\n }\n foreach (k; 0 .. N) {\n debug {\n writeln(k, \": \", now);\n }\n if (chmin(ans, now)) {\n km = k;\n }\n rem(P[N - 1 - k] - (N - 1 - k));\n posi -= cnt[2 * N - offset];\n nega += cnt[2 * N - offset];\n now -= posi;\n now += nega;\n --offset;\n add(P[N - 1 - k] - (N - 1 - k) + N);\n }\n writeln(ans, \" \", km);\n \n debug {\n long brt = long.max;\n int brtkm = -1;\n foreach (k; 0 .. N) {\n long cost;\n foreach (i; 0 .. N) {\n cost += abs(P[i] - (k + i) % N);\n }\n debug {\n writeln(\"brt \", k, \": \", cost);\n }\n if (chmin(brt, cost)) {\n brtkm = k;\n }\n }\n writeln(\"brt: \", brt, \" \", brtkm);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.math;\nimport std.range;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n alias Ev = Tuple!(int, long, long);\n auto n = next!long;\n auto p = next!long(n);\n p[] -= 1;\n auto dpt = new long[](cast(size_t)n); // delta per time\n void calcdpt(long i, long pi)\n {\n auto ts = redBlackTree!long([0]);\n if (pi >= i) ts.insert(pi - i);\n else ts.insert(n - i + pi);\n ts.insert(n - 1 - i);\n ts.insert(n - i);\n auto pd = long(0);\n debug auto tdpt = new long[](cast(size_t) n);\n foreach(t; ts)\n if (t < n)\n\t{\n\t auto val = abs((i + 1 + t) % n - pi) - abs((i + t) % n - pi);\n\t auto toadd = val - pd;\n\t dpt[cast(size_t)t] += toadd;\n\t debug tdpt[cast(size_t)t] += toadd;\n\t pd = val;\n\t}\n long delta = 0;\n debug writeln(\"after adding \", i, \" \", pi);\n debug foreach(t; 0 .. n)\n {\n\twrite(abs((i + 1 + t)%n - pi) - abs((i + t)%n - pi), \" \");\n }\n debug writeln;\n debug foreach(t; 0 .. n)\n {\n\tdelta += tdpt[cast(size_t)t];\n\twrite(delta, \" \");\n }\n debug writeln;\n }\n foreach(i, pi; p)\n calcdpt(cast(long) i, pi);\n long deviation = iota(0, n).map!(i => abs(i - p[cast(size_t)i])).sum;\n long bestdeviation = deviation;\n long besttime = 0;\n long delta = dpt[0];\n\n long dev = deviation;\n long accdelta = dpt[0];\n debug write(dev, \" \");\n debug foreach(t; 1 .. n)\n {\n dev += accdelta;\n write(dev, \"(\", iota(0, n).map!(i => abs((i + t) % n - p[cast(size_t)i])).sum, \") \");\n accdelta += dpt[cast(size_t)t];\n }\n writeln;\n foreach(t; 1 .. n)\n {\n deviation += delta;\n if (deviation < bestdeviation)\n\t{\n\t bestdeviation = deviation;\n\t besttime = t;\n\t}\n delta += dpt[cast(size_t)t];\n }\n writeln(bestdeviation, \" \", besttime);\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.math;\nimport std.range;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n alias Ev = Tuple!(int, int, int);\n auto n = next!int;\n auto p = next!int(n);\n p[] -= 1;\n auto dpt = new int[](n); // delta per time\n void calcdpt(int i, int pi)\n {\n auto ts = redBlackTree!int([0]);\n if (pi >= i) ts.insert(pi - i);\n else ts.insert(n - i + pi);\n ts.insert(n - 1 - i);\n ts.insert(n - i);\n auto pd = int(0);\n foreach(t; ts)\n if (t < n)\n\t{\n\t dpt[t] += abs((i + 1 + t) % n - pi) - abs((i + t) % n - pi) - pd;\n\t pd = dpt[t];\n\t}\n }\n foreach(i, pi; p)\n calcdpt(cast(int) i, pi);\n long deviation = iota(0, n).map!(i => abs(i - p[i])).sum;\n long bestdeviation = deviation;\n int besttime = 0;\n long delta = 0;\n foreach(t; 0 .. n)\n {\n deviation += delta;\n if (deviation < bestdeviation)\n\t{\n\t bestdeviation = deviation;\n\t besttime = t;\n\t}\n delta += dpt[t];\n }\n writeln(bestdeviation, \" \", besttime);\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.math;\nimport std.range;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n alias Ev = Tuple!(int, int, int);\n auto n = next!int;\n auto p = next!int(n);\n p[] -= 1;\n auto dpt = new int[](n); // delta per time\n void calcdpt(int i, int pi)\n {\n auto ts = redBlackTree!int([0]);\n if (pi >= i) ts.insert(pi - i);\n else ts.insert(n - i + pi);\n ts.insert(n - 1 - i);\n ts.insert(n - i);\n auto pd = int(0);\n debug auto tdpt = new int[](n);\n foreach(t; ts)\n if (t < n)\n\t{\n\t auto val = abs((i + 1 + t) % n - pi) - abs((i + t) % n - pi);\n\t auto toadd = val - pd;\n\t dpt[t] += toadd;\n\t debug tdpt[t] += toadd;\n\t pd = val;\n\t}\n long delta = 0;\n debug writeln(\"after adding \", i, \" \", pi);\n debug foreach(t; 0 .. n)\n {\n\twrite(abs((i + 1 + t)%n - pi) - abs((i + t)%n - pi), \" \");\n }\n debug writeln;\n debug foreach(t; 0 .. n)\n {\n\tdelta += tdpt[t];\n\twrite(delta, \" \");\n }\n debug writeln;\n }\n foreach(i, pi; p)\n calcdpt(cast(int) i, pi);\n long deviation = iota(0, n).map!(i => abs(i - p[i])).sum;\n long bestdeviation = deviation;\n int besttime = 0;\n long delta = dpt[0];\n\n long dev = deviation;\n long accdelta = dpt[0];\n debug write(dev, \" \");\n debug foreach(t; 1 .. n)\n {\n dev += accdelta;\n write(dev, \"(\", iota(0, n).map!(i => abs((i + t) % n - p[i])).sum, \") \");\n accdelta += dpt[t];\n }\n writeln;\n foreach(t; 1 .. n)\n {\n deviation += delta;\n if (deviation < bestdeviation)\n\t{\n\t bestdeviation = deviation;\n\t besttime = t;\n\t}\n delta += dpt[t];\n }\n writeln(bestdeviation, \" \", besttime);\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "src_uid": "01adc5002997b7f5c79eeb6d9b3dc60b"} {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\nenum inf3 = 1_001_001_001;\nenum inf6 = 1_001_001_001_001_001_001L;\nenum mod = 1_000_000_007L;\n\nint[] di = [1, 1, -1, -1];\nint[] dj = [1, -1, 1, -1];\n\nvoid main() {\n int n;\n scan(n);\n auto m = iota(n).map!(i => readln.chomp).array;\n int ans;\n\n foreach (i ; 1 .. n - 1) {\n foreach (j ; 1 .. n - 1) {\n if (m[i][j] != 'X') continue;\n bool ok = true;\n foreach (k ; 0 .. 4) {\n int ni = i + di[k];\n int nj = j + dj[k];\n if (m[ni][nj] != 'X') {\n ok = false;\n break;\n }\n }\n ans += ok;\n }\n }\n\n writeln(ans);\n}\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 998244353;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = N.iota.map!(_ => readln.chomp).array;\n int ans = 0;\n int[] dr = [0, -1, -1, 1, 1];\n int[] dc = [0, -1, 1, -1, 1];\n\n foreach (r; 1..N-1) {\n foreach (c; 1..N-1) {\n int ok = 1;\n foreach (k; 0..5) {\n int nr = r + dr[k];\n int nc = c + dc[k];\n if (S[nr][nc] == '.') {\n ok = 0;\n break;\n }\n }\n ans += ok;\n }\n }\n\n ans.writeln;\n}\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n=readln.chomp.to!int;\n auto a=new string[n];\n foreach(i;0..n)\n a[i]=readln.strip; \n int ans=0;\n foreach(i;1..n-1)\n foreach(j;1..n-1)\n if(a[i][j]=='X'\n && a[i-1][j-1]=='X'\n && a[i-1][j+1]=='X'\n && a[i+1][j-1]=='X'\n && a[i+1][j+1]=='X')\n ans++;\n writeln(ans);\n}\n\n"}], "negative_code": [], "src_uid": "3270260030fc56dda3e375af4dad9330"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nalias type = multi;\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, d;\n @dn long[] a;\n\n void solve(long tc = -1)\n {\n logSym!(this);\n long total = 0;\n foreach(i, ai; a)\n {\n if (i == 0)\n {\n total += ai;\n continue;\n }\n auto taken = min(ai, d / i);\n d -= taken * i;\n total += taken;\n }\n writeln(total);\n }\n}\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.stdio : writeln;\n\nstruct IO {\n string readToken() {\n import std.range : empty, front, popFront, split;\n import std.stdio : readln;\n\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n\n int readInt() {\n import std.conv : to;\n\n return readToken.to!int;\n }\n\n string[] tokens;\n}\n\nlong binom2(int n) {\n return n * (n + 1L) >> 1;\n}\n\nvoid main() {\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int m = io.readInt;\n int result = 0;\n for (int i = 0; i < n; ++i) {\n int a = io.readInt;\n while (m >= i && a) {\n result++, m -= i, a--;\n }\n }\n writeln(result);\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto d = RD!int;\n\t\tauto a = RDA;\n\t\tans[ti] = a[0];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tauto x = min(d/i, a[i]);\n\t\t\tans[ti] += x;\n\t\t\td -= i*x;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio;\n\n\nvoid main() {\n int t, n, d, v, res; readf(\"%d\", &t); while(t--) {\n scanf(\"%d %d\", &n, &d); scanf(\"%d\", &res);\n for (int i = 1; i < n; i++) { scanf(\"%d\", &v); if (d > 0) { res+= (i*v<=d ? v : (d/i)); d-=i*v; } }\n writeln(res);\n }\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n const n = r.next!uint ();\n auto d = r.next!uint ();\n auto a = r.nextA!uint (n);\n foreach (i; 1 .. n) {\n while (d >= i && a[i] > 0) {\n d -= i;\n a[0]++;\n a[i]--;\n }\n }\n writeln (a[0]);\n }\n}\n\n"}], "negative_code": [], "src_uid": "7bbb4b9f5eccfe13741445c815a4b1ca"} {"source_code": "import std.stdio, std.string;\n\nint dp[1000010][][];\n\nvoid solve(char[] str)\n{\n immutable auto mod = 1000000007;\n if (str[0] == '2')\n {\n writeln(0);\n return;\n }\n foreach (int i; 0 .. str.length)\n {\n dp[i] = new int[][4];\n foreach (int j; 0 .. 4)\n {\n dp[i][j] = new int[2];\n }\n }\n if (str[0] == '*')\n {\n dp[0][3][0] = 1;\n }\n else if (str[0] == '0')\n {\n dp[0][0][0] = 1;\n }\n else if (str[0] == '1')\n {\n dp[0][1][0] = 1;\n }\n else if (str[0] == '?')\n {\n dp[0][0][0] = dp[0][1][0] = dp[0][3][0] = 1;\n }\n foreach (int i; 1 .. str.length)\n {\n if (str[i] == '0' || str[i] == '?')\n {\n dp[i][0][0] = (dp[i][0][0] + dp[i - 1][0][0]) % mod;\n dp[i][0][0] = (dp[i][0][0] + dp[i - 1][1][1]) % mod;\n }\n if (str[i] == '1' || str[i] == '?')\n {\n dp[i][1][0] = (dp[i][1][0] + dp[i - 1][0][0]) % mod;\n dp[i][1][0] = (dp[i][1][0] + dp[i - 1][1][1]) % mod;\n dp[i][1][1] = (dp[i][1][1] + dp[i - 1][3][0]) % mod;\n }\n if (str[i] == '2' || str[i] == '?')\n {\n dp[i][2][1] = (dp[i][2][1] + dp[i - 1][3][0]) % mod;\n }\n if (str[i] == '*' || str[i] == '?')\n {\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][1][0]) % mod;\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][2][1]) % mod;\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][3][0]) % mod;\n }\n }\n int ans = 0;\n ans = (ans + dp[str.length - 1][0][0]) % mod;\n ans = (ans + dp[str.length - 1][1][1]) % mod;\n ans = (ans + dp[str.length - 1][3][0]) % mod;\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n char[] str;\n while (stdin.readln(str))\n {\n //str = chomp(str);\n solve(str[0 .. $ - 1]);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\n\nint dp[1000010][][];\n\nvoid solve(char[] str)\n{\n immutable auto mod = 1000000007;\n if (str[0] == '2')\n {\n writeln(0);\n return;\n }\n foreach (int i; 0 .. str.length)\n {\n dp[i] = new int[][4];\n foreach (int j; 0 .. 4)\n {\n dp[i][j] = new int[2];\n }\n }\n if (str[0] == '*')\n {\n dp[0][3][0] = 1;\n }\n else if (str[0] == '0')\n {\n dp[0][0][0] = 1;\n }\n else if (str[0] == '1')\n {\n dp[0][1][0] = 1;\n }\n else if (str[0] == '?')\n {\n dp[0][0][0] = dp[0][1][0] = dp[0][3][0] = 1;\n }\n foreach (int i; 1 .. str.length)\n {\n if (str[i] == '0' || str[i] == '?')\n {\n dp[i][0][0] = (dp[i][0][0] + dp[i - 1][0][0]) % mod;\n dp[i][0][0] = (dp[i][0][0] + dp[i - 1][1][1]) % mod;\n }\n if (str[i] == '1' || str[i] == '?')\n {\n dp[i][1][0] = (dp[i][1][0] + dp[i - 1][0][0]) % mod;\n dp[i][1][0] = (dp[i][1][0] + dp[i - 1][1][1]) % mod;\n dp[i][1][1] = (dp[i][1][1] + dp[i - 1][3][0]) % mod;\n }\n if (str[i] == '2' || str[i] == '?')\n {\n dp[i][2][1] = (dp[i][2][1] + dp[i - 1][3][0]) % mod;\n }\n if (str[i] == '*' || str[i] == '?')\n {\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][1][0]) % mod;\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][2][1]) % mod;\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][3][0]) % mod;\n }\n }\n int ans = 0;\n ans = (ans + dp[str.length - 1][0][0]) % mod;\n ans = (ans + dp[str.length - 1][1][1]) % mod;\n ans = (ans + dp[str.length - 1][3][0]) % mod;\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n char[] str;\n while (stdin.readln(str))\n {\n str = chomp(str);\n solve(str);\n }\n}"}, {"source_code": "import std.stdio, std.string;\n\nvoid solve(char[] str)\n{\n immutable auto mod = 1000000007;\n if (str[0] == '2')\n {\n writeln(0);\n return;\n }\n int[][][] dp = new int[][][str.length + 10];\n foreach (int k; 0 .. str.length)\n {\n dp[k] = new int[][4];\n foreach (int i; 0 .. 4)\n {\n dp[k][i] = new int[2];\n }\n }\n if (str[0] == '*')\n {\n dp[0][3][0] = 1;\n }\n else if (str[0] == '0')\n {\n dp[0][0][0] = 1;\n }\n else if (str[0] == '1')\n {\n dp[0][1][0] = 1;\n }\n else if (str[0] == '?')\n {\n dp[0][0][0] = dp[0][1][0] = dp[0][3][0] = 1;\n }\n foreach (int i; 1 .. str.length)\n {\n if (str[i] == '0' || str[i] == '?')\n {\n dp[i][0][0] = (dp[i][0][0] + dp[i - 1][0][0]) % mod;\n dp[i][0][0] = (dp[i][0][0] + dp[i - 1][1][1]) % mod;\n }\n if (str[i] == '1' || str[i] == '?')\n {\n dp[i][1][0] = (dp[i][1][0] + dp[i - 1][0][0]) % mod;\n dp[i][1][0] = (dp[i][1][0] + dp[i - 1][1][1]) % mod;\n dp[i][1][1] = (dp[i][1][1] + dp[i - 1][3][0]) % mod;\n }\n if (str[i] == '2' || str[i] == '?')\n {\n dp[i][2][1] = (dp[i][2][1] + dp[i - 1][3][0]) % mod;\n }\n if (str[i] == '*' || str[i] == '?')\n {\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][1][0]) % mod;\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][2][1]) % mod;\n dp[i][3][0] = (dp[i][3][0] + dp[i - 1][3][0]) % mod;\n }\n }\n int ans = 0;\n ans = (ans + dp[str.length - 1][0][0]) % mod;\n ans = (ans + dp[str.length - 1][1][1]) % mod;\n ans = (ans + dp[str.length - 1][3][0]) % mod;\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n char[] str;\n while (stdin.readln(str))\n {\n str = chomp(str);\n solve(str);\n }\n}"}], "negative_code": [], "src_uid": "c16c49baf7b2d179764871204475036e"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main()\n{\n auto n = strip(readln());\n auto x = to!string(n.retro());\n auto res = n ~ x;\n writeln(res);\n\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.string;\n\nvoid main() {\n\n\tstring nstr = readln.strip;\n\n writeln(nstr, nstr.retro);\n}"}], "negative_code": [], "src_uid": "bcf75978c9ef6202293773cf533afadf"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip;\r\n\t\twriteln (s[0..$ / 2].sum == s[$ / 2..$].sum ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.string;\r\n\r\nint[] rtln(T)() { return to!(T[])(strip(readln).split(\"\")); }\r\n\r\nvoid main() {\r\n int t, n, m;\r\n readf(\"%d\\n\", t);\r\n while(t--) {\r\n auto arr = rtln!int;\r\n\t\tif ((arr[0] + arr[1] + arr[2]) == (arr[3]+arr[4]+arr[5]))\r\n\t\t\twriteln(\"YES\");\r\n\t\telse\r\n\t\t\twriteln(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan.map!(c => c - '0').array;\r\n \r\n auto a = N[0..3].sum;\r\n auto b = N[3..6].sum;\r\n\r\n return a == b ? \"YES\" : \"NO\";\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "negative_code": [], "src_uid": "c7a5b4a015e28dd3759569bbdc130e93"} {"source_code": "import std.algorithm, std.bigint, std.conv, std.stdio, std.string;\nvoid main () {\n\tauto n = readln.strip.to!int, s = readln.strip, i = n / 2, j = n - i;\n\twhile (s[i] == '0') i -= 1;\n\twhile (j < n && s[j] == '0') j += 1;\n\tauto res = BigInt (s);\n\tif (i > 0) res = min (res, BigInt (s[0..i]) + BigInt (s[i..$]));\n\tif (j < n) res = min (res, BigInt (s[0..j]) + BigInt (s[j..$]));\n\twriteln (res);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.bigint;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\tint i = n / 2;\n\t\tint j = n - i;\n\t\twhile (s[i] == '0')\n\t\t{\n\t\t\ti -= 1;\n\t\t}\n\t\twhile (j < n && s[j] == '0')\n\t\t{\n\t\t\tj += 1;\n\t\t}\n\t\tauto res = BigInt (s);\n\t\tif (i > 0)\n\t\t{\n\t\t\tres = min (res, BigInt (s[0..i]) + BigInt (s[i..$]));\n\t\t}\n\t\tif (j < n)\n\t\t{\n\t\t\tres = min (res, BigInt (s[0..j]) + BigInt (s[j..$]));\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport std.bigint;\n\nT readNum(T)(){\n return readStr.to!T;\n}\n\nT[] readNums(T)(){\n return readStr.split.to!(T[]);\n}\n\nstring readStr(){\n return readln.chomp;\n}\n\nvoid main(){\n auto n = readNum!int;\n string s = readStr;\n\n BigInt ret = s;\n\n auto c = s.length / 2;\n auto found = false;\n auto d = s.length % 2 == 1 ? 1 : 0;\n auto p = s.length % 2 == 1 ? 1 : 0;\n\n while(1){\n if(s[c-d+p] != '0'){\n BigInt l = s[0 .. c-d+p];\n BigInt r = s[c-d+p .. $];\n\n ret = min(ret, l+r);\n found = true;\n }\n\n if(s[c+d] != '0'){\n BigInt l = s[0 .. c+d];\n BigInt r = s[c+d .. $];\n\n ret = min(ret, l+r);\n found = true;\n }\n\n if(found) break;\n else d++;\n }\n\n writeln(ret);\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\nimport std.bigint;\n\nalias Tree = RBT!int;\nalias ll = long;\n\nvoid main() {\n GC.disable();\n\n int l;\n readf(\" %s\\n\", l);\n string s = readln.strip;\n\n int idx = s.length/2;\n while(idx >= 0 && idx < s.length) {\n if (s[idx] != '0') break;\n idx--;\n }\n\n BigInt ans = s;\n if (idx > 0 && idx < s.length) {\n BigInt a = s[0 .. idx];\n BigInt b = s[idx .. $];\n BigInt ss = a + b;\n ans = min(ans, ss);\n }\n\n idx = s.length/2+1;\n\n while(idx >= 0 && idx < s.length) {\n if (s[idx] != '0') break;\n idx++;\n }\n\n if (idx > 0 && idx < s.length) {\n BigInt a = s[0 .. idx];\n BigInt b = s[idx .. $];\n BigInt ss = a + b;\n ans = min(ans, ss);\n }\n\n writeln(ans);\n\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.bigint;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\tint i = n / 2;\n\t\tint j = n - i;\n\t\twhile (s[i] == '0')\n\t\t{\n\t\t\ti -= 1;\n\t\t}\n\t\twhile (j < n && s[j] == '0')\n\t\t{\n\t\t\tj += 1;\n\t\t}\n\t\twriteln (i, \" \", j);\n\t\tauto res = BigInt (s);\n\t\tif (i > 0)\n\t\t{\n\t\t\tres = min (res, BigInt (s[0..i]) + BigInt (s[i..$]));\n\t\t}\n\t\tif (j < n)\n\t\t{\n\t\t\tres = min (res, BigInt (s[0..j]) + BigInt (s[j..$]));\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "08bce37778b7bfe478340d5c222ae362"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N, K, P;\nint[] A;\n\nint[][] solve() {\n\tint[][] as = new int[][2];\n\tforeach (a; A) {\n\t\tas[a % 2] ~= a;\n\t}\n\tif (as[1].length < K - P) {\n\t\treturn null;\n\t}\n\tint[][][] rets = new int[][][2];\n\t\n\tint[] rs;\n\tforeach (idx, a; as[1]) {\n\t\tif (idx < K - P) {\n\t\t\trets[1] ~= [ a ];\n\t\t} else {\n\t\t\trs ~= a;\n\t\t}\n\t}\n\tif (rs.length % 2 != 0) {\n\t\treturn null;\n\t}\n\t\n\tint[][] groups;\n\tforeach (a; as[0]) {\n\t\tgroups ~= [ a ];\n\t}\n\tfor (int j = 0; j < rs.length; j += 2) {\n\t\tgroups ~= rs[j .. j + 2];\n\t}\n\tif (groups.length < P) {\n\t\treturn null;\n\t}\n\tforeach (idx, group; groups) {\n\t\tif (idx < P) {\n\t\t\trets[0] ~= group;\n\t\t} else {\n\t\t\trets[(0 < P) ? 0 : 1][0] ~= group;\n\t\t}\n\t}\n\treturn rets[0] ~ rets[1];\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = readInt;\n\t\tP = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tif (auto res = solve) {\n\t\t\twriteln(\"YES\");\n\t\t\tforeach (line; res) {\n\t\t\t\twriteln(line.length, \" \", line.to!string.removechars(\"[],\"));\n\t\t\t}\n\t\t} else {\n\t\t\twriteln(\"NO\");\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid solve(int[] a, int n, int k, int p)\n{\n int[] odd, even;\n foreach (val; a)\n {\n if (val & 1)\n {\n odd ~= val;\n }\n else\n {\n even ~= val;\n }\n }\n auto evenAns = new int[][p + 1];\n auto oddAns = new int[][k - p + 1];\n int i, j, t, oddIdx, evenIdx;\n for (i = 0, j = 0; i < p && j < even.length; ++ i, ++ j)\n {\n evenAns[i] ~= even[j];\n }\n evenIdx = j;\n for (t = 0, j = 0; t < k - p && j < odd.length; ++ t, ++ j)\n {\n oddAns[t] ~= odd[j];\n }\n oddIdx = j;\n if (t < k - p)\n {\n writeln(\"NO\");\n return;\n }\n else if (i < p)\n {\n auto evenNeed = p - i;\n auto oddLeft = odd.length - oddIdx;\n if (oddLeft % 2 != 0 || (oddLeft >> 1) < evenNeed)\n {\n writeln(\"NO\");\n return;\n }\n j = oddIdx;\n while (i < p)\n {\n evenAns[i] ~= odd[j];\n evenAns[i] ~= odd[j + 1];\n ++ i;\n j += 2;\n }\n while (j < odd.length)\n {\n evenAns[p - 1] ~= odd[j];\n ++ j;\n }\n }\n else\n {\n auto oddLeft = odd.length - oddIdx;\n if (oddLeft & 1)\n {\n writeln(\"NO\");\n return;\n }\n for (j = oddIdx; j < odd.length; j += 2)\n {\n if (p > 0)\n {\n evenAns[p - 1] ~= odd[j];\n evenAns[p - 1] ~= odd[j + 1];\n }\n else\n {\n oddAns[k - p - 1] ~= odd[j];\n oddAns[k - p - 1] ~= odd[j + 1];\n }\n }\n for (j = evenIdx; j < even.length; ++ j)\n {\n if (p > 0)\n {\n evenAns[p - 1] ~= even[j];\n }\n else\n {\n oddAns[k - p - 1] ~= even[j];\n }\n }\n }\n writeln(\"YES\");\n foreach (idx; 0 .. p)\n {\n writef(\"%d \", evenAns[idx].length);\n foreach (val; evenAns[idx])\n {\n writef(\"%d \", val);\n }\n writeln();\n }\n foreach (idx; 0 .. k - p)\n {\n writef(\"%d \", oddAns[idx].length);\n foreach (val; oddAns[idx])\n {\n writef(\"%d \", val);\n }\n writeln();\n }\n}\n\nint main(string[] args)\n{\n int n, k, p;\n while (scanf(\"%d%d%d\", &n, &k, &p) == 3)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n scanf(\"%d\", &a[i]);\n }\n solve(a, n, k, p);\n }\n return 0;\n}"}], "negative_code": [{"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid solve(int[] a, int n, int k, int p)\n{\n int[] odd, even;\n foreach (i, val; a)\n {\n if (val & 1)\n {\n odd ~= val;\n }\n else\n {\n even ~= val;\n }\n }\n auto evenAns = new int[][p];\n auto oddAns = new int[][k - p];\n int i, j, t, oddIdx, evenIdx;\n for (i = 0, j = 0; i < p && j < even.length; ++ i, ++ j)\n {\n evenAns[i] ~= even[j];\n }\n evenIdx = j;\n for (t = 0, j = 0; t < k - p && j < odd.length; ++ t, ++ j)\n {\n oddAns[t] ~= odd[j];\n }\n oddIdx = j;\n if (t < k - p)\n {\n writeln(\"NO\");\n return;\n }\n else if (i < p)\n {\n auto evenNeed = p - i;\n auto oddLeft = odd.length - oddIdx;\n if (oddLeft % 2 != 0 || (oddLeft >> 1) < evenNeed)\n {\n writeln(\"NO\");\n return;\n }\n j = oddIdx;\n while (i < p)\n {\n evenAns[i] ~= odd[j];\n evenAns[i] ~= odd[j + 1];\n ++ i;\n ++ j;\n }\n while (j < odd.length)\n {\n evenAns[$ - 1] ~= odd[j];\n ++ j;\n }\n }\n else\n {\n auto oddLeft = odd.length - oddIdx;\n if (oddLeft & 1)\n {\n writeln(\"NO\");\n return;\n }\n for (j = oddIdx; j < odd.length; j += 2)\n {\n evenAns[$ - 1] ~= odd[j];\n evenAns[$ - 1] ~= odd[j + 1];\n }\n for (j = evenIdx; j < even.length; ++ j)\n {\n evenAns[$ - 1] ~= even[j];\n }\n }\n writeln(\"YES\");\n foreach (idx; 0 .. p)\n {\n writef(\"%d \", evenAns[idx].length);\n foreach (val; evenAns[idx])\n {\n writef(\"%d \", val);\n }\n writeln();\n }\n foreach (idx; 0 .. k - p)\n {\n writef(\"%d \", oddAns[idx].length);\n foreach (val; oddAns[idx])\n {\n writef(\"%d \", val);\n }\n writeln();\n }\n}\n\nint main(string[] args)\n{\n int n, k, p;\n while (scanf(\"%d%d%d\", &n, &k, &p) == 3)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n scanf(\"%d\", &a[i]);\n }\n solve(a, n, k, p);\n }\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid solve(int[] a, int n, int k, int p)\n{\n int[] odd, even;\n foreach (i, val; a)\n {\n if (val & 1)\n {\n odd ~= val;\n }\n else\n {\n even ~= val;\n }\n }\n auto evenAns = new int[][p];\n auto oddAns = new int[][k - p];\n int i, j, t, oddIdx, evenIdx;\n for (i = 0, j = 0; i < p && j < even.length; ++ i, ++ j)\n {\n evenAns[i] ~= even[j];\n }\n evenIdx = j;\n for (t = 0, j = 0; t < k - p && j < odd.length; ++ t, ++ j)\n {\n oddAns[t] ~= odd[j];\n }\n oddIdx = j;\n if (t < k - p)\n {\n writeln(\"NO\");\n return;\n }\n else if (i < p)\n {\n auto evenNeed = p - i;\n auto oddLeft = odd.length - oddIdx;\n if (oddLeft % 2 != 0 || (oddLeft << 1) < evenNeed)\n {\n writeln(\"NO\");\n return;\n }\n j = oddIdx;\n while (i < p)\n {\n evenAns[i] ~= odd[j];\n evenAns[i] ~= odd[j + 1];\n ++ i;\n ++ j;\n }\n while (j < odd.length)\n {\n evenAns[$ - 1] ~= odd[j];\n ++ j;\n }\n }\n else\n {\n auto oddLeft = odd.length - oddIdx;\n if (oddLeft & 1)\n {\n writeln(\"NO\");\n return;\n }\n for (j = oddIdx; j < odd.length; j += 2)\n {\n evenAns[$ - 1] ~= odd[j];\n evenAns[$ - 1] ~= odd[j + 1];\n }\n for (j = evenIdx; j < even.length; ++ j)\n {\n evenAns[$ - 1] ~= even[j];\n }\n }\n writeln(\"YES\");\n foreach (idx; 0 .. p)\n {\n writef(\"%d \", evenAns[idx].length);\n foreach (val; evenAns[idx])\n {\n writef(\"%d \", val);\n }\n writeln();\n }\n foreach (idx; 0 .. k - p)\n {\n writef(\"%d \", oddAns[idx].length);\n foreach (val; oddAns[idx])\n {\n writef(\"%d \", val);\n }\n writeln();\n }\n}\n\nint main(string[] args)\n{\n int n, k, p;\n while (scanf(\"%d%d%d\", &n, &k, &p) == 3)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n scanf(\"%d\", &a[i]);\n }\n solve(a, n, k, p);\n }\n return 0;\n}"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N, K, P;\nint[] A;\n\nint[][] solve() {\n\tint[][] as = new int[][2];\n\tforeach (a; A) {\n\t\tas[a % 2] ~= a;\n\t}\n\tif (as[1].length < K - P) {\n\t\treturn null;\n\t}\n\tif ((as[1].length - (K - P)) % 2 != 0) {\n\t\treturn null;\n\t}\n\tint[][][] rets = new int[][][2];\n\tint[] rs = as[0];\n\tforeach (idx, a; as[1]) {\n\t\tif (idx < K - P) {\n\t\t\trets[1] ~= [ a ];\n\t\t} else {\n\t\t\trs ~= a;\n\t\t}\n\t}\n\tforeach (idx, a; rs) {\n\t\tif (idx < P) {\n\t\t\trets[0] ~= [ a ];\n\t\t} else {\n\t\t\trets[0][0] ~= a;\n\t\t}\n\t}\n\treturn rets[0] ~ rets[1];\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = readInt;\n\t\tP = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tif (auto res = solve) {\n\t\t\twriteln(\"YES\");\n\t\t\tforeach (line; res) {\n\t\t\t\twriteln(line.length, \" \", line.to!string.removechars(\"[],\"));\n\t\t\t}\n\t\t} else {\n\t\t\twriteln(\"NO\");\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "src_uid": "5185f842c7c24d4118ae3661f4418a1d"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto a = ma(n, readInt!int);\n sort(a);\n foreach(i; 1 .. 1 + n/2)\n {\n writeln(a[i], \" \", a[0]);\n }\n writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto arr = scanArray;\n arr.sort;\n auto k = arr[0];\n for(int i = n/2 + (n % 2 != 0); i < n; ++i){\n writeln(arr[i], \" \", k);\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nstruct S { int x, y; };\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!int).array.sort.array;\n bool[int] nums;\n foreach (x ; a)\n nums[x] = true;\n bool[S] used;\n S[] ans;\n\n while (ans.length < n / 2) {\n int x = a[uniform(0, a.length)];\n int y = a[uniform(0, a.length)];\nagain:\n if (x < y)\n swap(x, y);\n if (x == y || (S(x, y) in used))\n continue;\n int z = x % y;\n if (!(z in nums)) {\n ans ~= S(x, y);\n used[S(x, y)] = true;\n } else {\n y = z;\n goto again;\n }\n }\n foreach (tmp ; ans) {\n writefln(\"%d %d\", tmp.x, tmp.y);\n }\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nstruct S { int x, y; };\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!int).array.sort.array;\n bool[int] nums;\n foreach (x ; a)\n nums[x] = true;\n bool[S] used;\n S[] ans;\n foreach_reverse (j ; 0 .. a.length) {\n foreach (i ; 0 .. j) {\n int x = a[j];\n int y = a[i];\n if ((S(x, y) in used) || ((x % y) in nums))\n continue;\n ans ~= S(x, y);\n used[S(x, y)] = true;\n }\n }\n/*\n while (ans.length < n / 2) {\n int x = a[uniform(0, a.length)];\n int y = a[uniform(0, a.length)];\n if (x < y)\n swap(x, y);\n if (x == y || (S(x, y) in used) || ((x % y) in nums))\n continue;\n ans ~= S(x, y);\n used[S(x, y)] = true;\n }\n*/\n foreach (tmp ; ans) {\n writefln(\"%d %d\", tmp.x, tmp.y);\n }\n }\n}\n"}], "src_uid": "6d5ecac49fe1320eef1391b6d5cf5f0d"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\twriteln(4 + n * 3);\n\twriteln(\"0 0\");\n\twriteln(\"0 1\");\n\twriteln(\"1 0\");\n\twriteln(\"1 1\");\n\n\tforeach (i; 0..n)\n\t{\n\t\twriteln(i+2, \" \", i+2);\n\t\twriteln(i+1, \" \", i+2);\n\t\twriteln(i+2, \" \", i+1);\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "// Code By H~$~C\n\nimport std.stdio, std.format;\nimport std.math, std.uni, std.bigint, std.numeric;\nimport std.array, std.string, std.container, std.range, std.typecons;\nimport std.algorithm, std.conv, std.functional, std.random;\n\nvoid _Main() {\n int n;\n readf!\" %s\"(n);\n writeln(3 * n + 4);\n writeln(\"0 0\\n0 1\");\n foreach(i; 0 .. n) {\n writefln!\"%s %s\\n%s %s\\n%s %s\"(i + 1, i, i + 1, i + 1, i + 1, i + 2);\n }\n writefln!\"%s %s\\n%s %s\"(n + 1, n, n + 1, n + 1);\n}\n\nvoid main(string[] args) {\n int tests = 1;\n// readf!\" %d\"(tests);\n foreach (test; 0 .. tests) _Main();\n}\n\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n debug {\n writeln(\"N = \", N);\n }\n \n writeln(3 * (N + 1) + 1);\n foreach (i; 0 .. N + 1) {\n writeln(i, \" \", i);\n writeln(i, \" \", i + 1);\n writeln(i + 1, \" \", i);\n }\n writeln(N + 1, \" \", N + 1);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\twriteln (n * 3 + 4);\n\t\twriteln (0, \" \", 0);\n\t\tforeach (i; 0..n + 1)\n\t\t{\n\t\t\tforeach (j; 0..2)\n\t\t\t{\n\t\t\t\tforeach (k; 0..2)\n\t\t\t\t{\n\t\t\t\t\tif (j + k > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (i + j, \" \", i + k);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n debug {\n writeln(\"N = \", N);\n }\n \n foreach (i; 0 .. N + 1) {\n writeln(i, \" \", i);\n writeln(i, \" \", i + 1);\n writeln(i + 1, \" \", i);\n }\n writeln(N + 1, \" \", N + 1);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "d87c40ae942f3c378bde372f3320a09f"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 998244353;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!long).array;\n auto C = readln.split.map!(to!long).array;\n\n auto B = N.iota.map!(i => tuple(C[i], i)).array;\n B.sort();\n int p = 0;\n\n foreach (_; 0..M) {\n\n s = readln.split.map!(to!int);\n auto t = s[0] - 1;\n auto d = s[1].to!long;\n long ans = 0;\n\n if (A[t] >= d) {\n writeln(C[t] * d);\n A[t] -= d;\n } else {\n ans += A[t] * C[t];\n d -= A[t];\n A[t] = 0;\n while (d > 0 && p < N) {\n while (p < N && A[B[p][1]] == 0) ++p;\n if (p >= N) break;\n long v = min(d, A[B[p][1]]);\n ans += v * C[B[p][1]];\n A[B[p][1]] -= v;\n d -= v;\n }\n if (d == 0) {\n writeln(ans);\n } else {\n writeln(0);\n }\n }\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\nenum inf3 = 1_001_001_001;\nenum inf6 = 1_001_001_001_001_001_001L;\nenum mod = 1_000_000_007L;\n\nalias Dish = Tuple!(int, \"cost\", int, \"index\");\n\nvoid main() {\n int n, m;\n scan(n, m);\n auto a = readln.split.to!(int[]);\n auto c = readln.split.to!(int[]);\n\n auto ds = new Dish[](n);\n foreach (i ; 0 .. n) {\n ds[i] = Dish(c[i], i);\n }\n\n ds.sort!();\n\n foreach (j ; 0 .. m) {\n int tj, dj;\n scan(tj, dj);\n tj--;\n\n long ans;\n\n if (a[tj] > 0) {\n int x = min(dj, a[tj]);\n ans += 1L * x * c[tj];\n a[tj] -= x;\n dj -= x;\n }\n\n while (dj > 0 && !ds.empty) {\n int cost = ds.front.cost;\n int ind = ds.front.index;\n\n int x = min(dj, a[ind]);\n ans += 1L * x * c[ind];\n a[ind] -= x;\n dj -= x;\n\n if (a[ind] == 0) {\n ds.popFront();\n }\n }\n\n if (dj > 0) {\n ans = 0;\n }\n\n writeln(ans);\n }\n}\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "2553ffea6d74fded12128e9db0db85dc"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto a = ma(n, readInt!int);\n\tint[2][] vis;\n\tauto ft = FenwickTree(n);\n\tforeach(i, ai; a) vis ~= [ai, cast(int)i];\n\tsort(vis);\n\tauto less = new int[](n);\n\tauto equal = new int[](n);\n\t{\n\t\tint i = 0;\n\t\twhile (i < n)\n\t\t{\n\t\t\tauto v = vis[i][0];\n\t\t\tint[] _is;\n\t\t\twhile (i < n && vis[i][0] == v)\n\t\t\t{\n\t\t\t\t_is ~= vis[i][1];\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tint cnt = 0;\n\t\t\tforeach(j; _is)\n\t\t\t{\n\t\t\t\tless[j] = ft.sum(j-1);\n\t\t\t\tequal[j] = cnt++;\n\t\t\t}\n\t\t\tforeach(j; _is)\n\t\t\t{\n\t\t\t\tft.add(j, 1);\n\t\t\t}\n\t\t}\n\t}\n\tauto deque = DList!int();\n\tlong mininvs = 0;\n\tdebug writeln(less);\n\tforeach(i; 0 .. n)\n\t{\n\t\tauto l = less[i];\n\t\tauto e = equal[i];\n\t\tauto g = i - l - e;\n\t\tmininvs += min(l, g);\n\t}\n\twriteln(mininvs);\n}\nstruct FenwickTree {\n\tint[] bit;\n\tint n;\n\n\tthis(int n) {\n\t\tthis.n = n;\n\t\tbit = new int[](n);\n\n\t}\n\n\tint sum(int r) {\n\t\tint ret = 0;\n\t\tfor (; r >= 0; r = (r & (r + 1)) - 1)\n\t\t\tret += bit[r];\n\t\treturn ret;\n\t}\n\n\tint sum(int l, int r) {\n\t\treturn sum(r) - sum(l - 1);\n\t}\n\n\tvoid add(int idx, int delta) {\n\t\tfor (; idx < n; idx = idx | (idx + 1))\n\t\t\tbit[idx] += delta;\n\t}\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nstruct fw {\r\n int[] arr;\r\n int sz;\r\n \r\n this(int sz) {\r\n this.sz = sz;\r\n arr = new int[sz+1];\r\n arr[] = 0;\r\n }\r\n \r\n void add(int p) {\r\n while (p <= sz) {\r\n arr[p] += 1;\r\n p += (1 << p.bsf);\r\n }\r\n }\r\n \r\n int sum(int p) {\r\n int ret = 0;\r\n while (p > 0) {\r\n ret += arr[p];\r\n p -= (1 << p.bsf);\r\n }\r\n \r\n return ret;\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n \r\n while (t--) {\r\n int n;\r\n readf!\"%s\"(n);\r\n readln;\r\n \r\n auto arr = readln.chomp.split.map!(to!int).array;\r\n \r\n auto uni = arr.dup.sort.uniq.array;\r\n int[int] mapping;\r\n foreach (i, e; uni.enumerate(1)) { mapping[e] = i; }\r\n arr = arr.map!(x => mapping[x]).array;\r\n \r\n debug { writeln(uni, ' ' , mapping, ' ', arr); }\r\n \r\n auto f = fw(uni.length.to!int);\r\n long ans = 0;\r\n foreach (i, e; arr) {\r\n auto smaller = f.sum(e-1);\r\n auto bigger = i - f.sum(e);\r\n \r\n ans += min(smaller, bigger);\r\n \r\n f.add(e);\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nstruct fw {\r\n int[] arr;\r\n int sz;\r\n \r\n this(int sz) {\r\n this.sz = sz;\r\n arr = new int[sz+1];\r\n arr[] = 0;\r\n }\r\n \r\n void add(int p) {\r\n while (p <= sz) {\r\n arr[p] += 1;\r\n p += (1 << p.bsf);\r\n }\r\n }\r\n \r\n int sum(int p) {\r\n int ret = 0;\r\n while (p > 0) {\r\n ret += arr[p];\r\n p -= (1 << p.bsf);\r\n }\r\n \r\n return ret;\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n \r\n while (t--) {\r\n int n;\r\n readf!\"%s\"(n);\r\n readln;\r\n \r\n auto arr = readln.chomp.split.map!(to!int).array;\r\n \r\n auto uni = arr.dup.sort.uniq.array;\r\n int[int] mapping;\r\n foreach (i, e; uni.enumerate(1)) { mapping[e] = i; }\r\n arr = arr.map!(x => mapping[x]).array;\r\n \r\n debug { writeln(uni, ' ' , mapping, ' ', arr); }\r\n \r\n auto f = fw(uni.length.to!int);\r\n int ans = 0;\r\n foreach (i, e; arr) {\r\n auto smaller = f.sum(e-1);\r\n auto bigger = i - f.sum(e);\r\n \r\n ans += min(smaller, bigger);\r\n \r\n f.add(e);\r\n }\r\n \r\n ans.writeln;\r\n }\r\n}"}], "src_uid": "aa78a750cac45117f7b4313928c50f76"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto b = RD!string;\n\t\tauto begin = b[0];\n\t\tauto end = b[$-1];\n\t\tforeach (i; 1..b.length-1)\n\t\t{\n\t\t\tif (i % 2 == 0) continue;\n\t\t\tans[ti] ~= b[i];\n\t\t}\n\t\tans[ti] = begin ~ ans[ti] ~ end;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.string : strip;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n auto s = readln.strip;\n writeln(s.takeOne.chain(s.dropOne.stride(2)));\n }\n}"}], "negative_code": [], "src_uid": "ac77e2e6c86b5528b401debe9f68fc8e"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!long);\n auto N = s[0];\n auto Q = s[1];\n\n while (Q--) {\n s = readln.split.map!(to!long);\n auto r = s[0];\n auto c = s[1];\n if ((r + c) % 2 == 0) {\n long odd = r / 2;\n long even = r - 1 - odd;\n long n = odd * (N / 2 + N % 2) + even * (N / 2);\n writeln(n + (c - 1) / 2 + 1);\n } else {\n long odd = r / 2;\n long even = r - 1 - odd;\n long n = odd * (N / 2) + even * (N / 2 + N % 2);\n n += N * N / 2 + N % 2;\n writeln(n + (c - 1) / 2 + 1);\n }\n }\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nlong f(int n, int x, int y) {\n auto sumOdd = (x+y) % 2 == 1;\n auto rowOdd = x % 2 == 1;\n auto prevRows = n % 2 == 0 ?\n cast(long)(x-1) * n/2 :\n cast(long)(x-1)/2 * (n/2 + n/2 + 1) + (!rowOdd ? (sumOdd ? n/2 : n/2+1) : 0);\n auto prevCols = (y-1) / 2;\n return 1 + prevRows + prevCols + (sumOdd ? f(n, n, n) : 0);\n}\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n\n while (q--) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n f(n, x, y).writeln;\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!long);\n auto N = s[0];\n auto Q = s[1];\n\n while (Q--) {\n s = readln.split.map!(to!long);\n auto r = s[0];\n auto c = s[1];\n if ((r + c) % 2 == 0) {\n long odd = r / 2;\n long even = r - 1 - odd;\n long n = odd * (N / 2 + N % 2) + even * N / 2;\n writeln(n + (c - 1) / 2 + 1);\n } else {\n long odd = r / 2;\n long even = r - 1 - odd;\n long n = odd * N / 2 + even * (N / 2 + N % 2);\n n += N * N / 2 + N % 2;\n writeln(n + (c - 1) / 2 + 1);\n }\n }\n}\n"}], "src_uid": "3c48123f326fb79ce2e4e17e1e0765f8"} {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tchar[] cs = readln.chomp.to!(char[]);\n\t\n\t\n\tif(n % 2 > 0){ // this matters only for n = 1\n\t\twriteln(\":(\");\n\t\treturn;\n\t}\n\t\n\tif(cs[0] == ')' || cs[$ - 1] == '('){\n\t\twriteln(\":(\");\n\t\treturn;\n\t}\n\t\n\tauto cntleft = cs.count!(x => x == '(');\n\tauto cntright = cs.count!(x => x == ')');\n\tif( cntleft > n / 2 || cntright > n / 2){\n\t\twriteln(\":(\");\n\t\treturn;\n\t}\n\t\n\tauto lackleft = n / 2 - cntleft;\n\tauto lackright = n / 2 - cntright;\n\tforeach(i; 0 .. n){\n\t\tif(cs[i] == '?') lackleft -= 1, cs[i] = '(';\n\t\tif(lackleft == 0) break;\n\t}\n\tforeach_reverse(i; 0 .. n){\n\t\tif(cs[i] == '?') lackright -= 1, cs[i] = ')';\n\t\tif(lackright == 0) break;\n\t}\n\t\n\tint depth = 0;\n\tforeach(i; 0 .. n){\n\t\tif(cs[i] == '(') depth += 1;\n\t\telse depth -= 1;\n\t\tif(i < n - 1 && depth == 0){\n\t\t\twriteln(\":(\");\n\t\t\treturn;\n\t\t}\n\t}\n\t\n\tcs.to!string.writeln;\n}\n\n/*\n\n- Fail if n is odd\n- Fail if the leftmost is )\n- Fail if the rightmost is (\n- Fail if there are too many (s\n- Fail if there are too many )s\n~ Otherwise, try this:\n - Fill with ( from the left end until (s are enough\n - Fill with ) from the right end until )s are enough\n- If the result is valid, it is valid\n- Otherwise, it is failure\n\n*/\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nimmutable string NO = \":(\";\n\nstring solve (int n, string s)\n{\n\tif (n & 1)\n\t{\n\t\treturn NO;\n\t}\n\tauto a = n / 2 - s.count ('(').to !(int);\n\tauto b = n / 2 - s.count (')').to !(int);\n\tif (a < 0 || b < 0)\n\t{\n\t\treturn NO;\n\t}\n\tauto t = s.dup;\n\tforeach (ref c; t)\n\t{\n\t\tif (c == '?')\n\t\t{\n\t\t\tif (a > 0)\n\t\t\t{\n\t\t\t\tc = '(';\n\t\t\t\ta -= 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tc = ')';\n\t\t\t\tb -= 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tint balance = 0;\n\tforeach (ref c; t[0..$ - 1])\n\t{\n\t\tbalance += (c == '(') ? +1 : -1;\n\t\tif (balance <= 0)\n\t\t{\n\t\t\treturn NO;\n\t\t}\n\t}\n\n\treturn t.idup;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\twriteln (solve (n, s));\n\t}\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n\n if (N % 2 == 1) {\n \":(\".writeln;\n return;\n }\n\n int open = N / 2 - S.map!(s => s == '(').sum;\n int tmp = 0;\n\n dchar[] ans;\n\n foreach (i; 0..N) {\n if (S[i] == '(') {\n tmp += 1;\n ans ~= '(';\n } else if (S[i] == ')') {\n tmp -= 1;\n ans ~= ')';\n } else if (open > 0) {\n tmp += 1;\n open -= 1;\n ans ~= '(';\n } else {\n tmp -= 1;\n ans ~= ')';\n }\n if (i != N - 1 && tmp <= 0) {\n \":(\".writeln;\n return;\n } else if (i == N - 1 && tmp != 0) {\n \":(\".writeln;\n return;\n }\n }\n\n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto s = readln.chomp;\n \n if (n % 2 != 0) {\n writeln(\":(\");\n return;\n }\n \n int open = n / 2 - s.count!(x => x == '(').to!int;\n int v = 0;\n string ans;\n foreach (i, e; s) {\n dchar nxt = e;\n if (e == '?') {\n if (open > 0) {\n nxt = '(';\n --open;\n } else {\n nxt = ')';\n }\n }\n \n ans ~= nxt;\n \n if (nxt == '(') { ++v; }\n else { --v; }\n \n if (v < 0 || (v == 0 && i < n-1)) {\n writeln(\":(\");\n return;\n }\n }\n \n if (v != 0) {\n writeln(\":(\");\n return;\n }\n \n writeln(ans);\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto s = readln.chomp;\n \n if (n % 2 != 0) {\n writeln(\":(\");\n return;\n }\n \n int open = n / 2 - s.count!(x => x == '(').to!int;\n int v = 0;\n string ans;\n foreach (i, e; s) {\n dchar nxt = e;\n if (e == '?') {\n if (open > 0) {\n nxt = '(';\n --open;\n } else {\n nxt = ')';\n }\n }\n \n ans ~= nxt;\n \n if (nxt == '(') { ++v; }\n else { --v; }\n \n if (v < 0 || (v == 0 && i < n-1)) {\n writeln(\":(\");\n return;\n }\n }\n \n writeln(ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.string;\n\nimmutable string NO = \":(\";\n\nstring solve (int n, string s)\n{\n\tif (n & 1)\n\t{\n\t\treturn NO;\n\t}\n\tauto a = n / 2 - s.count ('(');\n\tauto b = n / 2 - s.count (')');\n\tif (a < 0 || b < 0)\n\t{\n\t\treturn NO;\n\t}\n\tauto t = s.dup;\n\tforeach (ref c; t)\n\t{\n\t\tif (c == '?')\n\t\t{\n\t\t\tif (a > 0)\n\t\t\t{\n\t\t\t\tc = '(';\n\t\t\t\ta -= 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tc = ')';\n\t\t\t\tb -= 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tint balance = 0;\n\tforeach (ref c; t[0..$ - 1])\n\t{\n\t\tbalance += (c == '(') ? +1 : -1;\n\t\tif (balance == 0)\n\t\t{\n\t\t\treturn NO;\n\t\t}\n\t}\n\n\treturn t.idup;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\twriteln (solve (n, s));\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.string;\n\nimmutable string NO = \":(\";\n\nstring solve (int n, string s)\n{\n\tif (n & 1)\n\t{\n\t\treturn NO;\n\t}\n\tauto a = n / 2 - s.count ('(');\n\tauto b = n / 2 - s.count (')');\n\tif (a < 0 || b < 0)\n\t{\n\t\treturn NO;\n\t}\n\tauto t = s.dup;\n\tforeach (ref c; t)\n\t{\n\t\tif (c == '?')\n\t\t{\n\t\t\tif (a > 0)\n\t\t\t{\n\t\t\t\tc = '(';\n\t\t\t\ta -= 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tc = ')';\n\t\t\t\tb -= 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tint balance = 0;\n\tforeach (ref c; t[0..$ - 1])\n\t{\n\t\tbalance += (c == '(') ? +1 : -1;\n\t\tif (balance <= 0)\n\t\t{\n\t\t\treturn NO;\n\t\t}\n\t}\n\n\treturn t.idup;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\twriteln (solve (n, s));\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tchar[] cs = readln.chomp.to!(char[]);\n\t\n\tif(cs[0] == ')' || cs[$ - 1] == '('){\n\t\twriteln(\":(\");\n\t\treturn;\n\t}\n\t\n\tauto cntleft = cs.count!(x => x == '(');\n\tauto cntright = cs.count!(x => x == ')');\n\tif( cntleft > n / 2 || cntright > n / 2){\n\t\twriteln(\":(\");\n\t\treturn;\n\t}\n\t\n\tauto lackleft = n / 2 - cntleft;\n\tauto lackright = n / 2 - cntright;\n\tforeach(i; 0 .. n){\n\t\tif(cs[i] == '?') lackleft -= 1, cs[i] = '(';\n\t\tif(lackleft == 0) break;\n\t}\n\tforeach_reverse(i; 0 .. n){\n\t\tif(cs[i] == '?') lackright -= 1, cs[i] = ')';\n\t\tif(lackright == 0) break;\n\t}\n\t\n\tint depth = 0;\n\tforeach(i; 0 .. n){\n\t\tif(cs[i] == '(') depth += 1;\n\t\telse depth -= 1;\n\t\tif(i < n - 1 && depth == 0){\n\t\t\twriteln(\":(\");\n\t\t\treturn;\n\t\t}\n\t}\n\t\n\tcs.to!string.writeln;\n}\n\n/*\n\n- Fail if the leftmost is )\n- Fail if the rightmost is (\n- Fail if there are too many (s\n- Fail if there are too many )s\n~ Otherwise, try this:\n - Fill with ( from the left end until (s are enough\n - Fill with ) from the right end until )s are enough\n- If the result is valid, it is valid\n- Otherwise, it is failure\n\n*/\n"}], "src_uid": "e03bec836d52fe4784a5b4c62ab5b2c8"} {"source_code": "import std.stdio, std.range, std.algorithm;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n, k;\r\n readf!\"%d %d\\n\"(n, k);\r\n int[] p = iota(1, k + 1).array;\r\n reverse(p[2 * k - n - 1 .. k]);\r\n p.writefln!\"%(%s %)\";\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, K; get(N, K);\r\n auto res = 1.iota(K + 1).array();\r\n if (N != K) {\r\n auto i = K - (N - K) - 1;\r\n reverse(res[i..$]);\r\n }\r\n writefln!\"%(%d %)\"(res);\r\n }\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\tauto p = iota (1, k + 1).array;\r\n\t\treverse (p[k + k - n - 1..k]);\r\n\t\twritefln !(\"%(%s %)\") (p);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\r\n\t\tans[ti].length = k;\r\n\t\tauto d = n-k;\r\n\t\tforeach (i; 0..k-d)\r\n\t\t{\r\n\t\t\tans[ti][i] = i+1;\r\n\t\t}\r\n\t\tforeach (i; k-d-1..k)\r\n\t\t{\r\n\t\t\tans[ti][i] = (k-1) - (i-(k-d));\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, K; get(N, K);\r\n auto res = 1.iota(K + 1).array();\r\n if (N != K) swap(res[$-1], res[$-2]);\r\n writefln!\"%(%d %)\"(res);\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, K; get(N, K);\r\n auto res = 1.iota(K + 1).array();\r\n if (N > K) {\r\n auto n = K - (N - K) - 1;\r\n swap(res[n], res[n + 1]);\r\n }\r\n writefln!\"%(%d %)\"(res);\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\r\n\t\tans[ti].length = k;\r\n\t\tforeach (i; 0..k)\r\n\t\t{\r\n\t\t\tans[ti][i] = i+1;\r\n\t\t}\r\n\t\tif (n == k) continue;\r\n\t\tauto d = n-k;\r\n\t\tans[ti] = ans[ti][0..k-d-1] ~ ans[ti][k-d..$] ~ (k-d);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\r\n\t\tans[ti].length = k;\r\n\t\tforeach (i; 0..k)\r\n\t\t{\r\n\t\t\tans[ti][i] = i+1;\r\n\t\t}\r\n\t\tif (n == k) continue;\r\n\t\tswap(ans[ti][$-2], ans[ti][$-1]);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "67de9506ac2458ee67346bae1a9e3926"} {"source_code": "import std;\n\nvoid main () {\n int t;\n readf(\"%s\\n\", t);\n\n foreach (_; 0..t) {\n int[3] l;\n readf(\"%s %s %s\\n\", l[0], l[1], l[2]);\n\n l = sort(l.dup).array;\n\n if (l[0] + l[1] == l[2])\n writeln(\"YES\");\n else if (l[0] == l[1] && l[2] % 2 == 0)\n writeln(\"YES\");\n else if (l[1] == l[2] && l[0] % 2 == 0)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n// \"\"\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.conv;\nimport std.algorithm;\n\nenum MOD = 998244353;\n\nvoid main()\n{\n ulong count = readln.split[0].to!int;\n foreach (line; 0 .. count)\n {\n ulong[3] nums;\n auto nptr = nums.ptr;\n scanf(\"%lu %lu %lu\", nptr, nptr + 1, nptr + 2);\n if (nums.sumCase)\n {\n writeln(\"yes\");\n\n }\n else if (nums.binCase)\n {\n writeln(\"yes\");\n }\n else\n writeln(\"NO\");\n\n }\n}\n\nauto sumCase(ulong[3] nums)\n{\n for (int i = 0; i < 3; i++)\n {\n if (nums[(0 + i) % 3] == nums[(1 + i) % 3] + nums[(2 + i) % 3])\n return true;\n }\n return false;\n}\n\nauto binCase(ulong[3] nums)\n{\n for (int i = 0; i < 3; i++)\n {\n if (nums[(0 + i) % 3] == nums[(1 + i) % 3] && nums[(2 + i) % 3] % 2 == 0)\n return true;\n }\n return false;\n}\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception, \n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nvoid main() {\n int n;\n read(n);\n while (n--) {\n int[] arr = list!int();\n sort(arr);\n if (arr[2] == arr[0] + arr[1]) writeln(\"YES\"); \n else if (arr[0] == arr[1] && arr[2] % 2 == 0) writeln(\"YES\"); \n else if (arr[2] == arr[1] && arr[0] % 2 == 0) writeln(\"YES\");\n else writeln(\"NO\"); \n }\n}\n\n"}, {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n long[] nums = readln.strip.split(\" \").to!(long[]);\r\n nums.sort();\r\n if (nums[2] - nums[1] == nums[0])\r\n writeln(\"YES\");\r\n else if ((nums[0] == nums[1]) && (nums[2] % 2 == 0))\r\n writeln(\"YES\");\r\n else if ((nums[1] == nums[2]) && (nums[0] % 2 == 0))\r\n writeln(\"YES\");\r\n else\r\n writeln(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "void main() { runSolver(); }\n\nvoid problem() {\n auto QN = scan!long;\n auto Q = scan!long(3 * QN).chunks(3);\n\n auto solve() {\n bool[] ans;\n\n foreach(q; Q) {\n bool qa;\n foreach(i; 0..3) {\n const a = q[(i + 0) % 3];\n const b = q[(i + 1) % 3];\n const c = q[(i + 2) % 3];\n\n if (a > b && (a - b == c)) qa = true;\n if (a > c && (a - c == b)) qa = true;\n if (a % 2 == 0 && b == c) qa = true;\n }\n\n ans ~= qa;\n }\n\n return ans.map!(a => a ? \"YES\" : \"NO\").array;\n }\n\n outputForAtCoder(&solve);\n}\n\n// ----------------------------------------------\n\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; }\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\nvoid deb(T ...)(T t){ debug writeln(t); }\nalias Point = Tuple!(long, \"x\", long, \"y\");\nPoint invert(Point p) { return Point(p.y, p.x); }\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\nalias MInt1 = ModInt!(10^^9 + 7);\nalias MInt9 = ModInt!(998_244_353);\nvoid outputForAtCoder(T)(T delegate() fn) {\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\n else static if (is(T == void)) fn();\n else static if (is(T == string)) fn().writeln;\n else static if (isInputRange!T) {\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\n else foreach(r; fn()) r.writeln;\n }\n else fn().writeln;\n}\nvoid runSolver() {\n enum BORDER = \"==================================\";\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\n else problem();\n}\nenum YESNO = [true: \"Yes\", false: \"No\"];\n\n// -----------------------------------------------\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto a = readln.splitter.map!(to!long).array.sort.array;\n if (a[0] + a[1] == a[2]) {\n writeln(\"YES\");\n } else {\n if ((a[0] == a[1] && a[2] % 2 == 0) ||\n (a[1] == a[2] && a[0] % 2 == 0)) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n }\n}\n"}], "negative_code": [], "src_uid": "a4a69a5fbf35781ff0849332a45566ca"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto edges = new int[][](N);\n foreach (i; 0..N-1) {\n auto s = readln.split.map!(to!int);\n edges[s[0] - 1] ~= s[1] - 1;\n edges[s[1] - 1] ~= s[0] - 1;\n }\n\n if (N == 1) {\n writeln(0);\n return;\n }\n\n\n auto dists = new int[](N);\n auto exp = new real[](N);\n\n void dfs1(int n, int p, int d) {\n dists[n] = d;\n foreach (m; edges[n]) if (m != p) dfs1(m, n, d + 1);\n }\n\n void dfs2(int n, int p, real e) {\n exp[n] = e;\n int cnt = 0;\n foreach (m; edges[n]) if (m != p) cnt += 1;\n foreach (m; edges[n]) if (m != p) dfs2(m, n, e / cnt);\n }\n\n dfs1(0, -1, 0);\n dfs2(0, -1, 1);\n real ans = 0;\n foreach (i; 1..N) if (edges[i].length == 1) ans += dists[i] * exp[i];\n writefln(\"%.9f\", ans);\n}\n", "positive_code": [{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio, std.string, std.conv, std.algorithm, std.array;\n\nT[] getVals(T)() { return to!(T[])(readln().chomp().split(\" \")); }\n\nstruct IP { int i; double p; }\n\nvoid main() {\n int n = getVals!(int)()[0];\n Appender!(int[])[100001] aps;\n for (int i=1;i<n;i++) {\n auto xy = getVals!(int)();\n int x = xy[0], y = xy[1];\n aps[x].put(y);\n aps[y].put(x);\n }\n bool[100001] flags;\n auto temp1 = appender!(IP[])();\n temp1.put(IP(1, 1.0));\n flags[1] = true;\n auto ans = 0.0;\n for (int k = 0; k <= n; k++) {\n auto temp2 = appender!(IP[])();\n foreach (v ; temp1.data) {\n int c = 0;\n foreach (j ; aps[v.i].data) {\n if (flags[j]) { continue; }\n c++;\n }\n if (c == 0) {\n ans += double(k) * v.p;\n } else {\n auto p = v.p / double(c);\n foreach (j ; aps[v.i].data) {\n if (flags[j]) { continue; }\n flags[j] = true;\n temp2.put(IP(j, p));\n }\n }\n }\n if (temp2.data.length == 0) {\n break;\n }\n temp1 = temp2;\n }\n writefln(\"%.8f\", ans);\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto edges = new int[][](N);\n foreach (i; 0..N-1) {\n auto s = readln.split.map!(to!int);\n edges[s[0] - 1] ~= s[1] - 1;\n edges[s[1] - 1] ~= s[0] - 1;\n }\n\n if (N == 1) {\n writeln(0);\n return;\n }\n\n\n long[] dists;\n\n void dfs(int n, int p, int d) {\n int cnt = 0;\n foreach (m; edges[n]) if (m != p) cnt += 1;\n if (cnt == 0) {\n dists ~= d;\n } else {\n foreach (m; edges[n]) if (m != p) dfs(m, n, d + 1);\n }\n }\n\n dfs(0, -1, 0);\n writefln(\"%.9f\", 1.0L * dists.sum / dists.length);\n}\n"}], "src_uid": "adaae163882b064bf7257e82e8832ffb"} {"source_code": "immutable multi = true;\nimport std.range;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto a = ma(n, readInt!int);\n\tauto b = ma(n, readInt!int);\n\tsort(a), sort(b);\n\twhile (a.length && b.length)\n\t{\n\t\tauto fa = a.front;\n\t\tauto fb = b.front;\n\t\tif (fa > fb) return writeln(\"NO\");\n\t\tif (fa < fb)\n\t\t{\n\t\t\tif (fa != fb - 1) return writeln(\"NO\");\n\t\t}\n\t\ta.popFront; b.popFront;\n\t}\n\tif (a.length || b.length) return writeln(\"NO\");\n\treturn writeln(\"YES\");\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\tsort (b);\r\n\t\twriteln (n.iota.map !(i => b[i] - a[i])\r\n\t\t .all !(x => 0 <= x && x <= 1) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n long n = scan;\n auto a = scanArray!int;\n auto b = scanArray!int;\n auto freqa = new ll[301];\n auto freqb = new ll[301];\n auto cache = new ll[301];\n for(int i = 0; i < n; ++i){\n ++freqa[a[i] + 100];\n ++freqb[b[i] + 100];\n }\n for(int i = 0; i <= 200; ++i){\n ll take = min(freqb[i], cache[i]);\n cache[i] -= take;\n ll left = freqb[i] - take;\n freqa[i] -= left;\n if(freqa[i] < 0){\n writeln(\"NO\");\n return;\n }\n cache[i+1] += freqa[i];\n freqa[i] = 0;\n }\n writeln(\"YES\");\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [], "src_uid": "6ca98e655007bfb86f1039c9f096557e"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.functional, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n string s = readln.strip;\n char minch = 'z';\n size_t minidx;\n foreach (i ; 0 .. s.length) {\n if (s[i] <= minch) {\n minch = s[i];\n minidx = i;\n }\n }\n writefln(\"%c %s\", minch, s[0 .. minidx] ~ s[minidx + 1 .. $]);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\n\t\tchar c = 'z';\n\t\tsize_t pos;\n\t\tforeach (i, e; s)\n\t\t{\n\t\t\tif (e < c)\n\t\t\t{\n\t\t\t\tpos = i;\n\t\t\t\tc = e;\n\t\t\t}\n\t\t}\n\n\t\tans[ti] = [c, ' '];\n\t\tforeach (i, e; s)\n\t\t{\n\t\t\tif (i == pos) continue;\n\t\t\tans[ti] ~= e;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "4a58039c5171597ecf78837e9db1d71d"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto m = scan!int;\n tup[] blocks;\n for(int i = 0; i < m; ++i){\n blocks ~= tup(scan!int - 1, scan!int);\n }\n blocks.sort!((a, b) => b[1] > a[1]);\n blocks ~= tup(0, n+1);\n blocks ~= tup(1, n+1);\n\n int norm = 0;\n int yprev = 0;\n foreach(ref block; blocks){\n if(block[1] == yprev){\n block[1] -= norm;\n continue;\n }\n int gap = (block[1] - (yprev + 1)) % 2;\n norm += (block[1] - (yprev+1) - gap);\n yprev = block[1];\n block[1] -= norm;\n }\n int len = (n+1) - norm;\n assert(len <= 1_000_000);\n\n auto table = new int[][](2, len+1);\n foreach(block; blocks){\n table[block[0]][block[1]] = 1;\n }\n table[0][0] = 1;\n table[1][0] = 1;\n show(table);\n\n for(int k = len-1; k > 0; --k){\n if(!table[0][k] && !table[1][k]){\n /* table[0][k] = 1; */\n /* table[1][k] = 1; */\n }else if(!table[0][k]){\n if(table[0][k-1]){\n writeln(\"NO\");\n return;\n }\n table[0][k-1] = 1;\n }else if(!table[1][k]){\n if(table[1][k-1]){\n writeln(\"NO\");\n return;\n }\n table[1][k-1] = 1;\n }\n }\n writeln(\"YES\");\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(int, int);\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\talias Block = Tuple !(int, q{col}, int, q{row});\r\n\t\tauto b = new Block [m];\r\n\t\tforeach (ref c; b)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s\") (c.row, c.col);\r\n\t\t\tc.row -= 1;\r\n\t\t\tc.col -= 1;\r\n\t\t}\r\n\t\tsort (b);\r\n\r\n\t\tint mask = 0;\r\n\t\tint prev = 0;\r\n\t\tbool ok = true;\r\n\t\tforeach (ref c; b)\r\n\t\t{\r\n\t\t\tif (prev % 2 != c.col % 2)\r\n\t\t\t{\r\n\t\t\t\tmask = (3 - mask) % 3;\r\n\t\t\t\tprev += 1;\r\n\t\t\t}\r\n\t\t\tif (prev != c.col)\r\n\t\t\t{\r\n\t\t\t\tmask %= 3;\r\n\t\t\t\tprev = c.col;\r\n\t\t\t}\r\n\t\t\tif (mask & (1 << c.row))\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t\tmask |= 1 << c.row;\r\n\t\t}\r\n\r\n\t\tok &= (mask % 3 == 0);\r\n\t\twriteln (ok ? \"Yes\" : \"No\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\r\n\t\tint[int] a;\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tauto r = RD!int;\r\n\t\t\tauto c = RD!int-1;\r\n\t\t\ta[c] |= r;\r\n\t\t}\r\n\t\tdebug writeln(\"a:\", a);\r\n\r\n\t\tauto keys = a.keys.sort;\r\n\t\tauto len = keys.length;\r\n\t\tint ud;\r\n\t\tint eo;\r\n\t\tbool ok = true;\r\n\t\tforeach (key; keys)\r\n\t\t{\r\n\t\t\tauto v = a[key];\r\n\t\t\tauto i = key;\r\n\t\t\tif (ud == 0)\r\n\t\t\t{\r\n\t\t\t\tif (v == 1 || v == 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tud = v;\r\n\t\t\t\t\teo = i % 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (v == 3)\r\n\t\t\t\t{\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tif (ud & v)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (eo == i % 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tok = false;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tud = 0;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (eo != i % 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tok = false;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tud = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tdebug writeln(\"ud:\", ud, \" eo:\", eo);\r\n\t\t}\r\n\t\tif (ud != 0)\r\n\t\t\tok = false;\r\n\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto m = scan!int;\n tup[] blocks;\n for(int i = 0; i < m; ++i){\n blocks ~= tup(scan!int - 1, scan!int);\n }\n blocks.sort!((a, b) => b[1] > a[1]);\n blocks ~= tup(0, n+1);\n blocks ~= tup(1, n+1);\n\n int norm = 0;\n int yprev = 0;\n foreach(ref block; blocks){\n if(block[1] == yprev){\n block[1] -= norm;\n continue;\n }\n int gap = (block[1] - (yprev + 1)) % 2;\n norm += (block[1] - (yprev+1) - gap);\n yprev = block[1];\n block[1] -= norm;\n }\n int len = (n+1) - norm;\n assert(len <= 1_000_000);\n\n auto table = new bool[][](2, len+1);\n foreach(block; blocks){\n table[block[0]][block[1]] = 1;\n }\n table[0][0] = 1;\n table[1][0] = 1;\n\n for(int k = len-1; k > 0; --k){\n if(!table[0][k] && !table[1][k]){\n /* table[0][k] = 1; */\n /* table[1][k] = 1; */\n }else if(!table[0][k]){\n if(table[0][k-1]){\n writeln(\"NO\");\n return;\n }\n table[0][k-1] = 1;\n }else if(!table[1][k]){\n if(table[0][k-1]){\n writeln(\"NO\");\n return;\n }\n table[1][k-1] = 1;\n }\n }\n writeln(\"YES\");\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(int, int);\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto m = scan!int;\n tup[] blocks;\n for(int i = 0; i < m; ++i){\n blocks ~= tup(scan!int - 1, scan!int);\n }\n blocks.sort!((a, b) => b[1] > a[1]);\n blocks ~= tup(0, n+1);\n blocks ~= tup(1, n+1);\n\n int norm = 0;\n int yprev = 0;\n foreach(block; blocks){\n if(block[1] == yprev){\n block[1] -= norm;\n continue;\n }\n int gap = (block[1] - (yprev + 1)) % 2;\n norm += (block[1] - (yprev+1) - gap);\n yprev = block[1];\n block[1] -= norm;\n }\n int len = (n+1) - norm;\n show(len);\n assert(len <= 1_000_000);\n\n auto table = new bool[][](2, len+1);\n foreach(block; blocks){\n table[block[0]][block[1]] = 1;\n }\n table[0][0] = 1;\n table[1][0] = 1;\n\n for(int k = len-1; k > 0; --k){\n if(!table[0][k] && !table[1][k]){\n /* table[0][k] = 1; */\n /* table[1][k] = 1; */\n }else if(!table[0][k]){\n if(table[0][k-1]){\n writeln(\"NO\");\n return;\n }\n table[0][k-1] = 1;\n }else if(!table[1][k]){\n if(table[0][k-1]){\n writeln(\"NO\");\n return;\n }\n table[1][k-1] = 1;\n }\n }\n writeln(\"YES\");\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(int, int);\n"}], "src_uid": "fb500a8f56fe8b051b3e6d2d4656c81b"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tforeach(_; 0 .. rint){\n\t\tlong x = rlong, y = rlong, a = rlong, b = rlong;\n\t\tif((y - x) % (a + b) == 0) ((y - x) / (a + b)).writeln;\n\t\telse (-1).writeln;\n\t}\n}", "positive_code": [{"source_code": "import std.algorithm : max, maxElement;\nimport std.container : Array;\nimport std.stdio : stdin, write, writeln;\nimport std.typecons : Tuple, tuple;\n\nstruct IO {\n string readToken() {\n import std.range : empty, front, popFront, split;\n import std.stdio : readln;\n\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n\n int readInt() {\n import std.conv : to;\n\n return readToken.to!int;\n }\n\n string[] tokens;\n}\n\nvoid main() {\n IO io;\n int T = io.readInt;\n while (T--) {\n int x = io.readInt;\n int y = io.readInt;\n int a = io.readInt;\n int b = io.readInt;\n if ((y - x) % (a + b)) {\n writeln(-1);\n }\n else {\n writeln((y - x) / (a + b));\n }\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long x, y, a, b;\n\n void solve(long tc = -1)\n {\n if ((y - x) % (a + b) != 0)\n {\n writeln(-1);\n }\n else\n {\n writeln((y - x) / (a + b));\n }\n }\n}\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W)\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, string))\n {\n static assert(isDynamicArray!(typeOfField)\n , \" A field with dimension initialization UDA must be a dynamic array.\");\n enum uda = getUDAs!(fieldSymbol, string)[0];\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\tint c=0;\n\t\tint d=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\treadf(\" %d\", &d);\n\t\tif ((b-a)%(c+d)==0)\n\t\t{\n\t\t\twriteln((b-a)/(c+d));\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(-1);\n\t\t}\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD;\n\t\tauto y = RD;\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto d = y - x;\n\t\tif (d % (a+b) != 0)\n\t\t\tans[ti] = -1;\n\t\telse\n\t\t\tans[ti] = d / (a+b);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "9afcf090806cc9c3b87120b1b61f8f17"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, s;\r\n\t\treadf !(\" %s %s\") (n, s);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tlong [] p = [0];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tp ~= p.back + c;\r\n\t\t}\r\n\r\n\t\tint half = 1;\r\n\t\twhile (half < n + 1)\r\n\t\t{\r\n\t\t\thalf <<= 1;\r\n\t\t}\r\n\t\tauto t = new long [half * 2];\r\n\t\tt[] = long.max / 4;\r\n\t\tt[half..half + n + 1] = p[];\r\n\t\tforeach_reverse (i; 1..half)\r\n\t\t{\r\n\t\t\tt[i] = min (t[i * 2 + 0], t[i * 2 + 1]);\r\n\t\t}\r\n\r\n\t\tlong getMin (int lo, int hi)\r\n\t\t{\r\n\t\t\tauto res = long.max / 4;\r\n\t\t\tfor (lo += half, hi += half;\r\n\t\t\t lo < hi; lo >>= 1, hi >>= 1)\r\n\t\t\t{\r\n\t\t\t\tif (lo & 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tres = min (res, t[lo]);\r\n\t\t\t\t\tlo += 1;\r\n\t\t\t\t}\r\n\t\t\t\tif (hi & 1)\r\n\t\t\t\t{\r\n\t\t\t\t\thi -= 1;\r\n\t\t\t\t\tres = min (res, t[hi]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tint bestLo = -1;\r\n\t\tint bestHi = -1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tint lo = i;\r\n\t\t\tint hi = n + 1;\r\n\t\t\twhile (hi - lo > 1)\r\n\t\t\t{\r\n\t\t\t\tint me = (lo + hi) / 2;\r\n\t\t\t\tif (s < p[i] - getMin (i, me + 1))\r\n\t\t\t\t{\r\n\t\t\t\t\thi = me;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlo = me;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (bestHi - bestLo < lo - i)\r\n\t\t\t{\r\n\t\t\t\tbestLo = i;\r\n\t\t\t\tbestHi = lo;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (bestLo == bestHi)\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln (bestLo + 1, \" \", bestHi);\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N; long S; readf(\"%d %d\\n\", &N, &S);\r\n auto A = readarray!long;\r\n\r\n int len = 0;\r\n int[] ans = [0, 0];\r\n int l = 0, r = 0;\r\n long s = S;\r\n while (true) {\r\n if (r < N && s + A[r] >= 0) {\r\n s += A[r];\r\n r++;\r\n } else {\r\n if (l == r) {\r\n if (l == N) break;\r\n s = S;\r\n l = l + 1;\r\n r = r + 1;\r\n } else {\r\n s -= A[l];\r\n l++;\r\n }\r\n }\r\n if (r - l > len) {\r\n ans = [l, r];\r\n len = r - l;\r\n }\r\n }\r\n if (ans[0] == ans[1]) {\r\n writeln(-1);\r\n } else {\r\n ans[0]++;\r\n writefln(\"%(%s %)\", ans);\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "034536fc950299cb6b09675757ca77aa"} {"source_code": "import std;\n\nvoid main(){\n\tint t=readln().strip.to!int;\n\tforeach(_;0..t){\n\t\tauto z=readln().strip.split.to!(int[])[1];\n\t\tauto a=readln().strip.split.to!(int[]);\n\t\twriteln(a.map!(x=>x|z).reduce!max);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n const Z = readLong;\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n \n long ans;\n foreach (i; 0 .. N) {\n chmax(ans, Z | A[i]);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid solve()\n{\n ulong n, z;\n readf!(\" %s %s\")(n, z);\n readln;\n readln.splitter\n .map!(to!int)\n .map!(x => x | z)\n .maxElement!()\n .writeln;\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n solve();\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid solve()\n{\n ulong n, z;\n readf!(\" %s %s\")(n, z);\n readln;\n auto arr = readln.splitter.map!(to!int);\n arr.map!(x => x | z).maxElement!().writeln;\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n solve();\n}\n"}], "negative_code": [], "src_uid": "bb6168528e04156f68bde2ffc1ba828f"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1426/problem/D\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main () {\n long n = readln.chomp.to!long;\n\n long[] a = readln.split.map!(to!long).array;\n\n auto rbt = new RedBlackTree!long;\n long prefix = 0L;\n long ans = 0L;\n\n rbt.insert(0L);\n\n foreach(x; a) {\n prefix += x;\n if(prefix in rbt) {\n ans += 1L;\n rbt = new RedBlackTree!long;\n rbt.insert(0L);\n prefix = x;\n }\n rbt.insert(prefix);\n }\n\n ans.writeln;\n\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n ll[] pref = [0];\n foreach(el; arr){\n pref ~= el + pref.back;\n }\n int[long] vis;\n /* bool[long] seen; */\n foreach(el; pref){\n ++vis[el];\n }\n int[long] lastseen;\n ll cnt = 0;\n int lasti = -1;\n foreach(i; 0..n+1){\n assert(pref[i] in vis);\n if(vis[pref[i]] > 1){\n int prev = lastseen.get(pref[i], -1);\n if(lasti < prev){ \n ++cnt; \n lasti = i - 2;\n }\n }\n lastseen[pref[i]] = i;\n /* writeln(lasti, \" \", lastseen); */\n }\n writeln(cnt);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1426/problem/D\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main () {\n long n = readln.chomp.to!long;\n\n long[] a = readln.split.map!(to!long).array;\n\n auto rbt = new RedBlackTree!long;\n long prefix = 0L;\n long ans = 0L;\n\n rbt.insert(0L);\n\n foreach(x; a) {\n prefix += x;\n if(prefix in rbt) {\n ans += 1L;\n rbt.insert(0L);\n prefix = x;\n }\n rbt.insert(prefix);\n }\n\n ans.writeln;\n\n}\n\n"}], "src_uid": "05548be393d794bf106708627220b9a3"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m, q; rd(n, m, q);\n auto s=readln.chomp.to!(char[]);\n auto t=readln.chomp.to!(char[]);\n\n auto ok=new bool[](s.length+1);\n for(int i=0; i+t.length<=s.length; i++){\n if(s[i..(i+t.length)]==t) ok[i]=true;\n }\n while(q--){\n int l, r; rd(l, r);\n l--; r--;\n int w=0;\n for(int i=l; i<=r; i++){\n if(ok[i] && i+t.length-1<=r) w++;\n }\n writeln(w);\n }\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto Q = s[2];\n\n auto S = readln.chomp;\n auto T = readln.chomp;\n auto A = new int[](N+1);\n\n foreach (i; 0..N-M+1) {\n bool ok = true;\n foreach (j; i..i+M) {\n if (S[j] != T[j-i]) {\n ok = false;\n break;\n }\n }\n if (ok) A[i+1] += 1;\n }\n\n foreach (i; 0..N) A[i+1] += A[i];\n\n while (Q--) {\n s = readln.split.map!(to!int);\n int l = s[0] - 1;\n int r = s[1] - M;\n if (l > r)\n writeln(0);\n else\n writeln(A[r+1] - A[l]);\n }\n\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m, q;\n readf(\"%s %s %s\", &n, &m, &q);\n readln;\n \n auto s = readln.chomp;\n auto t = readln.chomp;\n \n auto cnt = new int [] (n+1);\n while (s.canFind(t)) {\n s = s.find(t);\n \n debug { s.writeln; }\n \n ++cnt[n - s.length + 1];\n \n s = s.dropOne();\n }\n \n cnt = cnt.cumulativeFold!((a, b) => a + b).array;\n \n debug { cnt.writeln; }\n \n while (q--) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n if (b - (a-1) < t.length) {\n writeln(0);\n continue;\n }\n \n writeln(cnt[b - t.length + 1] - cnt[a-1]);\n }\n}"}], "negative_code": [], "src_uid": "4cc5a6975d33cee60e53e8f648ec30de"} {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdio;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Lca(Node, int n, Flag!`checkBackReferences` checkBackReferences = No.checkBackReferences,\n Flag!`assignLineIndices` assignLineIndices = No.assignLineIndices) {\n Node*[n + 1] lp;\n int[n + 1] height;\n\n void init(Node* root) {\n int gid = 1;\n\n static if (checkBackReferences)\n alias PrevType = AliasSeq!(Node*);\n else\n alias PrevType = AliasSeq!();\n\n int dfs0(Node* self, in PrevType prev) {\n with (self) {\n id = deepestId = gid++;\n int h = bsf(id);\n foreach (node; adj) {\n static if (checkBackReferences) {\n if (node is prev[0])\n continue;\n const t = dfs0(node, self);\n } else\n const t = dfs0(node);\n if (t > h) {\n h = t;\n deepestId = node.deepestId;\n }\n lp[node.deepestId] = self;\n }\n height[id] = h;\n return h;\n }\n }\n\n void dfs1(Node* self, in PrevType prev, int index) {\n with (self) {\n static if (assignLineIndices)\n indexInLine = index;\n mask |= deepestId & -deepestId;\n foreach (node; adj)\n static if (checkBackReferences) {\n if (node !is prev[0]) {\n node.mask = mask;\n dfs1(node, self, deepestId == node.deepestId? index + 1 : 0);\n }\n } else {\n node.mask = mask;\n dfs1(node, deepestId == node.deepestId? index + 1 : 0);\n }\n }\n }\n\n root.mask = 0x0;\n static if (checkBackReferences) {\n dfs0(root, null);\n dfs1(root, null, 0);\n } else {\n dfs0(root);\n dfs1(root, 0);\n }\n }\n\n Node* get(Node* x, Node* y) {\n const dpx = x.deepestId, dpy = y.deepestId;\n if (dpx != dpy) {\n const k = bsr(dpx ^ dpy);\n const zh = bsf(x.mask & y.mask & ~0 << height[(dpx >> k | 0x1) << k]);\n\n Node* raise(int deepestId, int mask) {\n const k = bsr(mask & ((1 << zh) - 1));\n return lp[(deepestId >> k | 0x1) << k];\n }\n\n if (bsf(x.mask) != zh)\n x = raise(dpx, x.mask);\n if (bsf(y.mask) != zh)\n y = raise(dpy, y.mask);\n }\n return x.id < y.id? x : y;\n }\n}\n\nstruct AutoNode {\n int len;\n AutoNode*[char] next;\n AutoNode* link;\n AutoNode*[ ] invLinks;\n int id, deepestId, mask;\n\n alias adj = invLinks;\n\n this(this) {\n next = next.dup;\n }\n\n AutoNode* append(char c, AutoNode* last) {\n auto cur = createNode(last.len + 1);\n AutoNode** p;\n while ((p = c in last.next) is null) {\n last.next[c] = cur;\n last = last.link;\n if (last is null) {\n cur.link = &this;\n return cur;\n }\n }\n auto q = *p;\n if (q.len == last.len + 1) {\n cur.link = q;\n return cur;\n }\n auto clone = createNode(*q);\n clone.len = last.len + 1;\n cur.link = q.link = clone;\n do {\n *p = clone;\n last = last.link;\n if (last is null)\n break;\n p = c in last.next;\n } while (p !is null && *p == q);\n return cur;\n }\n}\n\nstruct TreeNode {\n char c;\n TreeNode*[ ] adj;\n int id, deepestId, mask, indexInLine, indexInString;\n\n void genString(in TreeNode* prev) {\n indexInString = strSize;\n str[strSize++] = c;\n foreach (node; adj)\n if (node !is prev && node.deepestId == deepestId) {\n node.genString(&this);\n break;\n }\n foreach (node; adj)\n if (node !is prev && node.deepestId != deepestId)\n node.genString(&this);\n }\n}\n\nstruct Waypoint {\n int pos, lpos, trgLpos;\n bool up;\n}\n\nint n;\nTreeNode[300_000] _nodes;\nint strSize;\nchar[300_000] str;\nint auNodesSize;\nAutoNode[ ] auNodes;\nAutoNode*[300_000] _tdNodes, _buNodes;\nAutoNode*[ ] tdNodes, buNodes;\nLca!(TreeNode, 300_000, Yes.checkBackReferences, Yes.assignLineIndices) treeLca;\nLca!(AutoNode, 1_200_000) auLca;\nWaypoint[38][2] wp;\n\nint solve(TreeNode* a, TreeNode* b, TreeNode* c, TreeNode* d) {\n auto calcWaypoints(TreeNode* a, TreeNode* b, Waypoint[ ] wp) {\n const lca = treeLca.get(a, b);\n int i = 0;\n\n void walkUp(const(TreeNode)* node, bool up) {\n while (node.deepestId != lca.deepestId) {\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, 0, up);\n node = treeLca.lp[node.deepestId];\n }\n if (up)\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine, up);\n else if (node !is lca)\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine + 1, up);\n }\n\n walkUp(a, true);\n const mid = i;\n walkUp(b, false);\n wp[mid .. i].reverse();\n return wp[0 .. i];\n }\n\n auto wp0 = calcWaypoints(a, b, wp[0][ ]);\n auto wp1 = calcWaypoints(c, d, wp[1][ ]);\n int result = 0;\n while (!wp0.empty && !wp1.empty) {\n const aw = wp0.front;\n const cw = wp1.front;\n auto node0 = aw.up? buNodes[aw.pos] : tdNodes[aw.pos - aw.lpos + aw.trgLpos];\n auto node1 = cw.up? buNodes[cw.pos] : tdNodes[cw.pos - cw.lpos + cw.trgLpos];\n const aLim = aw.lpos - aw.trgLpos + 1;\n const cLim = cw.lpos - cw.trgLpos + 1;\n const lce = min(auLca.get(node0, node1).len, aLim, cLim);\n result += lce;\n if (lce < aLim && lce < cLim)\n return result;\n\n void update(ref Waypoint[ ] wp, int lim) {\n if (lce == lim)\n wp.popFront();\n else if (wp.front.up) {\n wp.front.pos -= lce;\n wp.front.lpos -= lce;\n } else\n wp.front.trgLpos += lce;\n }\n\n update(wp0, aLim);\n update(wp1, cLim);\n }\n\n return result;\n}\n\nauto createNode(int len) {\n auNodes[auNodesSize] = AutoNode(len);\n return &auNodes[auNodesSize++];\n}\n\nauto createNode(ref AutoNode node) {\n auNodes[auNodesSize] = node;\n return &auNodes[auNodesSize++];\n}\n\nvoid main() {\n auNodes = uninitializedArray!(AutoNode[ ])(1_200_000);\n while (scanf(\"%d \", &n) == 1) {\n auto nodes = _nodes[0 .. n];\n foreach (ref node; nodes) {\n version (LocalProject)\n node = TreeNode.init;\n node.c = cast(char)getchar();\n }\n foreach (i; 1 .. n) {\n int a, b;\n scanf(\"%d%d\", &a, &b);\n a--;\n b--;\n nodes[a].adj ~= &nodes[b];\n nodes[b].adj ~= &nodes[a];\n }\n\n treeLca.init(&nodes[0]);\n strSize = 0;\n nodes[0].genString(null);\n assert(strSize == n);\n\n AutoNode root;\n tdNodes = _tdNodes[0 .. n];\n buNodes = _buNodes[0 .. n];\n auNodesSize = 0;\n //Build automata on reversed strings.\n auto last = &root;\n foreach_reverse (i, c; str[0 .. n])\n last = tdNodes[i] = root.append(c, last);\n foreach (i, c; str[0 .. n])\n last = buNodes[i] = root.append(c, last);\n foreach (ref node; auNodes[0 .. auNodesSize])\n node.link.invLinks ~= &node;\n auLca.init(&root);\n\n int q;\n scanf(\"%d\", &q);\n while (q--) {\n int a, b, c, d;\n scanf(\"%d%d%d%d\", &a, &b, &c, &d);\n printf(\"%d\\n\", solve(&nodes[a - 1], &nodes[b - 1], &nodes[c - 1], &nodes[d - 1]));\n }\n }\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdio;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)calloc(n, T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Lca(Node, int n, Flag!`checkBackReferences` checkBackReferences = No.checkBackReferences,\n Flag!`assignLineIndices` assignLineIndices = No.assignLineIndices) {\n Node*[n + 1] lp;\n int[n + 1] height;\n\n void init(Node* root) {\n int gid = 1;\n\n static if (checkBackReferences)\n alias PrevType = AliasSeq!(Node*);\n else\n alias PrevType = AliasSeq!();\n\n int dfs0(Node* self, in PrevType prev) {\n with (self) {\n id = deepestId = gid++;\n int h = bsf(id);\n foreach (node; adj) {\n static if (checkBackReferences) {\n if (node is prev[0])\n continue;\n const t = dfs0(node, self);\n } else\n const t = dfs0(node);\n if (t > h) {\n h = t;\n deepestId = node.deepestId;\n }\n lp[node.deepestId] = self;\n }\n height[id] = h;\n return h;\n }\n }\n\n void dfs1(Node* self, in PrevType prev, int index) {\n with (self) {\n static if (assignLineIndices)\n indexInLine = index;\n mask |= deepestId & -deepestId;\n foreach (node; adj)\n static if (checkBackReferences) {\n if (node !is prev[0]) {\n node.mask = mask;\n dfs1(node, self, deepestId == node.deepestId? index + 1 : 0);\n }\n } else {\n node.mask = mask;\n dfs1(node, deepestId == node.deepestId? index + 1 : 0);\n }\n }\n }\n\n root.mask = 0x0;\n static if (checkBackReferences) {\n dfs0(root, null);\n dfs1(root, null, 0);\n } else {\n dfs0(root);\n dfs1(root, 0);\n }\n }\n\n Node* get(Node* x, Node* y) {\n const dpx = x.deepestId, dpy = y.deepestId;\n if (dpx != dpy) {\n const k = bsr(dpx ^ dpy);\n const zh = bsf(x.mask & y.mask & ~0 << height[(dpx >> k | 0x1) << k]);\n\n Node* raise(int deepestId, int mask) {\n const k = bsr(mask & ((1 << zh) - 1));\n return lp[(deepestId >> k | 0x1) << k];\n }\n\n if (bsf(x.mask) != zh)\n x = raise(dpx, x.mask);\n if (bsf(y.mask) != zh)\n y = raise(dpy, y.mask);\n }\n return x.id < y.id? x : y;\n }\n}\n\nstruct AutoNode {\n int len;\n //AutoNode*[char] next;\n AutoNode*[26] next;\n AutoNode* link;\n AutoNode*[ ] invLinks;\n int id, deepestId, mask;\n\n alias adj = invLinks;\n\n /+\n this(this) {\n next = next.dup;\n }\n +/\n\n AutoNode* append(int c, AutoNode* last) {\n /+\n while (auNodesSize >= 1_200_000) { }\n auNodes[auNodesSize] = AutoNode(last.len + 1);\n auto cur = &auNodes[auNodesSize++];\n +/\n auto cur = new AutoNode(last.len + 1);\n /+\n AutoNode** p;\n while ((p = c in last.next) is null) {\n last.next[c] = cur;\n last = last.link;\n if (last is null) {\n cur.link = &this;\n return cur;\n }\n }\n while (p is null) { }\n +/\n for (; last !is null && last.next[c] is null; last = last.link)\n last.next[c] = cur;\n if (last is null) {\n cur.link = &this;\n return cur;\n }\n while (last is null) { }\n auto q = /+*p+/ last.next[c];\n while (q is null) { }\n if (q.len == last.len + 1) {\n cur.link = q;\n return cur;\n }\n /+\n while (auNodesSize >= 1_200_000) { }\n auNodes[auNodesSize] = *q;\n auto clone = &auNodes[auNodesSize++];\n +/\n auto clone = new AutoNode;\n *clone = *q;\n clone.len = last.len + 1;\n //clone.next = clone.next.dup;\n cur.link = q.link = clone;\n for (; last !is null && last.next[c] == q; last = last.link)\n last.next[c] = clone;\n /+\n do {\n while (p is null) { }\n *p = clone;\n last = last.link;\n if (last is null)\n break;\n p = c in last.next;\n } while (p !is null && *p == q);\n +/\n return cur;\n }\n}\n\nstruct TreeNode {\n char c;\n TreeNode*[ ] adj;\n int id, deepestId, mask, indexInLine, indexInString;\n\n void genString(in TreeNode* prev) {\n indexInString = strSize;\n str[strSize++] = c;\n foreach (node; adj)\n if (node !is prev && node.deepestId == deepestId) {\n node.genString(&this);\n break;\n }\n foreach (node; adj)\n if (node !is prev && node.deepestId != deepestId)\n node.genString(&this);\n }\n}\n\nstruct Waypoint {\n int pos, lpos, trgLpos;\n bool up;\n}\n\nint n;\nTreeNode[300_000] _nodes;\nint strSize;\nchar[300_000] str;\nint auNodesSize;\nAutoNode[ ] auNodes;\nAutoNode*[300_000] _tdNodes, _buNodes;\nAutoNode*[ ] tdNodes, buNodes;\nLca!(TreeNode, 300_000, Yes.checkBackReferences, Yes.assignLineIndices) treeLca;\nLca!(AutoNode, 1_200_000) auLca;\nWaypoint[38][2] wp;\n\nint solve(TreeNode* a, TreeNode* b, TreeNode* c, TreeNode* d) {\n auto calcWaypoints(TreeNode* a, TreeNode* b, Waypoint[ ] wp) {\n const lca = treeLca.get(a, b);\n int i = 0;\n\n void walkUp(const(TreeNode)* node, bool up) {\n while (node.deepestId != lca.deepestId) {\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, 0, up);\n node = treeLca.lp[node.deepestId];\n }\n if (up)\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine, up);\n else if (node !is lca)\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine + 1, up);\n }\n\n walkUp(a, true);\n const mid = i;\n walkUp(b, false);\n wp[mid .. i].reverse();\n return wp[0 .. i];\n }\n\n auto wp0 = calcWaypoints(a, b, wp[0][ ]);\n auto wp1 = calcWaypoints(c, d, wp[1][ ]);\n int result = 0;\n while (!wp0.empty && !wp1.empty) {\n const aw = wp0.front;\n const cw = wp1.front;\n auto node0 = aw.up? buNodes[aw.pos] : tdNodes[aw.pos - aw.lpos + aw.trgLpos];\n auto node1 = cw.up? buNodes[cw.pos] : tdNodes[cw.pos - cw.lpos + cw.trgLpos];\n const aLim = aw.lpos - aw.trgLpos + 1;\n const cLim = cw.lpos - cw.trgLpos + 1;\n const lce = min(auLca.get(node0, node1).len, aLim, cLim);\n result += lce;\n if (lce < aLim && lce < cLim)\n return result;\n\n void update(ref Waypoint[ ] wp, int lim) {\n if (lce == lim)\n wp.popFront();\n else if (wp.front.up) {\n wp.front.pos -= lce;\n wp.front.lpos -= lce;\n } else\n wp.front.trgLpos += lce;\n }\n\n update(wp0, aLim);\n update(wp1, cLim);\n }\n\n return result;\n}\n\nvoid main() {\n //auNodes = allocate!AutoNode(1_200_000);\n while (scanf(\"%d \", &n) == 1) {\n auto nodes = _nodes[0 .. n];\n foreach (ref node; nodes) {\n version (LocalProject)\n node = TreeNode.init;\n node.c = cast(char)getchar();\n }\n foreach (i; 1 .. n) {\n int a, b;\n scanf(\"%d%d\", &a, &b);\n a--;\n b--;\n nodes[a].adj ~= &nodes[b];\n nodes[b].adj ~= &nodes[a];\n }\n\n treeLca.init(&nodes[0]);\n strSize = 0;\n nodes[0].genString(null);\n while (strSize != n) { }\n\n AutoNode root;\n while (root.len) { }\n while (root.link !is null) { }\n tdNodes = _tdNodes[0 .. n];\n buNodes = _buNodes[0 .. n];\n auNodesSize = 0;\n //Build automata on reversed strings.\n auto last = &root;\n foreach_reverse (i, c; str[0 .. n]) {\n while (i < 0 || i >= tdNodes.length) { }\n last = tdNodes[i] = root.append(c - 'a', last);\n }\n foreach (i, c; str[0 .. n]) {\n while (i < 0 || i >= buNodes.length) { }\n last = buNodes[i] = root.append(c - 'a', last);\n }\n /+\n foreach (ref node; auNodes[0 .. auNodesSize]) {\n while (node.link is null) { }\n node.link.invLinks ~= &node;\n }\n +/\n\n void traverse(AutoNode* node) {\n if (node.link !is null) {\n node.link.invLinks ~= node;\n node.link = null;\n foreach (next; node.next)\n if (next !is null)\n traverse(next);\n }\n }\n\n foreach (node; root.next)\n if (node !is null)\n traverse(node);\n auLca.init(&root);\n\n int q;\n scanf(\"%d\", &q);\n while (q--) {\n int a, b, c, d;\n scanf(\"%d%d%d%d\", &a, &b, &c, &d);\n printf(\"%d\\n\", solve(&nodes[a - 1], &nodes[b - 1], &nodes[c - 1], &nodes[d - 1]));\n }\n }\n}\n"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdio;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)calloc(n, T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Lca(Node, int n, Flag!`checkBackReferences` checkBackReferences = No.checkBackReferences,\n Flag!`assignLineIndices` assignLineIndices = No.assignLineIndices) {\n Node*[n + 1] lp;\n int[n + 1] height;\n\n void init(Node* root) {\n int gid = 1;\n\n static if (checkBackReferences)\n alias PrevType = AliasSeq!(Node*);\n else\n alias PrevType = AliasSeq!();\n\n int dfs0(Node* self, in PrevType prev) {\n with (self) {\n id = deepestId = gid++;\n int h = bsf(id);\n foreach (node; adj) {\n static if (checkBackReferences) {\n if (node is prev[0])\n continue;\n const t = dfs0(node, self);\n } else\n const t = dfs0(node);\n if (t > h) {\n h = t;\n deepestId = node.deepestId;\n }\n lp[node.deepestId] = self;\n }\n height[id] = h;\n return h;\n }\n }\n\n void dfs1(Node* self, in PrevType prev, int index) {\n with (self) {\n static if (assignLineIndices)\n indexInLine = index;\n mask |= deepestId & -deepestId;\n foreach (node; adj)\n static if (checkBackReferences) {\n if (node !is prev[0]) {\n node.mask = mask;\n dfs1(node, self, deepestId == node.deepestId? index + 1 : 0);\n }\n } else {\n node.mask = mask;\n dfs1(node, deepestId == node.deepestId? index + 1 : 0);\n }\n }\n }\n\n root.mask = 0x0;\n static if (checkBackReferences) {\n dfs0(root, null);\n dfs1(root, null, 0);\n } else {\n dfs0(root);\n dfs1(root, 0);\n }\n }\n\n Node* get(Node* x, Node* y) {\n const dpx = x.deepestId, dpy = y.deepestId;\n if (dpx != dpy) {\n const k = bsr(dpx ^ dpy);\n const zh = bsf(x.mask & y.mask & ~0 << height[(dpx >> k | 0x1) << k]);\n\n Node* raise(int deepestId, int mask) {\n const k = bsr(mask & ((1 << zh) - 1));\n return lp[(deepestId >> k | 0x1) << k];\n }\n\n if (bsf(x.mask) != zh)\n x = raise(dpx, x.mask);\n if (bsf(y.mask) != zh)\n y = raise(dpy, y.mask);\n }\n return x.id < y.id? x : y;\n }\n}\n\nstruct AutoNode {\n int len;\n //AutoNode*[char] next;\n AutoNode*[26] next;\n AutoNode* link;\n AutoNode*[ ] invLinks;\n int id, deepestId, mask;\n\n alias adj = invLinks;\n\n /+\n this(this) {\n next = next.dup;\n }\n +/\n\n AutoNode* append(int c, AutoNode* last) {\n while (auNodesSize >= 1_200_000) { }\n auNodes[auNodesSize] = AutoNode(last.len + 1);\n auto cur = &auNodes[auNodesSize++];\n /+\n AutoNode** p;\n while ((p = c in last.next) is null) {\n last.next[c] = cur;\n last = last.link;\n if (last is null) {\n cur.link = &this;\n return cur;\n }\n }\n while (p is null) { }\n +/\n for (; last !is null && last.next[c] is null; last = last.link)\n last.next[c] = cur;\n if (last is null) {\n cur.link = &this;\n return cur;\n }\n while (last is null) { }\n auto q = /+*p+/ last.next[c];\n while (q is null) { }\n if (q.len == last.len + 1) {\n cur.link = q;\n return cur;\n }\n while (auNodesSize >= 1_200_000) { }\n auNodes[auNodesSize] = *q;\n auto clone = &auNodes[auNodesSize++];\n clone.len = last.len + 1;\n //clone.next = clone.next.dup;\n cur.link = q.link = clone;\n for (; last !is null && last.next[c] == q; last = last.link)\n last.next[c] = clone;\n /+\n do {\n while (p is null) { }\n *p = clone;\n last = last.link;\n if (last is null)\n break;\n p = c in last.next;\n } while (p !is null && *p == q);\n +/\n return cur;\n }\n}\n\nstruct TreeNode {\n char c;\n TreeNode*[ ] adj;\n int id, deepestId, mask, indexInLine, indexInString;\n\n void genString(in TreeNode* prev) {\n indexInString = strSize;\n str[strSize++] = c;\n foreach (node; adj)\n if (node !is prev && node.deepestId == deepestId) {\n node.genString(&this);\n break;\n }\n foreach (node; adj)\n if (node !is prev && node.deepestId != deepestId)\n node.genString(&this);\n }\n}\n\nstruct Waypoint {\n int pos, lpos, trgLpos;\n bool up;\n}\n\nint n;\nTreeNode[300_000] _nodes;\nint strSize;\nchar[300_000] str;\nint auNodesSize;\nAutoNode[ ] auNodes;\nAutoNode*[300_000] _tdNodes, _buNodes;\nAutoNode*[ ] tdNodes, buNodes;\nLca!(TreeNode, 300_000, Yes.checkBackReferences, Yes.assignLineIndices) treeLca;\nLca!(AutoNode, 1_200_000) auLca;\nWaypoint[38][2] wp;\n\nint solve(TreeNode* a, TreeNode* b, TreeNode* c, TreeNode* d) {\n auto calcWaypoints(TreeNode* a, TreeNode* b, Waypoint[ ] wp) {\n const lca = treeLca.get(a, b);\n int i = 0;\n\n void walkUp(const(TreeNode)* node, bool up) {\n while (node.deepestId != lca.deepestId) {\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, 0, up);\n node = treeLca.lp[node.deepestId];\n }\n if (up)\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine, up);\n else if (node !is lca)\n wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine + 1, up);\n }\n\n walkUp(a, true);\n const mid = i;\n walkUp(b, false);\n wp[mid .. i].reverse();\n return wp[0 .. i];\n }\n\n auto wp0 = calcWaypoints(a, b, wp[0][ ]);\n auto wp1 = calcWaypoints(c, d, wp[1][ ]);\n int result = 0;\n while (!wp0.empty && !wp1.empty) {\n const aw = wp0.front;\n const cw = wp1.front;\n auto node0 = aw.up? buNodes[aw.pos] : tdNodes[aw.pos - aw.lpos + aw.trgLpos];\n auto node1 = cw.up? buNodes[cw.pos] : tdNodes[cw.pos - cw.lpos + cw.trgLpos];\n const aLim = aw.lpos - aw.trgLpos + 1;\n const cLim = cw.lpos - cw.trgLpos + 1;\n const lce = min(auLca.get(node0, node1).len, aLim, cLim);\n result += lce;\n if (lce < aLim && lce < cLim)\n return result;\n\n void update(ref Waypoint[ ] wp, int lim) {\n if (lce == lim)\n wp.popFront();\n else if (wp.front.up) {\n wp.front.pos -= lce;\n wp.front.lpos -= lce;\n } else\n wp.front.trgLpos += lce;\n }\n\n update(wp0, aLim);\n update(wp1, cLim);\n }\n\n return result;\n}\n\nvoid main() {\n auNodes = new AutoNode[1_200_000];\n while (auNodes.ptr is null) { }\n while (scanf(\"%d \", &n) == 1) {\n auto nodes = _nodes[0 .. n];\n foreach (ref node; nodes) {\n version (LocalProject)\n node = TreeNode.init;\n node.c = cast(char)getchar();\n }\n foreach (i; 1 .. n) {\n int a, b;\n scanf(\"%d%d\", &a, &b);\n a--;\n b--;\n nodes[a].adj ~= &nodes[b];\n nodes[b].adj ~= &nodes[a];\n }\n\n treeLca.init(&nodes[0]);\n strSize = 0;\n nodes[0].genString(null);\n while (strSize != n) { }\n\n AutoNode root;\n while (root.len) { }\n while (root.link !is null) { }\n tdNodes = _tdNodes[0 .. n];\n buNodes = _buNodes[0 .. n];\n auNodesSize = 0;\n //Build automata on reversed strings.\n auto last = &root;\n foreach_reverse (i, c; str[0 .. n]) {\n while (i < 0 || i >= tdNodes.length) { }\n last = tdNodes[i] = root.append(c - 'a', last);\n }\n foreach (i, c; str[0 .. n]) {\n while (i < 0 || i >= buNodes.length) { }\n last = buNodes[i] = root.append(c - 'a', last);\n }\n /+\n foreach (ref node; auNodes[0 .. auNodesSize]) {\n while (node.link is null) { }\n node.link.invLinks ~= &node;\n }\n +/\n\n void traverse(AutoNode* node) {\n if (node.link !is null) {\n node.link.invLinks ~= node;\n node.link = null;\n foreach (next; node.next)\n if (next !is null)\n traverse(next);\n }\n }\n\n foreach (node; root.next)\n if (node !is null)\n traverse(node);\n auLca.init(&root);\n\n int q;\n scanf(\"%d\", &q);\n while (q--) {\n int a, b, c, d;\n scanf(\"%d%d%d%d\", &a, &b, &c, &d);\n printf(\"%d\\n\", solve(&nodes[a - 1], &nodes[b - 1], &nodes[c - 1], &nodes[d - 1]));\n }\n }\n}\n"}], "negative_code": [], "src_uid": "ee34d1e5a9efdcb7578b28b85819c5e7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = RDA;\n\t\tbool add, sub;\n\t\tans[ti] = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] > b[i])\n\t\t\t{\n\t\t\t\tif (!sub)\n\t\t\t\t{\n\t\t\t\t\tans[ti] = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (a[i] < b[i])\n\t\t\t{\n\t\t\t\tif (!add)\n\t\t\t\t{\n\t\t\t\t\tans[ti] = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (a[i] > 0)\n\t\t\t\tadd = true;\n\t\t\telse if (a[i] < 0)\n\t\t\t\tsub = true;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n const n = r.next!uint;\n auto a = r.nextA!int (n);\n auto b = r.nextA!int (n);\n auto mask = uninitializedArray!(uint[])(n);\n int flags = 0;\n foreach (i; 0 .. n) {\n if (a[i] < 0) flags |= 1;\n if (a[i] > 0) flags |= 2;\n mask[i] = flags;\n }\n bool test () {\n foreach_reverse (j; 0 .. n) {\n if (b[j] == a[j]) continue;\n const f = j > 0 ? mask[j-1] : 0;\n if (b[j] > a[j] && (f & 2)) continue;\n if (b[j] < a[j] && (f & 1)) continue;\n return false;\n }\n return true;\n }\n writeln (test() ? \"YES\" : \"NO\");\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. scan!int){\n int n = scan!int;\n long[] as = scan!long(n), bs = scan!long(n);\n bool f, g;\n bool isOK = 1;\n foreach(i; 0 .. n){\n long a = as[i], b = bs[i];\n if(a < b && ! f) isOK = 0;\n if(a > b && ! g) isOK = 0;\n\n if(a > 0) f = 1;\n if(a < 0) g = 1;\n }\n (isOK? \"YES\": \"NO\").writeln;\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tbool havePos = false;\n\t\tbool haveNeg = false;\n\t\tbool canDo = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] < b[i])\n\t\t\t{\n\t\t\t\tcanDo &= havePos;\n\t\t\t}\n\t\t\tif (a[i] > b[i])\n\t\t\t{\n\t\t\t\tcanDo &= haveNeg;\n\t\t\t}\n\t\t\thavePos |= (a[i] > 0);\n\t\t\thaveNeg |= (a[i] < 0);\n\t\t}\n\t\twriteln (canDo ? \"YES\" : \"NO\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "e425aa498e5a7fc3e518cec25eec6304"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\n// zero-prefixed array\nlong solvez(long[] a, long s)\n{\n long[long] freq;\n freq[s]++;\n foreach (i ; 1 .. a.length) {\n if (a[i] == 0) {\n long best = 0;\n long ans = 0;\n foreach (k, v ; freq) {\n if (v > best) {\n best = v;\n }\n }\n return best + solvez(a[i .. $], s);\n }\n s += a[i];\n freq[s]++;\n }\n long best = 0;\n long ans = 0;\n foreach (k, v ; freq) {\n if (v > best) {\n best = v;\n }\n }\n return best;\n}\n\nlong solve(long[] a)\n{\n long ans = 0;\n long s = 0;\n foreach (i ; 0 .. a.length) {\n s += a[i];\n if (a[i] == 0)\n return ans + solvez(a[i .. $], s);\n if (s == 0)\n ans++;\n }\n return ans;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!long;\n auto a = readln.splitter.map!(to!long).array;\n writeln(solve(a));\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n = read!int;\r\n auto s = readarray!long;\r\n long[long] d;\r\n long cur_sum, res;\r\n int i = 0;\r\n bool flag = false;\r\n while (i < s.length) {\r\n cur_sum += s[i];\r\n //writeln(\"sum\", cur_sum);\r\n if (flag) {\r\n if (s[i] == 0) {\r\n auto m_key = d.byPair.maxElement!(p => p.value);\r\n cur_sum += m_key.key;\r\n res += m_key.value;\r\n d.clear();\r\n }\r\n d[cur_sum] = 1 + d.get(cur_sum, 0);\r\n }\r\n else if (s[i] == 0) {\r\n flag = true;\r\n d[cur_sum] = 1 + d.get(cur_sum, 0);\r\n }\r\n else if (cur_sum == 0)\r\n res++;\r\n i++;\r\n }\r\n if (!d.empty) {\r\n auto m_key = d.byPair.maxElement!(p => p.value);\r\n cur_sum += m_key.key;\r\n res += m_key.value;\r\n }\r\n writeln(res);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [], "src_uid": "f4479bff71a45efdaa42729de64eb10f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tauto l = a.MIN_POS;\r\n\t\tauto r = a.MIN_POS!\"a > b\";\r\n\t\tans[ti] = [l+1, r+1];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e[0], \" \", e[1]);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto i = n - a.minPos.length.to !(int);\r\n\t\tauto j = n - a.maxPos.length.to !(int);\r\n\t\twriteln (i + 1, \" \", j + 1);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "7af4eee2e9f60283c4d99200769c77ec"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const S = readToken();\n int sum, zero, even;\n foreach (c; S) {\n const d = c - '0';\n sum += d;\n if (d == 0) {\n ++zero;\n }\n if (d % 2 == 0) {\n ++even;\n }\n }\n const ans = (sum % 3 == 0 && zero >= 1 && even >= 2);\n writeln(ans ? \"red\" : \"cyan\");\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n auto cnt = new int[](10);\n while (T--) {\n cnt[] = 0;\n auto S = readln.chomp;\n auto N = S.length.to!int;\n int zero = 0;\n int even = 0;\n int div3 = 0;\n foreach (i; 0..N) {\n int d = S[i]-'0';\n if (d == 0) zero += 1;\n if (d % 2 == 0) even += 1;\n div3 = (div3 + d) % 3;\n }\n if (zero >= 1 && even >= 2 && div3 == 0) {\n writeln(\"red\");\n } else {\n writeln(\"cyan\");\n }\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool solve (string s)\n{\n\tauto t = s.map !(q{a - '0'}).array;\n\tsort (t);\n\tif (t[0] != 0)\n\t{\n\t\treturn false;\n\t}\n\tif (t.sum % 3 != 0)\n\t{\n\t\treturn false;\n\t}\n\tif (!t.drop (1).canFind !(x => x % 2 == 0))\n\t{\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\t\twriteln (solve (s) ? \"red\" : \"cyan\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format, std.regex;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tstring[] as = rtypes!string(n);\n\n\tforeach(a; as){\n\t\tstring ans;\n\t\tint[] ks = a.split(\"\").map!(to!int).array;\n\t\tint[] cnt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\t\tforeach(k; ks) cnt[k] += 1;\n\t\tif(cnt[0] == 0) ans = \"cyan\";\n\t\telse if(cnt[0] + cnt[2] + cnt[4] + cnt[6] + cnt[8] <= 1) ans = \"cyan\";\n\t\telse if(ks.sum % 3 != 0) ans = \"cyan\";\n\t\telse ans = \"red\";\n\t\tans.writeln;\n\t}\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tforeach (i; 0..n)\n\t{\n\t\tauto s = RD!string;\n\t\tauto cnt = new int[](10);\n\t\tforeach (c; s)\n\t\t{\n\t\t\tauto x = c - '0';\n\t\t\t++cnt[x];\n\t\t}\n\t\tint x;\n\t\tforeach (j; 0..10)\n\t\t\tx += cnt[j] * j;\n\n\t\tif (cnt[0] == 0 || x % 3)\n\t\t\twriteln(\"cyan\");\n\t\t/*else if (s.length <= 3)\n\t\t{\n\t\t\tbool ok;\n\t\t\tif (cnt[6] >= 1)\n\t\t\t\tok = true;\n\t\t\telse if (cnt[1] == 1 && cnt[2]+cnt[8] == 1)\n\t\t\t\tok = true;\n\t\t\telse if (cnt[4] == 1 && cnt[2]+cnt[5]+cnt[8] == 1)\n\t\t\t\tok = true;\n\t\t\telse if (cnt[7] == 1 && cnt[8]+cnt[2] == 1)\n\t\t\t\tok = true;\n\t\t\twriteln(ok ? \"red\" : \"cyan\");\n\t\t}*/\n\t\telse if (cnt[0] == 1)\n\t\t{\n\t\t\tbool ok;\n\t\t\tforeach (j; 1..5)\n\t\t\t{\n\t\t\t\tif (cnt[j*2])\n\t\t\t\t\tok = true;\n\t\t\t}\n\t\t\twriteln(ok ? \"red\" : \"cyan\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"red\");\n\t\t}\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tforeach (i; 0..n)\n\t{\n\t\tauto s = RD!string;\n\t\tauto cnt = new int[](10);\n\t\tforeach (c; s)\n\t\t{\n\t\t\tauto x = c - '0';\n\t\t\t++cnt[x];\n\t\t}\n\t\tint x;\n\t\tforeach (j; 0..10)\n\t\t\tx += cnt[j] * j;\n\t\tif (x % 3)\n\t\t\twriteln(\"cyan\");\n\t\telse\n\t\t{\n\t\t\tif ((cnt[0] >= 1 && cnt[6] >= 1) || (cnt[0] >= 2))\n\t\t\t\twriteln(\"red\");\n\t\t\telse\n\t\t\t\twriteln(\"cyan\");\n\t\t}\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tforeach (i; 0..n)\n\t{\n\t\tauto s = RD!string;\n\t\tauto cnt = new int[](10);\n\t\tforeach (c; s)\n\t\t{\n\t\t\tauto x = c - '0';\n\t\t\t++cnt[x];\n\t\t}\n\t\tint x;\n\t\tforeach (j; 0..10)\n\t\t\tx += cnt[j] * j;\n\n\t\tif (s.length <= 3)\n\t\t{\n\t\t\tif (cnt[0] == 0)\n\t\t\t\twriteln(\"cyan\");\n\t\t\telse\n\t\t\t{\n\t\t\t\tbool ok;\n\t\t\t\tif (cnt[6] >= 1)\n\t\t\t\t\tok = true;\n\t\t\t\telse if (cnt[1] == 1 && cnt[2]+cnt[8] == 1)\n\t\t\t\t\tok = true;\n\t\t\t\telse if (cnt[4] == 1 && cnt[2]+cnt[5]+cnt[8] == 1)\n\t\t\t\t\tok = true;\n\t\t\t\telse if (cnt[7] == 1 && cnt[8]+cnt[2] == 1)\n\t\t\t\t\tok = true;\n\t\t\t\twriteln(ok ? \"red\" : \"cyan\");\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(x % 3 || (cnt[0] >= 1 && cnt[0]+cnt[6] <= 1) ? \"cyan\" : \"red\");\n\t\t}\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tforeach (i; 0..n)\n\t{\n\t\tauto s = RD!string;\n\t\tauto cnt = new int[](10);\n\t\tforeach (c; s)\n\t\t{\n\t\t\tauto x = c - '0';\n\t\t\t++cnt[x];\n\t\t}\n\t\tint x;\n\t\tforeach (j; 0..10)\n\t\t\tx += cnt[j] * j;\n\n\t\tif (s.length <= 3)\n\t\t{\n\t\t\tif (cnt[0] == 0)\n\t\t\t\twriteln(\"cyan\");\n\t\t\telse\n\t\t\t{\n\t\t\t\tbool ok;\n\t\t\t\tif (cnt[6] >= 1)\n\t\t\t\t\tok = true;\n\t\t\t\telse if (cnt[1] == 1 && cnt[2]+cnt[8] == 1)\n\t\t\t\t\tok = true;\n\t\t\t\telse if (cnt[4] == 1 && cnt[2]+cnt[5]+cnt[8] == 1)\n\t\t\t\t\tok = true;\n\t\t\t\telse if (cnt[7] == 1 && cnt[8]+cnt[2] == 1)\n\t\t\t\t\tok = true;\n\t\t\t\twriteln(ok ? \"red\" : \"cyan\");\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(x % 3 || (cnt[0] == 0 || cnt[0]+cnt[6] <= 1) ? \"cyan\" : \"red\");\n\t\t}\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "5bc07d2efb7453e51f4931cc7ec3aac7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\r\n\t\tans[ti] = n / 10;\r\n\t\tif (n % 10 == 9)\r\n\t\t\t++ans[ti];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\twriteln ((n + 1) / 10);\r\n\t}\r\n}\r\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop, std.random;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n while(tests--) {\r\n int n; readf!\"%s\\n\"(n);\r\n ((n + 1) / 10).writeln;\r\n }\r\n\r\n} // main\r\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport core.stdc.stdio;\n\nint main()\n{\n\tint t = readInt!int;\n\twhile (t--)\n\t{\n\t\tint n = readInt!int;\n\t\tif (n % 10 == 9)\n\t\t{\n\t\t\tn++;\n\t\t\t(n/10).writeln;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tn -= n%10;\n\t\t\t(n/10).writeln;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n writeln((n + 1) / 10);\n }\n}\n"}], "negative_code": [], "src_uid": "8e4194b356500cdaacca2b1d49c2affb"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tbool [long] cubes;\r\n\tfor (long s = 1; s <= 10 ^^ 4; s++)\r\n\t{\r\n\t\tcubes[s ^^ 3] = true;\r\n\t}\r\n\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(long);\r\n\t\tbool ok = false;\r\n\t\tfor (long s = 1; s ^^ 3 <= n; s++)\r\n\t\t{\r\n\t\t\tok |= ((n - s ^^ 3) in cubes) !is null;\r\n\t\t}\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n bool[long] memo;\r\n for (long b = 1; b^^3 <= 10L^^12; ++b) memo[b^^3] = true;\r\n int T; get(T); while (T--) {\r\n long X; get(X);\r\n for (long a = 1; a^^3 <= X; ++a) if (X - a^^3 in memo) {\r\n writeln(\"YES\");\r\n goto ok;\r\n }\r\n writeln(\"NO\");\r\n ok:\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto x = RD;\r\n\r\n\t\tfor (long i = 1; i^^3 < x; ++i)\r\n\t\t{\r\n\t\t\tauto a = i^^3;\r\n\t\t\tauto y = x - a;\r\n\t\t\tbool f(long j)\r\n\t\t\t{\r\n\t\t\t\tif (j > y/j) return false;\r\n\t\t\t\tif (j*j > y/j) return false;\r\n\t\t\t\treturn j^^3 <= y;\r\n\t\t\t}\r\n\t\t\tauto r = binarySearch!(f)(1, y+1);\r\n\t\t\tif (i == 5779)\r\n\t\t\t\tdebug writeln(\"i:\", i, \" r:\", r);\r\n\t\t\tans[ti] = true;\r\n\t\t\tforeach (j; 0..3)\r\n\t\t\t{\r\n\t\t\t\tif (y % r)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i == 5779)\r\n\t\t\t\t\t\tdebug writeln(\"y:\", y, \" r:\", r);\r\n\t\t\t\t\tans[ti] = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\ty /= r;\r\n\t\t\t}\r\n\t\t\tif (ans[ti] && y == 1)\r\n\t\t\t\tbreak;\r\n\t\t\telse\r\n\t\t\t\tans[ti] = false;\r\n\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "b4ca6a5ee6307ab2bcdab2ea5dd5b2b3"} {"source_code": "import std.algorithm;\nimport std.stdio;\n\nimmutable int MED_N = 10;\nimmutable int MAX_N = MED_N << 1;\nimmutable int POW_N = 1 << MAX_N;\n\nint [POW_N] a;\nint n;\n\nvoid main ()\n{\n while (scanf (\" %d\", &n) != EOF)\n {\n foreach (i; 0..n)\n {\n scanf (\" %d\", &a[i]);\n }\n sort (a[0..n]);\n reverse (a[0..n]);\n\n long k = 0;\n for (int p = n; p > 0; p >>= 2)\n {\n k++;\n }\n int cur = 1, total = 3;\n\n long res = 0;\n for (int i = 0; i < n; i++)\n {\n cur--;\n res += k * a[i];\n if (cur == 0)\n {\n k--;\n cur = total;\n total *= 4;\n }\n }\n\n writeln (res);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\n\nimmutable int MED_N = 10;\nimmutable int MAX_N = MED_N << 1;\nimmutable int POW_N = 1 << MAX_N;\n\nint [POW_N] a;\nint n;\n\nvoid main ()\n{\n while (scanf (\" %d\", &n) > 0)\n {\n foreach (i; 0..n)\n {\n scanf (\" %d\", &a[i]);\n }\n sort (a[0..n]);\n reverse (a[0..n]);\n\n long k = 0;\n for (int p = n; p > 0; p >>= 2)\n {\n k++;\n }\n int cur = 1, total = 3;\n\n long res = 0;\n for (int i = 0; i < n; i++)\n {\n cur--;\n res += k * a[i];\n if (cur == 0)\n {\n k--;\n cur = total;\n total *= 4;\n }\n }\n\n writeln (res);\n }\n}\n"}, {"source_code": "import std.stdio: readln, writeln;\nimport std.conv: to;\nimport std.string: strip;\nimport std.array: split;\nimport std.algorithm: sort, reverse;\n\n/**\n * User: Jior\n * Date: 04.06.13\n * Time: 17:55\n */\n\nvoid main(string[] args) {\n\tint countEls = to!int(strip(readln()));\n\tlong[] els = to!(long[])(strip(readln()).split());\n\tsort(els);\n\treverse(els);\n\n\tforeach (i, ref long el; els[1..$]) {\n\t\tel += els[i]; \n\t}\n\n\tlong result;\n\twhile (countEls > 0) {\n\t\tresult += els[countEls-1];\n\t\tcountEls /= 4; \n\t}\n\twriteln(result);\n}\n"}], "negative_code": [{"source_code": "import std.stdio: readln, writeln;\nimport std.conv: to;\nimport std.string: strip;\nimport std.array: split;\nimport std.algorithm: sort, reverse;\n\n/**\n * User: Jior\n * Date: 04.06.13\n * Time: 17:55\n */\n\nvoid main(string[] args) {\n\tint countEls = to!int(strip(readln()));\n\tint[] els = to!(int[])(strip(readln()).split());\n\tsort(els);\n\treverse(els);\n\n\tforeach (i, ref int el; els[1..$]) {\n\t\tel += els[i]; \n\t}\n\n\tlong result;\n\twhile (countEls > 0) {\n\t\tresult += els[countEls-1];\n\t\tcountEls /= 4; \n\t}\n\twriteln(result);\n}\n"}, {"source_code": "import std.stdio: readln, writeln;\nimport std.conv: to;\nimport std.string: strip;\nimport std.array: split;\n\nimport std.math: sqrt;\nimport std.algorithm: max;\n\n/**\n * User: Jior\n * Date: 04.06.13\n * Time: 17:55\n */\n\nint beauty(int[] mx) {\n\tint n = cast(int)sqrt(cast(float)mx.length);\n\tif (n == 1)\n\t\treturn mx[0];\n\t\n\tint m = mx[0];\n\tforeach(int l; mx[1..$]) {\n\t\tm = max(m, l);\n\t}\n\n\tint[] left, right;\n\tforeach (int i; 0..n) {\n\t\tleft ~= mx[i*n..((i+1)*n)-n/2];\n\t\tright ~= mx[i*n+n/2..(i+1)*n];\n\t}\n\n\treturn beauty(left[0..$/2]) + beauty(left[$/2..$]) + beauty(right[0..$/2]) + beauty(right[$/2..$]) + m;\n}\n\nvoid main(string[] args) {\n\tint countEls = to!int(strip(readln()));\n\tint[] els = to!(int[])(strip(readln()).split());\n\twriteln(beauty(els));\n}\n"}], "src_uid": "93f6404a23bd2ff867d63db9ddf868ff"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong mex(long[] a)\n{\n foreach (i ; 0L .. 10L) {\n bool good = true;\n foreach (x ; a) {\n if (x == i)\n good = false;\n }\n if (good)\n return i;\n }\n return -1L;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n\n long[] cache;\n long acc = 0;\n foreach (x ; 0L .. 3 * 100000 + 5) {\n acc ^= x;\n cache ~= acc;\n }\n\n assert(cache[4 - 1] == 0);\n assert(cache[5 - 1] == 4);\n\n while (t--) {\n long a, b;\n readf!\" %d %d \"(a, b);\n// writefln(\"a=%d b=%d\", a, b);\n/* if (mex([0L, b]) == a)\n writeln(2);\n else */ {\n long x = cache[cast(int)a - 1];\n if (x == b)\n writefln(\"%d\", a);\n else if ((x ^ b) != a)\n writefln(\"%d\", a + 1);\n else\n writefln(\"%d\", a + 2);\n }\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tauto arr = new long[]((10^^5) * 3);\r\n\tforeach (i; 1..(10^^5) * 3)\r\n\t{\r\n\t\tarr[i] = arr[i-1] ^ i;\r\n\t}\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD!int;\r\n\t\tauto b = RD!int;\r\n\r\n\t\tauto x = arr[a-1] ^ b;\r\n\t\t\r\n\t\tif (x == 0)\r\n\t\t\tans[ti] = a;\r\n\t\telse if (x == a)\r\n\t\t\tans[ti] = a + 2;\r\n\t\telse\r\n\t\t\tans[ti] = a + 1;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "immutable multi = true;\n\nint[3_00_000 + 3] cumulativeXor;\nstatic this()\n{\n\tcumulativeXor[0] = 0;\n\tforeach(i; 1 .. cumulativeXor.length)\n\t\tcumulativeXor[i] = cast(int)i ^ cumulativeXor[i-1];\n}\n\nvoid solve(int tc)\n{\n\tauto a = readInt!int;\n\tauto b = readInt!int;\n\tif (cumulativeXor[a-1] == b)\n\t{\n\t\twriteln(a);\n\t}\n\telse\n\t{\n\t\tauto req = cumulativeXor[a-1] ^ b;\n\t\tif (req < a)\n\t\t{\n\t\t\twriteln(a+1);\n\t\t}\n\t\telse if (req > a)\n\t\t{\n\t\t\twriteln(a+1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(a+2);\n\t\t}\n\t}\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong mex(long[] a)\n{\n foreach (i ; 0L .. 10L) {\n bool good = true;\n foreach (x ; a) {\n if (x == i)\n good = false;\n }\n if (good)\n return i;\n }\n return -1L;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n\n long[] cache;\n long acc = 0;\n foreach (x ; 0L .. 3 * 100000 + 5) {\n acc ^= x;\n cache ~= acc;\n }\n\n assert(cache[4 - 1] == 0);\n assert(cache[5 - 1] == 4);\n\n while (t--) {\n long a, b;\n readf!\" %d %d \"(a, b);\n// writefln(\"a=%d b=%d\", a, b);\n if (mex([0L, b]) == a)\n writeln(2);\n else {\n long x = cache[cast(int)a - 1];\n if (x == b)\n writefln(\"%d\", a);\n else if ((x ^ b) != a)\n writefln(\"%d\", a + 1);\n else\n writefln(\"%d\", a + 2);\n }\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong mex(long[] a)\n{\n foreach (i ; 0L .. 10L) {\n bool good = true;\n foreach (x ; a) {\n if (x == i)\n good = false;\n }\n if (good)\n return i;\n }\n return -1L;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long a, b;\n readf!\" %d %d \"(a, b);\n if (mex([0L, b]) != a)\n writeln(3);\n else\n writeln(2);\n }\n}\n"}], "src_uid": "d6790c9b4b2e488768fb4e746ee7ebe0"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n int[] a;\n for (int i = 0; i + 1 < n; i += 2) {\n a ~= (i + 1) + 1;\n a ~= (i + 0) + 1;\n }\n if (n % 2 == 1) {\n a ~= cast(int)a.length - 1;\n a[$ - 2] = cast(int)a.length;\n }\n writeln(a.map!text.joiner(\" \"));\n }\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1541/problem/A\n// greedy\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n if(n == 1) {\n \"1\".writeln;\n continue;\n }\n if(n % 2 == 0) {\n for(int i = 1; i <= n; ++i) {\n if(i % 2 == 1) {\n writef(\"%s \", i + 1);\n } else {\n writef(\"%s \", i - 1);\n }\n }\n \"\".writeln;\n continue;\n }\n \"2 3 1 \".write;\n for(int i = 4; i <= n; ++i) {\n if(i % 2 == 0) {\n writef(\"%s \", i + 1);\n } else {\n writef(\"%s \", i - 1);\n }\n }\n \"\".writeln;\n}\n}\n"}, {"source_code": "import std.stdio;\r\n\r\nvoid print(int start, int n) {\r\n if (start > n) return;\r\n write(start + 1, ' ', start,' ');\r\n print(start + 2, n);\r\n}\r\n\r\nvoid main() {\r\n int t, n;\r\n \r\n readf!\"%d\"(t);\r\n \r\n while (t--) {\r\n readf!\" %d\"(n);\r\n \r\n int start = 0;\r\n \r\n if (n >= 3 && n % 2 == 1) {\r\n write(\"3 1 2 \");\r\n print(4, n);\r\n } else {\r\n print(1, n);\r\n }\r\n writeln;\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1541/problem/A\n// greedy\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n writef(\"%s \", n);\n for(int i = 1; i < n; ++i) {\n writef(\"%s \", i);\n } \"\".writeln;\n}\n}\n"}], "src_uid": "f89bd4ec97ec7e02a7f67feaeb4d3958"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta.schwartzSort !(q{a & 1});\r\n\t\twritefln !(\"%(%s %)\") (a);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.stdio, std.string;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.strip)) {\r\n int n = to!int(readln.strip);\r\n auto ar = readln.split.map!(to!int).array;\r\n ar.partition!\"a%2\";\r\n writeln(ar.map!(to!string).join(\" \"));\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "fe2131c9228a2ec4365fdc3d0faa413a"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(uint M_) {\n import std.conv : to;\n alias M = M_;\n uint x;\n this(ModInt a) { x = a.x; }\n this(uint x_) { x = x_ % M; }\n this(ulong x_) { x = cast(uint)(x_ % M); }\n this(int x_) { x = ((x_ %= cast(int)(M)) < 0) ? (x_ + cast(int)(M)) : x_; }\n this(long x_) { x = cast(uint)(((x_ %= cast(long)(M)) < 0) ? (x_ + cast(long)(M)) : x_); }\n ref ModInt opAssign(T)(inout(T) a) if (is(T == uint) || is(T == ulong) || is(T == int) || is(T == long)) { return this = ModInt(a); }\n ref ModInt opOpAssign(string op, T)(T a) {\n static if (is(T == ModInt)) {\n static if (op == \"+\") { x = ((x += a.x) >= M) ? (x - M) : x; }\n else static if (op == \"-\") { x = ((x -= a.x) >= M) ? (x + M) : x; }\n else static if (op == \"*\") { x = cast(uint)((cast(ulong)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n } else static if (op == \"^^\") {\n if (a < 0) return this = inv()^^(-a);\n ModInt b = this, c = 1U;\n for (long e = a; e; e >>= 1) { if (e & 1) c *= b; b *= b; }\n return this = c;\n } else {\n return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n }\n ModInt inv() const {\n uint a = M, b = x; int y = 0, z = 1;\n for (; b; ) { const q = a / b; const c = a - q * b; a = b; b = c; const w = y - cast(int)(q) * z; y = z; z = w; }\n assert(a == 1); return ModInt(y);\n }\n ModInt opUnary(string op)() const {\n static if (op == \"+\") { return this; }\n else static if (op == \"-\") { ModInt a; a.x = x ? (M - x) : 0U; return a; }\n else static assert(false);\n }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op, T)(T a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n bool opCast(T: bool)() const { return (x != 0U); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 998244353;\nalias Mint = ModInt!MO;\n\nenum LIM = 2 * 10^^6 + 10;\nMint[] inv, fac, invFac;\nvoid prepare() {\n inv = new Mint[LIM];\n fac = new Mint[LIM];\n invFac = new Mint[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = -((Mint.M / i) * inv[cast(size_t)(Mint.M % i)]);\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = fac[i - 1] * i;\n invFac[i] = invFac[i - 1] * inv[i];\n }\n}\nMint binom(long n, long k) {\n if (n < 0) {\n if (k >= 0) {\n return (-1)^^(k & 1) * binom(-n + k - 1, k);\n } else if (n - k >= 0) {\n return (-1)^^((n - k) & 1) * binom(-k - 1, n - k);\n } else {\n return Mint(0);\n }\n } else {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\n } else {\n return Mint(0);\n }\n }\n}\n\n\n\nvoid main() {\n prepare;\n \n /*\n debug {\n foreach (n; 1 .. 5 + 1) {\n auto freq = new int[string][n];\n auto ps = iota(n).array;\n do {\n int[] qs = ps.dup;\n int[][] qss = [qs.dup];\n foreach (k; 0 .. n - 1) {\n foreach (i; 0 .. n - 1) {\n if (qs[i] > qs[i + 1]) {\n swap(qs[i], qs[i + 1]);\n }\n }\n qss ~= qs.dup;\n }\n auto rss = new int[][](n, n);\n foreach (k; 0 .. n) {\n foreach (i; 0 .. n) {\n foreach (j; 0 .. i) if (qss[k][j] > qss[k][i]) {\n ++rss[k][i];\n }\n }\n }\n writeln(qss, \" \", rss);\n foreach (k; 0 .. n - 1) {\n auto fs = rss[k].dup;\n auto gs = rss[k + 1].dup;\n fs.sort;\n gs.sort;\n foreach (i; 0 .. n) {\n assert(max(fs[i] - 1, 0) == gs[i]);\n }\n }\n foreach (k; 0 .. n) {\n ++freq[k][rss[k].to!string];\n }\n } while (ps.nextPermutation);\n foreach (k; 0 .. n) {\n foreach (rs, val; freq[k]) {\n writeln(k, \" \", rs, \": \", val);\n }\n }\n }\n // return;\n }\n */\n \n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n const K = readInt;\n auto V = new int[N];\n foreach (i; 0 .. N) {\n V[i] = readInt;\n }\n \n Mint ans = 1;\n foreach (i; 0 .. N - K) {\n if (~V[i]) {\n if (V[i] == 0) {\n ans *= (K + 1);\n }\n } else {\n ans *= ((K + 1) + i);\n }\n }\n foreach (i; N - K .. N) {\n if (~V[i]) {\n if (V[i] != 0) {\n ans = 0;\n }\n }\n ans *= (N - i);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int mod = 998_244_353;\r\n\r\nint solve (int [] a, int n, int k)\r\n{\r\n\tforeach (i; 0..n - k)\r\n\t{\r\n\t\tif (a[i] > i)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (i; n - k..n)\r\n\t{\r\n\t\tif (a[i] > 0)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n\r\n\tint res = 1;\r\n\tforeach (i; 0..k)\r\n\t{\r\n\t\tres = (res * 1L * (i + 1)) % mod;\r\n\t}\r\n\tforeach (i; 0..n - k)\r\n\t{\r\n\t\tif (a[i] == -1)\r\n\t\t{\r\n\t\t\tres = (res * 1L * (i + k + 1)) % mod;\r\n\t\t}\r\n\t\telse if (a[i] == 0)\r\n\t\t{\r\n\t\t\tres = (res * 1L * (k + 1)) % mod;\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (a, n, k));\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "f2b2d12ab1c8a511d2ca550faa9768d4"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(int[]);\n auto xs = new int[](5001);\n auto ls = new int[](5001);\n foreach (i; 1..N+1) {\n auto a = as[i-1];\n if (xs[a]) {\n if (xs[a] > 1) goto ok;\n if (ls[a] != i-1) goto ok;\n }\n ++xs[a];\n ls[a] = i;\n }\n writeln(\"NO\");\n continue;\n ok:\n writeln(\"YES\");\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA(-1);\n\t\tauto cnt = new int[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tcnt[a[i]] ~= i;\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (cnt[i].length <= 1) continue;\n\t\t\tif (cnt[i].length >= 3)\n\t\t\t{\n\t\t\t\tans[ti] = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (cnt[i][0]+1 != cnt[i][1])\n\t\t\t\t{\n\t\t\t\t\tans[ti] = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(int[]);\n foreach (i; 0..N) {\n if (i+2 < N && as[i] == as[i+2]) goto ok;\n if (i+3 < N && as[i] == as[i+3] && as[i+1] == as[i+2]) goto ok;\n }\n writeln(\"NO\");\n continue;\n ok:\n writeln(\"YES\");\n }\n}"}], "src_uid": "5139d222fbbfa70d50e990f5d6c92726"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!long;\n auto isPrime(long m)\n {\n for (long d = 2; d * d <= m; d++)\n if (m % d == 0) return false;\n return true;\n }\n n--;\n for (long d = 2;; d++)\n {\n if (isPrime(d) && n % d != 0)\n\t{\n\t writeln(n - d, \" \", d, \" \", 1);\n\t return;\n\t}\n }\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.numeric;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tint c = 1;\r\n\t\tint a = n - n / 2;\r\n\t\tint b = n - a - c;\r\n\t\tif (gcd (a, b) != c)\r\n\t\t{\r\n\t\t\ta += 1;\r\n\t\t\tb -= 1;\r\n\t\t}\r\n\t\tif (gcd (a, b) != c)\r\n\t\t{\r\n\t\t\tassert (false);\r\n\t\t}\r\n\t\twriteln (a, \" \", b, \" \", c);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD;\r\n\r\n\t\tif (n % 2)\r\n\t\t{\r\n\t\t\t--n;\r\n\t\t\tauto x = n / 2;\r\n\t\t\tauto d = x % 2 ? 2 : 1;\r\n\t\t\tans[ti] = [x-d, x+d, 1];\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tans[ti] = [n/2, n/2-1, 1];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e[0], \" \", e[1], \" \", e[2]);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std;\n\nT read (T, string ending = \"\", string beginning = \"\") () @trusted {\n scope T x;\n readf!(beginning ~ \"%s\" ~ ending)(x);\n return x;\n}\n\nvoid main () {\n immutable tests = readln.chomp.to!uint;\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n immutable n =\n readln().chomp()\n .to!uint;\n\n if (n % 2 == 0) {\n writeln(n - 3, \" 2 1\");\n } else {\n immutable half = n / 2;\n\n immutable first = half - (half % 2 == 0 ? 1 : 2);\n immutable second = half + (half % 2 == 0 ? 1 : 2);\n\n writeln(first, ' ', second, ' ', 1);\n }\n }\n}\n\n// \"\" `` '' () {} []\n"}], "negative_code": [{"source_code": "import std;\r\n\r\nvoid main () {\r\n int t;\r\n readf(\"%s\\n\", t);\r\n\r\n foreach (i; 0 .. t) {\r\n int a;\r\n readf(\"%s\\n\", a);\r\n if (a % 2 == 0) {\r\n writeln(2, ' ', a - 3, ' ' , 1);\r\n } else {\r\n writeln(a / 2 - 1, ' ', a / 2 + 1, ' ', 1);\r\n }\r\n }\r\n}\r\n\r\n//\"\"\r\n"}, {"source_code": "import std;\r\n\r\nvoid main () {\r\n int t;\r\n readf(\"%s\\n\", t);\r\n\r\n foreach (i; 0 .. t) {\r\n int a;\r\n readf(\"%s\\n\", a);\r\n if (a % 2 == 0) {\r\n writeln(2, ' ', a - 3, ' ' , 1);\r\n } else {\r\n writeln((a - 1) / 2, ' ', (a + 1) / 2, ' ', 1);\r\n }\r\n }\r\n}\r\n\r\n//\"\"\r\n"}, {"source_code": "import std;\r\n\r\nvoid main () {\r\n int t;\r\n readf(\"%s\\n\", t);\r\n\r\n foreach (i; 0 .. t) {\r\n int a;\r\n readf(\"%s\\n\", a);\r\n if (a % 2 == 0) {\r\n write(2, ' ', a - 3, ' ' , 1);\r\n } else {\r\n write((a - 1) / 2, ' ', (a + 1) / 2, ' ', 1);\r\n }\r\n }\r\n}\r\n\r\n//\"\"\r\n"}], "src_uid": "d4f4d6341f52cceb862faa89e85a42a3"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n\r\n bool check(int[] xs) {\r\n if (xs.length <= 2) return true;\r\n auto n = xs.length;\r\n for (int i = 0; i < n; i++) {\r\n for (int j = i+1; j < n; j++) {\r\n for (int k = j+1; k < n; k++) {\r\n if (xs[i] <= xs[j] && xs[j] <= xs[k]) return false;\r\n if (xs[i] >= xs[j] && xs[j] >= xs[k]) return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n int ans = 0;\r\n for (int l = 0; l < N; l++) {\r\n for (int r = l + 1; r <= min(l + 4, N); r++) {\r\n if (check(A[l..r])) {\r\n //writeln([l, r]);\r\n ans++;\r\n }\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\t\r\n\t\tif (n == 1)\r\n\t\t{\r\n\t\t\tans[ti] = 1;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tans[ti] = 3;\r\n\t\tbool f(int i, int j, int k)\r\n\t\t{\r\n\t\t\treturn inside(a[j], min(a[i], a[k]), max(a[i], a[k])+1);\r\n\t\t}\r\n\t\tforeach (i; 0..n-2)\r\n\t\t{\r\n\t\t\tif (f(i, i+1, i+2))\r\n\t\t\t\tans[ti] += 2;\r\n\t\t\telse \r\n\t\t\t{\r\n\t\t\t\tans[ti] += 3;\r\n\t\t\t\tif (i + 3 < n)\r\n\t\t\t\t{\r\n\t\t\t\t\tbool ok = true;\r\n\t\t\t\t\t(){\r\n\t\t\t\t\tforeach (l; i..i+2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tforeach (m; l+1..i+4)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tforeach (r; m+1..i+4)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (f(l, m, r))\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tok = false;\r\n\t\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}}();\r\n\t\t\t\t\tif (ok)\r\n\t\t\t\t\t\t++ans[ti];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n long result = 0;\n foreach (i ; 0 .. n) {\n if (i + 2 < n) {\n int x1 = a[i];\n int x2 = a[i + 1];\n int x3 = a[i + 2];\n if ((x2 > x1 && x2 > x3) || (x2 < x1 && x2 < x3))\n result++;\n }\n if (i + 3 < n) {\n int x1 = a[i];\n int x2 = a[i + 1];\n int x3 = a[i + 2];\n int x4 = a[i + 3];\n if ((x2 > x1 && x2 > x4) && (x3 < x1 && x3 < x4))\n result++;\n else if ((x2 < x1 && x2 < x4) && (x3 > x1 && x3 > x4))\n result++;\n }\n }\n writeln(result + n + n - 1);\n }\n}\n"}], "negative_code": [], "src_uid": "e87ff02ce425fc3e96c09a15679aa656"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!int;\n int[] rs;\n int k = 0;\n while (N) {\n if (N%10 != 0) {\n rs ~= N%10 * 10^^k;\n }\n N /= 10;\n ++k;\n }\n writeln(rs.length);\n writeln(rs.to!(string[]).join(\" \"));\n }\n}", "positive_code": [{"source_code": "void main() {\n\tauto t = ri;\n\tforeach(i; 0..t) {\n\t\tauto S = rs;\n\t\tulong cnt;\n\t\tulong[] l;\n\t\tforeach(j, c; S) {\n\t\t\tif(c != '0') {\n\t\t\t\tcnt++;\n\t\t\t\tl ~= 10 ^^ (S.length - j - 1) * (c - '0');\n\t\t\t}\n\t\t}\n\t\tcnt.writeln;\n\t\twritefln(\"%(%d %)\", l);\n\t}\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\nlong rl() {\n\treturn readAs!long;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}"}, {"source_code": "import std.stdio;\n \nint main() {\n int t;\n readf(\"%d\\n\", &t);\n while(t--) {\n \tint n;\n \treadf(\"%d\\n\", &n);\n \tint[] result;\n \tint d = 1;\n \twhile(n > 0) {\n \t\tif(n % 10 != 0)\n \t\t\tresult ~= (n % 10) * d;\n \t\td *= 10;\n \t\tn /= 10;\n \t}\n \t\n \twriteln(result.length);\n\t\tforeach(x; result)\n\t\t\twrite(x, \" \");\n \twriteln();\n }\n \n return 0;\n}"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\t\tauto d = s.length;\n\t\tstring [] ans;\n\t\tforeach (i, c; s)\n\t\t{\n\t\t\tif (c > '0')\n\t\t\t{\n\t\t\t\tans ~= c ~ \"0\".repeat (d - i - 1).joiner.text;\n\t\t\t}\n\t\t}\n\t\twriteln (ans.length);\n\t\twritefln !(\"%-(%s %)\") (ans);\n\t}\n}\n"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\n// dynamic programming with large constant, run once at the start\nimport std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nauto prepare (int limit)\n{\n\tauto moves = iota (1, limit)\n\t .filter !(j => j.text.count !(q{a > '0'}) == 1).array;\n\tauto f = new int [] [limit];\n\tforeach (i; moves)\n\t{\n\t\tf[i] ~= i;\n\t}\n\tforeach (i; 1..limit)\n\t{\n\t\tforeach (j; moves)\n\t\t{\n\t\t\tif (j < i)\n\t\t\t{\n\t\t\t\tif (f[i] is null || f[i].length >\n\t\t\t\t f[i - j].length + uniform (0, 2))\n\t\t\t\t{\n\t\t\t\t\tf[i] = f[i - j] ~ j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn f;\n}\n\nvoid main ()\n{\n\trndGen.seed (25256);\n\tauto f = prepare (10001);\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\twriteln (f[n].length);\n\t\twritefln !(\"%(%s %)\") (f[n]);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid calc(int n) {\n int[] ans;\n int x = 1000000;\n while (x > 0) {\n int t = n / x;\n if (t > 0) ans ~= t * x;\n n %= x;\n x /= 10;\n }\n writeln(ans.length);\n writeln(ans.map!text.join(' '));\n}\n\nvoid main() {\n int t; scan(t);\n foreach (_; 0..t) {\n int n; scan(n);\n calc(n);\n }\n}\n\nvoid scan(T...)(ref T a) {\n string[] ss = readln.split;\n foreach (i, t; T) a[i] = ss[i].to!t;\n}\nT read(T=string)() { return readln.chomp.to!T; }\nT[] reads(T)() { return readln.split.to!(T[]); }\nalias readints = reads!int;\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.conv;\nimport std.string;\n\nT readNum(T)(){\n return readStr.to!T;\n}\n\nT[] readNums(T)(){\n return readStr.split.to!(T[]);\n}\n\nstring readStr(){\n return readln.chomp;\n}\n\nvoid main(){\n auto t = readNum!int;\n\n foreach(i; 0 .. t){\n auto s = readStr;\n auto n = s.length - count(s, \"0\");\n writeln(n);\n\n foreach_reverse(j, e; s){\n if(e != '0'){\n write(e);\n foreach(k; 0 .. s.length - j - 1){\n write(\"0\");\n }\n write(\" \");\n }\n }\n\n writeln();\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!string;\n\t\tforeach (i; 0..n.length)\n\t\t{\n\t\t\tif (n[i] != '0')\n\t\t\t{\n\t\t\t\tans[ti] ~= (n[i]-'0') * 10^^(n.length-i-1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\te.map!(to!string).join(\" \").writeln();\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "cd2519f4a7888b2c292f05c64a9db13a"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n int[int] cnt;\n readln.chomp.split.each!(x => ++cnt[x.to!int]);\n \n debug { cnt.writeln; }\n \n cnt.remove(0);\n if (cnt.values.any!(x => x > 2)) {\n writeln(-1);\n return;\n }\n \n cnt.values.count!(x => x == 2).writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint [int] v;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint id;\n\t\t\treadf (\" %s\", &id);\n\t\t\tif (id != 0)\n\t\t\t{\n\t\t\t\tv[id]++;\n\t\t\t}\n\t\t}\n\t\tint res = 0;\n\t\tforeach (u; v)\n\t\t{\n\t\t\tif (u > 2)\n\t\t\t{\n\t\t\t\tres = -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (u == 2)\n\t\t\t{\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "module sigod.codeforces.p291A;\n\nimport std.algorithm;\nimport std.stdio;\n\nvoid main()\n{\n\tint n;\n\tstdin.readf(\" %s\", &n);\n\n\tint[] d = new int[n];\n\tforeach (i; 0 .. n) {\n\t\tstdin.readf(\" %s\", &d[i]);\n\t}\n\n\tstdout.writeln(solve(d));\n}\n\n//*\n\nint solve(int[] d)\n{\n\td.sort();\n\n\tint start = -1;\n\tforeach (i, di; d) {\n\t\tif (di != 0) {\n\t\t\tstart = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (start != -1) {\n\t\td = d[start .. $];\n\t}\n\telse if (d[d.length - 1] == 0) {\n\t\treturn 0;\n\t}\n\n\tint count = 0;\n\n\tforeach (tuple; d.group()) {\n\t\tif (tuple[1] == 2) {\n\t\t\t++count;\n\t\t}\n\t\telse if (tuple[1] > 2) {\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\treturn count;\n}\n\nunittest {\n\tassert(solve([0, 1, 7, 1, 7, 10]) == 2);\n\tassert(solve([1, 1, 1]) == -1);\n\tassert(solve([0]) == 0);\n}"}, {"source_code": "import std.stdio, std.conv, std.string;\nvoid main()\n{\n uint n;\n readf(\"%d\\n\", &n);\n uint[uint] sessions;\n uint session;\n uint pairs;\n string sessionString;\n sessionString = readln();\n foreach(i;0..n)\n {\n session = parse!uint(sessionString);\n munch(sessionString, \" \");\n if (session == 0) continue;\n if (session !in sessions)\n {\n sessions[session] = 1;\n }\n else\n {\n ++sessions[session];\n ++pairs;\n if (sessions[session] > 2)\n {\n write(-1);\n return;\n }\n }\n }\n write(pairs);\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\tint n;\n\treadf(\" %s\", &n);\n\tint[] a;\n\ta.length = n;\n\tfor (int i = 0; i < n; i++) {\n\t\treadf(\" %s\", &a[i]);\n\t}\n\t \n\tsort(a);\n\tint cnt = 0;\n\tint ans = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tif (a[i] == 0)\n\t\t\tcontinue;\n\t\tif (i > 0 && a[i] == a[i - 1])\n\t\t\t++cnt;\n\t\telse\n\t\t\tcnt = 1;\n\n\t\tif (cnt > 2) {\n\t\t\tans = -1;\n\t\t\tbreak;\n\t\t}\n\t\tif (cnt == 2)\n\t\t\t++ans;\n\t}\n\twriteln(ans);\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string;\nvoid main()\n{\n\tuint n;\n\treadf(\"%d\\n\", &n);\n\tuint[uint] sessions;\n\tuint session;\n\tuint pairs;\n\tstring sessionString;\n\tsessionString = readln();\n\tforeach(i;0..n)\n\t{\n\t\tsession = parse!uint(sessionString);\n\t\tmunch(sessionString, \" \");\n\t\tif (session !in sessions)\n\t\t{\n\t\t\tsessions[session] = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t++sessions[session];\n\t\t\t++pairs;\n\t\t\tif (sessions[session] > 2)\n\t\t\t{\n\t\t\t\twrite(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\twrite(pairs);\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\tint n;\n\treadf(\" %s\", &n);\n\tint[] a;\n\ta.length = n;\n\tfor (int i = 0; i < n; i++) {\n\t\treadf(\" %s\", &a[i]);\n\t}\n\t \n\tsort(a);\n\tint cnt = 1;\n\tint ans = 0;\n\tfor (int i = 1; i < n; i++) {\n\t\tif (a[i] == a[i - 1])\n\t\t\t++cnt;\n\t\telse\n\t\t\tcnt = 1;\n\n\t\tif (cnt > 2) {\n\t\t\tans = -1;\n\t\t\tbreak;\n\t\t}\n\t\tif (cnt == 2)\n\t\t\t++ans;\n\t}\n\twriteln(ans);\n}\n"}], "src_uid": "45e51f3dee9a22cee86e1a98da519e2d"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto c = new int [] [] (n, k);\n\t\tauto d = new long [] [] (n, k);\n\t\tlong res = 0;\n\n\t\tvoid recur (int v, int p)\n\t\t{\n\t\t\tc[v][0] = 1;\n\t\t\tc[v][1..$] = 0;\n\t\t\td[v][0] = 0;\n\t\t\td[v][1..$] = 0;\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tif (u == p)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\trecur (u, v);\n\t\t\t\tforeach (i; 0..k)\n\t\t\t\t{\n\t\t\t\t\tforeach (j; 0..k)\n\t\t\t\t\t{\n\t\t\t\t\t\tint carry = (i + j + 1 > 0) +\n\t\t\t\t\t\t (i + j + 1 > k);\n\t\t\t\t\t\tres += d[v][i] * c[u][j];\n\t\t\t\t\t\tres += d[u][j] * c[v][i];\n\t\t\t\t\t\tres += carry * c[u][j] * 1L *\n\t\t\t\t\t\t c[v][i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tforeach (i; 0..k)\n\t\t\t\t{\n\t\t\t\t\tint j = i + 1;\n\t\t\t\t\tif (j == k)\n\t\t\t\t\t{\n\t\t\t\t\t\tj = 0;\n\t\t\t\t\t}\n\t\t\t\t\tc[v][j] += c[u][i];\n\t\t\t\t\td[v][j] += d[u][i];\n\t\t\t\t\tif (j == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\td[v][j] += c[u][i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0, -1);\n\t\tdebug {writeln (c); writeln (d);}\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, K;\nint[] A, B;\n\nint[][] G;\nlong ans;\n\nvoid solveCentroidDecomp() {\n auto sz = new int[N];\n auto del = new bool[N];\n void dfsSz(int u, int p) {\n sz[u] = 1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n dfsSz(v, u);\n sz[u] += sz[v];\n }\n }\n }\n dfsSz(0, -1);\n\n // r: centroid\n void solveSubtree(int r) {\n debug {\n string dfsDebug(int u, int p) {\n string ret = u.to!string;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n ret ~= \"(\" ~ dfsDebug(v, u) ~ \")\";\n }\n }\n return ret;\n }\n writeln(\"solveSubtree \", dfsDebug(r, -1));\n }\n \n int[] vs;\n foreach (i; G[r]) {\n const v = A[i] ^ B[i] ^ r;\n if (!del[v]) {\n vs ~= v;\n }\n }\n \n const len = cast(int)(vs.length);\n auto fs0 = new long[K];\n auto fs1 = new long[K];\n auto gs0 = new long[][](len, K);\n auto gs1 = new long[][](len, K);\n \n void dfs(int j, int u, int p, int d) {\n fs0[d % K] += 1;\n fs1[d % K] += d;\n gs0[j][d % K] += 1;\n gs1[j][d % K] += d;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n dfs(j, v, u, d + 1);\n }\n }\n }\n fs0[0] += 1;\n fs1[0] += 0;\n foreach (j; 0 .. len) {\n dfs(j, vs[j], r, 1);\n }\n \n debug {\n writeln(\"fs0 = \", fs0);\n writeln(\"gs1 = \", fs1);\n writeln(\"fs0 = \", gs0);\n writeln(\"gs1 = \", gs1);\n }\n foreach (x; 0 .. K) foreach (y; 0 .. K) {\n const z = (K - (x + y) % K) % K;\n ans += fs1[x] * fs0[y];\n ans += fs0[x] * fs1[y];\n ans += fs0[x] * fs0[y] * z;\n foreach (j; 0 .. len) {\n ans -= gs1[j][x] * gs0[j][y];\n ans -= gs0[j][x] * gs1[j][y];\n ans -= gs0[j][x] * gs0[j][y] * z;\n }\n }\n }\n\n void solveRec(int u) {\n for (; ; ) {\n int vm = -1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (vm == -1 || sz[vm] < sz[v]) {\n vm = v;\n }\n }\n }\n if (vm == -1 || sz[u] >= 2 * sz[vm]) {\n solveSubtree(u);\n del[u] = true;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n solveRec(v);\n }\n }\n break;\n } else {\n sz[u] -= sz[vm];\n sz[vm] += sz[u];\n u = vm;\n }\n }\n }\n solveRec(0);\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n K = readInt();\n A = new int[N - 1];\n B = new int[N - 1];\n foreach (i; 0 .. N - 1) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n G = new int[][N];\n foreach (i; 0 .. N - 1) {\n G[A[i]] ~= i;\n G[B[i]] ~= i;\n }\n \n ans = 0;\n solveCentroidDecomp;\n ans /= K;\n ans /= 2;\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "0b4362204bb9f0e95eaf7e2949315c8f"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto k = next!int - 1;\n auto perm = new int[](n);\n void solve(int i, int j, int l)\n {\n debug writeln(i, \" \", j, \" \", l, \" \", k);\n if (k == 0 || j - i == 1)\n {\n\tint v = l;\n\tforeach(k; i .. j)\n\t {\n\t perm[k] = v;\n\t v++;\n\t }\n\treturn;\n }\n int mid = (i + j) / 2;\n auto ls = mid - i;\n auto rs = j - i - ls;\n k -= 2;\n solve(i, mid, l + rs);\n solve(mid, j, l);\n }\n solve(0, n, 1);\n if (k != 0) return (-1).writeln;\n perm.each!(p => p.write(\" \")), writeln;\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n if (k % 2 == 0) {\n writeln(-1);\n return;\n }\n \n auto nodes = new int[] (n+1);\n nodes[1] = 1;\n foreach (i; 2 .. n+1) {\n int lft = i/2;\n int rt = i - lft;\n nodes[i] = nodes[lft] + 1 + nodes[rt];\n }\n \n \n if (nodes[n] < k) {\n writeln(-1);\n return;\n }\n \n auto arr = (n+1).iota.dropOne.array;\n \n void go(int le, int r, int need) {\n if (le+1 == r) { return; }\n \n if (need == 0) { return; }\n \n int md = (le + r) / 2;\n \n swap(arr[md-1], arr[md]);\n need -= 2;\n \n int capLft = nodes[md - le] - 1;\n int needLft = min(need, capLft);\n go(le, md, needLft);\n go(md, r, need - needLft);\n }\n \n go(0, n, k-1);\n \n arr.writefln!\"%(%s %)\";\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n if (k % 2 == 0) {\n writeln(-1);\n return;\n }\n \n auto szCap = new int[] (n+1);\n \n int getCap(int sz) {\n if (szCap[sz] != 0) { return szCap[sz]; }\n \n foreach (i; 1 .. 20) {\n int val = 1 << i;\n if (val > n) { break; }\n \n if (! (val & sz) ) { continue; }\n \n szCap[sz] += val * 2 - 1;\n }\n \n return szCap[sz];\n }\n \n if (getCap(n) < k) {\n writeln(-1);\n return;\n }\n \n auto arr = (n+1).iota.dropOne.array;\n \n void go(int le, int r, int need) {\n if (le+1 == r) { return; }\n \n if (need == 0) { return; }\n \n int md = (le + r) / 2;\n \n swap(arr[md-1], arr[md]);\n need -= 2;\n \n int capLft = getCap(md - le);\n int needLft = min(need, capLft);\n go(le, md, needLft);\n go(md, r, need - needLft);\n }\n \n go(0, n, k-1);\n \n arr.writefln!\"%(%s %)\";\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n if (k % 2 == 0) {\n writeln(-1);\n return;\n }\n \n auto nodes = new int[] (n+1);\n \n int getNodes(int sz) {\n if (nodes[sz] != 0) { return nodes[sz]; }\n \n foreach (i; 0 .. 20) {\n int val = 1 << i;\n if (val > n) { break; }\n \n if (! (val & sz) ) { continue; }\n \n nodes[sz] += val * 2 - 1;\n }\n \n return nodes[sz];\n }\n \n if (getNodes(n) < k) {\n writeln(-1);\n return;\n }\n \n auto arr = (n+1).iota.dropOne.array;\n \n void go(int le, int r, int need) {\n if (le+1 == r) { return; }\n \n if (need == 0) { return; }\n \n int md = (le + r) / 2;\n \n swap(arr[md-1], arr[md]);\n need -= 2;\n \n int capLft = getNodes(md - le) - 1;\n int needLft = min(need, capLft);\n go(le, md, needLft);\n go(md, r, need - needLft);\n }\n \n go(0, n, k-1);\n \n arr.writefln!\"%(%s %)\";\n}"}], "src_uid": "55ffdab213ed5b00d2ff69f0f91c0c74"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readLong();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n long df(int i, long b) {\n return A[i] - 1 - 3 * b * (1 + b);\n }\n \n long calc(int i, long val) {\n // >= val, < val\n long lo = -1, hi = A[i];\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n ((df(i, mid) >= val) ? lo : hi) = mid;\n }\n return hi;\n }\n \n // >= K, < K\n long lo = -4 * 10L^^18, hi = 2 * 10L^^9;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n long num;\n foreach (i; 0 .. N) {\n num += calc(i, mid);\n }\n ((num >= K) ? lo : hi) = mid;\n }\n debug {\n // writeln(\"lo = \", lo, \", hi = \", hi);\n }\n \n auto bs = new long[N];\n long now;\n foreach (i; 0 .. N) {\n now += bs[i] = calc(i, hi);\n }\n foreach (i; 0 .. N) {\n if (now < K && bs[i] < A[i] && df(i, bs[i]) == lo) {\n ++now;\n ++bs[i];\n }\n }\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(bs[i]);\n }\n writeln();\n \n debug {\n auto brt = new long[N];\n foreach (k; 0 .. K) {\n long mx = long.min;\n int im = -1;\n foreach (i; 0 .. N) {\n if (brt[i] < A[i]) {\n if (chmax(mx, df(i, brt[i]))) {\n im = i;\n }\n }\n }\n assert(im != -1);\n // writeln(im, \" \", mx);\n ++brt[im];\n }\n writeln(brt);\n assert(brt == bs);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\n\nimmutable long infinity = 3 * 10L ^^ 18;\n\nlong fun (int a, int b) {\n\treturn b * 3L * (b - 1) - a + 1;\n}\n\nint lastB (long border, int a) {\n\tint lo = 0;\n\tint hi = a;\n\twhile (lo < hi) {\n\t\tint me = (lo + hi + 1) / 2;\n\t\tlong cur = fun (a, me);\n\t\tif (cur > border)\n\t\t\thi = me - 1;\n\t\telse\n\t\t\tlo = me;\n\t}\n\treturn lo;\n}\n\nvoid main () {\n\tint n;\n\tlong k;\n\twhile (readf !(\" %s %s\") (n, k) > 0) {\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong lo = -infinity;\n\t\tlong hi = +infinity;\n\t\twhile (lo < hi) {\n\t\t\tlong me = lo + (hi - lo) / 2;\n\t\t\tlong cur = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t\tcur += lastB (me, a[i]);\n\t\t\tif (cur >= k)\n\t\t\t\thi = me;\n\t\t\telse\n\t\t\t\tlo = me + 1;\n\t\t}\n\n\t\tauto b = a.dup;\n\t\tforeach (i; 0..n) {\n\t\t\tb[i] = lastB (lo, a[i]);\n\t\t\tk -= b[i];\n\t\t}\n\t\tforeach (i; 0..n) {\n\t\t\tif (k < 0 && fun (a[i], b[i]) == lo) {\n\t\t\t\tk += 1;\n\t\t\t\tb[i] -= 1;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%s %)\") (b);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable long infinity = 3 * 10L ^^ 18;\n\nlong fun (int a, int b)\n{\n\treturn b * 3L * (b - 1) - a + 1;\n}\n\nint lastB (long border, int a)\n{\n\tint lo = 0;\n\tint hi = a;\n\twhile (lo < hi)\n\t{\n\t\tint me = (lo + hi + 1) / 2;\n\t\tlong cur = fun (a, me);\n\t\tif (cur > border)\n\t\t{\n\t\t\thi = me - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlo = me;\n\t\t}\n\t}\n\treturn lo;\n}\n\nvoid main ()\n{\n\tint n;\n\tlong k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong total = a.sum (0L);\n\t\tlong lo = -infinity;\n\t\tlong hi = +infinity;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tlong me = lo + (hi - lo) / 2;\n\t\t\tlong cur = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tcur += lastB (me, a[i]);\n\t\t\t}\n//\t\t\twriteln (lo, \" \", me, \" \", hi, \" \", cur);\n\t\t\tif (cur >= k)\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo = me + 1;\n\t\t\t}\n\t\t}\n\n\t\tauto b = a.dup;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb[i] = lastB (lo, a[i]);\n\t\t\tk -= b[i];\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n//\t\t\twriteln (i, \" \", k, \" \", fun (a[i], b[i]), \" \", lo);\n\t\t\tif (k < 0 && fun (a[i], b[i]) == lo)\n\t\t\t{\n\t\t\t\tk += 1;\n\t\t\t\tb[i] -= 1;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%s %)\") (b);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable long infinity = 4 * 10L ^^ 18;\n\nlong fun (int a, int b)\n{\n\treturn b * 3L * (b - 1) - a + 1;\n}\n\nint lastB (long border, int a)\n{\n\tint lo = 0;\n\tint hi = a;\n\twhile (lo < hi)\n\t{\n\t\tint me = (lo + hi + 1) / 2;\n\t\tlong cur = fun (a, me);\n\t\tif (cur > border)\n\t\t{\n\t\t\thi = me - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlo = me;\n\t\t}\n\t}\n\treturn lo;\n}\n\nvoid main ()\n{\n\tint n;\n\tlong k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong total = a.sum (0L);\n\t\tlong lo = 0;\n\t\tlong hi = infinity;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tlong me = (lo + hi) / 2;\n\t\t\tlong cur = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tcur += lastB (me, a[i]);\n\t\t\t}\n//\t\t\twriteln (lo, \" \", me, \" \", hi, \" \", cur);\n\t\t\tif (cur >= k)\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo = me + 1;\n\t\t\t}\n\t\t}\n\n\t\tauto b = a.dup;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb[i] = lastB (lo, a[i]);\n\t\t\tk -= b[i];\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n//\t\t\twriteln (i, \" \", k, \" \", fun (a[i], b[i]), \" \", lo);\n\t\t\tif (k < 0 && fun (a[i], b[i]) == lo)\n\t\t\t{\n\t\t\t\tk += 1;\n\t\t\t\tb[i] -= 1;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%s %)\") (b);\n\t}\n}\n"}], "src_uid": "5c17e01d02df26148e87dcba60ddf499"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tlong x;\r\n\t\tlong[] cnt;\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\t++x;\r\n\t\t\tif (s[i] != s[i+1])\r\n\t\t\t{\r\n\t\t\t\tcnt ~= x;\r\n\t\t\t\tx = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\tcnt ~= x+1;\r\n\r\n\t\tlong p = s[0] == '0' ? 0 : 1;\r\n\t\tif (cnt.length != 1)\r\n\t\t{\r\n\t\t\tforeach (i; 0..cnt.length)\r\n\t\t\t{\r\n\t\t\t\tif (i % 2 != p) continue;\r\n\t\t\t\r\n\t\t\t\tif (i == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tcnt[i+1] += min(cnt[i], m);\r\n\t\t\t\t\tcnt[i] = max(cnt[i]-m, 0);\r\n\t\t\t\t}\r\n\t\t\t\telse if (i == cnt.length-1)\r\n\t\t\t\t{\r\n\t\t\t\t\tcnt[i-1] += min(cnt[i], m);\r\n\t\t\t\t\tcnt[i] = max(cnt[i]-m, 0);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tcnt[i-1] += min(cnt[i]/2, m);\r\n\t\t\t\t\tcnt[i+1] += min(cnt[i]/2, m);\r\n\t\t\t\t\tcnt[i] = max(cnt[i]-m*2, cnt[i]%2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..cnt.length)\r\n\t\t{\r\n\t\t\tforeach (e; 0..cnt[i])\r\n\t\t\t\tans[ti] ~= cast(char)('0'+p);\r\n\t\t\tp ^= 1;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range;\n\nvoid main()\n{\n int t, n, m;\n readf!\" %d \"(t);\n foreach (i ; 0 .. t) {\n readf!\" %d %d\"(n, m);\n readln;\n auto a = readln.chomp.split(\"\").map!(to!int).array;\n for (int j = 0; j < a.length; j++) {\n if (a[j] == 1) {\n a[j] = 0;\n } else {\n a[j] = -1;\n }\n }\n int step = 0;\n bool progress = true;\n while (progress) {\n progress = false;\n for (int j = 0; j < a.length; j++) {\n if (a[j] != -1)\n continue;\n int left = -1;\n if (j - 1 >= 0)\n left = a[j - 1];\n int right = -1;\n if (j + 1 < a.length)\n right = a[j + 1];\n if (left == step && right != step) {\n a[j] = step + 1;\n progress = true;\n } else if (left != step && right == step) {\n a[j] = step + 1;\n progress = true;\n }\n }\n step++;\n }\n auto b = a.map!(x => (x >= 0 && x <= m) ? \"1\" : \"0\").joiner(\"\");\n writeln(b);\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto s = '#' ~ readln.strip.dup ~ '#';\r\n\t\tm = min (m, n);\r\n\t\tforeach (step; 0..m)\r\n\t\t{\r\n\t\t\tauto t = s.dup;\r\n\t\t\tforeach (i; 1..n + 1)\r\n\t\t\t{\r\n\t\t\t\tif ((s[i - 1] == '1') ^ (s[i + 1] == '1'))\r\n\t\t\t\t{\r\n\t\t\t\t\tt[i] = '1';\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ts = t;\r\n\t\t}\r\n\t\twriteln (s[1..$ - 1]);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "9c9befb908f24a0d7481b75bfdd5780b"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n, m, q;\n\twhile (readf (\" %s %s %s\", &n, &m, &q) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto b = new int [n];\n\n\t\tauto d = new int [n];\n\t\tauto p = new int [n];\n\t\tforeach (k; 0..n)\n\t\t{\n\t\t\tif (b[k] > 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tTuple !(int, int) recur (int v, int c, int r)\n\t\t\t{\n\t\t\t\tif (b[v] >= c)\n\t\t\t\t{\n\t\t\t\t\treturn Tuple !(int, int) (0, 0);\n\t\t\t\t}\n\t\t\t\tb[v] = c;\n\t\t\t\tp[v] = k;\n\n\t\t\t\tauto res = Tuple !(int, int) (r, v);\n\t\t\t\tforeach (u; a[v])\n\t\t\t\t{\n\t\t\t\t\tres = max (res, recur (u, c, r + 1));\n\t\t\t\t}\n\t\t\t\treturn res;\n\t\t\t}\n\n\t\t\tint diameter (int v)\n\t\t\t{\n\t\t\t\tauto p = recur (v, 1, 0);\n\t\t\t\tauto q = recur (p[1], 2, 0);\n\t\t\t\treturn q[0];\n\t\t\t}\n\n\t\t\td[k] = diameter (k);\n\t\t\tdebug {writeln (k, ' ', d[k]);}\n\t\t}\n\n\t\tint root (int v)\n\t\t{\n\t\t\tif (p[v] == v)\n\t\t\t{\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\treturn (p[v] = root (p[v]));\n\t\t}\n\n\t\tvoid unite (int x, int y)\n\t\t{\n\t\t\tx = root (x);\n\t\t\ty = root (y);\n\t\t\tif (x == y)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\td[x] = max (d[x], d[y],\n\t\t\t ((d[x] + 1) >> 1) + ((d[y] + 1) >> 1) + 1);\n\t\t\tdebug {writeln (x, ' ', y, ' ', d[x]);}\n\t\t\tp[y] = x;\n\t\t}\n\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tint t;\n\t\t\treadf (\" %s\", &t);\n\t\t\tif (t == 1)\n\t\t\t{\n\t\t\t\tint x;\n\t\t\t\treadf (\" %s\", &x);\n\t\t\t\tx--;\n\t\t\t\tx = root (x);\n\t\t\t\twriteln (d[x]);\n\t\t\t}\n\t\t\telse if (t == 2)\n\t\t\t{\n\t\t\t\tint x, y;\n\t\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\t\tx--;\n\t\t\t\ty--;\n\t\t\t\tunite (x, y);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n, m, q;\n\twhile (readf (\" %s %s %s\", &n, &m, &q) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto b = new int [n];\n\n\t\tauto d = new int [n];\n\t\tauto p = new int [n];\n\t\tforeach (k; 0..n)\n\t\t{\n\t\t\tif (b[k] > 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tTuple !(int, int) recur (int v, int c, int r)\n\t\t\t{\n\t\t\t\tif (b[v] >= c)\n\t\t\t\t{\n\t\t\t\t\treturn Tuple !(int, int) (0, 0);\n\t\t\t\t}\n\t\t\t\tb[v] = c;\n\t\t\t\tp[v] = k;\n\n\t\t\t\tauto res = Tuple !(int, int) (r, v);\n\t\t\t\tforeach (u; a[v])\n\t\t\t\t{\n\t\t\t\t\tres = max (res, recur (u, c, r + 1));\n\t\t\t\t}\n\t\t\t\treturn res;\n\t\t\t}\n\n\t\t\tint diameter (int v)\n\t\t\t{\n\t\t\t\tauto p = recur (v, 1, 0);\n\t\t\t\tauto q = recur (p[1], 2, 0);\n\t\t\t\treturn q[0];\n\t\t\t}\n\n\t\t\td[k] = diameter (k);\n\t\t\tdebug {writeln (k, ' ', d[k]);}\n\t\t}\n\n\t\tint root (int v)\n\t\t{\n\t\t\tif (p[v] == v)\n\t\t\t{\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\treturn (p[v] = root (p[v]));\n\t\t}\n\n\t\tvoid unite (int x, int y)\n\t\t{\n\t\t\tx = root (x);\n\t\t\ty = root (y);\n\t\t\tif (x == y)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint rx = (d[x] + 1) >> 1;\n\t\t\tint ry = (d[y] + 1) >> 1;\n\t\t\tint dx = rx + max (d[x] - rx, 1 + ry);\n\t\t\tint dy = ry + max (d[y] - ry, 1 + rx);\n\t\t\td[x] = max (dx, dy);\n\t\t\tdebug {writeln (x, ' ', y, ' ', d[x]);}\n\t\t\tp[y] = x;\n\t\t}\n\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tint t;\n\t\t\treadf (\" %s\", &t);\n\t\t\tif (t == 1)\n\t\t\t{\n\t\t\t\tint x;\n\t\t\t\treadf (\" %s\", &x);\n\t\t\t\tx--;\n\t\t\t\tx = root (x);\n\t\t\t\twriteln (d[x]);\n\t\t\t}\n\t\t\telse if (t == 2)\n\t\t\t{\n\t\t\t\tint x, y;\n\t\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\t\tx--;\n\t\t\t\ty--;\n\t\t\t\tunite (x, y);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n, m, q;\n\twhile (readf (\" %s %s %s\", &n, &m, &q) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto b = new int [n];\n\n\t\tauto d = new int [n];\n\t\tauto p = new int [n];\n\t\tforeach (k; 0..n)\n\t\t{\n\t\t\tif (b[k] > 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tTuple !(int, int) recur (int v, int c, int r)\n\t\t\t{\n\t\t\t\tif (b[v] >= c)\n\t\t\t\t{\n\t\t\t\t\treturn Tuple !(int, int) (0, 0);\n\t\t\t\t}\n\t\t\t\tb[v] = c;\n\t\t\t\tp[v] = k;\n\n\t\t\t\tauto res = Tuple !(int, int) (r, v);\n\t\t\t\tforeach (u; a[v])\n\t\t\t\t{\n\t\t\t\t\tres = max (res, recur (u, c, r + 1));\n\t\t\t\t}\n\t\t\t\treturn res;\n\t\t\t}\n\n\t\t\tint diameter (int v)\n\t\t\t{\n\t\t\t\tauto p = recur (v, 1, 0);\n\t\t\t\tauto q = recur (p[1], 2, 0);\n\t\t\t\treturn q[0];\n\t\t\t}\n\n\t\t\td[k] = diameter (k);\n\t\t\tdebug {writeln (k, ' ', d[k]);}\n\t\t}\n\n\t\tint root (int v)\n\t\t{\n\t\t\tif (p[v] == v)\n\t\t\t{\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\treturn (p[v] = root (p[v]));\n\t\t}\n\n\t\tvoid unite (int x, int y)\n\t\t{\n\t\t\tx = root (x);\n\t\t\ty = root (y);\n\t\t\tif (x == y)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint rx = (d[x] + 1) >> 1;\n\t\t\tint ry = (d[y] + 1) >> 1;\n\t\t\tint dx = rx + max (d[x] - rx, 1 + ry);\n\t\t\tint dy = ry + max (d[y] - ry, 1 + rx);\n\t\t\td[x] = min (dx, dy);\n\t\t\tdebug {writeln (x, ' ', y, ' ', d[x]);}\n\t\t\tp[y] = x;\n\t\t}\n\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tint t;\n\t\t\treadf (\" %s\", &t);\n\t\t\tif (t == 1)\n\t\t\t{\n\t\t\t\tint x;\n\t\t\t\treadf (\" %s\", &x);\n\t\t\t\tx--;\n\t\t\t\tx = root (x);\n\t\t\t\twriteln (d[x]);\n\t\t\t}\n\t\t\telse if (t == 2)\n\t\t\t{\n\t\t\t\tint x, y;\n\t\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\t\tx--;\n\t\t\t\ty--;\n\t\t\t\tunite (x, y);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "src_uid": "54c1d57482a1aa9c1013c2d54c5f9c13"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nlong ask (int lo, int hi)\r\n{\r\n\twriteln (\"? \", lo, \" \", hi);\r\n\tstdout.flush ();\r\n\treturn readln.strip.to !(long);\r\n}\r\n\r\nvoid solve (int n)\r\n{\r\n\tauto total = ask (1, n);\r\n\r\n\tint lo = 1;\r\n\tint hi = n;\r\n\twhile (lo < hi)\r\n\t{\r\n\t\tint me = (lo + hi) / 2;\r\n\t\tauto cur = ask (1, me);\r\n\t\tif (cur < total)\r\n\t\t{\r\n\t\t\tlo = me + 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\thi = me;\r\n\t\t}\r\n\t}\r\n\r\n\tint k = hi;\r\n\tauto all1 = ask (1, k);\r\n\tauto cut1 = ask (1, k - 1);\r\n\tauto delta1 = cast (int) (all1 - cut1);\r\n\r\n\tint j = k - delta1;\r\n\tauto all2 = ask (1, j - 1);\r\n\tauto cut2 = ask (1, j - 2);\r\n\tauto delta2 = cast (int) (all2 - cut2);\r\n\r\n\tint i = j - 1 - delta2;\r\n\twriteln (\"! \", i, \" \", j, \" \", k);\r\n\tstdout.flush ();\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tsolve (n);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\timport std.functional;\n\timport core.stdc.stdlib;\n\tauto n = readInt!long;\n\tlong[long] cache;\n\tlong getInvs(long k)\n\t{\n\t\tif (k in cache) return cache[k];\n\t\twriteln(\"? \", 1, \" \", k);\n\t\tstdout.flush;\n\t\tauto ans = readInt!long;\n\t\tif (ans == -1) exit(0);\n\t\treturn cache[k] = ans;\n\t}\n\tlong total = getInvs(n);\n\tlong k = -1;\n\tlong low = 1;\n\tlong high = n;\n\twhile (low <= high)\n\t{\n\t\tlong mid = (low + high) / 2;\n\t\tif (getInvs(mid) == total)\n\t\t{\n\t\t\tk = mid;\n\t\t\thigh = mid - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlow = mid + 1;\n\t\t}\n\t}\n\tassert (k != -1);\n\tlong diffK = getInvs(k) - getInvs(k-1);\n\tlong j = k - diffK;\n\tauto diffJ = getInvs(j-1) - getInvs(j-2);\n\tlong i = j - 1 - diffJ;\n\twriteln(\"! \", i, \" \", j, \" \", k);\n\tstdout.flush;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "6be52845d61d8fbd297d742842acd28e"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n if (n == 1) {\n writeln(arr.front);\n return;\n }\n \n auto s = arr.map!abs.sum(0L);\n \n debug { s.writeln; }\n \n int[] mnle;\n mnle ~= arr.front;\n foreach (e; arr.dropOne) mnle ~= min(mnle.back, e);\n int[] mnr;\n mnr ~= arr.back;\n foreach (e; arr.retro.dropOne) mnr ~= min(mnr.back, e);\n reverse(mnr);\n \n debug { mnle.writeln; mnr.writeln; }\n \n auto ans = arr.front.to!long - mnr[1] + (s - abs(arr.front) - abs(mnr[1]));\n ans = max(ans, arr.back.to!long - mnle[$-1] + (s - abs(arr.back) - abs(mnle[$-1])));\n \n foreach (i, e; arr.dropOne.dropBackOne.enumerate(1)) {\n auto cur = e.to!long - mnle[i-1] - mnr[i+1] + (s - abs(e) - abs(mnle[i-1]) - abs(mnr[i+1]));\n ans = max(ans, cur);\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nlong saiki(int idx, int s, int n, int[] a, long[][] dp)\n{\n if (dp[idx][s] != -1)\n {\n return dp[idx][s];\n }\n if (idx == n)\n {\n dp[idx][s] = (s == 3) ? 0 : long.min;\n return dp[idx][s];\n }\n auto ret0 = saiki(idx + 1, s | 1, n, a, dp);\n auto ret1 = saiki(idx + 1, s | 2, n, a, dp);\n auto res = long.min;\n if (ret0 != long.min) res = max(res, ret0 + a[idx]);\n if (ret1 != long.min) res = max(res, ret1 - a[idx]);\n dp[idx][s] = res;\n return res;\n}\n\nvoid solve(int[] a, int n)\n{\n if (n == 1)\n {\n writeln(a[0]);\n return;\n }\n auto dp = new long[][](n + 1, 4);\n foreach (i; 0 .. n + 1)\n {\n fill(dp[i], -1);\n }\n auto res = saiki(0, 0, n, a, dp);\n writeln(res);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a, n);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n if (N == 1) {\n writeln(A[0]);\n return;\n }\n\n long S = A.map!(a => abs(a)).sum;\n long ans = -INF;\n\n foreach (i; 0..N-1) {\n auto sub = abs(A[i] - A[i+1]);\n ans = max(ans, S - abs(A[i]) - abs(A[i+1]) + sub);\n }\n\n ans.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n if (N == 1) {\n writeln(A[0]);\n return;\n }\n\n auto S = A.sum;\n long ans = -INF;\n\n foreach (i; 0..N-1) {\n auto sub = abs(A[i] - A[i+1]);\n ans = max(ans, S - A[i] - A[i+1] + sub);\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n auto dp = new long[][](N+1, 2);\n foreach (i; 0..N+1) dp[i][0] = -INF;\n foreach (i; 0..N+1) dp[i][1] = INF;\n dp[1][0] = dp[1][1] = A[0];\n\n foreach (i; 1..N) {\n dp[i+1][0] = max(dp[i+1][0], dp[i][0] - A[i]);\n dp[i+1][0] = max(dp[i+1][0], A[i] - dp[i][0]);\n dp[i+1][0] = max(dp[i+1][0], dp[i][1] - A[i]);\n dp[i+1][0] = max(dp[i+1][0], A[i] - dp[i][1]);\n dp[i+1][1] = min(dp[i+1][1], dp[i][0] - A[i]);\n dp[i+1][1] = min(dp[i+1][1], A[i] - dp[i][0]);\n dp[i+1][1] = min(dp[i+1][1], dp[i][1] - A[i]);\n dp[i+1][1] = min(dp[i+1][1], A[i] - dp[i][1]);\n }\n\n dp[N][0].writeln;\n}\n"}], "src_uid": "090f57798ba45ba9e4c9d2d0514e478c"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n immutable int MD = 10 ^^ 9 + 7;\n \n auto s = readln.chomp;\n \n s ~= 'b';\n int ans = 0;\n int cur = 0;\n foreach (c; s) {\n if (c == 'a') ++cur;\n else if (c == 'b') {\n auto toadd = (cast(long)cur * ans % MD + cur) % MD;\n ans = (ans + toadd) % MD;\n cur = 0;\n }\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.array, std.conv;\nimport std.algorithm;\n\nint solve(string s)\n{\n static int mod = 1000000007;\n auto n = to!int(s.length);\n auto dp = new int[n];\n auto next = new int[][](n, 2);\n next[n - 1][0] = next[n - 1][1] = n;\n if (s[n - 1] == 'a') dp[n - 1] = 1;\n foreach_reverse (i; 0 .. n - 1)\n {\n foreach (j; 0 .. 2) next[i][j] = next[i + 1][j];\n if (s[i + 1] == 'a') next[i][0] = i + 1;\n else if (s[i + 1] == 'b') next[i][1] = i + 1;\n if (s[i] == 'a')\n {\n dp[i] = 1;\n auto idx = next[i][1];\n if (idx < n)\n {\n idx = next[idx][0];\n if (idx < n) dp[i] = (dp[i] + dp[idx]) % mod;\n }\n idx = next[i][0];\n if (idx < n) dp[i] = (dp[i] + dp[idx]) % mod;\n }\n }\n if (s[0] == 'a') return dp[0];\n auto idx = next[0][0];\n if (idx < n) return dp[idx];\n return 0;\n}\n\nint main(string[] args)\n{\n auto s = readln.strip;\n auto ret = solve(s);\n writeln(ret);\n return 0;\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n immutable int MD = 10 ^^ 9 + 7;\n \n auto s = readln.chomp;\n \n s ~= 'b';\n int ans = 0;\n int cur = 0;\n foreach (c; s) {\n if (c == 'a') ++cur;\n else if (c == 'b') {\n auto toadd = (cur * ans % MD + cur) % MD;\n ans = (ans + toadd) % MD;\n cur = 0;\n }\n }\n \n ans.writeln;\n}"}], "src_uid": "a765463559901e608035083be47aa245"} {"source_code": "module cf_245A;\n\nimport std.stdio;\n\nvoid main() {\n int n, t, x, y;\n int lostPCA = 0, acceptPCA = 0;\n int lostPCB = 0, acceptPCB = 0;\n\n readf(\"%d\", &n);\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d %d\", &t, &x, &y);\n\n if (t == 1) {\n acceptPCA += x;\n lostPCA += y;\n } else {\n acceptPCB += x;\n lostPCB += y;\n }\n }\n\n lostPCA += acceptPCA;\n lostPCB += acceptPCB;\n\n writeln((acceptPCA >= lostPCA / 2)? \"LIVE\": \"DEAD\");\n writeln((acceptPCB >= lostPCB / 2)? \"LIVE\": \"DEAD\");\n}", "positive_code": [{"source_code": "import std.stdio;\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[2][3] table;\n int n;\n readf(\" %s\\n\", &n);\n foreach(i; 0 .. n) {\n int a, b, c;\n readf(\" %s %s %s\\n\", &a, &b, &c);\n table[a][0] += b;\n table[a][1] += c;\n }\n if (table[1][0] >= table[1][1]) writeln(\"LIVE\");\n else writeln(\"DEAD\");\n if (table[2][0] >= table[2][1]) writeln(\"LIVE\");\n else writeln(\"DEAD\");\n \n return 0;\n}"}, {"source_code": "import std.stdio;\nint main()\n{\n\tint n=0;\n\treadf(\" %d\", &n);\n\tint l1=0;\n\tint l2=0;\n\tint d1=0;\n\tint d2=0;\n\tfor (int i=0; i<n; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\tint c=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\tif (a==1)\n\t\t{\n\t\t\tl1=l1+b;\n\t\t\td1=d1+c;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tl2=l2+b;\n\t\t\td2=d2+c;\n\t\t}\n\t}\n\tif (l1>=d1)\n\t{\n\t\twriteln(\"LIVE\");\n\t}\n\telse\n\t{\n\t\twriteln(\"DEAD\");\n\t}\n\tif (l2>=d2)\n\t{\n\t\twriteln(\"LIVE\");\n\t}\n\telse\n\t{\n\t\twriteln(\"DEAD\");\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "1d8870a705036b9820227309d74dd1e8"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto p = readln.chomp.split.map!(to!int).array;\n \n auto g = new int[][] (n+1);\n \n foreach (i, e; p.enumerate(2)) {\n g[i] ~= e;\n g[e] ~= i;\n }\n \n debug { g.each!writeln; }\n \n immutable int MX_LVL = log2(n).to!int + 1;\n auto lca = new int[][] (MX_LVL, n+1);\n auto h = new int[] (n+1);\n\n void calcLcaArr (int n) {\n void dfs (int v, int fr) {\n if (fr != 0) { \n lca[0][v] = fr;\n h[v] = h[fr] + 1;\n }\n foreach (u; g[v]) {\n if (u == fr) { continue; }\n\n dfs(u, v);\n }\n }\n\n foreach (lvl; 0 .. MX_LVL) { lca[lvl][] = 0; }\n lca[0][1] = 1;\n h[1] = 0;\n \n dfs(1, 0);\n \n foreach (lvl; 1 .. MX_LVL) {\n foreach (v; 1 .. n+1) {\n lca[lvl][v] = lca[lvl-1][lca[lvl-1][v]];\n }\n }\n }\n \n calcLcaArr(n); \n \n int getLca (int a, int b) {\n if (h[a] < h[b]) { swap(a, b); }\n \n foreach_reverse (lvl; 0 .. MX_LVL) {\n if (h[a] - (1 << lvl) < h[b]) { continue; }\n \n a = lca[lvl][a];\n }\n \n if (a == b) {\n return a;\n }\n \n foreach_reverse (lvl; 0 .. MX_LVL) {\n if (lca[lvl][a] != lca[lvl][b]) {\n a = lca[lvl][a];\n b = lca[lvl][b];\n }\n }\n \n return lca[0][a];\n }\n \n debug {\n h.writeln;\n lca.each!writeln;\n \n writeln([getLca (1, 1), getLca(1, 2), getLca(2, 1), getLca(2, 2), getLca(2, 3)]\n .map!(to!string).join(\" \"));\n \n }\n \n int dst(int a, int b) {\n int vlca = getLca(a, b);\n return h[a] - h[vlca] + h[b] - h[vlca] + 1;\n }\n \n while (q--) {\n auto arr = readln.chomp.split.map!(to!int).array;\n\n int ans = 0;\n foreach (t; 0 .. 3) {\n int[] starts;\n foreach (i; 0 .. 3) { if (i != t) { starts ~= arr[i]; } }\n \n int cur = (dst(starts[0], arr[t]) + dst(starts[1], arr[t]) - dst(starts[0], starts[1])) / 2 + 1;\n \n ans = max(ans, cur);\n }\n \n ans.writeln;\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto S = readln.split.map!(to!int);\n auto N = S[0];\n auto Q = S[1];\n auto edges = new int[][](N);\n auto P = readln.split.map!(to!int).array;\n foreach (i; 0..N-1) {\n edges[i + 1] ~= P[i] - 1;\n edges[P[i] - 1] ~= i + 1;\n }\n\n auto depth = new int[](N);\n auto dp = new int[][](20, N);\n\n void dfs(int n, int p, int d) {\n dp[0][n] = p;\n depth[n] = d;\n foreach (m; edges[n]) if (m != p) dfs(m, n, d+1);\n }\n\n dfs(0, -1, 0);\n\n foreach (k; 0..19)\n foreach (n; 0..N)\n dp[k+1][n] = (dp[k][n] == -1) ? -1 : dp[k][dp[k][n]];\n\n int[int][int] mem;\n\n int lca(int a, int b) {\n if (depth[a] < depth[b]) swap(a, b);\n if (a in mem && b in mem[a]) return mem[a][b];\n\n auto orig_a = a;\n auto orig_b = b;\n\n while (depth[a] > depth[b]) {\n int K = 19;\n foreach (k; iota(K, -1, -1)) {\n if ((1L << k) <= depth[a] - depth[b]) {\n a = dp[k][a];\n K = k;\n }\n }\n }\n\n if (a == b) return mem[a][b] = a;\n\n while (dp[0][a] != dp[0][b]) {\n int K = 19;\n foreach (k; iota(K, -1, -1)) {\n if (dp[k][a] != dp[k][b]) {\n a = dp[k][a];\n b = dp[k][b];\n K = k;\n }\n }\n }\n\n return mem[a][b] = dp[0][a];\n }\n\n int dist(int a, int b, int ab) {\n return depth[a] + depth[b] - depth[ab] * 2;\n }\n\n\n foreach(_; 0..Q) {\n auto q = readln.split.map!(to!int).array;\n q.sort();\n int ans = 0;\n do {\n int s = q[0] - 1, t = q[1] - 1, f = q[2] - 1;\n int st = lca(s, t);\n int tf = lca(t, f);\n int fs = lca(f, s);\n int sft;\n if (depth[st] >= depth[tf] && depth[st] >= depth[fs]) sft = st;\n else if (depth[tf] >= depth[st] && depth[tf] >= depth[fs]) sft = tf;\n else sft = fs;\n ans = max(ans, dist(f, sft, lca(f, sft)) + 1);\n } while (nextPermutation(q));\n ans.writeln;\n }\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto p = readln.chomp.split.map!(to!int).array;\n \n auto g = new int[][] (n+1);\n \n foreach (i, e; p.enumerate(2)) {\n g[i] ~= e;\n g[e] ~= i;\n }\n \n debug { g.each!writeln; }\n \n immutable int MX_LVL = log2(n).to!int + 1;\n auto lca = new int[][] (MX_LVL, n+1);\n auto h = new int[] (n+1);\n\n void calcLcaArr (int n) {\n void dfs (int v, int fr) {\n if (fr != 0) { \n lca[0][v] = fr;\n h[v] = h[fr] + 1;\n }\n foreach (u; g[v]) {\n if (u == fr) { continue; }\n\n dfs(u, v);\n }\n }\n\n foreach (lvl; 0 .. MX_LVL) { lca[lvl][] = 0; }\n lca[0][1] = 1;\n h[1] = 0;\n \n dfs(1, 0);\n \n foreach (lvl; 1 .. MX_LVL) {\n foreach (v; 1 .. n+1) {\n lca[lvl][v] = lca[lvl-1][lca[lvl-1][v]];\n }\n }\n }\n \n calcLcaArr(n); \n \n int getLca (int a, int b) {\n if (h[a] < h[b]) { swap(a, b); }\n \n foreach_reverse (lvl; 0 .. MX_LVL) {\n if (h[a] - (1 << lvl) < h[b]) { continue; }\n \n a = lca[lvl][a];\n }\n \n if (a == b) {\n return a;\n }\n \n foreach_reverse (lvl; 0 .. MX_LVL) {\n if (lca[lvl][a] != lca[lvl][b]) {\n a = lca[lvl][a];\n b = lca[lvl][b];\n }\n }\n \n return lca[0][a];\n }\n \n debug {\n h.writeln;\n lca.each!writeln;\n \n writeln([getLca (1, 1), getLca(1, 2), getLca(2, 1), getLca(2, 2), getLca(2, 3)]\n .map!(to!string).join(\" \"));\n \n }\n \n while (q--) {\n auto arr = readln.chomp.split.map!(to!int).array;\n\n int ans = 0;\n foreach (t; 0 .. 3) {\n int[] starts;\n foreach (i; 0 .. 3) { if (i != t) { starts ~= arr[i]; } }\n \n int lca1 = getLca(starts[0], starts[1]);\n int lca2 = getLca(starts[0], arr[t]);\n int lca3 = getLca(starts[1], arr[t]);\n \n int cur = 0;\n if (h[lca1] >= h[lca2] && h[lca1] >= h[lca3]) {\n int all = getLca(lca1, arr[t]);\n cur = h[lca1] - h[all] + h[arr[t]] - h[all];\n } else {\n cur = h[arr[t]] - max(h[lca2], h[lca3]);\n }\n \n ans = max(ans, cur + 1);\n }\n \n ans.writeln;\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto S = readln.split.map!(to!int);\n auto N = S[0];\n auto Q = S[1];\n auto edges = new int[][](N);\n auto P = readln.split.map!(to!int).array;\n foreach (i; 0..N-1) {\n edges[i + 1] ~= P[i] - 1;\n edges[P[i] - 1] ~= i + 1;\n }\n\n auto depth = new int[](N);\n auto dp = new int[][](20, N);\n\n void dfs(int n, int p, int d) {\n dp[0][n] = p;\n depth[n] = d;\n foreach (m; edges[n]) if (m != p) dfs(m, n, d+1);\n }\n\n dfs(0, -1, 0);\n\n foreach (k; 0..19)\n foreach (n; 0..N)\n dp[k+1][n] = (dp[k][n] == -1) ? -1 : dp[k][dp[k][n]];\n\n int[int][int] mem;\n\n int lca(int a, int b) {\n if (depth[a] < depth[b]) swap(a, b);\n if (a in mem && b in mem[a]) return mem[a][b];\n\n auto orig_a = a;\n auto orig_b = b;\n\n while (depth[a] > depth[b]) {\n int K = 19;\n foreach (k; iota(K, -1, -1)) {\n if ((1L << k) <= depth[a] - depth[b]) {\n a = dp[k][a];\n K = k;\n }\n }\n }\n\n if (a == b) return mem[a][b] = a;\n\n while (dp[0][a] != dp[0][b]) {\n int K = 19;\n foreach (k; iota(K, -1, -1)) {\n if (dp[k][a] != dp[k][b]) {\n a = dp[k][a];\n b = dp[k][b];\n K = k;\n }\n }\n }\n\n return mem[a][b] = dp[0][a];\n }\n\n int dist(int a, int b, int ab) {\n return depth[a] + depth[b] - depth[ab] * 2;\n }\n\n\n foreach(_; 0..Q) {\n auto q = readln.split.map!(to!int).array;\n q.sort();\n int ans = 0;\n do {\n int s = q[0] - 1, t = q[1] - 1, f = q[2] - 1;\n int st = lca(s, t);\n int sf = lca(s, f);\n int tf = lca(t, f);\n int d1 = dist(s, t, st);\n int d2 = dist(s, f, sf);\n int d3 = dist(t, f, tf);\n int stf1 = d1 < d2 ? st : sf;\n int d4 = dist(stf1, f, lca(stf1, f));\n int stf2 = d1 < d3 ? st : tf;\n int d5 = dist(stf2, f, lca(stf2, f));\n int d = min(d4, d5) + 1;\n ans = max(ans, d);\n } while (nextPermutation(q));\n ans.writeln;\n }\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto p = readln.chomp.split.map!(to!int).array;\n \n auto g = new int[][] (n+1);\n \n foreach (i, e; p.enumerate(2)) {\n g[i] ~= e;\n g[e] ~= i;\n }\n \n debug { g.each!writeln; }\n \n immutable int MX_LVL = log2(n).to!int + 1;\n auto lca = new int[][] (MX_LVL, n+1);\n auto h = new int[] (n+1);\n\n void calcLcaArr (int n) {\n void dfs (int v, int fr) {\n if (fr != 0) { \n lca[0][v] = fr;\n h[v] = h[fr] + 1;\n }\n foreach (u; g[v]) {\n if (u == fr) { continue; }\n\n dfs(u, v);\n }\n }\n\n foreach (lvl; 0 .. MX_LVL) { lca[lvl][] = 0; }\n lca[0][1] = 1;\n h[1] = 0;\n \n dfs(1, 0);\n \n foreach (lvl; 1 .. MX_LVL) {\n foreach (v; 1 .. n+1) {\n lca[lvl][v] = lca[lvl-1][lca[lvl-1][v]];\n }\n }\n }\n \n calcLcaArr(n); \n \n int getLca (int a, int b) {\n if (h[a] < h[b]) { swap(a, b); }\n \n foreach_reverse (lvl; 0 .. MX_LVL) {\n if (h[a] - (1 << lvl) < h[b]) { continue; }\n \n a = lca[lvl][a];\n }\n \n if (a == b) {\n return a;\n }\n \n foreach_reverse (lvl; 0 .. MX_LVL) {\n if (lca[lvl][a] != lca[lvl][b]) {\n a = lca[lvl][a];\n b = lca[lvl][b];\n }\n }\n \n return lca[0][a];\n }\n \n debug {\n h.writeln;\n lca.each!writeln;\n \n writeln([getLca (1, 1), getLca(1, 2), getLca(2, 1), getLca(2, 2), getLca(2, 3)]\n .map!(to!string).join(\" \"));\n \n }\n \n while (q--) {\n auto arr = readln.chomp.split.map!(to!int).array;\n\n int ans = 0;\n foreach (t; 0 .. 3) {\n int[] starts;\n foreach (i; 0 .. 3) { if (i != t) { starts ~= arr[i]; } }\n \n int lca1 = getLca(starts[0], starts[1]);\n int lca2 = getLca(starts[0], arr[t]);\n int lca3 = getLca(starts[1], arr[t]);\n \n int cur = 0;\n if (h[lca1] >= h[lca2] && h[lca1] >= h[lca3]) {\n int all = getLca(lca1, arr[t]);\n cur = h[lca1] - h[all] + h[t] - h[all];\n } else {\n cur = h[t] - max(h[lca2], h[lca3]);\n }\n \n debug { writeln(starts, ' ', lca1, ' ', lca2, ' ', lca3, ' ', cur); }\n \n ans = max(ans, cur + 1);\n }\n \n ans.writeln;\n }\n}"}], "src_uid": "dd0dc4390b4c8e58aeeb82b9a587e946"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n = read!int;\r\n auto a = readarray!int;\r\n if (n == 8)\r\n writeln(6);\r\n else if (n == 7)\r\n writeln(3*6);\r\n else\r\n writeln(6 * (10 - n)*(9 - n) / 2);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = readln.splitter.map!(to!int).array;\n bool[int] banned;\n foreach (x ; a)\n banned[x] = true;\n int ans = 0;\n foreach (d1 ; 0 .. 10)\n foreach (d2 ; 0 .. 10)\n foreach (d3 ; 0 .. 10)\n foreach (d4 ; 0 .. 10) {\n int[int] digits;\n int[4] code = [d1, d2, d3, d4];\n bool good = true;\n foreach (x ; code) {\n if (x in banned)\n good = false;\n digits[x]++;\n }\n if (digits.length != 2 || digits.values != [2, 2])\n good = false;\n if (good)\n ans++;\n }\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n long ans = (10 - N) * (10 - N - 1) / 2 * 6;\r\n writeln(ans);\r\n}\r\n"}], "negative_code": [], "src_uid": "33e751f5716cbd666be36ab8f5e3977e"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto M = scan!int;\r\n auto S = scan!string(N);\r\n\r\n long ans = long.max;\r\n foreach(i; 0..N - 1) foreach(j; i+1..N) {\r\n long tans;\r\n foreach(k; 0..M) {\r\n tans += (S[i][k] - S[j][k]).abs;\r\n }\r\n\r\n ans = min(ans, tans);\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.string;\r\nimport std.algorithm;\r\nimport std.format;\r\nimport std.typecons;\r\n\r\nint[] rtln(T)() { return to!(T[])(strip(readln).split(\" \")); }\r\n\r\n\r\nvoid main() {\r\n int t, n, m;\r\n readf(\"%d\\n\", t);\r\n while(t--) {\r\n\t\tchar[][] a;\r\n readf(\"%d %d\\n\", n, m);\r\n\t\twhile (n--)\r\n\t\t\ta ~= strip(readln).dup;\r\n int min;\r\n for (int p = 0; p < m; p++) {\r\n int tempTemp = (a[0][p] + '0') - (a[1][p] + '0');\r\n if (tempTemp < 0) tempTemp = -tempTemp;\r\n min += tempTemp;\r\n }\r\n if (min < 0)\r\n min = -min;\r\n\t\tfor (int i = 0; i < a.length; i++) {\r\n for (int j = 0; j < a.length; j++) {\r\n if (j == i)\r\n continue;\r\n int temp = 0;\r\n for (int p = 0; p < m; p++) {\r\n int tempTemp = (a[i][p] + '0') - (a[j][p] + '0');\r\n if (tempTemp < 0) \r\n tempTemp = -tempTemp;\r\n temp += tempTemp;\r\n }\r\n if (temp < min)\r\n min = temp;\r\n }\r\n }\r\n writeln(min);\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.utf;\r\n\r\nalias dist = (s, t) => zip (s.byChar, t.byChar).map !(q{abs (a[0] - a[1])}).sum;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tstring [] s;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\ts ~= readln.strip;\r\n\t\t}\r\n\t\tint res = int.max;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n)\r\n\t\t\t{\r\n\t\t\t\tres = min (res, dist (s[i], s[j]));\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "ef2b90d5b1073430795704a7df748ac3"} {"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nauto separators (string s, char start) {\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t\tif (cur != c) {\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\treturn res;\n}\n\nauto solveSingle (string s, string t)\n{\n\tint [2] [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front + q.front) {\n\t\tres ~= [p.front, q.front];\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nauto solve (string s, string t) {\n\tauto res = solveSingle (s, t);\n\tauto p = separators (s, 'a') ~ 0, q = separators (t, 'b') ~ 0;\n\treverse (p);\n\treverse (q);\n\tauto balance = (p.length.to!int - q.length.to!int) / 2;\n\tforeach (i; 0..2) foreach (j; 0..2) {\n\t\tint u = abs (balance) + i;\n\t\tint v = j;\n\t\tif (balance < 0) swap (u, v);\n\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v) continue;\n\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$], t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\tint [2] [] temp = [[p[u], q[v]]];\n\t\ttemp ~= solveSingle (s2, t2);\n\t\tif (res.length > temp.length) res = temp;\n\t}\n\treturn res;\n}\n\nvoid main () {\n\tauto s = readln.strip, t = readln.strip;\n\tauto res1 = solve (s, t), res2 = solve (t, s);\n\tif (res1.length > res2.length) {\n\t\tswap (res1, res2);\n\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t}\n\twriteln (res1.length);\n\tforeach (line; res1) writefln (\"%(%s %)\", line);\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nauto separators (string s, char start) {\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t\tif (cur != c) {\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\treturn res;\n}\n\nauto solveSingle (string s, string t)\n{\n\tint [2] [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front + q.front) {\n\t\tres ~= [p.front, q.front];\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nauto solve (string s, string t) {\n\tauto res = solveSingle (s, t);\n\tauto p = separators (s, 'a') ~ 0, q = separators (t, 'b') ~ 0;\n\treverse (p);\n\treverse (q);\n\tauto balance = (p.length.to!int - q.length.to!int) / 2;\n\tforeach (i; 0..3) foreach (j; 0..2) {\n\t\tint u = abs (balance) + i;\n\t\tint v = j;\n\t\tif (balance < 0) swap (u, v);\n\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v) continue;\n\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$], t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\tint [2] [] temp = [[p[u], q[v]]];\n\t\ttemp ~= solveSingle (s2, t2);\n\t\tif (res.length > temp.length) res = temp;\n\t}\n\treturn res;\n}\n\nvoid main () {\n\tauto s = readln.strip, t = readln.strip;\n\tauto res1 = solve (s, t), res2 = solve (t, s);\n\tif (res1.length > res2.length) {\n\t\tswap (res1, res2);\n\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t}\n\twriteln (res1.length);\n\tforeach (line; res1) writefln (\"%(%s %)\", line);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Record = Tuple !(int, q{a}, int, q{b});\n\nint [] separators (string s, char start)\n{\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t{\n\t\tif (cur != c)\n\t\t{\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\t}\n\tdebug {writeln (res);}\n\treturn res;\n}\n\nRecord [] solve (string s, string t)\n{\n\tRecord [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front > 0 || q.front > 0)\n\t{\n\t\tres ~= Record (p.front, q.front);\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nRecord [] solveStrategyLayer (string s, string t)\n{\n\tRecord [] res = solve (s, t);\n\tauto p = separators (s, 'a').chain (0.only).retro.array;\n\tauto q = separators (t, 'b').chain (0.only).retro.array;\n\tint balance = p.length.to!int - q.length.to!int;\n\tbalance /= 2;\n\tforeach (i; 0..4)\n\t{\n\t\tforeach (j; 0..2)\n\t\t{\n\t\t\tint u = abs (balance) - 2 + i;\n\t\t\tint v = j;\n\t\t\tif (balance < 0)\n\t\t\t{\n\t\t\t\tswap (u, v);\n\t\t\t}\n\t\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$];\n\t\t\tauto t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\t\tRecord [] temp = [Record (p[u], q[v])];\n\t\t\ttemp ~= solve (s2, t2);\n\t\t\tif (res.length > temp.length)\n\t\t\t{\n\t\t\t\tres = temp;\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tstring s, t;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tt = readln.strip;\n\t\tauto res1 = solveStrategyLayer (s, t);\n\t\tauto res2 = solveStrategyLayer (t, s);\n\t\tif (res1.length > res2.length)\n\t\t{\n\t\t\tswap (res1, res2);\n\t\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t\t}\n\t\twriteln (res1.length);\n\t\tforeach (ref line; res1)\n\t\t{\n\t\t\twritefln (\"%s %s\", line.a, line.b);\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nauto separators (string s, char start) {\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t\tif (cur != c) {\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\treturn res;\n}\n\nauto solveSingle (string s, string t)\n{\n\tint [2] [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front + q.front) {\n\t\tres ~= [p.front, q.front];\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nauto solve (string s, string t) {\n\tauto res = solveSingle (s, t);\n\tauto p = separators (s, 'a') ~ 0, q = separators (t, 'b') ~ 0;\n\treverse (p);\n\treverse (q);\n\tauto balance = (p.length.to!int - q.length.to!int) / 2;\n\tforeach (i; 0..3) foreach (j; 0..1) {\n\t\tint u = abs (balance) + i;\n\t\tint v = j;\n\t\tif (balance < 0) swap (u, v);\n\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v) continue;\n\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$], t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\tint [2] [] temp = [[p[u], q[v]]];\n\t\ttemp ~= solveSingle (s2, t2);\n\t\tif (res.length > temp.length) res = temp;\n\t}\n\treturn res;\n}\n\nvoid main () {\n\tauto s = readln.strip, t = readln.strip;\n\tauto res1 = solve (s, t), res2 = solve (t, s);\n\tif (res1.length > res2.length) {\n\t\tswap (res1, res2);\n\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t}\n\twriteln (res1.length);\n\tforeach (line; res1) writefln (\"%(%s %)\", line);\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nauto separators (string s, char start) {\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t\tif (cur != c) {\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\treturn res;\n}\n\nauto solveSingle (string s, string t)\n{\n\tint [2] [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front + q.front) {\n\t\tres ~= [p.front, q.front];\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nauto solve (string s, string t) {\n\tauto res = solveSingle (s, t);\n\tauto p = separators (s, 'a') ~ 0, q = separators (t, 'b') ~ 0;\n\treverse (p);\n\treverse (q);\n\tauto balance = (p.length.to!int - q.length.to!int) / 2;\n\tforeach (i; 0..2) foreach (j; 0..1) {\n\t\tint u = abs (balance) - 2 + i;\n\t\tint v = j;\n\t\tif (balance < 0) swap (u, v);\n\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v) continue;\n\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$], t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\tint [2] [] temp = [[p[u], q[v]]];\n\t\ttemp ~= solveSingle (s2, t2);\n\t\tif (res.length > temp.length) res = temp;\n\t}\n\treturn res;\n}\n\nvoid main () {\n\tauto s = readln.strip, t = readln.strip;\n\tauto res1 = solve (s, t), res2 = solve (t, s);\n\tif (res1.length > res2.length) {\n\t\tswap (res1, res2);\n\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t}\n\twriteln (res1.length);\n\tforeach (line; res1) writefln (\"%(%s %)\", line);\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nauto separators (string s, char start) {\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t\tif (cur != c) {\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\treturn res;\n}\n\nauto solveSingle (string s, string t)\n{\n\tint [2] [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front + q.front) {\n\t\tres ~= [p.front, q.front];\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nauto solve (string s, string t) {\n\tauto res = solveSingle (s, t);\n\tauto p = separators (s, 'a') ~ 0, q = separators (t, 'b') ~ 0;\n\treverse (p);\n\treverse (q);\n\tauto balance = (p.length.to!int - q.length.to!int) / 2;\n\tforeach (i; 0..2) foreach (j; 0..1) {\n\t\tint u = abs (balance) + i;\n\t\tint v = j;\n\t\tif (balance < 0) swap (u, v);\n\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v) continue;\n\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$], t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\tint [2] [] temp = [[p[u], q[v]]];\n\t\ttemp ~= solveSingle (s2, t2);\n\t\tif (res.length > temp.length) res = temp;\n\t}\n\treturn res;\n}\n\nvoid main () {\n\tauto s = readln.strip, t = readln.strip;\n\tauto res1 = solve (s, t), res2 = solve (t, s);\n\tif (res1.length > res2.length) {\n\t\tswap (res1, res2);\n\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t}\n\twriteln (res1.length);\n\tforeach (line; res1) writefln (\"%(%s %)\", line);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint [] separators (string s, char start)\n{\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t{\n\t\tif (cur != c)\n\t\t{\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\t}\n\tdebug {writeln (res);}\n\treturn res;\n}\n\nint [2] [] solve (string s, string t)\n{\n\tint [2] [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front > 0 || q.front > 0)\n\t{\n\t\tres ~= [p.front, q.front];\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tstring s, t;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tt = readln.strip;\n\t\tauto res1 = solve (s, t);\n\t\tauto res2 = solve (t, s);\n\t\tif (res1.length > res2.length)\n\t\t{\n\t\t\tswap (res1, res2);\n\t\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t\t}\n\t\twriteln (res1.length);\n\t\tforeach (ref line; res1)\n\t\t{\n\t\t\twritefln (\"%(%s %)\", line[]);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Record = Tuple !(int, q{a}, int, q{b});\n\nint [] separators (string s, char start)\n{\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t{\n\t\tif (cur != c)\n\t\t{\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\t}\n\tdebug {writeln (res);}\n\treturn res;\n}\n\nRecord [] solve (string s, string t)\n{\n\tRecord [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front > 0 || q.front > 0)\n\t{\n\t\tres ~= Record (p.front, q.front);\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nRecord [] solveStrategyLayer (string s, string t)\n{\n\tRecord [] res = solve (s, t);\n\tauto p = separators (s, 'a').chain (0.only).retro.array;\n\tauto q = separators (t, 'b').chain (0.only).retro.array;\n\tint balance = p.length.to!int - q.length.to!int;\n\tforeach (i; 0..4)\n\t{\n\t\tforeach (j; 0..3)\n\t\t{\n\t\t\tint u = abs (balance) - 2 + i;\n\t\t\tint v = j;\n\t\t\tif (balance < 0)\n\t\t\t{\n\t\t\t\tswap (u, v);\n\t\t\t}\n\t\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$];\n\t\t\tauto t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\t\tRecord [] temp = [Record (p[u], q[v])];\n\t\t\ttemp ~= solve (s2, t2);\n\t\t\tif (res.length > temp.length)\n\t\t\t{\n\t\t\t\tres = temp;\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tstring s, t;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tt = readln.strip;\n\t\tauto res1 = solveStrategyLayer (s, t);\n\t\tauto res2 = solveStrategyLayer (t, s);\n\t\tif (res1.length > res2.length)\n\t\t{\n\t\t\tswap (res1, res2);\n\t\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t\t}\n\t\twriteln (res1.length);\n\t\tforeach (ref line; res1)\n\t\t{\n\t\t\twritefln (\"%s %s\", line.a, line.b);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint [] separators (string s, char start)\n{\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t{\n\t\tif (cur != c)\n\t\t{\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\t}\n\tdebug {writeln (res);}\n\treturn res;\n}\n\nint [2] [] solve (string s, string t)\n{\n\tint [2] [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front > 0 || q.front > 0)\n\t{\n\t\tres ~= [p.front, q.front];\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nint [2] [] solveStrategyLayer (string s, string t)\n{\n\tint [2] [] res = solve (s, t);\n\tauto p = separators (s, 'a').chain (0.only).retro.array;\n\tauto q = separators (t, 'b').chain (0.only).retro.array;\n\tint balance = p.length.to!int - q.length.to!int;\n\tforeach (i; 0..4)\n\t{\n\t\tforeach (j; 0..2)\n\t\t{\n\t\t\tint u = abs (balance) - 1 + i;\n\t\t\tint v = j;\n\t\t\tif (balance < 0)\n\t\t\t{\n\t\t\t\tswap (u, v);\n\t\t\t}\n\t\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$];\n\t\t\tauto t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\t\tint [2] [] temp = [[p[u], q[v]]];\n\t\t\ttemp ~= solve (s2, t2);\n\t\t\tif (res.length > temp.length)\n\t\t\t{\n\t\t\t\tres = temp;\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tstring s, t;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tt = readln.strip;\n\t\tauto res1 = solveStrategyLayer (s, t);\n\t\tauto res2 = solveStrategyLayer (t, s);\n\t\tif (res1.length > res2.length)\n\t\t{\n\t\t\tswap (res1, res2);\n\t\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t\t}\n\t\twriteln (res1.length);\n\t\tforeach (ref line; res1)\n\t\t{\n\t\t\twritefln (\"%(%s %)\", line[]);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.math, std.range, std.stdio, std.string;\n\nauto separators (string s, char start) {\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t\tif (cur != c) {\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\treturn res;\n}\n\nauto solveSingle (string s, string t)\n{\n\tint [2] [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front + q.front) {\n\t\tres ~= [p.front, q.front];\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nauto solve (string s, string t) {\n\tauto res = solveSingle (s, t);\n\tauto p = separators (s, 'a') ~ 0, q = separators (t, 'b') ~ 0;\n\treverse (p);\n\treverse (q);\n\tauto balance = (p.length.to!int - q.length.to!int) / 2;\n\tforeach (i; 0..2) foreach (j; 0..2) {\n\t\tint u = abs (balance) - 1 + i;\n\t\tint v = j;\n\t\tif (balance < 0) swap (u, v);\n\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v) continue;\n\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$], t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\tint [2] [] temp = [[p[u], q[v]]];\n\t\ttemp ~= solveSingle (s2, t2);\n\t\tif (res.length > temp.length) res = temp;\n\t}\n\treturn res;\n}\n\nvoid main () {\n\tauto s = readln.strip, t = readln.strip;\n\tauto res1 = solve (s, t), res2 = solve (t, s);\n\tif (res1.length > res2.length) {\n\t\tswap (res1, res2);\n\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t}\n\twriteln (res1.length);\n\tforeach (line; res1) writefln (\"%(%s %)\", line);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Record = Tuple !(int, q{a}, int, q{b});\n\nint [] separators (string s, char start)\n{\n\tint [] res;\n\tchar cur = start;\n\tforeach_reverse (int i, char c; s)\n\t{\n\t\tif (cur != c)\n\t\t{\n\t\t\tres ~= i + 1;\n\t\t\tcur = c;\n\t\t}\n\t}\n\tdebug {writeln (res);}\n\treturn res;\n}\n\nRecord [] solve (string s, string t)\n{\n\tRecord [] res;\n\tauto p = separators (s, 'a').chain (0.only.cycle);\n\tauto q = separators (t, 'b').chain (0.only.cycle);\n\twhile (p.front > 0 || q.front > 0)\n\t{\n\t\tres ~= Record (p.front, q.front);\n\t\tp.popFront ();\n\t\tq.popFront ();\n\t\tswap (p, q);\n\t}\n\treturn res;\n}\n\nRecord [] solveStrategyLayer (string s, string t)\n{\n\tRecord [] res = solve (s, t);\n\tauto p = separators (s, 'a').chain (0.only).retro.array;\n\tauto q = separators (t, 'b').chain (0.only).retro.array;\n\tint balance = p.length.to!int - q.length.to!int;\n\tforeach (i; 0..6)\n\t{\n\t\tforeach (j; 0..2)\n\t\t{\n\t\t\tint u = abs (balance) - 2 + i;\n\t\t\tint v = j;\n\t\t\tif (balance < 0)\n\t\t\t{\n\t\t\t\tswap (u, v);\n\t\t\t}\n\t\t\tif (u < 0 || p.length <= u || v < 0 || q.length <= v)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto s2 = t[0..q[v]] ~ s[p[u]..$];\n\t\t\tauto t2 = s[0..p[u]] ~ t[q[v]..$];\n\t\t\tRecord [] temp = [Record (p[u], q[v])];\n\t\t\ttemp ~= solve (s2, t2);\n\t\t\tif (res.length > temp.length)\n\t\t\t{\n\t\t\t\tres = temp;\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tstring s, t;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tt = readln.strip;\n\t\tauto res1 = solveStrategyLayer (s, t);\n\t\tauto res2 = solveStrategyLayer (t, s);\n\t\tif (res1.length > res2.length)\n\t\t{\n\t\t\tswap (res1, res2);\n\t\t\tres1.each !((ref a) => swap (a[0], a[1]));\n\t\t}\n\t\twriteln (res1.length);\n\t\tforeach (ref line; res1)\n\t\t{\n\t\t\twritefln (\"%s %s\", line.a, line.b);\n\t\t}\n\t}\n}\n"}], "src_uid": "4a50c4147becea13946272230f3dde6d"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tforeach (t; 0..readln.strip.to !(int))\n\t{\n\t\tint n, m;\n\t\treadf !(\" %s %s\") (n, m);\n\t\tauto adj = new bool [int] [n];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tadj[v][u] = true;\n\t\t}\n\n\t\tauto z = new bool [n];\n\t\tforeach (u; 0..n)\n\t\t{\n\t\t\tbool [int] temp;\n\t\t\tforeach (v, _; adj[u])\n\t\t\t{\n\t\t\t\tif (!z[v])\n\t\t\t\t{\n\t\t\t\t\ttemp[v] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tadj[u] = temp;\n\t\t\tforeach (v, _; adj[u])\n\t\t\t{\n\t\t\t\tforeach (w, _; adj[v])\n\t\t\t\t{\n\t\t\t\t\tif (!z[w])\n\t\t\t\t\t{\n\t\t\t\t\t\tz[u] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (z.sum);\n\t\twritefln !(\"%(%s %)\")\n\t\t (n.iota.filter !(u => z[u]).map !(q{a + 1}));\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const M = readInt();\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n auto graph = new int[][N];\n foreach (i; 0 .. M) {\n graph[B[i]] ~= A[i];\n }\n \n auto col = new int[N];\n foreach (u; 0 .. N) {\n foreach (v; graph[u]) {\n if (col[v] < 2) {\n chmax(col[u], col[v] + 1);\n }\n }\n }\n \n const ans = iota(N).filter!(u => (col[u] == 2)).array;\n writeln(ans.length);\n foreach (index, u; ans) {\n if (index > 0) write(\" \");\n write(u + 1);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tforeach (t; 0..readln.strip.to !(int))\n\t{\n\t\tint n, m;\n\t\treadf !(\" %s %s\") (n, m);\n\t\tauto adj = new int [] [n];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tadj[u] ~= v;\n\t\t}\n\n\t\tauto z = new bool [n];\n\t\tforeach_reverse (u; 0..n)\n\t\t{\n\t\t\tforeach (v; adj[u])\n\t\t\t{\n\t\t\t\tif (!z[v])\n\t\t\t\t{\n\t\t\t\t\tforeach (w; adj[v])\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!z[w])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tz[u] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (z.sum);\n\t\twritefln !(\"%(%s %)\")\n\t\t (n.iota.filter !(u => z[u]).map !(q{a + 1}));\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, M;\nint[] A, B;\n\nbool[] del;\nint[][] graph;\nint[][] dp;\nint[][] prev;\n\nvoid solve(int u) {\n auto sums = new int[3];\n foreach (v; graph[u]) {\n solve(v);\n sums[] += dp[v][];\n }\n foreach (k; 0 .. 3) {\n // delete\n dp[u][k] = 1 + sums[0];\n // keep\n if (k < 2) {\n if (chmin(dp[u][k], sums[k + 1])) {\n prev[u][k] = 1;\n }\n }\n }\n}\n\nvoid recover(int u, int k) {\n int kk;\n if (prev[u][k] == 0) {\n del[u] = true;\n kk = 0;\n } else {\n kk = k + 1;\n }\n foreach (v; graph[u]) {\n recover(v, kk);\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n N = readInt();\n M = readInt();\n A = new int[M];\n B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n alias Entry = Tuple!(int, \"deg\", int, \"u\");\n auto es = new Entry[N];\n foreach (u; 0 .. N) {\n es[u].u = u;\n }\n auto graphIn = new int[][N];\n foreach (i; 0 .. M) {\n --es[A[i]].deg;\n --es[B[i]].deg;\n graphIn[B[i]] ~= A[i];\n }\n es.sort;\n \n del = new bool[N];\n foreach_reverse (ref e; es) {\n const u = e.u;\n int indeg;\n foreach (v; graphIn[u]) {\n if (!del[v]) {\n ++indeg;\n }\n }\n if (indeg >= 2) {\n del[u] = true;\n }\n }\n debug {\n writeln(\"del = \", del);\n }\n \n graph = new int[][N];\n auto isChild = new bool[N];\n foreach (i; 0 .. M) {\n if (!del[A[i]] && !del[B[i]]) {\n graph[A[i]] ~= B[i];\n isChild[B[i]] = true;\n }\n }\n debug {\n writeln(\"graph = \", graph);\n }\n \n dp = new int[][](N, 3);\n prev = new int[][](N, 3);\n foreach (u; 0 .. N) {\n if (!del[u]) {\n if (!isChild[u]) {\n solve(u);\n recover(u, 0);\n }\n }\n }\n debug {\n writeln(\"dp = \", dp);\n writeln(\"del = \", del);\n }\n \n int[] ans;\n foreach (u; 0 .. N) {\n if (del[u]) {\n ans ~= u;\n }\n }\n \nif(ans.length>N*7/4)for(;;){}\n writeln(ans.length);\n foreach (index, u; ans) {\n if (index > 0) write(\" \");\n write(u + 1);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, M;\nint[] A, B;\n\nbool[] del;\nint[][] graph;\nint[][] dp;\nint[][] prev;\n\nvoid solve(int u) {\n auto sums = new int[3];\n foreach (v; graph[u]) {\n solve(v);\n sums[] += dp[v][];\n }\n foreach (k; 0 .. 3) {\n // delete\n dp[u][k] = 1 + sums[0];\n // keep\n if (k < 2) {\n if (chmin(dp[u][k], sums[k + 1])) {\n prev[u][k] = 1;\n }\n }\n }\n}\n\nvoid recover(int u, int k) {\n int kk;\n if (prev[u][k] == 0) {\n del[u] = true;\n kk = 0;\n } else {\n kk = k + 1;\n }\n foreach (v; graph[u]) {\n recover(v, kk);\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n N = readInt();\n M = readInt();\n A = new int[M];\n B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n auto graphIn = new int[][N];\n foreach (i; 0 .. M) {\n graphIn[B[i]] ~= A[i];\n }\n \n del = new bool[N];\n foreach (u; 0 .. N) {\n int indeg;\n foreach (v; graphIn[u]) {\n if (!del[v]) {\n ++indeg;\n }\n }\n if (indeg >= 2) {\n del[u] = true;\n }\n }\n debug {\n writeln(\"del = \", del);\n }\n \n graph = new int[][N];\n auto isChild = new bool[N];\n foreach (i; 0 .. M) {\n if (!del[A[i]] && !del[B[i]]) {\n graph[A[i]] ~= B[i];\n isChild[B[i]] = true;\n }\n }\n debug {\n writeln(\"graph = \", graph);\n }\n \n dp = new int[][](N, 3);\n prev = new int[][](N, 3);\n foreach (u; 0 .. N) {\n if (!del[u]) {\n if (!isChild[u]) {\n solve(u);\n recover(u, 0);\n }\n }\n }\n debug {\n writeln(\"dp = \", dp);\n writeln(\"del = \", del);\n }\n \n int[] ans;\n foreach (u; 0 .. N) {\n if (del[u]) {\n ans ~= u;\n }\n }\n \n writeln(ans.length);\n foreach (index, u; ans) {\n if (index > 0) write(\" \");\n write(u + 1);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "6e0ca509476a3efa3a352ca08c43023e"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n string str = strip(readln());\n int n = str.length;\n int[] a = new int[n];\n foreach (i; 0..n-1) {\n a[i] = str[i] == str[i+1];\n }\n foreach (i; 1..n-1) {\n a[i] += a[i-1];\n }\n int m;\n readf(\"%d \", &m);\n foreach (i; 0..m) {\n int l;\n int r;\n readf(\"%d %d \", &l, &r);\n l--;\n r--;\n int res = a[r-1]-(l == 0 ? 0 : a[l-1]);\n writeln(res);\n }\n}", "positive_code": [{"source_code": "// https://codeforces.com/problemset/problem/313/B\nimport std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n string s = readln.chomp;\n\n int[100005] a;\n\n for(int i = 1; i < s.length; i++) {\n if(s[i] == s[i-1])\n a[i] = 1;\n }\n\n for(int i = 1; i < s.length; i++) {\n a[i] += a[i-1];\n }\n\n int m = readln.chomp.to!int;\n //m.writeln;\n\n int l, r;\n foreach(idx; 0..m) {\n readf(\"%d %d\\n\", &l, &r);\n writefln(\"%d\", a[--r]-a[--l]);\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln ()) != null)\n\t{\n\t\tint n = s.length;\n\t\tauto a = new int [n];\n\t\ta[0] = 0;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\ta[i] = (s[i - 1] == s[i]);\n\t\t}\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\ta[i] += a[i - 1];\n\t\t}\n\n\t\tint m;\n\t\treadf (\" %s \", &m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint l, r;\n\t\t\treadf (\" %s %s \", &l, &r);\n\t\t\twriteln (a[r - 1] - a[l - 1]);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio: readln, writeln;\nimport std.string: strip;\nimport std.conv: to;\nimport std.array: split;\n\n/**\n * User: Jior\n * Date: 03.06.13\n * Time: 14:25\n */\n\nvoid main(string[] args) {\n int[100001] m;\n char[] inString = strip(readln()).dup;\n for(int i = 0; i < inString.length-1; i++) {\n m[i+1] = m[i] + (inString[i] == inString[i+1]);\n }\n\n int countReq = to!int(strip(readln()).dup);\n foreach(int regNum; 0..countReq) {\n string request = strip(readln());\n int[] reqValue = to!(int[])(request.split());\n writeln(m[reqValue[1]-1] - m[reqValue[0]-1]);\n } \n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nvoid main() {\n auto S = readln.chomp;\n auto N = S.length.to!int;\n\n auto same = new int[](N);\n foreach (i; 1..N) {\n same[i] = (S[i] == S[i-1]);\n }\n\n auto acm = new int[](N);\n foreach (i; 1..N) {\n acm[i] = acm[i-1] + same[i];\n }\n\n auto M = readln.chomp.to!int;\n foreach (_; 0..M) {\n auto s = readln.split.map!(to!int);\n auto l = s[0]-1;\n auto r = s[1]-1;\n writeln(acm[r] - acm[max(0, l-1)] - same[l]);\n }\n \n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/313/B\nimport std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n string s = readln.chomp;\n\n int[100005] a;\n\n for(int i = 1; i < s.length; i++) {\n if(s[i] == s[i-1])\n a[i] = 1;\n a[i] += a[i-1];\n }\n\n int m = readln.chomp.to!int;\n //m.writeln;\n\n int l, r;\n foreach(idx; 0..m) {\n readf(\"%d %d\\n\", &l, &r);\n writefln(\"%d\", a[--r]-a[--l]);\n }\n}\n\n"}], "negative_code": [{"source_code": "// https://codeforces.com/problemset/problem/313/B\nimport std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n string s = readln.chomp;\n\n int[100005] a;\n\n for(int i = 1; i < s.length; i++) {\n if(s[i] == s[i-1])\n a[i+1] = 1;\n a[i] += a[i-1];\n }\n\n int m = readln.chomp.to!int;\n //m.writeln;\n\n int l, r;\n foreach(idx; 0..m) {\n readf(\"%d %d\\n\", &l, &r);\n writefln(\"%d\", a[--r]-a[--l]);\n }\n}\n\n"}], "src_uid": "b30e09449309b999473e4be6643d68cd"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n = read!int;\r\n int[] res;\r\n for(int i = 1; i <= n / 2 + n % 2; i++) {\r\n res ~= i;\r\n if (i > n - i)\r\n break;\r\n res ~= n - i + 1;\r\n }\r\n writefln(\"%(%s %)\",res);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = iota(1, n + 1).array;\n swap(a[1], a[$ - 1]);\n writefln(\"%(%s %)\", a);\n }\n}\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto a = new int[N];\r\n int l = 0, r = N - 1;\r\n for (int k = 1; k <= N; k++) {\r\n if (k % 2 == 0) {\r\n a[r--] = k;\r\n } else {\r\n a[l++] = k;\r\n }\r\n }\r\n writefln(\"%(%s %)\", a);\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n = read!int;\r\n int[] res;\r\n for(int i = 1; i <= n; i++) {\r\n res ~= i;\r\n if (i > n - i)\r\n break;\r\n res ~= n - i + 1;\r\n }\r\n writefln(\"%(%s %)\",res);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "src_uid": "6fced7d8ac3dd58b1791430ada53332d"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tlong res = 0;\n\t\tforeach (i; 1..n / 2 + 1)\n\t\t{\n\t\t\tres += i * 8L * i;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\n\t\tforeach (i; 0..n/2)\n\t\t{\n\t\t\tauto size = n - (i*2);\n\t\t\tauto cnt = size * 2 + (size-2) * 2;\n\t\t\tauto d = n/2 - i;\n\t\t\tans[ti] += cnt * d;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "b4b69320c6040d2d264ac32e9ba5196f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDR.ARR;\n\tauto toI = [4:0, 8:1, 15:2, 16:3, 23:4, 42:5];\n\tauto cnt = new long[](6);\n\tforeach (i; 0..n)\n\t{\n\t\tauto pos = toI[cast(int)a[i]];\n\t\tbool ok = true;\n\t\tforeach (j; 0..pos)\n\t\t{\n\t\t\tif (cnt[j] <= cnt[pos])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ok)\n\t\t\t++cnt[pos];\n\t}\n\tlong ans;\n\tans = n - (cnt[$-1]*6);\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\n\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\", n);\n int[] a = new int[n];\n int[] v = new int[n];\n v[] =0;\n foreach(i;0..n) readf(\" %s\", a[i]);\n\n int[] nn =[4, 8, 15, 16, 23, 42];\n int[] aa;\n int ii = 0;\n int cc = 0;\n int[6] sii;\n sii[] = 0;\n int i;\n i =0;\n while(i < n) {\n if (v[i] == 0 && a[i] == nn[ii]) {\n cc++;\n v[i] = 1;\n sii[ii] = i;\n ii = (ii+1) % nn.length;\n i = sii[0 .. ii+1].maxElement;\n }\n i++;\n }\n\n writeln(n - (cc/6)*6);\n\n}\n"}], "negative_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\n\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\", n);\n int[] a = new int[n];\n int[] v = new int[n];\n v[] =0;\n foreach(i;0..n) readf(\" %s\", a[i]);\n\n int[] nn =[4, 8, 15, 16, 23, 42];\n int[] aa;\n int ii = 0;\n int cc = 0;\n int[6] sii;\n int i;\n i =0;\n while(i < n) {\n if (v[i] == 0 && a[i] == nn[ii]) {\n sii[ii] = i;\n ii = (ii+1) % nn.length;\n cc++;\n v[i] = 1;\n i = sii[ii];\n }\n i++;\n }\n\n writeln(n - (cc/6)*6);\n\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\n\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\", n);\n int[] a = new int[n];\n foreach(i;0..n) readf(\" %s\", a[i]);\n\n int[] nn =[4, 8, 15, 16, 23, 42];\n int[] aa;\n int ii = 0;\n int cc = 0;\n foreach(e; a) {\n if (e == nn[ii]) {\n ii = (ii+1) % nn.length;\n cc++;\n }\n }\n\n\n writeln(n - (cc/6)*6);\n\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\n\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\", n);\n int[] a = new int[n];\n int[] v = new int[n];\n v[] =0;\n foreach(i;0..n) readf(\" %s\", a[i]);\n\n int[] nn =[4, 8, 15, 16, 23, 42];\n int[] aa;\n int ii = 0;\n int cc = 0;\n int[6] sii;\n sii[] = 0;\n int i;\n i =0;\n while(i < n) {\n if (v[i] == 0 && a[i] == nn[ii]) {\n sii[ii] = i;\n ii = (ii+1) % nn.length;\n cc++;\n v[i] = 1;\n i = sii[ii];\n }\n i++;\n }\n\n writeln(n - (cc/6)*6);\n\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\n\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\", n);\n int[] a = new int[n];\n foreach(i;0..n) readf(\" %s\", a[i]);\n\n int[] nn =[4, 8, 15, 16, 23, 42];\n int[] aa;\n int ii = 0;\n int cc = 0;\n foreach(e; a) {\n if (e == nn[ii]) {\n ii = (ii+1) % nn.length;\n cc++;\n }\n }\n\n\n writeln(n - (n/6)*6);\n\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDR.ARR;\n\tauto toI = [4:0, 8:1, 15:2, 16:3, 23:4, 42:5];\n\tauto cnt = new long[](6);\n\tlong ans;\n\tforeach (i; 0..n)\n\t{\n\t\tauto pos = toI[cast(int)a[i]];\n\t\tbool ok = true;\n\t\tforeach (j; 0..pos)\n\t\t{\n\t\t\tif (cnt[j] <= cnt[pos])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ok)\n\t\t\t++cnt[pos];\n\t\telse\n\t\t\t++ans;\n\t}\n\tdebug writeln(ans);\n\tans += (n-ans) % 6;\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "eb3155f0e6ba088308fa942f3572f582"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\n\t\tauto cnt = new long[][](s.length+1, 3);\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tauto num = s[i]-'1';\n\t\t\tcnt[i+1] = cnt[i].dup;\n\t\t\t++cnt[i+1][num];\n\t\t}\n\n\t\t\n\t\tint tmp = int.max;\n\t\tforeach (int i; 0..cast(int)s.length)\n\t\t{\n\t\t\tbool f(int j)\n\t\t\t{\n\t\t\t\tauto x = cnt[j].dup;\n\t\t\t\tx[] -= cnt[i][];\n\t\t\t\treturn x[0] != 0 && x[1] != 0 && x[2] != 0;\n\t\t\t}\n\t\t\tauto r = binarySearch!(f)(cast(int)s.length+1, i);\n\t\t\tif (r != s.length+1)\n\t\t\t{\n\t\t\t\ttmp.chmin(r-i);\n\t\t\t}\n\t\t}\n\t\tif (tmp != int.max)\n\t\t{\n\t\t\tans[ti] = tmp;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto S = readln.chomp;\n auto len = S.length;\n auto l1 = new size_t[](len);\n auto r1 = new size_t[](len);\n auto l2 = new size_t[](len);\n auto r2 = new size_t[](len);\n auto l3 = new size_t[](len);\n auto r3 = new size_t[](len);\n\n auto i1 = len, i2 = len, i3 = len;\n foreach (i, c; S) {\n switch (c) {\n case '1': i1 = i; break;\n case '2': i2 = i; break;\n default: i3 = i;\n }\n l1[i] = i1;\n l2[i] = i2;\n l3[i] = i3;\n }\n i1 = len, i2 = len, i3 = len;\n foreach_reverse (i, c; S) {\n switch (c) {\n case '1': i1 = i; break;\n case '2': i2 = i; break;\n default: i3 = i;\n }\n r1[i] = i1;\n r2[i] = i2;\n r3[i] = i3;\n }\n\n auto res = size_t.max;\n foreach (i; 0..len) {\n switch (S[i]) {\n case '1':\n if (l2[i] != len && r3[i] != len) {\n res = min(res, r3[i] - l2[i] + 1);\n }\n if (l3[i] != len && r2[i] != len) {\n res = min(res, r2[i] - l3[i] + 1);\n }\n break;\n case '2':\n if (l1[i] != len && r3[i] != len) {\n res = min(res, r3[i] - l1[i] + 1);\n }\n if (l3[i] != len && r1[i] != len) {\n res = min(res, r1[i] - l3[i] + 1);\n }\n break;\n default:\n if (l2[i] != len && r1[i] != len) {\n res = min(res, r1[i] - l2[i] + 1);\n }\n if (l1[i] != len && r2[i] != len) {\n res = min(res, r2[i] - l1[i] + 1);\n }\n }\n }\n writeln(res == size_t.max ? 0 : res);\n }\n}"}], "negative_code": [], "src_uid": "6cb06a02077750327602a1a7eeac770f"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 998244353;\nalias Mint = ModInt!MO;\n\nenum LIM = 3 * 10^^5 + 20;\nMint[] inv, fac, invFac;\nvoid prepare() {\n inv = new Mint[LIM];\n fac = new Mint[LIM];\n invFac = new Mint[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = fac[i - 1] * i;\n invFac[i] = invFac[i - 1] * inv[i];\n }\n}\nMint binom(long n, long k) {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\n } else {\n return Mint(0);\n }\n}\n\n\nenum LIM_K = 10^^5 + 5;\n\nvoid main() {\n prepare();\n \n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const Q = readInt();\n auto E = new int[N];\n foreach (i; 0 .. N) {\n E[i] = readInt() - 1;\n }\n auto L = new int[Q];\n auto R = new int[Q];\n auto K = new int[Q];\n foreach (q; 0 .. Q) {\n L[q] = readInt() - 1;\n R[q] = readInt();\n K[q] = readInt();\n }\n \n debug {\n // brute\n writeln(\"brute\");\n foreach (q; 0 .. Q) {\n auto as = new int[M];\n auto bs = new int[M];\n foreach (i; 0 .. N) {\n ++as[E[i]];\n if (L[q] <= i && i < R[q]) {\n ++bs[E[i]];\n }\n }\n Mint ans = 1;\n foreach (j; 0 .. M) {\n ans *= fac[K[q] + as[j]] * invFac[K[q] + as[j] - bs[j]];\n }\n foreach (i; R[q] - L[q] .. N) {\n ans *= (1L * K[q] * M + N - i);\n }\n writeln(ans);\n }\n }\n \n auto as = new int[M];\n foreach (i; 0 .. N) {\n ++as[E[i]];\n }\n \n class Query {\n int l, r;\n int id;\n int key0, key1;\n this(int l, int r, int id) {\n this.l = l;\n this.r = r;\n this.id = id;\n }\n override string toString() const {\n return format(\"[%s, %s)\", l, r);\n }\n }\n auto queriess = new Query[][LIM_K];\n foreach (q; 0 .. Q) {\n queriess[K[q]] ~= new Query(L[q], R[q], q);\n }\n auto ans = new Mint[Q];\n foreach (k; 0 .. LIM_K) {\n auto queries = queriess[k];\n if (queries) {\n // suffix prod for (k M + N - 0) ... (k M + N - (N - 1))\n auto prod = new Mint[N + 1];\n prod[N] = 1;\n foreach_reverse (i; 0 .. N) {\n prod[i] = (1L * k * M + N - i) * prod[i + 1];\n }\n \n const queriesLen = cast(int)(queries.length);\n // int sz = cast(int)(sqrt(cast(real)(N)));\n // chmax(sz, 10^^5 / queriesLen);\n const sz = max(N / cast(int)(sqrt(cast(real)(queriesLen))), 1);\n foreach (q; queries) {\n q.key0 = q.l / sz;\n q.key1 = q.r;\n if (q.key0 % 2 != 0) {\n q.key1 *= -1;\n }\n }\n queries.sort!((a, b) => ((a.key0 != b.key0) ? (a.key0 < b.key0) : (a.key1 < b.key1)));\n debug {\n writeln(\"k = \", k, \", sz = \", sz);\n writeln(\" queries = \", queries);\n }\n \n Mint now = 1;\n auto bs = new int[M];\n void add(int i) {\n const j = E[i];\n /*\n now *= fac[k + as[j] - bs[j]];\n ++bs[j];\n now *= invFac[k + as[j] - bs[j]];\n */\n now *= (k + as[j] - bs[j]);\n ++bs[j];\n }\n void rem(int i) {\n const j = E[i];\n /*\n now *= fac[k + as[j] - bs[j]];\n --bs[j];\n now *= invFac[k + as[j] - bs[j]];\n */\n --bs[j];\n now *= inv[k + as[j] - bs[j]];\n }\n \n int l, r;\n foreach (q; queries) {\n for (; l > q.l; ) add(--l);\n for (; r < q.r; ) add(r++);\n for (; l < q.l; ) rem(l++);\n for (; r > q.r; ) rem(--r);\n ans[q.id] = now * prod[q.r - q.l];\n }\n }\n }\n foreach (q; 0 .. Q) {\n writeln(ans[q]);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt(int M_) {\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 998244353;\nalias Mint = ModInt!MO;\n\nenum LIM = 3 * 10^^5 + 20;\nMint[] inv, fac, invFac;\nvoid prepare() {\n inv = new Mint[LIM];\n fac = new Mint[LIM];\n invFac = new Mint[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = fac[i - 1] * i;\n invFac[i] = invFac[i - 1] * inv[i];\n }\n}\nMint binom(long n, long k) {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\n } else {\n return Mint(0);\n }\n}\n\n\nenum LIM_K = 10^^5 + 5;\n\nvoid main() {\n prepare();\n \n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const Q = readInt();\n auto E = new int[N];\n foreach (i; 0 .. N) {\n E[i] = readInt() - 1;\n }\n auto L = new int[Q];\n auto R = new int[Q];\n auto K = new int[Q];\n foreach (q; 0 .. Q) {\n L[q] = readInt() - 1;\n R[q] = readInt();\n K[q] = readInt();\n }\n \n debug {\n // brute\n writeln(\"brute\");\n foreach (q; 0 .. Q) {\n auto as = new int[M];\n auto bs = new int[M];\n foreach (i; 0 .. N) {\n ++as[E[i]];\n if (L[q] <= i && i < R[q]) {\n ++bs[E[i]];\n }\n }\n Mint ans = 1;\n foreach (j; 0 .. M) {\n ans *= fac[K[q] + as[j]] * invFac[K[q] + as[j] - bs[j]];\n }\n foreach (i; R[q] - L[q] .. N) {\n ans *= (1L * K[q] * M + N - i);\n }\n writeln(ans);\n }\n }\n \n auto as = new int[M];\n foreach (i; 0 .. N) {\n ++as[E[i]];\n }\n \n class Query {\n int l, r;\n int id;\n int key0, key1;\n this(int l, int r, int id) {\n this.l = l;\n this.r = r;\n this.id = id;\n }\n override string toString() const {\n return format(\"[%s, %s)\", l, r);\n }\n }\n auto queriess = new Query[][LIM_K];\n foreach (q; 0 .. Q) {\n queriess[K[q]] ~= new Query(L[q], R[q], q);\n }\n auto ans = new Mint[Q];\n foreach (k; 0 .. LIM_K) {\n auto queries = queriess[k];\n if (queries) {\n // suffix prod for (k M + N - 0) ... (k M + N - (N - 1))\n auto prod = new Mint[N + 1];\n prod[N] = 1;\n foreach_reverse (i; 0 .. N) {\n prod[i] = (1L * k * M + N - i) * prod[i + 1];\n }\n \n const queriesLen = cast(int)(queries.length);\n int sz = cast(int)(sqrt(cast(real)(N)));\n chmax(sz, 10^^6 / queriesLen);\n // const sz = max(N / cast(int)(sqrt(cast(real)(queriesLen))), 1);\n foreach (q; queries) {\n q.key0 = q.l / sz;\n q.key1 = q.r;\n if (q.key0 % 2 != 0) {\n q.key1 *= -1;\n }\n }\n queries.sort!((a, b) => ((a.key0 != b.key0) ? (a.key0 < b.key0) : (a.key1 < b.key1)));\n debug {\n writeln(\"k = \", k, \", sz = \", sz);\n writeln(\" queries = \", queries);\n }\n \n Mint now = 1;\n auto bs = new int[M];\n void add(int i) {\n const j = E[i];\n /*\n now *= fac[k + as[j] - bs[j]];\n ++bs[j];\n now *= invFac[k + as[j] - bs[j]];\n */\n now *= (k + as[j] - bs[j]);\n ++bs[j];\n }\n void rem(int i) {\n const j = E[i];\n /*\n now *= fac[k + as[j] - bs[j]];\n --bs[j];\n now *= invFac[k + as[j] - bs[j]];\n */\n --bs[j];\n now *= inv[k + as[j] - bs[j]];\n }\n \n int l, r;\n foreach (q; queries) {\n for (; l > q.l; ) add(--l);\n for (; r < q.r; ) add(r++);\n for (; l < q.l; ) rem(l++);\n for (; r > q.r; ) rem(--r);\n ans[q.id] = now * prod[q.r - q.l];\n }\n }\n }\n foreach (q; 0 .. Q) {\n writeln(ans[q]);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "2ce880aa4d83ba9621e8dc2c0c0c87af"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto ls = readln.chomp.split.map!(to!int).array;\n auto ds = readln.chomp.split.map!(to!int).array;\n \n auto vals = make!(RedBlackTree!(int, \"a > b\", true));\n \n int ans = int.max;\n int biggersm = ds.sum(), smallersm = 0;\n auto arr = zip(ls, ds).sort!((t1, t2) => t1[0] < t2[0]).array;\n for (int i = 0; i < n; ) {\n debug { arr[i].writeln; }\n \n int j = i+1;\n \n while (j < n && arr[i][0] == arr[j][0]) { j += 1; }\n auto cursm = arr[i .. j].map!(t => t[1]).sum();\n biggersm -= cursm;\n \n debug { biggersm.writeln; }\n \n int[] omitted;\n for (int k = i; k < j-1 && ! vals.empty(); ++k) {\n omitted ~= vals.front;\n vals.removeFront();\n }\n \n ans = min(ans, biggersm + smallersm - omitted.sum());\n \n foreach (e; omitted) { vals.insert(e); }\n smallersm += cursm;\n for (int k = i; k < j; ++k) vals.insert(arr[k][1]);\n i = j;\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.container.binaryheap;\n\nalias Leg = Tuple!(int, \"l\", int, \"d\");\n\nvoid main() {\n int n;\n scanf(\"%d\", &n);\n Leg[] a = new Leg[n];\n foreach(i; 0..n) {\n scanf(\"%d\", &a[i].l);\n }\n foreach(i; 0..n) {\n scanf(\"%d\", &a[i].d);\n }\n a.sort();\n int[] s = new int[n + 1];\n foreach(i; 0..n) {\n s[i + 1] = s[i] + a[i].d;\n }\n int p = 0, q = 0;\n auto pq = BinaryHeap!(int[])(new int[n], 0);\n int ans = int.max, sum = 0;\n while (q < n) {\n while (p < n && a[p].l == a[q].l) {\n p++;\n }\n int ct = p - q;\n int cost = s[n];\n cost -= s[p] - s[q];\n int[] vs;\n foreach (v; pq.take(ct - 1)) {\n cost -= v;\n vs ~= v;\n }\n foreach(v; vs) {\n pq.insert(v);\n }\n ans = min(ans, cost);\n while (q < p) {\n sum += a[q].d;\n pq.insert(a[q].d);\n q++;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto ls = readln.chomp.split.map!(to!int).array;\n auto ds = readln.chomp.split.map!(to!int).array;\n \n auto vals = make!(RedBlackTree!(int, \"a > b\", true));\n \n int ans = int.max;\n int biggersm = ds.sum(), smallersm = 0;\n auto arr = zip(ls, ds).sort!((t1, t2) => t1[0] < t2[0]).array;\n for (int i = 0; i < n; ) {\n debug { arr[i].writeln; }\n \n int j = i+1;\n \n while (j < n && arr[i][0] == arr[j][0]) { j += 1; }\n auto cursm = arr[i .. j].map!(t => t[1]).sum();\n biggersm -= cursm;\n \n debug { biggersm.writeln; }\n \n int[] ommited;\n for (int k = i; k < j-1 && ! vals.empty(); ++k) {\n ommited ~= vals.front;\n vals.removeFront();\n }\n \n ans = min(ans, biggersm + smallersm - ommited.sum());\n \n foreach (e; ommited) { vals.insert(e); }\n smallersm += cursm;\n for (int k = i; k < j; ++k) vals.insert(arr[k][1]);\n i = j;\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "afd12d95b59b250a0a5af87e5277a3fb"} {"source_code": "module main;\n__gshared:\nimport core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\nalias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nenum mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt gcd(BigInt a, BigInt b)\n\t\t{\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///integer size\n\t\tint sz(T)(T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (!(a[m] < g))\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (!(a[l] < g)) ? l : r;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (g < a[m])\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (g < a[l]) ? l : r;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn binf(a, g) != a.length;\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treturn s == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treadln;\n\t\treturn s == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tfreopen(\"input.txt\", \"r\", core.stdc.stdio.stdin);\n\t\t//freopen(\"output.txt\", \"w\", core.stdc.stdio.stdout);\n\t\t/*StopWatch sw;\n\t\tsw.start;\n\t\tscope (exit)\n\t\t{\n\t\t\tsw.stop;\n\t\t\tstderr.writefln(\"\\nTime: %d ms\", sw.peek.msecs);\n\t\t}*/\n\t}\n\tint n;\n\tloop: while (read(n))\n\t{\n\t\tauto st = new SList!int;\n\t\tint cnt, ans, sp;\n\t\tforeach (_; 0 .. n)\n\t\t{\n\t\t\tint t;\n\t\t\tinput(t);\n\t\t\tswitch (t)\n\t\t\t{\n\t\t\tcase 1:\n\t\t\t\tread(sp);\n\t\t\t\twhile (!st.empty && st.front < sp)\n\t\t\t\t{\n\t\t\t\t\tans++;\n\t\t\t\t\tst.removeFront;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tans += cnt;\n\t\t\t\tcnt = 0;\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\tint g;\n\t\t\t\tread(g);\n\t\t\t\tst.insert(g);\n\t\t\t\twhile (!st.empty && st.front < sp)\n\t\t\t\t{\n\t\t\t\t\tans++;\n\t\t\t\t\tst.removeFront;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 4:\n\t\t\t\tcnt = 0;\n\t\t\t\tbreak;\n\t\t\tcase 5:\n\t\t\t\tst.clear;\n\t\t\t\tbreak;\n\t\t\tcase 6:\n\t\t\t\tcnt++;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tassert(0);\n\t\t\t}\n\n\t\t}\n\t\twriteln(ans);\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n int[] overtakes;\n Tuple!(int, int)[] speeds;\n foreach (i; 0 .. n) {\n int t;\n readf(\"%s\", &t);\n if (t == 2 || t == 4 || t == 6) { overtakes ~= t; }\n else {\n int x = 0;\n if (t == 1 || t == 3) { readf(\" %s\", &x); }\n \n speeds ~= tuple(t, x);\n }\n readln;\n }\n \n int ans = 0;\n int ostack = 0;\n foreach (e; overtakes) {\n if (e == 2) {\n ans += ostack;\n ostack = 0;\n } else if (e == 4) { ostack = 0; } \n else { ostack += 1; }\n }\n \n int cspeed = 0;\n int[] speedlims;\n foreach (e; speeds) {\n if (e[0] == 1) {\n while (!speedlims.empty() && speedlims.back() < e[1]) {\n ans += 1;\n speedlims.popBack();\n }\n cspeed = e[1];\n } else if (e[0] == 3) {\n if (cspeed > e[1]) { ans += 1; }\n else { speedlims ~= e[1]; }\n } else {\n speedlims = [];\n }\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "2dca11b202d7adbe22a404a52d627eed"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = ok - (ok-ng) / 2;\n\t\tif (unaryFun!pred(mid))\n\t\t\tok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = new int[][](n);\n\tauto mm = new int[][](n);\n\tauto oks = new bool[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto l = RD!int;\n\t\ts[i].length = l;\n\t\tforeach (j; 0..l)\n\t\t\ts[i][j] = RD!int;\n\n\t\tmm[i] = [int.max, int.min];\n\t\tint x = int.max;\n\t\tforeach (j; 0..l)\n\t\t{\n\t\t\tif (s[i][j] > x)\n\t\t\t\toks[i] = true;\n\t\t\tx.chmin(s[i][j]);\n\t\t\tmm[i][0].chmin(s[i][j]);\n\t\t\tmm[i][1].chmax(s[i][j]);\n\t\t}\n\t}\n\n\tlong cnt_ok;\n\tforeach (i; 0..n)\n\t\tif (oks[i]) ++cnt_ok;\n\n\tint[] list;\n\tforeach (i; 0..n)\n\t{\n\t\tif (oks[i]) continue;\n\t\tlist ~= mm[i][1];\n\t}\n\tlist.sort!\"a > b\"();\n\t\n\tlong ans = cnt_ok * cnt_ok;\n\tans += cnt_ok * (n - cnt_ok) * 2;\n\tforeach (i; 0..n)\n\t{\n\t\tdebug writeln(\"i:\", i, \" ans:\", ans);\n\t\tif (oks[i]) continue;\n\t\tbool f(int x)\n\t\t{\n\t\t\treturn list[x] > mm[i][0];\n\t\t}\n\t\tauto r = binarySearch!(f)(-1, cast(int)list.length);\n\t\tdebug writeln(\"i:\", i, \" r:\", r);\n\t\tans += r+1;\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = new int [] [n];\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tc = readln.splitter.drop (1).map !(to !(int)).array;\n\t\t}\n\n\t\tlong res = n * 1L * n;\n\t\ta = a.filter !(c => c.isSorted !(q{a > b})).array;\n\t\tauto lo = a.map !(minElement).array;\n\t\tauto hi = a.map !(maxElement).array;\n\t\tsort (lo);\n\t\tsort (hi);\n\n\t\tint k = lo.length.to !(int);\n\t\tint j = 0;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\twhile (j < k && hi[j] <= lo[i])\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\tres -= j;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tint[long] uc, vc;\n\tforeach(i; 0 .. n){\n\t\tint l = rint;\n\t\tlong[] aq = rlong(l);\n\n\t\tif(aq.hasAscent) continue;\n\t\telse{\n\t\t\tif(aq[0] !in uc) uc[aq[0]] = 0;\n\t\t\tuc[aq[0]] += 1;\n\n\t\t\tif(aq[$ - 1] !in vc) vc[aq[$ - 1]] = 0;\n\t\t\tvc[aq[$ - 1]] += 1;\n\t\t}\n\t}\n\tlog(\"uc:\", uc, \"vc:\", vc);\n\n\tlong[] uks = uc.keys, vks = vc.keys;\n\n\tlong[] zs = uks.dup;\n\tforeach(uk; uks) if(uk !in vc) vc[uk] = 0;\n\tforeach(vk; vks) if(vk !in uc) uc[vk] = 0, zs ~= vk;\n\tlog(\"uks:\", uks, \"vks:\", vks, \"zs:\", zs);\n\n\tzs.sort();\n\tlog(\"zs:\", zs);\n\n\tint[long] uu, vu;\n\tint vt = 0;\n\tforeach_reverse(z; zs){\n\t\tvu[z] = vt + vc[z];\n\t\tvt += vc[z];\n\t}\n\tint ut = 0;\n\tforeach(z; zs){\n\t\tuu[z] = ut + uc[z];\n\t\tut += uc[z];\n\t}\n\tlog( \"uu:\", uu, \"vc:\", vc);\n\n\tlong ans = n.to!long * n.to!long;\n\tforeach(z; zs){\n\t\tans -= uu[z].to!long * vc[z].to!long;\n\t}\n\n\tans.writeln;\n\n\n}\nbool hasAscent(long[] aq){\n\tlong b = aq[0];\n\tforeach(a; aq){\n\t\tif(b < a) return 1;\n\t\telse b = a;\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto L = new int[N];\n auto S = new int[][N];\n foreach (i; 0 .. N) {\n L[i] = readInt();\n S[i] = new int[L[i]];\n foreach (x; 0 .. L[i]) {\n S[i][x] = readInt();\n }\n }\n \n auto decr = new bool[N];\n foreach (i; 0 .. N) {\n decr[i] = true;\n foreach (x; 0 .. L[i] - 1) {\n decr[i] = decr[i] && (S[i][x] >= S[i][x + 1]);\n }\n }\n \n int lim;\n foreach (i; 0 .. N) {\n foreach (x; 0 .. L[i]) {\n chmax(lim, S[i][x]);\n }\n }\n lim += 10;\n auto fs = new long[lim];\n foreach (i; 0 .. N) {\n if (decr[i]) {\n ++fs[S[i][0]];\n }\n }\n foreach (a; 1 .. lim) {\n fs[a] += fs[a - 1];\n }\n \n long ans = 1L * N * N;\n foreach (i; 0 .. N) {\n if (decr[i]) {\n ans -= fs[S[i][L[i] - 1]];\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = ok - (ok-ng) / 2;\n\t\tif (unaryFun!pred(mid))\n\t\t\tok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = new int[][](n);\n\tauto mm = new int[][](n);\n\tauto oks = new bool[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto l = RD!int;\n\t\ts[i].length = l;\n\t\tforeach (j; 0..l)\n\t\t\ts[i][j] = RD!int;\n\n\t\tmm[i] = [int.max, int.min];\n\t\tint x = int.max;\n\t\tforeach (j; 0..l)\n\t\t{\n\t\t\tif (s[i][j] > x)\n\t\t\t\toks[i] = true;\n\t\t\tx.chmin(s[i][j]);\n\t\t\tmm[i][0].chmin(s[i][j]);\n\t\t\tmm[i][1].chmax(s[i][j]);\n\t\t}\n\t}\n\n\tint cnt_ok;\n\tforeach (i; 0..n)\n\t\tif (oks[i]) ++cnt_ok;\n\n\tint[] list;\n\tforeach (i; 0..n)\n\t{\n\t\tif (oks[i]) continue;\n\t\tlist ~= mm[i][1];\n\t}\n\tlist.sort!\"a > b\"();\n\t\n\tlong ans = max(cnt_ok * (cnt_ok+1) / 2 * 2 - cnt_ok, 0);\n\tans += cnt_ok * (n - cnt_ok) * 2;\n\tforeach (i; 0..n)\n\t{\n\t\tdebug writeln(\"i:\", i, \" ans:\", ans);\n\t\tif (oks[i]) continue;\n\t\tbool f(int x)\n\t\t{\n\t\t\treturn list[x] > mm[i][0];\n\t\t}\n\t\tauto r = binarySearch!(f)(-1, cast(int)list.length);\n\t\tdebug writeln(\"i:\", i, \" r:\", r);\n\t\tans += r+1;\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "b6b60d1e21e51771d6ba2a8b41619296"} {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\nimport std.bigint;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[2000] arr;\n int[] toomany, toofew;\n int[int] freq;\n int n, m;\n readf(\" %s %s\\n\", &n, &m);\n int minmax = n / m;\n foreach ( i; 1 .. m + 1 ) {\n freq[i] = 0;\n }\n foreach ( i; 0 .. n ) {\n readf(\" %s\", &arr[i]);\n if (arr[i] > m) toomany ~= arr[i];\n else freq[arr[i]] += 1;\n }\n foreach ( i; freq.byKey ) {\n if (freq[i] > minmax) {\n foreach ( j; 0 .. freq[i] - minmax) {\n toomany ~= i;\n }\n }\n else if (freq[i] < minmax) {\n foreach ( j; 0 .. minmax - freq[i]) {\n toofew ~= i;\n }\n }\n }\n int cnter = 0;\n for (int i = 0; !toofew.empty; ++i) {\n int idx = toomany.length - toomany.find(arr[i]).length;\n if (idx != toomany.length) {\n ++cnter;\n arr[i] = toofew.back;\n toofew.popBack;\n toomany = toomany.remove(idx);\n }\n }\n writeln(minmax, \" \", cnter);\n foreach ( i; 0 .. n ) {\n write(arr[i], \" \");\n }\n writeln();\n \n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\nimport std.container.rbtree;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[2000] arr;\n auto toomany = new RedBlackTree!(int, \"a < b\", true);\n int[] toofew;\n int[int] freq;\n int n, m;\n readf(\" %s %s\\n\", &n, &m);\n int minmax = n / m;\n foreach ( i; 1 .. m + 1 ) {\n freq[i] = 0;\n }\n foreach ( i; 0 .. n ) {\n readf(\" %s\", &arr[i]);\n if (arr[i] > m) toomany.insert(arr[i]);\n else freq[arr[i]] += 1;\n }\n foreach ( i; freq.byKey ) {\n if (freq[i] > minmax) {\n foreach ( j; 0 .. freq[i] - minmax) {\n toomany.insert(i);\n }\n }\n else if (freq[i] < minmax) {\n foreach ( j; 0 .. minmax - freq[i]) {\n toofew ~= i;\n }\n }\n }\n int cnter = 0;\n for (int i = 0; !toofew.empty; ++i) {\n auto er = toomany.equalRange(arr[i]);\n if (!er.empty) {\n ++cnter;\n toomany.removeKey(arr[i]);\n arr[i] = toofew.back;\n toofew.popBack;\n }\n }\n writeln(minmax, \" \", cnter);\n foreach ( i; 0 .. n ) {\n write(arr[i], \" \");\n }\n writeln();\n \n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[2000] arr;\n int[int] freq;\n int[int] toomany;\n int[] toofew;\n int n, m;\n readf(\" %s %s\\n\", &n, &m);\n int minmax = n / m;\n foreach ( i; 1 .. m + 1 ) {\n freq[i] = 0;\n }\n foreach ( i; 0 .. n ) {\n readf(\" %s\", &arr[i]);\n if (arr[i] > m) toomany[arr[i]] += 1;\n else freq[arr[i]] += 1;\n }\n foreach ( i; freq.byKey ) {\n if (freq[i] > minmax) {\n foreach ( j; 0 .. freq[i] - minmax) {\n toomany[i] += 1;\n }\n }\n else if (freq[i] < minmax) {\n foreach ( j; 0 .. minmax - freq[i]) {\n toofew ~= i;\n }\n }\n }\n int cnter = 0;\n for (int i = 0; !toofew.empty; ++i) {\n auto val = arr[i] in toomany;\n if (val && *val > 0) {\n ++cnter;\n *val -= 1;\n arr[i] = toofew.back;\n toofew.popBack;\n }\n }\n writeln(minmax, \" \", cnter);\n foreach ( i; 0 .. n ) {\n write(arr[i], \" \");\n }\n writeln();\n \n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\nimport std.bigint;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[2000] arr;\n int[] toomany, toofew;\n int[int] freq;\n int n, m;\n readf(\" %s %s\\n\", &n, &m);\n int minmax = n / m;\n foreach ( i; 1 .. m + 1 ) {\n freq[i] = 0;\n }\n foreach ( i; 0 .. n ) {\n readf(\" %s\", &arr[i]);\n if (arr[i] > m) toomany ~= arr[i];\n else freq[arr[i]] += 1;\n }\n foreach ( i; freq.byKey ) {\n if (freq[i] > minmax) toomany ~= i;\n else if (freq[i] < minmax) toofew ~= i;\n }\n int cnter = 0;\n for (int i = 0; !toofew.empty; ++i) {\n int idx = toomany.length - toomany.find(arr[i]).length;\n if (idx != toomany.length) {\n ++cnter;\n arr[i] = toofew.back;\n toofew.popBack;\n toomany = toomany.remove(idx);\n }\n }\n writeln(minmax, \" \", cnter);\n foreach ( i; 0 .. n ) {\n write(arr[i], \" \");\n }\n writeln();\n \n return 0;\n}"}], "src_uid": "0d89602f5ed765adf6807f86df1205bd"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nstring solve (int n, int [] a)\n{\n\tforeach_reverse (b; 0..30)\n\t{\n\t\tauto z = a.count !(x => (x & (1 << b)) > 0);\n\t\tif (z & 1)\n\t\t{\n\t\t\tif (z % 2 == n % 2 && z % 4 == 3)\n\t\t\t{\n\t\t\t\treturn \"LOSE\";\n\t\t\t}\n\t\t\treturn \"WIN\";\n\t\t}\n\t}\n\treturn \"DRAW\";\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (n, a));\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n debug {\n enum lim = 100;\n auto dp = new int[][][][](lim, lim, 2, 2);\n foreach (a; 0 .. lim) foreach (b; 0 .. lim) foreach (s; 0 .. 2) foreach (t; 0 .. 2) {\n if (a + b == 0) {\n dp[a][b][s][t] = s;\n } else if (t == 1) {\n dp[a][b][s][t] = 0;\n if (a > 0 && dp[a - 1][b][s ^ 0][t ^ 1] == 1) dp[a][b][s][t] = 1;\n if (b > 0 && dp[a][b - 1][s ^ 1][t ^ 1] == 1) dp[a][b][s][t] = 1;\n } else {\n dp[a][b][s][t] = 1;\n if (a > 0 && dp[a - 1][b][s][t ^ 1] == 0) dp[a][b][s][t] = 0;\n if (b > 0 && dp[a][b - 1][s][t ^ 1] == 0) dp[a][b][s][t] = 0;\n }\n }\n foreach (a; 0 .. lim) foreach (b; 0 .. lim) {\n if (b % 2 != 0) {\n // writeln(a, \" \", b, \": \", dp[a][b]);\n foreach (s; 0 .. 2) foreach (t; 0 .. 2) {\n assert(dp[a][b][s][t] == ((a % 2 == 0) ? (((b >> 1) & 1) ^ s ^ t) : t));\n }\n }\n }\n }\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n long sum;\n foreach (i; 0 .. N) {\n sum ^= A[i];\n }\n if (sum == 0) {\n writeln(\"DRAW\");\n } else {\n const e = bsr(sum);\n auto cnt = new int[2];\n foreach (i; 0 .. N) {\n ++cnt[cast(int)((A[i] >> e) & 1)];\n }\n debug {\n writeln(cnt);\n }\n const ans = (cnt[0] % 2 == 0) ? (((cnt[1] >> 1) & 1) ^ 1) : 1;\n writeln(ans ? \"WIN\" : \"LOSE\");\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nstring solve (int n, int [] a)\n{\n\tforeach_reverse (b; 0..30)\n\t{\n\t\tauto z = a.count !(x => (x & (1 << b)) > 0);\n\t\tif (z & 1)\n\t\t{\n\t\t\tif (z == n && z % 4 == 3)\n\t\t\t{\n\t\t\t\treturn \"LOSE\";\n\t\t\t}\n\t\t\treturn \"WIN\";\n\t\t}\n\t}\n\treturn \"DRAW\";\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (n, a));\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (a.fold !(q{a ^ b}) == 0 ? \"DRAW\" : \"WIN\");\n\t}\n}\n"}], "src_uid": "4b78c417abfbbceef51110365c4c0f15"} {"source_code": "import std.stdio, std.string;\n\nint f[100010];\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n foreach (int i; 0 .. 100001)\n {\n f[i] = -1;\n }\n int succ = 1;\n foreach (int i; 0 .. n)\n {\n int x, k;\n scanf(\"%d%d\", &x, &k);\n if (f[k] + 1 < x)\n {\n succ = 0;\n }\n else if (f[k] + 1 == x)\n {\n ++ f[k];\n }\n }\n if (succ == 1)\n {\n printf(\"YES\\n\");\n }\n else\n {\n printf(\"NO\\n\");\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n\tuint n;\n\treadf(\" %s\", &n);\n\n\tbool[uint][] nums = new bool[uint][100_000];\n\n\tfor(uint i = 0; i < n; i++)\n\t{\n\t\tuint x, k;\n\t\treadf(\" %s %s\", &x, &k);\n\n\t\tif(x != 0)\n\t\t{\n\t\t\tif(x - 1 !in nums[k])\n\t\t\t{\n\t\t\t\twriteln(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tnums[k][x] = true;\n\t}\n\n\twriteln(\"YES\");\n}"}], "negative_code": [], "src_uid": "6f6f56d3106e09d51ebb3a206fa4be3c"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n long x;\n readf(\"%s %s\", &n, &x);\n readln;\n\n auto d = readln.chomp.split.map!(to!int).array;\n \n d = d ~ d;\n \n debug { d.writeln; }\n \n long sumklast( int mx, int k ) {\n long sm( int k ) {\n return (1 + k).to!long * k / 2;\n }\n return sm( mx ) - sm( mx - k );\n }\n \n int le = 2*n - 1;\n long tot = 0;\n long ans = 0, cur = 0;\n foreach_reverse ( r; n .. 2*n ) {\n le = min( le, r );\n \n while ( tot + d[le] <= x ) {\n tot += d[le];\n cur += sumklast( d[le], d[le] );\n --le;\n }\n \n auto spillover = sumklast( d[le], (x - tot).to!int );\n \n debug { writeln( r, ' ', cur, ' ', spillover ); }\n \n ans = max( ans, cur + spillover );\n \n if ( r - le > 0 ) {\n auto tosub = min( d[r], x ).to!int;\n cur -= sumklast( d[r], tosub );\n tot -= tosub;\n }\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nlong t (long x)\n{\n\treturn x * (x + 1L) / 2;\n}\n\nvoid main ()\n{\n\tint n;\n\tlong x;\n\twhile (readf !(\" %s %s\") (n, x) > 0)\n\t{\n\t\treadln;\n\t\tauto d = readln.splitter.map !(to !(int)).array;\n\t\tlong res = 0;\n\t\tlong cur = 0;\n\t\tint j = n - 1;\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\twhile (d[j] <= x)\n\t\t\t{\n\t\t\t\tcur += t (d[j]);\n\t\t\t\tx -= d[j];\n\t\t\t\tj = (j + n - 1) % n;\n\t\t\t}\n\t\t\tres = max (res, cur + t (d[j]) - t (d[j] - x));\n\t\t\tcur -= t (d[i]);\n\t\t\tx += d[i];\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto x = next!long;\n auto d = next!long(n);\n if (x == 0) return 0.println;\n int i = 0;\n int j = 0;\n long noDaysInMonth = d[i];\n long hugs = d[i] * (d[i] + 1) / 2;\n long best = long.min;\n while (noDaysInMonth < x)\n {\n j--; if (j == -1) j = n - 1;\n noDaysInMonth += d[j];\n hugs += d[j] * (d[j] + 1) / 2;\n }\n while(i < n)\n {\n auto rem = noDaysInMonth - x;\n auto realHugs = hugs - rem * (rem + 1) / 2;\n \n debug print(\"i\", i, \"j\", j, \"rem\", rem, \"realHugs\", realHugs);\n debug writeln;\n \n best = max(realHugs, best);\n i++;\n if (i == n) break;\n noDaysInMonth += d[i];\n hugs += d[i] * (d[i] + 1) / 2;\n while(noDaysInMonth >= x)\n\t{\n\t noDaysInMonth -= d[j];\n\t hugs -= d[j] * (d[j] + 1) / 2;\n\t j++; if (j == n) j = 0 ;\n\t}\n j--; if (j < 0) j = n - 1;\n noDaysInMonth += d[j];\n hugs += d[j] * (d[j] + 1) / 2;\n }\n best.writeln;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto x = RD;\n\tauto d = RDA;\n\t\n\tlong ans;\n\tlong cnt;\n\tlong remain = x;\n\tlong[][] log;\n\tforeach_reverse (_i; 0..n*2)\n\t{\n\t\tauto i = _i % n;\n\t\tauto y = d[i] * (d[i]+1) / 2;\n\t\tauto z = max(d[i]-remain, 0);\n\t\tans.chmax(cnt + y - z * (z+1) / 2);\n\t\tdebug writeln(\"i:\", i, \" cnt1:\", cnt, \" remain:\", remain, \" log:\", log);\n\t\tif (remain < d[i])\n\t\t{\n\t\t\t(){\n\t\t\twhile (remain < d[i])\n\t\t\t{\n\t\t\t\tif (log.empty)\n\t\t\t\t{\n\t\t\t\t\tcnt = 0;\n\t\t\t\t\tauto zz = max(d[i]-x, 0);\n\t\t\t\t\tcnt += y - zz * (zz+1) / 2;\n\t\t\t\t\tans.chmax(cnt);\n\t\t\t\t\tcnt = 0;\n\t\t\t\t\tremain = x;\n\t\t\t\t\tdebug writeln(\"i:\", i, \" cnt2:\", cnt);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto l = log.front; log.popFront;\n\t\t\t\t\tremain += l[1];\n\t\t\t\t\tcnt -= l[0];\n\t\t\t\t\tauto zz = max(d[i]-remain, 0);\n\t\t\t\t\tif (remain > 0)\n\t\t\t\t\t\tans.chmax(cnt + y - zz * (zz+1) / 2);\n\t\t\t\t\tdebug writeln(\"i:\", i, \" cnt3:\", cnt, \" ans:\", ans);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcnt += y;\n\t\t\tans.chmax(cnt);\n\t\t\tremain -= d[i];\n\t\t\tlog ~= [y, d[i]];\n\t\t\t}();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcnt += y;\n\t\t\tremain -= d[i];\n\t\t\tlog ~= [y, d[i]];\n\t\t}\n\t\tdebug writeln(\"ans:\", ans);\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, x;\n readf(\"%s %s\", &n, &x);\n readln;\n\n auto d = readln.chomp.split.map!(to!int).array;\n \n d = d ~ d;\n \n debug { d.writeln; }\n \n long sumklast( int mx, int k ) {\n long sm( int k ) {\n return (1 + k).to!long * k / 2;\n }\n return sm( mx ) - sm( mx - k );\n }\n \n int le = 2*n - 1, tot = 0;\n long ans = 0, cur = 0;\n foreach_reverse ( r; n .. 2*n ) {\n while ( tot + d[le] <= x ) {\n tot += d[le];\n cur += sumklast( d[le], d[le] );\n --le;\n }\n \n auto spillover = sumklast( d[le], x - tot );\n \n debug { writeln( r, ' ', cur, ' ', spillover ); }\n \n ans = max( ans, cur + spillover );\n \n auto tosub = min( d[r], x );\n cur -= sumklast( d[r], tosub );\n tot -= tosub;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n long x;\n readf(\"%s %s\", &n, &x);\n readln;\n\n auto d = readln.chomp.split.map!(to!int).array;\n \n d = d ~ d;\n \n debug { d.writeln; }\n \n long sumklast( int mx, int k ) {\n long sm( int k ) {\n return (1 + k).to!long * k / 2;\n }\n return sm( mx ) - sm( mx - k );\n }\n \n int le = 2*n - 1;\n long tot = 0;\n long ans = 0, cur = 0;\n foreach_reverse ( r; n .. 2*n ) {\n while ( tot + d[le] <= x ) {\n tot += d[le];\n cur += sumklast( d[le], d[le] );\n --le;\n }\n \n auto spillover = sumklast( d[le], (x - tot).to!int );\n \n debug { writeln( r, ' ', cur, ' ', spillover ); }\n \n ans = max( ans, cur + spillover );\n \n auto tosub = min( d[r], x ).to!int;\n cur -= sumklast( d[r], tosub );\n tot -= tosub;\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto x = next!int;\n auto d = next!long(n);\n if (x == 0) return 0.println;\n int i = 0;\n int j = 0;\n long noDaysInMonth = d[i];\n long hugs = d[i] * (d[i] + 1) / 2;\n long best = long.min;\n while (noDaysInMonth < x)\n {\n j--; if (j == -1) j = n - 1;\n noDaysInMonth += d[j];\n hugs += d[j] * (d[j] + 1) / 2;\n }\n while(i < n)\n {\n auto rem = noDaysInMonth - x;\n auto realHugs = hugs - rem * (rem + 1) / 2;\n \n debug print(\"i\", i, \"j\", j, \"rem\", rem, \"realHugs\", realHugs);\n debug writeln;\n \n best = max(realHugs, best);\n i++;\n if (i == n) break;\n noDaysInMonth += d[i];\n hugs += d[i] * (d[i] + 1) / 2;\n while(noDaysInMonth >= x)\n\t{\n\t noDaysInMonth -= d[j];\n\t hugs -= d[j] * (d[j] + 1) / 2;\n\t j++; if (j == n) j = 0 ;\n\t}\n j--; if (j < 0) j = n - 1;\n noDaysInMonth += d[j];\n hugs += d[j] * (d[j] + 1) / 2;\n }\n best.writeln;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}], "src_uid": "9ba374e20305d93ba42ef152e2cad5b5"} {"source_code": "import std.stdio;\nimport std.array;\nimport std.range : enumerate, slide;\nimport std.algorithm : map;\nimport std.math : abs;\nimport std.string : strip, split;\nimport std.conv : to;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n auto a = readln.strip.split.map!(to!int);\n auto found = false;\n // an array is interesting if max(a) - min(a) >= len(a)\n // find an interesting nonempty subarray if it exists\n foreach (l, w; a.slide(2).enumerate) {\n if (abs(w[0] - w[1]) >= 2) {\n\twritefln(\"YES\\n%d %d\", l+1, l+2);\n\tfound = true;\n\tbreak;\n }\n }\n\n if (!found) writeln(\"NO\");\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\treadf !(\" %s\") (n);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (abs (a[i] - a[i - 1]) > 1)\n\t\t\t{\n\t\t\t\twriteln (\"YES\");\n\t\t\t\twriteln (i, \" \", i + 1);\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\t\twriteln (\"NO\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tA: foreach(_; 0 .. rint){\n\t\tint n = rint;\n\t\tlong[] as = rlong(n);\n\n\t\tforeach(i; 0 .. n - 1){\n\t\t\tlong a = as[i], b = as[i + 1];\n\t\t\tif(abs(b - a) >= 2){\n\t\t\t\t\"YES\".writeln;\n\t\t\t\twriteln(i + 1, \" \", i + 2);\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t}\n\n\t\t\"NO\".writeln;\n\t\t\n\t}\n\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tint l, r;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = a[i] - a[l];\n\t\t\tauto len = i-l+1;\n\t\t\tif (d >= len)\n\t\t\t{\n\t\t\t\tr = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (a[i] < a[l]+len)\n\t\t\t{\n\t\t\t\tl = i;\n\t\t\t}\n\t\t}\n\t\tif (r != 0)\n\t\t{\n\t\t\tans[ti] = [l, r];\n\t\t\tcontinue;\n\t\t}\n\t\tl = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = a[l] - a[i];\n\t\t\tauto len = i-l+1;\n\t\t\tif (d >= len)\n\t\t\t{\n\t\t\t\tr = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (a[i] > a[l]-len)\n\t\t\t{\n\t\t\t\tl = i;\n\t\t\t}\n\t\t}\n\t\tif (r != 0)\n\t\t{\n\t\t\tans[ti] = [l, r];\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(\"NO\");\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(e[0]+1, \" \", e[1]+1);\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "void main() {\n\tauto t = ri;\n\tforeach(_; 0..t) {\n\t\tauto n = ri;\n\t\tauto a = readAs!(int[]);\n\t\tbool flag = false;\n\t\tforeach(i; 0..n-1) {\n\t\t\tif(abs(a[i] - a[i+1]) >= 2) {\n\t\t\t\twriteln(\"YES\");\n\t\t\t\twritefln(\"%d %d\", i+1, i+2);\n\t\t\t\tflag = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(!flag) writeln(\"NO\");\n\t}\n}\n\n// ===================================\n\nimport std.stdio;\nimport std.string;\nimport std.functional;\nimport std.algorithm;\nimport std.range;\nimport std.traits;\nimport std.math;\nimport std.container;\nimport std.bigint;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.uni;\nimport std.ascii;\nimport std.bitmanip;\nimport core.bitop;\n\nT readAs(T)() if (isBasicType!T) {\n\treturn readln.chomp.to!T;\n}\nT readAs(T)() if (isArray!T) {\n\treturn readln.split.to!T;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tres[i] = readAs!(T[]);\n\t}\n\treturn res;\n}\n\nT[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {\n\tauto res = new T[][](height, width);\n\tforeach(i; 0..height) {\n\t\tauto s = rs;\n\t\tforeach(j; 0..width) res[i][j] = s[j].to!T;\n\t}\n\treturn res;\n}\n\nint ri() {\n\treturn readAs!int;\n}\n\ndouble rd() {\n\treturn readAs!double;\n}\n\nstring rs() {\n\treturn readln.chomp;\n}"}], "negative_code": [], "src_uid": "fa16d33fb9447eea06fcded0026c6e31"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\t\n\tint[][] zf = [\n\t\t[8, 9, 1, 13],\n\t\t[3, 12, 7, 5],\n\t\t[0, 2, 4, 11],\n\t\t[6, 10, 15, 14]\n\t];\n\t\n\tint[][] xf = new int[][](n, n);\n\tforeach(i; 0 .. n) foreach(j; 0 .. n){\n\t\tint zi = i % 4, zj = j % 4;\n\t\tint wi = i / 4, wj = j / 4;\n\t\tint w = wi * (n / 4) + wj;\n\t\txf[i][j] = w * 16 + zf[zi][zj];\n\t}\n\t\n\tlog(\"check i:\", n.iota.map!((i){ int res = 0; foreach(j; 0 .. n) res ^= xf[i][j]; return res;}));\n\tlog(\"check j:\", n.iota.map!((j){ int res = 0; foreach(i; 0 .. n) res ^= xf[i][j]; return res;}));\n\t\n\t\n\tforeach(i; 0 .. n) xf[i].map!(to!string).array.join(\" \").writeln;\n\t\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n \n auto a = new int[][](N, N);\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n a[x][y] = (y / 4) * (4 * N) + x * 4 + (y % 4);\n }\n \n debug {\n foreach (x; 0 .. N) {\n int sum;\n foreach (y; 0 .. N) {\n sum ^= a[x][y];\n }\n writeln(\"row \", x, \": \", sum);\n }\n foreach (y; 0 .. N) {\n int sum;\n foreach (x; 0 .. N) {\n sum ^= a[x][y];\n }\n writeln(\"col \", y, \": \", sum);\n }\n }\n \n foreach (x; 0 .. N) {\n foreach (y; 0 .. N) {\n if (y > 0) {\n write(\" \");\n }\n write(a[x][y]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "38ee7fc4cd2d019aa9e5b33d8bea4a2f"} {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nimmutable class SegTree {\n SegTree left, right;\n bool inv;\n int size, count;\n\n this(bool value) {\n left = right = null;\n inv = false;\n size = 1;\n count = value;\n }\n\n this(immutable SegTree left, immutable SegTree right, bool inv) {\n this.left = left;\n this.right = right;\n this.inv = inv;\n size = getSize(left) + getSize(right);\n count = getCount(left) + getCount(right);\n }\n\n static int getSize(immutable SegTree t) {\n return t is null? 0 : t.size;\n }\n\n static int getCount(immutable SegTree t) {\n return t is null? 0 : t.inv? t.size - t.count : t.count;\n }\n\n static auto invertOne(immutable SegTree t) {\n if (t is null)\n return null;\n if (t.left is null && t.right is null)\n return new immutable SegTree(!t.count);\n return new immutable SegTree(t.left, t.right, !t.inv);\n }\n\n auto push() {\n return inv? new immutable SegTree(invertOne(left), invertOne(right), false) : this;\n }\n\n auto update(int i, bool value) {\n assert(size >= 1, \"Size is %s\".format(size));\n if (size == 1) {\n assert(!i);\n return new immutable SegTree(value);\n }\n auto t = push();\n if (i < getSize(left))\n return new immutable SegTree(t.left.update(i, value), t.right, false);\n return new immutable SegTree(t.left, t.right.update(i - getSize(left), value), false);\n }\n\n auto invert(int lb, int rb) {\n if (!lb && rb == size)\n return invertOne(this);\n int mid = getSize(left);\n auto t = push();\n auto newLeft = lb >= mid? t.left : t.left.invert(lb, min(mid, rb));\n auto newRight = rb <= mid? t.right : t.right.invert(max(lb - mid, 0), rb - mid);\n return new immutable SegTree(newLeft, newRight, false);\n }\n}\n\nauto construct(int n) {\n assert(n >= 1);\n if (n == 1)\n return new immutable SegTree(false);\n return new immutable SegTree(construct(n >> 1), construct(n - (n >> 1)), false);\n}\n\nvoid main() {\n int n, m, q;\n while (read(&n, &m, &q)) {\n auto roots = [construct(n * m)];\n roots.reserve(q + 1);\n while (q--) {\n char c;\n int a, b;\n read(&c, &a);\n final switch (c) {\n case '1': case '2': {\n read(&b);\n roots ~= roots.back.update((a - 1) * m + b - 1, c == '1');\n break;\n }\n case '3': {\n roots ~= roots.back.invert((a - 1) * m, a * m);\n break;\n }\n case '4': {\n roots ~= roots[a];\n break;\n }\n }\n writeln(SegTree.getCount(roots.back));\n }\n debug writeln();\n }\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdio;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nimmutable class SegTree {\n SegTree left, right;\n bool inv;\n int size, count;\n\n this(bool value) {\n left = right = null;\n inv = false;\n size = 1;\n count = value;\n }\n\n this(immutable SegTree left, immutable SegTree right, bool inv) {\n this.left = left;\n this.right = right;\n this.inv = inv;\n size = getSize(left) + getSize(right);\n count = getCount(left) + getCount(right);\n }\n\n static int getSize(immutable SegTree t) {\n return t is null? 0 : t.size;\n }\n\n static int getCount(immutable SegTree t) {\n return t is null? 0 : t.inv? t.size - t.count : t.count;\n }\n\n static auto invertOne(immutable SegTree t) {\n if (t is null)\n return null;\n if (t.left is null && t.right is null)\n return new immutable SegTree(!t.count);\n return new immutable SegTree(t.left, t.right, !t.inv);\n }\n\n auto push() {\n return inv? new immutable SegTree(invertOne(left), invertOne(right), false) : this;\n }\n\n auto update(int i, bool value) {\n assert(size >= 1, \"Size is %s\".format(size));\n if (size == 1) {\n assert(!i);\n return new immutable SegTree(value);\n }\n auto t = push();\n if (i < getSize(left))\n return new immutable SegTree(t.left.update(i, value), t.right, false);\n return new immutable SegTree(t.left, t.right.update(i - getSize(left), value), false);\n }\n\n auto invert(int lb, int rb) {\n if (!lb && rb == size)\n return invertOne(this);\n int mid = getSize(left);\n auto t = push();\n auto newLeft = lb >= mid? t.left : t.left.invert(lb, min(mid, rb));\n auto newRight = rb <= mid? t.right : t.right.invert(max(lb - mid, 0), rb - mid);\n return new immutable SegTree(newLeft, newRight, false);\n }\n}\n\nauto construct(int n) {\n assert(n >= 1);\n if (n == 1)\n return new immutable SegTree(false);\n return new immutable SegTree(construct(n >> 1), construct(n - (n >> 1)), false);\n}\n\nvoid main() {\n int n, m, q;\n while (scanf(\"%d%d%d\", &n, &m, &q) == 3) {\n auto roots = [construct(n * m)];\n roots.reserve(q + 1);\n while (q--) {\n char c;\n int a, b;\n scanf(\" %c%d\", &c, &a);\n final switch (c) {\n case '1': case '2': {\n scanf(\"%d\", &b);\n roots ~= roots.back.update((a - 1) * m + b - 1, c == '1');\n break;\n }\n case '3': {\n roots ~= roots.back.invert((a - 1) * m, a * m);\n break;\n }\n case '4': {\n roots ~= roots[a];\n break;\n }\n }\n printf(\"%d\\n\", SegTree.getCount(roots.back));\n }\n debug putchar('\\n');\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nfinal class SegTree {\n int size;\n int sum;\n bool inv;\n SegTree left, right;\n\n invariant {\n assert(size > 0);\n assert(sum >= 0);\n assert(sum <= size);\n assert((left is null) == (right is null));\n }\n\n this(int size, int sum, bool inv) {\n this(size, sum, inv, null, null);\n }\n\n this(int size, int sum, bool inv, SegTree left, SegTree right) {\n this.size = size;\n this.sum = sum;\n this.inv = inv;\n this.left = left;\n this.right = right;\n }\n\n static SegTree build(int n) {\n assert(n > 0);\n if (n == 1)\n return new SegTree(1, 0, false);\n return new SegTree(n, 0, false, build(n >>> 1), build(n - (n >>> 1)));\n }\n\n static int getSum(const SegTree sgt) {\n return sgt is null ? 0 : sgt.inv ? sgt.size - sgt.sum : sgt.sum;\n }\n\n private void _push() {\n if (inv) {\n if (left !is null) {\n left.inv ^= true;\n right.inv ^= true;\n }\n sum = size - sum;\n inv = false;\n }\n }\n\n SegTree set(int i, bool value) {\n if (left is null)\n return new SegTree(1, value, false);\n _push();\n if (i < left.size) {\n auto newLeft = left.set(i, value);\n return new SegTree(size, getSum(newLeft) + getSum(right), false, newLeft, right);\n } else {\n auto newRight = right.set(i - left.size, value);\n return new SegTree(size, getSum(left) + getSum(newRight), false, left, newRight);\n }\n }\n\n SegTree invert(int lb, int rb) {\n if (lb >= rb)\n return this;\n _push();\n if (!lb && rb == size)\n return new SegTree(size, sum, !inv, left, right);\n assert(left !is null);\n auto newLeft = left.invert(lb, min(left.size, rb));\n auto newRight = right.invert(max(lb - left.size, 0), rb - left.size);\n return new SegTree(size, getSum(newLeft) + getSum(newRight), false, newLeft, newRight);\n }\n}\n\nvoid main() {\n int n, m, q;\n while (read(&n, &m, &q)) {\n Array!SegTree roots;\n roots.length = q + 1;\n roots[0] = SegTree.build(n * m);\n foreach (cur; 0 .. q) {\n char cmd;\n int i, j;\n read(&cmd);\n switch (cmd) {\n case '1': {\n read(&i, &j);\n i--;\n j--;\n roots[cur + 1] = roots[cur].set(i * m + j, true);\n break;\n }\n case '2': {\n read(&i, &j);\n i--;\n j--;\n roots[cur + 1] = roots[cur].set(i * m + j, false);\n break;\n }\n case '3': {\n read(&i);\n roots[cur + 1] = roots[cur].invert((i - 1) * m, i * m);\n break;\n }\n case '4': {\n read(&i);\n roots[cur + 1] = roots[i];\n break;\n }\n default: assert(false);\n }\n writeln(SegTree.getSum(roots[cur + 1]));\n }\n debug writeln();\n }\n}\n"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nfinal class SegTree {\n SegTree left, right;\n int size;\n int sum;\n bool inv;\n\n this(int size, int sum, bool inv) {\n this(size, sum, inv, null, null);\n }\n\n this(int size, int sum, bool inv, SegTree left, SegTree right) {\n this.size = size;\n this.sum = sum;\n this.inv = inv;\n this.left = left;\n this.right = right;\n }\n\n static SegTree build(int n) {\n assert(n > 0);\n if (n == 1)\n return new SegTree(1, 0, false);\n return new SegTree(n, 0, false, build(n >>> 1), build(n - (n >>> 1)));\n }\n\n static int getSum(const SegTree sgt) {\n return sgt is null ? 0 : sgt.sum;\n }\n\n private void _push() {\n if (inv) {\n if (left) {\n left.sum = left.size - left.sum;\n left.inv ^= true;\n }\n if (right) {\n right.sum = right.size - right.sum;\n right.inv ^= true;\n }\n inv = false;\n }\n }\n\n SegTree add(int i) {\n if (left is null)\n return new SegTree(1, 1, false);\n _push();\n if (i < left.size) {\n auto newLeft = left.add(i);\n return new SegTree(size, newLeft.sum + right.sum, false, newLeft, right);\n } else {\n auto newRight = right.add(i - left.size);\n return new SegTree(size, left.sum + newRight.sum, false, left, newRight);\n }\n }\n\n SegTree remove(int i) {\n if (left is null) {\n assert(right is null);\n return new SegTree(1, 0, false);\n }\n _push();\n if (i < left.size) {\n auto newLeft = left.remove(i);\n return new SegTree(size, newLeft.sum + right.sum, false, newLeft, right);\n } else {\n auto newRight = right.remove(i - left.size);\n return new SegTree(size, left.sum + newRight.sum, false, left, newRight);\n }\n }\n\n SegTree invert(int lb, int rb) {\n if (lb >= rb)\n return this;\n _push();\n if (!lb && rb == size)\n return new SegTree(size, size - sum, !inv, left, right);\n if (left is null)\n writeln(lb, ' ', rb);\n assert(left !is null);\n assert(right !is null);\n auto newLeft = left.invert(lb, min(left.size, rb));\n auto newRight = right.invert(max(lb - left.size, 0), rb - left.size);\n return new SegTree(size, newLeft.sum + newRight.sum, false, newLeft, newRight);\n }\n}\n\nvoid main() {\n int n, m, q;\n while (read(&n, &m, &q)) {\n Array!SegTree roots;\n roots.length = q + 1;\n roots[0] = SegTree.build(n * m);\n foreach (cur; 0 .. q) {\n char cmd;\n int i, j;\n read(&cmd);\n switch (cmd) {\n case '1': {\n read(&i, &j);\n i--;\n j--;\n roots[cur + 1] = roots[cur].add(i * m + j);\n break;\n }\n case '2': {\n read(&i, &j);\n i--;\n j--;\n roots[cur + 1] = roots[cur].remove(i * m + j);\n break;\n }\n case '3': {\n read(&i);\n roots[cur + 1] = roots[cur].invert((i - 1) * m, i * m);\n break;\n }\n case '4': {\n read(&i);\n roots[cur + 1] = roots[i];\n break;\n }\n default: assert(false);\n }\n writeln(roots[cur + 1].sum);\n }\n debug writeln();\n }\n}\n"}], "src_uid": "2b78f6626fce6b5b4f9628fb15666dc4"} {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.functional;\nimport std.conv;\nimport std.string;\n\nint main() {\n\n auto tmp = split(strip(readln()), \" \");\n auto n = to!int(tmp[0]);\n auto m = to!int(tmp[1]);\n auto x = to!int(tmp[2]);\n auto y = to!int(tmp[3]);\n auto table = new string[n];\n for (int i = 0; i < n; ++i)\n table[i] = strip(readln());\n\n int cntImpl(int color, int j) {\n int ans = 0;\n for (int i = 0; i < n; ++i)\n ans += table[i][j] == '.' ? color : 1 - color;\n return ans;\n }\n\n alias memoize!cntImpl cnt;\n\n int sum(int color, int end) {\n alias memoize!sum msum;\n if (end == 0)\n return cnt(color, end);\n else\n return cnt(color, end) + msum(color, end - 1);\n }\n\n int sum_of_color(int color, int start, int end) {\n if (start < 0) return 1000000000;\n return sum(color, end) - sum(color, start) + cnt(color, start);\n }\n\n int dp(int color, int num) {\n alias memoize!dp dpImpl; \n int ans = 1000000000;\n if (num < 0)\n return 0;\n for (int i = x; i <= y; ++i)\n ans = min(ans, dpImpl(1 - color, num - i) + sum_of_color(color, num - i + 1, num)); \n return ans;\n }\n writeln(min(dp(0, m - 1), dp(1, m - 1)));\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\n\nconst int max_n = 1024;\nconst int inf = cast(int)(1e9);\n\nint[max_n][max_n][2] dp;\n\nvoid main() {\n int n, m, x, y;\n readf(\"%d %d %d %d\", &n, &m, &x, &y);\n int[] black = new int[m];\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < m; ++j) {\n char c;\n readf(\" %c\", &c);\n black[j] += (c == '#');\n }\n }\n \n foreach (ref a; dp) {\n foreach (ref b; a) {\n b[] = inf;\n }\n }\n \n int get(int i, int c) {\n return (c == 0) ? black[i] : n - black[i];\n }\n \n for (int c = 0; c <= 1; ++c) {\n dp[c][0][1] = get(0, c);\n }\n \n for (int i = 1; i < m; ++i) {\n for (int c = 0; c <= 1; ++c) {\n dp[c][i][1] = get(i, c) + minPos(dp[c ^ 1][i - 1][x .. min($, y + 1)])[0];\n for (int j = 2; j <= i + 1; ++j) {\n dp[c][i][j] = get(i, c) + dp[c][i - 1][j - 1];\n }\n }\n }\n \n int res = inf;\n for (int c = 0; c <= 1; ++c) {\n res = min(res, minPos(dp[c][m - 1][x .. min($, y + 1)])[0]);\n }\n \n writeln(res);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\n\nconst int max_n = 10;\nconst int inf = cast(int)(1e9);\n\nint[max_n][max_n][2] dp;\n\nvoid main() {\n int n, m, x, y;\n readf(\"%d %d %d %d\", &n, &m, &x, &y);\n int[] black = new int[m];\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < m; ++j) {\n char c;\n readf(\" %c\", &c);\n black[j] += (c == '#');\n }\n }\n \n foreach (ref a; dp) {\n foreach (ref b; a) {\n b[] = inf;\n }\n }\n \n int get(int c) {\n return (c == 0) ? black[c] : n - black[c];\n }\n \n for (int c = 0; c <= 1; ++c) {\n dp[c][0][1] = get(c);\n }\n \n for (int i = 1; i < m; ++i) {\n for (int c = 0; c <= 1; ++c) {\n dp[c][i][1] = get(c) + minPos(dp[c ^ 1][i - 1][x .. y + 1])[0];\n for (int j = 2; j <= i + 1; ++j) {\n dp[c][i][j] = get(c) + dp[c][i - 1][j - 1];\n }\n }\n }\n \n int res = inf;\n for (int c = 0; c <= 1; ++c) {\n for (int j = x; j <= y; ++j) {\n res = min(res, dp[c][m - 1][j]);\n }\n }\n \n writeln(res);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.functional;\nimport std.conv;\nimport std.string;\n\nint main() {\n\n auto tmp = split(strip(readln()), \" \");\n auto n = to!int(tmp[0]);\n auto m = to!int(tmp[1]);\n auto x = to!int(tmp[2]);\n auto y = to!int(tmp[3]);\n string[] table = [];\n for (int i = 0; i < n; ++i)\n table ~= strip(readln());\n\n int cntImpl(int color, int j) {\n int ans = 0;\n for (int i = 0; i < n; ++i)\n ans += table[i][j] == '.' ? color : 1 - color;\n return ans;\n }\n\n alias memoize!cntImpl cnt;\n\n int sum(int color, int end) {\n alias memoize!sum msum;\n if (end < 0)\n return 1000000000;\n else if (end == 0)\n return cnt(color, end);\n else\n return cnt(color, end) + msum(color, end - 1);\n }\n\n int sum_of_color(int color, int start, int end) {\n return sum(color, end) - sum(color, start) + cnt(color, start);\n }\n\n int dp(int color, int num) {\n alias memoize!dp dpImpl; \n int ans = 1000000000;\n if (num == 0)\n return sum_of_color(color, 0, 0);\n for (int i = x; i <= y; ++i)\n if (num - i >= 0)\n \tans = min(ans, dpImpl(1 - color, num - i) + sum_of_color(color, num - i + 1, num)); \n return ans;\n }\n writeln(min(dp(0, m - 1), dp(1, m - 1)));\n return 0;\n}"}], "src_uid": "08d13e3c71040684d5a056bd1b53ef3b"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree set;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\n\tif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\tif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (!(a[l]<g))?l:r;\n}\npure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g<a[m])r=m;\n\t\telse l=m;\n\t}\n\treturn (g<a[l])?l:r;\n}\npure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\tsize_t l=0,r=a.length;\n\twhile(r-l>1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]<g))r=m;\n\t\telse l=m;\n\t}\n\treturn (g==a[l])?l:a.length;\n}\npure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n{\n\treturn binf(a,g)!=a.length;\n}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\twhile(input(&n))\n\t{\n\t\treadln;\n\t\tauto s=readln.strip;\n\t\tstring ans;\n\t\tforeach(i;0..s.length)\n\t\t{\n\t\t\tif(n&1)\n\t\t\t{\n\t\t\t\tif((i&1)==0)ans~=s[i];\n\t\t\t\telse ans=s[i]~ans;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif((i&1)==0)ans=s[i]~ans;\n\t\t\t\telse ans~=s[i];\n\t\t\t}\n\t\t}\n\t\twriteln(ans);\n\t}\n}\n", "positive_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\n\nvoid main(){\n int n=readln.chomp.to!int;\n auto s=readln.strip;\n char[] a;\n foreach(i;0..s.length){\n if(n&1) a~=s[i];\n else a=s[i]~a;\n n--;\n }\n writeln(a);\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\n\nvoid main(){\n int n=readln.chomp.to!int;\n auto s=readln.strip;\n char[] a;\n foreach(ref c;s){\n if(n&1) a~=c;\n else a=c~a;\n n--;\n }\n writeln(a);\n}\n\n"}], "negative_code": [], "src_uid": "2a414730d1bc7eef50bdb631ea966366"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main (){\n\tint n;\n\twhile (readf (\" %s\", &n) > 0){\n\t\treadln;\n\t\tint w = 0;\n\t\tint b = 0;\n\t\tforeach (i; 0..n){\n\t\t\tauto t = readln.splitter.drop (1).front == \"hard\";\n\t\t\tif (t) b ++;\n\t\t\telse w ++;\n\t\t}\n\t\tint res = 0;\n\t\twhile (true){\n\t\t\tint s = res ^^ 2;\n\t\t\tint sb = s / 2;\n\t\t\tint sw = s - sb;\n\t\t\tif (b <= sb && w <= sw) break;\n\t\t\tif (b <= sw && w <= sb) break;\n\t\t\tres ++;\n\t\t}\n\t\twriteln(res);\n\t}\n}", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tint w = 0;\n\t\tint b = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto t = readln.splitter.drop (1).front == \"hard\";\n\t\t\tif (t)\n\t\t\t{\n\t\t\t\tb += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tw += 1;\n\t\t\t}\n\t\t}\n\t\tint res = 0;\n\t\twhile (true)\n\t\t{\n\t\t\tint s = res ^^ 2;\n\t\t\tint sb = s / 2;\n\t\t\tint sw = s - sb;\n\t\t\tif (b <= sb && w <= sw)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (b <= sw && w <= sb)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tres += 1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tint w = 0;\n\t\tint b = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto t = readln.splitter.drop (1).front == \"hard\";\n\t\t\tif (t)\n\t\t\t{\n\t\t\t\tb += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tw += 1;\n\t\t\t}\n\t\t}\n\t\tint res = 0;\n\t\twhile (true)\n\t\t{\n\t\t\tint s = res ^^ 2;\n\t\t\tint sb = s / 2;\n\t\t\tint sw = s - sb;\n\t\t\tif (b <= sb && w <= sw)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tres += 1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "bea06c48418316042c19e6fd43fe20b5"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto k = RD;\n\t\tif (n < k^^2)\n\t\t\tans[ti] = false;\n\t\telse\n\t\t\tans[ti] = n % 2 == k % 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. scan!int){\n long n = scan!long, k = scan!long;\n if(n % 2 != k % 2) \"NO\".writeln;\n else if(n < k * k) \"NO\".writeln;\n else \"YES\".writeln;\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tif (n < k^^2)\n\t\t\tans[ti] = false;\n\t\telse\n\t\t\tans[ti] = n % 2 == k % 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tans[ti] = n % 2 == k % 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tif (k > n)\n\t\t\tans[ti] = false;\n\t\telse\n\t\t\tans[ti] = n % 2 == k % 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "a4c82fffb31bc7e42870fd84e043e815"} {"source_code": "import std.stdio: writeln, readln;\nimport std.conv: to;\nimport std.array: split, array;\nimport std.algorithm: map, filter, any;\nimport std.string: chomp;\n\nvoid main() {\n\tint t = readln.chomp.to!int;\n\tforeach (int _; 0..t) {\n\t\tint k = readln.chomp.split(\" \").map!(to!int).array[1];\n\t\tlong[] a = readln.chomp.split(\" \").map!(to!long).array;\n\n\t\tstring ans = \"YES\";\n\t\twhile (a.any!((long x) => x != 0)) {\n\t\t\tlong[] b = a.map!((long x) => x%k).filter!((long x) => x != 0).array;\n\t\t\tif (b > [1L]) {\n\t\t\t\tans = \"NO\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ta = a.map!((long x) => x/k).array;\n\t\t}\n\t\tans.writeln;\n\t}\n}\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nbool test (in ulong[] a, uint k) {\n debug stderr.writeln (a);\n bool[int] m;\n foreach (x; a) {\n ulong y = x;\n int o;\n debug stderr.writeln (\"x = \", x);\n while (y > 0) {\n uint t = (y % k).to!uint;\n debug stderr.writeln (y, ' ', t);\n if (t > 1) return false;\n if (t == 1) {\n if (o in m) return false;\n m[o] = true;\n }\n y /= k;\n ++o;\n }\n }\n return true;\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n const n = r.next!uint;\n const k = r.next!uint;\n auto a = r.nextA!ulong (n);\n writeln (test (a, k) ? \"YES\" : \"NO\");\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD;\n\t\tauto a = RDA;\n\t\tauto cnt = new int[](60);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint j;\n\t\t\twhile (a[i] != 0)\n\t\t\t{\n\t\t\t\tcnt[j] += a[i] % k;\n\t\t\t\ta[i] /= k;\n\t\t\t\t++j;\n\t\t\t}\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (e; cnt)\n\t\t{\n\t\t\tif (e > 1)\n\t\t\t\tok = false;\n\t\t}\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "b132bf94af4352c4a690316eb610ebe1"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.functional, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool solve(int n, Tuple!(int, int, int)[] edges, int mask, ref int ans)\n{\n auto uf = Dsu(n);\n foreach (e ; edges) {\n if (!uf.same(e[0], e[1]) && !(e[2] & mask)) {\n uf.merge(e[0], e[1]);\n ans |= e[2];\n }\n }\n return uf.size(0) == n;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n, m;\n readf!\" %d %d \"(n, m);\n Tuple!(int, int, int)[] edges;\n foreach (i ; 0 .. m) {\n int u, v, w;\n readf!\" %d %d %d \"(v, u, w);\n v--;\n u--;\n edges ~= tuple(v, u, w);\n }\n edges.sort!((x, y) => x[2] < y[2]);\n int mask = 0;\n int best_ans = int.max;\n foreach_reverse(maskbit ; 0 .. 31) {\n int ans = 0;\n if (solve(n, edges, mask | (1 << maskbit), ans)) {\n best_ans = min(best_ans, ans);\n mask |= (1 << maskbit);\n }\n }\n\n writeln(best_ans);\n }\n}\n\n// Code from: https://github.com/kotet/atcoder-library-d\n\nstruct Dsu\n{\npublic:\n this(long n) @safe nothrow\n {\n _n = cast(int) n, parent_or_size = new int[](cast(int)n);\n parent_or_size[] = -1;\n }\n\n int merge(long a, long b) @safe nothrow @nogc\n {\n assert(0 <= a && a < _n);\n assert(0 <= b && b < _n);\n int x = leader(a), y = leader(b);\n if (x == y)\n return x;\n if (-parent_or_size[x] < -parent_or_size[y])\n {\n auto tmp = x;\n x = y;\n y = tmp;\n }\n parent_or_size[x] += parent_or_size[y];\n parent_or_size[y] = x;\n return x;\n }\n\n bool same(long a, long b) @safe nothrow @nogc\n {\n assert(0 <= a && a < _n);\n assert(0 <= b && b < _n);\n return leader(a) == leader(b);\n }\n\n int leader(long a) @safe nothrow @nogc\n {\n assert(0 <= a && a < _n);\n if (parent_or_size[cast(int)a] < 0)\n return cast(int) a;\n return parent_or_size[cast(int)a] = leader(parent_or_size[cast(int)a]);\n }\n\n int size(long a) @safe nothrow @nogc\n {\n assert(0 <= a && a < _n);\n return -parent_or_size[leader(a)];\n }\n\n int[][] groups() @safe nothrow\n {\n auto leader_buf = new int[](_n), group_size = new int[](_n);\n foreach (i; 0 .. _n)\n {\n leader_buf[i] = leader(i);\n group_size[leader_buf[i]]++;\n }\n auto result = new int[][](_n);\n foreach (i; 0 .. _n)\n result[i].reserve(group_size[i]);\n foreach (i; 0 .. _n)\n result[leader_buf[i]] ~= i;\n int[][] filtered;\n foreach (r; result)\n if (r.length != 0)\n filtered ~= r;\n return filtered;\n }\n\nprivate:\n int _n;\n int[] parent_or_size;\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n auto T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias Edge = Tuple!(int, \"to\", long, \"cost\");\r\n\r\nvoid solve() {\r\n readln;\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto G = new Edge[][N];\r\n foreach (i; 0 .. M) {\r\n int u, v; long w; readf(\"%d %d %d\\n\", &u, &v, &w);\r\n u--; v--;\r\n G[u] ~= Edge(v, w);\r\n G[v] ~= Edge(u, w);\r\n }\r\n\r\n long ans = 0;\r\n for (int k = 31; k >= 0; k--) {\r\n long mask = ans | ((1L<<k) - 1);\r\n //writefln(\"k = %s, mask = %s\", k, mask);\r\n bool C() {\r\n auto uf = UnionFind(N);\r\n foreach (u; 0 .. N) {\r\n foreach (e; G[u]) {\r\n if ((e.cost & mask) == e.cost) {\r\n uf.merge(u, e.to);\r\n }\r\n }\r\n }\r\n return uf.ngroups == 1;\r\n }\r\n if (C()) {\r\n // k-th bit can be zero.\r\n } else {\r\n // k-th bit cannot be zero.\r\n ans |= (1L<<k);\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nstruct UnionFind {\r\n int N;\r\n int[] parent;\r\n int[] size;\r\n int ngroups;\r\n this(int N) {\r\n this.N = N;\r\n this.parent = new int[N];\r\n this.parent[] = -1;\r\n this.size = new int[N];\r\n this.size[] = 1;\r\n this.ngroups = N;\r\n }\r\n int root(int x) {\r\n if (parent[x] < 0) return x;\r\n return parent[x] = root(parent[x]);\r\n }\r\n void merge(int x, int y) {\r\n x = root(x);\r\n y = root(y);\r\n if (x == y) return;\r\n if (size[x] < size[y]) {\r\n parent[x] = y;\r\n size[x] += size[y];\r\n } else {\r\n parent[y] = x;\r\n size[y] += size[x];\r\n }\r\n ngroups--;\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n auto T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias Edge = Tuple!(int, \"to\", long, \"cost\");\r\n\r\nvoid solve() {\r\n readln;\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto G = new Edge[][N];\r\n foreach (i; 0 .. M) {\r\n int u, v; long w; readf(\"%d %d %d\\n\", &u, &v, &w);\r\n u--; v--;\r\n G[u] ~= Edge(v, w);\r\n G[v] ~= Edge(u, w);\r\n }\r\n\r\n long ans = 0;\r\n for (int k = 31; k >= 0; k--) {\r\n auto sG = new Edge[][N];\r\n long mask = ans | ((1L<<k) - 1);\r\n //writefln(\"k = %s, mask = %s\", k, mask);\r\n bool C() {\r\n auto uf = UnionFind(N);\r\n foreach (u; 0 .. N) {\r\n foreach (e; G[u]) {\r\n if ((e.cost & mask) == e.cost) {\r\n uf.merge(u, e.to);\r\n }\r\n }\r\n }\r\n return uf.ngroups == 1;\r\n }\r\n if (C()) {\r\n // k-th bit can be zero.\r\n } else {\r\n // k-th bit cannot be zero.\r\n ans |= (1L<<k);\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nstruct UnionFind {\r\n int N;\r\n int[] parent;\r\n int[] size;\r\n int ngroups;\r\n this(int N) {\r\n this.N = N;\r\n this.parent = new int[N];\r\n this.parent[] = -1;\r\n this.size = new int[N];\r\n this.size[] = 1;\r\n this.ngroups = N;\r\n }\r\n int root(int x) {\r\n if (parent[x] < 0) return x;\r\n return parent[x] = root(parent[x]);\r\n }\r\n void merge(int x, int y) {\r\n x = root(x);\r\n y = root(y);\r\n if (x == y) return;\r\n if (size[x] < size[y]) {\r\n parent[x] = y;\r\n size[x] += size[y];\r\n } else {\r\n parent[y] = x;\r\n size[y] += size[x];\r\n }\r\n ngroups--;\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "9a2e734bd78ef1e50140f2bb4f57d611"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n int ans = 0;\n\n for (int i = 1, p = 0; i <= N && p < N; ++i, ++p) {\n while (p < N && A[p] < i) ++p;\n if (p >= N) break;\n ans += 1;\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\t\n\tint[] as;\n\tforeach(i; 0 .. n) as ~= read.to!int;\n\t\n\tas.sort!();\n\t\n\tint ans = 0;\n\tfor(int i = 0, j = 0; i < n && j < n; ){\n\t\tif(as[j] < i + 1){\n\t\t\tj += 1;\n\t\t}\n\t\telse{\n\t\t\tans += 1;\n\t\t\ti += 1, j += 1;\n\t\t}\n\t}\n\tans.writeln;\n\t\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n uint n;\n readf(\" %s\", n);\n auto a = new long[n];\n iota(0, n).each!(i => readf(\" %s\", a[i]));\n\n sort(a);\n uint s = 0;\n long k = 1;\n long d = 0;\n // writeln(a);\n while(s < n) {\n while(s < n && a[s] < k) s++;\n if (s >= n) break;\n // writeln(k, \" \" , s, \" \", a[s]);\n if (k <= a[s]) { d++; } \n k += 1;\n s++;\n }\n\n writeln(d);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto N = RD!int;\n\tauto a = RDR.ARR;\n\ta.sort();\n\n\tlong ans;\n\tforeach (i; 0..N)\n\t{\n\t\tif (a[i] > ans)\n\t\t\t++ans;\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n uint n;\n readf(\" %s\", n);\n auto a = new long[n];\n iota(0, n).each!(i => readf(\" %s\", a[i]));\n\n sort(a);\n uint s = 0;\n long k = 1;\n long d = 0;\n // writeln(a);\n while(s < n) {\n while(s < n && a[s] < k) s++;\n if (s >= n) break;\n // writeln(k, \" \" , s, \" \", a[s]);\n if (k <= a[s]) { d++; } \n k *= 2;\n s++;\n }\n\n writeln(d);\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n uint n;\n readf(\" %s\", n);\n auto a = new int[n];\n iota(0, n).each!(i => readf(\" %s\", a[i]));\n\n sort(a);\n uint s = 0;\n uint k = 1;\n uint d = 1;\n while(true) {\n while(s < n && a[s] < k) s++;\n if (s >= n) {writeln(d); return;}\n // writeln(s, \" \" , a[s], \" \", k);\n d ++;\n k *= 2;\n s++;\n if (s >= n) {writeln(d-1); return ; }\n }\n\n\n assert(false);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto N = RD!int;\n\tauto a = RDR.ARR;\n\ta.sort();\n\n\tdebug writeln(a.uniq);\n\twriteln(a.uniq.array.length);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "4f02ac641ab112b9d6aee222e1365c09"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nint g (int x) {return (x < 2) ? x : (x < 5) ? (x - 2) : (x & 1) ? 0 : (1 + (g (x / 2) == 1));}\nint h (int x) {return (x < 3) ? x : !(x & 1);}\nvoid main () {\n\tint n, k;\n\treadf (\" %s %s\", &n, &k);\n\tk %= 2;\n\treadln;\n\twriteln (readln.split.map !(to !(int)).map !(x => k ? g (x) : h (x)).reduce !(q{a ^ b}) ? \"Kevin\" : \"Nicky\");\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\npure int g (int x)\n{\n\tif (x < 5)\n\t{\n\t\treturn [0, 1, 0, 1, 2][x];\n\t}\n\tif (x % 2 != 0)\n\t{\n\t\treturn 0;\n\t}\n\tint v = g (x / 2);\n\treturn 1 + (v == 1);\n}\n\npure int h (int x)\n{\n\tif (x < 3)\n\t{\n\t\treturn [0, 1, 2][x];\n\t}\n\tif (x % 2 != 0)\n\t{\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tk %= 2;\n\t\tint res;\n\t\tif (k)\n\t\t{\n\t\t\tres = a.map !(x => g (x)).reduce !(q{a ^ b});\n\t\t}\n\t\telse\n\t\t{\n\t\t\tres = a.map !(x => h (x)).reduce !(q{a ^ b});\n\t\t}\n\t\tdebug {writeln (n, ' ', k, ' ', a[0], ' ', res);}\n\t\twriteln (res ? \"Kevin\" : \"Nicky\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\npure int g (int x)\n{\n\tif (x < 5)\n\t{\n\t\treturn [0, 1, 0, 1, 2][x];\n\t}\n\tif (x % 2 != 0)\n\t{\n\t\treturn 0;\n\t}\n\treturn 3 ^ g (x / 2);\n}\n\npure int h (int x)\n{\n\tif (x < 3)\n\t{\n\t\treturn [0, 1, 2][x];\n\t}\n\tif (x % 2 != 0)\n\t{\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tk %= 2;\n\t\tint res;\n\t\tif (k)\n\t\t{\n\t\t\tres = a.map !(x => g (x)).reduce !(q{a ^ b});\n\t\t}\n\t\telse\n\t\t{\n\t\t\tres = a.map !(x => h (x)).reduce !(q{a ^ b});\n\t\t}\n\t\twriteln (res ? \"Kevin\" : \"Nicky\");\n\t}\n}\n"}], "src_uid": "5ae6585bf96e0bff343bb76c1af3ebc2"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto c = new long [] [n];\r\n\t\tauto w = new long [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tc[i] = readln.splitter.map !(to !(long)).array;\r\n\t\t\tforeach (j; 0..m)\r\n\t\t\t{\r\n\t\t\t\tw[i] += c[i][j] * j;\r\n\t\t\t}\r\n\t\t}\r\n\t\tauto p = w.length - w.maxPos.length;\r\n\t\twriteln (p + 1, \" \", w[p] - w[!p]);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const numCases = readInt;\r\n foreach (caseId; 0 .. numCases) {\r\n const N = readInt;\r\n const M = readInt;\r\n auto C = new long[][](N, M);\r\n foreach (i; 0 .. N) {\r\n foreach (j; 0 .. M) {\r\n C[i][j] = readLong;\r\n }\r\n }\r\n \r\n auto fs = new long[N];\r\n foreach (i; 0 .. N) {\r\n foreach (j; 0 .. M) {\r\n fs[i] += j * C[i][j];\r\n }\r\n }\r\n debug {\r\n writeln(\"fs = \", fs);\r\n }\r\n const minF = fs.minElement;\r\n const maxF = fs.maxElement;\r\n \r\n int im = -1;\r\n foreach (i; 0 .. N) {\r\n if (maxF == fs[i]) {\r\n im = i;\r\n break;\r\n }\r\n }\r\n writeln(im + 1, \" \", maxF - minF);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto c = new int [] [n];\r\n\t\tauto w = new long [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tc[i] = readln.splitter.map !(to !(int)).array;\r\n\t\t\tforeach (j; 0..m)\r\n\t\t\t{\r\n\t\t\t\tw[i] += c[i][j] * j;\r\n\t\t\t}\r\n\t\t}\r\n\t\tauto p = w.length - w.maxPos.length;\r\n\t\twriteln (p + 1, \" \", w[p] - w[!p]);\r\n\t}\r\n}\r\n"}], "src_uid": "abcafb310d4dcf3f7e34fc4eda1ee324"} {"source_code": "import std.stdio;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.functional;\nimport std.conv;\nimport std.string;\nimport std.math;\nimport core.bitop;\n\nulong[] arr;\nulong[] clone;\n\nbool check(ulong k) { // O(3n + n log n)\n\tforeach (i, v; arr) { // O(n)\n\t\tclone[i] = v;\n\t}\n\tforeach (ref v; clone) { // O(n)\n\t\tv ^= k;\n\t}\n\tclone.sort(); // O(n log n)\n\treturn clone == arr; // O(n)\n}\n\nvoid main() {\n\tint tt = readln().chomp.to!int;\n\touter: foreach (t; 0 .. tt) {\n\t\tsize_t n = readln().chomp.to!size_t;\n\t\tarr = readln().chomp.split(\" \").map!(to!ulong).array;\n\t\tarr.sort();\n\t\tclone.length = arr.length;\n\t\t// 1026 * (3 * 1024 + 1024 log 1024)\n\t\tforeach (k; 1 .. 1026) {\n\t\t\tif (check(k)) {\n\t\t\t\twriteln(k);\n\t\t\t\tcontinue outer;\n\t\t\t}\n\t\t}\n\t\twriteln(-1);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main () {\n\tforeach (t; 0..readln.strip.to!int) {\n\t\tint n = readln.strip.to!int, v;\n\t\tauto a = readln.splitter.map !(to!int).array;\n\t\ta.sort;\n\t\tfor (v = 1; v < 1024; v++) {\n\t\t\tauto b = a.dup;\n\t\t\tb[] ^= v;\n\t\t\tb.sort;\n\t\t\tif (a == b) break;\n\t\t}\n\t\tif (v == 1024) v = -1;\n\t\tv.writeln;\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RDA!int;\n\n\t\tans[ti] = -1;\n\t\tforeach (i; 1..2^^10)\n\t\t{\n\t\t\tauto cnt = new int[](2^^10);\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\t++cnt[s[j]];\n\t\t\t}\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tauto num = s[j] ^ i;\n\t\t\t\t--cnt[num];\n\t\t\t}\n\t\t\tbool ok = true;\n\t\t\tforeach (j; 0..2^^10)\n\t\t\t{\n\t\t\t\tif (cnt[j] != 0)\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t{\n\t\t\t\tans[ti] = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "3ecb65a8be42f882ae6b528fd86243cd"} {"source_code": "module main;\n\nimport std.stdio, std.string, std.conv;\n\nclass XD\n{\n public:\n this(int n)\n {\n len = n << 3;\n h = new int[][len];\n f = new bool[len];\n v = new long[len];\n }\n int getPosition(long n)\n {\n auto s = to!string(n);\n int pos = calc(s);\n while (f[pos] == true && v[pos] != n)\n {\n ++ pos;\n if (pos == len)\n {\n pos = 0;\n }\n }\n return pos;\n }\n void insert(long n, int idx)\n {\n auto pos = getPosition(n);\n //writefln(\"%d %d\", pos, n);\n v[pos] = n;\n f[pos] = true;\n h[pos] ~= idx;\n }\n int[] find(long n)\n {\n auto pos = getPosition(n);\n return h[pos];\n }\n int calc(string s)\n {\n long hash = 0;\n foreach (i, val; s)\n {\n hash = (hash << 4) ^ (hash >> 28) ^ val;\n }\n return (hash % len);\n }\n protected:\n int len;\n long[] v;\n bool[] f;\n int[][] h;\n};\n\nint search(int[] a, int bound)\n{\n int left = 0, right = a.length - 1, mid, res = 0;\n while (left <= right)\n {\n mid = (left + right) >> 1;\n if (a[mid] >= bound)\n {\n right = mid - 1;\n }\n else\n {\n res = mid + 1;\n left = mid + 1;\n }\n }\n //writefln(\"%d %d\", bound, res);\n return res;\n}\n\nvoid solve(int[] a)\n{\n XD xd = new XD(a.length);\n auto s = new long[a.length];\n s[0] = a[0];\n xd.insert(s[0], 0);\n foreach (i; 1 .. a.length)\n {\n s[i] = a[i] + s[i - 1];\n xd.insert(s[i], i);\n }\n long ans = 0;\n foreach (i; 2 .. a.length)\n {\n long sum = s[a.length - 1] - s[i - 1];\n if ((s[i - 1] & 1) == 0 && s[i - 1] / 2 == sum)\n {\n auto arr = xd.find(sum);\n //foreach (j, val; arr) writef(\"%d \", val);\n //writeln();\n ans += search(arr, i - 1);\n }\n }\n writefln(\"%d\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i, ref v; a)\n {\n scanf(\"%d\", &v);\n }\n solve(a);\n }\n return 0;\n}", "positive_code": [{"source_code": "module main;\n\nimport std.stdio, std.string, std.conv;\n\nclass XD\n{\n public:\n this(int n)\n {\n len = n;\n h = new int[][len];\n f = new bool[len];\n v = new long[len];\n }\n int getPosition(long n)\n {\n auto s = to!string(n);\n int pos = calc(s);\n while (f[pos] == true && v[pos] != n)\n {\n ++ pos;\n if (pos == len)\n {\n pos = 0;\n }\n }\n return pos;\n }\n void insert(long n, int idx)\n {\n auto pos = getPosition(n);\n //writefln(\"%d %d\", pos, n);\n v[pos] = n;\n f[pos] = true;\n h[pos] ~= idx;\n }\n int[] find(long n)\n {\n auto pos = getPosition(n);\n return h[pos];\n }\n int calc(string s)\n {\n long hash = 0;\n foreach (i, val; s)\n {\n hash = (hash << 4) ^ (hash >> 28) ^ val;\n }\n return (hash % len);\n }\n protected:\n int len;\n long[] v;\n bool[] f;\n int[][] h;\n};\n\nint search(int[] a, int bound)\n{\n int left = 0, right = a.length - 1, mid, res = 0;\n while (left <= right)\n {\n mid = (left + right) >> 1;\n if (a[mid] >= bound)\n {\n right = mid - 1;\n }\n else\n {\n res = mid + 1;\n left = mid + 1;\n }\n }\n //writefln(\"%d %d\", bound, res);\n return res;\n}\n\nvoid solve(int[] a)\n{\n XD xd = new XD(a.length);\n auto s = new long[a.length];\n s[0] = a[0];\n xd.insert(s[0], 0);\n foreach (i; 1 .. a.length)\n {\n s[i] = a[i] + s[i - 1];\n xd.insert(s[i], i);\n }\n long ans = 0;\n foreach (i; 2 .. a.length)\n {\n long sum = s[a.length - 1] - s[i - 1];\n if ((s[i - 1] & 1) == 0 && s[i - 1] / 2 == sum)\n {\n auto arr = xd.find(sum);\n //foreach (j, val; arr) writef(\"%d \", val);\n //writeln();\n ans += search(arr, i - 1);\n }\n }\n writefln(\"%d\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i, ref v; a)\n {\n scanf(\"%d\", &v);\n }\n solve(a);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n \n if (A.sum % 3 != 0) {\n writeln(0);\n return;\n }\n\n auto ave = A.sum / 3;\n\n auto acm_f = new long[](N);\n acm_f[0] = A[0];\n auto acm_b = new long[](N);\n acm_b[N-1] = A[N-1];\n \n foreach (i; 0..N-1) {\n acm_f[i+1] = acm_f[i] + A[i+1];\n acm_b[N-i-2] = acm_b[N-i-1] + A[N-i-2];\n }\n\n int[] f;\n int[] b;\n foreach (i; 0..N) {\n if (acm_f[i] == ave) f ~= i;\n if (acm_b[i] == ave) b ~= i;\n }\n\n auto B = b.assumeSorted;\n long ans = 0;\n\n foreach (i; f) {\n ans += B.upperBound(i+1).length;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "module main;\n\nimport std.stdio, std.string, std.conv;\n\nclass XD\n{\n public:\n this(int n)\n {\n len = n << 4;\n h = new int[][len];\n f = new bool[len];\n v = new long[len];\n }\n int getPosition(long n)\n {\n auto s = to!string(n);\n int pos = calc(s);\n while (f[pos] == true && v[pos] != n)\n {\n ++ pos;\n if (pos == len)\n {\n pos = 0;\n }\n }\n return pos;\n }\n void insert(long n, int idx)\n {\n auto pos = getPosition(n);\n //writefln(\"%d %d\", pos, n);\n v[pos] = n;\n f[pos] = true;\n h[pos] ~= idx;\n }\n int[] find(long n)\n {\n auto pos = getPosition(n);\n return h[pos];\n }\n int calc(string s)\n {\n long hash = 0;\n foreach (i, val; s)\n {\n hash = (hash << 4) ^ (hash >> 28) ^ val;\n }\n return (hash % len);\n }\n protected:\n int len;\n long[] v;\n bool[] f;\n int[][] h;\n};\n\nint search(int[] a, int bound)\n{\n int left = 0, right = a.length - 1, mid, res = 0;\n while (left <= right)\n {\n mid = (left + right) >> 1;\n if (a[mid] >= bound)\n {\n right = mid - 1;\n }\n else\n {\n res = mid + 1;\n left = mid + 1;\n }\n }\n //writefln(\"%d %d\", bound, res);\n return res;\n}\n\nvoid solve(int[] a)\n{\n XD xd = new XD(a.length);\n auto s = new long[a.length];\n s[0] = a[0];\n xd.insert(s[0], 0);\n foreach (i; 1 .. a.length)\n {\n s[i] = a[i] + s[i - 1];\n xd.insert(s[i], i);\n }\n long ans = 0;\n foreach (i; 2 .. a.length)\n {\n long sum = s[a.length - 1] - s[i - 1];\n if ((s[i - 1] & 1) == 0 && s[i - 1] / 2 == sum)\n {\n auto arr = xd.find(sum);\n //foreach (j, val; arr) writef(\"%d \", val);\n //writeln();\n ans += search(arr, i - 1);\n }\n }\n writefln(\"%d\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i, ref v; a)\n {\n scanf(\"%d\", &v);\n }\n solve(a);\n }\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.stdio, std.string, std.conv;\n\nclass XD\n{\n public:\n this(int n)\n {\n len = n << 2;\n h = new int[][len];\n f = new bool[len];\n v = new long[len];\n }\n int getPosition(long n)\n {\n auto s = to!string(n);\n int pos = calc(s);\n while (f[pos] == true && v[pos] != n)\n {\n ++ pos;\n if (pos == len)\n {\n pos = 0;\n }\n }\n return pos;\n }\n void insert(long n, int idx)\n {\n auto pos = getPosition(n);\n //writefln(\"%d %d\", pos, n);\n v[pos] = n;\n f[pos] = true;\n h[pos] ~= idx;\n }\n int[] find(long n)\n {\n auto pos = getPosition(n);\n return h[pos];\n }\n int calc(string s)\n {\n long hash = 0;\n foreach (i, val; s)\n {\n hash = (hash << 4) ^ (hash >> 28) ^ val;\n }\n return (hash % len);\n }\n protected:\n int len;\n long[] v;\n bool[] f;\n int[][] h;\n};\n\nint search(int[] a, int bound)\n{\n int left = 0, right = a.length - 1, mid, res = 0;\n while (left <= right)\n {\n mid = (left + right) >> 1;\n if (a[mid] >= bound)\n {\n right = mid - 1;\n }\n else\n {\n res = mid + 1;\n left = mid + 1;\n }\n }\n //writefln(\"%d %d\", bound, res);\n return res;\n}\n\nvoid solve(int[] a)\n{\n XD xd = new XD(a.length);\n auto s = new long[a.length];\n s[0] = a[0];\n xd.insert(s[0], 0);\n foreach (i; 1 .. a.length)\n {\n s[i] = a[i] + s[i - 1];\n xd.insert(s[i], i);\n }\n long ans = 0;\n foreach (i; 2 .. a.length)\n {\n long sum = s[a.length - 1] - s[i - 1];\n if ((s[i - 1] & 1) == 0 && s[i - 1] / 2 == sum)\n {\n auto arr = xd.find(sum);\n //foreach (j, val; arr) writef(\"%d \", val);\n //writeln();\n ans += search(arr, i - 1);\n }\n }\n writefln(\"%d\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i, ref v; a)\n {\n scanf(\"%d\", &v);\n }\n solve(a);\n }\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n \n if (A.sum % 3 != 0) {\n writeln(0);\n return;\n }\n\n auto ave = A.sum / 3;\n\n auto acm_f = new int[](N);\n acm_f[0] = A[0];\n auto acm_b = new int[](N);\n acm_b[N-1] = A[N-1];\n \n foreach (i; 0..N-1) {\n acm_f[i+1] = acm_f[i] + A[i+1];\n acm_b[N-i-2] = acm_b[N-i-1] + A[N-i-2];\n }\n\n int[] f;\n int[] b;\n foreach (i; 0..N) {\n if (acm_f[i] == ave) f ~= i;\n if (acm_b[i] == ave) b ~= i;\n }\n\n auto B = b.assumeSorted;\n long ans = 0;\n\n foreach (i; f) {\n ans += B.upperBound(i+1).length;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "module main;\n\nimport std.stdio, std.string, std.conv;\n\nclass XD\n{\n public:\n this(int n)\n {\n len = n << 3;\n h = new int[][n << 3];\n f = new bool[n << 3];\n v = new long[n << 3];\n }\n int getPosition(long n)\n {\n auto s = to!string(n);\n int pos = calc(s);\n while (f[pos] == true && v[pos] != n)\n {\n ++ pos;\n if (pos == len)\n {\n pos = 0;\n }\n }\n return pos;\n }\n void insert(long n, int idx)\n {\n auto pos = getPosition(n);\n v[pos] = n;\n f[pos] = true;\n h[pos] ~= idx;\n }\n int[] find(long n)\n {\n auto pos = getPosition(n);\n return h[pos];\n }\n int calc(string s)\n {\n long hash = 0;\n foreach (i, val; s)\n {\n hash = (hash << 4) ^ (hash >> 28) ^ val;\n }\n return (hash % len);\n }\n protected:\n int len;\n long[] v;\n bool[] f;\n int[][] h;\n};\n\nint search(int[] a, int bound)\n{\n int left = 0, right = a.length - 1, mid, res = 0;\n while (left <= right)\n {\n mid = (left + right) >> 1;\n if (a[mid] >= bound)\n {\n right = mid - 1;\n }\n else\n {\n res = mid - left + 1;\n left = mid + 1;\n }\n }\n return res;\n}\n\nvoid solve(int[] a)\n{\n XD xd = new XD(a.length);\n auto s = new long[a.length];\n s[0] = a[0];\n xd.insert(s[0], 0);\n foreach (i; 1 .. a.length)\n {\n s[i] = a[i] + s[i - 1];\n xd.insert(s[i], i);\n }\n long ans = 0;\n foreach (i; 2 .. a.length)\n {\n long sum = s[a.length - 1] - s[i - 1];\n if ((s[i - 1] & 1) == 0 && s[i - 1] / 2 == sum)\n {\n auto arr = xd.find(sum);\n ans += search(arr, i - 1);\n }\n }\n writefln(\"%d\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i, ref v; a)\n {\n scanf(\"%d\", &v);\n }\n solve(a);\n }\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.stdio, std.string, std.conv;\n\nclass XD\n{\n public:\n this(int n)\n {\n len = n;\n h = new int[][n << 3];\n f = new bool[n << 3];\n v = new long[n << 3];\n }\n int getPosition(long n)\n {\n auto s = to!string(n);\n int pos = calc(s);\n while (f[pos] == true && v[pos] != n)\n {\n ++ pos;\n if (pos == len)\n {\n pos = 0;\n }\n }\n return pos;\n }\n void insert(long n, int idx)\n {\n auto pos = getPosition(n);\n v[pos] = n;\n f[pos] = true;\n h[pos] ~= idx;\n }\n int[] find(long n)\n {\n auto pos = getPosition(n);\n return h[pos];\n }\n int calc(string s)\n {\n long hash = 0;\n foreach (i, val; s)\n {\n hash = (hash << 4) ^ (hash >> 28) ^ val;\n }\n return (hash % len);\n }\n protected:\n int len;\n long[] v;\n bool[] f;\n int[][] h;\n};\n\nint search(int[] a, int bound)\n{\n int left = 0, right = a.length - 1, mid, res = 0;\n while (left <= right)\n {\n mid = (left + right) >> 1;\n if (a[mid] >= bound)\n {\n right = mid - 1;\n }\n else\n {\n res = mid - left + 1;\n left = mid + 1;\n }\n }\n return res;\n}\n\nvoid solve(int[] a)\n{\n XD xd = new XD(a.length);\n auto s = new long[a.length];\n s[0] = a[0];\n xd.insert(s[0], 0);\n foreach (i; 1 .. a.length)\n {\n s[i] = a[i] + s[i - 1];\n xd.insert(s[i], i);\n }\n long ans = 0;\n foreach (i; 2 .. a.length)\n {\n long sum = s[a.length - 1] - s[i - 1];\n auto arr = xd.find(sum);\n ans += search(arr, i - 1);\n }\n writefln(\"%d\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i, ref v; a)\n {\n scanf(\"%d\", &v);\n }\n solve(a);\n }\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.stdio, std.string, std.conv;\n\nclass XD\n{\n public:\n this(int n)\n {\n len = n;\n h = new int[][n << 3];\n f = new bool[n << 3];\n v = new long[n << 3];\n }\n int getPosition(long n)\n {\n auto s = to!string(n);\n int pos = calc(s);\n while (f[pos] == true && v[pos] != n)\n {\n ++ pos;\n if (pos == len)\n {\n pos = 0;\n }\n }\n return pos;\n }\n void insert(long n, int idx)\n {\n auto pos = getPosition(n);\n v[pos] = n;\n f[pos] = true;\n h[pos] ~= idx;\n }\n int[] find(long n)\n {\n auto pos = getPosition(n);\n return h[pos];\n }\n int calc(string s)\n {\n long hash = 0;\n foreach (i, val; s)\n {\n hash = (hash << 4) ^ (hash >> 28) ^ val;\n }\n return (hash % len);\n }\n protected:\n int len;\n long[] v;\n bool[] f;\n int[][] h;\n};\n\nint search(int[] a, int bound)\n{\n int left = 0, right = a.length - 1, mid, res = 0;\n while (left <= right)\n {\n mid = (left + right) >> 1;\n if (a[mid] >= bound)\n {\n right = mid - 1;\n }\n else\n {\n res = mid - left + 1;\n left = mid + 1;\n }\n }\n return res;\n}\n\nvoid solve(int[] a)\n{\n XD xd = new XD(a.length);\n auto s = new long[a.length];\n s[0] = a[0];\n xd.insert(s[0], 0);\n foreach (i; 1 .. a.length)\n {\n s[i] = a[i] + s[i - 1];\n xd.insert(s[i], i);\n }\n long ans = 0;\n foreach (i; 2 .. a.length)\n {\n long sum = s[a.length - 1] - s[i - 1];\n if (s[i - 1] / 2 == sum)\n {\n auto arr = xd.find(sum);\n ans += search(arr, i - 1);\n }\n }\n writefln(\"%d\", ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i, ref v; a)\n {\n scanf(\"%d\", &v);\n }\n solve(a);\n }\n return 0;\n}"}], "src_uid": "2558db57229e55ffe0de0d8cf217035b"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n// M: prime, G: primitive root\nclass Fft(int M_, int G, int K) {\n import std.algorithm : reverse;\n import std.traits : isIntegral;\n alias M = M_;\n // 1, 1/4, 1/8, 3/8, 1/16, 5/16, 3/16, 7/16, ...\n int[] gs;\n this() {\n static assert(2 <= K && K <= 30, \"Fft: 2 <= K <= 30 must hold\");\n static assert(!((M - 1) & ((1 << K) - 1)), \"Fft: 2^K | M - 1 must hold\");\n gs = new int[1 << (K - 1)];\n gs[0] = 1;\n long g2 = G, gg = 1;\n for (int e = (M - 1) >> K; e; e >>= 1) {\n if (e & 1) gg = (gg * g2) % M;\n g2 = (g2 * g2) % M;\n }\n gs[1 << (K - 2)] = cast(int)(gg);\n for (int l = 1 << (K - 2); l >= 2; l >>= 1) {\n gs[l >> 1] = cast(int)((cast(long)(gs[l]) * gs[l]) % M);\n }\n assert((cast(long)(gs[1]) * gs[1]) % M == M - 1,\n \"Fft: g^(2^(K-1)) == -1 (mod M) must hold\");\n for (int l = 2; l <= 1 << (K - 2); l <<= 1) {\n foreach (i; 1 .. l) {\n gs[l + i] = cast(int)((cast(long)(gs[l]) * gs[i]) % M);\n }\n }\n }\n void fft(int[] xs) const {\n const n = cast(int)(xs.length);\n assert(!(n & (n - 1)), \"Fft.fft: |xs| must be a power of two\");\n assert(n <= 1 << K, \"Fft.fft: |xs| <= 2^K must hold\");\n for (int l = n; l >>= 1; ) {\n foreach (i; 0 .. (n >> 1) / l) {\n const(long) g = gs[i];\n foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {\n const t = cast(int)((g * xs[j + l]) % M);\n if ((xs[j + l] = xs[j] - t) < 0) xs[j + l] += M;\n if ((xs[j] += t) >= M) xs[j] -= M;\n }\n }\n }\n }\n void invFft(int[] xs) const {\n const n = cast(int)(xs.length);\n assert(!(n & (n - 1)), \"Fft.invFft: |xs| must be a power of two\");\n assert(n <= 1 << K, \"Fft.invFft: |xs| <= 2^K must hold\");\n for (int l = 1; l < n; l <<= 1) reverse(xs[l .. l << 1]);\n for (int l = 1; l < n; l <<= 1) {\n foreach (i; 0 .. (n >> 1) / l) {\n const(long) g = gs[i];\n foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {\n int t = cast(int)((g * (xs[j] - xs[j + l])) % M);\n if (t < 0) t += M;\n if ((xs[j] += xs[j + l]) >= M) xs[j] -= M;\n xs[j + l] = t;\n }\n }\n }\n }\n T[] convolute(T)(inout(T)[] as, inout(T)[] bs) const if (isIntegral!T) {\n const na = cast(int)(as.length), nb = cast(int)(bs.length);\n int n, invN = 1;\n for (n = 1; n < na + nb - 1; n <<= 1) {\n invN = ((invN & 1) ? (invN + M) : invN) >> 1;\n }\n auto xs = new int[n], ys = new int[n];\n foreach (i; 0 .. na) if ((xs[i] = cast(int)(as[i] % M)) < 0) xs[i] += M;\n foreach (i; 0 .. nb) if ((ys[i] = cast(int)(bs[i] % M)) < 0) ys[i] += M;\n fft(xs);\n fft(ys);\n foreach (i; 0 .. n) {\n xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);\n }\n invFft(xs);\n auto cs = new T[na + nb - 1];\n foreach (i; 0 .. na + nb - 1) cs[i] = cast(T)(xs[i]);\n return cs;\n }\n}\n\nalias Fft0 = Fft!(998244353, 3, 20);\n\n\nvoid main() {\n const FFT = new Fft0;\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const S = readToken();\n \n auto fs = new int[N + 1];\n auto gs = new int[N + 1];\n foreach (i; 0 .. N) {\n switch (S[i]) {\n case 'V': ++fs[i]; break;\n case 'K': ++gs[N - i]; break;\n default: {}\n }\n }\n const hs = FFT.convolute(fs, gs);\n debug {\n writeln(\"hs = \", hs);\n }\n \n auto has = new bool[N + 1];\n foreach (x; -N .. +N + 1) {\n if (hs[N + x]) {\n has[abs(x)] = true;\n }\n }\n \n int[] ans;\n foreach (k; 1 .. N + 1) {\n bool ok = true;\n for (int l = k; l <= N; l += k) {\n ok = ok && !has[l];\n }\n if (ok) {\n ans ~= k;\n }\n }\n writeln(ans.length);\n foreach (index, k; ans) {\n if (index > 0) write(\" \");\n write(k);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint tt;\n\tread(tt);\n\tauto a = new Complex!double[1 << 20], b = new Complex!double[1 << 20];\n\tauto ca = a.dup, cb = b.dup;\n\tauto d = new int[1 << 20];\n\tauto r = new int[500_000];\n\tFft f = new Fft(1 << 20);\n\tstring s;\n\tforeach (ii; 0 .. tt)\n\t{\n\t\ts = readln;\n\t\tint n;\n\t\tread(n);\n\t\ts = readln.strip;\n\t\tint st = 1;\n\t\twhile (st <= n)\n\t\t\tst *= 2;\n\t\tst *= 2;\n\t\tauto z = Complex!double(0, 0);\n\t\ta[0 .. st] = z;\n\t\tb[0 .. st] = z;\n\t\tca[0 .. st] = z;\n\t\tcb[0 .. st] = z;\n\t\tforeach (i; 0 .. n)\n\t\t{\n\t\t\tif (s[i] == 'V')\n\t\t\t\ta[i] = 1;\n\t\t\telse if (s[i] == 'K')\n\t\t\t\tb[n - 1 - i] = 1;\n\t\t}\n\t\tf.fft(a[0 .. st], ca[0 .. st]);\n\t\tf.fft(b[0 .. st], cb[0 .. st]);\n\t\tca[0 .. st] *= cb[0 .. st];\n\t\tcb[0 .. st] = z;\n\t\tdebug writeln(ca[0 .. st]);\n\t\tf.inverseFft(ca[0 .. st], cb[0 .. st]);\n\t\tforeach (i; 0 .. st)\n\t\t{\n\t\t\td[i] = roundTo!int(cb[i].re);\n\t\t}\n\t\tr[n - 1] = d[n - 1];\n\t\tforeach (i; 1 .. n)\n\t\t{\n\t\t\tr[i] = d[n - 1 - i] + d[n - 1 + i];\n\t\t}\n\t\tint[] ans;\n\t\tforeach (i; 1 .. n)\n\t\t{\n\t\t\tbool flag = true;\n\t\t\tforeach (j; 1 .. (n - 1) / i + 1)\n\t\t\t{\n\t\t\t\tif (r[i * j])\n\t\t\t\t{\n\t\t\t\t\tflag = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (flag)\n\t\t\t{\n\t\t\t\tans ~= i;\n\t\t\t}\n\t\t}\n\t\tans ~= n;\n\t\twriteln(ans.length);\n\t\tforeach (x; ans)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t\twriteln;\n\t}\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint tt;\n\tread(tt);\n\tauto a = new Complex!double[1 << 20], b = new Complex!double[1 << 20];\n\tauto ca = a.dup, cb = b.dup;\n\tauto d = new int[1 << 20];\n\tauto r = new int[500_000];\n\tFft f = new Fft(1 << 20);\n\tstring s;\n\tforeach (ii; 0 .. tt)\n\t{\n\t\ts = readln;\n\t\tint n;\n\t\tread(n);\n\t\ts = readln.strip;\n\t\tint st = 1;\n\t\twhile (st <= n)\n\t\t\tst *= 2;\n\t\tst *= 2;\n\t\tauto z = Complex!double(0, 0);\n\t\ta[0 .. st] = z;\n\t\tb[0 .. st] = z;\n\t\tca[0 .. st] = z;\n\t\tcb[0 .. st] = z;\n\t\tforeach (i; 0 .. n)\n\t\t{\n\t\t\tif (s[i] == 'V')\n\t\t\t\ta[i] = 1;\n\t\t\telse if (s[i] == 'K')\n\t\t\t\tb[n - 1 - i] = 1;\n\t\t}\n\t\tf.fft(a[0 .. st], ca[0 .. st]);\n\t\tf.fft(b[0 .. st], cb[0 .. st]);\n\t\tca[0 .. st] *= cb[0 .. st];\n\t\tcb[0 .. st] = z;\n\t\tdebug writeln(ca[0 .. st]);\n\t\tf.inverseFft(ca[0 .. st], cb[0 .. st]);\n\t\tforeach (i; 0 .. st)\n\t\t{\n\t\t\td[i] = roundTo!int(cb[i].re);\n\t\t}\n\t\tr[n - 1] = d[n - 1];\n\t\tforeach (i; 1 .. n)\n\t\t{\n\t\t\tr[i] = d[n - 1 - i] + d[n - 1 + i];\n\t\t}\n\t\tint[] ans;\n\t\tforeach (i; 1 .. n)\n\t\t{\n\t\t\tbool flag = true;\n\t\t\tforeach (j; 1 .. (n - 1) / i + 1)\n\t\t\t{\n\t\t\t\tif (r[i * j])\n\t\t\t\t{\n\t\t\t\t\tflag = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (flag)\n\t\t\t{\n\t\t\t\tans ~= i;\n\t\t\t}\n\t\t}\n\t\tans ~= n;\n\t\twriteln(ans.length);\n\t\tforeach (x; ans)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t}\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint tt;\n\tread(tt);\n\tauto a = new Complex!double[1 << 20], b = new Complex!double[1 << 20];\n\tauto ca = a.dup, cb = b.dup;\n\tauto d = new int[1 << 20];\n\tauto r = new int[500_000];\n\tFft f = new Fft(1 << 20);\n\tforeach (ii; 0 .. tt)\n\t{\n\t\tauto s = readln;\n\t\tint n;\n\t\tread(n);\n\t\ts = readln.strip;\n\t\tint st = 1;\n\t\twhile (st <= n)\n\t\t\tst *= 2;\n\t\tst *= 2;\n\t\tauto z = Complex!double(0, 0);\n\t\ta[0 .. st] = z;\n\t\tb[0 .. st] = z;\n\t\tca[0 .. st] = z;\n\t\tcb[0 .. st] = z;\n\t\tforeach (i; 0 .. n)\n\t\t{\n\t\t\tif (s[i] == 'V')\n\t\t\t\ta[i] = 1;\n\t\t\telse if (s[i] == 'K')\n\t\t\t\tb[n - 1 - i] = 1;\n\t\t}\n\t\tf.fft(a[0 .. st], ca[0 .. st]);\n\t\tf.fft(b[0 .. st], cb[0 .. st]);\n\t\tca[0 .. st] *= cb[0 .. st];\n\t\tcb[0 .. st] = z;\n\t\tdebug writeln(ca[0 .. st]);\n\t\tf.inverseFft(ca[0 .. st], cb[0 .. st]);\n\t\tforeach (i; 0 .. st)\n\t\t{\n\t\t\td[i] = roundTo!int(cb[i].re);\n\t\t}\n\t\tr[n - 1] = d[n - 1];\n\t\tforeach (i; 1 .. n)\n\t\t{\n\t\t\tr[i] = d[n - 1 - i] + d[n - 1 + i];\n\t\t}\n\t\tint[] ans;\n\t\tforeach (i; 1 .. n)\n\t\t{\n\t\t\tbool flag = true;\n\t\t\tforeach (j; 1 .. (n - 1) / i + 1)\n\t\t\t{\n\t\t\t\tif (r[i * j])\n\t\t\t\t{\n\t\t\t\t\tflag = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (flag)\n\t\t\t{\n\t\t\t\tans ~= i;\n\t\t\t}\n\t\t}\n\t\tans ~= n;\n\t\twriteln(ans.length);\n\t\tforeach (x; ans)\n\t\t{\n\t\t\twrite(x, ' ');\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "4bfe403a49594bbd9c88e517668051d4"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n int[int] cnt;\n foreach (a; A) cnt[a] += 1;\n\n auto cumsum = new int[](N+2);\n foreach (a; cnt.values) cumsum[a+1] += 1;\n foreach (i; 0..N+1) cumsum[i+1] += cumsum[i];\n\n int calc_maxh(int w, int n) {\n return n / w;\n }\n\n int[][] build(int h, int w) {\n int[] B;\n Tuple!(int, int)[] C;\n\n foreach (k, v; cnt) C ~= tuple(k, min(w, v));\n C.sort!\"a[1] > b[1]\";\n foreach (c; C) foreach (_; 0..c[1]) B ~= c[0];\n\n auto ans = new int[][](h, w);\n int idx = 0;\n\n for (int r = 0, c = 0; idx < h * w; ++idx) {\n while (ans[r][c] != 0) (c += 1) %= w;\n ans[r][c] = B[idx];\n (r += 1) %= h;\n (c += 1) %= w;\n }\n\n return ans;\n }\n\n int maxh = 0;\n int maxw = 0;\n int count = cnt.keys.length.to!int;\n\n foreach (i; 1..sqrt(N.to!real).to!int+10) {\n if (count < i * i) break;\n int h = calc_maxh(i, count);\n if (h * i >= maxh * maxw) {\n maxh = h;\n maxw = i;\n }\n count += (cumsum[N] - cumsum[i+1]);\n }\n\n auto ans = build(maxh, maxw);\n writeln(maxh * maxw);\n writeln(maxh, \" \", maxw);\n ans.map!(a => a.map!(to!string).join(\" \")).each!writeln;\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n A.sort;\n \n auto ds = new int[N + 1];\n ds[1 .. $] = 1;\n foreach (d; 1 .. N + 1) {\n for (int m = d; m <= N; m += d) {\n chmax(ds[m], min(d, m / d));\n }\n }\n debug {\n writeln(\"ds = \", ds);\n }\n \n BinaryHeap!(Array!(Tuple!(int, int))) que;\n foreach (grp; A.group) {\n que.insert(tuple(cast(int)(grp[1]), grp[0]));\n }\n for (int m = N; m > 0; --m) {\n if (que.front[0] <= ds[m]) {\n const d = ds[m], e = m / ds[m];\n auto ans = new int[][](d, e);\n int pos;\n for (; !que.empty; ) {\n auto t = que.front;\n que.removeFront;\n foreach (_; 0 .. t[0]) {\n ans[pos % d][(pos % d + pos / d) % e] = t[1];\n ++pos;\n }\n }\n writeln(m);\n writeln(d, \" \", e);\n foreach (x; 0 .. d) {\n foreach (y; 0 .. e) {\n if (y > 0) write(\" \");\n write(ans[x][y]);\n }\n writeln();\n }\n break;\n }\n auto t = que.front;\n que.removeFront;\n if (t[0] >= 2) {\n que.insert(tuple(t[0] - 1, t[1]));\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n int[int] cnt;\n foreach (a; A) cnt[a] += 1;\n\n bool check(int n) {\n int sq = sqrt(n.to!real).to!int;\n while (sq * sq > n) --sq;\n while ((sq + 1) * (sq + 1) <= n) ++sq;\n return cnt.values.map!(a => min(a, sq)).sum >= sq * sq;\n }\n\n int[][] build(int n) {\n int sq = sqrt(n.to!real).to!int;\n while (sq * sq > n) --sq;\n while ((sq + 1) * (sq + 1) <= n) ++sq;\n\n int[] B;\n Tuple!(int, int)[] C;\n\n foreach (k, v; cnt) C ~= tuple(k, v);\n C.sort!\"a[1] > b[1]\";\n foreach (c; C) foreach (_; 0..c[1]) B ~= c[0];\n\n auto sm = C.map!(a => a[1]).sum;\n\n int h = sq, w = sq;\n while ((h + 1) * w <= sm) ++h;\n\n auto ans = new int[][](h, w);\n int idx = 0;\n\n for (int r = 0, c = 0; idx < h * w; ++idx) {\n while (ans[r][c] != 0) (c += 1) %= w;\n ans[r][c] = B[idx];\n (r += 1) %= h;\n (c += 1) %= w;\n }\n\n return ans;\n }\n\n int hi = sqrt(N.to!real).to!int + 10;\n int lo = 1;\n\n while (hi - lo > 1) {\n auto mid = (hi + lo) / 2;\n (check(mid) ? lo : hi) = mid;\n }\n\n auto ans = build(lo);\n auto h = ans.length.to!int;\n auto w = ans.front.length.to!int;\n writeln(h * w);\n writeln(h, \" \", w);\n ans.map!(a => a.map!(to!string).join(\" \")).each!writeln;\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n int[int] cnt;\n foreach (a; A) cnt[a] += 1;\n\n bool check(int n) {\n int sq = sqrt(n.to!real).to!int;\n while (sq * sq > n) --sq;\n while ((sq + 1) * (sq + 1) <= n) ++sq;\n return cnt.values.map!(a => min(a, sq)).sum >= sq * sq;\n }\n\n int[][] build(int n) {\n int sq = sqrt(n.to!real).to!int;\n while (sq * sq > n) --sq;\n while ((sq + 1) * (sq + 1) <= n) ++sq;\n\n int[] B;\n Tuple!(int, int)[] C;\n\n foreach (k, v; cnt) C ~= tuple(k, min(sq, v));\n C.sort!\"a[1] > b[1]\";\n foreach (c; C) foreach (_; 0..c[1]) B ~= c[0];\n\n auto sm = C.map!(a => a[1]).sum;\n\n int h = sq, w = sq;\n while ((h + 1) * w <= sm) ++h;\n\n auto ans = new int[][](h, w);\n int idx = 0;\n\n for (int r = 0, c = 0; idx < h * w; ++idx) {\n while (ans[r][c] != 0) (c += 1) %= w;\n ans[r][c] = B[idx];\n (r += 1) %= h;\n (c += 1) %= w;\n }\n\n return ans;\n }\n\n int hi = sqrt(N.to!real).to!int + 10;\n int lo = 1;\n\n while (hi - lo > 1) {\n auto mid = (hi + lo) / 2;\n (check(mid) ? lo : hi) = mid;\n }\n\n auto ans = build(lo);\n auto h = ans.length.to!int;\n auto w = ans.front.length.to!int;\n writeln(h * w);\n writeln(h, \" \", w);\n ans.map!(a => a.map!(to!string).join(\" \")).each!writeln;\n}"}], "src_uid": "db447a8896347bb47ce05a1df334a8b3"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint num (int limit, int bit)\r\n{\r\n\tauto half = 1 << bit;\r\n\tauto full = half << 1;\r\n\tauto pieces = limit / full;\r\n\tauto tail = limit % full;\r\n\tauto res = pieces * half + min (tail, half);\r\n\treturn res;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint lo, hi;\r\n\t\treadf !(\" %s %s\") (lo, hi);\r\n\t\tint res = int.max;\r\n\t\tforeach (i; 0..30)\r\n\t\t{\r\n\t\t\tres = min (res, num (hi + 1, i) - num (lo, i));\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tauto cnt = new long[][](18, 2*(10^^5)+1);\r\n\tforeach (i; 0..18)\r\n\t{\r\n\t\tauto bit = 1L << i;\r\n\t\tforeach (j; 1..2*(10^^5)+1)\r\n\t\t{\r\n\t\t\tcnt[i][j] = cnt[i][j-1];\r\n\t\t\tif (j & bit)\r\n\t\t\t\t++cnt[i][j];\r\n\t\t}\r\n\t}\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto l = RD!int;\r\n\t\tauto r = RD!int;\r\n\r\n\t\tauto len = r - l + 1;\r\n\t\tans[ti] = long.max;\r\n\t\tforeach (i; 0..18)\r\n\t\t{\r\n\t\t\tans[ti].chmin(len - (cnt[i][r]-cnt[i][l-1]));\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import core.stdc.stdio;\nint[20][200002] s;\nvoid main() {\n\tfor(int i=0;i<20;++i){\n\t\tfor(int j=1;j<=200000;++j)\n\t\t\ts[j][i]=s[j-1][i]+(j>>i&1);\n\t}\n\tint t;\n\tscanf(\"%d\",&t);\n\twhile(t--){\n\t\tint n,ans,l,r;\n\t\tscanf(\"%d%d\",&l,&r);\n\t\tfor(int i=0;i<20;++i){\n\t\t\tint x=s[r][i]-s[l-1][i];\n\t\t\tif(x>ans)\n\t\t\t\tans=x;\n\t\t}\n\t\tprintf(\"%d\\n\",r-l-ans+1);\n\t}\n}\n \t\t \t \t \t \t \t \t \t\t \t \t"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto l = readInt!uint;\n auto r = readInt!uint;\n int ans = int.max;\n int getOnes(int n, int b)\n {\n int blksize = (1 << b);\n int blk = n / blksize;\n int off = n % blksize;\n if (blk == 0) return 0;\n int pblk = blk;\n int blk1 = pblk / 2;\n if (blk&1) off++;\n else off = 0;\n return blk1 * blksize + off;\n }\n foreach(bit; 0 .. 32)\n {\n auto or = getOnes(r, bit);\n auto ol = getOnes(l-1, bit);\n debug writeln(bit, \" \", or, \" \", ol);\n ans = min(ans, r - l + 1 - (or - ol));\n }\n ans.writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid cnt_set_bit(ref int[32] bitcnt, int n)\n{\n if (n == 0)\n return;\n\n int p = -1;\n while (1 << (p + 1) <= n)\n p++;\n\n foreach (i ; 0 .. p)\n bitcnt[i] += (1 << p) / 2;\n\n bitcnt[p] += n - (1 << p) + 1;\n\n cnt_set_bit(bitcnt, n - (1 << p));\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int l, r;\n int[32] bitcnt;\n readf!\" %d %d \"(l, r);\n int[32] bitcnt1;\n int[32] bitcnt2;\n cnt_set_bit(bitcnt1, l - 1);\n cnt_set_bit(bitcnt2, r);\n foreach (i ; 0 .. 30) {\n bitcnt[i] = bitcnt2[i] - bitcnt1[i];\n }\n int ans = int.max;\n foreach (bt ; 0 .. 30) {\n if (bitcnt[bt] != 0)\n ans = min(ans, r - l + 1 - bitcnt[bt]);\n }\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum E = 20;\nenum LIM = 2 * 10^^5 + 10;\n\nvoid main() {\n auto sums = new int[][](E, LIM + 1);\n foreach (e; 0 .. E) {\n foreach (i; 0 .. LIM) {\n sums[e][i + 1] = sums[e][i] + (i >> e & 1);\n }\n }\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const L = readInt();\n const R = readInt() + 1;\n \n int ans;\n foreach (e; 0 .. 20) {\n chmax(ans, sums[e][R] - sums[e][L]);\n }\n ans = (R - L) - ans;\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto l = RD!int;\r\n\t\tauto r = RD!int;\r\n\r\n\t\tauto len = r - l + 1;\r\n\t\tans[ti] = len - len / 2 - (len % 2 ? l % 2 : 0);\r\n\t\tforeach (i; 0..18)\r\n\t\t{\r\n\t\t\tauto bit = 1L << i;\r\n\t\t\tif (bit < l)\r\n\t\t\t{\r\n\t\t\t\tif (l & bit)\r\n\t\t\t\t\tans[ti].chmin(len - min(r - l + 1, bit));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tauto x = l | bit;\r\n\t\t\t\t\tx >>= i;\r\n\t\t\t\t\tx <<= i;\r\n\t\t\t\t\tans[ti].chmin(len - min(r - x + 1, bit));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tans[ti].chmin(len - min(r - bit + 1, bit));\r\n\t\t}\r\n\t}\r\n\t\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto l = RD!int;\r\n\t\tauto r = RD!int;\r\n\r\n\t\tauto len = r - l + 1;\r\n\t\tans[ti] = len - len / 2 - (len % 2 ? l % 2 : 0);\r\n\t\tforeach (i; 0..18)\r\n\t\t{\r\n\t\t\tauto bit = 1L << i;\r\n\t\t\tif (bit < l) continue;\r\n\t\t\tans[ti].chmin(len - min(r - bit + 1, bit));\r\n\t\t}\r\n\t}\r\n\t\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto l = RD!int;\r\n\t\tauto r = RD!int;\r\n\r\n\t\tauto len = r - l + 1;\r\n\t\tans[ti] = len - (len+1) / 2;\r\n\t\tforeach (i; 0..18)\r\n\t\t{\r\n\t\t\tauto bit = 1L << i;\r\n\t\t\tif (bit < l) continue;\r\n\t\t\tans[ti].chmin(len - min(r - bit + 1, bit-1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "0601e3636b5d5b6ad0c8c1abb7f83d82"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\n\nvoid main() {\n debug stdin = File(\"input.txt\", \"r\");\n\n int n;\n readf(\"%d\\n\", &n);\n string[] words = new string[n];\n foreach (ref word; words) {\n readf(\"%s\\n\", &word);\n }\n\n string s;\n readf(\"%s\\n\", &s);\n\n foreach (ref word; words) {\n word = \"<3\" ~ word;\n }\n words[$ - 1] ~= \"<3\";\n\n string all = join(words);\n\n int cur = 0;\n foreach (c; s) {\n if (c == all[cur]) {\n ++cur;\n }\n if (cur == all.length){\n writeln(\"yes\");\n return;\n }\n }\n\n writeln(\"no\");\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\n\n\nint main(string[] argv)\n{\n\tint n = to!int(readln()[0..$-1]);\n\t\n\n\tstring words = \"<3\";\n\tfor (int i = 0; i < n; ++i) {\n\t\t\n\t\twords ~= readln()[0..$-1] ~ \"<3\";\n\t}\n\tstring code = readln()[0..$-1];\n\tint t = 0;\n\tforeach (char ch; words) {\n\t\tif (t == code.length) {\n\t\t\twriteln(\"no\");\n\t\t\treturn 0;\n\t\t}\n\t\twhile (ch != code[t]) {\n\t\t\tt += 1;\n\t\t\tif (t == code.length) {\n\t\t\t\twriteln(\"no\");\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\tt += 1;\n\t\t\n\t}\n\twriteln(\"yes\");\n return 0;\n}\n"}, {"source_code": "#!/usr/bin/env rdmd\nimport std.stdio, std.string, std.conv;\nimport std.algorithm, std.array;\n\nvoid main()\n{\n for(string S; (S=readln().chomp()).length; )\n {\n auto n = S.to!int();\n string w = \"<3\";\n foreach(i;0..n)\n w ~= readln().chomp() ~ \"<3\";\n immutable string t = readln().chomp().idup;\n const auto M = w.length;\n const auto N = t.length;\n if(M>N){ writeln(\"no\"); return; }\n auto dp = new int[N+1];\n auto dpn = new int[N+1];\n foreach(j,v;w)\n {\n foreach(i;j..j+N-M+1)\n dpn[i+1]=max(dpn[i],dp[i+(v==t[i]?0:1)]+(v==t[i]?1:0));\n dp.swap(dpn);\n }\n writeln(w.length==dp[N]?\"yes\":\"no\");\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\n\n\nint main(string[] argv)\n{\n\tint n = to!int(readln()[0..$-1]);\n\t\n\n\tstring words = \"<3\";\n\tfor (int i = 0; i < n; ++i) {\n\t\t\n\t\twords ~= readln()[0..$-1] ~ \"<3\";\n\t}\n\tstring code = readln()[0..$-1];\n\tint t = 0;\n\tforeach (char ch; words) {\n\t\tif (t >= code.length) {\n\t\t\twriteln(\"no\");\n\t\t\treturn 0;\n\t\t}\n\t\twhile (ch != code[t]) {\n\t\t\tt += 1;\n\t\t\tif (t >= code.length) {\n\t\t\t\twriteln(\"no\");\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\tt += 1;\n\t\t\n\t}\n\twriteln(\"yes\");\n return 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\n\nint main(string[] argv)\n{\n\tint n;\n\treadf(\" %d\", &n);\n\n\tstring words;\n\tfor (int i = 0; i < n; ++i) {\n\t\twords ~= readln() ~ \"<3\";\n\t}\n\tstring code = readln();\n\tint i = 0;\n\tforeach (char ch; words) {\n\t\twhile (ch != code[i]) {\n\t\t\ti += 1;\n\t\t\tif (i == code.length - 1) {\n\t\t\t\twriteln(\"no\");\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\ti += 1;\n\t\tif (i == code.length - 1) {\n\t\t\twriteln(\"no\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\twriteln(\"yes\");\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\n\n\nint main(string[] argv)\n{\n\tint n = to!int(readln()[0..$-1]);\n\t\n\n\tstring words = \"<3\";\n\tfor (int i = 0; i < n; ++i) {\n\t\t\n\t\twords ~= readln()[0..$-1] ~ \"<3\";\n\t}\n\tstring code = readln()[0..$-1];\n\tint i = 0;\n\tforeach (char ch; words) {\n\t\twhile (ch != code[i]) {\n\t\t\ti += 1;\n\t\t\tif (i == code.length) {\n\t\t\t\twriteln(\"no\");\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\ti += 1;\n\t\tif (i == code.length) {\n\t\t\twriteln(\"no\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\twriteln(\"yes\");\n return 0;\n}\n"}], "src_uid": "36fb3a01860ef0cc2a1065d78e4efbd5"} {"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n int n;\n sc.read(n);\n long[long] mp;\n foreach (i; 0..n) {\n long a, b;\n sc.read(a, b);\n mp[a] = b;\n }\n int m;\n sc.read(m);\n foreach (i; 0..m) {\n long a, b;\n sc.read(a, b);\n if (a !in mp) mp[a] = b;\n else mp[a] = max(mp[a], b);\n }\n writeln(mp.values.sum);\n return 0;\n}\n/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.datetime;\n\nvoid main() {\n long[long] s;\n\n auto N = readln.chomp.to!int;\n foreach (_; 0..N) {\n auto t = readln.split.map!(to!long);\n auto a = t[0];\n auto x = t[1];\n if (a in s) s[a] = max(s[a], x);\n else s[a] = x;\n }\n\n auto M = readln.chomp.to!int;\n foreach (_; 0..M) {\n auto t = readln.split.map!(to!long);\n auto a = t[0];\n auto x = t[1];\n if (a in s) s[a] = max(s[a], x);\n else s[a] = x;\n }\n\n s.values.sum.writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int [int] mp;\n \n foreach ( _; 0..2 ) {\n int n;\n readf( \"%s\", &n );\n readln;\n \n while ( n-- ) {\n int k, v;\n readf(\"%s %s\", &k, &v);\n readln;\n \n mp[k] = max( mp.get(k, 0), v );\n }\n }\n \n writeln( mp.values().sum(0L) );\n}"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n\twhile (true)\n\t{\n\t\tint [int] v;\n\t\tforeach (k; 0..2)\n\t\t{\n\t\t\tint n;\n\t\t\tif (readf (\" %s\", &n) != 1)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tint a, x;\n\t\t\t\treadf (\" %s %s\", &a, &x);\n\t\t\t\tv[a] = max (v.get (a, x), x);\n\t\t\t}\n\t\t}\n\t\twriteln (v.byValue.sum (0L));\n\t}\n}\n"}], "negative_code": [], "src_uid": "fe5c302d844b0b94d030b180e017b9b2"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nvoid bAdd(T)(T[] bit, int pos, T val)\nin {\n assert(0 <= pos && pos < bit.length, \"bAdd: 0 <= pos < |bit| must hold\");\n}\ndo {\n for (int x = pos; x < bit.length; x |= x + 1) {\n bit[x] += val;\n }\n}\n\n// sum of [0, pos)\nT bSum(T)(T[] bit, int pos)\nin {\n assert(0 <= pos && pos <= bit.length, \"bSum: 0 <= pos <= |bit| must hold\");\n}\ndo {\n T sum = 0;\n for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {\n sum += bit[x];\n }\n return sum;\n}\n\n// min pos s.t. pred(sum of [0, pos))\n// assume pred(sum of [0, pos)) is non-decreasing\nint bBinarySearch(alias pred, T)(T[] bit) {\n import core.bitop : bsr;\n import std.functional : unaryFun;\n alias predFun = unaryFun!pred;\n if (predFun(0)) return 0;\n int pos = 0;\n T sum = 0;\n foreach_reverse (e; 0 .. bsr(bit.length) + 1) {\n const x = (pos | 1 << e) - 1;\n if (x < bit.length && !predFun(sum + bit[x])) {\n pos |= 1 << e;\n sum += bit[x];\n }\n }\n return pos + 1;\n}\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n const M = readInt();\n auto K = new int[M];\n auto P = new int[M];\n foreach (m; 0 .. M) {\n K[m] = readInt();\n P[m] = readInt();\n }\n \n auto queries = new int[][N + 1];\n foreach (m; 0 .. M) {\n queries[K[m]] ~= m;\n }\n auto ans = new int[M];\n \n auto as = new Tuple!(int, int)[N];\n foreach (i; 0 .. N) {\n as[i] = tuple(A[i], i);\n }\n as.sort!((a, b) => ((a[0] != b[0]) ? (a[0] > b[0]) : (a[1] < b[1])));\n \n auto bit = new int[N];\n foreach (i; 0 .. N) {\n bit.bAdd(as[i][1], 1);\n foreach (m; queries[i + 1]) {\n const res = bit.bBinarySearch!(s => (s >= P[m]));\n ans[m] = A[res - 1];\n }\n }\n \n foreach (m; 0 .. M) {\n writeln(ans[m]);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\tauto m = RD!int;\n\t\n\tint[][int] pos;\n\tforeach (i; 0..n)\n\t{\n\t\tpos[a[i]] ~= i;\n\t}\n\n\tauto keys = pos.keys;\n\tkeys.sort!\"a > b\"();\n\tforeach (i; 0..m)\n\t{\n\t\tauto k = RD!int;\n\t\tauto p = RD!int-1;\n\t\tbool[int] ans;\n\t\tint cnt;\n\t\t(){\n\t\tforeach (key; keys)\n\t\t{\n\t\t\tforeach (j; pos[key])\n\t\t\t{\n\t\t\t\tans[j] = true;\n\t\t\t\t++cnt;\n\t\t\t\tif (cnt == k) return;\n\t\t\t}\n\t\t}}();\n\t\tauto keys_a = ans.keys;\n\t\tkeys_a.sort();\n\t\twriteln(a[keys_a[p]]);\n\t}\n\t\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "1e56f4d17c4ad0b5dde7f05b4e362cfc"} {"source_code": "/+ dub.sdl:\n name \"C\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n, r;\n sc.read(n, r);\n int[] f = new int[n], s = new int[n];\n double[] p = new double[n];\n foreach (i; 0..n) {\n sc.read(f[i], s[i], p[i]); p[i] /= 100;\n }\n\n double[][] dp = new double[][](n+1, r+1);\n double lx = 0, rx = 1e10;\n foreach (ph; 0..100) {\n double md = (lx+rx)/2;\n\n dp[n][] = 0.0;\n foreach_reverse (i; 0..n) {\n foreach (j; 0..r+1) {\n dp[i][j] = 0.0;\n if (j+f[i] <= r) {\n dp[i][j] += p[i] * (f[i] + dp[i+1][j+f[i]]);\n } else {\n dp[i][j] += p[i] * (f[i] + md);\n }\n if (j+s[i] <= r) {\n dp[i][j] += (1-p[i]) * (s[i] + dp[i+1][j+s[i]]);\n } else {\n dp[i][j] += (1-p[i]) * (s[i] + md);\n }\n dp[i][j] = min(dp[i][j], md);\n }\n }\n\n if (md <= dp[0][0]) {\n lx = md;\n } else {\n rx = md;\n }\n }\n\n writefln(\"%.20f\", dp[0][0]);\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const R = readInt();\n auto F = new int[N];\n auto S = new int[N];\n auto P = new real[N];\n foreach (i; 0 .. N) {\n F[i] = readInt();\n S[i] = readInt();\n P[i] = readInt() / 100.0L;\n }\n \n // <= 5000 * (1 / 0.8)^50\n real lo = 0.0L, hi = 1e+12;\n foreach (_; 0 .. 100) {\n const mid = (lo + hi) / 2.0L;\n auto dp = new real[][](N + 1, R + 1);\n dp[N][] = 0.0L;\n foreach_reverse (i; 0 .. N) {\n foreach (x; 0 .. R + 1) {\n dp[i][x] = 0.0;\n dp[i][x] += P[i] * (F[i] + ((x + F[i] <= R) ? dp[i + 1][x + F[i]] : mid));\n dp[i][x] += (1.0L - P[i]) * (S[i] + ((x + S[i] <= R) ? dp[i + 1][x + S[i]] : mid));\n chmin(dp[i][x], mid);\n }\n }\n ((dp[0][0] < mid) ? hi : lo) = mid;\n }\n writefln(\"%.12f\", lo);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "b461bb51eab4ff8088460c1980dacb93"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport core.stdc.stdio;\n\nint main()\n{\n auto t = readInt!int;\n foreach(ti; 0 .. t)\n {\n int[4] s;\n s[0] = readInt!int;\n s[1] = readInt!int;\n s[2] = readInt!int;\n s[3] = readInt!int;\n if (min(s[2], s[3]) > max(s[0], s[1]) || min(s[0], s[1]) > max(s[2], s[3]))\n {\n writeln(\"NO\");\n }\n else writeln(\"YES\");\n }\n return 0;\n}\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n long rep;\n this(long num)\n {\n rep = num;\n }\n Z!m opBinary(string operator)(Z!m rhs)\n {\n static if (operator == \"+\")\n {\n long result = rhs.rep + this.rep;\n if (result >= m) result -= m;\n return Z!m(result);\n }\n else static if (operator == \"-\")\n {\n long result = this.rep - rhs.rep;\n if (result < 0) result += m;\n return Z!m(result);\n }\n else static if (operator == \"*\")\n {\n long result = this.rep * rhs.rep;\n if (result >= m) result %= m;\n return Z!m(result);\n } else static assert(text(\"Operator \", operator, \" not supported\"));\n }\n Z!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n {\n assert(exponent >= 0);\n Z!m base = this;\n Z!m result = 1;\n while (exponent)\n {\n if (exponent & 1)\n result = result * base;\n base = base * base;\n exponent >>= 1;\n }\n return result;\n }\n invariant\n {\n assert(rep >= 0 && rep < m);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto arr = readln().chomp.splitter(\" \").map!(to!long).array;\r\n auto rev = arr.retro.array;\r\n \r\n if(arr[0] > arr[2] && arr[1] > arr[2] && arr[0] > arr[3] && arr[1] > arr[3])\r\n writeln(\"NO\");\r\n else if(rev[0] > rev[2] && rev[1] > rev[2] && rev[0] > rev[3] && rev[1] > rev[3])\r\n writeln(\"NO\");\r\n else\r\n writeln(\"YES\");\r\n }\r\n}"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1535/problem/A\n// implementation\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int[] s = readln.split.map!(to!int).array;\n\n int winner_a = max(s[0],s[1]);\n int winner_b = max(s[2],s[3]);\n\n if(winner_a > winner_b)\n swap(winner_a, winner_b);\n\n s.sort;\n s = [s[2],s[3]];\n\n if(winner_a == s[0] && winner_b == s[1])\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n auto b = readln.chomp.split.map!(to!int).array;\n auto a = b.dup;\n b.sort;\n int[int] winners;\n winners[b[2]] = true;\n winners[b[3]] = true;\n// writeln(a);\n// writeln(winners);\n if ((winners.get(a[0], false) || winners.get(a[1], false)) &&\n (winners.get(a[2], false) || winners.get(a[3], false))) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (min (a[0], a[1]) < max (a[2], a[3]) &&\r\n\t\t min (a[2], a[3]) < max (a[0], a[1]) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto arr = readln().chomp.splitter(\" \").map!(to!long).array;\r\n auto rev = arr.retro.array;\r\n \r\n if(arr[0] > arr[2] && arr[1] > arr[2])\r\n writeln(\"NO\");\r\n else if(rev[0] > rev[2] && rev[1] > rev[2])\r\n writeln(\"NO\");\r\n else\r\n writeln(\"YES\");\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.numeric;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto arr = readln().chomp.splitter(\" \").map!(to!long).array;\r\n auto rev = arr.retro.array;\r\n \r\n if(arr[0] > arr[2] && arr[1] > arr[2] && arr[0] > arr[3] && arr[1] > arr[4])\r\n writeln(\"NO\");\r\n else if(rev[0] > arr[2] && rev[1] > rev[2] && rev[0] > rev[3] && rev[1] > rev[4])\r\n writeln(\"NO\");\r\n else\r\n writeln(\"YES\");\r\n }\r\n}"}], "src_uid": "cb24509580ff9b2f1a11103a0e4cdcbd"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n int ans = 0;\n int tmp = 0;\n\n foreach (i; 0..N) {\n tmp = max(tmp, A[i]);\n if (i + 1 == tmp) ans += 1, tmp = 0;\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nint[10^^4+1] MEMO;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n int n, r;\n foreach (i, a; readln.split.to!(int[])) {\n ++n;\n ++MEMO[a-1];\n n -= MEMO[i];\n if (!n) ++r;\n }\n writeln(r);\n}"}], "negative_code": [], "src_uid": "291601d6cdafa4113c1154f0dda3470d"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD;\n\t\tauto y = RD;\n\n\t\tif (x >= y)\n\t\t\tans[ti] = [x-1, y];\n\t\telse\n\t\t\tans[ti] = [x-1, y];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0], \" \", e[1]);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint a, b;\n\t\treadf !(\" %s %s\") (a, b);\n\t\twriteln (a - 1, \" \", b);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD;\n\t\tauto y = RD;\n\n\t\tif (x >= y)\n\t\t\tans[ti] = [x-y, 1];\n\t\telse\n\t\t\tans[ti] = [x-1, y];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0], \" \", e[1]);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD;\n\t\tauto y = RD;\n\n\t\tif (x >= y)\n\t\t\tans[ti] = [x-y, 1];\n\t\telse\n\t\t\tans[ti] = [0, y-x+1];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0], \" \", e[1]);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "09625e65e62fc1c618d12969932508de"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto str = readString;\n if (str.length == 2)\n {\n if (str[0] != str[1]) return writeln(\"NO\");\n }\n if (str.count!(ci => ci == 'N') == 1) return writeln(\"NO\");\n return writeln(\"YES\");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main () {\n auto readN = () { int n; readf(\"%s\\n\", n); return n; };\n\n immutable n = readN();\n\n foreach (i; 0 .. n) {\n string s = readln()[0 .. $ - 1];\n writeln(s.count('N') == 1 ? \"NO\" : \"YES\");\n }\n}\n\n// \"\"\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto s = readln.strip;\n writeln(s.count('N') == 1 ? \"NO\" : \"YES\");\n }\n}\n"}], "negative_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto str = readString;\n if (str.length == 2)\n {\n if (str[0] != str[1]) return writeln(\"NO\");\n }\n if (str[0 .. $ - 1].count!(ci => ci == 'N') == 1) return writeln(\"NO\");\n return writeln(\"YES\");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto str = readString;\n if (str.length == 2)\n {\n if (str[0] != str[1]) return writeln(\"NO\");\n }\n return writeln(\"YES\");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "e744184150bf55a30568060cca69de04"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto g = a.group.map !(q{a[0]}).array;\n\t\tint [int] v;\n\t\tforeach (x; g)\n\t\t{\n\t\t\tv[x] += 1;\n\t\t}\n\t\tint res = int.max;\n\t\tforeach (x, num; v)\n\t\t{\n\t\t\tres = min (res, num - (x == g.front) - (x == g.back));\n\t\t}\n\t\twriteln (res + 1);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA(-1);\n\n\t\tlong[] b = [a[0]];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i-1] != a[i])\n\t\t\t\tb ~= a[i];\n\t\t}\n\t\tauto cnt = new long[](n);\n\t\tforeach (e; b)\n\t\t{\n\t\t\t++cnt[cast(int)e];\n\t\t}\n\t\tans[ti] = long.max;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (cnt[i] == 0) continue;\n\t\t\tif (i == b[0])\n\t\t\t\t--cnt[i];\n\t\t\tif (i == b[$-1])\n\t\t\t\t--cnt[i];\n\t\t\tans[ti].chmin(cnt[i]+1);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "080eb61cbc4b0ffcbab10b86918f70fe"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, M;\nint[] U, V;\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n // !!!3N vertices!!!\n N = readInt();\n M = readInt();\n U = new int[M];\n V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n debug {\n writeln(\"N = \", N, \", M = \", M);\n writeln(\"U = \", U);\n writeln(\"V = \", V);\n }\n \n int cnt;\n auto matching = new bool[M];\n auto used = new bool[3 * N];\n foreach (i; 0 .. M) {\n if (!used[U[i]] && !used[V[i]]) {\n ++cnt;\n matching[i] = true;\n used[U[i]] = true;\n used[V[i]] = true;\n }\n }\n \n int[] ans;\n if (cnt >= N) {\n writeln(\"Matching\");\n foreach (i; 0 .. M) {\n if (matching[i]) {\n ans ~= i + 1;\n }\n }\n } else {\n writeln(\"IndSet\");\n foreach (u; 0 .. 3 * N) {\n if (!used[u]) {\n ans ~= u + 1;\n }\n }\n }\n ans = ans[0 .. N];\n foreach (idx, a; ans) {\n if (idx > 0) {\n write(\" \");\n }\n write(a);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"C\"\n dependency \"dunkelheit\" version=\"1.0.1\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner, dkh.datastructure.segtree;\n\nvoid solve(Scanner sc) {\n\n int n, m;\n sc.read(n, m);\n\n int[] edges;\n int[] used = new int[3 * n];\n foreach (i; 0..m) {\n int a, b;\n sc.read(a, b);\n a--; b--;\n\n if (edges.length.to!int < n) {\n if (used[a] || used[b]) continue;\n used[a] = used[b] = true;\n edges ~= i + 1;\n }\n }\n\n if (edges.length == n) {\n writeln(\"Matching\");\n edges.map!(to!string).join(\" \").writeln;\n } else {\n writeln(\"IndSet\");\n iota(3 * n).filter!(i => !used[i]).take(n).map!(i => (i + 1).to!string).join(\" \").writeln;\n }\n\n}\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n\n int t;\n sc.read(t);\n\n foreach (i; 0..t) {\n solve(sc);\n }\n return 0;\n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/datastructure/segtree.d */\n// module dkh.datastructure.segtree;\n\nimport std.conv : to;\nimport std.functional : binaryFun;\nimport std.traits : isInstanceOf;\n\nstruct SegTree(alias E, Args...) {\n import std.traits : ReturnType;\n alias Engine = E!Args;\n alias T = Engine.DataType;\n alias L = Engine.LazyType;\n\n Engine eng;\n\n this(size_t n) { eng = Engine(n.to!uint); }\n this(T[] first) { eng = Engine(first); }\n\n @property size_t length() const { return eng.length(); }\n @property size_t opDollar() const { return eng.length(); }\n \n struct Range {\n Engine* eng;\n size_t start, end;\n @property const(T) sum() {\n return eng.sum(start.to!uint, end.to!uint);\n }\n }\n const(T) opIndex(size_t k) {\n assert(0 <= k && k < eng.length());\n return eng.single(k.to!uint);\n }\n void opIndexAssign(T x, size_t k) {\n assert(0 <= k && k < eng.length());\n eng.singleSet(k.to!uint, x);\n }\n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) {\n assert(0 <= start && start <= end && end <= eng.length());\n return [start, end];\n }\n Range opIndex(size_t[2] rng) {\n return Range(&eng, rng[0].to!uint, rng[1].to!uint);\n }\n static if (!is(L == void)) {\n void opIndexOpAssign(string op : \"+\")(L x, size_t[2] rng) {\n eng.add(rng[0].to!uint, rng[1].to!uint, x);\n }\n }\n}\n\nptrdiff_t binSearchLeft(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b) \nif (isInstanceOf!(SegTree, TR)) {\n return TR.Engine.BinSearch!(false, pred)(t.eng, a.to!int, b.to!int);\n}\n\nptrdiff_t binSearchRight(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b) \nif (isInstanceOf!(SegTree, TR)) {\n return TR.Engine.BinSearch!(true, pred)(t.eng, a.to!int, b.to!int);\n}\n\n \nalias SimpleSeg(T, alias opTT, T eT, alias Engine = SimpleSegEngine) =\n SegTree!(Engine, T, binaryFun!opTT, eT);\n\n \n \n\nstruct SimpleSegEngine(T, alias opTT, T eT) {\n alias DataType = T;\n alias LazyType = void;\n alias BinSearch = binSearchSimple;\n uint n, sz, lg;\n T[] d;\n @property uint length() const {return n;}\n this(uint n) {\n import std.algorithm : each;\n this.n = n;\n if (n == 0) return;\n while ((2^^lg) < n) lg++;\n sz = 2^^lg;\n d = new T[](2*sz);\n d.each!((ref x) => x = eT);\n }\n this(T[] first) {\n import std.conv : to;\n import std.algorithm : each;\n n = first.length.to!uint;\n if (n == 0) return;\n while ((2^^lg) < n) lg++;\n sz = 2^^lg;\n d = new T[](2*sz);\n d.each!((ref x) => x = eT);\n foreach (i; 0..n) {\n d[sz+i] = first[i];\n }\n foreach_reverse (i; 1..sz) {\n update(i);\n }\n }\n pragma(inline):\n void update(uint k) {\n d[k] = opTT(d[2*k], d[2*k+1]);\n }\n T single(uint k) {\n return d[k+sz];\n }\n void singleSet(uint k, T x) {\n k += sz;\n d[k] = x;\n foreach (uint i; 1..lg+1) {\n update(k>>i);\n }\n }\n T sum(uint a, uint b) {\n assert(0 <= a && a <= b && b <= n);\n T sml = eT, smr = eT;\n a += sz; b += sz;\n while (a < b) {\n if (a & 1) sml = opTT(sml, d[a++]);\n if (b & 1) smr = opTT(d[--b], smr);\n a >>= 1; b >>= 1;\n }\n return opTT(sml, smr);\n }\n}\n\nint binSearchSimple(bool rev, alias pred, TR)(TR t, int a, int b) {\n import std.traits : TemplateArgsOf;\n alias args = TemplateArgsOf!TR;\n alias opTT = args[1];\n auto x = args[2];\n with (t) {\n static if (!rev) {\n \n if (pred(x)) return a-1;\n int pos = a;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, d[k]))) {\n x = opTT(x, d[k]);\n pos = r;\n return;\n }\n if (l+1 == r) return;\n int md = (l+r)/2;\n f(a, b, l, md, 2*k);\n if (pos >= md) f(a, b, md, r, 2*k+1);\n }\n f(a, b, 0, sz, 1);\n return pos; \n } else {\n \n if (pred(x)) return b;\n int pos = b-1;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, d[k]))) {\n x = opTT(d[k], x);\n pos = l-1;\n return;\n }\n if (l+1 == r) return;\n int md = (l+r)/2;\n f(a, b, md, r, 2*k+1);\n if (pos < md) f(a, b, l, md, 2*k);\n }\n f(a, b, 0, sz, 1);\n return pos; \n }\n }\n}\n\n \nalias LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL, alias Engine = LazySegEngine) =\n SegTree!(Engine, T, L , binaryFun!opTT, binaryFun!opTL, binaryFun!opLL, eT, eL);\n\n \n \n\n\nstruct LazySegEngine(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {\n import std.typecons : Tuple;\n alias DataType = T;\n alias LazyType = L;\n alias BinSearch = binSearchLazy;\n alias S = Tuple!(T, \"d\", L, \"lz\");\n uint n, sz, lg;\n S[] s;\n this(uint n) {\n import std.conv : to;\n import std.algorithm : each;\n this.n = n;\n uint lg = 0;\n while ((2^^lg) < n) lg++;\n this.lg = lg;\n sz = 2^^lg;\n s = new S[](2*sz);\n s.each!((ref x) => x = S(eT, eL));\n }\n this(T[] first) {\n import std.conv : to;\n import std.algorithm : each;\n n = first.length.to!uint;\n uint lg = 0;\n while ((2^^lg) < n) lg++;\n this.lg = lg;\n sz = 2^^lg;\n\n s = new S[](2*sz);\n s.each!((ref x) => x = S(eT, eL));\n foreach (i; 0..n) {\n s[sz+i].d = first[i];\n }\n foreach_reverse (i; 1..sz) {\n update(i);\n }\n }\n @property uint length() const { return n; }\n pragma(inline):\n private void lzAdd(uint k, in L x) {\n s[k].lz = opLL(s[k].lz, x);\n s[k].d = opTL(s[k].d, x);\n }\n public void push(uint k) {\n if (s[k].lz == eL) return;\n lzAdd(2*k, s[k].lz);\n lzAdd(2*k+1, s[k].lz);\n s[k].lz = eL;\n }\n private void update(uint k) {\n s[k].d = opTT(s[2*k].d, s[2*k+1].d);\n }\n T single(uint k) {\n k += sz;\n foreach_reverse (uint i; 1..lg+1) {\n push(k>>i);\n }\n return s[k].d;\n }\n void singleSet(uint k, T x) {\n k += sz;\n foreach_reverse (uint i; 1..lg+1) {\n push(k>>i);\n }\n s[k].d = x;\n foreach (uint i; 1..lg+1) {\n update(k>>i);\n }\n }\n T sum(uint a, uint b) {\n assert(0 <= a && a <= b && b <= n);\n if (a == b) return eT;\n a += sz; b--; b += sz;\n uint tlg = lg;\n while (true) {\n uint k = a >> tlg;\n if (a >> tlg != b >> tlg) {\n tlg++;\n break;\n }\n if (((a-1) >> tlg) + 2 == (b+1) >> tlg) return s[k].d;\n push(k);\n tlg--;\n }\n T sm = eT;\n foreach_reverse (l; 0..tlg) {\n uint k = a >> l;\n if ((a-1)>>l != a>>l) {\n sm = opTT(s[k].d, sm);\n break;\n }\n push(k);\n if (!((a >> (l-1)) & 1)) sm = opTT(s[2*k+1].d, sm);\n }\n foreach_reverse (l; 0..tlg) {\n uint k = b >> l;\n if (b>>l != (b+1)>>l) {\n sm = opTT(sm, s[k].d);\n break;\n }\n push(k);\n if ((b >> (l-1)) & 1) sm = opTT(sm, s[2*k].d);\n }\n return sm;\n }\n void add(uint a, uint b, L x) {\n assert(0 <= a && a <= b && b <= n);\n if (a == b) return;\n a += sz; b--; b += sz;\n uint tlg = lg;\n while (true) {\n uint k = a >> tlg;\n if (a >> tlg != b >> tlg) {\n tlg++;\n break;\n }\n if (((a-1) >> tlg) + 2 == (b+1) >> tlg) {\n lzAdd(k, x);\n foreach (l; tlg+1..lg+1) {\n update(a >> l);\n }\n return;\n }\n push(k);\n tlg--;\n }\n foreach_reverse (l; 0..tlg) {\n uint k = a >> l;\n if ((a-1)>>l != a>>l) {\n lzAdd(k, x);\n foreach (h; l+1..tlg) {\n update(a >> h);\n }\n break;\n }\n push(k);\n if (!((a >> (l-1)) & 1)) lzAdd(2*k+1, x);\n }\n foreach_reverse (l; 0..tlg) {\n uint k = b >> l;\n if (b>>l != (b+1)>>l) {\n lzAdd(k, x);\n foreach (h; l+1..tlg) {\n update(b >> h);\n }\n break;\n }\n push(k);\n if ((b >> (l-1)) & 1) lzAdd(2*k, x);\n }\n foreach (l; tlg..lg+1) {\n update(a >> l);\n }\n }\n}\n\n \n\nint binSearchLazy(bool rev, alias pred, TR)(TR t, int a, int b) {\n import std.traits : TemplateArgsOf;\n alias args = TemplateArgsOf!TR;\n alias opTT = args[2];\n auto x = args[5];\n with (t) {\n static if (!rev) {\n \n if (pred(x)) return a-1;\n int pos = a;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {\n x = opTT(x, s[k].d);\n pos = r;\n return;\n }\n if (l+1 == r) return;\n push(k);\n int md = (l+r)/2;\n f(a, b, l, md, 2*k);\n if (pos >= md) f(a, b, md, r, 2*k+1);\n }\n f(a, b, 0, sz, 1);\n return pos;\n } else {\n \n if (pred(x)) return b;\n int pos = b-1;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {\n x = opTT(s[k].d, x);\n pos = l-1;\n return;\n }\n if (l+1 == r) return;\n push(k);\n int md = (l+r)/2;\n f(a, b, md, r, 2*k+1);\n if (pos < md) f(a, b, l, md, 2*k);\n }\n f(a, b, 0, sz, 1);\n return pos; \n }\n }\n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n private File f;\n \n this(File f) {\n this.f = f;\n }\n private char[512] lineBuf;\n private char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n assert(succW());\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n \n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n \n void read(Args...)(auto ref Args args) {\n import std.exception : enforce;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n \n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nenum {none = 0, matching = 1, indSet = 2};\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, m;\n\t\treadf !(\" %s %s\") (n, m);\n\t\talias Edge = Tuple !(int, q{d}, int, q{num});\n\t\tauto adj = new Edge [] [n * 3];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tadj[u] ~= Edge (v, j);\n\t\t\tadj[v] ~= Edge (u, j);\n\t\t}\n\n\t\tauto state = new int [n * 3];\n\t\tint [] edges;\n\t\tint [] vertices;\n\nuLoop:\n\t\tforeach (u; 0..n * 3)\n\t\t{\n\t\t\tif (state[u] == none)\n\t\t\t{\n\t\t\t\tforeach (e; adj[u])\n\t\t\t\t{\n\t\t\t\t\tif (state[e.d] == none)\n\t\t\t\t\t{\n\t\t\t\t\t\tstate[u] = matching;\n\t\t\t\t\t\tstate[e.d] = matching;\n\t\t\t\t\t\tedges ~= e.num + 1;\n\t\t\t\t\t\tcontinue uLoop;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstate[u] = indSet;\n\t\t\t\tvertices ~= u + 1;\n\t\t\t}\n\t\t}\n\n\t\tif (edges.length >= n)\n\t\t{\n\t\t\twriteln (\"Matching\");\n\t\t\twritefln !(\"%(%s %)\") (edges[0..n]);\n\t\t}\n\t\telse if (vertices.length >= n)\n\t\t{\n\t\t\twriteln (\"IndSet\");\n\t\t\twritefln !(\"%(%s %)\") (vertices[0..n]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tassert (false);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "0cca30daffe672caa6a6fdbb6a935f43"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid solve() {\n readln;\n int[] arr = readln.splitter.map!(to!int).array;\n writeln(arr.front);\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach(_;0..TC) solve();\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (a.back);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "329ac6671e26b73ab70749ca509f5b09"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto l = new long[](n);\r\n\t\tauto r = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tl[i] = RD;\r\n\t\t\tr[i] = RD;\r\n\t\t}\r\n\t\tauto edges = new int[][](n);\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tauto u = RD!int-1;\r\n\t\t\tauto v = RD!int-1;\r\n\t\t\tedges[u] ~= v;\r\n\t\t\tedges[v] ~= u;\r\n\t\t}\r\n\r\n\t\tlong[][] dfs(int pos, int last)\r\n\t\t{\r\n\t\t\tlong[][] res = [[l[pos], 0], [r[pos], 0]];\r\n\t\t\tforeach (v; edges[pos])\r\n\t\t\t{\r\n\t\t\t\tif (v == last) continue;\r\n\t\t\t\tauto tmp = dfs(v, pos);\r\n\t\t\t\tauto ll = abs(tmp[0][0] - l[pos]) + tmp[0][1];\r\n\t\t\t\tauto lr = abs(tmp[0][0] - r[pos]) + tmp[0][1];\r\n\t\t\t\tauto rl = abs(tmp[1][0] - l[pos]) + tmp[1][1];\r\n\t\t\t\tauto rr = abs(tmp[1][0] - r[pos]) + tmp[1][1];\r\n\t\t\t\tres[0][1] += max(ll, rl);\r\n\t\t\t\tres[1][1] += max(lr, rr);\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\t\tauto res = dfs(0, -1);\r\n\t\tans[ti] = max(res[0][1], res[1][1]);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto lo = new int [n];\r\n\t\tauto hi = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s\") (lo[i], hi[i]);\r\n\t\t}\r\n\t\tauto adj = new int [] [n];\r\n\t\tforeach (i; 0..n - 1)\r\n\t\t{\r\n\t\t\tint u, v;\r\n\t\t\treadf !(\" %s %s\") (u, v);\r\n\t\t\tu -= 1;\r\n\t\t\tv -= 1;\r\n\t\t\tadj[u] ~= v;\r\n\t\t\tadj[v] ~= u;\r\n\t\t}\r\n\t\treadln;\r\n\r\n\t\tauto f = new long [2] [n];\r\n\r\n\t\tlong recur (int v, int p)\r\n\t\t{\r\n\t\t\tforeach (u; adj[v])\r\n\t\t\t{\r\n\t\t\t\tif (u != p)\r\n\t\t\t\t{\r\n\t\t\t\t\trecur (u, v);\r\n\t\t\t\t\tf[v][0] += max (\r\n\t\t\t\t\t f[u][0] + abs (lo[v] - lo[u]),\r\n\t\t\t\t\t f[u][1] + abs (lo[v] - hi[u]));\r\n\t\t\t\t\tf[v][1] += max (\r\n\t\t\t\t\t f[u][0] + abs (hi[v] - lo[u]),\r\n\t\t\t\t\t f[u][1] + abs (hi[v] - hi[u]));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn max (f[v][0], f[v][1]);\r\n\t\t}\r\n\r\n\t\twriteln (recur (0, -1));\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math;\n\nlong solve2(int root, long[][] dp, long[] l, long[] r, int[][] vtx, bool[] visited)\n{\n if (visited[root])\n return 0;\n\n visited[root] = true;\n\n if (dp[0][root] != -1L && dp[1][root] != -1L)\n return max(dp[0][root], dp[1][root]);\n\n long best_beauty_l = 0;\n long best_beauty_r = 0;\n\n foreach (leaf ; vtx[root]) {\n if (visited[leaf])\n continue;\n if (dp[0][leaf] == -1L || dp[1][leaf] == -1L)\n solve2(leaf, dp, l, r, vtx, visited);\n long beauty_ll = abs(l[root] - l[leaf]) + dp[0][leaf];\n long beauty_lr = abs(l[root] - r[leaf]) + dp[1][leaf];\n long beauty_rl = abs(r[root] - l[leaf]) + dp[0][leaf];\n long beauty_rr = abs(r[root] - r[leaf]) + dp[1][leaf];\n long beauty_l = max(beauty_ll, beauty_lr);\n long beauty_r = max(beauty_rl, beauty_rr);\n// writeln(beauty_l);\n// writeln(beauty_r);\n best_beauty_l += beauty_l;\n best_beauty_r += beauty_r;\n }\n\n dp[0][root] = best_beauty_l;\n dp[1][root] = best_beauty_r;\n return max(dp[0][root], dp[1][root]);\n}\n\nlong solve()\n{\n int n;\n readf!(\" %d\")(n);\n auto dp = new long[][](2, n);\n auto l = new long[](n);\n auto r = new long[](n);\n auto vtx = new int[][](n, 0);\n auto visited = new bool[](n);\n dp[0][] = -1L;\n dp[1][] = -1L;\n\n for (int j = 0; j < n; j++) {\n readf!(\" %d %d\")(l[j], r[j]);\n }\n for (int j = 0; j < n - 1; j++) {\n int u, v;\n readf!(\" %d %d\")(u, v);\n vtx[u - 1] ~= v - 1;\n vtx[v - 1] ~= u - 1;\n }\n/*\n writeln(vtx);\n foreach (i, x ; vtx) {\n printf(\"%d => \", i + 1);\n writeln(x.map!(a => a + 1));\n }\n*/\n/*\n long best = -1;\n for (int j = 0; j < n; j++) {\n best = max(best, solve2(j, dp, l, r, vtx, visited));\n }\n*/\n long best = solve2(0, dp, l, r, vtx, visited);\n\n// writeln(dp);\n return best;\n}\n\nvoid main()\n{\n int t;\n readf!(\" %d\")(t);\n\n for (int i = 0; i < t; i++) {\n writeln(solve());\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math;\n\nlong solve2(int root, long[][] dp, long[] l, long[] r, int[][] vtx)\n{\n if (dp[0][root] != -1L && dp[1][root] != -1L)\n return max(dp[0][root], dp[1][root]);\n\n if (vtx[root].length == 0) {\n dp[0][root] = 0;\n dp[1][root] = 0;\n return 0;\n }\n\n long best_beauty_l = 0;\n long best_beauty_r = 0;\n\n foreach (leaf ; vtx[root]) {\n if (dp[0][leaf] == -1L || dp[1][leaf] == -1L)\n solve2(leaf, dp, l, r, vtx);\n long beauty_ll = abs(l[root] - l[leaf]) + dp[0][leaf];\n long beauty_lr = abs(l[root] - r[leaf]) + dp[1][leaf];\n long beauty_rl = abs(r[root] - l[leaf]) + dp[0][leaf];\n long beauty_rr = abs(r[root] - r[leaf]) + dp[1][leaf];\n long beauty_l = max(beauty_ll, beauty_lr);\n long beauty_r = max(beauty_rl, beauty_rr);\n// writeln(beauty_l);\n// writeln(beauty_r);\n best_beauty_l += beauty_l;\n best_beauty_r += beauty_r;\n }\n\n dp[0][root] = best_beauty_l;\n dp[1][root] = best_beauty_r;\n return max(dp[0][root], dp[1][root]);\n}\n\nlong solve()\n{\n int n;\n readf!(\" %d\")(n);\n auto dp = new long[][](2, n);\n auto l = new long[](n);\n auto r = new long[](n);\n auto vtx = new int[][](n, 0);\n dp[0][] = -1L;\n dp[1][] = -1L;\n// writeln(dp);\n\n for (int j = 0; j < n; j++) {\n readf!(\" %d %d\")(l[j], r[j]);\n }\n for (int j = 0; j < n - 1; j++) {\n int u, v;\n readf!(\" %d %d\")(u, v);\n vtx[v - 1] ~= u - 1;\n }\n\n// writeln(vtx);\n\n long best = -1;\n for (int j = 0; j < n; j++) {\n best = max(best, solve2(j, dp, l, r, vtx));\n }\n\n// writeln(dp);\n return best;\n}\n\nvoid main()\n{\n int t;\n readf!(\" %d\")(t);\n\n for (int i = 0; i < t; i++) {\n writeln(solve());\n }\n}\n"}], "src_uid": "a5063294f814f359f7ab6b7b801eaf3e"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint rows, cols;\n\twhile (readf (\" %s %s\", &rows, &cols) > 0)\n\t{\n\t\treadln;\n\t\tauto a = new bool [] [] (rows + 2, cols + 2);\n\t\tforeach (row; 1..rows + 1)\n\t\t{\n\t\t\tauto s = readln.strip;\n\t\t\tforeach (col; 1..cols + 1)\n\t\t\t{\n\t\t\t\ta[row][col] = (s[col - 1] == '*');\n\t\t\t}\n\t\t}\n\t\trows += 2;\n\t\tcols += 2;\n\n\t\tauto dr = new int [] [] (rows, cols);\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint val = -1;\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tif (a[row][col])\n\t\t\t\t{\n\t\t\t\t\tval += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tval = -1;\n\t\t\t\t}\n\t\t\t\tdr[row][col] = val;\n\t\t\t}\n\t\t}\n\n\t\tauto dl = new int [] [] (rows, cols);\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint val = -1;\n\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t{\n\t\t\t\tif (a[row][col])\n\t\t\t\t{\n\t\t\t\t\tval += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tval = -1;\n\t\t\t\t}\n\t\t\t\tdl[row][col] = val;\n\t\t\t}\n\t\t}\n\n\t\tauto dd = new int [] [] (rows, cols);\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint val = -1;\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tif (a[row][col])\n\t\t\t\t{\n\t\t\t\t\tval += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tval = -1;\n\t\t\t\t}\n\t\t\t\tdd[row][col] = val;\n\t\t\t}\n\t\t}\n\n\t\tauto du = new int [] [] (rows, cols);\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint val = -1;\n\t\t\tforeach_reverse (row; 0..rows)\n\t\t\t{\n\t\t\t\tif (a[row][col])\n\t\t\t\t{\n\t\t\t\t\tval += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tval = -1;\n\t\t\t\t}\n\t\t\t\tdu[row][col] = val;\n\t\t\t}\n\t\t}\n\n\t\tint res = 0;\n\t\tauto mr = new int [] [] (rows, cols);\n\t\tauto ml = new int [] [] (rows, cols);\n\t\tauto md = new int [] [] (rows, cols);\n\t\tauto mu = new int [] [] (rows, cols);\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tauto d = min (dr[row][col], dl[row][col],\n\t\t\t\t dd[row][col], du[row][col]);\n\t\t\t\tif (d <= 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint r = d * 2 + 1;\n\t\t\t\tres += 1;\n\t\t\t\tmr[row][col - d] = max (mr[row][col - d], r);\n\t\t\t\tml[row][col + d] = max (ml[row][col + d], r);\n\t\t\t\tmd[row - d][col] = max (md[row - d][col], r);\n\t\t\t\tmu[row + d][col] = max (mu[row + d][col], r);\n\t\t\t}\n\t\t}\n\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint val = 0;\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tval = max (val, mr[row][col]);\n\t\t\t\tif (val > 0)\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = false;\n\t\t\t\t\tval -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint val = 0;\n\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t{\n\t\t\t\tval = max (val, ml[row][col]);\n\t\t\t\tif (val > 0)\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = false;\n\t\t\t\t\tval -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint val = 0;\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tval = max (val, md[row][col]);\n\t\t\t\tif (val > 0)\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = false;\n\t\t\t\t\tval -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint val = 0;\n\t\t\tforeach_reverse (row; 0..rows)\n\t\t\t{\n\t\t\t\tval = max (val, mu[row][col]);\n\t\t\t\tif (val > 0)\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = false;\n\t\t\t\t\tval -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdebug {writefln (\"%(%(%d %)\\n%)\", a);}\n\t\tif (a.any !(any))\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\n\t\twriteln (res);\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tauto d = min (dr[row][col], dl[row][col],\n\t\t\t\t dd[row][col], du[row][col]);\n\t\t\t\tif (d <= 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\twriteln (row, \" \", col, \" \", d);\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n dchar[][] arr;\n arr ~= (cast(dchar)'.').repeat(m).array;\n foreach (_; 0 .. n) arr ~= readln.chomp.to!(dchar[]);\n arr ~= (cast(dchar)'.').repeat(m).array;\n \n foreach (ref rw; arr) rw = cast(dchar)'.' ~ rw ~ cast(dchar)'.';\n \n debug { arr.writeln; }\n \n auto covered = new bool[][] (n+1, m+1);\n Tuple!(int, int, int)[] ans;\n foreach (i, rw; arr) {\n foreach (j, el; rw) {\n if (el != '*') continue;\n \n int range = 0;\n while (arr[i-range-1][j] == '*' && arr[i+range+1][j] == '*'\n && arr[i][j-range-1] == '*' && arr[i][j+range+1] == '*') {\n covered[i-range-1][j] = true;\n covered[i+range+1][j] = true;\n covered[i][j-range-1] = true;\n covered[i][j+range+1] = true;\n ++range;\n }\n \n if (range > 0) {\n covered[i][j] = true;\n ans ~= tuple(cast(int)i, cast(int)j, range);\n }\n }\n }\n \n foreach (i, rw; covered) {\n foreach (j, e; rw) {\n if (arr[i][j] == '*' && !covered[i][j]) {\n writeln(-1);\n return;\n }\n }\n }\n \n ans.length.writeln;\n ans.each!(t => writeln(t[0], ' ', t[1], ' ', t[2]));\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint rows, cols;\n\twhile (readf (\" %s %s\", &rows, &cols) > 0)\n\t{\n\t\treadln;\n\t\tauto a = new bool [] [] (rows + 2, cols + 2);\n\t\tforeach (row; 1..rows + 1)\n\t\t{\n\t\t\tauto s = readln.strip;\n\t\t\tforeach (col; 1..cols + 1)\n\t\t\t{\n\t\t\t\ta[row][col] = (s[col - 1] == '*');\n\t\t\t}\n\t\t}\n\t\trows += 2;\n\t\tcols += 2;\n\n\t\tauto dr = new int [] [] (rows, cols);\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint val = -1;\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tif (a[row][col])\n\t\t\t\t{\n\t\t\t\t\tval += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tval = -1;\n\t\t\t\t}\n\t\t\t\tdr[row][col] = val;\n\t\t\t}\n\t\t}\n\n\t\tauto dl = new int [] [] (rows, cols);\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint val = -1;\n\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t{\n\t\t\t\tif (a[row][col])\n\t\t\t\t{\n\t\t\t\t\tval += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tval = -1;\n\t\t\t\t}\n\t\t\t\tdl[row][col] = val;\n\t\t\t}\n\t\t}\n\n\t\tauto dd = new int [] [] (rows, cols);\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint val = -1;\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tif (a[row][col])\n\t\t\t\t{\n\t\t\t\t\tval += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tval = -1;\n\t\t\t\t}\n\t\t\t\tdd[row][col] = val;\n\t\t\t}\n\t\t}\n\n\t\tauto du = new int [] [] (rows, cols);\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint val = -1;\n\t\t\tforeach_reverse (row; 0..rows)\n\t\t\t{\n\t\t\t\tif (a[row][col])\n\t\t\t\t{\n\t\t\t\t\tval += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tval = -1;\n\t\t\t\t}\n\t\t\t\tdu[row][col] = val;\n\t\t\t}\n\t\t}\n\n\t\tint res = 0;\n\t\tauto mr = new int [] [] (rows, cols);\n\t\tauto ml = new int [] [] (rows, cols);\n\t\tauto md = new int [] [] (rows, cols);\n\t\tauto mu = new int [] [] (rows, cols);\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tauto d = min (dr[row][col], dl[row][col],\n\t\t\t\t dd[row][col], du[row][col]);\n\t\t\t\tif (d <= 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint r = d * 2 + 1;\n\t\t\t\tres += 1;\n\t\t\t\tmr[row][col - d] = max (mr[row][col - d], r);\n\t\t\t\tml[row][col + d] = max (ml[row][col + d], r);\n\t\t\t\tmd[row - d][col] = max (md[row - d][col], r);\n\t\t\t\tmu[row + d][col] = max (mu[row + d][col], r);\n\t\t\t}\n\t\t}\n\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint val = 0;\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tval = max (val, mr[row][col]);\n\t\t\t\tif (val > 0)\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = false;\n\t\t\t\t\tval -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint val = 0;\n\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t{\n\t\t\t\tval = max (val, ml[row][col]);\n\t\t\t\tif (val > 0)\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = false;\n\t\t\t\t\tval -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint val = 0;\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tval = max (val, md[row][col]);\n\t\t\t\tif (val > 0)\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = false;\n\t\t\t\t\tval -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint val = 0;\n\t\t\tforeach_reverse (row; 0..rows)\n\t\t\t{\n\t\t\t\tval = max (val, mu[row][col]);\n\t\t\t\tif (val > 0)\n\t\t\t\t{\n\t\t\t\t\ta[row][col] = false;\n\t\t\t\t\tval -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdebug {writefln (\"%(%(%d %)\\n%)\", a);}\n\t\tif (a.any !(any))\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\n\t\twriteln (res);\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tauto d = min (dr[row][col], dl[row][col],\n\t\t\t\t dd[row][col], du[row][col]);\n\t\t\t\tif (d <= 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\twriteln (row, \" \", col, \" \", d);\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n dchar[][] arr;\n arr ~= (cast(dchar)'.').repeat(m).array;\n foreach (_; 0 .. n) arr ~= readln.chomp.to!(dchar[]);\n arr ~= (cast(dchar)'.').repeat(m).array;\n \n foreach (ref rw; arr) rw = cast(dchar)'.' ~ rw ~ cast(dchar)'.';\n \n debug { arr.writeln; }\n \n auto reach = new int[][][] (n+2, m+2, 4);\n foreach (i, rw; arr) {\n foreach (j, e; rw) {\n if (e == '.') reach[i][j][0] = reach[i][j][1] = 0;\n else {\n reach[i][j][0] = 1 + reach[i-1][j][0];\n reach[i][j][1] = 1 + reach[i][j-1][1];\n }\n }\n }\n foreach_reverse (i, rw; arr) {\n foreach_reverse (j, e; rw) {\n if (e == '.') reach[i][j][2] = reach[i][j][3] = 0;\n else {\n reach[i][j][2] = 1 + reach[i+1][j][2];\n reach[i][j][3] = 1 + reach[i][j+1][3];\n }\n \n }\n }\n \n auto cnt = new int[][][] (2, n+2, m+2);\n Tuple!(int, int, int)[] ans;\n foreach (i, rw; arr) {\n foreach (j, el; rw) {\n if (el != '*') continue;\n \n int range = reach[i][j].minElement - 1;\n \n if (range > 0) {\n cnt[0][i][j-range] += 1;\n cnt[0][i][j+range+1] -= 1;\n cnt[1][i-range][j] += 1;\n cnt[1][i+range+1][j] -= 1;\n ans ~= tuple(cast(int)i, cast(int)j, range);\n }\n }\n }\n \n foreach (ref rw; cnt[0]) {\n rw = rw.cumulativeFold!((a, b) => a + b).array;\n }\n foreach (i, rw; cnt[1]) {\n foreach (j, ref e; rw) {\n if (i > 0) e += cnt[1][i-1][j];\n }\n }\n \n foreach (i, rw; arr) {\n foreach (j, e; rw) {\n if (e == '.') continue;\n if (!cnt[0][i][j] && !cnt[1][i][j]) {\n writeln(-1);\n return;\n }\n }\n }\n \n ans.length.writeln;\n ans.each!(t => writeln(t[0], ' ', t[1], ' ', t[2]));\n}"}], "negative_code": [], "src_uid": "59d4c66892fa3157d1163225a550a368"} {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nint N;\nint[] A;\nvoid main() {\n scanf(\"%d\\n\", &N);\n A = readln.chomp.split(\" \").map!(to!int).array;\n int[] L1 = new int[N];\n int[] L2 = new int[N];\n\n L1[0] = 1;\n foreach (i; 0 .. N - 1) {\n if (A[i] + 1 <= A[i + 1]) {\n L1[i + 1] = L1[i] + 1;\n } else {\n L1[i + 1] = 1;\n }\n }\n\n L2[N - 1] = 1;\n for (int i = N - 1; i > 0; i--) {\n if (A[i - 1] + 1 <= A[i]) {\n L2[i - 1] = L2[i] + 1;\n } else {\n L2[i - 1] = 1;\n }\n }\n //writeln(L1);\n //writeln(L2);\n\n int Ans = L1.reduce!max;\n if (N > 1 && L2[0] == 1) Ans = max(Ans, L2[1] + 1);\n if (N > 1 && L1[$ - 1] == 1) Ans = max(Ans, L1[$ - 2] + 1);\n foreach (i; 0 .. N - 2) {\n if (A[i] >= A[i + 1]) {\n Ans = max(Ans, L1[i] + 1, L2[i + 1] + 1);\n }\n if (A[i] + 2 <= A[i + 2]) {\n Ans = max(Ans, L1[i] + L2[i + 2] + 1);\n }\n }\n writeln(Ans);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n \n auto dp = new int[][](2, N);\n dp[0][0] = dp[1][N-1] = 1;\n \n foreach (i; 1..N) {\n dp[0][i] = (A[i] > A[i-1]) ? dp[0][i-1] + 1 : 1;\n dp[1][N-i-1] = (A[N-i] > A[N-i-1]) ? dp[1][N-i] + 1 : 1;\n }\n\n \n int ans = 0;\n \n foreach (i; 0..N) ans = max(max(ans, dp[0][i]+1), dp[1][i]+1);\n foreach (i; 0..N-2) if (A[i+2] - A[i] >= 2) ans = max(ans, dp[0][i]+dp[1][i+2]+1);\n\n writeln(min(ans, N));\n}\n"}, {"source_code": "import std.stdio, std.string;\n\nvoid update(ref int tar, int val)\n{\n if (val > tar)\n {\n tar = val;\n }\n}\n\nvoid solve(int[] a)\n{\n auto pre = new int[a.length];\n auto len = new int[a.length];\n pre[0] = 0;\n len[0] = 1;\n foreach (i; 1 .. a.length)\n {\n if (a[i] > a[i - 1])\n {\n pre[i] = pre[i - 1];\n }\n else\n {\n pre[i] = i;\n }\n len[i] = i - pre[i] + 1;\n }\n int ans = 0;\n foreach (i; 0 .. a.length)\n {\n update(ans, len[i]);\n int idx = pre[i];\n if (idx > 0)\n {\n update(ans, len[i] + 1);\n if (len[i] == 1)\n {\n update(ans, len[idx - 1] + 1);\n }\n }\n if (idx > 1)\n {\n if (a[idx] - a[idx - 2] > 1)\n {\n update(ans, len[i] + 1 + len[idx - 2]);\n }\n if (len[i] > 1)\n {\n if (a[idx + 1] - a[idx - 1] > 1)\n {\n update(ans, len[i] + len[idx - 1]);\n }\n }\n }\n }\n writefln(\"%d\", ans);\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n scanf(\"%d\", &a[i]);\n }\n solve(a);\n }\n}"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nint[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tint[] ls = new int[N];\n\t\tint[] rs = new int[N];\n\t\tls[0] = 0;\n\t\tforeach (i; 1 .. N) {\n\t\t\tls[i] = (A[i - 1] < A[i]) ? ls[i - 1] : i;\n\t\t}\n\t\trs[N - 1] = N - 1;\n\t\tforeach_reverse (i; 0 .. N - 1) {\n\t\t\trs[i] = (A[i] < A[i + 1]) ? rs[i + 1] : i;\n\t\t}\n\t\t\n\t\tint ans;\n\t\t\n\t\t//\tno change\n\t\tforeach (i; 0 .. N) {\n\t\t\tchmax(ans, rs[i] - i + 1);\n\t\t}\n\t\t\n\t\t//\tone change, one side\n\t\tforeach (i; 0 .. N) {\n\t\t\tif (i - 1 >= 0) {\n\t\t\t\tchmax(ans, i - ls[i - 1] + 1);\n\t\t\t}\n\t\t\tif (i + 1 < N) {\n\t\t\t\tchmax(ans, rs[i + 1] - i + 1);\n\t\t\t}\n\t\t}\n\t\t\n\t\t//\tone change, two sides\n\t\tforeach (i; 1 .. N - 1) {\n\t\t\tif (A[i + 1] - A[i - 1] >= 2) {\n\t\t\t\tchmax(ans, rs[i + 1] - ls[i - 1] + 1);\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nint N;\nint[] A;\nvoid main() {\n scanf(\"%d\\n\", &N);\n A = readln.chomp.split(\" \").map!(to!int).array;\n int[] L1 = new int[N];\n int[] L2 = new int[N];\n\n L1[0] = 1;\n foreach (i; 0 .. N - 1) {\n if (A[i] + 1 <= A[i + 1]) {\n L1[i + 1] = L1[i] + 1;\n } else {\n L1[i + 1] = 1;\n }\n }\n\n L2[N - 1] = 1;\n for (int i = N - 1; i > 0; i--) {\n if (A[i - 1] + 1 <= A[i]) {\n L2[i - 1] = L2[i] + 1;\n } else {\n L2[i - 1] = 1;\n }\n }\n\n int Ans = L1.reduce!max;\n if (N > 1 && L1[$ - 1] == 1) Ans = max(Ans, L1[$ - 2] + 1);\n foreach (i; 0 .. N - 2) {\n if (A[i] >= A[i + 1]) Ans = max(Ans, L1[i] + 1);\n if (A[i] + 2 <= A[i + 2]) {\n Ans = max(Ans, L1[i] + L2[i + 2] + 1);\n }\n }\n writeln(Ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nint N;\nint[] A;\nvoid main() {\n scanf(\"%d\\n\", &N);\n A = readln.chomp.split(\" \").map!(to!int).array;\n int[] L1 = new int[N];\n int[] L2 = new int[N];\n\n if (N == 2) {\n writeln(2);\n return;\n }\n\n L1[0] = 1;\n foreach (i; 0 .. N - 1) {\n if (A[i] + 1 <= A[i + 1]) {\n L1[i + 1] = L1[i] + 1;\n } else {\n L1[i + 1] = 1;\n }\n }\n\n L2[N - 1] = 1;\n for (int i = N - 1; i > 0; i--) {\n if (A[i - 1] + 1 <= A[i]) {\n L2[i - 1] = L2[i] + 1;\n } else {\n L2[i - 1] = 1;\n }\n }\n\n int Ans = L1.reduce!max;\n foreach (i; 0 .. N - 2) {\n if (A[i] >= A[i + 1]) Ans = max(Ans, L1[i] + 1);\n if (A[i] + 2 <= A[i + 2]) {\n Ans = max(Ans, L1[i] + L2[i + 2] + 1);\n }\n }\n writeln(Ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nint N;\nint[] A;\nvoid main() {\n scanf(\"%d\\n\", &N);\n A = readln.chomp.split(\" \").map!(to!int).array;\n int[] L1 = new int[N];\n int[] L2 = new int[N];\n\n if (N == 2) {\n writeln(2);\n return;\n }\n\n L1[0] = 1;\n foreach (i; 0 .. N - 1) {\n if (A[i] + 1 <= A[i + 1]) {\n L1[i + 1] = L1[i] + 1;\n } else {\n L1[i + 1] = 1;\n }\n }\n\n L2[N - 1] = 1;\n for (int i = N - 1; i > 0; i--) {\n if (A[i - 1] + 1 <= A[i]) {\n L2[i - 1] = L2[i] + 1;\n } else {\n L2[i - 1] = 1;\n }\n }\n\n int Ans = L1.reduce!max;\n if (L1[$ - 1] == 1) Ans = max(Ans, L1[$ - 2] + 1);\n foreach (i; 0 .. N - 2) {\n if (A[i] >= A[i + 1]) Ans = max(Ans, L1[i] + 1);\n if (A[i] + 2 <= A[i + 2]) {\n Ans = max(Ans, L1[i] + L2[i + 2] + 1);\n }\n }\n writeln(Ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nint N;\nint[] A;\nvoid main() {\n scanf(\"%d\\n\", &N);\n A = readln.chomp.split(\" \").map!(to!int).array;\n int[] L1 = new int[N];\n int[] L2 = new int[N];\n\n L1[0] = 1;\n foreach (i; 0 .. N - 1) {\n if (A[i] + 1 <= A[i + 1]) {\n L1[i + 1] = L1[i] + 1;\n } else {\n L1[i + 1] = 1;\n }\n }\n\n L2[N - 1] = 1;\n for (int i = N - 1; i > 0; i--) {\n if (A[i - 1] + 1 <= A[i]) {\n L2[i - 1] = L2[i] + 1;\n } else {\n L2[i - 1] = 1;\n }\n }\n //writeln(L1);\n //writeln(L2);\n\n int Ans = L1.reduce!max;\n if (N > 1 && L2[0] == 1) Ans = max(Ans, L2[1] + 1);\n if (N > 1 && L1[$ - 1] == 1) Ans = max(Ans, L1[$ - 2] + 1);\n foreach (i; 0 .. N - 2) {\n if (A[i] >= A[i + 1]) Ans = max(Ans, L1[i] + 1);\n if (A[i] + 2 <= A[i + 2]) {\n Ans = max(Ans, L1[i] + L2[i + 2] + 1);\n }\n }\n writeln(Ans);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n \n auto dp = new int[][](N, 3);\n dp[0][0] = 1;\n \n foreach (i; 1..N) {\n if (A[i] > A[i-1]) {\n dp[i][0] = dp[i-1][0] + 1;\n if (i > 1 && A[i] > A[i-2] + 1)\n dp[i][2] = dp[i-1][1] + 1;\n dp[i][2] = max(dp[i][2], dp[i-1][2]+1);\n }\n else {\n dp[i][0] = 1;\n dp[i][1] = dp[i-1][0]+1;\n dp[i][2] = 1;\n }\n }\n\n int ans = 0;\n foreach (i; 0..N) foreach (j; 0..2) ans = max(ans, dp[i][j]);\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n \n auto dp = new int[][](N, 3);\n dp[0][0] = 1;\n \n foreach (i; 1..N) {\n if (A[i] > A[i-1]) {\n dp[i][0] = dp[i-1][0] + 1;\n if (i > 1 && A[i] > A[i-2] + 1)\n dp[i][2] = dp[i-1][1] + 1;\n dp[i][2] = max(dp[i][2], dp[i-1][2]+1);\n }\n else {\n dp[i][0] = 1;\n dp[i][1] = dp[i-1][0]+1;\n dp[i][2] = 1;\n }\n }\n\n int ans = 0;\n foreach (i; 0..N) foreach (j; 0..3) ans = max(ans, dp[i][j]);\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n \n auto dp = new int[](N);\n dp[0] = 1;\n \n foreach (i; 1..N)\n dp[i] = (A[i] > A[i-1]) ? dp[i-1] + 1 : 1;\n\n \n int ans = 0;\n \n foreach (i; 0..N) ans = max(ans, dp[i]+1);\n foreach (i; 0..N-2) if (dp[i+2] - dp[i] >= 2) ans = max(ans, dp[i]+dp[i+2]+1);\n\n\n writeln(min(ans, N));\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n \n auto dp = new int[][](N, 2);\n dp[0][0] = dp[0][1] = 1;\n \n foreach (i; 1..N) {\n if (A[i] > A[i-1]) {\n dp[i][0] = dp[i-1][0] + 1;\n dp[i][1] = dp[i-1][1] + 1;\n }\n else {\n dp[i][0] = 1;\n dp[i][1] = max(dp[i-1][1], dp[i-1][0]+1);\n }\n }\n\n int ans = 0;\n foreach (i; 0..N) foreach (j; 0..2) ans = max(ans, dp[i][j]);\n writeln(ans);\n}\n"}], "src_uid": "9e0d271b9bada1364dfcb47297549652"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tint m = readInt!int;\n\tauto a = new long[][](2, m);\n\tauto score = new long[](m);\n\tforeach(ref row; a) foreach(ref cell; row) cell = readInt!long;\n\tauto pf1 = a[0].cumulativeFold!((a, b) => a + b).array;\n\tauto pf2 = a[1].cumulativeFold!((a, b) => a + b).array;\n\talias sum1 = (i, j) => (i > 0? pf1[j] - pf1[i - 1] : pf1[j]);\n\talias sum2 = (i, j) => (i > 0? pf2[j] - pf2[i - 1] : pf2[j]);\n\tforeach(i; 0 .. m)\n\t{\n\t\tscore[i] = sum1(0, i) + sum2(i, m - 1);\n\t}\n\tauto mxp = score.cumulativeFold!max.array; mxp[] -= a[0][0];\n\tauto mxs = score.reverse.cumulativeFold!max.array.reverse.array; mxs[] -= a[1][m-1];\n\tlong minAns = long.max;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto p1 = i > 0? sum2(0, i - 1) : 0;\n\t\tauto p2 = i + 1 < m? sum1(i + 1, m - 1) : 0;\n\t\tminAns = min(minAns, max(p1, p2));\n\t}\n\tminAns.writeln;\n}\n\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n\n\nimport std.algorithm;\nimport std.random;\n\nstruct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)\n{\n\talias This = typeof(this);\n\tsize_t length;\n\tsize_t realLength = 0;\n\tV[] _nodeFValue; \n\tU[] _nodeUpdate;\n\tbool[] _nodeHasUpdate;\n\tsize_t[] _nodeRangeEnd;\n\tsize_t[] _nodeRangeStart;\n\tstring toString()\n\t{\n\t\timport std.conv;\n\t\tstring str;\n\t\tforeach(i; 0 .. realLength)\n\t\t\tif (_nodeHasUpdate[i])\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \"(\", _nodeUpdate[i], \"), \");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \", \");\n\t\t\t}\n\t\treturn str;\n\t}\n\tthis(size_t length, V initialValue)\n\t{\n\t\tthis.length = length;\n\t\tsize_t noNodes = 4 * length;\n\t\t_nodeFValue = new V[](noNodes);\n\t\t_nodeUpdate = new U[](noNodes);\n\t\t_nodeHasUpdate = new bool[](noNodes);\n\t\t_nodeRangeEnd = new size_t[](noNodes);\n\t\t_nodeRangeStart = new size_t[](noNodes);\n\t\tvoid fill(size_t i, size_t rangeStart, size_t rangeEnd)\n\t\t{\n\t\t\trealLength = max(realLength, i + 1);\n\t\t\t_nodeRangeStart[i] = rangeStart;\n\t\t\t_nodeRangeEnd[i] = rangeEnd;\n\t\t\tif (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }\n\t\t\tsize_t l = i<<1;\n\t\t\tsize_t r = l+1;\n\t\t\tsize_t m = (rangeStart + rangeEnd) / 2;\n\t\t\tfill(l, rangeStart, m), fill(r, m + 1, rangeEnd);\n\t\t\t_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);\n\t\t}\n\t\tfill(1, 0, length - 1);\n\t}\n\tV rangeF(size_t start, size_t end)\n\t{\n\t\tbool set = false;\n\t\tV result;\n\t\tvoid visit(size_t i) in(_hasFragments(i, start, end))\n\t\t{\n\t\t\tif (_isFragment(i, start, end))\n\t\t\t{\n\t\t\t\tif (!set) { result = _cookedF(i); set = true; }\n\t\t\t\telse { result = f(result, _cookedF(i)); }\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_clearUpdate(i);\n\t\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t\tif (_hasFragments(l, start, end)) visit(l);\n\t\t\tif (_hasFragments(r, start, end)) visit(r);\n\t\t}\n\t\tvisit(1);\n\t\treturn result;\n\t}\n\tvoid rangeU(size_t start, size_t end, U u)\n\t{\n\t\tvoid visit(size_t i) in(_hasFragments(i, start, end))\n\t\t{\n\t\t\tif (_isFragment(i, start, end))\n\t\t\t{\n\t\t\t\t_addUpdate(i, u);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_clearUpdate(i);\n\t\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t\tif (_hasFragments(l, start, end)) visit(l);\n\t\t\tif (_hasFragments(r, start, end)) visit(r);\n\t\t\t_nodeFValue[i] = f(_cookedF(l), _cookedF(r));\n\t\t}\n\t\tvisit(1);\n\t}\n\tV _cookedF(size_t i)\n\t{\n\t\tif (_nodeHasUpdate[i]) { return fou(_nodeFValue[i], \n\t\t\t\t\t\t _nodeUpdate[i],\n\t\t\t\t\t\t _nodeRangeStart[i],\n\t\t\t\t\t\t _nodeRangeEnd[i]); }\n\t\treturn _nodeFValue[i];\n\t}\n\tvoid _clearUpdate(size_t i)\n\t{\n\t\tif (!_nodeHasUpdate[i]) return;\n\t\tif (_isLeaf(i)) { _nodeFValue[i] = _cookedF(i); _nodeHasUpdate[i] = false; return;}\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedF(l), _cookedF(r));\n\t\t_nodeHasUpdate[i] = false;\n\t}\n\tvoid _addUpdate(size_t i, U u)\n\t{\n\t\tif (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; return; }\n\t\t_nodeUpdate[i] = uou(_nodeUpdate[i], u);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn _nodeRangeStart[i] == _nodeRangeEnd[i];\n\t}\n\tbool _isFragment(size_t i, size_t rangeStart, size_t rangeEnd)\n\t{\n\t\treturn rangeStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= rangeEnd;\n\t}\n\tbool _hasFragments(size_t i, size_t rangeStart, size_t rangeEnd)\n\t{\n\t\treturn _nodeRangeStart[i] <= rangeEnd && rangeStart <= _nodeRangeEnd[i];\n\t}\n\t// prettifiers\n\tstruct Handle\n\t{\n\t\timport std.ascii;\n\t\tsize_t _start, _end;\n\t\tThis* _parent;\n\t\tauto f()\n\t\t{\n\t\t\treturn _parent.rangeF(_start, _end);\n\t\t}\n\t\tauto u(U v)\n\t\t{\n\t\t\t_parent.rangeU(_start, _end, v);\n\t\t}\n\t\tstatic if (fName !is null)\n\t\t{\n\t\t\tmixin(q{alias }, fName, q{ = f;});\n\t\t}\n\t\tstatic if (uName !is null)\n\t\t{\n\t\t\tstatic if (uName[0].isAlphaNum)\n\t\t\t{\n\t\t\t\tmixin(q{alias }, uName, q{ = u;});\n\t\t\t}\n\t\t\telse static if (uName[0] != ' ')\n\t\t\t{\n\t\t\t\tref Handle opOpAssign(string operator)(U v) \n\t\t\t\tif (operator == uName)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tref Handle opAssign(U v)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)\n\t{\n\t\treturn [s, e-1];\n\t}\n\tauto opIndex(size_t[2] slice)\n\t{\n\t\treturn Handle(slice[0], slice[1], &this);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n int m;\n readf!\" %d \"(m);\n auto a = readln.strip.split.map!(to!long).array;\n auto b = readln.strip.split.map!(to!long).array;\n\n long[] sfa = [0L];\n long sum;\n foreach_reverse (x ; a) {\n sum += x;\n sfa ~= sum;\n }\n long[] pfb = [0L];\n sum = 0;\n foreach (x ; b) {\n sum += x;\n pfb ~= sum;\n }\n\n long min_bobscore = long.max;\n foreach (i ; 0 .. m) {\n long bobscore1 = pfb[i];\n long bobscore2 = sfa[$ - i - 2];\n long bobscore = max(bobscore1, bobscore2);\n if (bobscore < min_bobscore)\n min_bobscore = bobscore;\n }\n writeln(min_bobscore);\n }\n}\n"}, {"source_code": "import std;\n\nT read (T, string ending = \"\", string beginning = \"\") () @trusted {\n scope T x;\n readf!(beginning ~ \"%s\" ~ ending)(x);\n return x;\n}\n\nvoid main () {\n immutable tests = read!(uint, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n immutable m = readln.chomp.to!uint;\n\n\n auto mat = (){\n auto result = appender!(uint[]);\n result.reserve(2 * m);\n\n foreach (line; stdin.byLine.take(2))\n result.put(line.splitter(' ').map!(to!uint));\n\n return chunks(result[].assumeUnique, m);\n }();\n\n immutable sum = mat[0].sum;\n\n StoppingPolicy.requireSameLength.zip(\n cumulativeFold!\"a - b\"(mat[0], sum),\n cumulativeFold!\"a + b\"(chain([0], mat[1].dropBackOne))\n ).map!\"max(a.expand)\".minElement.writeln;\n }\n}\n\n// \"\" `` '' () {} []\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tint m = readInt!int;\n\tauto a = new long[][](2, m);\n\tauto score = new long[](m);\n\tforeach(ref row; a) foreach(ref cell; row) cell = readInt!long;\n\tauto pf1 = a[0].cumulativeFold!((a, b) => a + b).array;\n\tauto pf2 = a[1].cumulativeFold!((a, b) => a + b).array;\n\talias sum1 = (i, j) => (i > 0? pf1[j] - pf1[i - 1] : pf1[j]);\n\talias sum2 = (i, j) => (i > 0? pf2[j] - pf2[i - 1] : pf2[j]);\n\tforeach(i; 0 .. m)\n\t{\n\t\tscore[i] = sum1(0, i) + sum2(i, m - 1);\n\t}\n\tauto mxp = score.cumulativeFold!max.array; mxp[] -= a[0][0];\n\tauto mxs = score.reverse.cumulativeFold!max.array.reverse.array; mxs[] -= a[1][m-1];\n\tlong minAns = long.max;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto p1 = i > 0? mxp[i - 1] - sum2(i, m - 1) : 0;\n\t\tauto p2 = i + 1 < m? mxs[i + 1] - sum1(0, i) : 0;\n\t\tminAns = min(minAns, max(p1, p2));\n\t}\n\tminAns.writeln;\n}\n\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n\n\nimport std.algorithm;\nimport std.random;\n\nstruct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)\n{\n\talias This = typeof(this);\n\tsize_t length;\n\tsize_t realLength = 0;\n\tV[] _nodeFValue; \n\tU[] _nodeUpdate;\n\tbool[] _nodeHasUpdate;\n\tsize_t[] _nodeRangeEnd;\n\tsize_t[] _nodeRangeStart;\n\tstring toString()\n\t{\n\t\timport std.conv;\n\t\tstring str;\n\t\tforeach(i; 0 .. realLength)\n\t\t\tif (_nodeHasUpdate[i])\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \"(\", _nodeUpdate[i], \"), \");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \", \");\n\t\t\t}\n\t\treturn str;\n\t}\n\tthis(size_t length, V initialValue)\n\t{\n\t\tthis.length = length;\n\t\tsize_t noNodes = 4 * length;\n\t\t_nodeFValue = new V[](noNodes);\n\t\t_nodeUpdate = new U[](noNodes);\n\t\t_nodeHasUpdate = new bool[](noNodes);\n\t\t_nodeRangeEnd = new size_t[](noNodes);\n\t\t_nodeRangeStart = new size_t[](noNodes);\n\t\tvoid fill(size_t i, size_t rangeStart, size_t rangeEnd)\n\t\t{\n\t\t\trealLength = max(realLength, i + 1);\n\t\t\t_nodeRangeStart[i] = rangeStart;\n\t\t\t_nodeRangeEnd[i] = rangeEnd;\n\t\t\tif (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }\n\t\t\tsize_t l = i<<1;\n\t\t\tsize_t r = l+1;\n\t\t\tsize_t m = (rangeStart + rangeEnd) / 2;\n\t\t\tfill(l, rangeStart, m), fill(r, m + 1, rangeEnd);\n\t\t\t_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);\n\t\t}\n\t\tfill(1, 0, length - 1);\n\t}\n\tV rangeF(size_t start, size_t end)\n\t{\n\t\tbool set = false;\n\t\tV result;\n\t\tvoid visit(size_t i) in(_hasFragments(i, start, end))\n\t\t{\n\t\t\tif (_isFragment(i, start, end))\n\t\t\t{\n\t\t\t\tif (!set) { result = _cookedF(i); set = true; }\n\t\t\t\telse { result = f(result, _cookedF(i)); }\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_clearUpdate(i);\n\t\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t\tif (_hasFragments(l, start, end)) visit(l);\n\t\t\tif (_hasFragments(r, start, end)) visit(r);\n\t\t}\n\t\tvisit(1);\n\t\treturn result;\n\t}\n\tvoid rangeU(size_t start, size_t end, U u)\n\t{\n\t\tvoid visit(size_t i) in(_hasFragments(i, start, end))\n\t\t{\n\t\t\tif (_isFragment(i, start, end))\n\t\t\t{\n\t\t\t\t_addUpdate(i, u);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_clearUpdate(i);\n\t\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t\tif (_hasFragments(l, start, end)) visit(l);\n\t\t\tif (_hasFragments(r, start, end)) visit(r);\n\t\t\t_nodeFValue[i] = f(_cookedF(l), _cookedF(r));\n\t\t}\n\t\tvisit(1);\n\t}\n\tV _cookedF(size_t i)\n\t{\n\t\tif (_nodeHasUpdate[i]) { return fou(_nodeFValue[i], \n\t\t\t\t\t\t _nodeUpdate[i],\n\t\t\t\t\t\t _nodeRangeStart[i],\n\t\t\t\t\t\t _nodeRangeEnd[i]); }\n\t\treturn _nodeFValue[i];\n\t}\n\tvoid _clearUpdate(size_t i)\n\t{\n\t\tif (!_nodeHasUpdate[i]) return;\n\t\tif (_isLeaf(i)) { _nodeFValue[i] = _cookedF(i); _nodeHasUpdate[i] = false; return;}\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedF(l), _cookedF(r));\n\t\t_nodeHasUpdate[i] = false;\n\t}\n\tvoid _addUpdate(size_t i, U u)\n\t{\n\t\tif (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; return; }\n\t\t_nodeUpdate[i] = uou(_nodeUpdate[i], u);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn _nodeRangeStart[i] == _nodeRangeEnd[i];\n\t}\n\tbool _isFragment(size_t i, size_t rangeStart, size_t rangeEnd)\n\t{\n\t\treturn rangeStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= rangeEnd;\n\t}\n\tbool _hasFragments(size_t i, size_t rangeStart, size_t rangeEnd)\n\t{\n\t\treturn _nodeRangeStart[i] <= rangeEnd && rangeStart <= _nodeRangeEnd[i];\n\t}\n\t// prettifiers\n\tstruct Handle\n\t{\n\t\timport std.ascii;\n\t\tsize_t _start, _end;\n\t\tThis* _parent;\n\t\tauto f()\n\t\t{\n\t\t\treturn _parent.rangeF(_start, _end);\n\t\t}\n\t\tauto u(U v)\n\t\t{\n\t\t\t_parent.rangeU(_start, _end, v);\n\t\t}\n\t\tstatic if (fName !is null)\n\t\t{\n\t\t\tmixin(q{alias }, fName, q{ = f;});\n\t\t}\n\t\tstatic if (uName !is null)\n\t\t{\n\t\t\tstatic if (uName[0].isAlphaNum)\n\t\t\t{\n\t\t\t\tmixin(q{alias }, uName, q{ = u;});\n\t\t\t}\n\t\t\telse static if (uName[0] != ' ')\n\t\t\t{\n\t\t\t\tref Handle opOpAssign(string operator)(U v) \n\t\t\t\tif (operator == uName)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tref Handle opAssign(U v)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)\n\t{\n\t\treturn [s, e-1];\n\t}\n\tauto opIndex(size_t[2] slice)\n\t{\n\t\treturn Handle(slice[0], slice[1], &this);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tint m = readInt!int;\n\tauto a = new long[][](2, m);\n\tauto score = SegmentTreeLazy!(long, long,\n\t\t\t(a, b) => max(a, b),\n\t\t\t(mx, u, rs, re) => u,\n\t\t\t(u1, u2) => u2,\n\t\t\t\"max\",\n\t\t\t\" \")(m, 0);\n\tforeach(ref row; a) foreach(ref cell; row) cell = readInt!int;\n\tauto pf1 = a[0].cumulativeFold!((a, b) => a + b).array;\n\tauto pf2 = a[1].cumulativeFold!((a, b) => a + b).array;\n\talias sum1 = (i, j) => (i > 0? pf1[j] - pf1[i - 1] : pf1[j]);\n\talias sum2 = (i, j) => (i > 0? pf2[j] - pf2[i - 1] : pf2[j]);\n\tforeach(i; 0 .. m)\n\t\tscore[i .. i + 1] = sum1(0, i) + sum2(i, m - 1);\n\tdebug \n\t{\n\t\tforeach(i; 0 .. m) score[i .. i + 1].max.write(\" \");\n\t\twriteln;\n\t}\n\tlong minAns = long.max;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto p1 = i > 0? score[0 .. i].max - sum2(i, m - 1) - a[0][0] : 0;\n\t\tauto p2 = i + 1 < m? score[i + 1 .. m].max - sum1(0, i) - a[1][m-1] : 0;\n\t\tdebug writeln(\"p1 = \", p1, \" p2 = \", p2);\n\t\tminAns = min(minAns, max(p1, p2));\n\t}\n\tminAns.writeln;\n}\n\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n\n\nimport std.algorithm;\nimport std.random;\n\nstruct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)\n{\n\talias This = typeof(this);\n\tsize_t length;\n\tsize_t realLength = 0;\n\tV[] _nodeFValue; \n\tU[] _nodeUpdate;\n\tbool[] _nodeHasUpdate;\n\tsize_t[] _nodeRangeEnd;\n\tsize_t[] _nodeRangeStart;\n\tstring toString()\n\t{\n\t\timport std.conv;\n\t\tstring str;\n\t\tforeach(i; 0 .. realLength)\n\t\t\tif (_nodeHasUpdate[i])\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \"(\", _nodeUpdate[i], \"), \");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstr ~= text(_nodeFValue[i], \", \");\n\t\t\t}\n\t\treturn str;\n\t}\n\tthis(size_t length, V initialValue)\n\t{\n\t\tthis.length = length;\n\t\tsize_t noNodes = 4 * length;\n\t\t_nodeFValue = new V[](noNodes);\n\t\t_nodeUpdate = new U[](noNodes);\n\t\t_nodeHasUpdate = new bool[](noNodes);\n\t\t_nodeRangeEnd = new size_t[](noNodes);\n\t\t_nodeRangeStart = new size_t[](noNodes);\n\t\tvoid fill(size_t i, size_t rangeStart, size_t rangeEnd)\n\t\t{\n\t\t\trealLength = max(realLength, i + 1);\n\t\t\t_nodeRangeStart[i] = rangeStart;\n\t\t\t_nodeRangeEnd[i] = rangeEnd;\n\t\t\tif (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }\n\t\t\tsize_t l = i<<1;\n\t\t\tsize_t r = l+1;\n\t\t\tsize_t m = (rangeStart + rangeEnd) / 2;\n\t\t\tfill(l, rangeStart, m), fill(r, m + 1, rangeEnd);\n\t\t\t_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);\n\t\t}\n\t\tfill(1, 0, length - 1);\n\t}\n\tV rangeF(size_t start, size_t end)\n\t{\n\t\tbool set = false;\n\t\tV result;\n\t\tvoid visit(size_t i) in(_hasFragments(i, start, end))\n\t\t{\n\t\t\tif (_isFragment(i, start, end))\n\t\t\t{\n\t\t\t\tif (!set) { result = _cookedF(i); set = true; }\n\t\t\t\telse { result = f(result, _cookedF(i)); }\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_clearUpdate(i);\n\t\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t\tif (_hasFragments(l, start, end)) visit(l);\n\t\t\tif (_hasFragments(r, start, end)) visit(r);\n\t\t}\n\t\tvisit(1);\n\t\treturn result;\n\t}\n\tvoid rangeU(size_t start, size_t end, U u)\n\t{\n\t\tvoid visit(size_t i) in(_hasFragments(i, start, end))\n\t\t{\n\t\t\tif (_isFragment(i, start, end))\n\t\t\t{\n\t\t\t\t_addUpdate(i, u);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_clearUpdate(i);\n\t\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t\tif (_hasFragments(l, start, end)) visit(l);\n\t\t\tif (_hasFragments(r, start, end)) visit(r);\n\t\t\t_nodeFValue[i] = f(_cookedF(l), _cookedF(r));\n\t\t}\n\t\tvisit(1);\n\t}\n\tV _cookedF(size_t i)\n\t{\n\t\tif (_nodeHasUpdate[i]) { return fou(_nodeFValue[i], \n\t\t\t\t\t\t _nodeUpdate[i],\n\t\t\t\t\t\t _nodeRangeStart[i],\n\t\t\t\t\t\t _nodeRangeEnd[i]); }\n\t\treturn _nodeFValue[i];\n\t}\n\tvoid _clearUpdate(size_t i)\n\t{\n\t\tif (!_nodeHasUpdate[i]) return;\n\t\tif (_isLeaf(i)) { _nodeFValue[i] = _cookedF(i); _nodeHasUpdate[i] = false; return;}\n\t\tsize_t l = i<<1, r = (i<<1)+1;\n\t\t_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);\n\t\t_nodeFValue[i] = f(_cookedF(l), _cookedF(r));\n\t\t_nodeHasUpdate[i] = false;\n\t}\n\tvoid _addUpdate(size_t i, U u)\n\t{\n\t\tif (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; return; }\n\t\t_nodeUpdate[i] = uou(_nodeUpdate[i], u);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn _nodeRangeStart[i] == _nodeRangeEnd[i];\n\t}\n\tbool _isFragment(size_t i, size_t rangeStart, size_t rangeEnd)\n\t{\n\t\treturn rangeStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= rangeEnd;\n\t}\n\tbool _hasFragments(size_t i, size_t rangeStart, size_t rangeEnd)\n\t{\n\t\treturn _nodeRangeStart[i] <= rangeEnd && rangeStart <= _nodeRangeEnd[i];\n\t}\n\t// prettifiers\n\tstruct Handle\n\t{\n\t\timport std.ascii;\n\t\tsize_t _start, _end;\n\t\tThis* _parent;\n\t\tauto f()\n\t\t{\n\t\t\treturn _parent.rangeF(_start, _end);\n\t\t}\n\t\tauto u(U v)\n\t\t{\n\t\t\t_parent.rangeU(_start, _end, v);\n\t\t}\n\t\tstatic if (fName !is null)\n\t\t{\n\t\t\tmixin(q{alias }, fName, q{ = f;});\n\t\t}\n\t\tstatic if (uName !is null)\n\t\t{\n\t\t\tstatic if (uName[0].isAlphaNum)\n\t\t\t{\n\t\t\t\tmixin(q{alias }, uName, q{ = u;});\n\t\t\t}\n\t\t\telse static if (uName[0] != ' ')\n\t\t\t{\n\t\t\t\tref Handle opOpAssign(string operator)(U v) \n\t\t\t\tif (operator == uName)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tref Handle opAssign(U v)\n\t\t\t\t{\n\t\t\t\t\tu(v);\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)\n\t{\n\t\treturn [s, e-1];\n\t}\n\tauto opIndex(size_t[2] slice)\n\t{\n\t\treturn Handle(slice[0], slice[1], &this);\n\t}\n}\n"}], "src_uid": "f3ee3a0de5ddf3cf15ef02fb62a2768e"} {"source_code": "import std.stdio, std.algorithm;\r\nlong solve(long[] a)\r\n{\r\n int n = cast(int) a.length;\r\n a.sort();\r\n return a[n / 2] - a[(n - 1) / 2] + 1;\r\n}\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n;\r\n readf!\"%d\\n\"(n);\r\n long[] a = new long[n], b = new long[n];\r\n foreach (i; 0 .. n)\r\n readf!\"%d %d\\n\"(a[i], b[i]);\r\n writeln(solve(a) * solve(b));\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto x = new long[](n);\r\n\t\tauto y = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tx[i] = RD;\r\n\t\t\ty[i] = RD;\r\n\t\t}\r\n\t\tx.sort;\r\n\t\ty.sort;\r\n\t\t\r\n\t\tlong a, b;\r\n\t\tif (n % 2)\r\n\t\t{\r\n\t\t\ta = 1;\r\n\t\t\tb = 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\ta = x[n/2] - x[n/2-1] + 1;\r\n\t\t\tb = y[n/2] - y[n/2-1] + 1;\r\n\t\t}\r\n\t\tans[ti] = a * b;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n int N; get(N);\r\n long[] xs, ys; get_lines(N, xs, ys);\r\n if (N % 2 == 1) {\r\n writeln(1);\r\n continue;\r\n }\r\n sort(xs);\r\n auto x = xs[N / 2] - xs[N / 2 - 1] + 1;\r\n sort(ys);\r\n auto y = ys[N / 2] - ys[N / 2 - 1] + 1;\r\n writeln(x * y);\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "e0a1dc397838852957d0e15ec98d5efe"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum E = 61;\n\nvoid main() {\n try {\n for (; ; ) {\n const Q = readInt();\n auto T = new int[Q];\n auto X = new long[Q];\n auto K = new long[Q];\n foreach (q; 0 .. Q) {\n T[q] = readInt();\n X[q] = readLong();\n if (T[q] == 1 || T[q] == 2) {\n K[q] = readLong();\n }\n }\n \n // e: [2^e, 2^(e+1))\n auto xs = new long[E];\n auto ys = new long[E];\n auto zs = new long[E];\n foreach (q; 0 .. Q) {\n int e = bsr(X[q]);\n switch (T[q]) {\n case 1: {\n (xs[e] += K[q]) &= ((1L << e) - 1);\n } break;\n case 2: {\n (ys[e] += K[q]) &= ((1L << e) - 1);\n long k = K[q] & ((1L << e) - 1);\n foreach (f; e .. E) {\n (zs[f] += k) &= ((1L << f) - 1);\n k <<= 1;\n }\n } break;\n case 3: {\n debug {\n writeln(\"query \", X[q]);\n writeln(\" xs = \", xs);\n writeln(\" ys = \", ys);\n writeln(\" zs = \", zs);\n }\n long[] ans;\n long u = X[q];\n // u = (1L << e) + ((u - (1L << e) - zs[e]) & ((1L << e) - 1));\n u = (1L << e) + ((u - (1L << e) + xs[e]) & ((1L << e) - 1));\n for (; ; ) {\n const val = (1L << e) + ((u - (1L << e) - xs[e]) & ((1L << e) - 1));\n ans ~= val;\n if (e == 0) {\n break;\n }\n u = (1L << e) + ((u - (1L << e) + ys[e]) & ((1L << e) - 1));\n u >>= 1;\n --e;\n }\n foreach (idx, val; ans) {\n if (idx > 0) write(\" \");\n write(val);\n }\n writeln();\n } break;\n default: assert(false);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid pickV(R,T...)(ref R r,ref T t){foreach(ref v;t)pick(r,v);}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int q; readV(q);\n\n auto v = new long[](64), n = new long[](64);\n\n foreach (_; 0..q) {\n auto rd = rdsp;\n int t; long x; pickV(rd, t, x);\n auto r = x.bsr, r2 = (1L<<r);\n switch (t) {\n case 1:\n long k; pick(rd, k);\n (v[r] += k%r2 + r2) %= r2;\n break;\n case 2:\n long k; pick(rd, k);\n (n[r] += k%r2 + r2) %= r2;\n break;\n case 3:\n auto s = new long[](r+1);\n foreach (i; 1..r+1) s[i] = (s[i-1]*2+n[i])%(1L<<i);\n\n auto ri = x.bitReset(r)+v[r]+s[r];\n foreach_reverse (i; 0..r+1) {\n auto si = (v[i]+s[i])%(1L<<i);\n auto y = (((1L<<i)-si+ri)%(1L<<i)).bitSet(i);\n write(y);\n if (i > 0) write(\" \");\n ri >>= 1;\n }\n writeln;\n break;\n default:\n assert(0);\n }\n }\n}\n\npragma(inline) {\n pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }\n pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }\n pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }\n pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }\n\n pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }\n pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }\n pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }\n\n import core.bitop;\n pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }\n pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }\n pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum E = 61;\n\nvoid main() {\n try {\n for (; ; ) {\n const Q = readInt();\n auto T = new int[Q];\n auto X = new long[Q];\n auto K = new long[Q];\n foreach (q; 0 .. Q) {\n T[q] = readInt();\n X[q] = readLong();\n if (T[q] == 1 || T[q] == 2) {\n K[q] = readLong();\n }\n }\n \n // e: [2^e, 2^(e+1))\n auto xs = new long[E];\n auto ys = new long[E];\n foreach (q; 0 .. Q) {\n int e = bsr(X[q]);\n switch (T[q]) {\n case 1: {\n (xs[e] += K[q]) &= ((1L << e) - 1);\n } break;\n case 2: {\n (ys[e] += K[q]) &= ((1L << e) - 1);\n } break;\n case 3: {\n debug {\n writeln(\"query \", X[q]);\n writeln(\" xs = \", xs);\n writeln(\" ys = \", ys);\n }\n long[] ans;\n long u = X[q];\n for (; ; ) {\n const val = (1L << e) + ((u - (1L << e) - xs[e]) & ((1L << e) - 1));\n ans ~= val;\n if (e == 0) {\n break;\n }\n u = (1L << e) + ((u - (1L << e) + ys[e]) & ((1L << e) - 1));\n u >>= 1;\n --e;\n }\n foreach (idx, val; ans) {\n if (idx > 0) write(\" \");\n write(val);\n }\n writeln();\n } break;\n default: assert(false);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum E = 61;\n\nvoid main() {\n try {\n for (; ; ) {\n const Q = readInt();\n auto T = new int[Q];\n auto X = new long[Q];\n auto K = new long[Q];\n foreach (q; 0 .. Q) {\n T[q] = readInt();\n X[q] = readLong();\n if (T[q] == 1 || T[q] == 2) {\n K[q] = readLong();\n }\n }\n \n // e: [2^e, 2^(e+1))\n auto xs = new long[E];\n auto ys = new long[E];\n auto zs = new long[E];\n foreach (q; 0 .. Q) {\n int e = bsr(X[q]);\n switch (T[q]) {\n case 1: {\n (xs[e] += K[q]) &= ((1L << e) - 1);\n } break;\n case 2: {\n (ys[e] += K[q]) &= ((1L << e) - 1);\n long k = K[q] & ((1L << e) - 1);\n foreach (f; e .. E) {\n (zs[f] += k) &= ((1L << f) - 1);\n k <<= 1;\n }\n } break;\n case 3: {\n debug {\n writeln(\"query \", X[q]);\n writeln(\" xs = \", xs);\n writeln(\" ys = \", ys);\n }\n long[] ans;\n long u = X[q];\n u = (1L << e) + ((u - (1L << e) - zs[e]) & ((1L << e) - 1));\n for (; ; ) {\n const val = (1L << e) + ((u - (1L << e) - xs[e]) & ((1L << e) - 1));\n ans ~= val;\n if (e == 0) {\n break;\n }\n u = (1L << e) + ((u - (1L << e) + ys[e]) & ((1L << e) - 1));\n u >>= 1;\n --e;\n }\n foreach (idx, val; ans) {\n if (idx > 0) write(\" \");\n write(val);\n }\n writeln();\n } break;\n default: assert(false);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "d87bbd969c2fcc1541c5d6119e47efae"} {"source_code": "import std;\r\n\r\nint t;\r\n\r\nvoid main() {\r\n scanf(\"%d\\n\", &t);\r\n foreach(_;0..t) {\r\n bool flag = false;\r\n foreach(k; 0..8){\r\n string row_s = readln.strip;\r\n char[] row = row_s.dup;\r\n if ((uniq(row).array.length == 1) && (row[0] == 'R')) {\r\n flag = true;\r\n }\r\n }\r\n readln;\r\n if (flag)\r\n writeln(\"R\");\r\n else\r\n writeln(\"B\");\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n readln;\n string[] grid;\n foreach (i ; 0 .. 8)\n grid ~= readln.strip;\n\n char ans = '?';\n\n foreach (i ; 0 .. 8) {\n char first = grid[i][0];\n bool match = (first == 'R');\n foreach (j ; 1 .. 8) {\n if (grid[i][j] != first) {\n match = false;\n break;\n }\n }\n if (match)\n ans = first;\n }\n\n foreach (i ; 0 .. 8) {\n char first = grid[0][i];\n bool match = (first == 'B');\n foreach (j ; 1 .. 8) {\n if (grid[j][i] != first) {\n match = false;\n break;\n }\n }\n if (match)\n ans = first;\n }\n\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n readln;\r\n int N = 8;\r\n auto F = new string[N];\r\n foreach (i; 0 .. N) F[i] = readln.chomp;\r\n\r\n char f() {\r\n bool allY(int y) {\r\n return F[y].all!(c => c == 'R');\r\n }\r\n bool allX(int x) {\r\n return iota(N).all!(y => F[y][x] == 'B');\r\n }\r\n for (int y = 0; y < N; y++) {\r\n if (allY(y)) return 'R';\r\n }\r\n for (int x = 0; x < N; x++) {\r\n if (allX(x)) return 'B';\r\n }\r\n assert(false);\r\n }\r\n writeln(f());\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n readln;\n string[] grid;\n foreach (i ; 0 .. 8)\n grid ~= readln.strip;\n char ans = '?';\n foreach (i ; 0 .. 8) {\n char first = grid[i][0];\n bool match = (first != '.');\n foreach (j ; 1 .. 8) {\n if (grid[i][j] != first) {\n match = false;\n break;\n }\n }\n if (match)\n ans = first;\n }\n foreach (i ; 0 .. 8) {\n char first = grid[0][i];\n bool match = (first != '.');\n foreach (j ; 1 .. 8) {\n if (grid[j][i] != first) {\n match = false;\n break;\n }\n }\n if (match)\n ans = first;\n }\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n readln;\r\n int N = 8;\r\n auto F = new string[N];\r\n foreach (i; 0 .. N) F[i] = readln.chomp;\r\n\r\n char f() {\r\n bool allY(int y) {\r\n return F[y].all!(c => c == 'R') || F[y].all!(c => c == 'B');\r\n }\r\n bool allX(int x) {\r\n return iota(N).all!(y => F[y][x] == 'R')\r\n || iota(N).all!(y => F[y][x] == 'B');\r\n }\r\n for (int y = 0; y < N; y++) {\r\n if (allY(y)) return F[y][0];\r\n }\r\n for (int x = 0; x < N; x++) {\r\n if (allX(x)) return F[0][x];\r\n }\r\n assert(false);\r\n }\r\n writeln(f());\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std;\r\n\r\nint t;\r\n\r\nvoid main() {\r\n scanf(\"%d\\n\", &t);\r\n outer: foreach(_;0..t) {\r\n foreach(k; 0..9){\r\n string row_s = readln.strip;\r\n char[] row = row_s.dup;\r\n if ((uniq(row).array.length == 1) && (row[0] == 'R')) {\r\n writeln(\"R\");\r\n continue outer;\r\n }\r\n }\r\n writeln(\"B\");\r\n }\r\n}\r\n"}], "src_uid": "2c7add49d423de44a2bc09de56ffacf1"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto S = scan;\r\n int n = cast(int)S.length;\r\n\r\n auto a = new int[](n + 2);\r\n auto b = new int[](n + 2);\r\n auto c = new int[](n + 2);\r\n foreach(i; 1..n + 1) a[i] = (S[i - 1] - '0') ^ 1;\r\n foreach(i; 1..n + 1) b[i] = b[i - 1] + a[i];\r\n foreach(i; iota(n, 0, -1)) c[i] = c[i + 1] + a[i];\r\n\r\n long ans = b[n];\r\n foreach(i; 0.. b[n] + 1) ans = min(ans, b[n] - (b[i] + c[n - b[n] + i + 1]));\r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nstruct SegTree(alias pred = \"a + b\", T = long) {\r\n alias predFun = binaryFun!pred;\r\n int size;\r\n T[] data;\r\n T monoid;\r\n \r\n this(T[] src, T monoid = T.init) {\r\n this.monoid = monoid;\r\n\r\n for(int i = 2; i < 2L^^32; i *= 2) {\r\n if (src.length <= i) {\r\n size = i;\r\n break;\r\n }\r\n }\r\n \r\n data = new T[](size * 2);\r\n foreach(i, s; src) data[i + size] = s;\r\n foreach_reverse(b; 1..size) {\r\n data[b] = predFun(data[b * 2], data[b * 2 + 1]);\r\n }\r\n }\r\n \r\n void update(int index, T value) {\r\n int i = index + size;\r\n data[i] = value;\r\n while(i > 0) {\r\n i /= 2;\r\n data[i] = predFun(data[i * 2], data[i * 2 + 1]);\r\n }\r\n }\r\n \r\n T get(int index) {\r\n return data[index + size];\r\n }\r\n \r\n T sum(int a, int b, int k = 1, int l = 0, int r = -1) {\r\n if (r < 0) r = size;\r\n \r\n if (r <= a || b <= l) return monoid;\r\n if (a <= l && r <= b) return data[k];\r\n \r\n T leftValue = sum(a, b, 2*k, l, (l + r) / 2);\r\n T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);\r\n return predFun(leftValue, rightValue);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nauto go (T) (T c)\r\n{\r\n\tint [] s = [0];\r\n\tforeach (ref x; c)\r\n\t{\r\n\t\ts ~= s.back + (x ? +1 : -1);\r\n\t}\r\n\treturn s;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto a = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto n = a.length.to !(int);\r\n\t\tauto s0 = [0];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\ts0 ~= s0.back + !c;\r\n\t\t}\r\n\t\tauto s1 = [0];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\ts1 ~= s1.back + c;\r\n\t\t}\r\n\r\n\t\tbool go (int limit)\r\n\t\t{\r\n\t\t\tint j = 0;\r\n\t\t\tint cur0 = 0;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tj = max (j, i);\r\n\t\t\t\twhile (j < n && s0[j + 1] - s0[i] <= limit)\r\n\t\t\t\t{\r\n\t\t\t\t\tj += 1;\r\n\t\t\t\t}\r\n\t\t\t\tif (s1[i] - s1[0] + s1[n] - s1[j] <= limit)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn true;\r\n }\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tint lo = 0;\r\n\t\tint hi = n;\r\n\t\twhile (lo < hi)\r\n\t\t{\r\n\t\t\tint me = (lo + hi) / 2;\r\n\t\t\tif (go (me))\r\n\t\t\t{\r\n\t\t\t\thi = me;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlo = me + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (lo);\r\n\t}\r\n}\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto S = scan;\r\n int n = cast(int)S.length;\r\n \r\n auto pre = new int[](n + 1);\r\n auto suf = new int[](n + 1);\r\n foreach(i; 1..n + 1) {\r\n pre[i] = pre[i - 1] + (S[i - 1] == '0');\r\n suf[i] = suf[i - 1] + (S[n - i] == '0');\r\n }\r\n // pre.deb;\r\n // suf.deb;\r\n\r\n int a, ans;\r\n a = ans = pre[n];\r\n foreach(i; 0..a + 1) {\r\n ans = min(ans, a - pre[i] - suf[a - i]);\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nstruct SegTree(alias pred = \"a + b\", T = long) {\r\n alias predFun = binaryFun!pred;\r\n int size;\r\n T[] data;\r\n T monoid;\r\n \r\n this(T[] src, T monoid = T.init) {\r\n this.monoid = monoid;\r\n\r\n for(int i = 2; i < 2L^^32; i *= 2) {\r\n if (src.length <= i) {\r\n size = i;\r\n break;\r\n }\r\n }\r\n \r\n data = new T[](size * 2);\r\n foreach(i, s; src) data[i + size] = s;\r\n foreach_reverse(b; 1..size) {\r\n data[b] = predFun(data[b * 2], data[b * 2 + 1]);\r\n }\r\n }\r\n \r\n void update(int index, T value) {\r\n int i = index + size;\r\n data[i] = value;\r\n while(i > 0) {\r\n i /= 2;\r\n data[i] = predFun(data[i * 2], data[i * 2 + 1]);\r\n }\r\n }\r\n \r\n T get(int index) {\r\n return data[index + size];\r\n }\r\n \r\n T sum(int a, int b, int k = 1, int l = 0, int r = -1) {\r\n if (r < 0) r = size;\r\n \r\n if (r <= a || b <= l) return monoid;\r\n if (a <= l && r <= b) return data[k];\r\n \r\n T leftValue = sum(a, b, 2*k, l, (l + r) / 2);\r\n T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);\r\n return predFun(leftValue, rightValue);\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "ea616a6b4ba7bf8742420b1c29ff0d16"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main() {\n int n = readln.strip.to!int;\n auto v = readln.splitter.map!(to!long).array;\n v.reverse;\n long md = 5000;\n writeln(n+1);\n //make v[i] = -i mod md.\n foreach(i,x;v) {\n //x + i + delta = k*md\n long target = (x+i+md)/md*md;\n long d = target - (x+i+1);\n v[i..$] += d;\n writefln!\"1 %d %d\" (n-i, d);\n debug {writeln(v);}\n }\n v.reverse;\n v[] %= md;\n debug {writeln(v);}\n writefln!\"2 %d %d\" (n, md);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n auto ans = new long[](N);\n long a = 0;\n\n foreach_reverse (i; 0..N) {\n long m = (A[i] + a) % N;\n long b = ((i - m) % N + N) % N;\n ans[i] = b;\n a += b;\n }\n\n writeln(N+1);\n foreach (i; 0..N) {\n writeln(1, \" \", N-i, \" \", ans[N-i-1]);\n }\n writeln(2, \" \", N, \" \", N);\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n auto ans = new long[](N);\n long a = 0;\n\n foreach_reverse (i; 0..N) {\n long m = (A[i] + a) % N;\n long b = ((i - m) % N + N) % N;\n ans[i] = b;\n a += b;\n }\n\n writeln(N+1);\n foreach (i; 0..N) {\n writeln(1, \" \", N-i, \" \", ans[N-i-1]);\n }\n writeln(2, \" \", 1, \" \", N);\n}\n"}], "src_uid": "e0ba8e0bfd9e1365daa41e1d14610200"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int dirs = 4;\nimmutable int [dirs] dRow = [-1, 0, +1, 0];\nimmutable int [dirs] dCol = [ 0, -1, 0, +1];\n\nvoid main ()\n{\n\tint rows, cols;\n\twhile (readf (\" %s %s\", &rows, &cols) > 0)\n\t{\n\t\treadln;\n\t\tstring [] a;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\ta ~= readln.strip;\n\t\t}\n\t\tint rowS, colS, rowF, colF;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tif (a[row][col] == 'S')\n\t\t\t\t{\n\t\t\t\t\trowS = row;\n\t\t\t\t\tcolS = col;\n\t\t\t\t}\n\t\t\t\tif (a[row][col] == 'E')\n\t\t\t\t{\n\t\t\t\t\trowF = row;\n\t\t\t\t\tcolF = col;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tauto commands = readln.strip.map !(x => x - '0').array;\n\n\t\tint res = 0;\n\t\tauto p = dirs.iota.array;\n\t\tdo\n\t\t{\n\t\t\tint row = rowS;\n\t\t\tint col = colS;\n\t\t\tforeach (dir; commands)\n\t\t\t{\n\t\t\t\trow += dRow[p[dir]];\n\t\t\t\tcol += dCol[p[dir]];\n\t\t\t\tif (row < 0 || rows <= row ||\n\t\t\t\t col < 0 || cols <= col)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (a[row][col] == '#')\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (tuple (row, col) == tuple (rowF, colF))\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres += (tuple (row, col) == tuple (rowF, colF));\n\t\t}\n\t\twhile (nextPermutation (p));\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n auto A = new string[M];\n foreach (x; 0 .. M) {\n A[x] = readToken();\n }\n const S = readToken();\n \n int sx, sy;\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n if (A[x][y] == 'S') {\n sx = x;\n sy = y;\n }\n }\n \n int ans;\n auto perm = iota(4).array;\n do {\n bool ok;\n int x = sx, y = sy;\n foreach (s; S) {\n const dir = perm[s - '0'];\n const xx = x + [+1, 0, -1, 0][dir];\n const yy = y + [0, -1, 0, +1][dir];\n if (0 <= xx && xx < M && 0 <= yy && yy < N && A[xx][yy] != '#') {\n x = xx;\n y = yy;\n if (A[x][y] == 'E') {\n ok = true;\n break;\n }\n } else {\n break;\n }\n }\n if (ok) {\n ++ans;\n }\n } while (perm.nextPermutation);\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\n// import dkh.array, dkh.dungeon;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) sc.read!true;\n\n int h, w;\n sc.read(h, w);\n char[][] g = new char[][](h, w);\n foreach (r; 0..h) sc.read(g[r]);\n\n string _s;\n sc.read(_s);\n int[] s = _s.map!(c => c-'0').map!(to!int).array;\n\n int ans = 0;\n foreach (idx; iota(4).permutations) {\n int[2] sv = g.findFirst2D('S');\n int[2] tv = g.findFirst2D('E');\n auto dh = Dungeon(h, w);\n bool f = true;\n foreach (_d; s) {\n int d = idx[_d];\n sv = dh.move4(sv, d);\n if (!dh.isInside(sv)) {\n f = false;\n break;\n }\n if (g.at2D(sv) == '#') {\n f = false;\n break;\n }\n if (sv == tv) break;\n }\n if (!f) continue;\n if (sv != tv) continue;\n ans++;\n }\n writeln(ans);\n return 0;\n}\n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/array.d */\n// module dkh.array;\n\n \nT[N] fixed(T, size_t N)(T[N] a) {return a;}\n\n \n \n\n \nint[2] findFirst2D(T, U)(in T mp, in U c) {\n import std.conv : to;\n int R = mp.length.to!int;\n int C = mp[0].length.to!int;\n foreach (i; 0..R) {\n foreach (j; 0..C) {\n if (mp[i][j] == c) return [i, j];\n }\n }\n assert(false);\n}\n\n \n \n\n \nauto ref at2D(T, U)(ref T mp, in U idx) {\n return mp[idx[0]][idx[1]];\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/dungeon.d */\n// module dkh.dungeon;\n\n \nimmutable static int[2][4] direction4 = [\n [1, 0], [0, 1], [-1, 0], [0, -1],\n];\n\n \nimmutable static int[2][8] direction8 = [\n [1, 0],\n [1, 1],\n [0, 1],\n [-1, 1],\n [-1, 0],\n [-1, -1],\n [0, -1],\n [1, -1],\n];\n\nstatic int[2] addInt2(in int[2] a, in int[2] b) {\n int[2] c;\n c[] = a[] + b[];\n return c;\n}\n\n \nstruct Dungeon {\n \n static int[2] move4(int[2] p, int dir) {\n return addInt2(p, direction4[dir]);\n }\n \n static int[2] move8(int[2] p, int dir) {\n return addInt2(p, direction8[dir]);\n }\n\n immutable int R, C;\n \n this(int R, int C) {\n this.R = R;\n this.C = C;\n }\n \n bool isInside(int[2] p) const {\n int r = p[0], c = p[1];\n return 0 <= r && r < R && 0 <= c && c < C;\n }\n \n int getID(int[2] p) const {\n int r = p[0], c = p[1];\n return r*R+c;\n }\n}\n\n \nauto neighbors4(int[2] p) {\n static struct Rng {\n int[2] center;\n size_t i;\n bool empty() const { return i == 4;}\n int[2] front() const { return addInt2(center, direction4[i]); }\n void popFront() { i++; }\n }\n return Rng(p, 0);\n}\n\n \n \n\n \nauto neighbors4(int[2] p, in Dungeon dg) {\n static struct Rng {\n int[2] center;\n Dungeon dg;\n size_t i;\n this(in int[2] center, in Dungeon dg) {\n this.center = center;\n this.dg = dg;\n while (!empty() && !dg.isInside(front)) i++;\n }\n bool empty() const { return i == 4;}\n int[2] front() const { return addInt2(center, direction4[i]); }\n void popFront() {\n i++;\n while (!empty() && !dg.isInside(front)) i++;\n }\n }\n return Rng(p, dg);\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {\n import std.exception;\n enforce(readSingle(x));\n static if (args.length == 0) {\n enforce(enforceEOF == false || !succ());\n } else {\n read!enforceEOF(args);\n }\n }\n void read(bool enforceEOF = false, Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length == 0) {\n enforce(enforceEOF == false || !succ());\n } else {\n enforce(readSingle(args[0]));\n read!enforceEOF(args);\n }\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int h, w; rd(h, w);\n auto c=new char[][](h);\n foreach(i; 0..h) c[i]=readln.chomp.to!(char[]);\n auto t=readln.chomp.to!(char[]);\n\n import std.typecons;\n alias P=Tuple!(int, \"i\", int, \"j\");\n P st, gl;\n foreach(i; 0..h)foreach(j; 0..w){\n if(c[i][j]=='S') st=P(i, j);\n if(c[i][j]=='E') gl=P(i, j);\n }\n auto dir=[[-1, 0], [0, 1], [1, 0], [0, -1]]; // LURD\n auto nums=[0, 1, 2, 3];\n int tot=0;\n do{\n auto cur=st;\n foreach(char ch; t){\n int x=ch-'0';\n auto d=dir[nums[x]];\n auto nex=P(cur.i+d[0], cur.j+d[1]);\n if(nex.i<0 || nex.i>=h || nex.j<0 || nex.j>=w) break;\n if(c[nex.i][nex.j]=='#') break;\n if(c[nex.i][nex.j]=='E'){tot++; break;}\n cur=nex;\n }\n }while(nextPermutation(nums));\n\n writeln(tot);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x){\n e=l[i].to!(typeof(e));\n }\n}\nvoid wr(T...)(T x){\n import std.stdio;\n foreach(e; x) write(e, \" \");\n writeln();\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int dirs = 4;\nimmutable int [dirs] dRow = [-1, 0, +1, 0];\nimmutable int [dirs] dCol = [ 0, -1, 0, +1];\n\nvoid main ()\n{\n\tint rows, cols;\n\twhile (readf (\" %s %s\", &rows, &cols) > 0)\n\t{\n\t\treadln;\n\t\tstring [] a;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\ta ~= readln.strip;\n\t\t}\n\t\tint rowS, colS, rowF, colF;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tif (a[row][col] == 'S')\n\t\t\t\t{\n\t\t\t\t\trowS = row;\n\t\t\t\t\tcolS = col;\n\t\t\t\t}\n\t\t\t\tif (a[row][col] == 'E')\n\t\t\t\t{\n\t\t\t\t\trowF = row;\n\t\t\t\t\tcolF = col;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tauto commands = readln.strip.map !(x => x - '0').array;\n\n\t\tint res = 0;\n\t\tauto p = dirs.iota.array;\n\t\tdo\n\t\t{\n\t\t\tint row = rowS;\n\t\t\tint col = colS;\n\t\t\tforeach (dir; commands)\n\t\t\t{\n\t\t\t\trow += dRow[p[dir]];\n\t\t\t\tcol += dCol[p[dir]];\n\t\t\t\tif (row < 0 || rows <= row ||\n\t\t\t\t col < 0 || cols <= col)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (tuple (row, col) == tuple (rowF, colF))\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres += (tuple (row, col) == tuple (rowF, colF));\n\t\t}\n\t\twhile (nextPermutation (p));\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "8a1799f4ca028d48d5a12e8ac4b8bee1"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tchar [] [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= readln.strip.dup;\n\t\t}\n\n\t\tbool isValid (int row, int col)\n\t\t{\n\t\t\treturn 0 <= row && row < n &&\n\t\t\t 0 <= col && col < n;\n\t\t}\n\n\t\tauto t = '.'.repeat (n * 2 - 1).array\n\t\t .repeat (n * 2 - 1).map!dup.array;\n\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tbool canHit = true;\n\t\t\t\tforeach (row; 0..n)\n\t\t\t\t{\n\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (s[row][col] == 'o')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (isValid (row +\n\t\t\t\t\t\t\t drow, col + dcol)\n\t\t\t\t\t\t\t && s[row + drow]\n\t\t\t\t\t\t\t [col + dcol] ==\n\t\t\t\t\t\t\t '.')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcanHit = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (canHit)\n\t\t\t\t{\n\t\t\t\t\tt[drow + (n - 1)][dcol + (n - 1)] =\n\t\t\t\t\t 'x';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tt[n - 1][n - 1] = 'o';\n\t\tdebug {writefln (\"%-(%s\\n%)\", t);}\n\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tif (t[drow + (n - 1)][dcol + (n - 1)] == 'x')\n\t\t\t\t{\n\t\t\t\t\tforeach (row; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[row][col] == 'o'\n\t\t\t\t\t\t\t && isValid (row +\n\t\t\t\t\t\t\t drow, col + dcol)\n\t\t\t\t\t\t\t && s[row + drow]\n\t\t\t\t\t\t\t [col + dcol] ==\n\t\t\t\t\t\t\t 'x')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ts[row + drow]\n\t\t\t\t\t\t\t\t [col +\n\t\t\t\t\t\t\t\t dcol] =\n\t\t\t\t\t\t\t\t '.';\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writefln (\"%-(%s\\n%)\", s);}\n\t\t\n\t\tbool ok = true;\n\t\tforeach (row; 0..n)\n\t\t{\n\t\t\tforeach (col; 0..n)\n\t\t\t{\n\t\t\t\tok &= (s[row][col] != 'x');\n\t\t\t}\n\t\t}\n\n\t\tif (ok)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln (\"%-(%s\\n%)\", t);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.math;\nimport std.conv;\nimport std.array;\nimport std.stdio;\nimport std.range;\nimport std.format;\nimport std.string;\nimport std.c.stdio : scanf;\nimport std.algorithm;\n\nstruct S {\n\tint x, y;\n}\n\nvoid main() {\n\tauto n = readln.strip.to!int, k = 2 * n - 1;\n\tS[] ps;\n\tchar[][] arr, r;\n\n\tr = uninitializedArray!(typeof(r))(k, k);\n\tforeach(p; r) p[] = '.';\n\tr[n - 1][n - 1] = 'o';\n\n\tforeach(y; 0..n) {\n\t\tarr ~= readln.strip.dup;\n\t\tforeach(x, c; arr.back) if(c == 'o') ps ~= S(cast(int)x, cast(int)y);\n\t}\n\n\tforeach(y, a; arr)\n\tforeach(x, ref c; a)\n\t\tif(c == 'x') {\n\t\t\tforeach(s; ps) {\n\t\t\t\tauto dx = x - s.x, dy = y - s.y;\n\t\t\t\tbool b;\n\n\t\t\t\tforeach(u; ps) {\n\t\t\t\t\tauto w = u.x + dx, e = u.y + dy;\n\t\t\t\t\tif(w >= 0 && w < n && e >= 0 && e < n && arr[e][w] == '.') b = true;\n\t\t\t\t}\n\n\t\t\t\tif(!b) {\n\t\t\t\t\tc = 0;\n\n\t\t\t\t\tforeach(u; ps) {\n\t\t\t\t\t\tauto w = u.x + dx, e = u.y + dy;\n\t\t\t\t\t\tif(w >= 0 && w < n && e >= 0 && e < n) arr[e][w] = 0;\n\t\t\t\t\t}\n\n\t\t\t\t\tr[n + dy - 1][n + dx - 1] = 'x';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\tif(arr.any!(a => a.canFind('x')))\n\t\twrite(`NO`);\n\telse\n\t\twritef(\"YES\\n%-(%s\\n%)\", r);\n}\n"}], "negative_code": [{"source_code": "import std.math;\nimport std.conv;\nimport std.array;\nimport std.stdio;\nimport std.range;\nimport std.format;\nimport std.string;\nimport std.c.stdio : scanf;\nimport std.algorithm;\n\nstruct S {\n\tint x, y;\n}\n\nvoid main() {\n\tauto n = readln.strip.to!int, k = 2 * n - 1;\n\tS[] ps;\n\tchar[][] arr;\n\n\tforeach(y; 0..n) {\n\t\tarr ~= readln.strip.dup;\n\t\tforeach(x, c; arr.back) if(c == 'o') ps ~= S(cast(int)x, cast(int)y);\n\t}\n\n\tauto r = uninitializedArray!(char[][])(k, k);\n\tforeach(p; r) p[] = '.';\n\tr[n - 1][n - 1] = 'o';\n\n\tforeach(y, a; arr)\n\tloop: foreach(x, ref c; a)\n\t\tif(c == 'x') {\n\t\t\tforeach(s; ps) {\n\t\t\t\tauto dx = x - s.x, dy = y - s.y;\n\t\t\t\tbool b;\n\n\t\t\t\tforeach(u; ps) {\n\t\t\t\t\tauto w = u.x + dx, e = u.y + dy;\n\t\t\t\t\tif(w >= 0 && w < n && e >= 0 && e < n && arr[w][e] == '.') b = true;\n\t\t\t\t}\n\n\t\t\t\tif(!b) {\n\t\t\t\t\tc = 0;\n\t\t\t\t\tr[n + dx - 1][n + dy - 1] = 'x';\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\tif(arr.any!(a => a.canFind('x')))\n\t\twrite(`NO`);\n\telse\n\t\twritef(\"YES\\n%-(%s\\n%)\", r);\n}\n"}, {"source_code": "import std.math;\nimport std.conv;\nimport std.array;\nimport std.stdio;\nimport std.range;\nimport std.format;\nimport std.string;\nimport std.c.stdio : scanf;\nimport std.algorithm;\n\nstruct S {\n\tint x, y;\n}\n\nvoid main() {\n\tauto n = readln.strip.to!int, k = 2 * n - 1;\n\tS[] ps;\n\tstring[] arr;\n\n\tforeach(y; 0..n) {\n\t\tarr ~= readln.strip;\n\t\tforeach(x, c; arr.back) if(c == 'o') ps ~= S(cast(int)x, cast(int)y);\n\t}\n\n\tauto r = uninitializedArray!(char[][])(k, k);\n\tforeach(p; r) p[] = '.';\n\tr[n - 1][n - 1] = 'o';\n\n\tforeach(y, a; arr)\n\tforeach(x, c; a)\n\t\tif(c == 'x') {\n\t\t\tforeach(s; ps) {\n\t\t\t\tauto dx = x - s.x, dy = y - s.y;\n\n\t\t\t\tforeach(u; ps) {\n\t\t\t\t\tauto w = u.x + dx, e = u.y + dy;\n\t\t\t\t\tif(w >= 0 && w < n && e >= 0 && e < n && arr[w][e] == '.') return write(`NO`);\n\t\t\t\t}\n\n\t\t\t\tr[n + dx - 1][n + dy - 1] = 'x';\n\t\t\t}\n\t\t}\n\n\twritef(\"YES\\n%-(%s\\n%)\", r);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tchar [] [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= readln.strip.dup;\n\t\t}\n\n\t\tbool isValid (int row, int col)\n\t\t{\n\t\t\treturn 0 <= row && row < n &&\n\t\t\t 0 <= col && col < n;\n\t\t}\n\n\t\tauto t = '.'.repeat (n * 2 - 1).array\n\t\t .repeat (n * 2 - 1).map!dup.array;\n\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tbool canHit = true;\n\t\t\t\tforeach (row; 0..n)\n\t\t\t\t{\n\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (s[row][col] == 'o')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (isValid (row -\n\t\t\t\t\t\t\t drow, col - dcol)\n\t\t\t\t\t\t\t && s[row - drow]\n\t\t\t\t\t\t\t [col - dcol] ==\n\t\t\t\t\t\t\t '.')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcanHit = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (canHit)\n\t\t\t\t{\n\t\t\t\t\tt[drow + (n - 1)][dcol + (n - 1)] =\n\t\t\t\t\t 'x';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tt[n - 1][n - 1] = 'o';\n\t\tdebug {writefln (\"%-(%s\\n%)\", t);}\n\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tif (t[drow + (n - 1)][dcol + (n - 1)] == 'x')\n\t\t\t\t{\n\t\t\t\t\tforeach (row; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[row][col] == 'o'\n\t\t\t\t\t\t\t && isValid (row -\n\t\t\t\t\t\t\t drow, col - dcol)\n\t\t\t\t\t\t\t && s[row - drow]\n\t\t\t\t\t\t\t [col - dcol] ==\n\t\t\t\t\t\t\t 'x')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ts[row - drow]\n\t\t\t\t\t\t\t\t [col -\n\t\t\t\t\t\t\t\t dcol] =\n\t\t\t\t\t\t\t\t '.';\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writefln (\"%-(%s\\n%)\", s);}\n\t\t\n\t\tbool ok = true;\n\t\tforeach (row; 0..n)\n\t\t{\n\t\t\tforeach (col; 0..n)\n\t\t\t{\n\t\t\t\tok &= (s[row][col] != 'x');\n\t\t\t}\n\t\t}\n\n\t\tif (ok)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln (\"%-(%s\\n%)\", t);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tchar [] [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= readln.strip.dup;\n\t\t}\n\n\t\tbool isValid (int row, int col)\n\t\t{\n\t\t\treturn 0 <= row && row < n &&\n\t\t\t 0 <= col && col < n;\n\t\t}\n\n\t\tauto t = '.'.repeat (n * 2 - 1).array\n\t\t .repeat (n * 2 - 1).map!dup.array;\n\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tbool canHit = true;\n\t\t\t\tforeach (row; 0..n)\n\t\t\t\t{\n\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (s[row][col] == 'o')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (isValid (row -\n\t\t\t\t\t\t\t drow, col - dcol)\n\t\t\t\t\t\t\t && s[row - drow]\n\t\t\t\t\t\t\t [col - dcol] ==\n\t\t\t\t\t\t\t '.')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcanHit = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (canHit)\n\t\t\t\t{\n\t\t\t\t\tt[drow + (n - 1)][dcol + (n - 1)] =\n\t\t\t\t\t 'x';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tt[n - 1][n - 1] = 'o';\n\t\tdebug {writefln (\"%-(%s\\n%)\", t);}\n\n\t\tbool ok = true;\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tif (t[drow + (n - 1)][dcol + (n - 1)] == 'x')\n\t\t\t\t{\n\t\t\t\t\tforeach (row; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[row][col] == 'o'\n\t\t\t\t\t\t\t && isValid (row -\n\t\t\t\t\t\t\t drow, col - dcol)\n\t\t\t\t\t\t\t && s[row - drow]\n\t\t\t\t\t\t\t [col - dcol] ==\n\t\t\t\t\t\t\t '.')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tif (t[drow + (n - 1)][dcol + (n - 1)] == 'x')\n\t\t\t\t{\n\t\t\t\t\tforeach (row; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[row][col] == 'o'\n\t\t\t\t\t\t\t && isValid (row -\n\t\t\t\t\t\t\t drow, col - dcol)\n\t\t\t\t\t\t\t && s[row - drow]\n\t\t\t\t\t\t\t [col - dcol] ==\n\t\t\t\t\t\t\t 'x')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ts[row - drow]\n\t\t\t\t\t\t\t\t [col -\n\t\t\t\t\t\t\t\t dcol] =\n\t\t\t\t\t\t\t\t '.';\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writefln (\"%-(%s\\n%)\", s);}\n\t\t\n\t\tforeach (row; 0..n)\n\t\t{\n\t\t\tforeach (col; 0..n)\n\t\t\t{\n\t\t\t\tok &= (s[row][col] != 'x');\n\t\t\t}\n\t\t}\n\n\t\tif (ok)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln (\"%-(%s\\n%)\", t);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tchar [] [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= readln.strip.dup;\n\t\t}\n\n\t\tbool isValid (int row, int col)\n\t\t{\n\t\t\treturn 0 <= row && row < n &&\n\t\t\t 0 <= col && col < n;\n\t\t}\n\n\t\tauto t = '.'.repeat (n * 2 - 1).array\n\t\t .repeat (n * 2 - 1).map!dup.array;\n\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tbool canHit = true;\n\t\t\t\tforeach (row; 0..n)\n\t\t\t\t{\n\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (s[row][col] == 'o')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (isValid (row -\n\t\t\t\t\t\t\t drow, col - dcol)\n\t\t\t\t\t\t\t && s[row - drow]\n\t\t\t\t\t\t\t [col - dcol] ==\n\t\t\t\t\t\t\t '.')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcanHit = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (canHit)\n\t\t\t\t{\n\t\t\t\t\tt[drow + (n - 1)][dcol + (n - 1)] =\n\t\t\t\t\t 'x';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tt[n - 1][n - 1] = 'o';\n\n\t\tforeach (drow; -(n - 1)..n)\n\t\t{\n\t\t\tforeach (dcol; -(n - 1)..n)\n\t\t\t{\n\t\t\t\tif (t[drow + (n - 1)][dcol + (n - 1)] == 'x')\n\t\t\t\t{\n\t\t\t\t\tforeach (row; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (col; 0..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (isValid (row -\n\t\t\t\t\t\t\t drow, col - dcol)\n\t\t\t\t\t\t\t && s[row - drow]\n\t\t\t\t\t\t\t [col - dcol] ==\n\t\t\t\t\t\t\t 'x')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ts[row - drow]\n\t\t\t\t\t\t\t\t [col -\n\t\t\t\t\t\t\t\t dcol] =\n\t\t\t\t\t\t\t\t '.';\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tbool ok = true;\n\t\tforeach (row; 0..n)\n\t\t{\n\t\t\tforeach (col; 0..n)\n\t\t\t{\n\t\t\t\tok &= (s[row][col] != 'x');\n\t\t\t}\n\t\t}\n\n\t\tif (ok)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln (\"%-(%s\\n%)\", t);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t}\n}\n"}], "src_uid": "2fad1534434f042214dcd1f1dc75405a"} {"source_code": "module cf_78A;\n\nimport std.stdio;\n\nbool isVowel(char letter) {\n return letter == 'a' || letter == 'e' || letter == 'i' ||\n letter == 'o' || letter == 'u';\n}\n\nvoid main() {\n immutable MAX_ROWS = 3;\n immutable ROW_SYLLABLES = [ 5, 7, 5 ];\n\n string row;\n\n bool haiku = true;\n for (int i = 0; i < MAX_ROWS; ++i) {\n readf(\"%s\\n\", &row);\n\n int syllables = 0;\n for (int j = 0; j < row.length; ++j) {\n if (isVowel(row[j])) {\n ++syllables;\n }\n }\n if (syllables != ROW_SYLLABLES[i]) {\n haiku = false;\n }\n }\n\n writeln(haiku? \"YES\": \"NO\");\n}", "positive_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias boyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nimmutable int mod=10^^9+7;\nimmutable long hashmod=10L^^18+3;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m) if(isRandomAccessRange!X)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n) if(hasSlicing!X)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\nvoid main()\n{\n\t/*int n;\n\tloop:while(read(&n))\n\t{\n\n\t}*/\n\tauto a=new int[3];\n\tforeach(i;0..3)\n\t{\n\t\tauto s=readln.strip;\n\t\ta[i]=count!q{a=='a' || a=='o' || a=='e' || a=='u' || a=='i'}(s);\n\t}\n\tif(a==[5,7,5])writeln(\"YES\");\n\telse writeln(\"NO\");\n}"}], "negative_code": [], "src_uid": "46d734178b3acaddf2ee3706f04d603d"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid solve() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n int pos = -1;\n foreach (i; 0..N) if (S[i] == '8') {\n pos = i;\n break;\n }\n if (pos == -1 || N - pos < 11) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n }\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) solve;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tlong t = read.to!long;\n\tforeach(q; 0 .. t){\n\t\t\n\t\tlong n = read.to!long;\n\t\tstring s = readln.chomp;\n\t\t\n\t\tbool f = 0;\n\t\tfor(int i = 0; i < n - 10; i ++) if(s[i] == '8') f = 1;\n\n\t\tif(f) \"YES\".writeln;\n\t\telse \"NO\".writeln;\n\t\t\n\t}\n\t\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto T = RD!int;\n\tstring[] ans;\n\tforeach (i; 0..T)\n\t{\n\t\tauto N = RD!int;\n\t\tauto s = RD!string;\n\t\tbool a;\n\t\tforeach (j; 0..N)\n\t\t{\n\t\t\tif (j > N - 11) break;\n\t\t\t\n\t\t\tif (s[j] == '8')\n\t\t\t{\n\t\t\t\ta = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans ~= a ? \"YES\" : \"NO\";\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "module cf1167a;\nimport std.stdio;\nimport std.string : indexOf, strip;\nimport std.conv : to;\nvoid main() {\n\tint n;\n\tchar[] buf;\n\treadln(buf);\n\tn = buf.strip.to!int;\n\tdebug writeln(n);\n\tforeach(i; 0..n) {\n\t\tint x;\n\t\treadln(buf);\n\t\tx = buf.strip.to!int;\n\t\treadln(buf);\n\t\timmutable eight = buf.indexOf('8');\n\t\tdebug writeln(eight, \" \", x);\n\t\tif (eight >= 0 && eight + 11 <= x) {\n\t\t\twriteln(\"YES\");\n\t\t}else {\n\t\t\twriteln(\"NO\");\n\t\t}\n\t}\n}\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,t;\n t=readln.chomp.to!int;\n string s;\n while(t--){\n n=readln.chomp.to!int;\n s=readln.strip;\n long k=s.indexOf('8');\n if(k>=0 && n-k>=11)\n writeln(\"YES\");\n else writeln(\"NO\");\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.random;\n\nvoid main() {\n int nt = readln.strip.to!int;\n foreach (tid; 0 .. nt) {\n int n = readln.strip.to!int;\n auto s = readln.take (n).array;\n auto res = \"NO\";\n foreach (i; 0 .. n) {\n if (s[i] == '8' && (n - 1) - i >= 10) {\n res = \"YES\";\n break;\n }\n }\n writeln (res);\n }\n}\n\n"}], "negative_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,t;\n t=readln.chomp.to!int;\n string s;\n while(t--){\n n=readln.chomp.to!int;\n s=readln.strip;\n long k=s.indexOf('8');\n if(n>=11 && k>=0 && n-k+1>=10)\n writeln(\"YES\");\n else writeln(\"NO\");\n }\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,t;\n t=readln.chomp.to!int;\n string s;\n while(t--){\n n=readln.chomp.to!int;\n s=readln.strip;\n long k=s.indexOf('8');\n if(n>=11 && k>=0 && n-k>=10)\n writeln(\"YES\");\n else writeln(\"NO\");\n }\n}\n\n"}], "src_uid": "bcdd7862b718d6bcc25c9aba8716d487"} {"source_code": "import std.stdio;\n\nvoid main()\n{\n int curvas, curvasPerigosas;\n int[1001] x;\n int[1001] y;\n \n readf(\" %s \", &curvas);\n for(int i = 0; i <= curvas; ++i)\n {\n readf(\" %s %s\", &x[i], &y[i]);\n }\n \n for (int i = 1; i < curvas; ++i)\n {\n if (y[i] - y[i - 1] > 0 && x[i + 1] - x[i] < 0\n || x[i] - x[i - 1] > 0 && y[i + 1] - y[i] > 0\n || y[i] - y[i - 1] < 0 && x[i + 1] - x[i] > 0\n || x[i] - x[i - 1] < 0 && y[i + 1] - y[i] < 0)\n ++curvasPerigosas;\n }\n \n writeln(curvasPerigosas);\n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n int curvas, curvasPerigosas;\n int[1001] x;\n int[1001] y;\n \n readf(\" %s \", &curvas);\n for(int i = 0; i <= curvas; ++i)\n {\n readf(\" %s %s\", &x[i], &y[i]);\n }\n \n for (int i = 1; i < curvas; ++i)\n {\n if (y[i] - y[i - 1] > 0 && x[i + 1] - x[i] < 0\n || x[i] - x[i - 1] > 0 && y[i + 1] - y[i] > 0\n || y[i] - y[i - 1] < 0 && x[i + 1] - x[i] > 0\n || x[i] - x[i - 1] < 0 && y[i + 1] - y[i] < 0)\n ++curvasPerigosas;\n }\n \n writeln(curvasPerigosas);\n}\n"}, {"source_code": "import std.stdio;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n Tuple!(int, int)[] points;\n \n readf(\"%d\", &n);\n points = new Tuple!(int, int)[n + 2];\n for (int i = 0; i < n + 1; i++) {\n readf(\" %d %d\", &points[i][0], &points[i][1]);\n }\n points[n + 1] = points[1];\n \n int result = 0;\n for (int i = 1; i <= n; i++) {\n Tuple!(int, int) d[2];\n \n d[0][0] = points[i][0] - points[i - 1][0];\n d[0][1] = points[i][1] - points[i - 1][1];\n d[1][0] = points[i + 1][0] - points[i][0];\n d[1][1] = points[i + 1][1] - points[i][1];\n \n if (d[0][0] * d[1][1] - d[1][0] * d[0][1] > 0) {\n result++;\n }\n }\n \n writef(\"%d\\n\", result);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n int curvas, curvasPerigosas;\n int[1001] x;\n int[1001] y;\n \n readf(\" %s \", &curvas);\n readf(\" %s %s\", &x[0], &y[0]);\n for(int i = 1; i <= curvas; ++i)\n {\n readf(\" %s %s\", &x[i], &y[i]);\n if (y[i] - y[i - 1] > 0 && x[i + 1] - x[i] < 0\n || x[i] - x[i - 1] > 0 && y[i + 1] - y[i] > 0\n || y[i] - y[i - 1] < 0 && x[i + 1] - x[i] > 0\n || x[i] - x[i - 1] < 0 && y[i + 1] - y[i] < 0)\n ++curvasPerigosas;\n }\n \n writeln(curvasPerigosas);\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int curvas, curvasPerigosas;\n int[1001] x;\n int[1001] y;\n \n readf(\" %s \", &curvas);\n readf(\" %s %s\", &x[0], &y[0]);\n readf(\" %s %s\", &x[1], &y[1]);\n for(int i = 2; i <= curvas; ++i)\n {\n readf(\" %s %s\", &x[i], &y[i]);\n if (y[i] - y[i - 1] > 0 && x[i + 1] - x[i] < 0\n || x[i] - x[i - 1] > 0 && y[i + 1] - y[i] > 0\n || y[i] - y[i - 1] < 0 && x[i + 1] - x[i] > 0\n || x[i] - x[i - 1] < 0 && y[i + 1] - y[i] < 0)\n ++curvasPerigosas;\n }\n \n writeln(curvasPerigosas);\n}"}], "src_uid": "0054f9e2549900487d78fae9aa4c2d65"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long s, n;\n readf!\" %d %d \"(s, n);\n long[] ans;\n auto numpool = redBlackTree!(\"a<b\", true, long)();\n long mul = 1;\n while (s > 0) {\n long digit = s % 10;\n foreach (i ; 0 .. digit)\n numpool.insert(mul);\n s /= 10;\n mul *= 10;\n }\n while (true) {\n if (n == 1) {\n long final_num = 0;\n while (!numpool.empty) {\n final_num += numpool.front;\n numpool.removeFront;\n }\n ans ~= final_num;\n break;\n }\n if (n <= numpool.length || numpool.front == 1) {\n ans ~= numpool.front;\n numpool.removeFront;\n n--;\n continue;\n }\n long tmp = numpool.front;\n numpool.removeFront;\n assert(tmp > 0 && tmp % 10 == 0);\n foreach (i ; 0 .. 10)\n numpool.insert(tmp / 10);\n }\n writeln(ans.map!text.joiner(\" \"));\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto s = RD!string;\r\n\t\tauto n = RD!int;\r\n\r\n\t\tauto a = new int[](s.length);\r\n\t\tforeach (i; 0..s.length)\r\n\t\t\ta[i] = s[i]-'0';\r\n\r\n\t\tlong cnt = a.sum;\r\n\t\twhile (n > cnt)\r\n\t\t{\r\n\t\t\tint p = cast(int)a.length-2;\r\n\t\t\twhile (a[p] == 0)\r\n\t\t\t\t--p;\r\n\t\t\t--a[p];\r\n\t\t\ta[p+1] += 10;\r\n\t\t\tcnt += 9;\r\n\t\t}\r\n\r\n\t\t(){\r\n\t\tforeach (i; 0..a.length)\r\n\t\t{\r\n\t\t\tforeach (j; 0..a[i])\r\n\t\t\t{\r\n\t\t\t\tans[ti] ~= 10^^(a.length-i-1);\r\n\t\t\t\t--a[i];\r\n\t\t\t\tif (ans[ti].length == n) return;\r\n\t\t\t}\r\n\t\t}}();\r\n\t\tforeach (i; 0..a.length)\r\n\t\t{\r\n\t\t\tforeach (j; 0..a[i])\r\n\t\t\t{\r\n\t\t\t\tans[ti][j%n] += 10^^(a.length-i-1);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool solve(long s, long n, ref long[] a)\n{\n long[] ans;\n foreach (i ; 0 .. n - 1) {\n ans ~= 1;\n }\n if (s - (n - 1) <= 0)\n return false;\n\n ans ~= s - (n - 1);\n if (ans.length > 1 && ans.back >= 10) {\n ans.front += ans.back % 10;\n ans.back -= ans.back % 10;\n }\n a = ans;\n return true;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long s, n;\n readf!\" %d %d \"(s, n);\n long[] best_a;\n long best_div = 1;\n solve(s, n, best_a);\n long div = 10;\n while (s / div * div == s) {\n long[] a;\n if (solve(s / div, n, a)) {\n best_a = a;\n best_div = div;\n }\n div *= 10;\n }\n writeln(best_a.map!(x => (x * best_div).text).joiner(\" \"));\n/*\n long[] ans;\n foreach (i ; 0 .. n - 1) {\n ans ~= 1;\n }\n ans ~= s - (n - 1);\n if (ans.length > 1 && ans.back >= 10) {\n ans.front += ans.back % 10;\n ans.back -= ans.back % 10;\n }\n writeln(ans.map!text.joiner(\" \"));\n*/\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long s, n;\n readf!\" %d %d \"(s, n);\n long[] ans;\n foreach (i ; 0 .. n - 1) {\n ans ~= 1;\n }\n ans ~= s - (n - 1);\n if (ans.length > 1 && ans.back >= 10) {\n ans.front += ans.back % 10;\n ans.back -= ans.back % 10;\n }\n writeln(ans.map!text.joiner(\" \"));\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long s, n;\n readf!\" %d %d \"(s, n);\n long[] ans;\n foreach (i ; 0 .. n - 1) {\n ans ~= 1;\n }\n ans ~= s - (n - 1);\n if (ans.length > 1) {\n ans.front += ans.back % 10;\n ans.back -= ans.back % 10;\n }\n writeln(ans.map!text.joiner(\" \"));\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long s, n;\n readf!\" %d %d \"(s, n);\n long[] ans;\n foreach (i ; 0 .. n - 1) {\n ans ~= 1;\n }\n ans ~= s - (n - 1);\n ans.front += ans.back % 10;\n ans.back -= ans.back % 10;\n writeln(ans.map!text.joiner(\" \"));\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long s, n;\n readf!\" %d %d \"(s, n);\n long[] ans;\n foreach (i ; 0 .. n - 1) {\n ans ~= 1;\n }\n ans ~= s - (n - 1);\n writeln(ans.map!text.joiner(\" \"));\n }\n}\n"}], "src_uid": "2afb210831529a99f8f04f13e5438d55"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\ta.sort();\n\n\t\tlong x, y;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (x == a[i])\n\t\t\t\t++x;\n\t\t\telse if (y == a[i])\n\t\t\t\t++y;\n\t\t}\n\t\tans[ti] = x+y;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nbool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid main(string[] args){ args ~= [\"\", \"\"]; string cmd = args[1]; if(cmd == \"-debug\") DEBUG = 1;\nif(cmd == \"-gen\") gen; else if(cmd == \"-jury\") jury; else solve; } \nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid gen(){\n}\nvoid jury(){\n}\nvoid solve(){\n foreach(_; 0 .. scan!int){\n int n = scan!int;\n int[] as = scan!int(n);\n\n int[int] acnt;\n foreach(a; as){\n if(a !in acnt) acnt[a] = 0;\n acnt[a] += 1;\n }\n\n int ans = 0;\n int i = 0;\n\n while(i in acnt && acnt[i] >= 2) i ++;\n ans += i;\n\n while(i in acnt && acnt[i] >= 1) i ++;\n ans += i;\n\n ans.writeln;\n }\n}"}], "negative_code": [], "src_uid": "e26b0b117593c159b7f01cfac66a71d1"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto B = N.iota.map!(i => tuple(A[i], i)).array;\n B.sort();\n\n auto used = new int[](N);\n auto uf = new UnionFind(N);\n\n used[B[0][1]] = true;\n int max_locs = 1;\n int ans = B[0][0] + 1;\n uf.cnt = 1;\n uf.lens[1] = 1;\n\n foreach (i; 1..N) {\n int v = B[i][0];\n int n = B[i][1];\n used[n] = true;\n uf.cnt += 1;\n uf.lens[1] += 1;\n int lens = uf.lens[1];\n if (n > 0 && used[n-1]) lens = uf.unite(n, n-1);\n if (n < N-1 && used[n+1]) lens = uf.unite(n, n+1);\n if (lens == uf.cnt) {\n if (uf.cnt > max_locs) {\n max_locs = uf.cnt;\n ans = v + 1;\n }\n }\n }\n\n ans.writeln;\n}\n\nclass UnionFind {\n int N;\n int[] table;\n Tuple!(int, int)[] segs;\n int[] lens;\n int cnt;\n\n this(int n) {\n N = n;\n table = new int[](N);\n fill(table, -1);\n segs = N.iota.map!(i => tuple(i, i)).array;\n lens = new int[](N+10);\n cnt = 0;\n }\n\n int find(int x) {\n return table[x] < 0 ? x : (table[x] = find(table[x]));\n }\n\n int unite(int x, int y) {\n x = find(x);\n y = find(y);\n if (x == y) return -1;\n if (table[x] > table[y]) swap(x, y);\n cnt -= 1;\n table[x] += table[y];\n lens[segs[x][1] - segs[x][0] + 1] -= 1;\n lens[segs[y][1] - segs[y][0] + 1] -= 1;\n segs[x] = tuple(min(segs[x][0], segs[y][0]), max(segs[x][1], segs[y][1]));\n lens[segs[x][1] - segs[x][0] + 1] += 1;\n table[y] = x;\n return lens[segs[x][1] - segs[x][0] + 1];\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nauto biggestBit(T)(T t)\n{\n debug assert(t != 0);\n int bitpos = -1;\n while(t)\n {\n t >>= 1;\n bitpos++;\n }\n return bitpos;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n\n auto n = next!int;\n auto a = next!int(n);\n auto numRows = n.biggestBit;\n auto maxIn = new int[][](numRows + 1, n);\n foreach(r; 0 .. numRows + 1)\n maxIn[r][] = -1;\n foreach(i; 0 .. n)\n maxIn[0][i] = i;\n auto maxInd(int i, int j)\n {\n return a[i] > a[j]? i : j;\n }\n foreach(p; 1 .. numRows + 1)\n {\n foreach(i; 0 .. n)\n {\n if ((i + (1 << (p)) - 1) >= n)\n continue;\n maxIn[p][i] = maxInd(maxIn[p - 1][i], maxIn[p - 1][i + (1 << (p - 1))]);\n }\n }\n debug writeln(maxIn);\n auto maxInRange(int s, int e)\n {\n auto len = e - s + 1;\n auto p = len.biggestBit;\n auto lenwithoutbb = len - (1 << p);\n return maxInd(maxIn[p][s], maxIn[p][s + lenwithoutbb]);\n }\n\n auto poolSize = new int[](n);\n void doPoolSize(int s, int e)\n {\n if (s > e)\n return;\n auto len = e - s + 1;\n auto mxi = maxInRange(s, e);\n debug writeln(\"in range \", s, \" - \", e, \" max is \", a[mxi], \" with len \", len);\n assert(mxi >= s && mxi <= e);\n poolSize[mxi] = len;\n doPoolSize(s, mxi - 1);\n doPoolSize(mxi + 1, e);\n }\n doPoolSize(0, n - 1);\n debug writeln(poolSize);\n auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;\n auto lastInd = new int[](n + 1);\n auto sizeCnt = new int[](n + 1);\n auto bestBySize = new int[](n + 1);\n int bestSize = 0;\n lastInd[] = -1;\n debug foreach(i, ind; sortedIndexes)\n {\n write(poolSize[ind], \" \");\n }\n debug writeln;\n foreach(i, ind; sortedIndexes)\n {\n auto s = poolSize[ind];\n sizeCnt[s]++;\n auto l = lastInd[s];\n debug if (s == 3) {writeln(\"sizeCnt \", s, \" \", sizeCnt[s], \" i \", i);}\n if (sizeCnt[s] * s - 1 == i)\n {\n bestBySize[s] = sizeCnt[s];\n bestSize = max(bestBySize[s], bestSize);\n lastInd[s] = cast(int)i;\n }\n }\n debug writeln(\"bestBySize: \", bestBySize);\n int minimalUp = int.max;\n foreach(s, b; bestBySize)\n {\n if (s != 0 && b == bestSize)\n {\n minimalUp = min(minimalUp, s * b - 1);\n }\n }\n auto minV = a[sortedIndexes[minimalUp]];\n (minV + 1).writeln;\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nauto biggestBit(T)(T t)\n{\n debug assert(t != 0);\n int bitpos = -1;\n while(t)\n {\n t >>= 1;\n bitpos++;\n }\n return bitpos;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n\n auto n = next!int;\n auto a = next!int(n);\n auto numRows = n.biggestBit;\n auto maxIn = new int[][](numRows + 1, n);\n foreach(r; 0 .. numRows + 1)\n maxIn[r][] = -1;\n foreach(i; 0 .. n)\n maxIn[0][i] = i;\n foreach(p; 1 .. numRows + 1)\n {\n foreach(i; 0 .. n)\n {\n if ((i + (1 << (p)) - 1) >= n)\n continue;\n auto v0 = a[maxIn[p - 1][i]];\n auto v1 = a[maxIn[p - 1][i + (1 << (p - 1))]];\n if (v0 > v1)\n maxIn[p][i] = maxIn[p - 1][i];\n else\n maxIn[p][i] = maxIn[p - 1][i + (1 << (p - 1))];\n }\n }\n debug writeln(maxIn);\n auto maxInRange(int s, int e)\n {\n auto len = e - s + 1;\n auto p = len.biggestBit;\n auto lenwithoutbb = len - (1 << p);\n auto v0 = a[maxIn[p][s]];\n auto v1 = a[maxIn[p][s + lenwithoutbb]];\n if (v0 > v1)\n return maxIn[p][s];\n return maxIn[p][s + lenwithoutbb];\n }\n\n auto poolSize = new int[](n);\n void doPoolSize(int s, int e)\n {\n if (s > e)\n return;\n auto len = e - s + 1;\n auto mxi = maxInRange(s, e);\n debug writeln(\"in range \", s, \" - \", e, \" max is \", a[mxi], \" with len \", len);\n assert(mxi >= s && mxi <= e);\n poolSize[mxi] = len;\n doPoolSize(s, mxi - 1);\n doPoolSize(mxi + 1, e);\n }\n doPoolSize(0, n - 1);\n debug writeln(poolSize);\n auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;\n auto lastInd = new int[](n + 1);\n auto bestBySize = new int[](n + 1);\n int bestSize = 0;\n lastInd[] = -1;\n debug foreach(i, ind; sortedIndexes)\n {\n write(poolSize[ind], \" \");\n }\n debug writeln;\n foreach(i, ind; sortedIndexes)\n {\n auto s = poolSize[ind];\n auto l = lastInd[s];\n if (i - l == s)\n {\n bestBySize[s]++;\n bestSize = max(bestBySize[s], bestSize);\n lastInd[s] = cast(int)i;\n }\n }\n debug writeln(bestBySize);\n int minimalUp = int.max;\n foreach(s, b; bestBySize)\n {\n if (s != 0 && b == bestSize)\n {\n minimalUp = min(minimalUp, s * b - 1);\n }\n }\n auto minV = a[sortedIndexes[minimalUp]];\n (minV + 1).writeln;\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nauto biggestBit(T)(T t)\n{\n debug assert(t != 0);\n int bitpos = -1;\n while(t)\n {\n t >>= 1;\n bitpos++;\n }\n return bitpos;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n\n auto n = next!int;\n auto a = next!int(n);\n auto numRows = n.biggestBit;\n auto maxIn = new int[][](numRows + 1, n);\n foreach(r; 0 .. numRows + 1)\n maxIn[r][] = -1;\n foreach(i; 0 .. n)\n maxIn[0][i] = i;\n auto maxInd(int i, int j)\n {\n return a[i] > a[j]? i : j;\n }\n foreach(p; 1 .. numRows + 1)\n {\n foreach(i; 0 .. n)\n {\n if ((i + (1 << (p)) - 1) >= n)\n continue;\n maxIn[p][i] = maxInd(maxIn[p - 1][i], maxIn[p - 1][i + (1 << (p - 1))]);\n }\n }\n debug writeln(maxIn);\n auto maxInRange(int s, int e)\n {\n auto len = e - s + 1;\n auto p = len.biggestBit;\n auto lenwithoutbb = len - (1 << p);\n return maxInd(maxIn[p][s], maxIn[p][s + lenwithoutbb]);\n }\n\n auto poolSize = new int[](n);\n void doPoolSize(int s, int e)\n {\n if (s > e)\n return;\n auto len = e - s + 1;\n auto mxi = maxInRange(s, e);\n debug writeln(\"in range \", s, \" - \", e, \" max is \", a[mxi], \" with len \", len);\n assert(mxi >= s && mxi <= e);\n poolSize[mxi] = len;\n doPoolSize(s, mxi - 1);\n doPoolSize(mxi + 1, e);\n }\n doPoolSize(0, n - 1);\n debug writeln(poolSize);\n auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;\n auto sizeCnt = new int[](n + 1);\n auto bestBySize = new int[](n + 1);\n int bestSize = 0;\n debug foreach(i, ind; sortedIndexes)\n {\n write(poolSize[ind], \" \");\n }\n debug writeln;\n foreach(i, ind; sortedIndexes)\n {\n auto s = poolSize[ind];\n sizeCnt[s]++;\n debug if (s == 3) {writeln(\"sizeCnt \", s, \" \", sizeCnt[s], \" i \", i);}\n if (sizeCnt[s] * s - 1 == i)\n {\n bestBySize[s] = sizeCnt[s];\n bestSize = max(bestBySize[s], bestSize);\n }\n }\n debug writeln(\"bestBySize: \", bestBySize);\n int minimalUp = int.max;\n foreach(s, b; bestBySize)\n {\n if (s != 0 && b == bestSize)\n {\n minimalUp = min(minimalUp, s * b - 1);\n }\n }\n auto minV = a[sortedIndexes[minimalUp]];\n (minV + 1).writeln;\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto B = N.iota.map!(i => tuple(A[i], i)).array;\n B.sort();\n\n auto used = new int[](N);\n auto uf = new UnionFind(N);\n\n used[0] = true;\n int max_locs = 1;\n int ans = B[0][1] + 1;\n uf.cnt = 1;\n\n foreach (i; 1..N) {\n int v = B[i][0];\n int n = B[i][1];\n used[n] = true;\n uf.cnt += 1;\n int lens = -1;\n if (n > 0 && used[n-1]) lens = uf.unite(n, n-1);\n if (n < N-1 && used[n+1]) lens = uf.unite(n, n+1);\n if (lens > 0 && lens == uf.cnt) {\n if (uf.cnt > max_locs) {\n max_locs = uf.cnt;\n ans = v + 1;\n }\n }\n }\n\n ans.writeln;\n}\n\nclass UnionFind {\n int N;\n int[] table;\n Tuple!(int, int)[] segs;\n int[] lens;\n int cnt;\n\n this(int n) {\n N = n;\n table = new int[](N);\n fill(table, -1);\n segs = N.iota.map!(i => tuple(i, i)).array;\n lens = new int[](N+1);\n cnt = 0;\n }\n\n int find(int x) {\n return table[x] < 0 ? x : (table[x] = find(table[x]));\n }\n\n int unite(int x, int y) {\n x = find(x);\n y = find(y);\n if (x == y) return -1;\n if (table[x] > table[y]) swap(x, y);\n cnt -= 1;\n table[x] += table[y];\n lens[segs[x][1] - segs[x][0] + 1] -= 1;\n lens[segs[y][1] - segs[y][0] + 1] -= 1;\n segs[x] = tuple(min(segs[x][0], segs[y][0]), max(segs[x][1], segs[y][1]));\n lens[segs[x][1] - segs[x][0] + 1] += 1;\n table[y] = x;\n return lens[segs[x][1] - segs[x][0] + 1];\n }\n}\n"}], "src_uid": "b3d093272fcb289108fe45be8c72f38e"} {"source_code": "import std.stdio, std.string;\nT x(T)(T a) {\n\tif (a.length&1) return a;\n\tauto b=a[0..$/2].x, c=a[$/2..$].x;\n\treturn b<c ? b~c : c~b;\n}\nvoid main() {writeln (readln.strip.x==readln.strip.x ? \"YES\" : \"NO\");}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstring canonize (string a)\n{\n\tif (a.length % 2 == 0)\n\t{\n\t\tstring b = canonize (a[0..$ / 2]);\n\t\tstring c = canonize (a[$ / 2..$]);\n\t\treturn min (b, c) ~ max (b, c);\n\t}\n\treturn a;\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tstring t = readln.strip;\n\t\twriteln ((canonize (s) == canonize (t)) ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio, std.string;\n\nT x (T) (T a)\n{\n\tif (a.length & 1) return a;\n\tauto b = x (a[0..$ / 2]), c = x (a[$ / 2..$]);\n\treturn min (b, c) ~ max (b, c);\n}\n\nvoid main ()\n{\n\twriteln (readln.strip.x == readln.strip.x ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "T x(T)(T a){if(a.length&1)return a;auto b=a[0..$/2].x,c=a[$/2..$].x;return b<c?b~c:c~b;}\nvoid main(){import std.stdio;writeln(readln[0..$-1].x==readln[0..$-1].x?\"YES\":\"NO\");}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool ok (string a, string b)\n{\n\tif (a.length % 2 == 0)\n\t{\n\t\tif ((a[0..$ / 2] < a[$ / 2..$]) ==\n\t\t (b[0..$ / 2] < b[$ / 2..$]))\n\t\t{\n\t\t\treturn ok (a[0..$ / 2], b[0..$ / 2]) &&\n\t\t\t ok (a[$ / 2..$], b[$ / 2..$]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn ok (a[0..$ / 2], b[$ / 2..$]) &&\n\t\t\t ok (a[$ / 2..$], b[0..$ / 2]);\n\t\t}\n\t}\n\telse\n\t{\n\t\treturn a == b;\n\t}\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tstring t = readln.strip;\n\t\twriteln (ok (s, t) ? \"YES\" : \"NO\");\n\t}\n}\n"}], "src_uid": "21c0e12347d8be7dd19cb9f43a31be85"} {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tlong t = read.to!long;\n\t\n\tlong[] ss, ds;\n\tforeach(i; 0 .. n){\n\t\tss ~= read.to!long;\n\t\tds ~= read.to!long;\n\t}\n\t\n\tlong bestx = 10_000_000, ans = -1;\n\tforeach(i; 0 .. n){\n\t\tlong s = ss[i], d = ds[i];\n\t\tlong x;\n\t\tif(s >= t) x = s;\n\t\telse x = s + (t - s + d - 1) / d * d;\n\t\t\n\t\tif(x < bestx){\n\t\t\tbestx = x;\n\t\t\tans = i + 1;\n\t\t}\n\t}\n\t\n\tans.writeln;\n\n\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto T = s[1].to!long;\n\n long idx = -1;\n long ans = 1L << 59;\n\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n auto a = s[0].to!long;\n auto b = s[1].to!long;\n long tmp;\n if (a >= T) {\n tmp = a;\n } else {\n long m1 = T % b;\n long m2 = a % b;\n if (m1 <= m2) {\n tmp = T + m2 - m1;\n } else {\n tmp = T + b - m1 + m2;\n }\n }\n if (tmp < ans) {\n ans = tmp;\n idx = i + 1;\n }\n }\n\n idx.writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD;\n\tauto T = RD;\n\n\tlong best = long.max;\n\tlong ans;\n\tforeach (i; 0..N)\n\t{\n\t\tauto s = RD;\n\t\tauto d = RD;\n\t\tauto x = s - T;\n\t\tauto y = abs(x / d);\n\t\tif (x < 0)\n\t\t{\n\t\t\tx += (y+1) * d;\n\t\t\tx %= d;\n\t\t}\n\t\tif (x < best)\n\t\t{\n\t\t\tbest = x;\n\t\t\tans = i + 1;\n\t\t}\n\t\tdebug writeln(i, \" \", best, \" \", ans);\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "71be4cccd3b8c494ad7cc2d8a00cf5ed"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1516/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n, k;\n readf(\"%s %s\\n\", &n, &k);\n\n int[] a = readln.split.map!(to!int).array;\n\n int idx = 0;\n while(k > 0 && idx < n) {\n while(a[idx] <= 0) {\n idx += 1;\n }\n if (idx >= n - 1) break;\n a[idx]--;\n a[$ - 1]++;\n k -= 1;\n }\n\n foreach(item; a)\n writef(\"%s \", item);\n \"\".writeln;\n}\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tauto x = min(k, a[i]);\r\n\t\t\ta[i] -= x;\r\n\t\t\ta[$-1] += x;\r\n\t\t\tk -= x;\r\n\t\t}\r\n\t\tans[ti] = a;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp.splitter(\" \").array;\r\n int k = to!int(param[1]);\r\n auto arr = readln().chomp.split(\" \").map!(to!int).array;\r\n int e = arr.length-1;\r\n int b = 0;\r\n \r\n while(b < e && k > 0)\r\n {\r\n if(arr[b] > 0 && arr[e] < int.max)\r\n {\r\n arr[b]--;\r\n arr[e]++;\r\n k--;\r\n }\r\n else if(arr[b] <= 0)\r\n {\r\n b++;\r\n }\r\n else\r\n {\r\n e--;\r\n }\r\n }\r\n \r\n writeln(arr.map!(to!string).array.join(\" \"));\r\n }\r\n}"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1516/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n, k;\n readf(\"%s %s\\n\", &n, &k);\n\n int[] a = readln.split.map!(to!int).array;\n\n int idx = 0;\n while(k > 0 && idx < n - 1) {\n while(a[idx] <= 0) {\n idx += 1;\n }\n a[idx]--;\n a[$ - 1]++;\n k -= 1;\n }\n\n foreach(item; a)\n writef(\"%s \", item);\n \"\".writeln;\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1516/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n, k;\n readf(\"%s %s\\n\", &n, &k);\n\n int[] a = readln.split.map!(to!int).array;\n\n int idx = 0;\n while(k > 0 && idx <= n - 1) {\n while(a[idx] <= 0) {\n idx += 1;\n }\n a[idx]--;\n a[$ - 1]++;\n k -= 1;\n }\n\n foreach(item; a)\n writef(\"%s \", item);\n \"\".writeln;\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1516/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n, k;\n readf(\"%s %s\\n\", &n, &k);\n\n int[] a = readln.split.map!(to!int).array;\n\n int idx = 0;\n while(k-- && idx <= n - 1) {\n while(a[idx] <= 0) {\n idx += 1;\n }\n a[idx]--;\n a[$ - 1]++;\n }\n\n foreach(item; a)\n writef(\"%s \", item);\n \"\".writeln;\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1516/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n, k;\n readf(\"%s %s\\n\", &n, &k);\n\n int[] a = readln.split.map!(to!int).array;\n\n int idx = 0;\n while(k-- && idx <= n - 1) {\n if(a[idx] <= 0) {\n idx += 1;\n }\n a[idx]--;\n a[$ - 1]++;\n }\n\n foreach(item; a)\n writef(\"%s \", item);\n \"\".writeln;\n}\n}\n\n"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp.splitter(\" \").array;\r\n int k = to!int(param[1]);\r\n auto arr = readln().chomp.split(\" \").map!(to!int).array;\r\n int e = arr.length-1;\r\n int b = 0;\r\n \r\n while(b < e && k > 0)\r\n {\r\n if(arr[b] > 0)\r\n {\r\n arr[b]--;\r\n b++;\r\n }\r\n else\r\n {\r\n b++;\r\n }\r\n \r\n if(arr[e] < 10)\r\n {\r\n arr[e]++;\r\n }\r\n else\r\n {\r\n e--;\r\n }\r\n \r\n k--;\r\n }\r\n \r\n writeln(arr.map!(to!string).array.join(\" \"));\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp.splitter(\" \").array;\r\n int k = to!int(param[1]);\r\n auto arr = readln().chomp.split(\" \").map!(to!int).array;\r\n int e = arr.length-1;\r\n int b = 0;\r\n \r\n while(b < e && k > 0)\r\n {\r\n if(arr[b] > 0)\r\n {\r\n arr[b]--;\r\n arr[e]++;\r\n e--;\r\n k--;\r\n }\r\n b++;\r\n }\r\n \r\n writeln(arr.map!(to!string).array.join(\" \"));\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp.splitter(\" \").array;\r\n int k = to!int(param[1]);\r\n auto arr = readln().chomp.split(\" \").map!(to!int).array;\r\n int e = arr.length-1;\r\n int b = 0;\r\n \r\n while(b < e && k > 0)\r\n {\r\n while(b < arr.length && arr[b] == 0) b++;\r\n if(b == arr.length) continue;\r\n \r\n arr[b]--;\r\n arr[e]++;\r\n b++;\r\n e--;\r\n k--;\r\n }\r\n \r\n writeln(arr.map!(to!string).array.join(\" \"));\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp.splitter(\" \").array;\r\n int k = to!int(param[1]);\r\n auto arr = readln().chomp.split(\" \").map!(to!int).array;\r\n int e = arr.length-1;\r\n int b = 0;\r\n \r\n while(b < e && k > 0)\r\n {\r\n while(b < arr.length && arr[b] <= k) b++;\r\n if(b == arr.length) continue;\r\n \r\n arr[b]--;\r\n arr[e]++;\r\n b++;\r\n e--;\r\n k--;\r\n }\r\n \r\n writeln(arr.map!(to!string).array.join(\" \"));\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp.splitter(\" \").array;\r\n int k = to!int(param[1]);\r\n auto arr = readln().chomp.split(\" \").map!(to!int).array;\r\n int e = arr.length-1;\r\n int b = 0;\r\n \r\n while(b < e && k > 0)\r\n {\r\n while(b < arr.length && arr[b] <= k) b++;\r\n if(b == arr.length) continue;\r\n \r\n arr[b]--;\r\n arr[e]++;\r\n b++;\r\n e--;\r\n k--;\r\n }\r\n \r\n writeln(arr[]);\r\n }\r\n}"}], "src_uid": "6854ad3597f9f41d475aacb774b823ed"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\t\tif (s.length >= 2)\n\t\t{\n\t\t\tif (s[$-2..$] == \"po\")\n\t\t\t{\n\t\t\t\tans[ti] = \"FILIPINO\";\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (s.length >= 4)\n\t\t\t{\n\t\t\t\tif (s[$-4..$] == \"desu\" || s[$-4..$] == \"masu\")\n\t\t\t\t{\n\t\t\t\t\tans[ti] = \"JAPANESE\";\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (s.length >= 5)\n\t\t\t\t{\n\t\t\t\t\tif (s[$-5..$] == \"mnida\")\n\t\t\t\t\t{\n\t\t\t\t\t\tans[ti] = \"KOREAN\";\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tforeach (e; ans)\n\t\twriteln(e);\n\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n t = cin.read_int;\n while (t--) {\n string s = cin.read_string;\n if (endsWith(s, \"po\")) writeln(\"FILIPINO\");\n else if (endsWith(s, \"desu\") || endsWith(s, \"masu\")) writeln(\"JAPANESE\");\n else writeln(\"KOREAN\"); \n } \n}"}], "negative_code": [], "src_uid": "816907d873bce3573ce1e5ae3f494768"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\treadln;\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto add = (i + 1 == n || i + 1 < n / 2);\n\t\t\tres += (2 << i) * (add ? +1 : -1);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tlong x, y;\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tif (i < n/2-1)\n\t\t\t{\n\t\t\t\tx += 2^^(i+1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ty += 2^^(i+1);\n\t\t\t}\n\t\t}\n\t\tx += 2^^n;\n\t\tans[ti] = x - y;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!long;\n long a = 2L^^N, b;\n foreach (i; 1..N/2) {\n a += 2L^^i;\n }\n foreach (i; N/2..N) {\n b += 2L^^i;\n }\n writeln(a - b);\n }\n}"}], "negative_code": [], "src_uid": "787a45f427c2db98b2ddb78925e0e0f1"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N, X; scanf(\"%d %d\\n\", &N, &X);\n auto A = readln.chomp.split(\" \").map!(to!int).array;\n auto B = readln.chomp.split(\" \").map!(to!int).array;\n\n A.sort;\n B.sort;\n\n void first() {\n auto a = A.dup,\n b = B.dup;\n int L = a.back + b.back;\n a.popBack; b.popBack;\n int bi = 0;\n int ans = 1;\n for (int ai = N - 2; ai >= 0; ai--) {\n if (a[ai] + b[bi] <= L) {\n bi++;\n } else {\n ans++;\n }\n }\n write(ans);\n }\n void second() {\n auto a = A.dup,\n b = B.dup;\n auto set = redBlackTree!(true)(b);\n int ans = 0;\n for (int ai = 0; ai < N; ai++) {\n auto r = set.upperBound(X - a[ai] - 1);\n if (r.empty) continue;\n set.removeKey(r.front);\n ans++;\n }\n write(ans);\n }\n first(); write(\" \"); second();\n writeln;\n}\n\n ", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 2 ^^ 14 - 1;\n\nvoid main()\n{\n int n, x;\n readf(\"%s %s\", &n, &x);\n readln;\n\n auto arr = new int[][] (2);\n foreach (i; 0 .. 2) {\n arr[i] = readln.chomp.split.map!(to!int).array;\n arr[i].sort().reverse();\n }\n \n debug { arr[0].writeln; }\n \n int chk(int idx1) {\n int ans = 0, mv = n-1;\n foreach (i; 0 .. n) {\n while (mv >= 0 && arr[idx1][i] + arr[1-idx1][mv] < x) { --mv; }\n \n if (mv >= 0) { \n ++ans;\n --mv;\n }\n }\n \n return ans;\n }\n \n int ans = max(chk(0), chk(1));\n writeln(\"1 \", ans);\n}"}], "negative_code": [], "src_uid": "77919677f562a6fd1af64bc8cbc79de5"} {"source_code": "import core.bitop, std.algorithm, std.conv, std.stdio, std.string;\nalias f = n => (n *= 2) - n.popcnt;\nvoid main() {foreach (t; 0..readln.strip.to!int) readln.strip.to!long.f.writeln;}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\n\t\tauto cnt = new long[](64);\n\t\tcnt[0] = 1;\n\t\tforeach (i; 1..64)\n\t\t{\n\t\t\tcnt[i] = cnt[i-1] * 2 + 1;\n\t\t}\n\n\t\tforeach (i; 0..64)\n\t\t{\n\t\t\tauto bit = 1L << i;\n\t\t\tif (n & bit)\n\t\t\t{\n\t\t\t\tans[ti] += cnt[i];\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import core.bitop,std.conv,std.stdio,std.string;\nalias f=n=>(n*=2)-n.popcnt;\nvoid main(){foreach(t;0..readln.strip.to!int)readln.strip.to!long.f.writeln;}\n"}, {"source_code": "import std.stdio;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.functional;\nimport std.conv;\nimport std.string;\nimport std.math;\nimport core.bitop;\n\nulong diff(ulong a, ulong b) {\n\tulong res = 0;\n\tforeach (bit; 0 .. 64) {\n\t\tif ((a & (1UL << bit)) != (b & (1UL << bit))) {\n\t\t\tres++;\n\t\t}\n\t}\n\treturn res;\n}\n\nulong calc(ulong a) {\n\tif ((a & (a - 1)) == 0) {\n\t\treturn a | (a - 1);\n\t}\n\telse {\n\t\tulong highestBit = 1UL << bsr(a);\n\t\treturn calc(a - highestBit) + calc(highestBit);\n\t}\n}\n\nvoid main() {\n\t// ulong res = 0;\n\t// foreach (i; 0 .. 1000) {\n\t// \tres += diff(i, i + 1);\n\t// \twrite(\"f(\", (i + 1).to!string.padLeft(' ', 10), \") = \", res.to!string(2).padLeft('0', 10));\n\t// \twriteln(\"; \", calc(i + 1).to!string(2).padLeft('0', 10));\n\t// }\n\tint tt = readln().chomp.to!int;\n\touter: foreach (t; 0 .. tt) {\n\t\tulong n = readln().chomp.to!ulong;\n\t\t// writeln(n.to!string(2).padLeft('0', 64));\n\t\twriteln(calc(n));\n\t}\n}\n"}], "negative_code": [], "src_uid": "2a4f4c91522d83bc8f1ca2f086d24c3c"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n string s = readln.strip;\n int n = to!int(s.length);\n\n int[26] min_idx = n;\n\n for (int i = n-1; i >= 0; i--) {\n min_idx[s[i]-'a'] = i;\n }\n\n debug {\n writefln!\"%s\"(min_idx);\n }\n\n foreach (i; 0 .. n) {\n int j = s[i] - 'a';\n if (min_idx[0 .. j].any!( (a) => a < i )) {\n write(\"Ann\\n\");\n } else {\n write(\"Mike\\n\");\n }\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n string s = readln.strip;\n int n = to!int(s.length);\n\n int[26] min_idx = n;\n\n for (int i = n-1; i >= 0; i--) {\n min_idx[s[i]-'a'] = i;\n }\n\n debug {\n writefln!\"%s\"(min_idx);\n }\n\n foreach (i; 0 .. n) {\n int j = s[i] - 'a';\n if (min_idx[0 .. j].find!( (a,b) => a < b )(i).empty) {\n writeln(\"Mike\");\n } else {\n writeln(\"Ann\");\n }\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n string s = readln.strip;\n int n = to!int(s.length);\n\n int[26] min_idx = n;\n\n for (int i = n-1; i >= 0; i--) {\n min_idx[s[i]-'a'] = i;\n }\n\n debug {\n writefln!\"%s\"(min_idx);\n }\n\n foreach (i; 0 .. n) {\n int j = s[i] - 'a';\n if (min_idx[0 .. j].any!( (a) => a < i )) {\n writeln(\"Ann\");\n } else {\n writeln(\"Mike\");\n }\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const S = readToken();\n \n char mn = 'z' + 1;\n foreach (c; S) {\n writeln((mn < c) ? \"Ann\" : \"Mike\");\n chmin(mn, c);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto s = RD!string;\n\tchar best = s[0];\n\twriteln(\"Mike\");\n\tforeach (c; s[1..$])\n\t{\n\t\tif (c <= best)\n\t\t{\n\t\t\twriteln(\"Mike\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"Ann\");\n\t\t}\n\t\tbest = min(best, c);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "1e107d9fb8bead4ad942b857685304c4"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n readln;\n \n auto r = () => readln.chomp.split.map!(to!int).array; \n auto c = r();\n auto a = r();\n \n debug { c.writeln; a.writeln; }\n \n auto ans = 0;\n int aidx = 0;\n foreach (e; c) {\n if (e > a[aidx]) continue;\n \n ans += 1;\n ++aidx;\n \n if (aidx == a.length) break;\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto C = readln.split.map!(to!int).array;\n auto A = readln.split.map!(to!int).array;\n int ans = 0;\n\n for (int i = 0, p = 0; i < N && p < M; ++i) {\n if (C[i] <= A[p]) {\n ans += 1;\n p += 1;\n }\n }\n\n ans.writeln;\n}\n"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m; rd(n, m);\n auto c=readln.split.to!(int[]);\n auto a=readln.split.to!(int[]);\n\n int cnt=0;\n for(int i=0, j=0; i<n && j<m; ){\n if(c[i]<=a[j]){\n cnt++;\n i++; j++;\n }else{\n i++;\n }\n }\n\n writeln(cnt);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "negative_code": [], "src_uid": "c3f080681e3da5e1290ef935ff91f364"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int letters = 26;\nimmutable int mod = 10 ^^ 9 + 7;\n\nvoid main () {\n\tint n;\n\twhile (readf (\" %s\", &n) > 0) {\n\t\treadln;\n\t\tauto s = readln.strip.map !(x => x - 'a').array;\n\n\t\tauto next = new int [] [] (n, letters);\n\t\tforeach (let; 0..letters) {\n\t\t\tint pos = n;\n\t\t\tforeach_reverse (i; 0..n) {\n\t\t\t\tif (s[i] == let) pos = i;\n\t\t\t\tnext[i][let] = pos;\n\t\t\t}\n\t\t}\n\n\t\tauto f = new long [] [] (2, n + 1);\n\t\tint b = 0;\n\t\tf[b][] = 0;\n\t\tf[b][0] = 1;\n\t\tforeach (num; 0..n)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tf[b][] = 0;\n\t\t\tforeach (pos; 0..n) {\n\t\t\t\tauto cur = f[!b][pos];\n\t\t\t\tauto ptr = next[pos].ptr;\n\t\t\t\tforeach (let; 0..letters) f[b][*(ptr + let)] += cur;\n\t\t\t}\n\t\t\tforeach (pos; 0..n) f[b][pos] %= mod;\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (pos; 0..n) res = (res + f[b][pos]) % mod;\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int letters = 26;\nimmutable int mod = 10 ^^ 9 + 7;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip.map !(x => x - 'a').array;\n\n\t\tauto next = new int [] [] (n, letters);\n\t\tforeach (let; 0..letters)\n\t\t{\n\t\t\tint pos = n;\n\t\t\tforeach_reverse (i; 0..n)\n\t\t\t{\n\t\t\t\tif (s[i] == let)\n\t\t\t\t{\n\t\t\t\t\tpos = i;\n\t\t\t\t}\n\t\t\t\tnext[i][let] = pos;\n\t\t\t}\n\t\t}\n\n\t\tauto f = new long [] [] (2, n + 1);\n\t\tint b = 0;\n\t\tf[b][] = 0;\n\t\tf[b][0] = 1;\n\t\tforeach (num; 0..n)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tf[b][] = 0;\n\t\t\tforeach (pos; 0..n)\n\t\t\t{\n\t\t\t\tauto cur = f[!b][pos];\n\t\t\t\tauto ptr = next[pos].ptr;\n\t\t\t\tf[b][*(ptr + 0)] += cur;\n\t\t\t\tf[b][*(ptr + 1)] += cur;\n\t\t\t\tf[b][*(ptr + 2)] += cur;\n\t\t\t\tf[b][*(ptr + 3)] += cur;\n\t\t\t\tf[b][*(ptr + 4)] += cur;\n\t\t\t\tf[b][*(ptr + 5)] += cur;\n\t\t\t\tf[b][*(ptr + 6)] += cur;\n\t\t\t\tf[b][*(ptr + 7)] += cur;\n\t\t\t\tf[b][*(ptr + 8)] += cur;\n\t\t\t\tf[b][*(ptr + 9)] += cur;\n\t\t\t\tf[b][*(ptr + 10)] += cur;\n\t\t\t\tf[b][*(ptr + 11)] += cur;\n\t\t\t\tf[b][*(ptr + 12)] += cur;\n\t\t\t\tf[b][*(ptr + 13)] += cur;\n\t\t\t\tf[b][*(ptr + 14)] += cur;\n\t\t\t\tf[b][*(ptr + 15)] += cur;\n\t\t\t\tf[b][*(ptr + 16)] += cur;\n\t\t\t\tf[b][*(ptr + 17)] += cur;\n\t\t\t\tf[b][*(ptr + 18)] += cur;\n\t\t\t\tf[b][*(ptr + 19)] += cur;\n\t\t\t\tf[b][*(ptr + 20)] += cur;\n\t\t\t\tf[b][*(ptr + 21)] += cur;\n\t\t\t\tf[b][*(ptr + 22)] += cur;\n\t\t\t\tf[b][*(ptr + 23)] += cur;\n\t\t\t\tf[b][*(ptr + 24)] += cur;\n\t\t\t\tf[b][*(ptr + 25)] += cur;\n\t\t\t}\n\t\t\tforeach (pos; 0..n)\n\t\t\t{\n\t\t\t\tf[b][pos] %= mod;\n\t\t\t}\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (pos; 0..n)\n\t\t{\n\t\t\tres += f[b][pos];\n\t\t\tif (res >= mod)\n\t\t\t{\n\t\t\t\tres -= mod;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "81ad3bb3d58a33016221d60a601790d4"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nlong[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new long[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readLong;\n\t\t}\n\t\t\n\t\tlong[] ASum = new long[N + 1];\n\t\tforeach (i; 0 .. N) {\n\t\t\tASum[i + 1] = ASum[i] + A[i];\n\t\t}\n\t\t\n\t\tlong ans;\n\t\t\n\t\tif (ASum[N] % 3 == 0) {\n\t\t\tconst target = ASum[N] / 3;\n\t\t\tlong cnt;\n\t\t\tforeach (i; 1 .. N) {\n\t\t\t\tif (ASum[i] == target * 2) {\n\t\t\t\t\tans += cnt;\n\t\t\t\t}\n\t\t\t\tif (ASum[i] == target) {\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.string;\n\nvoid solve(int[] s)\n{\n auto sum = 0;\n foreach (val; s)\n {\n sum += val;\n }\n if (sum % 3 != 0)\n {\n writeln(\"0\");\n return;\n }\n sum /= 3;\n auto n = cast(int)s.length;\n auto cnt = new int[n];\n auto last = 0;\n auto acc = 0;\n for (int i = n - 1; i >= 0; -- i)\n {\n cnt[i] = last;\n acc += s[i];\n if (acc == sum)\n {\n ++ cnt[i];\n }\n last = cnt[i];\n }\n long ans = 0;\n last = 0;\n acc = 0;\n foreach (i; 0 .. n)\n {\n acc += s[i];\n if (acc == sum && i + 2 < n)\n {\n ans += cnt[i + 2];\n }\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto s = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &s[i]);\n }\n readln();\n solve(s);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "4798211615bcff8730378330756ae63f"} {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos].dup;\n\t\t\t\tforeach_reverse(j;0..sz(ss[pos])-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\treal cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tforeach(v;parallel(r[x]))\n\t\t\t{\n\t\t\t\tauto p=r[y].upb(diam-v-1);\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<ss[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000L/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}", "positive_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos].dup;\n\t\t\t\tforeach_reverse(j;0..sz(ss[pos])-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\treal cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tforeach(v;r[x])\n\t\t\t{\n\t\t\t\tauto p=assumeSorted(r[y]).lowerBound(diam-v-1).length;\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<ss[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000L/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos].dup;\n\t\t\t\tforeach_reverse(j;0..sz(ss[pos])-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\treal cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tforeach(v;r[x])\n\t\t\t{\n\t\t\t\tauto p=r[y].upb(diam-v-1);\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<ss[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000L/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos].dup;\n\t\t\t\tforeach_reverse(j;0..sz(ss[pos])-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\treal cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tauto a=assumeSorted(r[y]);\n\t\t\tforeach(v;r[x])\n\t\t\t{\n\t\t\t\tauto p=a.lowerBound(diam-v-1).length;\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<ss[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000L/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}"}], "negative_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos];\n\t\t\t\tforeach_reverse(j;0..ss[pos].length-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\treal cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tforeach(v;r[x])\n\t\t\t{\n\t\t\t\tauto p=upb(r[y],diam-v-1);\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<r[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000L/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos];\n\t\t\t\tforeach_reverse(j;0..sz(ss[pos])-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\treal cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tauto a=assumeSorted(r[y]);\n\t\t\tforeach(v;r[x])\n\t\t\t{\n\t\t\t\tauto p=a.lowerBound(diam-x-1).length;\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<r[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000L/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos];\n\t\t\t\tforeach_reverse(j;0..sz(ss[pos])-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\tdouble cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tauto a=assumeSorted(r[y]);\n\t\t\tforeach(v;r[x])\n\t\t\t{\n\t\t\t\tauto p=a.lowerBound(diam-v-1).length;\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<ss[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos];\n\t\t\t\tforeach_reverse(j;0..sz(ss[pos])-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\treal cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tforeach(v;r[x])\n\t\t\t{\n\t\t\t\tauto p=r[y].upb(diam-v-1);\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<ss[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000L/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,q,m;\nloop:while(read(n,m,q))\n\t{\n\t\tauto g=new int[][n+2],r=new long[][n+2],ss=new long[][n+2],comps=new int[][n+2];\n\t\tauto c=new int[n+2],d=new int[n+2];\n\t\tint pos=1;\n\t\tforeach(i;0..m)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tvoid dfs0(int v,int pr=-1)\n\t\t{\n\t\t\tcomps[pos]~=v;\n\t\t\tc[v]=pos;\n\t\t\tforeach(x;g[v])if(x!=pr)dfs0(x,v);\n\t\t}\n\t\tvoid dfs(int v,int pr=-1,int h=0)\n\t\t{\n\t\t\td[v]=max(d[v],h);\n\t\t\tforeach(x;g[v])if(x!=pr)dfs(x,v,h+1);\n\t\t}\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tif(c[i]==0)\n\t\t\t{\n\t\t\t\tdfs0(i);\n\t\t\t\tdfs(i);\n\t\t\t\tint ans=0,v=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t\td[x]=0;\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tans=0;\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tif(ans<d[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans=d[x];\n\t\t\t\t\t\tv=x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdfs(v);\n\t\t\t\tforeach(x;comps[pos])\n\t\t\t\t{\n\t\t\t\t\tr[pos]~=d[x];\n\t\t\t\t}\n\t\t\t\tsort(r[pos]);\n\t\t\t\tss[pos]=r[pos];\n\t\t\t\tforeach_reverse(j;0..ss[pos].length-1)\n\t\t\t\t{\n\t\t\t\t\tss[pos][j]+=ss[pos][j+1];\n\t\t\t\t}\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\t\treal cel(int x,int y)\n\t\t{\n\t\t\tlong ans;\n\t\t\tlong diam=max(r[x].back,r[y].back);\n\t\t\tauto a=assumeSorted(r[y]);\n\t\t\tforeach(v;r[x])\n\t\t\t{\n\t\t\t\tauto p=a.lowerBound(diam-x-1).length;\n\t\t\t\tans+=p*diam;\n\t\t\t\tif(p<r[y].length)ans+=ss[y][p]+(ss[y].length-p)*(v+1);\n\t\t\t}\n\t\t\treturn ans*1.00000L/(1L*r[x].length*r[y].length);\n\t\t}\n\t\talias getans=memoize!cel;\n\t\tforeach(ii;0..q)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(u,v);\n\t\t\tint p1=c[u],p2=c[v];\n\t\t\tif(r[p1].length>r[p2].length)swap(p2,p1);\n\t\t\tif(p1==p2)write(\"-1\\n\");\n\t\t\telse writef(\"%.10f\\n\",getans(p1,p2));\n\t\t}\n\t}\n}"}], "src_uid": "475afda5d655ed090b296a1a1a1fca3c"} {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main() {\n int N, K;\n readf(\" %s %s\", &N, &K);\n int[] A = new int[N];\n foreach (i, ref a; A) {\n readf(\" %s\", &a);\n if (a < 0 && K > 0) {\n a *= -1;\n K--;\n }\n }\n sort(A);\n while (K > 0) {\n A[0] *= -1;\n K--;\n }\n writeln(reduce!(\"a + b\")(0, A));\n}\n", "positive_code": [{"source_code": "import std.stdio : write, writeln, writefln, stdin;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.algorithm : max, min;\n\nint n;\nint k;\nint[] a;\n\nT sum(T)(T[] l ...){\n\tT s;\n\tforeach(v; l){\n\t\ts += v;\n\t}\n\treturn s;\n}\n\nvoid main(){\n\tn.next;\n\tk.next;\n\ta = a.init;\n\tforeach(i; n.iota){\n\t\ta ~= next!int();\n\t}\n\t\n\t/+\n\tforeach(ref v; a){\n\t\tif( v > 0 ){ break; }\n\t\tif( k <= 0 ){ break; }\n\t\tv *= -1;\n\t\t--k;\n\t}\n\t+/\n\tbool flag = true;\n\tfor(int i=0; 0<k; --k){\n\t\tif( a[i] >= 0 ){\n\t\t\ta.sort;\n\t\t\tfor(int j=0; j<k%2; ++j){\n\t\t\t\ta[0]*=-1;\n\t\t\t}\n\t\t\tbreak;\n\t\t}else{\n\t\t\ta[i] *= -1;\n\t\t\tif( i+1 < n ) ++i;\n\t\t}\n\t\t\n\t}\n\t\n\ta.sum.writeln;\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nshared string[] input;\nshared string delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nvoid next(T)(ref T v){\n\tv = next!T();\n}\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn true;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio : write, writeln, writefln, stdin;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.algorithm : max, min;\n\nint n;\nint k;\nint[] a;\n\nT sum(T)(T[] l ...){\n\tT s;\n\tforeach(v; l){\n\t\ts += v;\n\t}\n\treturn s;\n}\n\nvoid main(){\n\tn.next;\n\tk.next;\n\ta = a.init;\n\tforeach(i; n.iota){\n\t\ta ~= next!int();\n\t}\n\t\n\ta.sort;\n\tforeach(ref v; a){\n\t\tif( v > 0 ){ break; }\n\t\tif( k <= 0 ){ break; }\n\t\tv *= -1;\n\t\t--k;\n\t}\n\ta.sort;\n\tforeach(ref v; a){\n\t\tif( k <= 0 ){ break; }\n\t\tv *= -1;\n\t\t--k;\n\t}\n\t\n\ta.sum.writeln;\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nshared string[] input;\nshared string delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nvoid next(T)(ref T v){\n\tv = next!T();\n}\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn true;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}, {"source_code": "import std.stdio : write, writeln, writefln, stdin;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.algorithm : max, min;\n\nint n;\nint k;\nint[] a;\n\nT sum(T)(T[] l ...){\n\tT s;\n\tforeach(v; l){\n\t\ts += v;\n\t}\n\treturn s;\n}\n\nvoid main(){\n\tn.next;\n\tk.next;\n\ta = a.init;\n\tforeach(i; n.iota){\n\t\ta ~= next!int();\n\t}\n\t\n\t/+\n\tforeach(ref v; a){\n\t\tif( v > 0 ){ break; }\n\t\tif( k <= 0 ){ break; }\n\t\tv *= -1;\n\t\t--k;\n\t}\n\t+/\n\tbool flag = true;\n\tfor(int i=0; 0<k; --k){\n\t\tif( a[i] >= 0){\n\t\t\tflag = false;\n\t\t}\n\t\t\n\t\ta[i] *= -1;\n\n\t\tif( flag && i+1<n ){\n\t\t\t++i;\n\t\t}\n\t}\n\t\n\tassert( k == 0 );\n\ta.sum.writeln;\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nshared string[] input;\nshared string delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nvoid next(T)(ref T v){\n\tv = next!T();\n}\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn true;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}], "src_uid": "befd3b1b4afe19ff619c0b34ed1a4966"} {"source_code": "module _;\nvoid main() {\n\timport std.stdio;\n\timport std.string, std.conv;\n\tint n = readln.strip.to!int;\n\tauto s = readln.strip;\n\n\tbool check(int limit, ref string co, bool doco) {\n\t\tint r = 0, b = 0;\n\t\tforeach(ch; s) {\n\t\t\tif (ch == '(') {\n\t\t\t\tif (r < limit) {\n\t\t\t\t\tr++;\n\t\t\t\t\tif (doco) co ~= '0';\n\t\t\t\t} else if (b < limit) {\n\t\t\t\t\tb++;\n\t\t\t\t\tif (doco) co ~='1';\n\t\t\t\t} else {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (r > 0) {\n\t\t\t\t\tr--;\n\t\t\t\t\tif (doco) co ~= '0';\n\t\t\t\t} else if (b > 0) {\n\t\t\t\t\tb--;\n\t\t\t\t\tif (doco) co ~='1';\n\t\t\t\t} else {\n\t\t\t\t\t// impossible\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tstring ans = \"\";\n\tint l = 0, r = n;\n\twhile (l < r-1) {\n\t\tint mid = (l+r)/2;\n\t\tif (check(mid, ans, false)) {\n\t\t\tr = mid;\n\t\t} else {\n\t\t\tl = mid;\n\t\t}\n\t}\n\tcheck(r, ans, true);\n\twriteln(ans);\n}\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.random;\nvoid main() {\n immutable n = readln.strip.to!int;\n auto s = readln.take(n).array;\n int[] st;\n auto x = new int[n];\n auto ans = new char[n];\n foreach (i; 0 .. n) {\n if (s[i] == '(') {\n st ~= i;\n ans[i] = (st.length & 1) ? '0' : '1';\n } else {\n int j = st.back;\n st.popBack ();\n x[i] = j;\n x[j] = i;\n ans[i] = ans[j];\n }\n }\n writeln (ans);\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tstring s = readln.chomp;\n\t\n\tint d = 0;\n\tint dmax = 0;\n\tforeach(c; s){\n\t\tif(c == '(') d += 1;\n\t\telse d -= 1;\n\t\tif(d > dmax) dmax = d;\n\t}\n\t\n\tchar[] ans;\n\tforeach(c; s){\n\t\tif(c == '('){\n\t\t\td += 1;\n\t\t\tif(d > dmax / 2) ans ~= \"1\";\n\t\t\telse ans ~= \"0\";\n\t\t}\n\t\telse{\n\t\t\tif(d > dmax / 2) ans ~= \"1\";\n\t\t\telse ans ~= \"0\";\n\t\t\td -= 1;\n\t\t}\n\t}\n\t\n\tans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto ans = new int[](N);\n int tmp = 0;\n foreach (i; 0..N) {\n if (S[i] == '(') {\n ans[i] = tmp % 2;\n tmp += 1;\n } else {\n tmp -= 1;\n ans[i] = tmp % 2;\n }\n }\n ans.map!(to!string).join(\"\").writeln;\n}\n"}], "negative_code": [], "src_uid": "73b18cc560ea94476903f79a695d4268"} {"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}\n", "positive_code": [{"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}\n"}, {"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}\n"}, {"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}\n"}, {"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.string;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto s = new int [n];\n\t\tforeach (ref x; s)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tsort !(\"a > b\") (s);\n\n\t\tint m;\n\t\treadf (\" %s \", &m);\n\t\tint [] t;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tauto r = readln.strip;\n\t\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t\t}\n\t\ts = s[0..m];\n\n\t\tint m2 = 1 << m;\n\t\tauto f = new int [m2];\n\t\tf[m2 - 1] = 0;\n\n\t\tforeach_reverse (u; 0..m2 - 1)\n\t\t{\n\t\t\tint i = popcnt (u);\n\t\t\tf[u] = (t[i] & 1) ? int.max : int.min;\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tif (!(u & (1 << j)))\n\t\t\t\t{\n\t\t\t\t\tint v = u ^ (1 << j);\n\t\t\t\t\tswitch (t[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tcase 0: // b 1\n\t\t\t\t\t\t\tf[u] = max (f[u],\n\t\t\t\t\t\t\t f[v]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 1: // b 2\n\t\t\t\t\t\t\tf[u] = min (f[u],\n\t\t\t\t\t\t\t f[v]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2: // p 1\n\t\t\t\t\t\t\tf[u] = max (f[u],\n\t\t\t\t\t\t\t f[v] + s[j]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3: // p 2\n\t\t\t\t\t\t\tf[u] = min (f[u],\n\t\t\t\t\t\t\t f[v] - s[j]);\n\t\t\t\t\t\t break;\n\t\t\t\t\t default:\n\t\t\t\t\t\t\tassert (false);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (f[0]);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio, std.string, core.bitop;\nvoid main ()\n{\n\tint n;\n\treadf (\" %s\", &n);\n\tauto s = new int [n];\n\tforeach (ref x; s) readf (\" %s\", &x);\n\tsort !(\"a > b\") (s);\n\tint m;\n\treadf (\" %s \", &m);\n\tint [] t;\n\tforeach (i; 0..m)\n\t{\n\t\tauto r = readln.strip;\n\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t}\n\tint m2 = 1 << m;\n\tauto f = new int [m2];\n\tforeach (u; 1..m2)\n\t{\n\t\tint i = m - popcnt (u);\n\t\tf[u] = (t[i] & 1) ? int.max : int.min;\n\t\tforeach (j; 0..m) if (u & (1 << j))\n\t\t{\n\t\t\tint v = u ^ (1 << j);\n\t\t\tswitch (t[i])\n\t\t\t{\n\t\t\t\tcase 0: f[u] = max (f[u], f[v]); break;\n\t\t\t\tcase 1: f[u] = min (f[u], f[v]); break;\n\t\t\t\tcase 2: f[u] = max (f[u], f[v] + s[j]); break;\n\t\t\t\tcase 3: f[u] = min (f[u], f[v] - s[j]); break;\n\t\t\t\tdefault: assert (false);\n\t\t\t}\n\t\t}\n\t}\n\twriteln (f[$ - 1]);\n}\n"}, {"source_code": "import std.algorithm, std.stdio, std.string, core.bitop;\nvoid main ()\n{\n\tint n;\n\tscanf (\" %d\", &n);\n\tauto s = new int [n];\n\tforeach (ref x; s) scanf (\" %d\", &x);\n\tsort !(\"a > b\") (s);\n\tint m;\n\tscanf (\" %d \", &m);\n\tint [] t;\n\tforeach (i; 0..m)\n\t{\n\t\tauto r = readln.strip;\n\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t}\n\tint m2 = 1 << m;\n\tauto f = new int [m2];\n\tforeach_reverse (u; 0..m2 - 1)\n\t{\n\t\tint i = popcnt (u);\n\t\tf[u] = (t[i] & 1) ? int.max : int.min;\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tif (u & (1 << j)) continue;\n\t\t\tint v = u ^ (1 << j);\n\t\t\tswitch (t[i])\n\t\t\t{\n\t\t\t\tcase 0: f[u] = max (f[u], f[v]); break;\n\t\t\t\tcase 1: f[u] = min (f[u], f[v]); break;\n\t\t\t\tcase 2: f[u] = max (f[u], f[v] + s[j]); break;\n\t\t\t\tcase 3: f[u] = min (f[u], f[v] - s[j]); break;\n\t\t\t\tdefault: assert (false);\n\t\t\t}\n\t\t}\n\t}\n\twriteln (f[0]);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int INF = int.max / 2;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto s = new int [n];\n\t\tforeach (ref x; s)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tsort !(\"a > b\") (s);\n\n\t\tint m;\n\t\treadf (\" %s \", &m);\n\t\tint [] t;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tauto r = readln.strip;\n\t\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t\t\tdebug {writeln (r, ' ', t[i]);}\n\t\t}\n\t\ts = s[0..m];\n\n\t\tint m2 = 1 << m;\n\t\tauto f = new int [] [] (m + 1, m2);\n\t\tforeach (ref g; f)\n\t\t{\n\t\t\tg[] = int.max;\n\t\t}\n\n\t\tint fun (int i, int u)\n\t\t{\n\t\t\tif (i == m)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (f[i][u] != int.max)\n\t\t\t{\n\t\t\t\treturn f[i][u];\n\t\t\t}\n\t\t\tint res = (t[i] & 1) ? +INF : -INF;\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tif (!(u & (1 << j)))\n\t\t\t\t{\n\t\t\t\t\tint v = u ^ (1 << j);\n\t\t\t\t\tswitch (t[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tcase 0: // b 1\n\t\t\t\t\t\t\tres = max (res,\n\t\t\t\t\t\t\t fun (i + 1, v));\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 1: // b 2\n\t\t\t\t\t\t\tres = min (res,\n\t\t\t\t\t\t\t fun (i + 1, v));\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2: // p 1\n\t\t\t\t\t\t\tres = max (res,\n\t\t\t\t\t\t\t fun (i + 1, v) + s[j]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3: // p 2\n\t\t\t\t\t\t\tres = min (res,\n\t\t\t\t\t\t\t fun (i + 1, v) - s[j]);\n\t\t\t\t\t\t break;\n\t\t\t\t\t default:\n\t\t\t\t\t\t\tassert (false);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (i, ' ', u, ' ', res);}\n\t\t\tf[i][u] = res;\n\t\t\treturn res;\n\t\t}\n\n\t\twriteln (fun (0, 0));\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio, std.string, core.bitop;\nvoid main ()\n{\n\tint n;\n\treadf (\" %s\", &n);\n\tauto s = new int [n];\n\tforeach (ref x; s) readf (\" %s\", &x);\n\tsort !(\"a > b\") (s);\n\tint m;\n\treadf (\" %s \", &m);\n\tint [] t;\n\tforeach (i; 0..m)\n\t{\n\t\tauto r = readln.strip;\n\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t}\n\tint m2 = 1 << m;\n\tauto f = new int [m2];\n\tforeach_reverse (u; 0..m2 - 1)\n\t{\n\t\tint i = popcnt (u);\n\t\tf[u] = (t[i] & 1) ? int.max : int.min;\n\t\tforeach (j; 0..m) if (!(u & (1 << j)))\n\t\t{\n\t\t\tint v = u ^ (1 << j);\n\t\t\tswitch (t[i])\n\t\t\t{\n\t\t\t\tcase 0: f[u] = max (f[u], f[v]); break;\n\t\t\t\tcase 1: f[u] = min (f[u], f[v]); break;\n\t\t\t\tcase 2: f[u] = max (f[u], f[v] + s[j]); break;\n\t\t\t\tcase 3: f[u] = min (f[u], f[v] - s[j]); break;\n\t\t\t\tdefault: assert (false);\n\t\t\t}\n\t\t}\n\t}\n\twriteln (f[0]);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int INF = int.max / 2;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto s = new int [n];\n\t\tforeach (ref x; s)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tsort !(\"a > b\") (s);\n\n\t\tint m;\n\t\treadf (\" %s \", &m);\n\t\tint [] t;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tauto r = readln.strip;\n\t\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t\t\tdebug {writeln (r, ' ', t[i]);}\n\t\t}\n\t\ts = s[0..m];\n\n\t\tint m2 = 1 << m;\n\t\tauto f = new int [m2];\n\t\tf[] = int.max;\n\n\t\tint fun (int u)\n\t\t{\n\t\t\tint i = popcnt (u);\n\t\t\tif (i == m)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (f[u] != int.max)\n\t\t\t{\n\t\t\t\treturn f[u];\n\t\t\t}\n\t\t\tint res = (t[i] & 1) ? +INF : -INF;\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tif (!(u & (1 << j)))\n\t\t\t\t{\n\t\t\t\t\tint v = u ^ (1 << j);\n\t\t\t\t\tswitch (t[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tcase 0: // b 1\n\t\t\t\t\t\t\tres = max (res,\n\t\t\t\t\t\t\t fun (v));\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 1: // b 2\n\t\t\t\t\t\t\tres = min (res,\n\t\t\t\t\t\t\t fun (v));\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2: // p 1\n\t\t\t\t\t\t\tres = max (res,\n\t\t\t\t\t\t\t fun (v) + s[j]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3: // p 2\n\t\t\t\t\t\t\tres = min (res,\n\t\t\t\t\t\t\t fun (v) - s[j]);\n\t\t\t\t\t\t break;\n\t\t\t\t\t default:\n\t\t\t\t\t\t\tassert (false);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tf[u] = res;\n\t\t\treturn res;\n\t\t}\n\n\t\twriteln (fun (0));\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio, std.string, core.bitop;\nvoid main () {\n\tint n;\n\treadf (\" %s\", &n);\n\tauto s = new int [n];\n\tforeach (ref x; s) readf (\" %s\", &x);\n\tsort !(\"a > b\") (s);\n\tint m;\n\treadf (\" %s \", &m);\n\tint [] t;\n\tforeach (i; 0..m) {\n\t\tauto r = readln.strip;\n\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t}\n\tint m2 = 1 << m;\n\tauto f = new int [m2];\n\tforeach (u; 1..m2) {\n\t\tint i = m - u.popcnt;\n\t\tf[u] = (t[i] & 1) ? int.max : int.min;\n\t\tforeach (j; 0..m) if (u & (1 << j)) {\n\t\t\tint v = u ^ (1 << j);\n\t\t\tswitch (t[i]) {\n\t\t\t\tcase 0: f[u] = max (f[u], f[v]); break;\n\t\t\t\tcase 1: f[u] = min (f[u], f[v]); break;\n\t\t\t\tcase 2: f[u] = max (f[u], f[v] + s[j]); break;\n\t\t\t\tcase 3: f[u] = min (f[u], f[v] - s[j]); break;\n\t\t\t\tdefault: assert (false);\n\t}\t}\t}\n\tf[$ - 1].writeln;\n}\n"}, {"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}"}, {"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}\n"}, {"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}\n"}, {"source_code": "import std.algorithm,std.stdio,core.bitop;void main(){int n,m,w,k;scanf(\"%d\",&n);auto s=new int[n];foreach(ref x;s)scanf(\"%d\",&x);sort!\"a>b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<<m;auto f=new int[w];foreach(u;1..w){k=m-u.popcnt;f[u]=(t[k]&1)?int.max:int.min;foreach(j;0..m)if(u&(1<<j)){int v=u^(1<<j);switch(t[k]){case 0:f[u]=max(f[u],f[v]);break;case 1:f[u]=min(f[u],f[v]);break;case 2:f[u]=max(f[u],f[v]+s[j]);break;case 3:f[u]=min(f[u],f[v]-s[j]);break;default:}}}f[w-1].writeln;}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int INF = int.max / 2;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto s = new int [n];\n\t\tforeach (ref x; s)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tsort !(\"a > b\") (s);\n\n\t\tint m;\n\t\treadf (\" %s \", &m);\n\t\tint [] t;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tauto r = readln.strip;\n\t\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t\t\tdebug {writeln (r, ' ', t[i]);}\n\t\t}\n\t\ts = s[0..m];\n\n\t\tint m2 = 1 << m;\n\t\tauto f = new int [] [] (m + 1, m2);\n\t\tf[0][0] = 0;\n\t\tforeach (i; 1..m + 1)\n\t\t{\n\t\t\tforeach (u; 0..m2)\n\t\t\t{\n\t\t\t\tif (popcnt (u) != i)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tf[i][u] = (t[i - 1] & 1) ? -INF : +INF;\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\tif (u & (1 << j))\n\t\t\t\t\t{\n\t\t\t\t\t\tint v = u ^ (1 << j);\n\t\t\t\t\t\tswitch (t[i - 1])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase 0: // b 1\n\t\t\t\t\t\t\t\tf[i][u] = min (f[i][u],\n\t\t\t\t\t\t\t\t f[i - 1][v]);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase 1: // b 2\n\t\t\t\t\t\t\t\tf[i][u] = max (f[i][u],\n\t\t\t\t\t\t\t\t f[i - 1][v]);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase 2: // p 1\n\t\t\t\t\t\t\t\tf[i][u] = min (f[i][u],\n\t\t\t\t\t\t\t\t f[i - 1][v] + s[j]);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase 3: // p 2\n\t\t\t\t\t\t\t\tf[i][u] = max (f[i][u],\n\t\t\t\t\t\t\t\t f[i - 1][v] - s[j]);\n\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t default:\n\t\t\t\t\t\t\t\tassert (false);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (i, ' ', u, ' ', f[i][u]);}\n\t\t\t}\n\t\t}\n\t\twriteln (f[m][m2 - 1]);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int INF = int.max / 2;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto s = new int [n];\n\t\tforeach (ref x; s)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tsort !(\"a > b\") (s);\n\n\t\tint m;\n\t\treadf (\" %s \", &m);\n\t\tint [] t;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tauto r = readln.strip;\n\t\t\tt ~= (r[0] == 'p') * 2 + (r[2] == '2');\n\t\t}\n\t\ts = s[0..m];\n\n\t\tint m2 = 1 << m;\n\t\tauto f = new int [] [] (m + 1, m2);\n\t\tf[0][0] = 0;\n\t\tforeach (i; 1..m + 1)\n\t\t{\n\t\t\tforeach (u; 0..m2)\n\t\t\t{\n\t\t\t\tif (popcnt (u) != i)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tf[i][u] = (t[i - 1] & 1) ? +INF : -INF;\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\tif (u & (1 << j))\n\t\t\t\t\t{\n\t\t\t\t\t\tint v = u ^ (1 << j);\n\t\t\t\t\t\tswitch (t[i - 1])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\t\tf[i][u] = max (f[i][u],\n\t\t\t\t\t\t\t\t f[i - 1][v]);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\t\tf[i][u] = min (f[i][u],\n\t\t\t\t\t\t\t\t f[i - 1][v]);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\t\tf[i][u] = max (f[i][u],\n\t\t\t\t\t\t\t\t f[i - 1][v] - s[j]);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\t\tf[i][u] = min (f[i][u],\n\t\t\t\t\t\t\t\t f[i - 1][v] + s[j]);\n\t\t\t\t\t\t\t break;\n\t\t\t\t\t\t default:\n\t\t\t\t\t\t\t\tassert (false);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (-f[m][m2 - 1]);\n\t}\n}\n"}], "src_uid": "f0c830400468c805bd955198d177d5be"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n const Q = readInt();\n auto R = new int[Q];\n auto C = new int[Q];\n foreach (q; 0 .. Q) {\n R[q] = readInt() - 1;\n C[q] = readInt() - 1;\n }\n \n auto uf = new int[M + N];\n uf[] = -1;\n foreach (q; 0 .. Q) {\n uf.connect(R[q], M + C[q]);\n }\n int num, isoRow, isoCol;\n foreach (u; 0 .. M + N) {\n if (uf[u] < 0) {\n if (-uf[u] >= 2) {\n ++num;\n } else {\n (u < M) ? ++isoRow : ++isoCol;\n }\n }\n }\n debug {\n writeln(num, \" \", isoRow, \" \", isoCol);\n }\n int ans;\n if (num == 0) {\n ans = M + N - 1;\n } else {\n ans += num - 1;\n ans += isoRow;\n ans += isoCol;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, q;\n readf(\"%s %s %s\", &n, &m, &q);\n readln;\n \n Tuple!(int, int)[] prs;\n \n foreach (_; 0 .. q) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n prs ~= tuple(x, y);\n }\n \n struct uf {\n int[] p;\n int[] r;\n int sets;\n \n this(int sz) {\n p = new int[] (sz+1);\n foreach (i; 0 .. sz+1) { p[i] = i; }\n r = new int[] (sz+1);\n r[] = 0;\n sets = sz;\n }\n \n int fnd(int x) {\n if (p[x] != x) { p[x] = fnd(p[x]); }\n \n return p[x];\n }\n \n void uni(int a, int b) {\n a = fnd(a);\n b = fnd(b);\n \n if (a == b) { return; }\n \n if (r[a] > r[b]) { swap(a, b); }\n \n p[a] = b;\n if (r[a] == r[b]) { r[b] += 1; }\n \n --sets;\n }\n }\n \n uf u = uf(m);\n \n prs.sort();\n \n foreach (i; 1 .. q) {\n if (prs[i-1][0] == prs[i][0]) {\n u.uni(prs[i-1][1], prs[i][1]);\n }\n }\n \n int groups = u.sets;\n \n debug { groups.writeln; }\n \n int emptyRows = n - prs.map!(t => t[0]).array.uniq.array.length.to!int;\n \n auto ans = groups - 1 + emptyRows;\n \n ans.writeln;\n}"}, {"source_code": "import std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, m, q;\n\twhile (readf (\" %s %s %s\", &n, &m, &q) > 0)\n\t{\n\t\tint res = n + m - 1;\n\t\tauto p = (n + m).iota.array;\n\n\t\tint root (int w)\n\t\t{\n\t\t\tif (p[w] != w)\n\t\t\t{\n\t\t\t\tp[w] = root (p[w]);\n\t\t\t}\n\t\t\treturn p[w];\n\t\t}\n\n\t\tbool unite (int u, int v)\n\t\t{\n\t\t\tu = root (u);\n\t\t\tv = root (v);\n\t\t\tif (u == v)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tp[u] = v;\n\t\t\treturn true;\n\t\t}\n\n\t\tforeach (i; 0..q)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tv += n;\n\t\t\tif (unite (u, v))\n\t\t\t{\n\t\t\t\tres -= 1;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto m = next!int;\n auto adjr = new int[][](n);\n auto visr = new bool[](n);\n auto adjc = new int[][](m);\n auto visc = new bool[](m);\n auto q = next!int;\n foreach(qi; 0 .. q)\n {\n auto r = next!int - 1;\n auto c = next!int - 1;\n adjr[r] ~= c;\n adjc[c] ~= r;\n }\n void dfs(int i, int roc)\n {\n if (roc)\n {\n\tvisr[i] = true;\n\tforeach(nei; adjr[i])\n\t if (!visc[nei])\n\t dfs(nei, 0);\n }\n else\n {\n\tvisc[i] = true;\n\tforeach(nei; adjc[i])\n\t if (!visr[nei])\n\t dfs(nei, 1);\n }\n }\n int cmps = 0;\n foreach(i; 0 .. n)\n {\n if (!visr[i])\n\t{\n\t dfs(i, 1);\n\t cmps++;\n\t}\n }\n \n foreach(i; 0 .. m)\n {\n if (!visc[i])\n\t{\n\t dfs(i, 0);\n\t cmps++;\n\t}\n }\n (cmps - 1).writeln;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n const Q = readInt();\n auto R = new int[Q];\n auto C = new int[Q];\n foreach (q; 0 .. Q) {\n R[q] = readInt() - 1;\n C[q] = readInt() - 1;\n }\n \n auto uf = new int[M + N];\n uf[] = -1;\n foreach (q; 0 .. Q) {\n uf.connect(R[q], M + C[q]);\n }\n int num, isoRow, isoCol;\n foreach (u; 0 .. M + N) {\n if (uf[u] < 0) {\n if (-uf[u] >= 2) {\n ++num;\n } else {\n (u < M) ? ++isoRow : ++isoCol;\n }\n }\n }\n debug {\n writeln(num, \" \", isoRow, \" \", isoCol);\n }\n int ans = num - 1;\n ans += max(isoRow, isoCol);\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n const Q = readInt();\n auto R = new int[Q];\n auto C = new int[Q];\n foreach (q; 0 .. Q) {\n R[q] = readInt() - 1;\n C[q] = readInt() - 1;\n }\n \n auto uf = new int[M + N];\n uf[] = -1;\n foreach (q; 0 .. Q) {\n uf.connect(R[q], M + C[q]);\n }\n int num, isoRow, isoCol;\n foreach (u; 0 .. M + N) {\n if (uf[u] < 0) {\n if (-uf[u] >= 2) {\n ++num;\n } else {\n (u < M) ? ++isoRow : ++isoCol;\n }\n }\n }\n debug {\n writeln(num, \" \", isoRow, \" \", isoCol);\n }\n int ans;\n if (num == 0) {\n ans = M + N - 1;\n } else {\n ans += num - 1;\n ans += max(isoRow, isoCol);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "acd48e32c96a10cc0d4161225407bf67"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto p = n.iota.array;\r\n\t\tp.schwartzSort !(i => a[i], SwapStrategy.stable);\r\n\t\tauto s = p.map !(i => a[i]).group.map !(i => i[1]).maxElement;\r\n\t\tdebug {writeln (\"s = \", s);}\r\n\t\tauto q = p[s..$] ~ p[0..s];\r\n\t\tauto b = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tb[q[i]] = a[p[i]];\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (b);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt;\n }\n \n auto xss = new int[][N + 1];\n foreach (i; 0 .. N) {\n xss[A[i]] ~= i;\n }\n auto lens = new int[N + 1];\n foreach (a; 1 .. N + 1) {\n lens[a] = cast(int)(xss[a].length);\n }\n \n auto as = iota(1, N + 1).array;\n as.sort!((a, b) => (lens[a] > lens[b]));\n debug {\n writeln(\"xss = \", xss);\n writeln(\"lens = \", lens);\n writeln(\"as = \", as);\n }\n \n auto ans = new int[N];\n for (; lens[as[0]] >= 1; ) {\n int[] ys;\n foreach (a; as) {\n if (lens[a] == 0) {\n break;\n }\n ys ~= xss[a][--lens[a]];\n }\n debug {\n writeln(\"ys = \", ys);\n }\n const ysLen = cast(int)(ys.length);\n foreach (j; 0 .. ysLen - 1) {\n ans[ys[j]] = A[ys[j + 1]];\n }\n ans[ys[ysLen - 1]] = A[ys[0]];\n }\n \n foreach (i; 0 .. N) {\n if (i) write(\" \");\n write(ans[i]);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "01703877719e19dd8551e4599c3e1c85"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tauto tot = a.sum;\r\n\t\tauto rem = tot % n;\r\n\t\tans[ti] = rem * (n-rem);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1543/problem/B\n// math, greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n long[] a = readln.split.map!(to!long).array;\n long A = a.sum % n;\n writefln(\"%s\", A * (n - A));\n}\n}\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\nimport std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n while(tests--) {\r\n int n; readf!\"%s\\n\"(n);\r\n auto a = readln.splitter.map!(to!long).array;\r\n long s = a.sum;\r\n long r = s % n;\r\n (r * (n - r)).writeln;\r\n }\r\n\r\n} // main\r\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n = scan!int;\n auto arr = scanArray;\n arr.sort;\n ll summ = arr.sum;\n ll av = summ / n;\n ll rem = summ % n;\n writeln(rem * (n - rem));\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array.sort.array;\n auto sum = a.sum;\n if (sum % n == 0) {\n writeln(0);\n continue;\n }\n auto avgru = (sum + n - 1) / n;\n auto avgrd = (sum) / n;\n auto rem = sum - avgrd * n;\n// writefln(\"n=%d rem=%d\", n, rem);\n long result = rem * abs(n - rem);\n writeln(result);\n }\n}\n"}], "negative_code": [], "src_uid": "935bceb69117d06eb75121c805bff69c"} {"source_code": "module cf_276B;\n\nimport std.stdio;\n\nvoid main() {\n immutable MAX_LETTER_COUNT = 26;\n immutable FIRST_LETTER = 'a';\n\n string text;\n int[MAX_LETTER_COUNT] counters;\n\n readf(\"%s\\n\", &text);\n\n for (int i = 0; i < text.length; ++i) {\n ++counters[text[i] - FIRST_LETTER];\n }\n\n int odds = 0;\n for (int i = 0; i < MAX_LETTER_COUNT; ++i) {\n if (counters[i] % 2 != 0) {\n ++odds;\n }\n }\n\n if (odds == 0 || odds % 2 != 0) {\n writeln(\"First\");\n } else {\n writeln(\"Second\");\n }\n}", "positive_code": [{"source_code": "module cf_276B;\n\nimport std.stdio;\n\nvoid main() {\n immutable MAX_LETTER_COUNT = 26;\n immutable FIRST_LETTER = 'a';\n\n string text;\n int[MAX_LETTER_COUNT] counters;\n\n readf(\"%s\\n\", &text);\n for (int i = 0; i < text.length; ++i) {\n ++counters[text[i] - FIRST_LETTER];\n }\n\n int odds = 0;\n for (int i = 0; i < MAX_LETTER_COUNT; ++i) {\n if (counters[i] % 2 != 0) {\n ++odds;\n }\n }\n\n if (odds == 0 || odds % 2 != 0) {\n writeln(\"First\");\n } else {\n writeln(\"Second\");\n }\n}"}], "negative_code": [], "src_uid": "bbf2dbdea6dd3aa45250ab5a86833558"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort!\"a > b\"();\r\n\t\t\r\n\t\tlong x, y;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (i % 2 == a[i] % 2)\r\n\t\t\t{\r\n\t\t\t\tif (i % 2)\r\n\t\t\t\t\ty += a[i];\r\n\t\t\t\telse\r\n\t\t\t\t\tx += a[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = x > y ? -1 : x < y ? 1 : 0;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e == -1 ? \"Alice\" : e == 1 ? \"Bob\" : \"Tie\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort !(q{a > b}) (a);\r\n\t\tlong balance = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] % 2 == 0 && i % 2 == 0)\r\n\t\t\t{\r\n\t\t\t\tbalance += a[i];\r\n\t\t\t}\r\n\t\t\tif (a[i] % 2 == 1 && i % 2 == 1)\r\n\t\t\t{\r\n\t\t\t\tbalance -= a[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (balance == 0 ? \"Tie\" : balance > 0 ? \"Alice\" : \"Bob\");\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "b1e911fbc33fb031b2398cdd545f502a"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int maxLog = 18;\r\n\r\nstruct Node\r\n{\r\n\tint a;\r\n\tint c;\r\n\tint [maxLog] p;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tint q, a0, c0;\r\n\twhile (readf !(\" %s %s %s\") (q, a0, c0) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto t = new Node [q + 2];\r\n\t\tt[0].a = a0;\r\n\t\tt[0].c = c0;\r\n\t\tt[0].p[] = q + 1;\r\n\t\tt[q + 1].p[] = q + 1;\r\n\t\tforeach (i; 1..q + 1)\r\n\t\t{\r\n\t\t\tauto z = readln.split;\r\n\t\t\tif (z[0] == \"1\")\r\n\t\t\t{\r\n\t\t\t\tauto p = z[1].to !(int);\r\n\t\t\t\tauto a = z[2].to !(int);\r\n\t\t\t\tauto c = z[3].to !(int);\r\n\t\t\t\tt[i].a = a;\r\n\t\t\t\tt[i].c = c;\r\n\t\t\t\tt[i].p[0] = p;\r\n\t\t\t\tforeach (d; 1..maxLog)\r\n\t\t\t\t{\r\n\t\t\t\t\tt[i].p[d] = t[t[i].p[d - 1]].p[d - 1];\r\n\t\t\t\t}\r\n\t\t\t\tdebug {writeln (t[i].p);}\r\n\t\t\t}\r\n\t\t\telse if (z[0] == \"2\")\r\n\t\t\t{\r\n\t\t\t\tauto v = z[1].to !(int);\r\n\t\t\t\tauto w = z[2].to !(int);\r\n\t\t\t\tint step = 0;\r\n\t\t\t\tint r = v;\r\n\t\t\t\tforeach_reverse (d; 0..maxLog)\r\n\t\t\t\t{\r\n\t\t\t\t\tint u = t[r].p[d];\r\n\t\t\t\t\tif (t[u].a > 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tr = u;\r\n\t\t\t\t\t\tstep += 1 << d;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tint gold = 0;\r\n\t\t\t\tlong cost = 0;\r\n\t\t\t\tforeach_reverse (x; 0..step + 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (gold == w)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint y = x;\r\n\t\t\t\t\tint u = v;\r\n\t\t\t\t\tforeach_reverse (d; 0..maxLog)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (y >= 1 << d)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tu = t[u].p[d];\r\n\t\t\t\t\t\t\ty -= 1 << d;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint cur = min (w - gold, t[u].a);\r\n\t\t\t\t\tdebug {writefln !(\"step %s, \" ~\r\n\t\t\t\t\t \"take %s from %s\") (x, cur, u);}\r\n\t\t\t\t\tt[u].a -= cur;\r\n\t\t\t\t\tgold += cur;\r\n\t\t\t\t\tcost += cur * 1L * t[u].c;\r\n\t\t\t\t}\r\n\t\t\t\twriteln (gold, \" \", cost);\r\n\t\t\t\tstdout.flush ();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tassert (false);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nstatic import core.stdc.stdio;\n\nlong[300_000+2] a;\nlong[300_000+2] c;\n\nint main()\n{\n int[][] parent = new int[][](300_000+2, 20);\n int q = readInt!int;\n a[0] = readInt!long;\n c[0] = readInt!long;\n parent[0][] = -1;\n int getNthParent(int v, int n)\n {\n int i = 0;\n while (n)\n {\n if (n & 1)\n v = parent[v][i];\n n >>= 1;\n i++;\n }\n return v;\n }\n foreach(i; 1 .. q + 1)\n {\n int type = readInt!int;\n if (type == 1)\n {\n int pi = readInt!int;\n long ai = readInt!long;\n long ci = readInt!long;\n parent[i][0] = pi;\n foreach(j; 1 .. 20)\n {\n if (parent[i][j - 1] > 0)\n parent[i][j] = parent[parent[i][j - 1]][j - 1];\n else parent[i][j] = -1;\n }\n a[i] = ai;\n c[i] = ci;\n }\n else\n {\n int vi = readInt!int;\n long wi = readInt!long;\n int root = vi;\n int no = 0;\n long spent = 0;\n long bought = 0;\n foreach_reverse(j; 0 .. 20)\n {\n int possibleParent = parent[root][j];\n if (possibleParent < 0) continue;\n if (a[possibleParent] > 0)\n {\n root = possibleParent;\n no += (long(1) << j);\n }\n }\n debug writeln(\"for node \", vi, \" root is \", root, \" depth = \", no);\n while (wi > 0 && no >= 0)\n {\n int p = getNthParent(vi, no);\n debug writeln(\"Now is \", no, \" \", p, \" ap = \", a[p], \" wi = \", wi);\n long taken = min(wi, a[p]);\n wi -= taken;\n bought += taken;\n spent += taken * c[p];\n a[p] -= taken;\n no--;\n }\n writeln(bought, \" \", spent);\n stdout.flush;\n }\n }\n return 0;\n}\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = core.stdc.stdio.getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = core.stdc.stdio.getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n long rep;\n this(long num)\n {\n rep = num;\n }\n Z!m opBinary(string operator)(Z!m rhs)\n {\n static if (operator == \"+\")\n {\n long result = rhs.rep + this.rep;\n if (result >= m) result -= m;\n return Z!m(result);\n }\n else static if (operator == \"-\")\n {\n long result = this.rep - rhs.rep;\n if (result < 0) result += m;\n return Z!m(result);\n }\n else static if (operator == \"*\")\n {\n long result = this.rep * rhs.rep;\n if (result >= m) result %= m;\n return Z!m(result);\n } else static assert(text(\"Operator \", operator, \" not supported\"));\n }\n Z!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n {\n assert(exponent >= 0);\n Z!m base = this;\n Z!m result = 1;\n while (exponent)\n {\n if (exponent & 1)\n result = result * base;\n base = base * base;\n exponent >>= 1;\n }\n return result;\n }\n invariant\n {\n assert(rep >= 0 && rep < m);\n }\n}\n"}], "negative_code": [], "src_uid": "55c692d380a4d1c0478ceb7cffde342f"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n// Main Logic Here\nvoid play(){\n int x, y;\n x = rd!int;\n y = rd!int;\n ll tim = 2*max(x, y) - (x != y);\n writeln(tim);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle for testcases!\n while(t--) play(); // Let's play!\n return 0;\n}\n\n/**********That's All Folks!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp; // Read input\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nalias ll = long;\nalias tup = Tuple!(long, \"x\", long, \"y\");\nvoid show(A...)(A a) { debug{ foreach(t; a){ stderr.write(t, \"| \"); } stderr.writeln; } } // Debug\n/* Add if TLE, T max(T = long)(T a, T b){ return (a > b) ? a : b; } */\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint x, y;\n\t\treadf !(\" %s %s\") (x, y);\n\t\tx = abs (x);\n\t\ty = abs (y);\n\t\tif (x < y)\n\t\t{\n\t\t\tswap (x, y);\n\t\t}\n\t\tstring s = \"***\";\n\t\tint res = 0;\n\t\twhile (x || y)\n\t\t{\n\t\t\tif (x == y)\n\t\t\t{\n\t\t\t\tres += x + y;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (s[$ - 1..$] != \"a\")\n\t\t\t{\n\t\t\t\ts ~= 'a';\n\t\t\t\tx -= 1;\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ts ~= 'b';\n\t\t\t\ty = max (0, y - 1);\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (s);}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD!int;\n\t\tauto y = RD!int;\n\n\t\tans[ti] += min(x.abs, y.abs) * 2;\n\t\tauto d = max(x.abs, y.abs) - min(x.abs, y.abs);\n\t\tif (d == 0) continue;\n\t\tans[ti] += (d-1) * 2 + 1;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint x, y;\n\t\treadf !(\" %s %s\") (x, y);\n\t\tx = abs (x);\n\t\ty = abs (y);\n\t\tif (x < y)\n\t\t{\n\t\t\tswap (x, y);\n\t\t}\n\t\tstring s = \"***\";\n\t\tint res = 0;\n\t\twhile (x || y)\n\t\t{\n\t\t\tif (x == y)\n\t\t\t{\n\t\t\t\tres += x + y;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (s[$ - 1..$] != \"a\")\n\t\t\t{\n\t\t\t\ts ~= 'a';\n\t\t\t\tx -= 1;\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ts ~= 'b';\n\t\t\t\ty = max (0, y - 1);\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t}\n\t\twriteln (s);\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "8864c6a04fed970fcbc04e220df9d88d"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\n\nvoid main() {\n string s = readln.chomp;\n int n = s.length.to!int;\n\n bool check(int k, char ch) {\n int v = s[0 .. k].count!(a => a == ch);\n\n if (!v) return false;\n\n foreach (i ; k .. n) {\n v += (s[i] == ch);\n v -= (s[i - k] == ch);\n\n if (!v) return false;\n }\n\n return true;\n }\n\n int ans = n;\n\n foreach (char ch ; 'a' .. 'z' + 1) {\n if (!s.canFind(ch)) continue;\n\n int btm = 0, top = n;\n\n while (top - btm > 1) {\n int mid = (btm + top) / 2;\n\n if (check(mid, ch)) {\n top = mid;\n }\n else {\n btm = mid;\n }\n }\n\n ans = min(ans, top);\n }\n\n writeln(ans);\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nvoid main() {\n string s;\n scan(s);\n\n int n = s.length.to!int;\n\n int ans = n;\n\n foreach (char ch ; 'a' .. 'z' + 1) {\n int p = -1;\n int span;\n\n foreach (i ; 0 .. n) {\n if (s[i] == ch) {\n span = max(span, i - p);\n p = i;\n }\n }\n\n span = max(span, n - p);\n\n ans = min(span, ans);\n }\n\n writeln(ans);\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "81a558873e39efca5066ef91a9255f11"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 998244353;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n A.sort();\n long ans = 0;\n\n foreach (i; 0..N/2) {\n ans += (A[i] + A[N-i-1]) * (A[i] + A[N-i-1]);\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\nenum inf3 = 1_001_001_001;\nenum inf6 = 1_001_001_001_001_001_001L;\nenum mod = 1_000_000_007L;\n\n\nvoid main() {\n int n;\n scan(n);\n auto a = readln.split.to!(long[]);\n\n a.sort();\n\n long ans;\n\n foreach (i ; 0 .. n / 2) {\n ans += a[i]^^2 + a[n - 1 - i]^^2 + 2L * a[i] * a[n - 1 - i];\n }\n\n writeln(ans);\n}\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "28c555fefd5c36697a5082c61d8a82b3"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split;\n auto N = s[0].to!int;\n auto H = s[1].to!long;\n auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array;\n long ans = 0;\n long tmp = 0;\n long h = 0;\n\n for (int i = 0, j = 0; i < N; ++i) {\n if (j <= i) {\n tmp = A[i][1] - A[i][0];\n h = H;\n j = i;\n } else {\n tmp -= A[i][0] - A[i - 1][0];\n h += A[i][0] - A[i - 1][1];\n }\n while (j + 1 < N && h - (A[j + 1][0] - A[j][1]) > 0) {\n tmp += A[j + 1][1] - A[j][1];\n h -= A[j + 1][0] - A[j][1];\n ++j;\n }\n ans = max(ans, tmp + h);\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, h;\n readf(\"%s %s\", &n, &h);\n readln;\n \n Tuple!(int, int)[] sg;\n foreach (_; 0 .. n) {\n int x1, x2;\n readf(\"%s %s\", &x1, &x2);\n readln;\n \n sg ~= tuple(x1, x2);\n }\n \n debug { sg.writeln; }\n \n int lst = 0;\n int covered = 0;\n int cur = sg[0][1] - sg[0][0];\n int ans = cur;\n foreach (i; 1 .. n) {\n cur += sg[i][1] - sg[i][0];\n covered += sg[i][0] - sg[i-1][1];\n while (covered > h-1) {\n cur -= sg[lst][1] - sg[lst][0];\n covered -= sg[lst+1][0] - sg[lst][1];\n ++lst;\n }\n ans = max(ans, cur);\n }\n \n ans += h;\n \n ans.writeln;\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, h; rd(n, h);\n auto l=new int[](n), r=new int[](n);\n foreach(i; 0..n) rd(l[i], r[i]);\n\n int mx=0, len=0;\n for(int i=0, j=0, height=h; i<n; i++){\n while(j<n && height>0){\n mx=max(mx, len+(r[j]-l[j])+height);\n if((++j)<n){\n len+=l[j]-l[j-1];\n height-=l[j]-r[j-1];\n }\n }\n if(i+1<n){\n len-=l[i+1]-l[i];\n height+=l[i+1]-r[i];\n }\n }\n writeln(mx);\n\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, h;\n readf(\"%s %s\", &n, &h);\n readln;\n \n Tuple!(int, int)[] sg;\n foreach (_; 0 .. n) {\n int x1, x2;\n readf(\"%s %s\", &x1, &x2);\n readln;\n \n sg ~= tuple(x1, x2);\n }\n \n debug { sg.writeln; }\n \n int lst = 0;\n int covered = 0;\n int cur = sg[0][1] - sg[0][0];\n int ans = cur;\n foreach (i; 1 .. n) {\n cur += sg[i][1] - sg[i][0];\n covered += sg[i][0] - sg[i-1][1];\n while (covered > h) {\n cur -= sg[lst][1] - sg[lst][0];\n covered -= sg[lst+1][0] - sg[lst][1];\n ++lst;\n }\n ans = max(ans, cur);\n }\n \n ans += h;\n \n ans.writeln;\n}"}], "src_uid": "9d22a23124620f266d700eb8b305eab4"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto v = '9'.repeat (n).array;\n\t\tv[0..(n + 3) / 4] = '8';\n\t\twriteln (v.retro);\n\t}\n}\n", "positive_code": [{"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nvoid main()\n{\n int t;\n read(t);\n while(t--)\n {\n int n;\n read(n);\n int eights = (n + ((-n)%4+4)%4) / 4;\n foreach(i; 0 .. n - eights)\n write(\"9\");\n foreach(i; 0 .. eights)\n write(\"8\");\n writeln;\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = (n+3) / 4;\n\t\tforeach (i; 0..n-m)\n\t\t\tans[ti] ~= \"9\";\n\t\tforeach (i; 0..m)\n\t\t\tans[ti] ~= \"8\";\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "80c75a4c163c6b63a614075e094ad489"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new long[N];\n foreach (i; 0 .. N) {\n P[i] = readLong();\n }\n \n long ans;\n auto set = new RedBlackTree!(long, \"a < b\", true);\n foreach (i; 0 .. N) {\n // +1, -P[i]\n set.insert(P[i]);\n // -1, +P[i]\n ans += P[i];\n set.insert(P[i]);\n ans -= set.front;\n set.removeFront;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"D\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\n// import dkh.container.pairingheap;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n;\n long[] p;\n sc.read(n, p);\n\n PairingHeap!(long[2], \"a>b\") q;\n\n long ans = 0;\n foreach (d; p) {\n if (q.empty || q.front[0] >= d) {\n q.insert([d, 0]);\n } else {\n auto x = q.front; q.removeFront();\n ans += d - x[0];\n q.insert([d, 1]);\n if (x[1]) {\n q.insert([x[0], 0]);\n }\n }\n }\n writeln(ans);\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/pairingheap.d */\n// module dkh.container.pairingheap;\n\nprivate NP meldPairingHeapNode(alias less, NP)(NP x, NP y) {\n import std.algorithm : swap;\n if (!x) return y;\n if (!y) return x;\n if (less(x._item, y._item)) swap(x, y);\n y.next = x.head;\n x.head = y;\n return x;\n}\n\n \nstruct PairingHeap(T, alias less = \"a < b\") {\n import std.functional : binaryFun;\n private alias _less = binaryFun!less;\n\n private alias NP = Node*;\n private static struct Node {\n T _item;\n NP head, next;\n this(T item) {\n _item = item;\n }\n }\n\n private struct Payload {\n import std.algorithm : swap;\n private NP node;\n private uint len;\n\n void insert(T item) {\n len++;\n node = meldPairingHeapNode!_less(node, new Node(item));\n }\n inout(T) front() inout { return node._item; }\n void removeFront() {\n len--;\n\n NP s = node.head;\n NP t;\n \n \n while (s) {\n \n NP first, second;\n first = s; s = s.next; first.next = null;\n if (s) {\n second = s; s = s.next; second.next = null;\n }\n \n auto v = meldPairingHeapNode!_less(first, second);\n v.next = t;\n t = v;\n }\n node = null;\n \n while (t) {\n NP first = t; t = t.next; first.next = null;\n node = meldPairingHeapNode!_less(first, node);\n }\n }\n void meld(Payload* r) {\n len += r.len; r.len = 0;\n node = meldPairingHeapNode!_less(node, r.node);\n r.node = null;\n }\n }\n private Payload* _p;\n\n @property bool empty() const { return !_p || _p.len == 0; } \n @property size_t length() const { return (!_p) ? 0 : _p.len; } \n\n void insert(T item) {\n if (!_p) _p = new Payload();\n _p.insert(item);\n } \n inout(T) front() inout {\n assert(!empty, \"PairingHeap.front: heap is empty\");\n return _p.front;\n } \n void removeFront() {\n assert(!empty, \"PairingHeap.removeFront: heap is empty\");\n _p.removeFront;\n } \n \n void meld(PairingHeap r) { _p.meld(r._p); }\n}\n\n \n \n\n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}], "negative_code": [], "src_uid": "994bfacedc61a4a67c0997011cadb333"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = RDA;\n\t\tauto c = new long[](n);\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tc[j] = b[j] - a[j];\n\t\t}\n\t\tint l, r=1;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (c[j] != 0)\n\t\t\t{\n\t\t\t\tl = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tforeach_reverse (j; 0..n)\n\t\t{\n\t\t\tif (c[j] != 0)\n\t\t\t{\n\t\t\t\tr = j+1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(l, \":\", r);\n\t\tbool ok = c[l] >= 0;\n\t\tforeach (j; l+1..r)\n\t\t{\n\t\t\tif (c[j] < 0) ok = false;\n\t\t\tif (c[j] != c[j-1])\n\t\t\t\tok = false;\n\t\t}\n\t\tans[i] = ok;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto B = readln.split.map!(to!int).array;\n B[] -= A[];\n B = B.uniq.array;\n if (B.map!(b => b < 0).any) {\n writeln(\"NO\");\n } else if (B.length == 1) {\n writeln(\"YES\");\n } else if (B.length == 2 && (B.front == 0 || B.back == 0)) {\n writeln(\"YES\");\n } else if (B.length == 3 && (B.front == 0 && B.back == 0)) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint t = rint;\n\tforeach(_; 0 .. t){\n\t\tint n = rint;\n\t\tlong[] as = rlong(n);\n\t\tlong[] bs = rlong(n);\n\t\t\n\t\tlong[] us;\n\t\tforeach(i; 0 .. n) us ~= bs[i] - as[i];\n\t\tlog(\"us:\", us);\n\t\t\n\t\tint s = 0; // 0=\u307e\u3060\u306a\u3044 1=\u4eca\u305d\u306e\u9014\u4e2d 2=\u7d42\u308f\u3063\u305f -1=\u3060\u3081\n\t\tlong xu;\n\t\tforeach(u; us){\n\t\t\tif(u < 0) s = -1;\n\t\t\telse if(u == 0){\n\t\t\t\tif(s == 1) s = 2;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(s == 0){\n\t\t\t\t\ts = 1;\n\t\t\t\t\txu = u;\n\t\t\t\t}\n\t\t\t\telse if(s == 1){\n\t\t\t\t\tif(u != xu) s = -1;\n\t\t\t\t}\n\t\t\t\telse if(s == 2){\n\t\t\t\t\ts = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(s == -1) \"NO\".writeln;\n\t\telse \"YES\".writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = RDA;\n\t\tauto c = new long[](n);\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tc[j] = b[j] - a[j];\n\t\t}\n\t\tint l, r;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (c[j] != 0)\n\t\t\t{\n\t\t\t\tl = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tforeach_reverse (j; 0..n)\n\t\t{\n\t\t\tif (c[j] != 0)\n\t\t\t{\n\t\t\t\tr = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(l, \":\", r);\n\t\tbool ok = c[l] >= 0;\n\t\tforeach (j; l+1..r)\n\t\t{\n\t\t\tif (c[j] < 0) ok = false;\n\t\t\tif (c[j] != c[j-1])\n\t\t\t\tok = false;\n\t\t}\n\t\tans[i] = ok;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = RDA;\n\t\tauto c = new long[](n);\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tc[j] = b[j] - a[j];\n\t\t}\n\t\tbool ok = true;\n\t\tlong last;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (c[j] == 0) continue;\n\t\t\telse if (c[j] < 0)\n\t\t\t\tok = false;\n\n\t\t\tif (last == 0)\n\t\t\t\tlast = c[j];\n\t\t\telse if (c[j] != last)\n\t\t\t\tok = false;\n\t\t}\n\t\tans[i] = ok;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = RDA;\n\t\tauto c = new long[](n);\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tc[j] = b[j] - a[j];\n\t\t}\n\t\tint l, r=1;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (c[j] != 0)\n\t\t\t{\n\t\t\t\tl = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tforeach_reverse (j; 0..n)\n\t\t{\n\t\t\tif (c[j] != 0)\n\t\t\t{\n\t\t\t\tr = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(l, \":\", r);\n\t\tbool ok = c[l] >= 0;\n\t\tforeach (j; l+1..r)\n\t\t{\n\t\t\tif (c[j] < 0) ok = false;\n\t\t\tif (c[j] != c[j-1])\n\t\t\t\tok = false;\n\t\t}\n\t\tans[i] = ok;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "0e0ef011ebe7198b7189fce562b7d6c1"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n int n = scan!int, m = scan!int;\n long p = scan!long;\n \n long[] as = scan!long(n);\n long[] bs = scan!long(m);\n\n int imin, jmin;\n foreach(i, a; as) if(a % p != 0){\n imin = i.to!int;\n break;\n }\n foreach(j, b; bs) if(b % p != 0){\n jmin = j.to!int;\n break;\n }\n print(imin + jmin);\n}\n\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.random;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint ();\n const m = r.next!uint ();\n const p = r.next!uint ();\n auto a = r.nextA!uint (n);\n auto b = r.nextA!uint (m);\n int i, j;\n for (i = n - 1; i >= 0 && !(a[i] % p); --i) {}\n for (j = m - 1; j >= 0 && !(b[j] % p); --j) {}\n writeln (i + j);\n}\n\n"}], "negative_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.random;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint ();\n const m = r.next!uint ();\n const p = r.next!uint ();\n auto a = r.nextA!uint (n);\n auto b = r.nextA!uint (m);\n int i, j;\n for (i = n - 1; i >= 0 && !(a[i] % p); --i) {}\n for (j = m - 1; j >= 0 && !(a[j] % p); --j) {}\n writeln (i + j);\n}\n\n"}], "src_uid": "23c8f5922c7a1cdb82d229eb9938f3ee"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\nimport std.conv;\nimport std.math;\nimport std.typecons;\n\nvoid main()\n{\n int[] fst = readln().split.map!\"a.to!int\".array;\n int[] snd = readln().split.map!\"a.to!int\".array;\n int[] thr = readln().split.map!\"a.to!int\".array;\n\n int aUG = snd.filter!(x => x % 2 == 1)\n .array\n .length\n .to!int;\n int aG = snd.filter!(x => x % 2 == 0)\n .array\n .length\n .to!int;\n int bUG = thr.filter!(x => x % 2 == 1)\n .array\n .length\n .to!int;\n int bG = thr.filter!(x => x % 2 == 0)\n .array\n .length\n .to!int;\n\n (min(aUG, bG) + min(aG, bUG)).writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\n// import std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\n\tint n = read.to!int;\n\tint m = read.to!int;\n\t\n\tlong[] as = readln.chomp.split.to!(long[]);\n\tlong[] bs = readln.chomp.split.to!(long[]);\n\t\n\tint oddacnt, oddbcnt, evenacnt, evenbcnt;\n\tforeach(a; as) if(a % 2 == 0) evenacnt += 1; else oddacnt += 1;\n\tforeach(b; bs) if(b % 2 == 0) evenbcnt += 1; else oddbcnt += 1;\n\t\n\tint ans = min(evenacnt, oddbcnt) + min(oddacnt, evenbcnt);\n\t\n\tans.writeln;\n\n\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!int;\n\tauto M = RD!int;\n\tauto a = RDR.ARR;\n\tauto b = RDR.ARR;\n\n\tlong cnt_a;\n\tforeach (i; 0..N)\n\t{\n\t\tif (a[i] % 2 == 1)\n\t\t\t++cnt_a;\n\t}\n\tlong cnt_b;\n\tforeach (i; 0..M)\n\t{\n\t\tif (b[i] % 2 == 1)\n\t\t\t++cnt_b;\n\t}\n\tlong ans;\n\tans += min(cnt_a, M - cnt_b);\n\tans += min(cnt_b, N - cnt_a);\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array;\n \n long a = A.map!(a => a % 2 == 0).sum;\n long b = A.map!(a => a % 2 == 1).sum;\n long c = B.map!(a => a % 2 == 0).sum;\n long d = B.map!(a => a % 2 == 1).sum;\n\n writeln(min(a, d) + min(b, c));\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n int n = r.next!int, m = r.next!int;\n auto f (int k) {\n auto c = new int[2];\n foreach (i; 0 .. k) {\n ++c[1 & r.next!int];\n }\n return c;\n }\n auto a = f (n), b = f (m);\n writeln (min (a[0], b[1]) + min (a[1], b[0]));\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\nimport std.conv;\nimport std.math;\nimport std.typecons;\n\nvoid main()\n{\n int[] fst = readln().split.map!\"a.to!int\".array;\n int[] snd = readln().split.map!\"a.to!int\".array;\n int[] thr = readln().split.map!\"a.to!int\".array;\n\n int a = snd.filter!(x => x % 2 == 1)\n .array\n .length\n .to!int;\n int b = snd.filter!(x => x % 2 == 0)\n .array\n .length\n .to!int;\n int c = thr.filter!(x => x % 2 == 1)\n .array\n .length\n .to!int;\n int d = thr.filter!(x => x % 2 == 0)\n .array\n .length\n .to!int;\n\n min(a, b, c, d).writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\nimport std.conv;\nimport std.math;\nimport std.typecons;\n\nvoid main()\n{\n int[] fst = readln().split.map!\"a.to!int\".array;\n int[] snd = readln().split.map!\"a.to!int\".array;\n int[] thr = readln().split.map!\"a.to!int\".array;\n\n int aUG = snd.filter!(x => x % 2 == 1)\n .array\n .length\n .to!int;\n int aG = snd.filter!(x => x % 2 == 0)\n .array\n .length\n .to!int;\n int bUG = thr.filter!(x => x % 2 == 1)\n .array\n .length\n .to!int;\n int bG = thr.filter!(x => x % 2 == 0)\n .array\n .length\n .to!int;\n\n max(min(aUG, bG), min(aG, bUG)).writeln;\n}\n"}], "src_uid": "bc532d5c9845940b5f59485394187bf6"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tans[ti] ~= (i+1)%n + 1;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tauto tests = readln.strip.to!int;\n\tforeach (test; 0..tests)\n\t\treadln.strip.to!int.iota.map!q{a+1}.drop(1).chain(1.only).writefln!\"%(%s %)\";\n}\n"}], "negative_code": [], "src_uid": "f4779e16e0857e6507fdde55e6d4f982"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nstruct Score\n{\n public string player;\n public int score;\n}\n\nvoid main()\n{\n int n;\n Score[] game;\n int[string] totalScores;\n \n readf(\" %d\", &n);\n for (int i = 0; i < n; ++i)\n {\n string player;\n int score;\n \n readf(\" %s %d\", &player, &score);\n game ~= Score(player, score);\n totalScores[player] += score;\n }\n \n int maxScore = 0;\n foreach (score; totalScores.values)\n {\n if (score > maxScore)\n {\n maxScore = score;\n }\n }\n \n string[] potentialWinners;\n foreach (player, score; totalScores)\n {\n if (score == maxScore)\n {\n potentialWinners ~= player;\n }\n }\n \n totalScores.clear();\n \n string winner;\n foreach (con; game)\n {\n totalScores[con.player] += con.score;\n if (totalScores[con.player] >= maxScore && canFind(potentialWinners, con.player))\n {\n winner = con.player;\n break;\n }\n }\n \n writeln(winner);\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.algorithm;\n\nvoid main() {\n\tuint n;\n\tlong[string] score;\n\tlong[string] s2;\n\tstring[] gn;\n\tlong[] gs;\n\treadf(\"%s\", &n);\n\tstring mname;\n\tforeach(i; 0 .. n) {\n\t\tlong sc;\n\t\tstring name;\n\t\treadf(\"\\n%s %d\", &name, &sc);\n\t\tscore[name] += sc;\n\t\tgn ~= name;\n\t\tgs ~= sc;\n\t}\n\tauto m = score.reduce!(max);\n\n\tforeach(i; 0 .. n) {\n\t\ts2[gn[i]] += gs[i];\n\t\tif (s2[gn[i]] >= m && score[gn[i]] == m) {\n\t\t\twriteln(gn[i]);\n\t\t\tbreak;\n\t\t}\n\t}\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport core.stdc.stdio;\nimport core.stdc.string;\nimport std.array;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nstruct Round\n{\n\tstring name;\n\tint points;\n}\n\nint main()\n{\n\tint n;\n\tstring l = readline();\n\tn = parse!int(l);\n\tint[string] scoreboard;\n\tRound[] rounds; rounds.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tl = readline();\n\t\tstring[] values = split(l);\n\t\tpoints = parse!int(values[1]);\n\t\tstring nm = values[0];\n\t\tscoreboard[nm] += points;\n\t\trounds[i].name = nm;\n\t\trounds[i].points = points;\n\t}\n\n\tint max = int.min;\n\tforeach (string key; scoreboard.byKey)\n\t{\n\t\tif (scoreboard[key] > max) max = scoreboard[key];\n\t}\n\n\tbool[string] maxers;\n\tforeach (string key; scoreboard.byKey)\n\t{\n\t\tif (scoreboard[key] == max)\n\t\t\tmaxers[key] = true;\n\t\tscoreboard[key] = 0;\n\t}\n\n\tstring name = \"\";\n\tforeach (int i; 0..n)\n\t{\n\t\tscoreboard[rounds[i].name] += rounds[i].points;\n\t\tif (rounds[i].name in maxers && scoreboard[rounds[i].name] >= max)\n\t\t{\n\t\t\tname = rounds[i].name;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\twrite (name);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.conv;\nimport std.algorithm;\nimport std.container;\nimport std.exception;\n\nstring nextToken() {\n char c;\n string res;\n while (readf(\"%s\", &c) == 1) {\n if (isWhite(c)) {\n if (res.length > 0)\n break;\n } else\n res ~= c;\n }\n return res;\n}\n\nauto read(T)() {\n return nextToken.to!T;\n}\nbool read(T)(ref T val) {\n try {\n val = read!T;\n return true;\n } catch (ConvException)\n return false;\n}\n\nvoid reset(T)(ref T val) {\n val = T.init;\n}\n\nbool solve(int test) {\n int n;\n if (!read(n))\n return false;\n\n struct op {\n string name;\n int val;\n }\n op[] ops = new op[n];\n int score[string];\n\n foreach (ref cur; ops) {\n cur.name = read!string;\n cur.val = read!int;\n\n if (cur.name !in score)\n score[cur.name] = 0;\n score[cur.name] += cur.val;\n }\n int maxScore = 0;\n foreach (cur; score.byValue)\n maxScore = max(maxScore, cur);\n\n byte[string] maxPlayers;\n foreach (name, cur; score) {\n if (cur == maxScore)\n maxPlayers[name] = 0;\n }\n\n score.reset;\n bool found = false;\n foreach (cur; ops) {\n if (cur.name !in maxPlayers)\n continue;\n if (cur.name !in score)\n score[cur.name] = 0;\n score[cur.name] += cur.val;\n if (score[cur.name] >= maxScore) {\n writeln(cur.name);\n found = true;\n break;\n }\n }\n assert(found);\n return true;\n}\n\nvoid main() {\n int test = 0;\n while (solve(test))\n test++;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\n\nint main()\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[string] scoreboard;\n\tchar[32] name;\n\tstring max = \"\";\n\tint max_points = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tscanf(\"%s %d\", &name, &points);\n\t\tstring nm = to!string(name);\n\t\tscoreboard[nm] += points;\n\t\tif (scoreboard[nm] > max_points)\n\t\t{\n\t\t\tmax = nm;\n\t\t\tmax_points = scoreboard[nm];\n\t\t}\n\t}\n\twrite(max);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport core.stdc.stdio;\nimport core.stdc.string;\nimport std.array;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nint main()\n{\n\tint n;\n\tstring l = readline();\n\tn = parse!int(l);\n\tint[string] scoreboard;\n\tstring[] max;\n\tmax ~= \"\";\n\tint[] max_points;\n\tmax_points ~= int.min;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tl = readline();\n\t\tstring[] values = split(l);\n\t\tpoints = parse!int(values[1]);\n\t\tstring nm = values[0];\n\t\tscoreboard[nm] += points;\n\t\tif (nm == max.back)\n\t\t{\n\t\t\tmax_points.back = scoreboard[nm];\n\t\t\tif (max_points[$-1] < max_points[$-2])\n\t\t\t{\n\t\t\t\tmax_points.popBack();\n\t\t\t\tmax.popBack();\n\t\t\t}\n\t\t} else\n\t\tif (scoreboard[nm] > max_points.back)\n\t\t{\n\t\t\tmax ~= nm;\n\t\t\tmax_points ~= scoreboard[nm];\n\t\t}\n\t}\n\twrite(max.back);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport core.stdc.stdio;\nimport core.stdc.string;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nint main()\n{\n\tint n;\n\tstring l = readline();\n\tn = parse!int(l);\n\tint[string] scoreboard;\n\tstring max = \"\";\n\tint max_points = int.min;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tl = readline();\n\t\tstring[] values = split(l);\n\t\tpoints = parse!int(values[1]);\n\t\tstring nm = values[0];\n\t\tscoreboard[nm] += points;\n\t\tif (nm == max)\n\t\t{\n\t\t\tmax_points = scoreboard[nm];\n\t\t} else\n\t\tif (scoreboard[nm] > max_points)\n\t\t{\n\t\t\tmax = nm;\n\t\t\tmax_points = scoreboard[nm];\n\t\t}\n\t}\n\twrite(max);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport core.stdc.stdio;\nimport core.stdc.string;\nimport std.array;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nint main()\n{\n\tint n;\n\tstring l = readline();\n\tn = parse!int(l);\n\tint[string] scoreboard;\n\tstring[int] maxers;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tl = readline();\n\t\tstring[] values = split(l);\n\t\tpoints = parse!int(values[1]);\n\t\tstring nm = values[0];\n\t\tscoreboard[nm] += points;\n\t\tif (!(scoreboard[nm] in maxers))\n\t\t{\n\t\t\tmaxers[scoreboard[nm]] = nm;\n\t\t}\n\t}\n\n\tint max = int.min;\n\tforeach (string key; scoreboard.byKey)\n\t{\n\t\tif (scoreboard[key] > max)\n\t\t\tmax = scoreboard[key];\n\t}\n\twrite(maxers[max]);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport core.stdc.stdio;\nimport core.stdc.string;\nimport std.array;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nint main()\n{\n\tint n;\n\tstring l = readline();\n\tn = parse!int(l);\n\tint[string] scoreboard;\n\tint[string] pos;\n\tint[string] ms;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tl = readline();\n\t\tstring[] values = split(l);\n\t\tpoints = parse!int(values[1]);\n\t\tstring nm = values[0];\n\t\tint pv = (nm in scoreboard ? scoreboard[nm] : int.min);\n\t\tscoreboard[nm] += points;\n\t\tif (nm in ms)\n\t\t{\n\t\t\tif (scoreboard[nm] > ms[nm])\n\t\t\t{\n\t\t\t\tms[nm] = scoreboard[nm];\n\t\t\t\tpos[nm] = i;\n\t\t\t}\n\t\t} else {\n\t\t\tms[nm] = scoreboard[nm];\n\t\t\tpos[nm] = i;\n\t\t}\n\t}\n\n\tint max = int.min;\n\tint idx = -1;\n\tstring name = \"\";\n\tforeach (string key; scoreboard.byKey)\n\t{\n\t\tif (scoreboard[key] > max)\n\t\t{\n\t\t\tmax = scoreboard[key];\n\t\t\tname = key;\n\t\t\tidx = pos[key];\n\t\t} else\n\t\tif (scoreboard[key] == max && pos[key] < idx)\n\t\t{\n\t\t\tidx = pos[key];\n\t\t\tmax = scoreboard[key];\n\t\t\tname = key;\n\t\t}\n\t}\n\twrite(name);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport core.stdc.stdio;\nimport core.stdc.string;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nint main()\n{\n\tint n;\n\tstring l = readline();\n\tn = parse!int(l);\n\tint[string] scoreboard;\n\tstring max = \"\";\n\tint max_points = int.min;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tl = readline();\n\t\tstring[] values = split(l);\n\t\tpoints = parse!int(values[1]);\n\t\tstring nm = values[0];\n\t\tscoreboard[nm] += points;\n\t\tif (scoreboard[nm] > max_points)\n\t\t{\n\t\t\tmax = nm;\n\t\t\tmax_points = scoreboard[nm];\n\t\t}\n\t}\n\twrite(max);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport core.stdc.stdio;\nimport core.stdc.string;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nint main()\n{\n\tint n;\n\tstring l = readline();\n\tn = parse!int(l);\n\tint[string] scoreboard;\n\tstring max = \"\";\n\tint max_points = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tl = readline();\n\t\tstring[] values = split(l);\n\t\tpoints = parse!int(values[1]);\n\t\tstring nm = values[0];\n\t\tscoreboard[nm] += points;\n\t\tif (scoreboard[nm] > max_points)\n\t\t{\n\t\t\tmax = nm;\n\t\t\tmax_points = scoreboard[nm];\n\t\t}\n\t}\n\twrite(max);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\nimport std.string;\nimport core.stdc.stdio;\nimport core.stdc.string;\nimport std.array;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nint main()\n{\n\tint n;\n\tstring l = readline();\n\tn = parse!int(l);\n\tint[string] scoreboard;\n\tstring[] max;\n\tmax ~= \"\";\n\tint[] max_points;\n\tmax_points ~= int.min;\n\tstring[int] maxers;\n\tforeach (int i; 0..n)\n\t{\n\t\tint points;\n\t\tl = readline();\n\t\tstring[] values = split(l);\n\t\tpoints = parse!int(values[1]);\n\t\tstring nm = values[0];\n\t\tscoreboard[nm] += points;\n\t\tif (nm == max.back)\n\t\t{\n\t\t\tmax_points.back = scoreboard[nm];\n\t\t\tif (max_points[$-1] < max_points[$-2])\n\t\t\t{\n\t\t\t\tmax_points.popBack();\n\t\t\t\tmax.popBack();\n\t\t\t} else {\n\t\t\t\tif (!(scoreboard[nm] in maxers))\n\t\t\t\t\tmaxers[scoreboard[nm]] = nm;\n\t\t\t}\n\t\t} else\n\t\tif (scoreboard[nm] > max_points.back)\n\t\t{\n\t\t\tif (!(scoreboard[nm] in maxers))\n\t\t\t\tmaxers[scoreboard[nm]] = nm;\n\t\t\tmax ~= nm;\n\t\t\tmax_points ~= scoreboard[nm];\n\t\t}\n\t}\n\twrite(maxers[max_points.back]);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\nstruct Score\n{\n public string player;\n public int score;\n}\n\nvoid main()\n{\n int n;\n Score[] game;\n int[string] totalScores;\n \n readf(\"%d\", &n);\n for (int i = 0; i < n; ++i)\n {\n string player;\n int score;\n \n readf(\"%s %d\", &player, &score);\n game ~= Score(player, score);\n totalScores[player] += score;\n }\n \n int maxScore = 0;\n foreach (score; totalScores.values)\n {\n if (score > maxScore)\n {\n maxScore = score;\n }\n }\n totalScores.clear();\n \n string winner;\n foreach (con; game)\n {\n totalScores[con.player] += con.score;\n if (totalScores[con.player] == maxScore)\n {\n winner = con.player;\n break;\n }\n }\n \n writeln(winner);\n}"}, {"source_code": "import std.stdio, std.array, std.algorithm;\n\nvoid main() {\n\tlong n;\n\tlong[string] score;\n\treadf(\"%s\\n\", &n);\n\tlong max = 0;\n\tstring mname;\n\tforeach(i; 0 .. n) {\n\t\tlong sc;\n\t\tstring name;\n\t\treadf(\"%s %d\\n\", &name, &sc);\n\t\tscore[name] += sc;\n\t\tif (score[name] > max) {\n\t\t\tmname = name;\n\t\t\tmax = score[name];\n\t\t}\n\t}\n\twriteln(mname);\n}"}], "src_uid": "c9e9b82185481951911db3af72fd04e7"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tint [] [] a;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\ta ~= readln.splitter.map !(to !(int)).array;\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tsort (a[i]);\r\n\t\t}\r\n\t\tauto answer = new int [] [] (n, m);\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tint best = 0;\r\n\t\t\tforeach (i; 1..n)\r\n\t\t\t{\r\n\t\t\t\tif (!a[i].empty && a[best].front > a[i].front)\r\n\t\t\t\t{\r\n\t\t\t\t\tbest = i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tanswer[best][j] = a[best].front;\r\n\t\t\ta[best].popFront ();\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..m)\r\n\t\t\t{\r\n\t\t\t\tif (answer[i][j] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[i][j] = a[i].front;\r\n\t\t\t\t\ta[i].popFront ();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\twritefln !(\"%(%s %)\") (answer[i]);\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const M = readInt();\n auto B = new long[][](N, M);\n foreach (i; 0 .. N) {\n foreach (j; 0 .. M) {\n B[i][j] = readLong();\n }\n B[i].sort;\n }\n debug {\n writeln(\"B = \", B);\n }\n \n auto ls = new int[N];\n auto rs = new int[N];\n ls[] = 0;\n rs[] = M;\n \n auto ans = new long[][](M, N);\n foreach (h; 0 .. M) {\n int im = -1;\n foreach (i; 0 .. N) {\n if (im == -1 || B[im][ls[im]] > B[i][ls[i]]) {\n im = i;\n }\n }\n debug {\n writeln(ls, \" \", rs, \" \", im, \" \", B[im][ls[im]]);\n }\n ans[h][im] = B[im][ls[im]++];\n foreach (i; 0 .. N) {\n if (im != i) {\n ans[h][i] = B[i][--rs[i]];\n }\n }\n }\n \n foreach (i; 0 .. N) {\n foreach (h; 0 .. M) {\n if (h > 0) write(\" \");\n write(ans[h][i]);\n }\n writeln;\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "a9021fed22299e90aaef50c4d0d9f5b2"} {"source_code": "import std;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!long;\n auto s = readln.strip;\n int ans = 0;\n foreach (ch ; s)\n ans = max(ans, ch - 'a' + 1);\n writeln(ans);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.algorithm, std.array;\r\n\r\nvoid main()\r\n{\r\n auto t = readln().strip().to!int;\r\n foreach (i; 0..t)\r\n {\r\n auto n = readln().strip().to!int;\r\n auto s = readln().strip().dup.array;\r\n sort(s);\r\n writefln(\"%d\", s[$-1] - 'a' + 1);\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "4841cbc3d3ef29929690b78e30fbf22e"} {"source_code": "module cf_296A;\n\nimport std.stdio;\n\nvoid main() {\n immutable MAX_NUMBER = 1000;\n\n int n, num;\n int[MAX_NUMBER + 1] counters;\n\n readf(\"%d\", &n);\n for (int i = 0; i < n; ++i) {\n readf(\" %d\", &num);\n ++counters[num];\n }\n\n bool canExchange = true;\n for (int i = counters.length - 1; i >= 0; --i) {\n if (2 * counters[i] - 1 > n) {\n canExchange = false;\n break;\n }\n }\n\n writeln(canExchange? \"YES\": \"NO\");\n}", "positive_code": [{"source_code": "module sigod.codeforces.p296A;\n\nimport std.stdio;\n\nvoid main()\n{\n\tint n;\n\tstdin.readf(\" %s\", &n);\n\n\tint[] array = new int[n];\n\n\tforeach (ref a; array) {\n\t\tstdin.readf(\" %s\", &a);\n\t}\n\n\tstdout.writeln(solve(array) ? \"YES\" : \"NO\");\n}\n\nbool solve(int[] array)\n{\n\tif (array.length == 1) return true;\n\n\tint[int] counts;\n\n\tforeach (e; array) {\n\t\t++counts[e];\n\t}\n\n\tint max = 0;\n\tforeach (value; counts.byValue) {\n\t\tif (value > max) max = value;\n\t}\n\n\treturn (max - 1) <= (array.length - max);\n}\n\nunittest {\n\tassert(solve([1]) == true);\n\tassert(solve([1, 1, 2]) == true);\n\tassert(solve([7, 7, 7, 7]) == false);\n}"}], "negative_code": [], "src_uid": "2c58d94f37a9dd5fb09fd69fc7788f0d"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto A = RD;\r\n\t\tauto B = RD;\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\tauto b = RDA;\r\n\r\n\t\tauto index = a.MAKE_IDX;\r\n\t\tbool ok = true;\r\n\t\tforeach (i; index)\r\n\t\t{\r\n\t\t\tif (B <= 0)\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tauto cnt = (b[i]+A-1) / A;\r\n\t\t\tB -= a[i] * cnt;\r\n\t\t\tif (B <= -a[i])\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nalias E = Tuple!(long, \"a\", long, \"b\");\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n long A, B; int N; get(A, B, N);\r\n auto es = new E[](N);\r\n foreach (i, a; readln.split) es[i].a = a.to!long;\r\n foreach (i, b; readln.split) es[i].b = b.to!long;\r\n sort!\"a.a < b.a\"(es);\r\n foreach (e; es) with (e) {\r\n auto t = b / A - (b % A == 0 ? 1 : 0);\r\n B -= a * t;\r\n if (B <= 0) {\r\n writeln(\"NO\");\r\n goto next;\r\n }\r\n B -= a;\r\n }\r\n writeln(\"YES\");\r\n next:\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n long A, B; int N; get(A, B, N);\r\n long[] aa; get(aa);\r\n long[] bb; get(bb);\r\n foreach (i; 0..N) {\r\n auto a = aa[i];\r\n auto b = bb[i];\r\n auto t = b / A - (b % A == 0 ? 1 : 0);\r\n B -= a * t;\r\n if (B <= 0) {\r\n writeln(\"NO\");\r\n goto next;\r\n }\r\n B -= a;\r\n }\r\n writeln(\"YES\");\r\n next:\r\n }\r\n}"}], "src_uid": "b63a6369023642a8e7e8f449d7d4b73f"} {"source_code": "import std.stdio, std.string;\n\nimmutable int maxn = 1010;\n\nint mat[maxn][maxn];\nlong[][][4] dp;\nint d[4][2] = [[-1, 0], [0, -1], [1, 0], [0, 1]];\nint c[4][2] = [[0, 1], [0, 3], [2, 3], [1, 2]];\nint s[4][2] = [[0, 0], [0, 0], [0, 0], [0, 0]];\n\nvoid init(int n, int m)\n{\n s[1][1] = m - 1;\n s[2][0] = n - 1;\n s[2][1] = m - 1;\n s[3][0] = n - 1;\n}\n\nbool check(int x, int y, int n, int m)\n{\n if (x >= 0 && x < n && y >= 0 && y < m)\n {\n return true;\n }\n return false;\n}\n\nvoid solve(int n, int m)\n{\n init(n, m);\n foreach (int k; 0 .. 4)\n {\n int dx = s[k][0] == 0 ? 1 : -1;\n for (int i = s[k][0]; i < n && i >= 0; i += dx) \n {\n int dy = s[k][1] == 0 ? 1 : -1;\n for (int j = s[k][1]; j < m && j >= 0; j += dy)\n {\n long opt = -1;\n int sx, sy;\n foreach (int t; 0 .. 2)\n {\n sx = i + d[c[k][t]][0];\n sy = j + d[c[k][t]][1];\n if (check(sx, sy, n, m) && dp[k][sx][sy] > opt)\n {\n opt = dp[k][sx][sy];\n }\n }\n dp[k][i][j] = mat[i][j];\n if (opt != -1)\n {\n dp[k][i][j] += opt;\n }\n }\n }\n }\n long ans = -1;\n foreach (int i; 0 .. n)\n {\n foreach (int j; 0 .. m)\n {\n long cnt = 0, opt = -1;\n if (i > 0 && j > 0)\n {\n cnt = dp[0][i - 1][j] + dp[3][i][j - 1];\n if (i < n - 1 && j < m - 1)\n {\n cnt += dp[1][i][j + 1] + dp[2][i + 1][j];\n if (cnt > ans)\n {\n ans = cnt;\n }\n }\n }\n if (i < n - 1 && j > 0)\n {\n cnt = dp[0][i][j - 1] + dp[3][i + 1][j];\n if (i > 0 && j < m - 1)\n {\n cnt += dp[1][i - 1][j] + dp[2][i][j + 1];\n if (cnt > ans)\n {\n ans = cnt;\n }\n }\n }\n }\n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d%d\", &n, &m) == 2)\n {\n foreach (int i; 0 .. 4)\n {\n dp[i] = new long[][n];\n foreach (int j; 0 .. n)\n {\n dp[i][j] = new long[m];\n }\n }\n foreach (int i; 0 .. n)\n {\n foreach (int j; 0 .. m)\n {\n scanf(\"%d\", &mat[i][j]);\n }\n }\n solve(n, m);\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [] [] (n, m);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\treadf (\" %s\", &a[i][j]);\n\t\t\t}\n\t\t}\n\n\t\tauto f = new int [4] [] [] (n, m);\n\t\tforeach (k; 0..4)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\tint cur = 0;\n\t\t\t\t\tif (i > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = max (cur, f[i - 1][j][k]);\n\t\t\t\t\t}\n\t\t\t\t\tif (j > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = max (cur, f[i][j - 1][k]);\n\t\t\t\t\t}\n\t\t\t\t\tf[i][j][k] = cur + a[i][j];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tauto b = new int [] [] (m, n);\n\t\t\tauto g = new int [4] [] [] (m, n);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\tb[j][n - 1 - i] = a[i][j];\n\t\t\t\t\tg[j][n - 1 - i] = f[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t\ta = b;\n\t\t\tf = g;\n\t\t\tswap (m, n);\n\t\t}\n\t\tdebug {writeln (f);}\n\n\t\tint res = 0;\n\t\tforeach (i; 1..n - 1)\n\t\t{\n\t\t\tforeach (j; 1..m - 1)\n\t\t\t{\n\t\t\t\tint cur = max (f[i - 1][j][0] +\n\t\t\t\t f[i + 1][j][2] +\n\t\t\t\t f[i][j - 1][1] +\n\t\t\t\t f[i][j + 1][3],\n\t\t\t\t f[i - 1][j][3] +\n\t\t\t\t f[i + 1][j][1] +\n\t\t\t\t f[i][j - 1][0] +\n\t\t\t\t f[i][j + 1][2]);\n\t\t\t\tres = max (res, cur);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string;\n\nimmutable int maxn = 1010;\n\nint mat[maxn][maxn];\nlong[][][4] dp;\nint d[4][2];\nint c[4][2];\nint s[4][2];\n\nvoid init(int n, int m)\n{\n\td[0][0] = -1;\n\td[0][1] = 0;\n\td[1][0] = 0;\n\td[1][1] = -1;\n\td[2][0] = 1;\n\td[2][1] = 0;\n\td[3][0] = 0;\n\td[3][1] = 1;\n\t///\n\tc[0][0] = 0;\n\tc[0][1] = 1;\n\tc[1][0] = 0;\n\tc[1][1] = 3;\n\tc[2][0] = 2;\n\tc[2][1] = 3;\n\tc[3][0] = 1;\n\tc[3][1] = 2;\n\t///\n\ts[0][0] = 0;\n\ts[0][1] = 0;\n\ts[1][0] = 0;\n\ts[1][1] = m - 1;\n\ts[2][0] = n - 1;\n\ts[2][1] = m - 1;\n\ts[3][0] = n - 1;\n\ts[3][1] = 0;\n}\n\nbool check(int x, int y, int n, int m)\n{\n\tif (x >= 0 && x < n && y >= 0 && y < m)\n\t{\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nvoid solve(int n, int m)\n{\n\tinit(n, m);\n\tforeach (int k; 0 .. 4)\n\t{\n\t\tint dx = s[k][0] == 0 ? 1 : -1;\n\t\tfor (int i = s[k][0]; i < n && i >= 0; i += dx) \n\t\t{\n\t\t\tint dy = s[k][1] == 0 ? 1 : -1;\n\t\t\tfor (int j = s[k][1]; j < m && j >= 0; j += dy)\n\t\t\t{\n\t\t\t\tlong opt = -1;\n\t\t\t\tint sx, sy;\n\t\t\t\tforeach (int t; 0 .. 2)\n\t\t\t\t{\n\t\t\t\t\tsx = i + d[c[k][t]][0];\n\t\t\t\t\tsy = j + d[c[k][t]][1];\n\t\t\t\t\tif (check(sx, sy, n, m) && dp[k][sx][sy] > opt)\n\t\t\t\t\t{\n\t\t\t\t\t\topt = dp[k][sx][sy];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdp[k][i][j] = mat[i][j];\n\t\t\t\tif (opt != -1)\n\t\t\t\t{\n\t\t\t\t\tdp[k][i][j] += opt;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tlong ans = -1;\n\tforeach (int i; 0 .. n)\n\t{\n\t\tforeach (int j; 0 .. m)\n\t\t{\n\t\t\tlong cnt = 0, opt = -1;\n\t\t\t/*foreach (int k; 0 .. 4)\n\t\t\t{\n\t\t\t\tcnt += dp[k][i][j];\n\t\t\t}\n\t\t\tcnt -= mat[i][j] << 2;\n\t\t\tcnt += dp[0][i][j] - mat[i][j];\n\t\t\tcnt += dp[3][i][j] - mat[i][j];\n\t\t\tif (i == 0 && j == m - 1 && i < n - 1)\n\t\t\t{\n\t\t\t\topt = dp[2][i + 1][j];\n\t\t\t}\n\t\t\tif (i == n - 1 && j == m - 1 && i > 0)\n\t\t\t{\n\t\t\t\topt = dp[1][i - 1][j];\n\t\t\t}\n\t\t\tif (i > 0 && i < n - 1 && dp[1][i - 1][j] + dp[2][i + 1][j] > opt)\n\t\t\t{\n\t\t\t\topt = dp[1][i - 1][j] + dp[2][i + 1][j];\n\t\t\t}\n\t\t\tif (i > 0 && j < m - 1 && dp[1][i - 1][j] + dp[2][i][j + 1] > opt)\n\t\t\t{\n\t\t\t\topt = dp[1][i - 1][j] + dp[2][i][j + 1];\n\t\t\t}\n\t\t\tif (i < n - 1 && j < m - 1 && dp[1][i][j + 1] + dp[2][i + 1][j] > opt)\n\t\t\t{\n\t\t\t\topt = dp[1][i][j + 1] + dp[2][i + 1][j];\n\t\t\t}*/\n\t\t\tif (i > 0 && j > 0)\n\t\t\t{\n\t\t\t\tcnt = dp[0][i - 1][j] + dp[3][i][j - 1];\n\t\t\t\tif (i < n - 1 && j < m - 1)\n\t\t\t\t{\n\t\t\t\t\tcnt += dp[1][i][j + 1] + dp[2][i + 1][j];\n\t\t\t\t\tif (cnt > ans)\n\t\t\t\t\t{\n\t\t\t\t\t\tans = cnt;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i < n - 1 && j > 0)\n\t\t\t{\n\t\t\t\tcnt = dp[0][i][j - 1] + dp[3][i + 1][j];\n\t\t\t\tif (i > 0 && j < m - 1)\n\t\t\t\t{\n\t\t\t\t\tcnt += dp[1][i - 1][j] + dp[2][i][j + 1];\n\t\t\t\t\tif (cnt > ans)\n\t\t\t\t\t{\n\t\t\t\t\t\tans = cnt;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(ans);\n}\n\nvoid main(string[] args)\n{\n\tint n, m;\n\twhile (scanf(\"%d%d\", &n, &m) == 2)\n\t{\n\t\tforeach (int i; 0 .. 4)\n\t\t{\n\t\t\tdp[i] = new long[][n];\n\t\t\tforeach (int j; 0 .. n)\n\t\t\t{\n\t\t\t\tdp[i][j] = new long[m];\n\t\t\t}\n\t\t}\n\t\tforeach (int i; 0 .. n)\n\t\t{\n\t\t\tforeach (int j; 0 .. m)\n\t\t\t{\n\t\t\t\tscanf(\"%d\", &mat[i][j]);\n\t\t\t}\n\t\t}\n\t\tsolve(n, m);\n\t}\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\n\nimmutable int maxn = 1010;\n\nint mat[maxn][maxn];\nlong[][][4] dp;\nint d[4][2];\nint c[4][2];\nint s[4][2];\n\nvoid init(int n, int m)\n{\n d[0][0] = -1;\n d[0][1] = 0;\n d[1][0] = 0;\n d[1][1] = -1;\n d[2][0] = 1;\n d[2][1] = 0;\n d[3][0] = 0;\n d[3][1] = 1;\n ///\n c[0][0] = 0;\n c[0][1] = 1;\n c[1][0] = 0;\n c[1][1] = 3;\n c[2][0] = 2;\n c[2][1] = 3;\n c[3][0] = 1;\n c[3][1] = 2;\n ///\n s[0][0] = 0;\n s[0][1] = 0;\n s[1][0] = 0;\n s[1][1] = m - 1;\n s[2][0] = n - 1;\n s[2][1] = m - 1;\n s[3][0] = n - 1;\n s[3][1] = 0;\n}\n\nbool check(int x, int y, int n, int m)\n{\n if (x >= 0 && x < n && y >= 0 && y < m)\n {\n return true;\n }\n return false;\n}\n\nvoid solve(int n, int m)\n{\n init(n, m);\n foreach (int k; 0 .. 4)\n {\n int dx = s[k][0] == 0 ? 1 : -1;\n for (int i = s[k][0]; i < n && i >= 0; i += dx) \n {\n int dy = s[k][1] == 0 ? 1 : -1;\n for (int j = s[k][1]; j < m && j >= 0; j += dy)\n {\n long opt = -1;\n int sx, sy;\n foreach (int t; 0 .. 2)\n {\n sx = i + d[c[k][t]][0];\n sy = j + d[c[k][t]][1];\n if (check(sx, sy, n, m) && dp[k][sx][sy] > opt)\n {\n opt = dp[k][sx][sy];\n }\n }\n dp[k][i][j] = mat[i][j];\n if (opt != -1)\n {\n dp[k][i][j] += opt;\n }\n }\n }\n }\n long ans = -1;\n foreach (int i; 0 .. n)\n {\n foreach (int j; 0 .. m)\n {\n long opt = 0;\n foreach (int k; 0 .. 4)\n {\n opt += dp[k][i][j];\n }\n opt -= mat[i][j] << 2;\n if (opt > ans)\n {\n ans = opt;\n }\n }\n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d%d\", &n, &m) == 2)\n {\n foreach (int i; 0 .. 4)\n {\n dp[i] = new long[][n];\n foreach (int j; 0 .. n)\n {\n dp[i][j] = new long[m];\n }\n }\n foreach (int i; 0 .. n)\n {\n foreach (int j; 0 .. m)\n {\n scanf(\"%d\", &mat[i][j]);\n }\n }\n solve(n, m);\n }\n}"}], "src_uid": "ed5d0eca057f2a2e371b1fc7e3b618bb"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n foreach (a; A) {\n auto m = a % 14;\n if (a <= 14) {\n writeln(\"NO\");\n } else if (m != 0 && m <= 6) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto x = RDA;\n\tforeach (i; 0..t)\n\t{\n\t\tif (x[i] < 15)\n\t\t\twriteln(\"NO\");\n\t\telse\n\t\t{\n\t\t\tauto y = x[i] % 14;\n\t\t\twriteln(y <= 6 && y != 0 ? \"YES\" : \"NO\");\n\t\t}\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool solve (long n)\n{\n\treturn n > 14 && 1 <= n % 14 && n % 14 <= 6;\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tlong n;\n\t\treadf !(\" %s\") (n);\n\t\twriteln (solve (n) ? \"YES \" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tlong[] as = rlong(n);\n\n\tforeach(a; as){\n\t\tif(a < 15) \"NO\".writeln;\n\t\telse if(a % 14 >= 1 && a % 14 <= 6) \"YES\".writeln;\n\t\telse \"NO\".writeln;\n\t}\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const X = readLong();\n const q = X / 14, r = X % 14;\n const ans = (q >= 1 && 1 <= r && r <= 6);\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n foreach (a; A) {\n auto m = a % 14;\n if (a <= 14) {\n writeln(\"NO\");\n } else if (m <= 6) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto x = RDA;\n\tforeach (i; 0..t)\n\t{\n\t\tauto y = x[i] % 14;\n\t\twriteln(y <= 6 && y != 0 ? \"YES\" : \"NO\");\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "840a4e16454290471faa5a27a3c795d9"} {"source_code": "import std.stdio, std.string;\nimport std.container.rbtree;\n\nvoid solve(int[] a, int k)\n{\n auto n = cast(int)a.length;\n auto rbt = redBlackTree!int();\n int[int] cnt;\n foreach (i; 0 .. n)\n {\n if (i >= k && a[i - k] != a[i])\n {\n -- cnt[a[i - k]];\n if (cnt[a[i - k]] == 1)\n {\n rbt.insert(a[i - k]);\n }\n else\n {\n rbt.removeKey(a[i - k]);\n }\n }\n if (i < k || a[i - k] != a[i])\n {\n if (!(a[i] in cnt)) \n {\n cnt[a[i]] = 0;\n }\n ++ cnt[a[i]];\n if (cnt[a[i]] == 1)\n {\n rbt.insert(a[i]);\n }\n else\n {\n rbt.removeKey(a[i]);\n }\n }\n if (i >= k - 1)\n {\n if (rbt.length > 0)\n {\n writeln(rbt.back());\n }\n else\n {\n writeln(\"Nothing\");\n }\n }\n }\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\"%d\\n\", &a[i]);\n }\n solve(a, k);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.random;\n\nclass Treap(T)\n{\n class Node\n {\n Node left;\n Node right;\n T val;\n int priority;\n\n this()\n {\n left = right = null;\n }\n\n //int opCmp(Node node)\n //{\n //return this.priority - node.priority;\n //}\n\n int cmpPriority(int priority)\n {\n if (this.priority == priority) return 0;\n return this.priority < priority ? -1 : 1;\n }\n\n int cmpVal(T val)\n {\n if (this.val == val) return 0;\n return this.val < val ? -1 : 1;\n }\n }\n\n protected Node root;\n protected Xorshift rnd;\n protected int size;\n protected T minimal;\n protected T maximal;\n\n this()\n {\n root = null;\n rnd = Xorshift(1234567891);\n size = 0;\n minimal = T.max;\n maximal = T.min;\n }\n\n protected void leftRotate(ref Node node)\n {\n if (!node.right) return;\n auto rightNode = node.right;\n if (rightNode)\n {\n node.right = rightNode.left;\n rightNode.left = node;\n node = rightNode;\n }\n }\n\n protected void rightRotate(ref Node node)\n {\n if (!node.left) return;\n auto leftNode = node.left;\n if (leftNode)\n {\n node.left = leftNode.right;\n leftNode.right = node;\n node = leftNode;\n }\n }\n\n protected Node find(T val)\n {\n return _find(root, val);\n }\n\n protected Node _find(Node node, T val)\n {\n if (!node) return null;\n auto ret = node.cmpVal(val);\n if (ret == 0) return node;\n if (ret == -1) return _find(node.right, val);\n return _find(node.left, val);\n }\n\n public void insert(T val)\n {\n _insert(root, val);\n }\n\n protected void _insert(ref Node node, T val)\n {\n if (!node)\n {\n node = new Node();\n node.val = val;\n node.priority = this.rnd.front;\n this.rnd.seed(unpredictableSeed);\n ++ size;\n return;\n }\n auto ret = node.cmpVal(val);\n if (ret == 0) return;\n if (ret == 1)\n {\n _insert(node.left, val);\n if (node.left.priority > node.priority)\n {\n rightRotate(node);\n }\n }\n else if (ret == -1)\n {\n _insert(node.right, val);\n if (node.right.priority > node.priority)\n {\n leftRotate(node);\n }\n }\n }\n\n public void remove(T val)\n {\n _remove(root, val);\n }\n\n protected void _remove(ref Node node, T val)\n {\n if (!node) return;\n auto ret = node.cmpVal(val);\n if (ret == 0)\n {\n if (!node.left && !node.right)\n {\n node = null;\n -- size;\n return;\n }\n if (!node.left)\n {\n node = node.right;\n -- size;\n return;\n }\n if (!node.right)\n {\n node = node.left;\n -- size;\n return;\n }\n if (node.left.cmpPriority(node.right.priority) == 1) \n {\n rightRotate(node);\n _remove(node.right, val);\n }\n else\n {\n leftRotate(node);\n _remove(node.left, val);\n }\n return;\n }\n if (ret == -1)\n {\n _remove(node.right, val);\n }\n else\n {\n _remove(node.left, val);\n }\n }\n\n protected T _getMinimal(Node node)\n {\n if (!node) return minimal; \n if (!node.left) return node.val;\n return _getMinimal(node.left);\n }\n\n public T getMinimal()\n {\n return _getMinimal(root);\n }\n\n protected T _getMaximal(Node node)\n {\n if (!node) return maximal;\n if (!node.right) return node.val;\n return _getMaximal(node.right);\n }\n\n public T getMaximal()\n {\n return _getMaximal(root);\n }\n\n public void travel()\n {\n _travel(root);\n }\n\n protected void _travel(Node node)\n {\n if (!node) return;\n _travel(node.left);\n writeln(node.val);\n writeln(node.priority);\n _travel(node.right);\n }\n\n public void clear()\n {\n while (root)\n {\n remove(root.val);\n }\n }\n}\n\nvoid solve(int[] a, int k)\n{\n auto n = cast(int)a.length;\n auto treap = new Treap!int();\n int[int] cnt;\n foreach (i; 0 .. n)\n {\n if (i >= k && a[i - k] != a[i])\n {\n -- cnt[a[i - k]];\n if (cnt[a[i - k]] == 1)\n {\n treap.insert(a[i - k]);\n }\n else\n {\n treap.remove(a[i - k]);\n }\n }\n if (i < k || a[i - k] != a[i])\n {\n if (!(a[i] in cnt)) \n {\n cnt[a[i]] = 0;\n }\n ++ cnt[a[i]];\n if (cnt[a[i]] == 1)\n {\n treap.insert(a[i]);\n }\n else\n {\n treap.remove(a[i]);\n }\n }\n if (i >= k - 1)\n {\n if (treap.size > 0)\n {\n writeln(treap.getMaximal());\n }\n else\n {\n writeln(\"Nothing\");\n }\n }\n }\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\"%d\\n\", &a[i]);\n }\n solve(a, k);\n }\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.random;\n\nclass Treap(T)\n{\n class Node\n {\n Node left;\n Node right;\n T val;\n int priority;\n\n this()\n {\n left = right = null;\n }\n\n //int opCmp(Node node)\n //{\n //return this.priority - node.priority;\n //}\n\n int cmpPriority(int priority)\n {\n if (this.priority == priority) return 0;\n return this.priority < priority ? -1 : 1;\n }\n\n int cmpVal(T val)\n {\n if (this.val == val) return 0;\n return this.val < val ? -1 : 1;\n }\n }\n\n protected Node root;\n protected Xorshift rnd;\n protected int size;\n protected T minimal;\n protected T maximal;\n\n this()\n {\n root = null;\n rnd = Xorshift(1234567891);\n size = 0;\n minimal = T.max;\n maximal = T.min;\n }\n\n protected void leftRotate(ref Node node)\n {\n if (!node.right) return;\n auto rightNode = node.right;\n if (rightNode)\n {\n node.right = rightNode.left;\n rightNode.left = node;\n node = rightNode;\n }\n }\n\n protected void rightRotate(ref Node node)\n {\n if (!node.left) return;\n auto leftNode = node.left;\n if (leftNode)\n {\n node.left = leftNode.right;\n leftNode.right = node;\n node = leftNode;\n }\n }\n\n protected Node find(T val)\n {\n return _find(root, val);\n }\n\n protected Node _find(Node node, T val)\n {\n if (!node) return null;\n auto ret = node.cmpVal(val);\n if (ret == 0) return node;\n if (ret == -1) return _find(node.right, val);\n return _find(node.left, val);\n }\n\n public void insert(T val)\n {\n _insert(root, val);\n }\n\n protected void _insert(ref Node node, T val)\n {\n if (!node)\n {\n node = new Node();\n node.val = val;\n node.priority = this.rnd.front;\n this.rnd.seed(unpredictableSeed);\n ++ size;\n return;\n }\n auto ret = node.cmpVal(val);\n if (ret == 0) return;\n ++ size;\n if (ret == 1)\n {\n _insert(node.left, val);\n if (node.left.priority > node.priority)\n {\n rightRotate(node);\n }\n }\n else if (ret == -1)\n {\n _insert(node.right, val);\n if (node.right.priority > node.priority)\n {\n leftRotate(node);\n }\n }\n }\n\n public void remove(T val)\n {\n _remove(root, val);\n }\n\n protected void _remove(ref Node node, T val)\n {\n if (!node) return;\n auto ret = node.cmpVal(val);\n if (ret == 0)\n {\n -- size;\n if (!node.left && !node.right)\n {\n node = null;\n return;\n }\n if (!node.left)\n {\n node = node.right;\n return;\n }\n if (!node.right)\n {\n node = node.left;\n return;\n }\n if (node.left.cmpPriority(node.right.priority) == 1) \n {\n rightRotate(node);\n _remove(node.right, val);\n }\n else\n {\n leftRotate(node);\n _remove(node.left, val);\n }\n return;\n }\n if (ret == -1)\n {\n _remove(node.right, val);\n }\n else\n {\n _remove(node.left, val);\n }\n }\n\n protected T _getMinimal(Node node)\n {\n if (!node) return minimal; \n if (!node.left) return node.val;\n return _getMinimal(node.left);\n }\n\n public T getMinimal()\n {\n return _getMinimal(root);\n }\n\n protected T _getMaximal(Node node)\n {\n if (!node) return maximal;\n if (!node.right) return node.val;\n return _getMaximal(node.right);\n }\n\n public T getMaximal()\n {\n return _getMaximal(root);\n }\n\n public void travel()\n {\n _travel(root);\n }\n\n protected void _travel(Node node)\n {\n if (!node) return;\n _travel(node.left);\n writeln(node.val);\n writeln(node.priority);\n _travel(node.right);\n }\n\n public void clear()\n {\n while (root)\n {\n remove(root.val);\n }\n }\n}\n\nvoid solve(int[] a, int k)\n{\n auto n = cast(int)a.length;\n auto treap = new Treap!int();\n int[int] cnt;\n foreach (i; 0 .. n)\n {\n if (i >= k && a[i - k] != a[i])\n {\n -- cnt[a[i - k]];\n if (cnt[a[i - k]] == 1)\n {\n treap.insert(a[i - k]);\n }\n else\n {\n treap.remove(a[i - k]);\n }\n }\n if (i < k || a[i - k] != a[i])\n {\n if (!(a[i] in cnt)) \n {\n cnt[a[i]] = 0;\n }\n ++ cnt[a[i]];\n if (cnt[a[i]] == 1)\n {\n treap.insert(a[i]);\n }\n else\n {\n treap.remove(a[i]);\n }\n }\n if (i >= k - 1)\n {\n if (treap.size > 0)\n {\n writeln(treap.getMaximal());\n }\n else\n {\n writeln(\"Nothing\");\n }\n }\n }\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\"%d\\n\", &a[i]);\n }\n solve(a, k);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.random;\n\nclass Treap(T)\n{\n class Node\n {\n Node left;\n Node right;\n T val;\n int priority;\n\n this()\n {\n left = right = null;\n }\n\n //int opCmp(Node node)\n //{\n //return this.priority - node.priority;\n //}\n\n int cmpPriority(int priority)\n {\n if (this.priority == priority) return 0;\n return this.priority < priority ? -1 : 1;\n }\n\n int cmpVal(T val)\n {\n if (this.val == val) return 0;\n return this.val < val ? -1 : 1;\n }\n }\n\n protected Node root;\n protected Xorshift rnd;\n protected int size;\n protected T minimal;\n protected T maximal;\n\n this()\n {\n root = null;\n rnd = Xorshift(1234567891);\n size = 0;\n minimal = T.max;\n maximal = T.min;\n }\n\n protected void leftRotate(ref Node node)\n {\n if (!node.right) return;\n auto rightNode = node.right;\n if (rightNode)\n {\n node.right = rightNode.left;\n rightNode.left = node;\n node = rightNode;\n }\n }\n\n protected void rightRotate(ref Node node)\n {\n if (!node.left) return;\n auto leftNode = node.left;\n if (leftNode)\n {\n node.left = leftNode.right;\n leftNode.right = node;\n node = leftNode;\n }\n }\n\n protected Node find(T val)\n {\n return _find(root, val);\n }\n\n protected Node _find(Node node, T val)\n {\n if (!node) return null;\n auto ret = node.cmpVal(val);\n if (ret == 0) return node;\n if (ret == -1) return _find(node.right, val);\n return _find(node.left, val);\n }\n\n public void insert(T val)\n {\n _insert(root, val);\n }\n\n protected void _insert(ref Node node, T val)\n {\n if (!node)\n {\n node = new Node();\n node.val = val;\n node.priority = this.rnd.front;\n this.rnd.seed(unpredictableSeed);\n ++ size;\n return;\n }\n auto ret = node.cmpVal(val);\n if (ret == 0) return;\n if (ret == 1)\n {\n _insert(node.left, val);\n if (node.left.priority > node.priority)\n {\n rightRotate(node);\n }\n }\n else if (ret == -1)\n {\n _insert(node.right, val);\n if (node.right.priority > node.priority)\n {\n leftRotate(node);\n }\n }\n }\n\n public void remove(T val)\n {\n _remove(root, val);\n }\n\n protected void _remove(ref Node node, T val)\n {\n if (!node) return;\n auto ret = node.cmpVal(val);\n if (ret == 0)\n {\n -- size;\n if (!node.left && !node.right)\n {\n node = null;\n return;\n }\n if (!node.left)\n {\n node = node.right;\n return;\n }\n if (!node.right)\n {\n node = node.left;\n return;\n }\n if (node.left.cmpPriority(node.right.priority) == 1) \n {\n rightRotate(node);\n _remove(node.right, val);\n }\n else\n {\n leftRotate(node);\n _remove(node.left, val);\n }\n return;\n }\n if (ret == -1)\n {\n _remove(node.right, val);\n }\n else\n {\n _remove(node.left, val);\n }\n }\n\n protected T _getMinimal(Node node)\n {\n if (!node) return minimal; \n if (!node.left) return node.val;\n return _getMinimal(node.left);\n }\n\n public T getMinimal()\n {\n return _getMinimal(root);\n }\n\n protected T _getMaximal(Node node)\n {\n if (!node) return maximal;\n if (!node.right) return node.val;\n return _getMaximal(node.right);\n }\n\n public T getMaximal()\n {\n return _getMaximal(root);\n }\n\n public void travel()\n {\n _travel(root);\n }\n\n protected void _travel(Node node)\n {\n if (!node) return;\n _travel(node.left);\n writeln(node.val);\n writeln(node.priority);\n _travel(node.right);\n }\n\n public void clear()\n {\n while (root)\n {\n remove(root.val);\n }\n }\n}\n\nvoid solve(int[] a, int k)\n{\n auto n = cast(int)a.length;\n auto treap = new Treap!int();\n int[int] cnt;\n foreach (i; 0 .. n)\n {\n if (i >= k && a[i - k] != a[i])\n {\n -- cnt[a[i - k]];\n if (cnt[a[i - k]] == 1)\n {\n treap.insert(a[i - k]);\n }\n else\n {\n treap.remove(a[i - k]);\n }\n }\n if (i < k || a[i - k] != a[i])\n {\n if (!(a[i] in cnt)) \n {\n cnt[a[i]] = 0;\n }\n ++ cnt[a[i]];\n if (cnt[a[i]] == 1)\n {\n treap.insert(a[i]);\n }\n else\n {\n treap.remove(a[i]);\n }\n }\n if (i >= k - 1)\n {\n if (treap.size > 0)\n {\n writeln(treap.getMaximal());\n }\n else\n {\n writeln(\"Nothing\");\n }\n }\n }\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\"%d\\n\", &a[i]);\n }\n solve(a, k);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.container.rbtree;\n\nvoid solve(int[] a, int k)\n{\n auto n = cast(int)a.length;\n auto rbt = redBlackTree!int();\n int[int] cnt;\n foreach (i; 0 .. n)\n {\n if (i >= k && a[i - k] != a[i])\n {\n -- cnt[a[i - k]];\n if (cnt[a[i - k]] == 1)\n {\n rbt.insert(a[i - k]);\n }\n }\n if (i < k || a[i - k] != a[i])\n {\n if (!(a[i] in cnt)) \n {\n cnt[a[i]] = 0;\n }\n ++ cnt[a[i]];\n if (cnt[a[i]] == 1)\n {\n rbt.insert(a[i]);\n }\n else\n {\n rbt.removeKey(a[i]);\n }\n }\n if (i >= k - 1)\n {\n if (rbt.length > 0)\n {\n writeln(rbt.back());\n }\n else\n {\n writeln(\"Nothing\");\n }\n }\n }\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\"%d\\n\", &a[i]);\n }\n solve(a, k);\n }\n return 0;\n}"}], "src_uid": "1f6675459b1eca7a3fdb422f03f91563"} {"source_code": "import std.stdio;\nimport std.string;\n\nprivate int n;\n\nprivate int good(string s)\n{\n int[26] x;\n int i;\n for (i = 0; i < 26; i++)\n x[i] = 0;\n foreach (c; s)\n x[c - 'a']++;\n for (i = 0; i < 26 && !x[i]; i++) {}\n for (; i < 26 && x[i] == 1; i++) {}\n for (; i < 26 && !x[i]; i++) {}\n return i == 26;\n}\n\nvoid main()\n{\n scanf(\"%d\\n\", &n);\n for (auto i = 0; i < n; i++)\n writeln(good(readln().strip()) ? \"Yes\" : \"No\");\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n while (N--) solve;\n}\n\nvoid solve() {\n auto S = readln.chomp.map!(a => (a - 'a').to!int).array;\n S.sort();\n bool ok = true;\n foreach (i; 0..S.length.to!int-1) {\n if (S[i] + 1 != S[i+1]) {\n ok = false;\n }\n }\n writeln(ok ? \"Yes\" : \"No\");\n}"}], "negative_code": [], "src_uid": "02a94c136d3fb198025242e91264823b"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.array; \nimport std.range;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--)\n\t{\n\t\tsolve();\n\t}\n}\nvoid solve()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto p = new int[](n);\n\tforeach(ref pi; p) pi = readInt!int - 1;\n\tint[] kcnt = new int[](n);\n\tforeach(i, ref pi; p)\n\t{\n\t\tkcnt[((pi-cast(int)i)%n+n)%n]++;\n\t}\n\tint[] ks;\n\tforeach(k; 0 .. n)\n\t{\n\t\tif (kcnt[k] >= n/3)\n\t\t{\n\t\t\tdebug writeln(\"trying k = \", k);\n\t\t\tint[] cycledP = new int[](n);\n\t\t\tforeach(i, ref ci; cycledP)\n\t\t\t{\n\t\t\t\tci = p[((cast(int)i-k)%n+n)%n];\n\t\t\t}\n\t\t\tdebug writeln(\"cycled is \", cycledP);\n\t\t\tint requiredSwaps = noSwaps(cycledP);\n\t\t\tdebug writeln(\"requires \", requiredSwaps, \" swaps\");\n\t\t\tif (requiredSwaps <= m)\n\t\t\t{\n\t\t\t\tks ~= k;\n\t\t\t}\n\t\t}\n\t}\n\tauto rks = new int[](ks.length);\n\tforeach(i, ref rksi; rks)\n\t{\n\t\trksi = (n-ks[i])%n;\n\t}\n\tsort(rks);\n\twrite(ks.length, \" \");\n\tforeach(k; rks) write(k, \" \");\n\twriteln;\n}\n\nint noSwaps(int[] p)\n{\n\tbool[] visited = new bool[](p.length);\n\tvoid visit(int n)\n\t{\n\t\tassert(!visited[n]);\n\t\tvisited[n] = true;\n\t\tif (!visited[p[n]]) visit(p[n]);\n\t}\n\tint g = 0;\n\tforeach(i; 0 .. cast(int)p.length)\n\t{\n\t\tif (!visited[i])\n\t\t{\n\t\t\tvisit(i);\n\t\t\tg++;\n\t\t}\n\t}\n\treturn cast(int)p.length - g;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool canShift (int n, int m, int [] p, int shift)\r\n{\r\n auto q = new int [n];\r\n foreach (i; 0..n)\r\n {\r\n \tq[i] = (p[i] + n - shift) % n;\r\n }\r\n\r\n\tauto used = new bool [n];\r\n\tint ops = 0;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tif (!used[i] && q[i] != i)\r\n\t\t{\r\n\t\t\tused[i] = true;\r\n\t\t\tfor (int j = q[i]; j != i; j = q[j])\r\n\t\t\t{\r\n\t\t\t\tused[j] = true;\r\n\t\t\t\tops += 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn ops <= m;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto p = readln.splitter.map !(to !(int)).array;\r\n\t\tp[] -= 1;\r\n\r\n\t\tauto d = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\td[(p[i] + n - i) % n] += 1;\r\n\t\t}\r\n\r\n\t\tint [] answer;\r\n\t\tforeach (shift; 0..n)\r\n\t\t{\r\n\t\t\tif (d[shift] + 2 * m >= n)\r\n\t\t\t{\r\n\t\t\t\tif (canShift (n, m, p, shift))\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer ~= (n - shift) % n;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tsort (answer);\r\n\r\n\t\twritefln !(\"%s%( %s%)\") (answer.length, answer);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "2c610873aa1a772a4c7f32cb74dd75fa"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n @(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n auto adjacent = redBlackTree!long();\n foreach(i; 0 .. n)\n {\n if (a.at(i) == -1)\n {\n if (i - 1 >= 0 && a.at(i - 1) != -1)\n adjacent.insert(a.at(i - 1));\n if (i + 1 < n && a.at(i + 1) != -1)\n adjacent.insert(a.at(i + 1));\n }\n }\n if (adjacent.empty)\n {\n writeln(0, \" \", 0);\n }\n else\n {\n auto k = (adjacent.front + adjacent.back) / 2;\n foreach(i; 0 .. n)\n if (a.at(i) == -1)\n a.at(i) = k;\n auto m = iota(0, n - 1).fold!((res, i) => max(res, abs(a.at(i) - a.at(i + 1))))(long.min);\n writeln(m, \" \", k);\n }\n }\n}\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W)\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, string))\n {\n static assert(isDynamicArray!(typeOfField)\n , \" A field with dimension initialization UDA must be a dynamic array.\");\n enum uda = getUDAs!(fieldSymbol, string)[0];\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tlong b = long.max, c = long.min;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] != -1) continue;\n\t\t\tif (i != 0)\n\t\t\t{\n\t\t\t\tif (a[i-1] != -1)\n\t\t\t\t{\n\t\t\t\t\tb.chmin(a[i-1]);\n\t\t\t\t\tc.chmax(a[i-1]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i != n-1)\n\t\t\t{\n\t\t\t\tif (a[i+1] != -1)\n\t\t\t\t{\n\t\t\t\t\tb.chmin(a[i+1]);\n\t\t\t\t\tc.chmax(a[i+1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tauto x = (b+c) / 2;\n\t\tauto y = max(0, x-b, c-x);\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] != -1 && a[i-1] != -1)\n\t\t\t{\n\t\t\t\ty.chmax(abs(a[i] - a[i-1]));\n\t\t\t}\n\t\t}\n\t\tans[ti] = [y, x];\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0], \" \", e[1]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tforeach(_; 0 .. rint){\n\t\tint n = rint;\n\t\tlong[] as = rlong(n);\n\t\tlong l = 1_000_000_000, r = 0;\n\t\tforeach(i; 0 .. n){\n\t\t\tif(as[i] >= 0) continue;\n\t\t\telse{\n\t\t\t\tif(i > 0 && as[i - 1] >= 0) l.chmin(as[i - 1]), r.chmax(as[i - 1]);\n\t\t\t\tif(i < n - 1 && as[i + 1] >= 0) l.chmin(as[i + 1]), r.chmax(as[i + 1]);\n\t\t\t}\n\t\t}\n\t\tlog(\"n:\", n, \"as:\", as, \"l:\", l, \"r:\", r);\n\t\tlong ans = 0;\n\t\tforeach(i; 0 .. n - 1){\n\t\t\tif(as[i] >= 0 && as[i + 1] >= 0) ans.chmax(abs(as[i + 1] - as[i]));\n\t\t}\n\t\tans.chmax((r - l + 1) / 2);\n\n\t\twriteln(ans, \" \", (l + r) / 2);\n\t}\n}"}], "negative_code": [], "src_uid": "8ffd80167fc4396788b745b53068c9d3"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n \n Tuple!(int, int)[][int][int] mp;\n foreach (int i; 1 .. n+1) {\n auto v = readln.chomp.split.map!(to!int);\n auto x = v[0], y = v[1], z = v[2];\n \n mp[x][y] ~= tuple(z, i);\n }\n \n debug { mp.writeln; }\n \n Tuple!(int, int)[] ans;\n \n void takePairs(ref int[] arr, ref int[] leftOvers) {\n while (arr.length > 1) {\n auto idx1 = arr.back;\n arr.popBack();\n auto idx2 = arr.back;\n arr.popBack();\n ans ~= tuple(idx1, idx2);\n }\n \n if (arr.length == 1) {\n leftOvers ~= arr.back;\n arr.popBack();\n }\n }\n \n int[] lftx;\n foreach (xx; mp.keys.sort()) {\n int[] lfty;\n foreach (yy; mp[xx].keys.sort()) {\n auto values = mp[xx][yy].sort().map!(t => t[1]).array;\n takePairs(values, lfty);\n }\n \n takePairs(lfty, lftx);\n }\n \n int[] dummy;\n takePairs(lftx, dummy);\n \n ans.each!(t => writeln(t[0], ' ', t[1]));\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int NA = -1;\n\nalias Point = Tuple !(int, q{x}, int, q{y}, int, q{z}, int, q{num});\n\nPoint [] p;\nbool [] vis;\nint [] [] res;\nint n;\n\nvoid loop (alias pred) ()\n{\n\tint i = NA;\n\tint j = NA;\n\tforeach (k; 0..n)\n\t{\n\t\tif (!vis[k])\n\t\t{\n\t\t\tif (i == NA)\n\t\t\t{\n\t\t\t\ti = k;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tj = k;\n\t\t\t\tif (pred (i, j))\n\t\t\t\t{\n\t\t\t\t\tres ~= [p[i].num,\n\t\t\t\t\t p[j].num];\n\t\t\t\t\tvis[i] = true;\n\t\t\t\t\tvis[j] = true;\n\t\t\t\t\ti = NA;\n\t\t\t\t\tj = NA;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ti = j;\n\t\t\t\t\tj = NA;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tp = new Point [n];\n\t\tforeach (i, ref q; p)\n\t\t{\n\t\t\treadf (\" %s %s %s\", &q.x, &q.y, &q.z);\n\t\t\tq.num = i + 1;\n\t\t}\n\n\t\tsort (p);\n\t\tvis = new bool [n];\n\t\tres = null;\n\n\t\tloop !((i, j) => p[i].x == p[j].x && p[i].y == p[j].y);\n\t\tloop !((i, j) => p[i].x == p[j].x);\n\t\tloop !((i, j) => true);\n\t\twritefln (\"%(%(%s %)\\n%)\", res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tP[] ps;\n\tforeach(i; 0 .. n){\n\t\tps ~= P(i, i + 1, rlong, rlong, rlong);\n\t}\n\t\n\tP[][long][long] pm;\n\tforeach(p; ps){\n\t\tif(p.x !in pm){\n\t\t\tP[][long] tmp;\n\t\t\tpm[p.x] = tmp;\n\t\t}\n\t\tif(p.y !in pm[p.x]) pm[p.x][p.y] = [];\n\t\tpm[p.x][p.y] ~= p;\n\t}\n\t\n\tint[][] ans;\n\t\n\tlong[] xs = pm.keys;\n\txs.sort();\n\tP superleft;\n\tbool hasSuperleft;\n\tforeach(x; xs){\n\t\tlong[] ys = pm[x].keys;\n\t\tys.sort();\n\t\tP left;\n\t\tbool hasLeft;\n\t\tforeach(y; ys){\n\t\t\tP[] pq = pm[x][y];\n\t\t\tpq.sort!isLess();\n\t\t\tforeach(i; 0 .. pq.length / 2){\n\t\t\t\tans ~= [pq[i * 2].name, pq[i * 2 + 1].name];\n\t\t\t}\n\t\t\tif(pq.length % 2){\n\t\t\t\tif(hasLeft){\n\t\t\t\t\tans ~= [pq[$ - 1].name, left.name];\n\t\t\t\t\thasLeft = 0;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tleft = pq[$ - 1];\n\t\t\t\t\thasLeft = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(hasLeft){\n\t\t\tif(hasSuperleft){\n\t\t\t\tans ~= [left.name, superleft.name];\n\t\t\t\thasLeft = 0, hasSuperleft = 0;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tsuperleft = left;\n\t\t\t\thasLeft = 0, hasSuperleft = 1;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tforeach(an; ans) writeln(an[0], \" \", an[1]);\n}\n\nstruct P{\n\tint id, name;\n\tlong x, y, z;\n}\nbool isLess(P a, P b){\n\tif(a.x != b.x) return a.x < b.x;\n\tif(a.y != b.y) return a.y < b.y;\n\treturn a.z < b.z;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nalias Pt = Tuple!(int, \"x\", int, \"y\", int, \"z\", int, \"id\");\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new Pt[N];\n foreach (i; 0 .. N) {\n P[i].x = readInt();\n P[i].y = readInt();\n P[i].z = readInt();\n P[i].id = i;\n }\n \n sort(P);\n \n int[] ans;\n \n int[] as;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && P[i].x == P[j].x; ++j) {}\n int[] bs;\n for (int k = i, l; k < j; k = l) {\n for (l = k; l < j && P[k].y == P[l].y; ++l) {}\n foreach (m; k .. k + (l - k) / 2 * 2) {\n ans ~= P[m].id;\n }\n if ((l - k) % 2 != 0) {\n bs ~= P[l - 1].id;\n }\n }\n const bsLen = cast(int)(bs.length);\n foreach (m; 0 .. bsLen / 2 * 2) {\n ans ~= bs[m];\n }\n if (bsLen % 2 != 0) {\n as ~= bs[$ - 1];\n }\n }\n assert(as.length % 2 == 0);\n ans ~= as;\n \n for (int i = 0; i < N; i += 2) {\n writeln(ans[i] + 1, \" \", ans[i + 1] + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n alias elem = Tuple!(int, int, int, int);\n elem[] arr;\n \n foreach (i; 1 .. n+1) {\n int x, y, z;\n readf(\"%s %s %s\", &x, &y, &z);\n readln;\n \n arr ~= tuple(x, y, z, i);\n }\n \n arr.sort();\n \n foreach (cur; n.iota.stride(2)) {\n writeln(arr[cur][3], ' ', arr[cur+1][3]);\n }\n}"}], "src_uid": "3d92a54be5c544b313f1e87f7b9cc5c8"} {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tfor(int i = 0; i<1; i++)\n\t\tscanf(\"%d\", &n);\n\tif (n%2==1)\n\t{\n\t printf(\"7\");\n\t n-=3;\n\t}\n\tfor (int i=0;i<n/2;i++)\n\t{\n\t printf(\"1\");\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "\ufeffmodule main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d %d\", &n, &k);\n\tif(n%2==1)\n\t{\n\t n-=3;\n\t printf(\"7\");\n\t}\n\twhile(n>0)\n\t{\n\t printf(\"1\");\n\t n-=2;\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}"}, {"source_code": "module main;\nimport std.c.stdio;\nint main(string[] args){\n\tint n; scanf(\"%d\", &n);\n\tif(n % 2){\n\t\tprintf(\"7\");\n\t\tn -= 3;\n\t}\n\tfor(int i = 0; i < n / 2; i++)\n\t\tprintf(\"1\");\n\treturn 0;\n}\n"}, {"source_code": "module main;\nimport std.c.stdio;\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\",&n);\n\tint [] arr = new int[10];\n\tarr[0]=6;\n\tarr[1]=2;\n\tarr[2]=5;\n\tarr[3]=5;\n\tarr[4]=4;\n\tarr[5]=5;\n\tarr[6]=6;\n\tarr[7]=3;\n\tarr[8]=7;\n\tarr[9]=6;\n\t\n\tint len=n/2;\n\tfor(int i=1;i<=len;i++)\n\t{\n\t\tint ok=-1;\n\t\tfor(int j=9;j>-1;j--)\n\t\t{\n\t\t\tint req=n-arr[j];\n\t\t\tif( req>= (len-i)*2 )\n\t\t\t{\n\t\t\t\tif(ok==-1)ok=j;\n\t\t\t}\n\t\t}\n\t\tn=n-arr[ok];\n\t\tprintf(\"%d\",ok);\n\t}\n\t\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n auto nums = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6];\n int n;\n scanf(\"%d\", &n);\n int len = n / 2;\n \n while (len > 0)\n {\n foreach_reverse (i; 0..10)\n if ((len - 1) * 2 <= n - nums[i])\n {\n write(i);\n n -= nums[i];\n break;\n }\n len = len - 1;\n }\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tif(n > 1) {\n\tif(n % 2 == 0) printf(\"1\");\n\telse printf(\"7\");\n\tfor(;n>3;n-=2) printf(\"1\");\n\t} else {\n\tprintf(\"0\");\n\t}\n\treturn 0;\n}\n"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tif(n == 2)\n\t{\n\t printf(\"%d\", 1);\n\t return 0;\n\t} \n\telse if(n == 3)\n\t{\n\t printf(\"%d\", 7);\n\t return 0;\n\t}\n\telse\n\t{\n\t if(n % 2 == 1)\n\t {\n\t n = n - 3;\n\t printf(\"%d\", 7);\n\t }\n\t else\n\t {\n\t n = n - 2;\n\t printf(\"%d\", 1);\n\t }\n\t \n\t while (n > 0)\n\t {\n\t printf(\"%d\", 1);\n\t n = n - 2;\n\t }\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.c.stdio;\n\nint main()\n{ \n long n;\n \n scanf(\"%d\", &n);\n \n long co = n/2;\n \n if(n%2 == 1){\n co--;\n printf(\"%d\", 7);\n }\n for(long i=0;i<co;i++)\n printf(\"%d\", 1);\n \n return 0;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio;\n\nint main(string[] argv) {\n\tint n = 0;\n\tscanf(\"%d\", &n);\n\tif((n & 1) == 1) {\n\t\tn -= 3;\n\t\tputchar('7');\n\t}\n\tfor(int i = 0; i < n; i += 2)\n\t\tputchar('1');\n\treturn 0;\n}\n"}, {"source_code": "module main;\n\n\nimport std.c.stdio;\n\n\nint main(string[] argv)\n{\n\t\nint n, one, seven, a1, a7;\n\t\na1 = 1;\n\ta7 = 7;\n\t\nscanf(\"%d\", &n);\n\t\nif (n % 2 == 1) {seven = 1; one = (n - 3) / 2;}\n\t\nelse {one = n / 2;}\n\t\n\t\nfor (int i = 0; i < seven; i++) printf(\"%d\", a7);\n\t\nfor (int i = 0; i < one; i++) printf(\"%d\", a1);\n\t\nreturn 0;\n}"}, {"source_code": "import std.stdio;\n \nvoid main()\n{\n int n;\n scanf(\"%d\", &n);\n if (n % 2 == 1) { write('7'); n -= 3; }\n for (; n > 0; n -= 2) write('1');\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tif (n%2 == 1)\n\t\tprintf(\"%d\", 7);\n\telse\n\t\tprintf(\"%d\", 1);\n\t\t\n\tfor(int i = 0; i<n/2-1; i++)\n\t\tprintf(\"1\");\n\t\t\n\treturn 0;\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nvoid main()\n{ \n int n;\nread(n);\nif(((n/2)*2) != n) {\nwrite(7);\nn = n - 3;\n}\nwhile(n>=2){\nwrite(1);\nn = n - 2;\n}\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint m = n / 2, k = n % 2;\n\tif(k == 1){\n printf(\"7\");\n --m;\n }\n\twhile(m--)printf(\"1\"); \n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n long x, i;\n readf(\" %s\", &x);\n if (x % 2 == 1)\n {\n write(7);\n x -= 3;\n }\n for (i = 0; i < x; i += 2)\n write(1);\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n if(n%2==1){\n printf(\"7\");\n }else{\n printf(\"1\");\n }\n\tfor(int i = 0; i<n/2-1; i++)\n\t\tprintf(\"1\");\n\treturn 0;\n}"}, {"source_code": "\ufeffmodule main;\nimport std.c.stdio;\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tif(n % 2 == 0)\n\t{\n\t for(int i = 0; i < n / 2; i++)\n\t printf(\"1\");\n\t}\n\telse\n\t{\n\t printf(\"7\");\n\t n -= 3;\n\t for(int i = 0; i < n / 2; i++)\n\t printf(\"1\");\n\t}\n\treturn 0;\n}"}, {"source_code": "module main;\nimport std.c.stdio;\nint main(string[] argv)\n{ \n int number;\n scanf(\"%d\",&number);\n if(number%2==0)\n {\n for(int i=1;i<=number/2;++i) printf(\"1\");\n }\n else{\n printf(\"7\");\n for(int i=1;i<=(number-3)/2;++i) printf(\"1\");\n }\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d %d\", &n, &k);\n\tif(n%2==1)\n\t{\n\t n-=3;\n\t printf(\"7\");\n\t}\n\twhile(n>0)\n\t{\n\t printf(\"1\");\n\t n-=2;\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}"}], "negative_code": [{"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tfor(;n>3;n-=2) printf(\"1\");\n\tif(n == 3) printf(\"7\");\n\telse printf(\"1\");\n\treturn 0;\n}\n"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint m = n / 3, k = n % 3;\n\tif(k == 1){\n\tm--;\n\tif(m<0)m=0;\n\tk=2;\n\t} else \n\tif(k==2)k = 1;\n\twhile(m--)printf(\"7\"); \n\twhile(k--)printf(\"1\");\n\treturn 0;\n}"}, {"source_code": "module main;\nimport std.c.stdio;\nint main(string[] args){\n\tint n; scanf(\"%d\", &n);\n\tif(n % 2){\n\t\tprintf(\"7\");\n\t\tn -= 3;\n\t}\n\tfor(int i = 0; i < n / 2; i++)\n\t\tprintf(\"2\");\n\treturn 0;\n}\n"}, {"source_code": "module main;\nimport std.c.stdio;\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\",&n);\n\tint [] arr = new int[10];\n\tarr[0]=6;\n\tarr[1]=2;\n\tarr[2]=5;\n\tarr[3]=5;\n\tarr[4]=4;\n\tarr[5]=5;\n\tarr[6]=6;\n\tarr[7]=3;\n\tarr[8]=7;\n\tarr[9]=6;\n\tint len=n/2;\n\tfor(int i=1;i<=len;i++)\n\t{\n\t\tint ok=-1;\n\t\tfor(int j=9;j>-1;j--)\n\t\t{\n\t\t\tint req=n-arr[j];\n\t\t\tif( req>= (len-i)*2 )\n\t\t\t{\n\t\t\t\tif(ok==-1)ok=j;\n\t\t\t}\n\t\t}\n\t\tprintf(\"%d\",ok);\n\t}\n\t\n\treturn 0;\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n auto nums = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6];\n int n;\n scanf(\"%d\", &n);\n int len = n / 2;\n \n while (len > 0)\n {\n foreach_reverse (i; 0..10)\n if ((len - 1) * 2 <= n - nums[i])\n {\n write(i);\n break;\n }\n len = len - 1;\n }\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nvoid main()\n{ \n int n;\nread(n);\nif(n%3 != 0) {\nwrite(7);\nn = n - 3;\n}\nwhile(n>=2){\nwrite(1);\nn = n - 2;\n}\n}"}], "src_uid": "4ebea3f56ffd43efc9e1496a0ef7fa2d"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\nimport std.array;\nimport std.conv;\nimport std.math;\n\nint main(string[] argv)\n{ \n\tint n = to!int(readln.split[0] , 10);\n\t\n\tstring[] s = new string[n];\n\tfor(int i = 0;i < n;i++){\n\t\ts[i] = readln;\n\t}\n\ts.sort();\n\tint[] h = new int[n];\n\tint[] m = new int[n];\n\tfor(int i = 0;i < n;i++){\n\t auto x = s[i].split(':');\n\t // writeln(x);\n\t h[i] = to!int(x[0],10);\n\t\tm[i] = to!int(x[1].split('\\n')[0],10);\n// \t\twriteln(h[i] , m[i]);\n\t}\n\tint d = 0;\n\tfor(int i = 0;i < n - 1;i++){\n\t int x = 60 * (h[i + 1] - h[i]) + m[i + 1] - m[i] - 1;\n\t // writeln(x);\n\t if(d < x)d = x;\n\t}\n\tint x = 60 * (23 - h[n - 1]) + 60 - m[n - 1] + 60 * h[0] + m[0] - 1;\n\tif(d < x)d = x;\n\tint a = d % 60;\n\td = (d - a)/60;\n if(d < 10){\n if(a < 10)writeln(\"0\" , to!string(d) , \":0\" , to!string(a));\n else writeln(\"0\" , to!string(d) , \":\" , to!string(a));\n }\n\telse {\n\t if(a < 10)writeln(to!string(d) , \":0\" , to!string(a));\n\t else writeln(to!string(d) , \":\" , to!string(a));\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main(string[] args) {\n int n;\n int[1440] time;\n scanf(\"%d\", &n);\n for ( int i = 0; i < 1440; i++ ) { \n time[ i ] = 0; \n }\n int h, m;\n for ( int i = 0; i < n; i++ ) { \n scanf(\"%d:%d\", &h, &m);\n time[h*60+m] = 1;\n }\n int mm=0;\n int cur=0;\n int cur1=0;\n int t = 0;\n for ( int i = 0; i < 1440; i++){\n if (time[i] == 0){\n cur = cur + 1;\n }\n else {\n if (t == 0){\n cur1 = cur;\n cur = 0;\n t = 1;\n }\n if (cur > mm){\n mm = cur;\n }\n cur = 0;\n }\n }\n if (cur+cur1 > mm){\n mm = cur+cur1;\n }\n writeln(mm/60/10,mm/60%10,\":\",mm%60/10,mm%60%10);\n}"}, {"source_code": "import std.stdio;\n\nint[8888] cnt;\n\nint main() {\n int n;\n \n readf(\"%d\\n\", &n);\n\n\n for (int i = 0; i < n - 1; i++) {\n \tint h, m;\n \t\n \treadf(\"%d:%d\\n\", &h, &m);\n \tint x = h * 60 + m;\n \tcnt[x] = 1;\n \t\n \tcnt[x + 24 * 60] = 1;\n }\n \n \tint h, m;\n \t\n \treadf(\"%d:%d\", &h, &m);\n \tint x = h * 60 + m;\n \tcnt[x] = 1;\n \t\n \tcnt[x + 24 * 60] = 1;\n \n int ans = 0, cur = 0;\n \n for (int i = 0; i < 2 * 24 * 60; i++) {\n \n \tif (cnt[i] == 1) {\n \t\tif (ans < cur) {\n \t\t ans = cur;\n \t\t }\n \t\tcur = 0;\n \t} else cur++;\n \n }\n \n if (ans < cur) {\n ans = cur;\n }\n \n printf(\"%02d:%02d\", ans/60, ans % 60);\n\n return 0; \n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tif (n == 1) {\n\t\tprintf(\"23:59\");\n\t\treturn 0;\n\t}\n\tint cm = 0;\n\tint time = 0;\n\tint[] ms = new int[n];\n\tfor (int i = 0; i < n; ++i) {\n\t\tgetchar();\n\t\tint h = (getchar() - '0') * 10 + getchar() - '0';\n\t\tgetchar();\n\t\tint m = (getchar() - '0') * 10 + getchar() - '0';\n\t\tms[i] = 60 * h + m;\n\t}\n\tms.sort();\n\tint dif = ms[0] + 24 * 60 - ms[n - 1];\n\tfor (int i = 1; i < n; ++i) {\n\t\tif (ms[i] - ms[i - 1] > dif) {\n\t\t\tdif = ms[i] - ms[i - 1];\n\t\t}\n\t}\n\t--dif;\n\tint h1 = dif / 60;\n\tdif = dif - 60 * h1;\n\tprintf(\"%d%d:%d%d\", h1 / 10, h1 % 10, dif / 10, dif % 10);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\nint main(string[] argv)\n{\n\tint n, h,m,ot, z,a;\n\tot = 0;\n\tscanf(\"%d\", &n);\n\t\n\tint [] t = new int[n];\n\t\n\t\n\tfor(int i = 0; i<n; i++)\n\t{\n\t\tscanf(\"%d:%d\", &h, &m);\n\t\tt[i] = h*60+m;\n\t}\n\tt.sort(); \n\tz=t[0]+24*60;\n\tfor(int i = 1; i<n; i++)\n\t{\n\t if (t[i]-t[i-1]-1>ot) ot=t[i]-t[i-1]-1;\n\t}\n\tif (z-t[n-1]-1>ot) ot=z-t[n-1]-1;\n\ta = ot/60;\n\tif (a<10) printf(\"0%d:\",a);\n\telse printf(\"%d:\",a);\n\ta = ot%60;\n\tif (a<10) printf(\"0%d\",a);\n\telse printf(\"%d\",a);\n\treturn 0;\n}"}, {"source_code": "module main;\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint [] arr = new int[105];\n\t\n\tint n;\n\tscanf(\"%d\", &n);\n\t\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tint h, m;\n\t\tchar c;\n\t\tscanf(\"%d%c%d\", &h, &c, &m);\n\t\tint now = h * 60 + m;\n\t\tarr[i] = now;\n\t}\n\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tfor (int j = n - 1; j >= i + 1; j--)\n\t\t{\n\t\t\tif (arr[j] < arr[j - 1])\n\t\t\t{\n\t\t\t\tint t = arr[j - 1];\n\t\t\t\tarr[j - 1] = arr[j];\n\t\t\t\tarr[j] = t;\n\t\t\t}\n\t\t}\n\t}\n\tarr[n] = arr[0] + 24 * 60;\n\tn++;\n\n\tint ans = 0;\n\tfor (int i = 1; i < n; i++)\n\t{\n\t\tif (ans < arr[i] - arr[i - 1] - 1)\n\t\t\tans = arr[i] - arr[i - 1] - 1;\n\t}\n\n\tint h = ans / 60, m = ans % 60;\n\n\tif (h < 10)\n\t\tprintf(\"0%d\", h);\n\telse\n\t\tprintf(\"%d\", h);\n\tprintf(\":\");\n\tif (m < 10)\n\t\tprintf(\"0%d\", m);\n\telse\n\t\tprintf(\"%d\", m);\n\t\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\n\nint main (string[] argv)\n{\n\tint n;\n\tscanf (\"%d\", &n);\n\tint [] arr = new int[n + 1];\n\tfor (int i = 0, h, m; i < n; i++) {\n\t\tscanf(\"%d:%d\", &h, &m);\n\t\tarr[i] = h * 60 + m;\n\t}\n\tarr[n] = 1000000000;\n\tsort (arr);\n\tarr[n] = arr[0] + 24 * 60;\n\t\n\tint ans = -1;\n\tfor (int i = 1; i <= n; i++) {\n\t\tans = max (ans, arr[i] - arr[i - 1] - 1);\n\t}\n\tprintf (\"%02d:%02d\\n\", ans / 60, ans % 60);\n\t\n\treturn 0;\n}"}, {"source_code": "module main;\nimport std.c.stdio;\nimport std.algorithm.sorting;\n\nint n;\nint[] ar = new int[1111];\n\t\nvoid read()\n{\n for(int i = 0 ; i < 1111 ; i ++) ar[i] = 2147483647;\n\tscanf(\"%d\", &n);\n\tfor(int i = 0 ; i < n ; i ++)\n\t{\n\t char c;\n\t\tint h, m; scanf(\"%d%c%d\", &h, &c, &m);\n\t\tar[i] = (h * 60) + m;\n\t}\n}\n\t\nint solve()\n{\n\tint res = 0;\n\n\tsort(ar);\n\n\t\n\tar[n] = ar[0] + 24 * 60;\n\tfor(int i = 1 ; i <= n ; i ++)\n\t{\n\t\tif(res < ar[i] - ar[i - 1] - 1)\n\t\t{\n\t\t\tres = ar[i] - ar[i - 1] - 1;\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid print(int s)\n{\n\tint h = s / 60;\n\tint m = s % 60;\n\t\n\tif (h < 10)\n\t\tprintf(\"0%d\", h);\n\telse\n\t\tprintf(\"%d\", h);\n\t\n\tprintf(\":\");\n\t\n\tif (m < 10)\n\t\tprintf(\"0%d\", m);\n\telse\n\t\tprintf(\"%d\", m);\n}\n\t\nint main(string[] argv)\n{\n\tread();\n\tprint(solve());\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.array, std.conv, std.algorithm;\n\nvoid main()\n{\n auto max = 0;\n stdin.readln();\n auto arr = stdin\n .byLineCopy\n .array\n .sort!((a, b) => a < b) // descending order\n .map!(l => l.split(\":\"))\n .map!(l => to!int(l[0]) * 60 + to!int(l[1]));\n for (int i = 0; i < arr.length; i++) {\n if (i < arr.length - 1 && arr[i + 1] - arr[i] > max) max = arr[i + 1] - arr[i];\n if (i == arr.length - 1 && arr[0] + 1440 - arr[i] > max) max = arr[0] + 1440 - arr[i];\n }\n max = max - 1;\n printf(\"%02d:%02d\", max / 60, max % 60);\n}"}, {"source_code": "import std.stdio;\n\nint[3500] cnt;\n\nint main() {\n int n;\n readf(\"%d\\n\", &n);\n\n\n for (int i = 0; i < n; i++) {\n \tint h, m;\n \treadf(\"%d:%d\\n\", &h, &m);\n \tint x = h * 60 + m;\n \tcnt[x] = 1;\n \tcnt[x + 24 * 60] = 1;\n }\n \n int ans = 0, cur = 0;\n for (int i = 0; i < 2 * 24 * 60; i++) {\n \tif (cnt[i] == 1) {\n \t\tif (ans < cur) ans = cur;\n \t\tcur = 0;\n \t} else cur++;\n }\n \n if (ans < cur) ans = cur;\n printf(\"%02d:%02d\", ans/60, ans % 60);\n\n return 0; \n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nstatic int [1440] all;\nint [2000] t;\n\nint format(char[] s) {\n return ((s[0] - '0') * 10 + (s[1] - '0')) * 60 + (s[3] - '0') * 10 + (s[4] - '0');\n}\n\nvoid pr(int x) {\n printf(\"%d\", (x / 60) / 10);\n printf(\"%d\", (x / 60) % 10);\n printf(\":\");\n printf(\"%d\", (x % 60) / 10);\n printf(\"%d\", (x % 60) % 10);\n}\n\nint main(string[] argv)\n{\n int n;\n scanf(\"%d\", &n);\n for (int i = 0; i < n; i++) {\n char [6] s;\n scanf(\"%s\", &s);\n all[format(s)]++;\n }\n int j = 0;\n\tfor (int i = 0; i < 1440; i++) {\n\t if (all[i] > 0) t[j++] = i;\n\t}\n\tint ans = 0;\n\tfor (int i = 1; i < j; i++) {\n\t if (ans < t[i] - t[i - 1] - 1) {\n\t ans = t[i] - t[i - 1] - 1;\n\t }\n\t}\n\tif (ans < t[0] + 1439 - t[j - 1]) {\n\t ans = t[0] + 1439 - t[j - 1];\n\t}\n\tpr(ans);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i<n; i++){\n\t int h,m;\n\t\tscanf(\"%d:%d\", &h,&m);\n\t\th*=60;\n\t\tarr[i] = h+m;\n\t}\n\tarr.sort();\n\tint mx=0;\n\tfor(int i=0;i<n-1;i++){\n\t\tint dif = arr[i+1] - arr[i] - 1;\n\t\tif(dif>mx)mx = dif;\n\t}\n\tint dif = 1440 - arr[n-1] + arr[0] - 1;\n\tif(dif>mx)mx=dif;\n\tif(n==1){\n\t\tprintf(\"23:59\\n\");\n\t}\n\tif(n!=1){\n\t if(mx/600==0){\n\t printf(\"0\");\n\t }\n\t\tprintf(\"%d:\", mx/60);\n\t\tif((mx-mx/60*60)/10 == 0){\n\t\t printf(\"0\");\n\t\t}\n\t\tprintf(\"%d\\n\",mx-mx/60*60);\n\t}\n\treturn 0;\n}"}, {"source_code": "module main;\nimport core.stdc.stdio;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n int n, ans = 0;\n scanf(\"%d\", &n);\n int[] t = new int[n];\n for (int i = 0; i < n; ++i) {\n int h, m;\n scanf(\"%d:%d\", &h, &m);\n t[i] = 60*h+m;\n }\n if (n == 1) {\n puts(\"23:59\");\n return 0;\n }\n t.sort();\n \n for (int i = 1; i < n; ++i) {\n int v = t[i]-t[i-1]-1;\n if (v > ans) ans = v;\n }\n int tmp = 60*24+t[0]-t[n-1]-1;\n if (tmp > ans) ans = tmp;\n printf(\"%02d:%02d\\n\", ans/60, ans%60);\n \n return 0;\n}"}, {"source_code": "//Written by libra9z,Use D\nmodule main;\nimport core.stdc.stdio;\nimport std.algorithm;\nint max(int a,int b)\n{\n if(a>b) return a;\n\telse return b;\n}\nint main()\n{\n int n;\n scanf(\"%d\",&n);\n if(n==1)\n\t{\n printf(\"23:59\");\n return 0;\n }\n int [] arr=new int[n];\n for(int i=0;i<n;i++)\n\t{\n int a,b;\n scanf(\"%d:%d\",&a,&b);\n arr[i]=a*60+b;\n }\n arr.sort();\n int ans=arr[0]+(24*60-arr[n-1]);\n for(int i=0;i<n-1;i++)\n\t{\n ans=max(ans,arr[i+1]-arr[i]);\n }\n ans--;\n printf(\"%02d:%02d\",ans/60,ans%60);\n return 0;\n}"}, {"source_code": "//Written by libra9z,Use D\nmodule main;\nimport core.stdc.stdio;\nint max(int a,int b)\n{\n if(a>b) return a;\n\telse return b;\n}\nint main()\n{\n int n;\n scanf(\"%d\",&n);\n if(n==1)\n\t{\n printf(\"23:59\");\n return 0;\n }\n int [] arr=new int[105];\n for(int i=0;i<n;i++)\n\t{\n int a,b;\n scanf(\"%d:%d\",&a,&b);\n arr[i]=a*60+b;\n }\n for(int i=0;i<n;i++)\n\t{\n for(int j=0;j<n;j++)\n\t\t{\n if(arr[i]<arr[j])\n\t\t\t{\n int t=arr[i];\n arr[i]=arr[j];\n arr[j]=t;\n }\n }\n }\n int ans=arr[0]+(24*60-arr[n-1]);\n for(int i=0;i<n-1;i++)\n\t{\n ans=max(ans,arr[i+1]-arr[i]);\n }\n ans--;\n printf(\"%02d:%02d\",ans/60,ans%60);\n return 0;\n}"}, {"source_code": "//Written by libra9z,Use D\nmodule main;\nimport core.stdc.stdio;\nimport std.algorithm;\nint main()\n{\n int n;\n scanf(\"%d\",&n);\n if(n==1)\n\t{\n printf(\"23:59\");\n return 0;\n }\n int [] arr=new int[n];\n for(int i=0;i<n;i++)\n\t{\n int a,b;\n scanf(\"%d:%d\",&a,&b);\n arr[i]=a*60+b;\n }\n arr.sort();\n int ans=arr[0]+(24*60-arr[n-1]);\n for(int i=0;i<n-1;i++)\n\t{\n ans=max(ans,arr[i+1]-arr[i]);\n }\n ans--;\n printf(\"%02d:%02d\",ans/60,ans%60);\n return 0;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio ;\n\nint main()\n{\n\tint n,l,r,q,k=0,j=0,ans=0,low,mid,i;\n\tscanf(\"%d\", &q);\n\tint [] a = new int[1000005];\n \n for(i=0;i<q;i++)\n {\n scanf(\"%d:%d\",&l,&r);\n k=l*60+r;\n a[k]++;\n a[k+1440]++;\n }\n for(i=0;i<2879;i++){\n if(a[i]==0) j++;\n else {\n if(ans<j) ans=j;\n j=0;\n }\n }\n if(ans<j) ans=j;\n int hh=ans/60;\n int mm=ans%60;\n if(hh<10) printf(\"0%d:\",hh);\n else printf(\"%d:\",hh);\n \n if(mm<10) printf(\"0%d\",mm);\n else printf(\"%d\",mm);\n\treturn 0;\n}"}, {"source_code": "module main;\nimport core.stdc.stdio;\n\nint max(int a,int b){\n if(a>b) return a; else return b;\n}\n\nint main(){\n int n;\n scanf(\"%d\",&n);\n if(n==1){\n printf(\"23:59\");\n return 0;\n }\n \n int [] arr=new int[105];\n for(int i=0;i<n;i++){\n int a,b;\n scanf(\"%d:%d\",&a,&b);\n //printf(\"%d %d\",a,b);\n \n arr[i]=a*60+b;\n }\n \n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(arr[i]<arr[j]){\n int t=arr[i];\n arr[i]=arr[j];\n arr[j]=t;\n }\n }\n }\n \n // for(int i=0;i<n;i++){\n // printf(\"%d \",arr[i]);\n // }\n \n int ans=arr[0]+(24*60-arr[n-1]);\n for(int i=0;i<n-1;i++){\n ans=max(ans,arr[i+1]-arr[i]);\n }\n ans--;\n printf(\"%02d:%02d\",ans/60,ans%60);\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] a = new int[1005];\n\tint [] b = new int[1005];\n\tint [] c = new int[1005];\n\tfor(int i = 1; i<=n; i++)\n\t\tscanf(\"%d:%d\", &a[i],&b[i]);\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\n\tc[i]=a[i]*60+b[i];//printf(\"%d \",c[i]);\n\t}\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\tint minn=100000000,pla=0,j;\n\t\tfor(j=i;j<=n;j++)\n\t\t{\n\t\t\tif(c[j]<minn)\n\t\t\t{\n\t\t\t\tminn=c[j];\n\t\t\t\tpla=j;\n\t\t\t}\n\t\t}\n\t\t//printf(\"pla:%d\",pla);\n\t\tint t=c[pla];\n\t\tc[pla]=c[i];\n\t\tc[i]=t;\n\t}\n\tint ans=0;\n\tfor(int i=1;i<n;i++)\n\t{\n\t//printf(\"%d \",c[i]);\n\tif(c[i+1]-c[i]>ans) ans=c[i+1]-c[i];\n\t}\n\tif(n==1)\n\t{\n\t\tprintf(\"23:59\");\n\t\treturn 0;\n\t}\n\telse\n\t{\n\tif(1440-c[n]+c[1]>ans) ans=1440-c[n]+c[1];\n\t\tans--;\n\t\tprintf(\"%02d:%02d\",ans/60,ans%60);\n\t}\n\treturn 0;\n}"}, {"source_code": "module main;\nimport core.stdc.stdio;\n\nint max(int a,int b){\n if(a>b) return a; else return b;\n}\n\nint main(){\n int n;\n scanf(\"%d\",&n);\n if(n==1){\n printf(\"23:59\");\n return 0;\n }\n \n int [] arr=new int[105];\n for(int i=0;i<n;i++){\n int a,b;\n scanf(\"%d:%d\",&a,&b);\n //printf(\"%d %d\",a,b);\n \n arr[i]=a*60+b;\n }\n \n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(arr[i]<arr[j]){\n int t=arr[i];\n arr[i]=arr[j];\n arr[j]=t;\n }\n }\n }\n \n // for(int i=0;i<n;i++){\n // printf(\"%d \",arr[i]);\n // }\n \n int ans=arr[0]+(24*60-arr[n-1]);\n for(int i=0;i<n-1;i++){\n ans=max(ans,arr[i+1]-arr[i]);\n }\n ans--;\n printf(\"%02d:%02d\",ans/60,ans%60);\n return 0;\n}"}, {"source_code": "\nmodule main;\n\nimport std.c.stdio;\n\nint dig(char c){\n c -= '0';\n return c <= 9 ? c : -1;\n}\n\nint main(string[] argv)\n{\n\tchar[] arr = new char[15];\n int t = 24 * 60;\n int[] a = new int[t];\n for(int i = 0; i < t; i++) a[i] = 0;\n\tint n;\n\tscanf(\"%d\", &n);\n\tfor(int i = 0; i<n; i++){\n\t \n\t for(int j = 0; j < 15; j++) arr[j] = 0;\n\t scanf(\"%s\", &arr[0]);\n\t //printf(\"%c\\n\", arr[0]);\n\t int u = dig(arr[0]), uu = dig(arr[1]), v = dig(arr[3]), vv = dig(arr[4]);\n\t //printf(\"%d\\n\", 60 * (10 * u + uu) + (10 * v + vv));\n\t a[60 * (10 * u + uu) + (10 * v + vv)] = 1;\n\t}\n\t\n\tint mxmin = 1;\n\tfor(int i = 0; i < t; i++){\n\t // start at time i\n\t if(a[i] != 1){\n\t for(int j = 0; j < t; j++){\n\t if(a[(i + j) % t] == 1){\n\t if(mxmin < j) mxmin = j;\n\t break;\n\t }\n\t }\n\t }\n\t}\n\t\n\t\n\tint hrs = mxmin / 60;\n\tint mns = mxmin - 60 * hrs;\n\t\n\tif(hrs < 10) printf(\"%d\", 0);\n\tprintf(\"%d\", hrs);\n\t\n\tprintf(\":\");\n\t\n\tif(mns < 10) printf(\"%d\", 0);\n\tprintf(\"%d\\n\", mns);\n\t\n\t\n\treturn 0;\n}\n"}, {"source_code": "import std.c.stdio;\n\nint main()\n{\n int n;\n int a[100];\n scanf(\"%d\",&n);\n for(int i=0;i<n;i++)\n {\n int h,m;\n scanf(\"%d:%d\",&h,&m);\n a[i]=h*60+m;\n }\n for(int i=0;i<n;i++)\n for(int j=0;j+1<n;j++)\n if(a[j]>a[j+1])\n {\n int t=a[j];\n a[j]=a[j+1];\n a[j+1]=t;\n }\n int res=0;\n for(int i=0;i+1<n;i++)\n {\n if(res<a[i+1]-a[i]-1)\n res=a[i+1]-a[i]-1;\n }\n if(res<a[0]+24*60-a[n-1]-1)\n res=a[0]+24*60-a[n-1]-1;\n printf(\"%02d:%02d\",res/60, res%60);\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i<n; i++){\n\t int h,m;\n\t\tscanf(\"%d:%d\", &h,&m);\n\t\th*=60;\n\t\tarr[i] = h+m;\n\t}\n\tarr.sort();\n\tint mx=0;\n\tfor(int i=0;i<n-1;i++){\n\t\tint dif = arr[i+1] - arr[i] - 1;\n\t\tif(dif>mx)mx = dif;\n\t}\n\tif(n==1){\n\t\tprintf(\"23:59\\n\");\n\t}\n\tif(n!=1){\n\t if(mx/600==0){\n\t printf(\"0\");\n\t }\n\t\tprintf(\"%d:\", mx/60);\n\t\tif((mx-mx/60*60)/10 == 0){\n\t\t printf(\"0\");\n\t\t}\n\t\tprintf(\"%d\\n\",mx-mx/60*60);\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i<n; i++){\n\t int h,m;\n\t\tscanf(\"%d:%d\", &h,&m);\n\t\th*=60;\n\t\tarr[i] = h+m;\n\t}\n\tarr.sort();\n\tint mx=0;\n\tfor(int i=0;i<n-1;i++){\n\t\tint dif = arr[i+1] - arr[i] - 1;\n\t\tif(dif>mx)mx = dif;\n\t}\n\tint dif = 1320 - arr[n-1] + arr[0];\n\tif(dif>mx)mx=dif;\n\tif(n==1){\n\t\tprintf(\"23:59\\n\");\n\t}\n\tif(n!=1){\n\t if(mx/600==0){\n\t printf(\"0\");\n\t }\n\t\tprintf(\"%d:\", mx/60);\n\t\tif((mx-mx/60*60)/10 == 0){\n\t\t printf(\"0\");\n\t\t}\n\t\tprintf(\"%d\\n\",mx-mx/60*60);\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i<n; i++){\n\t int h,m;\n\t\tscanf(\"%d:%d\", &h,&m);\n\t\th*=60;\n\t\tarr[i] = h+m;\n\t}\n\tarr.sort();\n\tint mx=0;\n\tfor(int i=0;i<n-1;i++){\n\t\tint dif = arr[i+1] - arr[i] - 1;\n\t\tif(dif>mx)mx = dif;\n\t}\n\tint dif = 1440 - arr[n-1] + arr[0];\n\tif(dif>mx)mx=dif;\n\tif(n==1){\n\t\tprintf(\"23:59\\n\");\n\t}\n\tif(n!=1){\n\t if(mx/600==0){\n\t printf(\"0\");\n\t }\n\t\tprintf(\"%d:\", mx/60);\n\t\tif((mx-mx/60*60)/10 == 0){\n\t\t printf(\"0\");\n\t\t}\n\t\tprintf(\"%d\\n\",mx-mx/60*60);\n\t}\n\treturn 0;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i<n; i++){\n\t int h,m;\n\t\tscanf(\"%d:%d\", &h,&m);\n\t\th*=60;\n\t\tarr[i] = h+m;\n\t}\n\tarr.sort();\n\tint mx=0;\n\tfor(int i=0;i<n-1;i++){\n\t\tint dif = arr[i+1] - arr[i] - 1;\n\t\tif(dif>mx)mx = dif;\n\t}\n\tint dif = arr[n-1] - arr[0] - 1;\n\tif(dif>mx)mx=dif;\n\tif(n==1){\n\t\tprintf(\"23:59\\n\");\n\t}\n\tif(n!=1){\n\t if(mx/600==0){\n\t printf(\"0\");\n\t }\n\t\tprintf(\"%d:\", mx/60);\n\t\tif((mx-mx/60*60)/10 == 0){\n\t\t printf(\"0\");\n\t\t}\n\t\tprintf(\"%d\\n\",mx-mx/60*60);\n\t}\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio ;\n\nint main()\n{\n\tint n,l,r,q,k=0,j=0,ans=0,low,mid,i;\n\tscanf(\"%d\", &q);\n\tint [] a = new int[1000005];\n \n for(i=0;i<q;i++)\n {\n scanf(\"%d:%intd\",&l,&r);\n k=l*60+r;\n a[k]++;\n a[k+1440]++;\n }\n for(i=0;i<2880;i++){\n if(a[i]==0) j++;\n else {\n if(ans<j) ans=j;\n j=0;\n }\n }\n if(ans<j) ans=j;\n int hh=ans/60;\n int mm=ans%60;\n if(hh<10) printf(\"0%d:\",hh);\n else printf(\"%d:\",hh);\n \n if(mm<10) printf(\"0%d\",mm);\n else printf(\"%d\",mm);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio ;\n\nint main()\n{\n\tint n,l,r,q,k=0,j=0,ans=0,low,mid,i;\n\tscanf(\"%d\", &q);\n\tint [] a = new int[1000005];\n \n for(i=0;i<q;i++)\n {\n scanf(\"%d:%intd\",&l,&r);\n k=l*60+r;\n a[k]++;\n a[k+1440]++;\n }\n for(i=0;i<2880;i++){\n if(a[i]==0) j++;\n else {\n if(ans<j) ans=j;\n j=0;\n }\n }\n if(ans<j) ans=j;\n printf(\"%d:%d\",ans/60,ans%60);\n\treturn 0;\n}"}, {"source_code": "module main;\nimport core.stdc.stdio;\n\nint max(int a,int b){\n if(a>b) return a; else return b;\n}\n\nint main(){\n int n;\n scanf(\"%d\",&n);\n if(n==1){\n printf(\"23:59\");\n return 0;\n }\n \n int [] arr=new int[105];\n for(int i=0;i<n;i++){\n int a,b;\n scanf(\"%d:%d\",&a,&b);\n //printf(\"%d %d\",a,b);\n \n arr[i]=a*60+b;\n }\n \n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(arr[i]<arr[j]){\n int t=arr[i];\n arr[i]=arr[j];\n arr[j]=t;\n }\n }\n }\n \n // for(int i=0;i<n;i++){\n // printf(\"%d \",arr[i]);\n // }\n \n int ans=arr[0]+(24*60-arr[n-1])-1;\n for(int i=0;i<n-1;i++){\n ans=max(ans,arr[i+1]-arr[i]);\n }\n ans--;\n printf(\"%02d:%02d\",ans/60,ans%60);\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\nimport std.array;\nimport std.conv;\nimport std.math;\n\nint main(string[] argv)\n{ \n\tint n = to!int(readln.split[0] , 10);\n\t\n\tstring[] s = new string[n];\n\tfor(int i = 0;i < n;i++){\n\t\ts[i] = readln;\n\t}\n\ts.sort();\n\tint[] h = new int[n];\n\tint[] m = new int[n];\n\tfor(int i = 0;i < n;i++){\n\t auto x = s[i].split(':');\n\t // writeln(x);\n\t h[i] = to!int(x[0],10);\n\t\tm[i] = to!int(x[1].split('\\n')[0],10);\n// \t\twriteln(h[i] , m[i]);\n\t}\n\tint d = 0;\n\tfor(int i = 0;i < n - 1;i++){\n\t int x = 60 * (h[i + 1] - h[i]) + m[i + 1] - m[i] - 1;\n\t // writeln(x);\n\t if(d < x)d = x;\n\t}\n\tint x = 60 * (23 - h[n - 1]) + 60 - m[n - 1] + 60 * h[0] + m[0] - 1;\n\tif(d < x)d = x;\n\tint a = d % 60;\n\td = (d - a)/60;\n// \twriteln(d);\n// \twriteln(a);\n\twriteln(to!string(d) , \":\" , to!string(a));\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\nimport std.array;\nimport std.conv;\nimport std.math;\n\nint main(string[] argv)\n{ \n\tint n = to!int(readln.split[0] , 10);\n\t\n\tstring[] s = new string[n];\n\tfor(int i = 0;i < n;i++){\n\t\ts[i] = readln;\n\t}\n\ts.sort();\n\tint[] h = new int[n];\n\tint[] m = new int[n];\n\tfor(int i = 0;i < n;i++){\n\t auto x = s[i].split(':');\n\t // writeln(x);\n\t h[i] = to!int(x[0],10);\n\t\tm[i] = to!int(x[1].split('\\n')[0],10);\n// \t\twriteln(h[i] , m[i]);\n\t}\n\tint d = 0;\n\tfor(int i = 0;i < n - 1;i++){\n\t int x = 60 * (h[i + 1] - h[i]) + m[i + 1] - m[i] - 1;\n\t // writeln(x);\n\t if(d < x)d = x;\n\t}\n\tint x = 60 * (23 - h[n - 1]) + 60 - m[n - 1] + 60 * h[0] + m[0] - 1;\n\tif(d < x)d = x;\n\tint a = d % 60;\n\td = (d - a)/60;\n// \twriteln(d);\n// \twriteln(a);\n if(d < 10)writeln(\"0\" , to!string(d) , \":\" , to!string(a));\n\telse writeln(to!string(d) , \":\" , to!string(a));\n\treturn 0;\n}"}, {"source_code": "module main;\nimport std.c.stdio;\nimport std.algorithm.sorting;\n\nint n;\nint[] ar = new int[1111];\n\t\nvoid read()\n{\n\tscanf(\"%d\", &n);\n\tfor(int i = 0 ; i < n ; i ++)\n\t{\n\t\tint h, m; scanf(\"%d %d\", &h, &m);\n\t\tar[i] = (h * 60) + m;\n\t}\n}\n\t\nint solve()\n{\n\tint res = 0;\n\tar.sort();\n\tar[n] = ar[0] + 24 * 60;\n\tfor(int i = 1 ; i <= n ; i ++)\n\t\tif(res < ar[i] - ar[i - 1] - 1)\n\t\t\tres = ar[i] - ar[i - 1] - 1;\n\treturn res;\n}\n\nvoid print(int s)\n{\n\tint h = s / 60;\n\tint m = s % 60;\n\t\n\tif (h < 10)\n\t\tprintf(\"0%d\", h);\n\telse\n\t\tprintf(\"%d\", h);\n\t\n\tprintf(\":\");\n\t\n\tif (m < 10)\n\t\tprintf(\"0%d\", m);\n\telse\n\t\tprintf(\"%d\", m);\n}\n\t\nint main(string[] argv)\n{\n\tread();\n\tprint(solve());\n\treturn 0;\n}"}, {"source_code": "module main;\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint [] arr = new int[105];\n\t\n\tint n;\n\tscanf(\"%d\", &n);\n\t\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tint h, m;\n\t\tchar c;\n\t\tscanf(\"%d%c%d\", &h, &c, &m);\n\t\tint now = h * 60 + m;\n\t\tarr[i] = now;\n\t}\n\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tfor (int j = n - 1; j >= i + 1; j--)\n\t\t{\n\t\t\tif (arr[j] < arr[j - 1])\n\t\t\t{\n\t\t\t\tint t = arr[j - 1];\n\t\t\t\tarr[j - 1] = arr[j];\n\t\t\t\tarr[j] = t;\n\t\t\t}\n\t\t}\n\t}\n\tarr[n] = arr[0] + 24 * 60;\n\tn++;\n\n\tint ans = 0;\n\tfor (int i = 1; i < n; i++)\n\t{\n\t\tif (ans < arr[i] - arr[i - 1] - 1)\n\t\t\tans = arr[i] - arr[i - 1] - 1;\n\t}\n\n\tint h = ans / 60, m = ans % 60;\n\tprintf(\"%d%c%d\", h, ':', m);\n\t\n\treturn 0;\n}"}], "src_uid": "c3b0b7194ce018bea9c0b9139e537a09"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n uint n, k, le;\n readf( \"%s %s %s\", &n, &k, &le );\n readln;\n auto a = readln.split.map!(to!int).array;\n a.sort();\n \n auto overLimit = Array!uint();\n ulong ans = 0;\n for ( int i = 0; i < n*k; i += k ) {\n ans += a[ i ];\n if ( a[ 0 ] + le < a[ i ] ) overLimit ~= a[ i ];\n debug { writeln(i); }\n }\n \n auto candidates = Array!uint();\n for ( int i = 0; i < n*k && a[ i ] <= a[ 0 ] + le; ++i ) {\n if ( i % k == 0 ) continue;\n \n candidates ~= a[ i ];\n }\n \n debug { writeln(a); writeln(ans); writeln(overLimit.array); writeln(candidates.array); }\n \n while ( !overLimit.empty() ) {\n if ( candidates.empty() ) {\n writeln( 0 );\n return;\n }\n \n ans -= overLimit.back - candidates.back;\n overLimit.removeBack();\n candidates.removeBack();\n }\n \n writeln ( ans );\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\nimport std.bigint;\n\nvoid main()\n{\n\tint n, k, l;\n\treadln.chomp.split.tie(n, k, l);\n\tlong[] a = readln.chomp.split.map!(to!long).array;\n\talias Tree = RedBlackTree!(long, \"a < b\", true);\n\tTree left = new Tree();\n\tTree right = new Tree();\n\tlong target = a.reduce!min;\n\tforeach (i, v; a) {\n\t\tif (v <= target + l) {\n\t\t\tleft.insert(v);\n\t\t} else {\n\t\t\tright.insert(v);\n\t\t}\n\t}\n\tdebug verbose(left);\n\tdebug verbose(right);\n\tbool ok = true;\n\tlong sum = 0;\n\twhile (right.length) {\n\t\tif (left.length == 0) {\n\t\t\tok = false;\n\t\t\tbreak;\n\t\t}\n\t\tint t = 0;\n\t\tfor (;t < k - 1 && right.length > 0;) {\n\t\t\tright.removeBack;\n\t\t\t++t;\n\t\t}\n\t\tlong v = left.back;\n\t\tfor (;t < k && left.length > 0;) {\n\t\t\tv = left.back;\n\t\t\tleft.removeBack;\n\t\t\t++t;\n\t\t}\n\t\tif (t < k) {\n\t\t\tok = false;\n\t\t\tbreak;\n\t\t}\n\t\tsum += v;\n\t}\n\twhile (left.length) {\n\t\tint t = 0;\n\t\tlong v = left.back;\n\t\tfor (;t < k && left.length > 0;) {\n\t\t\tv = left.back;\n\t\t\tleft.removeBack;\n\t\t\t++t;\n\t\t}\n\t\tif (t < k) {\n\t\t\tok = false;\n\t\t\tbreak;\n\t\t}\n\t\tsum += v;\n\t}\n\tif (ok) {\n\t\tsum.writeln;\n\t} else {\n\t\t0.writeln;\n\t}\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\nimport std.bigint;\n\nvoid main()\n{\n\tint n, k, l;\n\treadln.chomp.split.tie(n, k, l);\n\tlong[] a = readln.chomp.split.map!(to!long).array;\n\talias Tree = RedBlackTree!(long, \"a < b\", true);\n\tTree left = new Tree();\n\tTree right = new Tree();\n\tlong target = a.reduce!min;\n\tforeach (i, v; a) {\n\t\tif (v <= target + l) {\n\t\t\tleft.insert(v);\n\t\t} else {\n\t\t\tright.insert(v);\n\t\t}\n\t}\n\tdebug verbose(left);\n\tdebug verbose(right);\n\tbool ok = true;\n\tlong sum = 0;\n\twhile (right.length) {\n\t\tif (left.length == 0) {\n\t\t\tok = false;\n\t\t\tbreak;\n\t\t}\n\t\tint t = 0;\n\t\tfor (;t < k - 1 && right.length > 0;) {\n\t\t\tright.removeBack;\n\t\t\t++t;\n\t\t}\n\t\tlong v = left.back;\n\t\tfor (;t < k && left.length > 0;) {\n\t\t\tv = left.back;\n\t\t\tleft.removeBack;\n\t\t\t++t;\n\t\t}\n\t\tif (t < k) {\n\t\t\tok = false;\n\t\t\tbreak;\n\t\t}\n\t\tsum += v;\n\t}\n\twhile (left.length) {\n\t\tint t = 0;\n\t\tlong v = left.back;\n\t\tfor (;t < k && left.length > 0;) {\n\t\t\tv = left.back;\n\t\t\tleft.removeBack;\n\t\t\t++t;\n\t\t}\n\t\tif (t < k) {\n\t\t\tok = false;\n\t\t\tbreak;\n\t\t}\n\t\tsum += v;\n\t}\n\tif (ok) {\n\t\tsum.writeln;\n\t} else {\n\t\t0.writeln;\n\t}\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}], "negative_code": [], "src_uid": "d40fcaf3e305910f66fec02f5507c327"} {"source_code": "import std.algorithm;\nimport std.container.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main() {\n int n;\n readf(\"%d \", &n);\n auto a = readln().split().map!(to!int)().array();\n int[int] d, first, last;\n foreach (i, x; a) {\n d[x]++;\n if (x !in first)\n first[x] = i;\n last[x] = i;\n }\n Array!int keys;\n int result = 0;\n foreach (k, v; d)\n if (v > result) {\n keys.clear();\n keys ~= k;\n result = v;\n } else if (v == result)\n keys ~= k;\n int resX, resY;\n result = n;\n foreach (k; keys) {\n int x = first[k], y = last[k];\n if (y - x < result) {\n resX = x;\n resY = y;\n result = y - x;\n }\n }\n writeln(resX + 1, ' ', resY + 1);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.typecons;\n\nvoid main() {\n int n = readln().strip().to!int;\n int[] a = readln().split().map!(to!int).array;\n int[int] l, r, ct;\n foreach(int i, v; a) {\n if (v in l) {\n l[v] = min(l[v] ,i);\n r[v] = max(r[v] ,i);\n ct[v]++;\n } else {\n l[v] = i;\n r[v] = i;\n ct[v] = 1;\n }\n }\n int[] max_ks;\n int max_v = 0;\n foreach(k, v; ct) {\n if (max_v < v) {\n max_ks.length = 0;\n max_v = v;\n }\n if (max_v == v) {\n max_ks ~= k;\n }\n }\n int min_len = n + 1, min_k;\n foreach(k; max_ks) {\n if (r[k] - l[k] + 1 < min_len) {\n min_len = r[k] - l[k] + 1;\n min_k = k;\n }\n }\n writeln(l[min_k] + 1, ' ', r[min_k] + 1);\n}\n"}], "negative_code": [], "src_uid": "ecd9bbc05b97f3cd43017dd0eddd014d"} {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\n\nvoid main() {\n int n, w ;\n scanf(\"%d %d\\n\", &n, &w);\n int[] a = readln().split().map!(to!int).array;\n a.sort();\n real cap = min(real(a[0]), a[n] / 2.0);\n writefln(\"%.10f\", min(real(w), cap * n + 2 * cap * n));\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main() {\n int n, w;\n readf(\"%d %d\\n\", &n, &w);\n\n int[] a = readln.chomp.split.map!(to!int).array.sort;\n\n int woman_min = a[0];\n int man_min = a[n];\n\n double base = 0.0;\n if (woman_min * 2 > man_min) {\n base = man_min / 2.0;\n } else {\n base = cast(double)woman_min;\n }\n\n double whole = base * 3 * n;\n\n if (whole <= w) {\n writefln(\"%.10f\", base * 3 * n);\n } else {\n writeln(w);\n }\n}"}], "negative_code": [], "src_uid": "b2031a328d72b464f965b4789fd35b93"} {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n int n, l, r;\n scanf(\"%d %d %d\", &n, &l, &r);\n l = l - 1; r = r - 1;\n int [] a = new int[n];\n for (int i = 0; i < n; i++)\n scanf(\"%d\", &a[i]);\n int [] b = new int[n];\n for (int i = 0; i < n; i++)\n scanf(\"%d\", &b[i]);\n int ok = 0;\n for (int i = 0; i < n; i++)\n if ((i < l || i > r) && a[i] != b[i])\n ok = ok + 1;\n if (ok == 0)\n printf(\"TRUTH\");\n else\n printf(\"LIE\");\n\treturn 0;\n}", "positive_code": [{"source_code": "\ufeffmodule main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k,l,r;\n\tscanf(\"%d %d %d\", &n, &l,&r);\n\tint [] arr = new int[n];\n\tint [] arr2 =new int[n];\n\tint[] arr3 = new int[n];\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr3[i]);\n\tint q;\n\tbool ok=0;\n\tfor(int i = 0; i<l-1; i++)\n\t if(arr3[i]!=arr[i])\n\t {\n\t printf(\"LIE\");\n\t return 0;\n\t }\n for(int i = r; i<n; i++)\n\t if(arr3[i]!=arr[i])\n\t {\n\t printf(\"LIE\");\n\t return 0;\n\t }\n\t \n\tprintf(\"TRUTH\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,l,r, y = 0;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tl--;\n\tr--;\n\tint [] arr = new int[n];\n\tint [] arr2 = new int[n];\n\tint [] arr3 = new int[n];\n\tint [] arr4 = new int[n];\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tfor(int i = 0; i<n; i++)\n\t scanf(\"%d\", &arr2[i]);\n\tint q;\n\tfor(int i = 0; i<n; i++)\n\t\tif((i < l || i > r) && arr[i] != arr2[i]) y = 1;\n\tfor(int i = 0; i<n; i++)\n\t if(i >= l && i <= r) arr3[arr[i]]++, arr4[arr2[i]]++;\n\tfor(int i = 0; i<n; i++)\n\t if(arr3[i] != arr4[i]) y = 1;\n\tif (y == 1) printf(\"LIE\");\n\telse printf(\"TRUTH\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,l,r;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tl--;\n\tr--;\n\tint [] arr = new int[n];\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tint q;\n\tfor(int i = 0; i<n; i++)\n\t{\n\t scanf(\"%d\", &q);\n\t if(q != arr[i] && (i < l || i > r))\n\t {\n\t printf(\"LIE\");\n\t return 0;\n\t }\n\t}\n\tprintf(\"TRUTH\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint main(string[] argv) {\n\tint n, L, R;\n\tscanf(\"%d %d %d\", &n, &L, &R);\n\n\tint [] arr = new int[1 + n];\n\tfor (int i = 1; i <= n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tint [] arr2 = new int[1 + n];\n\tfor (int i = 1; i <= n; i++)\n\t\tscanf(\"%d\", &arr2[i]);\n\t\t\n\tint len = R - L + 1;\n\tint [] a = new int[len];\n\tint [] b = new int[len];\n\n\tint j = 0;\n\tfor (int i = L; i <= R; ++i) {\n\t\ta[j] = arr[i];\n\t\tb[j] = arr2[i];\n\t\tj++;\n\t}\n\n\tsort(a);\n\tsort(b);\n\n\tint q = 1;\n\tfor (int i = 0; i < len; ++i) {\n\t\tif (a[i] != b[i]) {\n\t\t\tq = 0;\n\t\t}\n\t}\n\t\n\tfor (int i = 1; i <= L - 1; ++i) {\n\t\tif (arr[i] != arr2[i]) {\n\t\t\tq = 0;\n\t\t}\n\t}\n\t\n\tfor (int i = R + 1; i <= n; ++i) {\n\t\tif (arr[i] != arr2[i]) {\n\t\t\tq = 0;\n\t\t}\n\t}\n\n\tif (q == 1)\n\t\tprintf(\"TRUTH\");\n\telse\n\t\tprintf(\"LIE\");\n\t\n\treturn 0;\n}"}, {"source_code": "\ufeffmodule main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,l,r;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tint [] current = new int[n];\n\tint [] was = new int[n];\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &was[i]);\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", ¤t[i]);\n\tbool outside = true;\n\tfor(int i = 0; i<l - 1; i++){\n\t outside &= (was[i] == current[i]);\n }\n\tfor(int i = r; i<n; i++){\n\t outside &= (was[i] == current[i]);\n\t}\n\tbool inside = true;\n\tint [] counts = new int[n];\n\tfor(int i = l - 1; i<r; i++){\n\t counts[was[i]]++;\n\t counts[current[i]]--;\n\t}\n\tint cnt = 0;\n\tfor(int i = 0; i<n; i++){\n\t inside &= (counts[i] == 0);\n\t}\n\tif (inside && outside)\n\t printf(\"TRUTH\");\n\telse\n\t printf(\"LIE\");\n\treturn 0;\n}"}, {"source_code": "\ufeffmodule main;\n\nimport std.c.stdio;\nimport std.algorithm.sorting;\n\nint main(string[] argv)\n{\n\tint n,l,r;\n\tbool flag;\n\tflag = 1;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tint [] a = new int[n];\n\tint [] b = new int[n];\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &a[i]);\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &b[i]);\n\tfor(int i = 0; i<l - 1; i++)\n\t if (flag && a[i] != b[i])\n\t flag = 0;\n\tfor(int i = r; i<n; i++)\n\t if (flag && a[i] != b[i])\n\t flag = 0;\n a.sort();\n b.sort();\n\tfor(int i = 0; i<n; i++)\n\t if (flag && a[i] != b[i])\n\t flag = 0;\n if (flag)\n printf(\"TRUTH\");\n else\n printf(\"LIE\");\n\treturn 0;\n}"}, {"source_code": "\ufeffmodule main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,l, r;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tint [] arr = new int[n];\n\tl = l - 1;\n\tr = r - 1;\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tbool ans = true;\n\tint j;\n\tfor (int i = 0; i < n; i++) {\n\t scanf(\"%d\", &j);\n\t if (i < l || i > r) \n\t if (j != arr[i]) \n\t ans = false;\n\t}\n\tif (ans) printf(\"TRUTH\");\n\telse printf(\"LIE\");\n\treturn 0;\n}"}, {"source_code": "import std.stdio : writeln, stdin;\n\nimport std.c.stdio;\n\nint[] a = new int[111111];\n\nvoid main()\n{ \n int n, l, r;\n scanf(\"%d\", &n);\n scanf(\"%d\", &l);\n scanf(\"%d\", &r);\n int i;\n for (i = 0; i < n; ++i) {\n scanf(\"%d\", &a[i]);\n }\n int x;\n for (i = 0; i < n; ++i) {\n scanf(\"%d\", &x);\n if ((i + 1 >= l) && (i + 1 <= r)) {\n continue;\n }\n if (a[i] != x) {\n writeln(\"LIE\");\n return;\n }\n }\n writeln(\"TRUTH\");\n}\n"}, {"source_code": "module main;\n\nimport std.stdio : writeln, stdin;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n, l, r;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tl = l - 1;\n\tr = r - 1;\n\tint [] arr = new int[n];\n\tint [] b = new int[n];\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tfor (int i = 0; i < n; i++)\n\t scanf(\"%d\", &b[i]);\n\tfor (int i = 0; i < l; i++) {\n\t if (arr[i] != b[i]) {\n\t writeln(\"LIE\");\n\t return 0;\n\t }\n\t}\n\tfor (int i = r + 1; i < n; i++) {\n \tif (arr[i] != b[i]) {\n \t writeln(\"LIE\");\n \t return 0;\n \t }\n }\n\twriteln(\"TRUTH\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k,l,r;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tint [] arr = new int[n];\n\tint [] arr2 = new int[n];\n\tint [] mk = new int[n+1];\n\tfor(int i = 0; i<n; i++) scanf(\"%d\", &arr[i]);\n\tfor(int i = 0; i<n; i++) scanf(\"%d\", &arr2[i]);\n// \tfor(int i = 0; i<n; i++) printf(\"%d \", arr[i]);\n\tfor(int i = 0; i <= n; i++) mk[i] = 0;\n\tfor(int i = l; i <= r; i++){\n\t mk[arr[i-1]]++;\n\t mk[arr2[i-1]]--;\n\t}\n\tfor(int e = 0; e <=n; e++){\n\t if(mk[e] != 0){\n\t printf(\"LIE\\n\");\n\t return 0;\n\t }\n\t }\n\tfor(int e = 0; e < n; e++){\n\t if(l <= e+1 && e+1 <= r) continue;\n\t if(arr[e] != arr2[e]){\n\t printf(\"LIE\\n\");\n\t return 0;\n\t }\n\t}\n\t printf(\"TRUTH\\n\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n int a,b,c;\n scanf(\"%d %d %d\",&a,&b,&c);\n int[] vasha = new int[a+1];\n int[] vashab = new int[a+1];\n for(int i = 1; i <= a; i++)\n {\n scanf(\"%d\",&vasha[i]);\n }\n for(int i = 1; i <= a; i++)\n {\n scanf(\"%d\",&vashab[i]);\n }\n \n for(int i = 1; i <= a; i++)\n {\n if(i<b||i>c){\n if(vasha[i]!=vashab[i]){\n printf(\"LIE\");\n return 0;\n }\n }\n }\n \n printf(\"TRUTH\");\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,l,r;\n\tscanf(\"%d %d %d\", &n, &l,&r);\n\tl-=1;\n\tr-=1;\n\tint [] arr = new int[n];\n\tint [] arr2=new int[n];\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tfor(int i = 0; i<n; i++)\n\t\tscanf(\"%d\", &arr2[i]);\n\tfor(int i=0;i<n;i++){\n\t if(i<l || i>r){\n\t if(arr[i]!=arr2[i]){\n\t printf(\"LIE\");\n\t return 0;\n\t }\n\t }\n\t}\n\tprintf(\"TRUTH\");\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\nint main() {\n int a[123456];\n int b[123456];\n int n, l, r;\n readf(\" %d %d %d\", &n, &l, &r);\n for (int i = 1; i <= n; i++) {\n readf(\" %d\", &a[i]);\n }\n for (int i = 1; i <= n; i++) {\n readf(\" %d\", &b[i]);\n }\n int ans = 0;\n for (int i = 1; i < l; i++) {\n if (a[i] != b[i]) {\n ans = 1;\n }\n }\n for (int i = r + 1; i <= n; i++) {\n if (a[i] != b[i]) {\n ans = 1;\n }\n }\n if (ans) {\n writeln(\"LIE\");\n } else {\n writeln(\"TRUTH\");\n }\n return 0;\n}\n"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,l,r;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tint [] a = new int[n+5];\n\tint [] b = new int[n+5];\n\tint [] f = new int[n+5];\n\tfor(int i = 1; i<=n; i++)\n\t\tscanf(\"%d\", &a[i]);\n\tfor(int i = 1; i<=n; i++)\n\t\tscanf(\"%d\", &b[i]);\n\tfor (int i=1; i<l; i++) {\n\t if (a[i]!=b[i]) {\n\t printf(\"LIE\\n\");\n\t return 0;\n\t }\n\t}\n\tfor (int i=r+1; i<=n; i++) {\n\t if (a[i]!=b[i]) {\n\t printf(\"LIE\\n\");\n\t return 0;\n\t }\n\t}\n\tfor (int i=l; i<=r; i++) f[a[i]]++;\n\tfor (int i=l; i<=r; i++) f[b[i]]--;\n\tfor (int i=1; i<=n; i++) if (f[i]!=0) {\n\tprintf(\"LIE\\n\");\n\treturn 0;\n\t}\n\tprintf(\"TRUTH\\n\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm.sorting;\n\nint main(string[] argv)\n{\n int n, l, r;\n scanf(\"%d %d %d\", &n, &l, &r);\n int [] a = new int[n];\n int [] b = new int[n];\n int [] aa = new int[r-l+1];\n int [] bb = new int[r-l+1];\n for(int i = 0; i<n; i++)\n scanf(\"%d\", &a[i]);\n for(int i = 0; i<n; i++)\n scanf(\"%d\", &b[i]);\n bool ok = 1;\n for (int i = 0; i < l-1; i++)\n if (a[i] != b[i])\n ok = 0;\n for (int i = r; i < n; i++)\n if (a[i] != b[i])\n ok = 0;\n for (int i = l; i <= r; i++) {\n aa[i-l] = a[i-1];\n bb[i-l] = b[i-1];\n }\n aa.sort();\n bb.sort();\n for (int i = 0; i < r-l+1; i++)\n if (aa[i] != bb[i])\n ok = 0;\n if (ok)\n printf(\"TRUTH\");\n else\n printf(\"LIE\");\n return 0;\n}"}, {"source_code": "import std.stdio;\nint a[4000000];\nint b[4000000];\n\nint n, l, r;\nint main() {\n\treadf(\"%s %s %s\\n\", &n, &l, &r);\n\tfor (int i = 1; i < n; i++) readf(\"%s \", &a[i]);\n\treadf(\"%s\\n\", &a[n]);\n\tfor (int i = 1; i < n; i++) readf(\"%s \", &b[i]);\n\treadf(\"%s\", &b[n]);\n\n\tfor (int i = 1;i <= l - 1; i++) if (a[i] != b[i]) {\n\t\twrite(\"LIE\");\n\t\treturn 0;\n\t}\n\tfor (int i = r + 1; i <= n; i++) if (a[i] != b[i]) {\n\t\twrite(\"LIE\");\n\t\treturn 0;\n\t}\n\twrite(\"TRUTH\");\n\n\treturn 0;\n}"}, {"source_code": "\ufeffmodule main;\n\nimport std.c.stdio;\n\n\nint main(string[] argv)\n{\n int n,l,r;\n scanf(\"%d%d%d\",&n,&l,&r);\n l--;r--;\n int [] a = new int[n];\n for (int i=0;i<n;i++)\n scanf(\"%d\",&a[i]);\n int [] b = new int[n];\n for (int i=0;i<n;i++)\n scanf(\"%d\",&b[i]);\n int [] m = new int[n+1];\n for (int i=l;i<=r;i++){\n m[a[i]]++;\n m[b[i]]--;\n }\n for (int i=0;i<=n;i++){\n if (m[i]!=0){\n printf(\"LIE\");\n return 0;\n }\n }\n for (int i=0;i<l;i++){\n if (a[i]!=b[i]){\n printf(\"LIE\");\n return 0;\n }\n }\n for (int i=r+1;i<n;i++){\n if (a[i]!=b[i]){\n printf(\"LIE\");\n return 0;\n }\n }\n printf(\"TRUTH\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio;\nimport std.algorithm.sorting;\n\nint main(string[] argv)\n{\n\tint n, l, r;\n\tbool ans = true;\n\t\n\tscanf(\"%d%d%d\", &n, &l, &r);\n\tint [] a = new int[n];\n\tint [] b = new int[n];\n\tfor(int i = 0; i < n; i++) scanf(\"%d\", &a[i]);\n\tfor(int i = 0; i < n; i++) scanf(\"%d\", &b[i]);\n\ta[l-1..r].sort();\n\tb[l-1..r].sort();\n\tfor(int i = 0; i < n; i++) if(a[i] != b[i]) ans = false;\n\t\n\tif(ans)\n\t printf(\"TRUTH\");\n\telse\n\t printf(\"LIE\");\n\t\n\treturn 0;\n}"}], "negative_code": [{"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint main(string[] argv) {\n\tint n, L, R;\n\tscanf(\"%d %d %d\", &n, &L, &R);\n\n\tint [] arr = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tint [] arr2 = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t\tscanf(\"%d\", &arr2[i]);\n\n\tint len = R - L + 1;\n\tint [] a = new int[len];\n\tint [] b = new int[len];\n\n\tint j = 0;\n\tfor (int i = L - 1; i < R; ++i) {\n\t\ta[j] = arr[i];\n\t\tb[j] = arr2[i];\n\t\tj++;\n\t}\n\n\tsort(a);\n\tsort(b);\n\n\tint q = 1;\n\tfor (int i = 0; i < len; ++i) {\n\t\tif (a[i] != b[i]) {\n\t\t\tq = 0;\n\t\t}\n\t}\n\n\tif (q == 1)\n\t\tprintf(\"TRUTH\");\n\telse\n\t\tprintf(\"LIE\");\n\t\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint main(string[] argv) {\n\tint n, L, R;\n\tscanf(\"%d %d %d\", &n, &L, &R);\n\n\tint [] arr = new int[1 + n];\n\tfor (int i = 1; i <= n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tint [] arr2 = new int[1 + n];\n\tfor (int i = 1; i <= n; i++)\n\t\tscanf(\"%d\", &arr2[i]);\n\n\tint len = R - L + 1;\n\tint [] a = new int[len];\n\tint [] b = new int[len];\n\n\tint j = 0;\n\tfor (int i = L; i <= R; ++i) {\n\t\ta[j] = arr[i];\n\t\tb[j] = arr2[i];\n\t\tj++;\n\t}\n\n\tsort(a);\n\tsort(b);\n\n\tint q = 1;\n\tfor (int i = 0; i < len; ++i) {\n\t\tif (a[i] != b[i]) {\n\t\t\tq = 0;\n\t\t}\n\t}\n\n\tfor (int i = 1; i < L; ++i) {\n\t\tif (a[i] != b[i]) {\n\t\t\tq = 0;\n\t\t}\n\t}\n\n\tfor (int i = R + 1; i <= n; ++i) {\n\t\tif (a[i] != b[i]) {\n\t\t\tq = 0;\n\t\t}\n\t}\n\n\tif (q == 1)\n\t\tprintf(\"TRUTH\");\n\telse\n\t\tprintf(\"LIE\");\n\t\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint main(string[] argv) {\n\tint n, L, R;\n\tscanf(\"%d %d %d\", &n, &L, &R);\n\n\tint [] arr = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t\tscanf(\"%d\", &arr[i]);\n\tint [] arr2 = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t\tscanf(\"%d\", &arr2[i]);\n\t\t\n\tint len = R - L + 1;\n\tint [] a = new int[len];\n\tint [] b = new int[len];\n\n\tint j = 0;\n\tfor (int i = L - 1; i < R; ++i) {\n\t\ta[j] = arr[i];\n\t\tb[j] = arr2[i];\n\t\tj++;\n\t}\n\n\tsort(a);\n\tsort(b);\n\n\tint q = 1;\n\tfor (int i = 0; i < len; ++i) {\n\t\tif (a[i] != b[i]) {\n\t\t\tq = 0;\n\t\t}\n\t}\n\n\tif (q == 1)\n\t\tprintf(\"TRUTH\");\n\telse\n\t\tprintf(\"LIE\");\n\t\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k,l,r;\n\tscanf(\"%d %d\", &n, &l, &r);\n\tint [] arr = new int[n];\n\tint [] arr2 = new int[n];\n\tint [] mk = new int[n+1];\n\tfor(int i = 0; i<n; i++) scanf(\"%d\", &arr[i]);\n\tfor(int i = 0; i<n; i++) scanf(\"%d\", &arr2[i]);\n\tfor(int i = l; i <= r; i++){\n\t mk[arr[i-1]]++;\n\t mk[arr2[i-1]]--;\n\t}\n\tfor(int e = 0; e <=n; e++){\n\t if(mk[e] != 0){\n\t printf(\"LIE\\n\");\n\t return 0;\n\t }\n\t }\n\t printf(\"TRUTH\\n\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k,l,r;\n\tscanf(\"%d %d %d\", &n, &l, &r);\n\tint [] arr = new int[n];\n\tint [] arr2 = new int[n];\n\tint [] mk = new int[n+1];\n\tfor(int i = 0; i<n; i++) scanf(\"%d\", &arr[i]);\n\tfor(int i = 0; i<n; i++) scanf(\"%d\", &arr2[i]);\n// \tfor(int i = 0; i<n; i++) printf(\"%d \", arr[i]);\n\tfor(int i = 0; i <= n; i++) mk[i] = 0;\n\tfor(int i = l; i <= r; i++){\n\t mk[arr[i-1]]++;\n\t mk[arr2[i-1]]--;\n\t}\n\tfor(int e = 0; e <=n; e++){\n\t if(mk[e] != 0){\n\t printf(\"LIE\\n\");\n\t return 0;\n\t }\n\t }\n\t printf(\"TRUTH\\n\");\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio;\nimport std.algorithm.sorting;\n\nint main(string[] argv)\n{\n\tint n, l, r;\n\tbool ans = true;\n\t\n\tscanf(\"%d%d%d\", &n, &l, &r);\n\tint [] a = new int[r - l + 1];\n\tint [] b = new int[r - l + 1];\n\tfor(int i = 1; i <= n; i++)\n\t{\n\t int t;\n\t\tscanf(\"%d\", &t);\n\t\tif(i < l || i > r) continue;\n\t\ta[i - l] = t;\n\t}\n\tfor(int i = 1; i <= n; i++)\n\t{\n\t int t;\n\t\tscanf(\"%d\", &t);\n\t\tif(i < l || i > r) continue;\n\t\tb[i - l] = t;\n\t}\n\ta.sort();\n\tb.sort();\n\tfor(int i = 0; i < r - l + 1; i++)\n\tif(a[i] != b[i]) ans = false;\n\t\n\tif(ans)\n\t printf(\"TRUTH\");\n\telse\n\t printf(\"LIE\");\n\t\n\treturn 0;\n}"}], "src_uid": "1951bf085050c7e32fcf713132b30605"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m, s;\n rd(n, m, s);\n s--;\n auto g = new int[][](n);\n foreach (_; 0 .. m) {\n int u, v;\n rd(u, v);\n g[u - 1] ~= (v - 1);\n }\n\n auto canReach = new bool[][](n, n);\n void dfs(int i, bool[] seen) {\n if (seen[i]) {\n return;\n }\n seen[i] = true;\n foreach (j; g[i]) {\n dfs(j, seen);\n }\n }\n\n foreach (i; 0 .. n) {\n dfs(i, canReach[i]);\n }\n auto root = new int[](n);\n fill(root, -1);\n int nn = 0;\n foreach (i; 0 .. n) {\n if (root[i] < 0) {\n root[i] = nn++;\n }\n foreach (j; 0 .. n) {\n if (canReach[i][j] && canReach[j][i]) {\n root[j] = root[i];\n }\n }\n }\n auto h = new int[][](nn);\n foreach (i; 0 .. n) {\n foreach (j; g[i]) {\n if (root[i] != root[j]) {\n h[root[i]] ~= root[j];\n }\n }\n }\n auto deg_in = new int[](nn);\n foreach (i; 0 .. nn) {\n foreach (j; h[i]) {\n deg_in[j]++;\n }\n }\n int ans = 0;\n foreach (i; 0 .. nn) {\n if (root[s] != i && deg_in[i] == 0) {\n ans++;\n }\n }\n writeln(ans);\n\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, s;\n readf(\"%s %s %s\", &n, &m, &s);\n readln;\n\n auto g = new int[][] (n+1);\n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n }\n \n immutable int INF = 10 ^^ 9 + 7;\n \n auto disc = new int[] (n+1);\n auto lo = new int[] (n+1);\n auto clr = new int[] (n+1);\n int[] stk;\n disc[] = 0;\n lo[] = INF;\n clr[] = 0;\n int nclr = 1;\n int t = 1;\n \n void dfs(int v) {\n disc[v] = t++;\n lo[v] = disc[v];\n stk ~= v;\n foreach (u; g[v]) {\n if (disc[u] == 0) {\n dfs(u);\n lo[v] = min(lo[v], lo[u]);\n } else if (clr[u] == 0) {\n lo[v] = min(lo[v], lo[u]);\n }\n }\n \n if (disc[v] == lo[v]) {\n while (stk.back != v) {\n auto u = stk.back;\n stk.popBack();\n clr[u] = nclr;\n }\n \n stk.popBack();\n clr[v] = nclr;\n \n ++nclr;\n }\n }\n \n foreach (i; 1 .. n+1) {\n if (disc[i] == 0) {\n dfs(i);\n }\n }\n \n debug { clr.writeln; }\n \n auto ng = new int[][] (nclr);\n foreach (v; 1 .. n+1) {\n foreach (u; g[v]) {\n if (clr[v] != clr[u]) {\n ng[clr[v]] ~= clr[u];\n }\n }\n }\n \n foreach (v; 1 .. nclr) {\n ng[v] = ng[v].sort().uniq().array;\n }\n \n debug { ng.writeln; }\n \n auto isRoot = new bool[] (nclr);\n isRoot[] = true;\n \n foreach (adj; ng) {\n foreach (u; adj) { isRoot[u] = false; }\n }\n \n auto ans = isRoot.dropOne.count!(x => x).to!int - (isRoot[clr[s]] ? 1 : 0);\n ans.writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, s;\n readf(\"%s %s %s\", &n, &m, &s);\n readln;\n\n auto g = new int[][] (n+1);\n auto isIn = new bool[] (n+1);\n isIn[] = false;\n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n isIn[v] = true;\n }\n \n auto vis = new bool[] (n+1);\n vis[] = false;\n void dfs(int v) {\n vis[v] = true;\n foreach (u; g[v]) {\n if (!vis[u]) { dfs(u); }\n }\n }\n \n dfs(s);\n \n int ans = 0;\n foreach (v; 1 .. n+1) {\n if (vis[v]) { continue; }\n if (!isIn[v]) { \n ++ans;\n dfs(v);\n }\n }\n \n foreach (v; 1 .. n+1) {\n if (vis[v]) { continue; }\n \n ++ans;\n dfs(v);\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, s;\n readf(\"%s %s %s\", &n, &m, &s);\n readln;\n\n auto g = new int[][] (n+1);\n auto isRoot = new bool[] (n+1);\n isRoot[] = true;\n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n g[u] ~= v;\n isRoot[v] = false;\n }\n \n auto vis = new bool[] (n+1);\n vis[] = false;\n void dfs(int v) {\n vis[v] = true;\n foreach (u; g[v]) {\n if (!vis[u]) { dfs(u); }\n }\n }\n \n dfs(s);\n \n int ans = 0;\n foreach (v; 1 .. n+1) {\n if (vis[v]) { continue; }\n if (isRoot[v]) { \n ++ans;\n dfs(v);\n }\n }\n \n foreach (v; 1 .. n+1) {\n if (vis[v]) { continue; }\n \n ++ans;\n dfs(v);\n }\n \n ans.writeln;\n}"}], "src_uid": "c02922c33eb816eea872b4d8a3c1dc0e"} {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.typecons;\n\nvoid main() {\n alias Pt = Tuple!(int, \"x\", int, \"y\");\n int n;\n scanf(\"%d\", &n);\n Pt[] ps = new Pt[n];\n foreach (i; 0..n) {\n scanf(\"%d%d\", &ps[i].x, &ps[i].y);\n }\n long ans = 0;\n foreach (p; ps) {\n real[] a;\n foreach (q; ps) {\n if (p == q) continue;\n Pt d = Pt(q.x - p.x, q.y - p.y);\n real v = atan2(real(d.x), real(d.y));\n while (v < 1e-9) v += PI;\n a ~= v;\n }\n int m = cast(int)a.length;\n a.sort();\n int i = 0, j = 0;\n while (i < m && j < m) {\n while (i < m && abs(a[i] - a[j]) < 1e-9) {\n i++;\n }\n ans += max(0, (m - (i - j)) * (i - j));\n j = i;\n i = j;\n }\n }\n writeln(ans / 6);\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n Tuple!(int, int)[] arr;\n foreach (_; 0 .. n) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n arr ~= tuple(a, b);\n }\n \n int [int][int] cnt;\n long subcnt = 0;\n foreach (i; 0 .. n) {\n cnt.clear();\n int x1 = arr[i][0], y1 = arr[i][1];\n foreach (j; i+1 .. n) {\n int x2 = arr[j][0], y2 = arr[j][1];\n \n int xd = x2 - x1, yd = y2 - y1;\n int g = gcd(abs(xd), abs(yd));\n xd /= g, yd /= g;\n if (xd < 0 || (xd == 0 && yd < 0)) { \n xd *= -1;\n yd *= -1;\n }\n \n if (xd in cnt) {\n subcnt += cnt[xd].get(yd, 0);\n }\n \n cnt[xd][yd] += 1;\n }\n }\n \n auto ans = n.to!long * (n-1) * (n-2) / 6 - subcnt;\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.typecons;\n\nvoid main() {\n alias Pt = Tuple!(int, \"x\", int, \"y\");\n int n;\n scanf(\"%d\", &n);\n Pt[] ps = new Pt[n];\n foreach (i; 0..n) {\n scanf(\"%d%d\", &ps[i].x, &ps[i].y);\n }\n long ans = 0;\n foreach (p; ps) {\n Pt[] a;\n foreach (q; ps) {\n if (p != q) a ~= q;\n }\n int m = cast(int)a.length;\n bool compare(Pt q, Pt r) {\n Pt dq = Pt(q.x - p.x, q.y - p.y);\n Pt dr = Pt(r.x - p.x, r.y - p.y);\n return atan2(real(dq.x), real(dq.y)) < atan2(real(dr.x), real(dr.y)); \n }\n a.sort!compare();\n int i = 0, j = 0;\n while (i < m && j < m) {\n while (i < m) {\n Pt dq = Pt(a[i].x - p.x, a[i].y - p.y);\n Pt dr = Pt(a[j].x - p.x, a[j].y - p.y);\n if (abs(atan2(real(dq.x), real(dq.y)) - atan2(real(dr.x), real(dr.y))) > 1e-9) break;\n i++;\n }\n ans += m - (i - j);\n j = i + 1;\n i = j;\n }\n }\n writeln(ans / 3);\n}\n"}, {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.typecons;\n\nvoid main() {\n alias Pt = Tuple!(int, \"x\", int, \"y\");\n int n;\n scanf(\"%d\", &n);\n Pt[] ps = new Pt[n];\n foreach (i; 0..n) {\n scanf(\"%d%d\", &ps[i].x, &ps[i].y);\n }\n long ans = 0;\n foreach (p; ps) {\n Pt[] a;\n foreach (q; ps) {\n if (p != q) a ~= q;\n }\n int m = cast(int)a.length;\n bool compare(Pt q, Pt r) {\n Pt dq = Pt(q.x - p.x, q.y - p.y);\n Pt dr = Pt(r.x - p.x, r.y - p.y);\n real v1 = atan2(real(dq.x), real(dq.y));\n real v2 = atan2(real(dr.x), real(dr.y));\n if (abs(v1 + PI / 2) < 1e-9) v1 = PI / 2;\n if (abs(v2 + PI / 2) < 1e-9) v2 = PI / 2;\n return v1 < v2 ; \n }\n a.sort!compare();\n int i = 0, j = 0;\n while (i < m && j < m) {\n while (i < m) {\n Pt dq = Pt(a[i].x - p.x, a[i].y - p.y);\n Pt dr = Pt(a[j].x - p.x, a[j].y - p.y);\n real v1 = atan2(real(dq.x), real(dq.y));\n real v2 = atan2(real(dr.x), real(dr.y));\n if (abs(v1 + PI / 2) < 1e-9) v1 = PI / 2;\n if (abs(v2 + PI / 2) < 1e-9) v2 = PI / 2;\n if (abs(v1 - v2) > 1e-9) break;\n i++;\n }\n ans += m - (i - j);\n j = i + 1;\n i = j;\n }\n }\n writeln(ans / 3);\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n Tuple!(int, int)[] arr;\n foreach (_; 0 .. n) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n arr ~= tuple(a, b);\n }\n \n int [int] cntspec;\n int [double][double] cnt;\n foreach (i; 0 .. n) {\n int x1 = arr[i][0], y1 = arr[i][1];\n foreach (j; i+1 .. n) {\n int x2 = arr[j][0], y2 = arr[j][1];\n \n if (x1 == x2) { cntspec[x1] += 0; }\n else {\n double a = (y2 - y1).to!double / (x2 - x1);\n double b = y1.to!double - a * x1;\n cnt[a][b] += 0;\n }\n }\n }\n \n debug { cnt.writeln; }\n \n foreach (i; 0 .. n) {\n cntspec[arr[i][0]] += 1;\n \n foreach (a; cnt.keys) {\n double b = arr[i][1].to!double - arr[i][0] * a;\n cnt[a][b] += 1;\n }\n }\n \n debug { cnt.writeln; }\n \n auto f = (int x) => x.to!long * (x-1) * (x-2) / 6;\n long ans = f(n);\n \n long linearOpts(int[] vals) {\n return vals.filter!(x => x >= 3).map!f.sum(0L);\n }\n \n ans -= linearOpts(cntspec.values);\n ans -= cnt.values.map!(dct => linearOpts(dct.values)).sum(0L);\n \n ans.writeln;\n}"}], "src_uid": "d5913f8208efa1641f53caaee7624622"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nstruct ModInt {\n static int M;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n ModInt.M = M;\n A.sort;\n \n auto freq = new long[M];\n auto freq2 = new long[M];\n foreach (i; 0 .. N) {\n const a = A[i] % M;\n foreach (x; 0 .. a + 1) {\n freq2[a - x] += freq[x];\n }\n foreach (x; a + 1 .. M) {\n freq2[a - x + M] += freq[x];\n }\n ++freq[a];\n }\n \n ModInt ans = 1;\n foreach (x; 0 .. M) {\n ans *= ModInt(x)^^freq2[x];\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tif (n > m)\n\t\t{\n\t\t\twriteln (0);\n\t\t\tcontinue;\n\t\t}\n\t\tint res = 1;\n\t\tforeach (i, x; a)\n\t\t{\n\t\t\tforeach (j, y; a)\n\t\t\t{\n\t\t\t\tif (i < j)\n\t\t\t\t{\n\t\t\t\t\tres = (res * 1L * abs (y - x)) % m;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.functional;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\npure\nX genericPower(alias mul, X, Y) (X x, Y y, X one = 1.to!X)\n if (isUnsigned!Y) {\n X a = one, b = x;\n while (y > 0) {\n if (y & 1) {\n a = binaryFun!mul (a, b);\n }\n b = binaryFun!mul (b, b);\n y >>>= 1;\n }\n return a;\n}\n\nint test (uint[] a, const int m) {\n sort (a);\n a[] %= m;\n auto d = new ulong[m];\n auto x = new int[m];\n foreach (f, i; a) {\n if (f > 0) {\n int k = i;\n foreach (j; 0 .. m) {\n d[k] += x[j];\n if (--k < 0) k += m;\n }\n }\n ++x[i];\n }\n if (d[0] > 0) return 0;\n debug stderr.writeln (d);\n int mul (int i, int j) {\n return (i * j) % m;\n }\n int res = 1;\n foreach (k; 1 .. m) {\n res = mul (res, genericPower!(mul, int, ulong)(k, d[k]));\n }\n return res;\n}\n\nvoid main() {\n auto r = new InputReader ();\n //immutable nt = r.next!uint ();\n const n = r.next!uint ();\n const m = r.next!uint ();\n auto a = r.nextA!uint (n);\n writeln (test (a, m));\n}\n\n"}], "negative_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.functional;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\npure\nX genericPower(alias mul, X, Y) (X x, Y y, X one = 1.to!X)\n if (isUnsigned!Y) {\n X a = one, b = x;\n while (y > 0) {\n if (y & 1) {\n a = binaryFun!mul (a, b);\n }\n b = binaryFun!mul (b, b);\n y >>>= 1;\n }\n return a;\n}\n\nint test (uint[] a, const int m) {\n sort (a);\n a[] %= m;\n auto d = new ulong[m];\n auto x = new int[m];\n foreach (f, i; a) {\n if (f > 0) {\n int k = i;\n foreach (j; 0 .. m) {\n d[k] += x[j];\n if (--k < 0) k += m;\n }\n }\n ++x[i];\n }\n /*\n auto c = new int[m];\n foreach (x; a) ++c[x % m];\n if (c[0] > 1) return 0;\n auto d = new ulong[m];\n foreach (i; 0 .. m) if (c[i] > 0) {\n foreach (j; 0 .. m) if (c[j] > 0) {\n if (i != j) {\n const int k = (m + i - j) % m;\n d[k] += c[i].to!ulong * c[j];\n }\n }\n }\n */\n debug stderr.writeln (d);\n int mul (int i, int j) {\n return (i * j) % m;\n }\n int res = 1;\n foreach (k; 1 .. m) {\n res = mul (res, genericPower!(mul, int, ulong)(k, d[k]));\n }\n return res;\n}\n\nvoid main() {\n auto r = new InputReader ();\n //immutable nt = r.next!uint ();\n const n = r.next!uint ();\n const m = r.next!uint ();\n auto a = r.nextA!uint (n);\n writeln (test (a, m));\n}\n\n"}], "src_uid": "bf115b24d85a0581e709c012793b248b"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n void subSolve(int n, int[] arr) {\r\n foreach(ref a; arr) {\r\n while(a > n) a /= 2;\r\n }\r\n \r\n auto counts = new int[](n + 1);\r\n foreach(a; arr) {\r\n while(a > 0) {\r\n counts[a]++;\r\n a /= 2;\r\n }\r\n }\r\n\r\n auto used = new bool[](n + 1);\r\n foreach(a; arr) {\r\n int minValue = 0;\r\n int minCounts = int.max;\r\n while(a > 0) {\r\n if (!used[a] && minCounts.chmin(counts[a])) minValue = a;\r\n a /= 2;\r\n }\r\n\r\n if (minValue > 0) used[minValue] = true;\r\n }\r\n\r\n bool ans = used[1..$].count(false) == 0;\r\n writeln(ans ? \"YES\" : \"NO\");\r\n }\r\n\r\n foreach(_; 0..QN) {\r\n auto N = scan!int;\r\n subSolve(N, scan!int(N));\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool can_convert(int from, int to)\n{\n while (from > to) {\n from >>= 1;\n }\n return from == to;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!int).array;\n DList!int l;\n foreach (x ; a)\n l.insertBack(x);\n\n bool good = true;\n\n foreach_reverse (target ; 1 .. n + 1) {\n bool converted = false;\n foreach (i ; 0 .. n) {\n auto x = l.front;\n l.removeFront;\n if (can_convert(x, target)) {\n converted = true;\n break;\n }\n l.insertBack(x);\n }\n if (!converted) {\n good = false;\n break;\n }\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n BigLoop: foreach (test_index; 0 .. tests) {\n immutable n = readln().chomp.to!uint;\n\n size_t[][uint] aa;\n foreach (i, val; readln.chomp.split(' ').to!(uint[])) {\n while (val) {\n aa[val] ~= i;\n val /= 2;\n }\n }\n\n bool[size_t] used;\n\n foreach (val; iota(n, 0, -1)) {\n if (val !in aa) {\n writeln(\"NO\");\n continue BigLoop;\n }\n\n auto r = aa[val].filter!(x => x !in used);\n\n if (r.empty) {\n writeln(\"NO\");\n continue BigLoop;\n }\n used[r.front] = true;\n }\n writeln(\"YES\");\n }\n}\n// \"\"\n"}], "negative_code": [], "src_uid": "645459e0a41ec63b13648ea8dbe0f053"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int NA = -1;\n\nint [] [] g;\nbool [] b;\nint [] p;\n\nbool bipart (int v)\n{\n\tif (b[v])\n\t{\n\t\treturn false;\n\t}\n\tb[v] = true;\n\n\tforeach (c; g[v])\n\t{\n\t\tif (c == NA)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tif (p[c] == NA || bipart (p[c]))\n\t\t{\n\t\t\tp[c] = v;\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto r = new bool [n + 1];\n\t\tauto c = new bool [n + 1];\n\t\tr[] = false;\n\t\tc[] = false;\n\t\tr[2..n] = true;\n\t\tc[2..n] = true;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint cr, cc;\n\t\t\treadf (\" %s %s\", &cr, &cc);\n\t\t\tr[cr] = false;\n\t\t\tc[cc] = false;\n\t\t}\n\t\tint add = 0;\n\t\tif (n & 1)\n\t\t{\n\t\t\tif (r[n / 2 + 1] || c[n / 2 + 1])\n\t\t\t{\n\t\t\t\tadd++;\n\t\t\t\tr[n / 2 + 1] = false;\n\t\t\t\tc[n / 2 + 1] = false;\n\t\t\t}\n\t\t}\n\n\t\tauto rv = new int [] [] (n + 1, 2);\n\t\tauto cv = new int [] [] (n + 1, 2);\n\t\tg = new int [] [n * 4];\n\t\tint k = 0;\n\t\tforeach (i; 2..n)\n\t\t{\n\t\t\tif (r[i])\n\t\t\t{\n\t\t\t\trv[i] = [k, k + 1];\n\t\t\t\tk += 2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\trv[i] = [NA, NA];\n\t\t\t}\n\n\t\t\tif (c[i])\n\t\t\t{\n\t\t\t\tcv[i] = [k, k + 1];\n\t\t\t\tk += 2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcv[i] = [NA, NA];\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (\"k = \", k);}\n\n\t\tint res = 0;\n\t\tint t = 0;\n\t\tforeach (i; 2..n)\n\t\t{\n\t\t\tif (r[i])\n\t\t\t{\n\t\t\t\tg[t] = [t ^ 1, cv[i][0], cv[n - i + 1][1]];\n\t\t\t\tt++;\n\t\t\t\tg[t] = [t ^ 1, cv[i][1], cv[n - i + 1][0]];\n\t\t\t\tt++;\n\t\t\t}\n\t\t\tif (c[i])\n\t\t\t{\n\t\t\t\tg[t] = [t ^ 1, rv[i][0], rv[n - i + 1][1]];\n\t\t\t\tt++;\n\t\t\t\tg[t] = [t ^ 1, rv[i][1], rv[n - i + 1][0]];\n\t\t\t\tt++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tb = new bool [k];\n\t\tp = new int [k];\n\t\tp[] = NA;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tb[] = false;\n\t\t\tif (p[i] == NA && bipart (i))\n\t\t\t{\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\n\t\twriteln (k - res + add);\n\t}\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n, m;\n n = rd!int;\n m = rd!int;\n auto rows = new ll[](n);\n auto cols = new ll[](n);\n rows[n-1] += 2;\n cols[n-1] += 2;\n rows[0] += 2;\n cols[0] += 2;\n foreach(i; 0..m){\n int xi = rd!int - 1;\n int yi = rd!int - 1;\n ++rows[xi];\n ++cols[yi];\n }\n ll cnt = 0, midd = 0;\n foreach(i; 0..n){\n if(!rows[i]) ++cnt;\n if(!cols[i]) ++cnt;\n\n if(i == n/2){\n if(!rows[i]) ++midd;\n if(!cols[i]) ++midd;\n }\n }\n if(n % 2){\n cnt -= midd;\n if(midd) ++cnt;\n }\n writeln(cnt);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tlong n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\twhile (n % 3 == 0)\n\t\t{\n\t\t\tn /= 3;\n\t\t}\n\t\tlong res = n / 3 + 1;\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "a26a97586d4efb5855aa3b930e9effa7"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt(uint M_) {\n import std.conv : to;\n alias M = M_;\n uint x;\n this(ModInt a) { x = a.x; }\n this(uint x_) { x = x_ % M; }\n this(ulong x_) { x = x_ % M; }\n this(int x_) { x = ((x_ %= cast(int)(M)) < 0) ? (x_ + cast(int)(M)) : x_; }\n this(long x_) { x = cast(uint)(((x_ %= cast(long)(M)) < 0) ? (x_ + cast(long)(M)) : x_); }\n ref ModInt opAssign(T)(inout(T) a) if (is(T == uint) || is(T == ulong) || is(T == int) || is(T == long)) { return this = ModInt(a); }\n ref ModInt opOpAssign(string op, T)(T a) {\n static if (is(T == ModInt)) {\n static if (op == \"+\") { x = ((x += a.x) >= M) ? (x - M) : x; }\n else static if (op == \"-\") { x = ((x -= a.x) >= M) ? (x + M) : x; }\n else static if (op == \"*\") { x = cast(uint)((cast(ulong)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n } else static if (op == \"^^\") {\n if (a < 0) return this = inv()^^(-a);\n ModInt b = this, c = 1U;\n for (long e = a; e; e >>= 1) { if (e & 1) c *= b; b *= b; }\n return this = c;\n } else {\n return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n }\n ModInt inv() const {\n uint a = M, b = x; int y = 0, z = 1;\n for (; b; ) { const q = a / b; const c = a - q * b; a = b; b = c; const w = y - cast(int)(q) * z; y = z; z = w; }\n assert(a == 1); return ModInt(y);\n }\n ModInt opUnary(string op)() const {\n static if (op == \"+\") { return this; }\n else static if (op == \"-\") { ModInt a; a.x = x ? (M - x) : 0U; return a; }\n else static assert(false);\n }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op, T)(T a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n bool opCast(T: bool)() const { return (x != 0U); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 998244353;\nalias Mint = ModInt!MO;\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto X = new long[N];\n auto Y = new long[N];\n auto S = new int[N];\n foreach (i; 0 .. N) {\n X[i] = readLong();\n Y[i] = readLong();\n S[i] = readInt();\n }\n \n long[] xs;\n xs ~= X;\n xs ~= Y;\n xs ~= 0;\n xs.sort;\n const xsLen = cast(int)(xs.length);\n xs ~= X[N - 1] + 1;\n \n auto es = new int[N];\n auto fs = new int[N];\n auto ids = new int[xsLen];\n ids[] = -1;\n foreach (i; 0 .. N) {\n es[i] = xs.lowerBound(X[i]);\n fs[i] = xs.lowerBound(Y[i]);\n ids[es[i]] = ids[fs[i]] = i;\n }\n debug {\n writeln(\"xs = \", xs);\n writeln(\"es = \", es);\n writeln(\"fs = \", fs);\n writeln(\"ids = \", ids);\n }\n \n auto ts = new Mint[xsLen];\n ts[xsLen - 1] = 1;\n foreach_reverse (e; 1 .. xsLen) {\n const i = ids[e];\n if (e == es[i]) {\n ts[e - 1] = ts[e] + (ts[e] - (S[i] ? 0 : 1));\n } else {\n ts[e - 1] = ts[e] - (ts[es[i]] - (S[i] ? 0 : 1));\n }\n }\n debug {\n writeln(\"ts = \", ts);\n }\n \n Mint ans;\n foreach (e; 0 .. xsLen) {\n ans += ts[e] * Mint(xs[e + 1] - xs[e]);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int mod = 998_244_353;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\talias Teleport = Tuple !(int, q{x}, int, q{y}, int, q{state});\r\n\t\tauto t = new Teleport [n];\r\n\t\talias Event = Tuple !(int, q{pos}, int, q{num}, int, q{type});\r\n\t\tEvent [] e;\r\n\t\te.reserve (n * 2);\r\n\t\tforeach (int i, ref c; t)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s %s\") (c.x, c.y, c.state);\r\n\t\t\te ~= Event (c.x, i, 0);\r\n\t\t\te ~= Event (c.y, i, 1);\r\n\t\t}\r\n\t\te.schwartzSort !(v => v.pos);\r\n\r\n\t\tauto ptr = new int [2] [n];\r\n\t\tforeach (j; 0..n * 2)\r\n\t\t{\r\n\t\t\tptr[e[j].num][e[j].type] = j;\r\n\t\t}\r\n\r\n\t\tauto r = new int [n * 2 + 1];\r\n\r\n\t\tvoid inc (int pos, int val)\r\n\t\t{\r\n\t\t\tfor (pos += 1; pos <= n * 2; pos += (pos & -pos))\r\n\t\t\t{\r\n\t\t\t\tr[pos] += val - mod;\r\n\t\t\t\tr[pos] += (r[pos] < 0) * mod;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint tot (int pos)\r\n\t\t{\r\n\t\t\tint res = 0;\r\n\t\t\tfor (pos += 1; pos > 0; pos -= (pos & -pos))\r\n\t\t\t{\r\n\t\t\t\tres += r[pos] - mod;\r\n\t\t\t\tres += (res < 0) * mod;\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tint tot2 (int lo, int hi)\r\n\t\tin\r\n\t\t{\r\n\t\t\tdebug {write (lo, \" \", hi);}\r\n\t\t}\r\n\t\tout (res)\r\n\t\t{\r\n\t\t\tdebug {writeln (\": \", res);}\r\n\t\t}\r\n\t\tbody\r\n\t\t{\r\n\t\t\treturn (tot (hi - 1) + mod - tot (lo - 1)) % mod;\r\n\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tint value = (t[i].x - t[i].y) % mod;\r\n\t\t\tvalue = (value + tot2 (ptr[i][1], ptr[i][0])) % mod;\r\n\t\t\tinc (ptr[i][0], value);\r\n\t\t}\r\n\t\tdebug {writeln (r);}\r\n\r\n\t\tint res = (t.back.x + 1) % mod;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (t[i].state)\r\n\t\t\t{\r\n\t\t\t\tauto pos = ptr[i][0];\r\n\t\t\t\tdebug {writeln (i, \": \", tot2 (pos, pos + 1));}\r\n\t\t\t\tres = (res + tot2 (pos, pos + 1)) % mod;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int mod = 998_244_353;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\talias Teleport = Tuple !(int, q{x}, int, q{y}, int, q{state});\r\n\t\tauto t = new Teleport [n];\r\n\t\talias Event = Tuple !(int, q{pos}, int, q{num}, int, q{type});\r\n\t\tEvent [] e;\r\n\t\te.reserve (n * 2);\r\n\t\tforeach (int i, ref c; t)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s %s\") (c.x, c.y, c.state);\r\n\t\t\te ~= Event (c.x, i, 0);\r\n\t\t\te ~= Event (c.y, i, 1);\r\n\t\t}\r\n\t\te.schwartzSort !(v => v.pos);\r\n\r\n\t\tauto ptr = new int [2] [n];\r\n\t\tforeach (j; 0..n * 2)\r\n\t\t{\r\n\t\t\tptr[e[j].num][e[j].type] = j;\r\n\t\t}\r\n\r\n\t\tauto r = new int [n * 2 + 1];\r\n\r\n\t\tvoid inc (int pos, int val)\r\n\t\t{\r\n\t\t\tfor (pos += 1; pos <= n * 2; pos += (pos & -pos))\r\n\t\t\t{\r\n\t\t\t\tr[pos] += val - mod;\r\n\t\t\t\tr[pos] += (r[pos] < 0) * mod;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint tot (int pos)\r\n\t\t{\r\n\t\t\tint res = 0;\r\n\t\t\tfor (pos += 1; pos > 0; pos -= (pos & -pos))\r\n\t\t\t{\r\n\t\t\t\tres += r[pos] - mod;\r\n\t\t\t\tres += (res < 0) * mod;\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tint tot2 (int lo, int hi)\r\n\t\tin\r\n\t\t{\r\n\t\t\tdebug {write (lo, \" \", hi);}\r\n\t\t}\r\n\t\tout (res)\r\n\t\t{\r\n\t\t\tdebug {writeln (\": \", res);}\r\n\t\t}\r\n\t\tbody\r\n\t\t{\r\n\t\t\treturn (tot (hi - 1) + mod - tot (lo - 1)) % mod;\r\n\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tint value = (t[i].x - t[i].y) % mod;\r\n\t\t\tvalue = (value + tot2 (ptr[i][1], ptr[i][0])) % mod;\r\n\t\t\tinc (ptr[i][0], value);\r\n\t\t}\r\n\t\tdebug {writeln (r);}\r\n\r\n\t\tint res = t.back.x + 1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (t[i].state)\r\n\t\t\t{\r\n\t\t\t\tauto pos = ptr[i][0];\r\n\t\t\t\tdebug {writeln (i, \": \", tot2 (pos, pos + 1));}\r\n\t\t\t\tres = (res + tot2 (pos, pos + 1)) % mod;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "src_uid": "6dd3839826320795fa29702331a15744"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n auto B = N.iota.map!(i => tuple(i, A[i])).array;\n\n if (N == 2) {\n writeln(1);\n return;\n }\n\n if (N == 3) {\n writeln(2);\n return;\n }\n\n int solve() {\n long d = B[1][1] - B[0][1];\n int cnt = 0;\n int ans = -1;\n long prev = B[1][1];\n\n foreach (i; 2..N) {\n if (B[i][1] - prev != d) {\n cnt += 1;\n if (cnt > 1) break;\n ans = B[i][0] + 1;\n } else {\n prev = B[i][1];\n }\n }\n\n if (cnt == 0) {\n return B[0][0] + 1;\n } else if (cnt == 1) {\n return ans;\n } else {\n return -1;\n }\n }\n\n B.sort!\"a[1] < b[1]\";\n int ans = solve();\n if (ans != -1) {\n ans.writeln;\n return;\n }\n\n B.sort!\"a[1] > b[1]\";\n ans = solve();\n if (ans != -1) {\n ans.writeln;\n return;\n }\n\n writeln(-1);\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nbool isAP (R) (R a)\n{\n\tforeach (i; 2..a.length)\n\t{\n\t\tif (a[i - 0].value - a[i - 1].value !=\n\t\t a[i - 1].value - a[i - 2].value)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\talias Pair = Tuple !(int, q{value}, int, q{num});\n\t\tauto a = new Pair [n];\n\t\tforeach (i, ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x.value);\n\t\t\tx.num = i + 1;\n\t\t}\n\t\tsort (a);\n\n\t\tint res = -1;\n\t\tif (isAP (a[1..$]))\n\t\t{\n\t\t\tres = 0;\n\t\t}\n\t\telse if (isAP (a[0..$ - 1]))\n\t\t{\n\t\t\tres = n - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint d = a[$ - 1].value - a[0].value;\n\t\t\tif (d % (n - 2) == 0)\n\t\t\t{\n\t\t\t\td /= n - 2;\n\t\t\t\tint j = -1;\n\t\t\t\tforeach (i; 0..n)\n\t\t\t\t{\n\t\t\t\t\tif (a[i].value != a[0].value + d * i)\n\t\t\t\t\t{\n\t\t\t\t\t\tj = i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isAP (a[0..j] ~ a[j + 1..$]))\n\t\t\t\t{\n\t\t\t\t\tres = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res >= 0 ? a[res].num : res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n auto B = N.iota.map!(i => tuple(i, A[i])).array;\n\n if (N == 2) {\n writeln(1);\n return;\n }\n\n if (N == 3) {\n writeln(2);\n return;\n }\n\n int solve() {\n long d = B[1][1] - B[0][1];\n int cnt = 0;\n int ans = -1;\n long prev = B[1][1];\n\n foreach (i; 2..N) {\n if (B[i][1] - prev != d) {\n cnt += 1;\n if (cnt > 1) break;\n ans = B[i][0] + 1;\n } else {\n prev = B[i][1];\n }\n }\n\n if (cnt == 0) {\n return 1;\n } else if (cnt == 1) {\n return ans;\n } else {\n return -1;\n }\n }\n\n B.sort!\"a[1] < b[1]\";\n int ans = solve();\n if (ans != -1) {\n ans.writeln;\n return;\n }\n B.sort!\"a[1] > b[1]\";\n ans = solve();\n if (ans != -1) {\n ans.writeln;\n return;\n }\n writeln(-1);\n}"}], "src_uid": "6946f088e462d12da47419f492ad51ea"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto S = scan;\r\n int[char] counts;\r\n foreach(c; S) counts[c]++;\r\n\r\n string ans;\r\n foreach(c, count; counts) {\r\n if (count == 2) ans ~= c;\r\n }\r\n\r\n ans ~= ans;\r\n foreach(c, count; counts) {\r\n if (count == 1) ans ~= c;\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\treadln.strip.array.sort.text.writeln;\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int[] s = readln.strip.dup.map!(x => cast(int)x).array;\n s.sort;\n writeln(s.map!(x => cast(char)x).array.idup);\n }\n}\n"}], "negative_code": [], "src_uid": "28102f75e0798960740e5a2625393c8f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto _n = RD!(char[]);\r\n\t\t_n.reverse;\r\n\t\tauto n = _n.idup;\r\n\r\n\t\tforeach (i; 0..2^^n.length)\r\n\t\t{\r\n\t\t\tif (i >> max(0, cast(int)(n.length)-2)) continue;\r\n\t\t\tlong cnt = 1;\r\n\t\t\tforeach (j; 0..n.length)\r\n\t\t\t{\r\n\t\t\t\tlong x = n[j] - '0';\r\n\t\t\t\tif (j >= 2)\r\n\t\t\t\t\tif (i & (1L << (j-2)))\r\n\t\t\t\t\t\t--x;\r\n\r\n\t\t\t\tlong c;\r\n\t\t\t\tif (i & (1L << j))\r\n\t\t\t\t\tx += 10;\r\n\t\t\t\tforeach (k; 0..10)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (inside(x - k, 0, 10))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t++c;\r\n\t\t\t\t\t\tdebug writeln(\"i:\", i, \" j:\", j, \" x:\", x, \" k:\", k);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tcnt *= c;\r\n\t\t\t}\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tif (cnt != 0)\r\n\t\t\t\t\tans[ti] += cnt-2;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tans[ti] += cnt;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong solve(long n)\n{\n long odd, even;\n long mult = 1;\n while (n > 0) {\n long odddigit = n % 10;\n n /= 10;\n long evendigit = n % 10;\n n /= 10;\n odd += odddigit * mult;\n even += evendigit * mult;\n mult *= 10;\n }\n return (odd + 1) * (even + 1) - 2;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n writeln(solve(n));\n }\n}\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!long;\n\tint[10] digs;\n\tforeach(i, ref di; digs)\n\t{\n\t\tdi = n%10;\n\t\tn/=10;\n\t}\n\tdebug writeln(digs);\n\tauto ans = 0L;\n\tvoid consider(int carry)\n\t{\n\t\tif (carry&0b11) return;\n\t\tint carryAt(int i)\n\t\t{\n\t\t\treturn int((carry & (1 << i)) != 0);\n\t\t}\n\t\tlong ways = 1;\n\t\tforeach(i; 0 .. 10)\n\t\t{\n\t\t\tif (carryAt(i+2))\n\t\t\t{\n\t\t\t\tauto d = digs[i];\n\t\t\t\t// x1+ci + x2 >= 10\n\t\t\t\t// (x1+x2)%10 == d\n\t\t\t\t// if (x1+ci > d) x2 is set, x1+ci + x2 >= 10\n\t\t\t\t// x1+ci > d x1+ci+9\n\t\t\t\tlong w = void;\n\t\t\t\t// x1+ci+x2 = 10+d\n\t\t\t\t// x2 = 10+d-x1-ci\n\t\t\t\t// x2 >= 0 10+d-x1-ci >= 0 x1 <= \n\t\t\t\t// x2 < 10 10+d-x1-ci < 10\n\t\t\t\t// d-x1-ci < 0\n\t\t\t\tlong l = d-carryAt(i)+1;\n\t\t\t\tlong h = 9;\n\t\t\t\tif (l <= h) w = h-l+1;\n\t\t\t\telse w = 0;\n\t\t\t\tways *= w;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tauto d = digs[i];\n\t\t\t\tlong w = void;\n\t\t\t\t//x1+ci+x2 = d\n\t\t\t\t// x2 = d-x1-ci\n\t\t\t\t// x2 >= 0 -> d-x1-ci >= 0 -> x1 <= d-ci\n\t\t\t\t// x2 < 10 -> d-x1-ci < 10 -> x1 > d-ci-10\n\t\t\t\tlong l = 0;\n\t\t\t\tlong h = d-carryAt(i);\n\t\t\t\tif (l <= h) w = h-l+1;\n\t\t\t\telse w = 0;\n\t\t\t\tways *= w;\n\t\t\t}\n\t\t}\n\t\tans += ways;\n\t}\n\tforeach(int carry; 0 .. (1<<8))\n\t{\n\t\tconsider(carry<<2);\n\t}\n\twriteln(ans-2);\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "8588dd273c9651f8d51cd3a2b7bd81bd"} {"source_code": "import std.conv, std.functional, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, M;\nint[] A, B;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n M = readInt();\n A = new int[M];\n B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n auto cnt = new int[N];\n auto mn = new int[N];\n mn[] = N;\n foreach (i; 0 .. M) {\n ++cnt[A[i]];\n chmin(mn[A[i]], (B[i] - A[i] + N) % N);\n }\n \n foreach (x; 0 .. N) {\n int ans;\n foreach (y; 0 .. N) {\n if (cnt[y] > 0) {\n chmax(ans, (y - x + N) % N + (cnt[y] - 1) * N + mn[y]);\n }\n }\n if (x > 0) {\n write(\" \");\n }\n write(ans);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\nimmutable int MD = 998244353;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto cnt = new int[] (n);\n auto dst = new int[] (n);\n \n foreach (_; 0 .. m) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n \n --a, --b;\n cnt[a] += 1;\n int closest = b - a + (b < a ? n : 0);\n dst[a] = dst[a] == 0 ? closest : min(dst[a], closest);\n }\n \n debug { writeln(dst, ' ', cnt); }\n \n int[] ans;\n \n foreach (st; 0 .. n) {\n int cur = 0;\n foreach (mv; 0 .. n) {\n int pos = (st + mv) % n;\n cur = max(cur, mv + (cnt[pos] - 1) * n + dst[pos]);\n }\n \n ans ~= cur;\n }\n \n ans.writefln!\"%(%s %)\";\n}"}], "negative_code": [], "src_uid": "ecda736a0caa924ebd5f8f133586d542"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main(){\n auto N = readln.chomp.to!(int);\n auto A = readln.split.map!(x => x.to!(int)-1).array;\n\n auto cnt = new int[](10);\n int ans = 0;\n int day = 0;\n\n foreach (a; A) {\n ++day;\n cnt[a] += 1;\n foreach (j; 0..10) {\n if (cnt[j] == 0) continue;\n cnt[j] -= 1;\n if (cnt.filter!(x => x != 0).empty || cnt.reduce!max == cnt.filter!(x => x != 0).reduce!min) {\n ans = day;\n }\n cnt[j] += 1;\n }\n\n }\n\n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] us;\n\t\n\tforeach(i; 0 .. n) us ~= read.to!int - 1;\n\t\n\tint bestx = 1;\n\tint minc, maxc;\n\tint[] ucnt = new int[](100_009);\n\tint[] ccnt = new int[](100_009);\n\tint allccnt;\n\tforeach(i; 0 .. n){\n\t\tint u = us[i];\n\t\tint c = ucnt[u];\n\t\tif(c > 0) ccnt[c] -= 1;\n\t\tif(c == minc && ccnt[c] == 0) minc += 1;\n\t\tucnt[u] += 1;\n\t\tc = ucnt[u];\n\t\tccnt[c] += 1;\n\t\tif(c == 1) minc = 1, allccnt += 1;\n\t\tif(c > maxc) maxc = c;\n\t\t\n\t\tif(minc == 1 && ccnt[minc] == 1 && ccnt[minc] + ccnt[maxc] == allccnt) bestx = i + 1;\n\t\tif(minc == maxc - 1 && ccnt[maxc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && ccnt[minc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && minc == 1 && ccnt[minc] > 1) bestx = i + 1;\n\t\t\n\t}\n\t\n\tbestx.writeln;\n\t\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] us;\n\t\n\tforeach(i; 0 .. n) us ~= read.to!int - 1;\n\t\n\tint bestx = 1;\n\tint[] ucnt = new int[](10);\n\tforeach(i; 0 .. n){\n\t\tint u = us[i];\n\t\tucnt[u] += 1;\n\t\tif(isOk(ucnt)) bestx = i + 1;\n\t}\n\t\n\tbestx.writeln;\n\t\n}\n\nbool isOk(int[] ucnt){\n\tint[int] countcnt;\n\tforeach(u; 0 .. 10){\n\t\tif(ucnt[u] == 0) continue;\n\t\tif(!ucnt[u] in countcnt) countcnt[ucnt[u]] = 0;\n\t\tcountcnt[ucnt[u]] += 1;\n\t}\n\t\n\tprint!1(countcnt);\n\t\n\tint[] ks = countcnt.keys;\n\tif(ks.length == 1){\n\t\tif(ks[0] == 1) return 1;\n\t}\n\telse if(ks.length == 2){\n\t\tif(ks[0] > ks[1]){\n\t\t\tif(ks[0] - ks[1] == 1 && countcnt[ks[0]] == 1) return 1;\n\t\t\tif(ks[1] == 1 && countcnt[ks[1]] == 1) return 1;\n\t\t}\n\t\tif(ks[0] < ks[1]){\n\t\t\tif(ks[1] - ks[0] == 1 && countcnt[ks[1]] == 1) return 1;\n\t\t\tif(ks[0] == 1 && countcnt[ks[0]] == 1) return 1;\n\t\t}\n\t}\n\t\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] us;\n\t\n\tforeach(i; 0 .. n) us ~= read.to!int - 1;\n\t\n\tint bestx = 1;\n\tint minc, maxc;\n\tint[] ucnt = new int[](100_009);\n\tint[] ccnt = new int[](100_009);\n\tforeach(i; 0 .. n){\n\t\tint u = us[i];\n\t\tint c = ucnt[u];\n\t\tif(c > 0) ccnt[c] -= 1;\n\t\tif(c == minc && ccnt[c] == 0) minc += 1;\n\t\tucnt[u] += 1;\n\t\tc = ucnt[u];\n\t\tccnt[c] += 1;\n\t\tif(c == 1) minc = 1;\n\t\tif(c > maxc) maxc = c;\n\t\t\n\t\tif(minc == 1 && ccnt[minc] == 1) bestx = i + 1;\n\t\tif(minc == maxc - 1 && ccnt[maxc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && ccnt[minc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && minc == 1 && ccnt[minc] > 1) bestx = i + 1;\n\t\t\n\t}\n\t\n\tbestx.writeln;\n\t\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] us;\n\t\n\tforeach(i; 0 .. n) us ~= read.to!int - 1;\n\t\n\tint bestx = 1;\n\tint[] ucnt = new int[](10);\n\tforeach(i; 0 .. n){\n\t\tint u = us[i];\n\t\tucnt[u] += 1;\n\t\tif(isOk(ucnt)) bestx = i + 1;\n\t}\n\t\n\tbestx.writeln;\n\t\n}\n\nbool isOk(int[] ucnt){\n\tint[int] countcnt;\n\tforeach(u; 0 .. 10){\n\t\tif(ucnt[u] == 0) continue;\n\t\tif(!ucnt[u] in countcnt) countcnt[ucnt[u]] = 1;\n\t\tcountcnt[ucnt[u]] += 1;\n\t}\n\t\n\tprint!1(countcnt);\n\t\n\tint[] ks = countcnt.keys;\n\tif(ks.length == 1){\n\t\tif(ks[0] == 1) return 1;\n\t}\n\telse if(ks.length == 2){\n\t\tif(ks[0] > ks[1]){\n\t\t\tif(ks[0] - ks[1] == 1 && countcnt[ks[0]] == 1) return 1;\n\t\t\tif(ks[1] == 1 && countcnt[ks[1]] == 1) return 1;\n\t\t}\n\t\tif(ks[0] < ks[1]){\n\t\t\tif(ks[1] - ks[0] == 1 && countcnt[ks[1]] == 1) return 1;\n\t\t\tif(ks[0] == 1 && countcnt[ks[0]] == 1) return 1;\n\t\t}\n\t}\n\t\n\treturn 0;\n}\n"}], "src_uid": "2d020e6c3000836e8b903a12ae39dd9b"} {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, q; readV(n, q);\n long[] a; readA(n, a);\n long[] k; readA(q, k);\n\n foreach (i; 1..n) a[i] += a[i-1];\n auto as = a.assumeSorted;\n\n auto t = 0L;\n foreach (ki; k) {\n t += ki;\n if (t >= as.back) t = 0;\n writeln(as.upperBound(t).length);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.string, std.array, std.range;\n\nvoid main()\n{\n int n, q;\n readf(\" %s %s\", n, q);\n\n auto s = new long[n];\n\n long cs = 0;\n\n foreach(ref v; s)\n {\n long t;\n readf(\" %s\", t);\n cs += t;\n v = cs;\n }\n\n auto sorted = assumeSorted(s);\n\n cs = 0;\n\n foreach (_; 0 .. q)\n {\n long t;\n readf(\" %s\", t);\n cs += t;\n\n if (cs < s.back)\n {\n writeln(sorted.upperBound(cs).length);\n }\n else\n {\n writeln(s.length);\n cs = 0;\n }\n }\n}"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main()\n{\n\tint n, q;\n\treadln.chomp.split.tie(n, q);\n\tulong[] a = readln.chomp.split.map!(to!ulong).array;\n\tulong[] k = readln.chomp.split.map!(to!ulong).array;\n\t\n\tulong[] b = new ulong[](n);\n\tb[0] = a[0];\n\tfor (int i = 1; i < n; ++i) {\n\t\tb[i] = b[i - 1] + a[i];\n\t}\n\tauto c = b.assumeSorted;\n\tulong l = 0;\n\tOutBuffer buf = new OutBuffer();\n\tforeach (v; k) {\n\t\tl += v;\n\t\tdebug verbose(l, c.upperBound(l));\n\t\tauto remain = c.upperBound(l).length;\n\t\tif (remain == 0) {\n\t\t\tl = 0;\n\t\t\tremain = n;\n\t\t}\n\t\tbuf.writeln = remain;\n\t}\n\tbuf.toString.write;\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n auto a = readln.splitter.map!(to!ulong).cumulativeFold!((a,b) => a+b).array;\n auto q = readln.splitter.map!(to!ulong).array;\n \n debug { writeln(a); writeln(q); }\n \n ulong cur = 0;\n ulong [] ans;\n foreach (order; q) {\n cur += order;\n auto rng = a.assumeSorted.upperBound(cur);\n ans ~= rng.length > 0 ? rng.length : a.length;\n if (rng.length == 0) cur = 0;\n }\n \n ans.each!writeln;\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.range, std.array;\n\n int n, q; rd(n, q);\n auto as=readln.split.to!(long[]);\n auto bs=readln.split.to!(long[]);\n auto sub=new long[](n+1); // sum(as[l, r])=sub[r]-sub[l-1]; 1-indexed\n foreach(i; 0..n) sub[i+1]=sub[i]+as[i];\n int pos=1;\n long cur=0;\n foreach(b; bs){\n auto rem=(sub[pos]-sub[0])-cur;\n if(b<rem){\n writeln(n-pos+1);\n // writeln(\"a\");\n cur+=b;\n }else{\n auto o=b-rem;\n if((sub[n]-sub[pos])<=o){\n writeln(n);\n // writeln(\"b\");\n pos=1;\n cur=0;\n }else{\n auto tri=sub.assumeSorted.trisect(o+(sub[pos]-sub[0]));\n // if(tri[1].length>0){\n // pos=tri[0].length+1;\n // }else{\n\n // }\n pos=(tri[0].length+tri[1].length).to!(int); // aaaaa\n writeln(n-pos+1);\n // writeln(\"c\");\n cur+=b;\n }\n }\n // writeln(\"cur: \", cur);\n // writeln(\"pos: \", pos);\n }\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "negative_code": [], "src_uid": "23d69ae8b432111c4291e7b767443925"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tint t = n * (n - 1) / 2;\n\t\tif (t <= k)\n\t\t{\n\t\t\twriteln (\"no solution\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\twritefln (\"%s %s\", 0, i);\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n int n;\n int k;\n readf(\"%d %d \", &n, &k);\n if (n*(n-1)/2 <= k) {\n writeln(\"no solution\");\n } else {\n foreach (i; 0..n) {\n writeln(0, ' ', i);\n }\n }\n}"}], "negative_code": [{"source_code": "import std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n int n;\n int k;\n readf(\"%d %d \", &n, &k);\n if (n*(n-1)/2 < k) {\n writeln(\"no solution\");\n } else {\n foreach (i; 0..n) {\n writeln(0, ' ', i);\n }\n }\n}"}, {"source_code": "import std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n int n;\n int k;\n readf(\"%d %d \", &n, &k);\n if (n*(n-1)/2 > k) {\n writeln(\"no solution\");\n } else {\n foreach (i; 0..n) {\n writeln(0, ' ', i);\n }\n }\n}"}], "src_uid": "a7846e4ae1f3fa5051fab9139a25539c"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(string a, int n, string b, int m)\n{\n const static int mod = 998244353;\n auto v = new int[n];\n v[n - 1] = 1;\n for (int i = n - 2; i >= 0; -- i)\n {\n v[i] = v[i + 1] << 1;\n v[i] %= mod;\n }\n auto c = new int[max(n, m)];\n fill(c, 0);\n auto start = n > m ? n - m : 0;\n foreach (i; start .. max(n, m))\n {\n c[i] = b[i - start] == '1' ? 1 : 0;\n if (i > start) c[i] += c[i - 1];\n }\n auto ans = 0;\n auto shift = n > m ? 0 : m - n; \n start = n > m ? n - m : 0;\n foreach (i; start .. n)\n {\n if (a[i] == '1')\n {\n ans += (cast(long)c[i + shift] * v[i]) % mod;\n ans %= mod;\n }\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n, m;\n while (readf(\"%d %d\\n\", &n, &m) == 2)\n {\n auto a = readln.strip;\n auto b = readln.strip;\n solve(a, n, b, m);\n }\n return 0;\n}", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.array;\n\n int n, m;\n rd(n, m);\n auto a = readln.chomp\n .to!(char[])\n .map!((ch) => (ch - '0'))\n .array\n .to!(long[]);\n auto b = readln.chomp\n .to!(char[])\n .map!((ch) => (ch - '0'))\n .array\n .to!(long[]);\n\n if (n < m) {\n a.reverse;\n foreach (_; 0 .. (m - n))\n a ~= 0;\n a.reverse;\n } else {\n b.reverse;\n foreach (_; 0 .. (n - m))\n b ~= 0;\n b.reverse;\n }\n\n foreach (i; 1 .. b.length)\n b[i] += b[i - 1];\n const long mod = 998244353;\n long pow2 = 1, ans = 0;\n foreach_reverse (i; 0 .. a.length) {\n if (a[i]) {\n ans += pow2 * b[i] % mod;\n ans %= mod;\n }\n pow2 *= 2;\n pow2 %= mod;\n }\n writeln(ans);\n\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(string a, int n, string b, int m)\n{\n const static int mod = 998244353;\n auto v = new int[n];\n v[n - 1] = 1;\n for (int i = n - 2; i >= 0; -- i)\n {\n v[i] = v[i + 1] << 1;\n v[i] %= mod;\n }\n auto c = new int[max(n, m)];\n fill(c, 0);\n auto start = n > m ? n - m : 0;\n foreach (i; start .. max(n, m))\n {\n c[i] = b[i] == '1' ? 1 : 0;\n if (i > start) c[i] += c[i - 1];\n }\n auto ans = 0;\n start = n > m ? n - m : m - n;\n foreach (i; start .. start + n)\n {\n if (a[i - start] == '1')\n {\n ans += (cast(long)c[i] * v[i - start]) % mod;\n ans %= mod;\n }\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n, m;\n while (readf(\"%d %d\\n\", &n, &m) == 2)\n {\n auto a = readln.strip;\n auto b = readln.strip;\n solve(a, n, b, m);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(string a, int n, string b, int m)\n{\n const static int mod = 998244353;\n auto v = new int[n];\n v[n - 1] = 1;\n for (int i = n - 2; i >= 0; -- i)\n {\n v[i] = v[i + 1] << 1;\n v[i] %= mod;\n }\n auto c = new int[max(n, m)];\n auto start = 0;\n if (n > m)\n {\n start = n - m;\n foreach (i; 0 .. n - m)\n {\n c[i] = 0;\n }\n }\n foreach (i; start .. max(n, m))\n {\n c[i] = b[i] == '1' ? 1 : 0;\n if (i > start) c[i] += c[i - 1];\n }\n auto ans = 0;\n start = m > n ? m - n : 0;\n foreach (i; start .. start + n)\n {\n if (a[i - start] == '1')\n {\n ans += (cast(long)c[i] * v[i - start]) % mod;\n ans %= mod;\n }\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n, m;\n while (readf(\"%d %d\\n\", &n, &m) == 2)\n {\n auto a = readln.strip;\n auto b = readln.strip;\n solve(a, n, b, m);\n }\n return 0;\n}"}], "src_uid": "d2fe5a201d1ec20c5b32cd99b54e13d0"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.random;\n\nint ri () {\n return readln.stripRight.to!int;\n}\n\nstring slow (string z, int k) {\n auto s = z.dup;\n for (int i = 0; i + k <= s.length; ++i) {\n reverse (s[i .. i + k]);\n }\n return s.idup;\n}\n\nvoid research (int k) {\n string p = \"1234567890\";\n foreach (i; 1 .. k + 1) {\n stderr.writeln (slow (p[0 .. k], i));\n }\n}\n\nvoid reseach0 () {\n research (5);\n stderr.writeln;\n research (6);\n stderr.writeln;\n research (7);\n stderr.writeln;\n research (9);\n}\n\nvoid main() {\n debug reseach0 ();\n const nt = ri ();\n foreach (tid; 0 .. nt) {\n const n = ri ();\n const s = readln.stripRight;\n auto z = new byte[2*n];\n foreach (i; 0 .. 2*n) z[i] = s[i%n].to!byte;\n int best = n - 1;\n byte[] ans = z[0 .. n].dup;\n reverse (ans);\n auto u = new byte[n];\n foreach_reverse (k; 0 .. n - 1) {\n u[] = z[k .. k + n][];\n/*\n123456 0\n234561 1\n345612 2\n456321 3\n561234 4\n654321 5\n\n123456789 0\n234567891 1\n345678921 2\n456789123 3\n567894321 4\n678912345 5\n789654321 6\n891234567 7\n987654321 8\n*/\n if ((k & 1) != (n & 1)) {\n reverse (u[n - k .. n]);\n }\n if (cmp (u, ans) <= 0) {\n ans = u.dup;\n best = k;\n }\n }\n foreach (i; ans) {\n write(i.to!char);\n }\n writeln;\n writeln (best+1);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. scan!int){\n int n = scan!int;\n char[] s = scan!(char[]);\n\n char[] ans;\n foreach(c; s) ans ~= c;\n long best = 0;\n foreach(k; 0 .. n){\n char[] t;\n foreach(c; s[k .. n]) t ~= c;\n if((n - k) % 2) foreach_reverse(c; s[0 .. k]) t ~= c;\n else foreach(c; s[0 .. k]) t ~= c;\n log(\"s:\", s, \"k:\", k, \"t:\", t, \"ans:\", ans, \"best:\", best);\n\n if(ans <= t) continue;\n else ans = t, best = k;\n }\n\n ans.writeln;\n (best + 1).writeln;\n\n }\n \n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tauto k = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\t\tauto list = new int[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i..n)\n\t\t\t\tlist[i] ~= s[j]-'a';\n\t\t\tif ((n-i) % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (j; 0..i)\n\t\t\t\t\tlist[i] ~= s[j]-'a';\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach_reverse (j; 0..i)\n\t\t\t\t\tlist[i] ~= s[j]-'a';\n\t\t\t}\n\t\t}\n\t\tauto pos = list.MIN_POS();\n\t\tk[ti] = cast(int)(pos+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tans[ti] ~= cast(char)(list[pos][i]+'a');\n\t\t}\n\t}\n\n\tforeach (ti; 0..t)\n\t{\n\t\twriteln(ans[ti]);\n\t\twriteln(k[ti]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "f501e17271a220f3bcd69377c01721a1"} {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n assert(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nstring[] words;\n\nint solve(char c) {\n int[] arr = new int[words.length];\n \n foreach (i, w; words) {\n auto a = w.count(c).to!int;\n arr[i] = a - (w.length.to!int - a);\n }\n \n sort(arr);\n reverse(arr);\n \n if (arr[0] < 1) return 0;\n \n long total = arr[0];\n int answer = 1;\n \n foreach (i; 1 .. arr.length) {\n total += arr[i];\n if (total <= 0) break;\n answer++;\n }\n \n return answer;\n}\n\nvoid main() {\n int t;\n read(t);\n \n while (t--) {\n int n;\n read(n);\n words = new string[n];\n \n foreach (i; 0 .. n) words[i] = readln[0 .. $ - 1];\n \n int answer = 0;\n foreach (c; 'a' .. 'f') {\n answer = max(answer, solve(c));\n }\n \n writeln(answer);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--)\n\t{\n\t\tsolve();\n\t}\n}\n\n\nvoid solve()\n{\n\tint n = readInt!int;\n\tauto words = new char[][](n);\n\tforeach(ref word; words)\n\t{\n\t\tword = cast(char[])readString;\n\t}\n\tint maxwords = 0;\n\tvoid tryChar(char ch)\n\t{\n\t\tauto diff = new int[](n);\n\t\tforeach(i; 0 .. n)\n\t\t{\n\t\t\tdiff[i] = 0;\n\t\t\tforeach(c; words[i])\n\t\t\t{\n\t\t\t\tif (c == ch) diff[i]++;\n\t\t\t\telse diff[i]--;\n\t\t\t}\n\t\t}\n\t\tsort!((a, b) => a > b)(diff);\n\t\tint maxlen = 0;\n\t\tint prefsum = 0;\n\t\tforeach(i, di; diff)\n\t\t{\n\t\t\tprefsum += di;\n\t\t\tif (prefsum > 0) maxlen = cast(int)i + 1;\n\t\t}\n\t\tmaxwords = max(maxwords, maxlen);\n\t}\n\tforeach(ch; ['a', 'b', 'c', 'd', 'e'])\n\t{\n\t\ttryChar(ch);\n\t}\n\tmaxwords.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}], "negative_code": [], "src_uid": "18ac51a009c907fe8e4cd2bb8612da20"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n A: foreach(_; 0 .. scan!int){\n string s = scan;\n int n = s.length.to!int;\n\n int a = 0, b = n - 1;\n while(a < b){\n log(\"a:\", a, \"b:\", b, \"s[a]:\", s[a], \"s[b]:\", s[b]);\n if(s[a] != s[b]) break;\n a ++, b --;\n }\n if(a >= b){\n s.writeln;\n continue A;\n }\n log(\"a:\", a, \"b:\", b);\n \n string s2 = s.split(\"\").join(\"$\");\n int[] mana1 = manacher(s);\n int[] manatmp = manacher(s2);\n int[] mana2; foreach(i; 0 .. manatmp.length / 2) mana2 ~= manatmp[1 + i * 2] / 2;\n log(\"mana1:\", mana1);\n log(\"mana2:\", mana2);\n\n bool isPalin(int u, int v){ // s[u .. v] is palin.\n log(\"u:\", u, \"v:\", v, \"s[u..v]:\", s[u .. v]);\n if((v - u) % 2){\n int r = mana1[u + (v - u) / 2];\n log(\"odd;\", \"r:\", r);\n return r - 1 + r >= v - u;\n }\n else{\n int r = mana2[(u + v - 1) / 2];\n log(\"even;\", \"r:\", r);\n return r + r >= v - u;\n }\n }\n\n\n foreach_reverse(i; 0 .. b - a + 1){\n if(isPalin(a, a + i)){\n (s[0 .. a + i] ~ s[b + 1 .. $]).writeln;\n continue A;\n }\n if(isPalin(b - i + 1, b + 1)){\n (s[0 .. a] ~ s[b - i + 1 .. $]).writeln;\n continue A;\n }\n }\n }\n}\n\n// Manacher's algorithm\n// https://snuke.hatenablog.com/entry/2014/12/02/235837\nint[] manacher(string s){\n int n = s.length.to!int;\n int[] res = new int[](n);\n int i = 0, j = 0;\n while(i < n){\n while(i - j >= 0 && i + j < n && s[i - j] == s[i + j]) ++j;\n res[i] = j;\n int k = 1;\n while(i - k >= 0 && i + k < n && k + res[i - k] < j) res [i + k] = res[i - k], ++k;\n i += k; j -= k;\n }\n return res;\n}\n\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nint[] manacher(T)(T a) {\n const n = cast(int)(a.length);\n auto r = new int[n * 2];\n for (int i = 0, j = 0, k; i < n * 2; i += k, j = max(j - k, 0)) {\n for (; 0 <= i - j && i + j + 1 < n * 2 && a[(i - j) / 2] == a[(i + j + 1) / 2]; ++j) {}\n r[i] = j;\n for (k = 1; 0 <= i - k && 0 <= j - k && r[i - k] != j - k; ++k) {\n r[i + k] = min(r[i - k], j - k);\n }\n }\n return r;\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const S = readToken();\n const L = cast(int)(S.length);\n \n const rads = manacher(S);\n debug {\n writeln(\"rads = \", rads);\n }\n \n auto ls = new int[L + 1];\n ls[] = -1;\n foreach (x; 0 .. L) {\n // x - rads[x] <= 2 k\n chmax(ls[(x - rads[x] + 1) / 2], x);\n }\n foreach (k; 1 .. L + 1) {\n chmax(ls[k], ls[k - 1]);\n }\n auto rs = new int[L + 1];\n rs[] = 2 * L;\n foreach (x; L - 1 .. 2 * L - 1) {\n // 2 (L - 1 - k) <= x + rads[x]\n chmin(rs[(2 * (L - 1) - x - rads[x] + 1) / 2], x);\n }\n foreach (k; 1 .. L + 1) {\n chmin(rs[k], rs[k - 1]);\n }\n debug {\n writeln(\"ls = \", ls);\n writeln(\"rs = \", rs);\n }\n \n int ansA, ansB;\n void check(int a, int b) {\n if (ansA + ansB < a + b) {\n ansA = a;\n ansB = b;\n }\n }\n foreach (k; 0 .. L + 1) {\n check(k, k);\n if (ls[k] != -1) {\n const i = k;\n const j = ls[k] - i;\n check(k + (j - i + 1), k);\n }\n if (rs[k] != 2 * L) {\n const i = L - 1 - k;\n const j = rs[k] - i;\n check(k, (i - j + 1) + k);\n }\n if ((k + 1) + (k + 1) > L) {\n break;\n }\n if (S[k] != S[L - 1 - k]) {\n break;\n }\n }\n writeln(S[0 .. ansA] ~ S[L - ansB .. L]);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport std.stdio, std.array, std.string, std.math, std.uni, std.format, std.bigint;\nimport std.algorithm, std.conv, std.container, std.range, std.functional;\nimport std.random, std.typecons;\n\n// FIXME\nint[] buildZ(in string s) {\n int n = cast(int)(s.length);\n int[] z; z.length = n;\n for (int i = 1, l = 0, r = 0; i < n; ++i) {\n if (i <= r) z[i] = (z[i - l] < r - i + 1 ? z[i - l] : r - i + 1);\n while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];\n if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;\n }\n return z;\n}\n\nvoid solve(in int testcase) {\n string s, t;\n s.read;\n int n = cast(int)(s.length), m;\n for (int i = 0; i < n; ++i)\n t ~= s[n - i - 1];\n if (s == t) {\n s.writeln;\n return ;\n }\n int[] z = buildZ(s ~ '$' ~ t);\n int x = z[n + 1];\n string ans1 = s[0 .. x];\n string ans2 = \"\";\n int mx = 0;\n string p = s[x .. n - x];\n string o;\n {\n n = cast(int)(p.length), m = n * 2 + 1;\n t = \"\";\n for (int i = 0; i < n; ++i)\n t ~= p[n - i - 1];\n o = p ~ '$' ~ t;\n z = buildZ(o);\n for (int i = m - 1; i >= 0; --i) {\n if (z[i] == m - i && mx < m - i) {\n mx = m - i;\n ans2 = o[i .. $];\n }\n }\n }\n p = t;\n {\n n = cast(int)(p.length), m = n * 2 + 1;\n t = \"\";\n for (int i = 0; i < n; ++i)\n t ~= p[n - i - 1];\n o = p ~ '$' ~ t;\n z = buildZ(o);\n for (int i = m - 1; i >= 0; --i) {\n if (z[i] == m - i && mx < m - i) {\n mx = m - i;\n ans2 = o[i .. $];\n }\n }\n }\n string ans3;\n for (int i = 0; i < x; ++i)\n ans3 ~= ans1[x - i - 1];\n (ans1 ~ ans2 ~ ans3).writeln;\n}\n\n// ************************************************************\n\nT reader(T)() { return readToken().to!T; }\nvoid read(T)(ref T t) { t = reader!T; }\nT[] readarray(T)() { return readln.splitter.map!(to!T).array; }\nvoid chmax(T)(ref T a, T b) { a = max(a, b); }\nvoid chmin(T)(ref T a, T b) { a = min(a, b); }\nalias less = (a, b) => a < b;\nalias greater = (a, b) => a > b;\nT min_element(T)(in T[] a) { return a.element!less; }\nT max_element(T)(in T[] a) { return a.element!greater; }\nalias unique = uniq;\n\n// constant or some variables\nimmutable int inf = 0x3f3f3f3f;\nimmutable long lnf = 0x3f3f3f3f3f3f3f3f;\nimmutable typeof(null) NULL = null;\nstring[] _tokens;\n\n// functions\nT element(alias pred, T)(in T[] a) {\n int pos = 0;\n for (int i = 1; i < cast(int)(a.length); ++i)\n if (binaryFun!pred(a[i], a[pos])) pos = i;\n return a[pos];\n}\nstring readToken() {\n for (; _tokens.empty; ) {\n if (stdin.eof) return \"\";\n _tokens = readln.split;\n }\n auto token = _tokens.front;\n _tokens.popFront;\n return token;\n}\nint binary_bearch(alias pred, T)(in T[] as) {\n int l = -1, h = cast(int)(as.length), mid;\n for (; l + 1 < h; ) {\n mid = (l + h) >> 1;\n (unaryFun!pred(as[mid]) ? h : l) = mid;\n }\n return h;\n}\nint lower_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => a == val || pred(val, a));\n}\nint upper_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => pred(val, a));\n}\n\nvoid main(string[] args) {\n int tests = 1;\n tests.read();\n foreach(test; 1 .. tests + 1) solve(test);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int q1 = 987_654_319;\nimmutable int q2 = 987_654_299;\nimmutable int maxN = 1_000_007;\n\nvoid main ()\n{\n\tint p1 = uniform (123_456_789, 444_333_222) * 2 + 1;\n\tint p2 = uniform (123_456_789, 444_333_222) * 2 + 1;\n\tint [] p1pow = [1];\n\tp1pow.reserve (maxN + 1);\n\tint [] p2pow = [1];\n\tp2pow.reserve (maxN + 1);\n\tforeach (i; 0..maxN)\n\t{\n\t\tp1pow ~= (p1pow.back * 1L * p1) % q1;\n\t\tp2pow ~= (p2pow.back * 1L * p2) % q2;\n\t}\n\n\tint tests;\n\treadf !(\" %s\") (tests);\n\treadln;\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\n\t\tstring lo = \"\";\n\t\twhile (s.length >= 2 && s[0] == s[$ - 1])\n\t\t{\n\t\t\tlo ~= s[0];\n\t\t\ts = s[1..$ - 1];\n\t\t}\n\t\tstring hi = lo.retro.text;\n\n\t\tauto n = s.length.to !(int);\n\n\t\tvoid calc (ref int [] h1, ref int [] h2, const ref string r)\n\t\t{\n\t\t\th1[0] = 0;\n\t\t\th2[0] = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\th1[i + 1] = (h1[i] * 1L * p1 + r[i]) % q1;\n\t\t\t\th2[i + 1] = (h2[i] * 1L * p2 + r[i]) % q2;\n\t\t\t}\n\t\t}\n\n\t\tauto h1lo = new int [n + 1];\n\t\tauto h2lo = new int [n + 1];\n\t\tcalc (h1lo, h2lo, s);\n\n\t\tauto t = s.retro.text;\n\t\tauto h1hi = new int [n + 1];\n\t\tauto h2hi = new int [n + 1];\n\t\tcalc (h1hi, h2hi, t);\n\t\treverse (h1hi);\n\t\treverse (h2hi);\n\n\t\tint bestLo = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tif ((h1hi[0] - h1hi[i] * 1L * p1pow[i] -\n\t\t\t h1lo[i]) % q1 == 0 &&\n\t\t\t (h2hi[0] - h2hi[i] * 1L * p2pow[i] -\n\t\t\t h2lo[i]) % q2 == 0)\n\t\t\t{\n\t\t\t\tbestLo = i;\n\t\t\t}\n\t\t}\n\n\t\treverse (h1lo);\n\t\treverse (h2lo);\n\t\treverse (h1hi);\n\t\treverse (h2hi);\n\t\tswap (h1lo, h1hi);\n\t\tswap (h2lo, h2hi);\n\t\tint bestHi = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tif ((h1hi[0] - h1hi[i] * 1L * p1pow[i] -\n\t\t\t h1lo[i]) % q1 == 0 &&\n\t\t\t (h2hi[0] - h2hi[i] * 1L * p2pow[i] -\n\t\t\t h2lo[i]) % q2 == 0)\n\t\t\t{\n\t\t\t\tbestHi = i;\n\t\t\t}\n\t\t}\n\n\t\tif (bestLo > bestHi)\n\t\t{\n\t\t\tlo ~= s[0..bestLo];\n\t\t}\n\t\telse\n\t\t{\n\t\t\thi = s[$ - bestHi..$] ~ hi;\n\t\t}\n\t\twriteln (lo, hi);\n\t}\n}\n"}, {"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport std.stdio, std.array, std.string, std.math, std.uni, std.format, std.bigint;\nimport std.algorithm, std.conv, std.container, std.range, std.functional;\nimport std.random, std.typecons;\n\n// FIXME\nint[] buildZ(in string s) {\n int n = cast(int)(s.length);\n int[] z; z.length = n;\n for (int i = 1, l = 0, r = 0; i < n; ++i) {\n if (i <= r) z[i] = (z[i - l] < r - i + 1 ? z[i - l] : r - i + 1);\n while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];\n if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;\n }\n return z;\n}\n\nvoid solve(in int testcase) {\n string s, t;\n s.read;\n int n = cast(int)(s.length), m;\n for (int i = 0; i < n; ++i)\n t ~= s[n - i - 1];\n if (s == t) {\n s.writeln;\n return ;\n }\n int[] z = buildZ(s ~ '$' ~ t);\n int x = z[n + 1];\n string ans1 = s[0 .. x];\n string ans2 = \"\";\n int mx = 0;\n string p = s[x .. n - x];\n string o;\n {\n n = cast(int)(p.length), m = n * 2 + 1;\n t = \"\";\n for (int i = 0; i < n; ++i)\n t ~= p[n - i - 1];\n o = p ~ '$' ~ t;\n z = buildZ(o);\n for (int i = m - 1; i >= 0; --i) {\n if (z[i] == m - i && mx < m - i) {\n mx = m - i;\n ans2 = o[i .. $];\n }\n }\n }\n p = t;\n {\n n = cast(int)(p.length), m = n * 2 + 1;\n t = \"\";\n for (int i = 0; i < n; ++i)\n t ~= p[n - i - 1];\n o = p ~ '$' ~ t;\n z = buildZ(o);\n for (int i = m - 1; i >= 0; --i) {\n if (z[i] == m - i && mx < m - i) {\n mx = m - i;\n ans2 = o[i .. $];\n }\n }\n }\n string ans3;\n for (int i = 0; i < x; ++i)\n ans3 ~= ans1[x - i - 1];\n (ans1 ~ ans2 ~ ans3).writeln;\n}\n\n// ************************************************************\n\nT reader(T)() { return readToken().to!T; }\nvoid read(T)(ref T t) { t = reader!T; }\nT[] readarray(T)() { return readln.splitter.map!(to!T).array; }\nvoid chmax(T)(ref T a, T b) { a = max(a, b); }\nvoid chmin(T)(ref T a, T b) { a = min(a, b); }\nalias less = (a, b) => a < b;\nalias greater = (a, b) => a > b;\nT min_element(T)(in T[] a) { return a.element!less; }\nT max_element(T)(in T[] a) { return a.element!greater; }\nalias unique = uniq;\n\n// constant or some variables\nimmutable int inf = 0x3f3f3f3f;\nimmutable long lnf = 0x3f3f3f3f3f3f3f3f;\nimmutable typeof(null) NULL = null;\nstring[] _tokens;\n\n// functions\nT element(alias pred, T)(in T[] a) {\n int pos = 0;\n for (int i = 1; i < cast(int)(a.length); ++i)\n if (binaryFun!pred(a[i], a[pos])) pos = i;\n return a[pos];\n}\nstring readToken() {\n for (; _tokens.empty; ) {\n if (stdin.eof) return \"\";\n _tokens = readln.split;\n }\n auto token = _tokens.front;\n _tokens.popFront;\n return token;\n}\nint binary_bearch(alias pred, T)(in T[] as) {\n int l = -1, h = cast(int)(as.length), mid;\n for (; l + 1 < h; ) {\n mid = (l + h) >> 1;\n (unaryFun!pred(as[mid]) ? h : l) = mid;\n }\n return h;\n}\nint lower_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => a == val || pred(val, a));\n}\nint upper_bound(alias pred = less, T)(in T[] as, T val) {\n return as.binary_bearch!(a => pred(val, a));\n}\n\nvoid main(string[] args) {\n int tests = 1;\n tests.read();\n foreach(test; 1 .. tests + 1) solve(test);\n}\n"}], "negative_code": [], "src_uid": "beaccd2c0213a330538fe741d1f4b5bf"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\n\t\tans[ti].length = n;\n\t\tforeach (i; 0..n)\n\t\t\tans[ti][i].length = n;\n\n\t\tif (n % 2 == 0)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..2)\n\t\t\t\t{\n\t\t\t\t\tauto x = (i/2) * 2 + j;\n\t\t\t\t\tans[ti][i][x] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (n % 3 == 2 || n % 3 == 0)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..3)\n\t\t\t\t{\n\t\t\t\t\tauto x = (i/3) * 3 + j;\n\t\t\t\t\tif (x >= n) break;\n\t\t\t\t\tans[ti][i][x] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 0..n-4)\n\t\t\t{\n\t\t\t\tforeach (j; 0..3)\n\t\t\t\t{\n\t\t\t\t\tauto x = (i/3) * 3 + j;\n\t\t\t\t\tif (x >= n) break;\n\t\t\t\t\tans[ti][i][x] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (i; n-4..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..2)\n\t\t\t\t{\n\t\t\t\t\tauto x = ((i-(n-4))/2) * 2 + (n-4) + j;\n\t\t\t\t\tans[ti][i][x] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (i; 0..e.length)\n\t\t{\n\t\t\twrite(e[i][0]);\n\t\t\tforeach (j; 1..e.length)\n\t\t\t{\n\t\t\t\twrite(\" \", e[i][j]);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n;\n n = rd!int;\n auto mat = new ll[][](n, n);\n foreach(i; 0..n){\n mat[i][] = 0;\n mat[i][i] = 1;\n mat[i][(i + 1) % n] = 1;\n }\n foreach(i; 0..n){\n mat[i].each!(a => write(a, \" \"));\n writeln;\n }\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, \"x\", long, \"y\");\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\n\t\tans[ti].length = n;\n\t\tforeach (i; 0..n)\n\t\t\tans[ti][i].length = n;\n\n\t\tif (n % 2 == 0)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..2)\n\t\t\t\t{\n\t\t\t\t\tauto x = (i/2) * 2 + j;\n\t\t\t\t\tans[ti][i][x] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..3)\n\t\t\t\t{\n\t\t\t\t\tauto x = (i/3) * 3 + j;\n\t\t\t\t\tans[ti][i][x] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (i; 0..e.length)\n\t\t{\n\t\t\twrite(e[i][0]);\n\t\t\tforeach (j; 1..e.length)\n\t\t\t{\n\t\t\t\twrite(\" \", e[i][j]);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\n\t\tans[ti].length = n;\n\t\tforeach (i; 0..n)\n\t\t\tans[ti][i].length = n;\n\n\t\tif (n % 2 == 0)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..2)\n\t\t\t\t{\n\t\t\t\t\tauto x = (i/2) * 2 + j;\n\t\t\t\t\tans[ti][i][x] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..3)\n\t\t\t\t{\n\t\t\t\t\tauto x = (i/3) * 3 + j;\n\t\t\t\t\tif (x >= n) break;\n\t\t\t\t\tans[ti][i][x] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (i; 0..e.length)\n\t\t{\n\t\t\twrite(e[i][0]);\n\t\t\tforeach (j; 1..e.length)\n\t\t\t{\n\t\t\t\twrite(\" \", e[i][j]);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "df6ee0d8bb25dc2040adf1f115f4a83b"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tint [] [] a;\t\n\t\ta ~= readln.splitter.map !(to !(int)).array;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tauto b = new int [n - i];\n\t\t\tforeach (j; 0..n - i)\n\t\t\t{\n\t\t\t\tb[j] = a[i - 1][j] ^ a[i - 1][j + 1];\n\t\t\t}\n\t\t\ta ~= b;\n\t\t}\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tforeach (j; 0..n - i)\n\t\t\t{\n\t\t\t\ta[i][j] = max (a[i][j],\n\t\t\t\t a[i - 1][j], a[i - 1][j + 1]);\n\t\t\t}\n\t\t}\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (v; 0..q)\n\t\t{\n\t\t\tint l, r;\n\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\tl -= 1;\n\t\t\tr -= 1;\n\t\t\twriteln (a[r - l][l]);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n auto B = new long[][](N, N);\n foreach (i; 0..N) B[i][i] = A[i];\n\n foreach (len; 2..N+1) {\n foreach (l; 0..N-len+1) {\n int r = l + len - 1;\n B[l][r] = B[l+1][r] ^ B[l][r-1];\n }\n }\n\n auto dp = new long[][](N, N);\n foreach (i; 0..N) dp[i][i] = A[i];\n\n foreach (len; 2..N+1) {\n foreach (l; 0..N-len+1) {\n int r = l + len - 1;\n dp[l][r] = B[l][r];\n dp[l][r] = max(dp[l][r], dp[l+1][r]);\n dp[l][r] = max(dp[l][r], dp[l][r-1]);\n }\n }\n\n auto Q = readln.chomp.to!int;\n while (Q--) {\n auto s = readln.split.map!(to!int);\n auto a = s[0] - 1;\n auto b = s[1] - 1;\n dp[a][b].writeln;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n auto dp = new int[][](N, N);\n foreach (i; 0..N) dp[i][i] = A[i];\n\n foreach (len; 2..N+1) {\n foreach (l; 0..N-len+1) {\n int r = l + len - 1;\n if (len == 2 || len % 2 == 1) {\n dp[l][r] = A[l] ^ A[r];\n } else {\n dp[l][r] = A[l] ^ A[l+1] ^ A[r-1] ^ A[r];\n }\n dp[l][r] = max(dp[l][r], dp[l+1][r]);\n dp[l][r] = max(dp[l][r], dp[l][r-1]);\n }\n }\n\n auto Q = readln.chomp.to!int;\n while (Q--) {\n auto s = readln.split.map!(to!int);\n auto a = s[0] - 1;\n auto b = s[1] - 1;\n dp[a][b].writeln;\n }\n}\n"}], "src_uid": "5a686ba072078c9d0258987cb32d00fc"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n int N; get(N);\r\n int[] AA; get(AA);\r\n int[3] cs;\r\n foreach (a; AA) ++cs[a % 3];\r\n int r;\r\n foreach (i; 0..4) {\r\n auto d = max(0, cs[i % 3] - N / 3);\r\n cs[i % 3] -= d;\r\n r += d;\r\n cs[(i + 1) % 3] += d;\r\n }\r\n writeln(r);\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA!int;\r\n\r\n\t\tauto cnt = new int[](3);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\t++cnt[a[i]%3];\r\n\t\t}\r\n\t\tdebug writeln(\"cnt:\", cnt);\r\n\r\n\t\tauto y = n/3;\r\n\t\tbool done;\r\n\t\twhile (!done)\r\n\t\t{\r\n\t\t\tdone = true;\r\n\t\t\tforeach (i; 0..3)\r\n\t\t\t{\r\n\t\t\t\tif (cnt[i] > y)\r\n\t\t\t\t{\r\n\t\t\t\t\tdone = false;\r\n\t\t\t\t\tauto x = cnt[i] - y;\r\n\t\t\t\t\tcnt[i] = y;\r\n\t\t\t\t\tans[ti] += x;\r\n\t\t\t\t\tcnt[(i+1)%3] += x;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tdebug writeln(\"cnt:\", cnt);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = new int [3];\r\n\t\tforeach (ref x; a)\r\n\t\t{\r\n\t\t\tc[x % 3] += 1;\r\n\t\t}\r\n\t\tint res = 0;\r\n\t\tforeach (j; 0..2)\r\n\t\t{\r\n\t\t\tforeach (i; 0..3)\r\n\t\t\t{\r\n\t\t\t\twhile (c[i] > n / 3)\r\n\t\t\t\t{\r\n\t\t\t\t\tc[i] -= 1;\r\n\t\t\t\t\tc[(i + 1) % 3] += 1;\r\n\t\t\t\t\tres += 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "e0de8a6441614d1e41a53223b5fa576b"} {"source_code": "import std.stdio, std.string;\nimport std.conv, std.algorithm;\n\nint[] transform(long num)\n{\n int[] res;\n while (num)\n {\n res ~= (num % 10);\n num /= 10;\n }\n reverse(res);\n return res;\n}\n\nint saiki(int idx, int cnt, int flag, int[][][] dp, int[] d)\n{\n if (dp[idx][cnt][flag] != -1) return dp[idx][cnt][flag];\n if (idx == cast(int)d.length)\n {\n dp[idx][cnt][flag] = 1;\n return 1;\n }\n dp[idx][cnt][flag] = 0;\n auto bound = flag == 0 ? d[idx] : 9;\n foreach (i; 0 .. bound + 1)\n {\n if (i == 0 || cnt < 3)\n {\n auto nextFlag = i < d[idx] ? 1 : flag;\n auto ret = saiki(idx + 1, cnt + (i != 0), nextFlag, dp, d);\n dp[idx][cnt][flag] += ret;\n }\n }\n return dp[idx][cnt][flag];\n}\n\nvoid solve(long left, long right)\n{\n auto dl = transform(left - 1);\n auto dr = transform(right);\n auto m = max(dl.length, dr.length);\n auto dp = new int[][][](m + 1, 4, 2);\n foreach (i; 0 .. m + 1)\n {\n foreach (j; 0 .. 4) fill(dp[i][j], -1);\n }\n auto cl = saiki(0, 0, 0, dp, dl);\n foreach (i; 0 .. m + 1)\n {\n foreach (j; 0 .. 4) fill(dp[i][j], -1);\n }\n auto cr = saiki(0, 0, 0, dp, dr);\n writeln(cr - cl);\n}\n\nint main(string[] drgs)\n{\n auto T = to!int(readln.strip);\n foreach (i; 0 .. T)\n {\n auto p = map!(to!long)(readln.strip.split(' '));\n solve(p[0], p[1]);\n }\n return 0;\n}", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.array;\n\n int t;\n rd(t);\n while (t--) {\n auto args = readln.split.to!(long[]);\n long solve(long nn) {\n auto n = digit(nn);\n auto dp = new long[][][](n.length + 1, 2, 20);\n dp[0][0][0] = 1;\n foreach (i; 0 .. n.length) {\n foreach (l; 0 .. 2) {\n foreach (c; 0 .. 19) {\n auto d = l ? 9 : n[i];\n for (int digit = 0; digit <= d; digit++) {\n auto less = l || (digit < d);\n auto count = c + (digit > 0);\n dp[i + 1][less][count] += dp[i][l][c];\n }\n }\n }\n }\n long ret = 0;\n foreach (l; 0 .. 2) {\n for (int c = 0; c <= 3; c++) {\n ret += dp[n.length][l][c];\n }\n }\n return ret;\n }\n\n writeln(solve(args[1]) - solve(args[0] - 1));\n }\n}\n\nint[] digit(long x) {\n int[] ret;\n do {\n ret = x % 10 ~ ret;\n x /= 10;\n }\n while (x);\n return ret;\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.array;\n\n int t;\n rd(t);\n while (t--) {\n auto args = readln.split.to!(long[]);\n long solve(long s) {\n int[] n;\n do {\n n = s % 10 ~ n;\n s /= 10;\n }\n while (s);\n auto memo = new long[][][](n.length + 1, 2, n.length + 1);\n foreach (i; 0 .. (n.length + 1))\n foreach (j; 0 .. 2)\n foreach (k; 0 .. (n.length + 1))\n memo[i][j][k] = -1;\n long f(size_t i, bool less, int count) {\n if (i == n.length) {\n return count <= 3;\n } else {\n if (memo[i][less][count] >= 0)\n return memo[i][less][count];\n long ret = 0;\n auto digit = less ? 9 : n[i];\n for (int d = 0; d <= digit; d++) {\n auto l = less || (d < digit);\n auto c = count + (d > 0);\n ret += f(i + 1, l, c);\n }\n return memo[i][less][count] = ret;\n }\n }\n\n return f(0, 0, 0);\n }\n\n writeln(solve(args[1]) - solve(args[0] - 1));\n }\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n\n while (t--) {\n long le, r;\n readf(\"%s %s\", &le, &r);\n readln;\n \n long go(string x) {\n int xlen = x.length.to!int;\n \n long getAns(bool alwaysSmaller, int pos, int nonZeroLeft, int allLeft) {\n if (pos >= xlen) { return 1; }\n \n if (alwaysSmaller) {\n if (pos == 0) { //nonZeroLeft and allLeft always > 0\n return 9 * getAns(true, pos+1, nonZeroLeft-1, allLeft-1);\n }\n \n long ret = 0;\n foreach (nrs; 0 .. nonZeroLeft + 1) {\n if (nrs > allLeft) { continue; }\n \n if (nrs == 0) { ret += 1; }\n if (nrs == 1) { ret += 9 * allLeft; }\n if (nrs == 2) { ret += 9 ^^ 2 * allLeft * (allLeft-1) / 2; }\n }\n \n return ret;\n }\n \n long ret = 0;\n int curDig = x[pos] - '0';\n \n if (pos > 0) { ret += getAns(curDig > 0, pos+1, nonZeroLeft, allLeft-1); }\n \n \n if (nonZeroLeft > 0 && curDig > 0) {\n if (curDig > 1) {\n int start = 1;\n int end = x[pos] - '0' - 1;\n int span = end - start + 1;\n ret += span * getAns(true, pos+1, nonZeroLeft-1, allLeft-1);\n }\n \n ret += getAns(false, pos+1, nonZeroLeft-1, allLeft-1);\n } \n \n return ret;\n }\n \n long ans = getAns(false, 0, 3, xlen);\n foreach (digs; 1 .. xlen) { ans += getAns(true, 0, 3, digs); }\n \n return ans;\n }\n \n auto ans = go(r.to!string) - go((le-1).to!string);\n ans.writeln;\n }\n}"}], "negative_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.array;\n\n int t;\n rd(t);\n while (t--) {\n auto args = readln.split.to!(long[]);\n long solve(long nn) {\n auto n = digit(nn);\n auto dp = new long[][][](n.length + 1, 2, 4);\n dp[0][0][0] = 1;\n foreach (i; 0 .. n.length) {\n foreach (l; 0 .. 2) {\n foreach (c; 0 .. 4) {\n auto d = l ? 9 : n[i];\n for (int digit = 0; digit <= d; digit++) {\n auto less = l || (digit < d);\n auto count = max(3, c + (digit > 0));\n dp[i + 1][less][count] += dp[i][l][c];\n }\n }\n }\n }\n long ret = 0;\n foreach (l; 0 .. 2) {\n for (int c = 0; c <= 3; c++) {\n ret += dp[n.length][l][c];\n }\n }\n return ret;\n }\n\n writeln(solve(args[1]) - solve(args[0] - 1));\n }\n}\n\nint[] digit(long x) {\n int[] ret;\n do {\n ret = x % 10 ~ ret;\n x /= 10;\n }\n while (x);\n return ret;\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "src_uid": "993f96a62a2ba75a12684b75a5b2f1ed"} {"source_code": "import std.stdio;\n\nvoid main() {\n int n, p;\n readf(\" %s %s\", &n, &p);\n auto l = new int[n];\n auto r = new int[n];\n foreach (i; 0..n) {\n readf(\" %s %s\", &l[i], &r[i]);\n }\n real exp = 0;\n foreach (i; 0..n) {\n int j = (i + 1) % n;\n int ci = r[i] / p - (l[i] - 1) / p;\n int cj = r[j] / p - (l[j] - 1) / p;\n exp += 1.0 * cj / (r[j] - l[j] + 1);\n exp += 1.0 * ci / (r[i] - l[i] + 1);\n exp -= 1.0 * ci * cj / (r[i] - l[i] + 1) / (r[j] - l[j] + 1);\n }\n writefln(\"%.10f\", exp * 2000);\n}\n", "positive_code": [{"source_code": "import std.stdio,std.conv;\ndouble[100000] pp;\ndouble ans;\nlong n,p,l,r;\nvoid main()\n{\n\tscanf(\" %d %d\",&n,&p);\n\tfor(int i=0;i<n;++i)\n\t{\n\t\tscanf(\" %d %d\",&l,&r);\n\t\tpp[i]=(to!double((l%p==0)+(r%p==0)+((r-1)/p-l/p)))/(r-l+1);\n\t}\n\tint t=to!int(n-1);\n\tans=(pp[0]+pp[t]-pp[0]*pp[t])*1000;\n\tfor(int i=1;i<n;++i)\n\t{\n\t\tans+=(pp[i]+pp[i-1]-pp[i]*pp[i-1])*1000;\n\t}\n\twritef(\"%.10f\",ans*2);\n}\n"}, {"source_code": "import std.stdio,std.conv;\ndouble[100000] pp;\ndouble ans;\nlong n,p,l,r;\nvoid main()\n{\n\tscanf(\" %d %d\",&n,&p);\n\tfor(int i=0;i<n;++i)\n\t{\n\t\tscanf(\" %d %d\",&l,&r);\n\t\tpp[i]=(to!double((r/p-(l-1)/p)))/(r-l+1);\n\t}\n\tint t=to!int(n-1);\n\tans=(pp[0]+pp[t]-pp[0]*pp[t])*1000;\n\tfor(int i=1;i<n;++i)\n\t{\n\t\tans+=(pp[i]+pp[i-1]-pp[i]*pp[i-1])*1000;\n\t}\n\twritef(\"%.10f\",ans*2);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n int n, p;\n readf(\" %s %s\", &n, &p);\n auto l = new int[n];\n auto r = new int[n];\n foreach (i; 0..n) {\n readf(\" %s %s\", &l[i], &r[i]);\n }\n real exp = 0;\n foreach (i; 0..n) {\n int j = (i + 1) % n;\n int ci = r[i] / p - (l[i] - 1) / p;\n int cj = r[j] / p - (l[j] - 1) / p;\n exp += 1.0 * cj / (r[j] - l[j] + 1);\n exp += 1.0 * ci / (r[i] - l[i] + 1);\n exp -= 1.0 * ci * cj / (r[i] - l[i] + 1) / (r[j] - l[j] + 1);\n }\n writeln(exp * 2000);\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n, p;\n readf(\" %s %s\", &n, &p);\n auto l = new int[n];\n auto r = new int[n];\n foreach (i; 0..n) {\n readf(\" %s %s\", &l[i], &r[i]);\n }\n real exp = 0;\n foreach (i; 0..n) {\n int j = (i + 1) % n;\n real denom = 1.0 * (r[i] - l[i] + 1) * (r[j] - l[j] + 1);\n int ci = r[i] / p - (l[i] - 1) / p;\n int cj = r[j] / p - (l[j] - 1) / p;\n exp += cj * (r[i] - l[i] + 1) / denom;\n exp += ci * (r[j] - l[j] + 1) / denom;\n exp -= ci * cj / denom;\n }\n writeln(exp * 2000);\n}\n"}, {"source_code": "import std.stdio,std.conv;\ndouble[100000] pp;\ndouble ans;\nlong n,p,l,r;\nvoid main()\n{\n\tscanf(\" %d %d\",&n,&p);\n\tfor(int i=0;i<n;++i)\n\t{\n\t\tscanf(\" %d %d\",&l,&r);\n\t\tpp[i]=(to!double((l%p==0)+(r%p==0)+((r-1)/p-l/p)))/(r-l+1);\n\t}\n\tint t=to!int(n-1);\n\tans=(pp[0]+pp[t]-pp[0]*pp[t])*1000;\n\tfor(int i=1;i<n;++i)\n\t{\n\t\tans+=(pp[i]+pp[i-1]-pp[i]*pp[i-1])*1000;\n\t}\n\twriteln(ans*2);\n}\n"}, {"source_code": "import std.stdio,std.conv;\ndouble[100000] pp;\ndouble ans;\nlong n,p,l,r;\nvoid main()\n{\n\tscanf(\" %d %d\",&n,&p);\n\tfor(int i=0;i<n;++i)\n\t{\n\t\tscanf(\" %d %d\",&l,&r);\n\t\tpp[i]=(to!double((r/p-(l-1)/p)))/(r-l+1);\n\t}\n\tint t=to!int(n-1);\n\tans=(pp[0]+pp[t]-pp[0]*pp[t])*1000;\n\tfor(int i=1;i<n;++i)\n\t{\n\t\tans+=(pp[i]+pp[i-1]-pp[i]*pp[i-1])*1000;\n\t}\n\twriteln(ans*2);\n}\n"}], "src_uid": "5aad0a82748d931338140ae81fed301d"} {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nlong max(long a, long b)\n{\n\tif (a > b) return a;\n\treturn b;\n}\n\nint main(string[] argv)\n{\n\tlong n;\n\tlong nums;\n\tlong[long] cnt;\n\tscanf(\"%d\", &n);\n\tforeach (long i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums);\n\t\tcnt[nums]++;\n\t}\n\tlong maxk = 0;\n\tforeach (long k; cnt.byKey)\n\t{\n\t\tif (k > maxk) maxk = k;\n\t}\n\t\n\tlong[] dp; dp.length = cast(uint)(maxk + 5);\n\tdp[0] = 0;\n\tdp[1] = (1 in cnt ? cnt[1] : 0);\n\tforeach (uint k; 2..dp.length)\n\t{\n\t\tdp[k] = max(dp[k-1], dp[k-2] + cast(long)k * (k in cnt ? cnt[k] : cast(long)0));\n\t}\n\twrite(dp[$-1]);\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MAX_K = 100_005;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto b = new long [MAX_K];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tb[x + 1]++;\n\t\t}\n\n\t\tauto f = new long [MAX_K];\n\t\tforeach_reverse (i; 0..MAX_K - 2)\n\t\t{\n\t\t\tf[i] = max (f[i + 1], f[i + 2] + (i + 1) * b[i + 2]);\n\t\t}\n\n\t\twriteln (f[0]);\n\t}\n}\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable LIM = 100_005;\n\nint N;\nint[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tlong[] ps = new long[LIM];\n\t\tforeach (i; 0 .. N) {\n\t\t\tps[A[i]] += A[i];\n\t\t}\n\t\t\n\t\tlong[] dp = new long[LIM];\n\t\tforeach (x; 0 .. LIM) {\n\t\t\tdp[x] = ps[x];\n\t\t\tif (x - 1 >= 0) {\n\t\t\t\tchmax(dp[x], dp[x - 1]);\n\t\t\t}\n\t\t\tif (x - 2 >= 0) {\n\t\t\t\tchmax(dp[x], dp[x - 2] + ps[x]);\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(dp[LIM - 1]);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n long[100000 + 1] aps = 0;\n foreach(ai; a)\n aps.at(ai)++;\n long[100000 + 1] dp = 0;\n dp[0] = 0;\n foreach(i; 1 .. dp.length)\n {\n if (i >= 2)\n dp[i] = max(aps.at(i) * cast(long)i\n + dp[i - 2],\n dp[i - 1]);\n else\n dp[i] = max(aps.at(i) * cast(long)i, dp[i - 1]);\n }\n writeln(dp[100000]);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.algorithm, std.range, std.math, std.string;\n\nalias number = long;\n\nvoid main() {\n\tint n;\n\treadf(\" %s \", &n);\n\tassert(1 <= n && n <= 10^^5);\n\tauto a = new number[n];\n\tforeach (ref ai; a)\n\t\treadf(\" %s \", &ai);\n\tnumber prev_max, cur_max;\n\tnumber last_used = -1;\n\tforeach (ref ri; a.sort.group) {\n\t\tnumber new_max;\n\t\tauto value = ri[0] * ri[1];\n\t\tif (last_used == ri[0] - 1) {\n\t\t\tif (cur_max >= prev_max + value) {\n\t\t\t\tnew_max = cur_max;\n\t\t\t} else {\n\t\t\t\tlast_used = ri[0];\n\t\t\t\tnew_max = prev_max + value;\n\t\t\t}\n\t\t} else {\n\t\t\tlast_used = ri[0];\n\t\t\tnew_max = cur_max + value;\n\t\t}\n\t\tprev_max = cur_max;\n\t\tcur_max = new_max;\n\t}\n\twriteln(cur_max);\n}\n"}, {"source_code": "import std.algorithm;\n\nstatic immutable MAXA = 100000 + 1;\n\nulong solve(const uint[] as) {\n\tauto sums = new ulong[](MAXA);\n\tauto dp = new ulong[][](MAXA, 2);\n\n\tforeach (a; as) {\n\t\tsums[a] += a;\n\t}\n\n\tforeach (i; 1..MAXA) {\n\t\tdp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);\n\t\tdp[i][1] = dp[i - 1][0] + sums[i];\n\t}\n\n\treturn max(dp[$ - 1][0], dp[$ - 1][1]);\n}\n\nunittest {\n\t{\n\t\tuint[] as = [1, 2];\n\t\tassert(2 == solve(as));\n\t}\n\n\t{\n\t\tuint[] as = [1, 2, 3];\n\t\tassert(4 == solve(as));\n\t}\n\t\n\t{\n\t\tuint[] as = [1, 2, 1, 3, 2, 2, 2, 2, 3];\n\t\tassert(10 == solve(as));\n\t}\n\n\t{\n\t\tuint[] as = [2, 3, 2, 2, 2, 2, 3];\n\t\tassert(10 == solve(as));\n\t}\n\n\t{\n\t\tuint[] as = [2, 3, 2, 2, 2, 2, 3, 3, 3];\n\t\tassert(12 == solve(as));\n\t}\n\n\t{\n\t\tuint[] as = [666];\n\t\tassert(666 == solve(as));\n\t}\n\n\t{\n\t\tuint[] as = [1];\n\t\tassert(1 == solve(as));\n\t}\n\n\t{\n\t\tuint[] as = [100000];\n\t\tassert(100000 == solve(as));\n\t}\n\n\t{\n\t\tuint[] as = [99999, 100000];\n\t\tassert(100000 == solve(as));\n\t}\n\n\t{\n\t\tuint[] as = [99999, 99999, 100000];\n\t\tassert(199998 == solve(as));\n\t}\n}\n\nint main(string[] argv) {\n\timport std.stdio;\n\tuint n = 0;\n\treadf(\" %s\", &n);\n\tauto as = new uint[](n);\n\tforeach (i; 0..n) {\n\t\treadf(\" %s\", &(as[i]));\n\t}\n\twriteln(solve(as));\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nlong max(long a, long b)\n{\n\tif (a > b) return a;\n\treturn b;\n}\n\nint main(string[] argv)\n{\n\tlong n;\n\tlong nums;\n\tlong[long] cnt;\n\tscanf(\"%d\", &n);\n\tforeach (long i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums);\n\t\tcnt[nums]++;\n\t}\n\tlong maxk = 0;\n\tforeach (long k; cnt.byKey)\n\t{\n\t\tif (k > maxk) maxk = k;\n\t}\n\t\n\tlong[] dp; dp.length = 100005;\n\tdp[0] = 0;\n\tdp[1] = (1 in cnt ? cnt[1] : 0);\n\tforeach (uint k; 2..dp.length)\n\t{\n\t\tdp[k] = max(dp[k-1], dp[k-2] + cast(long)k * (k in cnt ? cnt[k] : cast(long)0));\n\t}\n\twrite(dp[$-1]);\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n;\n\tint[] nums;\n\tint[int] cnt;\n\tscanf(\"%d\", &n); nums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t\tcnt[nums[i]]++;\n\t}\n\tforeach (int k; cnt.byKey)\n\t{\n\t\tcnt[k] *= k;\n\t}\n\tint[] keys = cnt.keys;\n\tkeys.sort!((x, y) => cnt[x] > cnt[y]);\n\tint sum1 = 0;\n\tint sum2 = 0;\n\tint pk1 = -2;\n\tint pk2 = -2;\n\tforeach (int i; 0..keys.length)\n\t{\n\t\tif (keys[i] + 1 != pk1 && keys[i] - 1 != pk1)\n\t\t{\n\t\t\tpk1 = keys[i];\n\t\t\tsum1 += cnt[keys[i]];\n\t\t} else\n\t\tif (keys[i] +1 != pk2 && keys[i] - 1 != pk2)\n\t\t{\n\t\t\tpk2 = keys[i];\n\t\t\tsum2 += cnt[keys[i]];\n\t\t}\n\t}\n\twrite(sum1 > sum2 ? sum1 : sum2);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nlong max(long a, long b)\n{\n\tif (a > b) return a;\n\treturn b;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tint[] nums;\n\tint[int] cnt;\n\tscanf(\"%d\", &n); nums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t\tcnt[nums[i]]++;\n\t}\n\tint maxk = 0;\n\tforeach (int k; cnt.byKey)\n\t{\n\t\tif (k > maxk) maxk = k;\n\t}\n\t\n\tlong[] dp; dp.length = maxk+2;\n\tdp[0] = 0;\n\tdp[1] = (1 in cnt ? cnt[1] : 0);\n\tforeach (int k; 2..(maxk+2))\n\t{\n\t\tdp[k] = max(dp[k-1], dp[k-2] + k * (k in cnt ? cnt[k] : 0));\n\t}\n\twrite(dp[maxk+1]);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint max(int a, int b)\n{\n\tif (a > b) return a;\n\treturn b;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tint[] nums;\n\tint[int] cnt;\n\tscanf(\"%d\", &n); nums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t\tcnt[nums[i]]++;\n\t}\n\tint maxk = 0;\n\tforeach (int k; cnt.byKey)\n\t{\n\t\tcnt[k] *= k;\n\t\tif (k > maxk) maxk = k;\n\t}\n\t\n\tint[] dp; dp.length = maxk+2;\n\tdp[0] = 0;\n\tdp[1] = (1 in cnt ? cnt[1] : 0);\n\tforeach (int k; 2..(maxk+2))\n\t{\n\t\tdp[k] = max(dp[k-1], dp[k-2] + (k in cnt ? cnt[k] : 0));\n\t}\n\twrite(dp[maxk+1]);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n;\n\tint[] nums;\n\tint[int] cnt;\n\tscanf(\"%d\", &n); nums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t\tcnt[nums[i]]++;\n\t}\n\tforeach (int k; cnt.byKey)\n\t{\n\t\tcnt[k] *= k;\n\t}\n\tint[] keys = cnt.keys;\n\tkeys.sort!((x, y) => cnt[x] > cnt[y]);\n\tint sum1 = 0;\n\tint sum2 = 0;\n\tbool[int] sumk1;\n\tbool[int] sumk2;\n\tforeach (int i; 0..keys.length)\n\t{\n\t\tif (!(keys[i] in sumk1))\n\t\t{\n\t\t\tsum1 += cnt[keys[i]];\n\t\t\tsumk1[keys[i]] = true;\n\t\t\tsumk1[keys[i]-1] = true;\n\t\t\tsumk1[keys[i]+1] = true;\n\t\t} else\n\t\tif (!(keys[i] in sumk2))\n\t\t{\n\t\t\tsum2 += cnt[keys[i]];\n\t\t\tsumk2[keys[i]] = true;\n\t\t\tsumk2[keys[i]-1] = true;\n\t\t\tsumk2[keys[i]+1] = true;\n\t\t}\n\t}\n\twrite(sum1 > sum2 ? sum1 : sum2);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n;\n\tint[] nums;\n\tint[int] cnt;\n\tscanf(\"%d\", &n); nums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t\tcnt[nums[i]]++;\n\t}\n\tint sum_1 = 0;\n\tint sum_2 = 0;\n\tforeach (int i; 0..(n/2 + 1))\n\t{\n\t\tint idx1 = 2*i;\n\t\tint idx2 = 2*i+1;\n\t\tsum_1 += idx1 * (idx1 in cnt ? cnt[idx1] : 0);\n\t\tsum_2 += idx2 * (idx2 in cnt ? cnt[idx2] : 0);\n\t}\n\twrite(sum_1 > sum_2 ? sum_1 : sum_2);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nlong max(long a, long b)\n{\n\tif (a > b) return a;\n\treturn b;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tint[] nums;\n\tint[int] cnt;\n\tscanf(\"%d\", &n); nums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t\tcnt[nums[i]]++;\n\t}\n\tint maxk = 0;\n\tforeach (int k; cnt.byKey)\n\t{\n\t\tcnt[k] *= k;\n\t\tif (k > maxk) maxk = k;\n\t}\n\t\n\tlong[] dp; dp.length = maxk+2;\n\tdp[0] = 0;\n\tdp[1] = (1 in cnt ? cnt[1] : 0);\n\tforeach (int k; 2..(maxk+2))\n\t{\n\t\tdp[k] = max(dp[k-1], dp[k-2] + (k in cnt ? cnt[k] : 0));\n\t}\n\twrite(dp[maxk+1]);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n;\n\tint[] nums;\n\tint[int] cnt;\n\tscanf(\"%d\", &n); nums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t\tcnt[nums[i]]++;\n\t}\n\tint points = 0;\n\tbool canPick = true;\n\twhile (canPick)\n\t{\n\t\tint max = int.min;\n\t\tint p = -1;\n\t\tforeach (int k; cnt.byKey)\n\t\t{\n\t\t\tint lm = (k-1) in cnt ? (k-1) * cnt[k-1] : 0;\n\t\t\tlm += (k+1) in cnt ? (k+1) * cnt[k+1] : 0;\n\t\t\tlm = k * cnt[k] - lm;\n\t\t\tif (lm > max)\n\t\t\t{\n\t\t\t\tmax = lm;\n\t\t\t\tp = k;\n\t\t\t}\n\t\t}\n\n\t\tpoints += p; cnt[p]--;\n\t\tcnt.remove(p-1);\n\t\tcnt.remove(p+1);\n\t\tcanPick = cnt[p] != 0;\n\t\tif (!canPick)\n\t\t{\n\t\t\tcnt.remove(p);\n\t\t\tforeach (int k; cnt.byKey)\n\t\t\t\tif (cnt[k] != 0)\n\t\t\t\t{\n\t\t\t\t\tcanPick = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t}\n\twrite(points);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.algorithm, std.range, std.math, std.string;\n\nvoid main() {\n\tint n;\n\treadf(\" %s \", &n);\n\tassert(1 <= n && n <= 10^^5);\n\tauto a = new int[n];\n\tforeach (ref ai; a)\n\t\treadf(\" %s \", &ai);\n\tint prev_max, cur_max;\n\tint last_used = -1;\n\tforeach (ref ri; a.sort.group) {\n\t\tint new_max;\n\t\tint value = ri[0] * ri[1];\n\t\tif (last_used == ri[0] - 1) {\n\t\t\tif (cur_max >= prev_max + value) {\n\t\t\t\tnew_max = cur_max;\n\t\t\t} else {\n\t\t\t\tlast_used = ri[0];\n\t\t\t\tnew_max = prev_max + value;\n\t\t\t}\n\t\t} else {\n\t\t\tlast_used = ri[0];\n\t\t\tnew_max = cur_max + value;\n\t\t}\n\t\tprev_max = cur_max;\n\t\tcur_max = new_max;\n\t}\n\twriteln(cur_max);\n}\n"}], "src_uid": "41b3e726b8146dc733244ee8415383c0"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop, core.checkedint;\n\nbool check(long[] a, long div)\n{\n bool prev = ((a[0] % div) != 0);\n foreach (x ; a[1 .. $]) {\n bool cur = ((x % div) != 0);\n if (cur == prev)\n return false;\n prev = cur;\n }\n return true;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!long).array;\n long[] e, o;\n foreach (i ; 0 .. n) {\n if (i % 2 == 0)\n e ~= a[i];\n else\n o ~= a[i];\n }\n\n long gcdo = o[0];\n foreach (x ; o[1 .. $])\n gcdo = gcd(gcdo, x);\n long gcde = e[0];\n foreach (x ; e[1 .. $])\n gcde = gcd(gcde, x);\n\n if (check(a, gcdo)) {\n writeln(gcdo);\n } else if (check(a, gcde)) {\n writeln(gcde);\n } else {\n writeln(0);\n }\n }\n}\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto a = ma(n, readInt!long);\n\n long[] even, odd;\n foreach(i; 0 .. n)\n {\n if (i%2)\n\t{\n\t odd ~= a[i];\n\t}\n else\n\t{\n\t even ~= a[i];\n\t}\n }\n auto egcd = even.fold!gcd,\n ogcd = odd.fold!gcd;\n if (odd.all!(ai => ai % egcd != 0)) return writeln(egcd);\n if (even.all!(ai => ai % ogcd != 0)) return writeln(ogcd);\n return writeln(0);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan;\n auto arr = scanArray;\n long gcd1 = arr[0];\n for(int i = 2; i < n; i += 2){\n gcd1 = gcd(gcd1, arr[i]);\n }\n long gcd2 = arr[1];\n for(int i = 3; i < n; i += 2){\n gcd2 = gcd(gcd2, arr[i]);\n }\n show(gcd1, gcd2);\n\n bool f = 1;\n for(int i = 1; i < n; i += 2){\n if(arr[i] % gcd1 == 0){\n f = 0;\n break;\n }\n }\n if(f){\n writeln(gcd1);\n return;\n }\n\n f = 1;\n for(int i = 0; i < n; i += 2){\n if(arr[i] % gcd2 == 0){\n f = 0;\n break;\n }\n }\n if(f){\n writeln(gcd2);\n return;\n }\n\n writeln(0);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool check(long[] a, long div)\n{\n bool prev = ((a[0] % div) != 0);\n foreach (x ; a[1 .. $]) {\n bool cur = ((x % div) != 0);\n if (cur == prev)\n return false;\n prev = cur;\n }\n return true;\n}\n\n// From: https://rosettacode.org/wiki/Least_common_multiple#D\nT lcm(T)(T m, T n) pure nothrow {\n if (m == 0) return m;\n if (n == 0) return n;\n return abs((m * n) / gcd(m, n));\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!long).array;\n long[] b;\n foreach (i ; 1 .. n) {\n long x = a[i], y = a[i - 1];\n if (x > y)\n swap(x, y);\n if (y % x == 0)\n b ~= y / x;\n b ~= x;\n b ~= y;\n }\n\n long ans = 0;\n foreach (div ; b) {\n if (check(a, div)) {\n ans = div;\n break;\n }\n }\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool check(long[] a, long div)\n{\n bool prev = ((a[0] % div) != 0);\n foreach (x ; a[1 .. $]) {\n bool cur = ((x % div) != 0);\n if (cur == prev)\n return false;\n prev = cur;\n }\n return true;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!long).array;\n long ans = 0;\n foreach (div ; a) {\n if (check(a, div)) {\n ans = div;\n break;\n }\n }\n writeln(ans);\n }\n}\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto a = ma(n, readInt!int);\n\n int[] even, odd;\n foreach(i; 0 .. n)\n {\n if (i%2)\n\t{\n\t odd ~= a[i];\n\t}\n else\n\t{\n\t even ~= a[i];\n\t}\n }\n auto egcd = even.fold!gcd,\n ogcd = odd.fold!gcd;\n if (odd.all!(ai => ai % egcd != 0)) return writeln(egcd);\n if (even.all!(ai => ai % ogcd != 0)) return writeln(ogcd);\n return writeln(0);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "e6c91f6872c4dd845cb7a156aacab7c7"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array;\n\nint[] removeminmax(int[] a, int min_x, int max_x)\n{\n auto l = a.countUntil!(x => (x == min_x || x == max_x));\n a = a.dup.reverse;\n auto r = a.countUntil!(x => (x == min_x || x == max_x));\n if (l < r) {\n a.reverse;\n return a[l + 1 .. $];\n } else {\n return a[r + 1 .. $];\n }\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n int min_x = a.minElement;\n int max_x = a.maxElement;\n int[] step1 = removeminmax(a, min_x, max_x);\n int[] step2 = removeminmax(step1, min_x, max_x);\n writeln(a.length - step2.length);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.stdio, std.string;\r\n\r\nvoid main() {\r\n foreach(t; 0 .. to!int(readln.strip)) {\r\n int n = to!int(readln.strip);\r\n auto ar = readln.strip.split.map!(to!int);\r\n int mn = ar.countUntil(1), mx = ar.countUntil(n);\r\n if(mn > mx) swap(mn, mx);\r\n writeln(min(n-mn, mx+1, n-mx+mn+1));\r\n }\r\n}\r\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1538/problem/A\n// \nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nint abs(int x) {\n return x > 0 ? x : -x;\n}\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(to!int).array;\n\n int maxima = a.maxElement;\n int minima = a.minElement;\n\n int left = 0;\n int right;\n\n for(int i = 0; i < n; ++i) {\n left += 1;\n if(a[i] == maxima || a[i] == minima) {\n break;\n }\n }\n\n for(int i = n - 1; i >= 0; --i) {\n right += 1;\n if(a[i] == maxima || a[i] == minima) {\n break;\n }\n }\n\n //left.writeln;\n //right.writeln;\n\n int between = abs(left - n + right - 1);\n //between.writeln;\n int[] ans = [left, right, between];\n ans.sort;\n //ans.writeln;\n (ans[0] + ans[1]).writeln;\n}\n}\n"}], "negative_code": [], "src_uid": "d5fc2bc618dd9d453a5e7ae30ccb73f3"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n Tuple!(int, int)[][] vals;\n foreach (_; 0 .. 2) vals ~= readln.chomp.split.map!(to!int).enumerate.map!(t => tuple(cast(int)t[0], t[1])).array;\n\n debug { vals.writeln; }\n \n auto ans = new int[][] (n, m);\n \n foreach_reverse (b; 0 .. 31) {\n auto cur = 1 << b;\n \n auto f = (Tuple!(int, int)[] arr) => arr.filter!(t => (t[1] & cur) > 0).map!(t => t[0]).array;\n auto nrs = vals.map!f.array;\n \n debug { if (b < 4) writeln(cur, ' ', nrs[0], ' ', nrs[1]); }\n \n if (nrs[0].length % 2 != nrs[1].length % 2) {\n writeln(\"NO\");\n return;\n }\n \n if (nrs[0].length % 2 == 0) { // both even from above\n if (nrs[0].empty) foreach (j; nrs[1]) ans[0][j] ^= cur;\n else if (nrs[1].empty) foreach (i; nrs[0]) ans[i][0] ^= cur;\n else {\n while (nrs[0].length < nrs[1].length) nrs[0] ~= nrs[0].back;\n while (nrs[1].length < nrs[0].length) nrs[1] ~= nrs[1].back;\n foreach (i, j; lockstep(nrs[0], nrs[1])) ans[i][j] ^= cur;\n }\n } else { // both odd\n foreach (i; nrs[0]) {\n foreach (j; nrs[1]) {\n ans[i][j] ^= cur;\n }\n }\n }\n }\n \n writeln(\"YES\");\n ans.each!(arr => arr.writefln!(\"%(%s %)\"));\n}", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m; rd(n, m);\n auto a=readln.split.to!(int[]);\n auto b=readln.split.to!(int[]);\n\n auto ax=a.reduce!((r, e)=>(r^e)),\n bx=b.reduce!((r, e)=>(r^e));\n if(ax!=bx){writeln(\"NO\"); return;}\n writeln(\"YES\");\n write(a[0]^b[0]^bx, \" \");\n writefln(\"%(%s %)\", b[1..$]);\n foreach(i; 1..n){\n write(a[i], \" \");\n auto zero=new int[](m-1);\n writefln(\"%(%s %)\", zero);\n }\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array;\n\n long a = 0;\n long b = 0;\n\n foreach (i; 0..N) a ^= A[i];\n foreach (i; 0..M) b ^= B[i];\n\n if (a != b) {\n writeln(\"NO\");\n return;\n }\n\n a = 0;\n b = 0;\n auto ans = new long[][](N, M);\n foreach (i; 0..N-1) ans[i][M-1] = A[i], a ^= A[i];\n foreach (j; 0..M-1) ans[N-1][j] = B[j], b ^= B[j];\n ans[N-1][M-1] = a ^ B[M-1];\n\n writeln(\"YES\");\n ans.each!(a => a.map!(to!string).join(\" \").writeln);\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n Tuple!(int, int)[][] vals;\n foreach (_; 0 .. 2) vals ~= readln.chomp.split.map!(to!int).enumerate.map!(t => tuple(cast(int)t[0], t[1])).array;\n\n debug { vals.writeln; }\n \n auto ans = new int[][] (n, m);\n \n foreach_reverse (b; 0 .. 31) {\n auto cur = 1 << b;\n \n auto f = (Tuple!(int, int)[] arr) => arr.filter!(t => (t[1] & cur) > 0).map!(t => t[0]).array;\n auto nrs = vals.map!f.array;\n \n debug { if (b < 4) writeln(cur, ' ', nrs[0], ' ', nrs[1]); }\n \n if (nrs[0].length % 2 != nrs[1].length % 2) {\n writeln(\"NO\");\n return;\n }\n \n if (nrs[0].length == 0) {\n foreach (j; nrs[1]) ans[0][j] ^= cur;\n } else if (nrs[1].length == 0) {\n foreach (i; nrs[0]) ans[i][0] ^= cur;\n } else if (nrs[0].length % 2 == 1) { // && nrs[1].length % 2 == 1 from above\n foreach (i; nrs[0]) {\n foreach (j; nrs[1]) {\n ans[i][j] ^= cur;\n }\n }\n } else {\n while (nrs[0].length < nrs[1].length) nrs[0] ~= nrs[1].back;\n while (nrs[1].length < nrs[0].length) nrs[1] ~= nrs[0].back;\n foreach (i, j; lockstep(nrs[0], nrs[1])) ans[i][j] ^= cur;\n }\n }\n \n writeln(\"YES\");\n ans.each!(arr => arr.writefln!(\"%(%s %)\"));\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n Tuple!(int, int)[][] vals;\n foreach (_; 0 .. 2) vals ~= readln.chomp.split.map!(to!int).enumerate.map!(t => tuple(cast(int)t[0], t[1])).array;\n\n debug { vals.writeln; }\n \n auto ans = new int[][] (n, m);\n \n foreach_reverse (b; 0 .. 31) {\n auto cur = 1 << b;\n \n auto f = (Tuple!(int, int)[] arr) => arr.filter!(t => (t[1] & cur) > 0).map!(t => t[0]).array;\n auto nrs = vals.map!f.array;\n \n debug { if (b < 4) writeln(cur, ' ', nrs[0], ' ', nrs[1]); }\n \n if (nrs[0].length % 2 != nrs[1].length % 2) {\n writeln(\"NO\");\n return;\n }\n \n if (nrs[0].length == 0) {\n foreach (j; nrs[1]) ans[0][j] ^= cur;\n } else if (nrs[1].length == 0) {\n foreach (i; nrs[0]) ans[i][0] ^= cur;\n } else if (nrs[0].length % 2 == 1) { // && nrs[1].length % 2 == 1 from above\n foreach (i; nrs[0]) {\n foreach (j; nrs[1]) {\n ans[i][j] ^= cur;\n }\n }\n } else {\n while (nrs[0].length < nrs[1].length) nrs[0] ~= nrs[1].back;\n while (nrs[1].length < nrs[0].length) nrs[1] ~= nrs[0].back;\n foreach (i, j; lockstep(nrs[0], nrs[1])) ans[i][j] ^= cur;\n }\n }\n \n ans.each!(arr => arr.writefln!(\"%(%s %)\"));\n}"}], "src_uid": "3815d18843dbd15a73383d69eb6880dd"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\tauto l = RD;\r\n\tauto k = RD!int;\r\n\tauto d = RDA ~ l;\r\n\tauto a = RDA;\r\n\r\n\tauto dp = new long[][](n, k+1);\r\n\tforeach (i; 0..n)\r\n\t\tdp[i][] = -1;\r\n\tdp[0][k] = 0;\r\n\tforeach (i; 1..n)\r\n\t{\r\n\t\tauto ndp = new long[][](n, k+1);\r\n\t\tforeach (j; 0..n)\r\n\t\t\tndp[j][] = -1;\r\n\t\tforeach (j; 0..i)\r\n\t\t{\r\n\t\t\tforeach (m; 0..k+1)\r\n\t\t\t{\r\n\t\t\t\tif (dp[j][m] == -1) continue;\r\n\t\t\t\tndp[i][m].chmax(dp[j][m]);\r\n\t\t\t\tif (m != 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tndp[j][m-1].chmax(dp[j][m] + (a[i] - a[j]) * (d[i+1] - d[i]));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tdp = ndp;\r\n\t\tdebug writeln(dp);\r\n\t}\r\n\r\n\tlong ans;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tans += a[i] * (d[i+1] - d[i]);\r\n\t}\r\n\tlong tmp;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tforeach (j; 0..k+1)\r\n\t\t{\r\n\t\t\ttmp.chmax(dp[i][j]);\r\n\t\t}\r\n\t}\r\n\tans -= tmp;\r\n\r\n\twriteln(ans);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{\r\n immutable int INF = int.max;\r\n\r\n int n, t, k;\r\n readf!\"%s %s %s\"(n, t, k);\r\n readln;\r\n\r\n auto d = readln.chomp.split.map!(to!int).array;\r\n auto a = readln.chomp.split.map!(to!int).array;\r\n\r\n d ~= t;\r\n\r\n auto dp = new int[][] (n+1, k+1);\r\n dp[n][] = 0;\r\n foreach (i; 0 .. n) { dp[i][] = INF; }\r\n\r\n foreach_reverse (i; 0 .. n) {\r\n foreach (maxk; 0 .. k+1) {\r\n if (maxk > 0) { dp[i][maxk] = dp[i][maxk-1]; }\r\n for (int nxt = i+1, leftk = maxk; nxt <= n && leftk >= 0; ++nxt, --leftk) {\r\n auto cur = dp[nxt][leftk] + (d[nxt] - d[i]) * a[i];\r\n dp[i][maxk] = min(dp[i][maxk], cur);\r\n }\r\n }\r\n }\r\n\r\n debug { dp.writeln; }\r\n\r\n dp[0][k].writeln;\r\n}"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto N = scan!int;\r\n auto L = scan!long;\r\n auto K = scan!int;\r\n auto X = scan!long(N) ~ L;\r\n auto S = scan!long(N) ~ 0;\r\n\r\n auto solve() {\r\n auto dp = new long[][](N, K + 1);\r\n foreach(ref p; dp) p[] = int.max;\r\n dp[0][0] = X[1] * S[0];\r\n auto preDp = new long[][](N, K + 1);\r\n\r\n foreach(i; 1..N) {\r\n // dp.deb;\r\n swap(dp, preDp);\r\n dp = new long[][](N, K + 1);\r\n foreach(ref p; dp) p[] = int.max;\r\n const distance = X[i + 1] - X[i];\r\n\r\n foreach(from; 0..i) {\r\n foreach(skipped; 0..K) {\r\n dp[from][skipped + 1].chmin(preDp[from][skipped] + S[from]*distance);\r\n }\r\n foreach(skipped; 0..K + 1) {\r\n dp[i][skipped].chmin(preDp[from][skipped] + S[i]*distance);\r\n }\r\n }\r\n }\r\n // dp.deb;\r\n\r\n return dp.map!minElement.minElement;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nenum int INF = 1<<30;\r\n\r\nvoid main() {\r\n int N, L, K; readf(\"%d %d %d\\n\", &N, &L, &K);\r\n auto D = readarray!int ~ [L];\r\n auto A = readarray!int ~ [0];\r\n N++;\r\n\r\n auto f = new int[][](K + 1, N + 1);\r\n auto nf = new int[][](K + 1, N + 1);\r\n foreach (ref l; f) l[] = INF;\r\n f[0][0] = 0;\r\n for (int n = 1; n < N; n++) {\r\n foreach (ref l; nf) l[] = INF;\r\n int d = D[n] - D[n-1];\r\n for (int k = 0; k <= min(K, n); k++) {\r\n for (int s = 0; s < n; s++) {\r\n nf[k][n] = min(nf[k][n], f[k][s] + d * A[s]);\r\n if (k + 1 <= min(K, n)) {\r\n nf[k + 1][s] = min(nf[k + 1][s], f[k][s] + d * A[s]);\r\n }\r\n }\r\n }\r\n swap(f, nf);\r\n }\r\n int ans = INF;\r\n for (int k = 0; k <= K; k++) {\r\n ans = min(ans, f[k].reduce!min);\r\n }\r\n writeln(ans);\r\n}\r\n"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{\r\n immutable int INF = int.max;\r\n\r\n int n, t, k;\r\n readf!\"%s %s %s\"(n, t, k);\r\n readln;\r\n\r\n auto d = readln.chomp.split.map!(to!int).array;\r\n auto a = readln.chomp.split.map!(to!int).array;\r\n\r\n d ~= t;\r\n\r\n auto dp = new int[][] (n+1, k+1);\r\n dp[n][] = 0;\r\n foreach (i; 0 .. n) { dp[i][] = INF; }\r\n\r\n foreach_reverse (i; 0 .. n) {\r\n foreach (maxk; 0 .. k+1) {\r\n for (int nxt = i+1, leftk = maxk; nxt <= n && leftk >= 0; ++nxt, --leftk) {\r\n auto cur = dp[nxt][leftk] + (d[nxt] - d[i]) * a[i];\r\n dp[i][maxk] = min(dp[i][maxk], cur);\r\n }\r\n }\r\n }\r\n\r\n debug { dp.writeln; }\r\n\r\n dp[0][k].writeln;\r\n}"}], "negative_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto N = scan!int;\r\n auto L = scan!long;\r\n auto K = scan!int;\r\n auto X = scan!long(N) ~ L;\r\n auto S = scan!long(N) ~ 0;\r\n\r\n struct Run {\r\n long time;\r\n long speed;\r\n\r\n int opCmp(Run other) {\r\n if (time > other.time) return 1;\r\n if (time < other.time) return -1;\r\n\r\n return speed > other.speed ? 1 : speed == other.speed ? 0 : -1;\r\n }\r\n }\r\n\r\n auto solve() {\r\n auto dp = new Run[][](N, K + 1);\r\n foreach(ref d; dp) foreach(ref x; d) x = Run(int.max, int.max);\r\n dp[0][0] = Run(S[0] * X[1], S[0]);\r\n\r\n foreach(i; 1..N) {\r\n auto pre = dp[i - 1];\r\n const d = X[i + 1] - X[i];\r\n const speed = S[i];\r\n\r\n foreach(k; 0..K) {\r\n if (pre[k].speed == int.max) continue;\r\n\r\n const preSpeed = pre[k].speed;\r\n const newTime = pre[k].time + preSpeed * d;\r\n auto run = Run(newTime, preSpeed);\r\n dp[i][k + 1].chmin(run);\r\n }\r\n foreach(k; 0..K + 1) {\r\n if (pre[k].speed == int.max) continue;\r\n\r\n const newTime = pre[k].time + speed * d;\r\n auto run = Run(newTime, speed);\r\n dp[i][k].chmin(run);\r\n }\r\n }\r\n\r\n dp.each!deb;\r\n // dp.deb;\r\n return dp[N - 1].map!\"a.time\".minElement;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto N = scan!int;\r\n auto L = scan!long;\r\n auto K = scan!int;\r\n auto X = scan!long(N) ~ L;\r\n auto S = scan!long(N) ~ 0;\r\n\r\n auto solve() {\r\n alias Run = Tuple!(long, \"time\", long, \"speed\");\r\n auto dp = new Run[][](N, K + 1);\r\n foreach(ref d; dp) foreach(ref x; d) x = Run(int.max, int.max);\r\n dp[0][0] = Run(S[0] * X[1], S[0]);\r\n\r\n foreach(i; 1..N) {\r\n auto pre = dp[i - 1];\r\n const d = X[i + 1] - X[i];\r\n const speed = S[i];\r\n\r\n foreach(k; 0..K) {\r\n if (pre[k].speed == int.max) continue;\r\n\r\n const preSpeed = pre[k].speed;\r\n const newTime = pre[k].time + preSpeed * d;\r\n if (dp[i][k + 1].time > newTime) {\r\n dp[i][k + 1] = Run(newTime, preSpeed);\r\n }\r\n }\r\n foreach(k; 0..K + 1) {\r\n if (pre[k].speed == int.max) continue;\r\n\r\n const newTime = pre[k].time + speed * d;\r\n if (dp[i][k].time > newTime) {\r\n dp[i][k] = Run(newTime, speed);\r\n }\r\n }\r\n }\r\n\r\n dp.each!deb;\r\n // dp.deb;\r\n return dp[N - 1].map!\"a.time\".minElement;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto N = scan!int;\r\n auto L = scan!long;\r\n auto K = scan!int;\r\n auto X = scan!long(N) ~ L;\r\n auto S = scan!long(N) ~ 0;\r\n\r\n auto solve() {\r\n alias Run = Tuple!(long, \"time\", long, \"speed\");\r\n auto dp = new Run[][](N, K + 1);\r\n foreach(ref d; dp) d[] = Run(int.max, int.max);\r\n dp[0][0] = Run(S[0] * X[1], S[0]);\r\n\r\n foreach(i; 1..N) {\r\n auto pre = dp[i - 1];\r\n const d = X[i + 1] - X[i];\r\n const speed = S[i];\r\n\r\n foreach(k; 0..K) {\r\n if (pre[k].speed == int.max) continue;\r\n\r\n const preSpeed = pre[k].speed;\r\n const newTime = pre[k].time + preSpeed * d;\r\n if (dp[i][k + 1].time > newTime) {\r\n dp[i][k + 1] = Run(newTime, preSpeed);\r\n }\r\n }\r\n foreach(k; 0..K + 1) {\r\n if (pre[k].speed == int.max) continue;\r\n\r\n const newTime = pre[k].time + speed * d;\r\n if (dp[i][k].time > newTime) {\r\n dp[i][k] = Run(newTime, speed);\r\n }\r\n }\r\n }\r\n\r\n // dp.each!deb;\r\n\r\n // dp.deb;\r\n return dp[N - 1].map!\"a.time\".minElement;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto N = scan!int;\r\n auto L = scan!long;\r\n auto K = scan!int;\r\n auto X = scan!long(N) ~ L;\r\n auto S = scan!long(N) ~ 0;\r\n\r\n auto solve() {\r\n alias Run = Tuple!(long, \"time\", long, \"speed\");\r\n auto dp = new Run[][](N, K + 1);\r\n foreach(ref d; dp) d[] = Run(int.max, int.max);\r\n dp[0][0] = Run(S[0] * X[1], S[0]);\r\n\r\n foreach(i; 1..N) {\r\n auto pre = dp[i - 1];\r\n const d = X[i + 1] - X[i];\r\n const speed = S[i];\r\n\r\n foreach(k; 0..K) {\r\n const preSpeed = pre[k].speed;\r\n const newTime = pre[k].time + preSpeed * d;\r\n if (dp[i][k + 1].time > newTime) {\r\n dp[i][k + 1] = Run(newTime, preSpeed);\r\n }\r\n }\r\n foreach(k; 0..K + 1) {\r\n const newTime = pre[k].time + speed * d;\r\n if (dp[i][k].time > newTime) {\r\n dp[i][k] = Run(newTime, speed);\r\n }\r\n }\r\n }\r\n\r\n // dp.deb;\r\n return dp[N - 1].map!\"a.time\".minElement;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto N = scan!int;\r\n auto L = scan!int;\r\n auto K = scan!int;\r\n auto X = scan!int(N) ~ L;\r\n auto S = scan!int(N) ~ 0;\r\n\r\n auto solve() {\r\n alias Run = Tuple!(long, \"time\", long, \"speed\");\r\n auto dp = new Run[][](N, K + 1);\r\n foreach(ref d; dp) d[] = Run(int.max, int.max);\r\n dp[0][0] = Run(S[0] * X[1], S[0]);\r\n\r\n foreach(i; 1..N) {\r\n auto pre = dp[i - 1];\r\n const d = X[i + 1] - X[i];\r\n const speed = S[i];\r\n\r\n foreach(k; 0..K) {\r\n const preSpeed = pre[k].speed;\r\n const newTime = pre[k].time + preSpeed * d;\r\n if (dp[i][k + 1].time > newTime) {\r\n dp[i][k + 1] = Run(newTime, preSpeed);\r\n }\r\n }\r\n foreach(k; 0..K + 1) {\r\n const newTime = pre[k].time + speed * d;\r\n if (dp[i][k].time > newTime) {\r\n dp[i][k] = Run(newTime, speed);\r\n }\r\n }\r\n }\r\n\r\n // dp.deb;\r\n return dp[N - 1].map!\"a.time\".minElement;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\tauto l = RD;\r\n\tauto k = RD!int;\r\n\tauto d = RDA ~ l;\r\n\tauto a = RDA;\r\n\r\n\tauto dp = new long[][](n, k+1);\r\n\tforeach (i; 1..n)\r\n\t{\r\n\t\tauto ndp = new long[][](n, k+1);\r\n\t\tforeach (j; 0..i)\r\n\t\t{\r\n\t\t\tforeach (m; 0..k+1)\r\n\t\t\t{\r\n\t\t\t\tndp[i][m].chmax(dp[j][m]);\r\n\t\t\t\tif (m != 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tndp[j][m-1].chmax(dp[j][m] + (a[i] - a[j]) * (d[i+1] - d[i]));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tdp = ndp;\r\n\t\tdebug writeln(dp);\r\n\t}\r\n\r\n\tlong ans;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tans += a[i] * (d[i+1] - d[i]);\r\n\t}\r\n\tlong tmp;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tforeach (j; 0..k+1)\r\n\t\t{\r\n\t\t\ttmp.chmax(dp[i][j]);\r\n\t\t}\r\n\t}\r\n\tans -= tmp;\r\n\r\n\twriteln(ans);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "dd62b6860b6a4cf33aef89c2f674331f"} {"source_code": "import std.stdio, std.array, std.range, std.string, std.typecons;\nimport std.algorithm, std.container, std.math, std.numeric, std.random;\nvoid scan(T...)(ref T args) { foreach (ref arg; args) readf(\" %s\", &arg); }\nvoid minify(T)(ref T a, in T b) { if (a > b) a = b; }\nvoid maxify(T)(ref T a, in T b) { if (a < b) a = b; }\nvoid ewriteln(T...)(T args) { stderr.writeln(\"\\033[35m\", args, \"\\033[0m\"); }\nint ilen(T)(const ref T a) { return cast(int)(a.length); }\n\n// ok i'm half asleep this was not a good idea (no pun intended)\n\nstruct Edge {\n\tint v1, v2;\n\tbool w, u;\n}\n\nenum int N = 100008;\nenum long OO = 10L ^^ 18;\nint n, m;\nsize_t[][N] graph;\nlong[N] dist;\nsize_t[N] parent;\n\nint[N] heap;\nsize_t[N] invheap;\nsize_t heaplen;\n\nvoid hpush(int v) {\n\theaplen++;\n\theap[heaplen] = v;\n\tinvheap[v] = heaplen;\n\tpercUpIx(heaplen);\n}\nvoid hswap(size_t i1, size_t i2) {\n\tswap(heap[i1], heap[i2]);\n\tswap(invheap[heap[i1]], invheap[heap[i2]]);\n}\nvoid percUpIx(size_t ix) {\n\tif (ix == 1) return;\n\tsize_t parent = ix / 2;\n\tif (dist[heap[parent]] > dist[heap[ix]]) {\n\t\thswap(parent, ix);\n\t\tpercUpIx(parent);\n\t}\n}\nvoid percDownIx(size_t ix) {\n\tsize_t tgt = ix;\n\tforeach (tix; tuple(2*ix, 2*ix + 1)) {\n\t\tif (tix <= heaplen && dist[heap[tix]] < dist[heap[tgt]]) {\n\t\t\ttgt = tix;\n\t\t}\n\t}\n\tif (tgt != ix) {\n\t\thswap(tgt, ix);\n\t\tpercDownIx(tgt);\n\t}\n}\nvoid percUp(int v) { percUpIx(invheap[v]); }\nint hpop() {\n\tassert(heaplen > 0);\n\tint ret = heap[1];\n\thswap(1, heaplen);\n\theaplen--;\n\tpercDownIx(1);\n\treturn ret;\n}\n\nEdge[N] edges;\n\nbool[N] vis;\n\nvoid printDiff() {\n\tint v = n;\n\twhile (v != 1) {\n\t\tauto ei = parent[v];\n\t\tedges[ei].u = true;\n\t\tEdge e = edges[ei];\n\t\te.u = true;\n\t\tassert(v == e.v1 || v == e.v2);\n\t\tv = e.v1 ^ e.v2 ^ v;\n\t}\n\tint count = 0;\n\tforeach (ei; 0..m) {\n\t\tEdge e = edges[ei];\n\t\tif (e.w ^ e.u) {\n\t\t\tcount++;\n\t\t}\n\t}\n\twriteln(count);\n\tforeach (ei; 0..m) {\n\t\tEdge e = edges[ei];\n\t\tif (e.w ^ e.u) {\n\t\t\twriteln(e.v1, \" \", e.v2, \" \", e.u ? 1 : 0);\n\t\t}\n\t}\n}\n\nvoid main() {\n\tscan(n, m);\n\tforeach (i; 0..m) {\n\t\tint a, b, w;\n\t\tscan(a, b, w);\n\t\tedges[i] = Edge(a, b, cast(bool)w, false);\n\t\tgraph[a] ~= i;\n\t\tgraph[b] ~= i;\n\t}\n\tforeach (v; 2..n+1) {\n\t\tdist[v] = OO;\n\t}\n\thpush(1);\n\twhile (true) {\n\t\tint nxt = hpop();\n\t\tvis[nxt] = true;\n\t\tif (nxt == n) {\n\t\t\tprintDiff();\n\t\t\treturn;\n\t\t}\n\t\tforeach (ei; graph[nxt]) {\n\t\t\tEdge e = edges[ei];\n\t\t\tassert(nxt == e.v1 || nxt == e.v2);\n\t\t\tint other = e.v1 ^ e.v2 ^ nxt;\n\t\t\tlong newdist = dist[nxt] + N + (e.w ? -1 : 1);\n\t\t\tif (newdist < dist[other]) {\n\t\t\t\tparent[other] = ei;\n\t\t\t\tif (dist[other] == OO) {\n\t\t\t\t\tdist[other] = newdist;\n\t\t\t\t\thpush(other);\n\t\t\t\t} else {\n\t\t\t\t\tdist[other] = newdist;\n\t\t\t\t\tpercUp(other);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N, M;\nint[] A, B, C;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tM = readInt;\n\t\tA = new int[M];\n\t\tB = new int[M];\n\t\tC = new int[M];\n\t\tforeach (i; 0 .. M) {\n\t\t\tA[i] = readInt - 1;\n\t\t\tB[i] = readInt - 1;\n\t\t\tC[i] = readInt;\n\t\t}\n\t\t\n\t\tauto g = new int[][N];\n\t\tforeach (i; 0 .. M) {\n\t\t\tg[A[i]] ~= i;\n\t\t\tg[B[i]] ~= i;\n\t\t}\n\t\t\n\t\tint[] q;\n\t\tint[] d = new int[N];\n\t\td[] = -1;\n\t\tint[] dp = new int[N];\n\t\tdp[] = int.min;\n\t\tint[] prv = new int[N];\n\t\tprv[] = -1;\n\t\t\n\t\td[0] = 0;\n\t\tq ~= 0;\n\t\tdp[0] = 0;\n\t\tfor (; !q.empty; ) {\n\t\t\tconst u = q.front; q.popFront;\n\t\t\tforeach (i; g[u]) {\n\t\t\t\tconst v = A[i] ^ B[i] ^ u;\n\t\t\t\tif (d[v] == -1) {\n\t\t\t\t\td[v] = d[u] + 1;\n\t\t\t\t\tq ~= v;\n\t\t\t\t}\n\t\t\t\tif (d[v] == d[u] + 1) {\n\t\t\t\t\tif (dp[v] < dp[u] + C[i]) {\n\t\t\t\t\t\tdp[v] = dp[u] + C[i];\n\t\t\t\t\t\tprv[v] = i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\ndebug{\nwriteln(\"d = \",d);\nwriteln(\"dp = \",dp);\nwriteln(\"prv = \",prv);\n}\n\t\t\n\t\tbool[] used = new bool[M];\n\t\tPair!(int, Pair!(int, int))[] anss;\n\t\tfor (int u = N - 1; u != 0; ) {\n\t\t\tconst i = prv[u];\n\t\t\tused[i] = true;\n\t\t\tif (C[i] == 0) {\n\t\t\t\tanss ~= pair(1, pair(A[i], B[i]));\n\t\t\t}\n\t\t\tu = A[i] ^ B[i] ^ u;\n\t\t}\n\t\tforeach (i; 0 .. M) if (!used[i]) {\n\t\t\tif (C[i] == 1) {\n\t\t\t\tanss ~= pair(0, pair(A[i], B[i]));\n\t\t\t}\n\t\t}\n\t\twriteln(anss.length);\n\t\tforeach (ans; anss) {\n\t\t\twriteln(ans.y.x + 1, \" \", ans.y.y + 1, \" \", ans.x);\n\t\t}\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "a7d3548c4bc356b4bcd40fca7fe839b2"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\t\tint balance = 0;\n\t\tint lo = 0;\n\t\tlong res = s.length;\n\t\tforeach (i, char c; s)\n\t\t{\n\t\t\tbalance += (c == '+') ? +1 : -1;\n\t\t\tif (lo > balance)\n\t\t\t{\n\t\t\t\tlo = balance;\n\t\t\t\tres += i + 1;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\n\t\tlong last;\n\t\tlong cnt;\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tif (s[i] == '-')\n\t\t\t\t--cnt;\n\t\t\telse\n\t\t\t\t++cnt;\n\n\t\t\tif (cnt < last)\n\t\t\t{\n\t\t\t\t--last;\n\t\t\t\tans[ti] += i+1;\n\t\t\t}\n\t\t}\n\t\tans[ti] += s.length;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.algorithm;\n\nvoid main() {\n\tint t;\n\tscanf(\"%d\\n\", &t);\n\n\twhile (t--) {\t\n\t\tauto s = stdin.byLine.front;\n\t\tint n = s.length;\n\n\t\tint[] first_neg_i = repeat(-1, n + 3).array;\n\n\n\t\tint cur = 0;\n\t\tforeach (i, c; s) {\n\t\t\tif (c == '-') cur--;\n\t\t\telse cur++;\n\n\t\t\tif (cur < 0 && first_neg_i[-cur] == -1)\n\t\t\t\tfirst_neg_i[-cur] = i + 1;\n\t\t}\n\n\t\tlong res = 0;\n\t\tint next = 1;\n\t\twhile (true) {\n\t\t\tif (first_neg_i[next] != -1) {\n\t\t\t\tres += first_neg_i[next++];\n\t\t\t} else {\n\t\t\t\tres += n;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tres.writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\n\t\tlong last;\n\t\tlong cnt;\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tif (s[i] == '-')\n\t\t\t\t--cnt;\n\t\t\telse\n\t\t\t\t++cnt;\n\n\t\t\tif (cnt < last)\n\t\t\t{\n\t\t\t\t--last;\n\t\t\t\tans[ti] += i+1;\n\t\t\t}\n\t\t}\n\t\tans[ti] += s.length;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "07eecfe948aa78623586b5e30e84e415"} {"source_code": "import std.stdio;\nimport std.algorithm : max;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%d %d %d\\n\", &n, &m, &k);\n auto t = new int[n + 1];\n auto s = new long[n + 1];\n auto w = new long[n + 1];\n auto p = new long[n + 1];\n foreach(i; 1 .. n + 1)\n {\n readf(\" %d\", &t[i]);\n if (i)\n s[i] = s[i - 1] + t[i];\n }\n\n foreach(i; 0 .. k)\n {\n foreach(j; m .. n + 1)\n w[j] = max(w[j - 1], p[j - m] + s[j] - s[j - m]);\n p = w.dup;\n }\n writeln(w[n]);\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n int n, m, k;\n readf(\" %s %s %s\", &n, &m, &k);\n auto a = new int [n];\n auto sum = new long [n];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n sum[i] = a[i];\n if (i > 0) {\n sum[i] += sum[i-1];\n }\n }\n auto f = new long [][] (n, k);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < k; j++) {\n if (i - 1 >= 0) { \n f[i][j] = f[i - 1][j];\n }\n long q = sum[i] - (i - m >= 0 ? sum[i - m] : 0);\n f[i][j] = max(f[i][j], (i - m >= 0 && j - 1 >= 0 ? f[i - m][j - 1] : 0) + q);\n if (i - 1 >= 0) { \n f[i][j] = max(f[i - 1][j], f[i][j]);\n }\n }\n }\n writeln(f[n - 1][k - 1]);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto K = s[2];\n auto A = readln.split.map!(to!long).array;;\n \n auto B = new long[](N-M+1);\n B[0] = 0;\n foreach (i; 0..M)\n B[0] += A[i];\n foreach (i; M..N) {\n B[i-M+1] = B[i-M] - A[i-M] + A[i];\n }\n\n \n auto dp = new long[][](N-M+1, K);\n foreach (i; 0..N-M+1)\n fill(dp[i], 0);\n dp[0][0] = B[0];\n\n foreach (i; 1..N-M+1) {\n dp[i][0] = B[i];\n foreach (j; 0..K) {\n dp[i][j] = max(dp[i][j], dp[i-1][j]);\n if (i >= M && j > 0) {\n dp[i][j] = max(dp[i][j], dp[i-M][j-1]+B[i]);\n dp[i][j] = max(dp[i][j], dp[i-M][j]);\n }\n }\n }\n\n //B.writeln;\n //dp.each!(writeln);\n dp[N-M][K-1].writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto K = s[2];\n auto A = readln.split.map!(to!long).array;;\n \n auto B = new long[](N-M+1);\n B[0] = 0;\n foreach (i; 0..M)\n B[0] += A[i];\n foreach (i; M..N) {\n B[i-M+1] = B[i-M] - A[i-M] + A[i];\n }\n\n \n auto dp = new long[][](N-M+1, K);\n foreach (i; 0..N-M+1)\n fill(dp[i], 0);\n dp[0][0] = B[0];\n\n foreach (i; 1..N-M+1) {\n dp[i][0] = max(dp[i-1][0], B[i]);\n foreach (j; 1..K) {\n if (i >= M)\n dp[i][j] = max(dp[i-1][j-1]+B[i], dp[i-1][j]);\n }\n }\n\n dp[N-M][K-1].writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm : max;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%d %d %d\\n\", &n, &m, &k);\n auto t = new int[n + 1];\n auto s = new long[n + 1];\n auto w = new long[n + 1];\n auto p = new long[n + 1];\n foreach(i; 1 .. n + 1)\n {\n readf(\" %d\", &t[i]);\n if (i)\n s[i] = s[i - 1] + t[i];\n }\n\n foreach(i; 0 .. k)\n {\n writeln(s);\n writeln(w);\n foreach(j; m .. n + 1)\n w[j] = max(w[j - 1], p[j - m] + s[j] - s[j - m]);\n p = w.dup;\n }\n writeln(w[n]);\n}"}], "src_uid": "ee3c228cc817536bf6c10ea4508d786f"} {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int n; readf!\"%s\\n\"(n);\r\n alias NodeType = Tuple!(int, \"v\", int, \"x\");\r\n NodeType[] a;\r\n foreach(i; 0 .. n) {\r\n int x, y; readf!\"%s %s\\n\"(x, y);\r\n a ~= NodeType(x + y, x);\r\n }\r\n a.sort;\r\n RedBlackTree!(long, \"a > b\", true) hl = make!(RedBlackTree!(long, \"a > b\", true))();\r\n RedBlackTree!(long, \"a < b\", true) hr = make!(RedBlackTree!(long, \"a < b\", true))();\r\n foreach(i; 0 .. n + 1) {\r\n hl.insert(0);\r\n hr.insert(0);\r\n }\r\n int last;\r\n long tag, ans;\r\n foreach(i; 0 .. n) {\r\n int d = a[i].v - last;\r\n last = a[i].v;\r\n tag += d;\r\n int x = a[i].x;\r\n if (x <= hl.front) {\r\n ans += hl.front - x;\r\n hl.insert(x);\r\n hl.insert(x);\r\n hr.insert(hl.front - tag);\r\n hl.removeFront;\r\n }\r\n else if (x >= hr.front + tag) {\r\n ans += x - (hr.front + tag);\r\n hr.insert(x - tag);\r\n hr.insert(x - tag);\r\n hl.insert(hr.front + tag);\r\n hr.removeFront;\r\n }\r\n else {\r\n hl.insert(x);\r\n hr.insert(x - tag);\r\n }\r\n }\r\n ans.writeln;\r\n\r\n} // main", "positive_code": [{"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int n; readf!\"%s\\n\"(n);\r\n alias NodeType = Tuple!(int, \"v\", int, \"x\");\r\n NodeType[] a;\r\n foreach(i; 0 .. n) {\r\n int x, y; readf!\"%s %s\\n\"(x, y);\r\n a ~= NodeType(x + y, x);\r\n }\r\n a.sort;\r\n BinaryHeap!(Array!long) hl;\r\n BinaryHeap!(Array!long, \"a > b\") hr;\r\n foreach(i; 0 .. n + 1) {\r\n hl.insert(0);\r\n hr.insert(0);\r\n }\r\n int last;\r\n long tag, ans;\r\n foreach(i; 0 .. n) {\r\n int d = a[i].v - last;\r\n last = a[i].v;\r\n tag += d;\r\n int x = a[i].x;\r\n if (x <= hl.front) {\r\n ans += hl.front - x;\r\n hl.insert(x);\r\n hl.insert(x);\r\n hr.insert(hl.front() - tag);\r\n hl.popFront;\r\n }\r\n else if (x >= hr.front + tag) {\r\n ans += x - (hr.front + tag);\r\n hr.insert(x - tag);\r\n hr.insert(x - tag);\r\n hl.insert(hr.front + tag);\r\n hr.popFront;\r\n }\r\n else {\r\n hl.insert(x);\r\n hr.insert(x - tag);\r\n }\r\n }\r\n ans.writeln;\r\n\r\n} // main"}], "negative_code": [], "src_uid": "2df96204e085fb8c28f56b6ffddc0714"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tif (a == b)\n\t\t\tans[ti] = 0;\n\t\telse if (b > a)\n\t\t\tans[ti] = (b - a) % 2 == 0 ? 2 : 1;\n\t\telse\n\t\t\tans[ti] = (a - b) % 2 == 0 ? 1 : 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio : readln, writeln;\n\nstruct IO {\n import std.conv : to;\n import std.range : empty, front, popFront, split;\n\n string readToken() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n\n int readInt() {\n return readToken.to!int;\n }\n\n string[] tokens;\n}\n\nint solve(int a, int b) {\n if (a == b) {\n return 0;\n }\n if (a < b) {\n return (b & 1) == (a & 1) ? 2 : 1;\n }\n return (b & 1) == (a & 1) ? 1 : 2;\n}\n\nvoid main() {\n IO io;\n int T = io.readInt;\n while (T--) {\n int a = io.readInt;\n int b = io.readInt;\n writeln(solve(a, b));\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. rint){\n int a = rint, b = rint;\n if(a < b){\n if((b - a) % 2) 1.writeln;\n else 2.writeln;\n }\n else if(a == b) 0.writeln;\n else{\n if((a - b) % 2) 2.writeln;\n else 1.writeln;\n }\n }\n}"}, {"source_code": "import std.stdio;\n\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\tif (a==b)\n\t\t{\n\t\t\twriteln(0);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (((b-a)%2==1 && b>a) || ((b-a)%2==0 && b<a))\n\t\t\t{\n\t\t\t\twriteln(1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twriteln(2);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "fcd55a1ca29e96c05a3b65b7a8103842"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n immutable int MAX = 2 * 10 ^^ 5 + 1;\n \n auto starts = new int[][] (MAX);\n auto end = new int[] (n+1);\n \n foreach (i; 0 .. n) {\n int le, r;\n readf(\"%s %s\", &le, &r);\n readln;\n \n starts[le] ~= i+1;\n end[i+1] = r;\n }\n \n alias seg = Tuple!(int, int);\n auto rbt = make!(RedBlackTree!seg);\n \n int[] ans;\n foreach (p; 0 .. MAX) {\n foreach (e; starts[p]) {\n rbt.insert(seg(end[e], e));\n }\n \n while (rbt.length > k) {\n ans ~= rbt.back[1];\n rbt.removeBack();\n }\n \n while (!rbt.empty() && rbt.front[0] == p) {\n rbt.removeFront();\n }\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(' ').writeln;\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n immutable int MAX = 200 + 1;\n \n auto starts = new int[][] (MAX);\n auto ends = new int[] (n+1);\n \n foreach (i; 0 .. n) {\n int le, r;\n readf(\"%s %s\", &le, &r);\n readln;\n \n starts[le] ~= i+1;\n ends[i+1] = r;\n }\n \n auto rbt = make!(RedBlackTree!(Tuple!(int, int)));\n \n int cur = 0;\n int[] ans;\n foreach (p; 0 .. MAX) {\n foreach (e; starts[p]) {\n ++cur;\n rbt.insert(tuple(ends[e], e));\n }\n \n while (cur > k) {\n ans ~= rbt.back[1];\n rbt.removeBack();\n --cur;\n }\n \n while (!rbt.empty() && rbt.front[0] == p) {\n rbt.removeFront();\n --cur;\n }\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(' ').writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n immutable int MAX = 2 * 10 ^^ 5 + 1;\n \n auto starts = new int[][] (MAX);\n auto ends = new int[] (n+1);\n \n foreach (i; 0 .. n) {\n int le, r;\n readf(\"%s %s\", &le, &r);\n readln;\n \n starts[le] ~= i+1;\n ends[i+1] = r;\n }\n \n auto rbt = make!(RedBlackTree!(Tuple!(int, int)));\n \n int[] ans;\n foreach (p; 0 .. MAX) {\n foreach (e; starts[p]) {\n rbt.insert(tuple(ends[e], e));\n }\n \n while (rbt.length > k) {\n ans ~= rbt.back[1];\n rbt.removeBack();\n }\n \n while (!rbt.empty() && rbt.front[0] == p) {\n rbt.removeFront();\n }\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(' ').writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n immutable int MAX = 2 * 10 ^^ 5 + 1;\n \n auto starts = new int[][] (MAX);\n auto end = new int[] (n+1);\n \n foreach (i; 0 .. n) {\n int le, r;\n readf(\"%s %s\", &le, &r);\n readln;\n \n starts[le] ~= i+1;\n end[i+1] = r;\n }\n \n auto rbt = make!(RedBlackTree!(Tuple!(int, int)));\n \n int[] ans;\n foreach (p; 0 .. MAX) {\n foreach (e; starts[p]) {\n rbt.insert(tuple(end[e], e));\n }\n \n while (rbt.length > k) {\n ans ~= rbt.back[1];\n rbt.removeBack();\n }\n \n while (!rbt.empty() && rbt.front[0] == p) {\n rbt.removeFront();\n }\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(' ').writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n immutable int MAX = 2 * 10 ^^ 5 + 1;\n \n auto starts = new int[][] (MAX);\n auto ends = new int[] (n+1);\n \n foreach (i; 0 .. n) {\n int le, r;\n readf(\"%s %s\", &le, &r);\n readln;\n \n starts[le] ~= i+1;\n ends[i+1] = r;\n }\n \n auto rbt = make!(RedBlackTree!(Tuple!(int, int)));\n \n int cur = 0;\n int[] ans;\n foreach (p; 0 .. MAX) {\n foreach (e; starts[p]) {\n ++cur;\n rbt.insert(tuple(ends[e], e));\n }\n \n while (cur > k) {\n ans ~= rbt.back[1];\n rbt.removeBack();\n --cur;\n }\n \n while (!rbt.empty() && rbt.front[0] == p) {\n rbt.removeFront();\n --cur;\n }\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(' ').writeln;\n}"}], "negative_code": [], "src_uid": "7f9c5a137e9304d4d7eee5ee1a891d1d"} {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\tint m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tint u;\n\t\t\tint v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto c = new int [n];\n\n\t\tvoid recur (int v, int cur)\n\t\t{\n\t\t\tdebug {writeln (v, \" \", cur);}\n\t\t\tif ((c[v] & cur) == cur)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tc[v] |= cur;\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\trecur (u, cur ^ 3);\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (c[i] == 0)\n\t\t\t{\n\t\t\t\trecur (i, 1);\n\t\t\t}\n\t\t}\n\n\t\tif (n.iota.any !(x => c[x] == 3))\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 1..3)\n\t\t\t{\n\t\t\t\tauto ans =\n\t\t\t\t n.iota.filter !(x => c[x] == i).array;\n\t\t\t\twritefln (\"%s\\n%(%s %)\",\n\t\t\t\t ans.length, ans.map !(x => x + 1));\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nimmutable int MAXN = cast(int)5e5;\n\nint N, M;\nint[][MAXN] G;\nint[MAXN] d;\nint[] A, B;\nbool correct = 1;\n\nvoid dfs(int v, int col) {\n\td[v] = col;\n\tforeach(u; G[v]) {\n\t\tif (!d[u]) dfs(u, -col);\n\t\telse if (d[u] == d[v]) correct = 0;\n\t}\n}\n\nvoid print(int[] arr) {\n\tprintf(\"%d\\n\", arr.length);\n\tforeach(i; arr) printf(\"%d \", i);\n\tprintf(\"\\n\");\n}\n\nvoid main() {\n\treadf(\"%d %d\\n\", &N, &M);\n\tfor (int i = 0; i < M; ++i) {\n\t\tint u, v; readf(\"%d %d\\n\", &u, &v);\n\t\tG[u] ~= v; G[v] ~= u;\n\t}\n\tfor (int i = 1; i <= N; ++i) if (!d[i]) dfs(i, 1);\n\tif (!correct) { \n\t\twritef(\"-1\\n\"); return;\n\t}\n\tfor (int i = 1; i <= N; ++i) (d[i] == 1 ? A : B) ~= i;\n\tprint(A); print(B);\n}"}, {"source_code": "import std.stdio;\nimport std.container: DList;\n\n\nint opposite_color(int c) {\n if (c == 1) return 2;\n return 1;\n}\n\n\nvoid main() {\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n int[][] graph;\n int[] colors;\n graph.length = n;\n colors.length = n;\n int first_colors = 0;\n int second_colors = 0;\n\n for(int i = 0; i < m; ++i) {\n int u, v;\n readf(\"%d %d\\n\", &u, &v);\n --u;\n --v;\n graph[u] ~= v;\n graph[v] ~= u;\n }\n bool possible = true;\nouterLoop:\n foreach (int i, int color; colors) {\n if (color == 0 && graph[i].length != 0) {\n auto queue = DList!int();\n queue.insertBack(i);\n while (!queue.empty()) {\n int u = queue.front;\n queue.removeFront(1);\n foreach (int j, int v; graph[u]) {\n if (colors[v] != 0 && colors[v] == colors[u]) {\n possible = false;\n break outerLoop;\n } else if (colors[v] == 0) {\n int opColor = opposite_color(colors[u]);\n colors[v] = opColor;\n if (opColor == 1) first_colors++;\n else second_colors++;\n queue.insertBack(v);\n }\n }\n }\n }\n }\n\n if (possible) {\n writeln(first_colors);\n foreach(int i, int c; colors) {\n if(c == 1) {\n write(i+1, \" \");\n }\n }\n writeln();\n writeln(second_colors);\n foreach(int i, int c; colors) {\n if(c == 2) {\n write(i+1, \" \");\n }\n }\n writeln();\n } else {\n writeln(-1);\n }\n}\n"}], "negative_code": [], "src_uid": "810f267655da0ad14538c275fd13821d"} {"source_code": "import std.stdio : File, writeln, writefln;\nimport std.array;\nimport std.range;\nimport std.algorithm : min;\n\nint n;\nint[] arr;\n\nvoid swap(T)(ref T a, ref T b){\n\tT tmp = a;\n\ta = b;\n\tb = tmp;\n}\n\nFile ifp;\nFile ofp;\n\nvoid main(){\n\tifp = File(\"input.txt\", \"r\");\n\tofp = File(\"output.txt\", \"w\");\n\t\n\tchar[] l = ['B', 'G'];\n\t\n\tint n = next!int();\n\tint m = next!int();\n\t\n\tauto str = cycle(l[]).take(min(n, m)*2).array;\n\t\n\tif(n>m){\n\t\tofp.write = str;\n\t\tofp.write = repeat('B').take(n-m).array;\n\t}else{\n\t\tofp.write = repeat('G').take(m-n).array;\n\t\tofp.write = str;\n\t}\n\t\n\tofp.writeln;\n}\n\nimport std.stdio : readln, chomp;\nimport std.conv : to;\nimport std.string : split;\nshared string[] input;\nshared string delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nvoid next(T)(ref T v){\n\tv = next!T();\n}\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\treturn true;\n\t}\n\t\n//\tstring str = readln;\n\tstring str = ifp.readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn true;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n", "positive_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nstring b=\"B\",g=\"G\";\nvoid main(){\n stdin=File(\"input.txt\",\"r\");\n stdout=File(\"output.txt\",\"w\");\n int n,m;\n readf!\"%d %d\"(n,m);\n readln;\n if(m<n){\n swap(b,g);\n swap(n,m);\n }\n writeln((g~b).replicate(n)~g.replicate(m-n));\n}\n\n"}, {"source_code": "module cf_253A;\n\nimport std.stdio, std.algorithm;\n\nvoid main() {\n File fin = File(\"input.txt\", \"r\");\n File fout = File(\"output.txt\", \"w\");\n int n, m;\n\n fin.readf(\"%d %d\", &n, &m);\n\n string pair = (n > m)? \"BG\": \"GB\";\n for (int i = min(n, m); i > 0; --i) {\n fout.writef(\"%s\", pair);\n }\n for (int i = n - min(n, m); i > 0; --i) {\n fout.writef(\"B\");\n }\n for (int i = m - min(n, m); i > 0; --i) {\n fout.writef(\"G\");\n }\n fout.writeln();\n}"}], "negative_code": [{"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nstring b=\"B\",g=\"G\";\nvoid main(){\n int n,m;\n scanf(\"%d %d\",&n,&m);\n if(m<n){\n swap(b,g);\n swap(n,m);\n }\n writeln((g~b).replicate(n)~g.replicate(m-n));\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nstring b=\"B\",g=\"G\";\nvoid main(){\n stdin=File(\"input.txt\",\"r\");\n stdout=File(\"output.txt\",\"w\");\n int n,m;\n scanf(\"%d %d\",&n,&m);\n if(m<n){\n swap(b,g);\n swap(n,m);\n }\n writeln((g~b).replicate(n)~g.replicate(m-n));\n}\n\n"}, {"source_code": "module cf_253A;\n\nimport std.stdio, std.algorithm;\n\nvoid main() {\n int n, m;\n\n readf(\"%d %d\", &n, &m);\n\n string pair = (n > m)? \"BG\": \"GB\";\n for (int i = min(n, m); i > 0; --i) {\n writef(\"%s\", pair);\n }\n for (int i = n - min(n, m); i > 0; --i) {\n writef(\"B\");\n }\n for (int i = m - min(n, m); i > 0; --i) {\n writef(\"G\");\n }\n writeln();\n}"}, {"source_code": "module cf_253A;\n\nimport std.stdio, std.algorithm;\n\nvoid main() {\n int n, m;\n\n readf(\"%d %d\", &n, &m);\n\n string pair = (n > m)? \"BG\": \"GB\";\n for (int i = min(n, m); i > 0; --i) {\n writef(\"%s\", pair);\n }\n for (int i = n - min(n, m); i > 0; --i) {\n writef(\"B\");\n }\n for (int i = m - min(n, m); i > 0; --i) {\n writef(\"G\");\n }\n}"}], "src_uid": "5392996bd06bf52b48fe30b64493f8f5"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tS[] as = rlong(n).map!(v => S(v, 1)).array;\n\n\tauto sta = new Stack!S;\n\tforeach(a; as){\n\t\twhile(sta.length > 0 && sta.peek.gt(a)){\n\t\t\tS b = sta.pop;\n\t\t\ta = S(b.sum + a.sum, b.count + a.count);\n\t\t}\n\t\tsta.push(a);\n\t}\n\n\tS[] ans = sta.array;\n\tforeach(an; ans){\n\t\tforeach(i; 0 .. an.count) writefln(\"%10.10f\", an.sum.to!real / an.count.to!real);\n\t}\n\n}\n\nstruct S{\n\tlong sum;\n\tint count;\n\tbool lt(S b){ return sum * b.count < b.sum * count; }\n\tbool gt(S b){ return sum * b.count > b.sum * count; }\n\tbool le(S b){ return !gt(b); }\n\tbool ge(S b){ return !lt(b); }\n}\n\n// ----- \u30b9\u30bf\u30c3\u30af -----\nclass Stack(T){\n\tprivate T[] xs;\n\tprivate uint j; // j : \u6b21\u306b\u66f8\u304d\u8fbc\u3080\u4f4d\u7f6e\n\tthis(){\t}\n\tthis(T[] xs){ this.xs = xs; j = xs.length.to!uint; }\n\tuint length(){ return j; }\n\tbool isEmpty(){ return j == 0; }\n\tvoid push(T x){\n\t\twhile(j + 1 >= xs.length) xs.length = xs.length * 2 + 1;\n\t\txs[j ++] = x;\n\t}\n\tT pop(){ assert(j > 0); return xs[-- j]; }\n\tT peek(){ assert(j > 0); return xs[j - 1]; }\n\tT opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }\n\tstatic Stack!T opCall(){ return new Stack!T; }\n\tstatic Stack!T opCall(T[] xs){ return new Stack!T(xs); }\n\tT[] array(){ return xs[0 .. j]; }\n\toverride string toString(){ return array.to!string; }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int len;\n auto numers = new long[N];\n auto denoms = new long[N];\n foreach_reverse (i; 0 .. N) {\n long p = A[i], q = 1;\n for (; len >= 1 && numers[len - 1] * q <= p * denoms[len - 1]; ) {\n p += numers[len - 1];\n q += denoms[len - 1];\n --len;\n }\n numers[len] = p;\n denoms[len] = q;\n ++len;\n }\n foreach_reverse (j; 0 .. len) {\n const ans = cast(real)(numers[j]) / denoms[j];\n foreach (_; 0 .. denoms[j]) {\n writefln(\"%.10f\", ans);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto s = [0L];\n\t\ts.reserve (n + 1);\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\ts ~= s.back + c;\n\t\t}\n\n\t\tauto p = [0, 1];\n\t\tforeach (i; 2..n + 1)\n\t\t{\n\t\t\twhile (p.length > 1 &&\n\t\t\t (s[i] - s[p[$ - 1]]) * 1L * (i - p[$ - 2]) <=\n\t\t\t (s[i] - s[p[$ - 2]]) * 1L * (i - p[$ - 1]))\n\t\t\t{\n\t\t\t\tp.popBack ();\n\t\t\t\tp.assumeSafeAppend ();\n\t\t\t}\n\t\t\tp ~= i;\n\t\t}\n\n\t\tauto answer = new real [n];\n\t\tforeach (j; 1..p.length)\n\t\t{\n\t\t\treal cur = s[p[j]] - s[p[j - 1]];\n\t\t\tcur /= p[j] - p[j - 1];\n\t\t\tforeach (i; p[j - 1]..p[j])\n\t\t\t{\n\t\t\t\tanswer[i] = cur;\n\t\t\t}\n\t\t}\n\t\tforeach (const ref c; answer)\n\t\t{\n\t\t\twritefln (\"%.10f\", c);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "3b5b8c54dc9956e7060c7f154eebd063"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto P = new long[N];\n foreach (i; 0 .. N) {\n P[i] = readLong();\n }\n const X = readLong();\n const A = readInt();\n const Y = readLong();\n const B = readInt();\n const K = readLong();\n \n sort(P);\n reverse(P);\n \n bool check(int l) {\n auto zs = new long[l];\n foreach (i; 0 .. l) {\n if ((i + 1) % A == 0) {\n zs[i] += X;\n }\n if ((i + 1) % B == 0) {\n zs[i] += Y;\n }\n }\n sort(zs);\n reverse(zs);\n long sum;\n foreach (i; 0 .. l) {\n sum += P[i] / 100 * zs[i];\n }\n return (sum >= K);\n }\n \n int lo = -1, hi = N + 1;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n check(mid) ? (hi = mid) : (lo = mid);\n }\n writeln((hi <= N) ? hi : -1);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint tests;\n\treadf (\" %s\", &tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\treadf (\" %s\", &n);\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tsort (p);\n\t\treverse (p);\n\t\tp[] /= 100;\n\t\tint x, a;\n\t\treadf (\" %s %s\", &x, &a);\n\t\tint y, b;\n\t\treadf (\" %s %s\", &y, &b);\n\t\tlong k;\n\t\treadf (\" %s\", &k);\n\n\t\tint solve ()\n\t\t{\n\t\t\tint lo = 1;\n\t\t\tint hi = n + 1;\n\t\t\twhile (lo < hi)\n\t\t\t{\n\t\t\t\tint me = (lo + hi) / 2;\n\t\t\t\tauto q = p;\n\t\t\t\tlong total = 0;\n\t\t\t\tfor (int i = 1; i <= me; i++)\n\t\t\t\t{\n\t\t\t\t\tif (i % a == 0 && i % b == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\ttotal += q.front * (x + y);\n\t\t\t\t\t\tq.popFront ();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int i = 1; i <= me; i++)\n\t\t\t\t{\n\t\t\t\t\tif (i % a == 0 && i % b != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\ttotal += q.front * (x + 0);\n\t\t\t\t\t\tq.popFront ();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int i = 1; i <= me; i++)\n\t\t\t\t{\n\t\t\t\t\tif (i % a != 0 && i % b == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\ttotal += q.front * (0 + y);\n\t\t\t\t\t\tq.popFront ();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (total >= k)\n\t\t\t\t{\n\t\t\t\t\thi = me;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlo = me + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn lo;\n\t\t}\n\n\t\tauto res = solve ();\n\t\tswap (x, y);\n\t\tswap (a, b);\n\t\tres = min (res, solve ());\n\t\tif (res == n + 1)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "4835d79ad6055a7c9eb5d4566befeafc"} {"source_code": "import std.container, std.range, std.stdio, std.typecons;\n\nalias Piece = Tuple !(int, q{a}, int, q{b}, int, q{l}, int, q{u});\n\nvoid main ()\n{\n\tint n, q;\n\twhile (readf (\" %s %s\", &n, &q) > 0)\n\t{\n\t\tauto s = redBlackTree !(Piece) ();\n\t\ts.insert (Piece (1, n, 0, 0));\n\t\tforeach (k; 0..q)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar t;\n\t\t\treadf (\" %s %s %s\", &x, &y, &t);\n\t\t\tauto cur = Piece (x, n + 1, 0, 0);\n\t\t\tauto r = s.lowerBound (cur);\n\t\t\tauto prev = r.empty ? Piece.init : r.back;\n\t\t\tint c = x;\n\t\t\twith (prev)\n\t\t\t{\n\t\t\t\tif (c < a || b < c)\n\t\t\t\t{\n\t\t\t\t\twriteln (0);\n\t\t\t\t}\n\t\t\t\telse if (t == 'L')\n\t\t\t\t{\n\t\t\t\t\ts.removeKey (prev);\n\t\t\t\t\twriteln (x - l);\n\t\t\t\t\tif (a <= c - 1)\n\t\t\t\t\t{\n\t\t\t\t\t\ts.insert (Piece (a, c - 1,\n\t\t\t\t\t\t l, y));\n\t\t\t\t\t}\n\t\t\t\t\tif (c + 1 <= b)\n\t\t\t\t\t{\n\t\t\t\t\t\ts.insert (Piece (c + 1, b,\n\t\t\t\t\t\t l, u));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (t == 'U')\n\t\t\t\t{\n\t\t\t\t\ts.removeKey (prev);\n\t\t\t\t\twriteln (y - u);\n\t\t\t\t\tif (a <= c - 1)\n\t\t\t\t\t{\n\t\t\t\t\t\ts.insert (Piece (a, c - 1,\n\t\t\t\t\t\t l, u));\n\t\t\t\t\t}\n\t\t\t\t\tif (c + 1 <= b)\n\t\t\t\t\t{\n\t\t\t\t\t\ts.insert (Piece (c + 1, b,\n\t\t\t\t\t\t x, u));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tassert (false);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Piece = Tuple !(int, q{a}, int, q{b}, int, q{l}, int, q{u});\n\nvoid main ()\n{\n\tint n;\n\tint q;\n\twhile (readf (\" %s %s\", &n, &q) > 0)\n\t{\n\t\tauto s = redBlackTree !(Piece) ();\n\t\ts.insert (Piece (1, n, 0, 0));\n\t\tforeach (k; 0..q)\n\t\t{\n\t\t\tint x;\n\t\t\tint y;\n\t\t\tchar t;\n\t\t\treadf (\" %s %s %s\", &x, &y, &t);\n\t\t\tauto cur = Piece (x, n + 1, 0, 0);\n\t\t\tauto r = s.lowerBound (cur);\n\t\t\tauto prev = r.empty ? Piece.init : r.back;\n\t\t\tint c = x;\n\t\t\twith (prev)\n\t\t\t{\n\t\t\t\tif (c < a || b < c)\n\t\t\t\t{\n\t\t\t\t\twriteln (0);\n\t\t\t\t}\n\t\t\t\telse if (t == 'L')\n\t\t\t\t{\n\t\t\t\t\ts.removeKey (prev);\n\t\t\t\t\twriteln (x - l);\n\t\t\t\t\tif (a <= c - 1)\n\t\t\t\t\t{\n\t\t\t\t\t\ts.insert (Piece (a, c - 1,\n\t\t\t\t\t\t l, y));\n\t\t\t\t\t}\n\t\t\t\t\tif (c + 1 <= b)\n\t\t\t\t\t{\n\t\t\t\t\t\ts.insert (Piece (c + 1, b,\n\t\t\t\t\t\t l, u));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (t == 'U')\n\t\t\t\t{\n\t\t\t\t\ts.removeKey (prev);\n\t\t\t\t\twriteln (y - u);\n\t\t\t\t\tif (a <= c - 1)\n\t\t\t\t\t{\n\t\t\t\t\t\ts.insert (Piece (a, c - 1,\n\t\t\t\t\t\t l, u));\n\t\t\t\t\t}\n\t\t\t\t\tif (c + 1 <= b)\n\t\t\t\t\t{\n\t\t\t\t\t\ts.insert (Piece (c + 1, b,\n\t\t\t\t\t\t x, u));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tassert (false);\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (s[].map !(text).join (\"\\n\"));}\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "870720d864ce169db2037f19f029719c"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto A = readarray!int;\r\n long ans = 0;\r\n for (long i = 0; i <= N - 1; i++) {\r\n ans += (i + N - 1) * (N - i) / 2L - i * (N - i) + (N - i);\r\n }\r\n\r\n for (int i = 0; i + 1 < N; i++) {\r\n if (A[i] == A[i + 1]) {\r\n long l = i + 1;\r\n long r = N - i - 1;\r\n ans -= l * r;\r\n }\r\n }\r\n\r\n foreach (q; 0 .. M) {\r\n int i, x; readf(\"%d %d\\n\", &i, &x);\r\n i--;\r\n if (i - 1 >= 0) {\r\n if (A[i - 1] != A[i] && A[i - 1] == x) {\r\n long lc = i;\r\n long rc = N - i;\r\n ans -= lc * rc;\r\n }\r\n if (A[i - 1] == A[i] && A[i - 1] != x) {\r\n long lc = i;\r\n long rc = N - i;\r\n ans += lc * rc;\r\n }\r\n }\r\n if (i + 1 < N) {\r\n if (A[i + 1] != A[i] && A[i + 1] == x) {\r\n long lc = i + 1;\r\n long rc = N - i - 1;\r\n ans -= lc * rc;\r\n }\r\n if (A[i + 1] == A[i] && A[i + 1] != x) {\r\n long lc = i + 1;\r\n long rc = N - i - 1;\r\n ans += lc * rc;\r\n }\r\n }\r\n A[i] = x;\r\n writeln(ans);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nconst bool dbg = true;\r\nvoid DBG(alias x)() { static if (dbg) stderr.writefln(\"DBG: %s = %s\", x.stringof, x); }\r\nvoid MSG(in string x) { static if (dbg) stderr.writefln(\"MSG: %s\", x); }\r\n\r\nvoid main() {\r\n int N, M; scanf(\"%d %d\\n\", &N, &M);\r\n auto A = readln.chomp.split(\" \").map!(to!long).array;\r\n\r\n long f(long N) {\r\n long x = N * (N + 1) / 2;\r\n long y = N * (N + 1) * (2 * N + 1) / 6;\r\n return N * x + x - y;\r\n }\r\n\r\n long T = f(N);\r\n long D = 0;\r\n for (int i = 0; i + 1 < N; i++) {\r\n if (A[i] == A[i + 1]) {\r\n D += cast(long)(i + 1) * cast(long)(N - (i + 1));\r\n }\r\n }\r\n long Y = T - D; // initial \r\n\r\n long prod(long i) {\r\n return i * (cast(long)N - i);\r\n }\r\n long diff(long x, long y) {\r\n if (x == y) return 0L;\r\n return 1L;\r\n }\r\n\r\n for (int q = 0; q < M; q++) {\r\n long d = 0;\r\n int I, X; scanf(\"%d %d\\n\", &I, &X);\r\n\r\n if (I - 2 >= 0) {\r\n d += (diff(A[I-2], X) - diff(A[I-2], A[I-1])) * prod(I-1);\r\n }\r\n if (I < N) {\r\n d += (diff(X, A[I]) - diff(A[I-1], A[I])) * prod(I);\r\n }\r\n\r\n Y += d;\r\n writeln(Y);\r\n\r\n A[I - 1] = X;\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto A = readarray!int;\r\n long ans = 0;\r\n for (long i = 0; i <= N - 1; i++) {\r\n ans += (i + N - 1) * (N - i) / 2L - i * (N - i) + (N - i);\r\n }\r\n\r\n for (int i = 0; i + 1 < N; i++) {\r\n if (A[i] == A[i + 1]) {\r\n long l = i + 1;\r\n long r = N - i - 1;\r\n ans -= l * r;\r\n }\r\n }\r\n\r\n foreach (q; 0 .. M) {\r\n int i, x; readf(\"%d %d\\n\", &i, &x);\r\n i--;\r\n if (A[i] == x) continue;\r\n if (i - 1 >= 0) {\r\n if (A[i - 1] != A[i] && A[i - 1] == x) {\r\n long lc = i;\r\n long rc = N - i;\r\n ans -= lc * rc;\r\n }\r\n if (A[i - 1] == A[i] && A[i - 1] != x) {\r\n long lc = i;\r\n long rc = N - i;\r\n ans += lc * rc;\r\n }\r\n }\r\n if (i + 1 < N) {\r\n if (A[i + 1] != A[i] && A[i + 1] == x) {\r\n long lc = i + 1;\r\n long rc = N - i - 1;\r\n ans -= lc * rc;\r\n }\r\n if (A[i + 1] == A[i] && A[i + 1] != x) {\r\n long lc = i + 1;\r\n long rc = N - i - 1;\r\n ans += lc * rc;\r\n }\r\n }\r\n A[i] = x;\r\n writeln(ans);\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nconst bool dbg = true;\r\nvoid DBG(alias x)() { static if (dbg) stderr.writefln(\"DBG: %s = %s\", x.stringof, x); }\r\nvoid MSG(in string x) { static if (dbg) stderr.writefln(\"MSG: %s\", x); }\r\n\r\nvoid main() {\r\n int N, M; scanf(\"%d %d\\n\", &N, &M);\r\n auto A = readln.chomp.split(\" \").map!(to!long).array;\r\n\r\n long f(long N) {\r\n long x = N * (N + 1) / 2;\r\n long y = N * (N + 1) * (2 * N + 1) / 6;\r\n return N * x + x - y;\r\n }\r\n\r\n long T = f(N);\r\n long D = 0;\r\n for (int i = 0; i + 1 < N; i++) {\r\n if (A[i] == A[i + 1]) {\r\n D += cast(long)(i + 1) * cast(long)(N - (i + 1));\r\n }\r\n }\r\n long Y = T - D; // initial \r\n\r\n long prod(long i) {\r\n return i * (N - i);\r\n }\r\n long diff(long x, long y) {\r\n if (x == y) return 0;\r\n return 1;\r\n }\r\n\r\n for (int q = 0; q < M; q++) {\r\n long d = 0;\r\n int I, X; scanf(\"%d %d\\n\", &I, &X);\r\n if (A[I - 1] == X) continue; // nothing changed\r\n\r\n if (I - 2 >= 0) {\r\n d += (diff(A[I-2], X) - diff(A[I-2], A[I-1])) * prod(I-1);\r\n }\r\n if (I < N) {\r\n d += (diff(X, A[I]) - diff(A[I-1], A[I])) * prod(I);\r\n }\r\n\r\n Y += d;\r\n writeln(Y);\r\n\r\n A[I - 1] = X;\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nconst bool dbg = true;\r\nvoid DBG(alias x)() { static if (dbg) stderr.writefln(\"DBG: %s = %s\", x.stringof, x); }\r\nvoid MSG(in string x) { static if (dbg) stderr.writefln(\"MSG: %s\", x); }\r\n\r\nvoid main() {\r\n int N, M; scanf(\"%d %d\\n\", &N, &M);\r\n auto A = readln.chomp.split(\" \").map!(to!long).array;\r\n\r\n long f(long N) {\r\n long x = N * (N + 1) / 2;\r\n long y = N * (N + 1) * (2 * N + 1) / 6;\r\n return N * x + x - y;\r\n }\r\n\r\n long T = f(N);\r\n long D = 0;\r\n for (int i = 0; i + 1 < N; i++) {\r\n if (A[i] == A[i + 1]) {\r\n D += (i + 1) * (N - (i + 1));\r\n }\r\n }\r\n long Y = T - D; // initial \r\n\r\n long prod(long i) {\r\n return i * (N - i);\r\n }\r\n long diff(long x, long y) {\r\n if (x == y) return 0;\r\n return 1;\r\n }\r\n\r\n for (int q = 0; q < M; q++) {\r\n long d = 0;\r\n int I, X; scanf(\"%d %d\\n\", &I, &X);\r\n if (A[I - 1] == X) continue; // nothing changed\r\n\r\n if (I - 2 >= 0) {\r\n d += (diff(A[I-2], X) - diff(A[I-2], A[I-1])) * prod(I-1);\r\n }\r\n if (I < N) {\r\n d += (diff(X, A[I]) - diff(A[I-1], A[I])) * prod(I);\r\n }\r\n\r\n Y += d;\r\n writeln(Y);\r\n\r\n A[I - 1] = X;\r\n }\r\n}\r\n"}], "src_uid": "d70a774248d9137c30f33fb37c6467a7"} {"source_code": "import std.stdio;\n\nT read(T)()\n{\n T t;\n readf(\" %s\", &t);\n return t;\n}\n\nint main(string[] args)\n{\n auto n = read!int;\n bool a[100_001];\n a[] = false;\n int curr = n;\n\n for (int i = 0; i < n; i++)\n {\n auto q = read!int;\n a[q] = true;\n if (q == curr)\n {\n while (a[curr])\n {\n write(curr, \" \");\n curr--;\n }\n }\n writeln;\n }\n\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.container : BinaryHeap;\n\nint main(string[] args)\n{\n\tint n; readf(\" %d\", n);\n\n\tint[] h = new int[n];\n\tauto bh = BinaryHeap!(int[])(h, 0);\n\t\n\tint cur_expected = n;\n\t\n\tforeach (i; 0..n){\n\t\tint num; readf(\" %d\", num);\n\t\tbh.insert(num);\n\t\t\n\t\twhile(!bh.empty() && bh.front() == cur_expected){\n\t\t\twritef(\"%d \", bh.front());\n\t\t\tbh.popFront();\n\t\t\tcur_expected--;\n\t\t}\n\t\t\n\t\twriteln();\n\t}\n\t\n\treturn 0;\n}\n\n"}], "negative_code": [], "src_uid": "3d648acee2abbf834f865b582aa9b7bc"} {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nstruct node {\n int seqlen;\n int unleft;\n int unright;\n this(int sl, int ul, int ur) {\n seqlen = sl;\n unleft = ul;\n unright = ur;\n }\n}\n\n__gshared {\n node[] segtree;\n string parens;\n}\n\nnode SegTreeConstruct(int sb, int se, int si) {\n if (sb == se) {\n if (parens[sb] == '(') segtree[si] = node(0, 1, 0);\n if (parens[sb] == ')') segtree[si] = node(0, 0, 1);\n return segtree[si];\n }\n\n int mid = (sb + se) / 2;\n node nl = SegTreeConstruct(sb, mid, si * 2 + 1);\n node nr = SegTreeConstruct(mid + 1, se, si * 2 + 2);\n int m = min(nl.unleft, nr.unright);\n segtree[si] = node(nl.seqlen + nr.seqlen + 2 * m,\n nl.unleft + nr.unleft - m,\n nl.unright + nr.unright - m);\n return segtree[si];\n}\n\nnode SegTreeRead(int sb, int se, int qb, int qe, int si) {\n if (qb <= sb && qe >= se)\n return segtree[si];\n\n if (se < qb || sb > qe)\n return node(0, 0, 0);\n\n int mid = (sb + se) / 2;\n node nl = SegTreeRead(sb, mid, qb, qe, 2 * si + 1);\n node nr = SegTreeRead(mid + 1, se, qb, qe, 2 * si + 2);\n int m = min(nl.unleft, nr.unright);\n return node(nl.seqlen + nr.seqlen + 2 * m,\n nl.unleft + nr.unleft - m,\n nl.unright + nr.unright - m);\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n readf(\" %s\\n\", &parens);\n segtree = new node[parens.length * 4];\n SegTreeConstruct(0, parens.length - 1, 0);\n\n int n;\n readf(\" %s\\n\", &n);\n foreach (i; 0 .. n) {\n int left, right;\n readf(\" %s %s\\n\", &left, &right);\n node nd = SegTreeRead(0, parens.length - 1, left - 1, right - 1, 0);\n writeln(nd.seqlen);\n }\n\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nstruct node {\n int seqlen;\n int unleft;\n int unright;\n this(int sl, int ul, int ur) {\n seqlen = sl;\n unleft = ul;\n unright = ur;\n }\n}\n\nnode[] segtree;\nstring parens;\n\nnode SegTreeConstruct(int sb, int se, int si) {\n if (sb == se) {\n if (parens[sb] == '(') segtree[si] = node(0, 1, 0);\n if (parens[sb] == ')') segtree[si] = node(0, 0, 1);\n return segtree[si];\n }\n\n int mid = (sb + se) / 2;\n node nl = SegTreeConstruct(sb, mid, si * 2 + 1);\n node nr = SegTreeConstruct(mid + 1, se, si * 2 + 2);\n int m = min(nl.unleft, nr.unright);\n segtree[si] = node(nl.seqlen + nr.seqlen + 2 * m,\n nl.unleft + nr.unleft - m,\n nl.unright + nr.unright - m);\n return segtree[si];\n}\n\nnode SegTreeRead(int sb, int se, int qb, int qe, int si) {\n if (qb <= sb && qe >= se)\n return segtree[si];\n\n if (se < qb || sb > qe)\n return node(0, 0, 0);\n\n int mid = (sb + se) / 2;\n node nl = SegTreeRead(sb, mid, qb, qe, 2 * si + 1);\n node nr = SegTreeRead(mid + 1, se, qb, qe, 2 * si + 2);\n int m = min(nl.unleft, nr.unright);\n return node(nl.seqlen + nr.seqlen + 2 * m,\n nl.unleft + nr.unleft - m,\n nl.unright + nr.unright - m);\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n readf(\" %s\\n\", &parens);\n segtree = new node[parens.length * 4];\n SegTreeConstruct(0, parens.length - 1, 0);\n\n int n;\n readf(\" %s\\n\", &n);\n foreach (i; 0 .. n) {\n int left, right;\n readf(\" %s %s\\n\", &left, &right);\n node nd = SegTreeRead(0, parens.length - 1, left - 1, right - 1, 0);\n writeln(nd.seqlen);\n }\n\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nstruct node {\n int seqlen;\n int unleft;\n int unright;\n this(int sl, int ul, int ur) {\n seqlen = sl;\n unleft = ul;\n unright = ur;\n }\n}\n\n__gshared {\n node[] segtree;\n string parens;\n}\n\nnode SegTreeConstruct(int sb, int se, int si) {\n if (sb == se) {\n if (parens[sb] == '(') segtree[si] = node(0, 1, 0);\n if (parens[sb] == ')') segtree[si] = node(0, 0, 1);\n return segtree[si];\n }\n\n int mid = (sb + se) / 2;\n node nl = SegTreeConstruct(sb, mid, si * 2);\n node nr = SegTreeConstruct(mid + 1, se, si * 2 + 1);\n int m = min(nl.unleft, nr.unright);\n segtree[si] = node(nl.seqlen + nr.seqlen + 2 * m,\n nl.unleft + nr.unleft - m,\n nl.unright + nr.unright - m);\n return segtree[si];\n}\n\nnode SegTreeRead(int sb, int se, int qb, int qe, int si) {\n if (qb <= sb && qe >= se)\n return segtree[si];\n\n if (se < qb || sb > qe)\n return node(0, 0, 0);\n\n int mid = (sb + se) / 2;\n node nl = SegTreeRead(sb, mid, qb, qe, 2 * si);\n node nr = SegTreeRead(mid + 1, se, qb, qe, 2 * si + 1);\n int m = min(nl.unleft, nr.unright);\n return node(nl.seqlen + nr.seqlen + 2 * m,\n nl.unleft + nr.unleft - m,\n nl.unright + nr.unright - m);\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n readf(\" %s\\n\", &parens);\n segtree = new node[parens.length * 4];\n SegTreeConstruct(0, parens.length - 1, 1);\n\n int n;\n readf(\" %s\\n\", &n);\n foreach (i; 0 .. n) {\n int left, right;\n readf(\" %s %s\\n\", &left, &right);\n node nd = SegTreeRead(0, parens.length - 1, left - 1, right - 1, 1);\n writeln(nd.seqlen);\n }\n\n return 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nstruct query {\n int index;\n int l;\n int r;\n int answer;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string paren;\n readf(\" %s\\n\", &paren);\n int n;\n readf(\" %s\\n\", &n);\n query[] qarr = new query[n];\n foreach (i; 0 .. n) {\n query q;\n readf(\" %s %s\\n\", &q.l, &q.r);\n --q.l;\n --q.r;\n q.index = i;\n qarr[i] = q;\n }\n int[1000000] posarr = -1;\n int[] pstack;\n foreach (int i, char c; paren) {\n if (c == '(') pstack ~= i;\n else if (!pstack.empty) {\n posarr[i] = pstack.back;\n posarr[pstack.back] = i;\n pstack.popBack();\n }\n }\n qarr.sort!\"a.r < b.r\";\n int pl = 0, pr = 0, answer = 0;\n foreach (ref q; qarr) {\n for ( ; pr < q.r + 1; ++pr) {\n if (posarr[pr] >=0 && posarr[pr] < pr && pl <= posarr[pr]) answer += 2;\n }\n if (pl < q.l) {\n for ( ; pl < q.l; ++pl) {\n if (posarr[pl] > pl && pr >= posarr[pl]) answer -= 2;\n }\n }\n else while (pl > q.l) {\n --pl;\n if (posarr[pl] > pl && pr >= posarr[pl]) answer += 2;\n }\n q.answer = answer;\n }\n qarr.sort!\"a.index < b.index\";\n foreach (q; qarr) writeln(q.answer);\n\n return 0;\n}\n"}], "src_uid": "a3e88504793c44fb3110a322d9dbdf17"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new char[][](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto d = RD!string;\n\t\tauto e = new long[](n);\n\t\tforeach (j, c; d)\n\t\t{\n\t\t\te[j] = [c].to!long;\n\t\t}\n\t\tauto index = new size_t[](e.length);\n\t\tmakeIndex!(\"a < b\", SwapStrategy.stable)(e, index);\n\t\tsize_t[] a1 = [index[0]], a2;\n\t\tbool ok = true;\n\t\tforeach (j; index[1..$])\n\t\t{\n\t\t\tif (a2.empty)\n\t\t\t{\n\t\t\t\tif (j >= a1.back)\n\t\t\t\t\ta1 ~= j;\n\t\t\t\telse\n\t\t\t\t\ta2 ~= j;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (j >= a1.back && e[j] == e[a2.front])\n\t\t\t\t\ta1 ~= j;\n\t\t\t\telse if (j >= a2.back)\n\t\t\t\t\ta2 ~= j;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug writeln(a1, a2);\n\t\tif (ok)\n\t\t{\n\t\t\tans[i] = new char[](n);\n\t\t\tif (a2.empty)\n\t\t\t{\n\t\t\t\tforeach (j; 0..n) ans[i][j] = '1';\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach (j; a1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = '1';\n\t\t\t\t}\n\t\t\t\tforeach (j; a2)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = '2';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t\tans[i] = \"-\".dup;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid solve(){\n\tint t = rint;\n\t\n\tA:\n\tforeach(_; 0 .. t){\n\t\t\n\t\tint n = rint;\n\t\tchar[] cs = read.to!(char[]);\n\t\t\n\t\tint[] as;\n\t\tforeach(c; cs) as ~= (\"\" ~ c).to!int;\n\t\t\n\t\tstring ans = \"-\";\n\t\tforeach(k; 0 .. 9){\n\t\t\tint u = 0, v = k;\n\t\t\tint isOK = 1;\n\t\t\tstring tempans = \"\";\n\t\t\tforeach(a; as){\n\t\t\t\tif(a >= v){\n\t\t\t\t\ttempans ~= \"2\";\n\t\t\t\t\tif(a > v) v = a;\n\t\t\t\t}\n\t\t\t\telse if(a <= k && a >= u){\n\t\t\t\t\ttempans ~= \"1\";\n\t\t\t\t\tif(a > u) u = a;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tisOK = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tlog(\"cs:\", cs, \"k:\", k, \"a:\", a, \"u:\", u, \"v:\", v, \"tempans:\", tempans);\n\t\t\t}\n\t\t\tif(isOK){\n\t\t\t\tans = tempans;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans.writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid solve(){\n\tint t = rint;\n\t\n\tA:\n\tforeach(_; 0 .. t){\n\t\t\n\t\tint n = rint;\n\t\tchar[] cs = read.to!(char[]);\n\t\t\n\t\tint a = 0, b = 0;\n\t\tstring ans = \"\";\n\t\tforeach(c; cs){\n\t\t\tint x = (\"\" ~ c).to!int;\n\t\t\tif(b <= c) b = c, ans ~= \"2\";\n\t\t\telse if(a <= c) a = c, ans ~= \"1\";\n\t\t\telse{\n\t\t\t\t\"-\".writeln;\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t}\n\t\tans.writeln;\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new char[][](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto d = RD!string;\n\t\tauto e = new long[](n);\n\t\tforeach (j, c; d)\n\t\t{\n\t\t\te[j] = [c].to!long;\n\t\t}\n\t\tauto index = new size_t[](e.length);\n\t\tmakeIndex!(\"a < b\", SwapStrategy.stable)(e, index);\n\t\tsize_t[] a1 = [index[0]], a2;\n\t\tbool ok = true;\n\t\tforeach (j; index[1..$])\n\t\t{\n\t\t\tif (j >= a1.back)\n\t\t\t\ta1 ~= j;\n\t\t\telse if (a2.empty)\n\t\t\t\ta2 ~= j;\n\t\t\telse if (j >= a2.back)\n\t\t\t\ta2 ~= j;\n\t\t\telse\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(a1, a2);\n\t\tif (ok)\n\t\t{\n\t\t\tans[i] = new char[](n);\n\t\t\tif (a2.empty)\n\t\t\t{\n\t\t\t\tforeach (j; 0..n) ans[i][j] = '1';\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach (j; a1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = '1';\n\t\t\t\t}\n\t\t\t\tforeach (j; a2)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = '2';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t\tans[i] = \"-\".dup;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "886f773e75fa3c770fb70133ff1b595b"} {"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\treadf(\" %d\", &a);\n\t\tint[] m = new int[a];\n\t\tfor (int j=0; j<a; j++)\n\t\t{\n\t\t\treadf(\" %d\", &m[j]);\n\t\t}\n\t\tif (a==1 && m[0]%2==1)\n\t\t{\n\t\t\twriteln(-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint count=0;\n\t\t\tfor (int j=0; j<a; j++)\n\t\t\t{\n\t\t\t\tif (m[j]%2==0)\n\t\t\t\t{\n\t\t\t\t\tcount=count+1;\n\t\t\t\t\twriteln(1);\n\t\t\t\t\twriteln(j+1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (count==0)\n\t\t\t{\n\t\t\t\twriteln(2);\n\t\t\t\twriteln(1);\n\t\t\t\twriteln(2);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] % 2 == 0)\n\t\t\t{\n\t\t\t\tans[ti] = [i+1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!ans[ti].empty) continue;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] % 2)\n\t\t\t{\n\t\t\t\tans[ti] ~= i+1;\n\t\t\t}\n\t\t}\n\t\tif (ans[ti].length == 1)\n\t\t\tans[ti].length = 0;\n\t\telse\n\t\t\tans[ti] = ans[ti][0..2];\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t{\n\t\t\twriteln(e.length);\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "3fe51d644621962fe41c32a2d90c7f94"} {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\n\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\n\nInput input;\n\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto brange(alias low, alias high, alias pred, bool value)()\n{\n return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);\n}\nauto ftrue(alias low, alias high, alias pred)()\n{\n return brange!(low, high, pred, false).length + low;\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t;\n get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\nstruct ModNum(T)\n{\n T representative, modulus;\n this(T representative, T modulus)\n {\n this.representative = representative;\n this.modulus = modulus;\n }\n T minimalPositiveRepresentative()\n {\n return ((representative % modulus) + modulus) % modulus;\n }\n T minimalNegativeRepresentative()\n {\n return ((representative % modulus) - modulus) % modulus;\n }\n T maxRepresentative(T upperBound)\n {\n return upperBound - pmod(upperBound - representative, modulus);\n }\n T minRepresentative(T lowerBound)\n {\n return lowerBound + pmod(representative - lowerBound, modulus);\n }\n}\n// minimum possible representative of x modulo m.\nT pmod(T)(T x, T m)\n{\n return (x % m + m) % m;\n}\n// solves ax + by = gcd(a, b) and returns gcd(a, b)\nT extendedEuclideanAlgorithm(T)(T a, T b, out T x, out T y)\n{\n if (a == 0)\n {\n x = 0, y = 1;\n return b;\n }\n T x1, y1;\n auto d = egcd(b % a, a, x1, y1);\n x = y1 - (b / a) * x1, y = x1;\n return d;\n}\nalias egcd = extendedEuclideanAlgorithm;\n// solves ax = b (mod m) giving a solution as a modulus class.\nbool solveLinearCongruence(T)(T a, T b, T m, out ModNum!T res)\n{\n T x, p;\n b = pmod(b, m);\n T y;\n T g = egcd(a, m, x, y);\n if (b % g != 0)\n return false;\n p = m / g;\n x = pmod(x * b / g, p);\n res.representative = x;\n res.modulus = p;\n return true;\n}\n\nvoid main()\n{\n // a - x >= 0 \n // b - y - 2x >= 0\n // b - 2y >= 0\n\n alias ln = int;\n ln t; get(t);\n while(t--)\n {\n ln a, b, c; get(a, b, c);\n ln mx = 0;\n for(ln x = 0; x <= a; x++)\n\t{\n\t for(ln y = 0; c - 2 * y >= 0; y++)\n\t {\n\t if ( b - y - 2 * x >= 0)\n\t\t{\n\t\t mx = max(mx, x + y + 2 * x + 2 * y);\n\t\t}\n\t }\n\t}\n wr(mx); }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto c = RD;\n\t\tauto cnt1 = min(c/2, b);\n\t\tauto cnt2 = min((b-cnt1)/2, a);\n\t\tans[i] = (cnt1+cnt2) * 3;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\n\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\n\nInput input;\n\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto brange(alias low, alias high, alias pred, bool value)()\n{\n return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);\n}\nauto ftrue(alias low, alias high, alias pred)()\n{\n return brange!(low, high, pred, false).length + low;\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t;\n get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\nstruct ModNum(T)\n{\n T representative, modulus;\n this(T representative, T modulus)\n {\n this.representative = representative;\n this.modulus = modulus;\n }\n T minimalPositiveRepresentative()\n {\n return ((representative % modulus) + modulus) % modulus;\n }\n T minimalNegativeRepresentative()\n {\n return ((representative % modulus) - modulus) % modulus;\n }\n T maxRepresentative(T upperBound)\n {\n return upperBound - pmod(upperBound - representative, modulus);\n }\n T minRepresentative(T lowerBound)\n {\n return lowerBound + pmod(representative - lowerBound, modulus);\n }\n}\n// minimum possible representative of x modulo m.\nT pmod(T)(T x, T m)\n{\n return (x % m + m) % m;\n}\n// solves ax + by = gcd(a, b) and returns gcd(a, b)\nT extendedEuclideanAlgorithm(T)(T a, T b, out T x, out T y)\n{\n if (a == 0)\n {\n x = 0, y = 1;\n return b;\n }\n T x1, y1;\n auto d = egcd(b % a, a, x1, y1);\n x = y1 - (b / a) * x1, y = x1;\n return d;\n}\nalias egcd = extendedEuclideanAlgorithm;\n// solves ax = b (mod m) giving a solution as a modulus class.\nbool solveLinearCongruence(T)(T a, T b, T m, out ModNum!T res)\n{\n T x, p;\n b = pmod(b, m);\n T y;\n T g = egcd(a, m, x, y);\n if (b % g != 0)\n return false;\n p = m / g;\n x = pmod(x * b / g, p);\n res.representative = x;\n res.modulus = p;\n return true;\n}\n\nvoid main()\n{\n // a - x >= 0 \n // b - y - 2x >= 0\n // b - 2y >= 0\n\n alias ln = int;\n ln t; get(t);\n while(t--)\n {\n ln a, b, c; get(a, b, c);\n ln mx = 0;\n for(ln x = 0; x <= a; x++)\n\t{\n\t for(ln y = 0; 2 * y <= b; y++)\n\t {\n\t if ( b - y - 2 * x >= 0 && c - 2 * y >= 0)\n\t\t{\n\t\t mx = max(mx, x + y + 2 * x + 2 * y);\n\t\t}\n\t }\n\t}\n wr(mx); }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\n\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\n\nInput input;\n\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto brange(alias low, alias high, alias pred, bool value)()\n{\n return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);\n}\nauto ftrue(alias low, alias high, alias pred)()\n{\n return brange!(low, high, pred, false).length + low;\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t;\n get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\nstruct ModNum(T)\n{\n T representative, modulus;\n this(T representative, T modulus)\n {\n this.representative = representative;\n this.modulus = modulus;\n }\n T minimalPositiveRepresentative()\n {\n return ((representative % modulus) + modulus) % modulus;\n }\n T minimalNegativeRepresentative()\n {\n return ((representative % modulus) - modulus) % modulus;\n }\n T maxRepresentative(T upperBound)\n {\n return upperBound - pmod(upperBound - representative, modulus);\n }\n T minRepresentative(T lowerBound)\n {\n return lowerBound + pmod(representative - lowerBound, modulus);\n }\n}\n// minimum possible representative of x modulo m.\nT pmod(T)(T x, T m)\n{\n return (x % m + m) % m;\n}\n// solves ax + by = gcd(a, b) and returns gcd(a, b)\nT extendedEuclideanAlgorithm(T)(T a, T b, out T x, out T y)\n{\n if (a == 0)\n {\n x = 0, y = 1;\n return b;\n }\n T x1, y1;\n auto d = egcd(b % a, a, x1, y1);\n x = y1 - (b / a) * x1, y = x1;\n return d;\n}\nalias egcd = extendedEuclideanAlgorithm;\n// solves ax = b (mod m) giving a solution as a modulus class.\nbool solveLinearCongruence(T)(T a, T b, T m, out ModNum!T res)\n{\n T x, p;\n b = pmod(b, m);\n T y;\n T g = egcd(a, m, x, y);\n if (b % g != 0)\n return false;\n p = m / g;\n x = pmod(x * b / g, p);\n res.representative = x;\n res.modulus = p;\n return true;\n}\n\nvoid main()\n{\n // a - x >= 0 \n // b - y - 2x >= 0\n // b - 2y >= 0\n\n alias ln = int;\n ln t; get(t);\n while(t--)\n {\n ln a, b, c; get(a, b, c);\n ln mx = 0;\n for(ln x = 0; x <= a; x++)\n\t{\n\t for(ln y = 0; 2 * y <= b; y++)\n\t {\n\t if ( b - y - 2 * x >= 0 && b - 2 * y >= 0)\n\t\t{\n\t\t mx = max(mx, x + y + 2 * x + 2 * y);\n\t\t}\n\t }\n\t}\n wr(mx);\n }\n}\n"}], "src_uid": "14fccd50d5dfb557dd53f2896ed844c3"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum A = 2050L;\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readLong();\n \n long ans;\n if (N % A == 0) {\n for (long m = N / A; m > 0; m /= 10) {\n ans += m % 10;\n }\n } else {\n ans = -1;\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int base = 2050;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(long);\r\n\t\tif (n % base != 0)\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tn /= base;\r\n\t\t\twriteln (n.text.map !(q{a - '0'}).sum);\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp;\r\n long d = to!long(param);\r\n \r\n if(d % 2050 != 0)\r\n {\r\n writeln(-1);\r\n }\r\n else\r\n {\r\n long m = d / 2050;\r\n long sum = 0;\r\n while(m > 0)\r\n {\r\n sum += (m%10);\r\n m /= 10; \r\n }\r\n \r\n writeln(sum);\r\n }\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp;\r\n real d = to!real(param);\r\n if(d < 2050)\r\n {\r\n writeln(-1);\r\n continue;\r\n }\r\n real m = 2050 * pow(10, ceil(log10(d))-4);\r\n //writeln(m);\r\n int c = 0;\r\n \r\n while(d > m)\r\n {\r\n d -= m;\r\n c++;\r\n \r\n if(m > d)\r\n m /= 10;\r\n }\r\n \r\n if(d < m)\r\n writeln(-1);\r\n else \r\n writeln(c+1);\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n outer : foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp;\r\n long d = to!long(param);\r\n long m = 2050;\r\n \r\n while(m*10 <= d)\r\n {\r\n m = m*10;\r\n }\r\n \r\n int c = 0;\r\n while(d >= m)\r\n {\r\n d -= m;\r\n c++;\r\n \r\n if(m > d && m >= 10)\r\n m /= 10;\r\n }\r\n \r\n if(d != 0)\r\n writeln(-1);\r\n else writeln(c);\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n outer : foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp;\r\n long d = to!long(param);\r\n long m = 2050;\r\n \r\n while(m*10 <= d)\r\n {\r\n m = m*10;\r\n }\r\n \r\n int c = 0;\r\n while(d >= m)\r\n {\r\n d -= m;\r\n c++;\r\n \r\n if(m > d && m > 10)\r\n m /= 10;\r\n }\r\n \r\n if(d != 0)\r\n writeln(-1);\r\n else writeln(c);\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp;\r\n long d = to!long(param);\r\n long m = 2050;\r\n \r\n if(d < m || d % m != 0)\r\n {\r\n writeln(-1);\r\n continue;\r\n }\r\n \r\n long q = d / m;\r\n \r\n while(m*10 <= d)\r\n {\r\n m = m*10;\r\n }\r\n \r\n int c = 0;\r\n while(d > 0)\r\n {\r\n d -= m;\r\n c++;\r\n if(m > d)\r\n m /= 10;\r\n \r\n }\r\n \r\n writeln(c);\r\n }\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto n= to!long(readln().chomp);\r\n foreach(_; 0..n)\r\n {\r\n auto param = readln().chomp;\r\n long d = to!long(param);\r\n long m = 2050;\r\n \r\n if(d < m || d % m != 0)\r\n {\r\n writeln(-1);\r\n continue;\r\n }\r\n \r\n long q = d / m;\r\n \r\n while(m*10 < d)\r\n {\r\n m = m*10;\r\n }\r\n \r\n int c = 0;\r\n while(d > 0)\r\n {\r\n d -= m;\r\n c++;\r\n if(m > d)\r\n m /= 10;\r\n \r\n }\r\n \r\n writeln(c);\r\n }\r\n}"}], "src_uid": "f3e413954c9c02520fd25bd2cba4747e"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint [] [] moves;\n\t\tforeach (i; 0..2)\n\t\t{\n\t\t\tint [] line;\n\t\t\tint k;\n\t\t\treadf (\" %s\", &k);\n\t\t\tforeach (j; 0..k)\n\t\t\t{\n\t\t\t\tint v;\n\t\t\t\treadf (\" %s\", &v);\n\t\t\t\tline ~= n - v;\n\t\t\t}\n\t\t\tmoves ~= line;\n\t\t}\n\n\t\tauto g = new int [] [] (2, n);\n\t\tauto c = new int [] [] (2, n);\n\n\t\talias Pair = Tuple !(int, q{who}, int, q{pos});\n\t\tPair [] q;\n\n\t\tvoid add (Pair p, int v)\n\t\t{\n\t\t\tg[p.who][p.pos] = v;\n\t\t\tc[p.who][p.pos] = n;\n\t\t\tq ~= p;\n\t\t}\n\n\t\tadd (Pair (0, 0), -1);\n\t\tadd (Pair (1, 0), -1);\n\n\t\twhile (!q.empty)\n\t\t{\n\t\t\tauto who = q.front.who;\n\t\t\tauto pos = q.front.pos;\n\t\t\tauto res = g[who][pos];\n\t\t\tq.popFront ();\n\t\t\tq.assumeSafeAppend ();\n\n\t\t\tforeach (d; moves[!who])\n\t\t\t{\n\t\t\t\tint next = (pos + d) % n;\n\t\t\t\tif (g[!who][next] != 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (res == -1)\n\t\t\t\t{\n\t\t\t\t\tadd (Pair (!who, next), +1);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tc[!who][next] += 1;\n\t\t\t\t\tif (c[!who][next] >=\n\t\t\t\t\t moves[!who].length)\n\t\t\t\t\t{\n\t\t\t\t\t\tadd (Pair (!who, next), -1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (line; g)\n\t\t{\n\t\t\tline.drop (1).map !(x =>\n\t\t\t [\"Lose\", \"Loop\", \"Win\"][x + 1]).join (\" \").writeln;\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto K = new int[2];\n auto S = new int[][2];\n foreach (i; 0 .. 2) {\n K[i] = readInt();\n S[i] = new int[K[i]];\n foreach (j; 0 .. K[i]) {\n S[i][j] = readInt();\n }\n }\n \n auto dp = new int[][](2, N);\n auto cnt = new int[][](2, N);\n foreach (t; 0 .. 2) foreach (u; 0 .. N) {\n dp[t][u] = -1;\n cnt[t][u] = K[t];\n }\n \n auto que = new int[2 * N * 2];\n int qb, qe;\n foreach (t; 0 .. 2) {\n dp[t][0] = 0;\n que[qe++] = t;\n que[qe++] = 0;\n }\n \n for (; qb != qe; ) {\n const t = que[qb++];\n const x = que[qb++];\n foreach (s; S[t ^ 1]) {\n const tt = t ^ 1;\n const xx = (x - s < 0) ? (x - s + N) : (x - s);\n if (dp[tt][xx] == -1) {\n if (dp[t][x] & 1) {\n if (--cnt[tt][xx] > 0) {\n continue;\n }\n }\n dp[tt][xx] = dp[t][x] + 1;\n que[qe++] = tt;\n que[qe++] = xx;\n }\n }\n }\n \n foreach (t; 0 .. 2) {\n foreach (x; 1 .. N) {\n if (x > 1) write(\" \");\n write((dp[t][x] == -1) ? \"Loop\" : (dp[t][x] & 1) ? \"Win\" : \"Lose\");\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "7c6b04687b4e608be1fd7d04abb015ee"} {"source_code": "module cf_159b;\n\nimport std.stdio;\nimport std.algorithm;\n\nvoid main() {\n immutable MAX_VALUE = 1000;\n\n int n, m, a, b;\n int[MAX_VALUE + 1][MAX_VALUE + 1] pairCount;\n int[MAX_VALUE + 1] diamCount;\n int closed = 0, nicelyClosed = 0;\n \n readf(\"%d %d\", &n, &m);\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d\", &a, &b);\n ++pairCount[a][b];\n ++diamCount[b];\n }\n for (int i = 0; i < m; ++i) {\n readf(\" %d %d\", &a, &b);\n \n if (pairCount[a][b] > 0) {\n ++nicelyClosed;\n --pairCount[a][b];\n }\n if (diamCount[b] > 0) {\n ++closed;\n --diamCount[b];\n }\n }\n \n writeln(closed, \" \", nicelyClosed);\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n auto ns = readln.chomp.split.map!(to!int).array;\n\n auto vals = new int[][][] (2, 1001, 1001);\n foreach (i; 0 .. 2) {\n foreach (_; 0 .. ns[i]) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n vals[i][y][x] += 1;\n }\n }\n \n int u = 0, v = 0;\n foreach (d; 1 .. 1001) {\n int mleft = 0, cleft = 0;\n int ok = 0;\n foreach (c; 1 .. 1001) {\n ok += min(vals[0][d][c], vals[1][d][c]);\n if (vals[0][d][c] > vals[1][d][c]) mleft += vals[0][d][c] - vals[1][d][c];\n else cleft += vals[1][d][c] - vals[0][d][c];\n }\n \n u += ok;\n v += ok;\n \n u += min(mleft, cleft);\n }\n \n writeln(u, ' ', v);\n}"}], "negative_code": [{"source_code": "module cf_159b;\n\nimport std.stdio;\nimport std.algorithm;\n\nvoid main() {\n immutable MAX_VALUE = 1000;\n\n int n, m, a, b;\n int[MAX_VALUE + 1][MAX_VALUE + 1] pairCount;\n int[MAX_VALUE + 1] diamCount;\n int closed = 0, nicelyClosed = 0;\n \n readf(\"%d %d\", &n, &m);\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d\", &a, &b);\n ++pairCount[a][b];\n ++diamCount[b];\n }\n for (int i = 0; i < m; ++i) {\n readf(\" %d %d\", &a, &b);\n \n if (pairCount[a][b] > 0) {\n ++nicelyClosed;\n }\n if (diamCount[b] > 0) {\n ++closed;\n }\n }\n \n writeln(closed, \" \", nicelyClosed);\n}"}, {"source_code": "module cf_159b;\n\nimport std.stdio;\nimport std.algorithm;\n\nvoid main() {\n int n, m;\n int[2][] markers, caps;\n \n readf(\"%d %d\", &n, &m);\n markers = new int[2][n];\n caps = new int[2][m];\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d\", &markers[i][0], &markers[i][1]);\n }\n for (int i = 0; i < m; ++i) {\n readf(\" %d %d\", &caps[i][0], &caps[i][1]);\n }\n \n sort!((a, b) { return a[0] < b[0] || a[0] == b[0] && a[1] < b[1]; })(markers);\n sort!((a, b) { return a[0] < b[0] || a[0] == b[0] && a[1] < b[1]; })(caps);\n \n int nicelyClosed = 0;\n for (int i = 0; i < n; ++i) {\n int l = 0, r = caps.length - 1;\n while (l < r) {\n int mid = (l + r) / 2;\n bool leftCondition = markers[i][0] > caps[mid][0] || \n markers[i][0] == caps[mid][0] && markers[i][1] > caps[mid][1];\n if (leftCondition) {\n l = mid + 1;\n } else {\n r = mid;\n }\n }\n \n bool cond = markers[i][0] == caps[r][0] && markers[i][1] == caps[r][1];\n if (cond) {\n ++nicelyClosed;\n }\n }\n \n sort!((a, b) { return a[1] < b[1]; })(markers);\n sort!((a, b) { return a[1] < b[1]; })(caps);\n \n int closed = 0;\n for (int i = 0; i < n; ++i) {\n int l = 0, r = caps.length - 1;\n while (l < r) {\n int mid = (l + r) / 2;\n if (markers[i][1] > caps[mid][1]) {\n l = mid + 1;\n } else {\n r = mid;\n }\n }\n \n bool cond = markers[i][1] == caps[r][1];\n if (cond) {\n ++closed;\n }\n }\n \n writeln(closed, \" \", nicelyClosed);\n}"}], "src_uid": "3c9fb72577838f54b1670e84b4b60c61"} {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint tests;\n\treadf (\" %s\", &tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\treadf (\" %s\", &n);\n\t\tlong res = n * 1L * (n + 1) / 2;\n\t\tfor (int p = 1; p <= n; p <<= 1)\n\t\t{\n\t\t\tres -= p * 2;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n t = cin.readInt;\n while (t--) {\n long n = cin.readString.to!long;\n long sum = (n * (n + 1)) / 2;\n int num = 0;\n for (int i = 1; num <= n; i++) {\n num = 1 << i;\n sum -= num;\n }\n writeln(sum);\n } \n}"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.string;\nimport std.range;\nimport std.typecons;\nimport std.conv;\nimport std.functional;\nimport std.container;\nimport std.math;\nimport std.algorithm;\n\n\nimmutable int MAX_LOG = 31;\nint[MAX_LOG] powers;\nlong[MAX_LOG] prefixes;\n\n\nlong specialSum( int n ) {\n\n// debug {writeln((1L + n) * n / 2);\n// writeln(cast (int)(trunc(log2(cast (double)(n)))));\n// writeln(prefixes[cast (int)(trunc(log2(cast (double)(n))))]);};\n return (1L + n) * n / 2 - 2 *\n prefixes[cast (int)(trunc(log2(cast (double)(n))))];\n}\n\n\nint main() {\n\n auto t = readln().strip().to! (int);\n long answers[];\n\n powers[0] = 1;\n foreach (int i; 1..powers.length)\n powers[i] = powers[i - 1] * 2;\n prefixes[0] = 1;\n foreach (int i; 1..prefixes.length)\n prefixes[i] = prefixes[i - 1] + powers[i];\n\n // debug {writeln(powers, '\\n', prefixes);};\n\n foreach (int i; 0..t) {\n auto n = readln().strip().to! (int);\n\n answers ~= specialSum(n);\n }\n\n foreach (i; answers)\n writeln(i);\n\n\treturn 0;\n}\n"}], "negative_code": [], "src_uid": "a3705f29b9a8be97a9e9e54b6eccba09"} {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable lim = 2 * 10^^5 + 7;\nimmutable inf = 2 * 10^^9 + 7;\nalias Query = Tuple!(int, \"l\", int, \"type\", int, \"r\", int, \"c\");\nint n, x;\n\nvoid main() {\n scan(n, x);\n\n auto t = new Query[](2*n);\n\n int li, ri, ci;\n\n foreach (i ; 0 .. n) {\n scan(li, ri, ci);\n t[2*i] = Query(li, 0, ri, ci);\n t[2*i + 1] = Query(ri, 1, li, ci);\n }\n\n t.sort();\n\n auto minc = new int[](lim);\n minc[] = inf;\n\n int ans = inf;\n\n foreach (i ; 0 .. 2*n) {\n if (t[i].type == 0) {\n int d = t[i].r - t[i].l + 1;\n if (x - d >= 0 && minc[x - d] < inf) {\n ans = min(ans, minc[x - d] + t[i].c);\n }\n }\n else {\n int d = t[i].l - t[i].r + 1;\n minc[d] = min(minc[d], t[i].c);\n }\n }\n\n if (ans == inf) {\n writeln(-1);\n }\n else {\n writeln(ans);\n }\n}\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable lim = 2 * 10^^5 + 7;\nimmutable inf = 2 * 10^^9 + 7;\nalias Trip = Tuple!(int, \"r\", int, \"l\", int, \"c\");\nint n, x;\n\nvoid main() {\n scan(n, x);\n\n auto t = new Trip[](n);\n\n int li, ri, ci;\n\n foreach (i ; 0 .. n) {\n scan(li, ri, ci);\n t[i] = Trip(ri, li, ci);\n }\n\n auto tl = t.dup;\n\n t.sort();\n tl.sort!\"a[1] < b[1]\"();\n\n debug {\n writeln(\"t:\", t);\n writeln(\"tl:\", tl);\n }\n\n auto minc = new long[](lim);\n minc[] = inf;\n\n long ans = inf;\n\n foreach (i ; 1 .. lim) {\n while (!tl.empty && i == tl.front.l) {\n int d = tl.front.r - tl.front.l + 1;\n if (x - d >= 0) {\n ans = min(ans, minc[x - d] + tl.front.c);\n }\n tl.popFront();\n }\n\n while (!tl.empty && i == t.front.r) {\n int d = t.front.r - t.front.l + 1;\n minc[d] = min(minc[d], t.front.c);\n t.popFront();\n }\n }\n\n if (ans == inf) {\n writeln(-1);\n }\n else {\n writeln(ans);\n }\n}\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable lim = 2 * 10^^5 + 7;\nimmutable inf = 2 * 10^^9 + 7;\nalias Trip = Tuple!(int, \"r\", int, \"l\", int, \"c\");\nint n, x;\n\nvoid main() {\n scan(n, x);\n\n auto t = new Trip[](n);\n\n int li, ri, ci;\n\n foreach (i ; 0 .. n) {\n scan(li, ri, ci);\n t[i] = Trip(ri, li, ci);\n }\n\n t.sort();\n\n auto dp = new int[][](lim, 3);\n\n foreach (i ; 0 .. lim) {\n dp[i][1] = dp[i][2] = inf;\n }\n\n foreach (i ; 1 .. lim) {\n dp[i][1] = min(dp[i][1], dp[i - 1][1]);\n dp[i][2] = min(dp[i][2], dp[i - 1][2]);\n\n while (!t.empty && i == t.front.r) {\n dp[i][1] = min(dp[i][1], t.front.c);\n\n dp[i][2] = min(dp[i][2], dp[t.front.l - 1][1] + t.front.c);\n\n t.popFront();\n }\n }\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", dp[0 .. 10]);\n }\n\n int ans = dp[lim - 1][2];\n\n if (ans == inf) {\n writeln(-1);\n }\n else {\n writeln(ans);\n }\n}\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable lim = 2 * 10^^5 + 7;\nimmutable inf = 2 * 10^^9 + 7;\nalias Trip = Tuple!(int, \"r\", int, \"l\", int, \"c\");\nint n, x;\n\nvoid main() {\n scan(n, x);\n\n auto t = new Trip[](n);\n\n int li, ri, ci;\n\n foreach (i ; 0 .. n) {\n scan(li, ri, ci);\n t[i] = Trip(ri, li, ci);\n }\n\n t.sort();\n\n auto dp = new long[][](lim, 3);\n\n foreach (i ; 0 .. lim) {\n dp[i][1] = dp[i][2] = inf;\n }\n\n foreach (i ; 1 .. lim) {\n dp[i][1] = min(dp[i][1], dp[i - 1][1]);\n dp[i][2] = min(dp[i][2], dp[i - 1][2]);\n\n while (!t.empty && i == t.front.r) {\n dp[i][1] = min(dp[i][1], t.front.c);\n dp[i][2] = min(dp[i][2], dp[t.front.l - 1][1] + t.front.c);\n t.popFront();\n }\n }\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", dp[0 .. 10]);\n }\n\n long ans = dp[lim - 1][2];\n\n if (ans == inf) {\n writeln(-1);\n }\n else {\n writeln(ans);\n }\n}\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "src_uid": "211d872af386c69b9ddaab9d8cf3160f"} {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nlong ask(in char[] s) {\r\n writefln(\"? %s\", s);\r\n stdout.flush;\r\n long r = readln.chomp.to!long;\r\n return r;\r\n}\r\n\r\nvoid main() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n\r\n long[] L = new long[M]; L[$-1] = -1;\r\n\r\n char[] q = new char[M]; q[] = '0';\r\n for (int i = 0; i < M; i++) {\r\n q[i] = '1';\r\n L[i] = ask(q);\r\n q[i] = '0';\r\n }\r\n auto idx = M.iota.array.sort!((a, b) => L[a] < L[b]).array;\r\n\r\n long C = 0;\r\n foreach (k; idx) {\r\n q[k] = '1';\r\n long nC = ask(q);\r\n if (nC == C + L[k]) {\r\n // need k\r\n C = nC;\r\n } else {\r\n // don't need k\r\n q[k] = '0';\r\n }\r\n }\r\n writefln(\"! %s\", C);\r\n stdout.flush;\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint ask (bool [] used)\r\n{\r\n\twritefln !(\"? %(%s%)\") (used.map !(to !(int)));\r\n\tstdout.flush ();\r\n\treturn readln.strip.to !(int);\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tint n, m;\r\n\twhile (readf !(\" %s %s\") (n, m) > 0)\r\n\t{\r\n\t\treadln;\r\n\r\n\t\tauto len = new int [m];\r\n\t\tauto used = new bool [m];\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tused[i] = true;\r\n\t\t\tlen[i] = ask (used);\r\n\t\t\tused[i] = false;\r\n\t\t}\r\n\r\n\t\tint res = 0;\r\n\t\tauto p = m.iota.array;\r\n\t\tp.schwartzSort !(i => len[i]);\r\n\t\tforeach (i; p)\r\n\t\t{\r\n\t\t\tused[i] = true;\r\n\t\t\tint cur = ask (used);\r\n\t\t\tif (res + len[i] == cur)\r\n\t\t\t{\r\n\t\t\t\tres = cur;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tused[i] = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twritefln !(\"! %s\") (res);\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n const N = readInt;\n const M = readInt;\n \n alias Edge = Tuple!(long, \"c\", int, \"i\");\n auto es = new Edge[M];\n foreach (i; 0 .. M) {\n auto cs = new char[M];\n cs[] = '0';\n cs[i] = '1';\n writefln(\"? %s\", cs);\n stdout.flush;\n es[i].c = readLong;\n es[i].i = i;\n }\n es.sort;\n \n long ans;\n {\n auto cs = new char[M];\n cs[] = '0';\n long bef;\n foreach (e; es) {\n const i = e.i;\n cs[i] = '1';\n writefln(\"? %s\", cs);\n stdout.flush;\n const res = readLong;\n if (bef + e.c == res) {\n ans += e.c;\n bef = res;\n } else {\n cs[i] = '0';\n }\n }\n }\n \n writefln(\"! %s\", ans);\n stdout.flush;\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint ask (bool [] used)\r\n{\r\n\twritefln !(\"? %(%s%)\") (used.map !(to !(int)));\r\n\tstdout.flush ();\r\n\treturn readln.strip.to !(int);\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tint n, m;\r\n\twhile (readf !(\" %s %s\") (n, m) > 0)\r\n\t{\r\n\t\treadln;\r\n\r\n\t\tauto len = new int [m];\r\n\t\tauto used = new bool [m];\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tused[i] = true;\r\n\t\t\tlen[i] = ask (used);\r\n\t\t\tused[i] = false;\r\n\t\t}\r\n\r\n\t\tint res = 0;\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tused[i] = true;\r\n\t\t\tint cur = ask (used);\r\n\t\t\tif (res + len[i] == cur)\r\n\t\t\t{\r\n\t\t\t\tres = cur;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tused[i] = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twritefln !(\"! %s\") (res);\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}], "src_uid": "003b7257b35416ec93f189cb29e458e6"} {"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.bigint;\nimport std.string;\nBigInt calc(BigInt n)\n{\n\tBigInt med=n;\n\tint[]v;\n\tfor(;;)\n\t{\n\t\tif(n==0)break;\n\t\tv~=n%10;\n\t\tn/=10;\n\t}\n\tBigInt cnt=0;\n\tBigInt t=1;\n\tfor(int i=0;i<v.length;i++)\n\t{\n\t\tBigInt[]x;\n\t\tx.length=10;\n\t\tBigInt mm=med/(t*10);\n\t\tBigInt mm1=mm*10;\n\t\tfor(int j=0;j<=9;j++)\n\t\t{\n\t\t\tx[j]+=mm*t;\n\t\t\tif(mm1+j<med/t)x[j]+=t;\n\t\t\telse if(mm1+j==med/t)x[j]+=med-(mm1+j)*t+1;\n\t\t}\n\t\tfor(int j=0;j<=9;j++)cnt+=x[j]*j;\n\t\tt*=10;\n\t}\n\treturn cnt;\n}\nBigInt get(BigInt a)\n{\n\tBigInt beg=0,end=\"10000000000000000000000\";\n\tfor(;;)\n\t{\n\t\tif(beg==end)break;\n\t\tBigInt med=(beg+end)/2;\n\t\tBigInt cnt=calc(med);\n\t\tif(cnt<a)beg=med+1;\n\t\telse end=med;\n\t}\n\treturn beg;\n}\nvoid main()\n{\n\t//for(int i=0;i<200;i++)writeln(i,\" \",calc(to!BigInt(i)));\n\tBigInt a=to!BigInt(chomp(readln()));\n\tBigInt[]dat;\n\tdat.length=1000;\n\tfor(int i=0;i<1000;i++)dat[i]=-1;\n\tfor(int i=0;;i++)\n\t{\n\t\tBigInt t;\n\t\tBigInt x=a*i;\n\t\tx=get(x);\n\t\tt=calc(x);\n\t\t//writeln(x,\" \",get(x),\" \",t,\" \",t%a);\n\t\tif(dat[to!int(t%a)]!=-1&&dat[to!int(t%a)]!=x)\n\t\t{\n\t\t\twriteln(dat[to!int(t%a)]+1,\" \",x);\n\t\t\tbreak;\n\t\t}\n\t\tdat[to!int(t%a)]=x;\n\t}\n\treadln();\n}", "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nlong A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = readLong;\n\t\t\n\t\tlong l = 1_000_000_000_000_000_000;\n\t\tlong r = 2_000_000_000_000_000_000;\n\t\t\n\t\tlong sum;\n\t\t(sum += (r - l)) %= A;\n\t\tforeach (i; 0 .. 18) {\n\t\t\t(sum += (r - l) / 10 * 45) %= A;\n\t\t}\n\t\tl -= sum;\n\t\tr -= sum;\n\t\twriteln(l, \" \", r - 1);\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.bigint;\nimport std.string;\nBigInt calc(BigInt n)\n{\n\tBigInt med=n;\n\tint[]v;\n\tfor(;;)\n\t{\n\t\tif(n==0)break;\n\t\tv~=n%10;\n\t\tn/=10;\n\t}\n\tBigInt cnt=0;\n\tBigInt t=1;\n\tfor(int i=0;i<v.length;i++)\n\t{\n\t\tBigInt[]x;\n\t\tx.length=10;\n\t\tfor(int j=0;j<=9;j++)\n\t\t{\n\t\t\tx[j]+=(med/(t*10))*t;\n\t\t\tif(med/(t*10)*10+j<med/t)x[j]+=t;\n\t\t\telse if(med/(t*10)*10+j==med/t)x[j]+=med-(med/(t*10)*10+j)*t+1;\n\t\t}\n\t\tfor(int j=0;j<=9;j++)cnt+=x[j]*j;\n\t\tt*=10;\n\t}\n\treturn cnt;\n}\nBigInt get(BigInt a)\n{\n\tBigInt beg=0,end=\"100000000000000000000000000000\";\n\tfor(;;)\n\t{\n\t\tif(beg==end)break;\n\t\tBigInt med=(beg+end)/2;\n\t\tBigInt cnt=calc(med);\n\t\tif(cnt<a)beg=med+1;\n\t\telse end=med;\n\t}\n\treturn beg;\n}\nvoid main()\n{\n\t//for(int i=0;i<200;i++)writeln(i,\" \",calc(to!BigInt(i)));\n\tBigInt a=to!BigInt(chomp(readln()));\n\tBigInt[]dat;\n\tdat.length=1000;\n\tfor(int i=0;i<1000;i++)dat[i]=-1;\n\tfor(int i=0;;i++)\n\t{\n\t\tBigInt t;\n\t\tBigInt x=a*i;\n\t\tt=calc(get(x));\n\t\t//writeln(x,\" \",get(x),\" \",t,\" \",t%a);\n\t\tif(dat[to!int(t%a)]!=-1&&dat[to!int(t%a)]!=t)\n\t\t{\n\t\t\twriteln(dat[to!int(t%a)]+1,\" \",t);\n\t\t\tbreak;\n\t\t}\n\t\tdat[to!int(t%a)]=t;\n\t}\n\treadln();\n}"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.bigint;\nimport std.string;\nBigInt get(BigInt a)\n{\n\tBigInt beg=0,end=\"100000000000000000000000000000\";\n\tfor(;;)\n\t{\n\t\tif(beg==end)break;\n\t\tBigInt med=(beg+end)/2;\n\t\tBigInt n=med;\n\t\tint[]v;\n\t\tfor(;;)\n\t\t{\n\t\t\tif(n==0)break;\n\t\t\tv~=n%10;\n\t\t\tn/=10;\n\t\t}\n\t\tBigInt cnt=0;\n\t\tBigInt t=1;\n\t\tfor(int i=0;i<v.length;i++)\n\t\t{\n\t\t\tBigInt[]x;\n\t\t\tx.length=10;\n\t\t\tfor(int j=0;j<=9;j++)\n\t\t\t{\n\t\t\t\tx[j]+=(med/(t*10))*t;\n\t\t\t\tif(med/(t*10)*10+j<med/t)x[j]+=t;\n\t\t\t\telse if(med/(t*10)*10+j==med/t)x[j]+=med-(med/(t*10)*10+j)*t+1;\n\t\t\t}\n\t\t\tfor(int j=0;j<=9;j++)cnt+=x[j]*j;\n\t\t\tt*=10;\n\t\t}\n\t\tif(cnt<a)beg=med+1;\n\t\telse end=med;\n\t}\n\treturn beg;\n}\nvoid main()\n{\n\tBigInt a=to!BigInt(chomp(readln()));\n\tBigInt[]dat;\n\tdat.length=1000;\n\tfor(int i=0;;i++)\n\t{\n\t\tBigInt t;\n\t\tBigInt x=a*i;\n\t\tt=get(x);\n\t\tif(dat[to!int(t%a)]!=0)\n\t\t{\n\t\t\twriteln(dat[to!int(t%a)]+1,\" \",t);\n\t\t\tbreak;\n\t\t}\n\t\tdat[to!int(t%a)]=t;\n\t}\n\treadln();\n}"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.bigint;\nimport std.string;\nBigInt calc(BigInt n)\n{\n\tBigInt med=n;\n\tint[]v;\n\tfor(;;)\n\t{\n\t\tif(n==0)break;\n\t\tv~=n%10;\n\t\tn/=10;\n\t}\n\tBigInt cnt=0;\n\tBigInt t=1;\n\tfor(int i=0;i<v.length;i++)\n\t{\n\t\tBigInt[]x;\n\t\tx.length=10;\n\t\tfor(int j=0;j<=9;j++)\n\t\t{\n\t\t\tx[j]+=(med/(t*10))*t;\n\t\t\tif(med/(t*10)*10+j<med/t)x[j]+=t;\n\t\t\telse if(med/(t*10)*10+j==med/t)x[j]+=med-(med/(t*10)*10+j)*t+1;\n\t\t}\n\t\tfor(int j=0;j<=9;j++)cnt+=x[j]*j;\n\t\tt*=10;\n\t}\n\treturn cnt;\n}\nBigInt get(BigInt a)\n{\n\tBigInt beg=0,end=\"100000000000000000000000000000\";\n\tfor(;;)\n\t{\n\t\tif(beg==end)break;\n\t\tBigInt med=(beg+end)/2;\n\t\tBigInt cnt=calc(med);\n\t\tif(cnt<a)beg=med+1;\n\t\telse end=med;\n\t}\n\treturn beg;\n}\nvoid main()\n{\n\t//for(int i=0;i<110;i++)writeln(i,\" \",get(to!BigInt(i)));\n\tBigInt a=to!BigInt(chomp(readln()));\n\tBigInt[]dat;\n\tdat.length=1000;\n\tfor(int i=0;;i++)\n\t{\n\t\tBigInt t;\n\t\tBigInt x=a*i;\n\t\tt=calc(get(x));\n\t\tif(dat[to!int(t%a)]!=0)\n\t\t{\n\t\t\twriteln(dat[to!int(t%a)]+1,\" \",t);\n\t\t\tbreak;\n\t\t}\n\t\tdat[to!int(t%a)]=t;\n\t}\n\treadln();\n}"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nlong A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = readLong;\n\t\t\n\t\tlong l = 1_000_000_000_000_000_000;\n\t\tlong r = 2_000_000_000_000_000_000;\n\t\t\n\t\tlong sum;\n\t\tforeach (i; 0 .. 18) {\n\t\t\t(sum += (r - l) / 10 * 45) %= A;\n\t\t}\n\t\tl -= sum;\n\t\tr -= sum;\n\t\twriteln(l, \" \", r - 1);\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "src_uid": "52b8d97f216ea22693bc16fadcd46dae"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int MAX = 105;\n\nchar[MAX][MAX] t;\nbool[MAX][MAX] b;\nint[MAX] f;\n\nvoid main() {\n int n, m;\n readf(\" %s %s\", n, m);\n\n\n foreach(i; 0..n) {\n foreach(j; 0..m) {\n readf(\" %s\", t[i][j+1]);\n }\n }\n\n foreach(j; 1..m+1) {\n foreach(k; 0..j) {\n auto combi = true;\n foreach(i; 0..n-1) {\n if (!b[i][k] && t[i][j] > t[i+1][j]) {\n combi = false;\n break;\n }\n }\n if (!combi) {\n continue;\n }\n\n if (f[j] < f[k] + 1) {\n f[j] = f[k] + 1;\n foreach(i; 0..n-1) {\n b[i][j] = b[i][k] | (t[i][j] < t[i+1][j]);\n }\n }\n }\n } \n\n auto cols = 0;\n foreach(j; 1..m+1) {\n cols = max(cols, f[j]);\n }\n writeln(m - cols);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto F = new string[N];\n foreach (i; 0 .. N) {\n F[i] = readln.chomp;\n }\n\n int ans = 0;\n string[][] xs = [ F ];\n void C() {\n foreach (x; xs) {\n auto y = x.map!((s) => s[0]).array;\n auto y1 = y.dup;\n y1.sort;\n if (y != y1) {\n ans++;\n xs = xs.map!((x) => x.map!\"a[ 1 .. $ ]\".array).array;\n return;\n }\n }\n string[][] nxs;\n foreach (x; xs) {\n char p = x[0][0];\n string[] buf;\n foreach (y; x) {\n if (p == y[0]) {\n buf ~= y;\n } else {\n p = y[0];\n nxs ~= [buf];\n buf = [ y ];\n }\n }\n if (!buf.empty) nxs ~= [buf];\n }\n //writeln(nxs);\n xs = nxs.map!((x) => x.map!\"a[ 1 .. $ ]\".array).array;\n }\n\n foreach (i; 0 .. M) {\n C();\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s \", &n, &m) > 0)\n\t{\n\t\tstring [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= readln ().strip ();\n\t\t}\n\t\tauto b = new bool [n];\n\t\tlong res = 0;\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tbool ok = true;\n\t\t\tforeach (i; 1..n)\n\t\t\t{\n\t\t\t\tok &= b[i] || (s[i][j] >= s[i - 1][j]);\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t{\n\t\t\t\tres++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach (i; 1..n)\n\t\t\t\t{\n\t\t\t\t\tb[i] |= (s[i][j] > s[i - 1][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto F = new string[N];\n foreach (i; 0 .. N) {\n F[i] = readln.chomp;\n }\n\n int ans = 0;\n\n bool C(int x) {\n auto cs = new char[N];\n foreach (i; 0 .. N) {\n cs[i] = F[i][x];\n }\n auto ds = cs.dup;\n ds.sort;\n return cs == ds;\n }\n\n foreach (i; 0 .. M) {\n if (C(i)) {\n auto c = F[0][i];\n auto j = 0;\n while (j < N && c == F[j][i]) {\n j++;\n }\n F = F[0 .. j];\n N = j;\n } else {\n ans++;\n }\n }\n writeln(ans);\n}\n"}], "src_uid": "a45cfc2855f82f162133930d9834a9f0"} {"source_code": "// https://codeforces.com/contest/1104/problem/B\nimport std.stdio;\nimport std.string;\nimport std.range.primitives;\n\nvoid main() {\n string s = readln.chomp;\n char[] stack;\n bool first = false;\n foreach(ch; s) {\n if(stack.length > 0 && stack[$-1] == ch) {\n stack.popBack();\n first = !first;\n } else {\n stack ~= ch;\n }\n }\n if(first)\n writeln(\"Yes\");\n else\n writeln(\"No\");\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm: max;\n\nvoid main() {\n\tstring s = readln;\n\tchar[] t = ['#'];\n\tforeach (char c; s) {\n\t\tt ~= [c];\n\t\tif (c==t[$-2]) t=t[0..$-2];\n\t}\t\n\tif ((s.count - t.count) / 2 % 2 == 0) {\n\t\twriteln(\"Yes\");\n\t} else {\n\t\twriteln(\"No\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm: max;\n\nvoid main() {\n\tstring s = readln;\n\tstring t = \"#\";\n\tforeach (char c; s) {\n\t\tt ~= c;\n\t\tif (c==t[$-2]) t=t[0..$-2];\n\t}\t\n\tif (s.count - t.count / 2 % 2 == 0) {\n\t\twriteln(\"Yes\");\n\t} else {\n\t\twriteln(\"No\");\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm: max;\nimport std.range.primitives: popBack;\n\nvoid main() {\n\tstring s = readln;\n\tchar[] t = ['#'];\n\tforeach (char c; s) {\n\t\tif (c==t[$-1]) t.popBack;\n\t\tt ~= [c];\n\t}\t\n\tif ((s.count - t.count) / 2 % 2 == 0) {\n\t\twriteln(\"Yes\");\n\t} else {\n\t\twriteln(\"No\");\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\tstring a = readln;\n\tbool conseguido = true;\n\tint b = 0;\n\twhile (conseguido) {\n\t\tconseguido = false;\n\t\tfor (int i=1; i<a.count; i++) {\n\t\t\tif (a[i-1] == a[i]) {\n\t\t\t\ta = a[i+1..$];\n\t\t\t\tconseguido = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tb += 1;\n\t}\n\t\t\n\tif (b % 2 == 0) {\n\t\twriteln(\"Yes\");\n\t} else {\n\t\twriteln(\"No\");\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\tstring a = readln;\n\tbool conseguido = true;\n\tint b = 0;\n\tint last = 1;\n\twhile (conseguido) {\n\t\tconseguido = false;\n\t\tfor (int i=last; i<a.count; i++) {\n\t\t\tif (a[i-1] == a[i]) {\n\t\t\t\ta = a[0..i-1] ~ a[i+1..$];\n\t\t\t\tconseguido = true;\n\t\t\t\tlast = i-2;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tb += 1;\n\t}\n\t\t\n\tif (b % 2 == 0) {\n\t\twriteln(\"Yes\");\n\t} else {\n\t\twriteln(\"No\");\n\t}\n}\n"}], "src_uid": "8fd51c391728b433cc94923820e908ff"} {"source_code": "import std.stdio: writefln, readf;\nimport std.string;\nimport std.conv: to;\nimport std.array: array;\nimport std.algorithm: map, sort, max;\n\nvoid main() {\n\tint n;\n\treadf(\"%s\", &n);\n \n\tint l;\n\treadf(\" %s\", &l);\n\n\tint[] a = new int[n];\n\tforeach (ref x; a)\n\t\treadf(\" %s\", &x);\n\ta.sort;\n\n\tdouble dif = max(a[0], l - a[n-1]) * 2;\n\tfor (int i = 1; i < n; i++) {\n\t\tdif = max(dif, a[i] - a[i - 1]);\n\t}\n\n\tdif /= 2.0;\n\n\twritefln(\"%.10f\", dif);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.regex;\nimport std.algorithm.iteration;\nimport std.algorithm.searching;\nimport std.algorithm.sorting;\nimport std.array;\nimport std.range;\nimport std.algorithm.comparison;\n\nvoid main()\n{\n auto nl = stdin.readln.strip.split(regex(` +`)).map!(to!int).array;\n auto n = nl[0], l=nl[1];\n auto as = stdin.readln.strip.split(regex(` +`)).map!(to!int).array;\n double a = any!(a => a==l)(as) ? 0 : l - as.maxElement;\n double b = any!(a => a==0)(as) ? 0 : as.minElement;\n as.sort();\n writef(\"%.9f\", max( (as.length>1 ? as.slide(2).map!\"a[1]-a[0]\".array.maxElement.to!double / 2:0), a, b));\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n;\n\tint l;\n\tscanf(\"%d %d\", &n, &l);\n\tint[] lanterns; lanterns.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &lanterns[i]);\n\t}\n\tlanterns.sort!(\"a < b\");\n\tint max = (lanterns[0] - 0) * 2;\n\tforeach (int i; 1..lanterns.length)\n\t{\n\t\tint diff = lanterns[i] - lanterns[i-1];\n\t\tif (diff > max) max = diff;\n\t}\n\tif (((l - lanterns[$-1]) * 2) > max) max = (l - lanterns[$-1]) * 2;\n\tprintf(\"%.10f\", (cast(float)max / 2.0f));\n\treturn 0;\n}"}, {"source_code": "import std.stdio: writefln, readf;\nimport std.string;\nimport std.conv: to;\nimport std.array: array;\nimport std.algorithm: map, sort, max;\n\nvoid main() {\n\tint n, l;\n\treadf(\"%d %d\", &n, &l);\n\n\tint[] a = new int[n];\n\tforeach (ref x; a)\n\t\treadf(\" %d\", &x);\n\ta.sort;\n\n\tint dif;\n\tdouble max_dif;\n \tif (a[0] > l - a[n-1]) max_dif = a[0] * 2; else max_dif = (l - a[$-1]) * 2;\n\tforeach (int i; 1..n) {\n\t\tdif = a[i] - a[i - 1];\n\t\tif (dif > max_dif) max_dif = dif;\n\t}\n\n\twritefln(\"%.10f\", max_dif / 2.0);\n}\n"}, {"source_code": "import std.stdio: writefln, readf;\nimport std.string;\nimport std.conv: to;\nimport std.array: array;\nimport std.algorithm: map, sort, max;\n\nvoid main() {\n\tint n, l;\n\treadf(\"%d %d\", &n, &l);\n\n\tint[] a = new int[n];\n\tforeach (ref x; a)\n\t\treadf(\" %d\", &x);\n\ta.sort;\n\n\tint dif;\n\tdouble max_dif = max(a[0], l - a[n-1]) * 2;\n\tforeach (int i; 1..n) {\n\t\tdif = a[i] - a[i - 1];\n\t\tif (dif > max_dif) max_dif = dif;\n\t}\n\n\twritefln(\"%.10f\", max_dif / 2.0);\n}\n"}, {"source_code": "import std.stdio: writefln, readln;\nimport std.string;\nimport std.conv: to;\nimport std.array: array;\nimport std.algorithm: map, sort, max;\n\nvoid main() {\n\tint[2] line = readln.chomp.split(\" \").map!(to!int).array;\n\tint n = line[0];\n\tint l = line[1];\n\n\tint[] a = readln.chomp.split(\" \").map!(to!int).array.sort.array;\n\n\tdouble dif = max(a[0], l - a[n-1]) * 2;\n\tfor (int i = 1; i < n; i++) {\n\t\tdif = max(dif, a[i] - a[i - 1]);\n\t}\n\n\tdif /= 2.0;\n\n\twritefln(\"%.10f\", dif);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() { while (solve()) {} }\n\nbool solve() {\n\tint n;\n\tif (readf(\" %s\", &n) != 1) return false;\n\n\tint len;\n\treadf(\" %s\", &len);\n\tint[] a = new int[n];\n\tforeach (ref x; a)\n\t\treadf(\" %s\", &x);\n\ta.sort;\n\tint res = 0;\n\tforeach (i; 1..n) {\n\t\tres = max(res, a[i] - a[i - 1]);\n\t}\n\tres = max(res, max(len - a[$ - 1], a[0]) * 2);\n\n\twritef(\"%s\", res / 2);\n\tif (res % 2 != 0)\n\t\twritef(\".5\");\n\twriteln;\n\n\treturn true;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() { while (solve()) {} }\n\nbool solve() {\n\tint n;\n\tif (readf(\" %s\", &n) != 1) return false;\n\n\tint len;\n\treadf(\" %s\", &len);\n\tint[] a = new int[n];\n\tforeach (ref x; a)\n\t\treadf(\" %s\", &x);\n\ta.sort;\n\tint res = 0;\n\tforeach (i; 1..n) {\n\t\tres = max(res, a[i] - a[i - 1]);\n\t}\n\tres = max(res, max(len - a[$ - 1], a[0]) * 2);\n\n\twritef(\"%s\", res / 2);\n\tif (res % 2 != 0)\n\t\twritef(\".5\");\n\twriteln;\n\n\treturn true;\n}"}], "negative_code": [{"source_code": "import std.stdio: writeln, readln;\nimport std.string;\nimport std.conv: to;\nimport std.array: array;\nimport std.algorithm: map, sort, max;\n\nvoid main() {\n\tint[2] line = readln.chomp.split(\" \").map!(to!int).array;\n\tint n = line[0];\n\tint l = line[1];\n\n\tint[] a = readln.chomp.split(\" \").map!(to!int).array.sort.array;\n\n\tfloat dif = max(a[0], l - a[a.count - 1]);\n\tfor (int i = 1; i < n; i++) {\n\t\tdif = max(dif, (a[i] - a[i - 1]) / 2.0);\n\t}\n\n\tdif.writeln;\n}\n"}], "src_uid": "d79166497eb61d81fdfa4ef80ec1c8e8"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable long mod = 998_244_353;\n\nvoid main()\n{\n int n;\n readf!\" %s \"(n);\n string s = readln.strip;\n\n long pre = 0, post = 0;\n foreach (c; s) {\n if (c == s[0]) pre++;\n else break;\n }\n\n foreach_reverse (c; s) {\n if (c == s[n-1]) post++;\n else break;\n }\n\n long ans = 1 + pre + post;\n\n if (s[0] == s[n-1]) {\n ans = (ans + pre * post % mod) % mod;\n }\n\n writeln(ans);\n}\n", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto s = readln.chomp.to!(char[]);\n\n auto bf = new int[](26), af = new int[](26);\n int kind = 0;\n foreach (c; s) {\n af[c - 'a']++;\n if (af[c - 'a'] == 1) {\n kind++;\n }\n }\n int ans = 0, mod = 998244353;\n for (int i = 0, j = 0; i < n; i++) { // [i, j) remove\n while (j < n && kind >= 2) {\n if ((--af[s[j++] - 'a']) == 0) {\n kind--;\n }\n }\n if (kind == 1) {\n ans += (n - j + 1);\n ans %= mod;\n }\n if ((++af[s[i] - 'a']) == 1) {\n kind++;\n }\n }\n writeln(ans);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\nconst ll mod = 998244353;\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\\n\", n);\n string s = readln.strip;\n\n\n long sb = -1;\n foreach(i; 0 .. s.length) if (s[i] != s[0]) { sb = i; break; }\n\n long se = -1;\n foreach_reverse(i; 0 .. s.length) if (s[i] != s[$-1]) { se = i; break; }\n \n\n long ans = 1;\n if (sb == -1) {\n ans = (s.length * (s.length+1) / 2 ) % mod;\n } else if (s[0] == s[$-1]) {\n ans = ((sb + 1L) * ( s.length - se ) ) % mod;\n\n } else { // two different cases?\n ans = ( (sb + 1) + ( s.length - se) - 1 ) % mod;\n }\n\n writeln(ans);\n\n\n}\n"}], "negative_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto s = readln.chomp.to!(char[]);\n\n auto bf = new int[](26), af = new int[](26);\n int kind = 0;\n foreach (c; s) {\n af[c - 'a']++;\n if (af[c - 'a'] == 1) {\n kind++;\n }\n }\n int ans = 0;\n for (int i = 0, j = 0; i < n; i++) { // [i, j) remove\n while (j < n && kind >= 2) {\n if ((--af[s[j++] - 'a']) == 0) {\n kind--;\n }\n // writeln(j, \" \", kind);\n }\n if (kind == 1) {\n ans += (n - j + 1);\n }\n // writeln(\"! \", i, \" \", j, \" \", kind, \" \", ans);\n // while (i <= j && kind < 2) {\n // if ((++af[s[i++] - 'a']) == 1) {\n // kind++;\n // }\n // if (kind == 1) {\n // ans++;\n // }\n // }\n if ((++af[s[i] - 'a']) == 1) {\n kind++;\n }\n // writeln(i, \" \", j, \" \", kind, \" \", ans);\n }\n writeln(ans);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\nalias ll = long;\nconst ll mod = 998244353;\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\\n\", n);\n string s = readln.strip;\n\n\n int sb = -1;\n foreach(i; 0 .. s.length) if (s[i] != s[0]) { sb = i; break; }\n\n int se = -1;\n foreach_reverse(i; 0 .. s.length) if (s[i] != s[$-1]) { se = i; break; }\n \n\n long ans = 1;\n if (sb == -1) {\n ans = (s.length * (s.length+1) / 2 ) % mod;\n } else if (s[0] == s[$-1]) {\n ans = ((sb + 1) * ( s.length - se ) ) % mod;\n\n } else { // two different cases?\n ans = ( (sb + 1) + ( s.length - se) - 1 ) % mod;\n }\n\n writeln(ans);\n\n\n}\n"}], "src_uid": "9693f60fc65065d00a1899df999405fe"} {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable string vowels = \"aeiou\";\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tstring [] res;\nmain_loop:\n\t\twhile (!s.empty)\n\t\t{\n\t\t\tforeach (i; 2..s.length)\n\t\t\t{\n\t\t\t\tif (!vowels.canFind (s[i - 2]) &&\n\t\t\t\t !vowels.canFind (s[i - 1]) &&\n\t\t\t\t !vowels.canFind (s[i - 0]) &&\n\t\t\t\t (s[i - 2] != s[i - 1] ||\n\t\t\t\t s[i - 1] != s[i - 0]))\n\t\t\t\t{\n\t\t\t\t\tres ~= s[0..i];\n\t\t\t\t\ts = s[i..$];\n\t\t\t\t\tcontinue main_loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres ~= s;\n\t\t\ts = \"\";\n\t\t}\n\t\tres.join (\" \").writeln;\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nbool isCon(char c) {\n return (\" aeiou\".indexOf(c) == -1);\n}\n\nbool isBad(char a, char b, char c) {\n return (isCon(a) && isCon(b) && isCon(c) && !(a == b && a == c));\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const S = readToken();\n \n string ans;\n foreach (c; S) {\n for (; ans.length >= 2 && isBad(ans[$ - 2], ans[$ - 1], c); ) {\n ans ~= ' ';\n }\n ans ~= c;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "436c00c832de8df739fc391f2ed6dac4"} {"source_code": "import std;\n\nalias range = Tuple!(int, \"l\", int, \"r\");\n\nvoid main () {\n immutable tests = to!int(readln().dropBackOne);\n\n foreach (test_index; 0 .. tests) {\n immutable n = to!int(readln().dropBackOne);\n\n immutable x = stdin\n .byLine\n .take(n)\n .map!(l => range(l.split.to!(int[2])))\n .array\n .sort!\"a.r - a.l < b.r - b.l\"\n .release\n .assumeUnique;\n\n auto notSeen = redBlackTree(iota(1, n + 1));\n auto viz = new bool[n + 1];\n\n foreach (_, t; x) {\n immutable num = (){\n if (!viz[t.l])\n return t.l;\n if (!viz[t.r])\n return t.r;\n return notSeen.upperBound(t.l).front;\n }();\n\n writefln!\"%s %s %s\"(t.l, t.r, num);\n viz[num] = true;\n notSeen.removeKey(num);\n }\n\n writeln();\n }\n}\n// \"\"\n", "positive_code": [{"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n int n;\n read(n);\n\n int[][] arr = new int[][n];\n\n foreach (i; 0 .. n) {\n arr[i] = list!int;\n }\n\n foreach (range; arr) {\n if (range.front == range.back) {\n writeln(range.front, ' ', range.back, ' ', range.back);\n } else if (arr.canFind([range.front + 1, range.back])) {\n writeln(range.front, ' ', range.back, ' ', range.front);\n } else if (arr.canFind([range.front, range.back - 1])) {\n writeln(range.front, ' ', range.back, ' ', range.back);\n } else {\n foreach (d; range.front + 1 .. range.back) {\n if (arr.canFind([range.front, d - 1]) && arr.canFind([d + 1, range.back])) {\n writeln(range.front, ' ', range.back, ' ', d);\n }\n }\n }\n }\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto lr = new int[][](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t\tlr[i] = [RD!int, RD!int];\r\n\r\n\t\tlr.sort!(\"a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]\");\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tif (lr[i-1][0] == lr[i-1][1])\r\n\t\t\t\tans[ti] ~= lr[i-1] ~ lr[i-1][0];\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (lr[i-1][0] != lr[i][0])\r\n\t\t\t\t\tans[ti] ~= lr[i-1] ~ (lr[i][0]-1);\r\n\t\t\t\telse\r\n\t\t\t\t\tans[ti] ~= lr[i-1] ~ (lr[i][1]+1);\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] ~= lr[n-1] ~ lr[n-1][0];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tforeach (ee; e)\r\n\t\t\twriteln(ee[0], \" \", ee[1], \" \", ee[2]);\r\n\t\twriteln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "// \u63d0\u51fa\u89e3\r\nvoid solve(){\r\n\tforeach(_; 0 .. scan!int){\r\n\t\tint n = scan!int;\r\n\t\tint[][] us = new int[][](n), vs = new int[][](n);\r\n\t\t\t// us[a][]: \u5de6\u7aef\u304ca\u3067\u3042\u308b\u53f3\u7aef\u3001vs[b][]:\u53f3\u7aef\u304cb\u3067\u3042\u308b\u5de6\u7aef\r\n\t\tforeach(i; 0 .. n){\r\n\t\t\tint l = scan!int - 1, r = scan!int - 1;\r\n\t\t\tus[l] ~= r, vs[r] ~= l;\r\n\t\t}\r\n\t\tforeach(i; 0 .. n) us[i].sort!\"a>b\";\r\n\t\tforeach(i; 0 .. n) vs[i].sort!\"a<b\";\r\n\t\tforeach(i; 0 .. n) foreach(r, j; us[i]){\r\n\t\t\tif(r == us[i].length - 1) print(i + 1, j + 1, i + 1);\r\n\t\t\telse print(i + 1, j + 1, us[i][r + 1] + 1 + 1);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u611a\u76f4\u89e3\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30f3\u30d7\u30ec\r\nimport std;\r\nbool DEBUG = 0;\r\nvoid main(string[] args){\r\n\tif(args.canFind(\"-debug\")) DEBUG = 1;\r\n\tif(args.canFind(\"-gen\")) gen; else if(args.canFind(\"-jury\")) jury; else solve;\r\n}\r\nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\r\nvoid print(){ writeln(\"\"); }\r\nvoid print(T)(T t){ writeln(t); }\r\nvoid print(T, A ...)(T t, A a){ stdout.write(t, \" \"), print(a); }\r\nstring unsplit(T)(T xs, string d = \" \"){ return xs.array.to!(string[]).join(d); }\r\nstring scan(){\r\n\tstatic string[] ss; while(!ss.length) ss = readln.chomp.split;\r\n\tstring res = ss[0]; ss.popFront; return res;\r\n}\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\r\nT mini(T)(ref T x, T y){ if(x > y) x = y; return x; }\r\nT maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }\r\nT mid(T)(T l, T r, bool delegate(T) f){\r\n\tT m = (l + r) / 2; (f(m)? l: r) = m; return f(l)? f(r - 1)? r: mid(l, r, f): l;\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u57fa\u672c\uff09\r\n\r\nclass UnionFind{\r\n\tthis(int n){ foreach(i; 0 .. n) R ~= i, K ~= [i]; } int[] R; int[][] K;\r\n\tvoid unite(int a, int b){\r\n\t\tint ra = R[a], rb = R[b]; if(ra == rb) return;\r\n\t\tif(K[ra].length < K[rb].length) unite(b, a);\r\n\t\telse foreach(k; K[rb]) R[k] = ra, K[ra] ~= k;\r\n\t}\r\n\tint find(int a){ return R[a]; }\r\n\tint getSize(int a){ return K[R[a]].length.to!int; }\r\n}\r\nclass Queue(T){\r\n\tprivate T[] xs; private uint i, j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j - i; }\r\n\tbool isEmpty(){ return j == i; } \r\n\tvoid enq(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT deq(){ assert(i < j); return xs[i ++]; }\r\n\tT peek(){ assert(i < j); return xs[i]; }\r\n\tvoid flush(){ i = j; }\r\n\talias empty = isEmpty, front = peek, popFront = deq, pop = deq, push = enq, top = peek;\r\n\tQueue opOpAssign(string op)(T x) if(op == \"~\"){ enq(x); return this; }\r\n\tT opIndex(uint li){ assert(i + li < j); return xs[i + li]; }\r\n\tstatic Queue!T opCall(T[] xs){ return new Queue!T(xs); }\r\n\tT[] array(){ return xs[i .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\nclass Stack(T){\r\n\tprivate T[] xs; private uint j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j; }\r\n\tbool isEmpty(){ return j == 0; }\r\n\tvoid push(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT pop(){ assert(j > 0); return xs[-- j]; }\r\n\tT peek(){ assert(j > 0); return xs[j - 1]; }\r\n\tvoid clear(){ j = 0; }\r\n\talias empty = isEmpty, front = peek, popFront = pop, top = peek;\r\n\tStack opOpAssign(string op)(T x) if(op == \"~\"){ push(x); return this; }\r\n\tT opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }\r\n\tstatic Stack!T opCall(T[] xs = []){ return new Stack!T(xs); }\r\n\tT[] array(){ return xs[0 .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u8ffd\u52a0\uff09\r\n\r\n\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto R = scan!int(N * 2).chunks(2).array;\r\n string[] ans;\r\n \r\n bool[1001] visited;\r\n foreach(lr; R.sort!\"(a[1] - a[0]).abs < (b[1] - b[0]).abs\") {\r\n int n;\r\n foreach(m; lr[0]..lr[1] + 1) {\r\n if (!visited[m]) {\r\n n = m;\r\n visited[m] = true;\r\n break;\r\n }\r\n }\r\n ans ~= [lr[0], lr[1], n].toAnswerString;\r\n }\r\n\r\n ans.each!writeln;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n if (i > 0) \"\".writeln;\r\n subSolve();\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}"}], "negative_code": [{"source_code": "import std;\n\nalias range = Tuple!(int, \"l\", int, \"r\");\n\nvoid main () {\n immutable tests = to!int(readln().dropBackOne);\n\n foreach (test_index; 0 .. tests) {\n immutable n = to!int(readln().dropBackOne);\n\n immutable x = stdin\n .byLine\n .take(n)\n .map!(l => range(l.split.to!(int[2])))\n .array\n .sort!\"a.r - a.l < b.r - b.l\"\n .release\n .assumeUnique;\n\n auto notSeen = redBlackTree(iota(1, n + 1));\n auto viz = new bool[n + 1];\n\n foreach (_, t; x) {\n assert(t.l == t.r || viz[t.l] || viz[t.r]);\n\n immutable num = (){\n if (!viz[t.l])\n return t.l;\n if (!viz[t.r])\n return t.r;\n return notSeen.upperBound(t.l).back;\n }();\n\n writefln!\"%s %s %s\"(t.l, t.r, num);\n viz[num] = true;\n notSeen.removeKey(num);\n }\n\n writeln();\n }\n}\n// \"\"\n"}], "src_uid": "eca433877ef3fbda198c5f2c95a359e7"} {"source_code": "import std.stdio;\n\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n\tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n\nint main()\n{\n int n;\n r(n);\n foreach(e; 0 .. n)\n {\n int c, sum;\n r(c, sum);\n\t{\n\t int avg = sum / c;\n\t int residue = sum % c;\n\t if (residue > 0)\n\t {\n\t w(avg * avg * (c - residue) + (avg + 1) * (avg + 1) * residue);\n\t }\n\t else\n\t {\n\t w(avg * avg * c);\n\t }\n\t}\n }\n \n\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto ans = new int[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto c = RD!int;\n\t\tauto sum = RD!int;\n\t\tauto x = sum / c;\n\t\tauto y = sum % c;\n\t\tans[i] += ((x+1)^^2) * y;\n\t\tans[i] += (x^^2) * (c - y);\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tforeach(i; 0 .. n){\n\t\tlong c = rlong, s = rlong;\n\t\tlong x = s / c, d = s % c;\n\t\tlong ans = (c - d) * x * x + d * (x + 1) * (x + 1);\n\t\tans.writeln;\n\t}\n}\n"}], "negative_code": [], "src_uid": "0ec973bf4ad209de9731818c75469541"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).uniq.array;\r\n\t\ta = [-2, -1] ~ a;\r\n\t\tn = a.length;\r\n\t\tint res = 0;\r\n\t\tbool [int] seen;\r\n\t\tforeach (i; 2..n)\r\n\t\t{\r\n\t\t\tauto cur = a[i];\r\n\t\t\tif (cur == a[i - 2])\r\n\t\t\t{\r\n\t\t\t\tseen = null;\r\n\t\t\t\tseen[a[i - 1]] = true;\r\n\t\t\t\tseen[a[i]] = true;\r\n\t\t\t}\r\n\t\t\telse if (cur in seen)\r\n\t\t\t{\r\n\t\t\t\tseen = null;\r\n\t\t\t\tseen[a[i - 1]] = true;\r\n\t\t\t\tseen[a[i]] = true;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tseen[a[i]] = true;\r\n\t\t\t\tres += 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n int N = readInt();\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt();\r\n }\r\n A = A.uniq.array;\r\n N = cast(int)(A.length);\r\n debug {\r\n writeln(\"A = \", A);\r\n }\r\n \r\n const lim = A.maxElement + 1;\r\n auto app = new int[lim];\r\n app[] = -1;\r\n auto dp = new int[N + 1];\r\n foreach (i; 0 .. N) {\r\n dp[i + 1] = dp[i];\r\n const j = app[A[i]];\r\n if (j != -1) {\r\n chmax(dp[i + 1], dp[j + 2] + 1);\r\n if (j - 1 >= 0 && A[j - 1] == A[j + 1]) {\r\n chmax(dp[i + 1], dp[j + 1] + 2);\r\n }\r\n }\r\n app[A[i]] = i;\r\n }\r\n writeln(N - dp[N]);\r\n \r\n debug {\r\n int brt = N;\r\n foreach (p; 0 .. 1 << N) {\r\n int cost;\r\n int[2] bs = [-1, -1];\r\n foreach (i; 0 .. N) {\r\n const s = (p >> i) & 1;\r\n if (bs[s] != A[i]) {\r\n ++cost;\r\n bs[s] = A[i];\r\n }\r\n }\r\n chmin(brt, cost);\r\n }\r\n writeln(\"brt = \", brt);\r\n assert(brt == N - dp[N]);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid main(){\n auto n = scan!int;\n auto arr = scanArray!int;\n auto seen = redBlackTree!int;\n int[] seg1, seg2;\n int[] cur;\n\n seg1 ~= arr[0];\n int i = 1;\n while(i < n && arr[i] == seg1.back){\n seg1 ~= arr[i];\n ++i;\n }\n if(i < n){\n seg2 ~= arr[i]; ++i;\n seen.insert([seg1.back, seg2.back]);\n }\n\n while(i < n){\n if(cur.length && arr[i] == cur.back){\n cur ~= arr[i];\n }else if(arr[i] in seen){\n if(arr[i] == seg2.back){\n seg2 ~= arr[i];\n foreach(el; cur){\n if(el == arr[i]){\n seg2 ~= el;\n }else{\n seg1 ~= el;\n }\n }\n }else{\n seg1 ~= arr[i];\n foreach(el; cur){\n if(el == arr[i]){\n seg1 ~= el;\n }else{\n seg2 ~= el;\n }\n }\n }\n\n // Reset seen & cur\n seen.clear;\n seen.insert([seg1.back, seg2.back]);\n cur = [];\n }else{\n cur ~= arr[i];\n seen.insert(arr[i]);\n }\n ++i;\n }\n // Post while\n seg2 ~= cur;\n cur = []; seen.clear;\n\n show(seg1, seg2);\n\n // Calc Answer\n auto res = 1;\n for(int k = 1; k < seg1.length; ++k){\n if(seg1[k] != seg1[k-1]){ ++res; }\n }\n res += (seg2.length > 0);\n for(int k = 1; k < seg2.length; ++k){\n if(seg2[k] != seg2[k-1]){ ++res; }\n }\n\n writeln(res);\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int N; get(N);\r\n int[] aa; get(aa);\r\n auto nxt = new int[][10^^5 + 1];\r\n foreach (i, a; aa) nxt[a] ~= i.to!int;\r\n \r\n int x, y, c;\r\n foreach (a; aa) {\r\n nxt[a].popFront();\r\n if (a == x || a == y) continue;\r\n if (nxt[x].empty) {\r\n x = a;\r\n } else if (nxt[y].empty) {\r\n y = a;\r\n } else if (nxt[x].front > nxt[y].front) {\r\n x = a;\r\n } else {\r\n y = a;\r\n }\r\n ++c;\r\n }\r\n writeln(c);\r\n}"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid main(){\n auto n = scan!int;\n auto arr = scanArray!int;\n auto seen = redBlackTree!int;\n int[] seg1, seg2;\n int[] cur;\n\n seg1 ~= arr[0];\n int i = 1;\n while(i < n && arr[i] == seg1.back){\n seg1 ~= arr[i];\n ++i;\n }\n if(i < n){\n seg2 ~= arr[i]; ++i;\n seen.insert([seg1.back, seg2.back]);\n }\n\n while(i < n){\n if(cur.length && arr[i] == cur.back){\n cur ~= arr[i];\n }else if(arr[i] in seen){\n if(arr[i] == seg2.back){\n seg2 ~= arr[i];\n foreach(el; cur){\n if(el == arr[i]){\n seg2 ~= el;\n }else{\n seg1 ~= el;\n }\n }\n }else{\n seg1 ~= arr[i];\n foreach(el; cur){\n if(el == arr[i]){\n seg1 ~= el;\n }else{\n seg2 ~= el;\n }\n }\n }\n\n // Reset seen & cur\n seen.clear;\n seen.insert([seg1.back, seg2.back]);\n cur = [];\n }else{\n cur ~= arr[i];\n }\n ++i;\n }\n // Post while\n seg2 ~= cur;\n cur = []; seen.clear;\n\n show(seg1, seg2);\n\n // Calc Answer\n auto res = 1;\n for(int k = 1; k < seg1.length; ++k){\n if(seg1[k] != seg1[k-1]){ ++res; }\n }\n res += (seg2.length > 0);\n for(int k = 1; k < seg2.length; ++k){\n if(seg2[k] != seg2[k-1]){ ++res; }\n }\n\n writeln(res);\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid main(){\n auto n = scan!int;\n auto arr = scanArray!int;\n auto seen = redBlackTree!int;\n int[] seg1, seg2;\n int[] cur;\n\n seg1 ~= arr[0];\n int i = 1;\n while(i < n && arr[i] == seg1.back){\n seg1 ~= arr[i];\n ++i;\n }\n if(i < n){\n seg2 ~= arr[i]; ++i;\n seen.insert([seg1.back, seg2.back]);\n }\n\n while(i < n){\n if(arr[i] in seen){\n if(arr[i] == seg2.back){\n seg1 ~= cur;\n seg2 ~= arr[i];\n }else{\n seg1 ~= arr[i];\n foreach(el; cur){\n if(el == arr[i]){\n seg1 ~= el;\n }else{\n seg2 ~= el;\n }\n }\n }\n\n // Reset seen & cur\n seen.clear;\n seen.insert([seg1.back, seg2.back]);\n cur = [];\n }else{\n cur ~= arr[i];\n }\n ++i;\n }\n // Post while\n seg2 ~= cur;\n cur = []; seen.clear;\n\n show(seg1, seg2);\n\n // Calc Answer\n auto res = 1;\n for(int k = 1; k < seg1.length; ++k){\n if(seg1[k] != seg1[k-1]){ ++res; }\n }\n res += (seg2.length > 0);\n for(int k = 1; k < seg2.length; ++k){\n if(seg2[k] != seg2[k-1]){ ++res; }\n }\n\n writeln(res);\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint res = 0;\r\n\t\tint [2] [] p = [[-1, -1]];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tint [2] [] [2] q;\r\n\t\t\tint next = res;\r\n\t\t\tforeach (ref prev; p)\r\n\t\t\t{\r\n\t\t\t\tforeach (j; 0..2)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto good = (prev[j] != c);\r\n\t\t\t\t\tq[good] ~= [c, prev[!j]];\r\n\t \t}\r\n\t\t\t}\r\n\t\t\tforeach_reverse (j; 0..2)\r\n\t\t\t{\r\n\t\t\t\tif (!q[j].empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tres = next + j;\r\n\t\t\t\t\tp = q[j];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tforeach (ref prev; p)\r\n\t\t\t{\r\n\t\t\t\tsort (prev[]);\r\n\t\t\t}\r\n\t\t\tp = p.sort.uniq.take (4).array;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "src_uid": "5fe5427f839768215d4129ab83f36778"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b, T;\n readf(\"%s %s %s %s\", &n, &a, &b, &T);\n readln;\n \n auto s = readln.chomp;\n auto cost = s.map!(x => 1 + (x == 'w' ? b : 0)).array;\n\n debug { cost.writeln; }\n \n if (cost[0] > T) {\n writeln(0);\n return;\n }\n \n n -= 1;\n T -= cost[0];\n cost = cost.dropOne;\n \n int go(int[] rightcost, int[] leftcost, int n, int T) {\n auto ans = 0;\n auto leftsum = leftcost.sum + a * n;\n auto leftidx = n;\n auto rightsum = 0;\n auto rightidx = 0;\n while (rightidx < n) {\n rightsum += rightcost[rightidx] + a;\n ++rightidx;\n leftsum += a;\n \n while (leftsum + rightsum > T && leftidx > 0) {\n leftidx -= 1;\n leftsum -= leftcost[leftidx] + a;\n }\n \n if (rightsum <= T) {\n ans = max(ans, rightidx);\n if (leftsum + rightsum <= T) {\n ans = max(ans, min(n, leftidx + rightidx));\n }\n }\n \n debug { writeln([rightidx, rightsum, leftidx, leftsum, ans].map!(to!string).join(\" \")); }\n }\n \n return ans;\n }\n \n auto costrev = cost.dup.retro().array;\n \n int ans = 1 + max(go(cost, costrev, n, T), go(costrev, cost, n, T));\n ans.writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n, a, b, t;\n\twhile (readf (\" %s %s %s %s\", &n, &a, &b, &t) > 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.strip.map !(q{a == 'w'}).array;\n\t\tauto q = p.dup;\n\t\treverse (q[1..$]);\n\t\tt -= p[0] * b;\n\t\tt--;\n\n\t\tlong [] fun (bool [] r)\n\t\t{\n\t\t\tauto res = [0L];\n\t\t\tres.reserve (n);\n\t\t\tforeach (i; 1..n)\n\t\t\t{\n\t\t\t\tres ~= res.back + a + b * r[i] + 1;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tauto gp = fun (p);\n\t\tauto gq = fun (q);\n\n\t\tint solve (long [] fp, long [] fq)\n\t\t{\n\t\t\tint res = 0;\n\t\t\tint j = 0;\n\t\t\twhile (j < n && fq[j] <= t)\n\t\t\t{\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tj--;\n\t\t\tres = max (res, j);\n\t\t\n\t\t\tforeach (i; 1..n)\n\t\t\t{\n\t\t\t\tif (t < fp[i])\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tres = max (res, i);\n\t\t\t\twhile (j > 0 && t < fp[i] + fq[j] + i * a)\n\t\t\t\t{\n\t\t\t\t\tj--;\n\t\t\t\t}\n\t\t\t\tres = max (res, i + j);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tint res = max (solve (gp, gq), solve (gq, gp));\n\t\tres = min (res, n - 1);\n\t\tif (t >= 0)\n\t\t{\n\t\t\tres++;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, a, b, T;\n readf(\"%s %s %s %s\", &n, &a, &b, &T);\n readln;\n \n auto s = readln.chomp;\n auto cost = s.map!(x => 1 + (x == 'w' ? b : 0)).array;\n\n debug { cost.writeln; }\n \n if (cost[0] > T) {\n writeln(0);\n return;\n }\n \n T -= cost[0];\n cost = cost.dropOne;\n \n int go(int[] rightcost, int[] leftcost, int n, int T) {\n auto ans = 0;\n auto leftsum = leftcost.sum + a * n;\n auto leftidx = n;\n auto rightsum = 0;\n auto rightidx = 0;\n while (rightidx < n) {\n rightsum += rightcost[rightidx] + a;\n ++rightidx;\n leftsum += a;\n \n while (leftsum + rightsum > T && leftidx > 0) {\n leftidx -= 1;\n leftsum -= leftcost[leftidx] + a;\n }\n \n if (rightsum <= T) {\n ans = max(ans, rightidx);\n if (leftsum + rightsum <= T) {\n ans = max(ans, min(n, leftidx + rightidx));\n }\n }\n \n debug { writeln([rightidx, rightsum, leftidx, leftsum, ans].map!(to!string).join(\" \")); }\n }\n \n return ans;\n }\n \n auto costrev = cost.dup.retro().array;\n \n int ans = 1 + max(go(cost, costrev, n-1, T), go(costrev, cost, n-1, T));\n ans.writeln;\n}"}], "negative_code": [], "src_uid": "e53eabd41647dc17bd8daf060d736c63"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, K;\ndebug {\n int[] A;\n}\n\nbool Ask(int x, int y) {\n bool ret;\n debug {\n int xm = N, ym = N;\n foreach (a; A) {\n chmin(xm, abs(x - a));\n chmin(ym, abs(y - a));\n }\n ret = (xm <= ym);\n writefln(\"Ask %s %s = %s\", x, y, ret);\n } else {\n writefln(\"1 %s %s\", x, y);\n stdout.flush;\n const res = readToken();\n ret = (res == \"TAK\");\n }\n return ret;\n}\n\nvoid Answer(int x, int y) {\n writefln(\"2 %s %s\", x, y);\n stdout.flush;\n debug {\n assert(A.count(x) > 0);\n assert(A.count(y) > 0);\n }\n}\n\nvoid main() {\n N = readInt();\n K = readInt();\n debug {\n A = new int[K];\n foreach (i; 0 .. K) {\n A[i] = readInt();\n }\n }\n \n int solve(int lo, int hi, int ini = 0) {\n for (; lo + 1 < hi; ) {\n int mid = (lo + hi) / 2;\n if (ini == 1) {\n mid = (lo + lo + hi) / 3;\n ini = 0;\n }\n if (ini == 2) {\n mid = (lo + hi + hi) / 3;\n ini = 0;\n }\n if (Ask(mid, mid + 1)) {\n hi = mid;\n } else {\n lo = mid + 1;\n }\n }\n return Ask(lo, hi) ? lo : hi;\n }\n \n int ans0, ans1;\n \n ans0 = solve(1, N);\n if (1 <= ans0 - 1) {\n const res = solve(1, ans0 - 1, 1);\n if (Ask(res, ans0)) {\n ans1 = res;\n }\n }\n if (!ans1) {\n ans1 = solve(ans0 + 1, N, 2);\n }\n \n Answer(ans0, ans1);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n\n int hi = N - 1;\n int lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n int ans1 = hi;\n\n if (hi >= 2) {\n hi = hi - 1;\n lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n\n writeln(1, \" \", hi, \" \", ans1);\n stdout.flush;\n if (readln.chomp == \"TAK\") {\n writeln(2, \" \", hi, \" \", ans1);\n return;\n }\n }\n\n hi = N + 1;\n lo = ans1 + 1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid - 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") lo = mid;\n else hi = mid;\n }\n\n writeln(2, \" \", ans1, \" \", lo);\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n\n int hi = N - 1;\n int lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n int ans1 = hi;\n\n if (hi >= 2) {\n hi = hi - 1;\n lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n\n writeln(1, \" \", hi, \" \", ans1);\n stdout.flush;\n if (readln.chomp == \"TAK\") {\n writeln(2, \" \", hi, \" \", ans1);\n return;\n }\n }\n\n hi = N;\n lo = ans1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid - 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n\n writeln(2, \" \", ans1, \" \", hi);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n\n int hi = N - 1;\n int lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n int ans1 = hi;\n\n if (hi >= 2) {\n hi = hi - 1;\n lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n\n writeln(1, \" \", hi, \" \", ans1);\n stdout.flush;\n if (readln.chomp == \"TAK\") {\n writeln(2, \" \", hi, \" \", ans1);\n return;\n }\n }\n\n hi = N + 1;\n lo = ans1 + 1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid - 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") lo = mid;\n else hi = mid;\n }\n\n writeln(2, \" \", ans1, \" \", hi);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n\n int hi = N;\n int lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo)/ 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n int ans1 = hi;\n\n hi = N + 1;\n lo = 1;\n while (hi - lo > 1) {\n int mid = (hi + lo)/ 2;\n writeln(1, \" \", mid, \" \", mid - 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") lo = mid;\n else hi = mid;\n }\n int ans2 = lo;\n\n writeln(2, \" \", ans1, \" \", ans2);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n\n int hi = N - 1;\n int lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n int ans1 = hi;\n\n hi = N + 1;\n lo = 2;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid - 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") lo = mid;\n else hi = mid;\n }\n int ans2 = lo;\n\n writeln(2, \" \", ans1, \" \", ans2);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n\n int hi = N - 1;\n int lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n int ans1 = hi;\n\n hi = hi - 1;\n lo = 0;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid + 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n\n writeln(1, \" \", hi, \" \", ans1);\n stdout.flush;\n if (readln.chomp == \"TAK\") {\n writeln(2, \" \", hi, \" \", ans1);\n return;\n }\n\n hi = N;\n lo = ans1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n writeln(1, \" \", mid, \" \", mid - 1);\n stdout.flush;\n if (readln.chomp == \"TAK\") hi = mid;\n else lo = mid;\n }\n\n writeln(2, \" \", ans1, \" \", hi);\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, K;\ndebug {\n int[] A;\n}\n\nbool Ask(int x, int y) {\n bool ret;\n debug {\n int xm = N, ym = N;\n foreach (a; A) {\n chmin(xm, abs(x - a));\n chmin(ym, abs(y - a));\n }\n ret = (xm <= ym);\n writefln(\"Ask %s %s = %s\", x, y, ret);\n } else {\n writefln(\"1 %s %s\", x, y);\n stdout.flush;\n const res = readToken();\n ret = (res == \"TAK\");\n }\n return ret;\n}\n\nvoid Answer(int x, int y) {\n writefln(\"2 %s %s\", x, y);\n stdout.flush;\n debug {\n assert(A.count(x) > 0);\n assert(A.count(y) > 0);\n }\n}\n\nvoid main() {\n N = readInt();\n K = readInt();\n debug {\n A = new int[K];\n foreach (i; 0 .. K) {\n A[i] = readInt();\n }\n }\n \n int ans0, ans1;\n {\n int lo = 1, hi = N;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n (Ask(lo, hi) ? hi : lo) = mid;\n }\n ans0 = Ask(lo, hi) ? lo : hi;\n }\n if (1 <= ans0 - 1) {\n int lo = 1, hi = ans0 - 1;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n (Ask(lo, hi) ? hi : lo) = mid;\n }\n const x = Ask(lo, hi) ? lo : hi;\n if (Ask(x, ans0)) {\n ans1 = x;\n }\n }\n if (!ans1) {\n int lo = ans0 + 1, hi = N;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n (Ask(lo, hi) ? hi : lo) = mid;\n }\n ans1 = Ask(lo, hi) ? lo : hi;\n }\n \n Answer(ans0, ans1);\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, K;\ndebug {\n int[] A;\n}\n\nbool Ask(int x, int y) {\n bool ret;\n debug {\n int xm = N, ym = N;\n foreach (a; A) {\n chmin(xm, abs(x - a));\n chmin(ym, abs(y - a));\n }\n ret = (xm <= ym);\n writefln(\"Ask %s %s = %s\", x, y, ret);\n } else {\n writefln(\"1 %s %s\", x, y);\n stdout.flush;\n const res = readToken();\n ret = (res == \"TAK\");\n }\n return ret;\n}\n\nvoid Answer(int x, int y) {\n writefln(\"2 %s %s\", x, y);\n stdout.flush;\n debug {\n assert(A.count(x) > 0);\n assert(A.count(y) > 0);\n }\n}\n\nvoid main() {\n N = readInt();\n K = readInt();\n debug {\n A = new int[K];\n foreach (i; 0 .. K) {\n A[i] = readInt();\n }\n }\n \n int solve(int lo, int hi, int ini = 0) {\n for (; lo + 1 < hi; ) {\n int mid = (lo + hi) / 2;\n if (ini == 1) {\n mid = (lo + lo + hi) / 3;\n ini = 0;\n }\n if (ini == 2) {\n mid = (lo + hi + hi) / 3;\n ini = 0;\n }\n if (Ask(mid, mid + 1)) {\n hi = mid;\n } else {\n lo = mid + 1;\n }\n }\n return Ask(lo, hi) ? lo : hi;\n }\n \n int ans0, ans1;\n \n ans0 = solve(1, N);\n if (1 <= ans0 - 1) {\n ans1 = solve(1, ans0 - 1, 1);\n }\n if (!Ask(ans1, ans0)) {\n ans1 = solve(ans0 + 1, N, 2);\n }\n \n Answer(ans0, ans1);\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N, K;\ndebug {\n int[] A;\n}\n\nbool Ask(int x, int y) {\n bool ret;\n debug {\n int xm = N, ym = N;\n foreach (a; A) {\n chmin(xm, abs(x - a));\n chmin(ym, abs(y - a));\n }\n ret = (xm <= ym);\n writefln(\"Ask %s %s = %s\", x, y, ret);\n } else {\n writefln(\"1 %s %s\", x, y);\n stdout.flush;\n const res = readToken();\n ret = (res == \"TAK\");\n }\n return ret;\n}\n\nvoid Answer(int x, int y) {\n writefln(\"2 %s %s\", x, y);\n stdout.flush;\n debug {\n assert(A.count(x) > 0);\n assert(A.count(y) > 0);\n }\n}\n\nvoid main() {\n N = readInt();\n K = readInt();\n debug {\n A = new int[K];\n foreach (i; 0 .. K) {\n A[i] = readInt();\n }\n }\n \n int solve(int lo, int hi) {\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n (Ask(lo, hi) ? hi : lo) = mid;\n }\n return Ask(lo, hi) ? lo : hi;\n }\n \n int ans0, ans1;\n \n ans0 = solve(1, N);\n for (int e = 0; ans0 + (1 << e) <= N; ++e) {\n if (Ask(ans0 + (1 << e), ans0 + (1 << e) - 1)) {\n ans1 = solve(ans0 + (1 << e) - 1, N);\n goto found;\n }\n }\n for (int e = 0; ans0 + (1 << e) <= N; ++e) {\n if (Ask(ans0 - (1 << e), ans0 - (1 << e) + 1)) {\n ans1 = solve(1, ans0 - (1 << e) + 1);\n goto found;\n }\n }\n found:\n \n Answer(ans0, ans1);\n}\n"}], "src_uid": "f4240b7bbc46e2c4a62a4e5c563ec8f6"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n auto ans = new int[nt];\n foreach (tid; 0 .. nt) {\n const uint n = r.next!uint();\n const uint x = r.next!uint();\n auto a = r.nextA!uint (n);\n int res = int.max;\n int check (const int k) {\n if (x < k) {\n return 2;\n }\n int t = x / k;\n if (x % k) ++t;\n return t;\n }\n foreach_reverse (k; a) {\n res = min (res, check (k));\n }\n ans[tid] = res;\n }\n writefln!\"%(%s\\n%)\"(ans);\n}\n\n", "positive_code": [{"source_code": "import std.stdio : writeln;\n\nstruct IO {\n string readToken() {\n import std.range : empty, front, popFront, split;\n import std.stdio : readln;\n\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n\n int readInt() {\n import std.conv : to;\n\n return readToken.to!int;\n }\n\n string[] tokens;\n}\n\nvoid main() {\n import std.algorithm : max, maxElement;\n\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int x = io.readInt;\n int[] a = new int[n];\n bool found = false;\n for (int i = 0; i < n; ++i) {\n a[i] = io.readInt;\n found |= a[i] == x;\n }\n if (found) {\n writeln(1);\n }\n else {\n int maxa = a.maxElement;\n writeln(max(2, (x + maxa - 1) / maxa));\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto x = RD;\n\t\tauto a = RDA;\n\t\tbool isOne;\n\t\tlong y;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == x)\n\t\t\t\tisOne = true;\n\t\t\ty.chmax(a[i]);\n\t\t}\n\t\tif (isOne)\n\t\t\tans[ti] = 1;\n\t\telse\n\t\t\tans[ti] = max(2, (x+y-1) / y);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/1307/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n foreach(_; 0..t) {\n int n, x;\n readf(\"%s %s\\n\", &n, &x);\n\n int[] a = readln.split.map!(to!int).array;\n a.sort();\n\n if(a.count(x) > 0) {\n 1.writeln;\n continue;\n }\n\n long ans = max(2, ceil(real(x)/a[$-1])).to!long;\n writefln(\"%s\", ans);\n }\n}\n\n"}], "negative_code": [{"source_code": "// https://codeforces.com/problemset/problem/1307/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n foreach(_; 0..t) {\n int n, x;\n readf(\"%s %s\\n\", &n, &x);\n\n int[] a = readln.split.map!(to!int).array;\n a.sort();\n\n if(a.count(x) > 0) {\n 1.writeln;\n continue;\n }\n\n writefln(\"%s\", max(2, ceil(real(x)/a[$-1])));\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1307/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n foreach(_; 0..t) {\n int n, x;\n readf(\"%s %s\\n\", &n, &x);\n\n int[] a = readln.split.map!(to!int).array;\n a.sort();\n\n if(a.count(x) > 0) {\n 1.writeln;\n continue;\n }\n\n writefln(\"%s\", max(2, ceil(real(x/a[$-1]))));\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1307/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n foreach(_; 0..t) {\n int n, x;\n readf(\"%s %s\\n\", &n, &x);\n\n int[] a = readln.split.map!(to!int).array;\n a.sort();\n\n if(a.count(x) > 0) {\n 1.writeln;\n continue;\n }\n\n max(2, ceil(real(x)/a[$-1])).writeln;\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1307/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n foreach(_; 0..t) {\n int n, x;\n readf(\"%s %s\\n\", &n, &x);\n int[] a = readln.split.map!(to!int).array;\n a.sort();\n writefln(\"%s\", max(2, x/a[$-1]+1));\n }\n}\n\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n auto ans = new int[nt];\n foreach (tid; 0 .. nt) {\n const uint n = r.next!uint();\n const uint x = r.next!uint();\n auto a = r.nextA!uint (n);\n bool[int] h;\n foreach (i; a) h[i] = true;\n sort (a);\n int res = int.max;\n int check (const int k) {\n int t = x / k;\n if (t >= res) return t;\n const int z = x % k;\n //debug stderr.writefln (\"Case %d: t = %d, x = %d\", tid + 1, t, x);\n if (!z) {\n } else if (z in h) ++t;\n else {\n t += 2;\n }\n return t;\n }\n foreach_reverse (k; a) {\n res = min (res, check (k));\n }\n ans[tid] = res;\n }\n writefln!\"%(%s\\n%)\"(ans);\n}\n\n"}], "src_uid": "b6a7e8abc747bdcee74653817085002c"} {"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n ll den = n;\n ll num = 0; \n ll sum = 0, fsum = 0, rsum = 0;\n ll[] arr = rdarr;\n arr.sort;\n foreach(i; 0..arr.length){\n sum += arr[i];\n fsum += i * arr[i];\n rsum += (n - i - 1) * arr[i];\n }\n num = sum + 2 * (fsum - rsum);\n ll gcdd = gcd(num, den);\n num /= gcdd;\n den /= gcdd;\n writeln(num, \" \", den);\n}\n\nvoid main(){\n long t = 1;\n /* t = rd; */\n while(t--) solve();\n stdout.flush;\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int MAX_N = 100_005;\nimmutable int MAX_C = 0x3F3F3F3F;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n + 1];\n\t\ta[0] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &a[i + 1]);\n\t\t}\n\t\ta.sort !(\"a < b\", SwapStrategy.stable);\n\t\tlong num = 0;\n\t\tauto s = new long [n + 1];\n\t\ts[0] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tnum += a[i + 1];\n\t\t\ts[i + 1] = s[i] + a[i + 1];\n\t\t}\n//\t\tnum *= n - 1;\n\t\tdebug {writeln (num);}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlong cur = s[n] - s[i + 1];\n\t\t\tcur -= a[i + 1] * cast (long) (n - i - 1);\n//\t\t\tcur *= (n - 1);\n\t\t\tcur *= 2;\n\t\t\tdebug {writefln (\"%s: %s\", i, cur);}\n\t\t\tnum += cur;\n\t\t}\n\t\tlong den = n;\n//\t\tden *= n - 1;\n\t\tauto d = gcd (num, den);\n\t\tnum /= d;\n\t\tden /= d;\n\t\twriteln (num, ' ', den);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int MAX_N = 100_005;\nimmutable int MAX_C = 0x3F3F3F3F;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n + 1];\n\t\ta[0] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &a[i + 1]);\n\t\t}\n\t\tlong num = 0;\n\t\tauto s = new long [n + 1];\n\t\ts[0] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tnum += a[i + 1];\n\t\t\ts[i + 1] = s[i] + a[i + 1];\n\t\t}\n//\t\tnum *= n - 1;\n\t\tdebug {writeln (num);}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlong cur = s[n] - s[i + 1];\n\t\t\tcur -= a[i + 1] * cast (long) (n - i - 1);\n//\t\t\tcur *= (n - 1);\n\t\t\tcur *= 2;\n\t\t\tdebug {writefln (\"%s: %s\", i, cur);}\n\t\t\tnum += cur;\n\t\t}\n\t\tlong den = n;\n//\t\tden *= n - 1;\n\t\tauto d = gcd (num, den);\n\t\tnum /= d;\n\t\tden /= d;\n\t\twriteln (num, ' ', den);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n ll den = n;\n ll num = 0; \n ll sum = 0, fsum = 0, rsum = 0;\n ll[] arr = rdarr;\n foreach(i; 0..arr.length){\n sum += arr[i];\n fsum += i * arr[i];\n rsum += (n - i - 1) * arr[i];\n }\n num = sum + (n - 1) * (fsum - rsum);\n ll gcdd = gcd(num, den);\n num /= gcdd;\n den /= gcdd;\n writeln(num, \" \", den);\n}\n\nvoid main(){\n long t = 1;\n /* t = rd; */\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n ll den = n;\n ll num = 0; \n ll sum = 0, fsum = 0, rsum = 0;\n ll[] arr = rdarr;\n foreach(i; 0..arr.length){\n sum += arr[i];\n fsum += i * arr[i];\n rsum += (n - i - 1) * arr[i];\n }\n num = sum + 2 * (fsum - rsum);\n ll gcdd = gcd(num, den);\n num /= gcdd;\n den /= gcdd;\n writeln(num, \" \", den);\n}\n\nvoid main(){\n long t = 1;\n /* t = rd; */\n while(t--) solve();\n stdout.flush;\n}\n\n"}], "src_uid": "ad50e2946470fa8e02eb70d8cef161c5"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1542/problem/B\n// math, greedy\nimport std.container;\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n, a, b;\n readf(\"%s %s %s\\n\", &n, &a, &b);\n if(a == 1L) {\n if((n - 1L) % b == 0L)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n continue;\n }\n auto powers = new RedBlackTree!(long,\"a > b\");\n powers.insert(1L);\n while(powers.front <= n) {\n powers.insert(powers.front * a);\n }\n if(powers.front > n)\n powers.removeFront;\n n = n % b;\n bool found = false;\n while(!powers.empty) {\n if(powers.front % b == n)\n found = true;\n powers.removeFront;\n }\n if(found)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD;\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\r\n\t\tlong x = 1;\r\n\t\tif (a == 1)\r\n\t\t{\r\n\t\t\tauto rem = n - x;\r\n\t\t\tans[ti] = rem % b == 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twhile (x <= n)\r\n\t\t\t{\r\n\t\t\t\tif ((n-x) % b == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tx *= a;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"Yes\" : \"No\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nulong a, b;\n\nbool is_good(ulong n)\n{\n ulong val = 1;\n while (true) {\n if (val > n)\n return false;\n if ((n - val) % b == 0)\n return true;\n val *= a;\n }\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n ulong n;\n readf!\" %d %d %d \"(n, a, b);\n\n if (a == 1) {\n if ((n - 1) % b == 0)\n writeln(\"Yes\");\n else\n writeln(\"No\");\n continue;\n }\n\n if (is_good(n))\n writeln(\"Yes\");\n else\n writeln(\"No\");\n }\n}\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n immutable(long) mod = 10 ^^ 9 + 7;\r\n while(tests--) {\r\n long n, a, b;\r\n readf!\"%s %s %s\\n\"(n, a, b);\r\n if (a == 1) {\r\n if ((n - 1) % b == 0) {\r\n \"Yes\".writeln;\r\n }\r\n else {\r\n \"No\".writeln;\r\n }\r\n }\r\n else {\r\n bool flag = false;\r\n for (int i = 0; (a ^^ i) <= n; ++i) {\r\n if ((n - (a ^^ i)) % b == 0) {\r\n \"Yes\".writeln;\r\n flag = true;\r\n break;\r\n }\r\n }\r\n if (!flag) \"No\".writeln;\r\n }\r\n }\r\n\r\n} // main\r\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1542/problem/B\n// math, greedy\nimport std.container;\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n, a, b;\n readf(\"%s %s %s\\n\", &n, &a, &b);\n if(a == 1) {\n if((n - 1) % b == 0)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n continue;\n }\n auto powers = new RedBlackTree!(long,\"a > b\");\n powers.insert(1L);\n while(powers.front < n) {\n powers.insert(powers.front * a);\n }\n if(powers.front >= n)\n powers.removeFront;\n n = n % b;\n bool found = false;\n while(!powers.empty) {\n if(powers.front % b == n)\n found = true;\n powers.removeFront;\n }\n if(found)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1542/problem/B\n// math, greedy\nimport std.container;\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n, a, b;\n readf(\"%s %s %s\\n\", &n, &a, &b);\n if(a == 1) {\n if((n - 1) % b == 0)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n continue;\n }\n auto powers = new RedBlackTree!(long,\"a > b\");\n powers.insert(1L);\n while(powers.front < n) {\n powers.insert(powers.front * a);\n }\n powers.removeFront;\n n = n % b;\n bool found = false;\n while(!powers.empty) {\n if(powers.front % b == n)\n found = true;\n powers.removeFront;\n }\n if(found)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1542/problem/B\n// math, greedy\nimport std.container;\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n, a, b;\n readf(\"%s %s %s\\n\", &n, &a, &b);\n if(a == 1) {\n if((n - 1) % b == 0)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n continue;\n }\n auto powers = new RedBlackTree!(long,\"a > b\");\n powers.insert(1L);\n while(powers.front <= n) {\n powers.insert(powers.front * a);\n }\n n = n % b;\n bool found = false;\n while(!powers.empty) {\n if(powers.front % b == n)\n found = true;\n powers.removeFront;\n }\n if(found)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nulong a, b;\n\nbool is_good(ulong n)\n{\n ulong val = 1;\n while (true) {\n if (val > n)\n return false;\n if ((n - val) % b == 0)\n return true;\n val *= a;\n }\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n ulong n;\n readf!\" %d %d %d \"(n, a, b);\n\n if (a == 1) {\n if (n % b == 1)\n writeln(\"Yes\");\n else\n writeln(\"No\");\n continue;\n }\n\n if (is_good(n))\n writeln(\"Yes\");\n else\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong a, b;\n\nbool is_good(long n)\n{\n long x = 0;\n\n long val = 1;\n while (true) {\n if (val > n)\n return false;\n if ((n - val) % b == 0)\n return true;\n val *= a;\n }\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d %d %d \"(n, a, b);\n\n if (a == 1) {\n if (n % b == 1)\n writeln(\"Yes\");\n else\n writeln(\"No\");\n continue;\n }\n\n if (is_good(n))\n writeln(\"Yes\");\n else\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong a, b;\n\nbool is_good(long n)\n{\n long x = 0;\n\n long val = 1;\n while (true) {\n val *= a;\n if (val > n)\n return false;\n if ((n - val) % b == 0)\n return true;\n }\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d %d %d \"(n, a, b);\n\n if (a == 1) {\n if (n % b == 1)\n writeln(\"Yes\");\n else\n writeln(\"No\");\n continue;\n }\n\n if (is_good(n))\n writeln(\"Yes\");\n else\n writeln(\"No\");\n }\n}\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n immutable(long) mod = 10 ^^ 9 + 7;\r\n while(tests--) {\r\n long n, a, b;\r\n readf!\"%s %s %s\\n\"(n, a, b);\r\n if (a == 1) {\r\n if ((n - 1) % b == 0) {\r\n \"Yes\".writeln;\r\n }\r\n else {\r\n \"No\".writeln;\r\n }\r\n }\r\n else {\r\n bool flag = false;\r\n for (int i = 0; (a ^^ i) <= n; ++i) {\r\n if ((n - (a ^^ i)) % b == 0) {\r\n \"Yes\".writeln;\r\n flag = true;\r\n }\r\n }\r\n if (!flag) \"No\".writeln;\r\n }\r\n }\r\n\r\n} // main\r\n"}], "src_uid": "e0a3c678f6d1d89420c8162b0ddfcef7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\ta.sort();\n\t\tauto b = a.dup;\n\n\t\tint tot;\n\t\twhile (!a.empty)\n\t\t{\n\t\t\tif (tot+a.front != 0)\n\t\t\t{\n\t\t\t\ttot += a.front;\n\t\t\t\tans[ti] ~= a.front;\n\t\t\t\ta.popFront;\n\t\t\t}\n\t\t\telse if (tot+a.back != 0)\n\t\t\t{\n\t\t\t\ttot += a.back;\n\t\t\t\tans[ti] ~= a.back;\n\t\t\t\ta.popBack;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans[ti].length = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ans[ti].empty)\n\t\t{\n\t\t\ttot = 0;\n\t\t\ta = b;\n\t\t\tdebug writeln(a);\n\t\t\twhile (!a.empty)\n\t\t\t{\n\t\t\t\tif (tot+a.back != 0)\n\t\t\t\t{\n\t\t\t\t\ttot += a.back;\n\t\t\t\t\tans[ti] ~= a.back;\n\t\t\t\t\ta.popBack;\n\t\t\t\t}\n\t\t\t\telse if (tot+a.front != 0)\n\t\t\t\t{\n\t\t\t\t\ttot += a.front;\n\t\t\t\t\tans[ti] ~= a.front;\n\t\t\t\t\ta.popFront;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tans[ti].length = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdebug writeln(\"ans:\", ans[ti]);\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(\"NO\");\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n A.sort;\n \n const ASum = A.sum;\n if (ASum == 0) {\n writeln(\"NO\");\n } else {\n if (ASum > 0) {\n A.reverse;\n }\n writeln(\"YES\");\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(A[i]);\n }\n writeln;\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n sort(arr);\n ll pls = 0, mins = 0;\n foreach(el; arr){\n if(el < 0){\n mins += el;\n }else{\n pls += el;\n }\n }\n if((mins + pls) == 0){\n writeln(\"NO\");\n }else{\n writeln(\"YES\");\n if(-mins < pls){\n reverse(arr);\n }\n arr.each!((el)=> write(el, \" \"));\n writeln;\n }\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto s = a.sum;\n\t\tif (s == 0)\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue;\n\t\t}\n\t\tsort (a);\n\t\tif (s > 0)\n\t\t{\n\t\t\treverse (a);\n\t\t}\n\t\twriteln (\"YES\");\n\t\twritefln !(\"%(%s %)\") (a);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tif (sum (a) == 0)\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln !(\"%(%s %)\") (a);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto s = a.sum;\n\t\tif (s == 0)\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue;\n\t\t}\n\t\tsort (a);\n\t\tif (s > 0)\n\t\t{\n\t\t\treverse (a);\n\t\t}\n\t\twritefln !(\"%(%s %)\") (a);\n\t}\n}\n"}], "src_uid": "e57345f5757654749b411727ebb99c80"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n if (m < n-1) {\n writeln(\"Impossible\");\n return;\n }\n \n Tuple!(int, int)[] ans;\n \n outer: foreach (i; 1 .. n+1) {\n foreach (j; i+1 .. n+1) {\n if (gcd(i, j) > 1) continue;\n \n ans ~= tuple(i, j);\n \n if (ans.length == m) break outer;\n }\n }\n \n if (ans.length < m) {\n writeln(\"Impossible\");\n return;\n }\n \n writeln(\"Possible\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n\n if (M < N - 1) {\n writeln(\"Impossible\");\n return;\n }\n\n auto X = new int[][](N+1);\n auto Y = new int[][](N+1);\n\n foreach (i; 2..N+1) {\n if (!X[i].empty) continue;\n for (int j = i; j <= N; j += i) {\n X[j] ~= i;\n Y[i] ~= j;\n }\n }\n\n int cnt = 0;\n auto ans = new Tuple!(int, int)[](M);\n\n foreach (i; 2..N+1) {\n ans[cnt] = tuple(1, i);\n cnt += 1;\n }\n\n for (int i = N - (1 - N%2); i > 2 && cnt < M; i -= 2) {\n auto tmp = new bool[](i);\n foreach (j; X[i]) foreach (k; Y[j]) if (k < i) tmp[k] = true;\n for (int j = 2; j < i && cnt < M; ++j) if (!tmp[j]) ans[cnt] = tuple(j, i), cnt++;\n }\n for (int i = N - N%2; i > 1 && cnt < M; i -= 2) {\n auto tmp = new bool[](i);\n foreach (j; X[i]) foreach (k; Y[j]) if (k < i) tmp[k] = true;\n for (int j = 2; j < i && cnt < M; ++j) if (!tmp[j]) ans[cnt] = tuple(j, i), cnt++;\n }\n\n if (cnt == M) {\n writeln(\"Possible\");\n ans.each!(a => writeln(a[0], \" \", a[1]));\n } else {\n writeln(\"Impossible\");\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n\n if (M < N - 1) {\n writeln(\"Impossible\");\n return;\n }\n\n auto X = new int[][](N+1);\n auto Y = new int[][](N+1);\n\n foreach (i; 2..N+1) {\n if (!X[i].empty) continue;\n for (int j = i; j <= N; j += i) {\n X[j] ~= i;\n Y[i] ~= j;\n }\n }\n\n int cnt = 0;\n auto ans = new Tuple!(int, int)[](M);\n\n foreach (i; 2..N+1) {\n ans[cnt] = tuple(1, i);\n cnt += 1;\n }\n\n for (int i = N - (1 - N%2); i > 2 && cnt < M; --i) {\n auto tmp = new bool[](i);\n foreach (j; X[i]) foreach (k; Y[j]) if (k < i) tmp[k] = true;\n for (int j = 2; j < i && cnt < M; ++j) if (!tmp[j]) ans[cnt] = tuple(j, i), cnt++;\n }\n for (int i = N - N%2; i > 1 && cnt < M; --i) {\n auto tmp = new bool[](i);\n foreach (j; X[i]) foreach (k; Y[j]) if (k < i) tmp[k] = true;\n for (int j = 2; j < i && cnt < M; ++j) if (!tmp[j]) ans[cnt] = tuple(j, i), cnt++;\n }\n\n if (cnt == M) {\n writeln(\"Possible\");\n ans.each!(a => writeln(a[0], \" \", a[1]));\n } else {\n writeln(\"Impossible\");\n }\n}\n"}], "src_uid": "0ab1b97a8d2e0290cda31a3918ff86a4"} {"source_code": "import std.stdio, std.string, std.conv;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\nimport core.thread;\n\n//\tInput\nstring[] tokens;\nint tokenId = 0;\nstring readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }\n\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, T f) { if (t < f) t = f; }\n\nvoid main () {\n int N; N = readInt();\n int M; M = readInt();\n\n int[110] valid;\n int[110] invalid;\n\n int best = 0;\n\n foreach (i; 0 .. N) {\n valid[i] = readInt();\n chmax(best, valid[i]);\n }\n\n foreach (i; 0 .. M) {\n invalid[i] = readInt();\n chmax(best, invalid[i]);\n }\n\n bool ok = false;\n\n foreach (i; 1 .. best + 1) {\n bool les = true;\n bool exe = false;\n bool big = true;\n\n foreach (j; 0 .. N) {\n if (valid[j] > i) {\n les = false;\n }\n if (valid[j] * 2 <= i) {\n exe = true;\n }\n }\n\n foreach (j; 0 .. M) {\n if (invalid[j] <= i) {\n big = false;\n }\n } \n\n if (exe && les && big) {\n ok = true;\n writeln(\"\", i);\n break;\n }\n }\n \n if (!ok) {\n writeln(\"-1\");\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nvoid main() {\n int n, m; readf(\"%d %d\\n\", &n, &m);\n auto cs = stdin.readln.split.map!(to!int);\n auto ws = stdin.readln.split.map!(to!int);\n auto cmin = cs.reduce!min;\n auto cmax = cs.reduce!max;\n auto wmin = ws.reduce!min;\n int v = max(cmin * 2, cmax);\n if (v >= wmin) {\n writeln(-1);\n } else {\n writeln(v);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\nimport core.thread;\n\n// Input\nstring[] tokens;\nint tokenId = 0;\nstring readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }\n\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n// chmin/chmax\nvoid chmin(T)(ref T t, T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, T f) { if (t < f) t = f; }\n\nvoid main () {\n int N; N = readInt();\n int M; M = readInt();\n\n int[110] valid;\n int[110] invalid;\n\n int best = 0;\n\n foreach (i; 0 .. N) {\n valid[i] = readInt();\n chmax(best, valid[i]);\n }\n\n foreach (i; 0 .. M) {\n invalid[i] = readInt();\n chmax(best, valid[i]);\n }\n\n bool ok = false;\n\n foreach (i; 1 .. best + 1) {\n bool les = true;\n bool exe = false;\n bool big = true;\n\n foreach (j; 0 .. N) {\n if (valid[j] > i) {\n les = false;\n }\n if (valid[j] * 2 < i) {\n exe = true;\n }\n }\n\n foreach (j; 0 .. M) {\n if (invalid[j] < i) {\n big = false;\n }\n } \n\n if (exe && les && big) {\n ok = true;\n writeln(\"\", i);\n break;\n }\n }\n \n if (!ok) {\n writeln(\"-1\");\n }\n\n}"}], "src_uid": "49c47ebfd710a3733ce7ecb3a3c134a7"} {"source_code": "import std.stdio, std.random;\n\nalias V = long;\nalias P = int;\n\nclass Node\n{\n V value;\n V valueSum;\n V valuePendingAdd;\n Node left;\n Node right;\n int size;\n \n this(V value, Node left = null, Node right = null)\n {\n this.value = value;\n this.left = left;\n this.right = right;\n update();\n }\n \n void update()\n {\n size = getSize(left) + getSize(right) + 1;\n valueSum = getValueSum(left) + getValueSum(right) + value;\n }\n}\n\nint getSize(Node node)\n{\n return node is null ? 0 : node.size;\n}\n\nV getValueSum(Node node)\n{\n return node is null ? 0 : node.valueSum;\n}\n\nvoid pushPending(Node node)\n{\n if (node !is null && node.valuePendingAdd != 0)\n {\n if (node.left !is null) node.left.valuePendingAdd += node.valuePendingAdd;\n if (node.right !is null) node.right.valuePendingAdd += node.valuePendingAdd;\n \n node.value += node.valuePendingAdd;\n node.valuePendingAdd = 0;\n }\n}\n\nNode merge(Node l, Node r)\n{\n if (l is null) return r;\n if (r is null) return l;\n \n l.pushPending();\n r.pushPending();\n \n if (uniform(-l.size, r.size) < 0)\n {\n l.right = merge(l.right, r);\n l.update();\n return l;\n }\n else\n {\n r.left = merge(l, r.left);\n r.update();\n return r;\n }\n}\n\nvoid split(Node node, int splitIndex, out Node outL, out Node outR)\n{\n if (node is null)\n {\n outL = null;\n outR = null;\n return;\n }\n \n node.pushPending();\n \n int leftSize = getSize(node.left);\n Node newNode = null;\n \n if (leftSize < splitIndex)\n {\n if (node.right is null) outR = null;\n else split(node.right, splitIndex - leftSize - 1, newNode, outR);\n \n node.right = newNode;\n node.update();\n outL = node;\n }\n else\n {\n if (node.left is null) outL = null;\n else split(node.left, splitIndex, outL, newNode);\n \n node.left = newNode;\n node.update();\n outR = node;\n }\n}\n\nvoid main()\n{\n int n, k, q;\n readf(\"%d %d %d\", &n, &k, &q);\n \n Node root = null;\n \n for (int i = 0; i < 200010; i++)\n {\n root = merge(root, new Node(0));\n }\n \n for (int i = 0; i < n; i++)\n {\n int l, r;\n readf(\" %d %d\", &l, &r);\n \n Node a, b, c;\n \n root.split(r, b, c);\n b.split(l-1, a, b);\n \n b.valuePendingAdd++;\n root = merge(merge(a, b), c);\n }\n \n Node root2 = null;\n \n void traverse(Node node)\n {\n if (node is null) return;\n \n node.pushPending();\n \n traverse(node.left);\n \n root2 = merge(root2, new Node(node.value >= k ? 1 : 0));\n \n traverse(node.right);\n }\n \n traverse(root);\n \n for (int i = 0; i < q; i++)\n {\n int l, r;\n readf(\" %d %d\", &l, &r);\n \n Node a, b, c;\n \n root2.split(r, b, c);\n b.split(l-1, a, b);\n writeln(b.valueSum);\n root2 = merge(merge(a, b), c);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\n\nimmutable int max = 2 * 10^^5 + 2;\n\nint n, k, q;\n\nvoid main() {\n scan(n, k, q);\n \n auto adm = new int[](max);\n\n int li, ri;\n\n foreach (i ; 0 .. n) {\n scan(li, ri);\n adm[li]++;\n adm[ri+1]--;\n }\n\n foreach (i ; 1 .. max) {\n adm[i] += adm[i - 1];\n }\n\n foreach (i ; 0 .. max) {\n adm[i] = (adm[i] >= k);\n }\n\n foreach (i ; 1 .. max) {\n adm[i] += adm[i - 1];\n }\n\n int ai, bi;\n\n foreach (i ; 0 .. q) {\n scan(ai, bi);\n writeln(adm[bi] - adm[ai - 1]);\n }\n}\n\nvoid scan(T...)(ref T args) {\n auto line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n assert(line.empty);\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\n\nimmutable int max = 2 * 10^^5 + 10;\n\nint n, k, q;\n//int[] l, r;\n\nvoid main() {\n scan(n, k, q);\n \n auto adm = new int[](max);\n\n int li, ri;\n\n foreach (i ; 0 .. n) {\n scan(li, ri);\n adm[li]++;\n adm[ri+1]--;\n }\n\n iota(max - 1).each!(i => adm[i + 1] += adm[i]);\n\n debug {\n stderr.writeln(\"adm:\", adm[0 .. 120]);\n }\n\n adm = adm.map!(a => (a >= k).to!int).array;\n\n debug {\n stderr.writeln(\"adm:\", adm[0 .. 120]);\n }\n\n iota(max - 1).each!(i => adm[i + 1] += adm[i]);\n\n debug {\n stderr.writeln(\"adm:\", adm[0 .. 150]);\n }\n\n int ai, bi, ans;\n\n foreach (i ; 0 .. q) {\n scan(ai, bi);\n ans = adm[bi] - adm[ai - 1];\n ans.writeln;\n }\n}\n\nvoid scan(T...)(ref T args) {\n auto line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n assert(line.empty);\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum LIM = 200000 + 10;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n const Q = readInt();\n auto L = new int[N];\n auto R = new int[N];\n foreach (i; 0 .. N) {\n L[i] = readInt();\n R[i] = readInt();\n }\n auto A = new int[Q];\n auto B = new int[Q];\n foreach (q; 0 .. Q) {\n A[q] = readInt();\n B[q] = readInt();\n }\n \n auto fs = new int[LIM];\n foreach (i; 0 .. N) {\n ++fs[L[i]];\n --fs[R[i] + 1];\n }\n foreach (x; 1 .. LIM) {\n fs[x] += fs[x - 1];\n }\n auto gs = new int[LIM + 1];\n foreach (x; 0 .. LIM) {\n gs[x + 1] = gs[x] + ((fs[x] >= K) ? 1 : 0);\n }\n \n foreach (q; 0 .. Q) {\n const ans = gs[B[q] + 1] - gs[A[q]];\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto Q = s[2];\n \n auto cs = new int[](200020);\n foreach (_; 0..N) {\n s = readln.split.map!(to!int);\n cs[s[0]] += 1;\n cs[s[1]+1] -= 1; \n }\n foreach (i; 0..200019) {\n cs[i+1] += cs[i];\n }\n\n auto st = new SegmentTree(200020);\n foreach (i; 0..200020) if (cs[i] >= K) st.add(i, 1);\n\n while (Q--) {\n s = readln.split.map!(to!int);\n st.sum(s[0], s[1]).writeln;\n }\n \n}\n\n\nclass SegmentTree {\n int[] table;\n int size;\n\n this(int n) {\n assert(bsr(n) < 29);\n size = 1 << (bsr(n) + 2);\n table = new int[](size);\n }\n\n void add(int pos, int num) {\n return add(pos, num, 0, 0, size/2-1);\n }\n\n void add(int pos, int num, int i, int left, int right) {\n table[i] += num;\n if (left == right) {\n return;\n }\n auto mid = (left + right) / 2;\n if (pos <= mid)\n add(pos, num, i*2+1, left, mid);\n else\n add(pos, num, i*2+2, mid+1, right);\n }\n\n int sum(int pl, int pr) {\n return sum(pl, pr, 0, 0, size/2-1);\n }\n\n int sum(int pl, int pr, int i, int left, int right) {\n if (pl > right || pr < left)\n return 0;\n else if (pl <= left && right <= pr)\n return table[i];\n else\n return\n sum(pl, pr, i*2+1, left, (left+right)/2) + \n sum(pl, pr, i*2+2, (left+right)/2+1, right);\n }\n}\n"}], "negative_code": [], "src_uid": "4bdf819b73ffb708ad571accf3b8c23d"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tforeach (test; 0..readln.strip.to !(int))\n\t{\n\t\tint p, f;\n\t\treadf !(\" %s %s\") (p, f);\n\t\tint cs, cw;\n\t\treadf !(\" %s %s\") (cs, cw);\n\t\tint s, w;\n\t\treadf !(\" %s %s\") (s, w);\n\t\tif (s > w)\n\t\t{\n\t\t\tswap (s, w);\n\t\t\tswap (cs, cw);\n\t\t}\n\t\tint res = 0;\n\t\tforeach (ns; 0..cs + 1)\n\t\t{\n\t\t\tauto ns1 = min (ns, p / s);\n\t\t\tauto ns2 = min (cs - ns1, f / s);\n\t\t\tauto nw1 = min (cw, (p - ns1 * s) / w);\n\t\t\tauto nw2 = min (cw - nw1, (f - ns2 * s) / w);\n\t\t\tres = max (res, ns1 + ns2 + nw1 + nw2);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1400/problem/B\n// \nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n long t, p, f, cnts, cntw, s, w;\n\n readf(\"%s\", &t);\n readln;\n\n while(t--) {\n readf(\"%s %s\\n\", &p, &f);\n readf(\"%s %s\\n\", &cnts, &cntw);\n readf(\"%s %s\\n\", &s, &w);\n\n if(s > w) {\n swap(s,w);\n swap(cnts, cntw);\n }\n\n long ans = long.min;\n for(long swords = 0; swords <= cnts; ++swords) {\n if(p/s < swords)\n continue;\n\n long goku, freezer, cnt, maxima;\n goku = p;\n freezer = f;\n\n goku -= swords*s;\n cnt = min(f/s, cnts - swords);\n freezer -= cnt*s;\n\n maxima = swords + cnt;\n maxima += min(cntw, goku/w + freezer/w);\n\n //writefln(\"goku lleva %s espadas\", swords);\n //writefln(\"freezer lleva %s espadas\", cnt);\n //writefln(\"hachas %s\", min(cntw, goku/w + freezer/w));\n\n ans = max(maxima, ans);\n }\n\n ans.writeln;\n }\n}\n\n"}], "negative_code": [], "src_uid": "ee32db8e7cdd9561d9215651ff8a262e"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta[] -= 1;\r\n\t\tauto b = new int [] [n];\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tb[a[i]] ~= i;\r\n\t\t}\r\n\r\n\t\tauto t = new int [n + 1];\r\n\r\n\t\tvoid add (int i)\r\n\t\t{\r\n\t\t\tfor ( ; i <= n; i += i & -i)\r\n\t\t\t{\r\n\t\t\t\tt[i] += 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint ask (int i)\r\n\t\t{\r\n\t\t\tint res = 0;\r\n\t\t\tfor ( ; i > 0; i -= i & -i)\r\n\t\t\t{\r\n\t\t\t\tres += t[i];\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tlong res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (v; b[i])\r\n\t\t\t{\r\n\t\t\t\tres += ask (n - v);\r\n\t\t\t\tadd (n - v);\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!int(N);\r\n\r\n auto st = SegTree!(\"a + b\", int)(new int[](N + 1));\r\n int ans;\r\n foreach(i, a; A) {\r\n ans += st.sum(a, N + 1);\r\n \r\n auto x = st.get(a);\r\n st.update(a, x + 1);\r\n }\r\n \r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nstruct SegTree(alias pred = \"a + b\", T = long) {\r\n alias predFun = binaryFun!pred;\r\n int size;\r\n T[] data;\r\n T monoid;\r\n \r\n this(T[] src, T monoid = T.init) {\r\n this.monoid = monoid;\r\n\r\n for(int i = 2; i < 2L^^32; i *= 2) {\r\n if (src.length <= i) {\r\n size = i;\r\n break;\r\n }\r\n }\r\n \r\n data = new T[](size * 2);\r\n foreach(i, s; src) data[i + size] = s;\r\n foreach_reverse(b; 1..size) {\r\n data[b] = predFun(data[b * 2], data[b * 2 + 1]);\r\n }\r\n }\r\n \r\n void update(int index, T value) {\r\n int i = index + size;\r\n data[i] = value;\r\n while(i > 0) {\r\n i /= 2;\r\n data[i] = predFun(data[i * 2], data[i * 2 + 1]);\r\n }\r\n }\r\n \r\n T get(int index) {\r\n return data[index + size];\r\n }\r\n \r\n T sum(int a, int b, int k = 1, int l = 0, int r = -1) {\r\n if (r < 0) r = size;\r\n \r\n if (r <= a || b <= l) return monoid;\r\n if (a <= l && r <= b) return data[k];\r\n \r\n T leftValue = sum(a, b, 2*k, l, (l + r) / 2);\r\n T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);\r\n return predFun(leftValue, rightValue);\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "759b3909ccdf1b9ffd800bf0f65361cc"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n uint [][] a;\n foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;\n \n auto b = new uint [][] ( m, n );\n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n b[ i ][ j ] = a[ j ][ i ];\n }\n }\n \n uint[] sums;\n foreach ( j; 0..m ) {\n sums ~= b[ j ].sum;\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] (n, m);\n foreach ( i; 0..n ) a[i] = readln.chomp.array;\n \n auto b = transposed(a.dup);\n \n auto sums = new int[] (m);\n \n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n sums[ i ] += a[ j ][ i ] == '1';\n }\n }\n \n auto found = false;\n foreach ( i; 0..n ) {\n auto cur = true;\n foreach ( j; 0..m ) {\n cur &= a[ i ][ j ] == '0' || sums[ j ] > 1;\n }\n found |= cur;\n }\n writeln ( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] (n, m);\n foreach ( i; 0..n ) a[i] = readln.chomp.array;\n \n auto sums = new int[] (m);\n \n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n sums[ i ] += a[ j ][ i ] == '1';\n }\n }\n \n auto found = false;\n foreach ( i; 0..n ) {\n auto cur = true;\n foreach ( j; 0..m ) {\n cur &= a[ i ][ j ] == '0' || sums[ j ] > 1;\n }\n found |= cur;\n }\n writeln ( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n uint [][] a;\n foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;\n \n auto b = new uint [][] ( m, n );\n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n b[ i ][ j ] = a[ j ][ i ];\n }\n }\n \n ulong[] sums;\n foreach ( j; 0..m ) {\n sums ~= b[ j ].count!(c => c == 1);\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] (n, m);\n foreach ( i; 0..n ) a[i] = readln.chomp.array;\n \n auto b = transposed(a.dup);\n auto sums = b.map!(a => a.count!(c => c == '1')).array;\n \n auto found = false;\n foreach ( i; 0..n ) {\n auto cur = true;\n foreach ( j; 0..m ) {\n cur &= a[ i ][ j ] == '0' || sums[ j ] > 1;\n }\n found |= cur;\n }\n writeln ( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.array;\n \n auto b = transposed(a.dup);\n auto sums = new int[] (m);\n foreach ( j; 0..m ) {\n foreach ( i; 0..n ) {\n sums[ j ] += a[ i ][ j ] == '1';\n }\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n uint [][] a;\n foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;\n \n auto b = new uint [][] ( m, n );\n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n b[ i ][ j ] = a[ j ][ i ];\n }\n }\n \n ulong[] sums;\n foreach ( j; 0..m ) {\n sums ~= b[ j ].sum;\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport core.bitop;\nimport std.algorithm;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n string[] a;\n foreach ( i; 0..n ) a ~= readln.chomp;\n \n auto b = transposed(a.dup);\n auto sums = new int[] (m);\n foreach ( j; 0..m ) {\n foreach ( i; 0..n ) {\n sums[ j ] += a[ i ][ j ] == '1';\n }\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.array;\n \n auto b = transposed( a.dup );\n auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;\n\n auto found = n.iota.any!( i => m.iota.all!( j => a[ i ][ j ] == '0' || sums[ j ] > 1 ) );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport core.bitop;\nimport std.algorithm;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n uint [][] a;\n foreach ( i; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;\n \n auto b = transposed(a.dup);\n auto sums = new int[] (m);\n foreach ( j; 0..m ) {\n foreach ( i; 0..n ) {\n sums[ j ] += a[ i ][ j ];\n }\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 10 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.array;\n \n auto sums = new int [] ( m );\n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n sums[ i ] += a[ j ][ i ] == '1' ;\n }\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.array;\n \n auto b = transposed( a.dup );\n auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;\n\n auto goodCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1 ;\n auto goodRow = ( int i ) => m.iota.all!( j => goodCell( i , j ) );\n auto found = n.iota.any!( goodRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n uint [][] a;\n foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;\n \n auto b = new uint [][] ( m, n );\n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n b[ i ][ j ] = a[ j ][ i ];\n }\n }\n \n uint[] sums;\n foreach ( j; 0..m ) {\n sums ~= b[ j ].sum;\n }\n \n debug { writeln(a, ' ', sums); }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new int [][] (n, m);\n foreach ( i; 0..n ) a[i] = readln.chomp.map!( c => cast(int)c - cast(int)'0' ).array;\n \n auto b = transposed(a.dup);\n auto sums = b.map!sum.array;\n \n auto found = false;\n foreach ( i; 0..n ) {\n auto cur = true;\n foreach ( j; 0..m ) {\n cur &= a[ i ][ j ] == 0 || sums[ j ] > 1;\n }\n found |= cur;\n }\n writeln ( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.array;\n \n auto b = new dchar [][] ( m, n );\n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n b[ i ][ j ] = a[ j ][ i ];\n }\n }\n auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.array;\n \n auto b = transposed( a.dup );\n auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;\n \n auto found = false;\n foreach ( i; 0..n ) {\n auto cur = true;\n foreach ( j; 0..m ) {\n cur &= a[ i ][ j ] == '0' || sums[ j ] > 1;\n }\n found |= cur;\n }\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.array;\n \n auto b = transposed( a.dup );\n auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;\n \n auto found = false;\n foreach ( i; 0..n ) {\n found |= m.iota.all!(j => a[ i ][ j ] == '0' || sums[ j ] > 1);\n }\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n uint [][] a;\n foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;\n \n auto b = new uint [][] ( m, n );\n foreach ( i; 0..m ) {\n foreach ( j; 0..n ) {\n b[ i ][ j ] = a[ j ][ i ];\n }\n }\n \n int[] sums;\n foreach ( j; 0..m ) {\n sums ~= b[ j ].sum;\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport core.bitop;\nimport std.algorithm;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new uint [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.map!(q{a - '0'}).array;\n \n auto b = transposed(a.dup);\n auto sums = new int[] (m);\n foreach ( j; 0..m ) {\n foreach ( i; 0..n ) {\n sums[ j ] += a[ i ][ j ];\n }\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\nimport std.bigint;\n\nvoid main()\n{\n\tint n, m;\n\treadln.chomp.split.tie(n, m);\n\tchar[][] field = new char[][](n);\n\tforeach (ref a; field) {\n\t\ta = readln.chomp.dup;\n\t}\n\tint[] cnt = new int[](m);\n\tforeach (a; field) {\n\t\tforeach (i, v; a) {\n\t\t\tif (v == '0') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcnt[i]++;\n\t\t}\n\t}\n\tdebug verbose(cnt);\n\tbool ok = false;\n\tforeach (i; 0..n) {\n\t\t// ignore i-th\n\t\tbool flag = true;\n\t\tforeach (j; 0..m) {\n\t\t\tif (field[i][j] == '0') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tflag &= cnt[j] > 1;\n\t\t}\n\t\tok |= flag;\n\t}\n\twriteln = ok ? \"YES\" : \"NO\";\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n uint [][] a;\n foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;\n \n auto b = transposed(a.dup).map!array.array;\n ulong[] sums;\n foreach ( j; 0..m ) {\n sums ~= b[ j ].count!(c => c == 1);\n }\n \n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int N = 2 * 1 ^^ 3 + 100;\n\nvoid main()\n{\n int n, m;\n readf( \"%s %s\", &n, &m );\n readln;\n auto a = new dchar [][] ( n, m );\n foreach ( i; 0..n ) a[ i ] = readln.chomp.array;\n \n auto b = transposed( a.dup ).array.map!array;\n auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;\n\n auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;\n auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );\n auto found = n.iota.any!( redundantRow );\n writeln( found ? \"YES\" : \"NO\" );\n}"}], "src_uid": "5ce39a83d27253f039f0e26045249d99"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nint[] A, B;\n\nstruct Interval {\n\tint s, t;\n\tint id;\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new int[N];\n\t\tB = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t\tB[i] = readInt;\n\t\t\tif (A[i] > B[i]) {\n\t\t\t\tswap(A[i], B[i]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tInterval[] as = new Interval[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tas[i] = Interval(A[i], B[i], i);\n\t\t}\n\t\tas.sort!((a, b) => (a.s != b.s) ? (a.s < b.s) : (a.t < b.t));\ndebug{\nwriteln(as);\n}\n\t\t\n\t\tint[] dp = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tdp[i] = 1;\n\t\t\tforeach (j; 0 .. i) {\n\t\t\t\tif (as[j].t < as[i].s) {\n\t\t\t\t\tchmax(dp[i], dp[j] + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\ndebug{\nwriteln(\"dp = \",dp);\n}\n\t\t\n\t\tconst ans = reduce!max(0, dp);\n\t\tint[] ss = new int[ans + 1];\n\t\tint[] ts = new int[ans + 1];\n\t\tss[] = int.min;\n\t\tts[] = int.max;\n\t\tforeach (i; 0 .. N) {\n\t\t\tchmax(ss[dp[i]], as[i].s);\n\t\t\tchmin(ts[dp[i]], as[i].t);\n\t\t}\ndebug{\nwriteln(ss,\" \",ts);\n}\n\t\tforeach (j; 1 .. ans + 1) {\n\t\t\tassert(ss[j] <= ts[j]);\n\t\t}\n\t\t\n\t\twriteln(ans);\n\t\twriteln(ss[1 .. $].to!string.removechars(\"[],\"));\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.variant;\nimport std.range;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n alias Ev = Tuple!(int, int, int);\n enum int closeEv = +1;\n enum int openEv = -1;\n auto evs = new Ev[](2 * n);\n foreach(i; 0 .. n)\n {\n int l = next!int;\n int h = next!int;\n if (l > h) swap(l, h);\n evs[2 * i] = Ev(l, openEv, i);\n evs[2 * i + 1] = Ev(h, closeEv, i);\n }\n auto alive = new bool[](n); alive[] = true;\n auto open = redBlackTree!int();\n auto nails = new int[](0);\n sort(evs);\n foreach(ev; evs)\n {\n int i = ev[2];\n int x = ev[0];\n int t = ev[1];\n if (!alive[i]) continue;\n if (t == closeEv)\n\t{\n\t nails ~= x;\n\t foreach(oi; open) alive[oi] = false;\n\t open.clear;\n\t}\n else if (t == openEv)\n\t{\n\t open.insert([i]);\n\t}\n else\n\t{\n\t assert(0);\n\t}\n }\n nails.length.writeln;\n nails.each!(x => x.write(\" \"));\n writeln;\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [], "src_uid": "60558a2148f7c9741bb310412f655ee4"} {"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tstring s;\n\treadf(\" %s\", &s);\n\tchar[] m = s.dup;\n\tint n=0;\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tif (m[i]=='n')\n\t\t{\n\t\t\tn=n+1;\n\t\t}\n\t}\n\tfor (int i=0; i<n; i++)\n\t{\n\t\twriteln(1);\n\t}\n\tfor (int i=0; i<((a-n*3)/4); i++)\n\t{\n\t\twriteln(0);\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = RD!string;\n\tlong[char] cnt;\n\tcnt['n'] = 0;\n\tcnt['z'] = 0;\n\tforeach (c; s)\n\t{\n\t\t++cnt[c];\n\t}\n\n\tlong[] ans;\n\tforeach (i; 0..cnt['n'])\n\t\tans ~= 1;\n\tforeach (i; 0..cnt['z'])\n\t\tans ~= 0;\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const S = readToken();\n \n const z = S.count('z');\n const n = S.count('n');\n int ou;\n foreach (i; 0 .. n) {\n if (ou++) write(\" \");\n write(1);\n }\n foreach (i; 0 .. z) {\n if (ou++) write(\" \");\n write(0);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "5e5dbd70c7fcedf0f965aed5bafeb06c"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n int[][] arr;\n foreach (i; 0 .. n) {\n arr ~= readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n dst[] = 0;\n foreach (rw; 0 .. n) {\n if (arr[rw][col] >= n*m) { continue; }\n \n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = rw >= rwval ? rw - rwval : rw + 1 + n-1 - rwval;\n \n dst[curdst] += 1;\n }\n \n int colsum = n;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.algorithm.mutation;\n\nstring[] tokens;\n\nstring readToken()\n{\n while (tokens.empty)\n {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nvoid main()\n{\n int n = readInt;\n int m = readInt;\n int[][] a = new int[][n];\n for (int i = 0; i < n; ++i)\n {\n a[i] = new int[m];\n for (int j = 0; j < m; ++j)\n {\n a[i][j] = readInt - 1;\n }\n }\n\n int[] count = new int[n];\n\n int result = 0;\n for (int j = 0; j < m; ++j)\n {\n fill(count, 0);\n for (int i = 0; i < n; ++i)\n {\n int x = a[i][j];\n if (x < n * m && x % m == j)\n {\n count[(i + n - (x - j) / m) % n]++;\n }\n }\n int best = n;\n for (int i = 0; i < n; ++i)\n {\n int x = a[i][j];\n if (x < n * m && x % m == j)\n {\n int moves = (i + n - (x - j) / m) % n;\n best = min(best, n - count[moves] + moves);\n }\n }\n result += best;\n }\n writeln(result);\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n int[][] arr;\n foreach (i; 0 .. n) {\n arr ~= readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n dst[] = 0;\n foreach (rw; 0 .. n) {\n if (arr[rw][col] >= n*m) { continue; }\n \n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = (rw - rwval + n) % n;\n \n dst[curdst] += 1;\n }\n \n int colsum = n;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tauto a = new int [] [] (n, m);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\treadf !(\" %s\") (a[i][j]);\n\t\t\t\ta[i][j] -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tauto d = n.iota.array;\n\t\t\td[] += n;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (a[i][j] < n * m && a[i][j] % m == j)\n\t\t\t\t{\n\t\t\t\t\td[(i + n - a[i][j] / m) % n] -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres += minElement (d);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto arr = new int[][] (n);\n foreach (i; 0 .. n) {\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n dst[] = 0;\n foreach (rw; 0 .. n) {\n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;\n \n dst[curdst] += 1;\n }\n \n int colsum = n;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto arr = new int[][] (n);\n foreach (i; 0 .. n) {\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n foreach (rw; 0 .. n) {\n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = (rw - rwval + n) % n;\n \n dst[curdst] += 1;\n }\n \n int colsum = n-1;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto arr = new int[][] (n);\n foreach (i; 0 .. n) {\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n foreach (rw; 0 .. n) {\n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;\n \n dst[curdst] += 1;\n }\n \n int colsum = n;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto arr = new int[][] (n);\n foreach (i; 0 .. n) {\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n foreach (rw; 0 .. n) {\n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;\n \n dst[curdst] += 1;\n }\n \n int colsum = n-1;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto arr = new int[][] (n);\n foreach (i; 0 .. n) {\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n dst[] = 0;\n foreach (rw; 0 .. n) {\n if (arr[rw][col] >= n*m) { continue; }\n \n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;\n \n dst[curdst] += 1;\n }\n \n int colsum = n;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto arr = new int[][] (n);\n foreach (i; 0 .. n) {\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n foreach (rw; 0 .. n) {\n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = (rw - rwval + n-1) % (n-1);\n \n dst[curdst] += 1;\n }\n \n int colsum = n-1;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n int[][] arr;\n foreach (i; 0 .. n) {\n arr ~= readln.chomp.split.map!(to!int).array;\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n arr[i][j] -= 1;\n }\n }\n \n int ans = 0;\n foreach (col; 0 .. m) {\n auto dst = new int[] (n);\n dst[] = 0;\n foreach (rw; 0 .. n) {\n if (arr[rw][col] >= n*m) { continue; }\n \n int md = arr[rw][col] % m;\n if (md != col) { continue; }\n \n int rwval = arr[rw][col] / m;\n int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;\n \n dst[curdst] += 1;\n }\n \n int colsum = n;\n foreach (d; 0 .. n) {\n colsum = min(colsum, d + n - dst[d]);\n }\n \n ans += colsum;\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tauto a = new int [] [] (n, m);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\treadf !(\" %s\") (a[i][j]);\n\t\t\t\ta[i][j] -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tauto d = n.iota.array;\n\t\t\td[] += n;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (a[i][j] % m == j)\n\t\t\t\t{\n\t\t\t\t\td[(i + n - a[i][j] / m) % n] -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres += minElement (d);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.algorithm.mutation;\n\nstring[] tokens;\n\nstring readToken()\n{\n while (tokens.empty)\n {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nvoid main()\n{\n int n = readInt;\n int m = readInt;\n int[][] a = new int[][n];\n for (int i = 0; i < n; ++i)\n {\n a[i] = new int[m];\n for (int j = 0; j < m; ++j)\n {\n a[i][j] = readInt - 1;\n }\n }\n\n int[] count = new int[n];\n\n int result = 0;\n for (int j = 0; j < m; ++j)\n {\n fill(count, 0);\n for (int i = 0; i < n; ++i)\n {\n int x = a[i][j];\n if (x % m == j)\n {\n count[(i + n - (x - j) / m) % n]++;\n }\n }\n int best = n;\n for (int i = 0; i < n; ++i)\n {\n int x = a[i][j];\n if (x % m == j)\n {\n int moves = (i + n - (x - j) / m) % n;\n best = min(best, n - count[moves] + moves);\n }\n }\n result += best;\n }\n writeln(result);\n}\n"}], "src_uid": "f44041707694eece7de0cc7c087f57d9"} {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, a, b, c, te; readV(n, a, b, c, te);\n int[] t; readA(n, t);\n\n auto ans = 0;\n foreach (ti; t) {\n if (b > c) {\n ans += a;\n } else {\n ans += a + (c-b)*(te-ti);\n }\n }\n\n writeln(ans);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main() {\n\tauto args = readln.chomp.split.map!(to!int).array;\n\tint n = args[0];\n\tint A = args[1];\n\tint B = args[2];\n\tint C = args[3];\n\tint T = args[4];\n\tint[] t = readln.chomp.split.map!(to!int).array;\n\tint[][][] dp = new int[][][](T + 2, T + 2, 2);\n\tint[int] dic;\n\tfor (int i = 1; i <= T; ++i) {\n\t\tdic[i] = 0;\n\t}\n\tforeach (v; t) {\n\t\t++dic[v];\n\t}\n\tdebug stderr.writeln(dic);\n\tfor (int i = 1; i <= T; ++i) {\n\t\tfor (int j = 1; j <= i; ++j) {\n\t\t\tdebug stderr.writeln(tuple(i, j, 1));\n\t\t\t{\n\t\t\t\tdp[i + 1][j][1] = dp[i][j][1] + dic[j] * C;\n\t\t\t\tdebug stderr.writefln(\"\\tdp[%d][%d][1] = %d (%d + %d * %d)\", i + 1, j, dp[i + 1][j][0], dp[i][j][1], dic[j], C);\n\t\t\t}\n\t\t\t{\n\t\t\t\tint pena = A - (i - j) * B;\n\t\t\t\tdp[i + 1][j][0] = max(dp[i][j][0], dp[i][j][1] + dic[j] * pena);\n\t\t\t\tdebug stderr.writefln(\"\\tdp[%d][%d][0] = %d (max(%d, %d + %d * %d)\", i + 1, j, dp[i + 1][j][0], dp[i][j][0], dp[i][j][1], dic[j], pena);\n\t\t\t}\n\t\t}\n\t}\n\tint sum = 0;\n\tfor (int i = 1; i <= T; ++i) {\n\t\tdebug stderr.writefln(\"\\t(%d) : %d\", i, dp[T + 1][i][0]);\n\t\tsum += dp[T + 1][i][0];\n\t}\n\tsum.writeln;\n}\n\n\n"}], "negative_code": [], "src_uid": "281b95c3686c94ae1c1e4e2a18b7fcc4"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int base = 2020;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto q = n / base;\r\n\t\tauto r = n % base;\r\n\t\twriteln ((q >= base) || (q >= r) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n int x;\r\n while (N >= 2020) {\r\n N -= 2020;\r\n ++x;\r\n }\r\n writeln(x >= N ? \"YES\" : \"NO\");\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto cnt = n / 2020;\r\n\t\tauto rem = n % 2020;\r\n\t\tans[ti] = rem <= cnt;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "3ec1b7027f487181dbdfb12f295f11ae"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(Capa, Cost, Capa CAPA_EPS = 0) {\n int n, m;\n int[][] g;\n int[] as, bs;\n Capa[] capa;\n Cost[] cost, pot;\n Capa tof;\n Cost toc;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; as = []; bs = []; capa = []; cost = [];\n }\n int addEdge(int u, int v, Capa w, Cost c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; as ~= u; bs ~= v; capa ~= w; cost ~= c; ++m;\n g[v] ~= m; as ~= v; bs ~= u; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n bool solve(int source, int sink, Capa flow) {\n pot = new Cost[n];\n pot[] = 0;\n for (; ; ) {\n bool cont;\n foreach (u; 0 .. n) foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (pot[v] > pot[u] + cost[i]) {\n pot[v] = pot[u] + cost[i];\n cont = true;\n }\n }\n if (!cont) break;\n }\n DList!int que;\n auto dist = new Cost[n];\n auto prei = new int[n];\n auto on = new bool[n];\n for (tof = 0, toc = 0; tof + CAPA_EPS < flow; ) {\n dist[] = -1;\n prei[] = -1;\n on[] = false;\n dist[source] = 0;\n prei[source] = -2;\n on[source] = true;\n que ~= source;\n for (; !que.empty; ) {\n const u = que.front;\n que.removeFront;\n on[u] = false;\n foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n const cc = dist[u] + cost[i] + pot[u] - pot[v];\n if (prei[v] == -1 || dist[v] > cc) {\n dist[v] = cc;\n prei[v] = i;\n if (!on[v]) {\n on[v] = true;\n que ~= v;\n }\n }\n }\n }\n if (prei[sink] == -1) return false;\n Capa f = flow - tof;\n for (int v = sink; v != source; ) {\n const i = prei[v];\n if (f > capa[i]) f = capa[i];\n v = as[i];\n }\n for (int v = sink; v != source; ) {\n const i = prei[v];\n capa[i] -= f; capa[i ^ 1] += f;\n v = as[i];\n }\n tof += f;\n toc += f * (dist[sink] - pot[source] + pot[sink]);\n pot[] += dist[];\n }\n return true;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n debug {\n writeln(\"adj = \", adj);\n }\n \n auto mcf = new MinCostFlow!(int, long)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 0) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"tof = \", mcf.tof, \", toc = \", mcf.toc);\n }\n assert(res);\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(wint, cint) {\n int n, m;\n int[][] g;\n int[] zu;\n wint[] capa0, capa, ex;\n cint[] cost;\n real[] pot;\n bool[] vis;\n int[] itr, lev;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; zu = null; capa = null; cost = null;\n ex = new wint[n]; pot = new real[n]; pot[] = 0; vis = new bool[n]; itr = new int[n]; lev = new int[n];\n }\n int addEdge(int u, int v, wint w, cint c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; zu ~= v; capa0 ~= w; capa ~= w; cost ~= +c; ++m;\n g[v] ~= m; zu ~= u; capa0 ~= 0; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n wint augment(int u, int t, wint f) {\n if (u == t) return f;\n foreach (i; g[u][itr[u] .. $]) {\n if (capa[i] > 0 && lev[u] < lev[zu[i]]) {\n wint g = augment(zu[i], t, min(f, capa[i]));\n if (g > 0) {\n capa[i] -= g; capa[i ^ 1] += g; return g;\n }\n }\n ++itr[u];\n }\n return 0;\n }\n wint augment(int u, wint f) {\n if (ex[u] < 0) {\n wint g = min(f, -ex[u]); ex[u] += g; return g;\n }\n foreach (i; g[u][itr[u] .. $]) {\n if (capa[i] > 0 && cost[i] + pot[u] - pot[zu[i]] < 0) {\n wint g = augment(zu[i], min(f, capa[i]));\n if (g > 0) {\n capa[i] -= g; capa[i ^ 1] += g; return g;\n }\n }\n ++itr[u];\n }\n return 0;\n }\n wint dinic(int s, int t, wint f) {\n wint tof = 0;\n for (; tof < f; ) {\n int[] q;\n lev[] = -1;\n for (lev[s] = 0, q ~= s; !q.empty; ) {\n int u = q.front; q.popFront;\n foreach (i; g[u]) {\n int v = zu[i];\n if (capa[i] > 0 && lev[v] == -1) {\n lev[v] = lev[u] + 1; q ~= v;\n }\n }\n }\n if (lev[t] == -1) break;\n itr[] = 0;\n for (wint g; (g = augment(s, t, f - tof)) > 0; ) tof += g;\n }\n return tof;\n }\n void dfs(int u) {\n if (vis[u]) return; vis[u] = true;\n foreach (i; g[u]) if (capa[i] > 0 && cost[i] + pot[u] - pot[zu[i]] < 0) {\n dfs(zu[i]);\n }\n }\n cint solve() {\n real eps = 0;\n // cint solve(int s, int t, wint flow) {\n // real eps = 1;\n // ex[s] += flow;\n // ex[t] -= flow;\n foreach (i; 0 .. m) if (capa[i] > 0) chmax(eps, cast(real)(-cost[i]));\n for (; eps * n >= 1; ) {\n eps /= 4;\n foreach (i; 0 .. m) if (capa[i] > 0 && cost[i] + pot[zu[i ^ 1]] - pot[zu[i]] < 0) {\n ex[zu[i ^ 1]] -= capa[i]; ex[zu[i]] += capa[i]; capa[i ^ 1] += capa[i]; capa[i] = 0;\n }\n for (; ; ) {\n vis[] = false; itr[] = 0;\n foreach (u; 0 .. n) if (ex[u] > 0) dfs(u);\n foreach (u; 0 .. n) if (vis[u]) pot[u] -= eps;\n foreach (u; 0 .. n) for (wint f; ex[u] > 0 && (f = augment(u, ex[u])) > 0; ) ex[u] -= f;\n if (ex.all!\"a <= 0\") break;\n }\n }\n cint toc = 0;\n foreach (i; 0 .. m) if (capa0[i] > capa[i]) toc += (capa0[i] - capa[i]) * cost[i];\n return toc;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n debug {\n writeln(\"adj = \", adj);\n }\n \n auto mcf = new MinCostFlow!(int, int)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n // writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 0) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n /*\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"tof = \", mcf.tof, \", toc = \", mcf.toc);\n }\n assert(res);\n */\n mcf.addEdge(1, 0, N * (N - 1) / 2, -2 * N);\n const res = mcf.solve;\n // const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"res = \", res);\n }\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n // assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"X\"\n dependency \"dunkelheit\" version=\"1.0.1\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner, dkh.graph.mincostflow;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n, m;\n sc.read(n, m);\n int ec = n * (n - 1) / 2;\n int v = ec + n + 2;\n int sv = ec + n, tv = sv + 1;\n struct E {\n int to, rev, cap, dist;\n }\n E[][] g = new E[][](v);\n void addEdge(int from, int to, int cap, int dist) {\n g[from] ~= E(to, g[to].length.to!int, cap, dist);\n g[to] ~= E(from, g[from].length.to!int-1, 0, -dist);\n }\n int[][] def = new int[][](n, n);\n foreach (i; 0..m) {\n int a, b;\n sc.read(a, b); a--; b--;\n def[a][b] = 1;\n def[b][a] = -1;\n }\n int id = 0;\n foreach (i; 0..n) {\n foreach (j; i + 1..n) {\n addEdge(sv, id, 1, 0);\n if (def[i][j] != -1) {\n addEdge(id, ec + i, 1, 0);\n }\n if (def[j][i] != -1) {\n addEdge(id, ec + j, 1, 0);\n }\n id++;\n }\n }\n foreach (i; 0..n) {\n foreach (j; 1..n+1) {\n addEdge(ec + i, tv, 1, j - 1);\n }\n }\n auto mcfInfo = minCostFlow!(int, int, 0)(g, sv, tv, false);\n mcfInfo.manyFlow(10^^9);\n\n int[][] ans = new int[][](n, n);\n id = 0;\n foreach (i; 0..n) {\n foreach (j; i + 1..n) {\n foreach (e; g[id]) {\n if (e.to < ec || ec + n <= e.to) continue;\n if (e.cap) continue;\n if (e.to == ec + i) ans[i][j] = 1;\n else ans[j][i] = 1;\n break;\n }\n id++;\n }\n }\n\n foreach (i; 0..n) {\n foreach (j; 0..n) {\n write(ans[i][j]);\n }\n writeln;\n }\n return 0;\n}\n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/container/deque.d */\n// module dkh.container.deque;\n\nstruct DequePayload(T) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint start, len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n if (start + i < cap) return _data[start + i];\n else return _data[start + i - cap];\n }\n ref inout(T) front() inout { return this[0]; }\n ref inout(T) back() inout { return this[$-1]; }\n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import std.algorithm : max;\n import std.conv : to;\n if (newCap <= cap) return;\n T* newData = cast(T*)GC.malloc(newCap * T.sizeof);\n foreach (i; 0..length) {\n newData[i] = this[i];\n }\n _data = newData; start = 0; cap = newCap.to!uint;\n }\n void clear() {\n start = len = 0;\n }\n import std.algorithm : max;\n void insertFront(T item) {\n if (len == cap) reserve(max(cap * 2, 4));\n if (start == 0) start += cap;\n start--; len++;\n this[0] = item;\n }\n void insertBack(T item) {\n if (len == cap) reserve(max(cap * 2, 4));\n len++;\n this[len-1] = item;\n }\n void removeFront() {\n assert(!empty, \"Deque.removeFront: Deque is empty\");\n start++; len--;\n if (start == cap) start = 0;\n }\n void removeBack() {\n assert(!empty, \"Deque.removeBack: Deque is empty\"); \n len--;\n }\n}\n\n \nstruct Deque(T, bool mayNull = true) {\n import core.exception : RangeError;\n import std.range : ElementType, isInputRange;\n import std.traits : isImplicitlyConvertible;\n\n alias Payload = DequePayload!T;\n Payload* _p;\n \n static if (!mayNull) @disable this();\n\n \n this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {\n _p = new Payload();\n foreach (v; values) {\n insertBack(v);\n }\n }\n \n this(Range)(Range r)\n if (isInputRange!Range &&\n isImplicitlyConvertible!(ElementType!Range, T) &&\n !is(Range == T[])) {\n _p = new Payload();\n foreach (v; r) {\n insertBack(v);\n }\n }\n private this(Payload* p) { _p = p; }\n static Deque make() { return Deque(new Payload()); }\n \n private bool havePayload() const { return (!mayNull || _p); } \n @property bool empty() const { return (!havePayload || _p.empty); } \n @property size_t length() const { return (havePayload ? _p.length : 0); } \n alias opDollar = length; \n\n ref inout(T) opIndex(size_t i) inout {\n assert(!empty, \"Deque.opIndex: Deque is empty\");\n return (*_p)[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void clear() { if (_p) _p.clear(); } \n\n \n void insertFront(T item) {\n if (mayNull && !_p) _p = new Payload();\n _p.insertFront(item);\n }\n void insertBack(T item) {\n if (mayNull && !_p) _p = new Payload();\n _p.insertBack(item);\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n alias stableInsertBack = insertBack; \n\n \n void removeFront() {\n assert(!mayNull || _p, \"Deque.removeFront: Deque is empty\");\n _p.removeFront();\n }\n void removeBack() {\n assert(!mayNull || _p, \"Deque.removeBack: Deque is empty\");\n _p.removeBack();\n } \n alias stableRemoveBack = removeBack; \n\n \n alias Range = RangeT!(DequePayload!T);\n alias ConstRange = RangeT!(const DequePayload!T); \n alias ImmutableRange = RangeT!(immutable DequePayload!T); \n\n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {\n assert(start <= end && end <= length);\n return [start, end];\n } \n Range opIndex(size_t[2] rng) { return Range(_p, rng[0], rng[1]); } \n ConstRange opIndex(size_t[2] rng) const { return ConstRange(_p, rng[0], rng[1]); } \n ImmutableRange opIndex(size_t[2] rng) immutable { return ImmutableRange(_p, rng[0], rng[1]); } \n auto opIndex() inout { return this[0..$]; } \n\n static struct RangeT(QualifiedPayload) {\n alias A = QualifiedPayload;\n import std.traits : CopyTypeQualifiers;\n alias E = CopyTypeQualifiers!(A, T);\n A *p;\n size_t l, r;\n\n @property bool empty() const { return r <= l; }\n @property size_t length() const { return r - l; }\n alias opDollar = length;\n\n @property auto save() { return this; }\n \n ref inout(E) opIndex(size_t i) inout {\n version(assert) if (empty) throw new RangeError();\n return (*p)[l+i];\n }\n @property ref inout(E) front() inout { return this[0]; }\n @property ref inout(E) back() inout { return this[$-1]; }\n\n void popFront() {\n version(assert) if (empty) throw new RangeError();\n l++;\n }\n void popBack() {\n version(assert) if (empty) throw new RangeError();\n r--;\n }\n \n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {\n assert(start <= end && end <= length);\n return [start, end];\n }\n auto opIndex(size_t[2] rng) { return RangeT(p, l+rng[0], l+rng[1]); }\n auto opIndex(size_t[2] rng) const { return RangeT!(const A)(p, l+rng[0], l+rng[1]); }\n auto opIndex(size_t[2] rng) immutable { return RangeT!(immutable A)(p, l+rng[0], l+rng[1]); }\n auto opIndex() inout { return this[0..$]; }\n } \n}\n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/container/radixheap.d */\n// module dkh.container.radixheap;\n\n// import dkh.container.stackpayload;\n\nimport std.functional : unaryFun;\nimport std.traits : isSigned, isUnsigned;\n\n \ntemplate RadixHeap(T, alias pred = \"a\") {\n alias _pred = unaryFun!pred; \n alias K = typeof(_pred(T())); \n \n static if (isUnsigned!K) {\n \n\n struct RadixHeap {\n static struct Payload {\n StackPayload!T[K.sizeof*8+1] v;\n size_t len;\n K last;\n\n \n private static int bsr1(K x) {\n import core.bitop : bsr;\n return (x == 0) ? 0 : bsr(x)+1;\n }\n private void assign(T item) {\n K key = _pred(item);\n assert(last <= key);\n v[bsr1(key^last)] ~= item;\n }\n private void pull() {\n import std.range, std.algorithm;\n if (v[0].length) return;\n auto i = iota(K.sizeof*8+1).find!(a => v[a].length).front;\n \n last = v[i].data[].map!_pred.reduce!min;\n v[i].data.each!(a => assign(a));\n v[i].clear();\n }\n\n void insert(T item) {\n len++;\n assign(item);\n }\n T front() {\n pull();\n return v[0].back;\n }\n void removeFront() {\n pull();\n len--;\n v[0].removeBack();\n }\n }\n Payload* p;\n\n @property bool empty() const { return (!p || p.len == 0); } \n @property size_t length() const { return (!p ? 0 : p.len); } \n alias opDollar = length; \n\n \n T front() {\n assert(!empty, \"RadixHeap.front: heap is empty\");\n return p.front;\n }\n void insert(T item) {\n if (!p) p = new Payload();\n p.insert(item);\n } \n void removeFront() {\n assert(!empty, \"RadixHeap.removeFront: heap is empty\");\n p.removeFront();\n } \n }\n } else static if (isSigned!K) {\n \n import std.traits : Unsigned;\n static Unsigned!K pred2(in T item) {\n return _pred(item) ^ (K(1) << (K.sizeof*8 - 1));\n }\n alias RadixHeap = RadixHeap!(T, pred2);\n } else {\n static assert(false);\n }\n}\n\n \n \n\n \n\n \n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/graph/mincostflow.d */\n// module dkh.graph.mincostflow;\n\n// import dkh.container.deque;\n\n \nstruct MinCostFlowInfo(C, D, D EPS, T) {\n T g;\n int s, t;\n C nc, capFlow; \n D nd, flow; \n D[] dual; \n private int[] pv, pe;\n this(T g, int s, int t) {\n this.g = g;\n this.s = s;\n this.t = t;\n flow = D(0);\n dual = new D[g.length]; dual[] = D(0);\n pv = new int[g.length];\n pe = new int[g.length];\n }\n}\n\n \nMinCostFlowInfo!(C, D, EPS, T) minCostFlow(C, D, D EPS, T)(T g, int s, int t, bool neg = false) {\n assert(s != t);\n auto mcfInfo = MinCostFlowInfo!(C, D, EPS, T)(g, s, t);\n mcfInfo.dualRef(neg);\n return mcfInfo;\n}\n\n \n \n\n \nC singleFlow(C, D, alias EPS, T)(ref MinCostFlowInfo!(C, D, EPS, T) mcfInfo, C c) {\n import std.algorithm;\n with (mcfInfo) {\n if (nd == D.max) return nc;\n c = min(c, nc);\n for (int v = t; v != s; v = pv[v]) {\n g[pv[v]][pe[v]].cap -= c;\n g[v][g[pv[v]][pe[v]].rev].cap += c;\n } \n capFlow += c;\n flow += c * nd;\n nc -= c;\n if (!nc) dualRef(mcfInfo, false);\n }\n return c;\n}\n\n \nvoid manyFlow(C, D, alias EPS, T)(ref MinCostFlowInfo!(C, D, EPS, T) mcfInfo, C c) {\n with (mcfInfo) {\n while (c) {\n C f = singleFlow(mcfInfo, c);\n if (!f) break;\n c -= f;\n }\n }\n}\n\n// import dkh.container.stackpayload;\n// import dkh.container.radixheap;\n\nvoid dualRef(bool neg, C, D, alias EPS, T)(ref MinCostFlowInfo!(C, D, EPS, T) mcfInfo) {\n import std.conv : to;\n import std.traits : isIntegral;\n import std.typecons;\n import std.container;\n import std.algorithm;\n alias P = Tuple!(int, \"to\", D, \"dist\");\n\n with(mcfInfo) {\n int n = g.length.to!int;\n D[] dist = new D[n]; dist[] = D.max;\n pv[] = -1; pe[] = -1;\n StackPayload!int refV;\n auto que = (){\n static if (!neg) {\n static if (isIntegral!D) {\n return RadixHeap!(P, \"a.dist\")();\n } else {\n return heapify!\"a.dist>b.dist\"(make!(Array!P));\n }\n } else {\n return Deque!P();\n }\n }();\n void insert(P p) {\n static if (!neg) {\n que.insert(p);\n } else {\n que.insertBack(p);\n }\n }\n P pop() {\n P p;\n static if (!neg) {\n p = que.front();\n que.removeFront();\n } else {\n p = que.back();\n que.removeBack();\n }\n return p;\n }\n insert(P(s, D(0)));\n dist[s] = D(0);\n while (!que.empty) {\n P p = pop();\n int v = p.to;\n if (dist[v] < p.dist) continue;\n if (!neg) {\n if (v == t) break;\n refV ~= v;\n }\n foreach (int i, e; g[v]) {\n D ed = e.dist + dual[v] - dual[e.to];\n if (e.cap && dist[e.to] > dist[v] + ed + EPS) {\n dist[e.to] = dist[v] + ed;\n pv[e.to] = v; pe[e.to] = i;\n insert(P(e.to, dist[e.to]));\n }\n }\n }\n if (dist[t] == D.max) {\n nd = D.max;\n nc = 0;\n return;\n }\n static if (!neg) {\n foreach (v; refV.data) {\n if (dist[v] >= dist[t]) continue;\n dual[v] += dist[v]-dist[t];\n }\n } else {\n for (int v = 0; v < n; v++) {\n if (dist[v] == D.max) dual[v] = D.max;\n else dual[v] += dist[v];\n }\n }\n \n nd = dual[t]-dual[s];\n nc = C.max;\n for (int v = t; v != s; v = pv[v]) {\n nc = min(nc, g[pv[v]][pe[v]].cap);\n }\n }\n}\n\nvoid dualRef(C, D, alias EPS, T)(ref MinCostFlowInfo!(C, D, EPS, T) mcfInfo, bool neg) {\n if (neg == false) {\n dualRef!false(mcfInfo);\n } else {\n dualRef!true(mcfInfo);\n }\n}\n\n \n\n \n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n private File f;\n \n this(File f) {\n this.f = f;\n }\n private char[512] lineBuf;\n private char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n assert(succW());\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n \n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n \n void read(Args...)(auto ref Args args) {\n import std.exception : enforce;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n \n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(Capa, Cost, Capa CAPA_EPS = 0) {\n int n, m;\n int[][] g;\n int[] as, bs;\n Capa[] capa;\n Cost[] cost, pot;\n Capa tof;\n Cost toc;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; as = []; bs = []; capa = []; cost = [];\n }\n int addEdge(int u, int v, Capa w, Cost c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; as ~= u; bs ~= v; capa ~= w; cost ~= c; ++m;\n g[v] ~= m; as ~= v; bs ~= u; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n bool solve(int source, int sink, Capa flow) {\n pot = new Cost[n];\n pot[] = 0;\n for (; ; ) {\n bool cont;\n foreach (u; 0 .. n) foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (pot[v] > pot[u] + cost[i]) {\n pot[v] = pot[u] + cost[i];\n cont = true;\n }\n }\n if (!cont) break;\n }\n auto dist = new Cost[n];\n auto prei = new int[n];\n auto on = new bool[n];\n for (tof = 0, toc = 0; tof + CAPA_EPS < flow; ) {\n DList!int que;\n dist[] = -1;\n prei[] = -1;\n on[] = false;\n dist[source] = 0;\n prei[source] = -2;\n on[source] = true;\n que ~= source;\n for (; !que.empty(); ) {\n const u = que.front;\n que.removeFront;\n on[u] = false;\n foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n const cc = dist[u] + cost[i] + pot[u] - pot[v];\n if (prei[v] == -1 || dist[v] > cc) {\n dist[v] = cc;\n prei[v] = i;\n if (!on[v]) {\n on[v] = true;\n que ~= v;\n }\n }\n }\n }\n if (prei[sink] == -1) return false;\n Capa f = flow - tof;\n for (int v = sink; v != source; ) {\n const i = prei[v];\n if (f > capa[i]) f = capa[i];\n v = as[i];\n }\n for (int v = sink; v != source; ) {\n const i = prei[v];\n capa[i] -= f; capa[i ^ 1] += f;\n v = as[i];\n }\n tof += f;\n toc += f * (dist[sink] - pot[source] + pot[sink]);\n pot[] += dist[];\n }\n return true;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n debug {\n writeln(\"adj = \", adj);\n }\n \n auto mcf = new MinCostFlow!(int, long)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 0) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"tof = \", mcf.tof, \", toc = \", mcf.toc);\n }\n assert(res);\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(wint, cint) {\n int n, m;\n int[][] g;\n int[] zu;\n wint[] capa0, capa, ex;\n cint[] cost;\n real[] pot;\n bool[] vis;\n int[] itr, lev;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; zu = null; capa = null; cost = null;\n ex = new wint[n]; pot = new real[n]; pot[] = 0; vis = new bool[n]; itr = new int[n]; lev = new int[n];\n }\n int addEdge(int u, int v, wint w, cint c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; zu ~= v; capa0 ~= w; capa ~= w; cost ~= +c; ++m;\n g[v] ~= m; zu ~= u; capa0 ~= 0; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n wint augment(int u, int t, wint f) {\n if (u == t) return f;\n foreach (i; g[u][itr[u] .. $]) {\n if (capa[i] > 0 && lev[u] < lev[zu[i]]) {\n wint g = augment(zu[i], t, min(f, capa[i]));\n if (g > 0) {\n capa[i] -= g; capa[i ^ 1] += g; return g;\n }\n }\n ++itr[u];\n }\n return 0;\n }\n wint augment(int u, wint f) {\n if (ex[u] < 0) {\n wint g = min(f, -ex[u]); ex[u] += g; return g;\n }\n foreach (i; g[u][itr[u] .. $]) {\n if (capa[i] > 0 && cost[i] + pot[u] - pot[zu[i]] < 0) {\n wint g = augment(zu[i], min(f, capa[i]));\n if (g > 0) {\n capa[i] -= g; capa[i ^ 1] += g; return g;\n }\n }\n ++itr[u];\n }\n return 0;\n }\n wint dinic(int s, int t, wint f) {\n wint tof = 0;\n for (; tof < f; ) {\n int[] q;\n lev[] = -1;\n for (lev[s] = 0, q ~= s; !q.empty; ) {\n int u = q.front; q.popFront;\n foreach (i; g[u]) {\n int v = zu[i];\n if (capa[i] > 0 && lev[v] == -1) {\n lev[v] = lev[u] + 1; q ~= v;\n }\n }\n }\n if (lev[t] == -1) break;\n itr[] = 0;\n for (wint g; (g = augment(s, t, f - tof)) > 0; ) tof += g;\n }\n return tof;\n }\n void dfs(int u) {\n if (vis[u]) return; vis[u] = true;\n foreach (i; g[u]) if (capa[i] > 0 && cost[i] + pot[u] - pot[zu[i]] < 0) {\n dfs(zu[i]);\n }\n }\n // cint solve() {\n // real eps = 0;\n cint solve(int s, int t, wint flow) {\n real eps = 1;\n ex[s] += flow;\n ex[t] -= flow;\n foreach (i; 0 .. m) if (capa[i] > 0) chmax(eps, cast(real)(-cost[i]));\n for (; eps * n >= 1; ) {\n eps /= 4;\n foreach (i; 0 .. m) if (capa[i] > 0 && cost[i] + pot[zu[i ^ 1]] - pot[zu[i]] < 0) {\n ex[zu[i ^ 1]] -= capa[i]; ex[zu[i]] += capa[i]; capa[i ^ 1] += capa[i]; capa[i] = 0;\n }\n for (; ; ) {\n vis[] = false; itr[] = 0;\n foreach (u; 0 .. n) if (ex[u] > 0) dfs(u);\n foreach (u; 0 .. n) if (vis[u]) pot[u] -= eps;\n foreach (u; 0 .. n) for (wint f; ex[u] > 0 && (f = augment(u, ex[u])) > 0; ) ex[u] -= f;\n if (ex.all!\"a <= 0\") break;\n }\n }\n cint toc = 0;\n foreach (i; 0 .. m) if (capa0[i] > capa[i]) toc += (capa0[i] - capa[i]) * cost[i];\n return toc;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n debug {\n writeln(\"adj = \", adj);\n }\n \n auto mcf = new MinCostFlow!(int, int)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n // writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 0) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n /*\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"tof = \", mcf.tof, \", toc = \", mcf.toc);\n }\n assert(res);\n */\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"res = \", res);\n }\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n // assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(Capa, Cost, Capa CAPA_EPS = 0) {\n int n, m;\n int[][] g;\n int[] as, bs;\n Capa[] capa;\n Cost[] cost, pot;\n Capa tof;\n Cost toc;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; as = []; bs = []; capa = []; cost = [];\n }\n int addEdge(int u, int v, Capa w, Cost c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; as ~= u; bs ~= v; capa ~= w; cost ~= c; ++m;\n g[v] ~= m; as ~= v; bs ~= u; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n bool solve(int source, int sink, Capa flow) {\n pot = new Cost[n];\n pot[] = 0;\n for (; ; ) {\n bool cont;\n foreach (u; 0 .. n) foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (pot[v] > pot[u] + cost[i]) {\n pot[v] = pot[u] + cost[i];\n cont = true;\n }\n }\n if (!cont) break;\n }\n auto dist = new Cost[n];\n auto prei = new int[n];\n auto vis = new bool[n];\n for (tof = 0, toc = 0; tof + CAPA_EPS < flow; ) {\n alias Entry = Tuple!(Cost, \"c\", int, \"u\");\n BinaryHeap!(Array!Entry, \"a > b\") que;\n dist[] = -1;\n prei[] = -1;\n vis[] = false;\n dist[source] = 0;\n prei[source] = -2;\n que.insert(Entry(0, source));\n for (; !que.empty(); ) {\n const c = que.front.c;\n const u = que.front.u;\n que.removeFront;\n if (vis[u]) continue;\n vis[u] = true;\n if (u == sink) break;\n foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (vis[v]) continue;\n const cc = c + cost[i] + pot[u] - pot[v];\n if (prei[v] == -1 || dist[v] > cc) {\n dist[v] = cc;\n prei[v] = i;\n que.insert(Entry(cc, v));\n }\n }\n }\n if (!vis[sink]) return false;\n Capa f = flow - tof;\n for (int v = sink; v != source; ) {\n const i = prei[v];\n if (f > capa[i]) f = capa[i];\n v = as[i];\n }\n for (int v = sink; v != source; ) {\n const i = prei[v];\n capa[i] -= f; capa[i ^ 1] += f;\n v = as[i];\n }\n tof += f;\n toc += f * (dist[sink] - pot[source] + pot[sink]);\n pot[] += dist[];\n }\n return true;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n debug {\n writeln(\"adj = \", adj);\n }\n \n auto mcf = new MinCostFlow!(int, long)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 0) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"tof = \", mcf.tof, \", toc = \", mcf.toc);\n }\n assert(res);\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(Capa, Cost, Capa CAPA_EPS = 0) {\n int n, m;\n int[][] g;\n int[] as, bs;\n Capa[] capa;\n Cost[] cost, pot;\n Capa tof;\n Cost toc;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; as = []; bs = []; capa = []; cost = [];\n }\n int addEdge(int u, int v, Capa w, Cost c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; as ~= u; bs ~= v; capa ~= w; cost ~= c; ++m;\n g[v] ~= m; as ~= v; bs ~= u; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n bool solve(int source, int sink, Capa flow) {\n pot = new Cost[n];\n pot[] = 0;\n for (; ; ) {\n bool cont;\n foreach (u; 0 .. n) foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (pot[v] > pot[u] + cost[i]) {\n pot[v] = pot[u] + cost[i];\n cont = true;\n }\n }\n if (!cont) break;\n }\n for (tof = 0, toc = 0; tof + CAPA_EPS < flow; ) {\n class Heap {\n Heap l, r, p;\n Cost dist;\n int prei, id;\n }\n Heap merge(Heap a, Heap b) {\n if (!a) return b;\n if (!b) return a;\n if (a.dist > b.dist) swap(a, b);\n a.r = merge(a.r, b);\n swap(a.l, a.r);\n if (a.l) a.l.p = a;\n if (a.r) a.r.p = a;\n return a;\n }\n void pop(ref Heap a) {\n a = merge(a.l, a.r);\n }\n void sever(ref Heap a, Heap b) {\n if (a == b || b.p.dist <= b.dist) return;\n ((b.p.l == b) ? b.p.l : b.p.r) = null;\n a = merge(a, b);\n }\n auto nodes = new Heap[n];\n foreach (u; 0 .. n) {\n nodes[u] = new Heap();\n nodes[u].dist = -1;\n nodes[u].prei = -1;\n nodes[u].id = u;\n }\n nodes[source].dist = 0;\n nodes[source].prei = -2;\n Heap que = nodes[source];\n for (; que; ) {\n const u = que.id;\n pop(que);\n foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n const cc = nodes[u].dist + cost[i] + pot[u] - pot[v];\n if (nodes[v].prei == -1) {\n nodes[v].dist = cc;\n nodes[v].prei = i;\n que = merge(que, nodes[v]);\n } else if (nodes[v].dist > cc) {\n nodes[v].dist = cc;\n nodes[v].prei = i;\n sever(que, nodes[v]);\n }\n }\n }\n if (nodes[sink].prei == -1) return false;\n Capa f = flow - tof;\n for (int v = sink; v != source; ) {\n const i = nodes[v].prei;\n if (f > capa[i]) f = capa[i];\n v = as[i];\n }\n for (int v = sink; v != source; ) {\n const i = nodes[v].prei;\n capa[i] -= f; capa[i ^ 1] += f;\n v = as[i];\n }\n tof += f;\n toc += f * (nodes[sink].dist - pot[source] + pot[sink]);\n foreach (u; 0 .. n) pot[u] += nodes[u].dist;\n }\n return true;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n debug {\n writeln(\"adj = \", adj);\n }\n \n auto mcf = new MinCostFlow!(int, long)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 0) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"tof = \", mcf.tof, \", toc = \", mcf.toc);\n }\n assert(res);\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(Capa, Cost, Capa CAPA_EPS = 0) {\n int n, m;\n int[][] g;\n int[] as, bs;\n Capa[] capa;\n Cost[] cost, pot;\n Capa tof;\n Cost toc;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; as = []; bs = []; capa = []; cost = [];\n }\n int addEdge(int u, int v, Capa w, Cost c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; as ~= u; bs ~= v; capa ~= w; cost ~= c; ++m;\n g[v] ~= m; as ~= v; bs ~= u; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n bool solve(int source, int sink, Capa flow) {\n pot = new Cost[n];\n pot[] = 0;\n for (; ; ) {\n bool cont;\n foreach (u; 0 .. n) foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (pot[v] > pot[u] + cost[i]) {\n pot[v] = pot[u] + cost[i];\n cont = true;\n }\n }\n if (!cont) break;\n }\n auto dist = new Cost[n];\n auto prei = new int[n];\n auto vis = new bool[n];\n for (tof = 0, toc = 0; tof + CAPA_EPS < flow; ) {\n alias Entry = Tuple!(Cost, \"c\", int, \"u\");\n BinaryHeap!(Array!Entry, \"a > b\") que;\n dist[] = -1;\n prei[] = -1;\n vis[] = false;\n dist[source] = 0;\n prei[source] = -2;\n que.insert(Entry(0, source));\n for (; !que.empty(); ) {\n const c = que.front.c;\n const u = que.front.u;\n que.removeFront;\n if (vis[u]) continue;\n vis[u] = true;\n if (u == sink) break;\n foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (vis[v]) continue;\n const cc = c + cost[i] + pot[u] - pot[v];\n if (prei[v] == -1 || dist[v] > cc) {\n dist[v] = cc;\n prei[v] = i;\n que.insert(Entry(cc, v));\n }\n }\n }\n if (!vis[sink]) return false;\n Capa f = flow - tof;\n for (int v = sink; v != source; ) {\n const i = prei[v];\n if (f > capa[i]) f = capa[i];\n v = as[i];\n }\n for (int v = sink; v != source; ) {\n const i = prei[v];\n capa[i] -= f; capa[i ^ 1] += f;\n v = as[i];\n }\n tof += f;\n toc += f * (dist[sink] - pot[source] + pot[sink]);\n foreach (u; 0 .. n) if (vis[u]) pot[u] += dist[u];\n }\n return true;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n debug {\n writeln(\"adj = \", adj);\n }\n \n auto mcf = new MinCostFlow!(int, long)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 0) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"tof = \", mcf.tof, \", toc = \", mcf.toc);\n }\n assert(res);\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "/+ dub.sdl:\n name \"X\"\n dependency \"dunkelheit\" version=\"1.0.1\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner, dkh.graph.mincostflow;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n, m;\n sc.read(n, m);\n int ec = n * (n - 1) / 2;\n int v = ec + n + 2;\n int sv = ec + n, tv = sv + 1;\n struct E {\n int to, rev, cap, dist;\n }\n E[][] g = new E[][](v);\n void addEdge(int from, int to, int cap, int dist) {\n g[from] ~= E(to, g[to].length.to!int, cap, dist);\n g[to] ~= E(from, g[from].length.to!int-1, 0, -dist);\n }\n int[][] def = new int[][](n, n);\n foreach (i; 0..m) {\n int a, b;\n sc.read(a, b); a--; b--;\n def[a][b] = 1;\n def[b][a] = -1;\n }\n int id = 0;\n foreach (i; 0..n) {\n foreach (j; i + 1..n) {\n addEdge(sv, id, 1, 0);\n if (def[i][j] != -1) {\n addEdge(id, ec + i, 1, 0);\n }\n if (def[j][i] != -1) {\n addEdge(id, ec + j, 1, 0);\n }\n id++;\n }\n }\n foreach (i; 0..n) {\n foreach (j; 1..n+1) {\n addEdge(ec + i, tv, 1, j - 1);\n }\n }\n auto mcfInfo = minCostFlow!(int, int, 0)(g, sv, tv, false);\n mcfInfo.manyFlow(10^^9);\n\n int[][] ans = new int[][](n, n);\n id = 0;\n foreach (i; 0..n) {\n foreach (j; i + 1..n) {\n foreach (e; g[id]) {\n if (e.to < ec || ec + n <= e.to) continue;\n if (e.cap) continue;\n if (e.to == ec + i) ans[i][j] = 1;\n else ans[j][i] = 1;\n break;\n }\n id++;\n }\n }\n\n foreach (i; 0..n) {\n foreach (j; 0..n) {\n write(ans[i][j], \" \");\n }\n writeln;\n }\n return 0;\n}\n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/container/deque.d */\n// module dkh.container.deque;\n\nstruct DequePayload(T) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint start, len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n if (start + i < cap) return _data[start + i];\n else return _data[start + i - cap];\n }\n ref inout(T) front() inout { return this[0]; }\n ref inout(T) back() inout { return this[$-1]; }\n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import std.algorithm : max;\n import std.conv : to;\n if (newCap <= cap) return;\n T* newData = cast(T*)GC.malloc(newCap * T.sizeof);\n foreach (i; 0..length) {\n newData[i] = this[i];\n }\n _data = newData; start = 0; cap = newCap.to!uint;\n }\n void clear() {\n start = len = 0;\n }\n import std.algorithm : max;\n void insertFront(T item) {\n if (len == cap) reserve(max(cap * 2, 4));\n if (start == 0) start += cap;\n start--; len++;\n this[0] = item;\n }\n void insertBack(T item) {\n if (len == cap) reserve(max(cap * 2, 4));\n len++;\n this[len-1] = item;\n }\n void removeFront() {\n assert(!empty, \"Deque.removeFront: Deque is empty\");\n start++; len--;\n if (start == cap) start = 0;\n }\n void removeBack() {\n assert(!empty, \"Deque.removeBack: Deque is empty\"); \n len--;\n }\n}\n\n \nstruct Deque(T, bool mayNull = true) {\n import core.exception : RangeError;\n import std.range : ElementType, isInputRange;\n import std.traits : isImplicitlyConvertible;\n\n alias Payload = DequePayload!T;\n Payload* _p;\n \n static if (!mayNull) @disable this();\n\n \n this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {\n _p = new Payload();\n foreach (v; values) {\n insertBack(v);\n }\n }\n \n this(Range)(Range r)\n if (isInputRange!Range &&\n isImplicitlyConvertible!(ElementType!Range, T) &&\n !is(Range == T[])) {\n _p = new Payload();\n foreach (v; r) {\n insertBack(v);\n }\n }\n private this(Payload* p) { _p = p; }\n static Deque make() { return Deque(new Payload()); }\n \n private bool havePayload() const { return (!mayNull || _p); } \n @property bool empty() const { return (!havePayload || _p.empty); } \n @property size_t length() const { return (havePayload ? _p.length : 0); } \n alias opDollar = length; \n\n ref inout(T) opIndex(size_t i) inout {\n assert(!empty, \"Deque.opIndex: Deque is empty\");\n return (*_p)[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void clear() { if (_p) _p.clear(); } \n\n \n void insertFront(T item) {\n if (mayNull && !_p) _p = new Payload();\n _p.insertFront(item);\n }\n void insertBack(T item) {\n if (mayNull && !_p) _p = new Payload();\n _p.insertBack(item);\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n alias stableInsertBack = insertBack; \n\n \n void removeFront() {\n assert(!mayNull || _p, \"Deque.removeFront: Deque is empty\");\n _p.removeFront();\n }\n void removeBack() {\n assert(!mayNull || _p, \"Deque.removeBack: Deque is empty\");\n _p.removeBack();\n } \n alias stableRemoveBack = removeBack; \n\n \n alias Range = RangeT!(DequePayload!T);\n alias ConstRange = RangeT!(const DequePayload!T); \n alias ImmutableRange = RangeT!(immutable DequePayload!T); \n\n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {\n assert(start <= end && end <= length);\n return [start, end];\n } \n Range opIndex(size_t[2] rng) { return Range(_p, rng[0], rng[1]); } \n ConstRange opIndex(size_t[2] rng) const { return ConstRange(_p, rng[0], rng[1]); } \n ImmutableRange opIndex(size_t[2] rng) immutable { return ImmutableRange(_p, rng[0], rng[1]); } \n auto opIndex() inout { return this[0..$]; } \n\n static struct RangeT(QualifiedPayload) {\n alias A = QualifiedPayload;\n import std.traits : CopyTypeQualifiers;\n alias E = CopyTypeQualifiers!(A, T);\n A *p;\n size_t l, r;\n\n @property bool empty() const { return r <= l; }\n @property size_t length() const { return r - l; }\n alias opDollar = length;\n\n @property auto save() { return this; }\n \n ref inout(E) opIndex(size_t i) inout {\n version(assert) if (empty) throw new RangeError();\n return (*p)[l+i];\n }\n @property ref inout(E) front() inout { return this[0]; }\n @property ref inout(E) back() inout { return this[$-1]; }\n\n void popFront() {\n version(assert) if (empty) throw new RangeError();\n l++;\n }\n void popBack() {\n version(assert) if (empty) throw new RangeError();\n r--;\n }\n \n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {\n assert(start <= end && end <= length);\n return [start, end];\n }\n auto opIndex(size_t[2] rng) { return RangeT(p, l+rng[0], l+rng[1]); }\n auto opIndex(size_t[2] rng) const { return RangeT!(const A)(p, l+rng[0], l+rng[1]); }\n auto opIndex(size_t[2] rng) immutable { return RangeT!(immutable A)(p, l+rng[0], l+rng[1]); }\n auto opIndex() inout { return this[0..$]; }\n } \n}\n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/container/radixheap.d */\n// module dkh.container.radixheap;\n\n// import dkh.container.stackpayload;\n\nimport std.functional : unaryFun;\nimport std.traits : isSigned, isUnsigned;\n\n \ntemplate RadixHeap(T, alias pred = \"a\") {\n alias _pred = unaryFun!pred; \n alias K = typeof(_pred(T())); \n \n static if (isUnsigned!K) {\n \n\n struct RadixHeap {\n static struct Payload {\n StackPayload!T[K.sizeof*8+1] v;\n size_t len;\n K last;\n\n \n private static int bsr1(K x) {\n import core.bitop : bsr;\n return (x == 0) ? 0 : bsr(x)+1;\n }\n private void assign(T item) {\n K key = _pred(item);\n assert(last <= key);\n v[bsr1(key^last)] ~= item;\n }\n private void pull() {\n import std.range, std.algorithm;\n if (v[0].length) return;\n auto i = iota(K.sizeof*8+1).find!(a => v[a].length).front;\n \n last = v[i].data[].map!_pred.reduce!min;\n v[i].data.each!(a => assign(a));\n v[i].clear();\n }\n\n void insert(T item) {\n len++;\n assign(item);\n }\n T front() {\n pull();\n return v[0].back;\n }\n void removeFront() {\n pull();\n len--;\n v[0].removeBack();\n }\n }\n Payload* p;\n\n @property bool empty() const { return (!p || p.len == 0); } \n @property size_t length() const { return (!p ? 0 : p.len); } \n alias opDollar = length; \n\n \n T front() {\n assert(!empty, \"RadixHeap.front: heap is empty\");\n return p.front;\n }\n void insert(T item) {\n if (!p) p = new Payload();\n p.insert(item);\n } \n void removeFront() {\n assert(!empty, \"RadixHeap.removeFront: heap is empty\");\n p.removeFront();\n } \n }\n } else static if (isSigned!K) {\n \n import std.traits : Unsigned;\n static Unsigned!K pred2(in T item) {\n return _pred(item) ^ (K(1) << (K.sizeof*8 - 1));\n }\n alias RadixHeap = RadixHeap!(T, pred2);\n } else {\n static assert(false);\n }\n}\n\n \n \n\n \n\n \n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/graph/mincostflow.d */\n// module dkh.graph.mincostflow;\n\n// import dkh.container.deque;\n\n \nstruct MinCostFlowInfo(C, D, D EPS, T) {\n T g;\n int s, t;\n C nc, capFlow; \n D nd, flow; \n D[] dual; \n private int[] pv, pe;\n this(T g, int s, int t) {\n this.g = g;\n this.s = s;\n this.t = t;\n flow = D(0);\n dual = new D[g.length]; dual[] = D(0);\n pv = new int[g.length];\n pe = new int[g.length];\n }\n}\n\n \nMinCostFlowInfo!(C, D, EPS, T) minCostFlow(C, D, D EPS, T)(T g, int s, int t, bool neg = false) {\n assert(s != t);\n auto mcfInfo = MinCostFlowInfo!(C, D, EPS, T)(g, s, t);\n mcfInfo.dualRef(neg);\n return mcfInfo;\n}\n\n \n \n\n \nC singleFlow(C, D, alias EPS, T)(ref MinCostFlowInfo!(C, D, EPS, T) mcfInfo, C c) {\n import std.algorithm;\n with (mcfInfo) {\n if (nd == D.max) return nc;\n c = min(c, nc);\n for (int v = t; v != s; v = pv[v]) {\n g[pv[v]][pe[v]].cap -= c;\n g[v][g[pv[v]][pe[v]].rev].cap += c;\n } \n capFlow += c;\n flow += c * nd;\n nc -= c;\n if (!nc) dualRef(mcfInfo, false);\n }\n return c;\n}\n\n \nvoid manyFlow(C, D, alias EPS, T)(ref MinCostFlowInfo!(C, D, EPS, T) mcfInfo, C c) {\n with (mcfInfo) {\n while (c) {\n C f = singleFlow(mcfInfo, c);\n if (!f) break;\n c -= f;\n }\n }\n}\n\n// import dkh.container.stackpayload;\n// import dkh.container.radixheap;\n\nvoid dualRef(bool neg, C, D, alias EPS, T)(ref MinCostFlowInfo!(C, D, EPS, T) mcfInfo) {\n import std.conv : to;\n import std.traits : isIntegral;\n import std.typecons;\n import std.container;\n import std.algorithm;\n alias P = Tuple!(int, \"to\", D, \"dist\");\n\n with(mcfInfo) {\n int n = g.length.to!int;\n D[] dist = new D[n]; dist[] = D.max;\n pv[] = -1; pe[] = -1;\n StackPayload!int refV;\n auto que = (){\n static if (!neg) {\n static if (isIntegral!D) {\n return RadixHeap!(P, \"a.dist\")();\n } else {\n return heapify!\"a.dist>b.dist\"(make!(Array!P));\n }\n } else {\n return Deque!P();\n }\n }();\n void insert(P p) {\n static if (!neg) {\n que.insert(p);\n } else {\n que.insertBack(p);\n }\n }\n P pop() {\n P p;\n static if (!neg) {\n p = que.front();\n que.removeFront();\n } else {\n p = que.back();\n que.removeBack();\n }\n return p;\n }\n insert(P(s, D(0)));\n dist[s] = D(0);\n while (!que.empty) {\n P p = pop();\n int v = p.to;\n if (dist[v] < p.dist) continue;\n if (!neg) {\n if (v == t) break;\n refV ~= v;\n }\n foreach (int i, e; g[v]) {\n D ed = e.dist + dual[v] - dual[e.to];\n if (e.cap && dist[e.to] > dist[v] + ed + EPS) {\n dist[e.to] = dist[v] + ed;\n pv[e.to] = v; pe[e.to] = i;\n insert(P(e.to, dist[e.to]));\n }\n }\n }\n if (dist[t] == D.max) {\n nd = D.max;\n nc = 0;\n return;\n }\n static if (!neg) {\n foreach (v; refV.data) {\n if (dist[v] >= dist[t]) continue;\n dual[v] += dist[v]-dist[t];\n }\n } else {\n for (int v = 0; v < n; v++) {\n if (dist[v] == D.max) dual[v] = D.max;\n else dual[v] += dist[v];\n }\n }\n \n nd = dual[t]-dual[s];\n nc = C.max;\n for (int v = t; v != s; v = pv[v]) {\n nc = min(nc, g[pv[v]][pe[v]].cap);\n }\n }\n}\n\nvoid dualRef(C, D, alias EPS, T)(ref MinCostFlowInfo!(C, D, EPS, T) mcfInfo, bool neg) {\n if (neg == false) {\n dualRef!false(mcfInfo);\n } else {\n dualRef!true(mcfInfo);\n }\n}\n\n \n\n \n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n private File f;\n \n this(File f) {\n this.f = f;\n }\n private char[512] lineBuf;\n private char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n assert(succW());\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n \n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n \n void read(Args...)(auto ref Args args) {\n import std.exception : enforce;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n \n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(Capa, Cost, Capa CAPA_EPS = 0) {\n int n, m;\n int[][] g;\n int[] as, bs;\n Capa[] capa;\n Cost[] cost, pot;\n Capa tof;\n Cost toc;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; as = []; bs = []; capa = []; cost = [];\n }\n int addEdge(int u, int v, Capa w, Cost c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; as ~= u; bs ~= v; capa ~= w; cost ~= c; ++m;\n g[v] ~= m; as ~= v; bs ~= u; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n bool solve(int source, int sink, Capa flow) {\n pot = new Cost[n];\n pot[] = 0;\n for (; ; ) {\n bool cont;\n foreach (u; 0 .. n) foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (pot[v] > pot[u] + cost[i]) {\n pot[v] = pot[u] + cost[i];\n cont = true;\n }\n }\n if (!cont) break;\n }\n auto dist = new Cost[n];\n auto prei = new int[n];\n auto on = new bool[n];\n for (tof = 0, toc = 0; tof + CAPA_EPS < flow; ) {\n DList!int que;\n dist[] = -1;\n prei[] = -1;\n on[] = false;\n dist[source] = 0;\n prei[source] = -2;\n on[source] = true;\n que ~= source;\n for (; !que.empty(); ) {\n const u = que.front;\n que.removeFront;\n on[u] = false;\n if (u == sink) break;\n foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n const cc = dist[u] + cost[i] + pot[u] - pot[v];\n if (prei[v] == -1 || dist[v] > cc) {\n dist[v] = cc;\n prei[v] = i;\n if (!on[v]) {\n on[v] = true;\n que ~= v;\n }\n }\n }\n }\n if (prei[sink] == -1) return false;\n Capa f = flow - tof;\n for (int v = sink; v != source; ) {\n const i = prei[v];\n if (f > capa[i]) f = capa[i];\n v = as[i];\n }\n for (int v = sink; v != source; ) {\n const i = prei[v];\n capa[i] -= f; capa[i ^ 1] += f;\n v = as[i];\n }\n tof += f;\n toc += f * (dist[sink] - pot[source] + pot[sink]);\n pot[] += dist[];\n }\n return true;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n debug {\n writeln(\"adj = \", adj);\n }\n \n auto mcf = new MinCostFlow!(int, long)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 0) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n debug {\n writeln(\"tof = \", mcf.tof, \", toc = \", mcf.toc);\n }\n assert(res);\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n \nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n \nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n \nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n \nclass MaxFlow(Capa) {\n enum Capa wEPS = 0;\n enum Capa wINF = 10^^9;\n int n, m;\n int[][] g;\n int[] zu;\n Capa[] capa;\n Capa tof;\n int[] lev, see, que;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; zu = []; capa = [];\n lev = new int[n]; see = new int[n]; que = new int[n];\n }\n void addEdge(int u, int v, Capa w0, Capa w1 = 0) {\n g[u] ~= m; zu ~= v; capa ~= w0; ++m;\n g[v] ~= m; zu ~= u; capa ~= w1; ++m;\n }\n Capa augment(int src, int ink, Capa flo) {\n if (src == ink) return flo;\n foreach (i; g[src][see[src] .. $]) {\n if (capa[i] > wEPS && lev[src] < lev[zu[i]]) {\n Capa f = augment(zu[i], ink, min(flo, capa[i]));\n if (f > wEPS) { capa[i] -= f; capa[i ^ 1] += f; return f; }\n }\n ++see[src];\n }\n return 0;\n }\n bool dinic(int src, int ink, Capa flo = wINF) {\n for (tof = 0; tof + wEPS < flo; ) {\n int[] q;\n lev[] = -1;\n dinicBFS:\n for (lev[src] = 0, q ~= src; !q.empty; ) {\n int u = q.front; q.popFront;\n foreach (i; g[u]) {\n int v = zu[i];\n if (capa[i] > wEPS && lev[v] == -1) {\n lev[v] = lev[u] + 1; q ~= v;\n if (v == ink) break dinicBFS;\n }\n }\n }\n if (lev[ink] == -1) return false;\n see[] = 0;\n for (; ; ) {\n Capa f = augment(src, ink, flo - tof);\n if (f <= wEPS) break;\n tof += f;\n }\n }\n return true;\n }\n}\n \n \n \nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto ws = new int[N];\n auto ls = new int[N];\n foreach (i; 0 .. M) {\n ++ws[U[i]];\n ++ls[V[i]];\n }\n auto dp = new int[][](N + 1, N * (N - 1) / 2 + 1);\n auto prev = new int[][](N + 1, N * (N - 1) / 2 + 1);\n foreach (u; 0 .. N + 1) {\n dp[u][] = -1;\n }\n dp[0][0] = 0;\n foreach (u; 0 .. N) {\n foreach (a; 0 .. N * (N - 1) / 2 + 1) {\n if (dp[u][a] >= 0) {\n foreach (x; ws[u] .. (N - 1 - ls[u]) + 1) {\n if (a + x <= N * (N - 1) / 2) {\n if (chmax(dp[u + 1][a + x], dp[u][a] + x * (N - 1 - x))) {\n prev[u + 1][a + x] = x;\n }\n }\n }\n }\n }\n }\n auto xs = new int[N];\n for (int u = N, a = N * (N - 1) / 2; u > 0; ) {\n const x = prev[u][a];\n --u;\n a -= x;\n xs[u] = x;\n }\n debug {\n writeln(\"xs = \", xs);\n }\n \n auto ans = new char[][](N, N);\n foreach (u; 0 .. N) {\n ans[u][] = '0';\n }\n auto ys = new int[N];\n auto zs = new int[N];\n foreach (u; 0 .. N) {\n ys[u] = xs[u];\n zs[u] = N - 1 - xs[u];\n }\n foreach (i; 0 .. M) {\n ans[U[i]][V[i]] = '1';\n --ys[U[i]];\n --zs[V[i]];\n }\n debug {\n writeln(\"ys = \", ys);\n writeln(\"zs = \", zs);\n }\n \n auto mf = new MaxFlow!int(2 + N + N);\n foreach (u; 0 .. N) {\n mf.addEdge(0, 2 + u, ys[u]);\n mf.addEdge(2 + N + u, 1, zs[u]);\n }\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; 0 .. N) {\n if (u != v && ans[u][v] == '0' && ans[v][u] == '0') {\n ids[u][v] = mf.m;\n mf.addEdge(2 + u, 2 + N + v, 1);\n } else {\n ids[u][v] = -1;\n }\n }\n const res = mf.dinic(0, 1, N * (N - 1) / 2 - M);\n assert(res);\n \n foreach (u; 0 .. N) foreach (v; 0 .. N) {\n if (u != v && ans[u][v] == '0' && ans[v][u] == '0') {\n if (mf.capa[ids[u][v]] == 0) {\n ans[u][v] = '1';\n }\n }\n }\n foreach (u; 0 .. N) {\n writeln(ans[u]);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MinCostFlow(Capa, Cost, Capa CAPA_EPS = 0) {\n int n, m;\n int[][] g;\n int[] as, bs;\n Capa[] capa;\n Cost[] cost, pot;\n Capa tof;\n Cost toc;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; as = []; bs = []; capa = []; cost = [];\n }\n int addEdge(int u, int v, Capa w, Cost c) {\n debug {\n writeln(\"addEdge \", u, \" \", v, \" \", w, \" \", c);\n }\n const i = m;\n g[u] ~= m; as ~= u; bs ~= v; capa ~= w; cost ~= c; ++m;\n g[v] ~= m; as ~= v; bs ~= u; capa ~= 0; cost ~= -c; ++m;\n return i;\n }\n bool solve(int source, int sink, Capa flow) {\n pot = new Cost[n];\n pot[] = 0;\n for (; ; ) {\n bool cont;\n foreach (u; 0 .. n) foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n if (pot[v] > pot[u] + cost[i]) {\n pot[v] = pot[u] + cost[i];\n cont = true;\n }\n }\n if (!cont) break;\n }\n auto dist = new Cost[n];\n auto prei = new int[n];\n auto vis = new bool[n];\n for (tof = 0, toc = 0; tof + CAPA_EPS < flow; ) {\n alias Entry = Tuple!(Cost, \"c\", int, \"u\");\n BinaryHeap!(Array!Entry, \"a < b\") que;\n dist[] = -1;\n prei[] = -1;\n vis[] = false;\n dist[source] = 0;\n prei[source] = -2;\n que.insert(Entry(0, source));\n for (; !que.empty(); ) {\n const c = que.front.c;\n const u = que.front.u;\n que.removeFront;\n if (vis[u]) continue;\n vis[u] = true;\n foreach (i; g[u]) if (capa[i] > CAPA_EPS) {\n const v = bs[i];\n const cc = c + cost[i] + pot[u] - pot[v];\n if (prei[v] == -1 || dist[v] > cc) {\n dist[v] = cc;\n prei[v] = i;\n que.insert(Entry(cc, v));\n }\n }\n }\n if (!vis[sink]) return false;\n Capa f = flow - tof;\n for (int v = sink; v != source; ) {\n const i = prei[v];\n if (f > capa[i]) f = capa[i];\n v = as[i];\n }\n for (int v = sink; v != source; ) {\n const i = prei[v];\n capa[i] -= f; capa[i ^ 1] += f;\n v = as[i];\n }\n tof += f;\n toc += f * (dist[sink] - pot[source] + pot[sink]);\n pot[] += dist[];\n }\n return true;\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto adj = new int[][](N, N);\n foreach (u; 0 .. N) {\n adj[u][] = -1;\n }\n foreach (i; 0 .. M) {\n adj[U[i]][V[i]] = 1;\n adj[V[i]][U[i]] = 0;\n }\n \n auto mcf = new MinCostFlow!(int, long)(2 + N + N * (N - 1) / 2);\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) {\n // -d (N - 1 - d)\n foreach (d; 0 .. N - 1) {\n const diff = (-(d + 1) * (N - 1 - (d + 1))) - (-d * (N - 1 - d));\n mcf.addEdge(0, 2 + u, 1, diff);\n debug {\n writeln(u, \" \", d, \": \", diff);\n }\n }\n }\n foreach (x; 2 + N .. 2 + N + N * (N - 1) / 2) {\n mcf.addEdge(x, 1, 1, 0);\n }\n foreach (u; 0 .. N) {\n ids[u][] = -1;\n }\n {\n int x = 2 + N;\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (adj[u][v] != 0) ids[u][v] = mcf.addEdge(2 + u, x, 1, 0);\n if (adj[v][u] != 1) ids[v][u] = mcf.addEdge(2 + v, x, 1, 0);\n ++x;\n }\n assert(x == 2 + N + N * (N - 1) / 2);\n }\n const res = mcf.solve(0, 1, N * (N - 1) / 2);\n assert(res);\n \n auto ans = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; u + 1 .. N) {\n if (ids[u][v] != -1 && mcf.capa[ids[u][v]] == 0) ans[u][v] = 1;\n if (ids[v][u] != -1 && mcf.capa[ids[v][u]] == 0) ans[v][u] = 1;\n assert(ans[u][v] + ans[v][u] == 1);\n }\n foreach (u; 0 .. N) {\n foreach (v; 0 .. N) {\n write(ans[u][v]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nclass MaxFlow(Capa) {\n enum Capa wEPS = 0;\n enum Capa wINF = 10^^9;\n int n, m;\n int[][] g;\n int[] zu;\n Capa[] capa;\n Capa tof;\n int[] lev, see, que;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; zu = []; capa = [];\n lev = new int[n]; see = new int[n]; que = new int[n];\n }\n void addEdge(int u, int v, Capa w0, Capa w1 = 0) {\n g[u] ~= m; zu ~= v; capa ~= w0; ++m;\n g[v] ~= m; zu ~= u; capa ~= w1; ++m;\n }\n Capa augment(int src, int ink, Capa flo) {\n if (src == ink) return flo;\n foreach (i; g[src][see[src] .. $]) {\n if (capa[i] > wEPS && lev[src] < lev[zu[i]]) {\n Capa f = augment(zu[i], ink, min(flo, capa[i]));\n if (f > wEPS) { capa[i] -= f; capa[i ^ 1] += f; return f; }\n }\n ++see[src];\n }\n return 0;\n }\n bool dinic(int src, int ink, Capa flo = wINF) {\n for (tof = 0; tof + wEPS < flo; ) {\n int[] q;\n lev[] = -1;\n dinicBFS:\n for (lev[src] = 0, q ~= src; !q.empty; ) {\n int u = q.front; q.popFront;\n foreach (i; g[u]) {\n int v = zu[i];\n if (capa[i] > wEPS && lev[v] == -1) {\n lev[v] = lev[u] + 1; q ~= v;\n if (v == ink) break dinicBFS;\n }\n }\n }\n if (lev[ink] == -1) return false;\n see[] = 0;\n for (; ; ) {\n Capa f = augment(src, ink, flo - tof);\n if (f <= wEPS) break;\n tof += f;\n }\n }\n return true;\n }\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n }\n \n auto ws = new int[N];\n auto ls = new int[N];\n foreach (i; 0 .. M) {\n ++ws[U[i]];\n ++ls[V[i]];\n }\n auto dp = new int[][](N + 1, N * (N - 1) / 2 + 1);\n auto prev = new int[][](N + 1, N * (N - 1) / 2 + 1);\n foreach (u; 0 .. N + 1) {\n dp[u][] = -1;\n }\n dp[0][0] = 0;\n foreach (u; 0 .. N) {\n foreach (a; 0 .. N * (N - 1) / 2 + 1) {\n if (dp[u][a] >= 0) {\n foreach (x; ws[u] .. (N - 1 - ls[u]) + 1) {\n if (a + x <= N * (N - 1) / 2) {\n if (chmax(dp[u + 1][a + x], dp[u][a] + x * (N - 1 - x))) {\n prev[u + 1][a + x] = x;\n }\n }\n }\n }\n }\n }\n auto xs = new int[N];\n for (int u = N, a = N * (N - 1) / 2; u > 0; ) {\n const x = prev[u][a];\n --u;\n a -= x;\n xs[u] = x;\n }\n debug {\n writeln(\"xs = \", xs);\n }\n \n auto mf = new MaxFlow!int(2 + N + N);\n foreach (u; 0 .. N) {\n mf.addEdge(0, 2 + u, xs[u]);\n mf.addEdge(2 + N + u, 1, N - 1 - xs[u]);\n }\n auto ids = new int[][](N, N);\n foreach (u; 0 .. N) foreach (v; 0 .. N) {\n if (u != v) {\n ids[u][v] = mf.m;\n mf.addEdge(2 + u, 2 + N + v, 1);\n } else {\n ids[u][v] = -1;\n }\n }\n const res = mf.dinic(0, 1, N * (N - 1) / 2);\n assert(res);\n \n auto ans = new char[][](N, N);\n foreach (u; 0 .. N) {\n ans[u][] = '0';\n }\n foreach (u; 0 .. N) foreach (v; 0 .. N) {\n if (u != v) {\n if (mf.capa[ids[u][v]] == 0) {\n ans[u][v] = '1';\n }\n }\n }\n foreach (u; 0 .. N) {\n writeln(ans[u]);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "381d3bcba9093fb8957d25b66bb7df5c"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = RD!int-1;\n\t\tauto b = RD!int-1;\n\t\tauto c = RD!int-1;\n\t\tauto p = RDA;\n\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tauto u = RD!int-1;\n\t\t\tauto v = RD!int-1;\n\t\t\tedges[u] ~= v;\n\t\t\tedges[v] ~= u;\n\t\t}\n\n\t\tlong[] search(int s)\n\t\t{\n\t\t\tint[] open = [s];\n\t\t\tauto dist = new long[](n);\n\t\t\tdist[] = long.max;\n\t\t\tdist[s] = 0;\n\t\t\twhile (!open.empty)\n\t\t\t{\n\t\t\t\tauto from = open.front; open.popFront;\n\t\t\t\tauto d = dist[from]+1;\n\t\t\t\tforeach (to; edges[from])\n\t\t\t\t{\n\t\t\t\t\tif (d < dist[to])\n\t\t\t\t\t{\n\t\t\t\t\t\topen ~= to;\n\t\t\t\t\t\tdist[to] = d;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn dist;\n\t\t}\n\t\tauto dist_a = search(a);\n\t\tauto dist_b = search(b);\n\t\tauto dist_c = search(c);\n\t\t\n\t\tp.sort();\n\t\tauto pp = new long[](p.length+1);\n\t\tforeach (i; 0..p.length)\n\t\t{\n\t\t\tpp[i+1] = pp[i] + p[i];\n\t\t}\n\n\t\tans[ti] = long.max;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (dist_b[i]+dist_a[i]+dist_c[i] > p.length) continue;\n\t\t\tauto c1 = pp[cast(int)dist_b[i]];\n\t\t\tauto c2 = pp[cast(int)(dist_b[i]+dist_a[i])] - c1;\n\t\t\tauto c3 = pp[cast(int)(dist_b[i]+dist_a[i]+dist_c[i])] - (c1+c2);\n\t\t\tans[ti].chmin(c1*2+c2+c3);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\treadln;\n\tint n, m, a, b, c;\n\twhile (readf !(\" %s %s %s %s %s\") (n, m, a, b, c) > 0)\n\t{\n\t\ta -= 1;\n\t\tb -= 1;\n\t\tc -= 1;\n\t\treadln;\n\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tsort (p);\n\t\tauto s = [0L] ~ cumulativeFold !(q{a + b}) (p, 0L).array;\n\n\t\tauto adj = new int [] [n];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tadj[u] ~= v;\n\t\t\tadj[v] ~= u;\n\t\t}\n\n\t\tint [] bfs (int start)\n\t\t{\n\t\t\tauto d = new int [n];\n\t\t\td[] = int.max;\n\t\t\td[start] = 0;\n\t\t\tint [] q;\n\t\t\tq ~= start;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tauto v = q.front;\n\t\t\t\tq.popFront ();\n\t\t\t\tq.assumeSafeAppend ();\n\t\t\t\tforeach (u; adj[v])\n\t\t\t\t{\n\t\t\t\t\tif (d[u] == int.max)\n\t\t\t\t\t{\n\t\t\t\t\t\td[u] = d[v] + 1;\n\t\t\t\t\t\tq ~= u;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn d;\n\t\t}\n\n\t\tauto da = bfs (a);\n\t\tauto db = bfs (b);\n\t\tauto dc = bfs (c);\n\n\t\tlong res = long.max;\n\t\tforeach (u; 0..n)\n\t\t{\n\t\t\tauto common = db[u];\n\t\t\tauto total = da[u] + db[u] + dc[u];\n\t\t\tdebug {writeln (u + 1, \": \", common, \", \", total);}\n\t\t\tif (total <= m)\n\t\t\t{\n\t\t\t\tres = min (res, s[common] + s[total]);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "89be93cb82d9686ff099d156c309c146"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto T = RD!int;\r\n\tauto ans = new char[][](T);\r\n\tforeach (ti; 0..T)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tans[ti].length = n;\r\n\r\n\t\tint pos;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (s[i] == '?') continue;\r\n\t\t\tpos = i;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tforeach (i; pos..n)\r\n\t\t{\r\n\t\t\tif (s[i] != '?')\r\n\t\t\t\tans[ti][i] = s[i];\r\n\t\t\telse if (i == 0)\r\n\t\t\t{\r\n\t\t\t\tans[ti][i] = 'R';\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (ans[ti][i-1] == 'R')\r\n\t\t\t\t\tans[ti][i] = 'B';\r\n\t\t\t\telse\r\n\t\t\t\t\tans[ti][i] = 'R';\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach_reverse (i; 0..pos)\r\n\t\t{\r\n\t\t\tif (s[i] != '?')\r\n\t\t\t\tans[ti][i] = s[i];\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (ans[ti][i+1] == 'R')\r\n\t\t\t\t\tans[ti][i] = 'B';\r\n\t\t\t\telse\r\n\t\t\t\t\tans[ti][i] = 'R';\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "\nimmutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto s = readString;\n\tint prev = -1;\n\tchar[] ans = new char[](n);\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (s[i] != '?')\n\t\t{\n\t\t\tforeach_reverse(j; prev+1 .. i+1)\n\t\t\t{\n\t\t\t\tif (j%2 == i%2)\n\t\t\t\t\tans[j] = s[i];\n\t\t\t\telse\n\t\t\t\t\tans[j] = s[i] == 'R'? 'B' : 'R';\n\t\t\t}\n\t\t\tprev = i;\n\t\t}\n\t\telse\n\t\t{\n\t\t}\n\t}\n\tforeach(j; prev+1 .. n)\n\t{\n\t\tif ((prev+2)%2 == j%2)\n\t\t{\n\t\t\tans[j] = prev == -1? 'R' : s[prev];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[j] = prev == -1? 'B' : (s[prev] == 'R'? 'B' : 'R');\n\t\t}\n\t}\n\tans.writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [{"source_code": "\nimmutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto s = readString;\n\tint prev = -1;\n\tchar[] ans = new char[](n);\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (s[i] != '?')\n\t\t{\n\t\t\tforeach_reverse(j; prev+1 .. i+1)\n\t\t\t{\n\t\t\t\tif (j%2 == i%2)\n\t\t\t\t\tans[j] = s[i];\n\t\t\t\telse\n\t\t\t\t\tans[j] = s[i] == 'R'? 'B' : 'R';\n\t\t\t}\n\t\t\tprev = i;\n\t\t}\n\t\telse\n\t\t{\n\t\t}\n\t}\n\tforeach(j; prev+1 .. n)\n\t{\n\t\tif (prev%2 == j%2)\n\t\t{\n\t\t\tans[j] = prev == -1? 'R' : s[prev];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[j] = prev == -1? 'B' : (s[prev] == 'R'? 'B' : 'R');\n\t\t}\n\t}\n\tans.writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "280487a73e6070a7dc7deb44332d6319"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 1_000_000_007;\nimmutable int base = 10;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto n = s.length.to !(int);\n\t\tlong res = 0;\n\t\tlong cur = 1;\n\t\tlong add = 0;\n\t\tforeach (k; 0..n)\n\t\t{\n\t\t\tauto mult = ((n - k) * (n - k - 1L) / 2) % mod;\n\t\t\tmult = (mult * cur + add) % mod;\n\t\t\tres = (res + mult * (s[n - k - 1] - '0')) % mod;\n\t\t\tadd = (add + cur * (k + 1L)) % mod;\n\t\t\tcur = (cur * base) % mod;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nlong pmod(long a, long m)\n{\n if (a < 0) return (a % m) + m;\n return a % m;\n}\n\nvoid main(string[] args)\n{\n enum p = 1_000_000_000 + 7;\n auto n = next!string;\n auto tenpow = new long[](n.length);\n tenpow[n.length - 1] = 1;\n foreach_reverse(i; 0 .. n.length - 1)\n tenpow[i] = (tenpow[i + 1] * 10) % p;\n long rightNum = 0;\n foreach(d; n) rightNum = ((rightNum * 10) % p + long(d - '0')) % p;\n long leftSum = 0;\n long leftNum = 0;\n long res = 0;\n foreach(i; 0 .. n.length)\n {\n long li = cast(long)i;\n long dig = n[i] - '0';\n rightNum = pmod(rightNum - (dig * tenpow[i]) % p, p);\n \n res = (res%p + (rightNum * (li + 1))%p + (leftSum * tenpow[i])%p)%p;\n \n leftNum = ((leftNum * 10) % p + dig)%p; \n leftSum = (leftSum + leftNum) % p;\n }\n res.writeln;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!string;\n\t\n\tauto pat = new long[](n.length+1);\n\tforeach (i; 0..n.length)\n\t{\n\t\tpat[i+1] = pat[i];\n\t\tlong tmp = 10;\n\t\ttmp.modpow(i);\n\t\ttmp.modm(i+1);\n\t\tpat[i+1].moda(tmp);\n\t}\n\n\tlong ans;\n\tforeach (i; 0..n.length)\n\t{\n\t\t{\n\t\t\tlong num = n[i]-'0';\n\t\t\tlong left = i;\n\t\t\tleft *= (i+1);\n\t\t\tleft /= 2;\n\t\t\tleft %= mod;\n\t\t\tlong digit = 10;\n\t\t\tdigit.modpow(n.length-i-1);\n\t\t\tnum.modm(digit);\n\t\t\tleft.modm(num);\n\t\t\tans.moda(left);\n\t\t\tdebug writeln(\"i:\", i, \" ans:\", ans);\n\t\t}\n\t\t{\n\t\t\tlong num = n[i]-'0';\n\t\t\tnum.modm(pat[n.length-i-1]);\n\t\t\tans.moda(num);\n\t\t\tdebug writeln(\"i:\", i, \" ans:\", ans);\n\t\t}\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nconst ll PRIME = 10L^^9 + 7;\n\nvoid play(){\n dchar[] nummer;\n nummer = rd!(dchar[]);\n ll[] arr;\n foreach(c; nummer){\n arr ~= c-'0';\n }\n int n = arr.length.to!int;\n ll res = 0;\n // Ten-> Power of Ten, RevNN -> Reverse Natural Numbers\n ll tim = 0, ten = 1, revnn = 0;\n foreach_reverse(i; 0..n){\n // Add Before\n ll mul = ( ( 1L * i * (i + 1))/2L ) % PRIME;\n mul *= ten;\n mul %= PRIME;\n res += mul*arr[i];\n res %= PRIME;\n\n // Add After\n res += revnn * arr[i];\n res %= PRIME;\n\n // Remove Number Value\n\n show(ten, tim, mul*ten*arr[i], revnn);\n\n // Update Tim & Ten\n tim *= 10; tim += 1; tim %= PRIME;\n revnn *= 10; revnn += tim; revnn %= PRIME;\n ten *= 10; ten %= PRIME;\n\n }\n writeln(res);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nconst ll PRIME = 10L^^9 + 7;\n\nvoid play(){\n dchar[] nummer;\n nummer = rd!(dchar[]);\n ll[] arr;\n foreach(c; nummer){\n arr ~= c-'0';\n }\n int n = arr.length.to!int;\n ll res = 0;\n // Ten-> Power of Ten, RevNN -> Reverse Natural Numbers\n ll tim = 0, ten = 1, revnn = 0;\n foreach_reverse(i; 0..n){\n // Add Before\n ll mul = (i*(i+1))/2;\n mul %= PRIME;\n res += (mul*ten % PRIME)*arr[i];\n res %= PRIME;\n\n // Add After\n res += revnn * arr[i];\n res %= PRIME;\n\n // Remove Number Value\n\n show(ten, tim, mul*ten*arr[i], revnn);\n\n // Update Tim & Ten\n tim *= 10; tim += 1; tim %= PRIME;\n revnn *= 10; revnn += tim; revnn %= PRIME;\n ten *= 10; ten %= PRIME;\n\n }\n writeln(res);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!string;\n\t\n\tauto pat = new long[](n.length+1);\n\tforeach (i; 0..n.length)\n\t{\n\t\tpat[i+1] = pat[i];\n\t\tlong tmp = 10;\n\t\ttmp.modpow(i);\n\t\ttmp.modm(i+1);\n\t\tpat[i+1].moda(tmp);\n\t}\n\n\tlong ans;\n\tforeach (i; 0..n.length)\n\t{\n\t\t{\n\t\t\tlong num = n[i]-'0';\n\t\t\tlong left = i*(i+1)/2;\n\t\t\tlong digit = 10;\n\t\t\tdigit.modpow(n.length-i-1);\n\t\t\tnum.modm(digit);\n\t\t\tleft.modm(num);\n\t\t\tans.moda(left);\n\t\t\tdebug writeln(\"i:\", i, \" ans:\", ans);\n\t\t}\n\t\t{\n\t\t\tlong num = n[i]-'0';\n\t\t\tnum.modm(pat[n.length-i-1]);\n\t\t\tans.moda(num);\n\t\t\tdebug writeln(\"i:\", i, \" ans:\", ans);\n\t\t}\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "0ffa96d83e63d20bdfa2ecbf535adcdd"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\n\t\tlong x = n;\n\t\tfor (long i = 2; i*i <= n; ++i)\n\t\t{\n\t\t\tif (n % i == 0)\n\t\t\t{\n\t\t\t\tx = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[ti] = n + x + 2 * (k-1);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.algorithm;\n\nvoid main()\n{\n auto arr = iota(1100000).array;\n foreach (e, i; arr) {\n if (e != i || i < 2) continue; \n for (int j = i + i; j < arr.length; j += i) {\n arr[j] = min(arr[j], i);\n }\n }\n\n uint t, n, k;\n scanf(\"%d\", &t);\n while (t--) {\n scanf(\"%d%d\", &n, &k);\n if (k > 0 && n % 2 == 1) {\n k--;\n n += arr[n];\n }\n n += 2 * k;\n writef!\"%d\\n\"(n);\n }\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n auto ps = new long[](10^^6+1);\n foreach (i; 2..10^^6+1) if (ps[i] == 0) {\n ps[i] = i;\n auto x = i;\n while (x <= 10^^6) {\n if (ps[x] == 0) ps[x] = i;\n x += i;\n }\n }\n foreach (_t; 0..T) {\n auto nk = readln.split.to!(long[]);\n auto N = nk[0];\n auto K = nk[1];\n writeln(N + ps[N.to!size_t] + 2*(K-1));\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n auto ps = new long[](10^^6+1);\n foreach (i; 2..10^^6+1) if (ps[i] == 0) {\n ps[i] = i;\n auto x = i;\n while (x <= 10^^6) {\n ps[x] = i;\n x += i;\n }\n }\n foreach (_t; 0..T) {\n auto nk = readln.split.to!(long[]);\n auto N = nk[0];\n auto K = nk[1];\n writeln(N + ps[N.to!size_t] + 2*(K-1));\n }\n}"}], "src_uid": "9fd9bc0a037b2948d60ac2bd5d57740f"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!int).array;\n\n int p;\n int[] primes;\n int[] primes_n;\n foreach (i; 2..10^^5) {\n if (K % i == 0) {\n p += 1;\n primes ~= i;\n primes_n ~= 0;\n }\n while (K % i == 0) {\n K /= i;\n primes_n[p-1] += 1;\n }\n }\n if (K > 1) {\n p += 1;\n primes ~= K;\n primes_n ~= 1;\n }\n\n auto cumsum = new int[][](N+1, p);\n foreach (i; 0..N) {\n auto k = A[i];\n foreach (j; 0..p) {\n while (k % primes[j] == 0) {\n cumsum[i+1][j] += 1;\n k /= primes[j];\n }\n }\n }\n\n foreach (i; 0..N) {\n cumsum[i+1][] += cumsum[i][];\n }\n\n\n long ans = 0;\n auto cs = new int[](p);\n \n foreach (i; 0..N) {\n int hi = N;\n int lo = i - 1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n cs[] = cumsum[mid + 1][] - cumsum[i][];\n if (p.iota.map!(i => cs[i] >= primes_n[i]).all) hi = mid;\n else lo = mid;\n }\n ans += max(N - lo - 1, 0);\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.numeric;\nimport std.range;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n foreach(ref ai; a) ai %= k;\n auto st = SegmentTree!(long, (x, y) => (x * y) % k, \"mul\")(a);\n iota(0, n)\n .map!(i => cast(long)n - firstThat!(j => st.mul(i, j) == 0)(i, n - 1))\n .sum\n .writeln;\n}\n\n// BIN SEARCH\nauto firstThat(alias pred, T)(T i, T j)\n{\n T first = j + 1;\n while(i <= j)\n {\n auto mid = (i + j) / 2;\n if (pred(mid))\n\t{\n\t first = mid;\n\t j = mid - 1;\n\t}\n else\n\t{\n\t i = mid + 1;\n\t}\n }\n return first;\n}\n\n// Segment Tree\nstruct SegmentTree(T, alias f, string getMethodName = \"get\")\n{\n static assert(is(typeof((){T x, y; return f(x, y);}()) == T));\n class Node\n {\n size_t low, high;\n size_t length() {return high - low + 1;}\n this(size_t l, size_t h)\n {\n low = l;\n high = h;\n }\n T fValue;\n Node firstHalf, secondHalf;\n bool contains(size_t i, size_t j)\n {\n return max(low, i) <= min(high, j);\n }\n bool inside(size_t i, size_t j)\n {\n return i <= low && high <= j;\n }\n }\n Node _root;\n this(T[] arr)\n {\n _root = new Node(0, arr.length - 1);\n void fill(Node node)\n {\n if (node.length == 1) {node.fValue = arr[node.low]; return;}\n size_t mid = (node.low + node.high) / 2;\n node.firstHalf = new Node(node.low, mid);\n fill(node.firstHalf);\n node.secondHalf = new Node(mid + 1, node.high);\n fill(node.secondHalf);\n node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);\n }\n fill(_root);\n }\n mixin(q{alias }, getMethodName, q{ = fRange;});\n T fRange(size_t i, size_t j, Node node = null)\n {\n if (node is null) node = _root;\n debug assert(node !is null);\n debug assert(node.contains(i, j), text(node.low, \" \", node.high, \" \", i, \" \", j));\n if (node.inside(i, j)) return node.fValue;\n \n debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))\n\t\t || (node.secondHalf !is null && node.secondHalf.contains(i, j)));\n \n if (node.firstHalf !is null && node.firstHalf.contains(i, j))\n {\n\tif (node.secondHalf !is null && node.secondHalf.contains(i, j))\n\t return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));\n\treturn fRange(i, j, node.firstHalf);\n }\n else\n {\n\tdebug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));\n\treturn fRange(i, j, node.secondHalf);\n }\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nint n, k;\nint[] a;\n\nvoid main() {\n scan(n, k);\n a = readln.split.to!(int[]);\n\n if (k == 1) {\n writeln(1L * n * (n + 1) / 2L);\n return;\n }\n\n auto p = new int[](0);\n auto q = new int[](0);\n\n for (int d = 2; d*d <= k; d++) {\n if (k % d == 0) {\n p ~= d;\n int cnt = 0;\n\n while (k % d == 0) {\n cnt++;\n k /= d;\n }\n\n q ~= cnt;\n }\n }\n\n if (k > 1) {\n p ~= k;\n q ~= 1;\n }\n\n debug {\n writeln(\"p:\", p);\n writeln(\"q:\", q);\n }\n\n int m = p.length.to!int;\n\n auto div = new int[][](n, m);\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. m) {\n while (a[i] % p[j] == 0) {\n div[i][j]++;\n a[i] /= p[j];\n }\n }\n }\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", div);\n }\n\n auto cnt = new int[](m);\n long ans;\n\n for (int l, r; r < n + 1; l++) {\n for (; r < n + 1; r++) {\n if (iota(m).all!(i => cnt[i] >= q[i])) {\n ans += n + 1 - r;\n break;\n }\n else {\n if (r == n) {\n writeln(ans);\n return;\n }\n\n cnt[] += div[r][];\n }\n }\n\n cnt[] -= div[l][];\n }\n\n writeln(ans);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto k = next!int;\n auto a = next!long(n);\n foreach(ref ai; a) ai %= k;\n long mul(long a1, long a2)\n {\n return (a1 * a2) % k;\n }\n auto st = SegmentTree!(long, mul, \"mul\")(a);\n debug st.mul(0, 0).writeln;\n long ways = 0;\n foreach(i; 0 .. n)\n {\n bool divides(int j) {return st.mul(i, j) == 0;}\n auto end = firstThat!divides(i, n - 1);\n debug writeln(\"for \", i, \" is \", end);\n ways += n - end;\n }\n ways.writeln;\n}\n\n// BIN SEARCH\nauto firstThat(alias pred, T)(T i, T j)\n{\n T first = j + 1;\n while(i <= j)\n {\n debug writeln(i, \" \", j);\n auto mid = (i + j) / 2;\n if (pred(mid))\n\t{\n\t first = mid;\n\t j = mid - 1;\n\t}\n else\n\t{\n\t i = mid + 1;\n\t}\n }\n return first;\n}\n\n// Segment Tree\nstruct SegmentTree(T, alias f, string getMethodName = \"get\")\n{\n static assert(is(typeof((){T x, y; return f(x, y);}()) == T));\n class Node\n {\n size_t low, high;\n size_t length() {return high - low + 1;}\n this(size_t l, size_t h)\n {\n low = l;\n high = h;\n }\n T fValue;\n Node firstHalf, secondHalf;\n bool contains(size_t i, size_t j)\n {\n return max(low, i) <= min(high, j);\n }\n bool inside(size_t i, size_t j)\n {\n return i <= low && high <= j;\n }\n }\n Node _root;\n this(T[] arr)\n {\n _root = new Node(0, arr.length - 1);\n void fill(Node node)\n {\n if (node.length == 1) {node.fValue = arr[node.low]; return;}\n size_t mid = (node.low + node.high) / 2;\n node.firstHalf = new Node(node.low, mid);\n fill(node.firstHalf);\n node.secondHalf = new Node(mid + 1, node.high);\n fill(node.secondHalf);\n node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);\n }\n fill(_root);\n }\n mixin(q{alias }, getMethodName, q{ = fRange;});\n T fRange(size_t i, size_t j, Node node = null)\n {\n if (node is null) node = _root;\n debug assert(node !is null);\n debug assert(node.contains(i, j), text(node.low, \" \", node.high, \" \", i, \" \", j));\n if (node.inside(i, j)) return node.fValue;\n \n debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))\n\t\t || (node.secondHalf !is null && node.secondHalf.contains(i, j)));\n \n if (node.firstHalf !is null && node.firstHalf.contains(i, j))\n {\n\tif (node.secondHalf !is null && node.secondHalf.contains(i, j))\n\t return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));\n\treturn fRange(i, j, node.firstHalf);\n }\n else\n {\n\tdebug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));\n\treturn fRange(i, j, node.secondHalf);\n }\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!int).array;\n\n int p;\n int[] primes;\n int[] primes_n;\n foreach (i; 2..10^^5) {\n if (K % i == 0) {\n p += 1;\n primes ~= i;\n primes_n ~= 0;\n }\n while (K % i == 0) {\n K /= i;\n primes_n[p-1] += 1;\n }\n }\n\n auto cumsum = new int[][](N+1, p);\n foreach (i; 0..N) {\n auto k = A[i];\n foreach (j; 0..p) {\n while (k % primes[j] == 0) {\n cumsum[i+1][j] += 1;\n k /= primes[j];\n }\n }\n }\n\n foreach (i; 0..N) {\n cumsum[i+1][] += cumsum[i][];\n }\n\n\n long ans = 0;\n auto cs = new int[](p);\n \n foreach (i; 0..N) {\n int hi = N;\n int lo = i - 1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n cs[] = cumsum[mid + 1][] - cumsum[i][];\n if (p.iota.map!(i => cs[i] >= primes_n[i]).all) hi = mid;\n else lo = mid;\n }\n ans += max(N - lo - 1, 0);\n }\n\n ans.writeln;\n}\n"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nint n, k;\nlong[] a;\n\nvoid main() {\n scan(n, k);\n\n if (k == 1) {\n writeln(1L * n * (n + 1) / 2L);\n return;\n }\n\n a = readln.split.to!(long[]);\n\n auto sg = new SegTree!(long)(a, k);\n\n long ans;\n\n foreach (i ; 0 .. n) {\n if (sg.find(i, n, 0, 0, 2^^sg.depth) != 0) break;\n int btm = i, top = n, mid;\n\n while (top - btm > 1) {\n mid = (top + btm) / 2;\n\n if (sg.find(i, mid, 0, 0, 2^^sg.depth) == 0) {\n top = mid;\n }\n else {\n btm = mid;\n }\n }\n\n ans += n + 1 - top;\n }\n\n writeln(ans);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\nclass SegTree(T){\nprivate:\n T[] data;\n int N;\n long mod;\n int depth;\n \npublic:\n //int depth;\n \n this(T[] a, long k){\n N = a.length.to!int;\n mod = k;\n \n while(2^^depth < N){\n depth++;\n }\n \n data = new T[](2^^(depth + 1) - 1);\n \n data[] = 1L;\n data[2^^depth - 1 .. 2^^depth - 1 + N] = a[];\n \n foreach_reverse (i ; 0 .. 2^^depth - 1) {\n data[i] = 1L * data[2*i + 1] * data[2*i + 2] % mod;\n }\n }\n \n void update(int i, T x){\n i += 2^^depth - 1;\n data[i] = x;\n \n while(i > 0){\n i = (i - 1) / 2;\n data[i] = 1L * data[2*i + 1] * data[2*i + 2] % mod;\n }\n }\n \n T find(int s, int t, int k, int l, int r){\n if (r <= s || t <= l) {\n return 1L;\n }\n \n if (s <= l && r <= t) {\n return data[k];\n }\n \n auto vl = find(s, t, 2*k + 1, l, (l + r) / 2);\n auto vr = find(s, t, 2*k + 2, (l + r) / 2, r);\n \n return 1L * vl * vr % mod;\n }\n \n void print(){\n stderr.writefln(\"%(%s %)\", data);\n }\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.numeric;\nimport std.range;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto k = next!int;\n auto a = next!long(n);\n foreach(ref ai; a) ai %= k;\n auto st = SegmentTree!(long, (x, y) => (x * y) % k, \"mul\")(a);\n iota(0, n)\n .map!(i => n - firstThat!(j => st.mul(i, j) == 0)(i, n - 1))\n .sum\n .writeln;\n}\n\n// BIN SEARCH\nauto firstThat(alias pred, T)(T i, T j)\n{\n T first = j + 1;\n while(i <= j)\n {\n auto mid = (i + j) / 2;\n if (pred(mid))\n\t{\n\t first = mid;\n\t j = mid - 1;\n\t}\n else\n\t{\n\t i = mid + 1;\n\t}\n }\n return first;\n}\n\n// Segment Tree\nstruct SegmentTree(T, alias f, string getMethodName = \"get\")\n{\n static assert(is(typeof((){T x, y; return f(x, y);}()) == T));\n class Node\n {\n size_t low, high;\n size_t length() {return high - low + 1;}\n this(size_t l, size_t h)\n {\n low = l;\n high = h;\n }\n T fValue;\n Node firstHalf, secondHalf;\n bool contains(size_t i, size_t j)\n {\n return max(low, i) <= min(high, j);\n }\n bool inside(size_t i, size_t j)\n {\n return i <= low && high <= j;\n }\n }\n Node _root;\n this(T[] arr)\n {\n _root = new Node(0, arr.length - 1);\n void fill(Node node)\n {\n if (node.length == 1) {node.fValue = arr[node.low]; return;}\n size_t mid = (node.low + node.high) / 2;\n node.firstHalf = new Node(node.low, mid);\n fill(node.firstHalf);\n node.secondHalf = new Node(mid + 1, node.high);\n fill(node.secondHalf);\n node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);\n }\n fill(_root);\n }\n mixin(q{alias }, getMethodName, q{ = fRange;});\n T fRange(size_t i, size_t j, Node node = null)\n {\n if (node is null) node = _root;\n debug assert(node !is null);\n debug assert(node.contains(i, j), text(node.low, \" \", node.high, \" \", i, \" \", j));\n if (node.inside(i, j)) return node.fValue;\n \n debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))\n\t\t || (node.secondHalf !is null && node.secondHalf.contains(i, j)));\n \n if (node.firstHalf !is null && node.firstHalf.contains(i, j))\n {\n\tif (node.secondHalf !is null && node.secondHalf.contains(i, j))\n\t return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));\n\treturn fRange(i, j, node.firstHalf);\n }\n else\n {\n\tdebug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));\n\treturn fRange(i, j, node.secondHalf);\n }\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.numeric;\nimport std.range;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto k = next!long;\n auto a = next!long(n);\n foreach(ref ai; a) ai %= k;\n auto st = SegmentTree!(long, (x, y) => (x * y) % k, \"mul\")(a);\n iota(0, n)\n .map!(i => n - firstThat!(j => st.mul(i, j) == 0)(i, n - 1))\n .sum\n .writeln;\n}\n\n// BIN SEARCH\nauto firstThat(alias pred, T)(T i, T j)\n{\n T first = j + 1;\n while(i <= j)\n {\n auto mid = (i + j) / 2;\n if (pred(mid))\n\t{\n\t first = mid;\n\t j = mid - 1;\n\t}\n else\n\t{\n\t i = mid + 1;\n\t}\n }\n return first;\n}\n\n// Segment Tree\nstruct SegmentTree(T, alias f, string getMethodName = \"get\")\n{\n static assert(is(typeof((){T x, y; return f(x, y);}()) == T));\n class Node\n {\n size_t low, high;\n size_t length() {return high - low + 1;}\n this(size_t l, size_t h)\n {\n low = l;\n high = h;\n }\n T fValue;\n Node firstHalf, secondHalf;\n bool contains(size_t i, size_t j)\n {\n return max(low, i) <= min(high, j);\n }\n bool inside(size_t i, size_t j)\n {\n return i <= low && high <= j;\n }\n }\n Node _root;\n this(T[] arr)\n {\n _root = new Node(0, arr.length - 1);\n void fill(Node node)\n {\n if (node.length == 1) {node.fValue = arr[node.low]; return;}\n size_t mid = (node.low + node.high) / 2;\n node.firstHalf = new Node(node.low, mid);\n fill(node.firstHalf);\n node.secondHalf = new Node(mid + 1, node.high);\n fill(node.secondHalf);\n node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);\n }\n fill(_root);\n }\n mixin(q{alias }, getMethodName, q{ = fRange;});\n T fRange(size_t i, size_t j, Node node = null)\n {\n if (node is null) node = _root;\n debug assert(node !is null);\n debug assert(node.contains(i, j), text(node.low, \" \", node.high, \" \", i, \" \", j));\n if (node.inside(i, j)) return node.fValue;\n \n debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))\n\t\t || (node.secondHalf !is null && node.secondHalf.contains(i, j)));\n \n if (node.firstHalf !is null && node.firstHalf.contains(i, j))\n {\n\tif (node.secondHalf !is null && node.secondHalf.contains(i, j))\n\t return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));\n\treturn fRange(i, j, node.firstHalf);\n }\n else\n {\n\tdebug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));\n\treturn fRange(i, j, node.secondHalf);\n }\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto k = next!int;\n auto a = next!int(n);\n foreach(ref ai; a) ai %= k;\n int mul(int a1, int a2)\n {\n return (a1 * a2) % k;\n }\n auto st = SegmentTree!(int, mul, \"mul\")(a);\n debug st.mul(0, 0).writeln;\n long ways = 0;\n foreach(i; 0 .. n)\n {\n bool divides(int j) {return st.mul(i, j) == 0;}\n auto end = firstThat!divides(i, n - 1);\n debug writeln(\"for \", i, \" is \", end);\n ways += n - end;\n }\n ways.writeln;\n}\n\n// BIN SEARCH\nauto firstThat(alias pred, T)(T i, T j)\n{\n T first = j + 1;\n while(i <= j)\n {\n debug writeln(i, \" \", j);\n auto mid = (i + j) / 2;\n if (pred(mid))\n\t{\n\t first = mid;\n\t j = mid - 1;\n\t}\n else\n\t{\n\t i = mid + 1;\n\t}\n }\n return first;\n}\n\n// Segment Tree\nstruct SegmentTree(T, alias f, string getMethodName = \"get\")\n{\n static assert(is(typeof((){T x, y; return f(x, y);}()) == T));\n class Node\n {\n size_t low, high;\n size_t length() {return high - low + 1;}\n this(size_t l, size_t h)\n {\n low = l;\n high = h;\n }\n T fValue;\n Node firstHalf, secondHalf;\n bool contains(size_t i, size_t j)\n {\n return max(low, i) <= min(high, j);\n }\n bool inside(size_t i, size_t j)\n {\n return i <= low && high <= j;\n }\n }\n Node _root;\n this(T[] arr)\n {\n _root = new Node(0, arr.length - 1);\n void fill(Node node)\n {\n if (node.length == 1) {node.fValue = arr[node.low]; return;}\n size_t mid = (node.low + node.high) / 2;\n node.firstHalf = new Node(node.low, mid);\n fill(node.firstHalf);\n node.secondHalf = new Node(mid + 1, node.high);\n fill(node.secondHalf);\n node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);\n }\n fill(_root);\n }\n mixin(q{alias }, getMethodName, q{ = fRange;});\n T fRange(size_t i, size_t j, Node node = null)\n {\n if (node is null) node = _root;\n debug assert(node !is null);\n debug assert(node.contains(i, j), text(node.low, \" \", node.high, \" \", i, \" \", j));\n if (node.inside(i, j)) return node.fValue;\n \n debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))\n\t\t || (node.secondHalf !is null && node.secondHalf.contains(i, j)));\n \n if (node.firstHalf !is null && node.firstHalf.contains(i, j))\n {\n\tif (node.secondHalf !is null && node.secondHalf.contains(i, j))\n\t return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));\n\treturn fRange(i, j, node.firstHalf);\n }\n else\n {\n\tdebug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));\n\treturn fRange(i, j, node.secondHalf);\n }\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "src_uid": "f4d6c39a8224fb1fdb1cda63636f7f8e"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.exception;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s \", &n, &m) > 0)\n\t{\n\t\tauto a = new string [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] = readln ().strip ();\n\t\t}\n\n\t\tauto b = new int [] [] (m, n);\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tb[j][i] = a[i][j] - '0';\n\t\t\t}\n\t\t}\n \n\t\tint res = 0;\n\t\tauto c = new int [m + 1];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (b[j][i] != 0)\n\t\t\t\t{\n\t\t\t\t\tif (j > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tb[j][i] = b[j - 1][i] + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tc[] = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tc[b[j][i]]++;\n\t\t\t}\n\t\t\t\n\t\t\tint w;\n\t\t\tint h = 0;\n\t\t\tforeach_reverse (k; 0..m + 1)\n\t\t\t{\n\t\t\t\tforeach (q; 0..c[k])\n\t\t\t\t{\n\t\t\t\t\tw = k;\n\t\t\t\t\th++;\n\t\t\t\t\tdebug {writeln (w, ' ', h);}\n\t\t\t\t\tres = max (res, w * h);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\n\nvoid solve(int n, int m, char[][] mat)\n{\n auto cnt = new int[m + 1];\n auto len = new int[n];\n auto prelen = new int[n];\n int ans = 0;\n foreach (i; 0 .. m)\n {\n int[] modify;\n foreach (j; 0 .. n)\n {\n len[j] = 0;\n if (mat[j][i] == '1')\n {\n if (prelen[j])\n {\n len[j] = prelen[j] + 1;\n }\n else\n {\n len[j] = 1;\n }\n }\n if (!cnt[len[j]]) modify ~= len[j];\n ++ cnt[len[j]];\n }\n int count = 0;\n for (int j = i + 1; j > 0; -- j)\n {\n if (cnt[j])\n {\n count += cnt[j];\n if (j * count > ans) ans = j * count;\n }\n }\n foreach (val; modify) cnt[val] = 0;\n foreach (j; 0 .. n) prelen[j] = len[j]; \n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d%d\", &n, &m) == 2)\n {\n auto mat = new char[][n];\n stdin.readln(mat[0]);\n foreach (i; 0 .. n) stdin.readln(mat[i]);\n solve(n, m, mat);\n }\n}\n"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int n, int m, char[][] mat)\n{\n auto cnt = new int[m + 1];\n auto len = new int[n];\n auto prelen = new int[n];\n int ans = 0;\n foreach (i; 0 .. m)\n {\n //int[] modify;\n foreach (j; 0 .. n)\n {\n len[j] = 0;\n if (mat[j][i] == '1')\n {\n if (prelen[j])\n {\n len[j] = prelen[j] + 1;\n }\n else\n {\n len[j] = 1;\n }\n }\n //if (!cnt[len[j]]) modify ~= len[j];\n ++ cnt[len[j]];\n }\n int count = 0;\n for (int j = i + 1; j > 0; -- j)\n {\n if (cnt[j])\n {\n count += cnt[j];\n if (j * count > ans) ans = j * count;\n }\n }\n fill(cnt, 0);\n //foreach (val; modify) cnt[val] = 0;\n foreach (j; 0 .. n) prelen[j] = len[j]; \n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d%d\", &n, &m) == 2)\n {\n auto mat = new char[][n];\n stdin.readln(mat[0]);\n foreach (i; 0 .. n) stdin.readln(mat[i]);\n solve(n, m, mat);\n }\n}\n"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int n, int m, char[][] mat)\n{\n auto cnt = new int[m + 1];\n auto len = new int[n];\n auto prelen = new int[n];\n auto modify = new int[m + 1];\n int ans = 0;\n foreach (i; 0 .. m)\n {\n //int[] modify;\n int midx = 0;\n foreach (j; 0 .. n)\n {\n len[j] = 0;\n if (mat[j][i] == '1')\n {\n len[j] = 1;\n if (prelen[j])\n {\n len[j] += prelen[j];\n }\n }\n if (!cnt[len[j]]) modify[midx ++] = len[j];\n ++ cnt[len[j]];\n }\n int count = 0;\n for (int j = i + 1; j > 0; -- j)\n {\n if (cnt[j])\n {\n count += cnt[j];\n if (j * count > ans) ans = j * count;\n }\n }\n //fill(cnt, 0);\n for (int j = 0; j < midx; ++ j) cnt[modify[j]] = 0;\n //foreach (val; modify) cnt[val] = 0;\n foreach (j; 0 .. n) prelen[j] = len[j]; \n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n, m;\n while (scanf(\"%d%d\", &n, &m) == 2)\n {\n auto mat = new char[][n];\n stdin.readln(mat[0]);\n foreach (i; 0 .. n) stdin.readln(mat[i]);\n solve(n, m, mat);\n }\n}\n"}], "negative_code": [], "src_uid": "0accc8b26d7d684aa6e60e58545914a8"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n foreach(_; 0..QN) {\r\n auto N = scan!int;\r\n auto A = scan!long(N);\r\n \r\n (A.maxElement - A.minElement).writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!long).array;\n writeln(a.maxElement - a.minElement);\n }\n}\n"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n readln();\n const pair =\n readln.chomp\n .split(' ')\n .map!(str => to!int(str))\n .fold!(min, max);\n\n writeln(pair[1] - pair[0]);\n }\n}\n// \"\"\n"}], "negative_code": [], "src_uid": "cf3cfcae029a6997ee62701eda959a60"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto P = readarray!int;\r\n foreach (ref p; P) p--;\r\n auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1];\r\n G[p] ~= i;\r\n }\r\n auto C = readarray!long;\r\n\r\n long[Tuple!(int,int)] cache;\r\n long f(int v, int m) {\r\n if (G[v].empty) {\r\n return C[v] * m;\r\n } else {\r\n long r = C[v] * m;\r\n auto key = tuple(v, m);\r\n if (key in cache) return cache[key];\r\n int a = m / (G[v].length);\r\n int rem = m - a * G[v].length;\r\n auto xs = G[v].map!(u => f(u, a)).array;\r\n long sx = xs.reduce!\"a+b\";\r\n if (rem > 0) {\r\n auto ys = G[v].map!(u => f(u, a+1)).array;\r\n auto ds = iota(G[v].length).array.map!(i => ys[i] - xs[i]).array.sort!\"a > b\".array;\r\n long add = 0;\r\n for (int j = 0; j < rem; j++) {\r\n add += ds[j];\r\n }\r\n r += sx + add;\r\n return cache[key] = r;\r\n } else {\r\n r += sx;\r\n return cache[key] = r;\r\n }\r\n }\r\n }\r\n writeln(f(0, K));\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nlong K;\nint[] P;\nlong[] S;\n\nint[][] graph;\n\nint[] lens;\nlong[3][] kss, fss;\nlong solve(int u, long k) {\n foreach (j; 0 .. lens[u]) {\n if (kss[u][j] == k) {\n return fss[u][j];\n }\n }\n \n long ret = S[u] * k;\n const deg = cast(int)(graph[u].length);\n if (deg) {\n const q = k / deg;\n const r = k % deg;\n auto ds = new long[deg];\n foreach (j; 0 .. deg) {\n const v = graph[u][j];\n const res0 = solve(v, q);\n ret += res0;\n if (r) {\n const res1 = solve(v, q + 1);\n ds[j] = res1 - res0;\n }\n }\n ds.sort;\n ret += ds[deg - cast(int)(r) .. deg].sum;\n }\n \n assert(lens[u] < 3);\n kss[u][lens[u]] = k;\n fss[u][lens[u]] = ret;\n ++lens[u];\n return ret;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n N = readInt;\n K = readLong;\n P = new int[N];\n P[0] = -1;\n foreach (u; 1 .. N) {\n P[u] = readInt - 1;\n }\n S = new long[N];\n foreach (u; 0 .. N) {\n S[u] = readLong;\n }\n \n graph = new int[][N];\n foreach (u; 1 .. N) {\n graph[P[u]] ~= u;\n }\n \n lens = new int[N];\n kss = new long[3][N];\n fss = new long[3][N];\n const ans = solve(0, K);\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto p = [0] ~ readln.splitter.map !(to !(int)).array;\r\n\t\tp[] -= 1;\r\n\t\tauto s = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tauto adj = new int [] [n];\r\n\t\tauto d = new int [n];\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tadj[p[i]] ~= i;\r\n\t\t\td[p[i]] += 1;\r\n\t\t}\r\n\r\n\t\talias Pair = Tuple !(int, q{v}, int, q{num});\r\n\t\tlong [Pair] mem;\r\n\r\n\t\tlong recur (int v, int num)\r\n\t\t{\r\n\t\t\tauto coord = Pair (v, num);\r\n\t\t\tif (coord !in mem)\r\n\t\t\t{\r\n\t\t\t\tlong res = s[v] * 1L * num;\r\n\t\t\t\tif (d[v] > 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tint lo = num / d[v];\r\n\t\t\t\t\tint hi = (num + d[v] - 1) / d[v];\r\n\t\t\t\t\tlong [] vLo;\r\n\t\t\t\t\tlong [] vHi;\r\n\t\t\t\t\tforeach (u; adj[v])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvLo ~= recur (u, lo);\r\n\t\t\t\t\t\tvHi ~= recur (u, hi);\r\n\t\t\t\t\t\tres += vLo.back;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tauto p = d[v].iota.array;\r\n\t\t\t\t\tp.schwartzSort !(i => vHi[i] - vLo[i],\r\n\t\t\t\t\t q{a > b}, SwapStrategy.stable);\r\n\t\t\t\t\tint rem = num % d[v];\r\n\t\t\t\t\tforeach (i; p[0..rem])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tres += (vHi[i] - vLo[i]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tmem[coord] = res;\r\n\t\t\t}\r\n\t\t\treturn mem[coord];\r\n\t\t}\r\n\r\n\t\twriteln (recur (0, k));\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "9089fb2547751ca140a65f03fe78c916"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint root(int[] uf, int u) {\n\treturn (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool conn(int[] uf, int u, int v) {\n\tu = uf.root(u);\n\tv = uf.root(v);\n\tif (u == v) return 0;\n\tif (uf[u] > uf[v]) swap(u, v);\n\tuf[u] += uf[v];\n\tuf[v] = u;\n\treturn 1;\n}\n\nint N, M;\nint[] A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tM = readInt;\n\t\tA = new int[M];\n\t\tB = new int[M];\n\t\tforeach (i; 0 .. M) {\n\t\t\tA[i] = readInt - 1;\n\t\t\tB[i] = readInt - 1;\n\t\t}\n\t\t\n\t\tint[] uf = new int[N];\n\t\tuf[] = -1;\n\t\tforeach (i; 0 .. M) {\n\t\t\tuf.conn(A[i], B[i]);\n\t\t}\n\t\t\n\t\tlong ans = 1;\n\t\tforeach (u; 0 .. N) {\n\t\t\tif (!(uf[u] < 0)) {\n\t\t\t\tans *= 2;\n\t\t\t}\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n bool[][] G = new bool[][](N + 1, N + 1);\n foreach (ref L; G) L[] = false;\n foreach (i; 0 .. M) {\n int x, y; scanf(\"%d %d\\n\", &x, &y);\n G[x][y] = G[y][x] = true;\n }\n\n // \u9023\u7d50\u30b0\u30e9\u30d5\u306e\u500b\u6570\n int Count() {\n int Ret = 0;\n bool[] used = new bool[N + 1];\n\n void dfs(int x) {\n used[x] = true;\n for (int i = 1; i <= N; i++) {\n if (!used[i] && G[x][i]) {\n dfs(i);\n }\n }\n }\n\n for (int i = 1; i <= N; i++) {\n if (!used[i]) {\n dfs(i);\n Ret++;\n }\n }\n return Ret;\n }\n\n writeln( 1L << (N - Count()) );\n}\n"}, {"source_code": "import std.stdio;\nimport std.BigInt;\n\nvoid main()\n{\n int ctl;\n readf(\"%s\",&ctl);\n if(ctl == -1){\n run_tests();\n } else{\n run_instance(ctl);\n }\n\n}\n\n// void debug(T...)(T args){\n//\n// }\n// int DEBUG = false;\n//\n// void debug(){\n// if(DEBUG){\n//\n// }\n// }\n\n\nvoid run_instance(int ctl){\n int n = ctl;\n int m; readf(\" %s\\n\",&m);\n auto graph = new G(n);\n\n for(int i = 0; i < m; i++){\n int s; readf(\"%s \",&s);\n int d; readf(\"%s \",&d);\n graph.add_vertex(s,d);\n }\n\n BigInt r = calculate(n,m,graph);\n writefln(\"%s\",r);\n}\n\nBigInt calculate(int n, int m, G graph){\n int c = graph.components();\n BigInt r = 1;\n for(long i = 0; i < n-c; i++){\n r = r * 2;\n }\n return r;\n}\n\nvoid run_tests(){\n int[][] rs;\n // rs ~= [[calculate(1,0,new G(1,[])),1]];\n // rs ~= [[calculate(2,1,new G(2,[1,2])),2]];\n // rs ~= [[calculate(3,2,new G(3,[1,2,2,3])),4]];\n // rs ~= [[calculate(10,10,new G(10,[1,8,4,10,4,6,5,10,2,3,1,7,3,4,3,6,6,9,3,7])),512]];\n // rs ~= [[calculate(20,20,new G(20,[6,8,13,20,7,13,6,17,5,15,1,12,5,5,17,5,14,6,14,12,20,7,20,1,6,1,7,2,19,14,17,1,10,11,15,9,18,2,12])),32768]];\n // rs ~= [[calculate(40,40,new G(40,[40,40,28,33,15,21,12,29,14,31,2,26,3,12,25,34,6,30,6,25,5,28,9,17,23,29,30,36,3,21,35,37,7,25,29,39,15,19,12,35,24,34,15,25,19,33,26,31,7,29,1,40,11,27,6,9,6,27,36,39,10,14,6,16,23,25,2,38,3,24,30,31,29,30,4,12,11,13,14,40,22,39])),34359738368]];\n\n int i = 0;\n bool failed = false;\n foreach(int[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n writefln(\"%s Failed %s is NOT %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n\nclass G{\n int[][] vertex;\n int[] visited;\n int v_count = 0;\n\n this(int v_count){\n //writefln(\"NEW %s\",v_count);\n for (int i = 0; i< v_count; i++){\n this.vertex ~= [[]];\n this.visited ~= 0;\n }\n this.v_count = v_count;\n }\n\n this(int n, int[] list){\n this(n);\n for (int i = 1; i < list.length; i += 2){\n this.add_vertex(list[i-1],list[i]);\n }\n }\n\n int[] conn(int v){\n return this.vertex[v];\n }\n\n void add_vertex(int s,int d){\n //writefln(\"%s-%s\",s-1,d-1);\n vertex[s-1] ~= [d-1];\n vertex[d-1] ~= [s-1];\n }\n\n int components(){\n int cmp = 0;\n int[] q;\n\n int cur = 0;\n //writefln(\"%s\",this.v_count);\n for(int v = 0; v < this.v_count; v++){\n if(this.visited[v] == 0){\n //writefln(\"*Visited %s (%s)\",v,this.vertex[v]);\n this.visited[v] = 1;\n cmp++;\n q ~= this.vertex[v];\n\n while(q.length > cur){\n int vv = q[cur];\n cur++;\n if ( this.visited[vv] == 0 ){\n //writefln(\"Visited %s (%s)\",vv,this.vertex[vv]);\n this.visited[vv] = 1;\n q ~= this.vertex[vv];\n }\n }\n } else {\n //writefln(\"*NOT %s\",v,this.vertex[v]);\n }\n }\n\n return cmp;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n bool[][] G = new bool[][](N + 1, N + 1);\n foreach (ref L; G) L[] = false;\n foreach (i; 0 .. M) {\n int x, y; scanf(\"%d %d\\n\", &x, &y);\n G[x][y] = G[y][x] = true;\n }\n\n // \u9023\u7d50\u30b0\u30e9\u30d5\u306e\u500b\u6570\n int Count() {\n int Ret = 0;\n bool[] used = new bool[N + 1];\n\n void dfs(int x) {\n used[x] = true;\n for (int i = 1; i <= N; i++) {\n if (!used[i]) {\n dfs(i);\n }\n }\n }\n\n for (int i = 1; i <= N; i++) {\n if (!used[i]) {\n dfs(i);\n Ret++;\n }\n }\n return Ret;\n }\n\n writeln( 1L << (N - Count()) );\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int ctl;\n readf(\"%s\",&ctl);\n if(ctl == -1){\n run_tests();\n } else{\n run_instance(ctl);\n }\n\n}\n\n// void debug(T...)(T args){\n//\n// }\n// int DEBUG = false;\n//\n// void debug(){\n// if(DEBUG){\n//\n// }\n// }\n\n\nvoid run_instance(int ctl){\n int n = ctl;\n int m; readf(\" %s\\n\",&m);\n auto graph = new G(n);\n\n for(int i = 0; i < m; i++){\n int s; readf(\"%s \",&s);\n int d; readf(\"%s \",&d);\n graph.add_vertex(s,d);\n }\n\n int r = calculate(n,m,graph);\n writefln(\"%s\",r);\n}\n\nint calculate(int n, int m, G graph){\n int c = graph.components();\n int x = std.math.pow(2,n-c);\n //writefln(\"CX %s\",c);\n return x;\n}\n\nvoid run_tests(){\n int[][] rs;\n rs ~= [[calculate(1,0,new G(1,[])),1]];\n rs ~= [[calculate(2,1,new G(2,[1,2])),2]];\n rs ~= [[calculate(3,2,new G(3,[1,2,2,3])),4]];\n rs ~= [[calculate(10,10,new G(10,[1,8,4,10,4,6,5,10,2,3,1,7,3,4,3,6,6,9,3,7])),128]];\n rs ~= [[calculate(10,10,new G(10,[])),1]];\n\n int i = 0;\n bool failed = false;\n foreach(int[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n //writefln(\"%s Failed %s != %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n\nclass G{\n int[][] vertex;\n int[] visited;\n ulong v_count = 0;\n\n this(int v_count){\n //writefln(\"NEW %s\",v_count);\n for (int i = 0; i< v_count; i++){\n this.vertex ~= [[]];\n this.visited ~= 0;\n }\n this.v_count = v_count;\n }\n\n this(int n, int[] list){\n this(n);\n for (int i = 1; i < list.length; i += 2){\n this.add_vertex(list[i-1],list[i]);\n }\n }\n\n int[] conn(int v){\n return this.vertex[v];\n }\n\n void add_vertex(int s,int d){\n //writefln(\"%s-%s\",s,d);\n vertex[s-1] ~= [d-1];\n }\n\n int components(){\n int cmp = 0;\n int[] q;\n\n int cur = 0;\n for(int v = 0; v < this.v_count; v++){\n if(this.visited[v] == 0){\n //writefln(\"*Visited %s (%s)\",v+1,this.vertex[v].length);\n this.visited[v] = 1;\n cmp++;\n q ~= this.vertex[v];\n\n while(q.length > cur){\n v = q[cur];\n cur++;\n if ( this.visited[v] == 0 ){\n //writefln(\"Visited %s (%s)\",v+1,this.vertex[v].length);\n this.visited[v] = 1;\n q ~= this.vertex[v];\n }\n }\n }\n }\n\n return cmp;\n }\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int ctl;\n readf(\"%s\",&ctl);\n if(ctl == -1){\n run_tests();\n } else{\n run_instance(ctl);\n }\n\n}\n\n// void debug(T...)(T args){\n//\n// }\n// int DEBUG = false;\n//\n// void debug(){\n// if(DEBUG){\n//\n// }\n// }\n\n\nvoid run_instance(int ctl){\n int n = ctl;\n int m; readf(\" %s\\n\",&m);\n auto graph = new G(n);\n\n for(int i = 0; i < m; i++){\n int s; readf(\"%s \",&s);\n int d; readf(\"%s \",&d);\n graph.add_vertex(s,d);\n }\n\n int r = calculate(n,m,graph);\n writefln(\"%s\",r);\n}\n\nint calculate(int n, int m, G graph){\n int c = graph.components();\n int x = std.math.pow(2,n-c);\n //writefln(\"CX %s\",c);\n return x;\n}\n\nvoid run_tests(){\n int[][] rs;\n rs ~= [[calculate(1,0,new G(1,[])),1]];\n rs ~= [[calculate(2,1,new G(2,[1,2])),2]];\n rs ~= [[calculate(3,2,new G(3,[1,2,2,3])),4]];\n rs ~= [[calculate(10,10,new G(10,[1,8,4,10,4,6,5,10,2,3,1,7,3,4,3,6,6,9,3,7])),512]];\n rs ~= [[calculate(10,10,new G(10,[])),1]];\n\n int i = 0;\n bool failed = false;\n foreach(int[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n writefln(\"%s Failed %s != %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n\nclass G{\n int[][] vertex;\n int[] visited;\n ulong v_count = 0;\n\n this(int v_count){\n //writefln(\"NEW %s\",v_count);\n for (int i = 0; i< v_count; i++){\n this.vertex ~= [[]];\n this.visited ~= 0;\n }\n this.v_count = v_count;\n }\n\n this(int n, int[] list){\n this(n);\n for (int i = 1; i < list.length; i += 2){\n this.add_vertex(list[i-1],list[i]);\n }\n }\n\n int[] conn(int v){\n return this.vertex[v];\n }\n\n void add_vertex(int s,int d){\n //writefln(\"%s-%s\",s,d);\n vertex[s-1] ~= [d-1];\n vertex[d-1] ~= [s-1];\n }\n\n int components(){\n int cmp = 0;\n int[] q;\n\n int cur = 0;\n for(int v = 0; v < this.v_count; v++){\n if(this.visited[v] == 0){\n //writefln(\"*Visited %s (%s)\",v+1,this.vertex[v].length);\n this.visited[v] = 1;\n cmp++;\n q ~= this.vertex[v];\n\n while(q.length > cur){\n v = q[cur];\n cur++;\n if ( this.visited[v] == 0 ){\n //writefln(\"Visited %s (%s)\",v+1,this.vertex[v].length);\n this.visited[v] = 1;\n q ~= this.vertex[v];\n }\n }\n }\n }\n\n return cmp;\n }\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int ctl;\n readf(\"%s\",&ctl);\n if(ctl == -1){\n run_tests();\n } else{\n run_instance(ctl);\n }\n\n}\n\n// void debug(T...)(T args){\n//\n// }\n// int DEBUG = false;\n//\n// void debug(){\n// if(DEBUG){\n//\n// }\n// }\n\n\nvoid run_instance(int ctl){\n int n = ctl;\n int m; readf(\" %s\\n\",&m);\n auto graph = new G(n);\n\n for(int i = 0; i < m; i++){\n int s; readf(\"%s \",&s);\n int d; readf(\"%s \",&d);\n graph.add_vertex(s,d);\n }\n\n int r = calculate(n,m,graph);\n writefln(\"%s\",r);\n}\n\nint calculate(int n, int m, G graph){\n int c = graph.components();\n int x = std.math.pow(2,n-c);\n //writefln(\"CX %s\",c);\n return x;\n}\n\nvoid run_tests(){\n int[][] rs;\n rs ~= [[calculate(1,0,new G(1,[])),1]];\n rs ~= [[calculate(2,1,new G(2,[1,2])),2]];\n rs ~= [[calculate(3,2,new G(3,[1,2,2,3])),4]];\n rs ~= [[calculate(10,10,new G(10,[1,8,4,10,4,6,5,10,2,3,1,7,3,4,3,6,6,9,3,7])),512]];\n rs ~= [[calculate(20,20,new G(20,[6,8,13,20,7,13,6,17,5,15,1,12,5,5,17,5,14,6,14,12,20,7,20,1,6,1,7,2,19,14,17,1,10,11,15,9,18,2,12])),32768]];\n rs ~= [[calculate(30,30,new G(30,[30,30,7,28,16,26,14,24,16,18,20,29,4,28,19,21,8,26,1,25,14,22,13,23,4,15,15,16,2,19,29,30,12,20,3,4,3,26,3,11,22,27,5,16,2,24,2,18,7,16,17,21,17,25,8,15,23,27,12,21,5,30])),67108864]];\n\n int i = 0;\n bool failed = false;\n foreach(int[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n writefln(\"%s Failed %s is NOT %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n\nclass G{\n int[][] vertex;\n int[] visited;\n ulong v_count = 0;\n\n this(int v_count){\n //writefln(\"NEW %s\",v_count);\n for (int i = 0; i< v_count; i++){\n this.vertex ~= [[]];\n this.visited ~= 0;\n }\n this.v_count = v_count;\n }\n\n this(int n, int[] list){\n this(n);\n for (int i = 1; i < list.length; i += 2){\n this.add_vertex(list[i-1],list[i]);\n }\n }\n\n int[] conn(int v){\n return this.vertex[v];\n }\n\n void add_vertex(int s,int d){\n //writefln(\"%s-%s\",s-1,d-1);\n vertex[s-1] ~= [d-1];\n vertex[d-1] ~= [s-1];\n }\n\n int components(){\n int cmp = 0;\n int[] q;\n\n int cur = 0;\n //writefln(\"%s\",this.v_count);\n for(int v = 0; v < this.v_count; v++){\n if(this.visited[v] == 0){\n //writefln(\"*Visited %s (%s)\",v,this.vertex[v]);\n this.visited[v] = 1;\n cmp++;\n q ~= this.vertex[v];\n\n while(q.length > cur){\n int vv = q[cur];\n cur++;\n if ( this.visited[vv] == 0 ){\n //writefln(\"Visited %s (%s)\",vv,this.vertex[vv]);\n this.visited[vv] = 1;\n q ~= this.vertex[vv];\n }\n }\n } else {\n //writefln(\"*NOT %s\",v,this.vertex[v]);\n }\n }\n\n return cmp;\n }\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int ctl;\n readf(\"%s\",&ctl);\n if(ctl == -1){\n run_tests();\n } else{\n run_instance(ctl);\n }\n\n}\n\n// void debug(T...)(T args){\n//\n// }\n// int DEBUG = false;\n//\n// void debug(){\n// if(DEBUG){\n//\n// }\n// }\n\n\nvoid run_instance(int ctl){\n int n = ctl;\n int m; readf(\" %s\\n\",&m);\n auto graph = new G(n);\n\n for(int i = 0; i < m; i++){\n int s; readf(\"%s \",&s);\n int d; readf(\"%s \",&d);\n graph.add_vertex(s,d);\n }\n\n long r = calculate(n,m,graph);\n writefln(\"%s\",r);\n}\n\nlong calculate(int n, int m, G graph){\n int c = graph.components();\n long x = std.math.pow(2,n-c);\n //writefln(\"CX %s\",c);\n return x;\n}\n\nvoid run_tests(){\n int[][] rs;\n // rs ~= [[calculate(1,0,new G(1,[])),1]];\n // rs ~= [[calculate(2,1,new G(2,[1,2])),2]];\n // rs ~= [[calculate(3,2,new G(3,[1,2,2,3])),4]];\n // rs ~= [[calculate(10,10,new G(10,[1,8,4,10,4,6,5,10,2,3,1,7,3,4,3,6,6,9,3,7])),512]];\n // rs ~= [[calculate(20,20,new G(20,[6,8,13,20,7,13,6,17,5,15,1,12,5,5,17,5,14,6,14,12,20,7,20,1,6,1,7,2,19,14,17,1,10,11,15,9,18,2,12])),32768]];\n // rs ~= [[calculate(40,40,new G(40,[40,40,28,33,15,21,12,29,14,31,2,26,3,12,25,34,6,30,6,25,5,28,9,17,23,29,30,36,3,21,35,37,7,25,29,39,15,19,12,35,24,34,15,25,19,33,26,31,7,29,1,40,11,27,6,9,6,27,36,39,10,14,6,16,23,25,2,38,3,24,30,31,29,30,4,12,11,13,14,40,22,39])),34359738368]];\n\n int i = 0;\n bool failed = false;\n foreach(int[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n writefln(\"%s Failed %s is NOT %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n\nclass G{\n int[][] vertex;\n int[] visited;\n int v_count = 0;\n\n this(int v_count){\n //writefln(\"NEW %s\",v_count);\n for (int i = 0; i< v_count; i++){\n this.vertex ~= [[]];\n this.visited ~= 0;\n }\n this.v_count = v_count;\n }\n\n this(int n, int[] list){\n this(n);\n for (int i = 1; i < list.length; i += 2){\n this.add_vertex(list[i-1],list[i]);\n }\n }\n\n int[] conn(int v){\n return this.vertex[v];\n }\n\n void add_vertex(int s,int d){\n //writefln(\"%s-%s\",s-1,d-1);\n vertex[s-1] ~= [d-1];\n vertex[d-1] ~= [s-1];\n }\n\n int components(){\n int cmp = 0;\n int[] q;\n\n int cur = 0;\n //writefln(\"%s\",this.v_count);\n for(int v = 0; v < this.v_count; v++){\n if(this.visited[v] == 0){\n //writefln(\"*Visited %s (%s)\",v,this.vertex[v]);\n this.visited[v] = 1;\n cmp++;\n q ~= this.vertex[v];\n\n while(q.length > cur){\n int vv = q[cur];\n cur++;\n if ( this.visited[vv] == 0 ){\n //writefln(\"Visited %s (%s)\",vv,this.vertex[vv]);\n this.visited[vv] = 1;\n q ~= this.vertex[vv];\n }\n }\n } else {\n //writefln(\"*NOT %s\",v,this.vertex[v]);\n }\n }\n\n return cmp;\n }\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int ctl;\n readf(\"%s\",&ctl);\n if(ctl == -1){\n run_tests();\n } else{\n run_instance(ctl);\n }\n\n}\n\nvoid run_instance(int ctl){\n int n = ctl;\n int m; readf(\" %s\\n\",&m);\n auto graph = new G(n);\n\n for(int i = 0; i < m; i++){\n int s; readf(\"%s \",&s);\n int d; readf(\"%s \",&d);\n graph.add_vertex(s,d);\n }\n\n int r = calculate(n,m,graph);\n writefln(\"%s\",r);\n}\n\nint calculate(int n, int m, G graph){\n int c = graph.components();\n int x = std.math.pow(2,n-c);\n //writefln(\"CX %s\",c);\n return x;\n}\n\nvoid run_tests(){\n int[][] rs;\n rs ~= [[calculate(1,0,new G(1,[])),1]];\n rs ~= [[calculate(2,1,new G(2,[1,2])),2]];\n rs ~= [[calculate(3,2,new G(3,[1,2,2,3])),4]];\n int i = 0;\n bool failed = false;\n foreach(int[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n writefln(\"%s Failed %s != %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n\nclass G{\n int[][] vertex;\n int[] visited;\n ulong v_count = 0;\n\n this(int v_count){\n for (int i = 0; i< v_count; i++){\n this.vertex ~= [[]];\n this.visited ~= 0;\n }\n this.v_count = v_count;\n }\n\n this(int n, int[] list){\n this(n);\n for (int i = 1; i < list.length; i++){\n this.add_vertex(list[i-1],list[i]);\n }\n }\n\n int[] conn(int v){\n return this.vertex[v];\n }\n\n void add_vertex(int s,int d){\n vertex[s-1] ~= d-1;\n }\n\n int components(){\n int cmp = 0;\n int[] q;\n\n int cur = 0;\n for(int v = 0; v < this.v_count; v++){\n if(this.visited[v] == 0){\n this.visited[v] = 1;\n cmp++;\n q ~= this.vertex[v];\n\n while(q.length > cur){\n v = q[cur];\n cur++;\n\n if ( this.visited[v] == 0 ){\n this.visited[v] = 1;\n q ~= this.vertex[v];\n }\n }\n }\n }\n\n return cmp;\n }\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n int ctl;\n readf(\"%s\",&ctl);\n if(ctl == -1){\n run_tests();\n } else{\n run_instance(ctl);\n }\n\n}\n\n// void debug(T...)(T args){\n//\n// }\n// int DEBUG = false;\n//\n// void debug(){\n// if(DEBUG){\n//\n// }\n// }\n\n\nvoid run_instance(int ctl){\n int n = ctl;\n int m; readf(\" %s\\n\",&m);\n auto graph = new G(n);\n\n for(int i = 0; i < m; i++){\n int s; readf(\"%s \",&s);\n int d; readf(\"%s \",&d);\n graph.add_vertex(s,d);\n }\n\n int r = calculate(n,m,graph);\n writefln(\"%s\",r);\n}\n\nint calculate(int n, int m, G graph){\n int c = graph.components();\n int x = std.math.pow(2,n-c);\n writefln(\"CX %s\",c);\n return x;\n}\n\nvoid run_tests(){\n int[][] rs;\n rs ~= [[calculate(1,0,new G(1,[])),1]];\n rs ~= [[calculate(2,1,new G(2,[1,2])),2]];\n rs ~= [[calculate(3,2,new G(3,[1,2,2,3])),4]];\n rs ~= [[calculate(10,10,new G(10,[1,8,4,10,4,6,5,10,2,3,1,7,3,4,3,6,6,9,3,7])),512]];\n rs ~= [[calculate(20,20,new G(20,[6,8,13,20,7,13,6,17,5,15,1,12,5,5,17,5,14,6,14,12,20,7,20,1,6,1,7,2,19,14,17,1,10,11,15,9,18,2,12])),32768]];\n\n int i = 0;\n bool failed = false;\n foreach(int[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n writefln(\"%s Failed %s is NOT %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n\nclass G{\n int[][] vertex;\n int[] visited;\n ulong v_count = 0;\n\n this(int v_count){\n //writefln(\"NEW %s\",v_count);\n for (int i = 0; i< v_count; i++){\n this.vertex ~= [[]];\n this.visited ~= 0;\n }\n this.v_count = v_count;\n }\n\n this(int n, int[] list){\n this(n);\n for (int i = 1; i < list.length; i += 2){\n this.add_vertex(list[i-1],list[i]);\n }\n }\n\n int[] conn(int v){\n return this.vertex[v];\n }\n\n void add_vertex(int s,int d){\n //writefln(\"%s-%s\",s,d);\n vertex[s-1] ~= [d-1];\n vertex[d-1] ~= [s-1];\n }\n\n int components(){\n int cmp = 0;\n int[] q;\n\n int cur = 0;\n for(int v = 0; v < this.v_count; v++){\n if(this.visited[v] == 0){\n //writefln(\"*Visited %s (%s)\",v+1,this.vertex[v].length);\n this.visited[v] = 1;\n cmp++;\n q ~= this.vertex[v];\n\n while(q.length > cur){\n v = q[cur];\n cur++;\n if ( this.visited[v] == 0 ){\n //writefln(\"Visited %s (%s)\",v+1,this.vertex[v].length);\n this.visited[v] = 1;\n q ~= this.vertex[v];\n }\n }\n }\n }\n\n return cmp;\n }\n}\n"}], "src_uid": "c36f4bb34543476abc31fe986032122d"} {"source_code": "import std.stdio, std.string;\nimport std.typecons;\nimport std.algorithm;\n\nstruct XD\n{\n int c;\n int d;\n}\n\nlong saiki(int idx, int rem, long[][] dp, XD[][] b)\n{\n auto res = dp[idx][rem];\n if (res != -1) return res;\n if (idx == cast(int)b.length)\n {\n dp[idx][rem] = 0;\n return 0;\n }\n auto one = new int[3];\n fill(one, -1);\n auto two = -1;\n auto three = -1;\n foreach (i; 0 .. b[idx].length)\n {\n auto d = b[idx][i].d;\n if (b[idx][i].c == 1)\n {\n foreach (j; 0 .. 3)\n {\n if (d >= one[j])\n {\n for (int k = 2; k > j; -- k)\n {\n one[k] = one[k - 1];\n }\n one[j] = d;\n break;\n }\n }\n }\n else if (b[idx][i].c == 2)\n {\n if (d > two) two = d;\n }\n else\n {\n if (d > three) three = d;\n }\n }\n res = saiki(idx + 1, rem, dp, b);\n bool twice = (rem == 9);\n long ret = saiki(idx + 1, (rem + 1) % 10, dp, b);\n if (three != -1)\n {\n if (twice) res = max(res, ret + (three << 1));\n else res = max(res, ret + three);\n }\n if (two != -1)\n {\n if (twice) res = max(res, ret + (two << 1));\n else res = max(res, ret + two);\n }\n if (one[0] != -1)\n {\n if (twice) res = max(res, ret + (one[0] << 1));\n else res = max(res, ret + one[0]);\n }\n twice = (rem == 8 || rem == 9);\n ret = saiki(idx + 1, (rem + 2) % 10, dp, b);\n if (one[1] != -1)\n {\n if (twice) res = max(res, ret + (one[0] << 1) + one[1]);\n else res = max(res, ret + one[0] + one[1]);\n }\n if (one[0] != -1 && two != -1)\n {\n if (twice) res = max(res, ret + (max(one[0], two) << 1) + min(one[0], two));\n else res = max(res, ret + one[0] + two);\n }\n if (one[2] != -1)\n {\n twice = (rem >= 7 && rem < 10);\n ret = saiki(idx + 1, (rem + 3) % 10, dp, b);\n if (twice) res = max(res, ret + (one[0] << 1) + one[1] + one[2]);\n else res = max(res, ret + one[0] + one[1] + one[2]);\n }\n dp[idx][rem] = res;\n return res;\n}\n\nvoid solve(XD[][] b)\n{\n auto n = cast(int)b.length;\n auto dp = new long[][](n + 1, 10);\n foreach (i; 0 .. n + 1) fill(dp[i], -1);\n auto ans = saiki(0, 0, dp, b);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto b = new XD[][n];\n foreach (i; 0 .. n)\n {\n int k;\n readf(\"%d\\n\", &k);\n b[i] = new XD[k];\n foreach (j; 0 .. k)\n {\n readf(\"%d %d\\n\", &b[i][j].c, &b[i][j].d);\n }\n }\n solve(b);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.typecons;\nimport std.algorithm;\n\nlong saiki(int idx, int rem, long[][] dp, Tuple!(int, int)[][] b)\n{\n auto res = dp[idx][rem];\n if (res != -1) return res;\n if (idx == cast(int)b.length)\n {\n dp[idx][rem] = 0;\n return 0;\n }\n auto one = new int[3];\n fill(one, -1);\n auto two = -1;\n auto three = -1;\n foreach (i; 0 .. b[idx].length)\n {\n auto d = b[idx][i][1];\n if (b[idx][i][0] == 1)\n {\n foreach (j; 0 .. 3)\n {\n if (d >= one[j])\n {\n for (int k = 2; k > j; -- k) one[k] = one[k - 1];\n one[j] = d;\n break;\n }\n }\n }\n else if (b[idx][i][0] == 2)\n {\n if (d > two) two = d;\n }\n else\n {\n if (d > three) three = d;\n }\n }\n res = saiki(idx + 1, rem, dp, b);\n bool twice = (rem == 9);\n long ret = saiki(idx + 1, (rem + 1) % 10, dp, b);\n if (three != -1)\n {\n if (twice) res = max(res, ret + (three << 1));\n else res = max(res, ret + three);\n }\n if (two != -1)\n {\n if (twice) res = max(res, ret + (two << 1));\n else res = max(res, ret + two);\n }\n if (one[0] != -1)\n {\n if (twice) res = max(res, ret + (one[0] << 1));\n else res = max(res, ret + one[0]);\n }\n twice = (rem == 8 || rem == 9);\n ret = saiki(idx + 1, (rem + 2) % 10, dp, b);\n if (one[1] != -1)\n {\n if (twice) res = max(res, ret + (one[0] << 1) + one[1]);\n else res = max(res, ret + one[0] + one[1]);\n }\n if (one[0] != -1 && two != -1)\n {\n if (twice) res = max(res, ret + (max(one[0], two) << 1) + min(one[0], two));\n else res = max(res, ret + one[0] + two);\n }\n if (one[2] != -1)\n {\n twice = (rem >= 7 && rem < 10);\n ret = saiki(idx + 1, (rem + 3) % 10, dp, b);\n if (twice) res = max(res, ret + (one[0] << 1) + one[1] + one[2]);\n else res = max(res, ret + one[0] + one[1] + one[2]);\n }\n dp[idx][rem] = res;\n return res;\n}\n\nvoid solve(Tuple!(int, int)[][] b)\n{\n auto n = cast(int)b.length;\n auto dp = new long[][](n + 1, 10);\n foreach (i; 0 .. n + 1) fill(dp[i], -1);\n auto ans = saiki(0, 0, dp, b);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto b = new Tuple!(int, int)[][n];\n foreach (i; 0 .. n)\n {\n int k;\n readf(\"%d\\n\", &k);\n b[i] = new Tuple!(int, int)[k];\n foreach (j; 0 .. k) readf(\"%d %d\\n\", &b[i][j][0], &b[i][j][1]);\n }\n solve(b);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "fc84555813fc8f3cc4c524c377602fa8"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\nimport std.regex;\n\nvoid main() {\n readln;\n\n auto a = readln.chomp.split.map!(to!int);\n\n int max = a[0];\n int min = a[0];\n int maxInd = 0;\n int minInd = 0;\n\n foreach (int i, e; a.array) {\n if (max < e) {\n max = e;\n maxInd = i;\n }\n \n if (min >= e) {\n min = e;\n minInd = i;\n }\n }\n\n auto ans = maxInd + a.length - minInd - 1;\n if (minInd < maxInd) ans--;\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.algorithm;\n\nvoid main() \n{\n\tint n = to!int(readln.strip);\n\tauto line = to!(int[])(readln.strip.split);\n\n\tint left = fold!max(line);\n\tint indLeft = line.countUntil(left);\n\tcopy(line[0..indLeft].dup, line[1..indLeft+1]);\n\tline[0] = left;\n\t\t\n\tint right = fold!min(line);\n\tline.reverse;\n\tint indRight = line.countUntil(right);\n\twriteln(indLeft + indRight);\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[] nums;\n\tnums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t}\n\tint min = int.max;\n\tint p = 0;\n\tint totalmoves = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tif (nums[i] <= min)\n\t\t{\n\t\t\tmin = nums[i];\n\t\t\tp = i;\n\t\t}\n\t}\n\ttotalmoves = (n - p - 1);\n\tforeach (int i; p..(n-1))\n\t{\n\t\tnums[i] = nums[i+1];\n\t}\n\tnums[nums.length - 1] = min;\n\tint max = int.min;\n\tforeach (int i; 0..n)\n\t{\n\t\tif (nums[i] > max)\n\t\t{\n\t\t\tmax = nums[i];\n\t\t\tp = i;\n\t\t}\n\t}\n\ttotalmoves += p;\n\tprintf(\"%d\", totalmoves);\n\treturn 0;\n}\n\n"}], "negative_code": [], "src_uid": "ef9ff63d225811868e786e800ce49c92"} {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint x = read.to!int;\n\tint y = read.to!int;\n\t\n\tbool[] us = readln.chomp.map!(x => x == '1').array;\n\tbool[] ys;\n\tforeach_reverse(u; us) ys ~= u;\n\t\n\tprint!1(\"ys:\", ys);\n\t\n\tint ans;\n\tforeach(int i; 0 .. x){\n\t\tif(i == y && ! ys[i]) print!1(\"*\"), ans += 1;\n\t\tif(i != y && ys[i]) print!1(\"-\"), ans += 1;\n\t\tprint!1(ans);\n\t}\n\t\n\tans.writeln;\n\t\n\t\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto X = s[1];\n auto Y = s[2];\n auto S = readln.chomp;\n\n int ans = 0;\n\n foreach (i; 0..X) {\n if (i < Y) {\n ans += S[N-i-1] == '1' ;\n } else if (i == Y) {\n ans += S[N-i-1] == '0';\n } else {\n ans += S[N-i-1] == '1' ;\n }\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n //\n\n\n int n, x, y;\n readf(\" %s %s %s\\n\", n, x, y);\n auto s = readln().strip.dup;\n\n reverse(s);\n\n int tt = 0;\n if (s[y] == '0') tt++;\n tt += s[0 .. y].filter!\"a!='0'\".array.length;\n\n tt += s[y+1 .. x].filter!\"a!='0'\".array.length;\n\n writeln(tt);\n\n //\n\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto N = RD!int;\n\tauto X = RD!int;\n\tauto Y = RD!int;\n\tauto s = RD!string;\n\n\tlong ans;\n\tforeach_reverse (i; 0..N)\n\t{\n\t\tif (N-1-i == X) break;\n\t\tauto bit = N-1-i == Y ? '1' : '0';\n\t\tif (s[i] != bit)\n\t\t\t++ans;\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "075988685fa3f9b20bd215037c504a4f"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!long).array;\n \n if (arr.maxElement <= arr.minElement * 2) {\n (-1).repeat(n).map!(to!string).join(\" \").writeln;\n return;\n }\n \n auto arr3 = arr.chain(arr).chain(arr).array;\n \n debug { arr3.writeln; }\n \n auto ans = new int[] (n);\n \n int le = 0;\n alias elem = Tuple!(int, int);\n auto mx = make!(DList!elem);\n foreach (i, e; arr3) {\n while (!mx.empty() && e >= mx.back[0]) {\n mx.removeBack();\n }\n \n mx ~= tuple(e.to!int, i.to!int);\n \n debug { writeln(i, ' ', e, ' ', mx.front[0]); }\n \n while (!mx.empty() && e * 2 < mx.front[0]) {\n while (le <= mx.front[1]) {\n ans[le % n] = i.to!int - le;\n ++le;\n }\n \n debug { writeln(le); }\n mx.removeFront();\n }\n }\n \n ans.map!(to!string).join(\" \").writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int logHalf = 19;\nimmutable int half = 1 << logHalf;\nimmutable int limit = half << 1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tauto t = new int [limit];\n\t\tforeach (i; 0..n * 3 + 1)\n\t\t{\n\t\t\tt[i + half] = a[i % n];\n\t\t}\n\t\tforeach_reverse (i; 1..half)\n\t\t{\n\t\t\tt[i] = min (t[i * 2 + 0], t[i * 2 + 1]);\n\t\t}\n\n\t\tauto bads = new int [n * 2];\n\t\tfor (int i = 0; i < n * 2; i++)\n\t\t{\n\t\t\tint value = a[i % n];\n\t\t\tint hi = i + half;\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tif ((hi & 1) == 0 && t[hi + 1] * 2 < value)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\thi = hi / 2;\n\t\t\t}\n\t\t\twhile (hi < half)\n\t\t\t{\n\t\t\t\tint p = hi * 2 + 2;\n\t\t\t\tif (t[p] * 2 < value)\n\t\t\t\t{\n\t\t\t\t\tp -= 1;\n\t\t\t\t}\n\t\t\t\thi = p;\n\t\t\t}\n\t\t\tbads[i] = hi - half;\n\t\t\tdebug {writeln (i, \": \", bads[i]);}\n\t\t}\n\n\t\tforeach_reverse (i; 0..n * 2 - 1)\n\t\t{\n\t\t\tbads[i] = min (bads[i], bads[i + 1]);\n\t\t}\n\t\tdebug {writeln (bads);}\n\n\t\tauto res = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (bads[i] == n * 3)\n\t\t\t{\n\t\t\t\tres[i] = -1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres[i] = bads[i] - i + 1;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tlong[] as = rlong(n);\n\tas ~= as ~ as;\n\tlog(\"as:\", as);\n\t\n\tT uplimit(T)(T a, T c, bool delegate(T) f){\n\t\tif(f(c)) return c; if(! f(a)) return a - 1;\n\t\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) a = b; else c = b; }\n\t\treturn a;\n\t}\n\n\tint[] ans;\n\tK[] ks = new K[](n * 2);\n\tint l = 0, r = 0;\n\tint j0;\n\tforeach(int i, a; as){\n\t\twhile(l < r && ks[r - 1].value <= a) r -= 1;\n\t\tks[r] = K(i, a), r += 1;\n\t\tlog(\"i:\", i, \"a:\", a, \"l:\", l, \"r:\", r, \"ks:\", ks[0 .. n]);\n\t\tint newl = uplimit(l, r - 1, (int x) => (ks[x].value > a * 2));\n\t\tif(newl >= 0 && j0 <= ks[newl].pos){\n\t\t\tforeach(j; j0 .. ks[newl].pos + 1) ans ~= i - j;\n\t\t\tj0 = ks[newl].pos + 1;\n\t\t}\n\t\tlog(\"l:\", l, \"newl:\", newl, \"ans:\", ans);\n\t}\n\twhile(ans.length < n) ans ~= -1;\n\tans[0 .. n].map!(to!string).array.join(\" \").writeln;\n\t\n}\nstruct K{\n\tint pos;\n\tlong value;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nenum E = 20;\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto mx = new int[][](E, N);\n auto mn = new int[][](E, N);\n auto live = new bool[][](E, N);\n foreach (i; 0 .. N) {\n mx[0][i] = A[i];\n mn[0][i] = A[i];\n live[0][i] = true;\n }\n foreach (e; 0 .. E - 1) {\n foreach (i; 0 .. N) {\n const j = (i + (1 << e)) % N;\n mx[e + 1][i] = max(mx[e][i], mx[e][j]);\n mn[e + 1][i] = min(mn[e][i], mn[e][j]);\n live[e + 1][i] = live[e][i] && live[e][j] && !(mx[e][i] > 2 * mn[e][j]);\n }\n }\n auto ans = new int[N];\n foreach (i; 0 .. N) {\n int m = 0;\n int sum;\n int j = i;\n foreach_reverse (e; 0 .. E) {\n if (live[e][j] && !(m > 2 * mn[e][j])) {\n chmax(m, mx[e][j]);\n sum += 1 << e;\n j = (j + (1 << e)) % N;\n }\n }\n ans[i] = (sum >= 2 * N) ? -1 : sum;\n }\n \n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "86146bbbfd46634b68b1141e45201a41"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n int k = cin.readInt;\n int[] d = new int[n * k + 1];\n int[int] map;\n int[][] c = new int[][](k);\n\n for (int i = 0; i < k; i++) {\n int input = cin.readInt;\n d[input] = 1;\n map[i] = input;\n }\n \n int offSet = 1;\n for (int i = 0; i < k; i++) {\n c[i] ~= map[i];\n int count = 1;\n for (int j = offSet; count < n;) {\n if (!d[j]) {\n c[i] ~= j;\n d[j] = 1;\n count++;\n j++;\n offSet = j;\n } else {\n offSet++;\n j++;\n }\n }\n }\n\n for (int i = 0; i < k; i++) {\n for (int j = 0; j < c[i].length; j++) {\n write(c[i][j], \" \");\n }\n writeln();\n }\n } \n}", "positive_code": [{"source_code": "module sigod.codeforces.p244A;\n\nimport std.array : split;\nimport std.conv : to;\nimport std.stdio;\nimport std.string : strip;\n\nvoid main() {\n\tint n, k;\n\n\tread_variables(n, k);\n\n\tauto a = read_array!int();\n\tauto orange = new bool[n * k + 1];\n\n\tforeach (ref ai; a) {\n\t\torange[ai] = true;\n\t}\n\n\tint position = 1;\n\n\tforeach (ref ai; a) {\n\t\tstdout.write(ai);\n\n\t\tint count = 1;\n\t\twhile (count < n) {\n\t\t\tif (!orange[position]) {\n\t\t\t\tstdout.write(\" \", position);\n\n\t\t\t\torange[position] = true;\n\n\t\t\t\t++count;\n\t\t\t}\n\n\t\t\t++position;\n\t\t}\n\n\t\tstdout.writeln();\n\t}\n}\n\nprivate\nvoid read_variables(S...)(out S args) {\n\tauto input = stdin.readln().strip().split();\n\n\tforeach (index, ref arg; args) {\n\t\targ = input[index].to!(typeof(arg))();\n\t}\n}\n\nprivate\nT[] read_array(T)() {\n\tauto input = stdin.readln().strip().split();\n\n\tT[] result = new T[input.length];\n\n\tforeach (index, ref element; input) {\n\t\tresult[index] = element.to!T();\n\t}\n\n\treturn result;\n}"}], "negative_code": [{"source_code": "module sigod.codeforces.p244A;\n\nimport std.array : split;\nimport std.conv : to;\nimport std.stdio;\nimport std.string : strip;\n\nvoid main() {\n\tint n, k;\n\n\tread_variables(n, k);\n\n\tauto a = read_array!int();\n\n\tforeach (ai; a) {\n\t\tstdout.write(ai);\n\n\t\tforeach (ni; 1 .. n) {\n\t\t\tai += k;\n\n\t\t\tif (ai > n * k) ai %= n * k;\n\n\t\t\tstdout.write(\" \", ai);\n\t\t}\n\n\t\tstdout.writeln();\n\t}\n}\n\nprivate\nvoid read_variables(S...)(out S args) {\n\tauto input = stdin.readln().strip().split();\n\n\tforeach (index, ref arg; args) {\n\t\targ = input[index].to!(typeof(arg))();\n\t}\n}\n\nprivate\nT[] read_array(T)() {\n\tauto input = stdin.readln().strip().split();\n\n\tT[] result = new T[input.length];\n\n\tforeach (index, ref element; input) {\n\t\tresult[index] = element.to!T();\n\t}\n\n\treturn result;\n}"}], "src_uid": "928f18ee5dbf44364c0d578f4317944c"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!long(N);\r\n\r\n bool[long] visited;\r\n foreach(a; A) {\r\n if (a in visited) visited[-a] = true; else visited[a] = false;\r\n }\r\n\r\n return visited.length;\r\n }\r\n\r\n foreach(_; 0..QN) subSolve().writeln;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}", "positive_code": [{"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n\n immutable s =\n readln\n .chomp\n .split(' ')\n .to!(byte[])\n .sort\n .group\n .assocArray;\n\n immutable ans = s.length +\n s.byKey\n .count!((k) => s[k] >= 2 && -k !in s);\n\n writeln(ans);\n }\n}\n// \"\" ' '\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint [int] k;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tk[abs (c)] += 1;\r\n\t\t\tk[abs (c)] = min (k[abs (c)], 1 + (c != 0));\r\n\t\t}\r\n\t\tk.byValue.sum.writeln;\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!int).array;\n int[int] freq;\n foreach (x ; a)\n freq[x]++;\n int ans = (0 in freq) ? 1 : 0;\n foreach (i ; 1 .. 101) {\n int cnt = freq.get(i, 0) + freq.get(-i, 0);\n ans += min(cnt, 2);\n }\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt;\n }\n \n int[int] freq;\n foreach (i; 0 .. N) {\n ++freq[abs(A[i])];\n }\n int ans;\n foreach (key, val; freq) {\n ans += min((key == 0) ? 1 : 2, val);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n immutable arr = readln().chomp.split(' ').to!(int[]).assumeUnique;\n\n int[int] normal;\n foreach (val; arr) ++ normal[val];\n\n size_t maxi = normal.length;\n foreach (i; 0 .. n) {\n int[int] frec = normal.dup;\n\n foreach (j; i .. n) {\n if (arr[j]) {\n -- frec[arr[j]];\n ++ frec[-arr[j]];\n if (frec[arr[j]] == 0)\n frec.remove(arr[j]);\n }\n maxi = max(maxi, frec.length);\n }\n }\n\n maxi.writeln();\n }\n}\n// \"\" ' '\n"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n immutable arr = readln().chomp.split(' ').to!(int[]).assumeUnique;\n\n int[int] normal;\n foreach (val; arr) ++ normal[val];\n\n size_t maxi = normal.length;\n foreach (i; 0 .. n) {\n int[int] frec = normal.dup;\n int[int] inverted;\n\n size_t cont = frec.length;\n foreach (j; i .. n) {\n if (arr[j] != 0) {\n cont += (inverted[arr[j]] ++ == 0);\n cont -= (-- frec[arr[j]] == 0);\n }\n maxi = max(maxi, cont);\n }\n }\n\n maxi.writeln();\n }\n}\n// \"\" ' '\n"}], "src_uid": "23ef311011b381d0ca2e84bc861f0a31"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m;\n @Dim(\"n\") long[] a;\n @Dim(\"n - 1\") Tuple!(long, long)[] edges;\n\n void solve(long tc = -1)\n {\n foreach(ref edge; edges)\n edge[0]--, edge[1]--;\n auto alist = makeSlice!(long[])(n);\n auto visited = makeSlice!(bool)(n);\n foreach(edge; edges)\n {\n alist.at(edge[0]) ~= edge[1];\n alist.at(edge[1]) ~= edge[0];\n }\n long cnt = 0;\n void dfs(long node, long cats, bool good)\n {\n visited.at(node) = true;\n bool isLeaf = true;\n cats += a.at(node);\n if (cats > m)\n good = false;\n foreach(w; alist.at(node))\n if (!visited.at(w))\n {\n isLeaf = false;\n if (a.at(node) == 0)\n dfs(w, 0, good);\n else\n dfs(w, cats, good);\n }\n if (isLeaf && good)\n {\n cnt++;\n }\n }\n dfs(0, 0, true);\n writeln(cnt);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/problemset/problem/580/C\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nint n, m, answer;\nint[][] tree = new int[][](10^^5+5);\nint[] a;\n\nvoid dfs(int x, int parent, int cats, bool flag) {\n if(a[x] == 1)\n cats += 1;\n if(cats > m)\n flag = true;\n if(tree[x].length == 1 && x != 1 && !flag)\n answer += 1;\n foreach(item; tree[x])\n if(item != parent)\n dfs(item, x, cats*a[x], flag);\n}\n\nvoid main() {\n readf(\"%s %s\", &n, &m);\n readln;\n a = 0~readln.split.map!(to!int).array;\n\n foreach(i; 1..n) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n tree[x] ~= y;\n tree[y] ~= x;\n }\n\n dfs(1, 0, 0, 0);\n answer.writeln;\n}\n\n"}], "negative_code": [], "src_uid": "875e7048b7a254992b9f62b9365fcf9b"} {"source_code": "import std.stdio;\nimport std.array;\n\nvoid main() {\n int n, m, l, r, ones = 0, mones = 0;\n \"%d %d\\n\".readf(&n, &m);\n\n string[] a = readln.split;\n\n foreach(string i; a) {\n if(i == \"1\")\n ones++;\n else if(i == \"-1\")\n mones++;\n }\n \n foreach(_; 0 .. m) {\n \"%d %d\\n\".readf(&l, &r);\n if(\n (r-l) % 2 == 1 &&\n (r-l+1) / 2 <= ones &&\n (r-l+1) / 2 <= mones\n )\n 1.writeln;\n else\n 0.writeln;\n }\n\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N, M; scanf(\"%d %d\\n\", &N, &M);\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n sort(xs);\n int a, b;\n foreach (x; xs) {\n if (x == -1) {\n a++;\n } else {\n b++;\n }\n }\n foreach (i; 0 .. M) {\n int s, t; scanf(\"%d %d\\n\", &s, &t);\n int l = t - s + 1;\n if (l % 2 != 0) {\n writeln(0); continue;\n }\n if (a >= l / 2 && b >= l / 2) {\n writeln(1);\n } else {\n writeln(0);\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.string;\n\nvoid main() {\n int n, m, l, r, ones = 0, mones = 0;\n \"%d %d\\n\".readf(&n, &m);\n\n string[] a = readln.split.array;\n\n foreach(string i; a) {\n if(i == \"1\")\n ones++;\n else if(i == \"-1\")\n mones++;\n }\n \n foreach(_; 0 .. m) {\n \"%d %d\\n\".readf(&l, &r);\n if(\n (r-l) % 2 == 1 &&\n (r-l+1) / 2 <= ones &&\n (r-l+1) / 2 <= mones\n )\n 1.writeln;\n else\n 0.writeln;\n }\n\n}\n"}, {"source_code": "// unihernandez22\n// https://codeforces.com/contest/302/problem/A\n// greedy\n\nimport std.stdio;\nimport std.array;\n\nvoid main() {\n int n, m, l, r, ones = 0, mones = 0;\n \"%d %d\\n\".readf(&n, &m);\n\n int x;\n for(int i = 0; i < n; i++) {\n \"%d \".readf(&x);\n if(x == 1)\n ones++;\n else if(x == -1)\n mones++;\n }\n \n for(int i = 0; i < m; i++) {\n \"%d %d\\n\".readf(&l, &r);\n if(\n (r-l) % 2 == 1 &&\n (r-l+1) / 2 <= ones &&\n (r-l+1) / 2 <= mones\n )\n 1.writeln;\n else\n 0.writeln;\n }\n\n}\n"}], "negative_code": [], "src_uid": "deeb49969ac4bc4f1c7d76b89ac1402f"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n int c = cin.read_int;\n \n int[] arr = new int[n];\n \n foreach(ref x; arr) {\n x = cin.read_int;\n }\n\n int count = 0;\n for (int i = 0; i < n - 1; i++) {\n if (arr[i + 1] - arr[i] <= c) {\n count++;\n } else count = 0;\n }\n\n writeln(count + 1); \n //plus one since the first word is always added\n } \n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.conv;\nimport std.array;\nimport std.string;\nimport std.algorithm;\n\nvoid read(out long n, out long c, out long[] arr) {\n\t\n\treadf(\" %s %s\\n\", &n, &c);\n\n\tarr = readln.split.map!(to!long).array;\n}\n\nlong solv(out long res, in long c, in long[] arr) {\n\n\tres = 1;\n\tforeach (idx, el; arr[0 .. $ - 1]) {\n\t\tif (arr[idx + 1] - el > c) {\n\t\t\tres = 1;\n\t\t} else {\n\t\t\t++res;\n\t\t}\n\t}\n\n\treturn res;\n}\n\nvoid main() {\n\n\tlong n, c;\n\tlong[] arr;\n\n\tread(n, c, arr);\n\t\n\tlong res;\n\twriteln(solv(res, c, arr));\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.conv;\nimport std.array;\nimport std.string;\nimport std.algorithm;\n\nvoid read(out long n, out long c, out long[] arr) {\n\t\n\treadf(\" %s %s\\n\", &n, &c);\n\n\tarr = readln.split.map!(to!long).array;\n}\n\nlong solv(out long res, in long c, in long[] arr) {\n\n\tforeach (idx, el; arr[0 .. $ - 1]) {\n\t\tif (arr[idx + 1] - el > c) {\n\t\t\tres = 1;\n\t\t} else {\n\t\t\t++res;\n\t\t}\n\t}\n\n\treturn res;\n}\n\nvoid main() {\n\n\tlong n, c;\n\tlong[] arr;\n\n\tread(n, c, arr);\n\t\n\tlong res;\n\twriteln(solv(res, c, arr));\n}\n"}], "src_uid": "fb58bc3be4a7a78bdc001298d35c6b21"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto a = RDA!int;\r\n\r\n\t\tauto cnt = new long[](m);\r\n\t\tforeach (e; a)\r\n\t\t\t++cnt[e%m];\r\n\r\n\t\tforeach (i; 1..(m+1)/2)\r\n\t\t{\r\n\t\t\tauto x = cnt[i];\r\n\t\t\tauto y = cnt[m-i];\r\n\t\t\tauto z = min(x, y);\r\n\t\t\tx -= z;\r\n\t\t\ty -= z;\r\n\t\t\tif (z == 0)\r\n\t\t\t\tans[ti] += max(x, y);\r\n\t\t\telse\r\n\t\t\t\tans[ti] += max(max(x, y), 1);\r\n\t\t\tdebug writeln(\"i:\", i, \" ans:\", ans[ti]);\r\n\t\t}\r\n\t\tif (cnt[0] != 0)\r\n\t\t\t++ans[ti];\r\n\t\tif (m % 2 == 0 && cnt[m/2] != 0)\r\n\t\t\t++ans[ti];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1497/problem/B\n// modular arithmetic, math, greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\nwhile(t--) {\n uint n, m;\n readf(\"%s %s\\n\", &n, &m);\n long[] a = readln.split.map!(to!long).map!(x => x % m).array;\n\n long[] counter = new long[m];\n foreach(number; a) {\n counter[cast(uint)number] += 1L;\n }\n\n //a.writeln;\n //counter.writeln;\n\n long ans = 0L;\n if(counter[0L] > 0L)\n ans += 1L;\n\n for(uint i = 1L; i*2 <= m; i++) {\n if(counter[i] == 0L && counter[m - i] == 0L)\n continue;\n ans += 1L;\n if(2*i == m)\n continue;\n //writefln(\"ans: %s\", ans);\n\n long take = min(counter[i], counter[m - i]);\n //writefln(\"counter[%s] = %s\", i, counter[i]);\n //writefln(\"counter[%s] = %s\", m - i, counter[m - i]);\n\n counter[i] -= take;\n counter[m - i] -= take;\n\n if(counter[i] > 0L)\n counter[i] -= 1L;\n if(counter[m - i] > 0L)\n counter[m - i] -= 1L;\n ans += counter[i] + counter[m - i];\n }\n ans.writeln;\n}\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1497/problem/B\n// modular arithmetic, math, greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\nwhile(t--) {\n uint n, m;\n readf(\"%s %s\\n\", &n, &m);\n long[] a = readln.split.map!(to!long).map!(x => x % m).array;\n\n long[] counter = new long[m];\n foreach(number; a) {\n counter[cast(uint)number] += 1L;\n }\n\n //a.writeln;\n //counter.writeln;\n\n long ans = 0L;\n if(counter[0L] > 0L)\n ans += 1L;\n\n for(uint i = 1L; i*2 < m; i++) {\n if(counter[i] == 0L && counter[m - i] == 0L)\n continue;\n ans += 1L;\n //writefln(\"ans: %s\", ans);\n\n long take = min(counter[i], counter[m - i]);\n //writefln(\"counter[%s] = %s\", i, counter[i]);\n //writefln(\"counter[%s] = %s\", m - i, counter[m - i]);\n\n counter[i] -= take;\n counter[m - i] -= take;\n\n if(counter[i] > 0L)\n counter[i] -= 1L;\n if(counter[m - i] > 0L)\n counter[m - i] -= 1L;\n ans += counter[i] + counter[m - i];\n }\n if(counter[m/2] > 1) {\n ans += 1L;\n }\n ans.writeln;\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1497/problem/B\n// modular arithmetic, math, greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\nwhile(t--) {\n uint n, m;\n readf(\"%s %s\\n\", &n, &m);\n long[] a = readln.split.map!(to!long).map!(x => x % m).array;\n\n long[] counter = new long[m];\n foreach(number; a) {\n counter[cast(uint)number] += 1L;\n }\n\n //a.writeln;\n //counter.writeln;\n\n long ans = 0L;\n if(counter[0L] > 0L)\n ans += 1L;\n\n for(uint i = 1L; i*2 < m; i++) {\n if(counter[i] == 0L && counter[m - i] == 0L)\n continue;\n ans += 1L;\n //writefln(\"ans: %s\", ans);\n\n long take = min(counter[i], counter[m - i]);\n //writefln(\"counter[%s] = %s\", i, counter[i]);\n //writefln(\"counter[%s] = %s\", m - i, counter[m - i]);\n\n counter[i] -= take;\n counter[m - i] -= take;\n\n if(counter[i] > 0L)\n counter[i] -= 1L;\n if(counter[m - i] > 0L)\n counter[m - i] -= 1L;\n ans += counter[i] + counter[m - i];\n }\n if(m%2 == 0 && counter[m/2] > 1) {\n ans += 1L;\n }\n ans.writeln;\n}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto a = RDA!int;\r\n\r\n\t\tauto cnt = new long[](m);\r\n\t\tforeach (e; a)\r\n\t\t\t++cnt[e%m];\r\n\r\n\t\tforeach (i; 1..(m+1)/2)\r\n\t\t{\r\n\t\t\tauto x = cnt[i];\r\n\t\t\tauto y = cnt[m-i];\r\n\t\t\tauto z = min(x, y);\r\n\t\t\t++ans[ti];\r\n\t\t\tx -= z;\r\n\t\t\ty -= z;\r\n\t\t\tif (z == 0)\r\n\t\t\t\tans[ti] += max(x, y);\r\n\t\t\telse\r\n\t\t\t\tans[ti] += max(max(x, y) - 1, 0);\r\n\t\t}\r\n\t\tif (cnt[0] != 0)\r\n\t\t\t++ans[ti];\r\n\t\tif (m % 2 == 0 && cnt[m/2] != 0)\r\n\t\t\t++ans[ti];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto a = RDA!int;\r\n\r\n\t\tauto cnt = new long[](m);\r\n\t\tforeach (e; a)\r\n\t\t\t++cnt[e%m];\r\n\r\n\t\tforeach (i; 1..(m+1)/2)\r\n\t\t{\r\n\t\t\tauto x = cnt[i];\r\n\t\t\tauto y = cnt[m-i];\r\n\t\t\tauto z = min(x, y);\r\n\t\t\t++ans[ti];\r\n\t\t\tx -= z;\r\n\t\t\ty -= z;\r\n\t\t\tans[ti] += max(max(x, y) - 1, 0);\r\n\t\t}\r\n\t\tif (cnt[0] != 0)\r\n\t\t\t++ans[ti];\r\n\t\tif (m % 2 == 0 && cnt[m/2] != 0)\r\n\t\t\t++ans[ti];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "d107db1395ded62904d0adff164e5c1e"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tsort (b);\n\t\treverse (b);\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tif (a[i] < b[i])\n\t\t\t{\n\t\t\t\tswap (a[i], b[i]);\n\t\t\t}\n\t\t}\n\t\twriteln (sum (a));\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = RDA;\n\t\t\n\t\ta.sort!\"a > b\"();\n\t\tb.sort!\"a > b\"();\n\n\t\tforeach (i; 0..n-k)\n\t\t{\n\t\t\tans[ti] += a.front; a.popFront;\n\t\t}\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tif (a.front > b.front)\n\t\t\t{\n\t\t\t\tans[ti] += a.front; a.popFront;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans[ti] += b.front; b.popFront;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "7c2337c1575b4a62e062fc9990c0b098"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tlong[] as = rlong(n);\n\t\n\tlong sum = as.sum;\n\tlong[] ds;\n\tfor(long d = 1; d * d <= sum; d ++) if(sum % d == 0) ds ~= d, ds ~= sum / d;\n\tlog(\"as:\", as, \"sum:\", sum, \"ds:\", ds);\n\t// \u203b\u7d20\u6570\u306b\u7d5e\u3063\u3066\u3082\u826f\u3044\u306f\u305a\n\t\n\tlong ans = as.sum * n;\n\tforeach(d; ds){\n\t\tif(d == 1) continue;\n\t\tlong leftover;\n\t\tlong tempans;\n\t\tlong q;\n\t\tforeach(i, a; as){\n\t\t\tq += a, q %= d;\n\t\t\tif(q < d - q) tempans += q;\n\t\t\telse tempans += d - q;\n\t\t\tlog(\"i:\", i, \"q:\", q, \"tempans:\", tempans);\n\t\t}\n\t\tans = min(ans, tempans);\n\t\tlog(\"tempans:\", tempans, \"ans:\", ans);\n\t}\n\tif(ans >= as.sum * n) ans = -1;\n\tans.writeln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto total = sum (a, 0L);\n\t\tif (total == 1)\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlong [] p;\n\t\tfor (long d = 2; d * d <= total; d++)\n\t\t{\n\t\t\tif (total % d == 0)\n\t\t\t{\n\t\t\t\tp ~= d;\n\t\t\t\twhile (total % d == 0)\n\t\t\t\t{\n\t\t\t\t\ttotal /= d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (total > 1)\n\t\t{\n\t\t\tp ~= total;\n\t\t}\n\n\t\tlong solve (long d)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tlong res = 0;\n\t\t\tforeach (i; 0..n - 1)\n\t\t\t{\n\t\t\t\tcur += a[i];\n\t\t\t\tcur %= d;\n\t\t\t\tres += min (cur, d - cur);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tlong res = total * n;\n\t\tforeach (ref c; p)\n\t\t{\n\t\t\tres = min (res, solve (c));\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10L^^18;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n const S = A.sum;\n long[] ps;\n long s = S;\n for (long p = 2; p * p <= s; ++p) {\n if (s % p == 0) {\n do {\n s /= p;\n } while (s % p == 0);\n ps ~= p;\n }\n }\n if (s > 1) {\n ps ~= s;\n }\n debug {\n writeln(\"ps = \", ps);\n }\n \n long ans = INF;\n foreach (p; ps) {\n long cost;\n long now;\n foreach (i; 0 .. N) {\n now += A[i];\n now %= p;\n cost += min(now, p - now);\n }\n debug {\n writeln(p, \": \", cost);\n }\n chmin(ans, cost);\n }\n writeln((ans >= INF) ? -1 : ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "48494a73273cd8d999e94ba1a9581fdf"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1437/problem/A\n// math\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\n long l, r;\n while(t--) {\n readf(\"%s %s\\n\", &l, &r);\n if(2L * l > r)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto l = RD;\n\t\tauto r = RD;\n\t\tauto a = r+1;\n\t\tans[ti] = l*2 >= a;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint lo, hi;\n\t\treadf !(\" %s %s\") (lo, hi);\n\t\tauto mod = hi + 1;\n\t\twriteln ((lo % mod) * 2 >= mod ? \"YES\" : \"NO\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto l = RD;\n\t\tauto r = RD;\n\t\tauto a = (l-1)*2 + 1;\n\t\tans[ti] = a > r;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto l = RD;\n\t\tauto r = RD;\n\t\tauto a = r + 1;\n\t\tans[ti] = l * 2 > a;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "5172d358f1d451b42efff1019219a54d"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N, M;\nreal[] X;\nint[] A, B;\nreal[] C;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tM = readInt;\n\t\tX = new real[N];\n\t\tforeach (u; 0 .. N) {\n\t\t\tX[u] = readReal;\n\t\t}\n\t\tA = new int[M];\n\t\tB = new int[M];\n\t\tC = new real[M];\n\t\tforeach (i; 0 .. M) {\n\t\t\tA[i] = readInt - 1;\n\t\t\tB[i] = readInt - 1;\n\t\t\tC[i] = readReal;\n\t\t}\n\t\t\n\t\treal ans = 0.0;\n\t\tforeach (i; 0 .. M) {\n\t\t\tif (C[i] > 0) {\n\t\t\t\tchmax(ans, (X[A[i]] + X[B[i]]) / C[i]);\n\t\t\t}\n\t\t}\n\t\twritefln(\"%.10f\", ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \n\nvoid main() {\n int N, M;\n scanf(\"%d %d\\n\", &N, &M);\n int[] X = readln.chomp.split(\" \").map!(to!int).array;\n double Ans = 0;\n for (int i = 0; i < M; i++) {\n int a, b, c; scanf(\"%d %d %d\\n\", &a, &b, &c);\n a--; b--;\n Ans = max(Ans, cast(double)(X[a] + X[b]) / c);\n }\n writefln(\"%.12f\", Ans);\n}\n"}], "negative_code": [], "src_uid": "ba4304e79d85d13c12233bcbcce6d0a6"} {"source_code": "\nimport std.stdio, std.array, std.algorithm : sort, copy;\nimport std.conv;\nimport std.string;\n\nint main(string[] argv)\n{\n\tauto input = stdin.readln().chomp().split();\n\tauto leng = to!int(input[0]);\n\tauto curCountIceCream = to!long(input[1]);\n\n string line;\n\tint notSatisfiedCount = 0;\n\tint curLen = 0;\n while ((line = readln().chomp()) !is null)\n\t{\n\t\tauto newLine = removechars(line, ['\\x20']);\n\t\tauto curInput = to!long(newLine);\n\t\tif ( curCountIceCream + curInput >= 0 )\n\t\t\tcurCountIceCream += curInput;\n\t\telse \n\t\t\tnotSatisfiedCount++;\n\t\tcurLen++;\n\t\tif ( curLen == leng)\n\t\t\tbreak;\n\t}\n\n\twriteln( curCountIceCream , \" \" , notSatisfiedCount);\n\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\nclass Ice_Cream {\n \n this(long x) { this.x = x; }\n \n void setX(long d) { x += d; }\n \n protected static long x;\n}\n\nclass Kay : Ice_Cream {\n\n this() { super(x); }\n void setRest(long d) { Kay.x -= d; }\n \n @property long rest() { return Kay.x; }\n}\n\nclass Gerda : Ice_Cream {\n\n this() { super(x); }\n \n void setSad() { _sad++; }\n \n @property long sad() { return _sad; }\n \n private long _sad;\n}\n\nvoid main() {\n\n long n, x;\n \n readf(\" %s %s \", &n, &x);\n \n Ice_Cream ice = new Ice_Cream(x);\n Kay kay = new Kay();\n Gerda gerda = new Gerda();\n \n long d;\n char child_work;\n \n foreach (idx; 0 .. n) {\n \n readf(\" %s %s \", &child_work, &d);\n \n if (child_work == '+') {\n ice.setX(d);\n } else {\n if (ice.x < d) {\n gerda.setSad();\n } else {\n kay.setRest(d);\n }\n }\n }\n \n writeln(kay.rest, ' ', gerda.sad);\n}"}], "negative_code": [{"source_code": "\nimport std.stdio, std.array, std.algorithm : sort, copy;\nimport std.conv;\nimport std.string;\n\nint main(string[] argv)\n{\n\tauto input = stdin.readln().chomp().split();\n\tauto leng = to!int(input[0]);\n\tauto curCountIceCream = to!int(input[1]);\n\n string line;\n\tint notSatisfiedCount = 0;\n\tint curLen = 0;\n while ((line = readln().chomp()) !is null)\n\t{\n\t\tauto newLine = removechars(line, ['\\x20']);\n\t\tauto curInput = to!int(newLine);\n\t\tif ( curCountIceCream + curInput >= 0 )\n\t\t\tcurCountIceCream += curInput;\n\t\telse \n\t\t\tnotSatisfiedCount++;\n\t\tcurLen++;\n\t\tif ( curLen == leng)\n\t\t\tbreak;\n\t}\n\n\twriteln( curCountIceCream , \" \" , notSatisfiedCount);\n\n return 0;\n}\n"}, {"source_code": "\nimport std.stdio, std.array, std.algorithm : sort, copy;\nimport std.conv;\nimport std.string;\n\nint main(string[] argv)\n{\n\tauto input = stdin.readln().chomp().split();\n\tauto leng = to!int(input[0]);\n\tauto curCountIceCream = to!int(input[1]);\n\n string line;\n\tint notSatisfiedCount = 0;\n\tlong curLen = 0;\n while ((line = readln().chomp()) !is null)\n\t{\n\t\tauto newLine = removechars(line, ['\\x20']);\n\t\tauto curInput = to!long(newLine);\n\t\tif ( curCountIceCream + curInput >= 0 )\n\t\t\tcurCountIceCream += curInput;\n\t\telse \n\t\t\tnotSatisfiedCount++;\n\t\tcurLen++;\n\t\tif ( curLen == leng)\n\t\t\tbreak;\n\t}\n\n\twriteln( curCountIceCream , \" \" , notSatisfiedCount);\n\n return 0;\n}\n"}], "src_uid": "0a9ee8cbfa9888caef39b024563b7dcd"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n auto A = new string[M];\n foreach (x; 0 .. M) {\n A[x] = readToken();\n }\n \n auto uf = new int[M + N];\n uf[] = -1;\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n if (A[x][y] == '#') {\n uf.connect(x, M + y);\n }\n }\n auto board = new char[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n board[x][y] = (uf.root(x) == uf.root(M + y)) ? '#' : '.';\n }\n bool ans = true;\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n ans = ans && (A[x][y] == board[x][y]);\n }\n writeln(ans ? \"Yes\" : \"No\");\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}\nvoid readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}\nvoid readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}\n\nvoid main()\n{\n int n, m; readV(n, m);\n string[] s; readM(n, s);\n\n s = s.sort().uniq.array;\n\n auto b = new int[](m);\n foreach (si; s)\n b[] += si.map!(c => c == '#' ? 1 : 0).array[];\n\n writeln(b.all!\"a<=1\" ? \"Yes\" : \"No\");\n}\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}\n\nvoid main()\n{\n int n, m; readV(n, m);\n string[] s; readC(n, s);\n\n s = s.sort().uniq.array;\n\n auto b = new int[](m);\n foreach (si; s)\n b[] += si.map!(c => c == '#' ? 1 : 0).array[];\n\n writeln(b.all!\"a<=1\" ? \"Yes\" : \"No\");\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"A\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int h, w;\n sc.read(h, w);\n\n bool[][] g = new bool[][](h, w);\n foreach (i; 0..h) {\n string s;\n sc.read(s);\n foreach (j; 0..w) {\n g[i][j] = (s[j] == '#');\n }\n }\n\n bool[][] g2 = new bool[][](h, w);\n\n foreach (i; 0..h) {\n foreach (j; 0..w) {\n if (!g[i][j]) continue;\n int[] hv, wv;\n foreach (i2; 0..h) {\n if (g[i2][j]) hv ~= i2;\n }\n foreach (j2; 0..w) {\n if (g[i][j2]) wv ~= j2;\n }\n\n foreach (i2; hv) {\n foreach (j2; wv) {\n g2[i2][j2] = true;\n }\n }\n }\n } \n\n foreach (i; 0..h) {\n foreach (j; 0..w) {\n if (g[i][j] != g2[i][j]) {\n writeln(\"No\");\n return 0;\n }\n }\n }\n writeln(\"Yes\");\n\n // foreach (v; g2) {\n // writeln(v.map!(x => x ? '#' : '.'));\n // }\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n void read(Args...)(auto ref Args args) {\n import std.exception;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}], "negative_code": [], "src_uid": "ac718922461f3187d8b7587c360b05fc"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto mx = new int[] (n+1);\n foreach (i; 1 .. n+1) { mx[i] = i; }\n \n struct UF {\n int[] p, r;\n \n this (int n) {\n p = new int[] (n+1);\n r = new int[] (n+1);\n foreach (i; 1 .. n+1) {\n p[i] = i;\n r[i] = 1;\n }\n }\n \n int fnd(int v) {\n if (p[v] != v) {\n p[v] = fnd(p[v]);\n }\n \n return p[v];\n }\n \n void uni(int a, int b) {\n a = fnd(a);\n b = fnd(b);\n \n if (a == b) { return; }\n \n if (r[a] > r[b]) { swap(a, b); }\n \n p[a] = b;\n \n if (r[a] == r[b]) { ++r[b]; }\n }\n }\n \n auto uf = UF(n);\n \n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n mx[u] = max(mx[u], v);\n mx[v] = max(mx[v], u);\n \n uf.uni(u, v);\n }\n \n int ans = 0;\n int le = 1;\n while (le <= n) {\n int r = mx[le];\n int p = le+1;\n while (p <= r) {\n if (uf.fnd(le) != uf.fnd(p)) {\n ans += 1;\n uf.uni(le, p);\n }\n r = max(r, mx[p]);\n ++p;\n }\n \n le = r + 1;\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nstruct UnionFind\n{\n\tvoid init(int n) { par = new int[](n); foreach (i; 0..n) par[i] = i; cnt = new int[](n); fill(cnt, 1); }\n\tint root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }\n\tbool same(int i, int j) { return root(i) == root(j); }\n\tvoid unite(int i, int j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; cnt[j] += cnt[i]; }\n\tint size(int i) { return cnt[root(i)]; }\n\tint[] par, cnt;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tUnionFind uf;\n\tuf.init(n);\n\tforeach (i; 0..m)\n\t{\n\t\tauto u = RD!int-1;\n\t\tauto v = RD!int-1;\n\t\tuf.unite(u, v);\n\t}\n\t\n\tauto r = new int[](n);\n\tauto lr = new int[][](n, 2);\n\tforeach (i; 0..n)\n\t\tlr[i][0] = int.max;\n\n\tforeach (i; 0..n)\n\t{\n\t\tauto p = uf.root(i);\n\t\tr[i] = p;\n\t\tlr[p][0] = min(lr[p][0], i);\n\t\tlr[p][1] = max(lr[p][1], i);\n\t}\n\n\tauto index = lr.MAKE_IDX!\"a[0] < b[0]\";\n\tauto rMax = new int[](n+1);\n\tforeach (i; 0..n)\n\t{\n\t\trMax[i+1] = max(rMax[i], lr[index[i]][1]);\n\t}\n\tlong ans;\n\tforeach (ii, i; index)\n\t{\n\t\tif (lr[i][0] == int.max) break;\n\t\tif (lr[i][0] < rMax[ii])\n\t\t\t++ans;\n\t}\n\t\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto G = new int[][](N);\n auto uf = new UnionFind(N);\n\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n auto a = s[0] - 1;\n auto b = s[1] - 1;\n G[a] ~= b;\n G[b] ~= a;\n uf.unite(a, b);\n }\n\n Tuple!(int, int)[] A;\n foreach (i; 0..N) if (uf.table[i] < 0) A ~= tuple(uf.mn[i], uf.mx[i]);\n\n A.sort!\"a[0] < b[0]\";\n auto t = A.front;\n int ans = 0;\n\n foreach (i; 1..A.length.to!int) {\n if (A[i][0] > t[1]) {\n t = A[i];\n } else {\n ans += 1;\n t[1] = max(t[1], A[i][1]);\n }\n }\n\n ans.writeln;\n}\n\nclass UnionFind {\n import std.algorithm : swap;\n\n int n;\n int[] table;\n int[] mn;\n int[] mx;\n\n this(int n) {\n this.n = n;\n table = new int[](n);\n table[] = -1;\n mn = n.iota.array;\n mx = n.iota.array;\n }\n\n int find(int x) {\n return table[x] < 0 ? x : (table[x] = find(table[x]));\n }\n\n void unite(int x, int y) {\n int ox = x;\n int oy = y;\n x = find(x);\n y = find(y);\n mn[x] = min(mn[x], mn[y], ox, oy);\n mx[x] = max(mx[x], mx[y], ox, oy);\n if (x == y) return;\n if (table[x] > table[y]) swap(x, y);\n mn[x] = min(mn[x], mn[y], ox, oy);\n mx[x] = max(mx[x], mx[y], ox, oy);\n table[x] += table[y];\n table[y] = x;\n }\n\n bool same(int x, int y) {\n return find(x) == find(y);\n }\n}\n\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint, m = rint;\n\tNode[] nodes;\n\tforeach(i; 0 .. n) nodes ~= new Node(i, 0);\n\t\n\tX[] xs;\n\tforeach(j; 0 .. m){\n\t\tint a = rint - 1, b = rint - 1;\n\t\tif(a < b) xs ~= X(a, b);\n\t\telse xs ~= X(b, a);\n\t}\n\tlog(\"xs:\", xs);\n\t\n\tint[] us = new int[](n + 9);\n\tforeach(x; xs) us[x.a] += 1, us[x.b] -= 1;\n\tlog(\"us:\", us);\n\t\n\tint rangecount;\n\tint sum;\n\tforeach(i; 0 .. n){\n\t\tif(sum == 0 && us[i] > 0) rangecount += 1;\n\t\tif(sum > 0 || sum + us[i] > 0) nodes[i].value = 1;\n\t\tsum += us[i];\n\t}\n\tlog(\"rangecount:\", rangecount);\n\t\n\tforeach(x; xs) nodes[x.a].group.eat(nodes[x.b].group);\n\tint groupcount;\n\tforeach(nd; nodes){\n\t\tif(nd.value > 0 && nd.group.id == nd.id) groupcount += 1;\n\t}\n\tlog(\"groupcount:\", groupcount);\n\t\n\tint ans = groupcount - rangecount;\n\tans.writeln;\n\t\n}\nstruct X{\n\tint a, b;\n}\n/*\n\ncount how many distinct segment unions.\ncount how many connected subgraphs.\n\n*/\n\n\n// Union-Find \u6574\u7406\u3055\u308c\u3066\u3044\u308b\u3082\u306e \u203bEdge\u306f\u4f7f\u308f\u306a\u304f\u3066\u3082\u3088\u3044\n// \u4f7f\u3044\u65b9\u306f nd1.group.eat(nd2.group);\nclass Edge{\n\tNode node1;\n\tNode node2;\n\tlong value;\n\tthis(Node node1, Node node2, long value){\n\t\tthis.node1 = node1, this.node2 = node2;\n\t\tthis.value = value;\n\t}\n}\n\nclass Node{\n\tlong id;\n\tlong value;\n\tGroup group;\n\tthis(long id, long value){\n\t\tthis.id = id;\n\t\tthis.value = value;\n\t\tthis.group = new Group(this);\n\t}\n}\n\nclass Group{\n\tlong value;\n\tlong id;\n\tNode[] nodes;\n\tthis(Node node){\n\t\tthis.id = node.id;\n\t\tthis.nodes = [node];\n\t\tthis.value = node.value;\n\t}\n\tvoid eat(Group gp){\n\t\tif(this.id == gp.id) return;\n\t\tif(gp.nodes.length > this.nodes.length) gp.eat(this);\n\t\telse{\n\t\t\tforeach(nd; gp.nodes){\n\t\t\t\tthis.nodes ~= nd;\n\t\t\t\tnd.group = this;\n\t\t\t\tthis.value += nd.value;\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto G = new int[][](N);\n auto uf = new UnionFind(N);\n\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n auto a = s[0] - 1;\n auto b = s[1] - 1;\n G[a] ~= b;\n G[b] ~= a;\n uf.unite(a, b);\n }\n\n Tuple!(int, int)[] A;\n foreach (i; 0..N) if (uf.table[i] < 0) A ~= tuple(uf.mn[i], uf.mx[i]);\n\n A.sort!\"a[0] < b[0]\";\n auto t = A.front;\n int ans = 0;\n\n foreach (i; 1..A.length.to!int) {\n if (A[i][0] > t[1]) {\n t = A[i];\n } else {\n ans += 1;\n t[1] = max(t[1], A[i][1]);\n }\n }\n\n ans.writeln;\n}\n\nclass UnionFind {\n import std.algorithm : swap;\n\n int n;\n int[] table;\n int[] mn;\n int[] mx;\n\n this(int n) {\n this.n = n;\n table = new int[](n);\n table[] = -1;\n mn = n.iota.array;\n mx = n.iota.array;\n }\n\n int find(int x) {\n return table[x] < 0 ? x : (table[x] = find(table[x]));\n }\n\n void unite(int x, int y) {\n int ox = x;\n int oy = y;\n x = find(x);\n y = find(y);\n mn[x] = min(mn[x], ox, oy);\n mx[x] = max(mx[x], ox, oy);\n if (x == y) return;\n if (table[x] > table[y]) swap(x, y);\n table[x] += table[y];\n table[y] = x;\n }\n\n bool same(int x, int y) {\n return find(x) == find(y);\n }\n}\n\n\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto G = new int[][](N);\n auto uf = new UnionFind(N);\n\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n auto a = s[0] - 1;\n auto b = s[1] - 1;\n G[a] ~= b;\n G[b] ~= a;\n uf.unite(a, b);\n }\n\n Tuple!(int, int)[] A;\n foreach (i; 0..N) if (uf.table[i] < 0) A ~= tuple(uf.mn[i], uf.mx[i]);\n\n A.sort!\"a[0] < b[0]\";\n auto t = A.front;\n int ans = 0;\n\n foreach (i; 1..A.length.to!int) {\n if (A[i][0] > t[1]) {\n t = A[i];\n } else {\n ans += 1;\n t[1] = A[i][1];\n }\n }\n\n ans.writeln;\n}\n\nclass UnionFind {\n import std.algorithm : swap;\n\n int n;\n int[] table;\n int[] mn;\n int[] mx;\n\n this(int n) {\n this.n = n;\n table = new int[](n);\n table[] = -1;\n mn = n.iota.array;\n mx = n.iota.array;\n }\n\n int find(int x) {\n return table[x] < 0 ? x : (table[x] = find(table[x]));\n }\n\n void unite(int x, int y) {\n int ox = x;\n int oy = y;\n x = find(x);\n y = find(y);\n if (x == y) return;\n if (table[x] > table[y]) swap(x, y);\n mn[x] = min(mn[x], ox, oy);\n mx[x] = max(mx[x], ox, oy);\n table[x] += table[y];\n table[y] = x;\n }\n\n bool same(int x, int y) {\n return find(x) == find(y);\n }\n}\n\n\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto G = new int[][](N);\n auto uf = new UnionFind(N);\n\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n auto a = s[0] - 1;\n auto b = s[1] - 1;\n G[a] ~= b;\n G[b] ~= a;\n uf.unite(a, b);\n }\n\n Tuple!(int, int)[] A;\n foreach (i; 0..N) if (uf.table[i] < 0) A ~= tuple(uf.mn[i], uf.mx[i]);\n\n A.sort!\"a[0] < b[0]\";\n auto t = A.front;\n int ans = 0;\n\n foreach (i; 1..A.length.to!int) {\n if (A[i][0] > t[1]) {\n t = A[i];\n } else {\n ans += 1;\n t[1] = max(t[1], A[i][1]);\n }\n }\n\n ans.writeln;\n}\n\nclass UnionFind {\n import std.algorithm : swap;\n\n int n;\n int[] table;\n int[] mn;\n int[] mx;\n\n this(int n) {\n this.n = n;\n table = new int[](n);\n table[] = -1;\n mn = n.iota.array;\n mx = n.iota.array;\n }\n\n int find(int x) {\n return table[x] < 0 ? x : (table[x] = find(table[x]));\n }\n\n void unite(int x, int y) {\n int ox = x;\n int oy = y;\n x = find(x);\n y = find(y);\n if (x == y) return;\n if (table[x] > table[y]) swap(x, y);\n mn[x] = min(mn[x], ox, oy);\n mx[x] = max(mx[x], ox, oy);\n table[x] += table[y];\n table[y] = x;\n }\n\n bool same(int x, int y) {\n return find(x) == find(y);\n }\n}\n\n\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto G = new int[][](N);\n auto uf = new UnionFind(N);\n\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n auto a = s[0] - 1;\n auto b = s[1] - 1;\n G[a] ~= b;\n G[b] ~= a;\n uf.unite(a, b);\n }\n\n Tuple!(int, int)[] A;\n foreach (i; 0..N) if (uf.table[i] < 0) A ~= tuple(uf.mn[i], uf.mx[i]);\n\n A.sort!\"a[0] < b[0]\";\n auto t = A.front;\n int ans = 0;\n\n foreach (i; 1..A.length.to!int) {\n if (A[i][0] > t[1]) {\n t = A[i];\n } else {\n ans += 1;\n t[1] = max(t[1], A[i][1]);\n }\n }\n\n ans.writeln;\n}\n\nclass UnionFind {\n import std.algorithm : swap;\n\n int n;\n int[] table;\n int[] mn;\n int[] mx;\n\n this(int n) {\n this.n = n;\n table = new int[](n);\n table[] = -1;\n mn = n.iota.array;\n mx = n.iota.array;\n }\n\n int find(int x) {\n return table[x] < 0 ? x : (table[x] = find(table[x]));\n }\n\n void unite(int x, int y) {\n int ox = x;\n int oy = y;\n x = find(x);\n y = find(y);\n mn[x] = min(mn[x], ox, oy);\n mx[x] = max(mx[x], ox, oy);\n if (x == y) return;\n if (table[x] > table[y]) swap(x, y);\n mn[x] = min(mn[x], ox, oy);\n mx[x] = max(mx[x], ox, oy);\n table[x] += table[y];\n table[y] = x;\n }\n\n bool same(int x, int y) {\n return find(x) == find(y);\n }\n}\n\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint, m = rint;\n\tNode[] nodes;\n\tforeach(i; 0 .. n) nodes ~= new Node(i, 0);\n\t\n\tX[] xs;\n\tforeach(j; 0 .. m){\n\t\txs ~= X(rint - 1, rint - 1);\n\t}\n\tlog(\"xs:\", xs);\n\t\n\tforeach(x; xs){\n\t\tnodes[x.a].value = 1;\n\t\tnodes[x.b].value = 1;\n\t\tnodes[x.a].group.eat(nodes[x.b].group);\n\t}\n\tint groupcount;\n\tforeach(nd; nodes){\n\t\tif(nd.value > 0 && nd.group.id == nd.id) groupcount += 1;\n\t}\n\tlog(\"groupcount:\", groupcount);\n\t\n\tint[] us = new int[](n + 9);\n\tforeach(x; xs) us[x.a] += 1, us[x.b] -= 1;\n\tlog(\"us:\", us);\n\t\n\tint rangecount;\n\tint sum;\n\tforeach(i; 0 .. n){\n\t\tif(sum == 0 && us[i] > 0) rangecount += 1;\n\t\tsum += us[i];\n\t}\n\tlog(\"rangecount:\", rangecount);\n\t\n\tint ans = groupcount - rangecount;\n\tans.writeln;\n\t\n}\nstruct X{\n\tint a, b;\n}\n/*\n\ncount how many distinct segment unions.\ncount how many connected subgraphs.\n\n*/\n\n\n// Union-Find \u6574\u7406\u3055\u308c\u3066\u3044\u308b\u3082\u306e \u203bEdge\u306f\u4f7f\u308f\u306a\u304f\u3066\u3082\u3088\u3044\n// \u4f7f\u3044\u65b9\u306f nd1.group.eat(nd2.group);\nclass Edge{\n\tNode node1;\n\tNode node2;\n\tlong value;\n\tthis(Node node1, Node node2, long value){\n\t\tthis.node1 = node1, this.node2 = node2;\n\t\tthis.value = value;\n\t}\n}\n\nclass Node{\n\tlong id;\n\tlong value;\n\tGroup group;\n\tthis(long id, long value){\n\t\tthis.id = id;\n\t\tthis.value = value;\n\t\tthis.group = new Group(this);\n\t}\n}\n\nclass Group{\n\tlong value;\n\tlong id;\n\tNode[] nodes;\n\tthis(Node node){\n\t\tthis.id = node.id;\n\t\tthis.nodes = [node];\n\t\tthis.value = node.value;\n\t}\n\tvoid eat(Group gp){\n\t\tif(this.id == gp.id) return;\n\t\tif(gp.nodes.length > this.nodes.length) gp.eat(this);\n\t\telse{\n\t\t\tforeach(nd; gp.nodes){\n\t\t\t\tthis.nodes ~= nd;\n\t\t\t\tnd.group = this;\n\t\t\t\tthis.value += nd.value;\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint, m = rint;\n\tNode[] nodes;\n\tforeach(i; 0 .. n) nodes ~= new Node(i, 0);\n\t\n\tX[] xs;\n\tforeach(j; 0 .. m){\n\t\txs ~= X(rint - 1, rint - 1);\n\t}\n\tlog(\"xs:\", xs);\n\t\n\tint[] us = new int[](n + 9);\n\tforeach(x; xs) us[x.a] += 1, us[x.b] -= 1;\n\tlog(\"us:\", us);\n\t\n\tint rangecount;\n\tint sum;\n\tforeach(i; 0 .. n){\n\t\tif(sum == 0 && us[i] > 0) rangecount += 1;\n\t\tif(sum > 0 || sum + us[i] > 0) nodes[i].value = 1;\n\t\tsum += us[i];\n\t}\n\tlog(\"rangecount:\", rangecount);\n\t\n\tforeach(x; xs) nodes[x.a].group.eat(nodes[x.b].group);\n\tint groupcount;\n\tforeach(nd; nodes){\n\t\tif(nd.value > 0 && nd.group.id == nd.id) groupcount += 1;\n\t}\n\tlog(\"groupcount:\", groupcount);\n\t\n\tint ans = groupcount - rangecount;\n\tans.writeln;\n\t\n}\nstruct X{\n\tint a, b;\n}\n/*\n\ncount how many distinct segment unions.\ncount how many connected subgraphs.\n\n*/\n\n\n// Union-Find \u6574\u7406\u3055\u308c\u3066\u3044\u308b\u3082\u306e \u203bEdge\u306f\u4f7f\u308f\u306a\u304f\u3066\u3082\u3088\u3044\n// \u4f7f\u3044\u65b9\u306f nd1.group.eat(nd2.group);\nclass Edge{\n\tNode node1;\n\tNode node2;\n\tlong value;\n\tthis(Node node1, Node node2, long value){\n\t\tthis.node1 = node1, this.node2 = node2;\n\t\tthis.value = value;\n\t}\n}\n\nclass Node{\n\tlong id;\n\tlong value;\n\tGroup group;\n\tthis(long id, long value){\n\t\tthis.id = id;\n\t\tthis.value = value;\n\t\tthis.group = new Group(this);\n\t}\n}\n\nclass Group{\n\tlong value;\n\tlong id;\n\tNode[] nodes;\n\tthis(Node node){\n\t\tthis.id = node.id;\n\t\tthis.nodes = [node];\n\t\tthis.value = node.value;\n\t}\n\tvoid eat(Group gp){\n\t\tif(this.id == gp.id) return;\n\t\tif(gp.nodes.length > this.nodes.length) gp.eat(this);\n\t\telse{\n\t\t\tforeach(nd; gp.nodes){\n\t\t\t\tthis.nodes ~= nd;\n\t\t\t\tnd.group = this;\n\t\t\t\tthis.value += nd.value;\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "src_uid": "04fd1a55027cce56a491b984ce3a1d6d"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int NA = -1;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto x = a.count !(v => v % 2 == 0).to !(int);\r\n\t\tauto y = n - x;\r\n\t\tdebug {writeln (x, \" \", y);}\r\n\t\tauto f = new int [2] [] [] (x + 1, y + 1);\r\n\t\tforeach (ref g; f)\r\n\t\t{\r\n\t\t\tforeach (ref h; g)\r\n\t\t\t{\r\n\t\t\t\th[] = NA;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint go (int i, int j, int b)\r\n\t\t{\r\n\t\t\tif (f[i][j][b] == NA)\r\n\t\t\t{\r\n\t\t\t\tif (i == x && j == y)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn !b ^ ((i + j) & 1);\r\n\t\t\t\t}\r\n\t\t\t\tint res = 0;\r\n\t\t\t\tif (i < x)\r\n\t\t\t\t{\r\n\t\t\t\t\tres |= !go (i + 1, j, b);\r\n\t\t\t\t}\r\n\t\t\t\tif (j < y)\r\n\t\t\t\t{\r\n\t\t\t\t\tres |= !go (i, j + 1,\r\n\t\t\t\t\t !b ^ ((i + j) & 1));\r\n\t\t\t\t}\r\n\t\t\t\tf[i][j][b] = res;\r\n\t\t\t}\r\n\t\t\treturn f[i][j][b];\r\n\t\t}\r\n\r\n\t\twriteln (go (0, 0, 0) ? \"Alice\" : \"Bob\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto A = readln.chomp.split(\" \").map!(to!int).array;\r\n\r\n auto init = tuple(0, 0);\r\n foreach (a; A) {\r\n if (a % 2 == 0) {\r\n init[0]++;\r\n } else {\r\n init[1]++;\r\n }\r\n }\r\n\r\n bool[Tuple!(int,int,int,int)] cache;\r\n int f(int p, int s, int e, int o) {\r\n // p: 0:alice, 1:bob\r\n // s: alice's hand\r\n auto key = tuple(p, s, e, o);\r\n if (key in cache) return cache[key];\r\n if (e == 0 && o == 0) {\r\n return (p == 0 && s == 0) || (p == 1 && s == 1);\r\n }\r\n if (p == 0) {\r\n bool a_win = false;\r\n // alice's turn\r\n if (e >= 1) { a_win = a_win || !f(!p, s, e-1, o); }\r\n if (o >= 1) { a_win = a_win || !f(!p, !s, e, o-1); }\r\n return cache[key] = a_win;\r\n } else {\r\n bool b_win = false;\r\n if (e >= 1) { b_win = b_win || !f(!p, s, e-1, o); }\r\n if (o >= 1) { b_win = b_win || !f(!p, s, e, o-1); }\r\n return cache[key] = b_win;\r\n }\r\n }\r\n writeln(f(0, 0, init[0], init[1]) ? \"Alice\" : \"Bob\");\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nenum LIM = 105;\r\n\r\nvoid main() {\r\n auto ali = new bool[][][](LIM, LIM, 2);\r\n auto bob = new bool[][][](LIM, LIM, 2);\r\n foreach (m; 0 .. LIM) foreach (n; 0 .. LIM) foreach (s; 0 .. 2) {\r\n if (m == 0 && n == 0) {\r\n ali[m][n][s] = (s == 0);\r\n bob[m][n][s] = (s != 0);\r\n } else {\r\n if (m > 0 && !bob[m - 1][n][s ^ 0]) ali[m][n][s] = true;\r\n if (n > 0 && !bob[m][n - 1][s ^ 1]) ali[m][n][s] = true;\r\n if (m > 0 && !ali[m - 1][n][s]) bob[m][n][s] = true;\r\n if (n > 0 && !ali[m][n - 1][s]) bob[m][n][s] = true;\r\n }\r\n }\r\n debug {\r\n foreach (m; 0 .. 10) write(m, \": \", ali[m]);\r\n foreach (m; 0 .. 10) write(m, \": \", bob[m]);\r\n }\r\n \r\n try {\r\n for (; ; ) {\r\n const numCases = readInt;\r\n foreach (caseId; 0 .. numCases) {\r\n const N = readInt;\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt;\r\n }\r\n \r\n int[2] cnt;\r\n foreach (i; 0 .. N) {\r\n ++cnt[A[i] & 1];\r\n }\r\n const ans = ali[cnt[0]][cnt[1]][0];\r\n writeln(ans ? \"Alice\" : \"Bob\");\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto x = a.count !(v => v % 2 == 0).to !(int);\r\n\t\tauto y = n - x;\r\n\t\tdebug {writeln (x, \" \", y);}\r\n\t\tauto f = new bool [2] [] [] (x + 1, y + 1);\r\n\t\tf[x][y][0] = true;\r\n\t\tforeach_reverse (t; 0..x + y)\r\n\t\t{\r\n\t\t\tforeach (i; 0..x + 1)\r\n\t\t\t{\r\n\t\t\t\tint j = t - x;\r\n\t\t\t\tif (!(0 <= j && j <= y))\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tforeach (b; 0..2)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (t & 1) // Bob moves\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tf[i][j][b] = true;\r\n\t\t\t\t\t\tif (i < x)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tf[i][j][b] &= f[i + 1][j][b ^ 0];\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (j < y)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tf[i][j][b] &= f[i][j + 1][b ^ 0];\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse // Alice moves\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tf[i][j][b] = false;\r\n\t\t\t\t\t\tif (i < x)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tf[i][j][b] |= f[i + 1][j][b ^ 0];\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (j < y)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tf[i][j][b] |= f[i][j + 1][b ^ 1];\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tdebug {writefln !(\"%(%(%(%d%) %)\\n%)\") (f);}\r\n\t\twriteln (f[0][0][0] ? \"Alice\" : \"Bob\");\r\n\t}\r\n}\r\n"}], "src_uid": "d0c9f2f2037d093762fb87206f396850"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto s = a.sum;\n\t\tans[i] = s / n + (s % n != 0 ? 1 : 0);\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\treadf(\" %d\", &a);\n\t\tint sum=0;\n\t\tfor (int j=0; j<a; j++)\n\t\t{\n\t\t\tint b=0;\n\t\t\treadf(\" %d\", &b);\n\t\t\tsum=sum+b;\n\t\t}\n\t\tif (sum%a==0)\n\t\t{\n\t\t\twriteln(sum/a);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(sum/a+1);\n\t\t}\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "c457b77b16d94c6c4c95b7403a1dd0c7"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n if (A.sum % 2 == 1) {\n writeln(\"NO\");\n return;\n }\n\n if (A.reduce!max > A.sum - A.reduce!max) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.format;\n\nconst int MAX_N = 100000;\nint n;\n\nvoid main() {\n readln.strip.formattedRead(\" %s\", n);\n\n auto a = readln.strip.split.map!(a => parse!long(a));\n\n long total = a.sum;\n\n bool ok = total % 2 == 0;\n\n ok &= a.all!(v => v*2 <= total);\n\n if (ok) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n}\n"}], "negative_code": [], "src_uid": "52f4f2a48063c9d0e412a5f78c873e6f"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto s = new char [n];\n\t\tif (k > n)\n\t\t{\n\t\t\ts = cast (char []) \"-1\";\n\t\t}\n\t\telse if (k == 1)\n\t\t{\n\t\t\tif (n == 1)\n\t\t\t{\n\t\t\t\ts = cast (char []) \"a\";\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ts = cast (char []) \"-1\";\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\ts[i] = 'a' + (i & 1);\n\t\t\t}\n\t\t\tforeach (i; 0..k - 2)\n\t\t\t{\n\t\t\t\ts[$ - 1 - i] = cast (char) ('a' + (k - 1 - i));\n\t\t\t}\n\t\t}\n\t\twriteln (s);\n\t}\n}\n", "positive_code": [{"source_code": "module sigod.codeforces.p289C;\n\nimport std.array;\nimport std.stdio;\n\nvoid main()\n{\n\tint n, k;\n\tstdin.readf(\"%s %s\", &n, &k);\n\t\n\tstdout.writeln(solve(n, k));\n}\n\nstring solve(int n, int k)\n{\n\tif (n < k) return \"-1\";\n\tif (k == 1) {\n\t\tif (n == 1) return \"a\";\n\t\telse return \"-1\";\n\t}\n\n\tauto result = appender!string();\n\tresult.reserve(n);\n\n\tint g = n - max(k - 2, 0);\n\n\tforeach (i; 0 .. g / 2) {\n\t\tresult.put(\"ab\");\n\t}\n\n\tif (g % 2 != 0) result.put('a');\n\n\tforeach (i; 99 .. 99 + max(k - 2, 0)) {\n\t\tresult.put(cast(char) i);\n\t}\n\n\treturn result.data();\n}\n\nunittest {\n\tassert(solve(7, 4) == \"ababacd\");\n\tassert(solve(4, 7) == \"-1\");\n}\n\npure int max(int a, int b)\n{\n\tif (a > b) return a;\n\telse return b;\n}"}], "negative_code": [], "src_uid": "2f659be28674a81f58f5c587b6a0f465"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new double[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort;\r\n\r\n\t\tans[ti] = cast(double)(a[0..$-1].sum) / (n-1);\r\n\t\tans[ti] += a[$-1];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twritefln(FMT_F, e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "\nimmutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto a = ra!long;\n\tsort(a);\n\tauto sp = a.sum;\n\tdouble ans = -1e11;\n\tlong ss = 0;\n\tint pl = cast(int)a.length;\n\tforeach_reverse(ai; a)\n\t{\n\t\tsp -= ai;\n\t\tss += ai;\n\t\tpl--;\n\t\tif (pl > 0)\n\t\tans = max(ans, sp/(cast(double)pl) + ss/(cast(double)(a.length - pl)));\n\t}\n\twritef!\"%.12s\\n\"(ans);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [{"source_code": "\nimmutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto a = ra!long;\n\tsort(a);\n\tauto sp = a.sum;\n\tdouble ans = -1e11;\n\tlong ss = 0;\n\tint pl = cast(int)a.length;\n\tforeach_reverse(ai; a)\n\t{\n\t\tsp -= ai;\n\t\tss += ai;\n\t\tpl--;\n\t\tif (pl > 0)\n\t\tans = max(ans, sp/(cast(double)pl) + ss/(cast(double)(a.length - pl)));\n\t}\n\tans.writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "159b9c743d6d8792548645b9f7be2753"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int n, k; get(n, k);\r\n if (n % 2 == 0) {\r\n writeln((k - 1) % n + 1);\r\n } else if (k <= n) {\r\n writeln(k == n ? 2 : k + (k >= (n+1)/2 ? 1 : 0));\r\n } else {\r\n --k;\r\n auto p = (k / n) % (n / 2) * 2;\r\n k %= n;\r\n auto d = (n - p - 1) / 2;\r\n writeln((p + k + (k >= d + n/2 ? 2 : k >= d ? 1 : 0)) % n + 1);\r\n }\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\t\r\n\t\tif (n % 2)\r\n\t\t{\r\n\t\t\tauto loop = n / 2;\r\n\t\t\tauto x = (k-1) / loop;\r\n\t\t\tans[ti] = (k-1+x) % n + 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tans[ti] = (k-1) % n + 1;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\twriteln ((k - 1 + ((n & 1) ? (k - 1) / (n / 2) : 0)) % n + 1);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int n, k; get(n, k);\r\n if (n % 2 == 0) {\r\n writeln((k - 1) % n + 1);\r\n } else if (k <= n) {\r\n writeln(k == n ? 2 : k + (k >= (n+1)/2 ? 1 : 0));\r\n } else {\r\n --k;\r\n auto p = (k / n) % (n / 2) * 2;\r\n k %= n;\r\n auto d = (n - p - 1) / 2;\r\n writeln((p + k + (k >= n-1 ? 2 : k >= d ? 1 : 0)) % n + 1);\r\n }\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int n, k; get(n, k);\r\n if (n % 2 == 0) {\r\n writeln((k - 1) % n + 1);\r\n } else if (k <= n) {\r\n writeln(k == n ? 2 : k + (k >= (n+1)/2 ? 1 : 0));\r\n } else {\r\n --k;\r\n auto p = (k / n) % (n / 2) * 2;\r\n k %= n;\r\n auto d = (n - p) / 2;\r\n writeln((p + k + (k >= n-1 ? 2 : k >= d ? 1 : 0)) % n + 1);\r\n }\r\n }\r\n}"}], "src_uid": "2e837d3afc48177516578a950e957586"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nbool solve (int n, int k, int [] s)\r\n{\r\n\tif (k == 1)\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n\tif (k == n)\r\n\t{\r\n\t\ts = [0] ~ s;\r\n\t\tk += 1;\r\n\t}\r\n\tauto a = new long [n];\r\n\tforeach (i; 1..k)\r\n\t{\r\n\t\ta[n - i] = s[k - i] - s[k - i - 1];\r\n\t}\r\n\tforeach (i; k..n + 1)\r\n\t{\r\n\t\ta[n - i] = a[n - i + 1];\r\n\t}\r\n\tauto total = sum (a);\r\n\tdebug {writeln (a, \" \", total);}\r\n\tif (k == n && total != s.back)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\treturn (total >= s.back && isSorted (a));\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto s = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (n, k, s) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nint N, K;\r\nlong[] S;\r\n\r\nbool solve() {\r\n if (K == 1) {\r\n return true;\r\n }\r\n auto as = new long[N + 1];\r\n foreach_reverse (i; N - K + 1 .. N) {\r\n as[i] = S[i + 1] - S[i];\r\n }\r\n foreach_reverse (i; 0 .. N - K + 1) {\r\n as[i] = as[i + 1];\r\n }\r\n debug {\r\n writeln(\"K = \", K);\r\n writeln(\"S = \", S);\r\n writeln(\"as = \", as);\r\n }\r\n foreach (i; 0 .. N - 1) {\r\n if (!(as[i] <= as[i + 1])) {\r\n return false;\r\n }\r\n }\r\n const S0 = S[N] - as.sum;\r\n return (S0 <= 0);\r\n}\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const numCases = readInt;\r\n foreach (caseId; 0 .. numCases) {\r\n N = readInt;\r\n K = readInt;\r\n S = new long[N + 1];\r\n foreach (i; N - K + 1 .. N + 1) {\r\n S[i] = readLong;\r\n }\r\n \r\n const ans = solve;\r\n writeln(ans ? \"YES\" : \"NO\");\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nbool solve (int n, int k, int [] s)\r\n{\r\n\tif (k == 1)\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n\tauto a = new long [n];\r\n\tforeach (i; 1..k)\r\n\t{\r\n\t\ta[n - i] = s[k - i] - s[k - i - 1];\r\n\t}\r\n\tforeach (i; k..n + 1)\r\n\t{\r\n\t\ta[n - i] = a[n - i + 1];\r\n\t}\r\n\tauto total = sum (a);\r\n\tdebug {writeln (a, \" \", total);}\r\n\tif (k == n && total != s.back)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\treturn (total >= s.back && isSorted (a));\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto s = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (n, k, s) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nint N, K;\r\nlong[] S;\r\n\r\nbool solve() {\r\n if (K == 1) {\r\n return true;\r\n }\r\n auto as = new long[N + 1];\r\n foreach_reverse (i; N - K + 1 .. N) {\r\n as[i] = S[i + 1] - S[i];\r\n }\r\n foreach_reverse (i; 0 .. N - K + 1) {\r\n as[i] = as[i + 1];\r\n }\r\n debug {\r\n writeln(\"K = \", K);\r\n writeln(\"S = \", S);\r\n writeln(\"as = \", as);\r\n }\r\n const S0 = S[N] - as.sum;\r\n return (S0 <= 0);\r\n}\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const numCases = readInt;\r\n foreach (caseId; 0 .. numCases) {\r\n N = readInt;\r\n K = readInt;\r\n S = new long[N + 1];\r\n foreach (i; N - K + 1 .. N + 1) {\r\n S[i] = readLong;\r\n }\r\n \r\n const ans = solve;\r\n writeln(ans ? \"YES\" : \"NO\");\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "src_uid": "9edbe28b5be43a9cc6c633db98bc5a36"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tforeach (c; s)\r\n\t\t{\r\n\t\t\tif (c == 'U')\r\n\t\t\t\tans[ti] ~= \"D\";\r\n\t\t\telse if (c == 'L')\r\n\t\t\t\tans[ti] ~= \"L\";\r\n\t\t\telse if (c == 'R')\r\n\t\t\t\tans[ti] ~= \"R\";\r\n\t\t\telse\r\n\t\t\t\tans[ti] ~= \"U\";\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto grid = readString;\n\tstring ans;\n\tint i = 0;\n\twhile (i < n)\n\t{\n\t\tswitch(grid[i])\n\t\t{\n\t\tcase 'U':\n\t\t\tans ~= 'D';\n\t\t\tbreak;\n\t\tcase 'D':\n\t\t\tans ~= 'U';\n\t\t\tbreak;\n\t\tcase 'L':\n\t\t\tans ~= \"LR\";\n\t\t\ti++;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tassert(0);\n\t\t}\n\t\ti++;\n\t}\n\tassert(ans.length == grid.length);\n\twriteln(ans);\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto s = readln.strip;\n char[] s2;\n foreach (ch ; s) {\n if (ch == 'R')\n s2 ~= 'R';\n else if (ch == 'L')\n s2 ~= 'L';\n else if (ch == 'U')\n s2 ~= 'D';\n else\n s2 ~= 'U';\n }\n writeln(s2.idup);\n }\n}\n"}], "negative_code": [], "src_uid": "b894e16e8c00f8d97fde4a104466b3ef"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto p = n.iota.array;\n\t\tmakeIndex (a, p);\n\t\tif (a[p[0]] + a[p[1]] <= a[p[$ - 1]])\n\t\t{\n\t\t\tauto q = [p[0], p[1], p[$ - 1]];\n\t\t\tsort (q);\n\t\t\tq[] += 1;\n\t\t\twritefln !(\"%(%s %)\") (q);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1398/problem/A\n// math\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\n while(t--) {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n\n if(a[$-1] >= a[0] + a[1])\n writefln(\"1 2 %s\", n);\n else\n \"-1\".writeln;\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\tif (a[0]+a[1] > a[$-1])\n\t\t\tcontinue;\n\t\tans[ti] = [1, 2, n];\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\twriteln(e[0], \" \", e[1], \" \", e[2]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1398/problem/A\n// math\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n\n while(t--) {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n\n if(a[$-1] > a[0] + a[1])\n writefln(\"1 2 %s\", n);\n else\n \"-1\".writeln;\n }\n}\n\n"}], "src_uid": "341555349b0c1387334a0541730159ac"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto a = ma(n, readInt!int);\n int height = 1;\n foreach(i, ai; a)\n {\n final switch(ai)\n\t{\n\tcase 0:\n\t if (i > 0 && a[i-1] == 0) return writeln(-1);\n\t break;\n\tcase 1:\n\t if (i > 0 && a[i-1] == 1) height += 5;\n\t else height += 1;\n\t break;\n\t}\n }\n height.writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std;\r\nvoid main() {\r\n\tauto t = readln.strip.to!int;\r\n\tAttempt: foreach(tt; 0 .. t) {\r\n\t\tuint cm = 1;\r\n\t\treadln;\r\n\t\tauto ai = readln.split.to!(int[]);\r\n\t\tif(ai[0] == 1) {\r\n\t\t\tcm++;\r\n\t\t}\r\n\t\tif(ai.length >= 2) {\r\n\t\t\tforeach(i, a; ai[1 .. $]) {\r\n\t\t\t\tif(a == 0 && ai[i] == 0) {\r\n\t\t\t\t\twriteln(\"-1\");\r\n\t\t\t\t\tcontinue Attempt;\r\n\t\t\t\t} else if(a == 1 && ai[i] == 1) {\r\n\t\t\t\t\tcm += 5;\r\n\t\t\t\t} else if(a == 1) {\r\n\t\t\t\t\tcm++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln(cm);\r\n\t}\r\n}"}], "negative_code": [{"source_code": "import std;\r\nvoid main() {\r\n\twriteln(\"started\");\r\n\tauto t = readln.strip.to!int;\r\n\tAttempt: foreach(tt; 0 .. t) {\r\n\t\tuint cm = 1;\r\n\t\treadln;\r\n\t\tauto ai = readln.split.to!(int[]);\r\n\t\tif(ai[0] == 1) {\r\n\t\t\tcm++;\r\n\t\t}\r\n\t\tif(ai.length >= 2) {\r\n\t\t\tforeach(i, a; ai[1 .. $]) {\r\n\t\t\t\tif(a == 0 && ai[i] == 0) {\r\n\t\t\t\t\twriteln(\"-1\");\r\n\t\t\t\t\tcontinue Attempt;\r\n\t\t\t\t} else if(a == 1 && ai[i] == 1) {\r\n\t\t\t\t\tcm += 5;\r\n\t\t\t\t} else if(a == 1) {\r\n\t\t\t\t\tcm++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln(cm);\r\n\t}\r\n}"}], "src_uid": "d3aa0632053634e0602b995cfb476d83"} {"source_code": "import std.stdio, std.range, std.conv, std.algorithm, std.string;\nimport std.regex, std.math;\n\nvoid main() {\n int n = readln.chomp.to!int;\n auto rc = regex(r\"^R(\\d+)C(\\d+)$\");\n auto alnum = regex(r\"^([A-Z]+)(\\d+)$\");\n\n foreach (i; 0..n) {\n string coord = readln.chomp;\n auto rccap = coord.matchFirst(rc);\n if (!rccap.empty) {\n int row = rccap[1].to!int;\n int col = rccap[2].to!int;\n auto newcol = numToAl(col);\n writeln(newcol ~ rccap[1]);\n } else {\n auto alnumcap = coord.matchFirst(alnum);\n writeln(\"R\" ~ alnumcap[2] ~ \"C\" ~ alToNum(alnumcap[1]).to!string);\n }\n }\n}\n\nint alToNum(string row) {\n int ans;\n\n foreach (int i, c; (cast(char[])row).reverse) {\n int al = c - 'A' + 1;\n ans += al * pow(26, i);\n }\n\n return ans;\n}\n\nchar[] numToAl(int row) {\n char[] ans;\n while (row > 0) {\n ans ~= ((row - 1) % 26) + 'A';\n row = (row - 1) / 26;\n }\n return ans.reverse;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.regex, std.conv;\n\nstatic immutable string excelMap = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\nstatic immutable int base = excelMap.length;\n\nulong excelToDec(string excel) {\n ulong dec = 0, pow = 1;\n\n for (int i = excel.length-1; i >= 0; --i) {\n dec += (excel[i]-'A'+1) * pow;\n pow *= base;\n }\n\n return dec;\n}\n\nstring decToExcel(ulong dec) {\n string s;\n\n while (dec) {\n s = cast(char)(excelMap[--dec%base]) ~ s;\n dec /= base;\n }\n\n return s;\n}\n\nvoid main() {\n int n;\n readf(\"%d\\n\", &n);\n\n for (int i = 0; i < n; ++i) {\n auto s = readln();\n auto m = match(s, r\"^R([0-9]+)C([0-9]+)\");\n if (m) {\n writefln(\"%s%s\", decToExcel(to!int(m.captures[2])), m.captures[1]);\n } else {\n m = match(s, r\"^([A-Z]+)([0-9]+)\");\n writefln(\"R%sC%s\", m.captures[2], excelToDec(m.captures[1]));\n }\n }\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\n\nvoid tr1(in string s) {\n int r, c;\n s.ptr.sscanf(\"R%dC%d\".ptr, &r, &c);\n char[] cs;\n while (c > 0) {\n if (c % 26 == 0) {\n cs ~= 'Z';\n c = (c - 26) / 26;\n } else {\n cs ~= ('A' + c % 26 - 1);\n c /= 26;\n }\n }\n cs.reverse();\n writef(\"%s%d\\n\", cs, r);\n}\n\nvoid tr2(in string s) {\n auto m = s.match(regex(\"([A-Z]+)([0-9]+)\")).captures;\n auto cs = m[1], rs = m[2];\n int t = 0;\n foreach (i, c; cs) {\n t = t * 26 + c - 'A' + 1;\n }\n writef(\"R%sC%d\\n\", rs, t);\n}\n\nvoid tr(in string s) {\n if (!s.match(regex(\"R[0-9]+C[0-9]+\")).empty()) {\n //if (s[0] == 'R') {\n tr1(s);\n } else {\n tr2(s);\n }\n}\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n foreach (_; 0 .. n) {\n tr(stdin.readln());\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nstruct Cell\n{\n\tpublic int column;\n\tpublic int row;\n\n\tpublic int from_string(string col)\n\t{\n\t\tint res = 0;\n\t\tfor (int i = col.length - 1; i >= 0; i--)\n\t\t{\n\t\t\tres += ((col[i] - 'A') + 1) * pow(26, col.length - i - 1);\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic string toMode1()\n\t{\n\t\tstring s = \"R\" ~ to!string(row) ~ \"C\" ~ to!string(column);\n\t\treturn s;\n\t}\n\n\tpublic string toMode2()\n\t{\n\t\tint c = column;\n\t\tstring s = \"\";\n\t\twhile (c > 0)\n\t\t{\n\t\t\tc--;\n\t\t\tint lc = c % 26;\n\t\t\tif (lc < 0) lc += 26;\n\t\t\ts ~= cast(char)(lc + 'A');\n\t\t\tc = c / 26;\n\t\t}\n\t\tchar[] ms = s.dup;\n\t\treverse(ms);\n\t\treturn to!string(ms) ~ to!string(row);\n\t}\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\\n\", &n);\n\tauto mode1 = r\"^R([0-9]+)C([0-9]+$)\".regex;\n\tauto mode2 = r\"^([A-Z]+)([0-9]+)$\".regex;\n\tforeach (int i; 0..n)\n\t{\n\t\tstring expression = readline();\n\t\tCell c;\n\t\tauto m = matchFirst(expression, mode1);\n\t\tif (m.empty)\n\t\t{\n\t\t\tm = matchFirst(expression, mode2);\n\t\t\tc.column = c.from_string(m[1]);\n\t\t\tc.row = to!int(m[2]);\n\t\t\twrite(c.toMode1(), \"\\n\");\n\t\t} else {\n\t\t\tc.row = to!int(m[1]);\n\t\t\tc.column = to!int(m[2]);\n\t\t\twrite(c.toMode2(), \"\\n\");\n\t\t}\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.regex, std.conv;\n\nimmutable rx1 = r\"^([A-Z]+)(\\d+)$\";\nimmutable rx2 = r\"^R(\\d+)C(\\d+)$\";\n\nvoid main() {\n\tlong n;\n\treadf(\"%s\\n\", &n);\n\tforeach (i; 0 .. n) {\n\t\tstring s;\n\t\treadf(\"%s\\n\", &s);\n\t\tauto m = match(s, rx1);\n\t\tif (m) {\n\t\t\tlong col = 0;\n\t\t\tforeach(c; m.captures[1]) {\n\t\t\t\tcol *= 26;\n\t\t\t\tcol += c - 'A' + 1;\n\t\t\t}\n\t\t\twritefln(\"R%sC%d\", m.captures[2], col);\n\t\t} else {\n\t\t\tm = match(s, rx2);\n\t\t\tlong col = to!long(m.captures[2]);\n\t\t\tstring res = \"\";\n\t\t\twhile(col) {\n\t\t\t\tif (col % 26) {\n\t\t\t\t\tres = ((col % 26) - 1 + 'A') ~ res;\n\t\t\t\t} else {\n\t\t\t\t\tres = 'Z' ~ res;\n\t\t\t\t\tcol -= 26;\n\t\t\t\t}\n\t\t\t\tcol /= 26;\n\t\t\t}\n\t\t\twritefln(\"%s%s\", res, m.captures[1]);\n\t\t}\n\t}\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\n\nvoid tr1(in string s) {\n int r, c;\n s.ptr.sscanf(\"R%dC%d\".ptr, &r, &c);\n char[] cs;\n while (c > 0) {\n if (c % 26 == 0) {\n cs ~= 'Z';\n c = (c - 26) % 26;\n } else {\n cs ~= ('A' + c % 26 - 1);\n c /= 26;\n }\n }\n cs.reverse();\n writef(\"%s%d\\n\", cs, r);\n}\n\nvoid tr2(in string s) {\n auto m = s.match(regex(\"([A-Z]+)([0-9]+)\")).captures;\n auto cs = m[1], rs = m[2];\n int t = 0;\n foreach (i, c; cs) {\n t = t * 26 + c - 'A' + 1;\n }\n writef(\"R%sC%d\\n\", rs, t);\n}\n\nvoid tr(in string s) {\n if (s[0] == 'R') {\n tr1(s);\n } else {\n tr2(s);\n }\n}\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n foreach (_; 0 .. n) {\n tr(stdin.readln());\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\n\nvoid tr1(in string s) {\n int r, c;\n s.ptr.sscanf(\"R%dC%d\".ptr, &r, &c);\n char[] cs;\n while (c > 0) {\n if (c % 26 == 0) {\n cs ~= 'Z';\n c = (c - 26) % 26;\n } else {\n cs ~= ('A' + c % 26 - 1);\n c /= 26;\n }\n }\n cs.reverse();\n writef(\"%s%d\\n\", cs, r);\n}\n\nvoid tr2(in string s) {\n auto m = s.match(regex(\"([A-Z]+)([0-9]+)\")).captures;\n auto cs = m[1], rs = m[2];\n int t = 0;\n foreach (i, c; cs) {\n t = t * 26 + c - 'A' + 1;\n }\n writef(\"R%sC%d\\n\", rs, t);\n}\n\nvoid tr(in string s) {\n if (!s.match(regex(\"R[0-9]+C[0-9]+\")).empty()) {\n //if (s[0] == 'R') {\n tr1(s);\n } else {\n tr2(s);\n }\n}\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n foreach (_; 0 .. n) {\n tr(stdin.readln());\n }\n}\n"}, {"source_code": "import std.stdio, std.regex, std.conv;\n\nstatic immutable string excelMap = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\nstatic immutable int base = excelMap.length;\n\nulong excelToDec(string excel) {\n ulong dec = 0, pow = 1;\n\n for (int i = excel.length-1; i >= 0; --i) {\n dec += (excel[i]-'A'+1) * pow;\n pow *= base;\n }\n\n return dec;\n}\n\nstring decToExcel(ulong dec) {\n string s;\n\n while (dec) {\n s = cast(char)(excelMap[--dec%base]) ~ s;\n dec /= base;\n }\n\n return s;\n}\n\nvoid main() {\n writeln(decToExcel(494));\n\n int n;\n readf(\"%d\\n\", &n);\n\n for (int i = 0; i < n; ++i) {\n auto s = readln();\n auto m = match(s, r\"^R([0-9]+)C([0-9]+)\");\n if (m) {\n writefln(\"%s%s\", decToExcel(to!int(m.captures[2])), m.captures[1]);\n } else {\n m = match(s, r\"^([A-Z]+)([0-9]+)\");\n writefln(\"R%sC%s\", m.captures[2], excelToDec(m.captures[1]));\n }\n }\n}"}, {"source_code": "import std.stdio, std.regex, std.conv;\n\nstatic immutable string excelMap = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\nstatic immutable int base = excelMap.length;\n\nulong excelToDec(string excel) {\n ulong dec = 0, pow = 1;\n\n for (int i = excel.length-1; i >= 0; --i) {\n dec += (excel[i]-'A'+1) * pow;\n pow *= base;\n }\n\n return dec;\n}\n\nstring decToExcel(ulong dec) {\n string s;\n\n while (dec) {\n s = cast(char)(excelMap[dec%base]-1) ~ s;\n dec /= base;\n }\n\n return s;\n}\n\nvoid main() {\n int n;\n readf(\"%d\\n\", &n);\n\n for (int i = 0; i < n; ++i) {\n auto s = readln();\n auto m = match(s, r\"^R([0-9]+)C([0-9]+)\");\n if (m) {\n writefln(\"%s%s\", decToExcel(to!int(m.captures[2])), m.captures[1]);\n }\n else {\n m = match(s, r\"^([A-Z]+)([0-9]+)\");\n writefln(\"R%sC%s\", m.captures[2], excelToDec(m.captures[1]));\n }\n }\n}"}, {"source_code": "import std.stdio, std.regex, std.conv;\n\nstatic immutable string excelMap = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\nstatic immutable int base = excelMap.length;\n\nulong excelToDec(string excel) {\n ulong dec = 0, pow = 1;\n\n for (int i = excel.length-1; i >= 0; --i) {\n dec += (excel[i]-'A'+1) * pow;\n pow *= base;\n }\n\n return dec;\n}\n\nstring decToExcel(ulong dec) {\n string s;\n\n while (dec) {\n s = cast(char)(excelMap[dec%base]-1) ~ s;\n dec /= base;\n }\n\n return s;\n}\n\nvoid main() {\n int n;\n readf(\"%d\\n\", &n);\n\n for (int i = 0; i < n; ++i) {\n auto s = readln();\n writeln(s);\n auto m = match(s, r\"^R([0-9]+)C([0-9]+)\");\n if (m)\n writefln(\"%s%s\", decToExcel(to!int(m.captures[2])), m.captures[1]);\n else\n m = match(s, r\"^([A-Z]+)([0-9]+)\");\n writefln(\"R%sC%s\", m.captures[2], excelToDec(m.captures[1]));\n }\n}"}, {"source_code": "import std.stdio, std.regex, std.conv;\n\nstatic immutable string excelMap = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\nstatic immutable int base = excelMap.length;\n\nulong excelToDec(string excel) {\n ulong dec = 0, pow = 1;\n\n for (int i = excel.length-1; i >= 0; --i) {\n dec += (excel[i]-'A'+1) * pow;\n pow *= base;\n }\n\n return dec;\n}\n\nstring decToExcel(ulong dec) {\n string s;\n\n while (dec) {\n s = cast(char)(excelMap[dec%base]-1) ~ s;\n dec /= base;\n }\n\n return s;\n}\n\nvoid main() {\n int n;\n readf(\"%d\\n\", &n);\n\n for (int i = 0; i < n; ++i) {\n auto s = readln();\n auto m = match(s, r\"^R([0-9]+)C([0-9]+)\");\n if (m)\n writefln(\"%s%s\", decToExcel(to!int(m.captures[2])), m.captures[1]);\n else\n m = match(s, r\"^([A-Z]+)([0-9]+)\");\n writefln(\"R%sC%s\", m.captures[2], excelToDec(m.captures[1]));\n }\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.regex;\nimport std.math;\nimport std.conv;\n\nstring readline()\n{\n\tstring l = readln();\n\tif (l[$-1] == '\\n') l.length--;\n\treturn l;\n}\n\nstruct Cell\n{\n\tpublic int column;\n\tpublic int row;\n\n\tpublic int from_string(string col)\n\t{\n\t\tint res = 0;\n\t\tfor (int i = col.length - 1; i >= 0; i--)\n\t\t{\n\t\t\tres += ((col[i] - 'A') + 1) * pow(26, col.length - i - 1);\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic string toMode1()\n\t{\n\t\tstring s = \"R\" ~ to!string(row) ~ \"C\" ~ to!string(column);\n\t\treturn s;\n\t}\n\n\tpublic string toMode2()\n\t{\n\t\tint c = column;\n\t\tstring s = \"\";\n\t\twhile (c > 0)\n\t\t{\n\t\t\ts ~= cast(char)((c % 26) + 'A' - 1);\n\t\t\tc = c / 26;\n\t\t}\n\t\tchar[] ms = s.dup;\n\t\treverse(ms);\n\t\treturn to!string(ms) ~ to!string(row);\n\t}\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\\n\", &n);\n\tauto mode1 = r\"^R([0-9]+)C([0-9]+$)\".regex;\n\tauto mode2 = r\"^([A-Z]+)([0-9]+)$\".regex;\n\tforeach (int i; 0..n)\n\t{\n\t\tstring expression = readline();\n\t\tCell c;\n\t\tauto m = matchFirst(expression, mode1);\n\t\tif (m.empty)\n\t\t{\n\t\t\tm = matchFirst(expression, mode2);\n\t\t\tc.column = c.from_string(m[1]);\n\t\t\tc.row = to!int(m[2]);\n\t\t\twrite(c.toMode1(), \"\\n\");\n\t\t} else {\n\t\t\tc.row = to!int(m[1]);\n\t\t\tc.column = to!int(m[2]);\n\t\t\twrite(c.toMode2(), \"\\n\");\n\t\t}\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.range, std.conv, std.algorithm, std.string;\nimport std.regex, std.math;\n\nvoid main() {\n int n = readln.chomp.to!int;\n auto rc = regex(r\"^R(\\d+)C(\\d+)$\");\n auto alnum = regex(r\"^([A-Z]+)(\\d+)$\");\n\n foreach (i; 0..n) {\n string coord = readln.chomp;\n auto rccap = coord.matchFirst(rc);\n if (!rccap.empty) {\n int row = rccap[1].to!int;\n int col = rccap[2].to!int;\n auto newcol = numToAl(col);\n writeln(newcol ~ rccap[1]);\n } else {\n auto alnumcap = coord.matchFirst(alnum);\n writeln(\"R\" ~ alnumcap[2] ~ \"C\" ~ alToNum(alnumcap[1]).to!string);\n }\n }\n}\n\nint alToNum(string row) {\n int ans;\n\n foreach (int i, c; (cast(char[])row).reverse) {\n int al = c - 'A' + 1;\n ans += al * pow(26, i);\n }\n\n return ans;\n}\n\nchar[] numToAl(int row) {\n char[] ans;\n while (row > 25) {\n ans ~= (row % 26) + 'A' - 1;\n row /= 26;\n }\n\n ans ~= (row + 'A' - 1);\n return ans.reverse;\n}\n"}], "src_uid": "910c0e650d48af22fa51ab05e8123709"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf (\"%s %s\", &n, &m);\n readln;\n \n auto g = new int [][] (n+1);\n foreach (_; 0..m) {\n auto a = readln.split.map!(to!int).array;\n (2).iota.each!(i => g[a[i]] ~= a[1-i]);\n }\n \n auto vis = false.repeat(n+1).array;\n \n bool dfs (int v, int fr, int fin) {\n vis[v] = true;\n if (g[v].length != 2) return false;\n \n foreach (u; g[v]) {\n if (u == fr) continue;\n if (vis[u]) return u == fin;\n return dfs(u, v, fin);\n }\n \n assert(false);\n }\n \n int ans = 0;\n foreach (i; 1..n+1) {\n debug { writeln(g[i]); }\n if (vis[i]) continue;\n ans += dfs(i, -1, i);\n }\n \n writeln(ans);\n}", "positive_code": [{"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, m; readV(n, m);\n\n auto g = Graph!int(n), uf = UnionFind!int(n);\n foreach (i; 0..m) {\n int a, b; readV(a, b); --a; --b;\n g.addEdgeB(a, b);\n uf.unite(a, b);\n }\n\n writeln(uf.groups.count!(gi => gi.all!(vi => g[vi].length == 2)));\n}\n\nstruct Graph(N = int)\n{\n alias Node = N;\n Node n;\n Node[][] g;\n alias g this;\n this(Node n) { this.n = n; g = new Node[][](n); }\n void addEdge(Node u, Node v) { g[u] ~= v; }\n void addEdgeB(Node u, Node v) { g[u] ~= v; g[v] ~= u; }\n}\n\nstruct UnionFind(T)\n{\n import std.algorithm, std.range;\n\n T[] p; // parent\n const T s; // sentinel\n const T n;\n T countForests; // number of forests\n T[] countNodes; // number of nodes in forests\n\n this(T n)\n {\n this.n = n;\n s = n;\n p = new T[](n);\n p[] = s;\n countForests = n;\n countNodes = new T[](n);\n countNodes[] = 1;\n }\n\n T opIndex(T i)\n {\n if (p[i] == s) {\n return i;\n } else {\n p[i] = this[p[i]];\n return p[i];\n }\n }\n\n bool unite(T i, T j)\n {\n auto pi = this[i], pj = this[j];\n if (pi != pj) {\n p[pj] = pi;\n --countForests;\n countNodes[pi] += countNodes[pj];\n return true;\n } else {\n return false;\n }\n }\n\n auto countNodesOf(T i) { return countNodes[this[i]]; }\n bool isSame(T i, T j) { return this[i] == this[j]; }\n\n auto groups()\n {\n auto g = new T[][](n);\n foreach (i; 0..n) g[this[i]] ~= i;\n return g.filter!(l => !l.empty);\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf (\"%s %s\", &n, &m);\n readln;\n \n auto g = new int [][] (n+1);\n foreach (_; 0..m) {\n auto a = readln.split.map!(to!int).array;\n (2).iota.each!(i => g[a[i]] ~= a[1-i]);\n }\n \n auto vis = false.repeat(n+1).array;\n \n int[] bfs (int s) {\n auto r = [s];\n auto q = SList!int(s);\n while (!q.empty()) {\n auto v = q.front();\n q.removeFront();\n if (vis[v]) continue;\n vis[v] = true;\n r ~= v;\n foreach (u; g[v]) if (!vis[u]) q.insertFront(u);\n }\n return r;\n }\n \n auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);\n int ans = 0;\n foreach (i; 1..n+1) {\n debug { writeln(g[i]); }\n if (vis[i]) continue;\n ans += isCycle(bfs(i).array);\n }\n \n writeln(ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf (\"%s %s\", &n, &m);\n readln;\n \n auto g = new int [][] (n+1);\n foreach (_; 0..m) {\n auto a = readln.split.map!(to!int).array;\n (2).iota.each!(i => g[a[i]] ~= a[1-i]);\n }\n \n auto vis = false.repeat(n+1).array;\n \n void dfs (int v, ref int[] cur) {\n vis[v] = true;\n cur ~= v;\n \n foreach (u; g[v]) {\n if (!vis[u]) dfs(u, cur);\n }\n }\n \n auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);\n int ans = 0;\n foreach (i; 1..n+1) {\n debug { writeln(g[i]); }\n if (vis[i]) continue;\n int[] comp;\n dfs(i, comp);\n ans += isCycle(comp);\n }\n \n writeln(ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf (\"%s %s\", &n, &m);\n readln;\n \n auto g = new int [][] (n+1);\n foreach (_; 0..m) {\n auto a = readln.split.map!(to!int).array;\n (2).iota.each!(i => g[a[i]] ~= a[1-i]);\n }\n \n auto vis = false.repeat(n+1).array;\n \n SList!int bfs (int s) {\n auto r = SList!int(s);\n auto q = SList!int(s);\n while (!q.empty()) {\n auto v = q.front();\n q.removeFront();\n if (vis[v]) continue;\n vis[v] = true;\n r.insertFront(v);\n foreach (u; g[v]) if (!vis[u]) q.insertFront(u);\n }\n return r;\n }\n \n auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);\n int ans = 0;\n foreach (i; 1..n+1) {\n debug { writeln(g[i]); }\n if (vis[i]) continue;\n ans += isCycle(bfs(i).array);\n }\n \n writeln(ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf (\"%s %s\", &n, &m);\n readln;\n \n auto g = new int [][] (n+1);\n foreach (_; 0..m) {\n auto a = readln.split.map!(to!int).array;\n (2).iota.each!(i => g[a[i]] ~= a[1-i]);\n }\n \n auto vis = false.repeat(n+1).array;\n \n int[] bfs (int s) {\n auto r = Array!int(s);\n auto q = SList!int(s);\n while (!q.empty()) {\n auto v = q.front();\n q.removeFront();\n if (vis[v]) continue;\n vis[v] = true;\n r ~= v;\n foreach (u; g[v]) if (!vis[u]) q.insertFront(u);\n }\n return r.array;\n }\n \n int[][] comps;\n foreach (i; 1..n+1) {\n debug { writeln(g[i]); }\n if (vis[i]) continue;\n comps ~= bfs(i);\n }\n \n auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);\n auto ans = comps.count!(isCycle);\n \n writeln(ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf (\"%s %s\", &n, &m);\n readln;\n \n auto g = new int [][] (n+1);\n foreach (_; 0..m) {\n auto a = readln.split.map!(to!int).array;\n (2).iota.each!(i => g[a[i]] ~= a[1-i]);\n }\n \n auto vis = false.repeat(n+1).array;\n \n void dfs (int v, ref int[] cur) {\n vis[v] = true;\n cur ~= v;\n \n foreach (u; g[v]) {\n if (!vis[u]) dfs(u, cur);\n }\n }\n \n int[][] comps;\n foreach (i; 1..n+1) {\n debug { writeln(g[i]); }\n if (vis[i]) continue;\n int[] comp;\n dfs(i, comp);\n comps ~= comp;\n }\n \n auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);\n auto ans = comps.count!(isCycle);\n \n writeln(ans);\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf (\"%s %s\", &n, &m);\n readln;\n \n auto g = new int [][] (n+1);\n foreach (_; 0..m) {\n auto a = readln.split.map!(to!int).array;\n (2).iota.each!(i => g[a[i]] ~= a[1-i]);\n }\n \n auto vis = false.repeat(n+1).array;\n \n void dfs (int v, ref int[] cur) {\n vis[v] = true;\n cur ~= v;\n \n foreach (u; g[v]) {\n if (vis[u]) continue;\n return dfs(u, cur);\n }\n }\n \n int[][] comps;\n foreach (i; 1..n+1) {\n debug { writeln(g[i]); }\n if (vis[i]) continue;\n int[] comp;\n dfs(i, comp);\n comps ~= comp;\n }\n \n auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);\n auto ans = comps.count!(isCycle);\n \n writeln(ans);\n}"}], "src_uid": "cf7520d88e10ba171de443f36fdd2b73"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n int M = N / 3;\r\n int[] G;\r\n for (int i = 0; i < M; i++) {\r\n int x = ask(3*i+1, 3*i+2, 3*i+3);\r\n G ~= x;\r\n }\r\n int find_ic() {\r\n for (int i = 0; i+1 < M; i++) {\r\n if (G[i] != G[i + 1]) {\r\n // 3*i+1 ~ 3*i+6\r\n int[] p;\r\n for (int k = 3*i+1; k <= 3*i+4; k++) {\r\n int x = ask(k, k+1, k+2);\r\n if (!p.empty && p.back != x) {\r\n // (k, k+1) is (i,c) or (c,i)\r\n return k;\r\n } else {\r\n p ~= x;\r\n }\r\n }\r\n }\r\n }\r\n assert(false);\r\n }\r\n\r\n int k = find_ic();\r\n int[] Is, Cs;\r\n for (int i = 1; i <= N; i++) {\r\n if (i == k || i == k+1) continue;\r\n int x = ask(k, k+1, i);\r\n if (x == 0) {\r\n Is ~= i;\r\n } else {\r\n Cs ~= i;\r\n }\r\n }\r\n int x = ask(Is.back, Cs.back, k);\r\n if (x == 0) {\r\n Is ~= k;\r\n Cs ~= k + 1;\r\n } else {\r\n Is ~= k + 1;\r\n Cs ~= k;\r\n }\r\n writefln(\"! %s %(%s %)\", Is.length, Is);\r\n stdout.flush;\r\n}\r\n\r\nint ask(int a, int b, int c) {\r\n writefln(\"? %s %s %s\", a, b, c);\r\n stdout.flush;\r\n return read!int;\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\r\n\t\tauto ans = new long[](n);\r\n\t\tans[] = -1;\r\n\t\tauto r = new long[](n);\r\n\t\tforeach (i; 1..n-1)\r\n\t\t{\r\n\t\t\twriteln(\"? \", i, \" \", i+1, \" \", i+2);\r\n\t\t\tstdout.flush;\r\n\t\t\tr[i] = RD;\r\n\t\t}\r\n\t\tlong x, y;\r\n\t\tforeach (i; 1..n-2)\r\n\t\t{\r\n\t\t\tif (r[i] != r[i+1])\r\n\t\t\t{\r\n\t\t\t\tans[i-1] = r[i];\r\n\t\t\t\tans[i+2] = r[i+1];\r\n\t\t\t\tx = i-1;\r\n\t\t\t\ty = i+2;\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (ans[i] != -1) continue;\r\n\t\t\twriteln(\"? \", x+1, \" \", y+1, \" \", i+1);\r\n\t\t\tstdout.flush;\r\n\t\t\tans[i] = RD;\r\n\t\t}\r\n\t\tlong[] arr;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (ans[i] == 0)\r\n\t\t\t\tarr ~= i+1;\r\n\t\t}\r\n\t\twriteln(\"! \", arr.length, \" \", arr.map!(to!string).join(\" \"));\r\n\t\tstdout.flush;\r\n\t}\r\n\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.functional;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid solve (int n)\r\n{\r\n\tassert (n % 3 == 0);\r\n\r\n\tint ask (int a, int b, int c)\r\n\t{\r\n\t\twriteln (\"? \", a, \" \", b, \" \", c);\r\n\t\tstdout.flush ();\r\n\t\treturn readln.strip.to !(int);\r\n\t}\r\n\r\n\tint [] q;\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tq ~= ask (i + 1, i + 2, i + 3);\r\n\t}\r\n\r\n\tauto t0 = q.countUntil (0) * 3;\r\n\tauto t1 = q.countUntil (1) * 3;\r\n\tauto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];\r\n\tint pos = 1;\r\n\twhile (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)\r\n\t{\r\n\t\tpos += 1;\r\n\t}\r\n\r\n\tint p0 = six[pos - 1];\r\n\tint p1 = six[pos + 2];\r\n\r\n\tauto v = new bool [n + 1];\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tauto three = [i + 1, i + 2, i + 3];\r\n\t\tif (q[i / 3] == 0)\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p1);\r\n\t\t\tint y = ask (three[0], three[2], p1);\r\n\t\t\tint z = (x == 1 && y == 1) ? 0 :\r\n\t\t\t (x == 0 && y == 0) ? 0 : 1;\r\n\t\t\tv[three[0]] = 0;\r\n\t\t\tv[three[1]] = 0;\r\n\t\t\tv[three[2]] = 0;\r\n\t\t\tif (x == 1 && y == 1) v[three[0]] = 1;\r\n\t\t\tif (x == 1 && z == 1) v[three[1]] = 1;\r\n\t\t\tif (y == 1 && z == 1) v[three[2]] = 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p0);\r\n\t\t\tint y = ask (three[0], three[2], p0);\r\n\t\t\tint z = (x == 0 && y == 0) ? 1 :\r\n\t\t\t (x == 1 && y == 1) ? 1 : 0;\r\n\t\t\tv[three[0]] = 1;\r\n\t\t\tv[three[1]] = 1;\r\n\t\t\tv[three[2]] = 1;\r\n\t\t\tif (x == 0 && y == 0) v[three[0]] = 0;\r\n\t\t\tif (x == 0 && z == 0) v[three[1]] = 0;\r\n\t\t\tif (y == 0 && z == 0) v[three[2]] = 0;\r\n\t\t}\r\n\t}\r\n\r\n\tauto answer = iota (1, n + 1).filter !(i => v[i] == 0).array;\r\n\twritefln (\"! %s %(%s %)\", answer.length, answer);\r\n\tstdout.flush ();\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tsolve (n);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.functional;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid solve (int n)\r\n{\r\n\tassert (n % 3 == 0);\r\n\r\n\tint ask (int a, int b, int c)\r\n\t{\r\n\t\twriteln (\"? \", a, \" \", b, \" \", c);\r\n\t\tstdout.flush ();\r\n\t\treturn readln.strip.to !(int);\r\n\t}\r\n\r\n\tint [] q;\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tq ~= ask (i + 1, i + 2, i + 3);\r\n\t}\r\n\r\n\tauto t0 = q.countUntil (0) * 3;\r\n\tauto t1 = q.countUntil (1) * 3;\r\n\tauto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];\r\n\tint pos = 1;\r\n\twhile (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)\r\n\t{\r\n\t\tpos += 1;\r\n\t}\r\n\r\n\tint p0 = six[pos - 1];\r\n\tint p1 = six[pos + 2];\r\n\r\n\tauto v = new bool [n + 1];\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tauto three = [i + 1, i + 2, i + 3];\r\n\t\tif (q[i / 3] == 0)\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p1);\r\n\t\t\tint y = ask (three[0], three[2], p1);\r\n\t\t\tint z = (x == 0 && y == 0) ? 0 : 1;\r\n\t\t\tv[three[0]] = 0;\r\n\t\t\tv[three[1]] = 0;\r\n\t\t\tv[three[2]] = 0;\r\n\t\t\tif (x == 1 && y == 1) v[three[0]] = 1;\r\n\t\t\tif (x == 1 && z == 1) v[three[1]] = 1;\r\n\t\t\tif (y == 1 && z == 1) v[three[2]] = 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p0);\r\n\t\t\tint y = ask (three[0], three[2], p0);\r\n\t\t\tint z = (x == 1 && y == 1) ? 1 : 0;\r\n\t\t\tv[three[0]] = 1;\r\n\t\t\tv[three[1]] = 1;\r\n\t\t\tv[three[2]] = 1;\r\n\t\t\tif (x == 0 && y == 0) v[three[0]] = 0;\r\n\t\t\tif (x == 0 && z == 0) v[three[1]] = 0;\r\n\t\t\tif (y == 0 && z == 0) v[three[2]] = 0;\r\n\t\t}\r\n\t}\r\n\r\n\tauto answer = iota (1, n + 1).filter !(i => v[i] == 0).array;\r\n\twritefln (\"! %s %(%s %)\", answer.length, answer);\r\n\tstdout.flush ();\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tsolve (n);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.functional;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid solve (int n)\r\n{\r\n\tassert (n % 3 == 0);\r\n\r\n\tint askImpl () (int a, int b, int c)\r\n\t{\r\n\t\twriteln (\"? \", a, \" \", b, \" \", c);\r\n\t\tstdout.flush ();\r\n\t\treturn readln.strip.to !(int);\r\n\t}\r\n\r\n\talias ask = memoize !(askImpl !());\r\n\r\n\tint [] q;\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tq ~= ask (i + 1, i + 2, i + 3);\r\n\t}\r\n\r\n\tauto t0 = q.countUntil (0) * 3;\r\n\tauto t1 = q.countUntil (1) * 3;\r\n\tauto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];\r\n\tint pos = 1;\r\n\twhile (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)\r\n\t{\r\n\t\tpos += 1;\r\n\t}\r\n\r\n\tint p0 = six[pos - 1];\r\n\tint p1 = six[pos + 2];\r\n\r\n\tauto v = new bool [n + 1];\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tauto three = [i + 1, i + 2, i + 3];\r\n\t\tif (q[i / 3] == 0)\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p1);\r\n\t\t\tint y = ask (three[0], three[2], p1);\r\n\t\t\tint z = (x == 0 && y == 0) ? 0 : 1;\r\n\t\t\tv[three[0]] = 0;\r\n\t\t\tv[three[1]] = 0;\r\n\t\t\tv[three[2]] = 0;\r\n\t\t\tif (x == 1 && y == 1) v[three[0]] = 1;\r\n\t\t\tif (x == 1 && z == 1) v[three[1]] = 1;\r\n\t\t\tif (y == 1 && z == 1) v[three[2]] = 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p0);\r\n\t\t\tint y = ask (three[0], three[2], p0);\r\n\t\t\tint z = (x == 1 && y == 1) ? 1 : 0;\r\n\t\t\tv[three[0]] = 1;\r\n\t\t\tv[three[1]] = 1;\r\n\t\t\tv[three[2]] = 1;\r\n\t\t\tif (x == 0 && y == 0) v[three[0]] = 0;\r\n\t\t\tif (x == 0 && z == 0) v[three[1]] = 0;\r\n\t\t\tif (y == 0 && z == 0) v[three[2]] = 0;\r\n\t\t}\r\n\t}\r\n\r\n\tauto answer = iota (1, n + 1).filter !(i => v[i] == 0).array;\r\n\twritefln (\"! %s %(%s %)\", answer.length, answer);\r\n\tstdout.flush ();\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tsolve (n);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.functional;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid solve (int n)\r\n{\r\n\tassert (n % 3 == 0);\r\n\r\n\tint askImpl () (int a, int b, int c)\r\n\t{\r\n\t\twriteln (\"? \", a, \" \", b, \" \", c);\r\n\t\tstdout.flush ();\r\n\t\treturn readln.strip.to !(int);\r\n\t}\r\n\r\n\talias ask = memoize !(askImpl !());\r\n\r\n\tint [] q;\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tq ~= ask (i + 1, i + 2, i + 3);\r\n\t}\r\n\r\n\tauto t0 = q.countUntil (0) * 3;\r\n\tauto t1 = q.countUntil (1) * 3;\r\n\tauto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];\r\n\tint pos = 1;\r\n\twhile (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)\r\n\t{\r\n\t\tpos += 1;\r\n\t}\r\n\r\n\tint p0 = six[pos - 1];\r\n\tint p1 = six[pos + 2];\r\n\r\n\tauto v = new bool [n + 1];\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tauto three = [i + 1, i + 2, i + 3];\r\n\t\tif (q[i / 3] == 0)\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p1);\r\n\t\t\tint y = ask (three[0], three[2], p1);\r\n\t\t\tint z = (x == 0 && y == 0) ? 0 : 1;\r\n\t\t\tv[three[0]] = 0;\r\n\t\t\tv[three[1]] = 0;\r\n\t\t\tv[three[2]] = 0;\r\n\t\t\tif (x == 1 && y == 1) v[three[0]] = 1;\r\n\t\t\tif (x == 1 && z == 1) v[three[1]] = 1;\r\n\t\t\tif (y == 1 && z == 1) v[three[2]] = 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p0);\r\n\t\t\tint y = ask (three[0], three[2], p0);\r\n\t\t\tint z = (x == 1 && y == 1) ? 1 : 0;\r\n\t\t\tv[three[0]] = 1;\r\n\t\t\tv[three[1]] = 1;\r\n\t\t\tv[three[2]] = 1;\r\n\t\t\tif (x == 0 && y == 0) v[three[0]] = 0;\r\n\t\t\tif (x == 0 && z == 0) v[three[1]] = 0;\r\n\t\t\tif (y == 0 && z == 0) v[three[2]] = 0;\r\n\t\t}\r\n\t}\r\n\r\n\twritefln (\"! %(%s %)\", iota (1, n + 1).filter !(i => v[i] == 0));\r\n\tstdout.flush ();\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tsolve (n);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.functional;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid solve (int n)\r\n{\r\n\tassert (n % 3 == 0);\r\n\r\n\tint askImpl () (int a, int b, int c)\r\n\t{\r\n\t\twriteln (\"? \", a, \" \", b, \" \", c);\r\n\t\tstdout.flush ();\r\n\t\treturn readln.strip.to !(int);\r\n\t}\r\n\r\n\talias ask = memoize !(askImpl !());\r\n\r\n\tint [] q;\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tq ~= ask (i + 1, i + 2, i + 3);\r\n\t}\r\n\r\n\tauto t0 = q.countUntil (0) * 3;\r\n\tauto t1 = q.countUntil (1) * 3;\r\n\tauto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];\r\n\tint pos = 1;\r\n\twhile (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)\r\n\t{\r\n\t\tpos += 1;\r\n\t}\r\n\r\n\tint p0 = six[pos - 1];\r\n\tint p1 = six[pos + 2];\r\n\r\n\tauto v = new bool [n + 1];\r\n\tfor (int i = 0; i < n; i += 3)\r\n\t{\r\n\t\tauto three = [i + 1, i + 2, i + 3];\r\n\t\tif (q[i / 3] == 0)\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p1);\r\n\t\t\tint y = ask (three[0], three[2], p1);\r\n\t\t\tint z = (x == 0 && y == 0) ? 0 : 1;\r\n\t\t\tv[three[0]] = 0;\r\n\t\t\tv[three[1]] = 0;\r\n\t\t\tv[three[2]] = 0;\r\n\t\t\tif (x == 1 && y == 1) v[three[0]] = 1;\r\n\t\t\tif (x == 1 && z == 1) v[three[1]] = 1;\r\n\t\t\tif (y == 1 && z == 1) v[three[2]] = 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tint x = ask (three[0], three[1], p0);\r\n\t\t\tint y = ask (three[0], three[2], p0);\r\n\t\t\tint z = (x == 1 && y == 1) ? 1 : 0;\r\n\t\t\tv[three[0]] = 1;\r\n\t\t\tv[three[1]] = 1;\r\n\t\t\tv[three[2]] = 1;\r\n\t\t\tif (x == 0 && y == 0) v[three[0]] = 0;\r\n\t\t\tif (x == 0 && z == 0) v[three[1]] = 0;\r\n\t\t\tif (y == 0 && z == 0) v[three[2]] = 0;\r\n\t\t}\r\n\t}\r\n\r\n\twritefln (\"! %(%s %)\", iota (1, n + 1).filter !(i => v[i]));\r\n\tstdout.flush ();\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tsolve (n);\r\n\t}\r\n}\r\n"}], "src_uid": "6eac9c487764b9314b1a107720176f30"} {"source_code": "import std.algorithm, std.container, std.stdio, std.typecons;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\talias Island = Tuple !(long, q{lo}, long, q{hi});\n\t\tauto s = new Island [n];\n\t\tforeach (ref p; s)\n\t\t{\n\t\t\treadf (\" %s %s\", &p.lo, &p.hi);\n\t\t}\n\n\t\talias Segment = Tuple !(long, q{hi}, long, q{lo}, int, q{num});\n\t\tauto t = new Segment [n - 1];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tt[i] = Segment (s[i + 1].hi - s[i].lo,\n\t\t\t s[i + 1].lo - s[i].hi, i);\n\t\t}\n\t\tsort (t);\n\n\t\talias Bridge = Tuple !(long, q{len}, int, q{num});\n\t\tauto b = redBlackTree !(Bridge);\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tlong d;\n\t\t\treadf (\" %s\", &d);\n\t\t\tb.insert (Bridge (d, j));\n\t\t}\n\n\t\tauto ans = new int [n - 1];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tauto temp = Bridge (t[i].lo, -1);\n\t\t\tauto r = b.upperBound (temp);\n\t\t\tif (r.empty)\n\t\t\t{\n\t\t\t\tans = null;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tauto cur = r.front;\n\t\t\tif (cur.len > t[i].hi)\n\t\t\t{\n\t\t\t\tans = null;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[t[i].num] = cur.num + 1;\n\t\t\tb.removeKey (cur);\n\t\t}\n\n\t\tif (ans is null)\n\t\t{\n\t\t\twriteln (\"No\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"Yes\");\n\t\t\twritefln (\"%(%s %)\", ans);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\tint m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\talias Island = Tuple !(long, q{lo}, long, q{hi});\n\t\tauto s = new Island [n];\n\t\tforeach (ref p; s)\n\t\t{\n\t\t\treadf (\" %s %s\", &p.lo, &p.hi);\n\t\t}\n\n\t\talias Segment = Tuple !(long, q{hi}, long, q{lo}, int, q{num});\n\t\tauto t = new Segment [n - 1];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tt[i] = Segment (s[i + 1].hi - s[i].lo,\n\t\t\t s[i + 1].lo - s[i].hi, i);\n\t\t}\n\t\tsort !(q{a < b}, SwapStrategy.stable) (t);\n\n\t\talias Bridge = Tuple !(long, q{len}, int, q{num});\n\t\tauto b = redBlackTree !(Bridge);\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tlong d;\n\t\t\treadf (\" %s\", &d);\n\t\t\tb.insert (Bridge (d, j));\n\t\t}\n\t\tdebug {writeln (b[].map !(text).join (\" \"));}\n\n\t\tauto ans = new int [n - 1];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tauto temp = Bridge (t[i].lo, -1);\n\t\t\tauto r = b.upperBound (temp);\n\t\t\tif (r.empty)\n\t\t\t{\n\t\t\t\tans = null;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tauto cur = r.front;\n\t\t\tif (cur.len > t[i].hi)\n\t\t\t{\n\t\t\t\tans = null;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[t[i].num] = cur.num + 1;\n\t\t\tb.removeKey (cur);\n\t\t}\n\n\t\tif (ans is null)\n\t\t{\n\t\t\twriteln (\"No\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"Yes\");\n\t\t\twritefln (\"%(%s %)\", ans);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "f7a34711e8a4faa9822d42ef54a0bfc1"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tauto x = min(a, b);\n\t\tauto y = cast(long)max(a, b);\n\t\tauto arr = new bool[](x);\n\t\tforeach (j; 1..10^^5)\n\t\t{\n\t\t\tauto z = (y*j) % x;\n\t\t\tarr[cast(int)z] = true;\n\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (j; 0..arr.length)\n\t\t{\n\t\t\tif (arr[j] == false)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[i] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Finite\" : \"Infinite\");\n\t}\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string, core.stdc.stdlib;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n auto s = readln.split.map!(to!int);\n auto A = s[0];\n auto B = s[1];\n writeln(gcd(A, B) == 1 ? \"Finite\" : \"Infinite\");\n }\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.numeric;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n foreach (t; 0 .. r.next!uint) {\n auto a = r.next!uint;\n auto b = r.next!uint;\n writeln (gcd (a, b) == 1 ? \"Finite\" : \"Infinite\");\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tint[] open = [0];\n\t\tauto limit = (10^^6)+1;\n\t\tauto close = new bool[](limit);\n\t\tclose[0] = true;\n\t\twhile (!open.empty)\n\t\t{\n\t\t\tauto n = open.front; open.popFront;\n\t\t\tauto na = (n+a);\n\t\t\tauto nb = (n+b);\n\t\t\tif (na < limit) if (close[na] == false)\n\t\t\t{\n\t\t\t\tclose[na] = true;\n\t\t\t\topen ~= na;\n\t\t\t}\n\t\t\tif (nb < limit) if (close[nb] == false)\n\t\t\t{\n\t\t\t\tclose[nb] = true;\n\t\t\t\topen ~= nb;\n\t\t\t}\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (j; close.length-min(a,b)..close.length)\n\t\t{\n\t\t\tif (close[j] == false)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[i] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Finite\" : \"Infinite\");\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tint[] open = [0];\n\t\tauto limit = (10^^4)+1;\n\t\tauto close = new bool[](limit);\n\t\tclose[0] = true;\n\t\twhile (!open.empty)\n\t\t{\n\t\t\tauto n = open.front; open.popFront;\n\t\t\tauto na = (n+a);\n\t\t\tauto nb = (n+b);\n\t\t\tif (na < limit) if (close[na] == false)\n\t\t\t{\n\t\t\t\tclose[na] = true;\n\t\t\t\topen ~= na;\n\t\t\t}\n\t\t\tif (nb < limit) if (close[nb] == false)\n\t\t\t{\n\t\t\t\tclose[nb] = true;\n\t\t\t\topen ~= nb;\n\t\t\t}\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (j; close.length-min(a,b)..close.length)\n\t\t{\n\t\t\tif (close[j] == false)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[i] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Finite\" : \"Infinite\");\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tint[] open = [0];\n\t\tauto limit = (10^^4)+1;\n\t\tauto close = new bool[](limit);\n\t\tclose[0] = true;\n\t\twhile (!open.empty)\n\t\t{\n\t\t\tauto n = open.front; open.popFront;\n\t\t\tauto na = (n+a);\n\t\t\tauto nb = (n+b);\n\t\t\tif (na < limit) if (close[na] == false)\n\t\t\t{\n\t\t\t\tclose[na] = true;\n\t\t\t\topen ~= na;\n\t\t\t}\n\t\t\tif (nb < limit) if (close[nb] == false)\n\t\t\t{\n\t\t\t\tclose[nb] = true;\n\t\t\t\topen ~= nb;\n\t\t\t}\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (j; close.length-max(a,b)..close.length)\n\t\t{\n\t\t\tif (close[j] == false)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[i] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Finite\" : \"Infinite\");\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "388450021f2f33177d905879485bb531"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1555/problem/A\n// basic math\nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n;\n readf(\"%s\\n\", &n);\n long ans = max(6L, n + 1L) / 2L * 5L;\n ans.writeln;\n}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int; while (t--) solve;\n}\nvoid solve()\n{\n\tlong n = readInt!long;\n\tif (n <= 6)\n\t{\n\t\treturn 15.writeln;\n\t}\n\tn += n % 2; \n\t((n/2)*5).writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll n = scan;\n ll tim = (n / 2) * 5;\n if(n % 2 != 0) tim += 5;\n tim = max(tim, 15);\n writeln(tim);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n n = (n + 1) / 2;\n if (n < 3)\n n = 3;\n writeln(n * 5);\n }\n}\n"}], "negative_code": [], "src_uid": "3e27f1c06a263760f5b53c3afe4bf7ee"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new bool[](q);\n\tforeach (qi; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD;\n\t\tauto tlh = new long[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ttlh[i] = [RD, RD, RD];\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong t, h = m, l = m;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = tlh[i][0] - t;\n\t\t\tl = max(tlh[i][1], l-d);\n\t\t\th = min(tlh[i][2], h+d);\n\t\t\tdebug writeln(\"i:\", i, \" l:\", l, \" h:\", h);\n\t\t\tif (l > tlh[i][2] || h < tlh[i][1])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt = tlh[i][0];\n\t\t}\n\t\tans[qi] = ok;\n\t}\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tA: foreach(_; 0 .. rint){\n\t\tint n = rint;\n\t\tlong m = rlong;\n\t\tS[] as;\n\t\tforeach(i; 0 .. n) as ~= S(rlong, rlong, rlong);\n\t\t// as is sorted.\n\t\tlog(\"n:\", n, \"m:\", m, \"as:\", as);\n\n\t\tlong t = 0, l = m, r = m;\n\t\tforeach(a; as){\n\t\t\tlog(\"t:\", t, \"l:\", l, \"r:\", r);\n\t\t\tl = max(l - (a.t - t), a.l);\n\t\t\tr = min(r + (a.t - t), a.r);\n\t\t\tif(l > r){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t\tt = a.t;\n\t\t}\n\t\tlog(\"t:\", t, \"l:\", l, \"r:\", r);\n\t\t\"YES\".writeln;\n\t}\n}\nstruct S{\n\tlong t, l, r;\n\n}"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct Customer\n{\n long t;\n Interval i;\n}\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m;\n @(\"n\") Customer[] customers;\n\n void solve(long tc = -1)\n {\n if (tc == 1)\n logSym!(this);\n long lastTime = 0;\n Interval currentInterval = Interval(m, m);\n foreach(customer; customers)\n {\n with(customer)\n {\n auto elapsedTime = t - lastTime;\n currentInterval.l -= elapsedTime;\n currentInterval.h += elapsedTime;\n currentInterval = intersect(currentInterval, i);\n if (currentInterval.empty)\n break;\n lastTime = t;\n }\n }\n if (currentInterval.empty)\n {\n writeln(\"NO\");\n }\n else\n {\n writeln(\"YES\");\n }\n }\n}\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W)\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, string))\n {\n static assert(isDynamicArray!(typeOfField)\n , \" A field with dimension initialization UDA must be a dynamic array.\");\n enum uda = getUDAs!(fieldSymbol, string)[0];\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tA: foreach(_; 0 .. rint){\n\t\tint n = rint;\n\t\tlong m = rlong;\n\t\tS[] as;\n\t\tforeach(i; 0 .. n) as ~= S(rlong, rlong, rlong);\n\t\t// as is sorted.\n\n\t\tlong t = m, l = 0, r = 0;\n\t\tforeach(a; as){\n\t\t\tl = max(l - (a.t - t), a.l);\n\t\t\tr = min(r + (a.t - t), a.r);\n\t\t\tif(l > r){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t\tt = a.t;\n\t\t}\n\t\t\"YES\".writeln;\n\t}\n}\nstruct S{\n\tlong t, l, r;\n\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tA: foreach(_; 0 .. rint){\n\t\tint n = rint;\n\t\tlong m = rlong;\n\t\tS[] as;\n\t\tforeach(i; 0 .. n) as ~= S(rlong, rlong, rlong);\n\t\t// as is sorted.\n\n\t\tlong t = m, l = 0, r = 0;\n\t\tforeach(a; as){\n\t\t\tl = max(l - (a.t - t), a.l);\n\t\t\tr = min(r + (a.t - t), a.r);\n\t\t\tif(l > r){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t}\n\t\t\"YES\".writeln;\n\t}\n}\nstruct S{\n\tlong t, l, r;\n}"}], "src_uid": "a75b8b9b99b800762645ef7c3bc29905"} {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias BitArray bitset;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=10^^9+7;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const\n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,m;\n\tloop:while(read(&n,&m))\n\t{\n\t\tauto g=new int[][m+1];\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tint k;\n\t\t\tinput(&k);\n\t\t\tforeach(j;0..k)\n\t\t\t{\n\t\t\t\tint f;\n\t\t\t\tinput(&f);\n\t\t\t\tg[f]~=i;\n\t\t\t}\n\t\t}\n\t\tint[int[]] q;\n\t\tforeach(i;g[1..$])\n\t\t{\n\t\t\tq[i.idup]++;\n\t\t}\n\t\tauto fact=(1L~iota(1L,5L*(10^^6)).array).cumulativeFold!\"(a*b)%1000000007\"(1L).array;\n\t\tlong ans=1;\n\t\tforeach(i;q.byValue)\n\t\t{\n\t\t\tans=(ans*fact[i])%mod;\n\t\t}\n\t\t/*long ans=1,t=1;\n\t\tsort(g[1..$]);\n\t\tdebug foreach(i;g)writeln(i);\n\t\tforeach(i;2..m+1)\n\t\t{\n\t\t\tif(g[i]==g[i-1])\n\t\t\t{\n\t\t\t\tans=(ans*(++t))%mod;\n\t\t\t}\n\t\t\telse t=1;\n\t\t}*/\n\t\twriteln(ans);\n\t}\n}", "positive_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias BitArray bitset;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=10^^9+7;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const\n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,m;\n\tloop:while(read(&n,&m))\n\t{\n\t\tauto g=new int[][m+1];\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tint k;\n\t\t\tinput(&k);\n\t\t\tforeach(j;0..k)\n\t\t\t{\n\t\t\t\tint f;\n\t\t\t\tinput(&f);\n\t\t\t\tg[f]~=i;\n\t\t\t}\n\t\t}\n\t\tint[int[]] q;\n\t\tforeach(i;g[1..$])\n\t\t{\n\t\t\tq[i.idup]++;\n\t\t}\n\t\tauto fact=(1L~iota(1L,(10^^6)).array).cumulativeFold!\"(a*b)%1000000007\"(1L).array;\n\t\tlong ans=1;\n\t\tforeach(i;q.byValue)\n\t\t{\n\t\t\tans=(ans*fact[i])%mod;\n\t\t}\n\t\t/*long ans=1,t=1;\n\t\tsort(g[1..$]);\n\t\tdebug foreach(i;g)writeln(i);\n\t\tforeach(i;2..m+1)\n\t\t{\n\t\t\tif(g[i]==g[i-1])\n\t\t\t{\n\t\t\t\tans=(ans*(++t))%mod;\n\t\t\t}\n\t\t\telse t=1;\n\t\t}*/\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias BitArray bitset;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=10^^9+7;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const\n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,m;\n\tloop:while(read(&n,&m))\n\t{\n\t\tauto g=new int[][m+1];\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tint k;\n\t\t\tinput(&k);\n\t\t\tforeach(j;0..k)\n\t\t\t{\n\t\t\t\tint f;\n\t\t\t\tinput(&f);\n\t\t\t\tg[f]~=i;\n\t\t\t}\n\t\t}\n\t\t/*int[int[]] q;\n\t\tforeach(i;g)\n\t\t{\n\t\t\tif(i.length)q[i.idup]++;\n\t\t}\n\t\tauto fact=(1L~iota(1L,5L*(10^^5)+1).array).cumulativeFold!\"(a*b)%1000000007\"(1L).array;\n\t\tlong ans=1;\n\t\tforeach(i;q.byValue)\n\t\t{\n\t\t\tans=(ans*fact[i])%mod;\n\t\t}*/\n\t\tlong ans=1,t=1;\n\t\tsort(g[1..$]);\n\t\tdebug foreach(i;g)writeln(i);\n\t\tforeach(i;2..m+1)\n\t\t{\n\t\t\tif(g[i]==g[i-1])\n\t\t\t{\n\t\t\t\tans=(ans*(++t))%mod;\n\t\t\t}\n\t\t\telse t=1;\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto idx = new int[] (m+1);\n int nxtid = 1;\n foreach (_; 0 .. n) {\n auto nrs = readln.chomp.split.map!(to!int).dropOne.array;\n \n int[int] cnt;\n \n foreach (e; nrs) { cnt[e] += 1; }\n \n int[][int] groups;\n foreach (p; cnt.byKeyValue) {\n groups[p.value] ~= p.key;\n }\n \n debug { groups.writeln; }\n \n foreach (arr; groups.values) {\n arr.schwartzSort!(x => idx[x]);\n \n foreach (p, n; lockstep(arr, arr.dropOne)) {\n bool inc = idx[p] != idx[n];\n \n idx[p] = nxtid;\n \n if (inc) { nxtid += 1; }\n }\n \n idx[arr.back] = nxtid;\n \n ++nxtid;\n }\n \n debug { idx.dropOne.writeln; }\n }\n \n debug { idx.writeln; }\n \n auto grouped = idx.dropOne.sort.group.map!(t => t[1]);\n \n debug { grouped.writeln; }\n \n immutable int MD = 10 ^^ 9 + 7;\n \n auto fac = new int[] (m+1);\n fac[0] = 1;\n foreach (i; 1 .. m+1) { fac[i] = fac[i-1].to!long * i % MD; }\n \n auto ans = grouped.map!(x => fac[x])\n .fold!((x, y) => (x.to!long * y % MD).to!int)(1);\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int mod = 10 ^^ 9 + 7;\n\nvoid main ()\n{\n\tint n;\n\tint m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\treadln;\n\t\tauto hash = new ulong [m];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint [int] num;\n\t\t\tforeach (type; readln.split.drop (1).map !(to !(int)))\n\t\t\t{\n\t\t\t\tnum[type] += 1;\n\t\t\t}\n\t\t\talias Pair = Tuple !(int, q{num}, int, q{type});\n\t\t\tPair [] a;\n\t\t\ta.reserve (num.length);\n\t\t\tforeach (key, value; num)\n\t\t\t{\n\t\t\t\ta ~= Pair (value, key);\n\t\t\t}\n\t\t\tsort (a);\n\t\t\tforeach (g; a.chunkBy !(p => p.num))\n\t\t\t{\n\t\t\t\tauto v = uniform !(ulong) ();\n\t\t\t\tforeach (type; g[1].map !(x => x.type))\n\t\t\t\t{\n\t\t\t\t\thash[type - 1] ^= v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (hash);}\n\n\t\tlong res = 1;\n\t\tsort (hash);\n\t\tforeach (num; hash.group)\n\t\t{\n\t\t\tforeach (i; 0..num[1])\n\t\t\t{\n\t\t\t\tres = (res * 1L * (i + 1)) % mod;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable long mod = 10^^9 + 7;\n\nvoid main(){\n int N, M;\n readVars(N, M);\n\n auto types = new int[][M];\n\n foreach(i ; 0 .. N){\n auto line = readln.split.to!(int[]);\n\n foreach(t ; line[1 .. $]){\n types[t - 1] ~= i;\n }\n }\n\n foreach(i ; 0 .. types.length.to!int){\n sort(types[i]);\n }\n\n sort(types);\n\n long ans = 1, cnt = 1;\n\n foreach(i ; 0 .. types.length.to!int - 1){\n if (types[i] == types[i + 1]){\n cnt++;\n ans = (ans * cnt) % mod;\n } else {\n cnt = 1;\n }\n }\n\n writeln(ans);\n}\n\nvoid readVars(T...)(auto ref T args){\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n throw new Exception(\"args num < input num\");\n }\n}"}], "negative_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias BitArray bitset;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=10^^9+7;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const\n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,m;\n\tloop:while(read(&n,&m))\n\t{\n\t\tauto g=new int[][m+1];\n\t\tforeach(i;1..n+1)\n\t\t{\n\t\t\tint k;\n\t\t\tinput(&k);\n\t\t\tforeach(j;0..k)\n\t\t\t{\n\t\t\t\tint f;\n\t\t\t\tinput(&f);\n\t\t\t\tg[f]~=i;\n\t\t\t}\n\t\t}\n\t\tint[int[]] q;\n\t\tforeach(i;g[1..$])\n\t\t{\n\t\t\tq[i.idup]++;\n\t\t}\n\t\tauto fact=(1L~iota(1L,5L*(10^^5)+1).array).cumulativeFold!\"(a*b)%1000000007\"(1L).array;\n\t\tlong ans=1;\n\t\tforeach(i;q.byValue)\n\t\t{\n\t\t\tans=(ans*fact[i])%mod;\n\t\t}\n\t\t/*long ans=1,t=1;\n\t\tsort(g[1..$]);\n\t\tdebug foreach(i;g)writeln(i);\n\t\tforeach(i;2..m+1)\n\t\t{\n\t\t\tif(g[i]==g[i-1])\n\t\t\t{\n\t\t\t\tans=(ans*(++t))%mod;\n\t\t\t}\n\t\t\telse t=1;\n\t\t}*/\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias BitArray bitset;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const\n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,m;\n\tloop:while(read(&n,&m))\n\t{\n\t\tauto g=new int[][m+1];\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tint k;\n\t\t\tinput(&k);\n\t\t\tforeach(j;0..k)\n\t\t\t{\n\t\t\t\tint f;\n\t\t\t\tinput(&f);\n\t\t\t\tg[f]~=i;\n\t\t\t}\n\t\t}\n\t\tint[int[]] q;\n\t\tforeach(i;g)\n\t\t{\n\t\t\tif(i.length)q[i.idup]++;\n\t\t}\n\t\tauto fact=1L~iota(1L,5L*(10^^5)+1).cumulativeFold!\"(a*b)%1000000007\"(1L).array;\n\t\tlong ans=1;\n\t\tforeach(i;q.byValue)\n\t\t{\n\t\t\tans=(ans*fact[i])%mod;\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias BitArray bitset;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const\n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,m;\n\tloop:while(read(&n,&m))\n\t{\n\t\tauto g=new int[][m+1];\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tint k;\n\t\t\tinput(&k);\n\t\t\tforeach(j;0..k)\n\t\t\t{\n\t\t\t\tint f;\n\t\t\t\tinput(&f);\n\t\t\t\tg[f]~=i;\n\t\t\t}\n\t\t}\n\t\tint[int[]] q;\n\t\tforeach(i;g)\n\t\t{\n\t\t\tif(i.length)q[i.idup]++;\n\t\t}\n\t\tauto fact=(1L~iota(1L,5L*(10^^5)+1).array).cumulativeFold!\"(a*b)%1000000007\"(1L).array;\n\t\tlong ans=1;\n\t\tforeach(i;q.byValue)\n\t\t{\n\t\t\tans=(ans*fact[i])%mod;\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias BitArray bitset;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g<a[m])r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g<a[l])?l:r;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (g==a[l])?l:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n\tV foldr(R,V,T)(R range,T arg,V nach)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))\n\t{\n\t\tfor(;!range.empty;range.popFront()) nach=arg(nach,range.front);\n\t\treturn nach;\n\t}\n\tsize_t countr(R,T)(R range,T fun)\n\t\tif(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))\n\t{\n\t\tsize_t nach;\n\t\tfor(;!range.empty;range.popFront()) nach+=fun(range.front);\n\t\treturn nach;\n\t}\n\tT orient_square(T)(pair!(T,T)[] figure...)\n\t{\n\t\tauto n=figure.front,t=figure.front;\n\t\tfigure.popFront();\n\t\tT ans=0;\n\t\tfor(;!figure.empty;figure.popFront())\n\t\t{\n\t\t\tans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);\n\t\t\tt=figure.front;\n\t\t}\n\t\treturn ans+(n.fi-t.fi)*(n.se+t.se);\n\t}\n\treal square(T)(pair!(T,T)[] figure...)\n\t\tif(is(typeof(figure.front*figure.front)==T))\n\t{\n\t\treturn abs(orient_square(figure))/2.000000000000000;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n,in size_t m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const\n\t\tif(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,m;\n\tloop:while(read(&n,&m))\n\t{\n\t\tauto g=new int[][m+1];\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tint k;\n\t\t\tinput(&k);\n\t\t\tforeach(j;0..k)\n\t\t\t{\n\t\t\t\tint f;\n\t\t\t\tinput(&f);\n\t\t\t\tg[f]~=i;\n\t\t\t}\n\t\t}\n\t\tint[int[]] q;\n\t\tforeach(i;g)\n\t\t{\n\t\t\tif(i.length)q[i.idup]++;\n\t\t}\n\t\tauto fact=1~iota(1,5*(10^^5)+1).cumulativeFold!\"(a*b)%1000000007\"(1).array;\n\t\tlong ans=1;\n\t\tforeach(i;q.byValue)\n\t\t{\n\t\t\tans=(ans*fact[i])%mod;\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto idx = new int[] (m+1);\n int nxtid = 1;\n foreach (_; 0 .. n) {\n auto nrs = readln.chomp.split.map!(to!int).dropOne.array;\n \n int[int] cnt;\n \n foreach (e; nrs) { cnt[e] += 1; }\n \n int[][int] groups;\n foreach (p; cnt.byKeyValue) {\n groups[p.value] ~= p.key;\n }\n \n debug { groups.writeln; }\n \n foreach (arr; groups.values) {\n arr.schwartzSort!(x => idx[x]);\n \n debug { arr.writeln; }\n \n foreach (p, n; lockstep(arr, arr.dropOne)) {\n bool inc = idx[p] != idx[n];\n \n idx[p] = nxtid;\n \n if (inc) { nxtid += 1; }\n }\n \n idx[arr.back] = nxtid;\n \n ++nxtid;\n }\n }\n \n debug { idx.writeln; }\n \n auto grouped = idx.dropOne.sort.group.map!(t => t[1]);\n \n debug { grouped.writeln; }\n \n immutable int MD = 10 ^^ 9 + 23;\n \n auto fac = new int[] (m+1);\n fac[0] = 1;\n foreach (i; 1 .. m+1) { fac[i] = fac[i-1].to!long * i % MD; }\n \n auto ans = grouped.map!(x => fac[x])\n .fold!((x, y) => (x.to!long * y % MD).to!int)(1);\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto idx = new int[] (m+1);\n int nxtid = 1;\n foreach (_; 0 .. n) {\n auto nrs = readln.chomp.split.map!(to!int).dropOne.array;\n \n int[int] cnt;\n \n foreach (e; nrs) { cnt[e] += 1; }\n \n int[][int] groups;\n foreach (p; cnt.byKeyValue) {\n groups[p.value] ~= p.key;\n }\n \n debug { groups.writeln; }\n \n foreach (arr; groups.values) {\n arr.schwartzSort!(x => idx[x]);\n \n debug { arr.writeln; }\n \n foreach (p, n; lockstep(arr, arr.dropOne)) {\n bool inc = idx[p] != idx[n];\n \n idx[p] = nxtid;\n \n if (inc) { nxtid += 1; }\n }\n \n idx[arr.back] = nxtid;\n }\n \n ++nxtid;\n }\n \n debug { idx.writeln; }\n \n auto grouped = idx.dropOne.sort.group.map!(t => t[1]);\n \n debug { grouped.writeln; }\n \n immutable int MD = 10 ^^ 9 + 23;\n \n auto fac = new int[] (m+1);\n fac[0] = 1;\n foreach (i; 1 .. m+1) { fac[i] = fac[i-1].to!long * i % MD; }\n \n auto ans = grouped.map!(x => fac[x])\n .fold!((x, y) => (x.to!long * y % MD).to!int)(1);\n \n ans.writeln;\n}"}], "src_uid": "cff3074a82bffdd49579a47c7491f972"} {"source_code": "module main;\n__gshared:\nimport core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\nalias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nenum mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt gcd(BigInt a, BigInt b)\n\t\t{\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///integer size\n\t\tint sz(T)(T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (!(a[m] < g))\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (!(a[l] < g)) ? l : r;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (g < a[m])\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (g < a[l]) ? l : r;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn binf(a, g) != a.length;\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treturn s == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treadln;\n\t\treturn s == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tfreopen(\"input.txt\", \"r\", core.stdc.stdio.stdin);\n\t\t//freopen(\"output.txt\", \"w\", core.stdc.stdio.stdout);\n\t\t/*StopWatch sw;\n\t\tsw.start;\n\t\tscope (exit)\n\t\t{\n\t\t\tsw.stop;\n\t\t\tstderr.writefln(\"\\nTime: %d ms\", sw.peek.msecs);\n\t\t}*/\n\t}\n\tint n;\n\tloop: while (read(n))\n\t{\n\t\tpii[] a;\n\t\tforeach (_; 0 .. n)\n\t\t{\n\t\t\tint l, r;\n\t\t\tread(l, r);\n\t\t\ta ~= mp(l, 0);\n\t\t\ta ~= mp(r, 1);\n\t\t}\n\t\tsort(a);\n\t\tint c;\n\t\tforeach (x; a)\n\t\t{\n\t\t\tif (x.se > 0)\n\t\t\t\tc--;\n\t\t\telse\n\t\t\t\tc++;\n\t\t\tif (c > 2)\n\t\t\t{\n\t\t\t\twriteln(\"NO\");\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t}\n\t\twriteln(\"YES\");\n\t}\n}\n", "positive_code": [{"source_code": "// Codeforces My Practice\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"s\", int, \"e\");\n auto n = getNum!int;\n auto ap = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (_; 0..n) {\n auto se = getVals!int;\n ap.put(Tp(se[0], se[1]));\n }\n auto prgs = ap.data[];\n prgs.sort!\"a.s < b.s\";\n auto tv1 = Tp(-1,-1), tv2 = Tp(-1,-1);\n foreach (tp; prgs) {\n if (tv1.e < tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv2.e < tp.s) {\n tv2 = tp;\n continue;\n }\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\n}"}], "negative_code": [{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"s\", int, \"e\", int, \"p\");\n auto n = getNum!int;\n auto ap = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (i; 0..n) {\n auto se = getVals!int;\n ap.put(Tp(se[0], se[1], i));\n }\n auto prgs = ap.data[];\n prgs.sort!( (a, b) => a.s!=b.s ? a.s<b.s : (a.e!=b.e ? a.e<b.e : a.p<b.p) );\n auto tv1 = Tp(-1,-1,-1), tv2 = tv1;\n foreach (i,tp; prgs) {\n if (tv1.e < tp.s && tv2.e < tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv1.e < tp.s && tv2.e == tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv2.e < tp.s && tv1.e == tp.s) {\n tv2 = tp;\n continue;\n }\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(long, \"s\", long, \"e\", long, \"p\");\n auto n = getNum!int;\n auto ap = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (i; 0..n) {\n auto se = getVals!long;\n ap.put(Tp(se[0], se[1], i));\n }\n auto prgs = ap.data[];\n prgs.sort!( (a, b) => a.s!=b.s ? a.s<b.s : (a.e!=b.e ? a.e<b.e : a.p<b.p) );\n auto tv1 = Tp(-1,-1,-1), tv2 = tv1;\n foreach (tp; prgs) {\n if (tv1.e < tp.s && tv2.e < tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv1.e < tp.s && tv2.e == tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv2.e < tp.s && tv1.e == tp.s) {\n tv2 = tp;\n continue;\n }\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"s\", int, \"e\");\n auto n = getNum!int;\n auto ap = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (_; 0..n) {\n auto se = getVals!int;\n ap.put(Tp(se[0], se[1]));\n }\n auto prgs = ap.data[];\n prgs.sort!\"a.s < b.s\";\n auto tv1 = Tp(-1,-1), tv2 = Tp(-1,-1);\n foreach (tp; prgs) {\n if (tv1.e < tp.s && tv2.e < tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv1.e <= tp.s && tv2.e == tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv2.e <= tp.s && tv1.e == tp.s) {\n tv2 = tp;\n continue;\n }\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"s\", int, \"e\");\n auto n = getNum!int;\n auto ap = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (_; 0..n) {\n auto se = getVals!int;\n ap.put(Tp(se[0], se[1]));\n }\n auto prgs = ap.data[];\n prgs.sort!\"a.s < b.s\";\n auto tv1 = Tp(-1,-1), tv2 = Tp(-1,-1);\n foreach (tp; prgs) {\n if (tv1.e < tp.s && tv2.e < tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv1.e < tp.s && tv2.e == tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv2.e < tp.s && tv1.e == tp.s) {\n tv2 = tp;\n continue;\n }\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"s\", int, \"e\", int, \"p\");\n auto n = getNum!int;\n auto ap = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (i; 0..n) {\n auto se = getVals!int;\n ap.put(Tp(se[0], se[1], i));\n }\n auto prgs = ap.data[];\n prgs.sort!( (a, b) => a.s!=b.s ? a.s<b.s : (a.e!=b.e ? a.e<b.e : a.p<b.p) );\n auto tv1 = Tp(-1,-1,-1), tv2 = tv1;\n foreach (i,tp; prgs) {\n if (tv1.e < tp.s && tv2.e < tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv1.s < 0 && tv2.e == tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv2.s < 0 && tv1.e == tp.s) {\n tv2 = tp;\n continue;\n }\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"t\", int, \"p\");\n auto n = getNum!int;\n auto startsAp = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (i; 0..n) {\n auto se = getVals!int;\n startsAp.put(Tp(se[0], i));\n endsAp.put(Tp(se[1], i));\n }\n auto starts = startsAp.data[];\n auto ends = endsAp.data[];\n starts.sort!\"a.t < b.t\";\n ends.sort!\"a.t < b.t\";\n auto tv1 = -1, tv2 = -1;\n auto useTv1 = false, useTv2 = false;\n while (starts.length > 0) {\n if (starts[0].t <= ends[0].t) {\n if (tv1 < 0) {\n tv1 = starts[0].p;\n useTv1 = true;\n } else if (tv2 < 0) {\n tv2 = starts[0].p;\n useTv2 = true;\n } else {\n writeln(\"NO\");\n return;\n }\n starts = starts[1..$];\n } else if (starts[0].t > ends[0].t) {\n if (tv1 == ends[0].p) {\n tv1 = -1;\n } else if (tv2 == ends[0].p) {\n tv2 = -1;\n } else {\n writeln(\"NO\");\n return;\n }\n ends = ends[1..$];\n }\n }\n writeln(useTv1 && useTv2 ? \"YES\" : \"NO\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"t\", int, \"p\");\n auto n = getNum!int;\n auto startsAp = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (i; 0..n) {\n auto se = getVals!int;\n startsAp.put(Tp(se[0], i));\n endsAp.put(Tp(se[1], i));\n }\n auto starts = startsAp.data[];\n auto ends = endsAp.data[];\n starts.sort!( (a, b) => a.t == b.t ? a.p < b.p : a.t < b.t );\n ends.sort!( (a, b) => a.t == b.t ? a.p < b.p : a.t < b.t );\n auto tv1 = -1, tv2 = -1;\n while (starts.length > 0) {\n if (starts[0].t <= ends[0].t) {\n if (tv1 < 0) {\n tv1 = starts[0].p;\n } else if (tv2 < 0) {\n tv2 = starts[0].p;\n } else {\n writeln(\"NO\");\n return;\n }\n starts = starts[1..$];\n } else {\n if (tv1 == ends[0].p) {\n tv1 = -1;\n } else if (tv2 == ends[0].p) {\n tv2 = -1;\n } else {\n writeln(\"NO\");\n return;\n }\n ends = ends[1..$];\n }\n }\n writeln(\"YES\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"t\", int, \"p\");\n auto n = getNum!int;\n auto startsAp = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (i; 0..n) {\n auto se = getVals!int;\n startsAp.put(Tp(se[0], i));\n endsAp.put(Tp(se[1], i));\n }\n auto starts = startsAp.data[];\n auto ends = endsAp.data[];\n starts.sort!\"a.t < b.t\";\n ends.sort!\"a.t < b.t\";\n auto tv1 = -1, tv2 = -1;\n while (starts.length > 0) {\n if (starts[0].t <= ends[0].t) {\n if (tv1 < 0) {\n tv1 = starts[0].p;\n } else if (tv2 < 0) {\n tv2 = starts[0].p;\n } else {\n writeln(\"NO\");\n return;\n }\n starts = starts[1..$];\n } else if (starts[0].t > ends[0].t) {\n if (tv1 == ends[0].p) {\n tv1 = -1;\n } else if (tv2 == ends[0].p) {\n tv2 = -1;\n } else {\n writeln(\"NO\");\n return;\n }\n ends = ends[1..$];\n }\n }\n writeln(\"YES\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split, appender;\nimport std.conv : to;\nimport std.typecons : Tuple;\nimport std.algorithm : sort;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n alias Tp = Tuple!(int, \"s\", int, \"e\", int, \"p\");\n auto n = getNum!int;\n auto ap = appender!(Tp[])();\n auto endsAp = appender!(Tp[])();\n foreach (i; 0..n) {\n auto se = getVals!int;\n ap.put(Tp(se[0], se[1], i));\n }\n auto prgs = ap.data[];\n prgs.sort!( (a, b) => a.s!=b.s ? a.s<b.s : (a.e!=b.e ? a.e<b.e : a.p<b.p) );\n auto tv1 = Tp(-1,-1,-1), tv2 = tv1;\n foreach (i,tp; prgs) {\n if (tv1.e < tp.s && tv2.e < tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv1.e < tp.s && tv2.e == tp.s) {\n tv1 = tp;\n continue;\n }\n if (tv2.e < tp.s && tv1.e == tp.s) {\n tv2 = tp;\n continue;\n }\n writeln(\"NO\");\n return;\n }\n writeln(tv2.e < 0 ? \"NO\" : \"YES\");\n}"}], "src_uid": "9fa772b53e655a55f2ec502bc96d0e28"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{ \n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto s = readln.chomp;\n s ~= '2';\n int le = 0, r = 0;\n int ans = 0;\n while (le < n) {\n r = max(r, le);\n \n bool found = false;\n while (r+1 < n && s[r] != s[r+1]) { ++r; }\n found = r+1 < n;\n ++r;\n \n if (!found) {\n while (le < n && (le == n-1 || s[le] == s[le+1])) { ++le; }\n ++le;\n }\n \n while (le < n && (le == n-1 || s[le] == s[le+1])) { ++le; }\n ++le;\n \n ans += 1;\n }\n \n ans.writeln;\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tchar last = s[0];\n\t\tint[] a;\n\t\tint cnt;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == last)\n\t\t\t\t++cnt;\n\t\t\telse\n\t\t\t{\n\t\t\t\ta ~= cnt;\n\t\t\t\tcnt = 1;\n\t\t\t\tlast = s[i];\n\t\t\t}\n\t\t}\n\t\ta ~= cnt;\n\t\tdebug writeln(a);\n\n\t\tlong c;\n\t\tforeach (e; a)\n\t\t{\n\t\t\t++c;\n\t\t\tauto x = min(e-1, c);\n\t\t\tc -= x;\n\t\t\tans[ti] += x;\n\t\t}\n\t\tans[ti] += (c+1) / 2;\n\t}\n\n\tforeach (ti; 0..t)\n\t{\n\t\twriteln(ans[ti]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "d0030996e6b29c8580463fae43bb04d4"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto G = new int[][](N);\n foreach (_; 0..N-1) {\n auto s = readln.split.map!(to!int);\n G[s[0]-1] ~= s[1]-1;\n G[s[1]-1] ~= s[0]-1;\n }\n auto A = readln.split.map!(x => x.to!int-1).array;\n\n auto D = new int[](N);\n auto E = new int[][](N);\n auto P = new int[](N);\n auto order = new int[](N);\n\n void dfs(int n, int p, int d) {\n P[n] = p;\n D[n] = d;\n E[d] ~= n;\n foreach (m; G[n]) if (m != p) dfs(m, n, d+1);\n }\n dfs(0, -1, 0);\n\n foreach (i; 0..N-1) {\n if (D[A[i]] > D[A[i+1]]) {\n writeln(\"No\");\n return;\n }\n }\n\n foreach (i; 1..N) {\n if (D[A[i]] > D[A[i-1]]) {\n order[A[i]] = 0;\n } else {\n order[A[i]] = order[A[i-1]] + 1;\n }\n }\n\n foreach (i; 0..N-1) {\n if (D[A[i]] == D[A[i+1]] && order[P[A[i]]] > order[P[A[i+1]]]) {\n writeln(\"No\");\n return;\n }\n }\n\n writeln(\"Yes\");\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\n\t\tauto d = new int [n];\n\t\tauto r = new int [n];\n\n\t\tvoid recur (int v, int p, int depth)\n\t\t{\n\t\t\td[v] = depth;\n\t\t\tr[v] = p;\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tif (u != p)\n\t\t\t\t{\n\t\t\t\t\trecur (u, v, depth + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0, n, 0);\n\n\t\tbool ok = true;\n\t\tscope (exit) {writeln (ok ? \"Yes\" : \"No\");}\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tok &= (d[p[i - 1]] <= d[p[i]]);\n\t\t}\n\t\tif (!ok)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto q = new int [n];\n\t\tforeach (i, c; p)\n\t\t{\n\t\t\tq[c] = i;\n\t\t}\n\t\tforeach (j; 2..n)\n\t\t{\n\t\t\tint i = j - 1;\n\t\t\tauto u = p[i];\n\t\t\tauto v = p[j];\n\t\t\tif (r[u] != r[v])\n\t\t\t{\n\t\t\t\tok &= (q[r[u]] < q[r[v]]);\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto g = new int[][] (n+1);\n foreach (_; 0 .. n-1) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n g[x] ~= y;\n g[y] ~= x;\n }\n \n auto ord = readln.chomp.split.map!(to!int).array;\n if (ord.front != 1) {\n writeln(\"No\");\n return;\n }\n \n auto nxt = make!(DList!(RedBlackTree!int));\n nxt ~= make!RedBlackTree(g[1]);\n foreach (e; ord.dropOne) {\n while (!nxt.empty && e !in nxt.front) {\n nxt.removeFront;\n }\n if (nxt.empty) {\n writeln(\"No\");\n return;\n }\n \n nxt ~= make!RedBlackTree(g[e]);\n }\n \n writeln(\"Yes\");\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto g = new int[][] (n+1);\n foreach (_; 0 .. n-1) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n g[x] ~= y;\n g[y] ~= x;\n }\n \n auto ord = readln.chomp.split.map!(to!int).array;\n if (ord.front != 1) {\n writeln(\"No\");\n return;\n }\n \n auto vis = new bool[] (n+1);\n auto nxt = make!(DList!(RedBlackTree!int));\n vis[1] = true;\n nxt ~= make!RedBlackTree(g[1]);\n foreach (e; ord.dropOne) {\n if (!e in nxt.front) {\n writeln(\"No\");\n return;\n }\n nxt.front.removeKey(e);\n \n vis[e] = true;\n nxt ~= make!(RedBlackTree!int);\n foreach (u; g[e]) if (!vis[u]) nxt.back.insert(u);\n \n if (nxt.front.empty()) nxt.removeFront();\n }\n \n writeln(\"Yes\");\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\n\t\tauto d = new int [n];\n\t\tauto r = new int [n];\n\n\t\tvoid recur (int v, int p, int depth)\n\t\t{\n\t\t\td[v] = depth;\n\t\t\tr[v] = p;\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tif (u != p)\n\t\t\t\t{\n\t\t\t\t\trecur (u, v, depth + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0, n, 0);\n\n\t\tbool ok = true;\n\t\tscope (exit) {writeln (ok ? \"Yes\" : \"No\");}\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tok &= (d[p[i - 1]] <= d[p[i]]);\n\t\t}\n\t\tif (!ok)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tcontinue;\n\n\t\tauto q = new int [n];\n\t\tforeach (i, c; p)\n\t\t{\n\t\t\tq[c] = i;\n\t\t}\n\t\tforeach (j; 2..n)\n\t\t{\n\t\t\tint i = j - 1;\n\t\t\tauto u = p[i];\n\t\t\tauto v = p[j];\n\t\t\tif (r[u] != r[v])\n\t\t\t{\n\t\t\t\tok &= (q[r[u]] < q[r[v]]);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "src_uid": "82ff8ae62e39b8e64f9a273b736bf59e"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. scan!int){\n long x = scan!long;\n print(1, x - 1);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\treadf(\" %d\", &a);\n\t\twriteln(1);\n\t\twriteln(a-1);\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "2fa3e88688b92c27ad26a23884e26009"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint [] solve (bool [] s)\n{\n\tif (s.length < 2)\n\t{\n\t\treturn [];\n\t}\n\tauto res = solve (s[0..$ - 1]);\n\tif (s[$ - 2] == s[$ - 1])\n\t{\n\t\treturn res ~ 0;\n\t}\n\telse\n\t{\n\t\treverse (s[0..$ - 1]);\n\t\treturn res ~ 1;\n\t}\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto t = s.map !(c => c == 'b').array ~ true;\n\t\twritefln (\"%(%s %)\", solve (t));\n\t}\n}\n", "positive_code": [{"source_code": "import std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto n = s.length;\n\t\tint last = 'b';\n\t\tint [] ans;\n\t\tforeach_reverse (c; s)\n\t\t{\n\t\t\tif (c == last)\n\t\t\t{\n\t\t\t\tans ~= 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans ~= 1;\n\t\t\t\tlast = 'a' + 'b' - last;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", ans.retro);\n\t}\n}\n"}], "negative_code": [], "src_uid": "fc0d3b122d800dcbcb99795581229d42"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n int[] AA; get(AA);\r\n sort(AA);\r\n foreach (i; 0..N*2-1) {\r\n int[][int] memo;\r\n foreach_reverse (j, a; AA[0..$-1]) if (i != j) memo[a] ~= j.to!int;\r\n auto aa = new int[](N);\r\n aa[0] = AA[$-1];\r\n auto bb = new int[](N);\r\n bb[0] = AA[i];\r\n auto j = N*2 - 1;\r\n if (i == j) --j;\r\n auto fs = new bool[](N * 2);\r\n fs[$-1] = fs[i] = true;\r\n foreach (k; 1..N) {\r\n auto x = aa[k-1];\r\n while (fs[j]) --j;\r\n auto a = AA[j];\r\n memo[a].popFront();\r\n fs[j] = true;\r\n --j;\r\n auto b = x - a;\r\n if (b !in memo || memo[b].empty) goto ng;\r\n fs[memo[b].front] = true;\r\n memo[b].popFront();\r\n aa[k] = a;\r\n bb[k] = b;\r\n }\r\n writeln(\"YES\\n\", aa[0] + bb[0]);\r\n foreach (k; 0..N) writeln(aa[k], \" \", bb[k]);\r\n goto ok;\r\n ng:\r\n }\r\n writeln(\"NO\");\r\n continue;\r\n ok:\r\n }\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.container;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int limit = 10 ^^ 6 + 1;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\tRedBlackTree !(int, q{a < b}, true) t;\r\n\r\n\t\tint [2] [] solve (int lo, int hi)\r\n\t\t{\r\n\t\t\tint [2] [] answer = [[lo, hi]];\r\n\t\t\tint cur = hi;\r\n\t\t\tforeach (j; 0..n - 1)\r\n\t\t\t{\r\n\t\t\t\tauto two = t.back;\r\n\t\t\t\tt.removeBack ();\r\n\t\t\t\tauto one = cur - two;\r\n\t\t\t\tif (one !in t)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn null;\r\n\t\t\t\t}\r\n\t\t\t\tt.removeKey (one);\r\n\t\t\t\tanswer ~= [one, two];\r\n\t\t\t\tcur = two;\r\n\t\t\t}\r\n\t\t\treturn answer;\r\n\t\t}\r\n\r\n\t\tauto hi = a.back;\r\n\t\ta.popBack ();\r\n\t\tauto t0 = redBlackTree !(true, int) (a);\r\n\t\tint [2] [] answer;\r\n\t\tforeach (ref b; a)\r\n\t\t{\r\n\t\t\tt = t0.dup;\r\n\t\t\tt.removeKey (b);\r\n\t\t\tanswer = solve (b, hi);\r\n\t\t\tif (answer !is null)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (answer !is null)\r\n\t\t{\r\n\t\t\twriteln (\"YES\");\r\n\t\t\twriteln (answer.front[].sum);\r\n\t\t\twritefln !(\"%(%(%s %)\\n%)\") (answer);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln (\"NO\");\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{ \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto n = readln.chomp.to!int;\r\n auto arr = readln.chomp.split.map!(to!int).array;\r\n \r\n arr.sort();\r\n \r\n bool found = false;\r\n foreach (start; 0 .. 2*n - 1) {\r\n int[int] cnt;\r\n foreach (e; arr) { ++cnt[e]; }\r\n Tuple!(int, int)[] result;\r\n \r\n int x = arr[2*n-1] + arr[start];\r\n int pos = 2*n-1;\r\n while (pos >= 0) {\r\n if (cnt[arr[pos]] == 0) {\r\n --pos;\r\n continue;\r\n }\r\n \r\n int now = arr[pos];\r\n --cnt[now];\r\n \r\n int need = x - now;\r\n debug { writeln(\"pos \", pos, \" now: \", now, \" need: \", need); }\r\n if (need !in cnt || cnt[need] == 0) {\r\n break;\r\n }\r\n \r\n --cnt[need];\r\n result ~= tuple(need, now);\r\n \r\n x = now;\r\n \r\n --pos;\r\n }\r\n \r\n if (result.length == n) {\r\n writeln(\"YES\");\r\n writeln(result[0][0] + result[0][1]);\r\n foreach (r; result) { writeln(r[0], ' ', r[1]); }\r\n found = true;\r\n break;\r\n }\r\n }\r\n \r\n if (!found) { writeln(\"NO\"); }\r\n }\r\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{\r\n immutable int MAXN = 10 ^^ 6;\r\n \r\n auto cnt = new int[] (MAXN + 23);\r\n \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto n = readln.chomp.to!int;\r\n auto arr = readln.chomp.split.map!(to!int).array;\r\n \r\n arr.sort();\r\n \r\n bool found = false;\r\n foreach (start; 0 .. 2*n - 1) {\r\n foreach (e; arr) { cnt[e] = 0; }\r\n foreach (e; arr) { ++cnt[e]; }\r\n Tuple!(int, int)[] result;\r\n \r\n int x = arr[2*n-1] + arr[start];\r\n int pos = 2*n-1;\r\n while (pos >= 0) {\r\n if (cnt[arr[pos]] == 0) {\r\n --pos;\r\n continue;\r\n }\r\n \r\n int now = arr[pos];\r\n cnt[now] -= 1;\r\n \r\n int need = x - now;\r\n debug { writeln(\"pos \", pos, \" now: \", now, \" need: \", need); }\r\n if (cnt[need] == 0) {\r\n break;\r\n }\r\n \r\n --cnt[need];\r\n result ~= tuple(need, now);\r\n \r\n x = now;\r\n \r\n --pos;\r\n }\r\n \r\n if (result.length == n) {\r\n writeln(\"YES\");\r\n writeln(result[0][0] + result[0][1]);\r\n foreach (r; result) { writeln(r[0], ' ', r[1]); }\r\n found = true;\r\n break;\r\n }\r\n }\r\n \r\n if (!found) { writeln(\"NO\"); }\r\n }\r\n}"}], "src_uid": "d54205c8096408ae64b15ab0a344582e"} {"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\nimport std.range.primitives;\n\nalias ll = long;\nalias rbt = RedBlackTree;\nalias sr = SortedRange;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n SortedRange!(ll[])[] sectors;\n foreach(i; 0..n){\n sectors ~= sort(rdarr[1..$]);\n }\n // Check each cell in sector left & right\n ll cnt = 0;\n foreach(i; 0..n){\n int l = (i - 1 + n) % n;\n int r = (i + 1) % n;\n ll lold, rold;\n // writeln(sectors[i].length);\n foreach(k; 0..sectors[i].length){\n ll lnew = sectors[l].lowerBound(sectors[i][k]).length;\n ll rnew = sectors[r].lowerBound(sectors[i][k]).length;\n if(k != 0){\n ll lside = lnew - lold;\n ll rside = rnew - rold;\n if(lside != rside) ++cnt;\n /* debug writeln(lside, \" | \", rside, \" | \", i, \" \", k); */\n }\n lold = lnew;\n rold = rnew;\n }\n }\n writeln(cnt);\n}\n\nvoid main(){\n long t = 1;\n /* t = rd; */\n while(t--) solve();\n stdout.flush;\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = new int[][] (n);\n foreach (i; 0 .. n) {\n int nr;\n readf(\"%s \", &nr);\n \n arr[i] = readln.chomp.split.map!(to!int).array.sort().array;\n }\n \n debug { arr.each!writeln; }\n \n int ans = 0;\n foreach (i; 0 .. n) {\n int go(int c, ref int st, int e) {\n int ans = 0;\n while (st < arr[c].length && arr[c][st] < e) {\n ++st;\n ++ans;\n }\n \n return ans;\n }\n \n int prv = (i - 1 + n) % n;\n int nxt = (i + 1) % n;\n \n int cidx = 0, pidx = 0, nidx = 0;\n while (cidx < arr[i].length) {\n int cle = go(prv, pidx, arr[i][cidx]);\n int cr = go(nxt, nidx, arr[i][cidx]);\n \n if (cidx > 0 && cle != cr) { \n ++ans;\n \n debug { writeln(i, ' ', cidx, ' ', cle, ' ', cr); }\n }\n \n ++cidx;\n }\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "c8951278f649e78e5fae5c2b2b844315"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nint [] solve (int n, string s, string t) {\n\tint lo = n / 2, hi = lo;\n\tint [] res;\n\n\tstring op (string s, int x) {\n\t\tres ~= x;\n\t\treturn s[$ - x..$].retro.text ~ s[0..$ - x];\n\t}\n\n\twhile (hi - lo < n) {\n\t\tauto x = (hi ^ lo) & 1;\n\t\tauto p = s.drop (hi - lo).countUntil (x ? t[lo - 1] : t[hi]);\n\t\tif (p == -1) return [];\n\t\ts = op (s, n - hi + lo - p);\n\t\ts = op (s, p);\n\t\ts = op (s, n);\n\t\tif (x) lo -= 1;\n\t\telse hi += 1;\n\t}\n\tif (s != t) s = op (s, n);\n\treturn res;\n}\n\nvoid main () {\n\tauto n = readln.strip.to!int, s = readln.strip, t = readln.strip;\n\tauto res = solve (n, s, t);\n\tif (res.empty) writeln (-1);\n\telse writefln (\"%s\\n%(%s %)\", res.length, res);\n}\n", "positive_code": [{"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint n;\n\tread(n);\n\tauto ss = readln.strip;\n\tauto tt = readln.strip;\n\tchar[] s, t;\n\tforeach (c; ss)\n\t{\n\t\ts ~= c;\n\t}\n\tforeach (c; tt)\n\t{\n\t\tt ~= c;\n\t}\n\tint[] ans;\n\tforeach (i; 0 .. n)\n\t{\n\t\tchar c = t[n - i - 1];\n\t\tdebug writeln(c);\n\t\tint pos = -1;\n\t\tforeach (j; i .. n)\n\t\t{\n\t\t\tif (s[j] == c)\n\t\t\t{\n\t\t\t\tpos = j;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (pos == -1)\n\t\t\treturn writeln(-1);\n\t\tans ~= n;\n\t\treverse(s);\n\t\tpos = n - pos - 1;\n\t\tans ~= n - pos - 1;\n\t\treverse(s[pos + 1 .. n]);\n\t\ts = s[pos .. n] ~ s[0 .. pos];\n\t\tans ~= 1;\n\t}\n\twriteln(ans.length);\n\tforeach (x; ans)\n\t{\n\t\twrite(x, ' ');\n\t}\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint [] solve (int n, string s, string t)\n{\n\tauto lo = n / 2;\n\tauto hi = lo;\n\tint [] res;\n\n\tstring op (string s, int x)\n\tin\n\t{\n\t\tdebug {writeln (\"op \", s, \" \", x);}\n\t}\n\tout (ans)\n\t{\n\t\tdebug {writeln (ans);}\n\t}\n\tbody\n\t{\n\t\tres ~= x;\n\t\treturn s[$ - x..$].retro.text ~ s[0..$ - x];\n\t}\n\n\twhile (hi - lo < n)\n\t{\n\t\tdebug {writeln (lo, \" \", hi);}\n\t\tif ((hi - lo) & 1)\n\t\t{\n\t\t\tauto p = s.drop (hi - lo).countUntil (t[lo - 1]);\n\t\t\tdebug {writeln (p);}\n\t\t\tif (p == -1)\n\t\t\t{\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\ts = op (s, n - hi + lo - p);\n\t\t\ts = op (s, p);\n\t\t\ts = op (s, n);\n\t\t\tlo -= 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto p = s.drop (hi - lo).countUntil (t[hi]);\n\t\t\tdebug {writeln (p);}\n\t\t\tif (p == -1)\n\t\t\t{\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\ts = op (s, n - hi + lo - p);\n\t\t\ts = op (s, p);\n\t\t\ts = op (s, n);\n\t\t\thi += 1;\n\t\t}\n\t}\n\tif (s != t)\n\t{\n\t\ts = op (s, n);\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\tauto t = readln.strip;\n\t\tauto res = solve (n, s, t);\n\t\tif (res.empty)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (res.length);\n\t\t\twritefln (\"%(%s %)\", res);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nint [] g (S) (int n, S s, S t) {\n\tauto x = n / 2, y = x, r = [0];\n\n\tvoid f (int x) {\n\t\tr ~= x;\n\t\ts = s[$ - x..$].retro.text ~ s[0..$ - x];\n\t}\n\n\twhile (y - x < n) {\n\t\tauto z = (y ^ x) & 1, p = s[y - x..$].countUntil (z ? t[x - 1] : t[y]);\n\t\tif (p < 0) return [];\n\t\tf (n - y + x - p); f (p); f (n);\n\t\tif (z) x -= 1; else y += 1;\n\t}\n\tif (s != t) f (n);\n\treturn r;\n}\n\nvoid main () {\n\tauto n = readln.strip.to!int, s = readln.strip, t = readln.strip, r = g (n, s, t);\n\twritefln (\"%s\\n%(%s %)\", r.length.to!int - 1, r.drop (1));\n}\n"}], "negative_code": [], "src_uid": "df0b20cf9b848f7406a13378126f301f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto x = RD;\n\t\tauto a = RDA;\n\t\t\n\t\tbool ok = true;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] < a[i-1])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t}\n\t\tif (ok) continue;\n\n\t\tok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] > x)\n\t\t\t{\n\t\t\t\tswap(a[i], x);\n\t\t\t\t++ans[ti];\n\t\t\t\tbool done = true;\n\t\t\t\tforeach (j; i+1..n)\n\t\t\t\t{\n\t\t\t\t\tif (a[j] < a[j-1])\n\t\t\t\t\t{\n\t\t\t\t\t\tdone = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (done) break;\n\t\t\t}\n\t\t\telse if (a[i] < a[i-1])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t}\n\t\tif (!ok)\n\t\t\tans[ti] = -1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x;\n\t\treadf !(\" %s %s\") (n, x);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint pos = 0;\n\t\tint steps = 0;\n\t\twhile (pos < n && !a.isSorted)\n\t\t{\n\t\t\twhile (pos < n && a[pos] <= x)\n\t\t\t{\n\t\t\t\tpos += 1;\n\t\t\t}\n\t\t\tif (pos < n)\n\t\t\t{\n\t\t\t\tswap (x, a[pos]);\n\t\t\t\tsteps += 1;\n\t\t\t}\n\t\t}\n\t\twriteln (a.isSorted ? steps : -1);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto x = RD;\n\t\tauto a = RDA;\n\t\t\n\t\tbool ok = true;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] < a[i-1])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t}\n\t\tif (ok) continue;\n\n\t\tok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] > x)\n\t\t\t{\n\t\t\t\tswap(a[i], x);\n\t\t\t\t++ans[ti];\n\t\t\t}\n\t\t\telse if (a[i] < a[i-1])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t}\n\t\tif (!ok)\n\t\t\tans[ti] = -1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto x = RD;\n\t\tauto a = RDA;\n\t\t\n\t\tbool ok = true;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] < a[i-1])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t}\n\t\tif (ok) continue;\n\n\t\tok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i == n-1 && a[i] >= a[i-1]) continue;\n\t\t\tif (a[i] > x)\n\t\t\t{\n\t\t\t\tswap(a[i], x);\n\t\t\t\t++ans[ti];\n\t\t\t}\n\t\t\telse if (a[i] < a[i-1])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t}\n\t\tif (!ok)\n\t\t\tans[ti] = -1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "dc67f1ad9d93ce83cd83f09fa4842ad4"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tA: foreach(_; 0 .. rint){\n\t\tstring s = readln.chomp;\n\t\tint[] as = s.map!(c => (c - 'a').to!int).array;\n\t\tint n = s.length.to!int;\n\n\t\tif(n == 1){\n\t\t\t\"YES\".writeln;\n\t\t\t\"abcdefghijklmnopqrstuvwxyz\".writeln;\n\t\t\tcontinue A;\n\t\t}\n\n\n\t\tbool[][] xf = new bool[][](26, 26);\n\t\tforeach(i; 0 .. n - 1){\n\t\t\tint a = as[i], b = as[i + 1];\n\t\t\txf[a][b] = 1, xf[b][a] = 1;\n\t\t}\n\n\t\tint start = -1, end = -1;\n\t\tint[] cnt = new int[](26);\n\t\tforeach(a; 0 .. 26){\n\t\t\tforeach(b; 0 .. 26){\n\t\t\t\tif(xf[a][b]) cnt[a] += 1;\n\t\t\t}\n\t\t\tif(cnt[a] > 2){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t\tif(cnt[a] == 1){\n\t\t\t\tif(start < 0) start = a;\n\t\t\t\telse end = a;\n\t\t\t}\n\t\t}\n\n\t\tif(start < 0){\n\t\t\t\"NO\".writeln;\n\t\t\tcontinue A;\n\t\t}\n\n\t\t\"YES\".writeln;\n\n\t\tint x = start;\n\t\tint oldx = -1;\n\t\twrite(\"abcdefghijklmnopqrstuvwxyz\"[x]);\n\t\twhile(x != end){\n\t\t\tforeach(b; 0 .. 26) if(xf[x][b] && b != oldx){\n\t\t\t\toldx = x;\n\t\t\t\tx = b;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\twrite(\"abcdefghijklmnopqrstuvwxyz\"[x]);\n\t\t}\n\n\t\tforeach(a; 0 .. 26) if(cnt[a] == 0) write(\"abcdefghijklmnopqrstuvwxyz\"[a]);\n\t\twriteln(\"\");\n\t}\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto T = RD!int;\n\tauto ans = new string[](T);\n\tforeach (ti; 0..T)\n\t{\n\t\tauto s = RD!string;\n\t\tauto edges = new bool[][](26, 26);\n\t\tif (s.length == 2)\n\t\t{\n\t\t\tauto l = s[0]-'a';\n\t\t\tauto r = s[1]-'a';\n\t\t\tedges[l][r] = true;\n\t\t\tedges[r][l] = true;\n\t\t}\n\t\tforeach (i; 1..s.length-1)\n\t\t{\n\t\t\tauto m = s[i]-'a';\n\t\t\tauto l = s[i-1]-'a';\n\t\t\tauto r = s[i+1]-'a';\n\t\t\tedges[m][l] = true;\n\t\t\tedges[m][r] = true;\n\t\t\tedges[l][m] = true;\n\t\t\tedges[r][m] = true;\n\t\t}\n\t\tbool ok = true;\n\t\tint[] list;\n\t\tforeach (i, e; edges)\n\t\t{\n\t\t\tint cnt;\n\t\t\tforeach (ee; e)\n\t\t\t{\n\t\t\t\tif (ee)\n\t\t\t\t\t++cnt;\n\t\t\t}\n\t\t\tif (cnt >= 3)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (cnt == 1)\n\t\t\t{\n\t\t\t\tlist ~= cast(int)i;\n\t\t\t}\n\t\t\telse if (cnt == 0)\n\t\t\t{\n\t\t\t\tans[ti] ~= cast(char)(i+'a');\n\t\t\t}\n\t\t}\n\t\tdebug writeln(ans[ti]);\n\t\tif (!ok)\n\t\t{\n\t\t\tans[ti] = [];\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto used = new int[](26);\n\t\tvoid dfs(int i, int par)\n\t\t{\n\t\t\tused[i] = true;\n\t\t\tans[ti] ~= cast(char)(i+'a');\n\t\t\tforeach (j; 0..26)\n\t\t\t{\n\t\t\t\tif (j == par) continue;\n\t\t\t\tif (edges[i][j])\n\t\t\t\t{\n\t\t\t\t\tdfs(j, i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tforeach (e; list)\n\t\t{\n\t\t\tif (used[e] == false)\n\t\t\t\tdfs(e, -1);\n\t\t}\n\t\tdebug writeln(ans[ti]);\n\t\tif (ans[ti].length != 26)\n\t\t\tans[ti] = [];\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(\"NO\");\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(e);\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tA: foreach(_; 0 .. rint){\n\t\tstring s = readln.chomp;\n\t\tint[] as = s.map!(c => (c - 'a').to!int).array;\n\t\tint n = s.length.to!int;\n\t\tbool[][] xf = new bool[][](26, 26);\n\t\tforeach(i; 0 .. n - 1){\n\t\t\tint a = as[i], b = as[i + 1];\n\t\t\txf[a][b] = 1, xf[b][a] = 1;\n\t\t}\n\n\t\tint start = -1, end = -1;\n\t\tint[] cnt = new int[](26);\n\t\tforeach(a; 0 .. 26){\n\t\t\tforeach(b; 0 .. 26){\n\t\t\t\tif(xf[a][b]) cnt[a] += 1;\n\t\t\t}\n\t\t\tif(cnt[a] > 2){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t\tif(cnt[a] == 1){\n\t\t\t\tif(start < 0) start = a;\n\t\t\t\telse end = a;\n\t\t\t}\n\t\t}\n\n\t\tif(start < 0){\n\t\t\t\"NO\".writeln;\n\t\t\tcontinue A;\n\t\t}\n\n\t\tint x = start;\n\t\tint oldx = -1;\n\t\twrite(\"abcdefghijklmnopqrstuvwxyz\"[x]);\n\t\twhile(x != end){\n\t\t\tforeach(b; 0 .. 26) if(xf[x][b] && b != oldx){\n\t\t\t\toldx = x;\n\t\t\t\tx = b;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\twrite(\"abcdefghijklmnopqrstuvwxyz\"[x]);\n\t\t}\n\n\t\tforeach(a; 0 .. 26) if(cnt[a] == 0) write(\"abcdefghijklmnopqrstuvwxyz\"[a]);\n\t\twriteln(\"\");\n\t}\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tA: foreach(_; 0 .. rint){\n\t\tstring s = readln.chomp;\n\t\tint[] as = s.map!(c => (c - 'a').to!int).array;\n\t\tint n = s.length.to!int;\n\t\tbool[][] xf = new bool[][](26, 26);\n\t\tforeach(i; 0 .. n - 1){\n\t\t\tint a = as[i], b = as[i + 1];\n\t\t\txf[a][b] = 1, xf[b][a] = 1;\n\t\t}\n\n\t\tint start = -1, end = -1;\n\t\tint[] cnt = new int[](26);\n\t\tforeach(a; 0 .. 26){\n\t\t\tforeach(b; 0 .. 26){\n\t\t\t\tif(xf[a][b]) cnt[a] += 1;\n\t\t\t}\n\t\t\tif(cnt[a] > 2){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t\tif(cnt[a] == 1){\n\t\t\t\tif(start < 0) start = a;\n\t\t\t\telse end = a;\n\t\t\t}\n\t\t}\n\n\t\tif(start < 0){\n\t\t\t\"NO\".writeln;\n\t\t\tcontinue A;\n\t\t}\n\n\t\t\"YES\".writeln;\n\n\t\tint x = start;\n\t\tint oldx = -1;\n\t\twrite(\"abcdefghijklmnopqrstuvwxyz\"[x]);\n\t\twhile(x != end){\n\t\t\tforeach(b; 0 .. 26) if(xf[x][b] && b != oldx){\n\t\t\t\toldx = x;\n\t\t\t\tx = b;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\twrite(\"abcdefghijklmnopqrstuvwxyz\"[x]);\n\t\t}\n\n\t\tforeach(a; 0 .. 26) if(cnt[a] == 0) write(\"abcdefghijklmnopqrstuvwxyz\"[a]);\n\t\twriteln(\"\");\n\t}\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto T = RD!int;\n\tauto ans = new string[](T);\n\tforeach (ti; 0..T)\n\t{\n\t\tauto s = RD!string;\n\t\tauto edges = new bool[][](26, 26);\n\t\tforeach (i; 1..s.length-1)\n\t\t{\n\t\t\tauto m = s[i]-'a';\n\t\t\tauto l = s[i-1]-'a';\n\t\t\tauto r = s[i+1]-'a';\n\t\t\tedges[m][l] = true;\n\t\t\tedges[m][r] = true;\n\t\t\tedges[l][m] = true;\n\t\t\tedges[r][m] = true;\n\t\t}\n\t\tbool ok = true;\n\t\tint[] list;\n\t\tforeach (i, e; edges)\n\t\t{\n\t\t\tint cnt;\n\t\t\tforeach (ee; e)\n\t\t\t{\n\t\t\t\tif (ee)\n\t\t\t\t\t++cnt;\n\t\t\t}\n\t\t\tif (cnt >= 3)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (cnt == 1)\n\t\t\t{\n\t\t\t\tlist ~= cast(int)i;\n\t\t\t}\n\t\t\telse if (cnt == 0)\n\t\t\t{\n\t\t\t\tans[ti] ~= cast(char)(i+'a');\n\t\t\t}\n\t\t}\n\t\tdebug writeln(ans[ti]);\n\t\tif (!ok)\n\t\t{\n\t\t\tans[ti] = [];\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto used = new int[](26);\n\t\tvoid dfs(int i, int par)\n\t\t{\n\t\t\tused[i] = true;\n\t\t\tans[ti] ~= cast(char)(i+'a');\n\t\t\tforeach (j; 0..26)\n\t\t\t{\n\t\t\t\tif (j == par) continue;\n\t\t\t\tif (edges[i][j])\n\t\t\t\t{\n\t\t\t\t\tdfs(j, i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tforeach (e; list)\n\t\t{\n\t\t\tif (used[e] == false)\n\t\t\t\tdfs(e, -1);\n\t\t}\n\t\tdebug writeln(ans[ti]);\n\t\tif (ans[ti].length != 26)\n\t\t\tans[ti] = [];\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t\twriteln(\"NO\");\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(e);\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "8fb62b497b6fb2a5fb4f2669aeb51b73"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias Tuple!(int, \"to\", long, \"cost\") Edge;\r\n\r\nvoid solve() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto G = new Edge[][N];\r\n foreach (m; 0 .. M) {\r\n int i, j; string c; readf(\"%d %d %s\\n\", &i, &j, &c);\r\n i--; j--;\r\n int ci;\r\n if (c == \"imposter\") {\r\n ci = 1;\r\n } else {\r\n assert(c == \"crewmate\");\r\n ci = 0;\r\n }\r\n G[i] ~= Edge(j, ci);\r\n G[j] ~= Edge(i, ci);\r\n }\r\n\r\n auto truth = new int[N];\r\n truth[] = -1;\r\n\r\n Tuple!(int,int) dfs(int v, int c, int p) {\r\n auto ans = tuple(c, 1); // number of imposters, number of members in this group\r\n foreach (e; G[v]) {\r\n if (e.to == p) continue;\r\n int nc_should = (c + e.cost) % 2;\r\n if (truth[e.to] >= 0) {\r\n if (truth[e.to] != nc_should) return tuple(-1, 0);\r\n } else {\r\n truth[e.to] = nc_should;\r\n auto r = dfs(e.to, nc_should, v);\r\n if (r[0] < 0) return tuple(-1, 0);\r\n ans[0] += r[0];\r\n ans[1] += r[1];\r\n }\r\n }\r\n return ans;\r\n }\r\n\r\n int ans = 0;\r\n for (int i = 0; i < N; i++) {\r\n if (truth[i] < 0) {\r\n truth[i] = 0;\r\n auto r = dfs(i, 0, -1);\r\n if (r[0] < 0) {\r\n ans = -1;\r\n break;\r\n } else {\r\n ans += max(r[0], r[1] - r[0]);\r\n }\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nenum int INF = 1<<30;\r\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n\nint find(int v, int[] dsu){\n if(dsu[v] == -1) return v;\n return (dsu[v] = find(dsu[v], dsu));\n}\n\nbool onion(int u, int v, int[] dsu){\n int uid = find(u, dsu);\n int vid = find(v, dsu);\n if(uid != vid) dsu[vid] = uid;\n return (uid != vid);\n}\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n auto dsu = new int[](2*n+2);\n dsu[] = -1;\n auto cnt = new int[](2*n + 2);\n int[] qr, uarr, varr;\n for(int i = 0; i < m; ++i){\n int u = scan!int;\n int v = scan!int;\n auto oper = scan!(dchar[]);\n uarr ~= u;\n varr ~= v;\n if(oper == to!(dchar[])(\"imposter\")){\n qr ~= 1;\n }else{\n qr ~= 0;\n }\n }\n for(int i = 0; i < m; ++i){\n int u = uarr[i];\n int v = varr[i];\n if(qr[i]){\n int uid = find(u, dsu);\n if(uid == find(v, dsu)){\n writeln(-1);\n return;\n }\n onion(uid, n+v, dsu);\n onion(v, n+u, dsu);\n }else{\n int uinv = find(n+u, dsu);\n if(uinv == find(v, dsu)){\n writeln(-1);\n return;\n }\n onion(uinv, n+v, dsu);\n onion(v, u, dsu);\n }\n }\n auto rbt = redBlackTree!int;\n for(int i = 1; i <= n; ++i){\n int iid = find(i, dsu);\n cnt[iid] += 1;\n rbt.insert(iid);\n }\n ll res = 0;\n foreach(iid; rbt){\n int opp = (iid > n) ? iid - n : n + iid;\n int inv = find(opp, dsu);\n res += max(cnt[iid], cnt[inv]);\n cnt[iid] = 0;\n cnt[inv] = 0;\n }\n writeln(res);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n\nint find(int v, int[] dsu){\n if(dsu[v] == -1) return v;\n return (dsu[v] = find(dsu[v], dsu));\n}\n\nbool onion(int u, int v, int[] dsu){\n int uid = find(u, dsu);\n int vid = find(v, dsu);\n if(uid != vid) dsu[vid] = uid;\n return (uid != vid);\n}\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n auto dsu = new int[](2*n+2);\n dsu[] = -1;\n auto cnt = new int[](2*n + 2);\n int[] qr, uarr, varr;\n for(int i = 0; i < m; ++i){\n int u = scan!int;\n int v = scan!int;\n auto oper = scan!(dchar[]);\n uarr ~= u;\n varr ~= v;\n if(oper == to!(dchar[])(\"imposter\")){\n qr ~= 1;\n }else{\n qr ~= 0;\n }\n }\n for(int i = 0; i < m; ++i){\n int u = uarr[i];\n int v = varr[i];\n if(qr[i]){\n int uid = find(u, dsu);\n if(uid == find(v, dsu)){\n writeln(-1);\n return;\n }\n onion(uid, n+v, dsu);\n onion(v, n+u, dsu);\n }else{\n int uinv = find(n+u, dsu);\n if(uinv == find(v, dsu)){\n writeln(-1);\n return;\n }\n onion(uinv, n+v, dsu);\n onion(v, u, dsu);\n }\n }\n auto rbt = redBlackTree!int;\n for(int i = 1; i <= n; ++i){\n int iid = find(i, dsu);\n cnt[iid] += 1;\n if(iid <= n){\n rbt.insert(iid);\n }else{\n rbt.insert(iid - n);\n }\n }\n ll res = 0;\n foreach(iid; rbt){\n int inv = find(n+iid, dsu);\n res += max(cnt[iid], cnt[inv]);\n cnt[iid] = 0;\n cnt[inv] = 0;\n }\n writeln(res);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n\nint find(int v, int[] dsu){\n if(dsu[v] == -1) return v;\n return (dsu[v] = find(dsu[v], dsu));\n}\n\nbool onion(int u, int v, int[] dsu){\n int uid = find(u, dsu);\n int vid = find(v, dsu);\n if(uid != vid) dsu[vid] = uid;\n return (uid != vid);\n}\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n auto dsu = new int[](2*n+2);\n dsu[] = -1;\n auto cnt = new int[](2*n + 2);\n int[] qr, uarr, varr;\n for(int i = 0; i < m; ++i){\n int u = scan!int;\n int v = scan!int;\n auto oper = scan!(dchar[]);\n uarr ~= u;\n varr ~= v;\n if(oper == to!(dchar[])(\"imposter\")){\n qr ~= 1;\n }else{\n qr ~= 0;\n }\n }\n for(int i = 0; i < m; ++i){\n int u = uarr[i];\n int v = varr[i];\n if(qr[i]){\n int uid = find(u, dsu);\n if(uid == find(v, dsu)){\n writeln(-1);\n return;\n }\n onion(uid, n+v, dsu);\n onion(v, n+u, dsu);\n }else{\n int uinv = find(n+u, dsu);\n if(uinv == find(v, dsu)){\n writeln(-1);\n return;\n }\n onion(uinv, n+v, dsu);\n onion(v, u, dsu);\n }\n }\n auto rbt = redBlackTree!int;\n for(int i = 1; i <= n; ++i){\n int iid = find(i, dsu);\n cnt[iid] += 1;\n if(iid <= n){\n rbt.insert(iid);\n }\n }\n ll res = 0;\n foreach(iid; rbt){\n int inv = find(n+iid, dsu);\n res += max(cnt[iid], cnt[inv]);\n cnt[iid] = 0;\n cnt[inv] = 0;\n }\n writeln(res);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n\nint find(int v, int[] dsu){\n if(dsu[v] == -1) return v;\n return (dsu[v] = find(dsu[v], dsu));\n}\n\nbool onion(int u, int v, int[] dsu){\n int uid = find(u, dsu);\n int vid = find(v, dsu);\n if(uid != vid) dsu[vid] = uid;\n return (uid != vid);\n}\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n auto dsu = new int[](2*n+2);\n dsu[] = -1;\n auto cnt = new int[2*n+2];\n int[] qr, uarr, varr;\n for(int i = 0; i < m; ++i){\n int u = scan!int;\n int v = scan!int;\n auto oper = scan!(dchar[]);\n uarr ~= u;\n varr ~= v;\n if(oper == to!(dchar[])(\"imposter\")){\n qr ~= 1;\n }else{\n qr ~= 0;\n }\n }\n for(int i = 0; i < m; ++i){\n int u = uarr[i];\n int v = varr[i];\n if(qr[i]){\n int uid = find(u, dsu);\n if(uid == find(v, dsu)){\n writeln(-1);\n return;\n }\n onion(uid, n+v, dsu);\n onion(v, n+u, dsu);\n }else{\n int uinv = find(n+u, dsu);\n if(uinv == find(v, dsu)){\n writeln(-1);\n return;\n }\n onion(uinv, n+v, dsu);\n onion(v, u, dsu);\n }\n }\n auto rbt = redBlackTree!int;\n for(int i = 1; i <= n; ++i){\n int iid = find(i, dsu);\n cnt[iid] += 1;\n if(iid <= n){\n rbt.insert(iid);\n }\n }\n ll res = 0;\n if(rbt.length){\n foreach(iid; rbt){\n int inv = find(n+iid, dsu);\n res += max(cnt[iid], cnt[inv]);\n cnt[iid] = 0;\n cnt[inv] = 0;\n }\n }\n writeln(res);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nalias Tuple!(int, \"to\", long, \"cost\") Edge;\r\n\r\nvoid solve() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto G = new Edge[][N];\r\n foreach (m; 0 .. M) {\r\n int i, j; string c; readf(\"%d %d %s\\n\", &i, &j, &c);\r\n i--; j--;\r\n int ci;\r\n if (c == \"imposter\") {\r\n ci = 1;\r\n } else {\r\n assert(c == \"crewmate\");\r\n ci = 0;\r\n }\r\n G[i] ~= Edge(j, ci);\r\n G[j] ~= Edge(i, ci);\r\n }\r\n\r\n auto truth = new int[N];\r\n truth[] = -1;\r\n\r\n Tuple!(int,int) dfs(int v, int c, int p) {\r\n auto ans = tuple(c, 1); // number of imposters, number of members in this group\r\n foreach (e; G[v]) {\r\n if (e.to == p) continue;\r\n int nc_should = (c + e.cost) % 2;\r\n if (truth[e.to] >= 0) {\r\n if (truth[e.to] != nc_should) return tuple(-1, 0);\r\n } else {\r\n truth[e.to] = nc_should;\r\n auto r = dfs(e.to, nc_should, v);\r\n if (r[0] < 0) return tuple(-1, 0);\r\n ans[0] += r[0];\r\n ans[1] += r[1];\r\n }\r\n }\r\n return ans;\r\n }\r\n\r\n int ans = 0;\r\n for (int i = 0; i < N; i++) {\r\n if (truth[i] < 0) {\r\n auto r = dfs(i, 0, -1);\r\n if (r[0] < 0) {\r\n ans = -1;\r\n break;\r\n } else {\r\n ans += max(r[0], r[1] - r[0]);\r\n }\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nenum int INF = 1<<30;\r\n"}], "src_uid": "a18692e5fe2f98717608449b1d9b77f7"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. scan!int){\n int n = scan!int;\n if(n == 1) \"-1\".writeln;\n else{\n if(n % 9 == 1){\n foreach(i; 0 .. n - 2) \"5\".write;\n \"99\".writeln;\n }\n else{\n foreach(i; 0 .. n - 1) \"5\".write;\n \"9\".writeln;\n }\n }\n }\n}\n\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n if (N == 1) {\n writeln(-1);\n } else {\n write(8);\n foreach (i; 1 .. N) {\n write(9);\n }\n writeln();\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\treadf !(\" %s\") (n);\n\t\twriteln (n == 1 ? \"-1\" : \"2\" ~ \"3\".cycle.take (n - 1).text);\n\t}\n}\n"}], "negative_code": [], "src_uid": "43996d7e052aa628a46d03086f9c5436"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n dchar[][] arr;\n foreach (_; 0 .. n) { arr ~= readln.chomp.to!(dchar[]); }\n \n auto badCount = ((dchar[][] arr) => arr.count!(r => r.canFind('B')).to!int);\n int allBad = badCount(arr) + badCount(arr.dup.transposed.map!array.array);\n \n debug { arr.each!writeln; }\n \n debug { allBad.writeln; }\n \n auto firstR = new int[] (n), firstC = new int[] (n);\n auto lastR = new int[] (n), lastC = new int[] (n);\n firstR[] = -1, lastR[] = -1, firstC[] = -1, lastC[] = -1;\n \n foreach (i; 0 .. n) {\n foreach (j; 0 .. n) {\n if (arr[i][j] == 'B') { \n if (firstR[i] == -1) { firstR[i] = j; }\n if (firstC[j] == -1) { firstC[j] = i; }\n \n lastR[i] = j;\n lastC[j] = i;\n }\n }\n }\n \n debug { writeln(firstR, ' ', lastR); writeln(firstC, ' ', lastC); }\n \n auto rows = new int[][] (n+1, n+1);\n auto cols = new int[][] (n+1, n+1);\n \n foreach (i; 0 .. n) {\n if (firstR[i] != -1 && firstR[i] + k - 1 >= lastR[i]) {\n foreach (j; max(i - k + 1, 0) .. min(i + 1, n - k + 1)) {\n rows[j][max(lastR[i] - k + 1, 0)] += 1;\n rows[j][firstR[i] + 1] -= 1;\n }\n }\n if (firstC[i] != -1 && firstC[i] + k - 1 >= lastC[i]) {\n foreach (j; max(i - k + 1, 0) .. min(i + 1, n - k + 1)) {\n cols[j][max(lastC[i] - k + 1, 0)] += 1;\n cols[j][firstC[i] + 1] -= 1;\n }\n }\n }\n \n foreach (i; 0 .. n) {\n foreach (j; 1 .. n) {\n rows[i][j] += rows[i][j-1];\n cols[i][j] += cols[i][j-1];\n }\n }\n \n debug { rows.each!writeln; writeln; cols.each!writeln; }\n \n int mx = 0;\n foreach (i; 0 .. n) {\n foreach (j; 0 .. n) {\n mx = max(mx, rows[i][j] + cols[j][i]);\n }\n }\n \n auto ans = n+n - allBad + mx;\n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\tint k = read.to!int;\n\tlog(\"n:\", n, \"k:\", k);\n\t\n\tint z; // already done\n\t\n\tbool[][] af = new bool[][](n, n);\n\tforeach(i; 0 .. n){\n\t\tchar[] l = readln.chomp.to!(char[]);\n\t\tforeach(j; 0 .. n){\n\t\t\taf[i][j] = (l[j] == 'B');\n\t\t}\n\t}\n\tlog(\"af:\", af.fz);\n\t\n\tbool[][] uf = new bool[][](n, n);\n\tforeach(i; 0 .. n){\n\t\tforeach(j; 0 .. n){\n\t\t\tuf[i][j] = 1;\n\t\t\tif(af[i][j]) break;\n\t\t}\n\t\tbool f;\n\t\tforeach_reverse(j; 0 .. n){\n\t\t\tif(j - k + 1 >= 0) if(f) uf[i][j - k + 1] = 0;\n\t\t\tif(af[i][j]) f = 1;\n\t\t}\n\t\tif(!f){\n\t\t\tforeach(j; 0 .. n) uf[i][j] = 0;\n\t\t\tz += 1;\n\t\t}\n\t}\n\tlog(\"uf:\", uf.fz);\n\t\n\tbool[][] vf = new bool[][](n, n);\n\tforeach(j; 0 .. n){\n\t\tforeach(i; 0 .. n){\n\t\t\tvf[i][j] = 1;\n\t\t\tif(af[i][j]) break;\n\t\t}\n\t\tbool f;\n\t\tforeach_reverse(i; 0 .. n){\n\t\t\tif(i - k + 1 >= 0) if(f) vf[i - k + 1][j] = 0;\n\t\t\tif(af[i][j]) f = 1;\n\t\t}\n\t\tif(!f){\n\t\t\tforeach(i; 0 .. n) vf[i][j] = 0;\n\t\t\tz += 1;\n\t\t}\n\t}\n\tlog(\"vf:\", vf.fz);\n\t\n\tint[][] pf = new int[][](n, n);\n\tforeach(i; 0 .. n){\n\t\tint sum = 0;\n\t\tforeach(j; 0 .. n){\n\t\t\tsum += (vf[i][j]? 1: 0);\n\t\t\tpf[i][j] = sum;\n\t\t}\n\t}\n\tlog(\"pf:\", pf.fz);\n\t\n\tint[][] qf = new int[][](n, n);\n\tforeach(j; 0 .. n){\n\t\tint sum = 0;\n\t\tforeach(i; 0 .. n){\n\t\t\tsum += (uf[i][j]? 1: 0);\n\t\t\tqf[i][j] = sum;\n\t\t}\n\t}\n\tlog(\"qf:\", qf.fz);\n\t\n\tint[][] anf = new int[][](n, n);\n\tforeach(i; 0 .. n) foreach(j; 0 .. n){\n\t\tif(i + k - 1 >= n || j + k - 1 >= n) continue;\n\t\tanf[i][j] = pf[i][j + k - 1] + qf[i + k - 1][j];\n\t\tif(j > 0) anf[i][j] -= pf[i][j - 1];\n\t\tif(i > 0) anf[i][j] -= qf[i - 1][j];\n\t}\n\tlog(\"anf:\", anf.fz);\n\t\n\tint an = 0;\n\tforeach(i; 0 .. n) foreach(j; 0 .. n){\n\t\tan = max(an, anf[i][j]);\n\t}\n\t\n\t(an + z).writeln;\n}\n\nstring fz(bool[][] bf){\n\tstring[] res;\n\tforeach(bs; bf) res ~= bs.map!(x => (x? '#': '_')).array;\n\treturn \"\\n\" ~ res.join(\"\\n\");\n}\nstring fz(int[][] nf){\n\tstring[] res;\n\tforeach(ns; nf) res ~= ns.map!(to!string).array.join(\" \");\n\treturn \"\\n\" ~ res.join(\"\\n\");\n}\n"}], "negative_code": [], "src_uid": "97e149fe5933bf1c9dbe8d958c1b2e05"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto M = scan!int;\r\n auto G = scan!string(N);\r\n\r\n int mx = 100, my = 100;\r\n foreach(y; 0..N) foreach(x; 0..M) {\r\n if (G[y][x] == 'R') {\r\n mx = min(mx, x);\r\n my = min(my, y);\r\n }\r\n }\r\n\r\n bool ans;\r\n foreach(y; 0..N) foreach(x; 0..M) {\r\n if (G[y][x] == 'R' && x <= mx && y <= my) {\r\n ans = true;\r\n break;\r\n }\r\n }\r\n return ans ? \"YES\" : \"NO\";\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int NA = -1;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint rows, cols;\r\n\t\treadf !(\" %s %s\") (rows, cols);\r\n\t\treadln;\r\n\t\tstring [] board;\r\n\t\tforeach (row; 0..rows)\r\n\t\t{\r\n\t\t\tboard ~= readln.strip;\r\n\t\t}\r\n\t\tint lo = NA;\r\n\t\tbool ok = true;\r\n\t\tforeach (row; 0..rows)\r\n\t\t{\r\n\t\t\tauto cur = board[row].countUntil ('R');\r\n\t\t\tif (cur >= 0)\r\n\t\t\t{\r\n\t\t\t\tif (lo == NA)\r\n\t\t\t\t{\r\n\t\t\t\t\tlo = cur;\r\n\t\t\t\t}\r\n\t\t\t\telse if (lo > cur)\r\n\t\t\t\t{\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "96b6a96ded46bddb78b118d6d3a9d049"} {"source_code": "import std.stdio;\nimport std.string : split, strip;\nimport std.algorithm : count, map;\nimport std.conv : to;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n\n auto a = readln.strip.split.map!(to!int);\n auto even = a.count!\"(a & 1) == 0\";\n auto odd = n - even;\n\n if ((odd > 0 && even > 0) || (odd & 1) == 1) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint n=0;\n\t\treadf(\" %d\", &n);\n\t\tint sum=0;\n\t\tint count=0;\n\t\tfor (int j=0; j<n; j++)\n\t\t{\n\t\t\tint a=0;\n\t\t\treadf(\" %d\", &a);\n\t\t\tsum=sum+a;\n\t\t\tif (a%2==0)\n\t\t\t{\n\t\t\t\tcount=count+1;\n\t\t\t}\n\t\t}\n\t\tif (count==n)\n\t\t{\n\t\t\twriteln(\"NO\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (count==0 && n%2==0)\n\t\t\t{\n\t\t\t\twriteln(\"NO\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twriteln(\"YES\");\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tlong cnt;\n\t\tforeach (e; a)\n\t\t{\n\t\t\tif (e % 2 == 1)\n\t\t\t\t++cnt;\n\t\t}\n\t\tif (cnt == 0) continue;\n\t\tif (cnt % 2 == 0 && cnt == n) continue;\n\t\tans[ti] = true;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"Yes\" : \"No\");\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.algorithm.mutation;\nimport std.container.array;\n\nstring[] tokens;\n\nstring readToken()\n{\n while (tokens.empty)\n {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nbool solve()\n{\n int n = readInt;\n auto cnt = [0, 0];\n for (int i = 0; i < n; ++i)\n cnt[readInt % 2] = 1;\n if (cnt[1])\n {\n if (cnt[0])\n {\n return true;\n }\n return n % 2 == 1;\n }\n else\n {\n return false;\n }\n}\n\nvoid main()\n{\n int T = readInt;\n while (T--)\n {\n writeln(solve ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nvoid main()\n{\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto a = new int[n.ind];\n read(a);\n auto pa = a.map!(ai => ai % 2);\n auto c0 = pa.canFind(0);\n auto c1 = pa.canFind(1);\n if (c0 && c1)\n {\n writeln(\"YES\");\n }\n else if (c0)\n {\n writeln(\"NO\");\n }\n else\n {\n writeln(pa.sum % 2 == 1? \"YES\" : \"NO\");\n }\n }\n}\n"}], "negative_code": [], "src_uid": "2e8f7f611ba8d417fb7d12fda22c908b"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\treadln;\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto t = readln.strip.map !(q{a - '0'}).array;\r\n\t\t\tforeach (j; 0..n)\r\n\t\t\t{\r\n\t\t\t\ts[(i + n - j) % n] += t[j];\r\n\t\t\t}\r\n\t\t}\r\n\t\tauto total = s.sum;\r\n\t\tauto res = s.map !(c => total - c + n - c).minElement;\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n readln;\r\n int N = read!int;\r\n auto F = iota(N).map!(_ => readln.chomp).array;\r\n int no = 0;\r\n for (int y = 0; y < N; y++) {\r\n for (int x = 0; x < N; x++) {\r\n no += (F[y][x] == '1');\r\n }\r\n }\r\n int ans = N*N;\r\n for (int y = 0; y < N; y++) {\r\n int dno = 0;\r\n for (int k = 0; k < N; k++) {\r\n int i = (y + k) % N, j = k;\r\n dno += (F[i][j] == '1');\r\n }\r\n ans = min(ans, no - dno + N - dno);\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [], "src_uid": "d174982b64cc9e8d8a0f4b8646f1157c"} {"source_code": "/+ dub.sdl:\n name \"D\"\n dependency \"dcomp\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n\nimport std.typecons;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n int n, m;\n long[] c;\n sc.read(n, m, c);\n alias E = Tuple!(int, \"to\", int, \"id\");\n E[][] g = new E[][](n);\n foreach (i; 0..m) {\n int a, b;\n sc.read(a, b); a--; b--;\n g[a] ~= E(b, i);\n g[b] ~= E(a, i);\n }\n long[] res = new long[m];\n int[] dps = new int[n];\n int[] par = new int[n];\n int[] pid = new int[n]; pid[0] = -1;\n bool[] vis = new bool[n];\n\n int eid = -1, edown = -1, eup = -1, edps = -1;\n long dfs(int p, int b, int ndp = 0) {\n dps[p] = ndp;\n par[p] = b;\n vis[p] = true;\n long sm = c[p];\n foreach (e; g[p]) {\n int d = e.to;\n if (d == b) continue;\n if (!vis[d]) {\n pid[d] = e.id;\n long u = dfs(d, p, ndp+1);\n res[e.id] = u;\n sm -= u;\n continue;\n }\n if (dps[p] < dps[d]) continue;\n // back edge\n if ((dps[p] - dps[d]) % 2) continue;\n // odd cycle\n eid = e.id;\n edown = p; eup = d; edps = dps[p];\n }\n return sm;\n }\n\n long u = dfs(0, -1);\n if (edps % 2) u *= -1;\n if (u) {\n if (eid == -1) {\n writeln(\"NO\");\n return 0;\n }\n u /= 2;\n res[eid] += u; u *= -1;\n int s = edown;\n while (s != eup) {\n res[pid[s]] += u; u *= -1;\n s = par[s];\n }\n u *= 2;\n while (s) {\n res[pid[s]] += u; u *= -1;\n s = par[s];\n }\n }\n\n writeln(\"YES\"); \n writeln(res.map!(to!string).join(\"\\n\"));\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/stackpayload.d */\n// module dcomp.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */\n \n// module dcomp.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n// import dcomp.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dcomp and include dcomp's source code.\ndcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)\ndcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)\n*/\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nint N, M;\nlong[] C;\nint[] A, B;\n\nint[][] G;\nint[] par, pari;\nint[] dep;\nlong[] ans;\nint odI, odU, odV;\n\nlong dfs(int u, int p, int pi) {\n par[u] = p;\n pari[u] = pi;\n dep[u] = (p == -1) ? 0 : (dep[p] + 1);\n long ret = C[u];\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n if (dep[v] == -1) {\n ans[i] = dfs(v, u, i);\n ret -= ans[i];\n } else if (dep[u] > dep[v]) {\n if ((dep[u] - dep[v]) % 2 == 0) {\n odI = i;\n odU = u;\n odV = v;\n }\n }\n }\n }\n return ret;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n M = readInt();\n C = new long[N];\n foreach (u; 0 .. N) {\n C[u] = readLong();\n }\n A = new int[M];\n B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n }\n \n G = new int[][N];\n foreach (i; 0 .. M) {\n G[A[i]] ~= i;\n G[B[i]] ~= i;\n }\n par = new int[N];\n pari = new int[N];\n dep = new int[N];\n dep[] = -1;\n ans = new long[M];\n odI = odU = odV = -1;\n const rt = 0;\n const res = dfs(rt, -1, -1);\n debug {\n writeln(\"ans = \", ans);\n writefln(\"od = %s: %s %s\", odI, odU, odV);\n writeln(\"res = \", res);\n }\n if (res != 0) {\n if (odI != -1 && res % 2 == 0) {\n long d = (-1)^^(dep[odV] % 2) * (res / 2);\n ans[odI] += d;\n for (int w = odU; w != odV; w = par[w]) {\n d *= -1;\n ans[pari[w]] += d;\n }\n d *= 2;\n for (int w = odV; w != rt; w = par[w]) {\n d *= -1;\n ans[pari[w]] += d;\n }\n } else {\n ans = null;\n }\n }\n \n if (!ans.empty) {\n auto cs = new long[N];\n foreach (i; 0 .. M) {\n cs[A[i]] += ans[i];\n cs[B[i]] += ans[i];\n }\n if (C != cs) {\n ans = null;\n }\n }\n \n if (!ans.empty) {\n writeln(\"YES\");\n foreach (i; 0 .. M) {\n writeln(ans[i]);\n }\n } else {\n writeln(\"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "/+ dub.sdl:\n name \"C\"\n dependency \"dcomp\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n\nimport std.typecons;\n\n// import dcomp.segtree.lazyseg;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n\n int n, m;\n sc.read(n, m);\n int[][] g = new int[][n];\n foreach (i; 0..m) {\n int a, b;\n sc.read(a, b); a--; b--;\n g[a] ~= b; g[b] ~= a;\n }\n \n int[] par = new int[n];\n int[] dps = new int[n];\n bool[] vis = new bool[n];\n\n int[] ri = new int[n+1]; ri[] = n;\n\n void add(int s, int t) {\n int mi = t, ma = t;\n while (s != t) {\n mi = min(mi, s);\n ma = max(ma, s);\n s = par[s];\n }\n ri[mi] = min(ri[mi], ma);\n }\n\n void dfs(int p, int b = -1, int ndp = 0) {\n par[p] = b;\n dps[p] = ndp;\n vis[p] = true;\n foreach (d; g[p]) {\n if (d == b) continue;\n if (!vis[d]) {\n dfs(d, p, ndp+1);\n continue;\n }\n if (dps[p] < dps[d]) continue;\n add(p, d);\n }\n }\n foreach (i; 0..n) {\n if (vis[i]) continue;\n dfs(i);\n }\n foreach_reverse (i; 0..n-1) {\n ri[i] = min(ri[i], ri[i+1]);\n }\n// writeln(ri);\n\n int q;\n sc.read(q);\n long[] res = new long[q];\n\n alias E = Tuple!(int, \"left\", int, \"id\", bool, \"pos\");\n E[][] ev = new E[][](n+1);\n\n foreach (i; 0..q) {\n int a, b;\n sc.read(a, b); a--;\n res[i] = long(b-a) * long(b-a + 1) / 2;\n ev[b] ~= E(a, i, false);\n ev[b] ~= E(b, i, true);\n ev[a] ~= E(a, i, true);\n ev[a] ~= E(b, i, false);\n }\n\n alias N = Tuple!(long, int);\n auto seg = LazySeg!(N, long,\n (a, b) => N(a[0]+b[0], a[1]+b[1]),\n (a, b) => N(a[0]+a[1]*b, a[1]),\n \"a+b\",\n N(0, 0), 0)(N(0, 1).repeat.take(n).array);\n foreach (r; 0..n+1) {\n foreach (e; ev[r]) {\n long u = seg[e.left..$].sum[0];\n if (e.pos) {\n res[e.id] += u;\n } else {\n res[e.id] -= u;\n }\n }\n seg[ri[r]..$] += 1;\n }\n writeln(res.map!(to!string).join(\"\\n\"));\n\n\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */\n \n// module dcomp.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/segtree/lazyseg.d */\n// module dcomp.segtree.lazyseg;\n\n// import dcomp.segtree.primitive;\n\nimport std.functional : binaryFun;\n\n \nalias LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL, alias Engine = LazySegEngine) =\n SegTree!(Engine, T, L , binaryFun!opTT, binaryFun!opTL, binaryFun!opLL, eT, eL);\n\n \n \n\n\nstruct LazySegEngine(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {\n import std.typecons : Tuple;\n alias DataType = T;\n alias LazyType = L;\n alias BinSearch = binSearchLazy;\n alias S = Tuple!(T, \"d\", L, \"lz\");\n uint n, sz, lg;\n S[] s;\n this(uint n) {\n import std.conv : to;\n import std.algorithm : each;\n this.n = n;\n uint lg = 0;\n while ((2^^lg) < n) lg++;\n this.lg = lg;\n sz = 2^^lg;\n s = new S[](2*sz);\n s.each!((ref x) => x = S(eT, eL));\n }\n this(T[] first) {\n import std.conv : to;\n import std.algorithm : each;\n n = first.length.to!uint;\n uint lg = 0;\n while ((2^^lg) < n) lg++;\n this.lg = lg;\n sz = 2^^lg;\n\n s = new S[](2*sz);\n s.each!((ref x) => x = S(eT, eL));\n foreach (i; 0..n) {\n s[sz+i].d = first[i];\n }\n foreach_reverse (i; 1..sz) {\n update(i);\n }\n }\n @property uint length() const { return n; }\n pragma(inline):\n private void lzAdd(uint k, in L x) {\n s[k].lz = opLL(s[k].lz, x);\n s[k].d = opTL(s[k].d, x);\n }\n public void push(uint k) {\n if (s[k].lz == eL) return;\n lzAdd(2*k, s[k].lz);\n lzAdd(2*k+1, s[k].lz);\n s[k].lz = eL;\n }\n private void update(uint k) {\n s[k].d = opTT(s[2*k].d, s[2*k+1].d);\n }\n T single(uint k) {\n k += sz;\n foreach_reverse (uint i; 1..lg+1) {\n push(k>>i);\n }\n return s[k].d;\n }\n void singleSet(uint k, T x) {\n k += sz;\n foreach_reverse (uint i; 1..lg+1) {\n push(k>>i);\n }\n s[k].d = x;\n foreach (uint i; 1..lg+1) {\n update(k>>i);\n }\n }\n T sum(uint a, uint b) {\n assert(0 <= a && a <= b && b <= n);\n if (a == b) return eT;\n a += sz; b--; b += sz;\n uint tlg = lg;\n while (true) {\n uint k = a >> tlg;\n if (a >> tlg != b >> tlg) {\n tlg++;\n break;\n }\n if (((a-1) >> tlg) + 2 == (b+1) >> tlg) return s[k].d;\n push(k);\n tlg--;\n }\n T sm = eT;\n foreach_reverse (l; 0..tlg) {\n uint k = a >> l;\n if ((a-1)>>l != a>>l) {\n sm = opTT(s[k].d, sm);\n break;\n }\n push(k);\n if (!((a >> (l-1)) & 1)) sm = opTT(s[2*k+1].d, sm);\n }\n foreach_reverse (l; 0..tlg) {\n uint k = b >> l;\n if (b>>l != (b+1)>>l) {\n sm = opTT(sm, s[k].d);\n break;\n }\n push(k);\n if ((b >> (l-1)) & 1) sm = opTT(sm, s[2*k].d);\n }\n return sm;\n }\n void add(uint a, uint b, L x) {\n assert(0 <= a && a <= b && b <= n);\n if (a == b) return;\n a += sz; b--; b += sz;\n uint tlg = lg;\n while (true) {\n uint k = a >> tlg;\n if (a >> tlg != b >> tlg) {\n tlg++;\n break;\n }\n if (((a-1) >> tlg) + 2 == (b+1) >> tlg) {\n lzAdd(k, x);\n foreach (l; tlg+1..lg+1) {\n update(a >> l);\n }\n return;\n }\n push(k);\n tlg--;\n }\n foreach_reverse (l; 0..tlg) {\n uint k = a >> l;\n if ((a-1)>>l != a>>l) {\n lzAdd(k, x);\n foreach (h; l+1..tlg) {\n update(a >> h);\n }\n break;\n }\n push(k);\n if (!((a >> (l-1)) & 1)) lzAdd(2*k+1, x);\n }\n foreach_reverse (l; 0..tlg) {\n uint k = b >> l;\n if (b>>l != (b+1)>>l) {\n lzAdd(k, x);\n foreach (h; l+1..tlg) {\n update(b >> h);\n }\n break;\n }\n push(k);\n if ((b >> (l-1)) & 1) lzAdd(2*k, x);\n }\n foreach (l; tlg..lg+1) {\n update(a >> l);\n }\n }\n}\n\n\n\n \n\n\nint binSearchLazy(bool rev, alias pred, TR)(TR t, int a, int b) {\n import std.traits : TemplateArgsOf;\n alias args = TemplateArgsOf!TR;\n alias opTT = args[2];\n auto x = args[5];\n with (t) {\n static if (!rev) {\n \n if (pred(x)) return a-1;\n int pos = a;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {\n x = opTT(x, s[k].d);\n pos = r;\n return;\n }\n if (l+1 == r) return;\n push(k);\n int md = (l+r)/2;\n f(a, b, l, md, 2*k);\n if (pos >= md) f(a, b, md, r, 2*k+1);\n }\n f(a, b, 0, sz, 1);\n return pos;\n } else {\n \n if (pred(x)) return b;\n int pos = b-1;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {\n x = opTT(s[k].d, x);\n pos = l-1;\n return;\n }\n if (l+1 == r) return;\n push(k);\n int md = (l+r)/2;\n f(a, b, md, r, 2*k+1);\n if (pos < md) f(a, b, l, md, 2*k);\n }\n f(a, b, 0, sz, 1);\n return pos; \n }\n }\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n// import dcomp.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/segtree/primitive.d */\n// module dcomp.segtree.primitive;\n\nimport std.conv : to;\n\nstruct SegTree(alias E, Args...) {\n import std.traits : ReturnType;\n alias Engine = E!Args;\n alias T = Engine.DataType;\n alias L = Engine.LazyType;\n\n Engine eng;\n\n this(size_t n) { eng = Engine(n.to!uint); }\n this(T[] first) { eng = Engine(first); }\n\n @property size_t length() const { return eng.length(); }\n @property size_t opDollar() const { return eng.length(); }\n \n struct Range {\n Engine* eng;\n size_t start, end;\n @property const(T) sum() {\n return eng.sum(start.to!uint, end.to!uint);\n }\n }\n const(T) opIndex(size_t k) {\n assert(0 <= k && k < eng.length());\n return eng.single(k.to!uint);\n }\n void opIndexAssign(T x, size_t k) {\n assert(0 <= k && k < eng.length());\n eng.singleSet(k.to!uint, x);\n }\n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) {\n assert(0 <= start && start <= end && end <= eng.length());\n return [start, end];\n }\n Range opIndex(size_t[2] rng) {\n return Range(&eng, rng[0].to!uint, rng[1].to!uint);\n }\n static if (!is(L == void)) {\n void opIndexOpAssign(string op : \"+\")(L x, size_t[2] rng) {\n eng.add(rng[0].to!uint, rng[1].to!uint, x);\n }\n }\n}\n\nimport std.traits : isInstanceOf;\n\nptrdiff_t binSearchLeft(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b) \nif (isInstanceOf!(SegTree, TR)) {\n return TR.Engine.BinSearch!(false, pred)(t.eng, a.to!int, b.to!int);\n}\n\nptrdiff_t binSearchRight(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b) \nif (isInstanceOf!(SegTree, TR)) {\n return TR.Engine.BinSearch!(true, pred)(t.eng, a.to!int, b.to!int);\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/stackpayload.d */\n// module dcomp.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n\n/*\nThis source code generated by dcomp and include dcomp's source code.\ndcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)\ndcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)\n*/"}], "src_uid": "7f39a705edda80797df767936dd1279f"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll l = scan;\n ll r = scan;\n if(l == r){\n writeln(0);\n return;\n }\n ll d = r/2 + 1;\n d = max(l, d);\n writeln(r % d);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.algorithm;\r\n\r\nlong maximalModulus(long left, long right) {\r\n if (right / 2 + 1 >= left) {\r\n return right % (right / 2 + 1);\r\n }\r\n else {\r\n long max = -1;\r\n long i = 1;\r\n long x = 1;\r\n while (x > max + 1) {\r\n x = ((right - 1) / i) + 1;\r\n debug{writeln(\"x=\", x, \"right&x=\", right%x, \"max=\", max);}\r\n if (right%x > max) {\r\n max = right%x;\r\n }\r\n if (x < left) {\r\n return right % left;\r\n }\r\n ++i;\r\n }\r\n return max;\r\n }\r\n}\r\n\r\n// void find_mod(long left, long right)\r\n// {\r\n// long max_current = 0;\r\n// long max_delimeter = 0;\r\n// for (long a = right; a >= left; a--)\r\n// {\r\n// for (long b = max(a - 1, a / 2 + 1); b >= left ; b--)\r\n// {\r\n// auto current = a % b;\r\n// max_current = max(max_current, current);\r\n// if (max_current == b - 1)\r\n// {\r\n// writeln(max_current);\r\n// debug{writeln(\"A\",a,\" B\",b);}\r\n// return;\r\n// }\r\n// }\r\n// }\r\n// writeln(max_current);\r\n// return;\r\n// }\r\n\r\nvoid main()\r\n{\r\n int n;\r\n long l, r;\r\n scanf(\"%d\", &n);\r\n getchar();\r\n\r\n for (int k = 0; k < n; k++){\r\n\t scanf(\"%ld %ld\", &l, &r);\r\n getchar();\r\n // find_mod(l, r);\r\n writeln(maximalModulus(l, r));\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long l, r;\n readln.formattedRead!\" %d %d \"(l, r);\n long max_b = max(l, (r + 1) / 2);\n long max_a = min(max_b * 2, r);\n long maxrem = 0;\n foreach (i ; -5L .. 5L) {\n foreach (j ; -5L .. 5L) {\n long a = max(min(max_a + i, r), l);\n long b = max(min(max_b + j, r), l);\n if (b > a)\n continue;\n maxrem = max(maxrem, a % b);\n }\n }\n writeln(maxrem);\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto l = RD;\r\n\t\tauto r = RD;\r\n\r\n\t\tans[ti] = r % max(r / 2 + 1, l);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "c34db7897f051b0de2f49f2696c6ee2f"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const A = readToken();\n const B = readToken();\n \n int[] ansA, ansB;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && A[i] == A[j]; ++j) {}\n if (!(j == N && A[N - 1] == '0')) {\n ansA ~= j;\n }\n }\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && B[i] == B[j]; ++j) {}\n if (!(j == N && B[N - 1] == '0')) {\n ansB ~= j;\n }\n }\n \n int[] ans;\n foreach (j; ansA) {\n ans ~= j;\n }\n foreach_reverse (j; ansB) {\n ans ~= j;\n }\n \n write(ans.length);\n foreach (j; ans) {\n write(\" \", j);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto s = readln.strip.map !(q{a == '1'}).array;\n\t\tauto t = readln.strip.map !(q{a == '1'}).array;\n\n\t\tint [] answer;\n\t\tint lo = 0;\n\t\tint hi = n - 1;\n\t\tint p = 0;\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tauto cur = (p ? !s[hi] : s[lo]);\n\t\t\tif (cur == t[i])\n\t\t\t{\n\t\t\t\tanswer ~= 1;\n\t\t\t}\n\t\t\tanswer ~= i + 1;\n\t\t\tif (p)\n\t\t\t{\n\t\t\t\thi -= 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo += 1;\n\t\t\t}\n\t\t\tp ^= 1;\n\t\t}\n\t\twritefln !(\"%s\\n%(%s %)\") (answer.length, answer);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RD!(char[]);\n\t\tauto b = RD!(char[]);\n\n\t\tint l, r = n-1;\n\t\tbool inv;\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tint ll = inv ? r : l;\n\t\t\tint rr = inv ? l : r;\n\t\t\tdebug writeln(\"ll:\", ll, \" rr:\", rr);\n\t\t\tif ((a[rr] == b[i]) != inv)\n\t\t\t{\n\t\t\t\tif (inv)\n\t\t\t\t\t++l;\n\t\t\t\telse\n\t\t\t\t\t--r;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ((a[ll] == b[i]) != inv)\n\t\t\t{\n\t\t\t\tans[ti] ~= 1;\n\t\t\t}\n\t\t\tans[ti] ~= i+1;\n\t\t\tif (inv)\n\t\t\t\t--r;\n\t\t\telse\n\t\t\t\t++l;\n\t\t\tinv = !inv;\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twrite(e.length);\n\t\tif (e.empty)\n\t\t{\n\t\t\twriteln;\n\t\t\tcontinue;\n\t\t}\n\t\twrite(\" \");\n\t\te.map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto a = readln.chomp;\n auto b = readln.chomp;\n \n int[] ans;\n int p = 0;\n foreach (op; 0 .. n) {\n int cur = (a[p] - '0') ^ (op & 1);\n \n debug { writeln(p, ' ', op, ' ', cur); }\n \n if (cur == (b[n - op - 1] - '0')) {\n ans ~= 1;\n }\n \n ans ~= n - op;\n p = n - p - 1 + (op & 1);\n }\n \n ans.length.write;\n write(\" \");\n ans.map!(to!string).join(\" \").writeln;\n }\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto a = readln.chomp;\n auto b = readln.chomp;\n \n int[] ans;\n int p = 0;\n foreach (op; 0 .. n) {\n int cur = (a[p] - '0') ^ op;\n if (cur == (b[n - op - 1] - '0')) {\n ans ~= 1;\n }\n \n ans ~= n - op;\n p = n - p - 1;\n }\n \n ans.length.write;\n write(\" \");\n ans.map!(to!string).join(\" \").writeln;\n }\n}"}], "src_uid": "46c5ebf1ddf5547352e84ba0171eacbc"} {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n readln;\n\n immutable str = readln.chomp;\n\n immutable cut = (){\n immutable start = str[0];\n foreach (ret; 1 .. str.length)\n if (str[ret] == start || str[ret] > str[ret - 1])\n return ret;\n return str.length;\n }();\n\n (\n str[0 .. cut]\n ~ str[0 .. cut]\n .byCodeUnit\n .retro\n .array\n ).writeln();\n }\n}\n// \"\"\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool lexsmaller2(int idx, string rs, int[] cache)\n{\n if (cache[idx] != -1)\n return cast(bool)cache[idx];\n if (idx + 2 >= rs.length)\n return true;\n assert(idx + 2 < rs.length);\n if (rs[idx] < rs[idx + 2])\n return cache[idx] = 1;\n if (rs[idx] > rs[idx + 2])\n return cache[idx] = 0;\n\n return (cache[idx] = lexsmaller2(idx + 1, rs, cache)) != 0;\n}\n\nbool lexsmaller(char newch, int idx, string rs, int[] cache)\n{\n if (newch < rs[idx])\n return true;\n if (newch > rs[idx])\n return false;\n\n if (idx + 1 >= rs.length)\n return false;\n\n if (newch < rs[idx + 1])\n return true;\n if (newch > rs[idx + 1])\n return false;\n return lexsmaller2(idx + 2, rs, cache);\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto s = readln.strip;\n auto rs = s.dup.reverse.idup;\n int ans = 0;\n int[] cache = new int[](n);\n cache[] = -1;\n foreach (k ; 1 .. n) {\n int idx = n - k;\n char newch = s[k];\n if (lexsmaller(newch, idx, rs, cache)) {\n ans = k;\n } else {\n break;\n }\n }\n writeln(s[0 .. ans + 1] ~ s[0 .. ans + 1].dup.reverse.idup);\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.utf;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = readln.strip;\r\n\r\n\t\talias mirror = len => s[0..len] ~ s[0..len].byChar.retro.array;\r\n\r\n\t\tint len = 1;\r\n\t\tbool first = true;\r\n\t\tint [] cand = [1, n];\r\n\t\tforeach (i; 0..n - 1)\r\n\t\t{\r\n\t\t\tif (s[i + 1] < s[i])\r\n\t\t\t{\r\n\t\t\t\tcand ~= i + 1;\r\n\t\t\t}\r\n\t\t\tif (s[i + 1] > s[i])\r\n\t\t\t{\r\n\t\t\t\tcand ~= i + 1;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tdebug {writeln (cand);}\r\n\t\tcand.map !(mirror).minElement.writeln;\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n const S = readToken;\n \n char[] ans;\n if (N >= 2 && S[0] == S[1]) {\n ans ~= S[0];\n ans ~= S[0];\n } else {\n char[] cs;\n foreach (i; 0 .. N) {\n if (i > 0 && S[i - 1] < S[i]) {\n break;\n }\n cs ~= S[i];\n }\n ans ~= cs;\n cs.reverse;\n ans ~= cs;\n }\n \n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto S = cast(char[])scan;\r\n \r\n int k = 1;\r\n char last2 = S[0];\r\n char last = S[0];\r\n int eql;\r\n foreach(int i; 1..N) {\r\n // deb([i, k], [[last], [last2], [S[i]]]);\r\n if (i == 1) {\r\n if (last <= S[i]) break;\r\n } else {\r\n if (last < S[i] || last2 < S[i]) break;\r\n }\r\n\r\n last2 = last;\r\n last = S[i];\r\n k++;\r\n }\r\n\r\n return (S[0..k] ~ S[0..k].dup.reverse).to!string;\r\n }\r\n\r\n foreach(_; 0..QN) subSolve().writeln;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}"}], "negative_code": [{"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n readln;\n\n immutable str = readln.chomp;\n\n immutable cut = (){\n foreach (ret; 1 .. str.length)\n if (str[ret] >= str[ret - 1])\n return ret;\n return str.length;\n }();\n\n (\n str[0 .. cut]\n ~ str[0 .. cut]\n .byCodeUnit\n .retro\n .array\n ).writeln();\n }\n}\n// \"\"\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto S = cast(char[])scan;\r\n \r\n int k = 1;\r\n foreach(int i; 1..N) {\r\n if (S[i] >= S[i - 1]) break;\r\n k++;\r\n }\r\n\r\n return (S[0..k] ~ S[0..k].dup.reverse).to!string;\r\n }\r\n\r\n foreach(_; 0..QN) subSolve().writeln;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.utf;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = readln.strip;\r\n\r\n\t\talias mirror = len => s[0..len] ~ s[0..len].byChar.retro.array;\r\n\r\n\t\tint len = 1;\r\n\t\tbool first = true;\r\n\t\tint [] cand = [1, n];\r\n\t\tforeach (i; 0..n - 2)\r\n\t\t{\r\n\t\t\tif (s[i + 1] < s[i])\r\n\t\t\t{\r\n\t\t\t\tcand ~= i + 2;\r\n\t\t\t}\r\n\t\t\tif (s[i + 1] > s[i])\r\n\t\t\t{\r\n\t\t\t\tcand ~= i + 1;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tdebug {writeln (cand);}\r\n\t\tcand.map !(mirror).minElement.writeln;\r\n\t}\r\n}\r\n"}], "src_uid": "dd7faacff9f57635f8e00c2f8f5a4650"} {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nconst int[] dx = [1, 0, -1, 0];\nconst int[] dy = [0, 1, 0, -1];\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n char[][] F = new char[][n];\n for (int i = 0; i < n; i++) F[i] = new char[n];\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n F[i][j] = '?';\n int c = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (F[i][j] == '?') {\n F[i][j] = 'C';\n c++;\n for (int k = 0; k < 4; k++) {\n if (0 <= i + dy[k] && i + dy[k] < n && 0 <= j + dx[k] && j + dx[k] < n)\n F[i + dy[k]][j + dx[k]] = '.';\n }\n }\n }\n }\n c.writeln;\n F.join(\"\\n\").writeln;\n}\n", "positive_code": [{"source_code": "/** CodeForces Problem 384.A (1)\n * ACM summer training contest (3)\n * Noein\n */\n\nimport std.stdio;\n\nT mut(T)(in T inval) {\n import std.traits;\n \n return cast(Unqual!T) inval;\n}\n\nT imut(T)(in T inval) {\n //import std.traits;\n \n return cast(immutable) inval;\n}\n\nvoid main() {\n int n;\n \n readf(\"%s\\n\", &n);\n \n const bool odd = cast(bool) (n % 2);\n \n auto r = odd? n+1 : n;\n \n const result = (r * r / 2) - ( (odd) ? n : 0 );\n \n auto bitf = odd.mut;\n \n auto repr_str = \"\";\n \n for( int y; y < n; ++ y ) {\n for( int x; x < n; ++x ) {\n repr_str ~= ( (bitf) ? \"C\" : \".\" );\n bitf ^= true;\n }\n repr_str ~= \"\\n\";\n if(!odd) bitf ^= true;\n }\n \n \n writeln(result, \"\\n\", repr_str);\n}"}], "negative_code": [{"source_code": "/** CodeForces Problem 384.A (1)\n * ACM summer training contest (3)\n * Noein\n */\n\nimport std.stdio;\n\n\nvoid main() {\n int n;\n \n readf(\"%s\\n\", &n);\n \n const bool odd = cast(bool) (n % 2);\n \n const result = (n * n / 2) - ( (odd) ? n : 0 );\n \n auto bitf = false;\n \n auto repr_str = \"\";\n \n for( int y; y < n; ++ y ) {\n for( int x; x < n; ++x ) {\n repr_str ~= ( (bitf) ? \"C\" : \".\" );\n bitf ^= true;\n }\n repr_str ~= \"\\n\";\n if(!odd) bitf ^= true;\n }\n \n \n writeln(repr_str);\n}"}, {"source_code": "/** CodeForces Problem 384.A (1)\n * ACM summer training contest (3)\n * Noein\n */\n\nimport std.stdio;\n\n\nvoid main() {\n int n;\n \n readf(\"%s\\n\", &n);\n \n const bool odd = cast(bool) (n % 2);\n \n const result = (n * n / 2) - ( (odd) ? n : 0 );\n \n auto bitf = false;\n \n auto repr_str = \"\";\n \n for( int y; y < n; ++ y ) {\n for( int x; x < n; ++x ) {\n repr_str ~= ( (bitf) ? \"C\" : \".\" );\n bitf ^= true;\n }\n repr_str ~= \"\\n\";\n if(!odd) bitf ^= true;\n }\n \n \n writeln(result, \"\\n\", repr_str);\n}"}], "src_uid": "1aede54b41d6fad3e74f24a6592198eb"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n\n auto b = readln.chomp.split.map!(to!int).array;\n \n auto rbt = make!(RedBlackTree!(int, \"a < b\", true))(b);\n \n debug { rbt.writeln; }\n \n int[] ans;\n foreach (e; a) {\n auto mn = (n - e - 1 + n) % n;\n auto upper = rbt.upperBound(mn);\n auto up = upper.empty() ? rbt.front : upper.front;\n debug { writeln(e, ' ', mn, ' ', upper, ' ', rbt.front, ' ', up); }\n \n ans ~= (e + up) % n;\n rbt.removeKey(up);\n }\n \n ans.map!(to!string).join(\" \").writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tauto t = redBlackTree !(q{a < b}, true) (b);\n\t\tdebug {writeln (t);}\n\n\t\tint [] c;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto f = t.upperBound ((n - a[i]) % n - 1);\n\t\t\tif (f.empty)\n\t\t\t{\n\t\t\t\tf = t.upperBound (0 - 1);\n\t\t\t}\n\t\t\tauto v = f.front;\n\t\t\tc ~= (a[i] + v) % n;\n\t\t\tt.removeKey (v);\n\t\t}\n\t\twritefln (\"%(%s %)\", c);\n\t}\n}\n"}], "negative_code": [], "src_uid": "905df05453a12008fc9247ff4d02e7f0"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main() {\n int a = 0, b = 0;\n int less = -2;\n foreach(i; iota(29,-1,-1)) {\n debug {writeln(i);}\n int query(int x, int y) {\n x <<= i; y <<= i;\n x ^= a; y ^= b;\n writefln!\"? %d %d\" (x,y);\n stdout.flush;\n return readln.strip.to!int;\n }\n void set(int x, int y) {\n x <<= i; y <<= i;\n a ^= x; b ^= y;\n }\n if(less == -2) less = query(0,0);\n int k = query(1,1);\n if(less != k) {\n set(less > 0, less < 0);\n less = -2;\n continue;\n }\n k = query(0,1);\n set(k > 0, k > 0);\n }\n writefln!\"! %d %d\" (a,b);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable int M = 30;\nlong x, y;\nint cnt = 0;\n\nint ask(long c, long d) {\n debug {\n cnt += 1;\n if ((x^c) > (y^d)) return 1;\n else if ((x^c) == (y^d)) return 0;\n else return -1;\n }\n\n writeln(\"? \", c, \" \", d);\n stdout.flush;\n return readln.chomp.to!int;\n}\n\nvoid answer(long a, long b) {\n writeln(\"! \", a, \" \", b);\n stdout.flush;\n}\n\nvoid main() {\n debug {\n auto s = readln.split.map!(to!long);\n x = s[0];\n y = s[1];\n }\n\n int f = ask(0, 0);\n int ff = f;\n\n if (f == 0) {\n long a = 0;\n foreach_reverse (i; 0..M) {\n long c = (1L << (i + 1)) - 1;\n long d = (1L << i) - 1;\n c += a;\n d += a;\n f = ask(c, d);\n if (f == -1) {\n a += 1L << i;\n }\n }\n answer(a, a);\n return;\n }\n\n bool a_large = f == 1;\n long a = 0;\n long b = 0;\n auto same = new bool[](M);\n\n foreach_reverse (i; 0..M) {\n long c = 1L << i;\n f = ask(a+c, b+c);\n if (a_large && f == -1) {\n a += c;\n f = ask(a, b);\n a_large = f == 1;\n } else if (!a_large && f == 1) {\n b += c;\n f = ask(a, b);\n a_large = f == 1;\n } else {\n same[i] = true;\n }\n }\n\n foreach (i; 0..M) {\n if (!same[i]) {\n continue;\n }\n long c = 1L << i;\n f = ask(a+c, b);\n if (f == -1) {\n a += c;\n b += c;\n }\n }\n\n answer(a, b);\n debug{cnt.writeln;}\n}\n"}], "negative_code": [], "src_uid": "7dc1137dd1f0c645cc7ec6dfdb92f5df"} {"source_code": "import std.stdio;\n\nvoid main() {\n uint t, x, y, n, b;\n\n scanf(\"%d\", &t);\n\n while(t--) {\n uint ans;\n scanf(\"%d %d %d\", &x, &y, &n);\n\n if(x > n) ans = 0;\n \n b = n % x;\n if(b == y)\n ans = n;\n else if(b > y)\n ans = n - (b -y);\n else \n ans = n - b - (x - y);\n\n printf(\"%d\\n\", ans); \n } \n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n long x, y, n;\n readf!\"%d %d %d\\n\"(x, y, n);\n\n auto r = n - n % x + y;\n if (r > n) {\n r -= x;\n }\n\n writeln(r);\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint x, y, n;\n\t\treadf !(\" %s %s %s\") (x, y, n);\n\t\tn -= y;\n\t\tn -= n % x;\n\t\tn += y;\n\t\twriteln (n);\n\t}\n}\n"}], "negative_code": [], "src_uid": "2589e832f22089fac9ccd3456c0abcec"} {"source_code": "// xxxxx\nimport std.random;\nimport std.stdio;\n\nvoid main ()\n{\n\trndGen.seed (unpredictableSeed);\n\twriteln (uniform (0, 2) ? \"Even\" : \"Odd\");\n}\n\n\t\t \t \t \n\t \t \t \t\t\n\t\t \t \n\t \t\t\t\t ", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\twriteln(\"Odd\"); \n\n\n\n}\n\n\n\t\t \t \t\n \t\t \t \n \t \t\t \t\n \t \t\t\t"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main ()\n{\n\twriteln (\"Even\");\n}\n\n \t\t \t \t \n\t\t\t\t \n\t\t \t\t\t \t\n\t \t \t \t "}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\twriteln (25);\n}\n\n\t\t\t \t \t\t\t\n \t\t \t \n \t\t\t\t \t \n \t \t \t "}, {"source_code": "// xxx\nimport std.random;\nimport std.stdio;\n\nvoid main ()\n{\n\trndGen.seed (unpredictableSeed);\n\twriteln (uniform (0, 2) ? \"Even\" : \"Odd\");\n}\n\n\t\t\t \t \t\t\t\n \t\t \t \t \t\n\t\t\t \t\t\t \n\t \t\t\t\t\t\t \t"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\twriteln (\"Odd\");\n}\n\n \t \t\t\t \t \n\t\t \t\t \t\t\n\t\t\t\t \t \t \t\n \t \t \t\t "}, {"source_code": "// xxxx\nimport std.random;\nimport std.stdio;\n\nvoid main ()\n{\n\trndGen.seed (unpredictableSeed);\n\twriteln (uniform (0, 2) ? \"Even\" : \"Odd\");\n}\n\n \t \t \t\n \t\t \t\n \t \t\t \t \n\t \t\t \t"}, {"source_code": "import std.random;\nimport std.stdio;\n\nvoid main ()\n{\n\trndGen.seed (unpredictableSeed);\n\twriteln (uniform (0, 2) ? \"Even\" : \"Odd\");\n}\n\n \t\t\t \t \n \t\t \t\t\t \n\t\t\t \t\t\t \t \n\t\t \t\t \t\t"}, {"source_code": "// x\nimport std.random;\nimport std.stdio;\n\nvoid main ()\n{\n\trndGen.seed (unpredictableSeed);\n\twriteln (uniform (0, 2) ? \"Even\" : \"Odd\");\n}\n\n \t\t\t \t \t \n \t\t\t\t \t\t\t \n \t \t\t\t\t\n\t\t \t\t \t \t "}, {"source_code": "// xx\nimport std.random;\nimport std.stdio;\n\nvoid main ()\n{\n\trndGen.seed (unpredictableSeed);\n\twriteln (uniform (0, 2) ? \"Even\" : \"Odd\");\n}\n\n\t\t \t\t\t \t\n\t \t \n \t \t \t\t \n\t\t\t \t \t "}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\treadln.strip.writeln;\n}\n\n \t\t \t \t\t\t \n \t\t \t \t\t\t\n\t \t \t \t \n \t\t\t\t\t \t \t"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\twriteln(\"Odd\");\n\n\n}\n\n\n \t \t \n \t \t \t\n\t\t \t \t \n \t\t \t \t \t "}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\twriteln(\"Odd\");\n\n\n}\n\n\n \t\t \t\t\t\t\n \t \t \t \n\t \t\t\t \t\t \n \t \t\t \t "}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\twriteln(\"Odd\");\n\n\n\n\n}\n\n\n\t\t \t \t\t\t \t\n\t \t \t\t \n \t \t \t \n\t\t \t \t \t \t"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\twriteln(\"Even\");\n\n}\n\n\n \t \t \t\t \n\t\t\t\t\t \n\t \t\t\t\t\n\t\t\t\t \t\t\t"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.math;\n\n\nvoid main(){\n\n\twriteln(\"Odd\");\n\n\n}\n\n\n \t \t\t\t \t \n \t\t \t\t\t\n \t\t\t\t\t \t \n\t \t "}], "src_uid": "f2a71cb9706b76317f2f442a9129055f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tdouble ans = 0.0;\n\tforeach (i; 0..n)\n\t{\n\t\tans += 1.0 / (n-i);\n\t}\n\n\twritefln(FMT_F, ans);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n double ans = 0;\n foreach (e; (n+1).iota.dropOne) {\n ans += 1.0 / e;\n }\n \n writefln(\"%.10f\", ans);\n}"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n writeln(iota(long(1), long(next!long + 1)).map!(k => real(1) / real(k)).sum);\n}\n"}], "negative_code": [], "src_uid": "260666df22ee510fcce3ebdfbb8b71a2"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD!string;\n\t\tauto b = RD!string;\n\t\tauto c = RD!string;\n\t\tbool ok = true;\n\t\tforeach (i; 0..a.length)\n\t\t{\n\t\t\tif (a[i] == c[i] || b[i] == c[i]) continue;\n\t\t\tok = false;\n\t\t\tbreak;\n\t\t}\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"YES\" : \"NO\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tA: foreach(_; 0 .. rint){\n\t\tstring a = readln.chomp, b = readln.chomp, c = readln.chomp;\n\t\tforeach(i; 0 .. a.length){\n\t\t\tif(a[i] == c[i] || b[i] == c[i]) continue;\n\t\t\t\"NO\".writeln;\n\t\t\tcontinue A;\n\t\t}\n\t\t\"YES\".writeln;\n\t}\n}"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n string a, b, c;\n\n void solve(long tc = -1)\n {\n auto n = a.length;\n if (iota(0, n).all!(i => c[i] == b[i] || c[i] == a[i]))\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n}\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W)\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, string))\n {\n static assert(isDynamicArray!(typeOfField)\n , \" A field with dimension initialization UDA must be a dynamic array.\");\n enum uda = getUDAs!(fieldSymbol, string)[0];\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});\n }\n else static if (isDynamicArray!typeOfField)\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [], "src_uid": "08679e44ee5d3c3287230befddf7eced"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n const n = r.next!int;\n const int a = r.next!uint;\n const int b = r.next!uint;\n const int c = r.next!uint;\n const int d = r.next!uint;\n const u1 = n * (a - b), v1 = n * (a + b);\n const u2 = c - d, v2 = c + d;\n const u = max (u1, u2), v = min (v1, v2);\n writeln ((u <= v) ? \"Yes\" : \"No\");\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto nn = readln.split.to!(int[]);\n auto N = nn[0];\n auto A = nn[1];\n auto B = nn[2];\n auto C = nn[3];\n auto D = nn[4];\n if ((A-B)*N > (C+D) || (A+B)*N < (C-D)) {\n writeln(\"No\");\n } else {\n writeln(\"Yes\");\n }\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tauto c = RD!int;\n\t\tauto d = RD!int;\n\n\t\tif ((a-b)*n > c+d) continue;\n\t\tif ((a+b)*n < c-d) continue;\n\t\tans[ti] = true;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Yes\" : \"No\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "30cfce44a7a0922929fbe54446986748"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.container;\n\nimmutable int inf = cast(int)1e9;\n\nint N;\nint[] A, d;\n\nvoid main() {\n\treadf(\"%d\", &N);\n\tA = new int[N + 1];\n\tforeach (i; 1..N + 1) readf(\" %d\", &A[i]);\n\td = new int[N + 1]; fill(d, cast(int)1e9);\n\td[1] = 0; auto q = DList!int(1);\n\twhile (!q.empty) {\n\t\tint v = q.front; q.removeFront();\n\t\tforeach (u; [v - 1, v + 1, A[v]]) {\n\t\t\tif (u < 1 || u > N) continue;\n\t\t\tif (d[u] > d[v] + 1) {\n\t\t\t\td[u] = d[v] + 1;\n\t\t\t\tq.insertBack(u);\n\t\t\t}\n\t\t}\n\t}\n\tforeach(i; 1..N + 1) writef(\"%d \", d[i]); writeln(\"\");\n}", "positive_code": [{"source_code": "import std.stdio, std.conv;\nimport std.algorithm, std.range, std.random;\nimport std.string, std.array, std.container, std.bigint;\nimport std.exception;\n\n\nint main() {\n int n = readln.strip.to!int;;\n int[] a = readln.split.map!(a => a.to!int - 1).array;\n struct Edge(C) {\n int to;\n C cost;\n }\n alias E = Edge!int;\n E[][] e = new E[][](n);\n foreach (i; 0..n) {\n if (i < n-1) {\n e[i] ~= E(i+1, 1);\n }\n if (0 < i) {\n e[i] ~= E(i-1, 1);\n }\n e[i] ~= E(a[i], 1);\n }\n writeln(dijkstra(e, 0).map!(to!string).join(\" \"));\n\treturn 0;\n}\n\n\nC[] dijkstra(E, C = typeof(E.cost))(in E[][] graph, int s) {\n import std.typecons : Tuple;\n import std.container : Array, BinaryHeap;\n alias Q = Tuple!(int, \"to\", C, \"cost\");\n\n size_t n = graph.length;\n C[] dist = new C[graph.length]; dist[] = E.cost.max;\n bool[] used = new bool[n];\n auto que = BinaryHeap!(Array!Q, \"a.cost > b.cost\")();\n dist[s] = 0;\n que.insert(Q(s, 0));\n while (!que.empty) {\n auto p = que.front.to; que.popFront;\n if (used[p]) continue;\n used[p] = true;\n foreach (E e; graph[p]) {\n if (dist[e.to] > dist[p] + e.cost) {\n dist[e.to] = dist[p] + e.cost;\n que.insert(Q(e.to, dist[e.to]));\n }\n }\n }\n return dist;\n}\n\n\nstring readToken() {\n import std.stdio : readln;\n import std.string : split;\n static size_t pos;\n static string[] tokens;\n while (!(pos < tokens.length)) {\n pos = 0;\n tokens = readln.split;\n }\n return tokens[pos++];\n}\nT read(T)() {\n import std.conv : to;\n return readToken.to!T;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv;\nimport std.algorithm, std.range, std.random;\nimport std.string, std.array, std.container, std.bigint;\nimport std.exception;\n\n\nint main() {\n int n = readln.strip.to!int;;\n int[] a = readln.split.map!(a => a.to!int - 1).array;\n int[] d = new int[n]; d[] = 10^^9;\n d[0] = 0;\n foreach (i; 0..n) {\n if (i) {\n d[i] = min(d[i], d[i-1]+1);\n }\n d[a[i]] = min(d[a[i]], d[i]+1);\n }\n foreach_reverse (i; 0..n-1) {\n d[i] = min(d[i], d[i+1]+1);\n }\n writeln(d.map!(to!string).join(\" \"));\n\treturn 0;\n}\n\n\n\nstring readToken() {\n import std.stdio : readln;\n import std.string : split;\n static size_t pos;\n static string[] tokens;\n while (!(pos < tokens.length)) {\n pos = 0;\n tokens = readln.split;\n }\n return tokens[pos++];\n}\nT read(T)() {\n import std.conv : to;\n return readToken.to!T;\n}"}], "src_uid": "d465aec304757dff34a770f7877dd940"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n int N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n N += 2;\n A = [0L] ~ A ~ [0L];\n auto b = new bool[][](N, N);\n foreach (i; 0 .. N) foreach (j; 0 .. N) {\n b[i][j] = (gcd(A[i], A[j]) != 1);\n }\n \n auto dpL = new bool[][](N, N);\n auto dpR = new bool[][](N, N);\n foreach (i; 0 .. N - 1) {\n dpL[i + 1][i] = true;\n dpR[i][i + 1] = true;\n }\n foreach (w; 2 .. N) {\n foreach (i; 0 .. N - w) {\n const j = i + w;\n foreach (k; i + 1 .. j) {\n if (dpR[i][k] && dpL[j][k]) {\n if (b[i][k]) dpL[j][i] = true;\n if (b[j][k]) dpR[i][j] = true;\n }\n }\n }\n }\n writeln(dpL[N - 1][0] ? \"Yes\" : \"No\");\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\n\t\tauto g = new bool [] [] (n, n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tg[i][j] = gcd (a[i], a[j]) > 1;\n\t\t\t}\n\t\t}\n\n\t\tauto f = new bool [2] [] [] (n + 1, n + 1);\n\t\tforeach (b; 0..2)\n\t\t{\n\t\t\tforeach (i; 0..n + 1)\n\t\t\t{\n\t\t\t\tf[i][i][b] = true;\n\t\t\t}\n\t\t}\n\n\t\tforeach (len; 1..n + 1)\n\t\t{\n\t\t\tforeach (i; 0..n + 1)\n\t\t\t{\n\t\t\t\tint j = i + len;\n\t\t\t\tif (j > n)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (j < n)\n\t\t\t\t{\n\t\t\t\t\tint v = j;\n\t\t\t\t\t// [i..k) *k* [k+1..j) *v*\n\t\t\t\t\tforeach (k; i..j)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (g[k][v] &&\n\t\t\t\t\t\t f[i][k][0] &&\n\t\t\t\t\t\t f[k + 1][j][1])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[i][j][0] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (0 <= i - 1)\n\t\t\t\t{\n\t\t\t\t\tint v = i - 1;\n\t\t\t\t\t// *v* [i..k) *k* [k+1..j)\n\t\t\t\t\tforeach (k; i..j)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (g[k][v] &&\n\t\t\t\t\t\t f[i][k][0] &&\n\t\t\t\t\t\t f[k + 1][j][1])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[i][j][1] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tbool res = false;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tres |= f[0][i][0] && f[i + 1][n][1];\n\t\t}\n\t\twriteln (res ? \"Yes\" : \"No\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n int N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n N += 2;\n A = [1L] ~ A ~ [1L];\n auto b = new bool[][](N, N);\n foreach (i; 0 .. N) foreach (j; 0 .. N) {\n b[i][j] = (gcd(A[i], A[j]) != 1);\n }\n \n auto dp = new bool[][](N, N);\n foreach (i; 0 .. N - 1) {\n dp[i][i + 1] = true;\n }\n foreach (w; 2 .. N) {\n foreach (i; 0 .. N - w) {\n const j = i + w;\n foreach (k; i + 1 .. j) {\n if (b[i][k] || b[j][k]) {\n if (dp[i][k] && dp[k][j]) {\n dp[i][j] = true;\n break;\n }\n }\n }\n }\n }\n debug {\n writeln(\"dp = \", dp);\n }\n bool ans;\n foreach (i; 1 .. N - 1) {\n if (dp[0][i] && dp[i][N - 1]) {\n ans = true;\n break;\n }\n }\n writeln(ans ? \"Yes\" : \"No\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "bedb98780a71d7027798d14aa5f1f100"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1395/problem/A\n// greedy\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\", &t);\n readln;\n\n while(t--) {\n long r, g, b, w;\n readf(\"%s %s %s %s\", &r, &g, &b, &w);\n readln;\n\n long x = r%2 + g%2 + b%2 + w%2;\n\n if(x <= 1) {\n \"Yes\".writeln;\n continue;\n }\n\n if(r > 0 && g > 0 && b > 0) {\n r -= 1;\n g -= 1;\n b -= 1;\n w += 1;\n }\n\n x = r%2 + g%2 + b%2 + w%2;\n\n if(x <= 1) {\n \"Yes\".writeln;\n continue;\n }\n\n \"No\".writeln;\n }\n}\n", "positive_code": [{"source_code": "import std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint r, g, b, w;\n\t\treadf !(\" %s %s %s %s\") (r, g, b, w);\n\t\tauto s = (r & 1) + (g & 1) + (b & 1) + (w & 1);\n\t\twriteln (s <= 1 || (r && g && b && s >= 3) ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long r, g, b, w;\n\n void solve(long tc = -1)\n {\n long p = (r % 2 == 0) + (g % 2 == 0) + (b % 2 == 0)\n + (w % 2 == 0);\n long i = 4 - p;\n long ops = min(r, g, b);\n if (p == 3 || p == 4)\n {\n writeln(\"Yes\");\n return;\n }\n if (ops > 0)\n {\n if (p == 1 || p == 0)\n {\n writeln(\"Yes\");\n return;\n }\n }\n writeln(\"No\");\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RDA;\n\t\t\n\t\tint cnt;\n\t\tforeach (e; a[0..3])\n\t\t{\n\t\t\tif (e % 2)\n\t\t\t\t++cnt;\n\t\t}\n\t\t\n\t\tint cnt2 = a[3] % 2;\n\t\tif (cnt+cnt2 <= 1)\n\t\t{\n\t\t\tans[ti] = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (a[0] == 0 || a[1] == 0 || a[2] == 0)\n\t\t\tcontinue;\n\n\t\tint cnt3 = cnt2 % 2 ? 0 : 1;\n\t\tif (3 - cnt + cnt3 <= 1)\n\t\t\tans[ti] = true;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Yes\" : \"No\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint r, g, b, w;\n\t\treadf !(\" %s %s %s %s\") (r, g, b, w);\n\t\twriteln ((r & 1) + (g & 1) + (b & 1) + (w & 1) == 2 ?\n\t\t \"NO\" : \"YES\");\n\t}\n}\n"}], "src_uid": "749a106d462555543c91753f00a5a479"} {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tif (n == 1)\n\t\t{\n\t\t\twriteln (1);\n\t\t}\n\t\telse if (n % 4 >= 2)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto p = new int [n];\n\t\t\tif (n & 1)\n\t\t\t{\n\t\t\t\tp[n >> 1] = n >> 1;\n\t\t\t}\n\t\t\tforeach (i; 0..(n >> 2))\n\t\t\t{\n\t\t\t\tint j = i << 1;\n\t\t\t\tint k = n - j - 1;\n\t\t\t\tp[j] = j + 1;\n\t\t\t\tp[j + 1] = k;\n\t\t\t\tp[k] = k - 1;\n\t\t\t\tp[k - 1] = j;\n\t\t\t}\n\t\t\tp[] += 1;\n\t\t\twritefln (\"%(%s %)\", p);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tif (n == 1)\n\t\t{\n\t\t\twriteln (1);\n\t\t}\n\t\telse if (n % 4 >= 2)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto p = new int [n];\n\t\t\tif (n & 1)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"%s\", n >> 1);}\n\t\t\t\tp[n >> 1] = n >> 1;\n\t\t\t}\n\t\t\tforeach (i; 0..(n >> 2))\n\t\t\t{\n\t\t\t\tint j = i << 1;\n\t\t\t\tint k = n - j - 1;\n\t\t\t\tdebug {writefln (\"%s %s\", j, k);}\n\t\t\t\tp[j] = j + 1;\n\t\t\t\tp[j + 1] = k;\n\t\t\t\tp[k] = k - 1;\n\t\t\t\tp[k - 1] = j;\n\t\t\t}\n\t\t\tp[] += 1;\n\t\t\twritefln (\"%(%s %)\", p);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tif (n % 4 >= 2)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto p = new int [n];\n\t\t\tp[n >> 1] = n >> 1;\n\t\t\tfor (int i = 0, j = n - 1; i < j; i += 2, j -= 2)\n\t\t\t{\n\t\t\t\tp[i] = i + 1;\n\t\t\t\tp[i + 1] = j;\n\t\t\t\tp[j] = j - 1;\n\t\t\t\tp[j - 1] = i;\n\t\t\t}\n\t\t\tp[] += 1;\n\t\t\twritefln (\"%(%s %)\", p);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "dfca19b36c1d682ee83224a317e495e9"} {"source_code": "\ufeffimport std.stdio;\n\nbyte idx;\nint ans, min;\n\nvoid minfoo(byte m) {\n\tbyte temp;\n\tforeach (i; 0 .. m) {\n\t\treadf(\" %s\", &temp);\n\t\tmin += temp * 5;\n\t}\n\n\tmin += m * 15;\n\n\tif (ans > min || idx == 0)\n\t\tans = min;\n\n\tmin = 0;\n}\n\nbyte[] a;\n\nvoid main() {\n\tbyte n, k;\n\n\treadf(\" %s\", &n);\n\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %s\", &k);\n\t\ta ~= k;\n\t}\n\n\n\tfor (idx = 0; idx < n; ++idx) {\n\t\tminfoo(a[idx]);\n\t}\n\n\twriteln(ans);\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.container;\n\nvoid main()\n{\n int n = readln.chomp.to!int;\n auto cash = readln.split.map!(to!int);\n auto time = new int[](n);\n foreach (i; 0..n) {\n auto inp = readln.split.map!(to!int);\n foreach (j; 0..cash[i]) {\n time[i] += inp[j] * 5;\n time[i] += 15;\n }\n }\n time.reduce!(min).writeln;\n \n}"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n int[] c = new int[n];\n int minTime = 99999999;\n for (int i = 0; i < n; i++) {\n c[i] = cin.readInt;\n }\n for (int i = 0; i < n; i++) {\n int time = 0;\n for (int j = 0; j < c[i]; j++) {\n time += cin.readInt * 5;\n }\n time += c[i] * 15;\n minTime = min(minTime, time);\n }\n writeln(minTime);\n } \n}"}, {"source_code": "\ufeffimport std.conv;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\n\nvoid main()\n{\n\tint n = readln.chomp.to!int;\n\tauto cash = readln.split.map!(to!int);\n\tauto time = new int[](n);\n\tforeach (i; 0..n) {\n\t\tauto inp = readln.split.map!(to!int);\n\t\tforeach (j; 0 .. cash[i]) {\n\t\t\ttime[i] += inp[j] * 5;\n\t\t\ttime[i] += 15;\n\t\t}\n\t}\n\ttime.reduce!(min).writeln;\n}"}], "negative_code": [], "src_uid": "0ea79b2a7ddf3d4da9c7a348e61933a7"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto S = scan.map!(c => c - 'a').array;\r\n\r\n auto acc = new long[][](S.length + 1, 26);\r\n foreach(li, c; S) {\r\n const int i = cast(int)li;\r\n\r\n foreach(d; 0..26) acc[i + 1][d] = acc[i][d];\r\n acc[i + 1][c]++;\r\n }\r\n\r\n int[26] pre;\r\n pre[] = 1;\r\n auto cs = 26.iota.filter!(c => acc[$ - 1][c] != 0).array;\r\n bool ans = true;\r\n\r\n // acc.each!deb;\r\n foreach(li, c; S) {\r\n const int i = cast(int)li + 1;\r\n // [i, c.to!int, acc[i][c]].deb;\r\n\r\n if (acc[i][c] > 1) {\r\n // i.deb;\r\n auto p = pre[c] - 1;\r\n auto ma = cs.map!(x => acc[i][x] - acc[p][x]).reduce!max;\r\n auto mi = cs.map!(x => acc[i][x] - acc[p][x]).reduce!min;\r\n // [ma, mi].deb;\r\n if (ma - mi > 1) {\r\n ans = false;\r\n break;\r\n }\r\n }\r\n\r\n pre[c] = i;\r\n }\r\n \r\n return YESNO[ans];\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n outer: foreach(_; 0..t)\r\n {\r\n string s = readln.strip;\r\n auto u = s.array.sort.uniq.array;\r\n int ul = cast(int) u.length;\r\n if (ul == 1)\r\n {\r\n writeln(\"yes\");\r\n continue outer;\r\n }\r\n int[] zeros = new int[ul];\r\n auto tmp = assocArray(zip(u, zeros));\r\n foreach(int ind, ch; s.array)\r\n {\r\n if (tmp[ch] == 0)\r\n {\r\n tmp[ch] = ind + 1;\r\n continue;\r\n }\r\n if ((ind + 1) - tmp[ch] < ul)\r\n {\r\n writeln(\"no\");\r\n continue outer;\r\n }\r\n tmp[ch] = ind + 1;\r\n }\r\n writeln(\"yes\");\r\n }\r\n}\r\n"}, {"source_code": "// cheese-cracker [2022-05-03]\n\nvoid solve(){\n auto word = scan!(dchar[]);\n auto seen = new int[](26);\n int uniqs = -1;\n int cntuniq = 0;\n seen[] = -1;\n for(int i = 0; i < word.length; ++i){\n int cval = (word[i] - 'a').to!int; \n if(seen[cval] != -1){\n if(uniqs != -1 && i - seen[cval] != uniqs){\n writeln(\"NO\");\n return;\n }else{\n uniqs = (i - seen[cval]);\n }\n }else{\n ++cntuniq;\n }\n seen[cval] = i;\n }\n /* show(cntuniq, uniqs); */\n if(cntuniq == uniqs || uniqs == -1){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}], "negative_code": [{"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n outer: foreach(_; 0..t)\r\n {\r\n string s = readln.strip;\r\n auto u = s.array.sort.uniq.array;\r\n int ul = cast(int) u.length;\r\n int[] zeros = new int[ul];\r\n auto tmp = assocArray(zip(u, zeros));\r\n foreach(ind, ch; s.array)\r\n {\r\n if (tmp[ch] == 0)\r\n {\r\n tmp[ch] = cast(int) ind;\r\n continue;\r\n }\r\n if (ul == 1)\r\n {\r\n writeln(\"yes\");\r\n continue outer;\r\n }\r\n if (tmp[ch] - cast(int) ind < ul)\r\n {\r\n writeln(\"no\");\r\n continue outer;\r\n }\r\n tmp[ch] = cast(int) ind;\r\n }\r\n writeln(\"yes\");\r\n }\r\n}\r\n"}], "src_uid": "dd098a17343a02fa5dc0d2d6cea853c7"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nvoid main() {\n int n;\n scan(n);\n\n int ans;\n int set = (1<<26) - 1;\n bool safe;\n\n foreach (i ; 0 .. n-1) {\n char e;\n string s;\n scan(e, s);\n\n if (safe && e != '.') {\n ans++;\n continue;\n }\n\n int t;\n\n if (e == '!') {\n foreach (ch ; s) {\n t |= (1<<(ch - 'a'));\n }\n }\n else if (e == '.') {\n t = (1<<26) - 1;\n foreach (ch ; s) {\n t &= ~(1<<(ch - 'a'));\n }\n }\n else {\n t = ~(1<<(s[0] - 'a'));\n }\n\n set &= t;\n\n debug {\n writefln(\"%b\",set);\n }\n\n if (set.popcnt == 1) {\n safe = 1;\n }\n }\n\n writeln(ans);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"A\"\n dependency \"dunkelheit\" version=\">=0.9.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nimport core.bitop;\n\nimmutable int B = 26;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n int n;\n sc.read(n);\n int f = (1<<B) - 1;\n int ans = 0;\n foreach (i; 0..n-1) { //ignore last query\n char ty; string s;\n sc.read(ty, s);\n\n bool uni = popcnt(f) == 1;\n\n if (ty == '!') {\n //shock\n if (uni) ans++;\n int nf = 0;\n foreach (c; s) {\n nf |= (1 << (c - 'a')); \n }\n f &= nf;\n } else if (ty == '.') {\n int nf = 0;\n foreach (c; s) {\n nf |= (1 << (c - 'a')); \n }\n f &= ~nf; \n } else if (ty == '?') {\n if (uni) ans++;\n\n int nf = 0;\n foreach (c; s) {\n nf |= (1 << (c - 'a')); \n }\n f &= ~nf; \n }\n }\n// writeln(f, \" \", popcnt(f));\n writeln(ans);\n return 0;\n}\n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n bool f = succW();\n assert(f);\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}], "negative_code": [], "src_uid": "3583a9762191ee8f8c3c2a287cb1ec1d"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, k;\n readf (\"%s %s\", &n, &k);\n readln;\n \n auto a = readln.split.map!(to!int).array;\n a.sort();\n \n if (k == 0) {\n writeln(a[0] > 1 ? 1 : -1);\n } else if (k == n) {\n writeln(a[n-1]);\n } else {\n writeln(k == n || a[k-1] != a[k] ? a[k-1] : -1);\n }\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int n, k;\n readf (\"%s %s\", &n, &k);\n readln;\n \n auto a = readln.split.map!(to!int).array;\n a.sort();\n \n if (k == 0) {\n writeln(a[0] > 1 ? 1 : -1);\n } else if (k == n) {\n writeln(a[n-1]);\n } else {\n writeln(a[k-1] != a[k] ? a[k-1] : -1);\n }\n}"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, k; readV(n, k);\n int[] a; readA(n, a);\n\n a.sort();\n\n if (k == 0) {\n if (a[0] == 1)\n writeln(-1);\n else\n writeln(a[0]-1);\n } else {\n if (a[k-1] == 0 || a[k-1] == a[k])\n writeln(-1);\n else\n writeln(a[k-1]);\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.string;\n\nvoid main()\n{\n int n, k;\n readf(\" %s %s\", n, k);\n\n auto a = new int[n];\n\n foreach (ref t; a) readf(\" %s\", t);\n\n sort(a);\n\n if (k == 0 && a[0] > 1)\n {\n writeln(1);\n }\n else if (k == n || k > 0 && a[k-1] != a[k])\n {\n writeln(a[k-1]);\n }\n else\n {\n writeln(-1);\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.string;\n\nvoid main()\n{\n int n, k;\n readf(\" %s %s\", n, k);\n\n auto a = new int[n];\n\n foreach (ref t; a) readf(\" %s\", t);\n\n sort(a);\n\n if (k == n || a[k-1] != a[k])\n {\n writeln(a[k-1]);\n }\n else\n {\n writeln(-1);\n }\n}"}, {"source_code": "import std.stdio, std.algorithm, std.string;\n\nvoid main()\n{\n int n, k;\n readf(\" %s %s\", n, k);\n\n auto a = new int[n];\n\n foreach (ref t; a) readf(\" %s\", t);\n\n auto sortedRange = sort(a);\n\n if (sortedRange.upperBound(a[k-1]).length == n-k)\n {\n writeln(a[k-1]);\n }\n else\n {\n writeln(-1);\n }\n}"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, k; readV(n, k);\n int[] a; readA(n, a);\n\n a.sort();\n if (a[k-1] == 0 || a[k-1] == a[k])\n writeln(-1);\n else\n writeln(a[k-1]);\n}\n"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n, k; readV(n, k);\n int[] a; readA(n, a);\n\n a.sort();\n if (a[k-1] == a[k])\n writeln(-1);\n else\n writeln(a[k-1]);\n}\n"}], "src_uid": "55297e2a65144323af4d6abd6a6ef050"} {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t\tscanf (\" %d\", &a[i]);\n\t\tint [] s;\n\t\tint res;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twhile (s.length && s[$ - 1] < a[i])\n\t\t\t{\n\t\t\t\tres = max (res, s[$ - 1] ^ a[i]);\n\t\t\t\ts.length--;\n\t\t\t}\n\t\t\tif (s.length)\n\t\t\t\tres = max (res, s[$ - 1] ^ a[i]);\n\t\t\ts ~= a[i];\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tscanf (\" %d\", &a[i]);\n\t\t}\n\t\tint [] s;\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twhile (s.length >= 1 && s[$ - 1] < a[i])\n\t\t\t{\n\t\t\t\tres = max (res, s[$ - 1] ^ a[i]);\n\t\t\t\ts.length--;\n\t\t\t}\n\t\t\ts ~= a[i];\n\t\t\tif (s.length >= 2)\n\t\t\t{\n\t\t\t\tres = max (res, s[$ - 1] ^ s[$ - 2]);\n\t\t\t}\n\t\t}\n\t\twritefln (\"%s\", res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "c9b9c56d50eaf605e7bc088385a42a1d"} {"source_code": "import\n\t\tstd.math,\n\t\tstd.conv,\n\t\tstd.file,\n\t\tstd.range,\n\t\tstd.array,\n\t\tstd.stdio,\n\t\tstd.string,\n\t\tstd.bitmanip,\n\t\tstd.typecons,\n\t\tstd.algorithm;\n\n\nauto read()\n{\n\treturn readln.strip.split;\n}\n\nauto readn()\n{\n\treturn read.map!(to!int).array;\n}\n\nvoid main()\n{\n\tauto ns = readn;\n\tauto words = read;\n\n\tint[string] weight;\n\n\tforeach(i, w; readn)\n\t{\n\t\tweight[words[i]] = w;\n\t}\n\n\tforeach(gw; ns[1].iota.map!(_ => readn))\n\t{\n\t\tauto ws = words.indexed(gw[1..$].map!(a => a - 1));\n\t\tauto m = ws.map!(a => weight[a]).reduce!min;\n\n\t\tws.each!(a => weight[a] = m);\n\t}\n\n\tread.map!(a => weight[a]).reduce!`long(a)+b`.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\n\nvoid main()\n{\n\tauto aaa = readln.chomp.split.map!(to!int);\n\tint n = aaa[0];\n\tint k = aaa[1];\n\tint m = aaa[2];\n\tstring[] msg = readln.chomp.split;\n\tulong[string] mapper;\n\tforeach (i, s; msg) {\n\t\tmapper[s] = i;\n\t}\n\tulong[] cost = readln.chomp.split.map!(to!ulong).array;\n\tulong[] best = new ulong[n];\n\tforeach (i; 0..k) {\n\t\tauto bbb = readln.chomp.split.map!(to!ulong);\n\t\tulong x = bbb[0];\n\t\tulong[] a = bbb[1..$].array;\n\t\tulong ans = ulong.max;\n\t\tforeach (v; a) {\n\t\t\tulong w = v - 1;\n\t\t\tans = min(ans, cost[cast(uint)w]);\n\t\t}\n\t\t// stderr.writeln([x, ans]);\n\t\tforeach (v; a) {\n\t\t\tulong w = v - 1;\n\t\t\tbest[cast(uint)w] = ans;\n\t\t\t// stderr.writeln(\"\\tbest : \", msg[w], \" :\", [w, ans]);\n\t\t}\n\t}\n\tstring[] next = readln.chomp.split;\n\tulong sum = 0;\n\tforeach (s; next) {\n\t\tsum += best[cast(uint)mapper[s]];\n\t}\n\tsum.writeln;\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}\nvoid readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}\nvoid readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}\n\nvoid main()\n{\n int n, k, m; readV(n, k, m);\n string[] w; readA(n, w);\n int[] a; readA(n, a);\n auto g = new int[][](k);\n foreach (i; 0..k) g[i] = readXA!int;\n foreach (ref gi; g) gi[] -= 1;\n string[] s; readA(m, s);\n\n auto mc = new int[](k);\n foreach (int i, gi; g)\n mc[i] = gi.map!(gij => a[gij]).fold!min;\n\n auto h = new int[](n);\n foreach (int i, gi; g)\n foreach (gij; gi)\n h[gij] = mc[i];\n\n int[string] wg;\n foreach (int i, wi; w) wg[wi] = h[i];\n\n writeln(s.map!(si => wg[si].to!long).sum);\n}\n\nT[] readXA(T)()\n{\n auto r = readln.splitter;\n auto x = r.front.to!size_t; r.popFront;\n auto a = new T[](x);\n foreach (i; 0..x) {\n a[i] = r.front.to!T;\n r.popFront;\n }\n return a;\n}\n"}], "negative_code": [{"source_code": "import\n\t\tstd.math,\n\t\tstd.conv,\n\t\tstd.file,\n\t\tstd.range,\n\t\tstd.array,\n\t\tstd.stdio,\n\t\tstd.string,\n\t\tstd.bitmanip,\n\t\tstd.typecons,\n\t\tstd.algorithm;\n\n\nauto read()\n{\n\treturn readln.strip.split;\n}\n\nauto readn()\n{\n\treturn read.map!(to!int).array;\n}\n\nvoid main()\n{\n\tauto ns = readn;\n\tauto words = read;\n\n\tint[string] weight;\n\n\tforeach(i, w; readn)\n\t{\n\t\tweight[words[i]] = w;\n\t}\n\n\tforeach(gw; ns[1].iota.map!(_ => readn))\n\t{\n\t\tauto ws = words.indexed(gw[1..$].map!(a => a - 1));\n\t\tauto m = ws.map!(a => weight[a]).reduce!min;\n\n\t\tws.each!(a => weight[a] = m);\n\t}\n\n\tread.map!(a => weight[a]).reduce!`a+b`.writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\n\nvoid main()\n{\n\tauto aaa = readln.chomp.split.map!(to!int);\n\tint n = aaa[0];\n\tint k = aaa[1];\n\tint m = aaa[2];\n\tstring[] msg = readln.chomp.split;\n\tulong[string] mapper;\n\tforeach (i, s; msg) {\n\t\tmapper[s] = i;\n\t}\n\tint[] cost = readln.chomp.split.map!(to!int).array;\n\tint[] best = new int[n];\n\tforeach (i; 0..k) {\n\t\tauto bbb = readln.chomp.split.map!(to!int);\n\t\tint x = bbb[0];\n\t\tint[] a = bbb[1..$].array;\n\t\tint ans = int.max;\n\t\tforeach (v; a) {\n\t\t\tint w = v - 1;\n\t\t\tans = min(ans, cost[w]);\n\t\t}\n\t\t// stderr.writeln([x, ans]);\n\t\tforeach (v; a) {\n\t\t\tint w = v - 1;\n\t\t\tbest[w] = ans;\n\t\t\t// stderr.writeln(\"\\tbest : \", msg[w], \" :\", [w, ans]);\n\t\t}\n\t}\n\tstring[] next = readln.chomp.split;\n\tint sum = 0;\n\tforeach (s; next) {\n\t\tsum += best[cast(uint)mapper[s]];\n\t}\n\tsum.writeln;\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}\nvoid readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}\nvoid readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}\n\nvoid main()\n{\n int n, k, m; readV(n, k, m);\n string[] w; readA(n, w);\n int[] a; readA(n, a);\n auto g = new int[][](k);\n foreach (i; 0..k) g[i] = readXA!int;\n foreach (ref gi; g) gi[] -= 1;\n string[] s; readA(m, s);\n\n auto mc = new int[](k);\n foreach (int i, gi; g)\n mc[i] = gi.map!(gij => a[gij]).fold!min;\n\n auto h = new int[](n);\n foreach (int i, gi; g)\n foreach (gij; gi)\n h[gij] = mc[i];\n\n int[string] wg;\n foreach (int i, wi; w) wg[wi] = h[i];\n\n writeln(s.map!(si => wg[si]).sum);\n}\n\nT[] readXA(T)()\n{\n auto r = readln.splitter;\n auto x = r.front.to!size_t; r.popFront;\n auto a = new T[](x);\n foreach (i; 0..x) {\n a[i] = r.front.to!T;\n r.popFront;\n }\n return a;\n}\n"}], "src_uid": "296552dc2df23b3920baef7d47d0a591"} {"source_code": "import std.stdio;\r\nimport std.algorithm;\r\nimport std.conv;\r\nvoid main()\r\n{\r\n auto total = new long[10000001];\r\n for(int i = 1; i < 10000001; i++) {\r\n for(int j = i; j < 10000001; j += i){\r\n total[j] += i;\r\n }\r\n }\r\n int[] at = new int[10000001];\r\n at.fill(-1);\r\n for(int i = 10000000;i>0;i--){\r\n if(total[i]<10000001){\r\n at[to!uint(total[i])] = i ;\r\n }\r\n }\r\n int n;\r\n readf!\"%d\"(n);\r\n \r\n while (n--) {\r\n int c;\r\n readf!\" %d\"(c);\r\n writeln(at[c]);\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\n\nvoid main() {\n auto total = new long[10000001];\n for (int i = 1; i < 10000001; i++) {\n for (int j = i; j < 10000001; j += i) {\n total[j] += i;\n }\n }\n \n int[] ans = new int[10000001];\n ans.fill(-1);\n \n for (int i = 0; i < 10000001; i++) {\n if (total[i] < 10000001 && ans[to!uint(total[i])] == -1) {\n ans[to!uint(total[i])] = i;\n }\n }\n \n int n;\n readf!\"%d\"(n);\n \n while (n--) {\n int c;\n readf!\" %d\"(c);\n writeln(ans[c]);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n auto total = new long[10000001];\n for (int i = 1; i < 10000001; i++) {\n for (int j = i; j < 10000001; j += i) {\n total[j] += i;\n }\n }\n \n int[long] m;\n \n for (int i = 0; i < 50; i++) {\n if (total[i] !in m) {\n m[total[i]] = i;\n }\n }\n \n int n;\n readf!\"%d\"(n);\n \n while (n--) {\n int c;\n readf!\" %d\"(c);\n if (c !in m) {\n writeln(-1);\n } else {\n writeln(m[c]);\n }\n }\n \n \n \n}\n"}], "src_uid": "b5dcee7034ee2742b666aea4cbfc616f"} {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint m = rint, n = rint, k = rint, t = rint;\n\tlong[] as = rlong(m);\n\tas.sort!\"a>b\"();\n\n\tX[] traps;\n\tforeach(i; 0 .. k) traps ~= X(rint, rint, rlong);\n\t\n\tbool isOK(int x){\n\t\tlong a = (x > 0? as[x - 1]: 200_999);\n\t\tint[] ls, rs;\n\t\tforeach(tr; traps) if(tr.d > a) ls ~= tr.l, rs ~= tr.r;\n\t\tls.sort(), rs.sort();\n\t\tauto lq = new Queue!int(ls), rq = new Queue!int(rs);\n\t\tint leftpos = 0;\n\t\tint time = (n + 1);\n\t\tint cnt = 0;\n\t\tlog(\"x:\", x, \"a:\", a, \"ls:\", ls, \"rs:\", rs, \"lq:\", lq, \"rq:\", rq, \"leftpos:\", leftpos, \"cnt:\", cnt, \"time:\", time);\n\t\twhile(lq.length + rq.length > 0){\n\t\t\tif(lq.length > 0 && lq.peek <= rq.peek){\n\t\t\t\tif(cnt == 0) leftpos = lq.peek - 1;\n\t\t\t\tlq.deq, cnt += 1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(cnt == 1) time += (rq.peek - leftpos) * 2;\n\t\t\t\trq.deq, cnt -= 1;\n\t\t\t}\n\t\t\tlog(\"lq:\", lq, \"rq:\", rq, \"leftpos:\", leftpos, \"cnt:\", cnt, \"time:\", time);\n\t\t}\n//\t\tlog(\"x:\", x, \"a:\", a, \"leftend:\", leftend, \"rightend:\", rightend, \"time:\", time, \"isOK:\", time <= t);\n\t\treturn time <= t;\n\n\t}\n\n\tint ans = uplimit(0, m, &isOK);\n\tans.writeln;\n}\nstruct X{\n\tint l, r;\n\tlong d;\n}\n// \u4e8c\u5206\u63a2\u7d22\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\nT uplimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(c)) return c; if(! f(a)) return a - 1;\n\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) a = b; else c = b; }\n\treturn a;\n}\nT downlimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(a)) return a; if(! f(c)) return c + 1;\n\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) c = b; else a = b; }\n\treturn c;\n}\n// ----- \u30ad\u30e5\u30fc -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : \u6b21\u306b\u8aad\u307f\u51fa\u3059\u4f4d\u7f6e\u3000j: \u6b21\u306b\u66f8\u304d\u8fbc\u3080\u4f4d\u7f6e\n\tthis(){\t}\n\tthis(T[] xs){ this.xs = xs; j = xs.length; }\n\tvoid enq(T x){\n\t\twhile(j + 1 >= xs.length) xs.length = xs.length * 2 + 1;\n\t\txs[j ++] = x;\n\t}\n\tulong length(){ return j - i; }\n\tbool isEmpty(){ return j == i; }\n\tT deq(){ assert(i < j); return xs[i ++]; }\n\tT peek(){ assert(i < j); return xs[i]; }\n\tT[] array(){ return xs[i .. j]; }\n\toverride string toString(){ return array.to!string; }\n}\n/*\n5 6 4 14\n1 2 3 4 5\n1 5 2\n1 2 5\n3 4 5\n3 5 3\n*/", "positive_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n \tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\nint main()\n{\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n r(a);\n alias Trap = Tuple!(int, \"right\", int, \"danger\");\n Trap[][] pos;\n pos.length = n + 2;\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Trap(right, danger);\n }\n bool can(int ag)\n {\n if (ag <= 0) return true;\n int ct = 0;\n for(int i = 0; i < n + 1;)\n {\n\tint j, objective = i + 1;\n\tbool deact = false;\n\tfor(j = i + 1; j <= objective; j++)\n\t foreach(cell; pos[j])\n\t if(cell.danger > ag)\n\t\tobjective = max(objective, cell.right), deact = true;\n\tct += (objective - i) * (1 + 2 * deact);\n\tif (ct > t) return false;\n\ti = objective;\n }\n return true;\n }\n auto ag = iota(1, 200000 + 1).assumeSorted!((a, b) => !can(a) && can(b)).equalRange(0)[0];\n auto sortedA = sort!\"a < b\"(a);\n w(sortedA.upperBound(ag).length + sortedA.equalRange(ag).length);\n return 0;\n}\n"}, {"source_code": "\nimport std.stdio;\n \nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n \tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n \nstruct Cell\n{\n int right, danger;\n this(bool active, int right, int danger)\n {\n this.right = right;\n this.danger = danger;\n }\n}\n \n \nint main()\n{\n import std.container.rbtree;\n import std.algorithm;\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n Cell[][] pos;\n int[][] deact;\n pos.length = n + 2;\n deact.length = n + 2;\n r(a);\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Cell(true, right, danger);\n deact[right] ~= l;\n }\n bool can(int ag)\n {\n int pa = 0;\n int pm = 0;\n int ct = 0;\n bool[] active;\n active.length = n + 2;\n active[] = true;\n while(pa != n + 1)\n {\n \tint obj = 0;\n \twhile(true)\n \t {\n \t bool mustbreak = false;\n \t foreach(cell; pos[pm + 1])\n \t {\n \t\tif (active[pm + 1] && cell.danger > ag)\n \t\t {\n \t\t mustbreak = true;\n \t\t obj = max(obj, cell.right);\n \t\t }\n \t }\n \t if (mustbreak)\n \t break;\n \t pm++;\n \t pa++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t if (pa == n + 1)\n \t {\n \t\treturn true;\n \t }\n \t }\n \t\n \tfor(; pm <= obj;)\n \t {\n \t foreach(d; deact[pm])\n \t {\n \t\tactive[d] = false;\n \t }\n \t foreach(cell; pos[pm])\n \t {\n \t\tif (active[pm] && cell.danger > ag)\n \t\t obj = max(obj, cell.right);\n \t }\n \t if (pm == obj)\n \t {\n \t\tbreak;\n \t }\n \t pm++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t }\n \tassert(pm == obj);\n \tct += (pm - pa) * 2;\n \tpa = obj;\n \tif (ct > t)\n \t return false;\n }\n assert(0);\n }\n import std.range;\n auto ag = iota(1, 200000 + 1).map!((a=>cast(int)can(a))).assumeSorted.equalRange(0).length + 1;\n auto sortedA = sort!\"a < b\"(a);\n w(sortedA.upperBound(ag).length + sortedA.equalRange(ag).length);\n \n return 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\n \nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n \tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n \nstruct Cell\n{\n int right, danger;\n this(int right, int danger)\n {\n this.right = right;\n this.danger = danger;\n }\n}\nint main()\n{\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n r(a);\n Cell[][] pos;\n pos.length = n + 2;\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Cell(right, danger);\n }\n bool can(int ag)\n {\n if (ag <= 0) return true;\n int ct = 0;\n for(int i = 0; i < n + 1;)\n {\n\tint j, objective = i + 1;\n\tbool deact = false;\n\tfor(j = i + 1; j <= objective; j++)\n\t foreach(cell; pos[j])\n\t if(cell.danger > ag)\n\t\tobjective = max(objective, cell.right), deact = true;\n\tct += (objective - i) * (1 + 2 * deact);\n\tif (ct > t) return false;\n\ti = objective;\n }\n return true;\n }\n auto ag = iota(1, 200000 + 1).assumeSorted!((a, b) => !can(a) && can(b)).equalRange(0)[0];\n auto sortedA = sort!\"a < b\"(a);\n w(sortedA.upperBound(ag).length + sortedA.equalRange(ag).length);\n return 0;\n}\n"}, {"source_code": "\nimport std.stdio;\n \nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n \tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n \nstruct Cell\n{\n int right, danger;\n this(bool active, int right, int danger)\n {\n this.right = right;\n this.danger = danger;\n }\n}\n \n \nint main()\n{\n import std.container.rbtree;\n import std.algorithm;\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n Cell[][] pos;\n int[][] deact;\n pos.length = n + 2;\n deact.length = n + 2;\n r(a);\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Cell(true, right, danger);\n deact[right] ~= l;\n }\n bool can(int ag)\n {\n if (ag <= 0)\n return true;\n int pa = 0;\n int pm = 0;\n int ct = 0;\n bool[] active;\n active.length = n + 2;\n active[] = true;\n while(pa != n + 1)\n {\n \tint obj = 0;\n \twhile(true)\n \t {\n \t bool mustbreak = false;\n \t foreach(cell; pos[pm + 1])\n \t {\n \t\tif (active[pm + 1] && cell.danger > ag)\n \t\t {\n \t\t mustbreak = true;\n \t\t obj = max(obj, cell.right);\n \t\t }\n \t }\n \t if (mustbreak)\n \t break;\n \t pm++;\n \t pa++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t if (pa == n + 1)\n \t {\n \t\treturn true;\n \t }\n \t }\n \t\n \tfor(; pm <= obj;)\n \t {\n \t foreach(d; deact[pm])\n \t {\n \t\tactive[d] = false;\n \t }\n \t foreach(cell; pos[pm])\n \t {\n \t\tif (active[pm] && cell.danger > ag)\n \t\t obj = max(obj, cell.right);\n \t }\n \t if (pm == obj)\n \t {\n \t\tbreak;\n \t }\n \t pm++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t }\n \tassert(pm == obj);\n \tct += (pm - pa) * 2;\n \tpa = obj;\n \tif (ct > t)\n \t return false;\n }\n assert(0);\n }\n import std.range;\n auto ag = iota(1, 200000 + 1).assumeSorted!((a, b) => !can(a) && can(b)).equalRange(0)[0];\n auto sortedA = sort!\"a < b\"(a);\n w(sortedA.upperBound(ag).length + sortedA.equalRange(ag).length);\n \n return 0;\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k, t;\n readf(\"%s %s %s %s\", &m, &n, &k, &t);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto ds = new int[] (k);\n alias trap = Tuple!(int, bool);\n auto open = new int[][] (n+1);\n auto close = new int[][] (n+1);\n \n foreach (i; 0 .. k) {\n int le, r, d;\n readf(\"%s %s %s\", &le, &r, &d);\n readln;\n \n ds[i] = d;\n open[le] ~= i;\n close[r] ~= i;\n }\n \n arr.sort();\n arr.reverse();\n \n bool isOk(int toBring) {\n \n int tot = 0;\n int threshold = arr[toBring-1];\n \n debug { writeln(toBring, ' ', threshold); }\n \n bool alone = false;\n int soldiersPos = 0;\n int trapsCnt = 0;\n foreach (i; 1 .. n+1) {\n foreach (idx; open[i]) {\n if (ds[idx] <= threshold) { continue; }\n \n trapsCnt += 1;\n alone = true;\n }\n \n foreach (idx; close[i]) {\n if (ds[idx] <= threshold) { continue; }\n \n trapsCnt -= 1;\n }\n \n if (trapsCnt == 0) {\n if (alone) { tot += 2 * (i - soldiersPos); }\n tot += i - soldiersPos;\n soldiersPos = i;\n alone = false;\n }\n \n debug { writeln(i, ' ', soldiersPos, ' ', tot); }\n }\n \n tot += 1;\n return tot <= t;\n }\n \n int le = 0, r = m;\n while (le < r) {\n int c = (le + r) / 2 + 1;\n \n if (isOk(c)) { le = c; }\n else { r = c-1; }\n }\n \n le.writeln;\n}"}], "negative_code": [{"source_code": "\nimport std.stdio;\n \nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n \tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n \nstruct Cell\n{\n int right, danger;\n this(bool active, int right, int danger)\n {\n this.right = right;\n this.danger = danger;\n }\n}\n \n \nint main()\n{\n import std.container.rbtree;\n import std.algorithm;\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n Cell[][] pos;\n int[][] deact;\n pos.length = n + 2;\n deact.length = n + 2;\n r(a);\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Cell(true, right, danger);\n deact[right] ~= l;\n }\n bool can(int ag)\n {\n int pa = 0;\n int pm = 0;\n int ct = 0;\n bool[] active;\n active.length = n + 2;\n active[] = true;\n while(pa != n + 1)\n {\n \tint obj = 0;\n \twhile(true)\n \t {\n \t bool mustbreak = false;\n \t foreach(cell; pos[pm + 1])\n \t {\n \t\tif (active[pm + 1] && cell.danger > ag)\n \t\t {\n \t\t mustbreak = true;\n \t\t obj = max(obj, cell.right);\n \t\t }\n \t }\n \t if (mustbreak)\n \t break;\n \t pm++;\n \t pa++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t if (pa == n + 1)\n \t {\n \t\treturn true;\n \t }\n \t }\n \t\n \tfor(; pm <= obj;)\n \t {\n \t foreach(d; deact[pm])\n \t {\n \t\tactive[d] = false;\n \t }\n \t foreach(cell; pos[pm])\n \t {\n \t\tif (active[pm] && cell.danger > ag)\n \t\t obj = max(obj, cell.right);\n \t }\n \t if (pm == obj)\n \t {\n \t\tbreak;\n \t }\n \t pm++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t }\n \tassert(pm == obj);\n \tct += (pm - pa) * 2;\n \tpa = obj;\n \tif (ct > t)\n \t return false;\n }\n assert(0);\n }\n import std.range;\n auto ag = iota(1, 200000 + 1).assumeSorted!((a, b)=> cast(int)can(a) < cast(int)can(b)).upperBound(false)[0];\n auto sortedA = sort!\"a < b\"(a);\n w(sortedA.upperBound(ag).length + sortedA.equalRange(ag).length);\n \n return 0;\n}\n"}, {"source_code": "\nimport std.stdio;\n \nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n \tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n \nstruct Cell\n{\n int right, danger;\n this(bool active, int right, int danger)\n {\n this.right = right;\n this.danger = danger;\n }\n}\n \n \nint main()\n{\n import std.container.rbtree;\n import std.algorithm;\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n Cell[][] pos;\n int[][] deact;\n pos.length = n + 2;\n deact.length = n + 2;\n r(a);\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Cell(true, right, danger);\n deact[right] ~= l;\n }\n bool can(int ag)\n {\n int pa = 0;\n int pm = 0;\n int ct = 0;\n bool[] active;\n active.length = n + 2;\n active[] = true;\n while(pa != n + 1)\n {\n \tint obj = 0;\n \twhile(true)\n \t {\n \t bool mustbreak = false;\n \t foreach(cell; pos[pm + 1])\n \t {\n \t\tif (active[pm + 1] && cell.danger > ag)\n \t\t {\n \t\t mustbreak = true;\n \t\t obj = max(obj, cell.right);\n \t\t }\n \t }\n \t if (mustbreak)\n \t break;\n \t pm++;\n \t pa++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t if (pa == n + 1)\n \t {\n \t\treturn true;\n \t }\n \t }\n \t\n \tfor(; pm <= obj;)\n \t {\n \t foreach(d; deact[pm])\n \t {\n \t\tactive[d] = false;\n \t }\n \t foreach(cell; pos[pm])\n \t {\n \t\tif (active[pm] && cell.danger > ag)\n \t\t obj = max(obj, cell.right);\n \t }\n \t if (pm == obj)\n \t {\n \t\tbreak;\n \t }\n \t pm++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t }\n \tassert(pm == obj);\n \tct += (pm - pa) * 2;\n \tpa = obj;\n \tif (ct > t)\n \t return false;\n }\n assert(0);\n }\n import std.range;\n auto ag = iota(1, 10 + 1).assumeSorted!((a, b)=> cast(int)can(a) < cast(int)can(b)).upperBound(true)[0];\n auto sortedA = sort!\"a < b\"(a);\n w(sortedA.upperBound(ag).length + sortedA.equalRange(ag).length);\n \n return 0;\n}\n"}, {"source_code": "\nimport std.stdio;\n \nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n \tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n \nstruct Cell\n{\n int right, danger;\n this(bool active, int right, int danger)\n {\n this.right = right;\n this.danger = danger;\n }\n}\n \n \nint main()\n{\n import std.container.rbtree;\n import std.algorithm;\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n Cell[][] pos;\n int[][] deact;\n pos.length = n + 2;\n deact.length = n + 2;\n r(a);\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Cell(true, right, danger);\n deact[right] ~= l;\n }\n bool can(int ag)\n {\n int pa = 0;\n int pm = 0;\n int ct = 0;\n bool[] active;\n active.length = n + 2;\n active[] = true;\n while(pa != n + 1)\n {\n \tint obj = 0;\n \twhile(true)\n \t {\n \t bool mustbreak = false;\n \t foreach(cell; pos[pm + 1])\n \t {\n \t\tif (active[pm + 1] && cell.danger > ag)\n \t\t {\n \t\t mustbreak = true;\n \t\t obj = max(obj, cell.right);\n \t\t }\n \t }\n \t if (mustbreak)\n \t break;\n \t pm++;\n \t pa++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t if (pa == n + 1)\n \t {\n \t\treturn true;\n \t }\n \t }\n \t\n \tfor(; pm <= obj;)\n \t {\n \t foreach(d; deact[pm])\n \t {\n \t\tactive[d] = false;\n \t }\n \t foreach(cell; pos[pm])\n \t {\n \t\tif (active[pm] && cell.danger > ag)\n \t\t obj = max(obj, cell.right);\n \t }\n \t if (pm == obj)\n \t {\n \t\tbreak;\n \t }\n \t pm++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t }\n \tassert(pm == obj);\n \tct += (pm - pa) * 2;\n \tpa = obj;\n \tif (ct > t)\n \t return false;\n }\n assert(0);\n }\n import std.range;\n auto ag = iota(1, 200000 + 1).assumeSorted!((a, b)=> cast(int)can(a) < cast(int)can(b)).upperBound(true)[0];\n auto sortedA = sort!\"a < b\"(a);\n w(sortedA.upperBound(ag).length + sortedA.equalRange(ag).length);\n \n return 0;\n}\n"}, {"source_code": "\nimport std.stdio;\n \nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n \tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n \nstruct Cell\n{\n int right, danger;\n this(bool active, int right, int danger)\n {\n this.right = right;\n this.danger = danger;\n }\n}\n \n \nint main()\n{\n import std.container.rbtree;\n import std.algorithm;\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n Cell[][] pos;\n int[][] deact;\n pos.length = n + 2;\n deact.length = n + 2;\n r(a);\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Cell(true, right, danger);\n deact[right] ~= l;\n }\n bool can(int ag)\n {\n int pa = 0;\n int pm = 0;\n int ct = 0;\n bool[] active;\n active.length = n + 2;\n active[] = true;\n while(pa != n + 1)\n {\n \tint obj = 0;\n \twhile(true)\n \t {\n \t bool mustbreak = false;\n \t foreach(cell; pos[pm + 1])\n \t {\n \t\tif (active[pm + 1] && cell.danger > ag)\n \t\t {\n \t\t mustbreak = true;\n \t\t obj = max(obj, cell.right);\n \t\t }\n \t }\n \t if (mustbreak)\n \t break;\n \t pm++;\n \t pa++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t if (pa == n + 1)\n \t {\n \t\treturn true;\n \t }\n \t }\n \t\n \tfor(; pm <= obj;)\n \t {\n \t foreach(d; deact[pm])\n \t {\n \t\tactive[d] = false;\n \t }\n \t foreach(cell; pos[pm])\n \t {\n \t\tif (active[pm] && cell.danger > ag)\n \t\t obj = max(obj, cell.right);\n \t }\n \t if (pm == obj)\n \t {\n \t\tbreak;\n \t }\n \t pm++;\n \t ct++;\n \t if (ct > t)\n \t return false;\n \t }\n \tassert(pm == obj);\n \tct += (pm - pa) * 2;\n \tpa = obj;\n \tif (ct > t)\n \t return false;\n }\n assert(0);\n }\n import std.range;\n auto ag = iota(1, 200000 + 1).assumeSorted!((a, b) => !can(a) && can(b)).equalRange(false).length + 1;\n auto sortedA = sort!\"a < b\"(a);\n w(sortedA.upperBound(ag).length + sortedA.equalRange(ag).length);\n \n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]))\n foreach(ref e; args[i])\n\tread(e);\n else\n readf!\" %s\"(args[i]);\n}\nalias r = read;\nalias w = writeln;\n\nstruct Cell\n{\n int right, danger;\n this(bool active, int right, int danger)\n {\n this.right = right;\n this.danger = danger;\n }\n}\n\n\nint main()\n{\n import std.container.rbtree;\n import std.algorithm;\n int m, n, k, t;\n r(m, n, k, t);\n int[] a;\n a.length = m;\n Cell[][] pos;\n int[][] deact;\n pos.length = n + 2;\n deact.length = n + 2;\n r(a);\n foreach(i; 0 .. k)\n {\n int l, right, danger;\n r(l, right, danger);\n pos[l] ~= Cell(true, right, danger);\n deact[right] ~= l;\n }\n bool can(int ag)\n {\n int pa = 0;\n int pm = 0;\n int ct = 0;\n bool[] active;\n active.length = n + 2;\n active[] = true;\n while(pa != n + 1)\n {\n\tint obj = 0;\n\twhile(true)\n\t {\n\t bool mustbreak = false;\n\t foreach(cell; pos[pm + 1])\n\t\tif (active[pm + 1] && cell.danger > ag)\n\t\t {\n\t\t mustbreak = true;\n\t\t obj = max(obj, cell.right);\n\t\t }\n\t if (mustbreak)\n\t break;\n\t pm++;\n\t pa++;\n\t ct++;\n\t if (ct > t)\n\t return false;\n\t if (pa == n + 1)\n\t\treturn true;\n\t }\n\t\n\tfor(; pm <= obj;)\n\t {\n\t foreach(d; deact[pm])\n\t\tactive[d] = false;\n\t foreach(cell; pos[pm])\n\t\tif (active[pm] && cell.danger > ag)\n\t\t obj = max(obj, cell.right);\n\t if (pm == obj)\n\t\tbreak;\n\t pm++;\n\t ct++;\n\t if (ct > t)\n\t return false;\n\t }\n\tassert(pm == obj);\n\tct += (pm - pa) * 2;\n\tpa = obj;\n\tif (ct > t)\n\t return false;\n }\n assert(0);\n }\n import std.range;\n auto ag = (assumeSorted!((int a, int b) => !can(a) || can(b))(iota(1, 200000 + 1)).lowerBound(true).length + 1);\n auto sortedA = sort!\"a <= b\"(a);\n auto res = sortedA.upperBound(ag).length;\n w(res);\n \n return 0;\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k, t;\n readf(\"%s %s %s %s\", &n, &m, &k, &t);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto ds = new int[] (k);\n auto open = new int[][] (n+1);\n auto close = new int[][] (n+1);\n \n foreach (i; 0 .. k) {\n int le, r, d;\n readf(\"%s %s %s\", &le, &r, &d);\n readln;\n \n ds[i] = d;\n open[le] ~= i;\n close[r] ~= i;\n }\n \n arr.sort();\n arr.reverse();\n \n bool isOk(int toBring) {\n \n int tot = 0;\n int threshold = arr[toBring-1];\n \n debug { writeln(toBring, ' ', threshold); }\n \n bool alone = false;\n int soldiersPos = 0;\n auto onPath = new bool[] (k);\n onPath[] = false;\n int onPathCnt = 0;\n foreach (i; 1 .. n+1) {\n foreach (idx; open[i]) {\n if (ds[idx] <= threshold) { continue; }\n \n onPath[idx] = true;\n onPathCnt += 1;\n alone = true;\n }\n \n foreach (idx; close[i]) {\n if (onPath[idx]) {\n onPath[idx] = false;\n onPathCnt -= 1;\n }\n }\n \n if (onPathCnt == 0) {\n if (alone) { tot += 2 * (i - soldiersPos); }\n tot += i - soldiersPos;\n soldiersPos = i;\n alone = false;\n }\n \n debug { writeln(i, ' ', soldiersPos, ' ', onPath, ' ', tot); }\n }\n \n tot += 1;\n return tot <= t;\n }\n \n int le = 0, r = n;\n while (le < r) {\n int c = (le + r) / 2 + 1;\n \n if (isOk(c)) { le = c; }\n else { r = c-1; }\n }\n \n le.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k, t;\n readf(\"%s %s %s %s\", &n, &m, &k, &t);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto ds = new int[] (k);\n alias trap = Tuple!(int, bool);\n auto open = new int[][] (n+1);\n auto close = new int[][] (n+1);\n \n foreach (i; 0 .. k) {\n int le, r, d;\n readf(\"%s %s %s\", &le, &r, &d);\n readln;\n \n ds[i] = d;\n open[le] ~= i;\n close[r] ~= i;\n }\n \n arr.sort();\n arr.reverse();\n \n bool isOk(int toBring) {\n \n int tot = 0;\n int threshold = arr[toBring-1];\n \n debug { writeln(toBring, ' ', threshold); }\n \n bool alone = false;\n int soldiersPos = 0;\n auto onPath = new bool[] (k);\n onPath[] = false;\n int onPathCnt = 0;\n foreach (i; 1 .. n+1) {\n foreach (idx; open[i]) {\n if (ds[idx] <= threshold) { continue; }\n \n onPath[idx] = true;\n onPathCnt += 1;\n alone = true;\n }\n \n foreach (idx; close[i]) {\n if (onPath[idx]) {\n onPath[idx] = false;\n onPathCnt -= 1;\n }\n }\n \n if (onPathCnt == 0) {\n if (alone) { tot += 2 * (i - soldiersPos); }\n tot += i - soldiersPos;\n soldiersPos = i;\n alone = false;\n }\n \n debug { writeln(i, ' ', soldiersPos, ' ', onPath, ' ', tot); }\n }\n \n tot += 1;\n return tot <= t;\n }\n \n int le = 0, r = n;\n while (le < r) {\n int c = (le + r) / 2 + 1;\n \n if (isOk(c)) { le = c; }\n else { r = c-1; }\n }\n \n le.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k, t;\n readf(\"%s %s %s %s\", &m, &n, &k, &t);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto ds = new int[] (n);\n alias trap = Tuple!(int, bool);\n auto open = new int[][] (n+1);\n auto close = new int[][] (n+1);\n \n foreach (i; 0 .. k) {\n int le, r, d;\n readf(\"%s %s %s\", &le, &r, &d);\n readln;\n \n ds[i] = d;\n open[le] ~= i;\n close[r] ~= i;\n }\n \n arr.sort();\n arr.reverse();\n \n bool isOk(int toBring) {\n \n int tot = 0;\n int threshold = arr[toBring-1];\n \n debug { writeln(toBring, ' ', threshold); }\n \n bool alone = false;\n int soldiersPos = 0;\n auto onPath = new bool[] (k+1);\n onPath[] = false;\n int onPathCnt = 0;\n foreach (i; 1 .. n+1) {\n foreach (idx; open[i]) {\n if (ds[idx] <= threshold) { continue; }\n \n onPath[idx] = true;\n onPathCnt += 1;\n alone = true;\n }\n \n foreach (idx; close[i]) {\n if (onPath[idx]) {\n onPath[idx] = false;\n onPathCnt -= 1;\n }\n }\n \n if (onPathCnt == 0) {\n if (alone) { tot += 2 * (i - soldiersPos); }\n tot += i - soldiersPos;\n soldiersPos = i;\n alone = false;\n }\n \n debug { writeln(i, ' ', soldiersPos, ' ', onPath, ' ', tot); }\n }\n \n tot += 1;\n return tot <= t;\n }\n \n int le = 0, r = n;\n while (le < r) {\n int c = (le + r) / 2 + 1;\n \n if (isOk(c)) { le = c; }\n else { r = c-1; }\n }\n \n le.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k, t;\n readf(\"%s %s %s %s\", &n, &m, &k, &t);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto ds = new int[] (n);\n alias trap = Tuple!(int, bool);\n auto open = new int[][] (n+1);\n auto close = new int[][] (n+1);\n \n foreach (i; 0 .. k) {\n int le, r, d;\n readf(\"%s %s %s\", &le, &r, &d);\n readln;\n \n ds[i] = d;\n open[le] ~= i;\n close[r] ~= i;\n }\n \n arr.sort();\n arr.reverse();\n \n bool isOk(int toBring) {\n \n int tot = 0;\n int threshold = arr[toBring-1];\n \n debug { writeln(toBring, ' ', threshold); }\n \n bool alone = false;\n int soldiersPos = 0;\n auto onPath = new bool[] (k+1);\n onPath[] = false;\n int onPathCnt = 0;\n foreach (i; 1 .. n+1) {\n foreach (idx; open[i]) {\n if (ds[idx] <= threshold) { continue; }\n \n onPath[idx] = true;\n onPathCnt += 1;\n alone = true;\n }\n \n foreach (idx; close[i]) {\n if (onPath[idx]) {\n onPath[idx] = false;\n onPathCnt -= 1;\n }\n }\n \n if (onPathCnt == 0) {\n if (alone) { tot += 2 * (i - soldiersPos); }\n tot += i - soldiersPos;\n soldiersPos = i;\n alone = false;\n }\n \n debug { writeln(i, ' ', soldiersPos, ' ', onPath, ' ', tot); }\n }\n \n tot += 1;\n return tot <= t;\n }\n \n int le = 0, r = n;\n while (le < r) {\n int c = (le + r) / 2 + 1;\n \n if (isOk(c)) { le = c; }\n else { r = c-1; }\n }\n \n le.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k, t;\n readf(\"%s %s %s %s\", &n, &m, &k, &t);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto ds = new int[] (n);\n alias trap = Tuple!(int, bool);\n auto open = new int[][] (n+1);\n auto close = new int[][] (n+1);\n \n foreach (i; 0 .. k) {\n int le, r, d;\n readf(\"%s %s %s\", &le, &r, &d);\n readln;\n \n ds[i] = d;\n open[le] ~= i;\n close[r] ~= i;\n }\n \n arr.sort();\n arr.reverse();\n \n bool isOk(int toBring) {\n \n int tot = 0;\n int threshold = arr[toBring-1];\n \n debug { writeln(toBring, ' ', threshold); }\n \n bool alone = false;\n int soldiersPos = 0;\n auto onPath = new bool[] (n+1);\n onPath[] = false;\n int onPathCnt = 0;\n foreach (i; 1 .. n+1) {\n foreach (idx; open[i]) {\n if (ds[idx] <= threshold) { continue; }\n \n onPath[idx] = true;\n onPathCnt += 1;\n alone = true;\n }\n \n foreach (idx; close[i]) {\n if (onPath[idx]) {\n onPath[idx] = false;\n onPathCnt -= 1;\n }\n }\n \n if (onPathCnt == 0) {\n if (alone) { tot += 2 * (i - soldiersPos); }\n tot += i - soldiersPos;\n soldiersPos = i;\n alone = false;\n }\n \n debug { writeln(i, ' ', soldiersPos, ' ', onPath, ' ', tot); }\n }\n \n tot += 1;\n return tot <= t;\n }\n \n int le = 0, r = n;\n while (le < r) {\n int c = (le + r) / 2 + 1;\n \n if (isOk(c)) { le = c; }\n else { r = c-1; }\n }\n \n le.writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint m = rint, n = rint, k = rint, t = rint;\n\tlong[] as = rlong(m);\n\tas.sort!\"a>b\"();\n\n\tX[] traps;\n\tforeach(i; 0 .. k) traps ~= X(rint, rint, rlong);\n\n\tbool isOK(int x){\n\t\tlong a = (x > 0? as[x - 1]: 200_999);\n\t\tint rightend = 0;\n\t\tforeach(tr; traps) if(tr.d > a) rightend.chmax(tr.r);\n\t\tint time = rightend * 2 + n;\n\t\treturn (time <= t);\n\t}\n\n\tint ans = uplimit(0, m, &isOK);\n\tans.writeln;\n}\nstruct X{\n\tint l, r;\n\tlong d;\n}\n// \u4e8c\u5206\u63a2\u7d22\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\nT uplimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(c)) return c; if(! f(a)) return a - 1;\n\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) a = b; else c = b; }\n\treturn a;\n}\nT downlimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(a)) return a; if(! f(c)) return c + 1;\n\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) c = b; else a = b; }\n\treturn c;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint m = rint, n = rint, k = rint, t = rint;\n\tlong[] as = rlong(m);\n\tas.sort!\"a>b\"();\n\n\tX[] traps;\n\tforeach(i; 0 .. k) traps ~= X(rint, rint, rlong);\n\n\tbool isOK(int x){\n\t\tlong a = (x > 0? as[x - 1]: 200_999);\n\t\tint leftend = n + 1, rightend = 0;\n\t\tforeach(tr; traps) if(tr.d > a){\n\t\t\tleftend.chmin(tr.l);\n\t\t\trightend.chmax(tr.r);\n\t\t}\n\t\tif(leftend > rightend) leftend = rightend;\n\t\tint time = (rightend - leftend) * 2 + (n + 1);\n\t\tlog(\"x:\", x, \"leftend:\", leftend, \"rightend:\", rightend, \"time:\", time);\n\t\treturn (time <= t);\n\t}\n\n\tint ans = uplimit(0, m, &isOK);\n\tans.writeln;\n}\nstruct X{\n\tint l, r;\n\tlong d;\n}\n// \u4e8c\u5206\u63a2\u7d22\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\nT uplimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(c)) return c; if(! f(a)) return a - 1;\n\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) a = b; else c = b; }\n\treturn a;\n}\nT downlimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(a)) return a; if(! f(c)) return c + 1;\n\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) c = b; else a = b; }\n\treturn c;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint m = rint, n = rint, k = rint, t = rint;\n\tlong[] as = rlong(m);\n\n\tX[] traps;\n\tforeach(i; 0 .. k) traps ~= X(rint, rint, rlong);\n\n\tint rightmost = (t - (n + 1)) / 2;\n\n\tlong dmax = 0;\n\tforeach(tr; traps) if(tr.r > rightmost) dmax.chmax(tr.d);\n\n\tint ans = 0;\n\tforeach(a; as) if(a >= dmax) ans += 1;\n\tans.writeln;\n}\nstruct X{\n\tint l, r;\n\tlong d;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint m = rint, n = rint, k = rint, t = rint;\n\tlong[] as = rlong(m);\n\tas.sort!\"a>b\"();\n\n\tX[] traps;\n\tforeach(i; 0 .. k) traps ~= X(rint, rint, rlong);\n\t\n\tbool isOK(int x){\n\t\tlong a = (x > 0? as[x - 1]: 200_999);\n\t\tint[] ls, rs;\n\t\tforeach(tr; traps) if(tr.d > a) ls ~= tr.l, rs ~= tr.r;\n\t\tls.sort(), rs.sort();\n\t\tauto lq = new Queue!int(ls), rq = new Queue!int(rs);\n\t\tint leftpos = 0;\n\t\tint time = (n + 1);\n\t\tint cnt = 0;\n\t\tlog(\"x:\", x, \"a:\", a, \"ls:\", ls, \"rs:\", rs, \"lq:\", lq, \"rq:\", rq, \"leftpos:\", leftpos, \"cnt:\", cnt, \"time:\", time);\n\t\twhile(lq.length + rq.length > 0){\n\t\t\tif(lq.length > 0 && lq.peek <= rq.peek){\n\t\t\t\tif(cnt == 0) leftpos = lq.peek;\n\t\t\t\tlq.deq, cnt += 1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(cnt == 1) time += (rq.peek - leftpos) * 2;\n\t\t\t\trq.deq, cnt -= 1;\n\t\t\t}\n\t\t\tlog(\"lq:\", lq, \"rq:\", rq, \"leftpos:\", leftpos, \"cnt:\", cnt, \"time:\", time);\n\t\t}\n//\t\tlog(\"x:\", x, \"a:\", a, \"leftend:\", leftend, \"rightend:\", rightend, \"time:\", time, \"isOK:\", time <= t);\n\t\treturn time <= t;\n\n\t}\n\n\tint ans = uplimit(0, m, &isOK);\n\tans.writeln;\n}\nstruct X{\n\tint l, r;\n\tlong d;\n}\n// \u4e8c\u5206\u63a2\u7d22\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\nT uplimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(c)) return c; if(! f(a)) return a - 1;\n\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) a = b; else c = b; }\n\treturn a;\n}\nT downlimit(T)(T a, T c, bool delegate(T) f){\n\tif(f(a)) return a; if(! f(c)) return c + 1;\n\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) c = b; else a = b; }\n\treturn c;\n}\n// ----- \u30ad\u30e5\u30fc -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : \u6b21\u306b\u8aad\u307f\u51fa\u3059\u4f4d\u7f6e\u3000j: \u6b21\u306b\u66f8\u304d\u8fbc\u3080\u4f4d\u7f6e\n\tthis(){\t}\n\tthis(T[] xs){ this.xs = xs; j = xs.length; }\n\tvoid enq(T x){\n\t\twhile(j + 1 >= xs.length) xs.length = xs.length * 2 + 1;\n\t\txs[j ++] = x;\n\t}\n\tulong length(){ return j - i; }\n\tbool isEmpty(){ return j == i; }\n\tT deq(){ assert(i < j); return xs[i ++]; }\n\tT peek(){ assert(i < j); return xs[i]; }\n\tT[] array(){ return xs[i .. j]; }\n\toverride string toString(){ return array.to!string; }\n}\n/*\n5 6 4 14\n1 2 3 4 5\n1 5 2\n1 2 5\n3 4 5\n3 5 3\n*/"}], "src_uid": "14d158dd02d65096946445e14a5f210d"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.exception;\n\n int n;\n rd(n);\n auto a = readln.split.to!(int[]);\n sort(a);\n\n if (n == 1) {\n writeln(\"YES\");\n writeln(a[0]);\n return;\n }\n\n auto freq = new int[](1234);\n foreach (el; a) {\n freq[el]++;\n }\n if (n % 2 == 0) {\n auto mat = new int[][](n, n);\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = el;\n freq[el] -= 4;\n break;\n }\n }\n }\n }\n if (freq.any!((el) => (el > 0))) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n } else {\n auto mat = new int[][](n, n);\n foreach (el; a) {\n if (freq[el] % 4 == 1 || freq[el] % 4 == 3) {\n mat[n / 2][n / 2] = el;\n freq[el]--;\n break;\n }\n }\n if (freq.any!((el) => (el & 1))) {\n writeln(\"NO\");\n return;\n }\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 2) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = el;\n freq[el] -= 4;\n break;\n }\n }\n }\n }\n foreach (i; 0 .. n / 2) {\n if (mat[i][n / 2] == 0) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[i][n / 2] = mat[n - i - 1][n / 2] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n }\n foreach (j; 0 .. n / 2) {\n if (mat[n / 2][j] == 0) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[n / 2][j] = mat[n / 2][n - j - 1] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n }\n if (freq.any!((el) => (el > 0))) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n }\n}\n\n/*\n\n7\n5 9 5 4 1 9 8 4 5 1 4 10 7 7 8 4 2 4 4 5 4 4 10 3 4 6 8 1 9 9 5 6 8 7 1 8 6 6 7 5 3 1 1 4 7 2 3 3 8\n\n*/\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.exception;\n\n int n;\n rd(n);\n auto a = readln.split.to!(int[]);\n sort(a);\n\n if (n == 1) {\n writeln(\"YES\");\n writeln(a[0]);\n return;\n }\n\n auto freq = new int[](1234);\n foreach (el; a) {\n freq[el]++;\n }\n if (n % 2 == 0) {\n auto mat = new int[][](n, n);\n int k = 0;\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n if (k < n * n) {\n if (freq[a[k]] > 0 && freq[a[k]] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = a[k];\n freq[a[k]] -= 4;\n k += 4;\n }\n }\n }\n }\n if (k != n * n) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n } else {\n auto mat = new int[][](n, n);\n int od = 0;\n foreach(el; freq) {\n if (el & 1) {\n od++;\n }\n }\n if (od != 1) {\n writeln(\"NO\");\n return;\n }\n foreach (el; a) {\n if (freq[el] % 4 == 1 || freq[el] % 4 == 3) {\n mat[n / 2][n / 2] = el;\n freq[el]--;\n break;\n }\n }\n foreach (i; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] % 4 == 2) {\n mat[i][n / 2] = mat[n - i - 1][n / 2] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] % 4 == 2) {\n mat[n / 2][j] = mat[n / 2][n - j - 1] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = el;\n freq[el] -= 4;\n break;\n }\n }\n }\n }\n foreach (i; 0 .. n / 2) {\n if (mat[i][n / 2] == 0) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[i][n / 2] = mat[n - i - 1][n / 2] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n }\n foreach (j; 0 .. n / 2) {\n if (mat[n / 2][j] == 0) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[n / 2][j] = mat[n / 2][n - j - 1] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n }\n if (freq.any!((el) => (el != 0))) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n foreach (i; 0 .. n) {\n foreach (j; 0 .. n) {\n enforce(mat[i][j] > 0);\n enforce(mat[i][j] == mat[n - i - 1][j]);\n enforce(mat[i][j] == mat[i][n - j - 1]);\n enforce(mat[i][j] == mat[n - i - 1][n - j - 1]);\n }\n }\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n }\n}\n\n/*\n\n7\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3\n\n*/\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.exception;\n\n int n;\n rd(n);\n auto a = readln.split.to!(int[]);\n sort(a);\n\n if (n == 1) {\n writeln(\"YES\");\n writeln(a[0]);\n return;\n }\n\n auto freq = new int[](1234);\n foreach (el; a) {\n freq[el]++;\n }\n if (n % 2 == 0) {\n auto mat = new int[][](n, n);\n int k = 0;\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n if (k < n * n) {\n if (freq[a[k]] > 0 && freq[a[k]] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = a[k];\n freq[a[k]] -= 4;\n k += 4;\n }\n }\n }\n }\n if (k != n * n) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n } else {\n auto mat = new int[][](n, n);\n foreach (el; a) {\n if (freq[el] % 4 == 1 || freq[el] % 4 == 3) {\n mat[n / 2][n / 2] = el;\n freq[el]--;\n break;\n }\n }\n foreach (i; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] % 4 == 2) {\n mat[i][n / 2] = mat[n - i - 1][n / 2] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] % 4 == 2) {\n mat[n / 2][j] = mat[n / 2][n - j - 1] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = el;\n freq[el] -= 4;\n break;\n }\n }\n }\n }\n foreach (i; 0 .. n / 2) {\n if (mat[i][n / 2] == 0) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[i][n / 2] = mat[n - i - 1][n / 2] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n }\n foreach (j; 0 .. n / 2) {\n if (mat[n / 2][j] == 0) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[n / 2][j] = mat[n / 2][n - j - 1] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n }\n if (freq.any!((el) => (el != 0))) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n foreach (i; 0 .. n) {\n foreach (j; 0 .. n) {\n enforce(mat[i][j] > 0);\n enforce(mat[i][j] == mat[n - i - 1][j]);\n enforce(mat[i][j] == mat[i][n - j - 1]);\n enforce(mat[i][j] == mat[n - i - 1][n - j - 1]);\n }\n }\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n }\n}\n\n/*\n\n7\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3\n\n*/\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto a = readln.split.to!(int[]);\n sort(a);\n\n if (n == 1) {\n writeln(\"YES\");\n writeln(a[0]);\n return;\n }\n\n auto freq = new int[](1234);\n foreach (el; a) {\n freq[el]++;\n }\n if (n % 2 == 0) {\n auto mat = new int[][](n, n);\n int k = 0;\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n if (k < n * n) {\n if (freq[a[k]] > 0 && freq[a[k]] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = a[k];\n freq[a[k]] -= 4;\n k += 4;\n }\n }\n }\n }\n if (k != n * n) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n } else {\n auto mat = new int[][](n, n);\n foreach (el; a) {\n if (freq[el] % 4 == 1 || freq[el] % 4 == 3) {\n mat[n / 2][n / 2] = el;\n freq[el]--;\n break;\n }\n }\n foreach (i; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] % 4 == 2) {\n mat[i][n / 2] = mat[n - i - 1][n / 2] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] % 4 == 2) {\n mat[n / 2][j] = mat[n / 2][n - j - 1] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = el;\n freq[el] -= 4;\n break;\n }\n }\n }\n }\n foreach (i; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[i][n / 2] = mat[n - i - 1][n / 2] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[n / 2][j] = mat[n / 2][n - j - 1] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n if (freq.any!((el) => (el != 0))) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n }\n}\n\n/*\n \n\n*/\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.exception;\n\n int n;\n rd(n);\n auto a = readln.split.to!(int[]);\n sort(a);\n\n if (n == 1) {\n writeln(\"YES\");\n writeln(a[0]);\n return;\n }\n\n auto freq = new int[](1234);\n foreach (el; a) {\n freq[el]++;\n }\n if (n % 2 == 0) {\n auto mat = new int[][](n, n);\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = el;\n freq[el] -= 4;\n break;\n }\n }\n }\n }\n if (freq.any!((el) => (el > 0))) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n } else {\n auto mat = new int[][](n, n);\n foreach (el; a) {\n if (freq[el] % 4 == 1 || freq[el] % 4 == 3) {\n mat[n / 2][n / 2] = el;\n freq[el]--;\n break;\n }\n }\n foreach (i; 0 .. n / 2) {\n foreach (j; 0 .. n / 2) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 4 == 0) {\n mat[i][j] = mat[n - i - 1][j] = mat[i][n - j - 1] = mat[n - i - 1][n - j - 1] = el;\n freq[el] -= 4;\n break;\n }\n }\n }\n }\n foreach (i; 0 .. n / 2) {\n if (mat[i][n / 2] == 0) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[i][n / 2] = mat[n - i - 1][n / 2] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n }\n foreach (j; 0 .. n / 2) {\n if (mat[n / 2][j] == 0) {\n foreach (el; a) {\n if (freq[el] > 0 && freq[el] % 2 == 0) {\n mat[n / 2][j] = mat[n / 2][n - j - 1] = el;\n freq[el] -= 2;\n break;\n }\n }\n }\n }\n if (freq.any!((el) => (el != 0))) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n writefln(\"%(%(%s %)\\n%)\", mat);\n }\n }\n}\n\n/*\n\n7\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3\n\n*/\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "src_uid": "20928dd8e512bee2d86c6611c5e76390"} {"source_code": "//prewritten code: https://github.com/antma/algo\nmodule Solution;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.bitmanip;\nimport core.bitop;\nimport std.exception;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nalias MoResult = int;\n\nstruct MoQuery {\n int u, v;//inclusive\n MoResult res;\n}\n\nabstract class MoState {\n public:\n @property\n abstract bool fastReset () const;\n abstract void reset (); \n //[l, r)\n abstract void add (int l, int r);\n abstract void del (int l, int r);\n abstract MoResult result () const;\n}\n\nstruct MoRange {\n int l, r;\n bool fastReset;\n static immutable d = [3, 0, 0, 1];\n static long hilbert (const int x, const int y, const int k, const int a) {\n if (k < 0) return 0L;\n immutable int m = ~(1 << k), o = 3 & (((x >> k) ^ 3 * (y >> k)) + a);\n immutable long b = hilbert (x & m, y & m, k - 1, a + d[o]), ss = 1L << (2 * k); \n return ss * o + (o == 1 || o == 2 ? b : (ss - (b + 1)));\n }\n static size_t[] makeIdx (in MoQuery[] queries, const int t) {\n immutable nq = queries.length;\n auto x = uninitializedArray!(long[])(nq);\n foreach (i, const ref q; queries) {\n x[i] = hilbert (q.u, q.v, t, 0);\n }\n auto idx = uninitializedArray!(size_t[])(nq);\n makeIndex (x, idx);\n return idx;\n }\n void move (MoState s, ref MoQuery q) {\n if (l > r || (fastReset && (l > q.v || r < q.u))) {\n l = q.u;\n r = l - 1;\n s.reset ();\n }\n if (r < q.v) {\n s.add (r + 1, q.v + 1);\n r = q.v;\n } else if (r > q.v) {\n s.del (q.v + 1, r + 1);\n r = q.v;\n }\n if (l > q.u) {\n s.add (q.u, l);\n l = q.u;\n } else if (l < q.u) {\n s.del (l, q.u);\n l = q.u;\n }\n q.res = s.result ();\n }\n void processQueries (MoState s, MoQuery[] queries) {\n l = 0; r = -1; fastReset = s.fastReset; \n auto idx = makeIdx (queries, bsr (reduce!max(0, queries.map!(t => t.v)) + 1)); \n foreach (j; idx) {\n move (s, queries[j]);\n }\n }\n}\n\nfinal class EState : MoState {\n private:\n uint[] x;\n int[] ba;\n int sz;\n public:\n @property\n override bool fastReset () const {\n return false;\n }\n override void reset () {\n ba[] = 0;\n sz = 0;\n }\n //[l, r)\n override void add (int l, int r) {\n foreach (k; x[l .. r]) {\n if (++ba[k] == 1) ++sz;\n }\n }\n override void del (int l, int r) {\n foreach (k; x[l .. r]) {\n if (!--ba[k]) --sz;\n }\n }\n override MoResult result () const {\n return sz;\n }\n this (uint[] x, int n) {\n this.x = x;\n ba = new int[n];\n }\n}\n\nvoid test (in int n, uint[] a) {\n debug stderr.writeln (\"a = \", a);\n auto v = new int[n];\n foreach (i; 0 .. n) {\n v[i] = i;\n }\n auto prev = uninitializedArray!(int[]) (n);\n\n MoQuery[] q;\n \n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n q ~= MoQuery (prev[j] + 1, i.to!int - 1);\n }\n prev[j] = pos;\n }\n foreach (i; 0 .. n) {\n q ~= MoQuery (prev[i] + 1, a.length.to!int - 1);\n }\n\n auto state = new EState (a, n);\n MoRange rng;\n rng.processQueries (state, q); \n state = null;\n\n int cur;\n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n auto k = q[cur++].res; \n v[j] = max (v[j], k);\n }\n prev[j] = pos;\n }\n\n foreach (i; 0 .. n) {\n auto k = q[cur++].res;\n v[i] = max (v[i], k);\n }\n\n q = null;\n \n foreach (i; 0 .. n) {\n int j = v[i];\n int u = i;\n if (prev[i] >= n) {\n u = 0;\n }\n writeln (u + 1, ' ', j + 1);\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable n = r.next!uint;\n immutable m = r.next!uint;\n auto a = uninitializedArray!(uint[]) (n + m);\n foreach (i; 0 .. n) a[i] = n - 1 - i;\n foreach (i; 0 .. m) a[n+i] = r.next!uint - 1;\n a.length -= uniq (a).copy (a).length;\n test (n, a);\n}\n\n", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nmodule Solution;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.bitmanip;\nimport core.bitop;\nimport std.exception;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nalias MoResult = int;\n\nstruct MoQuery {\n int u, v;//inclusive\n MoResult res;\n}\n\nabstract class MoState {\n public:\n @property\n abstract bool fastReset () const;\n abstract void reset (); \n //[l, r)\n abstract void add (int l, int r);\n abstract void del (int l, int r);\n abstract MoResult result () const;\n}\n\nstruct MoRange {\n int l, r;\n bool fastReset;\n static immutable hilbertDirs = [3, 0, 0, 1];\n static long hilbert (int x, int y, int k, int a) {\n if (k < 0) return 0L;\n int m = 1 << k, o = 3 & (((x >> k) ^ 3 * (y >> k)) + a);\n long ss = 1L << (2 * k), b = hilbert (x & ~m, y & ~m, k - 1, a + hilbertDirs[o]);\n return ss * o + (o == 1 || o == 2 ? b : (ss - (b + 1)));\n }\n void move (MoState s, ref MoQuery q) {\n if (l > r || (fastReset && (l > q.v || r < q.u))) {\n l = q.u;\n r = l - 1;\n s.reset ();\n }\n if (r < q.v) {\n s.add (r + 1, q.v + 1);\n r = q.v;\n } else if (r > q.v) {\n s.del (q.v + 1, r + 1);\n r = q.v;\n }\n if (l > q.u) {\n s.add (q.u, l);\n l = q.u;\n } else if (l < q.u) {\n s.del (l, q.u);\n l = q.u;\n }\n q.res = s.result ();\n }\n void processQueries (MoState s, MoQuery[] queries) {\n l = 0;\n r = -1;\n fastReset = s.fastReset; \n auto nq = queries.length;\n auto n = reduce!max(queries.map!(t => t.v));\n debug stderr.writeln (\"n = \", n);\n auto t = bsr (n + 1);\n auto x = queries.map!(q => hilbert (q.u, q.v, t, 0)).array;\n auto idx = uninitializedArray!(size_t[]) (nq);\n makeIndex (x, idx);\n x = null;\n foreach (j; idx) {\n move (s, queries[j]);\n }\n }\n}\n\nfinal class EState : MoState {\n private:\n uint[] x;\n int[] ba;\n int sz;\n public:\n @property\n override bool fastReset () const {\n return false;\n }\n override void reset () {\n ba[] = 0;\n sz = 0;\n }\n //[l, r)\n override void add (int l, int r) {\n foreach (k; x[l .. r]) {\n if (++ba[k] == 1) ++sz;\n }\n }\n override void del (int l, int r) {\n foreach (k; x[l .. r]) {\n if (!--ba[k]) --sz;\n }\n }\n override MoResult result () const {\n return sz;\n }\n this (uint[] x, int n) {\n this.x = x;\n ba = new int[n];\n }\n}\n\nvoid test (in int n, uint[] a) {\n debug stderr.writeln (\"a = \", a);\n auto v = new int[n];\n foreach (i; 0 .. n) {\n v[i] = i;\n }\n auto prev = uninitializedArray!(int[]) (n);\n\n MoQuery[] q;\n \n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n q ~= MoQuery (prev[j] + 1, i.to!int - 1);\n }\n prev[j] = pos;\n }\n foreach (i; 0 .. n) {\n q ~= MoQuery (prev[i] + 1, a.length.to!int - 1);\n }\n\n auto state = new EState (a, n);\n MoRange rng;\n rng.processQueries (state, q); \n state = null;\n\n int cur;\n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n auto k = q[cur++].res; \n v[j] = max (v[j], k);\n }\n prev[j] = pos;\n }\n\n foreach (i; 0 .. n) {\n auto k = q[cur++].res;\n v[i] = max (v[i], k);\n }\n\n q = null;\n \n foreach (i; 0 .. n) {\n int j = v[i];\n int u = i;\n if (prev[i] >= n) {\n u = 0;\n }\n writeln (u + 1, ' ', j + 1);\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable n = r.next!uint;\n immutable m = r.next!uint;\n auto a = uninitializedArray!(uint[]) (n + m);\n foreach (i; 0 .. n) a[i] = n - 1 - i;\n foreach (i; 0 .. m) a[n+i] = r.next!uint - 1;\n a.length -= uniq (a).copy (a).length;\n test (n, a);\n}\n\n"}], "negative_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.bitmanip;\nimport core.bitop;\n\nfinal class SegmentTree(T = int, alias op=\"a+b\", T zero) {\n private:\n T [] t;\n size_t n;\n void build () {\n foreach_reverse (i; 1 .. n) {\n immutable k = i << 1;\n t[i] = binaryFun!op (t[k], t[k+1]);\n }\n }\n public:\n void update (size_t p, T v) {\n for (t[p += n] = v; p > 1; p >>= 1) {\n t[p>>1] = binaryFun!op (t[p], t[p ^ 1]);\n }\n }\n T reduce (size_t l, size_t r) {\n T res = zero;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n if (l & 1) {\n res = binaryFun!op (res, t[l++]);\n }\n if (r & 1) {\n res = binaryFun!op (t[--r], res);\n }\n }\n return res;\n }\n this (T[] a) {\n n = a.length;\n t = uninitializedArray!(T[])(n);\n t ~= a;\n build ();\n }\n}\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nuint[] mrg (uint[] a, uint[] b) {\n return merge (a, b).uniq.array;\n}\n\nstruct MoQuery {\n int u;\n int v;\n}\n\nalias R = int;\nfinal class MoRange {\n private:\n immutable uint[] x;\n int l, r;\n //CUSTOM\n BitArray ba;\n int sz;\n\n static long hilbert (int x, int y, int k, int a) {\n static immutable d = [3, 0, 0, 1];\n if (k < 0) return 0L;\n int m = 1 << k, o = 3 & (((x >> k) ^ 3 * (y >> k)) + a);\n long ss = 1L << (2 * k), b = hilbert (x & ~m, y & ~m, k - 1, a + d[o]);\n return ss * o + (o == 1 || o == 2 ? b : (ss - (b + 1)));\n }\n\n void clear () {\n //CUSTOM\n ba[] = false;\n sz = 0;\n }\n \n R move (ref in MoQuery q) {\n if (l > r || l > q.v || r < q.u) {\n l = q.u;\n r = l - 1;\n clear ();\n }\n if (r < q.v) {\n add (r + 1, q.v + 1);\n r = q.v;\n } else if (r > q.v) {\n del (q.v + 1, r + 1);\n r = q.v;\n }\n if (l > q.u) {\n add (q.u, l);\n l = q.u;\n } else if (l < q.u) {\n del (l, q.u);\n l = q.u;\n }\n //CUSTOM\n return sz; \n }\n void add (const int a, const int b) {\n debug stderr.writefln (\"add (%d, %d)\", a, b);\n foreach (k; x[a .. b]) {\n if (!ba[k]) {\n ba[k] = true;\n ++sz;\n }\n }\n }\n void del (const int a, const int b) {\n foreach (k; x[a .. b]) {\n //assert (freq[k] > 0, format!\"freq[%d] = %d\" (k, freq[k]));\n if (ba[k]) {\n ba[k] = false;\n --sz;\n }\n }\n }\n int[] processQueries (in MoQuery[] queries) {\n l = 0;\n r = -1;\n auto nq = queries.length;\n auto n = reduce!max(queries.map!(t => t.v));\n auto s = bsr (n);\n auto x = queries.map!(q => hilbert (q.u, q.v, s, 0)).array;\n auto idx = uninitializedArray!(size_t[]) (nq);\n makeIndex (x, idx);\n auto res = uninitializedArray!(R[]) (nq);\n foreach (j; idx) {\n if (queries[j].u > queries[j].v) res[j] = 0;\n else res[j] = move (queries[j]);\n }\n return res;\n }\n this (in uint[] a, int n) {\n x = a.idup;\n //CUSTOM\n ba.length = n;\n }\n}\n\nalias ST = SegmentTree!(uint[], mrg, []);\n\nvoid test (in int n, uint[] a) {\n debug stderr.writeln (\"a = \", a);\n auto v = new int[n];\n foreach (i; 0 .. n) {\n v[i] = i;\n }\n auto prev = uninitializedArray!(int[]) (n);\n\n MoQuery[] q;\n \n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n q ~= MoQuery (prev[j] + 1, i.to!int - 1);\n }\n prev[j] = pos;\n }\n foreach (i; 0 .. n) {\n q ~= MoQuery (prev[i] + 1, a.length.to!int - 1);\n }\n\n auto solve = new MoRange (a, n);\n auto res = solve.processQueries (q); \n\n int cur;\n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n auto k = res[cur++]; \n v[j] = max (v[j], k);\n }\n prev[j] = pos;\n }\n foreach (i; 0 .. n) {\n auto k = res[cur++];\n v[i] = max (v[i], k);\n }\n \n foreach (i; 0 .. n) {\n int j = v[i];\n int u = i;\n if (prev[i] >= n) {\n u = 0;\n }\n writeln (u + 1, ' ', j + 1);\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable n = r.next!uint;\n immutable m = r.next!uint;\n auto a = r.nextA!uint (m);\n foreach (i; 0 .. m) --a[i];\n auto b = new uint[n];\n foreach (i; 0 .. n) b[i] = n - 1 - i;\n b ~= a;\n a = b;\n b = null;\n //a.length -= uniq (a).copy (a).length;\n test (n, a);\n}\n\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.bitmanip;\nimport core.bitop;\n\nfinal class SegmentTree(T = int, alias op=\"a+b\", T zero) {\n private:\n T [] t;\n size_t n;\n void build () {\n foreach_reverse (i; 1 .. n) {\n immutable k = i << 1;\n t[i] = binaryFun!op (t[k], t[k+1]);\n }\n }\n public:\n void update (size_t p, T v) {\n for (t[p += n] = v; p > 1; p >>= 1) {\n t[p>>1] = binaryFun!op (t[p], t[p ^ 1]);\n }\n }\n T reduce (size_t l, size_t r) {\n T res = zero;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n if (l & 1) {\n res = binaryFun!op (res, t[l++]);\n }\n if (r & 1) {\n res = binaryFun!op (t[--r], res);\n }\n }\n return res;\n }\n this (T[] a) {\n n = a.length;\n t = uninitializedArray!(T[])(n);\n t ~= a;\n build ();\n }\n}\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nuint[] mrg (uint[] a, uint[] b) {\n return merge (a, b).uniq.array;\n}\n\nstruct MoQuery {\n int u;\n int v;\n}\n\nalias R = int;\nfinal class MoRange {\n private:\n immutable uint[] x;\n int l, r;\n //CUSTOM\n BitArray ba;\n int sz;\n\n static long hilbert (int x, int y, int k, int a) {\n static immutable d = [3, 0, 0, 1];\n if (k < 0) return 0L;\n int m = 1 << k, o = 3 & (((x >> k) ^ 3 * (y >> k)) + a);\n long ss = 1L << (2 * k), b = hilbert (x & ~m, y & ~m, k - 1, a + d[o]);\n return ss * o + (o == 1 || o == 2 ? b : (ss - (b + 1)));\n }\n\n void clear () {\n //CUSTOM\n ba[] = false;\n sz = 0;\n }\n \n R move (ref in MoQuery q) {\n if (l > r || l > q.v || r < q.u) {\n l = q.u;\n r = l - 1;\n clear ();\n }\n if (r < q.v) {\n add (r + 1, q.v + 1);\n r = q.v;\n } else if (r > q.v) {\n del (q.v + 1, r + 1);\n r = q.v;\n }\n if (l > q.u) {\n add (q.u, l);\n l = q.u;\n } else if (l < q.u) {\n del (l, q.u);\n l = q.u;\n }\n //CUSTOM\n return sz; \n }\n void add (const int a, const int b) {\n debug stderr.writefln (\"add (%d, %d)\", a, b);\n foreach (k; x[a .. b]) {\n if (!ba[k]) {\n ba[k] = true;\n ++sz;\n }\n }\n }\n void del (const int a, const int b) {\n foreach (k; x[a .. b]) {\n //assert (freq[k] > 0, format!\"freq[%d] = %d\" (k, freq[k]));\n if (ba[k]) {\n ba[k] = false;\n --sz;\n }\n }\n }\n int[] processQueries (in MoQuery[] queries) {\n l = 0;\n r = -1;\n auto nq = queries.length;\n auto n = reduce!max(queries.map!(t => t.v));\n auto s = bsr (n);\n auto x = queries.map!(q => hilbert (q.u, q.v, s, 0)).array;\n auto idx = uninitializedArray!(size_t[]) (nq);\n makeIndex (x, idx);\n auto res = uninitializedArray!(R[]) (nq);\n foreach (j; idx) {\n if (queries[j].u > queries[j].v) res[j] = 0;\n else res[j] = move (queries[j]);\n }\n return res;\n }\n this (in uint[] a, int n) {\n x = a.idup;\n //CUSTOM\n ba.length = n;\n }\n}\n\nalias ST = SegmentTree!(uint[], mrg, []);\n\nvoid test (in int n, uint[] a) {\n debug stderr.writeln (\"a = \", a);\n auto v = new int[n];\n foreach (i; 0 .. n) {\n v[i] = i;\n }\n auto prev = uninitializedArray!(int[]) (n);\n\n MoQuery[] q;\n \n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n q ~= MoQuery (prev[j] + 1, i.to!int - 1);\n }\n prev[j] = pos;\n }\n foreach (i; 0 .. n) {\n q ~= MoQuery (prev[i] + 1, a.length.to!int - 1);\n }\n\n auto solve = new MoRange (a, n);\n auto res = solve.processQueries (q); \n\n int cur;\n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n auto k = res[cur++]; \n v[j] = max (v[j], k);\n }\n prev[j] = pos;\n }\n foreach (i; 0 .. n) {\n auto k = res[cur++];\n v[i] = max (v[i], k);\n }\n \n foreach (i; 0 .. n) {\n int j = v[i];\n int u = i;\n if (prev[i] >= n) {\n u = 0;\n }\n writeln (u + 1, ' ', j + 1);\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable n = r.next!uint;\n immutable m = r.next!uint;\n auto a = r.nextA!uint (m);\n foreach (i; 0 .. m) --a[i];\n auto b = new uint[n];\n foreach (i; 0 .. n) b[i] = n - 1 - i;\n b ~= a;\n a = b;\n b = null;\n a.length -= uniq (a).copy (a).length;\n test (n, a);\n}\n\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.bitmanip;\nimport core.bitop;\n\nfinal class SegmentTree(T = int, alias op=\"a+b\", T zero) {\n private:\n T [] t;\n size_t n;\n void build () {\n foreach_reverse (i; 1 .. n) {\n immutable k = i << 1;\n t[i] = binaryFun!op (t[k], t[k+1]);\n }\n }\n public:\n void update (size_t p, T v) {\n for (t[p += n] = v; p > 1; p >>= 1) {\n t[p>>1] = binaryFun!op (t[p], t[p ^ 1]);\n }\n }\n T reduce (size_t l, size_t r) {\n T res = zero;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n if (l & 1) {\n res = binaryFun!op (res, t[l++]);\n }\n if (r & 1) {\n res = binaryFun!op (t[--r], res);\n }\n }\n return res;\n }\n this (T[] a) {\n n = a.length;\n t = uninitializedArray!(T[])(n);\n t ~= a;\n build ();\n }\n}\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nuint[] mrg (uint[] a, uint[] b) {\n return merge (a, b).uniq.array;\n}\n\nstruct MoQuery {\n int u;\n int v;\n}\n\nalias R = int;\nfinal class MoRange {\n private:\n immutable uint[] x;\n int l, r;\n //CUSTOM\n BitArray ba;\n int sz;\n\n static long hilbert (int x, int y, int k, int a) {\n static immutable d = [3, 0, 0, 1];\n if (k < 0) return 0L;\n int m = 1 << k, o = 3 & (((x >> k) ^ 3 * (y >> k)) + a);\n long ss = 1L << (2 * k), b = hilbert (x & ~m, y & ~m, k - 1, a + d[o]);\n return ss * o + (o == 1 || o == 2 ? b : (ss - (b + 1)));\n }\n\n void clear () {\n //CUSTOM\n ba[] = false;\n sz = 0;\n }\n \n R move (ref in MoQuery q) {\n if (l > r || l > q.v || r < q.u) {\n l = q.u;\n r = l - 1;\n clear ();\n }\n if (r < q.v) {\n add (r + 1, q.v + 1);\n r = q.v;\n } else if (r > q.v) {\n del (q.v + 1, r + 1);\n r = q.v;\n }\n if (l > q.u) {\n add (q.u, l);\n l = q.u;\n } else if (l < q.u) {\n del (l, q.u);\n l = q.u;\n }\n //CUSTOM\n return sz; \n }\n void add (const int a, const int b) {\n debug stderr.writefln (\"add (%d, %d)\", a, b);\n foreach (k; x[a .. b]) {\n if (!ba[k]) {\n ba[k] = true;\n ++sz;\n }\n }\n }\n void del (const int a, const int b) {\n foreach (k; x[a .. b]) {\n //assert (freq[k] > 0, format!\"freq[%d] = %d\" (k, freq[k]));\n if (ba[k]) {\n ba[k] = false;\n --sz;\n }\n }\n }\n int[] processQueries (in MoQuery[] queries) {\n l = 0;\n r = -1;\n auto nq = queries.length;\n auto n = reduce!max(queries.map!(t => t.v));\n auto s = bsr (n);\n auto x = queries.map!(q => hilbert (q.u, q.v, s, 0)).array;\n auto idx = uninitializedArray!(size_t[]) (nq);\n makeIndex (x, idx);\n auto res = uninitializedArray!(R[]) (nq);\n foreach (j; idx) {\n res[j] = move (queries[j]);\n }\n return res;\n }\n this (in uint[] a, int n) {\n x = a.idup;\n //CUSTOM\n ba.length = n;\n }\n}\n\nalias ST = SegmentTree!(uint[], mrg, []);\n\nvoid test (in int n, uint[] a) {\n debug stderr.writeln (\"a = \", a);\n auto v = new int[n];\n foreach (i; 0 .. n) {\n v[i] = i;\n }\n auto prev = uninitializedArray!(int[]) (n);\n\n MoQuery[] q;\n \n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n q ~= MoQuery (prev[j] + 1, i.to!int - 1);\n }\n prev[j] = pos;\n }\n foreach (i; 0 .. n) {\n q ~= MoQuery (prev[i] + 1, a.length.to!int - 1);\n }\n\n auto solve = new MoRange (a, n);\n auto res = solve.processQueries (q); \n\n int cur;\n prev[] = -1;\n foreach (i, j; a) {\n immutable int pos = i.to!int; \n if (prev[j] >= 0) {\n auto k = res[cur++]; \n v[j] = max (v[j], k);\n }\n prev[j] = pos;\n }\n foreach (i; 0 .. n) {\n auto k = res[cur++];\n v[i] = max (v[i], k);\n }\n \n foreach (i; 0 .. n) {\n int j = v[i];\n int u = i;\n if (prev[i] >= n) {\n u = 0;\n }\n writeln (u + 1, ' ', j + 1);\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable n = r.next!uint;\n immutable m = r.next!uint;\n auto a = r.nextA!uint (m);\n foreach (i; 0 .. m) --a[i];\n auto b = new uint[n];\n foreach (i; 0 .. n) b[i] = n - 1 - i;\n b ~= a;\n a = b;\n b = null;\n a.length -= uniq (a).copy (a).length;\n test (n, a);\n}\n\n"}], "src_uid": "f57ed2d5009724b006202349675e2f2c"} {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\n\nvoid main(){\n int n=readln.chomp\n .to!int;\n int a,b;\n string s;\n bool r=false;\n while(n--){\n readf!\"%s %d %d\"(s,a,b);\n readln;\n if(a>=2400 && b>a){\n r=true;\n break;\n }\n }\n writeln(r?\"YES\":\"NO\");\n}\n", "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n bool done = false;\n while (n--) {\n string name = cin.read_string;\n int prev_rating = cin.read_int;\n int new_rating = cin.read_int;\n if (prev_rating >= 2400 && new_rating > prev_rating) done = true;\n }\n if (done) writeln(\"YES\");\n else writeln(\"NO\");\n } \n}"}, {"source_code": "#!/usr/bin/env rdmd\n\nimport std.stdio;\n\nvoid main() {\n int n;\n char buffer[10];\n while (readf(\"%d \", &n) == 1) {\n bool ok = false;\n while (n--) {\n auto s = buffer[ ];\n int before, after;\n readf(\"%s %d %d \", &s, &before, &after);\n if (after > before && before >= 2400)\n ok = true;\n }\n writeln(ok ? \"YES\" : \"NO\");\n }\n}\n"}], "negative_code": [], "src_uid": "3bff9b69423cf6c8425e347a4beef96b"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto noTc = next!int;\n tcLoop: foreach(tc; 0 .. noTc)\n {\n auto n = next!int;\n auto a = next!int(n);\n auto leftCnt = new int[](n + 1);\n long caseRes = 0;\n foreach(ai; a) leftCnt[ai]++;\n foreach(k; 0 .. n)\n\t{\n\t leftCnt[a[k]]--;\n\t long crossingPairs = 0;\n\t foreach_reverse(i; 0 .. k)\n\t {\n\t if (a[i] == a[k])\n\t\tcaseRes += crossingPairs;\n\t crossingPairs += leftCnt[a[i]];\n\t }\n\t}\n caseRes.println;\n }\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tforeach (test; 0..readln.strip.to !(int))\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto num = new int [] [] (n, n + 1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tnum[i][j + 1] = num[i][j] + (a[i] == a[j]);\n\t\t\t}\n\t\t}\n\t\tlong res = 0;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tforeach (j; i + 1..n - 1)\n\t\t\t{\n\t\t\t\tres += num[j][i] *\n\t\t\t\t (num[i][n] - num[i][j + 1]);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "eef9527a79ecf15a71d7ae4dcbb831e3"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = readln.strip.map !(q{a == '+'}).array;\r\n\r\n\t\tint res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tint balance = 0;\r\n\t\t\tint pairs = 0;\r\n\t\t\tint add = 0;\r\n\t\t\tforeach (j; i..n)\r\n\t\t\t{\r\n\t\t\t\tif (s[j])\r\n\t\t\t\t{\r\n\t\t\t\t\tbalance += 1;\r\n\t\t\t\t\tadd = 0;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tbalance -= 1;\r\n\t\t\t\t\tadd += 1;\r\n\t\t\t\t\tif (add == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tadd = 0;\r\n\t\t\t\t\t\tpairs += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (balance <= 0 && balance + pairs * 3 >= 0 &&\r\n\t\t\t\t balance % 3 == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tres += 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto S = readln.chomp;\r\n auto plus = new int[][](N, N+1);\r\n auto minus = new int[][](N, N+1);\r\n for (int l = 0; l < N; l++) {\r\n for (int r = l; r < N; r++) {\r\n plus[l][r + 1] = plus[l][r] + (S[r] == '+');\r\n minus[l][r + 1] = minus[l][r] + (S[r] == '-');\r\n }\r\n }\r\n auto cm = new int[][](N, N+1);\r\n for (int l = 0; l < N; l++) {\r\n for (int r = l; r + 1 < N; r++) {\r\n cm[l][r + 2] = max(cm[l][r + 1], cm[l][r] + (S[r] == '-' && S[r + 1] == '-'));\r\n }\r\n }\r\n int ans = 0;\r\n for (int l = 0; l < N; l++) {\r\n for (int r = l + 1; r <= N; r++) {\r\n int d = minus[l][r] - plus[l][r];\r\n if (d < 0) continue;\r\n if (d % 3 == 0) ans++;\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [], "src_uid": "802e4d90444b371a1dbab10d3d589e55"} {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint m = read.to!int;\n\tlong ta = read.to!long;\n\tlong tb = read.to!long;\n\tint k = read.to!int;\n\t\n\tlong[] as = readln.chomp.split.map!(to!long).array;\n\tlong[] bs = readln.chomp.split.map!(to!long).array;\n\tprint!1(\"as:\", as);\n\tprint!1(\"bs:\", bs);\n\t\n\tint j;\n\tlong ans = 0;\n\tforeach(i; 0 .. k + 1){ // cancels (i) planes. = plane of index i goes.\n\t\tprint!1(\"i:\", i);\n\t\tif(i >= n){\n\t\t\tans = -1;\n\t\t\tbreak;\n\t\t}\n\t\twhile(bs[j] < as[i] + ta){\n\t\t\tj += 1;\n\t\t\tif(j >= m){\n\t\t\t\tans = -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tint j2 = j + (k - i); // possible plane\n\t\tprint!1(\"j:\", j, \" j2: \", j2);\n\t\tif(j2 >= m){\n\t\t\tans = -1;\n\t\t\tbreak;\n\t\t}\n\t\tans = max(ans, bs[j2] + tb);\n\t\tprint!1(\"ans: max(ans, \", bs[j2]+ tb, \") = \", ans);\n\t}\n\t\n\tans.writeln;\n\t\n\t\n\t\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 10^^9 + 7;\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1] + 1;\n auto K = s[4];\n auto Ta = s[2];\n auto Tb = s[3];\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array ~ INF;\n\n if (N <= K || M - 1 <= K) {\n writeln(-1);\n return;\n }\n\n auto opt = new int[](N);\n long ans = 0;\n\n for (int i = 0, j = 0; j < M; ++j) {\n while (i < N && A[i] + Ta <= B[j]) opt[i++] = j;\n }\n\n foreach (i; 0..N) {\n if (i > K) break;\n int j = opt[i] + K - i;\n if (j > M) {\n ans = INF;\n break;\n }\n ans = max(ans, B[j] + Tb);\n }\n\n writeln((ans >= INF ? -1 : ans));\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, m, k;\n\tlong ta, tb;\n\twhile (readf !(\" %s %s %s %s %s\") (n, m, ta, tb, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tauto b = readln.splitter.map !(to !(long)).array;\n\t\tsort (a);\n\t\tsort (b);\n\t\ta ~= b.back + 1;\n\t\tn += 1;\n\t\tlong res = long.min;\n\t\tint j = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i > k)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\twhile (j < m && a[i] + ta > b[j])\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\tint p = j + (k - i);\n\t\t\tif (p >= m)\n\t\t\t{\n\t\t\t\tres = long.max;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres = max (res, b[p] + tb);\n\t\t\t}\n\t\t}\n\t\tif (res == long.max)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n immutable m = r.next!int;\n immutable ta = r.next!long;\n immutable tb = r.next!long;\n immutable k = r.next!int;\n auto a = r.nextA!long(n).map!(t => t + ta).array;\n auto b = r.nextA!long(m);\n auto e = b.assumeSorted;\n long test () {\n if (a.length <= k || b.length <= k) {\n return -1L;\n }\n long res = long.min;\n foreach (i; 0 .. k + 1) {\n int d = k - i;\n auto r = e.upperBound (a[i] - 1);\n if (r.length <= d) {\n return -1;\n }\n res = max (res, r.drop(d).front);\n }\n return res + tb;\n }\n writeln (test ());\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 10^^9 + 7;\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1] + 1;\n auto K = s[4];\n auto Ta = s[2];\n auto Tb = s[3];\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array ~ INF;\n\n auto opt = new int[](N);\n long ans = 0;\n\n for (int i = 0, j = 0; j < M; ++j) {\n while (i < N && A[i] + Ta <= B[j]) opt[i++] = j;\n }\n\n foreach (i; 0..N) {\n if (i > K) break;\n int j = opt[i] + K - i;\n if (j >= M - 1) {\n ans = INF;\n break;\n }\n ans = max(ans, B[j] + Tb);\n }\n\n writeln((ans >= INF ? -1 : ans));\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, m, k;\n\tlong ta, tb;\n\twhile (readf !(\" %s %s %s %s %s\") (n, m, ta, tb, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tauto b = readln.splitter.map !(to !(long)).array;\n\t\tlong res = long.min;\n\t\tint j = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i > k)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\twhile (j < m && a[i] + ta > b[j])\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\tint p = j + (k - i);\n\t\t\tif (p >= m)\n\t\t\t{\n\t\t\t\tres = long.max;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres = max (res, b[p] + tb);\n\t\t\t}\n\t\t}\n\t\tif (res == long.max)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n immutable m = r.next!int;\n immutable ta = r.next!long;\n immutable tb = r.next!long;\n immutable k = r.next!int;\n auto a = r.nextA!long(n).map!(t => t + ta).array;\n auto b = r.nextA!long(m);\n auto e = b.assumeSorted;\n long test () {\n if (a.length < k || b.length < k) {\n return -1L;\n }\n long res = long.min;\n foreach (i; 0 .. k + 1) {\n int d = k - i;\n long t = a[i];\n auto r = e.upperBound (t - 1);\n if (r.length <= d) {\n return -1;\n }\n res = max (res, r.drop(d).front);\n }\n return res + tb;\n }\n writeln (test ());\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint m = read.to!int;\n\tlong ta = read.to!long;\n\tlong tb = read.to!long;\n\tint k = read.to!int;\n\t\n\tlong[] as = readln.chomp.split.map!(to!long).array;\n\tlong[] bs = readln.chomp.split.map!(to!long).array;\n\tprint!1(\"as:\", as);\n\tprint!1(\"bs:\", bs);\n\t\n\tint j;\n\tlong ans = 0;\n\tforeach(i; 0 .. k + 1){ // cancels (i) planes. = plane of index i goes.\n\t\tprint!1(\"i:\", i);\n\t\twhile(bs[j] < as[i] + ta){\n\t\t\tj += 1;\n\t\t\tif(j >= m){\n\t\t\t\tans = -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tint j2 = j + (k - i); // possible plane\n\t\tprint!1(\"j:\", j, \" j2: \", j2);\n\t\tif(j2 >= m){\n\t\t\tans = -1;\n\t\t\tbreak;\n\t\t}\n\t\tans = max(ans, bs[j2] + tb);\n\t\tprint!1(\"ans: max(ans, \", bs[j2]+ tb, \") = \", ans);\n\t}\n\t\n\tans.writeln;\n\t\n\t\n\t\n}\n\n"}], "src_uid": "bf60899aa2bd7350c805437d0fee1583"} {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\t\n\tS[] ps;\n\tforeach(i; 0 .. n) ps ~= S(i, read.to!int, read.to!int);\n\t\n\tS[] xs, ys;\n\tforeach(p; ps) if(p.a < p.b) xs ~= p; else ys ~= p;\n\t\n\tif(xs.length > ys.length){\n\t\txs.sort!\"a.a>b.a\"();\n\t\txs.length.writeln;\n\t\txs.map!(x => (x.id + 1).to!string).array.join(\" \").writeln;\n\t}\n\telse{\n\t\tys.sort!\"a.a<b.a\"();\n\t\tys.length.writeln;\n\t\tys.map!(y => (y.id + 1).to!string).array.join(\" \").writeln;\n\t}\n\t\n}\n\nstruct S{\n\tint id;\n\tint a, b;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Pair = Tuple !(int, q{a}, int, q{b}, int, q{c});\n\nint [] solve (Pair [] p)\n{\n\tauto q = p.filter !(x => x.a < x.b).array;\n\tsort (q);\n\treverse (q);\n\treturn q.map !(x => x.c).array;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto p = new Pair [n];\n\t\tforeach (i, ref x; p)\n\t\t{\n\t\t\treadf (\" %s %s\", &x.a, &x.b);\n\t\t\tx.c = i.to !(int) + 1;\n\t\t}\n\t\tauto ans = solve (p);\n\t\tforeach (ref x; p)\n\t\t{\n\t\t\tx = Pair (-x.a, -x.b, x.c);\n\t\t}\n\t\tauto alt = solve (p);\n\t\tif (ans.length < alt.length)\n\t\t{\n\t\t\tans = alt;\n\t\t}\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\n//alias T = Tuple!(int, int, int);\nalias T = Tuple!(int, int);\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n T[] t1, t2;\n foreach (i; 1 .. n + 1) {\n int u = r.next!int;\n int v = r.next!int;\n //auto t = tuple (r.next!int, r.next!int);\n if (u < v) {\n //t1 ~= tuple (u, v, i);\n t1 ~= tuple (v, i);\n } else {\n //t2 ~= tuple (u, v, i);\n t2 ~= tuple (u, i);\n }\n }\n if (t1.length >= t2.length) {\n t1.sort ();\n writeln (t1.length);\n bool f = true;\n foreach_reverse (u; t1) {\n if (f) f = false; else write (' ');\n write (u[1]);\n }\n writeln;\n } else {\n writeln (t2.length);\n t2.sort ();\n bool f = true;\n foreach (u; t2) {\n if (f) f = false; else write (' ');\n write (u[1]);\n }\n writeln;\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Pair = Tuple !(int, q{a}, int, q{b}, int, q{c});\n\nint [] solve (Pair [] p)\n{\n\tauto q = p.filter !(x => x.a < x.b).array;\n\tsort (q);\n\treverse (q);\n\treturn q.map !(x => x.c).array;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto p = new Pair [n];\n\t\tforeach (i, ref x; p)\n\t\t{\n\t\t\treadf (\" %s %s\", &x.a, &x.b);\n\t\t\tx.c = i.to !(int) + 1;\n\t\t}\n\t\tauto ans = solve (p);\n\t\tforeach (ref x; p)\n\t\t{\n\t\t\tx = Pair (-x.a, -x.b, x.c);\n\t\t}\n\t\tauto alt = solve (p);\n\t\tif (ans.length < alt.length)\n\t\t{\n\t\t\tans = alt;\n\t\t}\n\t\twriteln (alt.length);\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "src_uid": "6b720be3d26719ce649158e8903527e3"} {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003, MAX_L = 1048576;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\nchar [MAX_L] bufin, bufout;\n\nint main ()\n{\n\tint k, m, n;\n\tsetvbuf (stdin, &bufin[0], _IOFBF, MAX_L);\n\tsetvbuf (stdout, &bufout[0], _IOFBF, MAX_L);\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %c %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int H, W, Q; scanf(\"%d %d %d\\n\", &H, &W, &Q);\n auto F = new int[][H];\n foreach (h; 0 .. H) {\n F[h] = readln.chomp.split(\" \").map!(to!int).array;\n }\n\n auto R = iota(0, H, 1).array;\n auto C = iota(0, W, 1).array;\n foreach (q; 0 .. Q) {\n auto ss = readln.chomp.split(\" \");\n auto type = ss[0];\n int x = ss[1].to!int, y = ss[2].to!int;\n x--; y--;\n\n if (type == \"r\") {\n swap(R[x], R[y]);\n } else if (type == \"c\") {\n swap(C[x], C[y]);\n } else {\n assert(type == \"g\");\n writeln(F[ R[x] ][ C[y] ]);\n }\n //writeln(type, [x, y]);\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_L = 16384;\nchar [MAX_L] bufin, bufout;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %c %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] a;\n\t\ta = new int [n * m];\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i * m + j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritefln (\"%d\", a[p[x] * m + q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003, MAX_L = 65536;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\nchar [MAX_L] bufin, bufout;\n\nint main ()\n{\n\tint k, m, n;\n\tsetvbuf (stdin, &bufin[0], _IOFBF, MAX_L);\n\tsetvbuf (stdout, &bufout[0], _IOFBF, MAX_L);\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %c %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, p2, q, q2;\n\t\tp = new int [n];\n\t\tp2 = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t\tp2[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tq2 = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t\tq2[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p2[p[x]], p2[p[y]]);\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q2[q[x]], q2[q[y]]);\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritefln (\"%d\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] a;\n\t\ta = new int [n * m];\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i * m + j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritef (\"%d\\n\", a[p[x] * m + q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %c %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %c %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003, MAX_L = 16384;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\nchar [MAX_L] bufin, bufout;\n\nint main ()\n{\n\tint k, m, n;\n\tsetvbuf (stdin, &bufin[0], _IOFBF, MAX_L);\n\tsetvbuf (stdout, &bufout[0], _IOFBF, MAX_L);\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %c %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] a;\n\t\ta = new int [n * m];\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i * m + j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x] * m + q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\n\nint cur_char;\nbool eof = false;\n\nvoid skip_blanks ()\n{\n\tdo\n\t{\n\t\tcur_char = getchar ();\n\t}\n\twhile (0 <= cur_char && cur_char <= 32);\n\tif (cur_char == EOF)\n\t{\n\t\teof = true;\n\t}\n}\n\nchar read_char ()\n{\n\tskip_blanks ();\n\treturn cast (char) cur_char;\n}\n\nint read_int ()\n{\n\tskip_blanks ();\n\tint res = 0;\n\tdo\n\t{\n\t\tres = res * 10 + cast (int) (cur_char - '0');\n\t\tcur_char = getchar ();\n\t}\n\twhile (32 < cur_char);\n\treturn res;\n}\n\nint main ()\n{\n\tint k, m, n;\n\twhile (true)\n\t{\n\t n = read_int ();\n\t m = read_int ();\n\t k = read_int ();\n\t if (eof)\n\t {\n\t \tbreak;\n\t }\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\ta[i][j] = read_int ();\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tch = read_char ();\n\t\t\tx = read_int ();\n\t\t\ty = read_int ();\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritefln (\"%d\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\n\nint cur_char;\nbool eof = false;\n\nvoid skip_blanks ()\n{\n\tdo\n\t{\n\t\tcur_char = getchar ();\n\t}\n\twhile (0 <= cur_char && cur_char <= 32);\n\tif (cur_char == EOF)\n\t{\n\t\teof = true;\n\t}\n}\n\nchar read_char ()\n{\n\tskip_blanks ();\n\treturn cast (char) cur_char;\n}\n\nint read_int ()\n{\n\tskip_blanks ();\n\tint res = 0;\n\tdo\n\t{\n\t\tres = res * 10 + cur_char - '0';\n\t\tcur_char = getchar ();\n\t}\n\twhile (32 < cur_char);\n\treturn res;\n}\n\nvoid write_int (int v)\n{\n char buf [32];\n int k;\n\twhile (v > 0)\n\t{\n\t\tint w = v / 10;\n\t\tint r = v - w * 10;\n\t\tbuf[k] = cast (char) (r + '0');\n\t\tk++;\n\t\tv /= 10;\n\t}\n\tfor (k--; k >= 0; k--)\n\t{\n\t\tputchar (buf[k]);\n\t}\t\n}\n\nint main ()\n{\n\tint k, m, n;\n\twhile (true)\n\t{\n\t n = read_int ();\n\t m = read_int ();\n\t k = read_int ();\n\t if (eof)\n\t {\n\t \tbreak;\n\t }\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\ta[i][j] = read_int ();\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tch = read_char ();\n\t\t\tx = read_int ();\n\t\t\ty = read_int ();\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twrite_int (a[p[x]][q[y]]);\n\t\t\t\t\tputchar ('\\n');\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritefln (\"%d\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nconst int MAX_L = 16384;\n\nint main ()\n{\n\tint k, m, n;\n\tstdin.setvbuf (MAX_L, _IOFBF);\n\tstdout.setvbuf (MAX_L, _IOFBF);\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nconst int MAX_N = 1003;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritef (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_L = 16384;\nchar [MAX_L] bufin, bufout;\n\nint main ()\n{\n\tint k, m, n;\n\tsetvbuf (stdin, &bufin[0], _IOFBF, MAX_L);\n\tsetvbuf (stdout, &bufout[0], _IOFBF, MAX_L);\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %c %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003, MAX_L = 65536;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\nchar [MAX_L] buf;\n\nint main ()\n{\n\tint k, m, n;\n\tsetvbuf (stdin, &buf[0], _IOFBF, MAX_L);\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %c %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\tprintf (\"%d\\n\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nconst int MAX_N = 1003;\n\nint [MAX_N * MAX_N] a;\nint [MAX_N] p, q;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i * m + j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritef (\"%d\\n\", a[p[x] * m + q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\n\nconst int MAX_N = 1003;\n\nint [MAX_N] [MAX_N] a;\nint [MAX_N] p, q;\n\nint cur_char;\nbool eof = false;\n\nvoid skip_blanks ()\n{\n\tdo\n\t{\n\t\tcur_char = getchar ();\n\t}\n\twhile (0 <= cur_char && cur_char <= 32);\n\tif (cur_char == EOF)\n\t{\n\t\teof = true;\n\t}\n}\n\nchar read_char ()\n{\n\tskip_blanks ();\n\treturn cast (char) cur_char;\n}\n\nint read_int ()\n{\n\tskip_blanks ();\n\tint res = 0;\n\tdo\n\t{\n\t\tres = res * 10 + cur_char - '0';\n\t\tcur_char = getchar ();\n\t}\n\twhile (32 < cur_char);\n\treturn res;\n}\n\nvoid write_int (int v)\n{\n char buf [32];\n int k;\n\twhile (v > 0)\n\t{\n\t\tbuf[k] = cast (char) (v % 10 + '0');\n\t\tk++;\n\t\tv /= 10;\n\t}\n\tfor (k--; k >= 0; k--)\n\t{\n\t\tputchar (buf[k]);\n\t}\t\n}\n\nint main ()\n{\n\tint k, m, n;\n\twhile (true)\n\t{\n\t n = read_int ();\n\t m = read_int ();\n\t k = read_int ();\n\t if (eof)\n\t {\n\t \tbreak;\n\t }\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\ta[i][j] = read_int ();\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tch = read_char ();\n\t\t\tx = read_int ();\n\t\t\ty = read_int ();\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twrite_int (a[p[x]][q[y]]);\n\t\t\t\t\tputchar ('\\n');\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nconst int MAX_L = 16384;\n\nint main ()\n{\n\tint k, m, n;\n\tstdin.setvbuf (MAX_L, _IOFBF);\n\tstdout.setvbuf (MAX_L, _IOFBF);\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, q;\n\t\tp = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t}\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritefln (\"%d\", a[p[x]][q[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.c.string;\n\nvoid main() {\n\n\n InputReader ir = new InputReader();\n int n = ir.nextInt();\n int m = ir.nextInt();\n int k = ir.nextInt();\n int[][] table = new int[][](n, m);\n foreach (int i; 0 .. n)\n foreach (int j; 0 .. m)\n table[i][j] = ir.nextInt();\n char[] s = new char[k];\n int[] x = new int[k];\n int[] y = new int[k];\n foreach (int i; 0 .. k) {\n s[i] = ir.next()[0];\n //if (i>3)write(s[i], \" \");\n x[i] = ir.nextInt() - 1;\n //if (i>3)write(x[i] + 1, \" \");\n y[i] = ir.nextInt() - 1;\n //if (i>3)write(y[i] + 1, \" \");\n //if (i>3)writeln();\n }\n int[int] ii;\n int[int] jj;\n foreach (int i; 0 .. n)\n ii[i] = i;\n foreach (int j; 0 .. m)\n jj[j] = j;\n foreach (int i; 0 .. k) {\n if (s[i] == 'g') {\n std.c.stdio.printf(\"%d\\n\", table[ii[x[i]]][jj[y[i]]]);\n }\n else if (s[i] == 'c')\n swap(jj[y[i]], jj[x[i]]);\n else\n swap(ii[y[i]], ii[x[i]]);\n }\n}\n\nclass InputReader {\n\n char INP;\n int AM;\n\n this() {\n }\n \n void GETCHAR() {\n INP = to!char(std.c.stdio.getchar());\n }\n\n bool DIG(char a) {\n return (a >= '0') && (a <= '9');\n }\n\n bool LETTER(char a) {\n return DIG(a) || ((a >= 'a') && (a <= 'z')) || ((a >= 'A') && (a <= 'Z'));\n }\n \n int nextInt() {\n int x = 0, c;\n for (; cast(uint)((c = getchar()) - '0') >= 10; ) { \n if (c == '-') return -nextInt(); \n if (!~c) {} \n }\n do { \n x = (x << 3) + (x << 1) + (c - '0'); \n } while (cast(uint)((c = getchar()) - '0') < 10);\n return x;\n }\n\n char[] next() {\n GETCHAR();\n while (INP - 0 == 255)\n GETCHAR();\n char[] ans = [INP];\n GETCHAR();\n while (LETTER(INP)) {\n ans ~= INP;\n GETCHAR();\n }\n return ans;\n }\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.outbuffer;\nimport std.conv;\n\nint main() {\n InputReader ir = new InputReader();\n OutBuffer ob = new OutBuffer();\n int n = ir.nextInt();\n int m = ir.nextInt();\n int k = ir.nextInt();\n int[][] table = new int[][](n, m);\n \n foreach (int i; 0 .. n)\n foreach (int j; 0 .. m)\n table[i][j] = ir.nextInt();\n char[] s = new char[k];\n int[] x = new int[k];\n int[] y = new int[k];\n foreach (int i; 0 .. k) {\n s[i] = ir.next()[0];\n x[i] = ir.nextInt() - 1;\n y[i] = ir.nextInt() - 1;\n }\n int[int] ii;\n int[int] jj;\n foreach (int i; 0 .. n)\n ii[i] = i;\n foreach (int j; 0 .. m)\n jj[j] = j;\n foreach (int i; 0 .. k) {\n if (s[i] == 'g') {\n ob.write(to!string(table[ii[x[i]]][jj[y[i]]])~\"\\n\");\n }\n else if (s[i] == 'c')\n swap(jj[y[i]], jj[x[i]]);\n else\n swap(ii[y[i]], ii[x[i]]);\n }\n write(ob);\n return 0;\n}\n\nclass InputReader {\n\n import std.stdio, std.conv, std.string;\n \n private std.stdio.File input;\n private bool lastOne;\n private uint bufSize;\n private char[] buf; \n private uint remainStart;\n private uint idx = 0;\n private char d;\n\n public this(std.stdio.File input = stdin, uint bufSize = 100000000, char separator = ' ') {\n this.input = input;\n this.bufSize = bufSize;\n this.d = separator;\n this.lastOne = false;\n this.buf = new char[bufSize];\n this.input.rawRead(this.buf);\n this.idx = 0;\n this.buf = reduce(this.buf);\n this.remainStart = lastIndexOf(this.buf, '\\n');\n }\n\n private int first255(char[] ar) {\n int ans = -1;\n char term = to!char(255);\n for (int j = 0; j < ar.length; ++j)\n if (ar[j] == term)\n return j;\n return ans;\n }\n\n private char[] reduce(char[] ar) {\n auto termIndex = first255(ar);\n if (termIndex == 0) {\n this.lastOne = true;\n return null;\n }\n else if (termIndex == -1)\n return ar;\n else {\n this.lastOne = true;\n return ar[0 .. termIndex];\n }\n }\n\n private void refillBuf() {\n char[] newBuf = new char[bufSize];\n input.rawRead(newBuf); \n if (remainStart == -1 || remainStart == bufSize - 1)\n buf ~= reduce(newBuf);\n else\n buf = buf[(remainStart + 1) .. buf.length] ~ reduce(newBuf);\n remainStart = lastIndexOf(buf, \"\\n\");\n idx = 0;\n }\n\n public char[] next() {\n if ((idx >= remainStart) & !lastOne) \n refillBuf();\n while (idx < buf.length && (buf[idx] == d || buf[idx] == '\\n'))\n ++idx;\n if ((idx >= remainStart) & !lastOne)\n refillBuf(); \n uint cnt = idx;\n while (cnt < buf.length && buf[cnt] != d && buf[cnt] != '\\n')\n ++cnt; \n char[] ans = buf[idx .. cnt];\n idx = cnt;\n return ans;\n }\n\n public int nextInt() {\n return std.conv.to!int(strip(next()));\n }\n\n public long nextLong() {\n return std.conv.to!long(strip(next()));\n }\n\n public double nextDouble() {\n return std.conv.to!double(strip(next()));\n }\n\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.c.string;\nimport std.array;\n\nint curc;\nbool eof = false;\n\nvoid sb()\n{\n do\n {\n curc = getchar ();\n }\n while (0 <= curc && curc <= 32);\n if (curc == EOF)\n {\n eof = true;\n }\n}\n\nchar rc ()\n{\n sb ();\n return cast (char) curc;\n}\n\nint ni ()\n{\n return to!int(ns());\n}\n\nlong nl ()\n{\n return to!long(ns());\n}\n\ndouble nd()\n{\n return to!double(ns());\n}\n\nchar[] nlongs ()\n{\n sb ();\n auto res = appender!(char[])();\n do\n {\n res.put(to!char(curc));\n curc = getchar ();\n }\n while (32 < curc);\n return res.data;\n}\n\nchar[] ns ()\n{\n sb ();\n char[] res = [];\n do\n {\n res ~= to!char(curc);\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nchar nc()\n{\n curc = getchar();\n return to!char(curc);\n}\n\nvoid main() {\n int n = ni(), m = ni(), k = ni();\n int[][] table = new int[][](n, m);\n foreach (int i; 0 .. n)\n foreach (int j; 0 .. m)\n table[i][j] = ni();\n char[] s = new char[k];\n int[] x = new int[k];\n int[] y = new int[k];\n foreach (int i; 0 .. k) {\n s[i] = nc();\n x[i] = ni() - 1;\n y[i] = ni() - 1;\n }\n int[int] ii;\n int[int] jj;\n foreach (int i; 0 .. n)\n ii[i] = i;\n foreach (int j; 0 .. m)\n jj[j] = j;\n foreach (int i; 0 .. k) {\n if (s[i] == 'g') {\n printf(\"%d\\n\", table[ii[x[i]]][jj[y[i]]]);\n }\n else if (s[i] == 'c')\n swap(jj[y[i]], jj[x[i]]);\n else\n swap(ii[y[i]], ii[x[i]]);\n }\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.c.string;\nimport std.array;\n\nint curc;\nbool eof = false;\n\nvoid sb()\n{\n do\n {\n curc = getchar ();\n }\n while (0 <= curc && curc <= 32);\n if (curc == EOF)\n {\n eof = true;\n }\n}\n\nchar nc ()\n{\n sb ();\n return cast (char) curc;\n}\n\nint ni ()\n{\n sb ();\n int res = 0;\n int base = 10;\n bool pos = true;\n if (cast (char) curc == '-')\n {\n pos = false;\n curc = getchar();\n }\n if (pos)\n {\n do\n {\n res = res * base + cast (int) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n else\n {\n do\n {\n res = res * base - cast (int) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n \n return res;\n}\n\nvoid main() {\n int n = ni(), m = ni(), k = ni();\n int[][] table = new int[][](n, m);\n foreach (int i; 0 .. n)\n foreach (int j; 0 .. m)\n table[i][j] = ni();\n char[] s = new char[k];\n int[] x = new int[k];\n int[] y = new int[k];\n foreach (int i; 0 .. k) {\n s[i] = nc();\n x[i] = ni() - 1;\n y[i] = ni() - 1;\n }\n int[int] ii;\n int[int] jj;\n foreach (int i; 0 .. n)\n ii[i] = i;\n foreach (int j; 0 .. m)\n jj[j] = j;\n foreach (int i; 0 .. k) {\n if (s[i] == 'g') {\n printf(\"%d\\n\", table[ii[x[i]]][jj[y[i]]]);\n }\n else if (s[i] == 'c')\n swap(jj[y[i]], jj[x[i]]);\n else\n swap(ii[y[i]], ii[x[i]]);\n }\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.c.string;\nimport std.array;\n\nint curc;\nbool eof = false;\n\nvoid sb()\n{\n do\n {\n curc = getchar ();\n }\n while (0 <= curc && curc <= 32);\n if (curc == EOF)\n {\n eof = true;\n }\n}\n\nchar rc ()\n{\n sb ();\n return cast (char) curc;\n}\n\nint ni ()\n{\n return to!int(ns());\n}\n\nlong nl ()\n{\n return to!long(ns());\n}\n\ndouble nd()\n{\n return to!double(ns());\n}\n\nchar[] ns ()\n{\n sb ();\n auto res = appender!(char[])();\n do\n {\n res.put(to!char(curc));\n curc = getchar ();\n }\n while (32 < curc);\n return res.data;\n}\n\nchar nc()\n{\n curc = getchar();\n return to!char(curc);\n}\n\nvoid main() {\n int n = ni(), m = ni(), k = ni();\n int[][] table = new int[][](n, m);\n foreach (int i; 0 .. n)\n foreach (int j; 0 .. m)\n table[i][j] = ni();\n char[] s = new char[k];\n int[] x = new int[k];\n int[] y = new int[k];\n foreach (int i; 0 .. k) {\n s[i] = nc();\n x[i] = ni() - 1;\n y[i] = ni() - 1;\n }\n int[int] ii;\n int[int] jj;\n foreach (int i; 0 .. n)\n ii[i] = i;\n foreach (int j; 0 .. m)\n jj[j] = j;\n foreach (int i; 0 .. k) {\n if (s[i] == 'g') {\n printf(\"%d\\n\", table[ii[x[i]]][jj[y[i]]]);\n }\n else if (s[i] == 'c')\n swap(jj[y[i]], jj[x[i]]);\n else\n swap(ii[y[i]], ii[x[i]]);\n }\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\n\nint main ()\n{\n\tint k, m, n;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tint [] [] a;\n\t\ta = new int [] [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = new int [m];\n\t\t}\n\t\tint [] p, p2, q, q2;\n\t\tp = new int [n];\n\t\tp2 = new int [n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tp[i] = i;\n\t\t\tp2[i] = i;\n\t\t}\n\t\tq = new int [m];\n\t\tq2 = new int [m];\n\t\tfor (int j = 0; j < m; j++)\n\t\t{\n\t\t\tq[j] = j;\n\t\t\tq2[j] = j;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int l = 0; l < k; l++)\n\t\t{\n\t\t\tint x, y;\n\t\t\tchar ch;\n\t\t\tscanf (\" %s %d %d\", &ch, &x, &y);\n\t\t\tx--;\n\t\t\ty--;\n\t\t\tswitch (ch)\n\t\t\t{\n\t\t\t\tcase 'r':\n\t\t\t\t\tswap (p2[p[x]], p2[p[y]]);\n\t\t\t\t\tswap (p[x], p[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'c':\n\t\t\t\t\tswap (q2[q[x]], q2[q[y]]);\n\t\t\t\t\tswap (q[x], q[y]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'g':\n\t\t\t\t\twritefln (\"%d\", a[p2[x]][q2[y]]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.outbuffer;\nimport std.conv;\n\nint main() {\n InputReader ir = new InputReader();\n OutBuffer ob = new OutBuffer();\n int n = ir.nextInt();\n int m = ir.nextInt();\n int k = ir.nextInt();\n int[][] table = new int[][](n, m);\n \n foreach (int i; 0 .. n)\n foreach (int j; 0 .. m)\n table[i][j] = ir.nextInt();\n char[] s = new char[k];\n int[] x = new int[k];\n int[] y = new int[k];\n foreach (int i; 0 .. k) {\n s[i] = ir.next()[0];\n x[i] = ir.nextInt() - 1;\n y[i] = ir.nextInt() - 1;\n }\n int[int] ii;\n int[int] jj;\n foreach (int i; 0 .. n)\n ii[i] = i;\n foreach (int j; 0 .. m)\n jj[j] = j;\n foreach (int i; 0 .. k) {\n if (s[i] == 'g') {\n ob.write(to!string(table[ii[x[i]]][jj[y[i]]])~\"\\n\");\n }\n else if (s[i] == 'c')\n swap(jj[y[i]], jj[x[i]]);\n else\n swap(ii[y[i]], ii[x[i]]);\n }\n write(ob);\n return 0;\n}\n\nclass InputReader {\n\n import std.stdio, std.conv, std.string;\n \n private std.stdio.File input;\n private bool lastOne;\n private uint bufSize;\n private char[] buf; \n private uint remainStart;\n private uint idx = 0;\n private char d;\n\n public this(std.stdio.File input = stdin, uint bufSize = 1000000, char separator = ' ') {\n this.input = input;\n this.bufSize = bufSize;\n this.d = separator;\n this.lastOne = false;\n this.buf = new char[bufSize];\n this.input.rawRead(this.buf);\n this.idx = 0;\n this.buf = reduce(this.buf);\n this.remainStart = lastIndexOf(this.buf, '\\n');\n }\n\n private int first255(char[] ar) {\n int ans = -1;\n char term = to!char(255);\n for (int j = 0; j < ar.length; ++j)\n if (ar[j] == term)\n return j;\n return ans;\n }\n\n private char[] reduce(char[] ar) {\n auto termIndex = first255(ar);\n if (termIndex == 0) {\n this.lastOne = true;\n return null;\n }\n else if (termIndex == -1)\n return ar;\n else {\n this.lastOne = true;\n return ar[0 .. termIndex];\n }\n }\n\n private void refillBuf() {\n char[] newBuf = new char[bufSize];\n input.rawRead(newBuf); \n if (remainStart == -1 || remainStart == bufSize - 1)\n buf ~= reduce(newBuf);\n else\n buf = buf[(remainStart + 1) .. buf.length] ~ reduce(newBuf);\n remainStart = lastIndexOf(buf, \"\\n\");\n idx = 0;\n }\n\n public char[] next() {\n if ((idx >= remainStart) & !lastOne) \n refillBuf();\n while (idx < buf.length && (buf[idx] == d || buf[idx] == '\\n'))\n ++idx;\n if ((idx >= remainStart) & !lastOne)\n refillBuf(); \n uint cnt = idx;\n while (cnt < buf.length && buf[cnt] != d && buf[cnt] != '\\n')\n ++cnt; \n char[] ans = buf[idx .. cnt];\n idx = cnt;\n return ans;\n }\n\n public int nextInt() {\n return std.conv.to!int(strip(next()));\n }\n\n public long nextLong() {\n return std.conv.to!long(strip(next()));\n }\n\n public double nextDouble() {\n return std.conv.to!double(strip(next()));\n }\n\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\n\nint main() {\n InputReader ir = new InputReader();\n OutputWriter ow = new OutputWriter();\n int n = ir.nextInt();\n int m = ir.nextInt();\n int k = ir.nextInt();\n int[][] table = new int[][](n, m);\n \n foreach (int i; 0 .. n)\n foreach (int j; 0 .. m)\n table[i][j] = ir.nextInt();\n ow.println(table);\n char[] s = new char[k];\n int[] x = new int[k];\n int[] y = new int[k];\n foreach (int i; 0 .. k) {\n s[i] = ir.next()[0];\n x[i] = ir.nextInt() - 1;\n y[i] = ir.nextInt() - 1;\n }\n int[int] ii;\n int[int] jj;\n foreach (int i; 0 .. n)\n ii[i] = i;\n foreach (int j; 0 .. m)\n jj[j] = j;\n foreach (int i; 0 .. k) {\n if (s[i] == 'g') ow.println(table[ii[x[i]]][jj[y[i]]]);\n else if (s[i] == 'c')\n swap(jj[y[i]], jj[x[i]]);\n else\n swap(ii[y[i]], ii[x[i]]);\n }\n return 0;\n}\n\nclass StringTokenizer {\n \n private string rawData;\n private string[] tokens;\n private int counter;\n\n this(string rawData, string delimeter = \" \") {\n this.rawData = rawData;\n this.tokens = split(rawData, delimeter);\n }\n\n bool hasMoreTokens() {\n return this.counter < tokens.length;\n }\n\n string getRawData() {\n return this.rawData;\n }\n\n string next() {\n ++counter;\n return tokens[counter - 1];\n }\n}\n\nclass InputReader {\n private File input;\n private StringTokenizer st;\n\n this(string filename = null) {\n if (filename !is null)\n this.input = File(filename, \"r\");\n else\n this.input = stdin;\n }\n\n string next() {\n while ((st is null) || (!st.hasMoreTokens())) {\n string newLine;\n input.readln(newLine);\n if (newLine)\n st = new StringTokenizer(strip(newLine));\n else\n return null;\n }\n return st.next();\n }\n\n int nextInt() {\n return std.conv.to!int(next());\n }\n\n long nextLong() {\n return std.conv.to!long(next());\n }\n\n double nextDouble() {\n return std.conv.to!double(next()); \n }\n}\n\nclass OutputWriter {\n private File output;\n\n this(string filename = null) {\n if (filename !is null)\n this.output = File(filename, \"w\");\n else\n this.output = stdout;\n }\n\n void print(T...)(T args) { //bydlocode, Ky! razrabam -_-\n bool notfirst = false;\n foreach (el; args) {\n if (notfirst) output.write(\" \");\n output.write(el);\n notfirst = true;\n }\n }\n\n void println(T...)(T args) { //bydlocode, Ky! razrabam -_-\n foreach (el; args)\n output.writeln(el); \n }\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.outbuffer;\nimport std.conv;\n\nint main() {\n InputReader ir = new InputReader();\n OutBuffer ob = new OutBuffer();\n int n = ir.nextInt();\n int m = ir.nextInt();\n int k = ir.nextInt();\n int[][] table = new int[][](n, m);\n \n foreach (int i; 0 .. n)\n foreach (int j; 0 .. m)\n table[i][j] = ir.nextInt();\n char[] s = new char[k];\n int[] x = new int[k];\n int[] y = new int[k];\n foreach (int i; 0 .. k) {\n s[i] = ir.next()[0];\n x[i] = ir.nextInt() - 1;\n y[i] = ir.nextInt() - 1;\n }\n int[int] ii;\n int[int] jj;\n foreach (int i; 0 .. n)\n ii[i] = i;\n foreach (int j; 0 .. m)\n jj[j] = j;\n foreach (int i; 0 .. k) {\n if (s[i] == 'g') {\n ob.write(to!string(table[ii[x[i]]][jj[y[i]]])~\"\\n\");\n }\n else if (s[i] == 'c')\n swap(jj[y[i]], jj[x[i]]);\n else\n swap(ii[y[i]], ii[x[i]]);\n }\n write(ob);\n return 0;\n}\n\nclass InputReader {\n\n import std.stdio, std.conv, std.string;\n \n private std.stdio.File input;\n private bool lastOne;\n private uint bufSize;\n private char[] buf; \n private uint remainStart;\n private uint idx = 0;\n private char d;\n\n public this(std.stdio.File input = stdin, uint bufSize = 110000, char separator = ' ') {\n this.input = input;\n this.bufSize = bufSize;\n this.d = separator;\n this.lastOne = false;\n this.buf = new char[bufSize];\n this.input.rawRead(this.buf);\n this.idx = 0;\n this.buf = reduce(this.buf);\n this.remainStart = lastIndexOf(this.buf, '\\n');\n }\n\n private int first255(char[] ar) {\n int ans = -1;\n char term = to!char(255);\n for (int j = 0; j < ar.length; ++j)\n if (ar[j] == term)\n return j;\n return ans;\n }\n\n private char[] reduce(char[] ar) {\n auto termIndex = first255(ar);\n if (termIndex == 0) {\n this.lastOne = true;\n return null;\n }\n else if (termIndex == -1)\n return ar;\n else {\n this.lastOne = true;\n return ar[0 .. termIndex];\n }\n }\n\n private void refillBuf() {\n char[] newBuf = new char[bufSize];\n input.rawRead(newBuf); \n if (remainStart == -1 || remainStart == bufSize - 1)\n buf ~= reduce(newBuf);\n else\n buf = buf[(remainStart + 1) .. buf.length] ~ reduce(newBuf);\n remainStart = lastIndexOf(buf, \"\\n\");\n idx = 0;\n }\n\n public char[] next() {\n if ((idx >= remainStart) & !lastOne) \n refillBuf();\n while (idx < buf.length && (buf[idx] == d || buf[idx] == '\\n'))\n ++idx;\n if ((idx >= remainStart) & !lastOne)\n refillBuf(); \n uint cnt = idx;\n while (cnt < buf.length && buf[cnt] != d && buf[cnt] != '\\n')\n ++cnt; \n char[] ans = buf[idx .. cnt];\n idx = cnt;\n return ans;\n }\n\n public int nextInt() {\n return std.conv.to!int(strip(next()));\n }\n\n public long nextLong() {\n return std.conv.to!long(strip(next()));\n }\n\n public double nextDouble() {\n return std.conv.to!double(strip(next()));\n }\n\n}"}], "src_uid": "290d9779a6be44ce6a2e62989aee0dbd"} {"source_code": "//64-bit Integers required\nmodule _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n string s = cin.readString;\n auto loc = s.indexOf('^');\n long l = 0, r = 0;\n for (int i = 0; i < s.length; i++) {\n if (s[i] >= '1' && s[i] <= '9') {\n if (i < loc) l += (s[i] - '0') * (loc - i);\n else r += (s[i] - '0') * (i - loc);\n }\n }\n if (l == r) writeln(\"balance\");\n else if (l > r) writeln(\"left\");\n else writeln(\"right\");\n } \n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n auto lever = readln().chomp();\n auto pivot_pos = lever.indexOf(\"^\");\n\n ulong left_torque;\n for (auto pos_i = pivot_pos-1; pos_i >= 0; pos_i--) {\n if (lever[pos_i] != '=') {\n auto weight = to!int(lever[pos_i]) - to!int('0');\n left_torque += (pivot_pos - pos_i) * weight;\n }\n }\n ulong right_torque;\n for (auto pos_i = pivot_pos+1; pos_i < lever.length; pos_i++) {\n if (lever[pos_i] != '=') {\n const weight = to!int(lever[pos_i]) - to!int('0');\n right_torque += (pos_i - pivot_pos) * weight;\n }\n }\n if (left_torque > right_torque) {\n writeln(\"left\");\n } else if (left_torque < right_torque) {\n writeln(\"right\");\n } else {\n writeln(\"balance\");\n }\n}\n\n"}], "negative_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n string s = cin.readString;\n auto loc = s.indexOf('^');\n int l = 0, r = 0;\n for (int i = 0; i < s.length; i++) {\n if (s[i] >= '1' && s[i] <= '9') {\n if (i < loc) l += (s[i] - '0') * (loc - i);\n else r += (s[i] - '0') * (i - loc);\n }\n }\n if (l == r) writeln(\"balance\");\n else if (l > r) writeln(\"left\");\n else writeln(\"right\");\n } \n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.math;\nimport std.conv;\n\nvoid main() {\n auto lever = readln().chomp();\n auto pivot_pos = lever.indexOf(\"^\");\n\n int left_torque;\n for (auto pos_i = pivot_pos-1; pos_i >= 0; pos_i--) {\n if (lever[pos_i] != '=') {\n auto weight = to!int(lever[pos_i]) - to!int('0');\n left_torque += (pivot_pos - pos_i) * weight;\n }\n }\n int right_torque;\n for (auto pos_i = pivot_pos+1; pos_i < lever.length; pos_i++) {\n if (lever[pos_i] != '=') {\n const weight = to!int(lever[pos_i]) - to!int('0');\n right_torque += (pos_i - pivot_pos) * weight;\n }\n }\n if (left_torque > right_torque) {\n writeln(\"left\");\n } else if (left_torque < right_torque) {\n writeln(\"right\");\n } else {\n writeln(\"balance\");\n }\n}\n\n"}], "src_uid": "19f2c21b18e84f50e251b1dfd557d32f"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!long;\n if (n % 2 == 1) {\n writeln((n + 1) / 2);\n } else {\n writeln(n / 2);\n }\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n long n = read!long;\r\n writeln(cast(int)ceil(n / 2.));\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [], "src_uid": "0c5cf0af057b0c838f13b491b923447a"} {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n\treadln;\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\twriteln ((min (n, m) == 1 || max (n, m) <= 2) ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n if (N > M) swap(N, M);\n writeln(N == 1 || (N == 2 && M == 2) ? \"YES\" : \"NO\");\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tif (n == 1 || m == 1)\n\t\t\tans[ti] = true;\n\t\telse if (n == 2 && m == 2)\n\t\t\tans[ti] = true;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "55595ff38a08b80bc86cf1ebae6f55af"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto t = new int [n];\n\t\tt[] = -1;\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tauto m = new int [q + 1];\n\n\t\tforeach (curTime; 0..q)\n\t\t{\n\t\t\tint type;\n\t\t\treadf !(\" %s\") (type);\n\t\t\tif (type == 1)\n\t\t\t{\n\t\t\t\tint p, x;\n\t\t\t\treadf !(\" %s %s\") (p, x);\n\t\t\t\tp -= 1;\n\t\t\t\ta[p] = x;\n\t\t\t\tt[p] = curTime;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint x;\n\t\t\t\treadf !(\" %s\") (x);\n\t\t\t\tm[curTime] = x;\n\t\t\t}\n\t\t}\n\n\t\tforeach_reverse (curTime; 0..q)\n\t\t{\n\t\t\tm[curTime] = max (m[curTime], m[curTime + 1]);\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] = max (a[i], m[t[i] + 1]);\n\t\t}\n\n\t\twritefln !(\"%(%s %)\") (a);\n\t}\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dunkelheit\" version=\"1.0.1\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner, dkh.datastructure.segtree;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n;\n sc.read(n);\n int[] a;\n sc.read(a);\n\n auto seg = LazySeg!(int, int,\n \"a+b\",\n (a, b) => max(a, b),\n (a, b) => max(a, b),\n -1,\n -1)(a);\n\n int q;\n sc.read(q);\n\n foreach (i; 0..q) {\n int ty;\n sc.read(ty);\n if (ty == 1) {\n int p, x;\n sc.read(p, x); p--;\n seg[p] = x;\n } else {\n int x;\n sc.read(x);\n seg[0..n] += x;\n }\n }\n\n iota(n).map!(i => seg[i]).map!(to!string).join(\" \").writeln;\n return 0;\n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/datastructure/segtree.d */\n// module dkh.datastructure.segtree;\n\nimport std.conv : to;\nimport std.functional : binaryFun;\nimport std.traits : isInstanceOf;\n\nstruct SegTree(alias E, Args...) {\n import std.traits : ReturnType;\n alias Engine = E!Args;\n alias T = Engine.DataType;\n alias L = Engine.LazyType;\n\n Engine eng;\n\n this(size_t n) { eng = Engine(n.to!uint); }\n this(T[] first) { eng = Engine(first); }\n\n @property size_t length() const { return eng.length(); }\n @property size_t opDollar() const { return eng.length(); }\n \n struct Range {\n Engine* eng;\n size_t start, end;\n @property const(T) sum() {\n return eng.sum(start.to!uint, end.to!uint);\n }\n }\n const(T) opIndex(size_t k) {\n assert(0 <= k && k < eng.length());\n return eng.single(k.to!uint);\n }\n void opIndexAssign(T x, size_t k) {\n assert(0 <= k && k < eng.length());\n eng.singleSet(k.to!uint, x);\n }\n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) {\n assert(0 <= start && start <= end && end <= eng.length());\n return [start, end];\n }\n Range opIndex(size_t[2] rng) {\n return Range(&eng, rng[0].to!uint, rng[1].to!uint);\n }\n static if (!is(L == void)) {\n void opIndexOpAssign(string op : \"+\")(L x, size_t[2] rng) {\n eng.add(rng[0].to!uint, rng[1].to!uint, x);\n }\n }\n}\n\nptrdiff_t binSearchLeft(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b) \nif (isInstanceOf!(SegTree, TR)) {\n return TR.Engine.BinSearch!(false, pred)(t.eng, a.to!int, b.to!int);\n}\n\nptrdiff_t binSearchRight(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b) \nif (isInstanceOf!(SegTree, TR)) {\n return TR.Engine.BinSearch!(true, pred)(t.eng, a.to!int, b.to!int);\n}\n\n \nalias SimpleSeg(T, alias opTT, T eT, alias Engine = SimpleSegEngine) =\n SegTree!(Engine, T, binaryFun!opTT, eT);\n\n \n \n\nstruct SimpleSegEngine(T, alias opTT, T eT) {\n alias DataType = T;\n alias LazyType = void;\n alias BinSearch = binSearchSimple;\n uint n, sz, lg;\n T[] d;\n @property uint length() const {return n;}\n this(uint n) {\n import std.algorithm : each;\n this.n = n;\n if (n == 0) return;\n while ((2^^lg) < n) lg++;\n sz = 2^^lg;\n d = new T[](2*sz);\n d.each!((ref x) => x = eT);\n }\n this(T[] first) {\n import std.conv : to;\n import std.algorithm : each;\n n = first.length.to!uint;\n if (n == 0) return;\n while ((2^^lg) < n) lg++;\n sz = 2^^lg;\n d = new T[](2*sz);\n d.each!((ref x) => x = eT);\n foreach (i; 0..n) {\n d[sz+i] = first[i];\n }\n foreach_reverse (i; 1..sz) {\n update(i);\n }\n }\n pragma(inline):\n void update(uint k) {\n d[k] = opTT(d[2*k], d[2*k+1]);\n }\n T single(uint k) {\n return d[k+sz];\n }\n void singleSet(uint k, T x) {\n k += sz;\n d[k] = x;\n foreach (uint i; 1..lg+1) {\n update(k>>i);\n }\n }\n T sum(uint a, uint b) {\n assert(0 <= a && a <= b && b <= n);\n T sml = eT, smr = eT;\n a += sz; b += sz;\n while (a < b) {\n if (a & 1) sml = opTT(sml, d[a++]);\n if (b & 1) smr = opTT(d[--b], smr);\n a >>= 1; b >>= 1;\n }\n return opTT(sml, smr);\n }\n}\n\nint binSearchSimple(bool rev, alias pred, TR)(TR t, int a, int b) {\n import std.traits : TemplateArgsOf;\n alias args = TemplateArgsOf!TR;\n alias opTT = args[1];\n auto x = args[2];\n with (t) {\n static if (!rev) {\n \n if (pred(x)) return a-1;\n int pos = a;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, d[k]))) {\n x = opTT(x, d[k]);\n pos = r;\n return;\n }\n if (l+1 == r) return;\n int md = (l+r)/2;\n f(a, b, l, md, 2*k);\n if (pos >= md) f(a, b, md, r, 2*k+1);\n }\n f(a, b, 0, sz, 1);\n return pos; \n } else {\n \n if (pred(x)) return b;\n int pos = b-1;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, d[k]))) {\n x = opTT(d[k], x);\n pos = l-1;\n return;\n }\n if (l+1 == r) return;\n int md = (l+r)/2;\n f(a, b, md, r, 2*k+1);\n if (pos < md) f(a, b, l, md, 2*k);\n }\n f(a, b, 0, sz, 1);\n return pos; \n }\n }\n}\n\n \nalias LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL, alias Engine = LazySegEngine) =\n SegTree!(Engine, T, L , binaryFun!opTT, binaryFun!opTL, binaryFun!opLL, eT, eL);\n\n \n \n\n\nstruct LazySegEngine(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {\n import std.typecons : Tuple;\n alias DataType = T;\n alias LazyType = L;\n alias BinSearch = binSearchLazy;\n alias S = Tuple!(T, \"d\", L, \"lz\");\n uint n, sz, lg;\n S[] s;\n this(uint n) {\n import std.conv : to;\n import std.algorithm : each;\n this.n = n;\n uint lg = 0;\n while ((2^^lg) < n) lg++;\n this.lg = lg;\n sz = 2^^lg;\n s = new S[](2*sz);\n s.each!((ref x) => x = S(eT, eL));\n }\n this(T[] first) {\n import std.conv : to;\n import std.algorithm : each;\n n = first.length.to!uint;\n uint lg = 0;\n while ((2^^lg) < n) lg++;\n this.lg = lg;\n sz = 2^^lg;\n\n s = new S[](2*sz);\n s.each!((ref x) => x = S(eT, eL));\n foreach (i; 0..n) {\n s[sz+i].d = first[i];\n }\n foreach_reverse (i; 1..sz) {\n update(i);\n }\n }\n @property uint length() const { return n; }\n pragma(inline):\n private void lzAdd(uint k, in L x) {\n s[k].lz = opLL(s[k].lz, x);\n s[k].d = opTL(s[k].d, x);\n }\n public void push(uint k) {\n if (s[k].lz == eL) return;\n lzAdd(2*k, s[k].lz);\n lzAdd(2*k+1, s[k].lz);\n s[k].lz = eL;\n }\n private void update(uint k) {\n s[k].d = opTT(s[2*k].d, s[2*k+1].d);\n }\n T single(uint k) {\n k += sz;\n foreach_reverse (uint i; 1..lg+1) {\n push(k>>i);\n }\n return s[k].d;\n }\n void singleSet(uint k, T x) {\n k += sz;\n foreach_reverse (uint i; 1..lg+1) {\n push(k>>i);\n }\n s[k].d = x;\n foreach (uint i; 1..lg+1) {\n update(k>>i);\n }\n }\n T sum(uint a, uint b) {\n assert(0 <= a && a <= b && b <= n);\n if (a == b) return eT;\n a += sz; b--; b += sz;\n uint tlg = lg;\n while (true) {\n uint k = a >> tlg;\n if (a >> tlg != b >> tlg) {\n tlg++;\n break;\n }\n if (((a-1) >> tlg) + 2 == (b+1) >> tlg) return s[k].d;\n push(k);\n tlg--;\n }\n T sm = eT;\n foreach_reverse (l; 0..tlg) {\n uint k = a >> l;\n if ((a-1)>>l != a>>l) {\n sm = opTT(s[k].d, sm);\n break;\n }\n push(k);\n if (!((a >> (l-1)) & 1)) sm = opTT(s[2*k+1].d, sm);\n }\n foreach_reverse (l; 0..tlg) {\n uint k = b >> l;\n if (b>>l != (b+1)>>l) {\n sm = opTT(sm, s[k].d);\n break;\n }\n push(k);\n if ((b >> (l-1)) & 1) sm = opTT(sm, s[2*k].d);\n }\n return sm;\n }\n void add(uint a, uint b, L x) {\n assert(0 <= a && a <= b && b <= n);\n if (a == b) return;\n a += sz; b--; b += sz;\n uint tlg = lg;\n while (true) {\n uint k = a >> tlg;\n if (a >> tlg != b >> tlg) {\n tlg++;\n break;\n }\n if (((a-1) >> tlg) + 2 == (b+1) >> tlg) {\n lzAdd(k, x);\n foreach (l; tlg+1..lg+1) {\n update(a >> l);\n }\n return;\n }\n push(k);\n tlg--;\n }\n foreach_reverse (l; 0..tlg) {\n uint k = a >> l;\n if ((a-1)>>l != a>>l) {\n lzAdd(k, x);\n foreach (h; l+1..tlg) {\n update(a >> h);\n }\n break;\n }\n push(k);\n if (!((a >> (l-1)) & 1)) lzAdd(2*k+1, x);\n }\n foreach_reverse (l; 0..tlg) {\n uint k = b >> l;\n if (b>>l != (b+1)>>l) {\n lzAdd(k, x);\n foreach (h; l+1..tlg) {\n update(b >> h);\n }\n break;\n }\n push(k);\n if ((b >> (l-1)) & 1) lzAdd(2*k, x);\n }\n foreach (l; tlg..lg+1) {\n update(a >> l);\n }\n }\n}\n\n \n\nint binSearchLazy(bool rev, alias pred, TR)(TR t, int a, int b) {\n import std.traits : TemplateArgsOf;\n alias args = TemplateArgsOf!TR;\n alias opTT = args[2];\n auto x = args[5];\n with (t) {\n static if (!rev) {\n \n if (pred(x)) return a-1;\n int pos = a;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {\n x = opTT(x, s[k].d);\n pos = r;\n return;\n }\n if (l+1 == r) return;\n push(k);\n int md = (l+r)/2;\n f(a, b, l, md, 2*k);\n if (pos >= md) f(a, b, md, r, 2*k+1);\n }\n f(a, b, 0, sz, 1);\n return pos;\n } else {\n \n if (pred(x)) return b;\n int pos = b-1;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {\n x = opTT(s[k].d, x);\n pos = l-1;\n return;\n }\n if (l+1 == r) return;\n push(k);\n int md = (l+r)/2;\n f(a, b, md, r, 2*k+1);\n if (pos < md) f(a, b, l, md, 2*k);\n }\n f(a, b, 0, sz, 1);\n return pos; \n }\n }\n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n private File f;\n \n this(File f) {\n this.f = f;\n }\n private char[512] lineBuf;\n private char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n assert(succW());\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n \n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n \n void read(Args...)(auto ref Args args) {\n import std.exception : enforce;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n \n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] A;\nint Q;\nint[] T, P, X;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n Q = readInt();\n T = new int[Q];\n P = new int[Q];\n X = new int[Q];\n foreach (q; 0 .. Q) {\n T[q] = readInt();\n if (T[q] == 1) {\n P[q] = readInt() - 1;\n }\n X[q] = readInt();\n }\n \n auto ans = new int[N];\n ans[] = -1;\n int maxPay;\n foreach_reverse (q; 0 .. Q) {\n switch (T[q]) {\n case 1: {\n if (ans[P[q]] == -1) {\n ans[P[q]] = max(X[q], maxPay);\n }\n } break;\n case 2: {\n chmax(maxPay, X[q]);\n } break;\n default: assert(false);\n }\n }\n foreach (i; 0 .. N) {\n if (ans[i] == -1) {\n ans[i] = max(A[i], maxPay);\n }\n }\n \n foreach (i; 0 .. N) {\n if (i > 0) {\n write(\" \");\n }\n write(ans[i]);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int MAX = 200005;\nint n, q;\nint[MAX] a;\nint[MAX] p;\nint[MAX] last_spent, maxPayout, payout;\nint type, id, x;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n readf(\" %s\", q);\n foreach(i; 0..q) {\n readf(\" %s\", type);\n if (type == 1) {\n readf(\" %s %s\", id, x);\n id--;\n a[id] = x;\n last_spent[id] = i;\n } else {\n readf(\" %s\", payout[i]);\n }\n }\n foreach_reverse(i; 0..q) maxPayout[i] = max(maxPayout[i+1], payout[i]);\n foreach(i; 0..n) {\n int result = max(a[i], maxPayout[last_spent[i]]);\n write(result, \" \");\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int MAX = 200005;\nint n, q;\nint[MAX] a, p;\nint[MAX] lastSpent, maxPayout, payout;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n readf(\" %s\", q);\n foreach(i; 0..q) {\n int type;\n readf(\" %s\", type);\n if (type == 1) {\n int j, x;\n readf(\" %s %s\", j, x);\n j--;\n a[j] = x;\n lastSpent[j] = i;\n } else {\n readf(\" %s\", payout[i]);\n }\n }\n\n foreach_reverse(i; 0..q) maxPayout[i] = max(maxPayout[i+1], payout[i]);\n foreach(i; 0..n) {\n int result = max(a[i], maxPayout[lastSpent[i]]);\n write(result, \" \");\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int MAX = 200005;\nint n, q;\nint[MAX] a;\nint[MAX] p;\nint[MAX] last_spent, maxPayout, payout;\nint type, id, x;\n\nvoid main() {\n readf(\" %s\", n);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n readf(\" %s\", q);\n foreach(i; 0..q) {\n readf(\" %s\", type);\n if (type == 1) {\n readf(\" %s %s\", id, x);\n id--;\n a[id] = x;\n last_spent[id] = i;\n } else {\n readf(\" %s\", payout[i]);\n }\n }\n foreach_reverse(i; 0..n) maxPayout[i] = max(maxPayout[i+1], payout[i]);\n foreach(i; 0..n) {\n int result = max(a[i], maxPayout[last_spent[i]]);\n write(result, \" \");\n }\n}\n"}], "src_uid": "7b788c660fb8ca703af0030f4c84ce96"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto b = new bool [n];\n\n\t\tint res = 0;\n\t\tint best = 0;\n\t\tforeach (block; 1..n)\n\t\t{\n\t\t\tint cur = n - n / (block + 1) - !!(n % (block + 1));\n\t\t\tcur -= block;\n\t\t\tif (res < cur)\n\t\t\t{\n\t\t\t\tres = cur;\n\t\t\t\tbest = block + 1;\n\t\t\t}\n\t\t}\n\n\t\tvoid go (R) (R r)\n\t\t{\n\t\t\tauto len = r.walkLength.to !(int);\n\t\t\twritefln (\"%s%( %s%)\", len, r.map !(q{a + 1}));\n\t\t\tforeach (ref c; r)\n\t\t\t{\n\t\t\t\tb[c] = true;\n\t\t\t}\n\t\t\tstdout.flush ();\n\t\t\tint k;\n\t\t\treadf !(\" %s\") (k);\n\t\t\tif (k == -1)\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tk -= 1;\n\t\t\tforeach (i; 0..len)\n\t\t\t{\n\t\t\t\tb[k] = false;\n\t\t\t\tk = (k + 1) % n;\n\t\t\t}\n\t\t}\n\n\t\twhile (b.sum < res)\n\t\t{\n\t\t\tauto p = iota (n - 1)\n\t\t\t .filter !(i => i % best != best - 1)\n\t\t\t .filter !(i => !b[i]).array;\n\t\t\tgo (p);\n\t\t}\n\n\t\twriteln (0);\n\t\tstdout.flush ();\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n /*\n debug {\n foreach (n; 1 .. 16 + 1) {\n auto dp = new int[1 << n];\n auto prev = new int[1 << n];\n foreach (p; 0 .. 1 << n) {\n dp[p] = popcnt(p);\n prev[p] = -1;\n }\n int iter;\n for (; ; ++iter) {\n bool upd;\n foreach_reverse (p; 0 .. 1 << n) {\n const sup = ((1 << n) - 1) ^ p;\n for (int q = sup; q; --q &= sup) {\n const k = popcnt(q);\n int mn = n + 1;\n foreach (i; 0 .. n) {\n int r = p | q;\n foreach (j; 0 .. k) {\n r &= ~(1 << ((i + j) % n));\n }\n chmin(mn, dp[r]);\n }\n if (chmax(dp[p], mn)) {\n upd = true;\n prev[p] = q;\n }\n }\n }\n if (!upd) {\n break;\n }\n }\n write(n, \": \", iter, \" \", dp[0], \" \");\n foreach (i; 0 .. n) {\n write((prev[0] >> i) & 1);\n }\n writeln;\n for (int p = 0; ; ) {\n foreach (i; 0 .. n) {\n write((p >> i) & 1);\n }\n writeln;\n if (prev[p] == -1) {\n break;\n }\n foreach (i; 0 .. n) {\n write(((p | prev[p]) >> i) & 1);\n }\n writeln;\n const k = popcnt(prev[p]);\n int mn = n + 1;\n int rm = -1;\n foreach (i; 0 .. n) {\n int r = p | prev[p];\n foreach (j; 0 .. k) {\n r &= ~(1 << ((i + j) % n));\n }\n assert(dp[p] <= dp[r]);\n if (dp[p] == dp[r]) {\n if (chmin(mn, popcnt(r))) {\n rm = r;\n }\n }\n }\n assert(rm != -1);\n p = rm;\n }\n stdout.flush;\n }\n }\n //*/\n \n debug {\n foreach (n; 1 .. 16 + 1) {\n int mx;\n foreach (a; 1 .. n + 1) {\n const q = n / a, r = n % a;\n int score;\n foreach (x; 1 .. a) {\n score += (q + ((x < r) ? 1 : 0)) - 1;\n }\n chmax(mx, score);\n }\n writeln(n, \": \", mx);\n }\n }\n \n const N = readInt();\n \n int mx = -1;\n int am;\n foreach (a; 1 .. N + 1) {\n const q = N / a, r = N % a;\n int score;\n foreach (x; 1 .. a) {\n score += (q + ((x < r) ? 1 : 0)) - 1;\n }\n if (chmax(mx, score)) {\n am = a;\n }\n }\n \n bool[] on;\n const qm = N / am, rm = N % am;\n foreach (x; 0 .. am) {\n const b = qm + ((x < rm) ? 1 : 0);\n foreach (y; 0 .. b) {\n on ~= (y != 0);\n }\n }\n debug {\n writeln(N, \": \", mx, \" \", am, \" \", qm, \" \", rm, \" \", on);\n }\n \n auto now = new bool[N];\n for (; ; ) {\n if (now.count(true) >= mx) {\n writeln(0);\n stdout.flush;\n return;\n }\n int[] js;\n foreach (j; 0 .. N) {\n if (on[j] && !now[j]) {\n js ~= j;\n }\n }\n const jsLen = cast(int)(js.length);\n writeln(jsLen);\n foreach (k; 0 .. jsLen) {\n if (jsLen > 0) write(\" \");\n write(js[k] + 1);\n }\n writeln;\n stdout.flush;\n const res = readInt();\n if (res == -1) {\n stderr.writeln(\"ERROR\");\n return;\n }\n now[] = on[];\n foreach (k; 0 .. jsLen) {\n now[(res - 1 + k) % N] = false;\n }\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto b = new bool [n];\n\n\t\tvoid go (R) (R r)\n\t\t{\n\t\t\tauto len = r.walkLength.to !(int);\n\t\t\twritefln (\"%s%( %s%)\", len, r.map !(q{a + 1}));\n\t\t\tforeach (ref c; r)\n\t\t\t{\n\t\t\t\tb[c] = true;\n\t\t\t}\n\t\t\tstdout.flush ();\n\t\t\tint k;\n\t\t\treadf !(\" %s\") (k);\n\t\t\tk -= 1;\n\t\t\tforeach (i; 0..len)\n\t\t\t{\n\t\t\t\tb[k] = false;\n\t\t\t\tk = (k + 1) % n;\n\t\t\t}\n\t\t}\n\n\t\tint res = n / 2 - 1;\n\t\twhile (b.sum < res)\n\t\t{\n\t\t\tauto p = n.iota.drop (1).stride (2)\n\t\t\t .filter !(i => !b[i]).array;\n\t\t\tgo (p);\n\t\t}\n\n\t\twriteln (0);\n\t\tstdout.flush ();\n\t}\n}\n"}], "src_uid": "aea7e7220a8534c1053e8755a70dd499"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nsize_t n;\nlong[5000] staticA;\n\nlong solve(long[] arr)\n{\n debug writeln(\"solving \", arr);\n auto res = cast(long) arr.length;\n auto mn = arr.fold!min;\n arr[] -= mn;\n debug writeln(\"after cropping: \", arr);\n long cmps = mn;\n int nocmps = 0;\n int i = 0;\n while(i < arr.length)\n {\n while(i < arr.length && arr[i] == 0) i++;\n if (i == arr.length) { debug writeln(\"returns \", min(arr.length, cmps)); return min(arr.length, cmps); }\n debug assert(arr[i] > 0);\n int starti = i;\n while(i < arr.length && arr[i] > 0) i++;\n if (i > starti)\n\tcmps += solve(arr[starti .. i]);\n if (cmps >= res) { debug writeln(\"returns \", res); return res; }\n }\n debug assert(cmps < res);\n debug writeln(\"returns \", cmps);\n return cmps;\n}\n\nvoid main(string[] args)\n{\n n = next!size_t;\n auto a = staticA[0 .. n];\n foreach(ref ai; a) ai = next!long;\n solve(a).writeln;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n int[] A = readln.chomp.split(\" \").map!(to!int).array;\n\n int dfs(int s, int t, int d) {\n //writeln([s, t, d]);\n if (s == t) return 0;\n if (s + 1 == t) {\n return (A[s] > d ? 1 : 0);\n }\n int[] min_x;\n int min_v = int.max;\n for (int i = s; i < t; i++) {\n if (min_v > A[i]) {\n min_v = A[i];\n min_x = [i];\n } else if (min_v == A[i]) {\n min_x ~= i;\n }\n }\n \n int r = min_v - d;\n int Ret = r;\n\n Ret += dfs(s, min_x[0], min_v);\n for (int i = 0; i < cast(int)(min_x.length) - 1; i++) {\n if (min_x[i] == min_x[i + 1]) continue;\n Ret += dfs(min_x[i] + 1, min_x[i + 1], min_v);\n }\n Ret += dfs(min_x[$ - 1] + 1, t, min_v);\n\n //writeln([s, t, d], min_x, [Ret]);\n return min(Ret, t - s);\n }\n\n writeln(dfs(0, N, 0));\n}\n"}], "negative_code": [], "src_uid": "ddab0e510f9aceb2fbf75e26d27df166"} {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n auto as = stdin.readln.split.map!(to!int);\n int m; readf(\"%d\\n\", &m);\n auto bs = stdin.readln.split.map!(to!int);\n int max = 0, c = 0;\n foreach (a; as) {\n foreach (b; bs) {\n if (b % a == 0) {\n if (max == b / a) {\n c++;\n } else if (max < b / a) {\n max = b / a;\n c = 1;\n } \n }\n }\n }\n writeln(c);\n}\n", "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n double[] arr = new double[n];\n foreach (ref i; arr) i = cin.readDouble;\n int m = cin.readInt;\n double[] brr = new double[m];\n foreach (ref i; brr) i = cin.readDouble;\n double maxRatio = -99999.0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (brr[i] % arr[j] == 0)\n maxRatio = max(maxRatio, brr[i] / arr[j]);\n }\n }\n int count = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (abs(brr[i] / arr[j] - maxRatio) < 0.00001) count++;\n }\n }\n writeln(count);\n } \n}"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n double[] arr = new double[n];\n foreach (ref i; arr) i = cin.readDouble;\n int m = cin.readInt;\n double[] brr = new double[m];\n foreach (ref i; brr) i = cin.readDouble;\n double maxRatio = -99999.0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (brr[i] % arr[j] == 0)\n maxRatio = max(maxRatio, brr[i] / arr[j]);\n }\n }\n int count = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (brr[i] % arr[j] == 0 && brr[i] / arr[j] == maxRatio) count++;\n }\n }\n writeln(count);\n } \n}"}], "negative_code": [], "src_uid": "102667eaa3aee012fef70f4192464674"} {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nvoid solve() {\r\n int N, Q; readf(\"%d %d\\n\", &N, &Q);\r\n auto A = readln.chomp.split(\" \").map!(to!int).array;\r\n\r\n // M[k]: minimum IQ required to test all problems of [k, n)\r\n auto M = new int[N];\r\n M[N-1] = 1;\r\n for (int i = N-2; i >= 0; i--) {\r\n int q = M[i+1];\r\n if (q >= A[i]) {\r\n M[i] = q;\r\n } else {\r\n M[i] = q + 1;\r\n }\r\n }\r\n\r\n char[] buf = new char[N]; buf[] = '0';\r\n int ans = 0;\r\n for (int k = 0; k < N; k++) {\r\n if (Q >= M[k]) {\r\n ans += N - k;\r\n buf[k..$] = '1';\r\n break;\r\n } else {\r\n if (Q >= A[k]) {\r\n ans++;\r\n buf[k] = '1';\r\n }\r\n }\r\n }\r\n writeln(buf);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "// cheese-cracker [2022-07-16]\n\nvoid solve(){\n int n = scan!int;\n long q = scan;\n auto arr = scanArray;\n long k = 0;\n dchar[] res;\n for(int i = n-1; i >= 0; --i){\n if(k >= arr[i]){\n res ~= '1';\n }else{\n if(k < q){\n res ~= '1';\n ++k;\n }else{\n res ~= '0';\n }\n }\n }\n res.reverse;\n writeln(res);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm;\nimport std.container, std.math, std.numeric, std.functional;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n const Q = readInt;\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt;\n }\n \n auto ans = new char[N];\n ans[] = '0';\n \n int x = 0;\n foreach_reverse (i; 0 .. N) {\n if (x >= A[i]) {\n ans[i] = '1';\n } else {\n if (x < Q) {\n ans[i] = '1';\n ++x;\n }\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "62a90c34a7df8fb56419aa5a1cf2a75b"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto b = readln.strip.map !(q{a - '0'}).array;\r\n\r\n\t\tint mex (int lo, int hi)\r\n\t\t{\r\n\t\t\tbool [3] c;\r\n\t\t\tforeach (i; lo..hi)\r\n\t\t\t{\r\n\t\t\t\tc[a[i]] = true;\r\n\t\t\t\tc[b[i]] = true;\r\n\t\t\t}\r\n\t\t\tint res = 0;\r\n\t\t\twhile (c[res])\r\n\t\t\t{\r\n\t\t\t\tres += 1;\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tauto f = new int [n + 1];\r\n\t\tf[0] = 0;\r\n\t\tf[1] = mex (0, 1);\r\n\t\tforeach (i; 2..n + 1)\r\n\t\t{\r\n\t\t\tforeach (j; 1..3)\r\n\t\t\t{\r\n\t\t\t\tf[i] = max (f[i], mex (i - j, i) + f[i - j]);\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (f[n]);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int)\n{\n\tint n = readInt!int;\n\tstring[2] tb;\n\ttb[0] = readString;\n\ttb[1] = readString;\n\tauto mx = new int[](n);\n\tforeach(i, ref mxi; mx)\n\t{\n\t\tif (tb[0][i] != tb[1][i])\n\t\t{\n\t\t\tmx[i] = 2;\n\t\t}\n\t\telse if (tb[0][i] == '0')\n\t\t{\n\t\t\tmx[i] = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmx[i] = 0;\n\t\t}\n\t}\n\tauto ans = new int[](n);\n\tint calc(int i)\n\t{\n\t\tif (i == 0) return mx[i];\n\t\tif (mx[i] == 2) return 2 + ans[i-1];\n\t\tint opt1 = mx[i] + ans[i-1];\n\t\tint opt2 = 0;\n\t\tif (mx[i] != mx[i-1])\n\t\t{\n\t\t\tint prev = (i-2 >= 0)? ans[i-2] : 0;\n\t\t\topt2 = prev + 2;\n\t\t}\n\t\treturn max(opt1, opt2);\n\t}\n\tforeach(i; 0 .. n) ans[i] = calc(i);\n\tans[n-1].writeln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv;\r\n\r\nint mex(int[] arr)\r\n{\r\n\tif (arr.maxElement == 2)\r\n\t\treturn 2;\r\n\telse if (arr.minElement == arr.maxElement)\r\n\t\treturn 1 - arr.minElement;\r\n\telse\r\n\t\treturn 2;\r\n}\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(j; 0..t){\r\n\tint str_l;\r\n\tscanf(\"%d\", &str_l);\r\n\tgetchar();\r\n\tauto str1 = readln.strip();\r\n\tauto str2 = readln.strip();\r\n\tint[] result;\r\n\tfor (int i = 0; i < str_l; i++)\r\n\t{\r\n\t\tif (str1[i] == str2[i])\r\n\t\t{\r\n\t\t\tresult ~= cast(int)(str1[i] - '0');\r\n\t\t}\r\n\t\telse\r\n\t\t\tresult ~= 2;\r\n\t}\r\n\tint[] mex_res;\r\n\tdebug{writeln(result);}\r\n\tfor (int i = 0; i < str_l; i++)\r\n\t{\r\n\t\tmex_res ~= mex(result[i..i+1]);\r\n\t}\r\n\tdebug{writeln(mex_res);}\r\n\tfor (int i = 0; i < str_l; i++)\r\n\t{\r\n\t\tif (mex_res[i] == 0)\r\n\t\t{\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tif (mex_res[i+1] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (mex(result[i..i+2]) == 2)\r\n\t\t\t\t\t\tmex_res[i+1]++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse if (i == str_l - 1)\r\n\t\t\t{\r\n\t\t\t\tif (mex_res[i-1] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (mex(result[i-1..i+1]) == 2)\r\n\t\t\t\t\t\tmex_res[i-1]++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (mex_res[i-1] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (mex(result[i-1..i+1]) == 2)\r\n\t\t\t\t\t\tmex_res[i-1]++;\r\n\t\t\t\t}\r\n\t\t\t\telse if (mex_res[i+1] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (mex(result[i..i+2]) == 2)\r\n\t\t\t\t\t\tmex_res[i+1]++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\twriteln(mex_res.sum);\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.functional, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split(\"\").map!(x => (1 << x.to!int)).array;\n auto b = readln.strip.split(\"\").map!(x => (1 << x.to!int)).array;\n foreach (i ; 0 .. n)\n a[i] |= b[i];\n long[] mexval = [0L, 1L, 0L, 2L];\n long[][] ans = new long[][](n + 1, 2);\n int[][] bits = new int[][](n + 1, 2);\n ans[0][0] = mexval[a[0]];\n ans[0][1] = 0;\n bits[0][0] = 0;\n bits[0][1] = a[0];\n foreach (i ; 1 .. n) {\n // break sequence\n long ans1 = ans[i - 1][0] + mexval[bits[i - 1][0] | a[i]];\n long ans2 = ans[i - 1][1] + mexval[bits[i - 1][1] | a[i]];\n ans[i][0] = max(ans1, ans2);\n bits[i][0] = 0;\n // continue sequence\n if (ans[i - 1][0] + mexval[a[i]] >= ans[i - 1][1] + mexval[a[i] | bits[i - 1][1]]) {\n ans[i][1] = ans[i - 1][0];\n bits[i][1] = a[i];\n } else {\n ans[i][1] = ans[i - 1][1];\n bits[i][1] = bits[i - 1][1] | a[i];\n }\n }\n writeln(max(ans[n - 1][0] + mexval[bits[n - 1][0]], ans[n - 1][1] + mexval[bits[n - 1][1]]));\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto s1 = RD!string;\r\n\t\tauto s2 = RD!string;\r\n\r\n\t\tlong last = -1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (last == -1)\r\n\t\t\t{\r\n\t\t\t\tif (s1[i] != s2[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] += 2;\r\n\t\t\t\t\tlast = -1;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s1[i] == '0')\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] += 1;\r\n\t\t\t\t\tlast = 0;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tlast = 1;\r\n\t\t\t}\r\n\t\t\telse if (last == 0)\r\n\t\t\t{\r\n\t\t\t\tif (s1[i] != s2[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] += 2;\r\n\t\t\t\t\tlast = -1;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s1[i] == '0')\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] += 1;\r\n\t\t\t\t\tlast = 0;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] += 1;\r\n\t\t\t\t\tlast = -1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (s1[i] != s2[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] += 2;\r\n\t\t\t\t\tlast = -1;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s1[i] == '0')\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] += 2;\r\n\t\t\t\t\tlast = -1;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tlast = 1;\r\n\t\t\t}\r\n\t\t\tdebug writeln(\"i:\", i, \" \", ans[ti]);\r\n\t\t}\r\n\t}\r\n\t\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "6c4445ee23fedcb913ed3de1beacc099"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable L = 26;\n\nstring S;\nlong K;\nlong[] W;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tS = readToken;\n\t\tK = readLong;\n\t\tW = new long[L];\n\t\tforeach (i; 0 .. L) {\n\t\t\tW[i] = readLong;\n\t\t}\n\t\t\n\t\tlong ans;\n\t\tforeach (i, c; S) {\n\t\t\tans += W[c - 'a'] * (i + 1);\n\t\t}\n\t\tconst wMax = W.reduce!max;\n\t\tforeach (k; 0 .. K) {\n\t\t\tans += wMax * (S.length + 1 + k);\n\t\t}\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nvoid main() {\n string S = readln.chomp;\n int K; scanf(\"%d\\n\", &K);\n int[char] W;\n foreach (char c; 'a' .. 'z' + 1) {\n int w; scanf(\"%d\", &w);\n W[c] = w;\n }\n\n long Ans = 0;\n foreach (i, c; S) {\n Ans += W[c] * (i + 1);\n }\n\n int Max = 0;\n foreach (char c; 'a' .. 'z' + 1) {\n Max = max(Max, W[c]);\n }\n\n foreach (i; 0 .. K) {\n Ans += Max * (S.length + i + 1);\n }\n\n writeln(Ans);\n}\n"}, {"source_code": "//http://codeforces.com/contest/447/problem/B\nimport std.stdio;\n\nint C_OFFSET = 97;\n\nvoid main(){\n string s;\n int n;\n int max_id = 0;\n int[26] val;\n readf(\"%s\\n\" ,&s);\n readf(\"%s\\n\" ,&n);\n for(int i = 0; i < 26; i++){\n int v;\n readf(\"%s \" ,&v);\n val[i] = v;\n if (val[max_id] < v){\n max_id = i;\n }\n }\n writeln(run(s,n,max_id,val));\n}\n\nlong run(string s, int n, int max_id, int[] val){\n int[] a;\n foreach(char c;s){\n int cval = c - C_OFFSET;\n if(cval >= 0 && cval < 26){\n a ~= c - C_OFFSET;\n }\n }\n\n for(int i = 0; i < n; i++){\n a ~= max_id;\n }\n\n return s_prod(a,val);\n}\n\nlong s_prod(int[] a, int[] val){\n long sum = 0;\n foreach(i,x; a){\n sum += (i+1)*val[x];\n }\n return sum;\n}\n\n// TEST CASE AREA\nvoid test_case(){\n long[][] rs;\n rs ~= [run(\"abc\",3,1,[1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]),41];\n\n array_assert(rs);\n}\n\nvoid array_assert(long[][] rs){\n int i = 1;\n bool failed = false;\n\n writefln(\"TEST\");\n\n foreach(long[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n writefln(\"%s Failed %s is NOT %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n"}], "negative_code": [], "src_uid": "85f90533a9840e944deef9f3b4229cb8"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n long n = scan;\n long k = scan;\n auto arr = scanArray;\n arr.sort;\n long summ = 0;\n long[] take;\n for(int i = 0; i < k; ++i){\n take ~= arr.back;\n arr.popBack;\n take ~= arr.back;\n arr.popBack;\n }\n take.sort;\n long maxc = 0;\n long c = 1;\n for(int i = 1; i < 2*k; ++i){\n if(take[i-1] == take[i]){\n ++c;\n }else{\n maxc = max(c, maxc);\n c = 1;\n }\n }\n maxc = max(maxc, c);\n long left = max(2*k - maxc, 0);\n long same = max(maxc - left, 0);\n show(left, same);\n summ = same/2 + arr.sum;\n writeln(summ);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto k = readInt!int;\n auto a = ma(n, readInt!int);\n sort(a);\n auto upper = a[$ - 2 * k .. $];\n auto lower = a[0 .. $ - 2 * k];\n int[int] cnt;\n int mostAps = 0;\n foreach(ai; upper)\n {\n cnt[ai]++;\n if (cnt[ai] > mostAps)\n\t{\n\t mostAps = cnt[ai];\n\t}\n }\n debug writeln(\"upper \", upper);\n debug writeln(\"most aps \", mostAps);\n auto other = cast(int) upper.length - mostAps;\n int rem = max(mostAps - other, 0);\n (lower.sum + rem/2).writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n, k;\n readf!\" %d %d \"(n, k);\n auto a = readln.splitter.map!(to!int).array.sort.array;\n long ans;\n foreach (i ; 0 .. n - 2 * k)\n ans += a[i];\n auto b = a[$ - 2 * k .. $];\n if (b.length >= 2) {\n if (b[k] == b[k - 1]) {\n long same = b.count(b[k]);\n long lohi = b.length - same;\n if (same > lohi) {\n ans += (same - lohi) / 2;\n }\n }\n }\n writeln(ans);\n }\n}\n"}], "negative_code": [], "src_uid": "f48d55c60c12136979fe6db1e15c6053"} {"source_code": "import std.range, std.stdio, std.algorithm, std.bigint, std.conv;\n\nimmutable MN = 410;\nimmutable MA = 160_010;\nvoid main () {\n\tint n, m;\n\tint[MN][] d = new int[MN][](MN);\n\tshort[MA][] minp = new short[MA][](MN);\n\treadf(\"%d %d\\n\", &n, &m);\n\tforeach (i; 0..n) {\n\t\tstring[] s = split(readln());\n\t\tforeach (j; 0..m) {\n\t\t\tauto k = to!int(s[j]);\n\t\t\td[i][j] = k;\n\t\t}\n\t}\n\tlong ans = 0;\n\tint[MN][] u = new int[MN][](MN);\n\tint[MN] y;\n\tforeach (i; 0..n) {\n\t\ty[] = 0;\n\t\tforeach (r; 0..m) {\n\t\t\tforeach_reverse (l; 0..r+1) {\n\t\t\t\ty[l] = max(y[l], minp[l][d[i][r]]);\n\t\t\t\tu[l][r] = max(u[l][r], minp[r][d[i][l]]);\n\t\t\t\tif (r > 0) {\n\t\t\t\t\tu[l][r] = max(u[l][r], u[l][r-1]);\n\t\t\t\t}\n\t\t\t\tu[l][r] = max(u[l][r], u[l+1][r], y[l]);\n\t\t\t\tans = max(ans, (i-u[l][r]+1)*(r-l+1));\n\t\t\t}\n\t\t\tminp[r][d[i][r]] = cast(short)(i+1);\n\t\t}\n\t}\n\twriteln(ans);\n}", "positive_code": [{"source_code": "import std.range, std.stdio, std.algorithm, std.bigint, std.conv;\n\nimmutable MN = 410;\nimmutable MA = 160010;\n\nvoid main () {\n\tint n, m;\n\tint[MN][] d = new int[MN][](MN);\n\tint[MA][] minp = new int[MA][](MN);\n\treadf(\"%d %d\\n\", &n, &m);\n\tforeach (i; 0..n) {\n\t\tstring[] s = split(readln());\n\t\tforeach (j; 0..m) {\n\t\t\tauto k = to!int(s[j]);\n\t\t\td[i][j] = k;\n\t\t}\n\t}\t\n\tlong ans = 0;\n\tint[MN][] u = new int[MN][](MN);\n\tint[MN] y;\n\tforeach (i; 0..n) {\n\t\ty[] = 0;\n\t\tforeach (r; 0..m) {\n\t\t\tforeach_reverse (l; 0..r+1) {\n\t\t\t\ty[l] = max(y[l], minp[l][d[i][r]]);\n\t\t\t\tu[l][r] = max(u[l][r], minp[r][d[i][l]]);\n\t\t\t\tif (r > 0) {\n\t\t\t\t\tu[l][r] = max(u[l][r], u[l][r-1]);\n\t\t\t\t}\n\t\t\t\tu[l][r] = max(u[l][r], u[l+1][r], y[l]);\n\t\t\t\tans = max(ans, (i-u[l][r]+1)*(r-l+1));\n\t\t\t}\n\t\t\tminp[r][d[i][r]] = i+1;\n\t\t}\n\t}\n\twriteln(ans);\n}"}], "negative_code": [{"source_code": "import std.range, std.stdio, std.algorithm, std.bigint, std.conv;\n\nimmutable MN = 410;\nimmutable MA = 160010;\n\nvoid main () {\n\tint n, m;\n\tint[MN][] d = new int[MN][](MN);\n\tint[MA][] minp = new int[MA][](MN);\n\tforeach (ref a; minp) {\n\t\ta[] = MN;\n\t}\n\treadf(\"%d %d\\n\", &n, &m);\n\tforeach (i; 0..n) {\n\t\tstring[] s = split(readln());\n\t\tforeach (j; 0..m) {\n\t\t\tauto k = to!int(s[j]);\n\t\t\tminp[j][k] = min(minp[j][k], i);\n\t\t\td[i][j] = k;\n\t\t}\n\t}\t\n\tlong ans = 0;\n\tint[MN][] u = new int[MN][](MN);\n\tint[MN] y;\n\tforeach (i; 0..n) {\n\t\ty[] = 0;\n\t\tforeach (r; 0..m) {\n\t\t\tforeach_reverse (l; 0..r+1) {\n\t\t\t\tint p = minp[l][d[i][r]];\n\t\t\t\tif (p <= i && l < r) {\n\t\t\t\t\ty[l] = max(y[l], p+1);\n\t\t\t\t}\n\t\t\t\tp = minp[r][d[i][l]];\n\t\t\t\tif (p < i || (l < r && p == i)) {\n\t\t\t\t\tu[l][r] = max(u[l][r], p+1);\n\t\t\t\t}\n\t\t\t\tu[l][r] = max(u[l][r], u[l+1][r], y[l]);\n\t\t\t\tans = max(ans, (i-u[l][r]+1)*(r-l+1));\n\t\t\t}\n\t\t}\n\t}\n\twriteln(minp[0][2], ans);\n}"}, {"source_code": "import std.range, std.stdio, std.algorithm, std.bigint, std.conv;\n\nimmutable MN = 410;\nimmutable MA = 160010;\n\nvoid main () {\n\tint n, m;\n\tint[MN][] d = new int[MN][](MN);\n\tint[MA][] minp = new int[MA][](MN);\n\tforeach (ref a; minp) {\n\t\ta[] = MN;\n\t}\n\treadf(\"%d %d\\n\", &n, &m);\n\tforeach (i; 0..n) {\n\t\tstring[] s = split(readln());\n\t\tforeach (j; 0..m) {\n\t\t\tauto k = to!int(s[j]);\n\t\t\tminp[j][k] = min(minp[j][k], i);\n\t\t\td[i][j] = k;\n\t\t}\n\t}\t\n\tlong ans = 0;\n\tint[MN][] u = new int[MN][](MN);\n\tint[MN] y;\n\tforeach (i; 0..n) {\n\t\ty[] = 0;\n\t\tforeach (r; 0..m) {\n\t\t\tint p = minp[r][d[i][r]];\n\t\t\tif (p < i) {\n\t\t\t\ty[r] = u[r][r] = p+1;\n\t\t\t}\n\t\t\tans = max(ans, (i-u[r][r]+1));\n\t\t\tforeach_reverse (l; 0..r) {\n\t\t\t\tint pl = minp[l][d[i][r]];\n\t\t\t\tif (pl <= i) {\n\t\t\t\t\ty[l] = max(y[l], pl+1);\n\t\t\t\t}\n\t\t\t\tint pr = minp[r][d[i][l]];\n\t\t\t\tif (pr <= i) {\n\t\t\t\t\tu[l][r] = pr+1;\n\t\t\t\t}\n\t\t\t\tu[l][r] = max(u[l][r], u[l][r-1], u[l+1][r], y[l]);\n\t\t\t\tans = max(ans, (i-u[l][r]+1)*(r-l+1));\n\t\t\t}\n\t\t}\n\t}\n\twriteln(ans);\n}"}, {"source_code": "import std.range, std.stdio, std.algorithm, std.bigint, std.conv;\n\nimmutable MN = 410;\nimmutable MA = 160010;\n\nvoid main () {\n\tint n, m;\n\tint[MN][] d = new int[MN][](MN);\n\tint[MA][] minp = new int[MA][](MN);\n\tforeach (ref a; minp) {\n\t\ta[] = MN;\n\t}\n\treadf(\"%d %d\\n\", &n, &m);\n\tforeach (i; 0..n) {\n\t\tstring[] s = split(readln());\n\t\tforeach (j; 0..m) {\n\t\t\tauto k = to!int(s[j]);\n\t\t\tminp[j][k] = min(minp[j][k], i);\n\t\t\td[i][j] = k;\n\t\t}\n\t}\t\n\tlong ans = 0;\n\tint[MN][] u = new int[MN][](MN);\n\tint[MN] y;\n\tforeach (i; 0..n) {\n\t\ty[] = 0;\n\t\tforeach (r; 0..m) {\n\t\t\tint p = minp[r][d[i][r]];\n\t\t\tif (p < i) {\n\t\t\t\ty[r] = u[r][r] = p+1;\n\t\t\t}\n\t\t\tans = max(ans, (i-u[r][r]+1));\n\t\t\tforeach_reverse (l; 0..r) {\n\t\t\t\tint pl = minp[l][d[i][r]];\n\t\t\t\tif (pl <= i) {\n\t\t\t\t\ty[l] = max(y[l], pl+1);\n\t\t\t\t}\n\t\t\t\tint pr = minp[r][d[i][l]];\n\t\t\t\tif (pr <= i) {\n\t\t\t\t\tu[l][r] = pr+1;\n\t\t\t\t}\n\t\t\t\tu[l][r] = max(u[l][r], u[l][r-1], u[l+1][r], y[l]);\n\t\t\t\tans = max(ans, (i-u[l][r]+1)*(r-l+1));\n\t\t\t}\n\t\t}\n\t\tforeach (r; 0..m) {\n\t\t\tforeach (l; 0..r+1) {\n\t\t\t\twriteln(i, l, r, u[l][r]);\n\t\t\t}\n\t\t}\n\t}\n\twriteln(ans);\n}"}, {"source_code": "import std.range, std.stdio, std.algorithm, std.bigint, std.conv;\n\nimmutable MN = 410;\nimmutable MA = 160010;\n\nvoid main () {\n\tint n, m;\n\tint[MN][] d = new int[MN][](MN);\n\tint[MA][] minp = new int[MA][](MN);\n\tforeach (ref a; minp) {\n\t\ta[] = MN;\n\t}\n\treadf(\"%d %d\\n\", &n, &m);\n\tforeach (i; 0..n) {\n\t\tstring[] s = split(readln());\n\t\tforeach (j; 0..m) {\n\t\t\tauto k = to!int(s[j]);\n\t\t\tminp[j][k] = min(minp[j][k], i);\n\t\t\td[i][j] = k;\n\t\t}\n\t}\t\n\tlong ans = 0;\n\tint[MN][] u = new int[MN][](MN);\n\tint[MN] y;\n\tforeach (i; 0..n) {\n\t\ty[] = 0;\n\t\tforeach (r; 0..m) {\n\t\t\tforeach_reverse (l; 0..r+1) {\n\t\t\t\tint p = minp[l][d[i][r]];\n\t\t\t\tif (p <= i && l < r) {\n\t\t\t\t\ty[l] = max(y[l], p+1);\n\t\t\t\t}\n\t\t\t\tp = minp[r][d[i][l]];\n\t\t\t\tif (p < i || (l < r && p == i)) {\n\t\t\t\t\tu[l][r] = max(u[l][r], p+1);\n\t\t\t\t}\n\t\t\t\tu[l][r] = max(u[l][r], u[l+1][r], y[l]);\n\t\t\t\tans = max(ans, (i-u[l][r]+1)*(r-l+1));\n\t\t\t}\n\t\t}\n\t}\n\twriteln(ans);\n}"}, {"source_code": "import std.range, std.stdio, std.algorithm, std.bigint, std.conv;\n\nimmutable MN = 410;\nimmutable MA = 160010;\n\nvoid main () {\n\tint n, m;\n\tint[MN][] d = new int[MN][](MN);\n\tint[MA][] minp = new int[MA][](MN);\n\tforeach (a; minp) {\n\t\ta[] = MN;\n\t}\n\treadf(\"%d %d\\n\", &n, &m);\n\tforeach (i; 0..n) {\n\t\tstring[] s = split(readln());\n\t\tforeach (j; 0..m) {\n\t\t\tauto k = to!int(s[j]);\n\t\t\tminp[j][k] = min(minp[j][k], i);\n\t\t\td[i][j] = k;\n\t\t}\n\t}\t\n\tlong ans = 0;\n\tint[MN][] u = new int[MN][](MN);\n\tint[MN] y;\n\tforeach (i; 0..n) {\n\t\ty[] = 0;\n\t\tforeach (r; 0..m) {\n\t\t\tforeach_reverse (l; 0..r+1) {\n\t\t\t\tint p = minp[l][d[i][r]];\n\t\t\t\tif (p <= i && l < r) {\n\t\t\t\t\ty[l] = max(y[l], p+1);\n\t\t\t\t}\n\t\t\t\tp = minp[r][d[i][l]];\n\t\t\t\tif (p < i || (l < r && p == i)) {\n\t\t\t\t\tu[l][r] = max(u[l][r], p+1);\n\t\t\t\t}\n\t\t\t\tu[l][r] = max(u[l][r], u[l+1][r], y[l]);\n\t\t\t\tans = max(ans, (i-u[l][r]+1)*(r-l+1));\n\t\t\t}\n\t\t}\n\t}\n\twriteln(ans);\n}"}], "src_uid": "92e4375fe9c54b31d7032605e3fd4e9c"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.numeric;\nimport std.algorithm;\nimport core.stdc.stdio;\n\nint main()\n{\n int t = readInt!int;\n foreach(ti; 0 .. t)\n {\n int n = readInt!int;\n int[] a = new int[](n);\n int[] even;\n int[] odd;\n foreach(ref ai; a)\n {\n ai = readInt!int;\n if (ai & 1) odd ~= ai;\n else even ~= ai;\n }\n long count = 0;\n foreach(i, oi; odd)\n {\n foreach(j; i + 1 .. odd.length)\n {\n if (gcd(oi, odd[j]) > 1)\n {\n count++;\n }\n }\n }\n count += even.length * (even.length - 1) / 2;\n count += even.length * odd.length;\n count.writeln;\n }\n return 0;\n}\n\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n currChar = getchar();\n}\nchar topChar()\n{\n return cast(char) currChar;\n}\nvoid popChar()\n{\n currChar = getchar();\n}\nauto readInt(T)()\n{\n T num = 0;\n int sgn = 0;\n while (topChar.isWhite) popChar;\n while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }\n while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }\n if (sgn) return -num; return num;\n}\nstring readString()\n{\n string res = \"\";\n while (topChar.isWhite) popChar;\n while (!topChar.isWhite) { res ~= topChar; popChar; }\n return res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n long rep;\n this(long num)\n {\n rep = num;\n }\n Z!m opBinary(string operator)(Z!m rhs)\n {\n static if (operator == \"+\")\n {\n long result = rhs.rep + this.rep;\n if (result >= m) result -= m;\n return Z!m(result);\n }\n else static if (operator == \"-\")\n {\n long result = this.rep - rhs.rep;\n if (result < 0) result += m;\n return Z!m(result);\n }\n else static if (operator == \"*\")\n {\n long result = this.rep * rhs.rep;\n if (result >= m) result %= m;\n return Z!m(result);\n } else static assert(text(\"Operator \", operator, \" not supported\"));\n }\n Z!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n {\n assert(exponent >= 0);\n Z!m base = this;\n Z!m result = 1;\n while (exponent)\n {\n if (exponent & 1)\n result = result * base;\n base = base * base;\n exponent >>= 1;\n }\n return result;\n }\n invariant\n {\n assert(rep >= 0 && rep < m);\n }\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1535/problem/B\n//\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nlong gcd(long a, long b) {\n return b == 0L ? a : gcd(b, a%b);\n}\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n long[] a = readln.split.map!(to!long).array;\n\n long[] b;\n foreach(item; a) {\n if(item % 2 == 0)\n b = b ~ item;\n }\n foreach(item; a) {\n if(item % 2 == 1)\n b = b ~ item;\n }\n\n int ans = 0;\n for(int i = 0; i < n; ++i)\n for(int j = i + 1; j < n; ++j)\n if(gcd(b[i],2 * b[j]) > 1)\n ans += 1;\n ans.writeln;\n}\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range, std.math, std.numeric;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n long result = 0;\n foreach (i ; 0 .. a.length) {\n foreach (j ; i + 1 .. a.length) {\n if (gcd(a[i], a[j]) > 1)\n result++;\n else if (a[i] % 2 == 0 || a[j] % 2 == 0)\n result++;\n }\n }\n writeln(result);\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.numeric;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto lo = a.filter !(x => (x & 1) == 0).array;\r\n\t\tauto hi = a.filter !(x => (x & 1) == 1).array;\r\n\t\tauto b = lo ~ hi;\r\n\t\tint res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n)\r\n\t\t\t{\r\n\t\t\t\tif (gcd (b[i], b[j] * 2) > 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tres += 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1535/problem/B\n//\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nlong gcd(long a, long b) {\n return b == 0L ? a : gcd(b, a%b);\n}\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n = readln.chomp.to!int;\n long[] a = readln.split.map!(to!long).array;\n\n long[] b;\n foreach(item; a) {\n if(item % 2 == 0)\n b = b ~ item;\n }\n foreach(item; a) {\n if(item % 2 == 1)\n b = b ~ item;\n }\n int ans = 0;\n for(int i = 0; i < n; ++i)\n for(int j = i + 1; j < n; ++j)\n if(gcd(i,j) > 1)\n ans += 1;\n ans.writeln;\n}\n}\n"}], "src_uid": "d638f524fe07cb8e822b5c6ec3fe8216"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nInt gojo(Int)(Int a, Int b, out Int x, out Int y) {\n if (b != 0) { Int g = gojo(b, a % b, y, x); y -= (a / b) * x; return g; }\n x = 1; y = 0; return a;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const T = readLong();\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n auto X = new long[N + 1];\n foreach (i; 0 .. N) {\n X[i + 1] = X[i] + A[(i + 1) % N];\n }\n const M = X[N];\n debug {\n writeln(\"X = \", X);\n }\n \n long z0, z1;\n const D = gojo(M, T, z0, z1);\n \n alias Entry = Tuple!(long, \"val\", int, \"i\");\n auto es = new Entry[N];\n foreach (i; 0 .. N) {\n es[i] = Entry(X[i] % D, i);\n }\n es.sort;\n \n auto ans = new long[N];\n for (int j = 0, k; j < N; j = k) {\n for (k = j; k < N && es[j].val == es[k].val; ++k) {}\n debug {\n writeln(es[j .. k]);\n }\n const r = es[j].val;\n auto fs = new Entry[k - j];\n foreach (l; 0 .. k - j) {\n const i = es[j + l].i;\n /*\n X[i] == r + M a (mod T)\n X[i] + T b = r + M a\n (M / D) a - (T / D) b = (X[i] - r) / D\n (M / D) z0 + (T / D) z1 = 1\n */\n long a = (z0 * (((X[i] - r) / D) % (T / D))) % (T / D);\n if (a < 0) {\n a += T / D;\n }\n fs[l] = Entry(a, i);\n }\n fs.sort!\"(a.val != b.val) ? (a.val < b.val) : (a.i > b.i)\";\n debug {\n writeln(\" fs = \", fs);\n }\n foreach (l; 0 .. k - j - 1) {\n ans[fs[l].i] = fs[l + 1].val - fs[l].val;\n }\n ans[fs[k - j - 1].i] = T / D + fs[0].val - fs[k - j - 1].val;\n }\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln;\n \n debug {\n auto app = new bool[cast(int)(T)];\n auto brt = new long[N];\n foreach (h; 0 .. T) {\n foreach (i; 0 .. N) {\n const x = (X[i] + M * h) % T;\n if (!app[cast(int)(x)]) {\n app[cast(int)(x)] = true;\n ++brt[i];\n }\n }\n }\n writeln(\"brt = \", brt);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nInt gojo(Int)(Int a, Int b, out Int x, out Int y) {\n if (b != 0) { Int g = gojo(b, a % b, y, x); y -= (a / b) * x; return g; }\n x = 1; y = 0; return a;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const T = readLong();\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n auto X = new long[N + 1];\n foreach (i; 0 .. N) {\n X[i + 1] = X[i] + A[(i + 1) % N];\n }\n const M = X[N];\n debug {\n writeln(\"X = \", X);\n }\n \n long z0, z1;\n const D = gojo(M, T, z0, z1);\n \n alias Entry = Tuple!(long, \"val\", int, \"i\");\n auto es = new Entry[N];\n foreach (i; 0 .. N) {\n es[i] = Entry(X[i] % D, i);\n }\n es.sort;\n \n auto ans = new long[N];\n for (int j = 0, k; j < N; j = k) {\n for (k = j; k < N && es[j].val == es[k].val; ++k) {}\n debug {\n writeln(es[j .. k]);\n }\n const r = es[j].val;\n auto fs = new Entry[k - j];\n foreach (l; 0 .. k - j) {\n const i = es[j + l].i;\n /*\n X[i] == r + M a (mod T)\n X[i] + T b = r + M a\n (M / D) a - (T / D) b = (X[i] - r) / D\n (M / D) z0 + (T / D) z1 = 1\n */\n // long a = (z0 * ((X[i] - r) / D)) % (T / D);\n long a = cast(long)((z0 * BigInt((X[i] - r) / D)) % (T / D));\n if (a < 0) {\n a += T / D;\n }\n fs[l] = Entry(a, i);\n }\n fs.sort!\"(a.val != b.val) ? (a.val < b.val) : (a.i > b.i)\";\n debug {\n writeln(\" fs = \", fs);\n }\n foreach (l; 0 .. k - j - 1) {\n ans[fs[l].i] = fs[l + 1].val - fs[l].val;\n }\n ans[fs[k - j - 1].i] = T / D + fs[0].val - fs[k - j - 1].val;\n }\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln;\n \n debug {\n auto app = new bool[cast(int)(T)];\n auto brt = new long[N];\n foreach (h; 0 .. T) {\n foreach (i; 0 .. N) {\n const x = (X[i] + M * h) % T;\n if (!app[cast(int)(x)]) {\n app[cast(int)(x)] = true;\n ++brt[i];\n }\n }\n }\n writeln(\"brt = \", brt);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nInt gojo(Int)(Int a, Int b, out Int x, out Int y) {\n if (b != 0) { Int g = gojo(b, a % b, y, x); y -= (a / b) * x; return g; }\n x = 1; y = 0; return a;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const T = readLong();\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n auto X = new long[N + 1];\n foreach (i; 0 .. N) {\n X[i + 1] = X[i] + A[(i + 1) % N];\n }\n const M = X[N];\n debug {\n writeln(\"X = \", X);\n }\n \n long z0, z1;\n const D = gojo(M, T, z0, z1);\n \n alias Entry = Tuple!(long, \"val\", int, \"i\");\n auto es = new Entry[N];\n foreach (i; 0 .. N) {\n es[i] = Entry(X[i] % D, i);\n }\n es.sort;\n \n auto ans = new long[N];\n for (int j = 0, k; j < N; j = k) {\n for (k = j; k < N && es[j].val == es[k].val; ++k) {}\n debug {\n writeln(es[j .. k]);\n }\n const r = es[j].val;\n auto fs = new Entry[k - j];\n foreach (l; 0 .. k - j) {\n const i = es[j + l].i;\n /*\n X[i] == r + M a (mod T)\n X[i] + T b = r + M a\n (M / D) a - (T / D) b = (X[i] - r) / D\n (M / D) z0 + (T / D) z1 = 1\n */\n long a = (z0 * ((X[i] - r) / D)) % (T / D);\n if (a < 0) {\n a += T / D;\n }\n fs[l] = Entry(a, i);\n }\n fs.sort!\"(a.val != b.val) ? (a.val < b.val) : (a.i > b.i)\";\n debug {\n writeln(\" fs = \", fs);\n }\n foreach (l; 0 .. k - j - 1) {\n ans[fs[l].i] = fs[l + 1].val - fs[l].val;\n }\n ans[fs[k - j - 1].i] = T / D + fs[0].val - fs[k - j - 1].val;\n }\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln;\n \n debug {\n auto app = new bool[cast(int)(T)];\n auto brt = new long[N];\n foreach (h; 0 .. T) {\n foreach (i; 0 .. N) {\n const x = (X[i] + M * h) % T;\n if (!app[cast(int)(x)]) {\n app[cast(int)(x)] = true;\n ++brt[i];\n }\n }\n }\n writeln(\"brt = \", brt);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "85648fa52ac37b34a7ab8fa95984342a"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = RDA!int;\n\t\tauto s = a.sum;\n\t\tans[ti] = min(s, m);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n const n = r.next!uint ();\n const m = r.next!uint ();\n auto a = r.nextA!uint (n);\n const s = sum (a[1 .. $]);\n int delta = min (m - a[0], s);\n writeln (a[0] + delta);\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. scan!int){\n int n = scan!int, m = scan!int;\n long[] as = scan!long(n);\n\n min(m, as.sum).writeln;\n }\n}\n\n"}, {"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\tint c=0;\n\t\treadf(\" %d\", &c);\n\t\tint sum=0;\n\t\tfor (int j=1; j<a; j++)\n\t\t{\n\t\t\tint d=0;\n\t\t\treadf(\" %d\", &d);\n\t\t\tsum=sum+d;\n\t\t}\n\t\tif (sum>=b-c)\n\t\t{\n\t\t\twriteln(b);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(c+sum);\n\t\t}\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "7c2a61de728e6767b25e58c74497bbae"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int cur = 0;\n int[] ans;\n foreach (e; arr) {\n cur += e;\n int d = cur / m;\n int r = cur % m;\n ans ~= d;\n cur = r;\n }\n \n ans.writefln!(\"%(%s %)\");\n}", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; long m; rd(n, m);\n auto as=readln.split.to!(long[]);\n\n long s=0;\n long[] ans;\n foreach(a; as){\n s+=a;\n ans~=s/m;\n s%=m;\n }\n\n writefln(\"%(%s %)\", ans);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1].to!long;\n auto A = readln.split.map!(to!long).array;\n\n auto ans = new long[](N);\n long P = 0;\n\n foreach (i; 0..N) {\n ans[i] += A[i] / M;\n A[i] %= M;\n P += A[i];\n if (P >= M) ans[i] += 1, P %= M;\n }\n\n ans.map!(to!string).join(\" \").writeln;\n}\n"}], "negative_code": [], "src_uid": "a2085c2d21b2dbe4cc27a15fa4a1ec4f"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}\nvoid readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}\nvoid readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}\n\nvoid main()\n{\n int n; readV(n);\n\n if (n <= 5) {\n writeln(-1);\n } else {\n writeln(\"1 2\");\n writeln(\"1 3\");\n writeln(\"1 4\");\n foreach (i; 5..n+1) writeln(\"2 \", i);\n }\n\n foreach (i; 1..n)\n writeln(i, \" \", i+1);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\n\nvoid dame(int n)\n{\n\tif (n < 6) {\n\t\twriteln(-1);\n\t\treturn;\n\t}\n\twriteln(\"1 2\");\n\twriteln(\"1 3\");\n\twriteln(\"1 4\");\n\twriteln(\"4 5\");\n\twriteln(\"4 6\");\n\tint m = n - 6;\n\tint ite = 7;\n\tint prev = 1;\n\tforeach (i; 0..m) {\n\t\twritefln(\"%d %d\", prev, ite);\n\t\tprev = ite;\n\t\t++ite;\n\t}\n}\n\nvoid ok(int n) {\n\tforeach (i; 1..n) {\n\t\twriteln(1, \" \", i + 1);\n\t}\n}\n\nvoid main()\n{\n\tint n = readln.chomp.to!int;\n\tn.dame;\n\tn.ok;\n}\n"}], "negative_code": [], "src_uid": "b1959af75dfdf8281e70ae66375caa14"} {"source_code": "\ufeffimport std.stdio, std.string;\n\nstring[string] words;\n\nvoid main() {\n\t\n\tshort n, m;\n\t\n\tscanf(\"%hd%hd\", &n, &m);\n\n\tforeach (i; 0 .. m) {\n\t\tauto word1 = readln(' ').strip;\n\t\tauto word2 = readln.strip;\n\t\twords[word1] = (word2.length < word1.length) ? word2 : word1;\n\t}\n\t\n\tforeach (idx, lecture; readln.split) {\n\t\twrite(words[lecture]);\n\t\twrite((idx == n - 1) ? '\\n' : ' ');\n\t}\n}", "positive_code": [{"source_code": "\ufeffimport std.stdio, std.string;\n\nstring[string] words;\n\nvoid main() {\n\n\tshort n, m;\n\n\tscanf(\"%hd%hd\", &n, &m);\n\n\tforeach (i; 0 .. m) {\n\t\tauto tmp = readln(' ').strip;\n\t\twords[tmp] = readln.strip;\n\t}\n\n\tforeach (idx, lecture; readln.split) {\n\t\twrite((lecture.length <= words[lecture].length) ? lecture : words[lecture]);\n\t\twrite((idx == n - 1) ? '\\n' : ' ');\n\t}\n}"}, {"source_code": "\ufeffimport std.string : strip, split;\nimport std.stdio : scanf, readln, write;\n\nstring[string] words;\n\nvoid main() {\n\t\n\tshort n, m;\n\t\n\tscanf(\"%hd%hd\", &n, &m);\n\t\n\tforeach (i; 0 .. m) {\n\t\tauto word1 = readln(' ').strip;\n\t\tauto word2 = readln.strip;\n\t\tif (word2.length < word1.length)\n\t\t\twords[word1] = word2;\n\t}\n\n\tforeach (idx, lecture; readln.split) {\n\t\twrite(lecture in words ? words[lecture] : lecture);\n\t\twrite((idx == n - 1) ? '\\n' : ' ');\n\t}\n}"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n int n,m;\n readf!\"%d %d\"(n,m);\n readln;\n string[string] aa;\n string[] l;\n while(m--){\n l=readln.split;\n aa[l[0]]=l[1];\n }\n auto f(ref string a){\n string b=aa[a];\n if(b.length<a.length) return b;\n return a;\n }\n readln.split.map!f.join(\" \").writeln;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.range, std.algorithm, std.string;\nimport std.math;\n\nvoid main() {\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[string] dic;\n\n foreach(i; 0..m) {\n string a, b;\n readf(\"%s %s\\n\", &a, &b);\n if (a.length > b.length) {\n dic[a] = b;\n } else {\n dic[a] = a;\n }\n }\n\n string[] c = readln.chomp.split;\n c.map!(a => dic[a]).array.join(\" \").writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\n\nT read(T)()\n{\n T t;\n readf(\" %s\", &t);\n return t;\n}\n\nint main(string[] args)\n{\n int n = read!int;\n int m = read!int;\n\n string s = readln;\n string[string] dic;\n foreach (i; 0..m)\n {\n s = readln;\n auto t = s.split;\n dic[t[0]] = t[1];\n }\n\n\n bool first = true;\n foreach (w; readln.split)\n {\n if (first)\n first = false;\n else\n write(\" \");\n\n s = dic[w];\n if (s.length < w.length)\n write(s);\n else\n write(w);\n }\n writeln;\n\n return 0;\n}\n"}, {"source_code": "\ufeffimport std.stdio, std.string;\n\nstring[string] word;\n\nvoid main() {\n\t\n\tshort n, m;\n\t\n\tscanf(\"%hd%hd\", &n, &m);\n\t\n\tforeach (i; 0 .. m) {\n\t\tauto word1 = readln(' ').strip;\n\t\tauto word2 = readln.strip;\n\t\tword[word1] = (word2.length < word1.length) ? word2 : word1;\n\t}\n\t\n\tforeach (idx, lecture; readln.split) {\n\t\twrite(word[lecture]);\n\t\twrite((idx == n - 1) ? '\\n' : ' ');\n\t}\n}"}], "negative_code": [], "src_uid": "edd556d60de89587f1b8daa893538530"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n int n;\n @Dim(q{n}) int[] a;\n\n void solve(long tc = -1)\n {\n int turn = 0;\n int fi = -1;\n while(true)\n {\n int maxi = -1, maxa = 0;\n foreach(i; 0 .. n)\n {\n if (i != fi)\n {\n if (a[i] > maxa)\n {\n maxi = i;\n maxa = a[i];\n }\n }\n }\n if (maxa == 0 || maxi == -1)\n {\n writeln(turn == 0? \"HL\" : \"T\");\n break;\n }\n a[maxi]--;\n fi = maxi;\n turn++;\n turn %= 2;\n }\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\ta.sort!\"a > b\"();\n\t\t\n\t\tlong x = a[0];\n\t\tlong y;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\ty += a[i];\n\t\t}\n\t\tif (x > y)\n\t\t{\n\t\t\tans[ti] = true;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto d = y - x;\n\t\t\tif (d % 2)\n\t\t\t\tans[ti] = true;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"T\" : \"HL\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto s = a.sum;\n\t\tauto m = a.maxElement;\n\t\twriteln (s % 2 == 1 || m + m > s ? \"T\" : \"HL\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "5bfce6c17af24959b4af3c9408536d05"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.range;\nimport std.conv;\n\nlong distsq(int x, int y) {\n return (cast(long)x * x) + (cast(long)y * y);\n}\n\nstruct pnt {\n int x, y;\n long da, db;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, ax, ay, bx, by;\n readf(\" %s %s %s %s %s\\n\", &n, &ax, &ay, &bx, &by);\n pnt[] parr = new pnt[n + 1];\n foreach (i ; 0 .. n) {\n readf(\" %s %s\\n\", &parr[i].x, &parr[i].y);\n parr[i].da = distsq(parr[i].x - ax, parr[i].y - ay);\n parr[i].db = distsq(parr[i].x - bx, parr[i].y - by);\n }\n parr[n] = pnt(ax, ay, 0, distsq(ax - bx, ay - by));\n parr.sort!\"a.da < b.da\";\n long ans = long.max;\n foreach (i ; 0 .. n + 1) {\n long r12 = parr[i].da;\n long r22 = (i < n) ? parr[i + 1 .. $].maxElement!\"a.db\".db : 0;\n ans = min(ans, r12 + r22);\n }\n writeln(ans);\n\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.range;\nimport std.conv;\n\nlong distsq(int x, int y) {\n return (cast(long)x * x) + (cast(long)y * y);\n}\n\nstruct pnt {\n int x, y;\n long da, db;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, ax, ay, bx, by;\n readf(\" %s %s %s %s %s\\n\", &n, &ax, &ay, &bx, &by);\n pnt[] parr = new pnt[n];\n foreach (i ; 0 .. n) {\n readf(\" %s %s\\n\", &parr[i].x, &parr[i].y);\n parr[i].da = distsq(parr[i].x - ax, parr[i].y - ay);\n parr[i].db = distsq(parr[i].x - bx, parr[i].y - by);\n }\n parr.sort!\"a.da < b.da\";\n long ans = long.max;\n foreach (i ; 0 .. n - 1) {\n long r12 = parr[i].da;\n long r22 = parr[i + 1 .. $].maxElement!\"a.db\".db;\n ans = min(ans, r12 + r22);\n }\n ans = min(ans, parr[0 .. $].maxElement!\"a.db\".db);\n ans = min(ans, parr[n - 1].da);\n writeln(ans);\n\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.range;\nimport std.conv;\n\nlong distsq(int x, int y) {\n return (cast(long)x * x) + (cast(long)y * y);\n}\n\nstruct pnt {\n int x, y;\n long da, db;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, ax, ay, bx, by;\n readf(\" %s %s %s %s %s\\n\", &n, &ax, &ay, &bx, &by);\n pnt[] parr = new pnt[n];\n pnt*[] ppa = new pnt*[n];\n pnt*[] ppb = new pnt*[n];\n foreach (i ; 0 .. n) {\n readf(\" %s %s\\n\", &parr[i].x, &parr[i].y);\n parr[i].da = distsq(parr[i].x - ax, parr[i].y - ay);\n parr[i].db = distsq(parr[i].x - bx, parr[i].y - by);\n }\n foreach (i ; 0 .. n) {\n ppa[i] = &parr[i];\n ppb[i] = &parr[i];\n }\n ppa.sort!\"a.da < b.da\";\n ppb.sort!\"a.db < b.db\";\n long ans = long.max;\n ans = min(ans, ppa[n-1].da);\n ans = min(ans, ppb[n-1].db);\n int idx = n - 1;\n foreach (i ; 0 .. n - 1) {\n long r12 = ppa[i].da;\n ppa[i].db = 0;\n while (idx > 0 && ppb[idx].db == 0) \n --idx;\n long r22 = ppb[idx].db;\n ans = min(ans, r12 + r22);\n }\n writeln(ans);\n\n return 0;\n}"}], "negative_code": [], "src_uid": "5db9c5673a04256c52f180dbfca2a52f"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n immutable int MAX = 1500;\n immutable long MOD = 10^^9+7;\n\n auto modinv = new long[](MAX);\n modinv[0] = modinv[1] = 1;\n foreach(i; 2..MAX) {\n modinv[i] = modinv[MOD % i] * (MOD - MOD / i) % MOD;\n }\n\n auto f_mod = new long[](MAX);\n auto f_modinv = new long[](MAX);\n f_mod[0] = f_mod[1] = 1;\n f_modinv[0] = f_modinv[1] = 1;\n\n foreach(i; 2..MAX) {\n f_mod[i] = (i * f_mod[i-1]) % MOD;\n f_modinv[i] = (modinv[i] * f_modinv[i-1]) % MOD;\n }\n\n long nck(int n, int k) {\n return f_mod[n] * f_modinv[n-k] % MOD * f_modinv[k] % MOD;\n }\n \n auto N = readln.chomp.to!int;\n auto A = N.iota.map!(_ => readln.chomp.to!int).array;\n\n int acm = A.sum;\n int empty = N;\n long ans = 1;\n foreach (i; iota(N-1, -1, -1)) {\n ans = ans * nck(acm-1, A[i]-1) % MOD;\n acm -= A[i];\n }\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n static const int mod = 1000000007;\n auto t = reduce!((a, b) => a + b)(a);\n auto c = new int[][](t + 1, t + 1);\n foreach (i; 0 .. t + 1)\n {\n fill(c[i], 0);\n }\n foreach (i; 0 .. t + 1)\n {\n c[i][0] = 1;\n }\n foreach (i; 1 .. t + 1)\n {\n foreach (j; 1 .. i + 1)\n {\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;\n }\n }\n long ans = 1;\n for (int i = n - 1; i >= 0; -- i)\n {\n ans = (ans * c[t - 1][a[i] - 1]) % mod;\n t -= a[i];\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int k;\n while (readf(\"%d\\n\", &k) == 1)\n {\n auto c = new int[k];\n foreach (i; 0 .. k)\n {\n readf(\" %d\", &c[i]);\n }\n readln;\n solve(c, k);\n }\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n static const int mod = 1000000007;\n auto t = reduce!((a, b) => a + b)(a);\n auto c = new int[][](t + 1, t + 1);\n foreach (i; 0 .. t + 1)\n {\n fill(c[i], 0);\n }\n foreach (i; 0 .. t + 1)\n {\n c[i][0] = 1;\n }\n foreach (i; 1 .. t + 1)\n {\n foreach (j; 1 .. i + 1)\n {\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;\n }\n }\n auto ans = 1;\n for (int i = n - 1; i >= 0; -- i)\n {\n ans = (ans * c[t - 1][a[i] - 1]) % mod;\n t -= a[i];\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int k;\n while (readf(\"%d\\n\", &k) == 1)\n {\n auto c = new int[k];\n foreach (i; 0 .. k)\n {\n readf(\" %d\", &c[i]);\n }\n readln;\n solve(c, k);\n }\n return 0;\n}"}], "src_uid": "faf2c92c3a61ba5e33160bc7a18ad928"} {"source_code": "import std;\n\nT\nread (alias T, string end = \"\") () {\n T x;\n readf!(\"%s\" ~ end)(x);\n return x;\n}\n\n/** Returns how many increments must be done to `a` to reach a value\n * that satisfies `value | b == b`\n */\nuint\ndistance (in uint a, in uint b) {\n enforce(a < b);\n\n foreach (shift; iota(30, -1, -1))\n if ((a & 1 << shift) != 0 && (b & 1 << shift) == 0) {\n while (!((b & 1 << shift) != 0 && (a & 1 << shift) == 0))\n ++ shift;\n immutable end = 1 << shift;\n immutable start = ~(~0 << shift) & a;\n\n /*\n writefln!\"a: %032b\"(a);\n writefln!\"b: %032b\"(b);\n writefln!\"start: %032b\"(start);\n writefln!\"end: %032b\"(end);\n writeln(\"----\");\n */\n\n return end - start;\n }\n return 0;\n}\n\nvoid main () {\n immutable tests = read!(uint, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n import comp = std.algorithm.comparison;\n\n immutable a = read!(uint, \" \");\n immutable b = read!(uint, \"\\n\");\n\n if (a >= b) {\n writeln(a - b);\n continue;\n }\n\n uint min = b - a;\n\n for (uint i = 0, newB = b; i < min; ++ i, ++ newB) {\n immutable to_reach = a | newB;\n immutable steps = 1 + i + to_reach - newB;\n\n min = comp.min(min, steps);\n }\n\n for (uint i = 0, newB = b; i < min; ++ i, ++ newB) {\n immutable steps = 1 + i + distance(a, newB);\n min = comp.min(min, steps);\n }\n\n writeln(min);\n }\n}\n// \"\"\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport core.bitop;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nenum int INF = 1<<28;\r\n\r\nvoid solve() {\r\n int A, B; readf(\"%d %d\\n\", &A, &B);\r\n\r\n int ans = min(B - A, (A|B) - B + 1);\r\n\r\n for (int x = A; x <= B; x++) {\r\n uint y = 0;\r\n for (int k = 31; k >= 0; k--) {\r\n bool fa = (x & (1 << k)) > 0;\r\n bool fb = (B & (1 << k)) > 0;\r\n if (fa) {\r\n if (fb) {\r\n y |= 1 << k;\r\n } else {\r\n y |= 1 << k;\r\n break;\r\n }\r\n } else {\r\n if (fb) {\r\n y |= 1 << k;\r\n }\r\n }\r\n }\r\n int cost = (x - A) + (y - B) + (x | y) - y + 1;\r\n ans = min(ans, cost);\r\n }\r\n\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport core.bitop;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nenum int INF = 1<<28;\r\n\r\nvoid solve() {\r\n int A, B; readf(\"%d %d\\n\", &A, &B);\r\n\r\n /*\r\n writefln(\"%020b\", A);\r\n writefln(\"%020b\", B);\r\n */\r\n\r\n int ans = B - A;\r\n\r\n ans = min(ans, (A | B) - B + 1);\r\n\r\n int C = A & (~B);\r\n if (C > 0) {\r\n int k = C.bsr;\r\n ans = min(ans, (B & ~((1<<(k+1)) - 1)) - (A & ((1<<(k+1)) - 1)) + 1);\r\n ans = min(ans, (A & ((1<<(k+1)) - 1)) - (B & ((1<<(k+1)) - 1)) + 1);\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport core.bitop;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nenum int INF = 1<<28;\r\n\r\nvoid solve() {\r\n int A, B; readf(\"%d %d\\n\", &A, &B);\r\n\r\n /*\r\n writefln(\"%020b\", A);\r\n writefln(\"%020b\", B);\r\n */\r\n\r\n int ans = B - A;\r\n\r\n ans = min(ans, (A | B) - B + 1);\r\n\r\n int C = A & (~B);\r\n if (C > 0) {\r\n int k = C.bsr;\r\n ans = min(ans, (B & ~(1<<k)) - (A & ((1<<(k+1)) - 1)) + 1);\r\n ans = min(ans, (A & ((1<<(k+1)) - 1)) - (B & ((1<<(k+1)) - 1)) + 1);\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport core.bitop;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nenum int INF = 1<<28;\r\n\r\nvoid solve() {\r\n int A, B; readf(\"%d %d\\n\", &A, &B);\r\n\r\n /*\r\n writefln(\"%020b\", A);\r\n writefln(\"%020b\", B);\r\n */\r\n\r\n int ans = B - A;\r\n\r\n ans = min(ans, (A | B) - B + 1);\r\n\r\n int C = A & (~B);\r\n if (C > 0) {\r\n int k = C.bsr;\r\n ans = min(ans, (B & ~(1<<k)) - (A & ((1<<(k+1)) - 1)) + 1);\r\n }\r\n\r\n int ka = A.bsr;\r\n ans = min(ans, (A & ((1<<(ka+1)) - 1)) - (B & ((1<<(ka+1)) - 1)) + 1);\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "src_uid": "eed751c881767ecd978a728d980da594"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto s = readln.chomp;\n \n int taken = 0, unclosed = 0;\n dchar[] ans;\n foreach (e; s) {\n if (e == '(' && taken * 2 < k) {\n ans ~= e;\n ++taken;\n ++unclosed;\n } else if (e == ')' && unclosed > 0) {\n ans ~= e;\n --unclosed;\n }\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n const S = readToken();\n \n alias Entry = Tuple!(int, \"h\", int, \"i\", int, \"j\");\n Entry[] es;\n \n DList!int stack;\n int now;\n foreach (i; 0 .. N) {\n if (S[i] == '(') {\n stack ~= i;\n ++now;\n } else {\n const j = stack.back;\n stack.removeBack;\n --now;\n es ~= Entry(now, j, i);\n }\n }\n es.sort;\n debug {\n writeln(\"es = \", es);\n }\n \n auto used = new bool[N];\n foreach (k; 0 .. K / 2) {\n used[es[k].i] = used[es[k].j] = true;\n }\n string ans;\n foreach (i; 0 .. N) {\n if (used[i]) {\n ans ~= S[i];\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto S = readln.chomp;\n\n auto st = new int[](N*2);\n int p = -1;\n int cnt = 0;\n int front = 0;\n\n\n foreach (i; 0..N) {\n if (S[i] == '(') {\n st[++p] = i;\n } else if (cnt < N - K) {\n cnt += 2;\n p -= 1;\n } else {\n st[++p] = i;\n }\n }\n\n foreach (i; 0..p+1) {\n write(S[st[i]]);\n }\n\n writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto s = '[' ~ readln.strip ~ ']';\n\t\tn += 2;\n\t\tk += 2;\n\t\tauto next = n.iota.array;\n\t\tnext[] += 1;\n\t\tauto prev = n.iota.array;\n\t\tprev[] -= 1;\n\t\tint pos = 0;\n\t\twhile (k < n)\n\t\t{\n\t\t\tint cur = next[pos];\n\t\t\tdebug {writeln (pos, \" \", cur, \" \", k, \" \", n);}\n\t\t\tif (s[pos] == '(' && s[cur] == ')')\n\t\t\t{\n\t\t\t\tint lo = prev[pos];\n\t\t\t\tint hi = next[cur];\n\t\t\t\tnext[lo] = hi;\n\t\t\t\tprev[hi] = lo;\n\t\t\t\tn -= 2;\n\t\t\t\tpos = lo;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpos = next[pos];\n\t\t\t}\n\t\t}\n\n\t\tpos = 0;\n\t\twhile (true)\n\t\t{\n\t\t\tpos = next[pos];\n\t\t\tif (s[pos] == ']')\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\twrite (s[pos]);\n\t\t}\n\t\twriteln;\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main()\n{\n int n, k;\n readf(\"%d %d\\n\", &n, &k);\n auto s = readln[0 .. $ - 1];\n string a;\n foreach(i, c; s) {\n if (!a.empty && a.back == '(' && c == ')') {\n n -= 2;\n a.popBack;\n } else {\n a ~= c;\n }\n if (n == k) {\n a ~= s[i + 1 .. $];\n break; \n }\n }\n writeln(a);\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto s = readln.chomp;\n \n int left = k, v = 0;\n dchar[] ans;\n foreach (e; s) {\n if (e == '(' && left > 1) {\n ans ~= e;\n ++v;\n --left;\n } else if (e == ')' && v > 0 && left > 0) {\n ans ~= e;\n --v;\n --left;\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto s = '[' ~ readln.strip ~ ']';\n\t\tn += 2;\n\t\tk += 2;\n\t\tauto next = n.iota.array;\n\t\tnext[] += 1;\n\t\tauto prev = n.iota.array;\n\t\tprev[] -= 1;\n\t\tint pos = 0;\n\t\twhile (k < n)\n\t\t{\n\t\t\tint cur = next[pos];\n\t\t\twriteln (pos, \" \", cur, \" \", k, \" \", n);\n\t\t\tif (s[pos] == '(' && s[cur] == ')')\n\t\t\t{\n\t\t\t\tint lo = prev[pos];\n\t\t\t\tint hi = next[cur];\n\t\t\t\tnext[lo] = hi;\n\t\t\t\tprev[hi] = lo;\n\t\t\t\tn -= 2;\n\t\t\t\tpos = lo;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpos = next[pos];\n\t\t\t}\n\t\t}\n\n\t\tpos = 0;\n\t\twhile (true)\n\t\t{\n\t\t\tpos = next[pos];\n\t\t\tif (s[pos] == ']')\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\twrite (s[pos]);\n\t\t}\n\t\twriteln;\n\t}\n}\n"}], "src_uid": "c783434bb17819344fb9a49de1f63708"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RDA;\n\t\ts.sort();\n\t\tans[ti] = long.max;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tans[ti].chmin(s[i] - s[i-1]);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string : split, strip;\nimport std.algorithm : map, sort, minElement;\nimport std.conv : to;\nimport std.array;\nimport std.range : dropOne, zip;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n auto a = readln.strip.split.map!(to!int).array;\n a.sort;\n \n writeln(minElement(a.zip(a.dropOne).map!\"a[1] - a[0]\"));\n }\n}"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n;\n @Dim(\"n\") long[] s;\n\n void solve(long tc = -1)\n {\n sort(s);\n writeln(iota(0, n - 1).map!(i => abs(s.at(i) - s.at(i + 1))).fold!min(long.max));\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}], "negative_code": [], "src_uid": "d2669f85bdb59715352c6bc3d7ba9652"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\nimport std.algorithm.searching;\nimport std.algorithm.sorting;\nimport std.math;\n\n\nvoid main() {\n int cases;\n readf!\"%d\\n\"(cases);\n\n // per testcase\n for (int t = 0; t < cases; t++) {\n int n, m;\n readf!\"%d %d\\n\"(n, m);\n\n string s;\n readf!\"%s\\n\"(s);\n char[] instructions = s.dup;\n\n int x = 0;\n int y = 0;\n int min_x = 0;\n int min_y = 0;\n int max_x = 0;\n int max_y = 0;\n int x_size = 1;\n int y_size = 1;\n int offset_x = 0;\n int offset_y = 0;\n\n for (int i = 0; i < instructions.length; i++) {\n switch (instructions[i]) {\n case 'R':\n x ++;\n break;\n case 'L':\n x --;\n break;\n case 'D':\n y ++;\n break;\n case 'U':\n y --;\n break;\n default:\n break;\n }\n\n bool xflag = false;\n bool yflag = false;\n if (min_x > x) {\n xflag = true;\n min_x = x;\n }\n if (min_y > y) {\n yflag = true;\n min_y = y;\n }\n if (max_x < x) {\n max_x = x;\n }\n if (max_y < y) {\n max_y = y;\n }\n\n\n x_size = max_x - min_x + 1;\n y_size = max_y - min_y + 1;\n // writeln(to!string(instructions[i]) ~ \" \" ~ to!string(x_size) ~ \" \" ~ to!string(y_size));\n if (x_size > m) break;\n if (y_size > n) break;\n\n if (xflag) offset_x += 1;\n if (yflag) offset_y += 1;\n }\n\n writeln(to!string(offset_y + 1) ~ \" \" ~ to!string(offset_x + 1));\n }\n}\n", "positive_code": [{"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\r\nmodule solution;\r\nimport std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int dirs = 4;\r\nimmutable int [dirs] dRow = [ -1, 0, +1, 0];\r\nimmutable int [dirs] dCol = [ 0, -1, 0, +1];\r\nimmutable char [dirs] dName = ['U', 'L', 'D', 'R'];\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint rows, cols;\r\n\t\treadf !(\" %s %s\") (rows, cols);\r\n\t\treadln;\r\n\t\tauto s = readln.strip;\r\n\t\tint rLo = 0;\r\n\t\tint rHi = 0;\r\n\t\tint cLo = 0;\r\n\t\tint cHi = 0;\r\n\t\tint r = 0;\r\n\t\tint c = 0;\r\n\t\tforeach (ref cur; s)\r\n\t\t{\r\n\t\t\tauto dir = dName[].countUntil (cur);\r\n\t\t\tr += dRow[dir];\r\n\t\t\tc += dCol[dir];\r\n\t\t\tauto trLo = min (rLo, r);\r\n\t\t\tauto trHi = max (rHi, r);\r\n\t\t\tauto tcLo = min (cLo, c);\r\n\t\t\tauto tcHi = max (cHi, c);\r\n\t\t\tif (trHi - trLo >= rows)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif (tcHi - tcLo >= cols)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\trLo = trLo;\r\n\t\t\trHi = trHi;\r\n\t\t\tcLo = tcLo;\r\n\t\t\tcHi = tcHi;\r\n\t\t}\r\n\t\twriteln (1 - rLo, \" \", 1 - cLo);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\nimport std.algorithm.searching;\nimport std.algorithm.sorting;\nimport std.math;\n\n\nvoid main() {\n int cases;\n readf!\"%d\\n\"(cases);\n\n // per testcase\n for (int t = 0; t < cases; t++) {\n int n, m;\n readf!\"%d %d\\n\"(n, m);\n\n string s;\n readf!\"%s\\n\"(s);\n char[] instructions = s.dup;\n\n int x = 0;\n int y = 0;\n int min_x = 0;\n int min_y = 0;\n int max_x = 0;\n int max_y = 0;\n int x_size = 1;\n int y_size = 1;\n int offset_x = 0;\n int offset_y = 0;\n\n for (int i = 0; i < instructions.length; i++) {\n switch (instructions[i]) {\n case 'R':\n x ++;\n break;\n case 'L':\n x --;\n break;\n case 'D':\n y ++;\n break;\n case 'U':\n y --;\n break;\n default:\n break;\n }\n\n bool xflag = false;\n bool yflag = false;\n if (min_x > x) {\n xflag = true;\n min_x = x;\n }\n if (min_y > y) {\n yflag = true;\n min_y = y;\n }\n if (max_x < x) {\n max_x = x;\n }\n if (max_y > y) {\n max_y = y;\n }\n\n\n x_size = max_x - min_x + 1;\n y_size = max_y - min_y + 1;\n if (x_size > m) break;\n if (y_size > n) break;\n\n if (xflag) offset_x += 1;\n if (yflag) offset_y += 1;\n }\n\n writeln(to!string(offset_y + 1) ~ \" \" ~ to!string(offset_x + 1));\n }\n}\n"}], "src_uid": "585bb4a040144da39ed240366193e705"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n immutable int MX = 22;\n \n auto cnt = new int[] (MX);\n foreach (e; arr) {\n \n foreach (b; 0 .. MX) {\n if (e & (1 << b)) { cnt[b] += 1; }\n }\n }\n \n auto ans = 0L;\n foreach (i; 1 .. n+1) {\n int cur = 0;\n foreach (b; 0 .. MX) {\n if (cnt[b] >= i) { cur += (1 << b); }\n }\n \n ans += cur.to!long * cur;\n }\n \n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum E = 25;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n auto bs = new long[N];\n foreach (e; 0 .. E) {\n int cnt;\n foreach (i; 0 .. N) {\n if ((A[i] >> e) & 1) {\n ++cnt;\n }\n }\n debug {\n writeln(e, \": \", cnt);\n }\n foreach (i; 0 .. cnt) {\n bs[i] |= 1L << e;\n }\n }\n \n long ans;\n foreach (i; 0 .. N) {\n ans += bs[i]^^2;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\t\n\tauto cnt = new int[](20);\n\tforeach (i; 0..n)\n\t{\n\t\tforeach (j; 0..20)\n\t\t{\n\t\t\tauto bit = 1L << j;\n\t\t\tif (a[i] & bit)\n\t\t\t{\n\t\t\t\t++cnt[j];\n\t\t\t}\n\t\t}\n\t}\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t{\n\t\tlong t;\n\t\tforeach (j; 0..20)\n\t\t{\n\t\t\tif (cnt[j])\n\t\t\t{\n\t\t\t\tt += 1L << j;\n\t\t\t\t--cnt[j];\n\t\t\t}\n\t\t}\n\t\tans += t^^2;\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nimmutable int bits = 20;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint [bits] s;\n\t\tforeach (k; 0..bits)\n\t\t{\n\t\t\ts[k] = a.count !(x => (x & (1 << k)) != 0).to !(int);\n\t\t}\n\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tforeach (k; 0..bits)\n\t\t\t{\n\t\t\t\tif (s[k] > i)\n\t\t\t\t{\n\t\t\t\t\tcur |= (1 << k);\n\t\t\t\t}\n\t\t\t}\n\t\t\tres += cur * 1L * cur;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "// Code By H~$~C\n\nimport std.stdio, std.format;\nimport std.math, std.uni, std.bigint, std.numeric;\nimport std.array, std.string, std.container, std.range, std.typecons;\nimport std.algorithm, std.conv, std.functional, std.random;\n\nvoid _Main() {\n int n;\n readf!\" %d\\n\"(n);\n int[] a = readln.splitter.map!(to!int).array;\n int[][20] b;\n foreach(j; 0 .. 20) {\n b[j] = new int[n];\n }\n foreach(i; 0 .. n) {\n foreach(j; 0 .. 20) {\n b[j][i] = ((a[i] >> j) & 1);\n }\n }\n foreach(j; 0 .. 20) {\n b[j].sort!\"a > b\";\n }\n long ans = 0;\n foreach(i; 0 .. n) {\n long x = 0;\n foreach(j; 0 .. 20) {\n x += ((b[j][i]) << j);\n }\n ans += x * x;\n }\n writeln(ans);\n}\n\nvoid main(string[] args) {\n int tests = 1;\n// readf!\" %d\"(tests);\n foreach (test; 0 .. tests) _Main();\n}\n\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n foreach (i; 0 .. n-1) {\n auto le = arr[i] & arr[i+1];\n auto r = arr[i] | arr[i+1];\n \n arr[i] = le;\n arr[i+1] = r;\n }\n \n auto ans = arr.map!(x => x.to!long * x).sum(0L);\n \n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\t\n\ta.sort!\"a > b\";\n\tauto zero = new int[][](20);\n\tforeach (i; 0..n)\n\t{\n\t\tforeach (j; 0..20)\n\t\t{\n\t\t\tauto bit = 1L << j;\n\t\t\tif (!(a[i] & bit))\n\t\t\t{\n\t\t\t\tzero[j] ~= i;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach_reverse (i; 0..n)\n\t{\n\t\tauto x = a[i];\n\t\tforeach_reverse (j; 0..20)\n\t\t{\n\t\t\tauto bit = 1L << j;\n\t\t\tif (x & bit)\n\t\t\t{\n\t\t\t\tint pos = n;\n\t\t\t\twhile (!zero[j].empty)\n\t\t\t\t{\n\t\t\t\t\tif (pos < i) break;\n\t\t\t\t\tpos = zero[j].front; zero[j].popFront;\n\t\t\t\t}\n\t\t\t\tif (pos == n) continue;\n\n\t\t\t\tauto y = a[pos] & a[i];\n\t\t\t\ta[pos] |= a[i];\n\t\t\t\ta[i] = y;\n\t\t\t}\n\t\t}\n\t}\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t\tans += a[i]^^2;\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\t\n\ta.sort!\"a > b\";\n\tauto zero = new int[][](20);\n\tforeach (i; 0..n)\n\t{\n\t\tforeach (j; 0..20)\n\t\t{\n\t\t\tauto bit = 1L << j;\n\t\t\tif (!(a[i] & bit))\n\t\t\t{\n\t\t\t\tzero[j] ~= i;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach_reverse (i; 0..n)\n\t{\n\t\tauto x = a[i];\n\t\tbool[int] used;\n\t\tforeach_reverse (j; 0..20)\n\t\t{\n\t\t\tauto bit = 1L << j;\n\t\t\tif (x & bit)\n\t\t\t{\n\t\t\t\tint pos = n;\n\t\t\t\twhile (!zero[j].empty)\n\t\t\t\t{\n\t\t\t\t\tif (pos < i) break;\n\t\t\t\t\tpos = zero[j].front; zero[j].popFront;\n\t\t\t\t}\n\t\t\t\tif (pos == n) continue;\n\t\t\t\tif (used.get(pos, false)) continue;\n\t\t\t\tused[pos] = true;\n\t\t\t\tauto y = a[pos] & a[i];\n\t\t\t\ta[pos] |= a[i];\n\t\t\t\ta[i] = y;\n\t\t\t}\n\t\t}\n\t}\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t\tans += a[i]^^2;\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "56fbdca75b69bf41d2a45a1dfe81d022"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nsize_t binarySearch(alias pred, T)(in T[] arr, bool isLower = true)\n{ \n\tlong ok, ng;\n\tif (isLower) { ok = arr.length; ng = -1; }\n\telse\t\t { ok = 0; ng = arr.length; }\n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tsize_t mid = cast(size_t)(ok+ng) / 2;\n\t\tif (unaryFun!pred(arr[mid]))\n\t\t\tok = mid;\n\t\telse ng = mid;\n\t}\n\treturn cast(size_t)ok;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = RD!string;\n\tauto cnt = new int[][](s.length+1, 26);\n\tforeach (i; 0..s.length)\n\t{\n\t\tauto c = cnt[i].dup;\n\t\t++c[s[i]-'a'];\n\t\tcnt[i+1] = c;\n\t}\n\tauto m = RD!int;\n\tforeach (i; 0..m)\n\t{\n\t\tauto t = RD!string;\n\t\tauto cnt2 = new int[](26);\n\t\tforeach (c; t)\n\t\t{\n\t\t\t++cnt2[c-'a'];\n\t\t}\n\t\tbool check(in int[] cnt1)\n\t\t{\n\t\t\tforeach (j; 0..cnt1.length)\n\t\t\t{\n\t\t\t\tif (cnt1[j] < cnt2[j])\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tauto pos = binarySearch!(check)(cnt);\n\t\twriteln(pos);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nint cvt (dchar c) {\n return (c.to!int - 97);\n}\n\nvoid main() {\n immutable n = readln.strip.to!int;\n string s = readln.strip;\n auto idx = new int[][26];\n foreach (i; 0 .. n) {\n int o = cvt (s[i]);\n idx[o] ~= i + 1;\n }\n immutable m = readln.strip.to!int;\n debug stderr.writeln (m);\n foreach (qid; 0 .. m) {\n string t = readln.strip;\n int[26] c;\n foreach (ch; t) {\n ++c[cvt (ch)];\n }\n int res;\n foreach (i; 0 .. 26) {\n if (c[i] > 0) {\n res = max (res, idx[i][c[i]-1]);\n }\n }\n writeln (res);\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nalias T = Tuple!(int, int);\n\nint cvt (dchar c) {\n return 1 << (c.to!int - 48);\n}\n\nvoid main() {\n immutable n = readln.strip.to!int;\n string s = readln.strip;\n T[] h;\n int mask;\n foreach (i; 0 .. n) {\n int o = mask | cvt (s[i]);\n if (o != mask) {\n mask = o;\n h ~= tuple (mask, i + 1);\n }\n }\n immutable m = readln.strip.to!int;\n foreach (qid; 0 .. m) {\n string t = readln.strip;\n mask = t.fold! ( (acc, x) => acc | cvt (x))(0);\n foreach (p; h) {\n if ((p[0] & mask) == mask) {\n writeln (p[1]);\n break;\n }\n }\n }\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nalias T = Tuple!(int, int);\n\nint cvt (dchar c) {\n return 1 << (c.to!int - 97);\n}\n\nvoid main() {\n immutable n = readln.strip.to!int;\n string s = readln.strip;\n T[] h;\n int mask;\n foreach (i; 0 .. n) {\n int o = mask | cvt (s[i]);\n if (o != mask) {\n mask = o;\n h ~= tuple (mask, i + 1);\n }\n }\n immutable m = readln.strip.to!int;\n foreach (qid; 0 .. m) {\n string t = readln.strip;\n mask = t.fold! ( (acc, x) => acc | cvt (x))(0);\n foreach (p; h) {\n if ((p[0] & mask) == mask) {\n writeln (p[1]);\n break;\n }\n }\n }\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = RD!string;\n\tauto m = RD!int;\n\tforeach (i; 0..m)\n\t{\n\t\tauto t = RD!string;\n\t\tbool[char] set;\n\t\tforeach (c; t)\n\t\t{\n\t\t\tset[c] = true;\n\t\t}\n\t\tauto len = set.keys.length;\n\t\tforeach (j, c; s)\n\t\t{\n\t\t\tif (set.get(c, false))\n\t\t\t{\n\t\t\t\t--len;\n\t\t\t\tset[c] = false;\n\t\t\t\tif (len == 0)\n\t\t\t\t{\n\t\t\t\t\twriteln(j+1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "8736df815ea0fdf390cc8d500758bf84"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n auto A = new int[][](N, K);\n foreach (i; 0 .. N) {\n foreach (k; 0 .. K) {\n A[i][k] = readInt();\n }\n }\n \n auto fs = new int[1 << 4];\n foreach (i; 0 .. N) {\n int x;\n foreach (k; 0 .. K) {\n x |= (A[i][k] ^ 1) << k;\n }\n foreach (k; K .. 4) {\n x |= 1 << k;\n }\n ++fs[x];\n }\n debug {\n writeln(\"fs = \", fs);\n }\n \n bool ans;\n if (fs[(1 << 4) - 1] > 0) {\n ans = true;\n }\n foreach (p; 0 .. 1 << 4) foreach (q; p + 1 .. 1 << 4) {\n if (fs[p] > 0 && fs[q] > 0) {\n if ((p | q) == (1 << 4) - 1) {\n ans = true;\n }\n }\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\treadln;\n\tint [int] s;\n\tstring t;\n\twhile ((t = readln.split.join) > \"\") s[t.to!int (2)]++;\n\twriteln (s.byKey.any !(x => s.byKey.any !(y => !(x & y))) ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\tint n, k;\n\treadf (\" %s %s \", &n, &k);\n\tauto m = 1 << k, d = new int [m];\n\tforeach (i; 0..n) d[readln.split.join.to!int (2)]++;\n\twriteln (m.iota.any !(x => m.iota.any !(y => d[x] && d[y] && !(x & y))) ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto k2 = 1 << k;\n\t\tauto d = new int [k2];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto a = readln.split.join.to !(int) (2);\n\t\t\td[a] += 1;\n\t\t}\n\t\tdebug {writeln (d);}\n\n\t\tbool res = false;\n\t\tforeach (i; 0..k2)\n\t\t{\n\t\t\tforeach (j; 0..k2)\n\t\t\t{\n\t\t\t\tif (d[i] && d[j] && !(i & j))\n\t\t\t\t{\n\t\t\t\t\tres = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res ? \"YES\" : \"NO\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\treadln;\n\tint [int] s;\n\tstring t;\n\twhile ((t = readln.split.join) > \"\") s[t.to!int]++;\n\twriteln (s.byKey.any !(x => s.byKey.any !(y => !(x & y))) ? \"YES\" : \"NO\");\n}\n"}], "src_uid": "0928e12caeb71d631a26912c5606b568"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n \r\nvoid solve() {\r\n int n;\r\n char r;\r\n readf!\" %d %c \"(n, r);\r\n //scanf(\"%d %c\\n\", &n, &r);\r\n auto s = readln.strip;\r\n if (r == 'g') {\r\n writeln(0);\r\n return;\r\n }\r\n long fromStart;\r\n bool foundG, countR;\r\n long tmp, maxD;\r\n foreach(i, el; s) {\r\n if (el == 'g') {\r\n foundG = true;\r\n if (tmp > maxD)\r\n maxD = tmp;\r\n countR = false;\r\n tmp = 0;\r\n }\r\n if (el == r)\r\n countR = true;\r\n if (countR)\r\n tmp++;\r\n if (!foundG)\r\n fromStart++;\r\n }\r\n if (countR)\r\n writeln(max(maxD, tmp+fromStart));\r\n else\r\n writeln(maxD);\r\n\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.functional, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\n// Lengths of sequences satisfying the condition (moving to the right)\nint[] seq_length_right(alias less = \"a < b\", T)(T[] a)\n{\n if (a.length == 0)\n return new int[](0);\n auto tmp = new int[](a.length);\n int count = 1;\n tmp[$ - 1] = count;\n foreach_reverse (i ; 0 .. a.length - 1) {\n if (binaryFun!less(a[i], a[i + 1]))\n count++;\n else\n count = 1;\n tmp[i] = count;\n }\n return tmp;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto tmp = readln.split.array;\n auto n = tmp[0].to!long;\n auto ch = tmp[1].strip[0];\n auto s = readln.strip;\n auto ss = s ~ s;\n if (ch == 'g') {\n writeln(0);\n continue;\n }\n auto a = ss.seq_length_right!((a, b) => a != 'g')();\n long ans = 0;\n foreach (i ; 0 .. a.length) {\n if (ss[i] == ch)\n ans = max(a[i], ans);\n }\n writeln(ans - 1);\n }\n}\n"}], "negative_code": [], "src_uid": "9d3ee1b292a2402bb2204ab85dcab587"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RDA!int;\n\n\t\tans[ti] = 1;\n\t\tauto dp = new int[][](n, 21);\n\t\tforeach (i; 0..n)\n\t\t\tdp[i][] = int.max;\n\t\tforeach (i; 0..n/2)\n\t\t{\n\t\t\tdp[i][0] = s[i];\n\t\t}\n\t\tforeach (int to; 1..n+1)\n\t\t{\n\t\t\tint[] index;\n\t\t\tfor (long from = 1; from*from <= to; ++from)\n\t\t\t{\n\t\t\t\tif (to % from) continue;\n\t\t\t\tindex ~= cast(int)from;\n\t\t\t\tindex ~= cast(int)(to / from);\n\t\t\t}\n\t\t\tforeach (from; index)\n\t\t\t{\n\t\t\t\tforeach (k; 0..20)\n\t\t\t\t{\n\t\t\t\t\tif (dp[from-1][k] < s[to-1])\n\t\t\t\t\t{\n\t\t\t\t\t\tdp[to-1][k+1].chmin(s[to-1]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t(){\n\t\tforeach_reverse (i; 0..21)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tif (dp[j][i] != int.max)\n\t\t\t\t{\n\t\t\t\t\tans[ti] = i+1;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}}();\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto N = readln.chomp.to!int;\n auto ss = readln.split.to!(int[]);\n auto DP = new int[](N+1);\n foreach_reverse (i; 1..N+1) {\n int x = i * 2, n = 1;\n while (x <= N) {\n if (ss[x-1] > ss[i-1]) n = max(n, DP[x] + 1);\n x += i;\n }\n DP[i] = n;\n }\n int r;\n foreach (ref e; DP) r = max(r, e);\n writeln(r);\n }\n}"}], "negative_code": [], "src_uid": "0197047cab6d83a189a5c1eabf5b1dd3"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n auto hs = readln.chomp.split.map!(to!int).array;\n \n bool ok = true;\n foreach (a, b; lockstep(hs, hs.dropOne)) {\n if (a + m < b - k) {\n ok = false;\n break;\n }\n \n if (a > b - k) { m += a - max(b-k, 0); }\n else { m -= b-k - a; }\n }\n \n writeln(ok ? \"YES\" : \"NO\");\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD;\n\t\tauto k = RD;\n\t\tauto h = RDA;\n\t\tbool tmp = true;\n\t\tforeach (j; 1..n)\n\t\t{\n\t\t\tauto d = k - (h[j] - h[j-1]);\n\t\t\tm += min(d, h[j-1]);\n\t\t\tif (m < 0)\n\t\t\t{\n\t\t\t\ttmp = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[i] = tmp;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint t = read.to!int;\n\t\nA:\n\tforeach(_; 0 .. t){\n\t\tint n = read.to!int;\n\t\tlong m = read.to!long;\n\t\tlong k = read.to!long;\n\t\tlong[] hs;\n\t\tforeach(i; 0 .. n) hs ~= read.to!long;\n\t\tlog(\"t:\", t, \"n:\", n, \"m:\", m, \"k:\", k, \"hs:\", hs);\n\t\t\n\t\tforeach(i; 0 .. n - 1){\n\t\t\tlog(\"i:\", i, \"m:\", m, \"hs[i]:\", hs[i], \"hs[i + 1]:\", hs[i + 1]);\n\t\t\tif(hs[i] + m < hs[i + 1] - k){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\tcontinue A;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tlong h = hs[i + 1] - k;\n\t\t\t\tif(h < 0) h = 0;\n\t\t\t\tif(hs[i] > h) m += hs[i] - h;\n\t\t\t\telse m -= h - hs[i];\n\t\t\t\tlog(\"h:\", h, \"m:\", m);\n\t\t\t}\n\t\t}\n\t\t\"YES\".writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n auto hs = readln.chomp.split.map!(to!int).array;\n \n bool ok = true;\n foreach (a, b; lockstep(hs, hs.dropOne)) {\n if (a + m < b - k) {\n ok = false;\n break;\n }\n \n if (a > b - k) { m += a - (b-k); }\n else { m -= b-k - a; }\n }\n \n writeln(ok ? \"YES\" : \"NO\");\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto k = RD!int;\n\t\tauto h = RDA;\n\t\tbool tmp = true;\n\t\tforeach (j; 1..n)\n\t\t{\n\t\t\tauto d = k - (h[j] - h[j-1]);\n\t\t\tm += d;\n\t\t\tif (m < 0)\n\t\t\t{\n\t\t\t\ttmp = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[i] = tmp;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD;\n\t\tauto k = RD;\n\t\tauto h = RDA;\n\t\tbool tmp = true;\n\t\tforeach (j; 1..n)\n\t\t{\n\t\t\tauto d = k - (h[j] - h[j-1]);\n\t\t\tm += d;\n\t\t\tif (m < 0)\n\t\t\t{\n\t\t\t\ttmp = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tans[i] = tmp;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "3f60e740d9a3ec14223b2b1f62c52f61"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tauto q = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\tq[] -= 1;\n\t\tauto rp = new int [n];\n\t\tauto rq = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\trp[p[i]] = i;\n\t\t\trq[q[i]] = i;\n\t\t}\n\t\tint [int] delta;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tdelta[(n + rp[j] - rq[j]) % n] += 1;\n\t\t}\n\t\tdelta.byValue.maxElement.writeln;\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\tauto b = RDA;\n\t\t\n\tauto index1 = a.MAKE_IDX;\n\tauto index2 = b.MAKE_IDX;\n\n\tauto cnt = new long[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto d = cast(long)index1[i] - cast(long)index2[i];\n\t\tif (d < 0)\n\t\t\td = n + d;\n\t\t++cnt[cast(int)d];\n\t}\n\tauto ans = cnt[cnt.MIN_POS!\"a > b\"];\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tauto q = readln.splitter.map !(to !(int)).array;\n\t\tauto cp = new int [n];\n\t\tauto cq = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tcp[(n + p[i] - i) % n] += 1;\n\t\t\tcq[(n + q[i] - i) % n] += 1;\n\t\t}\n\t\twriteln (min (cp.maxElement, cq.maxElement));\n\t}\n}\n"}], "src_uid": "eb1bb862dc2b0094383192f6998891c5"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto a = next!long(n);\n long mx = long.min;\n foreach(i; 0 .. n)\n {\n auto ai = a[i];\n foreach(j; i .. n)\n\t{\n\t auto aij = ai | a[j];\n\t foreach(k; j .. n)\n\t mx = max(mx, aij | a[k]);\n\t}\n }\n mx.writeln;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tres = max (res, a[i]);\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tres = max (res, a[i] | a[j]);\n\t\t\t\tforeach (k; 0..n)\n\t\t\t\t{\n\t\t\t\t\tres = max (res, a[i] | a[j] | a[k]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "08345b5a41424021e52e47cd0bd03d63"} {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nint q;\n\nvoid main() {\n scan(q);\n\n int n;\n\n while (q--) {\n scan(n);\n solve(n).writeln;\n }\n}\n\nlong solve(int n) {\n if (n <= 5) {\n return n - 1;\n }\n\n long btm = 2, top = n - 1, mid;\n\n while (top - btm > 1) {\n mid = (btm + top) / 2;\n\n if (n + (mid - 1) * (mid - 2) / 2L <= 2L * (n - 1 - mid)) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n return min(n - 1 + btm * (btm - 1) / 2L, 2L * (n - 1 - btm));\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}", "positive_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nint q;\n\nvoid main() {\n scan(q);\n\n int n;\n\n while (q--) {\n scan(n);\n solve(n).writeln;\n }\n}\n\nlong solve(int n) {\n int btm = 2, top = n, mid;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n long e = 1L * mid * (mid - 1) / 2L;\n\n (e <= n - mid ? btm : top) = mid;\n }\n\n long ans = max(n - btm + 1L * btm * (btm - 1) / 2L, 2L * (n - btm - 1));\n\n return ans;\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nint q;\n\nvoid main() {\n scan(q);\n\n long n;\n\n while (q--) {\n scan(n);\n solve(n);\n }\n}\n\nvoid solve(long n) {\n long btm = 0, top = n*n, mid;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (check(n, mid)) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n writeln(n - 1 + btm);\n}\n\nbool check(long n, long K) {\n long btm = 0, top = K*K, mid;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (K <= mid * (mid + 1) / 2) {\n top = mid;\n }\n else {\n btm = mid;\n }\n }\n\n long tot = n - 1 + K;\n long bri = n - 1 - (top + 1);\n\n return 2*bri >= tot;\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "src_uid": "d70ce3b16614129c5d697a9597bcd2e3"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int[] n;\n auto memo = new long[][][][](11, 64, 1 << 10, 2);\n afill(memo, -1L);\n long f(const int base, int i, bool less, int used, bool zero) {\n if (i < 0) {\n return used == 0 && !zero;\n } else {\n if (less && memo[base][i][used][zero] >= 0) {\n return memo[base][i][used][zero];\n }\n long ret = 0;\n auto digit = less ? base - 1 : n[i];\n for (int d = 0; d <= digit; d++) {\n auto l = less || (d < digit);\n auto z = zero && (d == 0);\n auto u = used ^ (z ? 0 : (1 << d));\n ret += f(base, i - 1, l, u, z);\n }\n if (less) {\n return memo[base][i][used][zero] = ret;\n } else {\n return ret;\n }\n }\n }\n\n int q;\n rd(q);\n while (q--) {\n int b;\n long l, r;\n rd(b, l, r);\n long res = 0;\n n = digit(r, b).dup;\n res += f(b, (n.length - 1).to!(int), 0, 0, true);\n n = digit(l - 1, b).dup;\n res -= f(b, (n.length - 1).to!(int), 0, 0, true);\n writeln(res);\n }\n}\n\nint[] digit(long n, int base) {\n int[] ret;\n do {\n ret ~= n % base;\n n /= base;\n }\n while (n);\n return ret;\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n\nvoid afill(Range, Type)(Range r, Type value) {\n static if (is(typeof(r) == Type[])) {\n foreach (ref elem; r)\n elem = value;\n } else {\n foreach (ref arr; r)\n afill(arr, value);\n }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum LIM_B = 10;\nenum LIM_L = 100;\n\nvoid main() {\n auto dp = new long[][][LIM_B + 1];\n foreach (B; 2 .. LIM_B + 1) {\n dp[B] = new long[][](LIM_L + 1, 1 << B);\n dp[B][0][0] = 1;\n foreach (l; 0 .. LIM_L) {\n foreach (p; 0 .. 1 << B) {\n foreach (x; 0 .. B) {\n dp[B][l + 1][p ^ 1 << x] += dp[B][l][p];\n }\n }\n }\n }\n \n long solve(const(int) B, const(long) N) {\n int[] as;\n for (long n = N; n; n /= B) {\n as ~= cast(int)(n % B);\n }\n as.reverse;\n const asLen = cast(int)(as.length);\n long ans;\n // short\n foreach (l; 1 .. asLen) {\n foreach (x; 1 .. B) {\n ans += dp[B][l - 1][1 << x];\n }\n }\n // as long\n int p;\n foreach (i; 0 .. asLen) {\n foreach (x; 0 .. as[i]) {\n if (i > 0 || x > 0) {\n debug {\n // writeln(\" \", B, \" \", asLen - 1 - i, \" \", p ^ 1 << x, \": \", dp[B][asLen - 1 - i][p ^ 1 << x]);\n }\n ans += dp[B][asLen - 1 - i][p ^ 1 << x];\n }\n }\n p ^= 1 << as[i];\n }\n debug {\n writeln(\"solve \", B, \" \", as, \" = \", ans);\n }\n debug {\n long brt;\n foreach (n; 1 .. N) {\n int q;\n for (long nn = n; nn; nn /= B) {\n q ^= 1 << cast(int)(nn % B);\n }\n if (q == 0) {\n ++brt;\n }\n }\n writeln(\"brt = \", brt);\n assert(brt == ans);\n }\n return ans;\n }\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const B = readInt();\n const L = readLong();\n const R = readLong();\n \n long ans;\n ans -= solve(B, L);\n ans += solve(B, R + 1);\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int[] n;\n auto memo = new long[][][][](11, 64, 1 << 10, 2);\n afill(memo, -1L);\n long f(const int base, size_t i, bool less, int used, bool zero) {\n if (i == n.length) {\n return used == 0 && zero;\n } else {\n if (less && zero && memo[base][n.length-i-1][used][zero] >= 0) {\n return memo[base][n.length-i-1][used][zero];\n }\n long ret = 0;\n auto digit = less ? base - 1 : n[i];\n for (int d = 0; d <= digit; d++) {\n auto l = less || (d < digit);\n auto z = zero || (d > 0);\n auto u = !z ? used : (used ^ (1 << d));\n ret += f(base, i + 1, l, u, z);\n }\n if (less && zero) {\n memo[base][n.length-i-1][used][zero] = ret;\n }\n return ret;\n }\n }\n\n int q;\n rd(q);\n while (q--) {\n int b;\n long l, r;\n rd(b, l, r);\n long res = 0;\n n = digit(r, b).dup;\n res += f(b, 0, 0, 0, 0);\n n = digit(l - 1, b).dup;\n res -= f(b, 0, 0, 0, 0);\n writeln(res);\n }\n}\n\nint[] digit(long n, int base) {\n int[] ret;\n do {\n ret = n % base ~ ret;\n n /= base;\n }\n while (n);\n return ret;\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n\nvoid afill(Range, Type)(Range r, Type value) {\n static if (is(typeof(r) == Type[])) {\n foreach (ref elem; r)\n elem = value;\n } else {\n foreach (ref arr; r)\n afill(arr, value);\n }\n}\n"}], "negative_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int[] n;\n auto memo = new long[][][][](11, 64, 1 << 10, 2);\n afill(memo, -1L);\n long f(const int base, int i, bool less, int used, bool zero) {\n if (i < 0) {\n return used == 0 && !zero;\n } else {\n if (less && memo[base][i][used][zero] >= 0) {\n return memo[base][i][used][zero];\n }\n long ret = 0;\n auto digit = less ? base - 1 : n[i];\n for (int d = 0; d <= digit; d++) {\n auto l = less || (d < digit);\n auto z = zero && (d == 0);\n auto u = used ^ (z ? 0 : (1 << d));\n ret += f(base, i - 1, l, u, z);\n }\n return memo[base][i][used][zero] = ret;\n }\n }\n\n int q;\n rd(q);\n while (q--) {\n int b;\n long l, r;\n rd(b, l, r);\n long res = 0;\n n = digit(r, b).dup;\n res += f(b, (n.length - 1).to!(int), 0, 0, true);\n n = digit(l - 1, b).dup;\n res -= f(b, (n.length - 1).to!(int), 0, 0, true);\n writeln(res);\n }\n}\n\nint[] digit(long n, int base) {\n int[] ret;\n do {\n ret ~= n % base;\n n /= base;\n }\n while (n);\n return ret;\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n\nvoid afill(Range, Type)(Range r, Type value) {\n static if (is(typeof(r) == Type[])) {\n foreach (ref elem; r)\n elem = value;\n } else {\n foreach (ref arr; r)\n afill(arr, value);\n }\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int[] n;\n auto memo = new long[][][][](11, 64, 1 << 10, 2);\n afill(memo, -1L);\n long f(const int base, size_t i, bool less, int used, bool zero) {\n if (i == n.length) {\n return used == 0;\n } else {\n if (less && zero && memo[base][i][used][zero] >= 0) {\n return memo[base][i][used][zero];\n }\n long ret = 0;\n auto digit = less ? base - 1 : n[i];\n for (int d = 0; d <= digit; d++) {\n auto l = less || (d < digit);\n auto z = zero || (d > 0) || (i + 1 == n.length);\n auto u = !z ? used : (used ^ (1 << d));\n auto tmp = ret;\n ret += f(base, i + 1, l, u, z);\n }\n if (less && zero) { // leading zeros\u629c\u3051\u308b\u307e\u3067\u306f\u5206\u304b\u3089\u306a\u3044\u306e\u3067\n memo[base][i][used][zero] = ret;\n }\n return ret;\n }\n }\n\n int q;\n rd(q);\n while (q--) {\n int b;\n long l, r;\n rd(b, l, r);\n long res = 0;\n n = digit(r, b).dup;\n res += f(b, 0, 0, 0, 0);\n n = digit(l - 1, b).dup;\n res -= f(b, 0, 0, 0, 0);\n writeln(res);\n }\n}\n\nint[] digit(long n, int base) {\n int[] ret;\n do {\n ret = n % base ~ ret;\n n /= base;\n }\n while (n);\n return ret;\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n\nvoid afill(Range, Type)(Range r, Type value) {\n static if (is(typeof(r) == Type[])) {\n foreach (ref elem; r)\n elem = value;\n } else {\n foreach (ref arr; r)\n afill(arr, value);\n }\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int[] n;\n auto memo = new long[][][][](11, 64, 1 << 10, 2);\n afill(memo, -1L);\n long f(const int base, int i, bool less, int used, bool zero) {\n if (i < 0) {\n return used == 0;\n } else {\n if (less && memo[base][i][used][zero] >= 0) {\n return memo[base][i][used][zero];\n }\n long ret = 0;\n auto digit = less ? base - 1 : n[i];\n for (int d = 0; d <= digit; d++) {\n auto l = less || (d < digit);\n auto z = zero && (d == 0);\n auto u = used ^ (z ? 0 : (1 << d));\n ret += f(base, i - 1, l, u, z);\n }\n return memo[base][i][used][zero] = ret;\n }\n }\n\n int q;\n rd(q);\n while (q--) {\n int b;\n long l, r;\n rd(b, l, r);\n long res = 0;\n n = digit(r, b).dup;\n res += f(b, (n.length - 1).to!(int), 0, 0, true);\n n = digit(l - 1, b).dup;\n res -= f(b, (n.length - 1).to!(int), 0, 0, true);\n writeln(res);\n }\n}\n\nint[] digit(long n, int base) {\n int[] ret;\n do {\n ret ~= n % base;\n n /= base;\n }\n while (n);\n return ret;\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n\nvoid afill(Range, Type)(Range r, Type value) {\n static if (is(typeof(r) == Type[])) {\n foreach (ref elem; r)\n elem = value;\n } else {\n foreach (ref arr; r)\n afill(arr, value);\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum LIM_B = 10;\nenum LIM_L = 100;\n\nvoid main() {\n auto dp = new long[][][LIM_B + 1];\n foreach (B; 2 .. LIM_B + 1) {\n dp[B] = new long[][](LIM_L + 1, 1 << B);\n dp[B][0][0] = 1;\n foreach (l; 0 .. LIM_L) {\n foreach (p; 0 .. 1 << B) {\n foreach (x; 0 .. B) {\n dp[B][l + 1][p ^ 1 << x] += dp[B][l][p];\n }\n }\n }\n }\n \n long solve(const(int) B, const(long) N) {\n int[] as;\n for (long n = N; n; n /= B) {\n as ~= cast(int)(n % B);\n }\n as.reverse;\n const asLen = cast(int)(as.length);\n long ans;\n // short\n foreach (l; 1 .. asLen) {\n foreach (x; 1 .. B) {\n ans += dp[B][l - 1][1 << x];\n }\n }\n // as long\n int p;\n foreach (i; 0 .. asLen) {\n foreach (x; 0 .. as[i]) {\n if (i > 0 || x > 0) {\n debug {\n writeln(\" \", B, \" \", asLen - 1 - i, \" \", p ^ 1 << x, \": \", dp[B][asLen - 1 - i][p ^ 1 << x]);\n }\n ans += dp[B][asLen - 1 - i][p ^ 1 << x];\n }\n }\n p ^= 1 << as[i];\n }\n debug {\n writeln(\"solve \", B, \" \", as, \" = \", ans);\n }\n return ans;\n }\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const B = readInt();\n const L = readLong();\n const R = readLong();\n \n long ans;\n ans -= solve(B, L + 1);\n ans += solve(B, R + 1);\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "2df506710dfbc401e5c71ff7ae63746d"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tbool[long] set;\r\n\t\tforeach (i; 0..n)\r\n\t\t\tset[a[i]] = true;\r\n\r\n\t\tauto cnt = cast(int)set.length;\r\n\t\tans[ti].length = n;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto k = i + 1;\r\n\t\t\tans[ti][i] = k + max(0, cnt - k);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!long;\r\n auto A = scan!long(N);\r\n\r\n auto uniqSize = A.sort.uniq.array.length;\r\n return N.iota.map!(k => max(k + 1, uniqSize)).toAnswerString;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "negative_code": [], "src_uid": "06212223295c56a78a5d4e55c53a63e0"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.random;\n\nconst int maxn = 100;\nint n, a, b, k, fm; // a -- even, b -- odd, fm -- final turn player\nint data[maxn][maxn];\n\nvoid input() {\n\treadf(\"%s %s\", &n, &k);\n\tfor (int i = 0; i < n; ++i) {\n\t\tint t;\n\t\treadf(\" %s\", &t);\n\t\tif (t % 2) ++b; else ++a;\n\t}\n\tfm = (n - k) % 2;\n}\n\nint solve() {\n\tfor (int chet = 0; chet < maxn; ++chet)\n\t\tfor (int nech = 0; nech < maxn; ++nech) {\n\t\t\tif (chet + nech <= k)\n\t\t\t\tdata[chet][nech] = nech % 2;\n\t\t\telse {\n\t\t\t\tint cp = fm ^ 1 ^ ((chet + nech - k) % 2);\n\t\t\t\tif (cp == 0) {\n\t\t\t\t\tdata[chet][nech] = 1;\n\t\t\t\t\tif (chet) data[chet][nech] &= data[chet - 1][nech];\n\t\t\t\t\tif (nech) data[chet][nech] &= data[chet][nech - 1];\n\t\t\t\t} else {\n\t\t\t\t\tdata[chet][nech] = 0;\n\t\t\t\t\tif (chet) data[chet][nech] |= data[chet - 1][nech];\n\t\t\t\t\tif (nech) data[chet][nech] |= data[chet][nech - 1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn data[a][b];\n}\n\nint megasolve() {\n\tif (a < maxn && b < maxn && k < maxn)\n\t\treturn solve();\n\tif (n == k)\n\t\treturn b % 2;\n\tif (k % 2 == 0 && fm == 0)\n\t\treturn 0;\n\tif (k % 2 == 1 && fm == 0)\n\t\treturn b - a >= k;\n\tif (k % 2 == 0 && fm == 1)\n\t\treturn (b - a < k) && (a - b < k);\n\treturn a - b < k;\n}\n\nvoid main() {\n\tinput();\n\twriteln(megasolve() ? \"Stannis\" : \"Daenerys\");\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nbool solve (int n, int k, int even, int odd)\n{\n\tint moves = n - k;\n\tint dmoves = moves / 2;\n\tint smoves = moves - dmoves;\n\tif (n == k)\n\t{\n\t\treturn odd % 2 == 0;\n\t}\n\tif (odd <= dmoves)\n\t{\n\t\treturn true;\n\t}\n\tif (even <= smoves && k % 2 == 1)\n\t{\n\t\treturn false;\n\t}\n\tif (even <= dmoves && k % 2 == 0)\n\t{\n\t\treturn true;\n\t}\n\tif (even == 0)\n\t{\n\t\treturn k % 2 == 0;\n\t}\n\treturn dmoves >= smoves;\n}\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s \", &n, &k) > 0)\n\t{\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tint even = a.count !(q{a % 2 == 0});\n\t\tint odd = a.count !(q{a % 2 == 1});\n\t\tdebug {writeln (a, ' ', even, ' ', odd);}\n\t\twriteln (solve (n, k, even, odd) ? \"Daenerys\" : \"Stannis\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nbool solve (int n, int k, int even, int odd)\n{\n\tint moves = n - k;\n\tint dmoves = moves / 2;\n\tint smoves = moves - dmoves;\n\tif (odd <= dmoves)\n\t{\n\t\treturn true;\n\t}\n\tif (even <= smoves && k % 2 == 1)\n\t{\n\t\treturn false;\n\t}\n\tif (even <= dmoves && k % 2 == 0)\n\t{\n\t\treturn true;\n\t}\n\tif (even == 0)\n\t{\n\t\treturn k % 2 == 0;\n\t}\n\treturn dmoves >= smoves;\n}\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s \", &n, &k) > 0)\n\t{\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tint even = a.count !(q{a % 2 == 0});\n\t\tint odd = a.count !(q{a % 2 == 1});\n\t\tdebug {writeln (a, ' ', even, ' ', odd);}\n\t\twriteln (solve (n, k, even, odd) ? \"Daenerys\" : \"Stannis\");\n\t}\n}\n"}], "src_uid": "67e51db4d96b9f7996aea73cbdba3584"} {"source_code": "import std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\n\nstruct seg\n{\n int l = int.max;\n int r;\n}\n\nbool ask(int r, int c, int r1, int c1)\n{\n writefln(\"? %d %d %d %d\", r, c, r1, c1);\n stdout.flush;\n return \"YES\" == readln.chomp;\n}\n\nvoid main()\n{\n int n;\n readf(\"%d\\n\", &n);\n bool[] a;\n a.length = 2 * n - 2;\n int r = 1, c = 1;\n foreach (i; 0..n - 1) {\n ++r;\n a[i] = ask(r, c, n, n);\n if (!a[i]) {\n --r;\n ++c;\n }\n }\n r = c = n;\n foreach (i; 1..n) {\n --c;\n a[$ - i] = !ask(1, 1, r, c);\n if (a[$ - i]) {\n ++c;\n --r;\n }\n }\n write(\"! \");\n foreach (down; a) {\n write(down ? 'D' : 'R');\n }\n writeln;\n stdout.flush;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable int INF = 1 << 29;\n\nbool ask(int r1, int c1, int r2, int c2) {\n if (r1 > r2 && c2 > c1) return false;\n if (r2 > r1 && c1 > c2) return false;\n if (r1 > r2 || c1 > c2) swap(r1, r2), swap(c1, c2);\n writeln(\"? \", r1+1, \" \", c1+1, \" \", r2+1, \" \", c2+1);\n stdout.flush;\n return readln.chomp == \"YES\";\n}\n\nint dist(int r1, int c1, int r2, int c2) {\n return abs(r1 - r2) + abs(c1 - c2);\n}\n\nvoid main() {\n auto N = readln.chomp.to!int;\n Tuple!(int, int)[] ans = [tuple(0, 0)];\n Tuple!(int, int)[] ans2 = [tuple(N-1, N-1)];\n\n for (int r = 0, c = 0; dist(r, c, N-1, N-1) >= N; ) {\n if (ask(r+1, c, N-1, N-1)) {\n ++r;\n } else {\n ++c;\n }\n ans ~= tuple(r, c);\n }\n\n for (int r = N-1, c = N-1, p = ans.length.to!int-2; r != ans.back[0] || c != ans.back[1]; --p) {\n if (r == ans.back[0]) {\n --c;\n } else if (c == ans.back[1]) {\n --r;\n } else if (ask(r, c-1, ans[p][0], ans[p][1])) {\n --c;\n } else {\n --r;\n }\n ans2 ~= tuple(r, c);\n }\n\n ans2.reverse;\n ans = ans ~ ans2;\n string ans_s = \"! \";\n\n foreach (i; 0..ans.length.to!int-1) {\n int r1 = ans[i][0];\n int c1 = ans[i][1];\n int r2 = ans[i+1][0];\n int c2 = ans[i+1][1];\n if (r1 == r2 && c1 == c2) continue;\n if (r1 != r2) ans_s ~= \"D\";\n else ans_s ~= \"R\";\n }\n\n writeln(ans_s);\n stdout.flush;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nbool ask (int row1, int col1, int row2, int col2)\n{\n\twriteln (\"? \", row1, \" \", col1, \" \", row2, \" \", col2);\n\tstdout.flush ();\n\tauto res = readln.strip;\n\treturn (res == \"YES\");\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\n\t\tint [2] [] a;\n\t\t{\n\t\t\tint row1 = 1;\n\t\t\tint col1 = 1;\n\t\t\tint row2 = n;\n\t\t\tint col2 = n;\n\t\t\ta ~= [row1, col1];\n\t\t\tforeach (step; 0..n - 1)\n\t\t\t{\n\t\t\t\trow1 += 1;\n\t\t\t\tif (!ask (row1, col1, row2, col2))\n\t\t\t\t{\n\t\t\t\t\trow1 -= 1;\n\t\t\t\t\tcol1 += 1;\n\t\t\t\t}\n\t\t\t\ta ~= [row1, col1];\n\t\t\t}\n\t\t}\n\n\t\tint [2] [] b;\n\t\t{\n\t\t\tint row1 = 1;\n\t\t\tint col1 = 1;\n\t\t\tint row2 = n;\n\t\t\tint col2 = n;\n\t\t\tb ~= [row2, col2];\n\t\t\tforeach (step; 0..n - 1)\n\t\t\t{\n\t\t\t\tcol2 -= 1;\n\t\t\t\tif (!ask (row1, col1, row2, col2))\n\t\t\t\t{\n\t\t\t\t\tcol2 += 1;\n\t\t\t\t\trow2 -= 1;\n\t\t\t\t}\n\t\t\t\tb ~= [row2, col2];\n\t\t\t}\n\t\t}\n\n\t\tassert (a.back == b.back);\n\t\tauto c = a ~ b.retro.drop (1).array;\n\t\twrite (\"! \");\n\t\tforeach (i; 1..c.length)\n\t\t{\n\t\t\twrite ((c[i][0] == c[i - 1][0]) ? 'R' : 'D');\n\t\t}\n\t\twriteln;\n\t\tstdout.flush ();\n\t}\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto currw = 1, curcol = 1;\n dchar[] anspref;\n foreach (_; 0 .. n-1) {\n writeln(format(\"? %s %s %s %s\", currw, curcol+1, n, n));\n stdout.flush(); \n \n auto msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anspref ~= 'R';\n curcol += 1;\n } else {\n anspref ~= 'D';\n currw += 1;\n }\n }\n \n dchar[] anssuf;\n currw = n, curcol = n;\n foreach (_; 0 .. n-1) {\n writeln(format(\"? 1 1 %s %s\", currw-1, curcol));\n stdout.flush();\n \n auto msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anssuf ~= 'D';\n currw -= 1;\n } else {\n anssuf ~= 'R';\n curcol -= 1;\n }\n }\n reverse(anssuf);\n \n auto ans = anspref ~ anssuf;\n \n writeln(\"! \", ans);\n stdout.flush();\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\ndebug {\n string[] A;\n}\n\nbool Ask(int x0, int y0, int x1, int y1) {\n assert((x1 - x0) + (y1 - y0) >= N - 1);\n bool ret;\n debug {\n if (A[x0][y0] == '.' && A[x1][y1] == '.') {\n auto dp = new bool[][](N, N);\n dp[x0][y0] = true;\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n if (dp[x][y]) {\n if (x + 1 < N && A[x + 1][y] == '.') {\n dp[x + 1][y] = true;\n }\n if (y + 1 < N && A[x][y + 1] == '.') {\n dp[x][y + 1] = true;\n }\n }\n }\n ret = dp[x1][y1];\n writefln(\"Ask %s %s %s %s = %s\", x0, y0, x1, y1, ret);\n } else {\n ret = false;\n }\n } else {\n writefln(\"? %s %s %s %s\", x0 + 1, y0 + 1, x1 + 1, y1 + 1);\n stdout.flush;\n ret = (readToken() == \"YES\");\n }\n return ret;\n}\n\nvoid main() {\n N = readInt();\n debug {\n A = new string[N];\n foreach (x; 0 .. N) {\n A[x] = readToken();\n }\n }\n \n auto diagS = new bool[N];\n auto diagT = new bool[N];\n foreach (x; 0 .. N) {\n diagS[x] = Ask(0, 0, x, N - 1 - x);\n diagT[x] = Ask(x, N - 1 - x, N - 1, N - 1);\n }\n int xm = -1;\n foreach (x; 0 .. N) {\n if (diagS[x] && diagT[x]) {\n xm = x;\n break;\n }\n }\n debug {\n writeln(\"diagS = \", diagS);\n writeln(\"diagT = \", diagT);\n writeln(\"xm = \", xm);\n }\n \n string ansS, ansT;\n for (int x = 0, y = 0; !(x == xm && y == N - 1 - xm); ) {\n if (y + 1 <= N - 1 - xm && Ask(x, y + 1, N - 1, N - 1)) {\n ++y;\n ansS = ansS ~ 'R';\n } else {\n ++x;\n ansS = ansS ~ 'D';\n }\n }\n for (int x = N - 1, y = N - 1; !(x == xm && y == N - 1 - xm); ) {\n if (x - 1 >= xm && Ask(0, 0, x - 1, y)) {\n --x;\n ansT = 'D' ~ ansT;\n } else {\n --y;\n ansT = 'R' ~ ansT;\n }\n }\n \n writefln(\"! %s%s\", ansS, ansT);\n stdout.flush;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable int INF = 1 << 29;\n\nbool ask(int r1, int c1, int r2, int c2) {\n if (r1 > r2 && c2 > c1) return false;\n if (r2 > r1 && c1 > c2) return false;\n if (r1 > r2 || c1 > c2) swap(r1, r2), swap(c1, c2);\n writeln(\"? \", r1+1, \" \", c1+1, \" \", r2+1, \" \", c2+1);\n stdout.flush;\n return readln.chomp == \"YES\";\n}\n\nint dist(int r1, int c1, int r2, int c2) {\n return abs(r1 - r2) + abs(c1 - c2);\n}\n\nvoid main() {\n auto N = readln.chomp.to!int;\n Tuple!(int, int)[] ans = [tuple(0, 0)];\n Tuple!(int, int)[] ans2 = [tuple(N-1, N-1)];\n\n for (int r = 0, c = 0; dist(r, c, N-1, N-1) >= N; ) {\n if (ask(r+1, c, N-1, N-1)) {\n ++r;\n } else {\n ++c;\n }\n ans ~= tuple(r, c);\n }\n\n for (int r = N-1, c = N-1, p = ans.length.to!int-2; r != ans.back[0] || c != ans.back[1]; --p) {\n if (r == ans.back[0]) {\n --c;\n } else if (c == ans.back[1]) {\n --r;\n } else if (ask(r-1, c, ans[p][0], ans[p][1])) {\n --r;\n } else {\n --c;\n }\n ans2 ~= tuple(r, c);\n }\n\n ans2.reverse;\n ans = ans ~ ans2;\n string ans_s = \"! \";\n\n foreach (i; 0..ans.length.to!int-1) {\n int r1 = ans[i][0];\n int c1 = ans[i][1];\n int r2 = ans[i+1][0];\n int c2 = ans[i+1][1];\n if (r1 == r2 && c1 == c2) continue;\n if (r1 != r2) ans_s ~= \"D\";\n else ans_s ~= \"R\";\n }\n\n writeln(ans_s);\n stdout.flush;\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int rw = 1;\n foreach (x; 1 .. n+1) {\n writeln(format(\"? 1 1 %s %s\", x, n+1 - x));\n stdout.flush();\n \n auto msg1 = readln.chomp;\n \n if (msg1 == \"BAD\") return;\n \n writeln(format(\"? %s %s %s %s\", x, n+1 - x, n, n));\n stdout.flush();\n \n auto msg2 = readln.chomp;\n \n if (msg2 == \"BAD\") return;\n \n if (msg1 == \"YES\" && msg2 == \"YES\") {\n rw = x;\n break;\n }\n }\n \n dchar[] anssuf;\n int currw = rw, curcol = n+1 - rw;\n foreach (_; 0 .. n-1) {\n if (curcol + 1 > n) {\n anssuf ~= 'D';\n continue;\n }\n \n writeln(format(\"? 1 1 %s %s\", currw, curcol+1));\n stdout.flush();\n \n auto msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anssuf ~= 'R';\n curcol += 1;\n } else {\n anssuf ~= 'D';\n currw += 1;\n }\n }\n \n currw = rw, curcol = n+1 - rw;\n dchar[] anspref;\n foreach (_; 0 .. n-1) {\n if (currw == 1) {\n anspref ~= 'R';\n continue;\n }\n \n writeln(format(\"? %s %s %s %s\", currw-1, curcol, n, n));\n stdout.flush(); \n \n auto msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anspref ~= 'D';\n currw -= 1;\n } else {\n anspref ~= 'R';\n curcol -= 1;\n }\n }\n reverse(anspref);\n \n auto ans = anspref ~ anssuf;\n \n writeln(\"! \", ans);\n stdout.flush();\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n string msg;\n int rw = 1;\n foreach (x; 1 .. n+1) {\n writeln(format(\"? 1 1 %s %s\", x, n+1 - x));\n stdout.flush();\n \n msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n rw = x;\n break;\n }\n }\n \n dchar[] anssuf;\n int currw = rw, curcol = n+1 - rw;\n foreach (_; 0 .. n-1) {\n if (currw + 1 > n) {\n anssuf ~= 'R';\n continue;\n }\n \n writeln(format(\"? 1 1 %s %s\", currw+1, curcol));\n stdout.flush();\n \n msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anssuf ~= 'D';\n currw += 1;\n } else {\n anssuf ~= 'R';\n curcol += 1;\n }\n }\n \n currw = rw, curcol = n+1 - rw;\n dchar[] anspref;\n foreach (_; 0 .. n-1) {\n if (currw == 1) {\n anspref ~= 'R';\n continue;\n }\n \n writeln(format(\"? %s %s %s %s\", currw-1, curcol, n, n));\n stdout.flush(); \n \n msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anspref ~= 'D';\n currw -= 1;\n } else {\n anspref ~= 'R';\n curcol -= 1;\n }\n }\n reverse(anspref);\n \n auto ans = anspref ~ anssuf;\n \n writeln(\"! \", ans);\n stdout.flush();\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n string msg;\n int rw = 1;\n foreach (x; 1 .. n+1) {\n writeln(format(\"? 1 1 %s %s\", x, n+1 - x));\n stdout.flush();\n \n msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n rw = x;\n break;\n }\n }\n \n dchar[] anssuf;\n int currw = rw, curcol = n+1 - rw;\n foreach (_; 0 .. n-1) {\n if (currw + 1 > n) {\n anssuf ~= 'R';\n continue;\n }\n \n writeln(format(\"? 1 1 %s %s\", currw+1, curcol));\n stdout.flush();\n \n msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anssuf ~= 'D';\n currw += 1;\n } else {\n anssuf ~= 'R';\n curcol += 1;\n }\n }\n \n currw = rw, curcol = n+1 - rw;\n dchar[] anspref;\n foreach (_; 0 .. n-1) {\n if (currw == 1) {\n anspref ~= 'R';\n continue;\n }\n \n writeln(format(\"? %s %s %s %s\", currw-1, curcol, n, n));\n stdout.flush(); \n \n msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anspref ~= 'D';\n currw -= 1;\n } else {\n anspref ~= 'R';\n curcol -= 1;\n }\n }\n reverse(anspref);\n \n auto ans = anspref ~ anssuf;\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n int rw = 1;\n foreach (x; 1 .. n+1) {\n writeln(format(\"? 1 1 %s %s\", x, n+1 - x));\n stdout.flush();\n \n auto msg1 = readln.chomp;\n \n if (msg1 == \"BAD\") return;\n \n writeln(format(\"? %s %s %s %s\", x, n+1 - x, n, n));\n stdout.flush();\n \n auto msg2 = readln.chomp;\n \n if (msg2 == \"BAD\") return;\n \n if (msg1 == \"YES\" && msg2 == \"YES\") {\n rw = x;\n break;\n }\n }\n \n dchar[] anssuf;\n int currw = rw, curcol = n+1 - rw;\n foreach (_; 0 .. n-1) {\n if (currw + 1 > n) {\n anssuf ~= 'R';\n continue;\n }\n \n writeln(format(\"? 1 1 %s %s\", currw+1, curcol));\n stdout.flush();\n \n auto msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anssuf ~= 'D';\n currw += 1;\n } else {\n anssuf ~= 'R';\n curcol += 1;\n }\n }\n \n currw = rw, curcol = n+1 - rw;\n dchar[] anspref;\n foreach (_; 0 .. n-1) {\n if (curcol == 1) {\n anspref ~= 'D';\n continue;\n }\n \n writeln(format(\"? %s %s %s %s\", currw, curcol-1, n, n));\n stdout.flush(); \n \n auto msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anspref ~= 'R';\n curcol -= 1;\n } else {\n anspref ~= 'D';\n currw -= 1;\n }\n }\n reverse(anspref);\n \n auto ans = anspref ~ anssuf;\n \n writeln(\"! \", ans);\n stdout.flush();\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto currw = 1, curcol = 1;\n dchar[] anspref;\n foreach (_; 0 .. n-1) {\n writeln(format(\"? %s %s %s %s\", currw, curcol+1, n, n));\n stdout.flush(); \n \n auto msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anspref ~= 'R';\n curcol -= 1;\n } else {\n anspref ~= 'D';\n currw -= 1;\n }\n }\n \n dchar[] anssuf;\n currw = n, curcol = n;\n foreach (_; 0 .. n-1) {\n writeln(format(\"? 1 1 %s %s\", currw-1, curcol));\n stdout.flush();\n \n auto msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anssuf ~= 'D';\n currw += 1;\n } else {\n anssuf ~= 'R';\n curcol += 1;\n }\n }\n reverse(anssuf);\n \n auto ans = anspref ~ anssuf;\n \n writeln(\"! \", ans);\n stdout.flush();\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n string msg;\n int rw = 1;\n foreach (x; 1 .. n+1) {\n writeln(format(\"? 1 1 %s %s\", x, n+1 - x));\n stdout.flush();\n \n auto msg1 = readln.chomp;\n \n if (msg1 == \"BAD\") return;\n \n writeln(format(\"? %s %s %s %s\", x, n+1 - x, n, n));\n stdout.flush();\n \n auto msg2 = readln.chomp;\n \n if (msg2 == \"BAD\") return;\n \n if (msg1 == \"YES\" && msg2 == \"YES\") {\n rw = x;\n break;\n }\n }\n \n dchar[] anssuf;\n int currw = rw, curcol = n+1 - rw;\n foreach (_; 0 .. n-1) {\n if (currw + 1 > n) {\n anssuf ~= 'R';\n continue;\n }\n \n writeln(format(\"? 1 1 %s %s\", currw+1, curcol));\n stdout.flush();\n \n msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anssuf ~= 'D';\n currw += 1;\n } else {\n anssuf ~= 'R';\n curcol += 1;\n }\n }\n \n currw = rw, curcol = n+1 - rw;\n dchar[] anspref;\n foreach (_; 0 .. n-1) {\n if (currw == 1) {\n anspref ~= 'R';\n continue;\n }\n \n writeln(format(\"? %s %s %s %s\", currw-1, curcol, n, n));\n stdout.flush(); \n \n msg = readln.chomp;\n \n if (msg == \"BAD\") return;\n \n if (msg == \"YES\") {\n anspref ~= 'D';\n currw -= 1;\n } else {\n anspref ~= 'R';\n curcol -= 1;\n }\n }\n reverse(anspref);\n \n auto ans = anspref ~ anssuf;\n \n writeln(\"! \", ans);\n stdout.flush();\n}"}, {"source_code": "import std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\n\nstruct seg\n{\n int l = int.max;\n int r;\n}\n\nbool ask(int r, int c, int r1, int c1)\n{\n writefln(\"? %d %d %d %d\", r, c, r1, c1);\n stdout.flush;\n return \"YES\" == readln.chomp;\n}\n\nvoid main()\n{\n int n;\n readf(\"%d\\n\", &n);\n bool[] a;\n a.length = 2 * n - 2;\n int r = 1, c = 1;\n foreach (i; 0..n - 1) {\n ++r;\n a[i] = ask(r, c, n, n);\n if (!a[i]) {\n --r;\n ++c;\n }\n }\n r = c = n;\n foreach (i; 1..n) {\n --c;\n a[$ - i] = !ask(1, 1, r, c);\n if (a[$ - i]) {\n ++c;\n --r;\n }\n }\n foreach (down; a) {\n write(down ? 'D' : 'R');\n }\n writeln;\n stdout.flush;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\ndebug {\n string[] A;\n}\n\nint Ask(int x0, int y0, int x1, int y1) {\n bool ret;\n debug {\n if (A[x0][y0] == '.' && A[x1][y1] == '.') {\n auto dp = new bool[][](N, N);\n dp[x0][y0] = true;\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n if (dp[x][y]) {\n if (x + 1 < N && A[x + 1][y] == '.') {\n dp[x + 1][y] = true;\n }\n if (y + 1 < N && A[x][y + 1] == '.') {\n dp[x][y + 1] = true;\n }\n }\n }\n ret = dp[x1][y1];\n } else {\n ret = false;\n }\n } else {\n writefln(\"? %s %s %s %s\", x0 + 1, y0 + 1, x1 + 1, y1 + 1);\n stdout.flush;\n ret = (readToken() == \"YES\");\n }\n return ret;\n}\n\nvoid main() {\n N = readInt();\n debug {\n A = new string[N];\n foreach (x; 0 .. N) {\n A[x] = readToken();\n }\n }\n \n string ans;\n for (int x = 0, y = 0; !(x == N - 1 && y == N - 1); ) {\n if (x + y + 1 <= N - 1) {\n if (x + 1 < N && Ask(x + 1, y, N - 1, N - 1)) {\n ++x;\n ans ~= 'D';\n } else {\n ++y;\n ans ~= 'R';\n }\n } else {\n if (x + 1 < N && Ask(0, 0, x + 1, y)) {\n ++x;\n ans ~= 'D';\n } else {\n ++y;\n ans ~= 'R';\n }\n }\n }\n writefln(\"! %s\", ans);\n stdout.flush;\n}\n"}], "src_uid": "fe8734346e123981279747ac26d5a35b"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new string[N];\n auto B = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readToken();\n B[i] = readInt();\n }\n \n bool[string] app;\n foreach (i; 0 .. N) {\n app[A[i]] = true;\n }\n string dummy;\n for (int a = 10^^5 + 1; ; ++a) {\n if (a.to!string !in app) {\n dummy = a.to!string;\n break;\n }\n }\n \n const E = B.sum;\n auto ss = new string[N];\n int[string] tr;\n foreach (u; 0 .. N) {\n ss[u] = (u + 1).to!string;\n tr[ss[u]] = u;\n }\n \n // 0: vacant, 1: done, 2: need change\n auto status = new int[N];\n auto iss = new int[][2];\n foreach (i; 0 .. N) {\n if (A[i] in tr) {\n const u = tr[A[i]];\n status[u] = ((B[i] == 1) == (u < E)) ? 1 : 2;\n } else {\n iss[B[i]] ~= i;\n }\n }\n debug {\n writeln(\"status = \", status);\n writeln(\"iss = \", iss);\n }\n \n auto vacant = new DList!int[2];\n auto change = new DList!int[2];\n foreach (u; 0 .. N) {\n const b = (u < E) ? 1 : 0;\n if (status[u] == 0) vacant[b] ~= u;\n if (status[u] == 2) change[b] ~= u;\n }\n \n string[][] ans;\n int b0 = -1;\n \n if (vacant[0].empty && vacant[1].empty) {\n foreach (b; 0 .. 2) {\n if (!change[b].empty) {\n const u = change[b].back;\n change[b].removeBack;\n vacant[b] ~= u;\n ans ~= [ss[u], dummy];\n b0 = b;\n break;\n }\n }\n }\n \n for (; ; ) {\n bool upd;\n foreach (b; 0 .. 2) {\n if (!change[b].empty) {\n const u = change[b].back;\n if (!vacant[b ^ 1].empty) {\n const v = vacant[b ^ 1].back;\n change[b].removeBack;\n vacant[b ^ 1].removeBack;\n vacant[b] ~= u;\n ans ~= [ss[u], ss[v]];\n upd = true;\n break;\n }\n }\n }\n if (!upd) {\n break;\n }\n }\n \n if (b0 != -1) {\n assert(!vacant[b0 ^ 1].empty);\n const v = vacant[b0 ^ 1].back;\n vacant[b0 ^ 1].removeBack;\n ans ~= [dummy, ss[v]];\n }\n \n foreach (b; 0 .. 2) {\n foreach (i; iss[b]) {\n assert(!vacant[b].empty);\n const v = vacant[b].back;\n vacant[b].removeBack;\n ans ~= [A[i], ss[v]];\n }\n }\n \n writeln(ans.length);\n foreach (row; ans) {\n writeln(\"move \", row[0], \" \", row[1]);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto name = new string [n];\n\t\tauto isExample = new bool [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto t = readln.split;\n\t\t\tname[i] = t[0];\n\t\t\tisExample[i] = t[1].to !(int).to !(bool);\n\t\t}\n\n\t\tbool [string] [2] p;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tp[!isExample[i]][name[i]] = true;\n\t\t}\n\t\tint examples = isExample.sum;\n\n\t\tstring [] [4] [2] e;\n\t\tstring temp = \"\";\n\t\tstring tempDefault = (n + 1).text;\n\t\tforeach (num; 1..examples + 1)\n\t\t{\n\t\t\tauto str = num.text;\n\t\t\tif (str in p[0])\n\t\t\t{\n\t\t\t\te[0][0] ~= str;\n\t\t\t\tp[0][str] = false;\n\t\t\t}\n\t\t\telse if (str in p[1])\n\t\t\t{\n\t\t\t\te[1][1] ~= str;\n\t\t\t\tp[1][str] = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\te[0][3] ~= str;\n\t\t\t\ttemp = str;\n\t\t\t}\n\t\t}\n\t\tforeach (num; examples + 1..n + 1)\n\t\t{\n\t\t\tauto str = num.text;\n\t\t\tif (str in p[1])\n\t\t\t{\n\t\t\t\te[1][0] ~= str;\n\t\t\t\tp[1][str] = false;\n\t\t\t}\n\t\t\telse if (str in p[0])\n\t\t\t{\n\t\t\t\te[0][1] ~= str;\n\t\t\t\tp[0][str] = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\te[1][3] ~= str;\n\t\t\t\ttemp = str;\n\t\t\t}\n\t\t}\n\t\tif (temp == \"\")\n\t\t{\n\t\t\ttemp = tempDefault;\n\t\t}\n\t\tassert (temp != \"\" && !name.canFind (temp));\n\t\tforeach (k, v; p[0])\n\t\t{\n\t\t\tif (v)\n\t\t\t{\n\t\t\t\te[0][2] ~= k;\n\t\t\t}\n\t\t}\n\t\tforeach (k, v; p[1])\n\t\t{\n\t\t\tif (v)\n\t\t\t{\n\t\t\t\te[1][2] ~= k;\n\t\t\t}\n\t\t}\n\n\t\tstring [] [] ans;\n\t\twhile (!e[0][1].empty || !e[0][2].empty ||\n\t\t !e[1][1].empty || !e[1][2].empty)\n\t\t{\n\t\t\tdebug {writefln (\"%(%s\\n%)\\n%s\", e, temp);}\n\t\t\tif (e[0][3].empty && e[1][3].empty)\n\t\t\t{\n\t\t\t\tassert (temp == tempDefault);\n\t\t\t\tif (!e[0][1].empty)\n\t\t\t\t{\n\t\t\t\t\tans ~= [e[0][1].front, temp];\n\t\t\t\t\te[0][2].assumeSafeAppend ();\n\t\t\t\t\te[0][2] ~= temp;\n\t\t\t\t\te[1][3].assumeSafeAppend ();\n\t\t\t\t\te[1][3] ~= e[0][1].front;\n\t\t\t\t\te[0][1].popFront ();\n\t\t\t\t}\n\t\t\t\telse if (!e[1][1].empty)\n\t\t\t\t{\n\t\t\t\t\tans ~= [e[1][1].front, temp];\n\t\t\t\t\te[1][2].assumeSafeAppend ();\n\t\t\t\t\te[1][2] ~= temp;\n\t\t\t\t\te[0][3].assumeSafeAppend ();\n\t\t\t\t\te[0][3] ~= e[1][1].front;\n\t\t\t\t\te[1][1].popFront ();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tassert (false);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (!e[0][3].empty)\n\t\t\t\t{\n\t\t\t\t\tif (!e[0][1].empty)\n\t\t\t\t\t{\n\t\t\t\t\t\tans ~= [e[0][1].front,\n\t\t\t\t\t\t e[0][3].front];\n\t\t\t\t\t\te[0][0].assumeSafeAppend ();\n\t\t\t\t\t\te[0][0] ~= e[0][3].front;\n\t\t\t\t\t\te[1][3].assumeSafeAppend ();\n\t\t\t\t\t\te[1][3] ~= e[0][1].front;\n\t\t\t\t\t\te[0][1].popFront ();\n\t\t\t\t\t\te[0][3].popFront ();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tans ~= [e[0][2].front,\n\t\t\t\t\t\t e[0][3].front];\n\t\t\t\t\t\te[0][0].assumeSafeAppend ();\n\t\t\t\t\t\te[0][0] ~= e[0][3].front;\n\t\t\t\t\t\te[0][2].popFront ();\n\t\t\t\t\t\te[0][3].popFront ();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (!e[1][3].empty)\n\t\t\t\t{\n\t\t\t\t\tif (!e[1][1].empty)\n\t\t\t\t\t{\n\t\t\t\t\t\tans ~= [e[1][1].front,\n\t\t\t\t\t\t e[1][3].front];\n\t\t\t\t\t\te[1][0].assumeSafeAppend ();\n\t\t\t\t\t\te[1][0] ~= e[1][3].front;\n\t\t\t\t\t\te[0][3].assumeSafeAppend ();\n\t\t\t\t\t\te[0][3] ~= e[1][1].front;\n\t\t\t\t\t\te[1][1].popFront ();\n\t\t\t\t\t\te[1][3].popFront ();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tans ~= [e[1][2].front,\n\t\t\t\t\t\t e[1][3].front];\n\t\t\t\t\t\te[1][0].assumeSafeAppend ();\n\t\t\t\t\t\te[1][0] ~= e[1][3].front;\n\t\t\t\t\t\te[1][2].popFront ();\n\t\t\t\t\t\te[1][3].popFront ();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tassert (false);\n\t\t\t\t}\n\t \t}\n\t\t}\n\t\tdebug {writefln (\"%(%s\\n%)\\n%s\", e, temp);}\n\n\t\twriteln (ans.length);\n\t\tforeach (c; ans)\n\t\t{\n\t\t\twritefln (\"move %-(%s %)\", c);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "b755d530eb1704f2b990248c1239e8f4"} {"source_code": "import core.bitop;\r\nimport std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int mod = 10 ^^ 9 + 7;\r\nimmutable int limit = 32;\r\n\r\nvoid add (ref int a, int b)\r\n{\r\n\ta += b;\r\n\tif (a >= mod)\r\n\t{\r\n\t\ta -= mod;\r\n\t}\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = new int [limit];\r\n\t\tforeach (ref x; a)\r\n\t\t{\r\n\t\t\tc[x.bsf] += 1;\r\n\t\t}\r\n\r\n\t\tauto p2 = [1];\r\n\t\twhile (p2.length <= n)\r\n\t\t{\r\n\t\t\tp2 ~= (p2.back << 1) % mod;\r\n\t\t}\r\n\r\n\t\tint bads = 0;\r\n\t\tint k = n - c[0];\r\n\t\tforeach (i; 1..limit)\r\n\t\t{\r\n\t\t\tif (c[i] > 0)\r\n\t\t\t{\r\n\t\t\t\tauto cur = p2[k - 1];\r\n\t\t\t\tadd (bads, cur);\r\n\t\t\t\tk -= c[i];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint res = p2[n];\r\n\t\tadd (res, mod - 1 - bads);\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt(uint M_) {\n import std.conv : to;\n alias M = M_;\n uint x;\n this(ModInt a) { x = a.x; }\n this(uint x_) { x = x_ % M; }\n this(ulong x_) { x = x_ % M; }\n this(int x_) { x = ((x_ %= cast(int)(M)) < 0) ? (x_ + cast(int)(M)) : x_; }\n this(long x_) { x = cast(uint)(((x_ %= cast(long)(M)) < 0) ? (x_ + cast(long)(M)) : x_); }\n ref ModInt opAssign(T)(inout(T) a) if (is(T == uint) || is(T == ulong) || is(T == int) || is(T == long)) { return this = ModInt(a); }\n ref ModInt opOpAssign(string op, T)(T a) {\n static if (is(T == ModInt)) {\n static if (op == \"+\") { x = ((x += a.x) >= M) ? (x - M) : x; }\n else static if (op == \"-\") { x = ((x -= a.x) >= M) ? (x + M) : x; }\n else static if (op == \"*\") { x = cast(uint)((cast(ulong)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n } else static if (op == \"^^\") {\n if (a < 0) return this = inv()^^(-a);\n ModInt b = this, c = 1U;\n for (long e = a; e; e >>= 1) { if (e & 1) c *= b; b *= b; }\n return this = c;\n } else {\n return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n }\n ModInt inv() const {\n uint a = M, b = x; int y = 0, z = 1;\n for (; b; ) { const q = a / b; const c = a - q * b; a = b; b = c; const w = y - cast(int)(q) * z; y = z; z = w; }\n assert(a == 1); return ModInt(y);\n }\n ModInt opUnary(string op)() const {\n static if (op == \"+\") { return this; }\n else static if (op == \"-\") { ModInt a; a.x = x ? (M - x) : 0U; return a; }\n else static assert(false);\n }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op, T)(T a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n bool opCast(T: bool)() const { return (x != 0U); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 7;\nalias Mint = ModInt!MO;\n\nenum LIM = 4 * 10^^5 + 10;\nMint[] inv, fac, invFac;\nvoid prepare() {\n inv = new Mint[LIM];\n fac = new Mint[LIM];\n invFac = new Mint[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = -((Mint.M / i) * inv[cast(size_t)(Mint.M % i)]);\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = fac[i - 1] * i;\n invFac[i] = invFac[i - 1] * inv[i];\n }\n}\nMint binom(long n, long k) {\n if (n < 0) {\n if (k >= 0) {\n return (-1)^^(k & 1) * binom(-n + k - 1, k);\n } else if (n - k >= 0) {\n return (-1)^^((n - k) & 1) * binom(-k - 1, n - k);\n } else {\n return Mint(0);\n }\n } else {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\n } else {\n return Mint(0);\n }\n }\n}\n\n\nenum E = 30;\n\nvoid main() {\n prepare;\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto cnt = new int[E];\n foreach (i; 0 .. N) {\n ++cnt[bsf(A[i])];\n }\n \n Mint ans = Mint(2)^^N;\n ans -= 1;\n foreach (e; 1 .. E) {\n if (cnt[e] > 0) {\n int sum = cnt[e] - 1;\n foreach (f; e + 1 .. E) {\n sum += cnt[f];\n }\n ans -= Mint(2)^^sum;\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "// \u63d0\u51fa\u89e3\r\nconst long p = 1_000_000_007;\r\nvoid solve(){\r\n\tint n = scan!int;\r\n\tlong[] as = scan!long(n);\r\n\r\n\tint[] cnt = new int[](100);\r\n\tforeach(a; as){\r\n\t\tint c = 0;\r\n\t\tlong x = a;\r\n\t\twhile(x % 2 == 0) x /= 2, c += 1;\r\n\t\tcnt[c] += 1;\r\n\t}\r\n\tlog(\"cnt:\", cnt);\r\n\r\n\tlong[] pow2 = [1];\r\n\tforeach(i; 0 .. n + 1) pow2 ~= pow2[$ - 1] * 2 % p;\r\n\tlog(\"pow2:\", pow2);\r\n\r\n\tlong[] inv = [0, 1];\r\n\tforeach(i; 2 .. n + 1) inv ~= inv[p % i] * (p - p / i) % p;\r\n\tlog(\"inv:\", inv);\r\n\r\n\tlong[] perm = [1, 1], invperm = [1, 1];\r\n\tforeach(i; 2 .. n + 1){\r\n\t\tperm ~= perm[$ - 1] * i % p;\r\n\t\tinvperm ~= invperm[$ - 1] * inv[i] % p;\r\n\t}\r\n\tlog(\"perm:\", perm);\r\n\tlog(\"invperm:\", invperm);\r\n\r\n\tint left = n;\r\n\tlong ans;\r\n\r\n\tlong f(int x){\r\n\t\tlong res;\r\n\t\tif(x == 0) return 0;\r\n\t\telse res = pow2[x] * inv[2] % p;\r\n\t\tres += p - 1, res %= p;\r\n\t\tlog(\"res:\", res);\r\n\t\treturn res;\r\n\t}\r\n\r\n\tans += (pow2[cnt[0]] + p - 1) % p * pow2[left -= cnt[0]] % p, ans %= p;\r\n\tlog(\"i: 0\", \"ans:\", ans);\r\n\r\n\tforeach(i; 1 .. 100){\r\n\t\tans += f(cnt[i]) * pow2[left -= cnt[i]] % p, ans %= p;\r\n\t\tlog(\"i:\", i, \"ans:\", ans);\r\n\t}\r\n\r\n\tans.print;\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u611a\u76f4\u89e3\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30f3\u30d7\u30ec\r\nimport std;\r\nbool DEBUG = 0;\r\nvoid main(string[] args){\r\n\tif(args.canFind(\"-debug\")) DEBUG = 1;\r\n\tif(args.canFind(\"-gen\")) gen; else if(args.canFind(\"-jury\")) jury; else solve;\r\n}\r\nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\r\nvoid print(){ writeln(\"\"); }\r\nvoid print(T)(T t){ writeln(t); }\r\nvoid print(T, A ...)(T t, A a){ stdout.write(t, \" \"), print(a); }\r\nstring unsplit(T)(T xs, string d = \" \"){ return xs.array.to!(string[]).join(d); }\r\nstring scan(){\r\n\tstatic string[] ss; while(!ss.length) ss = readln.chomp.split;\r\n\tstring res = ss[0]; ss.popFront; return res;\r\n}\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\r\nT mini(T)(ref T x, T y){ if(x > y) x = y; return x; }\r\nT maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }\r\nT mid(T)(T l, T r, bool delegate(T) f){\r\n\tT m = (l + r) / 2; (f(m)? l: r) = m; return f(l)? f(r - 1)? r: mid(l, r, f): l;\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u57fa\u672c\uff09\r\n\r\nclass UnionFind{\r\n\tthis(int n){ foreach(i; 0 .. n) R ~= i, K ~= [i]; } int[] R; int[][] K;\r\n\tvoid unite(int a, int b){\r\n\t\tint ra = R[a], rb = R[b]; if(ra == rb) return;\r\n\t\tif(K[ra].length < K[rb].length) unite(b, a);\r\n\t\telse foreach(k; K[rb]) R[k] = ra, K[ra] ~= k;\r\n\t}\r\n\tint find(int a){ return R[a]; }\r\n\tint getSize(int a){ return K[R[a]].length.to!int; }\r\n}\r\nclass Queue(T){\r\n\tprivate T[] xs; private uint i, j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j - i; }\r\n\tbool isEmpty(){ return j == i; } \r\n\tvoid enq(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT deq(){ assert(i < j); return xs[i ++]; }\r\n\tT peek(){ assert(i < j); return xs[i]; }\r\n\tvoid flush(){ i = j; }\r\n\talias empty = isEmpty, front = peek, popFront = deq, pop = deq, push = enq, top = peek;\r\n\tQueue opOpAssign(string op)(T x) if(op == \"~\"){ enq(x); return this; }\r\n\tT opIndex(uint li){ assert(i + li < j); return xs[i + li]; }\r\n\tstatic Queue!T opCall(T[] xs){ return new Queue!T(xs); }\r\n\tT[] array(){ return xs[i .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\nclass Stack(T){\r\n\tprivate T[] xs; private uint j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j; }\r\n\tbool isEmpty(){ return j == 0; }\r\n\tvoid push(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT pop(){ assert(j > 0); return xs[-- j]; }\r\n\tT peek(){ assert(j > 0); return xs[j - 1]; }\r\n\tvoid clear(){ j = 0; }\r\n\talias empty = isEmpty, front = peek, popFront = pop, top = peek;\r\n\tStack opOpAssign(string op)(T x) if(op == \"~\"){ push(x); return this; }\r\n\tT opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }\r\n\tstatic Stack!T opCall(T[] xs = []){ return new Stack!T(xs); }\r\n\tT[] array(){ return xs[0 .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u8ffd\u52a0\uff09\r\n\r\n\r\n"}], "negative_code": [], "src_uid": "1d58ae45a677023dc8fd6c9473a89737"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\n// From: https://rosettacode.org/wiki/Sieve_of_Eratosthenes#D\n/// Extensible Sieve of Eratosthenes.\nstruct Prime {\n uint[] a = [2];\n private void grow() pure nothrow @safe {\n immutable p0 = a[$ - 1] + 1;\n auto b = new bool[p0];\n \n foreach (immutable di; a) {\n immutable uint i0 = p0 / di * di;\n uint i = (i0 < p0) ? i0 + di - p0 : i0 - p0;\n for (; i < b.length; i += di)\n b[i] = true;\n }\n foreach (immutable uint i, immutable bi; b)\n if (!b[i])\n a ~= p0 + i;\n }\n uint opCall(in uint n) pure nothrow @safe {\n while (n >= a.length)\n grow;\n return a[n];\n }\n}\n\nvoid main()\n{\n Prime pgen;\n auto primes = uint.max.iota.map!pgen.until!q{a > 100000}.array;\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n foreach (m ; primes) {\n if (primes.assumeSorted.contains(n + m))\n continue;\n writeln(m);\n break;\n }\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n = read!int;\r\n if (n == 2)\r\n writeln(7);\r\n else\r\n writeln(3);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\twriteln (n == 2 ? 2 : 3);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "b7e36ca8a96dd7951359070d4953beec"} {"source_code": "// cheese-cracker [2022-02-12]\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n auto dup = arr.dup;\n dup.sort;\n bool f = 0;\n for(int i = 0; i < n; ++i){\n if(dup[i] != arr[i]){\n f = 1;\n break;\n }\n }\n if(f){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (isSorted (a) ? \"NO\" : \"YES\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tif (a[i] > a[i+1])\r\n\t\t\t\tans[ti] = true;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10L^^18;\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n \n auto ls = new long[N + 1];\n auto rs = new long[N + 1];\n ls[0] = -INF;\n foreach (i; 0 .. N) {\n ls[i + 1] = max(ls[i], A[i]);\n }\n rs[N] = +INF;\n foreach_reverse (i; 0 .. N) {\n rs[i] = min(A[i], rs[i + 1]);\n }\n \n bool ans;\n foreach (i; 1 .. N) {\n ans = ans || (ls[i] > rs[i]);\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "ef1448a744f67347183479c697aa87e1"} {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto u = new bool[N];\n int c;\n foreach (i; 0 .. N) {\n int x; scanf(\"%d\", &x);\n x--;\n if (x >= N) c++;\n else if (u[x]) c++;\n u[x] = true;\n }\n writeln(c);\n}\n", "positive_code": [{"source_code": "module cf_137B;\n\nimport std.stdio, std.algorithm;\n\nvoid main() {\n\tint n;\n\tint[] numbers;\n\n\treadf(\"%d\", &n);\n\tnumbers = new int[n];\n\tfor (auto i = 0; i < n; ++i) {\n\t\treadf(\" %d\", &numbers[i]);\n\t}\n\n\tsort(numbers);\n\t\n\tint skip = 0, index = 0;\n\tfor (auto i = 1; i <= n; ++i) {\n\t\tif (index >= n) {\n\t\t\t++skip;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (numbers[index] == i) {\n\t\t\twhile (index < n && numbers[index] == i) {\n\t\t\t\t++index;\n\t\t\t}\n\t\t} else {\n\t\t\t++skip;\n\t\t}\n\t}\n\n\twriteln(skip);\n}"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int n_Cases = 1;\n // n_Cases = cin.readInt;\n \n\tfor (int case_i = 1; case_i <= n_Cases; case_i++) {\n int n = cin.readInt;\n int[] arr = new int[n];\n bool[5001] present = false;\n foreach (ref i; arr) {\n i = cin.readInt;\n present[i] = true;\n }\n int ans = 0;\n for (int i = 1; i <= n; i++) ans += !present[i]; \t\n writeln(ans);\n }\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n xs = xs.sort.uniq.array;\n writeln(N - xs.length);\n}\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.random;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto u = new bool[N];\n int c;\n foreach (i; 0 .. N) {\n int x; scanf(\"%d\", &x);\n x--;\n if (x >= N) c++;\n if (u[x]) c++;\n u[x] = true;\n }\n writeln(c);\n}\n"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int n_Cases = 1;\n // n_Cases = cin.readInt;\n \n\tfor (int case_i = 1; case_i <= n_Cases; case_i++) {\n int n = cin.readInt;\n int[] arr = new int[n];\n int maxx = -9999;\n bool[5001] present = false;\n foreach (ref i; arr) {\n i = cin.readInt;\n maxx = max(maxx, i);\n present[i] = true;\n }\n int ans = 0;\n for (int i = 1; i <= maxx; i++) ans += !present[i]; \t\n writeln(ans);\n }\n}"}], "src_uid": "bdd86c8bc54bbac6e2bb5a9d68b6eb1c"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto M = scan!int;\r\n\r\n auto rect = GridPoint(M, N);\r\n auto q = DList!GridPoint();\r\n q.insert(GridPoint(M / 2, N / 2));\r\n if (M % 2 == 0) q.insert(GridPoint(M / 2 - 1, N / 2));\r\n if (N % 2 == 0) q.insert(GridPoint(M / 2, N / 2 - 1));\r\n if (M % 2 == 0 && N % 2 == 0) q.insert(GridPoint(M / 2 - 1, N / 2 - 1));\r\n\r\n auto visited = new bool[][](N, M);\r\n // foreach(c; q.array) visited[c.y][c.x] = true;\r\n\r\n long[] acc;\r\n acc ~= q.array.length;\r\n while(!q.empty) {\r\n bool[GridPoint] nex;\r\n\r\n while(!q.empty) {\r\n auto p = q.front; q.removeFront;\r\n if (p.of(visited)) continue;\r\n visited[cast(int)p.y][cast(int)p.x] = true;\r\n\r\n foreach(a; p.around(rect)) {\r\n if (a.of(visited)) continue;\r\n\r\n nex[a] = true;\r\n }\r\n nex.remove(p);\r\n }\r\n\r\n acc ~= acc[$ - 1] + nex.length;\r\n q.insert(nex.keys);\r\n }\r\n // acc.deb;\r\n\r\n long[] ans;\r\n auto center = GridPoint(M / 2, N / 2);\r\n long distance = center.y + center.x;\r\n int t;\r\n foreach(k; 0..N * M) {\r\n if (acc[t] <= k) {\r\n distance++;\r\n t++;\r\n }\r\n ans ~= distance;\r\n }\r\n return ans.toAnswerString;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nstruct GridPoint {\r\n static enum ZERO = GridPoint(0, 0);\r\n long x, y;\r\n \r\n static GridPoint reversed(long y, long x) {\r\n return GridPoint(x, y);\r\n }\r\n \r\n this(long x, long y) {\r\n this.x = x;\r\n this.y = y;\r\n }\r\n \r\n inout GridPoint left() { return GridPoint(x - 1, y); }\r\n inout GridPoint right() { return GridPoint(x + 1, y); }\r\n inout GridPoint up() { return GridPoint(x, y - 1); }\r\n inout GridPoint down() { return GridPoint(x, y + 1); }\r\n inout GridPoint leftUp() { return GridPoint(x - 1, y - 1); }\r\n inout GridPoint leftDown() { return GridPoint(x - 1, y + 1); }\r\n inout GridPoint rightUp() { return GridPoint(x + 1, y - 1); }\r\n inout GridPoint rightDown() { return GridPoint(x + 1, y + 1); }\r\n inout GridPoint[] around() { return [left(), up(), right(), down()]; }\r\n inout GridPoint[] around(GridPoint max) { GridPoint[] ret; if (x > 0) ret ~= left; if(x < max.x-1) ret ~= right; if(y > 0) ret ~= up; if(y < max.y-1) ret ~= down; return ret; }\r\n inout T of(T)(inout ref T[][] grid) { return grid[cast(int)y][cast(int)x]; }\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint rows, cols;\r\n\t\treadf !(\" %s %s\") (rows, cols);\r\n\t\tint [] s;\r\n\t\tforeach (row; 0..rows)\r\n\t\t{\r\n\t\t\tforeach (col; 0..cols)\r\n\t\t\t{\r\n\t\t\t\ts ~= max (row, rows - row - 1) +\r\n\t\t\t\t max (col, cols - col - 1);\r\n\t\t\t}\r\n\t\t}\r\n\t\tsort (s);\r\n\t\twritefln !(\"%(%s %)\") (s);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "dc1dc5e5dd17d19760c772739ce244a7"} {"source_code": "import std.stdio;\n\nvoid main() {\n long t, n, m;\n readf!\"%d\\n\"(t);\n \n while (t--) {\n readf!\"%d %d\\n\"(n, m);\n\n long cycle_len = 1;\n long cycle_sum = 0;\n while ((cycle_len * m) % 10) {\n cycle_sum += (cycle_len++ * m) % 10;\n }\n cycle_len *= m;\n\n long total = (n / cycle_len) * cycle_sum;\n\n for (int i = 1; i <= (n % cycle_len) / m; i++)\n total += (i * m) % 10;\n \n writeln(total);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto q = RD!int;\n\tauto ans = new long[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD;\n\t\tauto m = RD;\n\t\tlong[] a = [0];\n\t\twhile ((a.back + m) % 10 != 0)\n\t\t{\n\t\t\ta ~= (a.back + m) % 10;\n\t\t}\n\t\ta.popFront;\n\t\ta ~= 0;\n\t\tauto x = a.sum;\n\t\tauto y = n / m;\n\t\tlong z1, z2;\n\t\tif (y != 0)\n\t\t{\n\t\t\tz1 = y / a.length;\n\t\t\tz2 = y % a.length;\n\t\t}\n\t\tans[i] = z1 * x + a[0..cast(int)z2].sum;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "9964bfdcfdd041b839ce120019e8220f"} {"source_code": "pure Tuple!(int, int) F(Tuple!(int, int) a, Tuple!(int, int) b) { return a > b? a : b; }\npure Tuple!(int, int) FoU(Tuple!(int, int) mx, Tuple!(int, int) st, size_t l) { return st; }\npure Tuple!(int, int) UoU(Tuple!(int, int) nw, Tuple!(int, int) ld) { return nw; }\n\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(Tuple!(int, int), Tuple!(int, int))\n\t\t.Type!(tuple(0, -1), \n\t\t\t\tF, FoU, UoU,\n\t\t\t\t\"max\", \"+\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st[range[0] .. range[1] + 1].max);\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] += tuple(dpi[0], cast(int)i);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\ntemplate STL(V, U)\n{\n\tstruct Type (V neutral, alias f, \n\t\t\talias fou, \n\t\t\talias uou, \n\t\t\tstring fName = \"f\", string uName = \"u\")\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t\tsize_t length = 0;\n\t\tint layers = 0;\n\t\tthis(size_t n, V v)\n\t\t{\n\t\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\t\tauto fn = n;\n\t\t\twhile (fn) {layers++; fn >>= 1;}\n\t\t\tlength = n;\n\t\t\tauto noNodes = 2 * n; \n\t\t\t_nF = new V[](noNodes); \n\t\t\tstatic if (neutral != V.init) _nF[n .. 2 * n] = v;\n\t\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t\t_nSz[n .. 2 * n] = 1;\n\t\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\t}\n\t\tvoid _clearU(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tauto li = layers - 1;\n\t\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t\t}\n\t\tvoid _refresh(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tl >>= 1; r >>= 1;\n\t\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t\t}\n\t\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t}\n\t\tV rangeF(size_t l, size_t r)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\t_clearU(l, r);\n\t\t\tV value = neutral;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tvoid rangeU(size_t l, size_t r, U u)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\tauto ol = l, or = r;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) _addU(l++, u); \n\t\t\t\tif (r & 1) _addU(--r, u);\n\t\t\t}\n\t\t\t_refresh(ol, or);\n\t\t}\n\t\tV _getNodeF(size_t i)\n\t\t{\n\t\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\t\treturn _nF[i];\n\t\t}\n\t\tbool _isLeaf(size_t i)\n\t\t{\n\t\t\treturn i >= length;\n\t\t}\n\t\tvoid _clearU(size_t i)\n\t\t{\n\t\t\tif (!_nHasU[i]) return;\n\t\t\tif (_isLeaf(i))\n\t\t\t{\n\t\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t\t_nHasU[i] = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nHasU[i] = false;\n\t\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t\t}\n\t\tvoid _addU(size_t i, U u)\n\t\t{\n\t\t\tif (!_nHasU[i])\n\t\t\t{\n\t\t\t\t_nU[i] = u;\n\t\t\t\t_nHasU[i] = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t\t{\n\t\t\treturn [cast(int)start, cast(int)end];\n\t\t}\n\t\tauto opIndex(int[2] slice)\n\t\t{\n\t\t\talias Parent = typeof(this);\n\t\t\tstruct Ans\n\t\t\t{\n\t\t\t\tParent* parent;\n\t\t\t\tint[2] slice;\n\t\t\t\tmixin(q{V }, fName, q{;});\n\t\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t\t{\n\t\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t\t}\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int).Type!(0, \n\t\t\t(v1, v2) => v1 + v2,\n\t\t\t(v, u, size_t l) => v + u * cast(int)l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart[i .. j] += v;\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n", "positive_code": [{"source_code": "\nimmutable multi = false;\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(int[2], \"max\", \"set\", [0, -1]);\n\tauto st = SegTree(noPoints, [0, -1]);\n\tauto dp = new int[2][](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = [0, -1];\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] = [dpi[0], cast(int)i];\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\timport std.traits;\n\tstatic pure bool isSingular(T)(T t)\n\t{\n\t\tpragma(inline, true);\n\t\tstatic if (isNumeric!T) return t == T.min;\n\t\telse return t[0] == typeof(t[0]).min;\n\t}\n\tstatic enum singular(T) = ()\n\t{\n\t\tstatic if (isNumeric!T) return T.min;\n\t\telse\n\t\t{\n\t\t\tT t;\n\t\t\tt[0] = typeof(t[0]).min;\n\t\t\treturn t;\n\t\t}\n\t}();\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u = singular!U;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (isSingular(_n[i].u)) return;\n\t\tassert(!_isLeaf(i));\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\t_n[i].u = singular!U;\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (isSingular(_n[i].u))\n\t\t\t_n[i].u = u;\n\t\telse\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF!V, funFoU!V, funUoU!V, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(int[2], \"max\", \"set\", [0, -1]);\n\tauto st = SegTree(noPoints, [0, -1]);\n\tauto dp = new int[2][](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = [0, -1];\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] = [dpi[0], cast(int)i];\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\timport std.traits;\n\tstatic pure bool isSingular(T)(T t)\n\t{\n\t\tstatic if (isNumeric!T) return t == T.min;\n\t\telse return t[0] == typeof(t[0]).min;\n\t}\n\tstatic enum singular(T) = ()\n\t{\n\t\tstatic if (isNumeric!T) return T.min;\n\t\telse\n\t\t{\n\t\t\tT t;\n\t\t\tt[0] = typeof(t[0]).min;\n\t\t\treturn t;\n\t\t}\n\t}();\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u = singular!U;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (isSingular(_n[i].u)) return;\n\t\tassert(!_isLeaf(i));\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\t_n[i].u = singular!U;\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (isSingular(_n[i].u))\n\t\t\t_n[i].u = u;\n\t\telse\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF!V, funFoU!V, funUoU!V, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(int[2], \"max\", \"set\", [0, -1]);\n\tauto st = SegTree(noPoints, [0, -1]);\n\tauto dp = new int[2][](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = [0, -1];\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] = [dpi[0], cast(int)i];\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF!V, funFoU!V, funUoU!V, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\tauto st = TSTL!(int, \"max\", \"set\", int.min)(noPoints, 0);\n\tauto st2 = TSTL!(int, \"max\", \"add\", 0)(noPoints, 0);\n\tauto dp = new int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = 0;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, dpi);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\n\tforeach(range; ranges[bi]) st2.rangeU(range[0], range[1] + 1, 1);\n\talive[bi] = false;\n\tauto pbi = bi;\n\tbi--;\n\twhile (bi >= 0)\n\t{\n\t\tif (dp[bi] == dp[pbi] - 1)\n\t\t{\n\t\t\tbool isGood = false;\n\t\t\tforeach(range; ranges[bi])\n\t\t\t{\n\t\t\t\t\tif (st2.rangeF(range[0], range[1] + 1) > 0) { isGood = true; break; }\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tforeach(range; ranges[pbi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, -1);\n\t\t\t\tforeach(range; ranges[bi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, +1);\n\t\t\t\talive[bi] = false;\n\t\t\t\tpbi = bi;\n\t\t\t}\n\t\t}\n\t\tbi--;\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tbool isPow2(size_t s) { return ((s - 1) & s) == 0; }\n\t\timport std.math;\n\t\timport core.bitop;\n\t\tlayers = bsr(n) + !isPow2(n);\n\t\tn = 1 << (layers++);\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF!V, funFoU!V, funUoU!V, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\tauto st = TSTL!(int, \"max\", \"set\", int.min)(noPoints, 0);\n\tauto st2 = TSTL!(int, \"max\", \"add\", 0)(noPoints, 0);\n\tauto dp = new int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = 0;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, dpi);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\n\tforeach(range; ranges[bi]) st2.rangeU(range[0], range[1] + 1, 1);\n\talive[bi] = false;\n\tauto pbi = bi;\n\tbi--;\n\twhile (bi >= 0)\n\t{\n\t\tif (dp[bi] == dp[pbi] - 1)\n\t\t{\n\t\t\tbool isGood = false;\n\t\t\tforeach(range; ranges[bi])\n\t\t\t{\n\t\t\t\t\tif (st2.rangeF(range[0], range[1] + 1) > 0) { isGood = true; break; }\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tforeach(range; ranges[pbi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, -1);\n\t\t\t\tforeach(range; ranges[bi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, +1);\n\t\t\t\talive[bi] = false;\n\t\t\t\tpbi = bi;\n\t\t\t}\n\t\t}\n\t\tbi--;\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF!V, funFoU!V, funUoU!V, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\nstruct Pair(T)\n{\n\tT[2] _d;\n\talias _d this; \n\tbool opBinary(string op)(Pair!T rhs) if (op == \"<\")\n\t{\n\t\tauto diff0 = _d[0] - rhs[0];\n\t\tif (diff0 == 0) return _d[1] - rhs[1];\n\t\treturn diff0;\n\t}\n\tthis(int x, int y) { _d = [x, y]; }\n}\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Pair!int, \"max\", \"set\", Pair!int(0, -1));\n\tauto st = SegTree(noPoints, Pair!int(0, -1));\n\tauto dp = new Pair!int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = Pair!int(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] = Pair!int(dpi[0], cast(int)i);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF!V, funFoU!V, funUoU!V, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\nstruct Pair(T)\n{\n\tT[2] _d;\n\talias _d this; \n\tbool opBinary(string op)(Pair!T rhs) if (op == \"<\")\n\t{\n\t\treturn _d[0] - rhs[0];\n\t}\n\tthis(int x, int y) { _d = [x, y]; }\n}\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Pair!int, \"max\", \"set\", Pair!int(0, -1));\n\tauto st = SegTree(noPoints, Pair!int(0, -1));\n\tauto dp = new Pair!int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = Pair!int(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] = Pair!int(dpi[0], cast(int)i);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF!V, funFoU!V, funUoU!V, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\", tuple(0, -1));\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] = tuple(dpi[0], cast(int)i);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];//\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF!V, funFoU!V, funUoU!V, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\", tuple(0, -1));\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] = tuple(dpi[0], cast(int)i);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\timport core.bitop;\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, length >> bsr(i));\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tversion(velocity)\n\t{\n\t\tint n = 100_000;\n\t\tint q = 100_000;\n\t\tauto st = SumQSumU(n, 0);\n\t\tint tot = 0;\n\t\tforeach(i; 0 .. q)\n\t\t{\n\t\t\tint f = uniform!\"[)\"(0, n);\n\t\t\tint t = uniform!\"[]\"(f + 1, n);\n\t\t\tif (i&1)\n\t\t\t{\n\t\t\t\ttot += st.addRange(f, t);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint u = uniform!\"[)\"(-1000, 1000);\n\t\t\t\tst.rangeU(f, t, u);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tauto n = 1000;\n\t\tint[] brute = new int[](n);\n\t\tauto smart = SumQSumU(n, 0);\n\t\tint rounds = 10;\n\t\tforeach(round; 0 .. rounds)\n\t\t{\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\t\tbrute[i .. j] += v;\n\t\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t\t}\n\t\t\tforeach(i; 0 .. n)\n\t\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t\t{\n\t\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t\t}\n\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\", tuple(0, -1));\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.maxRange(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] = tuple(dpi[0], cast(int)i);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t\tsize_t sz;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t\t_n[i].sz = 1; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t\t_n[i].sz = _n[i<<1].sz << 1;\n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tmixin(q{alias }, fName, q{Range = rangeF;});\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tstatic if (uName == \"set\")\n\t{\n\t\tauto opIndexAssign(U u, size_t[2] slice)\n\t\t{\n\t\t\trangeU(slice[0], slice[1], u);\n\t\t\treturn this;\n\t\t}\n\t}\n\telse static if (uName == \"add\")\n\t{\n\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, _n[i].sz);\n\t}\n\tsize_t[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [start, end];\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 1000;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 10;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\", tuple(0, -1));\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tstruct Node\n\t{\n\t\tV f;\n\t\tU u;\n\t\tbool hasU;\n\t\tsize_t sz;\n\t}\n\tNode[] _n;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_n = new Node[](noNodes);\n\n\t\tforeach(i; n .. 2 * n) \n\t\t{ \n\t\t\t_n[i].f = v; \n\t\t\t_n[i].sz = 1; \n\t\t}\n\t\tforeach_reverse(i; 1 .. n) \n\t\t{ \n\t\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f); \n\t\t\t_n[i].sz = _n[i<<1].sz << 1;\n\t\t}\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].f = f(_n[i<<1].f, _n[(i<<1)^1].f);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _n[l++].f); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _n[--r].f); \n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU) return;\n\t\tassert(!_isLeaf(i));\n\t\t_n[i].hasU = false;\n\t\t_addU(i << 1, _n[i].u), _addU((i << 1) ^ 1, _n[i].u);\n\t\tassert(_n[i].f == f(_n[i<<1].f, _n[(i<<1)^1].f));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_n[i].hasU)\n\t\t{\n\t\t\t_n[i].hasU = true;\n\t\t\t_n[i].u = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_n[i].u = uou(u, _n[i].u);\n\t\t}\n\t\t_n[i].f = fou(_n[i].f, u, _n[i].sz);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 1000;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 10;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\", tuple(0, -1));\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tbool[] _nHasU;\n\tsize_t[] _nSz;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_nF = new V[](noNodes); \n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new size_t[](noNodes);\n\n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lp = (l >> layer);\n\t\t\tauto rp = (r >> layer);\n\t\t\tif ((lp << layer) != l) _clearU(l >> layer);\n\t\t\tif ((rp << layer) != r) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lp = (l >> layer);\n\t\t\tauto rp = (r >> layer);\n\t\t\tif ((lp << layer) != l) _refresh(l >> layer);\n\t\t\tif ((rp << layer) != r) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_nF[i] = f(_nF[i<<1], _nF[(i<<1)^1]);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _nF[l++]); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _nF[--r]); \n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) return;\n\t\tassert(!_isLeaf(i));\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nHasU[i] = false;\n\t\tassert(_nF[i] == f(_nF[i<<1], _nF[(i<<1)^1]));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nHasU[i] = true;\n\t\t\t_nU[i] = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\t_nF[i] = fou(_nF[i], u, _nSz[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 1000;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 10;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\", tuple(0, -1));\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tbool[] _nHasU;\n\tsize_t[] _nSz;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_nF = new V[](noNodes); \n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new size_t[](noNodes);\n\n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tpragma(inline, true);\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tassert(!_isLeaf(i));\n\t\t_nF[i] = f(_nF[i<<1], _nF[(i<<1)^1]);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _nF[l++]); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _nF[--r]); \n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i]) return;\n\t\tassert(!_isLeaf(i));\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nHasU[i] = false;\n\t\tassert(_nF[i] == f(_nF[i<<1], _nF[(i<<1)^1]));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tpragma(inline, true);\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nHasU[i] = true;\n\t\t\t_nU[i] = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\t_nF[i] = fou(_nF[i], u, _nSz[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 1000;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 10;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\", tuple(0, -1));\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tbool[] _nHasU;\n\tsize_t[] _nSz;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\timport std.math;\n\t\tn = cast(size_t) nextPow2(n);\n\t\tlayers = cast(int) log2(n) + 1;\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\t_nF = new V[](noNodes); \n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new size_t[](noNodes);\n\n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tforeach_reverse(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _clearU(l >> layer);\n\t\t\tif (r & lowerBits) _clearU(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tforeach(layer; 1 .. layers)\n\t\t{\n\t\t\tauto lowerBits = (1 << layer) - 1;\n\t\t\tif (l & lowerBits) _refresh(l >> layer);\n\t\t\tif (r & lowerBits) _refresh(r >> layer);\n\t\t}\n\t}\n\tvoid _refresh(size_t i)\n\t{\n\t\tassert(!_isLeaf(i));\n\t\t_nF[i] = f(_nF[i<<1], _nF[(i<<1)^1]);\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t\tvalue = f(value, _nF[l++]); \n\t\t\tif (r & 1) \n\t\t\t\tvalue = f(value, _nF[--r]); \n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\t_clearU(l, r);\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\tpragma(inline, true);\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tassert(!_isLeaf(i));\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nHasU[i] = false;\n\t\tassert(_nF[i] == f(_nF[i<<1], _nF[(i<<1)^1]));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nHasU[i] = true;\n\t\t\t_nU[i] = u;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\t_nF[i] = fou(_nF[i], u, _nSz[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 1000;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 10;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\tauto st = TSTL!(int, \"max\", \"set\", int.min)(noPoints, 0);\n\tauto st2 = TSTL!(int, \"max\", \"add\", 0)(noPoints, 0);\n\tauto dp = new int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = 0;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st[range[0] .. range[1] + 1].max);\n\t\t}\n\t\tdpi++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, dpi);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\n\tforeach(range; ranges[bi]) st2.rangeU(range[0], range[1] + 1, 1);\n\talive[bi] = false;\n\tauto pbi = bi;\n\tbi--;\n\twhile (bi >= 0)\n\t{\n\t\tif (dp[bi] == dp[pbi] - 1)\n\t\t{\n\t\t\tbool isGood = false;\n\t\t\tforeach(range; ranges[bi])\n\t\t\t{\n\t\t\t\t\tif (st2.rangeF(range[0], range[1] + 1) > 0) { isGood = true; break; }\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tforeach(range; ranges[pbi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, -1);\n\t\t\t\tforeach(range; ranges[bi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, +1);\n\t\t\t\talive[bi] = false;\n\t\t\t\tpbi = bi;\n\t\t\t}\n\t\t}\n\t\tbi--;\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\tU emptyU,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\",\n\t\tstaticSize...)\n{\n\tstatic immutable bool isStatic = staticSize.length > 0;\n\tstatic if (isStatic) \n\t{\n\t\timmutable size_t size = cast(size_t)nextPow2(staticSize[0]) * 2;\n\t\tV[size] _nF;\n\t\tU[size] _nU;\n\t\tsize_t[size] _nSz;\n\t}\n\telse\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t}\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\tstatic if (!isStatic)\n\t\t{\n\t\t\t_nF = new V[](noNodes); \n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t}\n\n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(l++)); \n\t\t\t}\n\t\t\tif (r & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(--r)); \n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nU[i] != emptyU) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (_nU[i] == emptyU) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nU[i] = emptyU;\n\t\t\treturn;\n\t\t}\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nU[i] = emptyU;\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (_nU[i] == emptyU)\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, V emptyU, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\talias TSTL = STL!(V, V, neut, emptyU, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 100;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\timport core.memory;\n\tGC.disable;\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\tauto st = TSTL!(int, \"max\", \"set\", false)(noPoints, 0);\n\tauto st2 = TSTL!(int, \"max\", \"add\", false)(noPoints, 0);\n\tauto dp = new int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = 0;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st[range[0] .. range[1] + 1].max);\n\t\t}\n\t\tdpi++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, dpi);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\n\tforeach(range; ranges[bi]) st2.rangeU(range[0], range[1] + 1, 1);\n\talive[bi] = false;\n\tauto pbi = bi;\n\tbi--;\n\twhile (bi >= 0)\n\t{\n\t\tif (dp[bi] == dp[pbi] - 1)\n\t\t{\n\t\t\tbool isGood = false;\n\t\t\tforeach(range; ranges[bi])\n\t\t\t{\n\t\t\t\t\tif (st2.rangeF(range[0], range[1] + 1) > 0) { isGood = true; break; }\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tforeach(range; ranges[pbi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, -1);\n\t\t\t\tforeach(range; ranges[bi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, +1);\n\t\t\t\talive[bi] = false;\n\t\t\t\tpbi = bi;\n\t\t\t}\n\t\t}\n\t\tbi--;\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n\tGC.enable;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\",\n\t\tstaticSize...)\n{\n\tstatic immutable bool isStatic = staticSize.length > 0;\n\tstatic if (isStatic) \n\t{\n\t\timmutable size_t size = cast(size_t)nextPow2(staticSize[0]) * 2;\n\t\tV[size] _nF;\n\t\tU[size] _nU;\n\t\tsize_t[size] _nSz;\n\t\tbool[size] _nHasU;\n\t}\n\telse\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t}\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\tstatic if (!isStatic)\n\t\t{\n\t\t\t_nF = new V[](noNodes); \n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t}\n\n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(l++)); \n\t\t\t}\n\t\t\tif (r & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(--r)); \n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, bool hasSize, args...)\n{\n\tstatic if (hasSize) \n\t{\n\t\tauto neutral = args[1 .. $];\n\t}\n\telse \n\t{\n\t\tauto neutral = args[0 .. $];\n\t}\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\n\tstatic if (hasSize) alias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u, args[0]);\n\telse alias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 100;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\tauto st = TSTL!(int, \"max\", \"set\", false)(noPoints, 0);\n\tauto st2 = TSTL!(int, \"max\", \"add\", false)(noPoints, 0);\n\tauto dp = new int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = 0;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st[range[0] .. range[1] + 1].max);\n\t\t}\n\t\tdpi++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, dpi);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\n\tforeach(range; ranges[bi]) st2.rangeU(range[0], range[1] + 1, 1);\n\talive[bi] = false;\n\tauto pbi = bi;\n\tbi--;\n\twhile (bi >= 0)\n\t{\n\t\tif (dp[bi] == dp[pbi] - 1)\n\t\t{\n\t\t\tbool isGood = false;\n\t\t\tforeach(range; ranges[bi])\n\t\t\t{\n\t\t\t\t\tif (st2.rangeF(range[0], range[1] + 1) > 0) { isGood = true; break; }\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tforeach(range; ranges[pbi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, -1);\n\t\t\t\tforeach(range; ranges[bi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, +1);\n\t\t\t\talive[bi] = false;\n\t\t\t\tpbi = bi;\n\t\t\t}\n\t\t}\n\t\tbi--;\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\",\n\t\tstaticSize...)\n{\n\tstatic immutable bool isStatic = staticSize.length > 0;\n\tstatic if (isStatic) \n\t{\n\t\timmutable size_t size = cast(size_t)nextPow2(staticSize[0]) * 2;\n\t\tV[size] _nF;\n\t\tU[size] _nU;\n\t\tsize_t[size] _nSz;\n\t\tbool[size] _nHasU;\n\t}\n\telse\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t}\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\n\t\tstatic if (!isStatic)\n\t\t{\n\t\t\t_nF = new V[](noNodes); \n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t}\n\n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(l++)); \n\t\t\t}\n\t\t\tif (r & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(--r)); \n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, bool hasSize, args...)\n{\n\tstatic if (hasSize) \n\t{\n\t\tauto neutral = args[1 .. $];\n\t}\n\telse \n\t{\n\t\tauto neutral = args[0 .. $];\n\t}\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\n\tstatic if (hasSize) alias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u, args[0]);\n\telse alias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 100;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\tauto st = TSTL!(int, \"max\", \"set\")(noPoints, 0);\n\tauto st2 = TSTL!(int, \"max\", \"add\")(noPoints, 0);\n\tauto dp = new int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = 0;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st[range[0] .. range[1] + 1].max);\n\t\t}\n\t\tdpi++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, dpi);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\n\tforeach(range; ranges[bi]) st2.rangeU(range[0], range[1] + 1, 1);\n\talive[bi] = false;\n\tauto pbi = bi;\n\tbi--;\n\twhile (bi >= 0)\n\t{\n\t\tif (dp[bi] == dp[pbi] - 1)\n\t\t{\n\t\t\tbool isGood = false;\n\t\t\tforeach(range; ranges[bi])\n\t\t\t{\n\t\t\t\t\tif (st2.rangeF(range[0], range[1] + 1) > 0) { isGood = true; break; }\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tforeach(range; ranges[pbi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, -1);\n\t\t\t\tforeach(range; ranges[bi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, +1);\n\t\t\t\talive[bi] = false;\n\t\t\t\tpbi = bi;\n\t\t\t}\n\t\t}\n\t\tbi--;\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tsize_t[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new size_t[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(l++)); \n\t\t\t}\n\t\t\tif (r & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(--r)); \n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\n\talias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 100;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\", tuple(0, -1));\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral,\n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tsize_t[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new size_t[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(l++)); \n\t\t\t}\n\t\t\tif (r & 1) \n\t\t\t{ \n\t\t\t\tvalue = f(value, _getNodeF(--r)); \n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u, neutral...)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\tstatic if (neutral.length == 1)\n\t\timmutable neut = neutral[0];\n\telse static if (neutral.length == 0)\n\t{\n\t\talias neutralTemplate = mixin(f, \"Neutral\");\n\t\timmutable neut = neutralTemplate!V;\n\t}\n\telse static assert(false);\n\n\talias TSTL = STL!(V, V, neut, funF, funFoU, funUoU, f, u);\n}\nimmutable maxNeutral(T) = T.min;\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\nimmutable addNeutral(T) = T(0);\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 100;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), \"max\", \"set\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\talias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tsize_t[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\tif (v != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new size_t[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value;\n\t\tbool set = false;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) \n\t\t\t{ \n\t\t\t\tif (!set) \n\t\t\t\t{ \n\t\t\t\t\tvalue = _getNodeF(l++); set = true; \n\t\t\t\t} else value = f(value, _getNodeF(l++)); \n\t\t\t}\n\t\t\tif (r & 1) \n\t\t\t{ \n\t\t\t\tif (!set) \n\t\t\t\t{ \n\t\t\t\t\tvalue = _getNodeF(--r); set = true; \n\t\t\t\t} else value = f(value, _getNodeF(--r)); \n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, string f, string u)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\talias TSTL = STL!(V, V, funF, funFoU, funUoU, f, u);\n}\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, \"add\", \"add\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 100;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = TSTL!(Tuple!(int, int), tuple(0, -1), \"max\", \"set\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, U, \n\t\tV neutral, alias f, \n\t\talias fou, \n\t\talias uou, \n\t\tstring fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tsize_t[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\tstatic if (neutral != V.init) _nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new size_t[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] << 1;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\ntemplate TSTL(V, V neutral, string f, string u)\n{\n\talias funF = mixin(f);\n\talias funUoU = mixin(u);\n\talias funFoU = mixin(f, \"O\", u);\n\talias TSTL = STL!(V, V, neutral, funF, funFoU, funUoU, f, u);\n}\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minOset(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minOadd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T addOadd(T)(T sm, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn sm + ad * cast(T)l;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = TSTL!(int, 0, \"add\", \"add\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 100;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart.rangeU(i, j, v);\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart.rangeF(i, j);\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(Tuple!(int, int), Tuple!(int, int))\n\t\t.Type!(tuple(0, -1), max, maxCompSet, set, \"max\", \"+\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\ntemplate STL(V, U)\n{\n\tstruct Type (V neutral, alias f, \n\t\t\talias fou, \n\t\t\talias uou, \n\t\t\tstring fName = \"f\", string uName = \"u\")\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t\tsize_t length = 0;\n\t\tint layers = 0;\n\t\tthis(size_t n, V v)\n\t\t{\n\t\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\t\tauto fn = n;\n\t\t\twhile (fn) {layers++; fn >>= 1;}\n\t\t\tlength = n;\n\t\t\tauto noNodes = 2 * n; \n\t\t\t_nF = new V[](noNodes); \n\t\t\tstatic if (neutral != V.init) _nF[n .. 2 * n] = v;\n\t\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t\t_nSz[n .. 2 * n] = 1;\n\t\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\t}\n\t\tvoid _clearU(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tauto li = layers - 1;\n\t\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t\t}\n\t\tvoid _refresh(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tl >>= 1; r >>= 1;\n\t\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t\t}\n\t\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t}\n\t\tV rangeF(size_t l, size_t r)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\t_clearU(l, r);\n\t\t\tV value = neutral;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tvoid rangeU(size_t l, size_t r, U u)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\tauto ol = l, or = r;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) _addU(l++, u); \n\t\t\t\tif (r & 1) _addU(--r, u);\n\t\t\t}\n\t\t\t_refresh(ol, or);\n\t\t}\n\t\tV _getNodeF(size_t i)\n\t\t{\n\t\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\t\treturn _nF[i];\n\t\t}\n\t\tbool _isLeaf(size_t i)\n\t\t{\n\t\t\treturn i >= length;\n\t\t}\n\t\tvoid _clearU(size_t i)\n\t\t{\n\t\t\tif (!_nHasU[i]) return;\n\t\t\tif (_isLeaf(i))\n\t\t\t{\n\t\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t\t_nHasU[i] = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nHasU[i] = false;\n\t\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t\t}\n\t\tvoid _addU(size_t i, U u)\n\t\t{\n\t\t\tif (!_nHasU[i])\n\t\t\t{\n\t\t\t\t_nU[i] = u;\n\t\t\t\t_nHasU[i] = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t\t{\n\t\t\treturn [cast(int)start, cast(int)end];\n\t\t}\n\t\tauto opIndex(int[2] slice)\n\t\t{\n\t\t\talias Parent = typeof(this);\n\t\t\tstruct Ans\n\t\t\t{\n\t\t\t\tParent* parent;\n\t\t\t\tint[2] slice;\n\t\t\t\tmixin(q{V }, fName, q{;});\n\t\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t\t{\n\t\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t\t}\n\t}\n}\npure T max(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a > b? a : b;\n}\npure T add(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a + b;\n}\npure T min(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a < b? a : b;\n}\npure T set(T)(T a, T b)\n{\n\tpragma(inline, true);\n\treturn a;\n}\npure T maxCompSet(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T maxCompAdd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\npure T minCompSet(T)(T mx, T set, size_t l)\n{\n\tpragma(inline, true);\n\treturn set;\n}\npure T minCompAdd(T)(T mx, T ad, size_t l)\n{\n\tpragma(inline, true);\n\treturn mx + ad;\n}\n\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int).Type!(0, \n\t\t\t(v1, v2) => v1 + v2,\n\t\t\t(v, u, size_t l) => v + u * cast(int)l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart[i .. j] += v;\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\tstatic auto FoU(Tuple!(int, int) mx, Tuple!(int, int) st, size_t l) { pragma(inline, true); return st; }\n\tstatic auto UoU(Tuple!(int, int) nw, Tuple!(int, int) ld) { pragma(inline, true); return nw; }\n\talias SegTree = STL!(Tuple!(int, int), Tuple!(int, int))\n\t\t.Type!(tuple(0, -1), \n\t\t\t\tmax!(Tuple!(int, int), Tuple!(int, int)), FoU, UoU,\n\t\t\t\t\"max\", \"+\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\ntemplate STL(V, U)\n{\n\tstruct Type (V neutral, alias f, \n\t\t\talias fou, \n\t\t\talias uou, \n\t\t\tstring fName = \"f\", string uName = \"u\")\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t\tsize_t length = 0;\n\t\tint layers = 0;\n\t\tthis(size_t n, V v)\n\t\t{\n\t\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\t\tauto fn = n;\n\t\t\twhile (fn) {layers++; fn >>= 1;}\n\t\t\tlength = n;\n\t\t\tauto noNodes = 2 * n; \n\t\t\t_nF = new V[](noNodes); \n\t\t\tstatic if (neutral != V.init) _nF[n .. 2 * n] = v;\n\t\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t\t_nSz[n .. 2 * n] = 1;\n\t\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\t}\n\t\tvoid _clearU(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tauto li = layers - 1;\n\t\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t\t}\n\t\tvoid _refresh(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tl >>= 1; r >>= 1;\n\t\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t\t}\n\t\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t}\n\t\tV rangeF(size_t l, size_t r)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\t_clearU(l, r);\n\t\t\tV value = neutral;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tvoid rangeU(size_t l, size_t r, U u)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\tauto ol = l, or = r;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) _addU(l++, u); \n\t\t\t\tif (r & 1) _addU(--r, u);\n\t\t\t}\n\t\t\t_refresh(ol, or);\n\t\t}\n\t\tV _getNodeF(size_t i)\n\t\t{\n\t\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\t\treturn _nF[i];\n\t\t}\n\t\tbool _isLeaf(size_t i)\n\t\t{\n\t\t\treturn i >= length;\n\t\t}\n\t\tvoid _clearU(size_t i)\n\t\t{\n\t\t\tif (!_nHasU[i]) return;\n\t\t\tif (_isLeaf(i))\n\t\t\t{\n\t\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t\t_nHasU[i] = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nHasU[i] = false;\n\t\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t\t}\n\t\tvoid _addU(size_t i, U u)\n\t\t{\n\t\t\tif (!_nHasU[i])\n\t\t\t{\n\t\t\t\t_nU[i] = u;\n\t\t\t\t_nHasU[i] = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t\t{\n\t\t\treturn [cast(int)start, cast(int)end];\n\t\t}\n\t\tauto opIndex(int[2] slice)\n\t\t{\n\t\t\talias Parent = typeof(this);\n\t\t\tstruct Ans\n\t\t\t{\n\t\t\t\tParent* parent;\n\t\t\t\tint[2] slice;\n\t\t\t\tmixin(q{V }, fName, q{;});\n\t\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t\t{\n\t\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t\t}\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int).Type!(0, \n\t\t\t(v1, v2) => v1 + v2,\n\t\t\t(v, u, size_t l) => v + u * cast(int)l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart[i .. j] += v;\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "auto FoU(Tuple!(int, int) mx, Tuple!(int, int) st, size_t l) { pragma(inline, true); return st; }\nauto UoU(Tuple!(int, int) nw, Tuple!(int, int) ld) { pragma(inline, true); return nw; }\n\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(Tuple!(int, int), Tuple!(int, int))\n\t\t.Type!(tuple(0, -1), \n\t\t\t\tmax!(Tuple!(int, int), Tuple!(int, int)), FoU, UoU,\n\t\t\t\t\"max\", \"+\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\ntemplate STL(V, U)\n{\n\tstruct Type (V neutral, alias f, \n\t\t\talias fou, \n\t\t\talias uou, \n\t\t\tstring fName = \"f\", string uName = \"u\")\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t\tsize_t length = 0;\n\t\tint layers = 0;\n\t\tthis(size_t n, V v)\n\t\t{\n\t\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\t\tauto fn = n;\n\t\t\twhile (fn) {layers++; fn >>= 1;}\n\t\t\tlength = n;\n\t\t\tauto noNodes = 2 * n; \n\t\t\t_nF = new V[](noNodes); \n\t\t\tstatic if (neutral != V.init) _nF[n .. 2 * n] = v;\n\t\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t\t_nSz[n .. 2 * n] = 1;\n\t\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\t}\n\t\tvoid _clearU(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tauto li = layers - 1;\n\t\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t\t}\n\t\tvoid _refresh(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tl >>= 1; r >>= 1;\n\t\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t\t}\n\t\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t}\n\t\tV rangeF(size_t l, size_t r)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\t_clearU(l, r);\n\t\t\tV value = neutral;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tvoid rangeU(size_t l, size_t r, U u)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\tauto ol = l, or = r;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) _addU(l++, u); \n\t\t\t\tif (r & 1) _addU(--r, u);\n\t\t\t}\n\t\t\t_refresh(ol, or);\n\t\t}\n\t\tV _getNodeF(size_t i)\n\t\t{\n\t\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\t\treturn _nF[i];\n\t\t}\n\t\tbool _isLeaf(size_t i)\n\t\t{\n\t\t\treturn i >= length;\n\t\t}\n\t\tvoid _clearU(size_t i)\n\t\t{\n\t\t\tif (!_nHasU[i]) return;\n\t\t\tif (_isLeaf(i))\n\t\t\t{\n\t\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t\t_nHasU[i] = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nHasU[i] = false;\n\t\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t\t}\n\t\tvoid _addU(size_t i, U u)\n\t\t{\n\t\t\tif (!_nHasU[i])\n\t\t\t{\n\t\t\t\t_nU[i] = u;\n\t\t\t\t_nHasU[i] = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t\t{\n\t\t\treturn [cast(int)start, cast(int)end];\n\t\t}\n\t\tauto opIndex(int[2] slice)\n\t\t{\n\t\t\talias Parent = typeof(this);\n\t\t\tstruct Ans\n\t\t\t{\n\t\t\t\tParent* parent;\n\t\t\t\tint[2] slice;\n\t\t\t\tmixin(q{V }, fName, q{;});\n\t\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t\t{\n\t\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t\t}\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int).Type!(0, \n\t\t\t(v1, v2) => v1 + v2,\n\t\t\t(v, u, size_t l) => v + u * cast(int)l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart[i .. j] += v;\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "auto FoU(Tuple!(int, int) mx, Tuple!(int, int) st, size_t l) { pragma(inline, true); return st; }\nauto UoU(Tuple!(int, int) nw, Tuple!(int, int) ld) { pragma(inline, true); return nw; }\n\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(Tuple!(int, int), Tuple!(int, int))\n\t\t.Type!(tuple(0, -1), \n\t\t\t\tmax, FoU, UoU,\n\t\t\t\t\"max\", \"+\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\ntemplate STL(V, U)\n{\n\tstruct Type (V neutral, alias f, \n\t\t\talias fou, \n\t\t\talias uou, \n\t\t\tstring fName = \"f\", string uName = \"u\")\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t\tsize_t length = 0;\n\t\tint layers = 0;\n\t\tthis(size_t n, V v)\n\t\t{\n\t\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\t\tauto fn = n;\n\t\t\twhile (fn) {layers++; fn >>= 1;}\n\t\t\tlength = n;\n\t\t\tauto noNodes = 2 * n; \n\t\t\t_nF = new V[](noNodes); \n\t\t\tstatic if (neutral != V.init) _nF[n .. 2 * n] = v;\n\t\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t\t_nSz[n .. 2 * n] = 1;\n\t\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\t}\n\t\tvoid _clearU(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tauto li = layers - 1;\n\t\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t\t}\n\t\tvoid _refresh(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tl >>= 1; r >>= 1;\n\t\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t\t}\n\t\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t}\n\t\tV rangeF(size_t l, size_t r)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\t_clearU(l, r);\n\t\t\tV value = neutral;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tvoid rangeU(size_t l, size_t r, U u)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\tauto ol = l, or = r;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) _addU(l++, u); \n\t\t\t\tif (r & 1) _addU(--r, u);\n\t\t\t}\n\t\t\t_refresh(ol, or);\n\t\t}\n\t\tV _getNodeF(size_t i)\n\t\t{\n\t\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\t\treturn _nF[i];\n\t\t}\n\t\tbool _isLeaf(size_t i)\n\t\t{\n\t\t\treturn i >= length;\n\t\t}\n\t\tvoid _clearU(size_t i)\n\t\t{\n\t\t\tif (!_nHasU[i]) return;\n\t\t\tif (_isLeaf(i))\n\t\t\t{\n\t\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t\t_nHasU[i] = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nHasU[i] = false;\n\t\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t\t}\n\t\tvoid _addU(size_t i, U u)\n\t\t{\n\t\t\tif (!_nHasU[i])\n\t\t\t{\n\t\t\t\t_nU[i] = u;\n\t\t\t\t_nHasU[i] = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t\t{\n\t\t\treturn [cast(int)start, cast(int)end];\n\t\t}\n\t\tauto opIndex(int[2] slice)\n\t\t{\n\t\t\talias Parent = typeof(this);\n\t\t\tstruct Ans\n\t\t\t{\n\t\t\t\tParent* parent;\n\t\t\t\tint[2] slice;\n\t\t\t\tmixin(q{V }, fName, q{;});\n\t\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t\t{\n\t\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t\t}\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int).Type!(0, \n\t\t\t(v1, v2) => v1 + v2,\n\t\t\t(v, u, size_t l) => v + u * cast(int)l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart[i .. j] += v;\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "auto F(Tuple!(int, int) a, Tuple!(int, int) b) { pragma(inline, true); return a > b? a : b; }\nauto FoU(Tuple!(int, int) mx, Tuple!(int, int) st, size_t l) { pragma(inline, true); return st; }\nauto UoU(Tuple!(int, int) nw, Tuple!(int, int) ld) { pragma(inline, true); return nw; }\n\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(Tuple!(int, int), Tuple!(int, int))\n\t\t.Type!(tuple(0, -1), \n\t\t\t\tF, FoU, UoU,\n\t\t\t\t\"max\", \"+\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\ntemplate STL(V, U)\n{\n\tstruct Type (V neutral, alias f, \n\t\t\talias fou, \n\t\t\talias uou, \n\t\t\tstring fName = \"f\", string uName = \"u\")\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t\tsize_t length = 0;\n\t\tint layers = 0;\n\t\tthis(size_t n, V v)\n\t\t{\n\t\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\t\tauto fn = n;\n\t\t\twhile (fn) {layers++; fn >>= 1;}\n\t\t\tlength = n;\n\t\t\tauto noNodes = 2 * n; \n\t\t\t_nF = new V[](noNodes); \n\t\t\tstatic if (neutral != V.init) _nF[n .. 2 * n] = v;\n\t\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t\t_nSz[n .. 2 * n] = 1;\n\t\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\t}\n\t\tvoid _clearU(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tauto li = layers - 1;\n\t\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t\t}\n\t\tvoid _refresh(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tl >>= 1; r >>= 1;\n\t\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t\t}\n\t\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t}\n\t\tV rangeF(size_t l, size_t r)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\t_clearU(l, r);\n\t\t\tV value = neutral;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tvoid rangeU(size_t l, size_t r, U u)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\tauto ol = l, or = r;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) _addU(l++, u); \n\t\t\t\tif (r & 1) _addU(--r, u);\n\t\t\t}\n\t\t\t_refresh(ol, or);\n\t\t}\n\t\tV _getNodeF(size_t i)\n\t\t{\n\t\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\t\treturn _nF[i];\n\t\t}\n\t\tbool _isLeaf(size_t i)\n\t\t{\n\t\t\treturn i >= length;\n\t\t}\n\t\tvoid _clearU(size_t i)\n\t\t{\n\t\t\tif (!_nHasU[i]) return;\n\t\t\tif (_isLeaf(i))\n\t\t\t{\n\t\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t\t_nHasU[i] = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nHasU[i] = false;\n\t\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t\t}\n\t\tvoid _addU(size_t i, U u)\n\t\t{\n\t\t\tif (!_nHasU[i])\n\t\t\t{\n\t\t\t\t_nU[i] = u;\n\t\t\t\t_nHasU[i] = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t\t{\n\t\t\treturn [cast(int)start, cast(int)end];\n\t\t}\n\t\tauto opIndex(int[2] slice)\n\t\t{\n\t\t\talias Parent = typeof(this);\n\t\t\tstruct Ans\n\t\t\t{\n\t\t\t\tParent* parent;\n\t\t\t\tint[2] slice;\n\t\t\t\tmixin(q{V }, fName, q{;});\n\t\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t\t{\n\t\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t\t}\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int).Type!(0, \n\t\t\t(v1, v2) => v1 + v2,\n\t\t\t(v, u, size_t l) => v + u * cast(int)l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart[i .. j] += v;\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "pure auto F(Tuple!(int, int) a, Tuple!(int, int) b) { pragma(inline, true); return a > b? a : b; }\npure auto FoU(Tuple!(int, int) mx, Tuple!(int, int) st, size_t l) { pragma(inline, true); return st; }\npure auto UoU(Tuple!(int, int) nw, Tuple!(int, int) ld) { pragma(inline, true); return nw; }\n\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(Tuple!(int, int), Tuple!(int, int))\n\t\t.Type!(tuple(0, -1), \n\t\t\t\tF, FoU, UoU,\n\t\t\t\t\"max\", \"+\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st.rangeF(range[0], range[1] + 1));\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst.rangeU(range[0], range[1] + 1, tuple(dpi[0], cast(int)i));\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\ntemplate STL(V, U)\n{\n\tstruct Type (V neutral, alias f, \n\t\t\talias fou, \n\t\t\talias uou, \n\t\t\tstring fName = \"f\", string uName = \"u\")\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t\tsize_t length = 0;\n\t\tint layers = 0;\n\t\tthis(size_t n, V v)\n\t\t{\n\t\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\t\tauto fn = n;\n\t\t\twhile (fn) {layers++; fn >>= 1;}\n\t\t\tlength = n;\n\t\t\tauto noNodes = 2 * n; \n\t\t\t_nF = new V[](noNodes); \n\t\t\tstatic if (neutral != V.init) _nF[n .. 2 * n] = v;\n\t\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t\t_nSz[n .. 2 * n] = 1;\n\t\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\t}\n\t\tvoid _clearU(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tauto li = layers - 1;\n\t\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t\t}\n\t\tvoid _refresh(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tl >>= 1; r >>= 1;\n\t\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t\t}\n\t\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t}\n\t\tV rangeF(size_t l, size_t r)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\t_clearU(l, r);\n\t\t\tV value = neutral;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tvoid rangeU(size_t l, size_t r, U u)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\tauto ol = l, or = r;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) _addU(l++, u); \n\t\t\t\tif (r & 1) _addU(--r, u);\n\t\t\t}\n\t\t\t_refresh(ol, or);\n\t\t}\n\t\tV _getNodeF(size_t i)\n\t\t{\n\t\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\t\treturn _nF[i];\n\t\t}\n\t\tbool _isLeaf(size_t i)\n\t\t{\n\t\t\treturn i >= length;\n\t\t}\n\t\tvoid _clearU(size_t i)\n\t\t{\n\t\t\tif (!_nHasU[i]) return;\n\t\t\tif (_isLeaf(i))\n\t\t\t{\n\t\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t\t_nHasU[i] = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nHasU[i] = false;\n\t\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t\t}\n\t\tvoid _addU(size_t i, U u)\n\t\t{\n\t\t\tif (!_nHasU[i])\n\t\t\t{\n\t\t\t\t_nU[i] = u;\n\t\t\t\t_nHasU[i] = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t\t{\n\t\t\treturn [cast(int)start, cast(int)end];\n\t\t}\n\t\tauto opIndex(int[2] slice)\n\t\t{\n\t\t\talias Parent = typeof(this);\n\t\t\tstruct Ans\n\t\t\t{\n\t\t\t\tParent* parent;\n\t\t\t\tint[2] slice;\n\t\t\t\tmixin(q{V }, fName, q{;});\n\t\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t\t{\n\t\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t\t}\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int).Type!(0, \n\t\t\t(v1, v2) => v1 + v2,\n\t\t\t(v, u, size_t l) => v + u * cast(int)l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart[i .. j] += v;\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(int, int).Type!(0, \n\t\t\t(a, b) => max(a, b),\n\t\t\t(mx, set, sz) => set,\n\t\t\t(set1, set2) => set1,\n\t\t\t\"max\",\n\t\t\t\"+\");\n\tauto st = SegTree(noPoints, 0);\n\tauto st2 = STL!(int, int).Type!(0, \n\t\t\t(a, b) => max(a, b),\n\t\t\t(mx, add, sz) => mx + add,\n\t\t\t(add1, add2) => add1 + add2,\n\t\t\t\"max\",\n\t\t\t\"+\")(noPoints, 0);\n\tauto dp = new int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = 0;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st[range[0] .. range[1] + 1].max);\n\t\t}\n\t\tdpi++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] += dpi;\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\n\tforeach(range; ranges[bi]) st2.rangeU(range[0], range[1] + 1, 1);\n\talive[bi] = false;\n\tauto pbi = bi;\n\tbi--;\n\twhile (bi >= 0)\n\t{\n\t\tif (dp[bi] == dp[pbi] - 1)\n\t\t{\n\t\t\tbool isGood = false;\n\t\t\tforeach(range; ranges[bi])\n\t\t\t{\n\t\t\t\t\tif (st2.rangeF(range[0], range[1] + 1) > 0) { isGood = true; break; }\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tforeach(range; ranges[pbi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, -1);\n\t\t\t\tforeach(range; ranges[bi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, +1);\n\t\t\t\talive[bi] = false;\n\t\t\t\tpbi = bi;\n\t\t\t}\n\t\t}\n\t\tbi--;\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n\twriteln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\ntemplate STL(V, U)\n{\n\tstruct Type (V neutral, V function(V, V) f, \n\t\t\tV function(V, U, size_t) fou, \n\t\t\tU function(U, U) uou, \n\t\t\tstring fName = \"f\", string uName = \"u\")\n\t{\n\t\tV[] _nF;\n\t\tU[] _nU;\n\t\tsize_t[] _nSz;\n\t\tbool[] _nHasU;\n\t\tsize_t length = 0;\n\t\tint layers = 0;\n\t\tthis(size_t n, V v)\n\t\t{\n\t\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\t\tauto fn = n;\n\t\t\twhile (fn) {layers++; fn >>= 1;}\n\t\t\tlength = n;\n\t\t\tauto noNodes = 2 * n; \n\t\t\t_nF = new V[](noNodes); \n\t\t\t_nF[n .. 2 * n] = v;\n\t\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t\t_nU = new U[](noNodes);\n\t\t\t_nHasU = new bool[](noNodes);\n\t\t\t_nSz = new size_t[](noNodes);\n\t\t\t_nSz[n .. 2 * n] = 1;\n\t\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t\t}\n\t\tvoid _clearU(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tauto li = layers - 1;\n\t\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t\t}\n\t\tvoid _refresh(size_t l, size_t r)\n\t\t{\n\t\t\tr--;\n\t\t\tl >>= 1; r >>= 1;\n\t\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t\t}\n\t\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t}\n\t\tV rangeF(size_t l, size_t r)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\t_clearU(l, r);\n\t\t\tV value = neutral;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tvoid rangeU(size_t l, size_t r, U u)\n\t\t{\n\t\t\tl += length, r += length;\n\t\t\tauto ol = l, or = r;\n\t\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t\t{\n\t\t\t\tif (l & 1) _addU(l++, u); \n\t\t\t\tif (r & 1) _addU(--r, u);\n\t\t\t}\n\t\t\t_refresh(ol, or);\n\t\t}\n\t\tV _getNodeF(size_t i)\n\t\t{\n\t\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\t\treturn _nF[i];\n\t\t}\n\t\tbool _isLeaf(size_t i)\n\t\t{\n\t\t\treturn i >= length;\n\t\t}\n\t\tvoid _clearU(size_t i)\n\t\t{\n\t\t\tif (!_nHasU[i]) return;\n\t\t\tif (_isLeaf(i))\n\t\t\t{\n\t\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t\t_nHasU[i] = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nHasU[i] = false;\n\t\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t\t}\n\t\tvoid _addU(size_t i, U u)\n\t\t{\n\t\t\tif (!_nHasU[i])\n\t\t\t{\n\t\t\t\t_nU[i] = u;\n\t\t\t\t_nHasU[i] = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_nU[i] = uou(u, _nU[i]);\n\t\t}\n\t\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t\t{\n\t\t\treturn [cast(int)start, cast(int)end];\n\t\t}\n\t\tauto opIndex(int[2] slice)\n\t\t{\n\t\t\talias Parent = typeof(this);\n\t\t\tstruct Ans\n\t\t\t{\n\t\t\t\tParent* parent;\n\t\t\t\tint[2] slice;\n\t\t\t\tmixin(q{V }, fName, q{;});\n\t\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t\t{\n\t\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t\t}\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int).Type!(0, \n\t\t\t(v1, v2) => v1 + v2,\n\t\t\t(v, u, size_t l) => v + u * cast(int)l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\t\tbrute[i .. j] += v;\n\t\t\t\tsmart[i .. j] += v;\n\t\t\t}\n\t\tforeach(i; 0 .. n)\n\t\t\tforeach(j; i + 1 .. n + 1)\n\t\t\t{\n\t\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t\t}\n\t}\n}\n// }}}\n"}, {"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(int, 0, int, (a, b) => max(a, b),\n\t\t\t(mx, set, sz) => set,\n\t\t\t(set1, set2) => set1,\n\t\t\t\"max\",\n\t\t\t\"+\");\n\tauto st = SegTree(noPoints, 0);\n\tauto st2 = STL!(int, 0, int, (a, b) => max(a, b),\n\t\t\t(mx, add, sz) => mx + add,\n\t\t\t(add1, add2) => add1 + add2,\n\t\t\t\"max\",\n\t\t\t\"+\")(noPoints, 0);\n\tauto dp = new int[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = 0;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st[range[0] .. range[1] + 1].max);\n\t\t}\n\t\tdpi++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] += dpi;\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\n\tforeach(range; ranges[bi]) st2.rangeU(range[0], range[1] + 1, 1);\n\talive[bi] = false;\n\tauto pbi = bi;\n\tbi--;\n\twhile (bi >= 0)\n\t{\n\t\tif (dp[bi] == dp[pbi] - 1)\n\t\t{\n\t\t\tbool isGood = false;\n\t\t\tforeach(range; ranges[bi])\n\t\t\t{\n\t\t\t\t\tif (st2.rangeF(range[0], range[1] + 1) > 0) { isGood = true; break; }\n\t\t\t}\n\t\t\tif (isGood)\n\t\t\t{\n\t\t\t\tforeach(range; ranges[pbi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, -1);\n\t\t\t\tforeach(range; ranges[bi])\n\t\t\t\t\tst2.rangeU(range[0], range[1] + 1, +1);\n\t\t\t\talive[bi] = false;\n\t\t\t\tpbi = bi;\n\t\t\t}\n\t\t}\n\t\tbi--;\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, V neutral, U, alias f, alias fou, alias uou, string fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tauto ol = l, or = r;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(ol, or);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int, (v1, v2) => v1 + v2,\n\t\t\t(v, u, l) => v + u * l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\tforeach(j; i + 1 .. n + 1)\n\t\t{\n\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\tbrute[i .. j] += v;\n\t\t\tsmart[i .. j] += v;\n\t\t}\n\t\tforeach(i; 0 .. n)\n\t\tforeach(j; i + 1 .. n + 1)\n\t\t{\n\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\twriteln(bruteAnswer, \" =? \", smartAnswer);\n\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t}\n\t}\n}\n// }}}\n"}], "negative_code": [{"source_code": "\nimmutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto ranges = new Tuple!(int, int)[][](n);\n\tint[] pointSet;\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto rangeIndex = readInt!int - 1;\n\t\tauto rangeStart = readInt!int;\n\t\tauto rangeEnd = readInt!int;\n\t\tpointSet ~= rangeStart;\n\t\tpointSet ~= rangeEnd;\n\t\tranges[rangeIndex] ~= tuple(rangeStart, rangeEnd);\n\t} \n\tsort(pointSet);\n\tpointSet = pointSet.uniq.array;\n\tint noPoints = cast(int) pointSet.length;\n\tint[int] rank;\n\tint nextRank = 0;\n\tforeach(pi; pointSet) rank[pi] = nextRank++;\n\tforeach(ref rangeSet; ranges)\n\t\tforeach(ref range; rangeSet)\n\t\t{\n\t\t\trange[0] = rank[range[0]];\n\t\t\trange[1] = rank[range[1]];\n\t\t}\n\tdebug writeln(\"ranges: \", ranges);\n\talias SegTree = STL!(Tuple!(int, int), tuple(0, -1), Tuple!(int, int), (a, b) => max(a, b),\n\t\t\t(mx, set, sz) => set,\n\t\t\t(set1, set2) => set1,\n\t\t\t\"max\",\n\t\t\t\"+\");\n\tauto st = SegTree(noPoints, tuple(0, -1));\n\tauto dp = new Tuple!(int, int)[](n);\n\tforeach(i, ref dpi; dp)\n\t{\n\t\tdpi = tuple(0, -1);\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tdpi = max(dpi, st[range[0] .. range[1] + 1].max);\n\t\t}\n\t\tdpi[0]++;\n\t\tforeach(range; ranges[i])\n\t\t{\n\t\t\tst[range[0] .. range[1] + 1] += tuple(dpi[0], cast(int)i);\n\t\t}\n\t}\n\tdebug writeln(\"dp: \", dp);\n\tint bdpi = 0;\n\tint bi = -1;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (dp[i][0] > bdpi)\n\t\t{\n\t\t\tbdpi = dp[i][0];\n\t\t\tbi = i;\n\t\t}\n\t}\n\tdebug writeln(\"bdpi = \", bdpi, \" bi = \", bi);\n\tauto alive = new bool[](n);\n\talive[] = true;\n\twhile (bi >= 0)\n\t{\n\t\talive[bi] = false;\n\t\tbi = dp[bi][1];\n\t}\n\twriteln(n - bdpi);\n\tforeach(i; 0 .. n) if (alive[i]) write(i + 1, \" \");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n// STL V, U, f, fou, uou, fName, uName {{{\nstruct STL(V, V neutral, U, alias f, alias fou, alias uou, string fName = \"f\", string uName = \"u\")\n{\n\tV[] _nF;\n\tU[] _nU;\n\tlong[] _nSz;\n\tbool[] _nHasU;\n\tsize_t length = 0;\n\tint layers = 0;\n\tthis(size_t n, V v)\n\t{\n\t\tn = cast(size_t)nextPow2(cast(long)n);\n\t\tauto fn = n;\n\t\twhile (fn) {layers++; fn >>= 1;}\n\t\tlength = n;\n\t\tauto noNodes = 2 * n; \n\t\t_nF = new V[](noNodes); \n\t\t_nF[n .. 2 * n] = v;\n\t\tforeach_reverse(i; 1 .. n) _nF[i] = f(_nF[i<<1], _nF[(i<<1)+1]);\n\t\t_nU = new U[](noNodes);\n\t\t_nHasU = new bool[](noNodes);\n\t\t_nSz = new long[](noNodes);\n\t\t_nSz[n .. 2 * n] = 1;\n\t\tforeach_reverse(i; 1 .. n) _nSz[i] = _nSz[i<<1] * 2;\n\t}\n\tvoid _clearU(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tauto li = layers - 1;\n\t\tfor(; li > 0 && (l >> li) == (r >> li); li--) _clearU(l >> li);\n\t\tfor(; li > 0; li--) _clearU(l >> li), _clearU(r >> li);\n\t}\n\tvoid _refresh(size_t l, size_t r)\n\t{\n\t\tr--;\n\t\tl >>= 1; r >>= 1;\n\t\tfor(; l != r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\t_nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t\t\t_nF[r] = f(_getNodeF(r<<1), _getNodeF((r<<1)+1));\n\t\t}\n\t\tfor(; l; l >>= 1) _nF[l] = f(_getNodeF(l<<1), _getNodeF((l<<1)+1));\n\t}\n\tV rangeF(size_t l, size_t r)\n\t{\n\t\tl += length, r += length;\n\t\t_clearU(l, r);\n\t\tV value = neutral;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) value = f(value, _getNodeF(l++)); \n\t\t\tif (r & 1) value = f(value, _getNodeF(--r));\n\t\t}\n\t\treturn value;\n\t}\n\tvoid rangeU(size_t l, size_t r, U u)\n\t{\n\t\tl += length, r += length;\n\t\tfor(; l < r; l >>= 1, r >>= 1)\n\t\t{\n\t\t\tif (l & 1) _addU(l++, u); \n\t\t\tif (r & 1) _addU(--r, u);\n\t\t}\n\t\t_refresh(l, r);\n\t}\n\tV _getNodeF(size_t i)\n\t{\n\t\tif (_nHasU[i]) return cast(V) fou(_nF[i], _nU[i], _nSz[i]);\n\t\treturn _nF[i];\n\t}\n\tbool _isLeaf(size_t i)\n\t{\n\t\treturn i >= length;\n\t}\n\tvoid _clearU(size_t i)\n\t{\n\t\tif (!_nHasU[i]) return;\n\t\tif (_isLeaf(i))\n\t\t{\n\t\t\t_nF[i] = _getNodeF(i);\n\t\t\t_nHasU[i] = false;\n\t\t\treturn;\n\t\t}\n\t\t_nHasU[i] = false;\n\t\t_addU(i << 1, _nU[i]), _addU((i << 1) + 1, _nU[i]);\n\t\t_nF[i] = f(_getNodeF(i<<1), _getNodeF((i<<1)+1));\n\t}\n\tvoid _addU(size_t i, U u)\n\t{\n\t\tif (!_nHasU[i])\n\t\t{\n\t\t\t_nU[i] = u;\n\t\t\t_nHasU[i] = true;\n\t\t\treturn;\n\t\t}\n\t\t_nU[i] = uou(u, _nU[i]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\talias Parent = typeof(this);\n\t\tstruct Ans\n\t\t{\n\t\t\tParent* parent;\n\t\t\tint[2] slice;\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t\tvoid opOpAssign(string op)(U u) if (op == uName)\n\t\t\t{\n\t\t\t\tparent.rangeU(slice[0], slice[1], u);\n\t\t\t}\n\t\t}\n\t\treturn Ans(&this, slice, rangeF(slice[0], slice[1]));\n\t}\n}\nlong nextPow2(long n)\n{\n\tint p = 1;\n\tfor(; p < n; p <<= 1) {}\n\treturn p;\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.random;\n\timport std.stdio;\n\talias SumQSumU = STL!(int, int, (v1, v2) => v1 + v2,\n\t\t\t(v, u, l) => v + u * l,\n\t\t\t(ni, pi) => ni + pi,\n\t\t\t\"sum\",\n\t\t\t\"+\");\n\tauto n = 100;\n\tint[] brute = new int[](n);\n\tauto smart = SumQSumU(n, 0);\n\tint rounds = 1000;\n\tforeach(round; 0 .. rounds)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\tforeach(j; i + 1 .. n + 1)\n\t\t{\n\t\t\tint v = uniform!\"[]\"(1, 20);\n\t\t\tbrute[i .. j] += v;\n\t\t\tsmart[i .. j] += v;\n\t\t}\n\t\tforeach(i; 0 .. n)\n\t\tforeach(j; i + 1 .. n + 1)\n\t\t{\n\t\t\tauto bruteAnswer = brute[i .. j].fold!((a, b) => (a + b));\n\t\t\tauto smartAnswer = smart[i .. j].sum;\n\t\t\twriteln(bruteAnswer, \" =? \", smartAnswer);\n\t\t\tassert(bruteAnswer == smartAnswer);\n\t\t}\n\t}\n}\n// }}}\n"}], "src_uid": "ede7de5979a00d81f774ffdf27cea017"} {"source_code": "// cheese-cracker [2022-01-25]\n\nconst long INF = 1000_000_000_000;\n\nvoid main(){\n auto n = scanArray!int;\n\n auto arr = new tup[][4];\n arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n\n alias pr = Tuple!(int, int);\n for(int i = 0; i < 3; ++i){\n bool[pr] hmap;\n\n // Scan into hmap\n int m = scan!int;\n for(int j = 0; j < m; ++j){\n hmap[pr(scan!int, scan!int)] = 1;\n }\n\n // Sort and Update Prev Round\n int fst = i;\n int snd = fst+1;\n arr[fst].sort;\n foreach(ref el; arr[snd]){\n int x = el[1];\n bool f = 0;\n for(int k = 0; k < n[fst] && arr[fst][k][0] < INF; ++k){\n int y = arr[fst][k][1];\n if(! (pr(y, x) in hmap) ){\n el[0] += arr[fst][k][0];\n f = 1;\n break;\n }\n }\n if(!f){ el[0] = INF; }\n }\n hmap.clear;\n }\n arr[3].sort;\n writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, int);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.container;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int infinity = int.max / 2;\r\n\r\nvoid main ()\r\n{\r\n\tstring s;\r\n\twhile ((s = readln.strip) != \"\")\r\n\t{\r\n\t\tauto n = s.splitter.map !(to !(int)).array;\r\n\t\tint [] [] a;\r\n\t\tforeach (i; 0..4)\r\n\t\t{\r\n\t\t\ta ~= readln.splitter.map !(to !(int)).array;\r\n\t\t}\r\n\t\tforeach (i; 0..3)\r\n\t\t{\r\n\t\t\tauto t = redBlackTree !(true) (a[i]);\r\n\t\t\tt.insert (infinity);\r\n\t\t\tauto g = new int [] [n[i + 1]];\r\n\t\t\tauto m = readln.strip.to !(int);\r\n\t\t\tforeach (j; 0..m)\r\n\t\t\t{\r\n\t\t\t\tauto v = readln.split;\r\n\t\t\t\tg[v[1].to !(int) - 1] ~= v[0].to !(int) - 1;\r\n\t\t\t}\r\n\t\t\tforeach (k; 0..n[i + 1])\r\n\t\t\t{\r\n\t\t\t\tforeach (c; g[k])\r\n\t\t\t\t{\r\n\t\t\t\t\tt.removeKey (a[i][c]);\r\n\t\t\t\t}\r\n\t\t\t\tauto value = t.front;\r\n\t\t\t\tforeach (c; g[k])\r\n\t\t\t\t{\r\n\t\t\t\t\tt.insert (a[i][c]);\r\n\t\t\t\t}\r\n\t\t\t\ta[i + 1][k] = (value < infinity) ?\r\n\t\t\t\t a[i + 1][k] + value : infinity;\r\n\t\t\t}\r\n\t\t}\r\n\t\tauto res = a.back.minElement;\r\n\t\twriteln (res < infinity ? res : -1);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "// cheese-cracker [2022-01-25]\n\nconst long INF = 1000_000_000_000_000;\n\nvoid main(){\n auto n = scanArray!int;\n\n auto arr = new tup[][4];\n arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n\n alias pr = Tuple!(int, int);\n for(int i = 0; i < 3; ++i){\n bool[pr] hmap;\n\n // Scan into hmap\n int m = scan!int;\n for(int j = 0; j < m; ++j){\n hmap[pr(scan!int, scan!int)] = 1;\n }\n\n // Sort and Update Prev Round\n int fst = i;\n int snd = fst+1;\n arr[fst].sort;\n foreach(ref el; arr[snd]){\n int x = el[1];\n bool f = 0;\n for(int k = 0; k < n[fst] && arr[fst][k][0] < INF; ++k){\n int y = arr[fst][k][1];\n if(! (pr(x, y) in hmap) ){\n el[0] += arr[fst][k][0];\n f = 1;\n break;\n }\n }\n if(!f){ el[0] = INF; }\n }\n }\n arr[3].sort;\n writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, int);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}, {"source_code": "// cheese-cracker [2022-01-25]\n\nconst long INF = 1_000_000_000;\n\nvoid main(){\n auto n = scanArray!int;\n\n auto arr = new tup[][4];\n arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n\n alias pr = Tuple!(int, int);\n for(int i = 0; i < 3; ++i){\n auto hmap = redBlackTree!(pr);\n\n // Scan into hmap\n int m = scan!int;\n for(int j = 0; j < m; ++j){\n hmap.insert(pr(scan!int, scan!int));\n }\n\n // Sort and Update Prev Round\n int fst = i;\n int snd = fst+1;\n arr[fst].sort;\n foreach(ref el; arr[snd]){\n int x = el[1];\n bool f = 0;\n for(int k = 0; k < n[fst] && arr[fst][k][0] < INF; ++k){\n int y = arr[fst][k][1];\n if(! (pr(x, y) in hmap) ){\n el[0] += arr[fst][k][0];\n f = 1;\n break;\n }\n }\n if(!f){ el[0] = INF; }\n }\n }\n arr[3].sort;\n writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, int);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}, {"source_code": "// cheese-cracker [2022-01-25]\n\nconst long INF = 1_000_000_000;\n\nvoid main(){\n auto n = scanArray!int;\n\n auto arr = new tup[][4];\n arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n\n alias pr = Tuple!(int, int);\n for(int i = 0; i < 3; ++i){\n bool[pr] hmap;\n\n // Scan into hmap\n int m = scan!int;\n for(int j = 0; j < m; ++j){\n hmap[pr(scan!int, scan!int)] = 1;\n }\n\n // Sort and Update Prev Round\n int fst = i;\n int snd = fst+1;\n arr[fst].sort;\n foreach(ref el; arr[snd]){\n int x = el[1];\n bool f = 0;\n for(int k = 0; k < n[fst] && arr[fst][k][0] < INF; ++k){\n int y = arr[fst][k][1];\n if(! (pr(x, y) in hmap) ){\n el[0] += arr[fst][k][0];\n f = 1;\n break;\n }\n }\n if(!f){ el[0] = INF; }\n }\n }\n arr[3].sort;\n writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, int);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}, {"source_code": "// cheese-cracker [2022-01-25]\n\nconst long INF = 1_000_000_000;\n\nvoid main(){\n auto n = scanArray!int;\n\n auto arr = new tup[][4];\n arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;\n\n alias pr = Tuple!(int, int);\n for(int i = 0; i < 3; ++i){\n bool[pr] hmap;\n\n // Scan into hmap\n int m = scan!int;\n for(int j = 0; j < m; ++j){\n hmap[pr(scan!int, scan!int)] = 1;\n }\n\n // Sort and Update Prev Round\n int fst = i;\n int snd = fst+1;\n arr[fst].sort;\n foreach(ref el; arr[snd]){\n int x = el[1];\n bool f = 0;\n for(int k = 0; k < n[0] && arr[fst][k][0] < INF; ++k){\n int y = arr[fst][k][1];\n if(! (pr(x, y) in hmap) ){\n el[0] += arr[fst][k][0];\n f = 1;\n break;\n }\n }\n if(!f){ el[0] = INF; }\n }\n }\n arr[3].sort;\n writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, int);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}, {"source_code": "import std.algorithm;\r\nimport std.container;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int infinity = int.max / 2;\r\n\r\nvoid main ()\r\n{\r\n\tstring s;\r\n\twhile ((s = readln.strip) != \"\")\r\n\t{\r\n\t\tauto n = s.splitter.map !(to !(int)).array;\r\n\t\tint [] [] a;\r\n\t\tforeach (i; 0..4)\r\n\t\t{\r\n\t\t\ta ~= readln.splitter.map !(to !(int)).array;\r\n\t\t}\r\n\t\tforeach (i; 0..3)\r\n\t\t{\r\n\t\t\tauto t = redBlackTree !(true) (a[i]);\r\n\t\t\tt.insert (infinity);\r\n\t\t\tauto g = new int [] [n[i + 1]];\r\n\t\t\tauto m = readln.strip.to !(int);\r\n\t\t\tforeach (j; 0..m)\r\n\t\t\t{\r\n\t\t\t\tauto v = readln.splitter.map !(to !(int)).array;\r\n\t\t\t\tv[] -= 1;\r\n\t\t\t\tg[v[1]] ~= v[0];\r\n\t\t\t}\r\n\t\t\tforeach (k; 0..n[i + 1])\r\n\t\t\t{\r\n\t\t\t\tforeach (c; g[k])\r\n\t\t\t\t{\r\n\t\t\t\t\tt.removeKey (a[i][c]);\r\n\t\t\t\t}\r\n\t\t\t\tauto value = t.front;\r\n\t\t\t\tforeach (c; g[k])\r\n\t\t\t\t{\r\n\t\t\t\t\tt.insert (a[i][c]);\r\n\t\t\t\t}\r\n\t\t\t\ta[i + 1][k] = (value < infinity) ?\r\n\t\t\t\t a[i + 1][k] + value : infinity;\r\n\t\t\t}\r\n\t\t}\r\n\t\tauto res = a.back.maxElement;\r\n\t\twriteln (res < infinity ? res : -1);\r\n\t}\r\n}\r\n"}], "src_uid": "ed0765719bfc3903701c0c14b7ad15c7"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long k;\n readf!\" %d \"(k);\n long x, y;\n while ((x + 1) * (x + 1) < k)\n x++;\n y = k - x * x - 1;\n if (y <= x) {\n writefln(\"%d %d\", y + 1, x + 1);\n } else {\n long delta = y - x;\n y = x;\n x -= delta;\n writefln(\"%d %d\", y + 1, x + 1);\n }\n }\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll k = scan;\n k -= 1;\n ll rt = to!ll(floor(sqrt(to!double(k))));\n if((rt + 1) *(rt + 1) <= k){\n rt += 1;\n }\n ll lef = k - rt*rt;\n ll d = min(rt, lef);\n ll b = max(0, lef - rt);\n ll x = (rt+1) - b;\n ll y = d + 1;\n writeln(y, \" \", x);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "negative_code": [], "src_uid": "f8335c59cd05988c8053f138c4df06aa"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto s = readln.strip;\r\n\t\tauto t = readln.strip;\r\n\t\tauto b = n - m + 1;\r\n\t\tauto r = s[0..b];\r\n\t\tauto can = (t[0] == '0') ?\r\n\t\t r.minElement == '0' :\r\n\t\t r.maxElement == '1';\r\n\t\twriteln ((can && s[b..$] == t[1..$]) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nenum INF = 10L^^18;\r\n\r\nint N, M;\r\nstring A, B;\r\n\r\nbool solve() {\r\n if (A[N - M + 1 .. N] != B[1 .. M]) {\r\n return false;\r\n }\r\n bool[2] has;\r\n foreach (i; 0 .. N - M + 1) {\r\n has[A[i] - '0'] = true;\r\n }\r\n if (has[0] && B[0] == '0') return true;\r\n if (has[1] && B[0] == '1') return true;\r\n return false;\r\n}\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const numCases = readInt;\r\n foreach (caseId; 0 .. numCases) {\r\n N = readInt;\r\n M = readInt;\r\n A = readToken;\r\n B = readToken;\r\n \r\n const ans = solve;\r\n writeln(ans ? \"YES\" : \"NO\");\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "83050a8a4c7b64004681bdadb630292e"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n,m,k;\r\n readf!\" %d %d %d \"(n,m,k);\r\n auto a = readarray!int;\r\n bool flag = true;\r\n int capacity;\r\n int maxR = k;\r\n bool[int] memory;\r\n foreach(e; a) {\r\n if (e == maxR)\r\n maxR--;\r\n else {\r\n memory[e] = true;\r\n capacity++;\r\n }\r\n while (maxR in memory) {\r\n memory.remove(maxR);\r\n capacity--;\r\n maxR--;\r\n }\r\n if (capacity > n*m - 4) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag)\r\n writeln(\"YA\");\r\n else\r\n writeln(\"TIDAK\");\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n, m, k;\n readf!\" %d %d %d \"(n, m, k);\n auto a = readln.splitter.map!(to!long).map!(x => k + 1 - x).array;\n// writeln(a);\n long maxsize = n * m - 3;\n auto h = redBlackTree!(\"a<b\", true, long)();\n long stored = 0;\n bool good = true;\n foreach (x ; a) {\n while (!h.empty && h.front == stored + 1) {\n stored = h.front;\n h.removeFront;\n }\n if (h.length >= maxsize) {\n good = false;\n break;\n }\n h.insert(x);\n }\n// writeln(h);\n while (!h.empty && h.front == stored + 1) {\n stored = h.front;\n h.removeFront;\n }\n if (!h.empty)\n good = false;\n writeln(good ? \"YA\" : \"TIDAK\");\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m, k;\r\n\t\treadf !(\" %s %s %s\") (n, m, k);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta[] -= 1;\r\n\t\tint limit = n * m - 4;\r\n\t\tbool ok = true;\r\n\t\tint num = 0;\r\n\t\tint last = k - 1;\r\n\t\tauto vis = new bool [k];\r\n\t\tforeach (i, ref cur; a)\r\n\t\t{\r\n\t\t\tvis[cur] = true;\r\n\t\t\tnum += 1;\r\n\t\t\twhile (last >= 0 && vis[last])\r\n\t\t\t{\r\n\t\t\t\tlast -= 1;\r\n\t\t\t\tnum -= 1;\r\n\t\t\t}\r\n\t\t\tok &= (num <= limit);\r\n\t\t}\r\n\t\twriteln (ok ? \"YA\" : \"TIDAK\");\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n,m,k;\r\n readf!\" %d %d %d \"(n,m,k);\r\n auto a = readarray!int;\r\n bool flag = true;\r\n int capacity;\r\n int maxR = k;\r\n bool[int] memory;\r\n foreach(e; a) {\r\n if (e == maxR)\r\n maxR--;\r\n else {\r\n memory[e] = true;\r\n capacity++;\r\n }\r\n while (maxR in memory) {\r\n memory.remove(maxR);\r\n capacity--;\r\n maxR--;\r\n }\r\n if (capacity > (n-1)*(m-1)) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag)\r\n writeln(\"YA\");\r\n else\r\n writeln(\"TIDAK\");\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.functional;\r\n \r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n \r\nvoid solve() {\r\n int n,m,k;\r\n readf!\" %d %d %d \"(n,m,k);\r\n auto a = readarray!int;\r\n bool flag = true;\r\n int capacity;\r\n int maxR = k;\r\n bool[int] memory;\r\n foreach(e; a) {\r\n if (e == maxR)\r\n maxR--;\r\n else {\r\n memory[e] = true;\r\n capacity++;\r\n }\r\n while (maxR in memory) {\r\n memory.remove(e);\r\n capacity--;\r\n maxR--;\r\n }\r\n if (capacity > (n-1)*(m-1)) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n if (flag)\r\n writeln(\"YA\");\r\n else\r\n writeln(\"TIDAK\");\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "src_uid": "aaebae32edfe31f45bbe95c185f5460f"} {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nimport std.numeric: fft,Fft,gcd,inverseFft;\nalias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;\nalias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;\nprivate\n{\n\tpure nothrow \n\t{\n\t\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\t\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\t\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\t\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\t\tsize_t lowb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tsize_t l=0,r=a.length;\n\t\t\twhile(r-l>1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]<g))r=m;\n\t\t\t\telse l=m;\n\t\t\t}\n\t\t\treturn (!(a[l]<g))?l:r;\n\t\t}\n\t\tsize_t upb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tsize_t l=0,r=a.length;\n\t\t\twhile(r-l>1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g<a[m])r=m;\n\t\t\t\telse l=m;\n\t\t\t}\n\t\t\treturn (g<a[l])?l:r;\n\t\t}\n\t\tsize_t binf(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tauto pos=lowb(a,g);\n\t\t\treturn (g==a[pos])?pos:a.length;\n\t\t}\n\t\tbool binary_search(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\treturn binf(a,g)!=a.length;\n\t\t}\n\t}\n\tvoid putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))\n\t{foreach(const ref i;a)write(i,ch);}\n\tvoid putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))\n\t{\n\t\tforeach(ref const i;a)\n\t\t{\n\t\t\tforeach(ref const j;i)write(j,' ');\n\t\t\twriteln;\n\t\t}\n\t}\n\tbool getarr(X)(X a,in size_t n)\n\t{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\n\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treturn s==ptrs.length;\n\t}\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treadln;\n\t\treturn s==ptrs.length;\n\t}\n\tnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\n\tnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n\t@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nprivate\n{\n\n}\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint a,b,c;\nloop:while(read(a,b,c))\n\t{\n\t\tint n;\n\t\tread(n);\n\t\tauto ar=arread!int;\n\t\tsort(ar);\n\t\tdebug writeln(ar);\n\t\tdebug writeln(lowb(ar,c),' ',upb(ar,b));\n\t\twriteln(max(lowb(ar,c)*1L-upb(ar,b)*1L,0));\n\t}\n}", "positive_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nimport std.numeric: fft,Fft,gcd,inverseFft;\nalias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;\nalias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;\nprivate\n{\n\tpure nothrow \n\t{\n\t\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\t\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\t\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\t\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\t\tsize_t lowb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tsize_t l=0,r=a.length;\n\t\t\twhile(r-l>1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]<g))r=m;\n\t\t\t\telse l=m;\n\t\t\t}\n\t\t\treturn (!(a[l]<g))?l:r;\n\t\t}\n\t\tsize_t upb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tsize_t l=0,r=a.length;\n\t\t\twhile(r-l>1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g<a[m])r=m;\n\t\t\t\telse l=m;\n\t\t\t}\n\t\t\treturn (g<a[l])?l:r;\n\t\t}\n\t\tsize_t binf(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tauto pos=lowb(a,g);\n\t\t\treturn (g==a[pos])?pos:a.length;\n\t\t}\n\t\tbool binary_search(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\treturn binf(a,g)!=a.length;\n\t\t}\n\t}\n\tvoid putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))\n\t{foreach(const ref i;a)write(i,ch);}\n\tvoid putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))\n\t{\n\t\tforeach(ref const i;a)\n\t\t{\n\t\t\tforeach(ref const j;i)write(j,' ');\n\t\t\twriteln;\n\t\t}\n\t}\n\tbool getarr(X)(X a,in size_t n)\n\t{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\n\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treturn s==ptrs.length;\n\t}\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treadln;\n\t\treturn s==ptrs.length;\n\t}\n\tnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\n\tnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n\t@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nprivate\n{\n\n}\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint a,b,c;\nloop:while(read(a,b,c))\n\t{\n\t\tint n;\n\t\tread(n);\n\t\tint ans;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tint x;\n\t\t\tinput(x);\n\t\t\tif(x>b && x<c)ans++;\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const A = readInt();\n const B = readInt();\n const C = readInt();\n const N = readInt();\n auto X = new int[N];\n foreach (i; 0 .. N) {\n X[i] = readInt();\n }\n \n int ans;\n foreach (i; 0 .. N) {\n if (B < X[i] && X[i] < C) {\n ++ans;\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nimport std.numeric: fft,Fft,gcd,inverseFft;\nalias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;\nalias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;\nprivate\n{\n\tpure nothrow \n\t{\n\t\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\t\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\t\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\t\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\t\tsize_t lowb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tsize_t l=0,r=a.length;\n\t\t\twhile(r-l>1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]<g))r=m;\n\t\t\t\telse l=m;\n\t\t\t}\n\t\t\treturn (!(a[l]<g))?l:r;\n\t\t}\n\t\tsize_t upb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tauto pos=lowb(a,g);\n\t\t\tif(pos==a.length)return pos;\n\t\t\telse return a[pos]==g?pos+1:pos;\n\t\t}\n\t\tsize_t binf(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\tauto pos=lowb(a,g);\n\t\t\treturn (g==a[pos])?pos:a.length;\n\t\t}\n\t\tbool binary_search(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t\t{\n\t\t\treturn binf(a,g)!=a.length;\n\t\t}\n\t}\n\tvoid putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))\n\t{foreach(const ref i;a)write(i,ch);}\n\tvoid putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))\n\t{\n\t\tforeach(ref const i;a)\n\t\t{\n\t\t\tforeach(ref const j;i)write(j,' ');\n\t\t\twriteln;\n\t\t}\n\t}\n\tbool getarr(X)(X a,in size_t n)\n\t{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\n\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treturn s==ptrs.length;\n\t}\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treadln;\n\t\treturn s==ptrs.length;\n\t}\n\tnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\n\tnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n\t@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nprivate\n{\n\n}\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint a,b,c;\nloop:while(read(a,b,c))\n\t{\n\t\tint n;\n\t\tread(n);\n\t\tauto ar=arread!int;\n\t\tsort(ar);\n\t\tdebug writeln(lowb(ar,c),' ',upb(ar,b));\n\t\twriteln(max(lowb(ar,c)*1L-upb(ar,b)*1L,0));\n\t}\n}"}], "src_uid": "aceadc8eadf6d5efd7c5a9fbc0396423"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long a, b;\n readf!\" %d %d \"(a, b);\n long g = gcd(a, b);\n// writeln(g);\n if (b < a) {\n long tmp = b;\n b = a;\n a = tmp;\n }\n// writefln(\"a=%d b=%d\", a, b);\n long d = b - a;\n// writefln(\"d=%d\", d);\n if (a == b) {\n writeln(\"0 0\");\n continue;\n }\n long ans1 = abs(a - a / d * d);\n long ans2 = abs(a - (a + d - 1) / d * d);\n long ans3 = a;\n writefln(\"%d %d\", d, min(ans1, ans2, ans3));\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\r\n\t\tif (a == b)\r\n\t\t{\r\n\t\t\tans[ti] = [0, 0];\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (a > b)\r\n\t\t\tswap(a, b);\r\n\t\tauto d = b - a;\r\n\t\tauto rem = b % d;\r\n\t\tans[ti] = [d, min((d-rem) % d, rem)];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e[0], \" \", e[1]);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\nimport std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n while(tests--) {\r\n long a, b;\r\n readf!\"%s %s\\n\"(a, b);\r\n if (a == b) {\r\n \"0 0\".writeln;\r\n }\r\n else {\r\n long d = abs(a - b);\r\n long g = min(a % d, d - (a % d));\r\n writefln!\"%s %s\"(d, g);\r\n }\r\n }\r\n\r\n} // main\r\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll a = scan;\n ll b = scan;\n ll diff = abs(a - b);\n ll rem = 0;\n if(diff > 0){\n rem = min(b % diff, diff - (b % diff));\n }\n writeln(diff, \" \", rem);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1543/problem/A\n// math\nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long a, b;\n readf(\"%s %s\\n\", &a, &b);\n if(a == b) {\n \"0 0\".writeln;\n continue;\n }\n if(a > b) {\n swap(a, b);\n }\n writefln(\"%s %s\", b - a, min(a % (b - a), b - a - a % (b - a)));\n}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\r\n\t\tif (a == b)\r\n\t\t{\r\n\t\t\tans[ti] = [0, 0];\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\telse if (a == 0)\r\n\t\t{\r\n\t\t\tans[ti] = [b, 0];\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (a > b)\r\n\t\t\tswap(a, b);\r\n\t\tauto d = b - a;\r\n\t\tauto rem = b % d;\r\n\t\tans[ti] = [d, (d-rem) % d];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e[0], \" \", e[1]);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD;\r\n\t\tauto b = RD;\r\n\r\n\t\tif (a == b)\r\n\t\t{\r\n\t\t\tans[ti] = [0, 0];\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (a > b)\r\n\t\t\tswap(a, b);\r\n\t\tauto d = b - a;\r\n\t\tauto rem = b % d;\r\n\t\tans[ti] = [d, (d-rem) % d];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e[0], \" \", e[1]);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "994a9cb52cf0fdab72be068eab1b27ef"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MED_N = 1 << 17;\nimmutable int MAX_N = MED_N << 1;\n\nstruct Node\n{\n\tint max_value;\n\tint max_position;\n\tlong sum_values;\n}\n\n__gshared Node [MAX_N] t;\n\nlong get_sum (int l, int r)\n{\n\tlong res = 0;\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1)\n\t\t{\n\t\t\tres += t[l].sum_values;\n\t\t\tl++;\n\t\t}\n\t\tif (!(r & 1))\n\t\t{\n\t\t\tres += t[r].sum_values;\n\t\t\tr--;\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid assign (int k, int x)\n{\n\tassert (MED_N <= k && k < MAX_N);\n\tt[k].max_value = x;\n\tt[k].max_position = k;\n\tt[k].sum_values = x;\n\tfor (int i = k >> 1; i > 0; i >>= 1, k >>= 1)\n\t{\n\t\tif (t[k].max_value < t[k ^ 1].max_value)\n\t\t{\n\t\t\tk ^= 1;\n\t\t}\n\t\tt[i].max_value = t[k].max_value;\n\t\tt[i].max_position = t[k].max_position;\n\t\tt[i].sum_values = t[k].sum_values + t[k ^ 1].sum_values;\n\t}\n}\n\nvoid modulo (int k, int x)\n{\n\twhile (t[k].max_value >= x)\n\t{\n\t\tassign (t[k].max_position, t[k].max_value % x);\n\t}\n}\n\nvoid modulo (int l, int r, int x)\n{\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1)\n\t\t{\n\t\t\tmodulo (l, x);\n\t\t\tl++;\n\t\t}\n\t\tif (!(r & 1))\n\t\t{\n\t\t\tmodulo (r, x);\n\t\t\tr--;\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\tint n;\n\tint m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i, ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t\tassign (i + MED_N, x);\n\t\t}\n\t\tforeach (q; 0..m)\n\t\t{\n\t\t\tint t;\n\t\t\tint l;\n\t\t\tint r;\n\t\t\tint x;\n\t\t\tint k;\n\t\t\treadf (\" %s\", &t);\n\t\t\tswitch (t)\n\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\t\t\twriteln (get_sum (l - 1, r - 1));\n\t\t\t\t\tbreak;\n\t\t\t\tcase 2:\n\t\t\t\t\treadf (\" %s %s %s\", &l, &r, &x);\n\t\t\t\t\tmodulo (l - 1, r - 1, x);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 3:\n\t\t\t\t\treadf (\" %s %s\", &k, &x);\n\t\t\t\t\tassign (k - 1 + MED_N, x);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nimmutable int MED_N = 1 << 17, MAX_N = MED_N << 1;\n\nstruct Node {int v, p; long s;}\n\nNode [MAX_N] t;\n\nlong get_sum (int l, int r) {\n\tlong res = 0;\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {\n\t\tif (l & 1) res += t[l].s, l++;\n\t\tif (!(r & 1)) res += t[r].s, r--;\n\t}\n\treturn res;\n}\n\nvoid assign (int k, int x) {\n\tt[k].v = x;\n\tt[k].p = k;\n\tt[k].s = x;\n\tfor (int i = k >> 1; i > 0; k = i, i >>= 1) {\n\t\tif (t[k].v < t[k ^ 1].v) k ^= 1;\n\t\tt[i].v = t[k].v;\n\t\tt[i].p = t[k].p;\n\t\tt[i].s = t[k].s + t[k ^ 1].s;\n\t}\n}\n\nvoid modulo (int k, int x) {\n\twhile (t[k].v >= x) assign (t[k].p, t[k].v % x);\n}\n\nvoid modulo (int l, int r, int x) {\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {\n\t\tif (l & 1) modulo (l, x), l++;\n\t\tif (!(r & 1)) modulo (r, x), r--;\n\t}\n}\n\nvoid main () {\n\tint n, m, t, l, r, x, k;\n\twhile (readf (\" %s %s\", &n, &m) > 0) {\n\t\tforeach (i; 1..n + 1) {\n\t\t\treadf (\" %s\", &x);\n\t\t\tassign (i + MED_N, x);\n\t\t}\n\t\tforeach (q; 0..m) {\n\t\t\treadf (\" %s\", &t);\n\t\t\tif (t == 1) {\n\t\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\t\twriteln (get_sum (l, r));\n\t\t\t} else if (t == 2) {\n\t\t\t\treadf (\" %s %s %s\", &l, &r, &x);\n\t\t\t\tmodulo (l, r, x);\n\t\t\t} else if (t == 3) {\n\t\t\t\treadf (\" %s %s\", &k, &x);\n\t\t\t\tassign (k + MED_N, x);\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int MED_N = 1 << 17;\nimmutable int MAX_N = MED_N << 1;\n\nstruct Node\n{\n\tint v, p;\n\tlong s;\n}\n\nNode [MAX_N] t;\n\nlong get_sum (int l, int r)\n{\n\tlong res = 0;\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1)\n\t\t{\n\t\t\tres += t[l].s;\n\t\t\tl++;\n\t\t}\n\t\tif (!(r & 1))\n\t\t{\n\t\t\tres += t[r].s;\n\t\t\tr--;\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid assign (int k, int x)\n{\n\tt[k].v = x;\n\tt[k].p = k;\n\tt[k].s = x;\n\tfor (int i = k >> 1; i > 0; k = i, i >>= 1)\n\t{\n\t\tif (t[k].v < t[k ^ 1].v)\n\t\t{\n\t\t\tk ^= 1;\n\t\t}\n\t\tt[i].v = t[k].v;\n\t\tt[i].p = t[k].p;\n\t\tt[i].s = t[k].s + t[k ^ 1].s;\n\t}\n}\n\nvoid modulo (int k, int x)\n{\n\twhile (t[k].v >= x)\n\t{\n\t\tassign (t[k].p, t[k].v % x);\n\t}\n}\n\nvoid modulo (int l, int r, int x)\n{\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)\n\t{\n\t\tif (l & 1)\n\t\t{\n\t\t\tmodulo (l, x);\n\t\t\tl++;\n\t\t}\n\t\tif (!(r & 1))\n\t\t{\n\t\t\tmodulo (r, x);\n\t\t\tr--;\n\t\t}\n\t}\n}\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i, ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t\tassign (i + MED_N, x);\n\t\t}\n\t\tforeach (q; 0..m)\n\t\t{\n\t\t\tint t, l, r, x, k;\n\t\t\treadf (\" %s\", &t);\n\t\t\tswitch (t)\n\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\t\t\twriteln (get_sum (l - 1, r - 1));\n\t\t\t\t\tbreak;\n\t\t\t\tcase 2:\n\t\t\t\t\treadf (\" %s %s %s\", &l, &r, &x);\n\t\t\t\t\tmodulo (l - 1, r - 1, x);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 3:\n\t\t\t\t\treadf (\" %s %s\", &k, &x);\n\t\t\t\t\tassign (k - 1 + MED_N, x);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int MED_N = 1 << 17, MAX_N = MED_N << 1;\n\nstruct Node {int v, p; long s;}\n\nvoid main () {\nNode [MAX_N] a;\n\nlong get_sum (int l, int r) {\n\tlong res = 0;\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {\n\t\tif (l & 1) res += a[l].s, l++;\n\t\tif (!(r & 1)) res += a[r].s, r--;\n\t}\n\treturn res;\n}\n\nvoid assign (int k, int x) {\n\ta[k].v = x;\n\ta[k].p = k;\n\ta[k].s = x;\n\tfor (int i = k >> 1; i > 0; k = i, i >>= 1) {\n\t\tif (a[k].v < a[k ^ 1].v) k ^= 1;\n\t\ta[i].v = a[k].v;\n\t\ta[i].p = a[k].p;\n\t\ta[i].s = a[k].s + a[k ^ 1].s;\n\t}\n}\n\nvoid modulo (int k, int x) {\n\twhile (a[k].v >= x) assign (a[k].p, a[k].v % x);\n}\n\nvoid modulo2 (int l, int r, int x) {\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {\n\t\tif (l & 1) modulo (l, x), l++;\n\t\tif (!(r & 1)) modulo (r, x), r--;\n\t}\n}\n\n\tint n, m, t, l, r, x, k;\n\twhile (readf (\" %s %s\", &n, &m) > 0) {\n\t\tforeach (i; 1..n + 1) {\n\t\t\treadf (\" %s\", &x);\n\t\t\tassign (i + MED_N, x);\n\t\t}\n\t\tforeach (q; 0..m) {\n\t\t\treadf (\" %s\", &t);\n\t\t\tif (t == 1) {\n\t\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\t\twriteln (get_sum (l, r));\n\t\t\t} else if (t == 2) {\n\t\t\t\treadf (\" %s %s %s\", &l, &r, &x);\n\t\t\t\tmodulo2 (l, r, x);\n\t\t\t} else if (t == 3) {\n\t\t\t\treadf (\" %s %s\", &k, &x);\n\t\t\t\tassign (k + MED_N, x);\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int MED_N = 1 << 17, MAX_N = MED_N << 1;\n\nstruct Node {int v, p; long s;}\n\nclass D {\nstatic:\nNode [MAX_N] t;\n\nlong get_sum (int l, int r) {\n\tlong res = 0;\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {\n\t\tif (l & 1) res += t[l].s, l++;\n\t\tif (!(r & 1)) res += t[r].s, r--;\n\t}\n\treturn res;\n}\n\nvoid assign (int k, int x) {\n\tt[k].v = x;\n\tt[k].p = k;\n\tt[k].s = x;\n\tfor (int i = k >> 1; i > 0; k = i, i >>= 1) {\n\t\tif (t[k].v < t[k ^ 1].v) k ^= 1;\n\t\tt[i].v = t[k].v;\n\t\tt[i].p = t[k].p;\n\t\tt[i].s = t[k].s + t[k ^ 1].s;\n\t}\n}\n\nvoid modulo (int k, int x) {\n\twhile (t[k].v >= x) assign (t[k].p, t[k].v % x);\n}\n\nvoid modulo (int l, int r, int x) {\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {\n\t\tif (l & 1) modulo (l, x), l++;\n\t\tif (!(r & 1)) modulo (r, x), r--;\n\t}\n}\n\nvoid solve () {\n\tint n, m, t, l, r, x, k;\n\twhile (readf (\" %s %s\", &n, &m) > 0) {\n\t\tforeach (i; 1..n + 1) {\n\t\t\treadf (\" %s\", &x);\n\t\t\tassign (i + MED_N, x);\n\t\t}\n\t\tforeach (q; 0..m) {\n\t\t\treadf (\" %s\", &t);\n\t\t\tif (t == 1) {\n\t\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\t\twriteln (get_sum (l, r));\n\t\t\t} else if (t == 2) {\n\t\t\t\treadf (\" %s %s %s\", &l, &r, &x);\n\t\t\t\tmodulo (l, r, x);\n\t\t\t} else if (t == 3) {\n\t\t\t\treadf (\" %s %s\", &k, &x);\n\t\t\t\tassign (k + MED_N, x);\n\t\t\t}\n\t\t}\n\t}\n}\n}\n\nvoid main () {\n\tD.solve ();\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable int MED_N = 1 << 17, MAX_N = MED_N << 1;\n\nstruct Node {int v, p; long s;}\n\n__gshared Node [MAX_N] t;\n\nlong get_sum (int l, int r) {\n\tlong res = 0;\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {\n\t\tif (l & 1) res += t[l].s, l++;\n\t\tif (!(r & 1)) res += t[r].s, r--;\n\t}\n\treturn res;\n}\n\nvoid assign (int k, int x) {\n\tt[k].v = x;\n\tt[k].p = k;\n\tt[k].s = x;\n\tfor (int i = k >> 1; i > 0; k = i, i >>= 1) {\n\t\tif (t[k].v < t[k ^ 1].v) k ^= 1;\n\t\tt[i].v = t[k].v;\n\t\tt[i].p = t[k].p;\n\t\tt[i].s = t[k].s + t[k ^ 1].s;\n\t}\n}\n\nvoid modulo (int k, int x) {\n\twhile (t[k].v >= x) assign (t[k].p, t[k].v % x);\n}\n\nvoid modulo (int l, int r, int x) {\n\tfor (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {\n\t\tif (l & 1) modulo (l, x), l++;\n\t\tif (!(r & 1)) modulo (r, x), r--;\n\t}\n}\n\nvoid main () {\n\tint n, m, t, l, r, x, k;\n\twhile (readf (\" %s %s\", &n, &m) > 0) {\n\t\tforeach (i; 1..n + 1) {\n\t\t\treadf (\" %s\", &x);\n\t\t\tassign (i + MED_N, x);\n\t\t}\n\t\tforeach (q; 0..m) {\n\t\t\treadf (\" %s\", &t);\n\t\t\tif (t == 1) {\n\t\t\t\treadf (\" %s %s\", &l, &r);\n\t\t\t\twriteln (get_sum (l, r));\n\t\t\t} else if (t == 2) {\n\t\t\t\treadf (\" %s %s %s\", &l, &r, &x);\n\t\t\t\tmodulo (l, r, x);\n\t\t\t} else if (t == 3) {\n\t\t\t\treadf (\" %s %s\", &k, &x);\n\t\t\t\tassign (k + MED_N, x);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "69bfbd43579d74b921c08214cd5c9484"} {"source_code": "import std.algorithm.sorting : sort;\nimport std.stdio;\n\nvoid main()\n{\n char c;\n int n, k;\n readf!\"%d %d\\n\"(n, k);\n auto a = new int[n];\n auto b = new int[n-1];\n foreach (i; 0..n) readf!\"%d%c\"(a[i], c);\n foreach (i; 0..n-1) b[i] = a[i] - a[i+1];\n\n b.sort;\n\n int s = a[$-1] - a[0];\n foreach (i; 0..k-1) s += b[i];\n\n writeln(s);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto k = RD!int;\n\tauto a = RDA;\n\tauto d = new long[](n-1);\n\tforeach (i; 0..n-1)\n\t{\n\t\td[i] = a[i+1] - a[i];\n\t}\n\td.sort();\n\tauto ans = d[0..$-(k-1)].sum;\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\tint k = read.to!int;\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!int;\n\t\n\tlong sum = as[n - 1] - as[0];\n\tlog(\"sum:\", sum);\n\t\n\tlong[] ds;\n\tforeach(i; 0 .. n - 1) ds ~= as[i + 1] - as[i];\n\tlog(\"ds:\", ds);\n\t\n\tds.sort!\"a>b\"();\n\tlog(\"ds:\", ds);\n\t\n\tforeach(i; 0 .. k - 1){\n\t\tsum -= ds[i];\n\t}\n\t\n\tsum.writeln;\n\t\n}\n"}], "negative_code": [], "src_uid": "2895624e708159bc2a6f3e91140a6c45"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nimmutable int MD = 998244353;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n if (n.to!long * m * 2 % k != 0) {\n writeln(\"NO\");\n return;\n }\n \n auto r = 2*n;\n auto c = m;\n \n auto q = gcd(r, k);\n r /= q;\n k /= q;\n \n c /= k;\n \n if (r > n) r /= 2, c *= 2;\n if (c > m) {\n writeln(\"NOdf\");\n return;\n }\n \n auto p1 = tuple(0, 0);\n auto p2 = tuple(r, 0);\n auto p3 = tuple(0, c);\n \n writeln(\"YES\");\n [p1, p2, p3].each!(t => writeln(t[0], ' ', t[1]));\n}", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n long n, m, k;\n rd(n, m, k);\n if (n * m * 2 % k != 0) {\n writeln(\"NO\");\n return;\n }\n\n writeln(\"YES\");\n bool odd = true;\n if (k % 2 == 0) {\n k /= 2;\n odd = false;\n }\n import std.numeric : gcd;\n\n auto g = gcd(n, k), a = n / g;\n k /= g;\n auto b = m / k;\n if (odd) {\n if (a == n) {\n b *= 2;\n } else {\n a *= 2;\n }\n }\n writeln(0, \" \", 0);\n writeln(a, \" \", 0);\n writeln(0, \" \", b);\n\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "import core.stdc.stdio;\nimport std.algorithm;\nint n,m,k;\nint gcd(int p,int q)\n{\n\tif (q==0)\n\t{\n\t\treturn p;\n\t}\n\treturn gcd(q,p%q);\n}\nvoid main()\n{\n int i,x,y;\n\tscanf(\"%d%d%d\",&n,&m,&k);\n\tif (cast(long)2*n*m%k!=0)\n\t{\n\t\tprintf(\"NO\\n\");\n\t\treturn;\n\t}\n\tprintf(\"YES\\n\");\n\tif (k%2==0)\n\t{\n\t\tk/=2;\n\t\tx=gcd(n,k);\n\t\ty=k/x;\n\t\tprintf(\"0 0\\n\");\n\t\tprintf(\"%d 0\\n\",n/x);\n\t\tprintf(\"0 %d\\n\",m/y);\n\t\treturn;\n\t}\n\tx=gcd(n,k);\n\ty=k/x;\n\tprintf(\"0 0\\n\");\n\tprintf(\"%d 0\\n\",n/x*(x>1?2:1));\n\tprintf(\"0 %d\\n\",m/y*(x>1?1:2));\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nimmutable int MD = 998244353;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n if (n.to!long * m * 2 % k != 0) {\n writeln(\"NO\");\n return;\n }\n \n auto r = 2*n;\n auto c = m;\n \n auto q = gcd(r, k);\n r /= q;\n k /= q;\n \n c /= k;\n \n if (r > n) r /= 2, c *= 2;\n \n auto p1 = tuple(0, 0);\n auto p2 = tuple(r, 0);\n auto p3 = tuple(0, c);\n \n writeln(\"YES\");\n [p1, p2, p3].each!(t => writeln(t[0], ' ', t[1]));\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nimmutable int MD = 998244353;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n if (n.to!long * m % (2*k) != 0) {\n writeln(\"NO\");\n return;\n }\n \n auto q = gcd(n, k);\n auto r = n / q;\n k /= q;\n \n auto c = m / k;\n // k /= k;\n \n if (r * 2 <= n) r *= 2;\n else if (c * 2 <= m) c *= 2;\n else {\n writeln(\"NO\");\n return;\n }\n \n auto p1 = tuple(0, 0);\n auto p2 = tuple(r, 0);\n auto p3 = tuple(0, c);\n \n writeln(\"YES\");\n [p1, p2, p3].each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nimmutable int MD = 998244353;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n if (n.to!long * m % k != 0) {\n writeln(\"NO\");\n return;\n }\n \n auto r = 2*n;\n auto c = m;\n \n auto q = gcd(r, k);\n r /= q;\n k /= q;\n \n c /= k;\n \n if (r > n) r /= 2, c *= 2;\n if (c > m) {\n writeln(\"NO\");\n return;\n }\n \n auto p1 = tuple(0, 0);\n auto p2 = tuple(r, 0);\n auto p3 = tuple(0, c);\n \n writeln(\"YES\");\n [p1, p2, p3].each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n long n, m, k;\n rd(n, m, k);\n if (n * m * 2 % k != 0) {\n writeln(\"NO\");\n return;\n }\n\n writeln(\"YES\");\n if (k % 2 == 0)\n k /= 2;\n import std.numeric : gcd;\n\n auto g = gcd(n, k), a = n / g;\n k /= g;\n auto b = m / k;\n if (a * b / 2 != n * m * k) {\n if (a == n) {\n b *= 2;\n } else {\n a *= 2;\n }\n }\n writeln(0, \" \", 0);\n writeln(a, \" \", 0);\n writeln(0, \" \", b);\n\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n long n, m, k;\n rd(n, m, k);\n if (n * m * 2 % k != 0) {\n writeln(\"NO\");\n return;\n }\n\n writeln(\"YES\");\n if (k % 2 == 0)\n k /= 2;\n import std.numeric : gcd;\n\n auto g = gcd(n, k), a = n / g;\n k /= g;\n auto b = m / k;\n if (a == n) {\n b *= 2;\n } else {\n a *= 2;\n }\n writeln(0, \" \", 0);\n writeln(a, \" \", 0);\n writeln(0, \" \", b);\n\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n import std.bigint;\n\n BigInt n, m, k;\n rd(n, m, k);\n\n BigInt ansx, ansy;\n bool enough(BigInt x) { // x>0\n // x*y*0.5 = nm/k -> xy*k = 2nm\n auto y = m * n * 2 / k / x;\n if (y <= 0)\n return true;\n ansx = x;\n ansy = y;\n return x * y * k >= m * n * 2;\n }\n\n BigInt ng = 0, ok = n + 1;\n while (ok - ng > 1) {\n auto mid = (ng + ok) / 2;\n if (enough(mid))\n ok = mid;\n else\n ng = mid;\n }\n if (0 <= ok && ok <= n) {\n if (ansx * ansy * k == 2 * n * m) {\n writeln(\"YES\");\n writeln(0, \" \", 0);\n writeln(ansx, \" \", 0);\n writeln(0, \" \", ansy);\n } else {\n writeln(\"NO\");\n }\n } else {\n writeln(\"NO\");\n }\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio, std.string, std.conv;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "src_uid": "5c026adda2ae3d7b707d5054bd84db3f"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1494/problem/A\n// brute force\nimport std.array;\nimport std.stdio;\n\nbool check(string s) {\n int c = 0;\n foreach(p; s) {\n if(p == '(')\n c += 1;\n else\n c -= 1;\n if(c < 0)\n return false;\n }\n return c == 0;\n}\n\nstring generate(string t) {\n string p = \"()\";\n for(int i = 0; i < 2; i++) {\n for(int j = 0; j < 2; j++) {\n for(int k = 0; k < 2; k++) {\n string s = t\n .replace('A', p[i])\n .replace('B', p[j])\n .replace('C', p[k]);\n\n if(check(s)) {\n return \"YES\";\n }\n }\n }\n }\n return \"NO\";\n}\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n string a;\n readf(\"%s\\n\", &a);\n generate(a).writeln;\n}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.utf;\r\n\r\nbool isGood (R) (R s)\r\n{\r\n\tint balance = 0;\r\n\tforeach (c; s)\r\n\t{\r\n\t\tbalance += c ? +1 : -1;\r\n\t\tif (balance < 0)\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\treturn balance == 0;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip;\r\n\t\tbool ok = false;\r\n\t\tforeach (i; 0..8)\r\n\t\t{\r\n\t\t\tint [char] t;\r\n\t\t\tt['A'] = (i >> 0) & 1;\r\n\t\t\tt['B'] = (i >> 1) & 1;\r\n\t\t\tt['C'] = (i >> 2) & 1;\r\n\t\t\tok |= isGood (s.byChar.map !(c => t[c]));\r\n\t\t}\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD!string;\r\n\r\n\t\tforeach (i; 0..2^^3)\r\n\t\t{\r\n\t\t\tauto arr = new int[](3);\r\n\t\t\tarr[0] = i & 0b100;\r\n\t\t\tarr[1] = i & 0b010;\r\n\t\t\tarr[2] = i & 0b001;\r\n\t\t\tlong cnt;\r\n\t\t\tbool ok = true;\r\n\t\t\tforeach (c; a)\r\n\t\t\t{\r\n\t\t\t\tauto num = c - 'A';\r\n\t\t\t\tif (arr[num])\r\n\t\t\t\t\t++cnt;\r\n\t\t\t\telse\r\n\t\t\t\t\t--cnt;\r\n\t\t\t\tif (cnt < 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (!ok) continue;\r\n\t\t\tif (cnt == 0)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "4d24aaf5ebf70265b027a6af86e09250"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto k = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (k);\r\n\t\tint lo = 1;\r\n\t\tfor (int j = 1; j <= m; j++)\r\n\t\t{\r\n\t\t\tif (j <= n && j < k[$ - j])\r\n\t\t\t{\r\n\t\t\t\tk[$ - j] = j;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (k.map !(i => c[i - 1]).sum (0L));\r\n\t}\r\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nalias C = Tuple!(int, \"i\", long, \"k\", long, \"c\");\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, M; get(N, M);\r\n int[] KS; get(KS);\r\n long[] CS; get(CS);\r\n C[] cs;\r\n foreach (i, c; CS) cs ~= C(i.to!int, 0, c);\r\n foreach (k; KS) ++cs[k - 1].k;\r\n sort!\"a.c > b.c\"(cs);\r\n auto bs = new bool[](M);\r\n long r;\r\n int i;\r\n foreach (c; cs) {\r\n while (c.k > 0 && i < c.i) {\r\n if (!bs[i]) {\r\n bs[i] = true;\r\n r += CS[i];\r\n --c.k;\r\n }\r\n ++i;\r\n }\r\n bs[c.i] = true;\r\n while (c.k > 0) {\r\n r += c.c;\r\n --c.k;\r\n }\r\n }\r\n writeln(r);\r\n }\r\n}\r\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n, m;\n n = scan!int, m = scan!int;\n auto peeps = scanArray;\n auto gifts = scanArray;\n peeps.sort;\n peeps.reverse;\n ll res = 0;\n int gptr = 0;\n for(int i = 0; i < n; ++i){\n if(gptr < m && gifts[gptr] < gifts[to!int(peeps[i]-1)]){\n res += gifts[gptr];\n ++gptr;\n }else{\n res += gifts[to!int(peeps[i] -1)];\n }\n }\n writeln(res);\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto k = RDA!int(-1);\r\n\t\tauto c = RDA;\r\n\r\n\t\tk.sort();\r\n\t\tBinaryHeap!(Array!long, \"a > b\") heap1, heap2;\r\n\t\tint ci;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\twhile (ci <= k[i])\r\n\t\t\t{\r\n\t\t\t\theap1.insert(c[ci]);\r\n\t\t\t\t++ci;\r\n\t\t\t}\r\n\t\t\theap2.insert(c[k[i]]);\r\n\t\t\tif (heap2.front <= heap1.front)\r\n\t\t\t{\r\n\t\t\t\tans[ti] += heap2.front; heap2.removeFront;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tans[ti] += heap1.front; heap1.removeFront;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto k = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (k);\r\n\t\tint lo = 1;\r\n\t\tfor (int j = 1; j <= m; j++)\r\n\t\t{\r\n\t\t\tif (j <= n && j < k[$ - j])\r\n\t\t\t{\r\n\t\t\t\tk[$ - j] = j;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (k.map !(i => c[i - 1]).sum (0L));\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto k = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (k);\r\n\t\tint lo = 1;\r\n\t\tfor (int j = 1; j <= m; j++)\r\n\t\t{\r\n\t\t\tif (j <= n && j < k[$ - j])\r\n\t\t\t{\r\n\t\t\t\tk[$ - j] = j;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (k.map !(i => c[i - 1]).sum (0L));\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto k = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (k);\r\n\t\tint lo = 1;\r\n\t\tfor (int j = 1; j <= m; j++)\r\n\t\t{\r\n\t\t\tif (j <= n && j < k[$ - j])\r\n\t\t\t{\r\n\t\t\t\tk[$ - j] = j;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (k.map !(i => c[i - 1]).sum (0L));\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto k = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (k);\r\n\t\tint lo = 1;\r\n\t\tfor (int j = 1; j <= m; j++)\r\n\t\t{\r\n\t\t\tif (j <= n && j < k[$ - j])\r\n\t\t\t{\r\n\t\t\t\tk[$ - j] = j;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (k.map !(i => c[i - 1]).sum (0L));\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n \r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto k = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (k);\r\n\t\tint lo = 1;\r\n\t\tfor (int j = 1; j <= m; j++)\r\n\t\t{\r\n\t\t\tif (j <= n && j < k[$ - j])\r\n\t\t\t{\r\n\t\t\t\tk[$ - j] = j;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (k.map !(i => c[i - 1]).sum (0L));\r\n\t}\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto k = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (k);\r\n\t\tint lo = 1;\r\n\t\tfor (int j = 1; j <= m; j++)\r\n\t\t{\r\n\t\t\tif (j <= n && j < k[$ - j])\r\n\t\t\t{\r\n\t\t\t\tk[$ - j] = j;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (k.map !(i => c[i - 1]).sum (0L));\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "55962ef2cf88c87873b996dc54cc1bf1"} {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\n std.container, std.typecons, std.conv, std.random, std.bigint, std.string;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n assert(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nstring[] words;\n\nint solve(char c) {\n int[] arr = new int[words.length];\n \n foreach (i, w; words) {\n auto a = w.count(c).to!int;\n arr[i] = a - (w.length.to!int - a);\n }\n \n sort(arr);\n reverse(arr);\n \n if (arr[0] < 1) return 0;\n \n long total = arr[0];\n int answer = 1;\n \n foreach (i; 1 .. arr.length) {\n total += arr[i];\n if (total <= 0) break;\n answer++;\n }\n \n return answer;\n}\n\nvoid main() {\n int t;\n read(t);\n \n while (t--) {\n string s = readln.strip();\n \n int once = 0;\n int more = 0;\n foreach (c; 'a' .. 'z' + 1) {\n auto T = s.count(c);\n if (T == 1) once++;\n if (T > 1) more++;\n }\n \n writeln(more + once / 2);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--)\n\t{\n\t\tsolve();\n\t}\n}\n\nvoid solve()\n{\n\tstring s = readString;\n\tint[30] cnt = 0;\n\tforeach(c; s) cnt[c-'a']++;\n\tint c2 = 0;\n\tint c1 = 0;\n\tforeach(c; cnt)\n\t{\n\t\tif (c >= 2)\n\t\t{\n\t\t\tc2 += 1;\n\t\t}\n\t\tif (c == 1) \n\t\t{\n\t\t\tc1++;\n\t\t}\n\t}\n\t(((c1/2)*2+c2*2)/2).writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n auto a = readln.strip.split(\"\").map!(x => x[0] - 'a').array;\n int[int] freq;\n foreach (x ; a)\n freq[x]++;\n long nocolor = 0;\n foreach (k, v ; freq)\n if (v > 2)\n nocolor += v - 2;\n writeln((cast(long)a.length - nocolor) / 2);\n }\n}\n"}], "negative_code": [], "src_uid": "a6b760941ab8be2c32c6dc66c623ea0e"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n int[long] pos;\n pos[0] = 0;\n \n long ans = 0;\n long sm = 0;\n int lstpos = -1;\n foreach (i, e; arr) {\n sm += e;\n lstpos = max(lstpos, pos.get(sm, -1));\n ans += i+1 - (lstpos+1);\n pos[sm] = i.to!int + 1;\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nalias T = Tuple!(long, uint);\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n auto a = r.nextA!int (n);\n const s = sum (a, 0L);\n //prefix[i] + suffix[j] + a[i .. j] == s \n //prefix[i] + suffix[j] == s\n auto pr = new long[n+1];\n pr[0] = 0;\n foreach (i; 1 .. n + 1) pr[i] = pr[i-1] + a[i-1];\n /*\n auto sf = new long[n+1];\n sf[n] = 0;\n foreach_reverse (i; 0 .. n) sf[i] = sf[i+1] + a[i];\n */\n T[] x;\n x.reserve (n + 1);\n foreach (i; 0 .. n + 1) x ~= tuple (pr[i], i);\n sort (x);\n debug stderr.writeln (\"pr = \", pr);\n debug stderr.writeln (\"x = \", x);\n int i;\n auto z = new uint[n+1];\n z[] = uint.max;\n while (i < x.length) {\n int j = i + 1;\n while (j < x.length && x[i][0] == x[j][0]) ++j;\n uint last = uint.max;\n foreach_reverse (const ref q; x[i .. j]) {\n debug stderr.writeln (q);\n if (last != uint.max) {\n z[q[1]] = last - 1;\n }\n last = q[1];\n }\n i = j;\n }\n debug stderr.writeln (\"z = \", z);\n foreach_reverse (k; 0 .. n) {\n z[k] = min (z[k+1], z[k]);\n }\n debug stderr.writeln (\"z = \", z);\n long res;\n foreach (k; 0 .. n) {\n z[k] = min (z[k], n);\n if (z[k] > k) {\n res += z[k] - k;\n }\n }\n writeln (res);\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n int n = scan!int;\n long[] as = scan!long(n);\n\n long[] sums = [0];\n foreach(a; as) sums ~= sums[$ - 1] + a;\n\n long ans;\n int[long] pos;\n int l = 0;\n foreach(i, s; sums){\n if(s in pos) l.raiseTo(pos[s] + 1);\n ans += i - l;\n pos[s] = i.to!int;\n }\n\n ans.writeln;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nlong test(long[] arr)\n{\n\tlong res;\n\tforeach (i; 0..arr.length)\n\t{\n\t\tlong x;\n\t\tforeach (j; i..arr.length)\n\t\t{\n\t\t\tx += arr[j];\n\t\t\tif (arr[j] == 0 || x == 0) break;\n\t\t\t++res;\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\t/*while (true){\n\tauto n = 3;\n\tauto a = new long[](3);\n\tforeach (i; 0..3)\n\t{\n\t\ta[i] = uniform(-3, 4);\n\t}*/\n\n\tint[][long] set;\n\tauto b = new long[](n+1);\n\tforeach_reverse (i; 0..n)\n\t{\n\t\tb[i] = b[i+1] + a[i];\n\t}\n\tforeach (i; 0..n+1)\n\t{\n\t\tset[b[i]] ~= i;\n\t}\n\tauto zero = new RedBlackTree!(int);\n\tforeach (i; 0..n)\n\t{\n\t\tif (a[i] == 0)\n\t\t\tzero.insert(i);\n\t}\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t{\n\t\tif (a[i] == 0) continue;\n\t\tauto arr = set.get(b[i+1], []);\n\t\tif (arr.empty)\n\t\t{\n\t\t\tans += i+1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto r = binarySearch!((int p) => arr[p] < i)(-1, cast(int)arr.length);\n\t\t\tint r2 = -1;\n\t\t\tauto arr2 = zero.lowerBound(i);\n\t\t\tif (!arr2.empty)\n\t\t\t\tr2 = arr2.back;\n\t\t\tif (r == -1 && r2 == -1)\n\t\t\t{\n\t\t\t\tans += i+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint x;\n\t\t\t\tif (r != -1)\n\t\t\t\t\tx = arr[r];\n\t\t\t\tif (r2 != -1)\n\t\t\t\t\tx.chmax(r2);\n\t\t\t\tzero.insert(x);\n\t\t\t\tans += i - x;\n\t\t\t\t//debug writeln(\"i:\", i, \" r:\", r, \" arr[r]:\", arr[r]);\n\t\t\t}\n\t\t}\n\t\t//debug writeln(ans);\n\t}\n\n\t/*auto ans2 = test(a);\n\t/writeln(a);\n\twriteln(ans, \":\", ans2);*/\n\twriteln(ans);\n\tstdout.flush;\n\t/*if (ans != ans2) break;\n\t}*/\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong res = 0;\n\t\tint [long] used;\n\t\tused[0] = 0;\n\t\tint lo = 0;\n\t\tlong cur;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tcur += a[i];\n\t\t\tif (cur in used)\n\t\t\t{\n\t\t\t\tlo = max (lo, used[cur] + 1);\n\t\t\t}\n\t\t\tused[cur] = i + 1;\n\t\t\tres += i + 1 - lo;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n int[int] pos;\n pos[0] = 0;\n \n long ans = 0;\n int sm = 0, lstpos = -1;\n foreach (i, e; arr) {\n sm += e;\n lstpos = max(lstpos, pos.get(sm, -1));\n ans += i+1 - (lstpos+1);\n pos[sm] = i.to!int + 1;\n }\n \n ans.writeln;\n}"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n auto a = r.nextA!int (n);\n const s = sum (a, 0L);\n //prefix[i] + suffix[j] + a[i .. j] == s \n //prefix[i] + suffix[j] == s\n auto pr = new long[n+1];\n pr[0] = 0;\n foreach (i; 1 .. n + 1) pr[i] = pr[i-1] + a[i-1];\n /*\n auto sf = new long[n+1];\n sf[n] = 0;\n foreach_reverse (i; 0 .. n) sf[i] = sf[i+1] + a[i];\n */\n int[long] h;\n Tuple!(int, int)[] bad;\n h[0] = 0;\n debug stderr.writeln (\"pr = \", pr);\n foreach (j; 0 .. n) {\n //auto p = s - sf[j+1]; \n auto p = pr[j+1];\n auto ptr = p in h;\n if (ptr !is null) {\n bad ~= tuple (*ptr, (j + 1).to!int);\n } else {\n h[p] = j + 1;\n }\n }\n int cur = int.max;\n foreach_reverse (ref q; bad) {\n cur = min (cur, q[1]);\n q[1] = cur;\n }\n debug stderr.writeln(bad);\n long res;\n auto e = assumeSorted (bad);\n foreach (i; 0 .. n) {\n auto d = e.upperBound (tuple (i, -1));\n if (d.empty) {\n res += n - i;\n } else {\n res += d.front[1] - 1 - i; \n }\n }\n writeln (res);\n}\n\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n auto a = r.nextA!int (n);\n const s = sum (a, 0L);\n //prefix[i] + suffix[j] + a[i .. j] == s \n //prefix[i] + suffix[j] == s\n auto pr = new long[n+1];\n pr[0] = 0;\n foreach (i; 1 .. n + 1) pr[i] = pr[i-1] + a[i-1];\n /*\n auto sf = new long[n+1];\n sf[n] = 0;\n foreach_reverse (i; 0 .. n) sf[i] = sf[i+1] + a[i];\n */\n int[long] h;\n Tuple!(int, int)[] bad;\n h[0] = 0;\n debug stderr.writeln (\"pr = \", pr);\n foreach (j; 0 .. n) {\n //auto p = s - sf[j+1]; \n auto p = pr[j+1];\n auto ptr = p in h;\n if (ptr !is null) {\n bad ~= tuple (*ptr, (j + 1).to!int);\n }\n h[p] = j + 1;\n }\n int cur = int.max;\n foreach_reverse (ref q; bad) {\n cur = min (cur, q[1]);\n q[1] = cur;\n }\n debug stderr.writeln(bad);\n long res;\n auto e = assumeSorted (bad);\n foreach (i; 0 .. n) {\n auto d = e.upperBound (tuple (i, -1));\n if (d.empty) {\n res += n - i;\n } else {\n res += d.front[1] - 1 - i; \n }\n }\n writeln (res);\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tint[][long] set;\n\tauto b = new long[](n+1);\n\tforeach_reverse (i; 0..n)\n\t{\n\t\tb[i] = b[i+1] + a[i];\n\t}\n\tforeach (i; 0..n+1)\n\t{\n\t\tset[b[i]] ~= i;\n\t}\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t{\n\t\tif (a[i] == 0) continue;\n\t\tauto arr = set.get(b[i+1], []);\n\t\tif (arr.empty)\n\t\t{\n\t\t\tans += i+1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto r = binarySearch!((int p) => arr[p] < i)(-1, cast(int)arr.length);\n\t\t\tif (r == -1)\n\t\t\t{\n\t\t\t\tans += i+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans += i - arr[r];\n\t\t\t\tdebug writeln(\"i:\", i, \" r:\", r, \" arr[r]:\", arr[r]);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tint[][long] set;\n\tauto b = new long[](n+1);\n\tforeach_reverse (i; 0..n)\n\t{\n\t\tb[i] = b[i+1] + a[i];\n\t}\n\tforeach (i; 0..n+1)\n\t{\n\t\tset[b[i]] ~= i;\n\t}\n\n\tlong ans;\n\tlong x;\n\tforeach (i; 0..n)\n\t{\n\t\tx += a[i];\n\t\tauto arr = set.get(b[i+1], []);\n\t\tif (arr.empty)\n\t\t{\n\t\t\tans += i+1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto r = binarySearch!((int p) => arr[p] < i)(-1, cast(int)arr.length);\n\t\t\tif (r == -1)\n\t\t\t{\n\t\t\t\tans += i+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans += i - arr[r];\n\t\t\t\tdebug writeln(\"i:\", i, \" r:\", r, \" arr[r]:\", arr[r]);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tint[][long] set;\n\tauto b = new long[](n+1);\n\tforeach_reverse (i; 0..n)\n\t{\n\t\tb[i] = b[i+1] + a[i];\n\t}\n\tforeach (i; 0..n+1)\n\t{\n\t\tset[b[i]] ~= i;\n\t}\n\tint[] zero;\n\tforeach (i; 0..n)\n\t{\n\t\tif (a[i] == 0)\n\t\t\tzero ~= i;\n\t}\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t{\n\t\tif (a[i] == 0) continue;\n\t\tauto arr = set.get(b[i+1], []);\n\t\tif (arr.empty)\n\t\t{\n\t\t\tans += i+1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto r = binarySearch!((int p) => arr[p] < i)(-1, cast(int)arr.length);\n\t\t\tauto r2 = binarySearch!((int p) => zero[p] < i)(-1, cast(int)zero.length);\n\t\t\tif (r == -1 && r2 == -1)\n\t\t\t{\n\t\t\t\tans += i+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint x;\n\t\t\t\tif (r != -1)\n\t\t\t\t\tx = arr[r];\n\t\t\t\tif (r2 != -1)\n\t\t\t\t\tx.chmax(zero[r2]);\n\t\t\t\tans += i - x;\n\t\t\t\t//debug writeln(\"i:\", i, \" r:\", r, \" arr[r]:\", arr[r]);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "61fb771f915b551a9bcce90c74e0ef64"} {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int inf = 10^^9 + 7;\n\nvoid main() {\n int n, k;\n readVars(n, k);\n auto x = readln.split.map!(to!long).array;\n\n auto cs = new long[](n + 1);\n iota(n).each!(i => cs[i + 1] += cs[i] + x[i]);\n\n auto pfm = new long[](n + 1);\n auto sfm = new long[](n + 1);\n auto pfi = new int[](n + 1);\n auto sfi = new int[](n + 1);\n\n foreach (i ; k .. n + 1) {\n pfm[i] = pfm[i - 1];\n pfi[i] = pfi[i - 1];\n\n if (cs[i] - cs[i - k] > pfm[i - 1]) {\n pfm[i] = cs[i] - cs[i - k];\n pfi[i] = i - k;\n }\n }\n\n foreach_reverse (i ; 0 .. n - k + 1) {\n sfm[i] = sfm[i + 1];\n sfi[i] = sfi[i + 1];\n\n if (cs[i + k] - cs[i] >= sfm[i + 1]) {\n sfm[i] = cs[i + k] - cs[i];\n sfi[i] = i;\n }\n }\n\n debug {\n stderr.writeln(\"pfm:\",pfm);\n stderr.writeln(\"pfi:\",pfi);\n stderr.writeln(\"sfm:\",sfm);\n stderr.writeln(\"sfi:\",sfi);\n }\n\n long max_v;\n int a, b;\n\n foreach (i ; k .. n - k + 1) {\n if (pfm[i] + sfm[i] > max_v) {\n max_v = pfm[i] + sfm[i];\n a = pfi[i];\n b = sfi[i];\n }\n }\n\n writeln(a + 1, \" \", b + 1);\n}\n\n\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int inf = 10^^9 + 7;\n\nvoid main() {\n int n, k;\n readVars(n, k);\n auto x = readln.split.map!(to!long).array;\n\n auto cs = new long[](n + 1);\n iota(n).each!(i => cs[i + 1] += cs[i] + x[i]);\n\n auto pfm = new long[](n + 1);\n auto sfm = new long[](n + 1);\n auto pfi = new int[](n + 1);\n auto sfi = new int[](n + 1);\n\n foreach (i ; k .. n + 1) {\n pfm[i] = pfm[i - 1];\n pfi[i] = pfi[i - 1];\n\n if (cs[i] - cs[i - k] > pfm[i - 1]) {\n pfm[i] = cs[i] - cs[i - k];\n pfi[i] = i - k;\n }\n }\n\n foreach_reverse (i ; 0 .. n - k + 1) {\n sfm[i] = sfm[i + 1];\n sfi[i] = sfi[i + 1];\n\n if (cs[i + k] - cs[i] >= sfm[i + 1]) {\n sfm[i] = cs[i + k] - cs[i];\n sfi[i] = i;\n }\n }\n\n debug {\n //stderr.writeln(\"pfm:\",pfm);\n stderr.writeln(\"pfi:\",pfi);\n stderr.writeln(\"sfm:\",sfm);\n stderr.writeln(\"sfi:\",sfi);\n }\n\n long max_v;\n int a, b;\n\n foreach (i ; k .. n - k + 1) {\n if (pfm[i] + sfm[i] > max_v) {\n max_v = pfm[i] + sfm[i];\n a = pfi[i];\n b = sfi[i];\n }\n }\n\n writeln(a + 1, \" \", b + 1);\n}\n\n\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int inf = 10^^9 + 7;\n\nvoid main() {\n int n, k;\n readVars(n, k);\n auto x = readln.split.map!(to!long).array;\n\n auto cs = new long[](n + 1);\n iota(n).each!(i => cs[i + 1] += cs[i] + x[i]);\n\n int a = 0, b = k;\n long maxsum = cs[k] - cs[0] + cs[2*k] - cs[k];\n long maxpf = cs[k] - cs[0];\n int maxpfi = 0;\n\n foreach (i ; k + 1 .. n - k + 1) {\n if (cs[i] - cs[i - k] > maxpf) {\n maxpf = cs[i] - cs[i - k];\n maxpfi = i - k;\n }\n\n if (maxpf + cs[i + k] - cs[i] > maxsum) {\n maxsum = maxpf + cs[i + k] - cs[i];\n a = maxpfi;\n b = i;\n }\n }\n\n writeln(a + 1, \" \", b + 1);\n}\n\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}], "negative_code": [], "src_uid": "74095fe82bd22257eeb97e1caf586499"} {"source_code": "import std.stdio;\nimport std.algorithm;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint[] m = new int[a];\n\tfor (int i=0; i<a; i++)\n\t{\n\t\treadf(\" %d\", &m[i]);\n\t}\n\tsort(m);\n\tif (a%2==1)\n\t{\n\t\twriteln(m[a/2]);\n\t}\n\telse\n\t{\n\t\twriteln(m[a/2-1]);\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\n\nvoid main()\n{\n\tint n = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tstd.algorithm.sort(a);\n\ta[(n - 1) / 2].writeln;\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint[] m = new int[a];\n\tfor (int i=0; i<a; i++)\n\t{\n\t\treadf(\" %d\", &m[i]);\n\t}\n\tsort(m);\n\twriteln(m[a/2]);\n\treturn 0;\n}"}], "src_uid": "f93a8bd64a405233342f84542fce314d"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort !(q{a > b}) (a);\n\t\tint j = 0;\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twhile (j < n && (a[i] & a[j]) >= (a[i] ^ a[j]))\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\tres += j - i - 1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n sort(arr);\n ll tim = 1;\n ll res = 0;\n ll cnt = 0;\n foreach(i; 0..n){\n ll num = arr[i];\n bool chang = 0;\n while(num > 0 && num >= tim*2){\n tim *= 2;\n chang = 1;\n }\n if(!chang){\n ++cnt;\n }else{\n res += cnt*(cnt - 1)/2;\n cnt = 1;\n }\n }\n res += cnt*(cnt - 1)/2;\n writeln(res);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\n\nvoid get(Args...)(ref Args args)\n{\n import std.traits, std.meta, std.typecons;\n\n static if (Args.length == 1) {\n alias Arg = Args[0];\n \n static if (isArray!Arg) {\n args[0] = readln.split.to!Arg;\n } else static if (isTuple!Arg) {\n auto input = readln.split;\n static foreach (i; 0..Fields!Arg.length) {\n args[0][i] = input[i].to!(Fields!Arg[i]);\n }\n } else {\n args[0] = readln.chomp.to!Arg;\n }\n } else {\n auto input = readln.split;\n assert(input.length == Args.length);\n\n static foreach (i; 0..Args.length) {\n args[i] = input[i].to!(Args[i]);\n }\n }\n}\n\nvoid get_lines(Args...)(size_t N, ref Args args)\n{\n import std.traits, std.range;\n\n static foreach (i; 0..Args.length) {\n static assert(isArray!(Args[i]));\n args[i].length = N;\n }\n\n foreach (i; 0..N) {\n static if (Args.length == 1) {\n get(args[0][i]);\n } else {\n auto input = readln.split;\n static foreach (j; 0..Args.length) {\n args[j][i] = input[j].to!(ElementType!(Args[j]));\n }\n }\n }\n}\n\nuint bits_msb(uint v)\n{\n v = v | (v >> 1);\n v = v | (v >> 2);\n v = v | (v >> 4);\n v = v | (v >> 8);\n v = v | (v >> 16);\n return v ^ (v >> 1);\n}\n\nvoid solve()\n{\n int N; get(N);\n uint[] AS; get(AS);\n long[33] cs;\n foreach (a; AS) {\n a = bits_msb(a);\n static foreach (i; 0..33) {\n if (a & 1) ++cs[i];\n a >>= 1;\n }\n }\n long r;\n foreach (c; cs) r += c * (c-1) / 2;\n writeln(r);\n}\n\nvoid main()\n{\n int T; get(T);\n foreach (_; 0..T) solve();\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto a = next!long(n);\n long[35] cnt;\n cnt[] = 0;\n foreach(ai; a)\n\t{\n\t int bits = 0;\n\t while(ai != 0)\n\t {\n\t bits++;\n\t ai >>= 1;\n\t }\n\t cnt[bits]++;\n\t}\n long res = 0;\n foreach(c; cnt)\n\t{\n\t res += (c * (c - 1)) / 2;\n\t}\n res.writeln;\n }\n}\nulong bitCnt(T)(T x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tauto cnt = new long[](63);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach_reverse (j; 0..63)\n\t\t\t{\n\t\t\t\tauto bit = 1L << j;\n\t\t\t\tif (a[i] & bit)\n\t\t\t\t{\n\t\t\t\t\t++cnt[j];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..63)\n\t\t{\n\t\t\tans[ti] += cnt[i]*(cnt[i]-1)/2;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n \n\nint main() {\n\tint t;\n\tscanf(\"%d\", &t);\n\twhile (t --> 0) {\n int n;\n\t\tscanf(\"%d\", &n);\n\t\tint[] a = new int[n];\n int[] cnt = new int [42];\n long result = 0;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tscanf(\"%d\", &a[i]);\n int bit_id = 0;\n while (a[i] > 0) {\n \t++bit_id;\n a[i] /= 2;\n }\n result += cnt[bit_id];\n ++cnt[bit_id];\n\t\t}\n\t\tprintf(\"%lld\\n\", result);\n\t}\n\t\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\n\nvoid get(Args...)(ref Args args)\n{\n import std.traits, std.meta, std.typecons;\n\n static if (Args.length == 1) {\n alias Arg = Args[0];\n \n static if (isArray!Arg) {\n args[0] = readln.split.to!Arg;\n } else static if (isTuple!Arg) {\n auto input = readln.split;\n static foreach (i; 0..Fields!Arg.length) {\n args[0][i] = input[i].to!(Fields!Arg[i]);\n }\n } else {\n args[0] = readln.chomp.to!Arg;\n }\n } else {\n auto input = readln.split;\n assert(input.length == Args.length);\n\n static foreach (i; 0..Args.length) {\n args[i] = input[i].to!(Args[i]);\n }\n }\n}\n\nvoid get_lines(Args...)(size_t N, ref Args args)\n{\n import std.traits, std.range;\n\n static foreach (i; 0..Args.length) {\n static assert(isArray!(Args[i]));\n args[i].length = N;\n }\n\n foreach (i; 0..N) {\n static if (Args.length == 1) {\n get(args[0][i]);\n } else {\n auto input = readln.split;\n static foreach (j; 0..Args.length) {\n args[j][i] = input[j].to!(ElementType!(Args[j]));\n }\n }\n }\n}\n\nuint bits_msb(uint v)\n{\n v = v | (v >> 1);\n v = v | (v >> 2);\n v = v | (v >> 4);\n v = v | (v >> 8);\n v = v | (v >> 16);\n return v ^ (v >> 1);\n}\n\nvoid solve()\n{\n int N; get(N);\n uint[] AS; get(AS);\n long[10] cs;\n foreach (a; AS) {\n a = bits_msb(a);\n static foreach (i; 0..10) {\n if (a & 1) ++cs[i];\n a >>= 1;\n }\n }\n long r;\n foreach (c; cs) r += c * (c-1) / 2;\n writeln(r);\n}\n\nvoid main()\n{\n int T; get(T);\n foreach (_; 0..T) solve();\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto a = next!int(n);\n int[35] cnt;\n cnt[] = 0;\n foreach(ai; a)\n\t{\n\t int bits = 0;\n\t while(ai != 0)\n\t {\n\t bits++;\n\t ai >>= 1;\n\t }\n\t cnt[bits]++;\n\t}\n long res = 0;\n foreach(i, c; cnt)\n\t{\n\t res += c * (c - 1) / 2;\n\t}\n res.writeln;\n }\n}\nulong bitCnt(T)(T x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "src_uid": "04e2e1ce3f0b4efd2d4dda69748a0a25"} {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n;\nloop:while(read(n))\n\t{\n\t\tauto v=new int[5],p=new int[5],k=new int[5];\n\t\tforeach(i;0..5)\n\t\t{\n\t\t\tinput(v[i]);\n\t\t\tif(v[i]!=-1)k[i]++;\n\t\t}\n\t\tforeach(i;0..5)\n\t\t{\n\t\t\tinput(p[i]);\n\t\t\tif(p[i]!=-1)k[i]++;\n\t\t}\n\t\tdebug putarr(v);\n\t\tdebug writeln;\n\t\tdebug putarr(p);\n\t\tforeach(i;0..n-2)\n\t\t{\n\t\t\tforeach(j;0..5)\n\t\t\t{\n\t\t\t\tint x;\n\t\t\t\tinput(x);\n\t\t\t\tif(x!=-1)k[j]++;\n\t\t\t}\n\t\t}\n\t\tforeach(akks;0..32*n)\n\t\t{\n\t\t\tint vas,pet;\n\t\t\tforeach(i;0..5)\n\t\t\t{\n\t\t\t\tif(v[i]==-1)\n\t\t\t\t{\n\t\t\t\t\tif(p[i]==-1)continue;\n\t\t\t\t\tint x=(n+akks)/(k[i]);\n\t\t\t\t\tif(x>=32)pet+=3000-3000*p[i]/250;\n\t\t\t\t\telse if(x>=16)pet+=2500-2500*p[i]/250;\n\t\t\t\t\telse if(x>=8)pet+=2000-2000*p[i]/250;\n\t\t\t\t\telse if(x>=4)pet+=1500-1500*p[i]/250;\n\t\t\t\t\telse if(x>=2)pet+=1000-1000*p[i]/250;\n\t\t\t\t\telse if(x>=1)pet+=500-500*p[i]/250;\n\t\t\t\t}\n\t\t\t\telse if(p[i]==-1)\n\t\t\t\t{\n\t\t\t\t\tint x=(n+akks)/(k[i]);\n\t\t\t\t\tif(x>=32)vas+=3000-3000*v[i]/250;\n\t\t\t\t\telse if(x>=16)vas+=2500-2500*v[i]/250;\n\t\t\t\t\telse if(x>=8)vas+=2000-2000*v[i]/250;\n\t\t\t\t\telse if(x>=4)vas+=1500-1500*v[i]/250;\n\t\t\t\t\telse if(x>=2)vas+=1000-1000*v[i]/250;\n\t\t\t\t\telse if(x>=1)vas+=500-500*v[i]/250;\n\t\t\t\t}\n\t\t\t\telse if(v[i]<p[i])\n\t\t\t\t{\n\t\t\t\t\tint x=(n+akks)/(k[i]);\n\t\t\t\t\tif(x>=32)pet+=3000-3000*p[i]/250;\n\t\t\t\t\telse if(x>=16)pet+=2500-2500*p[i]/250;\n\t\t\t\t\telse if(x>=8)pet+=2000-2000*p[i]/250;\n\t\t\t\t\telse if(x>=4)pet+=1500-1500*p[i]/250;\n\t\t\t\t\telse if(x>=2)pet+=1000-1000*p[i]/250;\n\t\t\t\t\telse if(x>=1)pet+=500-500*p[i]/250;\n\t\t\t\t\tif(x>=32)vas+=3000-3000*v[i]/250;\n\t\t\t\t\telse if(x>=16)vas+=2500-2500*v[i]/250;\n\t\t\t\t\telse if(x>=8)vas+=2000-2000*v[i]/250;\n\t\t\t\t\telse if(x>=4)vas+=1500-1500*v[i]/250;\n\t\t\t\t\telse if(x>=2)vas+=1000-1000*v[i]/250;\n\t\t\t\t\telse if(x>=1)vas+=500-500*v[i]/250;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint x=(n+akks)/(k[i]+akks);\n\t\t\t\t\tif(x>=32)pet+=3000-3000*p[i]/250;\n\t\t\t\t\telse if(x>=16)pet+=2500-2500*p[i]/250;\n\t\t\t\t\telse if(x>=8)pet+=2000-2000*p[i]/250;\n\t\t\t\t\telse if(x>=4)pet+=1500-1500*p[i]/250;\n\t\t\t\t\telse if(x>=2)pet+=1000-1000*p[i]/250;\n\t\t\t\t\telse if(x>=1)pet+=500-500*p[i]/250;\n\t\t\t\t\tif(x>=32)vas+=3000-3000*v[i]/250;\n\t\t\t\t\telse if(x>=16)vas+=2500-2500*v[i]/250;\n\t\t\t\t\telse if(x>=8)vas+=2000-2000*v[i]/250;\n\t\t\t\t\telse if(x>=4)vas+=1500-1500*v[i]/250;\n\t\t\t\t\telse if(x>=2)vas+=1000-1000*v[i]/250;\n\t\t\t\t\telse if(x>=1)vas+=500-500*v[i]/250;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug writeln(vas,' ',pet);\n\t\t\tif(vas>pet)\n\t\t\t{\n\t\t\t\twriteln(akks);\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t}\n\t\twriteln(-1);\n\t}\n}", "positive_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n;\nloop:while(read(n))\n\t{\n\t\tauto v=new int[5],p=new int[5],k=new int[5];\n\t\tforeach(i;0..5)\n\t\t{\n\t\t\tinput(v[i]);\n\t\t\tif(v[i]!=-1)k[i]++;\n\t\t}\n\t\tforeach(i;0..5)\n\t\t{\n\t\t\tinput(p[i]);\n\t\t\tif(p[i]!=-1)k[i]++;\n\t\t}\n\t\tdebug putarr(v);\n\t\tdebug writeln;\n\t\tdebug putarr(p);\n\t\tforeach(i;0..n-2)\n\t\t{\n\t\t\tforeach(j;0..5)\n\t\t\t{\n\t\t\t\tint x;\n\t\t\t\tinput(x);\n\t\t\t\tif(x!=-1)k[j]++;\n\t\t\t}\n\t\t}\n\t\tforeach(akks;0..32*n)\n\t\t{\n\t\t\tint vas,pet;\n\t\t\tforeach(i;0..5)\n\t\t\t{\n\t\t\t\tif(v[i]==-1)\n\t\t\t\t{\n\t\t\t\t\tif(p[i]==-1)continue;\n\t\t\t\t\tint x=(n+akks)/(k[i]);\n\t\t\t\t\tif(x>=32)pet+=3000-3000*p[i]/250;\n\t\t\t\t\telse if(x>=16)pet+=2500-2500*p[i]/250;\n\t\t\t\t\telse if(x>=8)pet+=2000-2000*p[i]/250;\n\t\t\t\t\telse if(x>=4)pet+=1500-1500*p[i]/250;\n\t\t\t\t\telse if(x>=2)pet+=1000-1000*p[i]/250;\n\t\t\t\t\telse if(x>=1)pet+=500-500*p[i]/250;\n\t\t\t\t}\n\t\t\t\telse if(p[i]==-1)\n\t\t\t\t{\n\t\t\t\t\tint x=(n+akks)/(k[i]);\n\t\t\t\t\tif(x>=32)vas+=3000-3000*v[i]/250;\n\t\t\t\t\telse if(x>=16)vas+=2500-2500*v[i]/250;\n\t\t\t\t\telse if(x>=8)vas+=2000-2000*v[i]/250;\n\t\t\t\t\telse if(x>=4)vas+=1500-1500*v[i]/250;\n\t\t\t\t\telse if(x>=2)vas+=1000-1000*v[i]/250;\n\t\t\t\t\telse if(x>=1)vas+=500-500*v[i]/250;\n\t\t\t\t}\n\t\t\t\telse if(v[i]<p[i])\n\t\t\t\t{\n\t\t\t\t\tint x=(n+akks)/(k[i]);\n\t\t\t\t\tif(x>=32)pet+=3000-3000*p[i]/250;\n\t\t\t\t\telse if(x>=16)pet+=2500-2500*p[i]/250;\n\t\t\t\t\telse if(x>=8)pet+=2000-2000*p[i]/250;\n\t\t\t\t\telse if(x>=4)pet+=1500-1500*p[i]/250;\n\t\t\t\t\telse if(x>=2)pet+=1000-1000*p[i]/250;\n\t\t\t\t\telse if(x>=1)pet+=500-500*p[i]/250;\n\t\t\t\t\tif(x>=32)vas+=3000-3000*v[i]/250;\n\t\t\t\t\telse if(x>=16)vas+=2500-2500*v[i]/250;\n\t\t\t\t\telse if(x>=8)vas+=2000-2000*v[i]/250;\n\t\t\t\t\telse if(x>=4)vas+=1500-1500*v[i]/250;\n\t\t\t\t\telse if(x>=2)vas+=1000-1000*v[i]/250;\n\t\t\t\t\telse if(x>=1)vas+=500-500*v[i]/250;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint x=(n+akks)/(k[i]+akks);\n\t\t\t\t\tif(x>=32)pet+=3000-3000*p[i]/250;\n\t\t\t\t\telse if(x>=16)pet+=2500-2500*p[i]/250;\n\t\t\t\t\telse if(x>=8)pet+=2000-2000*p[i]/250;\n\t\t\t\t\telse if(x>=4)pet+=1500-1500*p[i]/250;\n\t\t\t\t\telse if(x>=2)pet+=1000-1000*p[i]/250;\n\t\t\t\t\telse if(x>=1)pet+=500-500*p[i]/250;\n\t\t\t\t\tif(x>=32)vas+=3000-3000*v[i]/250;\n\t\t\t\t\telse if(x>=16)vas+=2500-2500*v[i]/250;\n\t\t\t\t\telse if(x>=8)vas+=2000-2000*v[i]/250;\n\t\t\t\t\telse if(x>=4)vas+=1500-1500*v[i]/250;\n\t\t\t\t\telse if(x>=2)vas+=1000-1000*v[i]/250;\n\t\t\t\t\telse if(x>=1)vas+=500-500*v[i]/250;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug writeln(vas,' ',pet);\n\t\t\tif(vas>pet)\n\t\t\t{\n\t\t\t\twriteln(akks);\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t}\n\t\twriteln(-1);\n\t}\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum M = 5;\nenum K = 6;\nenum LIM = 10^^6;\n\nint calc(long p, long q) {\n foreach (k; 0 .. K - 1) {\n if (p > (q >> (k + 1))) {\n return k;\n }\n }\n return K - 1;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[][](N, M);\n foreach (i; 0 .. N) foreach (j; 0 .. M) {\n A[i][j] = readInt();\n }\n \n auto cnt = new int[M];\n foreach (i; 0 .. N) foreach (j; 0 .. M) {\n if (A[i][j] != -1) {\n ++cnt[j];\n }\n }\n \n foreach (n; 0 .. LIM) {\n int sum;\n foreach (j; 0 .. M) {\n int k;\n if (A[0][j] != -1 && A[1][j] != -1 && A[0][j] > A[1][j]) {\n k = calc(cnt[j] + n, N + n);\n } else {\n k = calc(cnt[j], N + n);\n }\n if (A[0][j] != -1) sum += 500 * (k + 1) - 2 * (k + 1) * A[0][j];\n if (A[1][j] != -1) sum -= 500 * (k + 1) - 2 * (k + 1) * A[1][j];\n }\n if (sum > 0) {\n writeln(n);\n goto found;\n }\n }\n writeln(-1);\n found:\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "bb68a49399e501739782601795609105"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n;\n readf!\" %d \"(n);\n auto k = readln.splitter.map!(to!long).array;\n auto h = readln.splitter.map!(to!long).array;\n\n foreach_reverse (i ; 1 .. cast(int)n) {\n long delay = k[i] - k[i - 1];\n if (delay < h[i] - h[i - 1])\n h[i - 1] = h[i] - delay;\n }\n\n long ans;\n ans = h[0] * (1L + h[0]) / 2;\n long power = h[0];\n foreach (i ; 1 .. cast(int)n) {\n long delay = k[i] - k[i - 1];\n if (delay >= h[i]) {\n ans += h[i] * (1L + h[i]) / 2;\n power = h[i];\n } else {\n ans += delay * ((power + 1) + (power + delay)) / 2;\n power += delay;\n }\n }\n writeln(ans);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nalias P = Tuple!(long, \"t\", int, \"i\");\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto K = readarray!long;\r\n auto H = readarray!long;\r\n\r\n long ans = 0;\r\n auto PQ = heapify!\"a.t == b.t ? a.i > b.i : a.t > b.t\"(new P[0], 0);\r\n foreach (i; 0 .. N) {\r\n long ti = K[i] - H[i] + 1;\r\n PQ.insert(P(ti, i));\r\n }\r\n long ct = 0;\r\n long cp = 0;\r\n while (! PQ.empty) {\r\n auto p = PQ.front; PQ.removeFront;\r\n int i = p.i;\r\n if (ct < p.t) {\r\n ans += (1L + H[i]) * H[i] / 2L;\r\n cp = H[i];\r\n ct = K[i];\r\n } else {\r\n if (K[i] <= ct) continue;\r\n ans += (cp + 1L + cp + K[i] - ct) * (K[i] - ct) / 2L;\r\n cp = cp + K[i] - ct;\r\n ct = K[i];\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto k = readln.splitter.map !(to !(long)).array;\r\n\t\tauto h = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n)\r\n\t\t\t{\r\n\t\t\t\th[i] = max (h[i], h[j] - k[j] + k[i]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tlong res = 0;\r\n\t\tlong cur = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (i > 0 && h[i] > k[i] - k[i - 1])\r\n\t\t\t{\r\n\t\t\t\tres += cur * 1L * (k[i] - k[i - 1]);\r\n\t\t\t\tres += (k[i] - k[i - 1]) *\r\n\t\t\t\t (k[i] - k[i - 1] + 1L) / 2;\r\n\t\t\t\tcur += k[i] - k[i - 1];\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tres += h[i] * (h[i] + 1L) / 2;\r\n\t\t\t\tcur = h[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto T = scan!long(N);\r\n auto H = scan!long(N);\r\n\r\n long lastTime = T[$ - 1];\r\n long lastDamage;\r\n long ans;\r\n foreach_reverse(t, h; zip(T, H)) {\r\n long damage = max(0, lastDamage - (lastTime - t));\r\n if (damage >= h) continue;\r\n\r\n if (damage == 0) {\r\n ans += h * (h + 1) / 2;\r\n lastDamage = h;\r\n lastTime = t;\r\n } else {\r\n ans -= lastDamage * (lastDamage + 1) / 2;\r\n lastDamage += h - damage;\r\n ans += lastDamage * (lastDamage + 1) / 2;\r\n }\r\n // [t, h, ans].deb;\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "import std;\n\nT\nread (alias T, string end = \"\") () {\n T x;\n readf!(\"%s\" ~ end)(x);\n return x;\n}\n\nvoid main () {\n immutable tests = read!(ushort, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n readln();\n\n immutable times = readln.chomp\n .split(\" \")\n .to!(uint[]);\n\n immutable hp = readln.chomp\n .split(\" \")\n .to!(uint[]);\n\n alias Pair = Tuple!(uint, \"start\", uint, \"end\");\n\n auto stack = Array!Pair();\n\n foreach (health, time; lockstep(hp, times, StoppingPolicy.requireSameLength)) {\n immutable start = time - health + 1;\n immutable end = time;\n\n while (stack.length != 0 && stack.back().start >= start)\n stack.removeBack();\n\n if (stack.length == 0)\n stack ~= Pair(start, end);\n else {\n if (stack.back.end >= start)\n stack.back.end = end;\n else\n stack ~= Pair(start, end);\n }\n }\n\n stack\n .fold!((a, b) {\n immutable ulong total_casts = b.end - b.start + 1;\n return a + total_casts * (total_casts + 1) / 2;\n })(0uL)\n .writeln();\n }\n}\n// \"\"\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nalias P = Tuple!(long, \"t\", int, \"i\");\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto K = readarray!long;\r\n auto H = readarray!long;\r\n\r\n long ans = 0;\r\n auto PQ = heapify!\"a.t == b.t ? a.i > b.i : a.t > b.t\"(new P[0], 0);\r\n foreach (i; 0 .. N) {\r\n long ti = K[i] - H[i] + 1;\r\n PQ.insert(P(ti, i));\r\n }\r\n long ct = 0;\r\n long cp = 0;\r\n while (! PQ.empty) {\r\n auto p = PQ.front; PQ.removeFront;\r\n int i = p.i;\r\n if (ct < p.t) {\r\n ans += (1L + H[i]) * H[i] / 2L;\r\n ct = K[i];\r\n cp = H[i];\r\n } else {\r\n if (K[i] < ct) continue;\r\n ans += (cp + 1L + cp + K[i] - ct) * (K[i] - ct) / 2L;\r\n ct = K[i];\r\n cp = cp + K[i] - ct;\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nalias P = Tuple!(long, \"t\", int, \"i\");\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto K = readarray!long;\r\n auto H = readarray!long;\r\n\r\n long ans = 0;\r\n auto PQ = heapify!\"a.t == b.t ? a.i > b.i : a.t > b.t\"(new P[0], 0);\r\n foreach (i; 0 .. N) {\r\n long ti = K[i] - H[i] + 1;\r\n PQ.insert(P(ti, i));\r\n }\r\n long ct = 0;\r\n long cp = 0;\r\n while (! PQ.empty) {\r\n auto p = PQ.front; PQ.removeFront;\r\n int i = p.i;\r\n if (ct < p.t) {\r\n ans += (1L + H[i]) * H[i] / 2L;\r\n ct = K[i];\r\n cp = H[i];\r\n } else {\r\n ans += (cp + 1L + cp + K[i] - ct) * (K[i] - ct) / 2L;\r\n ct = K[i];\r\n cp = cp + K[i] - ct;\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n;\n readf!\" %d \"(n);\n auto k = readln.splitter.map!(to!long).array;\n auto h = readln.splitter.map!(to!long).array;\n long ans;\n ans = h[0] * (1L + h[0]) / 2;\n long power = h[0];\n foreach (i ; 1 .. cast(int)n) {\n long delay = k[i] - k[i - 1];\n if (delay >= h[i]) {\n ans += h[i] * (1L + h[i]) / 2;\n power = h[i];\n } else {\n ans += delay * ((power + 1) + (power + delay)) / 2;\n power += delay;\n }\n }\n writeln(ans);\n }\n}\n"}, {"source_code": "import std;\n\nT\nread (alias T, string end = \"\") () {\n T x;\n readf!(\"%s\" ~ end)(x);\n return x;\n}\n\nvoid main () {\n immutable tests = read!(ushort, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n readln();\n\n immutable times = readln.chomp\n .split(\" \")\n .to!(uint[]);\n\n immutable hp = readln.chomp\n .split(\" \")\n .to!(uint[]);\n\n alias Pair = Tuple!(uint, \"start\", uint, \"end\");\n\n auto stack = Array!Pair();\n\n foreach (health, time; lockstep(hp, times, StoppingPolicy.requireSameLength)) {\n immutable start = time - health + 1;\n immutable end = time;\n\n while (stack.length != 0 && stack.back().start >= start)\n stack.removeBack();\n\n if (stack.length == 0)\n stack ~= Pair(start, end);\n else {\n if (stack.back.end >= start)\n stack.back.end = end;\n else\n stack ~= Pair(start, end);\n }\n }\n\n stack\n .fold!((a, b) {\n immutable total_casts = b.end - b.start + 1;\n return a + total_casts * (total_casts + 1) / 2;\n })(0)\n .writeln();\n }\n}\n// \"\"\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto T = scan!long(N);\r\n auto H = scan!long(N);\r\n\r\n long lastTime = T[$ - 1];\r\n long lastDamage;\r\n long ans;\r\n foreach_reverse(t, h; zip(T, H)) {\r\n long damage = max(0, lastDamage - (lastTime - t));\r\n if (damage >= h) continue;\r\n\r\n if (damage == 0) {\r\n ans += h * (h + 1) / 2;\r\n lastDamage = h;\r\n } else {\r\n ans -= lastDamage * (lastDamage + 1) / 2;\r\n lastDamage += h - damage;\r\n ans += lastDamage * (lastDamage + 1) / 2;\r\n }\r\n\r\n lastTime = t;\r\n // [t, h, ans].deb;\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "src_uid": "690c28ef1275035895b9154ff0e17f4c"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = array (iota (n + 2));\n\t\tauto b = array (iota (n + 2));\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t\tb[a[i]] = i;\n\t\t}\n\n\t\tauto f = new int [n + 2];\n\n\t\tvoid add (int p, int v)\n\t\t{\n\t\t\tfor ( ; p <= n + 1; p += (p & -p))\n\t\t\t{\n\t\t\t\tdebug {writeln (\"add \", p, \" \", v);}\n\t\t\t\tf[p] += v;\n\t\t\t}\n\t\t}\n\n\t\tint sum (int p)\n\t\t{\n\t\t\tint res = 0;\n\t\t\tfor ( ; p > 0; p -= (p & -p))\n\t\t\t{\n\t\t\t\tdebug {writeln (\"sum \", p);}\n\t\t\t\tres += f[p];\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tvoid mark (int p, int v)\n\t\t{\n\t\t\tif (b[p] > b[p + 1])\n\t\t\t{\n\t\t\t\tadd (p, v);\n\t\t\t}\n\t\t}\n\n\t\tf[] = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tmark (i, +1);\n\t\t}\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (z; 0..q)\n\t\t{\n\t\t\tdebug {writeln (\"a = \", a);}\n\t\t\tdebug {writeln (\"b = \", b);}\n\t\t\tdebug {writeln (\"f = \", f);}\n\t\t\tint t, x, y;\n\t\t\treadf (\" %s %s %s\", &t, &x, &y);\n\t\t\tif (t == 1)\n\t\t\t{\n\t\t\t\twriteln (sum (y - 1) - sum (x - 1) + 1);\n\t\t\t}\n\t\t\telse if (t == 2)\n\t\t\t{\n\t\t\t\tswap (a[x], a[y]);\n\t\t\t\tx = a[x];\n\t\t\t\ty = a[y];\n\t\t\t\tif (x > y)\n\t\t\t\t{\n\t\t\t\t\tswap (x, y);\n\t\t\t\t}\n\t\t\t\tmark (x - 1, -1);\n\t\t\t\tmark (x - 0, -1);\n\t\t\t\tif (y - 1 != x - 0)\n\t\t\t\t{\n\t\t\t\t\tmark (y - 1, -1);\n\t\t\t\t}\n\t\t\t\tmark (y - 0, -1);\n\t\t\t\tswap (b[x], b[y]);\n\t\t\t\tmark (x - 1, +1);\n\t\t\t\tmark (x - 0, +1);\n\t\t\t\tif (y - 1 != x - 0)\n\t\t\t\t{\n\t\t\t\t\tmark (y - 1, +1);\n\t\t\t\t}\n\t\t\t\tmark (y - 0, +1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (\"!\");}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = array (iota (n + 2));\n\t\tauto b = array (iota (n + 2));\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t\tb[a[i]] = i;\n\t\t}\n\n\t\tauto f = new int [n + 2];\n\n\t\tvoid add (int p, int v)\n\t\t{\n\t\t\tfor ( ; p <= n + 1; p += (p & -p))\n\t\t\t{\n\t\t\t\tdebug {writeln (\"add \", p, \" \", v);}\n\t\t\t\tf[p] += v;\n\t\t\t}\n\t\t}\n\n\t\tint sum (int p)\n\t\t{\n\t\t\tint res = 0;\n\t\t\tfor ( ; p > 0; p -= (p & -p))\n\t\t\t{\n\t\t\t\tdebug {writeln (\"sum \", p);}\n\t\t\t\tres += f[p];\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tvoid mark (int p, int v)\n\t\t{\n\t\t\tif (b[p] > b[p + 1])\n\t\t\t{\n\t\t\t\tadd (p, v);\n\t\t\t}\n\t\t}\n\n\t\tf[] = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tmark (i, +1);\n\t\t}\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (z; 0..q)\n\t\t{\n\t\t\tdebug {writeln (\"a = \", a);}\n\t\t\tdebug {writeln (\"b = \", b);}\n\t\t\tdebug {writeln (\"f = \", f);}\n\t\t\tint t, x, y;\n\t\t\treadf (\" %s %s %s\", &t, &x, &y);\n\t\t\tif (t == 1)\n\t\t\t{\n\t\t\t\twriteln (sum (y - 1) - sum (x - 1) + 1);\n\t\t\t}\n\t\t\telse if (t == 2)\n\t\t\t{\n\t\t\t\tswap (a[x], a[y]);\n\t\t\t\tx = a[x];\n\t\t\t\ty = a[y];\n\t\t\t\tif (x > y)\n\t\t\t\t{\n\t\t\t\t\tswap (x, y);\n\t\t\t\t}\n\t\t\t\tmark (x - 1, -1);\n\t\t\t\tmark (x - 0, -1);\n\t\t\t\tif (y - 1 != x - 0)\n\t\t\t\t{\n\t\t\t\t\tmark (y - 1, -1);\n\t\t\t\t}\n\t\t\t\tmark (y - 0, -1);\n\t\t\t\tswap (b[x], b[y]);\n\t\t\t\tmark (x - 1, +1);\n\t\t\t\tmark (x - 0, +1);\n\t\t\t\tif (y - 1 != x - 0)\n\t\t\t\t{\n\t\t\t\t\tmark (y - 1, +1);\n\t\t\t\t}\n\t\t\t\tmark (y - 0, +1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (\"!\");}\n\t}\n}\n"}], "negative_code": [], "src_uid": "0bf3f5b910d58b8f608ab8214732eb05"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new int[N];\n auto C = new int[N];\n foreach (u; 0 .. N) {\n P[u] = readInt() - 1;\n C[u] = readInt();\n }\n \n auto desc = new bool[][](N, N);\n foreach (u; 0 .. N) {\n for (int v = u; v != -1; v = P[v]) {\n desc[v][u] = true;\n }\n }\n auto sz = new int[N];\n foreach (u; 0 .. N) {\n sz[u] = desc[u].count(true);\n }\n auto us = iota(N).array;\n us.sort!((u, v) => (sz[u] < sz[v]));\n \n bool ok = true;\n foreach (u; 0 .. N) {\n ok = ok && (C[u] < sz[u]);\n }\n if (ok) {\n int num;\n auto ans = new int[N];\n foreach (u; us) {\n int[] xs;\n foreach (v; 0 .. N) {\n if (u != v && desc[u][v]) {\n xs ~= ans[v];\n }\n }\n xs.sort;\n xs ~= ++num;\n foreach (v; 0 .. N) {\n if (u != v && desc[u][v]) {\n int pos = xs.lowerBound(ans[v]);\n if (pos >= C[u]) {\n ++pos;\n }\n ans[v] = xs[pos];\n }\n }\n ans[u] = xs[C[u]];\n }\n writeln(\"YES\");\n foreach (u; 0 .. N) {\n if (u > 0) write(\" \");\n write(ans[u]);\n }\n writeln();\n \n debug {\n foreach (u; 0 .. N) {\n int cnt;\n foreach (v; 0 .. N) {\n if (u != v && desc[u][v]) {\n if (ans[u] > ans[v]) {\n ++cnt;\n }\n }\n }\n assert(C[u] == cnt);\n }\n }\n } else {\n writeln(\"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto adj = new int [] [n + 1];\n\t\tauto p = new int [n + 1];\n\t\tauto c = new int [n + 1];\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\treadf !(\" %s %s\") (p[i], c[i]);\n\t\t\tadj[p[i]] ~= i;\n\t\t}\n\n\t\tauto a = new int [n + 1];\n\t\tauto s = new int [] [n + 1];\n\n\t\tbool recur (int v)\n\t\t{\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tif (!recur (u))\n\t\t\t\t{\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tforeach (w; s[u])\n\t\t\t\t{\n\t\t\t\t\ta[w] += s[v].length.to !(int);\n\t\t\t\t}\n\t\t\t\ts[v] ~= s[u];\n\t\t\t}\n\n\t\t\tif (c[v] > s[v].length)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\ta[v] = c[v];\n\t\t\tforeach (w; s[v])\n\t\t\t{\n\t\t\t\tif (a[w] >= c[v])\n\t\t\t\t{\n\t\t\t\t\ta[w] += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\ts[v] ~= v;\n\t\t\tdebug {writeln (v, \" \", a);}\n\t\t\treturn true;\n\t\t}\n\n\t\tif (!recur (0))\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln !(\"%(%s %)\") (a[1..n + 1]);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tauto n = readln.strip.to!int, g = new int [] [n + 1],\n\t s = g.map !(x => x.dup).array,\n\t p = new int [n + 1], a = p.dup, r = 1;\n\tforeach (i; 1..n + 1) {\n\t\treadf !\" %s %s\" (p[i], a[i]);\n\t\tg[p[i]] ~= i;\n\t}\n\n\tvoid recur (int v) {\n\t\tforeach (u; g[v]) {\n\t\t\trecur (u);\n\t\t\tforeach (w; s[u])\n\t\t\t\ta[w] += s[v].length.to !(int);\n\t\t\ts[v] ~= s[u];\n\t\t}\n\n\t\tr &= (a[v] <= s[v].length);\n\t\tforeach (w; s[v])\n\t\t\ta[w] += (a[w] >= a[v]);\n\t\ts[v] ~= v;\n\t}\n\n\trecur (0);\n\tif (r) {\n\t\twriteln (\"YES\");\n\t\twritefln !(\"%(%s %)\") (a[1..n + 1]);\n\t}\n\telse\n\t\twriteln (\"NO\");\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n int n;\n read(n);\n auto p = new int[n.ind + 1];\n auto children = new int[][n.ind + 1];\n auto c = new int[n.ind + 1];\n int root = -1;\n foreach(i; 1 .. n + 1)\n {\n read(p[i], c[i]);\n if (p[i])\n children[p[i]] ~= i;\n else\n root = i;\n }\n auto subsize = new int[n.ind + 1];\n class Impossible: Throwable\n {\n this()\n {\n super(\"\");\n }\n }\n auto solution = new int[][n.ind + 1];\n void dfs(int node)\n {\n mixin(logCall);\n subsize[node.ind] = 1;\n solution[n.ind] = null;\n auto childSol = new int[0];\n foreach(child; children[node.ind])\n {\n dfs(child);\n subsize[node.ind] += subsize[child.ind];\n childSol ~= solution[child.ind];\n }\n assert(childSol.length == subsize[node.ind] - 1);\n if (c[node.ind] > subsize[node.ind] - 1)\n throw new Impossible();\n int value = 0;\n solution[node.ind] = childSol[0 .. c[node.ind].ind] ~ [node] ~ childSol[c[node.ind].ind .. $];\n }\n auto pos = new int[n.ind + 1];\n try dfs(root);\n catch(Impossible impossibl)\n goto no;\n yes:\n writeln(\"YES\");\n foreach(i; 0 .. solution[root.ind].length)\n pos[solution[root.ind][i]] = cast(int)i + 1;\n foreach(pi; pos[1 .. $])\n write(pi, \" \");\n writeln;\n return;\n no:\n writeln(\"NO\");\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable n = r.next!uint ();\n auto p = new int[n+1];\n auto c = new int[n+1];\n int root;\n auto e = new int[][n+1];\n foreach (i; 1 .. n + 1) {\n p[i] = r.next!uint ();\n c[i] = r.next!uint ();\n if (p[i] == 0) root = i;\n else {\n e[p[i]] ~= i;\n }\n }\n auto ss = new int[n+1];\n auto vis = new bool[n+1];\n void go (int i) {\n ss[i] = 1;\n foreach (j; e[i]) if (!vis[j]) {\n vis[j] = true;\n go (j);\n ss[i] += ss[j];\n }\n }\n vis[root] = true;\n go (root);\n foreach (i; 1 .. n + 1) {\n if (ss[i] - 1 < c[i]) {\n writeln (\"NO\");\n return;\n }\n }\n auto idx = iota (1, n.to!int + 1).array;\n auto a = new int[n+1];\n void go2 (int i, int l) {\n int k = c[i];\n int j = l;\n debug stderr.writeln (idx);\n debug stderr.writefln (\"k = %d\", k);\n while (idx[j] < 0) ++j;\n while (--k >= 0) {\n ++j;\n while (idx[j] < 0) ++j;\n }\n a[i] = idx[j];\n debug stderr.writefln (\"i = %d, j = %d, a[i] = %d, idx[j] = %d\", i, j, a[i], idx[j]);\n assert (a[i] >= 0);\n idx[j] = -1;\n foreach (u; e[i]) {\n go2 (u, 0);\n }\n }\n go2 (root, 0);\n writeln (\"YES\");\n writefln (\"%(%s %)\", a[1 .. $]);\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tNode[] nodes;\n\tNode root;\n\tforeach(i; 0 .. n) nodes ~= new Node(i);\n\n\tforeach(i; 0 .. n){\n\t\tint p = rint - 1;\n\t\tlong c = rlong;\n\t\tif(p >= 0){\n\t\t\tnodes[i].parent = nodes[p];\n\t\t\tnodes[p].sons ~= nodes[i];\n\t\t\tnodes[p].waitcount += 1;\n\t\t}\n\t\telse{\n\t\t\tnodes[i].parent = null;\n\t\t\troot = nodes[i];\n\t\t}\n\t\tnodes[i].value = c;\n\t}\n\n\tauto ndq = new Queue!Node;\n\tforeach(nd; nodes) ndq.enq(nd);\n\twhile(ndq.length){\n\t\tNode nd = ndq.deq;\n\t\tif(nd.waitcount == 0){\n\t\t\tif(nd.value == 0) nd.nodes ~= nd;\n\t\t\tforeach(son; nd.sons) foreach(q; son.nodes){\n\t\t\t\tnd.nodes ~= q;\n\t\t\t\tif(nd.value == nd.nodes.length) nd.nodes ~= nd;\n\t\t\t}\n\t\t\tif(nd.value > nd.nodes.length){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(nd.parent) nd.parent.waitcount -= 1;\n\t\t}\n\t\telse ndq.enq(nd);\n\t}\n\n\t\"YES\".writeln;\n\tforeach(i, nd; root.nodes){ nd.ans = i + 1; }\n\tnodes.map!(nd => nd.ans.to!string).join(\" \").writeln;\n\n}\nclass Node{\n\tint id;\n\tNode parent;\n\tlong value;\n\tint waitcount;\n\tlong ans;\n\tNode[] nodes;\n\tNode[] sons;\n\tthis(int id){\n\t\tthis.id = id;\n\t}\n}\n// ----- \u30ad\u30e5\u30fc -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : \u6b21\u306b\u8aad\u307f\u51fa\u3059\u4f4d\u7f6e\u3000j: \u6b21\u306b\u66f8\u304d\u8fbc\u3080\u4f4d\u7f6e\n\tthis(){\t}\n\tthis(T[] xs){ this.xs = xs; j = xs.length.to!uint; }\n\tuint length(){ return j - i; }\n\tbool isEmpty(){ return j == i; }\n\tvoid enq(T x){\n\t\twhile(j + 1 >= xs.length) xs.length = xs.length * 2 + 1;\n\t\txs[j ++] = x;\n\t}\n\tT deq(){ assert(i < j); return xs[i ++]; }\n\tT peek(){ assert(i < j); return xs[i]; }\n\tT opIndex(uint li){ assert(i + li < j); return xs[i + li]; }\n\tstatic Queue!T opCall(){ return new Queue!T; }\n\tstatic Queue!T opCall(T[] xs){ return new Queue!T(xs); }\n\tT[] array(){ return xs[i .. j]; }\n\toverride string toString(){ return array.to!string; }\n}\n// ----- \u30b9\u30bf\u30c3\u30af -----\nclass Stack(T){\n\tprivate T[] xs;\n\tprivate uint j; // j : \u6b21\u306b\u66f8\u304d\u8fbc\u3080\u4f4d\u7f6e\n\tthis(){\t}\n\tthis(T[] xs){ this.xs = xs; j = xs.length.to!uint; }\n\tuint length(){ return j; }\n\tbool isEmpty(){ return j == 0; }\n\tvoid push(T x){\n\t\twhile(j + 1 >= xs.length) xs.length = xs.length * 2 + 1;\n\t\txs[j ++] = x;\n\t}\n\tT pop(){ assert(j > 0); return xs[-- j]; }\n\tT peek(){ assert(j > 0); return xs[j - 1]; }\n\tT opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }\n\tstatic Stack!T opCall(){ return new Stack!T; }\n\tstatic Stack!T opCall(T[] xs){ return new Stack!T(xs); }\n\tT[] array(){ return xs[0 .. j]; }\n\toverride string toString(){ return array.to!string; }\n}\n\n"}], "negative_code": [], "src_uid": "f097cc7057bb9a6b9fc1d2a11ee99835"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nlong solve (int [] a, int [] b)\r\n{\r\n\tlong res = 0;\r\n\twhile (!a.empty && !b.empty)\r\n\t{\r\n\t\tres += a.back * 2;\r\n\t\ta.popBack ();\r\n\t\tswap (a, b);\r\n\t}\r\n\treturn res + sum (a, 0L) + sum (b, 0L);\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tauto u = n.iota.filter !(i => a[i] == 0)\r\n\t\t .map !(i => b[i]).array;\r\n\t\tauto v = n.iota.filter !(i => a[i] == 1)\r\n\t\t .map !(i => b[i]).array;\r\n\t\tsort (u);\r\n\t\tsort (v);\r\n\t\twriteln (max (solve (u, v), solve (v, u)));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const numCases = readInt;\r\n foreach (caseId; 0 .. numCases) {\r\n const N = readInt;\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt;\r\n }\r\n auto B = new long[N];\r\n foreach (i; 0 .. N) {\r\n B[i] = readLong;\r\n }\r\n \r\n long[][2] bss;\r\n foreach (i; 0 .. N) {\r\n bss[A[i]] ~= B[i];\r\n }\r\n foreach (h; 0 .. 2) {\r\n bss[h].sort;\r\n }\r\n \r\n long ans;\r\n foreach (h0; 0 .. 2) {\r\n int[2] poss;\r\n foreach (h; 0 .. 2) {\r\n poss[h] = cast(int)(bss[h].length);\r\n }\r\n long score;\r\n int lastA;\r\n long lastB;\r\n for (; poss[0] > 0 || poss[1] > 0; ) {\r\n foreach (h; [h0, h0 ^ 1]) if (poss[h] > 0) {\r\n score += ((h != lastA) ? 2 : 1) * lastB;\r\n lastA = h;\r\n lastB = bss[h][--poss[h]];\r\n }\r\n }\r\n score += lastB;\r\n debug {\r\n writeln(h0, \": \", score);\r\n }\r\n chmax(ans, score);\r\n }\r\n \r\n writeln(ans);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "bc1587d3affd867804e664fdb38ed765"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (u; 0 .. N) {\n A[u] = readInt();\n }\n \n auto as = A.dup;\n as.sort;\n auto uf = new int[N];\n uf[] = -1;\n foreach (u; 0 .. N) {\n const v = as.lowerBound(A[u]);\n uf.connect(u, v);\n }\n \n auto uss = new int[][N];\n foreach (u; 0 .. N) {\n uss[uf.root(u)] ~= u;\n }\n writeln(uf.count!\"a < 0\");\n foreach (r; 0 .. N) {\n if (uss[r]) {\n write(uss[r].length);\n foreach (u; uss[r]) {\n write(\" \", u + 1);\n }\n writeln;\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "module main;\n__gshared:\nimport core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\nalias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nenum mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt gcd(BigInt a, BigInt b)\n\t\t{\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///integer size\n\t\tint sz(T)(T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (!(a[m] < g))\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (!(a[l] < g)) ? l : r;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (g < a[m])\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (g < a[l]) ? l : r;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn binf(a, g) != a.length;\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treturn s == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treadln;\n\t\treturn s == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tfreopen(\"input.txt\", \"r\", core.stdc.stdio.stdin);\n\t\t//freopen(\"output.txt\", \"w\", core.stdc.stdio.stdout);\n\t\t/*StopWatch sw;\n\t\tsw.start;\n\t\tscope (exit)\n\t\t{\n\t\t\tsw.stop;\n\t\t\tstderr.writefln(\"\\nTime: %d ms\", sw.peek.msecs);\n\t\t}*/\n\t}\n\tint n;\n\tloop: while (read(n))\n\t{\n\t\tauto a = arread!int;\n\t\tauto b = a.dup;\n\t\tsort(b);\n\t\tauto r = a.map!(x => mp(x, binf(b, x))).array;\n\t\tauto u = new bool[n];\n\t\tsize_t[][] ans;\n\t\tforeach (i; 0 .. n)\n\t\t{\n\t\t\tif (u[i])\n\t\t\t\tcontinue;\n\t\t\tans.length++;\n\t\t\tsize_t p = i;\n\t\t\twhile (!u[p])\n\t\t\t{\n\t\t\t\tu[p] = 1;\n\t\t\t\tans.back ~= p + 1;\n\t\t\t\tp = r[p].se;\n\t\t\t}\n\t\t}\n\t\twriteln(ans.length);\n\t\tforeach (p; ans)\n\t\t{\n\t\t\twrite(p.length);\n\t\t\tforeach (x; p)\n\t\t\t{\n\t\t\t\twrite(' ', x);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t}\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"A\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n// import dcomp.datastructure.unionfind;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n; int[] a;\n sc.read(n, a);\n int[] idx = iota(n).array;\n idx.sort!((x, y) => a[x] < a[y]);\n auto uf = UnionFind(n);\n foreach (i, j; idx) {\n uf.merge(i.to!int, j);\n }\n writeln(uf.count);\n foreach (v; uf.groups) {\n if (v.length == 0) continue;\n writeln(v.length, \" \", v.map!(x => (x+1).to!string).join(\" \"));\n }\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n import core.bitop : bsf, bsr, popcnt;\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/datastructure/unionfind.d */\n// module dcomp.datastructure.unionfind;\n\n \nstruct UnionFind {\n import std.algorithm : map, swap, each;\n import std.range : iota, array;\n int[] id; \n int[][] groups; \n int count; \n \n this(int n) {\n id = iota(n).array;\n groups = iota(n).map!(a => [a]).array;\n count = n;\n }\n \n void merge(int a, int b) {\n if (same(a, b)) return;\n count--;\n int x = id[a], y = id[b];\n if (groups[x].length < groups[y].length) swap(x, y);\n groups[y].each!(a => id[a] = x);\n groups[x] ~= groups[y];\n groups[y] = [];\n }\n \n int[] group(int i) {\n return groups[id[i]];\n }\n \n bool same(int a, int b) {\n return id[a] == id[b];\n }\n}\n\n \n \n\n \n"}, {"source_code": "module solution;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = n.iota.array;\n\t\tmakeIndex (a, b);\n\t\tauto d = new bool [n];\n\t\tint [] [] ans;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (!d[i])\n\t\t\t{\n\t\t\t\tint [] line;\n\t\t\t\tint j = i;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tj = b[j];\n\t\t\t\t\td[j] = true;\n\t\t\t\t\tline ~= j + 1;\n\t\t\t\t}\n\t\t\t\twhile (j != i);\n\t\t\t\tans ~= line;\n\t\t\t}\n\t\t}\n\t\twriteln (ans.length);\n\t\tforeach (line; ans)\n\t\t{\n\t\t\twritefln (\"%s %(%s %)\", line.length, line);\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "module solution;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = n.iota.array;\n\t\tmakeIndex (a, b);\n\t\twriteln (b);\n\t\tauto d = new bool [n];\n\t\tint [] [] ans;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (!d[i])\n\t\t\t{\n\t\t\t\tint [] line;\n\t\t\t\tint j = i;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tj = b[j];\n\t\t\t\t\td[j] = true;\n\t\t\t\t\tline ~= j + 1;\n\t\t\t\t}\n\t\t\t\twhile (j != i);\n\t\t\t\tans ~= line;\n\t\t\t}\n\t\t}\n\t\twriteln (ans.length);\n\t\tforeach (line; ans)\n\t\t{\n\t\t\twritefln (\"%s %(%s %)\", line.length, line);\n\t\t}\n\t}\n}\n"}], "src_uid": "159365b2f037647fbaa656905e6f5252"} {"source_code": "module main;\r\nimport std.stdio, std.conv, std.string, std.ascii, std.algorithm, std.format;\r\n\r\nT read(T)()\r\n{\r\n static string[] tokens;\r\n while (!tokens.length)\r\n tokens = stdin.readln.split;\r\n auto result = tokens[0].to!T;\r\n tokens = tokens[1 .. $];\r\n return result;\r\n}\r\n\r\nchar mirror_char(char c)\r\n{\r\n switch (c)\r\n {\r\n case '0':\r\n return '0';\r\n case '1':\r\n return '1';\r\n case '2':\r\n return '5';\r\n case '5':\r\n return '2';\r\n case '8':\r\n return '8';\r\n default:\r\n return '\\0';\r\n }\r\n}\r\n\r\nchar[5] mirror_time(char[5] str)\r\nin(str[2] == ':')\r\n{\r\n return [\r\n mirror_char(str[4]), mirror_char(str[3]), ':', mirror_char(str[1]),\r\n mirror_char(str[0])\r\n ];\r\n}\r\n\r\nbool is_valid_hour(const char[] str, int h)\r\nin(str.length == 2)\r\nin(h >= 1 && h <= 100)\r\n{\r\n if (!str.all!isDigit)\r\n return false;\r\n int value = str.to!int;\r\n return value < h;\r\n}\r\n\r\nalias is_valid_minute = is_valid_hour;\r\n\r\nbool is_valid_time(char[5] str, int h, int m)\r\n{\r\n return is_valid_hour(str[0 .. 2], h) && is_valid_minute(str[3 .. 5], m);\r\n}\r\n\r\nchar[5] next_time_str(char[5] str, int h, int m)\r\nin(is_valid_time(str, h, m))\r\n{\r\n assert(str.length == 5);\r\n auto hour = str[0 .. 2].to!int;\r\n auto minute = str[3 .. 5].to!int;\r\n ++minute;\r\n if (minute >= m)\r\n {\r\n minute = 0;\r\n ++hour;\r\n }\r\n if (hour >= h)\r\n hour = 0;\r\n char[5] result;\r\n sformat!\"%02d:%02d\"(result, hour, minute);\r\n assert(is_valid_time(result, h, m));\r\n return result;\r\n}\r\n\r\nvoid solve_case()\r\n{\r\n auto h = read!int, m = read!int;\r\n char[5] time_str = read!string;\r\n assert(is_valid_time(time_str, h, m));\r\n while (!is_valid_time(mirror_time(time_str), h, m))\r\n {\r\n time_str = next_time_str(time_str, h, m);\r\n }\r\n writeln(time_str);\r\n}\r\n\r\nvoid main()\r\n{\r\n auto T = read!int;\r\n foreach (case_index; 0 .. T)\r\n solve_case();\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[](t);\r\n\tauto safe = [1, 1, 1, 0, 0, 1, 0, 0, 1, 0];\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto h = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tauto tokens = s.split(\":\");\r\n\t\tint hh, mm;\r\n\t\tvoid f (ref int x, string s)\r\n\t\t{\r\n\t\t\tforeach (i; 0..2)\r\n\t\t\t\tx += 10^^(1-i) * (s[i]-'0');\r\n\t\t}\r\n\t\tf(hh, tokens[0]);\r\n\t\tf(mm, tokens[1]);\r\n\t\t\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tauto hh_s = hh.to!string;\r\n\t\t\tauto mm_s = mm.to!string;\r\n\t\t\twhile (hh_s.length < 2)\r\n\t\t\t\thh_s = '0' ~ hh_s;\r\n\t\t\twhile (mm_s.length < 2)\r\n\t\t\t\tmm_s = '0' ~ mm_s;\r\n\t\t\tbool ok = true;\r\n\t\t\tforeach (c; hh_s ~ mm_s)\r\n\t\t\t{\r\n\t\t\t\tif (safe[c-'0'] == 0)\r\n\t\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t\tif (ok)\r\n\t\t\t{\r\n\t\t\t\tstring hh_s2, mm_s2;\r\n\t\t\t\tforeach_reverse (c; hh_s)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (c == '2')\r\n\t\t\t\t\t\tmm_s2 ~= '5';\r\n\t\t\t\t\telse if (c == '5')\r\n\t\t\t\t\t\tmm_s2 ~= '2';\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tmm_s2 ~= c;\r\n\t\t\t\t}\r\n\t\t\t\tforeach_reverse (c; mm_s)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (c == '2')\r\n\t\t\t\t\t\thh_s2 ~= '5';\r\n\t\t\t\t\telse if (c == '5')\r\n\t\t\t\t\t\thh_s2 ~= '2';\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\thh_s2 ~= c;\r\n\t\t\t\t}\r\n\t\t\t\tint hh2, mm2;\r\n\t\t\t\tf(hh2, hh_s2);\r\n\t\t\t\tf(mm2, mm_s2);\r\n\t\t\t\tif (hh2 >= h || mm2 >= m)\r\n\t\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t\tif (ok)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = hh_s ~ \":\" ~ mm_s;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t++mm;\r\n\t\t\tif (mm == m)\r\n\t\t\t{\r\n\t\t\t\tmm = 0;\r\n\t\t\t\t++hh;\r\n\t\t\t\tif (hh == h)\r\n\t\t\t\t\thh = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "module main;\r\nimport core.exception;\r\nimport std.stdio, std.conv, std.string, std.ascii, std.format;\r\n\r\nT read(T)()\r\n{\r\n static string[] tokens;\r\n while (!tokens.length)\r\n tokens = stdin.readln.split;\r\n immutable result = tokens[0].to!T;\r\n tokens = tokens[1 .. $];\r\n return result;\r\n}\r\n\r\nstruct Time\r\n{\r\n immutable int hc = 1, mc = 1;\r\n int h = 0, m = 0;\r\n\r\n invariant(h >= 0 && h < hc);\r\n invariant(m >= 0 && m < mc);\r\n\r\n this(int h, int m, int hc, int mc) inout\r\n in(hc >= 1 && hc <= 100)\r\n in(mc >= 1 && mc <= 100)\r\n {\r\n this.h = h;\r\n this.m = m;\r\n this.hc = hc;\r\n this.mc = mc;\r\n }\r\n\r\n this(char[5] str, int hc, int mc) inout\r\n in(str[2] == ':')\r\n {\r\n this(str[0 .. 2].to!int, str[3 .. 5].to!int, hc, mc);\r\n }\r\n\r\n string toString() const\r\n {\r\n return format!\"%02d:%02d\"(h, m);\r\n }\r\n\r\n ref Time opUnary(string op)() if (op == \"++\")\r\n {\r\n ++m;\r\n if (m >= mc)\r\n {\r\n m = 0;\r\n ++h;\r\n if (h >= hc)\r\n h = 0;\r\n }\r\n return this;\r\n }\r\n\r\n bool is_mirrored_valid() const\r\n {\r\n char mirror_char(char c)\r\n in(c.isDigit)\r\n {\r\n switch (c)\r\n {\r\n case '0':\r\n return '0';\r\n case '1':\r\n return '1';\r\n case '2':\r\n return '5';\r\n case '5':\r\n return '2';\r\n case '8':\r\n return '8';\r\n default:\r\n return 0;\r\n }\r\n }\r\n\r\n int mirror(int n)\r\n in(n >= 0 && n < 100)\r\n {\r\n immutable a = mirror_char(cast(char)('0' + n % 10));\r\n immutable b = mirror_char(cast(char)('0' + n / 10));\r\n if (!a || !b)\r\n return int.max;\r\n return [a, b].to!int;\r\n }\r\n\r\n return mirror(m) < hc && mirror(h) < mc;\r\n }\r\n}\r\n\r\nvoid solve_case()\r\n{\r\n immutable h = read!int, m = read!int;\r\n immutable char[5] time_str = read!string;\r\n auto time = Time(time_str, h, m);\r\n while (!time.is_mirrored_valid)\r\n ++time;\r\n writeln(time);\r\n}\r\n\r\nvoid main()\r\n{\r\n immutable T = read!int;\r\n foreach (case_index; 0 .. T)\r\n solve_case();\r\n}"}, {"source_code": "module main;\r\nimport core.exception;\r\nimport std.stdio, std.conv, std.string, std.ascii, std.format;\r\n\r\nT read(T)()\r\n{\r\n static string[] tokens;\r\n while (!tokens.length)\r\n tokens = stdin.readln.split;\r\n immutable result = tokens[0].to!T;\r\n tokens = tokens[1 .. $];\r\n return result;\r\n}\r\n\r\nstruct Time\r\n{\r\n immutable int hc = 1, mc = 1;\r\n int h = 0, m = 0;\r\n\r\n invariant(h >= 0 && h < hc);\r\n invariant(m >= 0 && m < mc);\r\n\r\n this(int h, int m, int hc, int mc) inout\r\n in(hc >= 1 && hc <= 100)\r\n in(mc >= 1 && mc <= 100)\r\n {\r\n this.h = h;\r\n this.m = m;\r\n this.hc = hc;\r\n this.mc = mc;\r\n }\r\n\r\n this(char[5] str, int hc, int mc) inout\r\n in(str[2] == ':')\r\n {\r\n this(str[0 .. 2].to!int, str[3 .. 5].to!int, hc, mc);\r\n }\r\n\r\n string toString() const\r\n {\r\n return format!\"%02d:%02d\"(h, m);\r\n }\r\n\r\n ref Time opUnary(string op)() if (op == \"++\")\r\n {\r\n ++m;\r\n if (m >= mc)\r\n {\r\n m = 0;\r\n ++h;\r\n if (h >= hc)\r\n h = 0;\r\n }\r\n return this;\r\n }\r\n\r\n bool is_mirrored_valid() const\r\n {\r\n char mirror_char(char c)\r\n in(c.isDigit)\r\n {\r\n final switch (c)\r\n {\r\n case '0':\r\n return '0';\r\n case '1':\r\n return '1';\r\n case '2':\r\n return '5';\r\n case '5':\r\n return '2';\r\n case '8':\r\n return '8';\r\n }\r\n }\r\n\r\n int mirror(int n)\r\n in(n >= 0 && n < 100)\r\n {\r\n immutable a = cast(char)('0' + n / 10);\r\n immutable b = cast(char)('0' + n % 10);\r\n return [mirror_char(b), mirror_char(a)].to!int;\r\n }\r\n\r\n try\r\n {\r\n return mirror(m) < hc && mirror(h) < mc;\r\n }\r\n catch (Throwable ex)\r\n {\r\n return false;\r\n }\r\n }\r\n}\r\n\r\nvoid solve_case()\r\n{\r\n immutable h = read!int, m = read!int;\r\n immutable char[5] time_str = read!string;\r\n auto time = Time(time_str, h, m);\r\n while (!time.is_mirrored_valid)\r\n ++time;\r\n writeln(time);\r\n}\r\n\r\nvoid main()\r\n{\r\n immutable T = read!int;\r\n foreach (case_index; 0 .. T)\r\n solve_case();\r\n}"}], "negative_code": [{"source_code": "module main;\r\nimport core.exception;\r\nimport std.stdio, std.conv, std.string, std.ascii, std.format;\r\n\r\nT read(T)()\r\n{\r\n static string[] tokens;\r\n while (!tokens.length)\r\n tokens = stdin.readln.split;\r\n immutable result = tokens[0].to!T;\r\n tokens = tokens[1 .. $];\r\n return result;\r\n}\r\n\r\nstruct Time\r\n{\r\n immutable int hc = 1, mc = 1;\r\n int h = 0, m = 0;\r\n\r\n invariant(h >= 0 && h < hc);\r\n invariant(m >= 0 && m < mc);\r\n\r\n this(int h, int m, int hc, int mc) inout\r\n in(hc >= 1 && hc <= 100)\r\n in(mc >= 1 && mc <= 100)\r\n {\r\n this.h = h;\r\n this.m = m;\r\n this.hc = hc;\r\n this.mc = mc;\r\n }\r\n\r\n this(char[5] str, int hc, int mc) inout\r\n in(str[2] == ':')\r\n {\r\n this(str[0 .. 2].to!int, str[3 .. 5].to!int, hc, mc);\r\n }\r\n\r\n string toString() const\r\n {\r\n return format!\"%02d:%02d\"(h, m);\r\n }\r\n\r\n ref Time opUnary(string op)() if (op == \"++\")\r\n {\r\n ++m;\r\n if (m >= mc)\r\n {\r\n m = 0;\r\n ++h;\r\n if (h >= hc)\r\n h = 0;\r\n }\r\n return this;\r\n }\r\n\r\n bool is_mirrored_valid() const\r\n {\r\n char mirror_char(char c)\r\n in(c.isDigit)\r\n {\r\n switch (c)\r\n {\r\n case '0':\r\n return '0';\r\n case '1':\r\n return '1';\r\n case '2':\r\n return '5';\r\n case '5':\r\n return '2';\r\n case '8':\r\n return '8';\r\n default:\r\n return 0;\r\n }\r\n }\r\n\r\n int mirror(int n)\r\n in(n >= 0 && n < 100)\r\n {\r\n immutable a = mirror_char(cast(char)('0' + n / 10));\r\n immutable b = mirror_char(cast(char)('0' + n % 10));\r\n if (!a || !b)\r\n return int.max;\r\n return [a, b].to!int;\r\n }\r\n\r\n return mirror(m) < hc && mirror(h) < mc;\r\n }\r\n}\r\n\r\nvoid solve_case()\r\n{\r\n immutable h = read!int, m = read!int;\r\n immutable char[5] time_str = read!string;\r\n auto time = Time(time_str, h, m);\r\n while (!time.is_mirrored_valid)\r\n ++time;\r\n writeln(time);\r\n}\r\n\r\nvoid main()\r\n{\r\n immutable T = read!int;\r\n foreach (case_index; 0 .. T)\r\n solve_case();\r\n}"}, {"source_code": "module main;\r\nimport core.exception;\r\nimport std.stdio, std.conv, std.string, std.ascii, std.format;\r\n\r\nT read(T)()\r\n{\r\n static string[] tokens;\r\n while (!tokens.length)\r\n tokens = stdin.readln.split;\r\n immutable result = tokens[0].to!T;\r\n tokens = tokens[1 .. $];\r\n return result;\r\n}\r\n\r\nstruct Time\r\n{\r\n immutable int hc = 1, mc = 1;\r\n int h = 0, m = 0;\r\n\r\n invariant(h >= 0 && h < hc);\r\n invariant(m >= 0 && m < mc);\r\n\r\n this(int h, int m, int hc, int mc) inout\r\n in(hc >= 1 && hc <= 100)\r\n in(mc >= 1 && mc <= 100)\r\n {\r\n this.h = h;\r\n this.m = m;\r\n this.hc = hc;\r\n this.mc = mc;\r\n }\r\n\r\n this(char[5] str, int hc, int mc) inout\r\n in(str[2] == ':')\r\n {\r\n this(str[0 .. 2].to!int, str[3 .. 5].to!int, hc, mc);\r\n }\r\n\r\n string toString() const\r\n {\r\n return format!\"%02d:%02d\"(h, m);\r\n }\r\n\r\n ref Time opUnary(string op)() if (op == \"++\")\r\n {\r\n ++m;\r\n if (m >= mc)\r\n {\r\n m = 0;\r\n ++h;\r\n if (h >= hc)\r\n h = 0;\r\n }\r\n return this;\r\n }\r\n\r\n bool is_mirrored_valid() const\r\n {\r\n char mirror_char(char c)\r\n in(c.isDigit)\r\n {\r\n final switch (c)\r\n {\r\n case '0':\r\n return '0';\r\n case '1':\r\n return '1';\r\n case '2':\r\n return '5';\r\n case '5':\r\n return '2';\r\n case '8':\r\n return '8';\r\n }\r\n }\r\n\r\n int mirror(int n)\r\n in(n >= 0 && n < 100)\r\n {\r\n immutable a = cast(char)('0' + n / 10);\r\n immutable b = cast(char)('0' + n % 10);\r\n return [mirror_char(b), mirror_char(a)].to!int;\r\n }\r\n\r\n try\r\n {\r\n return mirror(m) < hc && mirror(h) < mc;\r\n }\r\n catch (Throwable ex)\r\n {\r\n writeln(ex);\r\n return false;\r\n }\r\n }\r\n}\r\n\r\nvoid solve_case()\r\n{\r\n immutable h = read!int, m = read!int;\r\n immutable char[5] time_str = read!string;\r\n auto time = Time(time_str, h, m);\r\n while (!time.is_mirrored_valid)\r\n ++time;\r\n writeln(time);\r\n}\r\n\r\nvoid main()\r\n{\r\n immutable T = read!int;\r\n foreach (case_index; 0 .. T)\r\n solve_case();\r\n}"}, {"source_code": "module main;\r\nimport std.stdio, std.conv, std.string, std.ascii, std.algorithm, std.format;\r\n\r\nT read(T)()\r\n{\r\n static string[] tokens;\r\n while (!tokens.length)\r\n tokens = stdin.readln.split;\r\n auto result = tokens[0].to!T;\r\n tokens = tokens[1 .. $];\r\n return result;\r\n}\r\n\r\nchar mirror_char(char c)\r\n{\r\n switch (c)\r\n {\r\n case '0':\r\n return '0';\r\n case '1':\r\n return '1';\r\n case '2':\r\n return '5';\r\n case '5':\r\n return '2';\r\n case '6':\r\n return '9';\r\n case '8':\r\n return '8';\r\n case '9':\r\n return '6';\r\n default:\r\n return '\\0';\r\n }\r\n}\r\n\r\nchar[5] mirror_time(char[5] str)\r\nin(str[2] == ':')\r\n{\r\n return [\r\n mirror_char(str[4]), mirror_char(str[3]), ':', mirror_char(str[1]),\r\n mirror_char(str[0])\r\n ];\r\n}\r\n\r\nbool is_valid_hour(const char[] str, int h)\r\nin(str.length == 2)\r\nin(h >= 1 && h <= 100)\r\n{\r\n if (!str.all!isDigit)\r\n return false;\r\n int value = str.to!int;\r\n return value < h;\r\n}\r\n\r\nalias is_valid_minute = is_valid_hour;\r\n\r\nbool is_valid_time(char[5] str, int h, int m)\r\n{\r\n return is_valid_hour(str[0 .. 2], h) && is_valid_minute(str[3 .. 5], m);\r\n}\r\n\r\nchar[5] next_time_str(char[5] str, int h, int m)\r\nin(is_valid_time(str, h, m))\r\n{\r\n assert(str.length == 5);\r\n auto hour = str[0 .. 2].to!int;\r\n auto minute = str[3 .. 5].to!int;\r\n ++minute;\r\n if (minute >= m)\r\n {\r\n minute = 0;\r\n ++hour;\r\n }\r\n if (hour >= h)\r\n hour = 0;\r\n char[5] result;\r\n sformat!\"%02d:%02d\"(result, hour, minute);\r\n assert(is_valid_time(result, h, m));\r\n return result;\r\n}\r\n\r\nvoid solve_case()\r\n{\r\n auto h = read!int, m = read!int;\r\n char[5] time_str = read!string;\r\n assert(is_valid_time(time_str, h, m));\r\n while (!is_valid_time(mirror_time(time_str), h, m))\r\n {\r\n time_str = next_time_str(time_str, h, m);\r\n }\r\n writeln(time_str);\r\n}\r\n\r\nvoid main()\r\n{\r\n auto T = read!int;\r\n foreach (case_index; 0 .. T)\r\n solve_case();\r\n}"}], "src_uid": "7f28e4dbd199b84bd7885bf7f479cf38"} {"source_code": "import std.stdio;\nimport std.bigint;\nimport std.container;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\nimport std.bitmanip;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.range;\nimport std.uni;\nimport std.complex;\nimport std.typecons;\nimport core.stdc.stdio:freopen;\nimport core.bitop;\nimport std.regex;\nimport std.complex;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nimmutable int mod=1000000007;\npure nothrow @safe X binpow(X,Y)(X base,Y exp)\nif(!is(Y==float) && !is(Y==real) && !is(Y==double))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @safe auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(!is(Y==float) && !is(Y==real) && !is(Y==double))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@safe @property void putarr(X)(X a,in char ch=' ')\n{\n\tforeach(const ref i;a)write(i,ch);\n}\n@safe @property void putarr(X)(X[][] a)\n{\n\tforeach(i;0..a.length)\n\t{\n\t\tforeach(j;0..a[i].length)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nvoid getarr(X)(X a,in int n)\n{\n\tforeach(ref i;a[0..n])input(&i);\n}\nauto arread(T)()\n{\n\treturn readln.split.map!(to!(T)).array;\n}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {\n\treturn readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;\n}\nstruct pair(X,Y)\n{\n\tX fi;\n\tY se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t\t}\n\tthis(this){fi=fi;se=se;}\n\tint opCmp(ref const pair!(X,Y) s_) const pure nothrow\n\t{\n\t\tint cmp=0-(fi<s_.fi)+(fi>s_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(se<s_.se)+(se>s_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(X x_,Y y_) pure nothrow\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(X a_) pure nothrow @safe @property @nogc\n{\n\treturn a_*a_;\n}\nX cub(X)(X a_) pure nothrow @safe @property @nogc\n{\n\treturn a_*a_*a_;\n}\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nvoid inf(in char* name) nothrow @nogc @system\n{\n\tfreopen(name,\"r\",core.stdc.stdio.stdin);\n}\nvoid ouf(in char* name) nothrow @nogc @system\n{\n\tfreopen(name,\"w\",core.stdc.stdio.stdout);\n}\n//split strip readln equalRange upperBound lowerBound string wstring\n//dstring ulong wchar dchar array uint foreach_reverse find count false\n//nextPermutation isSorted fill reverse swap size_t clear empty insert\n//front back remove hypot sqrt round continue swapRanges minPos maxPos\n//break goto switch boyerMooreFinder minElement maxElement heapify true\n//static multiSort schwartzSort partialSort merge uniq joiner filter\n//cumulativeFold fold each sort isAlpha isNumber isWhite isLower isUpper\n//toLower toUpper mixin\nint[1000][1000] t,a,b;\nvoid main()\n{\n\tint n,m;\n\tinput(&n,&m);\n\tforeach(i;0..n) foreach(j;0..m){input(&t[i][j]);a[i][j]=b[i][j]=t[i][j];}\n\t\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;1..m)a[i][j]+=a[i][j-1];\n\t}\n\tforeach(i;0..m)\n\t{\n\t\tforeach(j;1..n)b[j][i]+=b[j-1][i];\n\t}\n\tint ans=0;\n\tfor(int i=0;i<n;i++)for(int j=0;j<m;j++)\n\t{\n\t\tif(t[i][j]==0)\n\t\t{\n\t\t\tif(a[i][j]>0)ans++;\n\t\t\tif(b[i][j]>0)ans++;\n\t\t\tif(a[i][j]<a[i][m-1])ans++;\n\t\t\tif(b[i][j]<b[n-1][j])ans++;\n\t\t}\n\t\t\n\t}\n\twriteln(ans);\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nint n, m;\nbool[1000][1000][2] a;\n\ninout(bool)[ ][3] findTrue(inout(bool)[ ] a) {\n int i = 0, j = cast(int)a.length;\n while (i < a.length && !a[i])\n i++;\n while (j > i && !a[j - 1])\n j--;\n return [a[0 .. i], a[i .. j], a[j .. $]];\n}\n\nvoid main() {\n while (read(&n, &m)) {\n foreach (i, ref row; a[0][0 .. n])\n foreach (j, ref elem; row[0 .. m]) {\n char c;\n read(&c);\n elem = a[1][j][i] = c == '1';\n }\n int result = 0;\n foreach (ref row; a[0][0 .. n]) {\n auto t = findTrue(row[0 .. m]);\n if (!t[1].empty) {\n result += t[0].count(false);\n result += t[1].count(false) << 1;\n result += t[2].count(false);\n }\n }\n foreach (ref row; a[1][0 .. m]) {\n auto t = findTrue(row[0 .. n]);\n if (!t[1].empty) {\n result += t[0].count(false);\n result += t[1].count(false) << 1;\n result += t[2].count(false);\n }\n }\n writeln(result);\n }\n}\n"}], "negative_code": [], "src_uid": "c3a7d82f6c3cf8678a1c7c521e0a5f51"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\talias Depth = Tuple !(int, q{depth}, int, q{num});\n\t\tauto d = new Depth [n];\n\n\t\talias Record =\n\t\t Tuple !(int, q{depth}, int, q{next}, int, q{num});\n\t\tauto c = new Record [] [n];\n\n\t\tvoid recur1 (int v, int p)\n\t\t{\n\t\t\tauto res = Depth (0, v);\n\t\t\tforeach (u; a[v]) if (u != p)\n\t\t\t{\n\t\t\t\trecur1 (u, v);\n\t\t\t\tres = max (res,\n\t\t\t\t Depth (d[u].depth + 1, d[u].num));\n\t\t\t\tc[v] ~= Record (d[u].depth + 1, u, d[u].num);\n\t\t\t}\n\t\t\td[v] = res;\n\t\t\tsort !(q{a > b}) (c[v]);\n\t\t\tc[v] ~= Record (0, NA, NA);\n\t\t\tc[v] ~= Record (0, NA, NA);\n\t\t\tc[v] ~= Record (0, NA, NA);\n\t\t}\n\n\t\trecur1 (0, NA);\n\n\t\tint x = NA;\n\t\tint y = NA;\n\t\tint z = NA;\n\t\tint answer = 0;\n\n\t\tvoid recur2 (int v, int p, Record h)\n\t\t{\n\t\t\tint cur = h.depth + c[v][0].depth + c[v][1].depth;\n\t\t\tif (answer < cur)\n\t\t\t{\n\t\t\t\tanswer = cur;\n\t\t\t\tx = h.num;\n\t\t\t\ty = c[v][0].num;\n\t\t\t\tz = c[v][1].num;\n\t\t\t}\n\n\t\t\tint alt = c[v][0].depth + c[v][1].depth + c[v][2].depth;\n\t\t\tif (answer < alt)\n\t\t\t{\n\t\t\t\tanswer = alt;\n\t\t\t\tx = c[v][0].num;\n\t\t\t\ty = c[v][1].num;\n\t\t\t\tz = c[v][2].num;\n\t\t\t}\n\n\t\t\tforeach (u; a[v]) if (u != p)\n\t\t\t{\n\t\t\t\tint i = 0;\n\t\t\t\tif (c[v][i].next == u)\n\t\t\t\t{\n\t\t\t\t\ti += 1;\n\t\t\t\t}\n\t\t\t\tauto t = max (h, c[v][i]);\n\t\t\t\tt.depth += 1;\n\t\t\t\trecur2 (u, v, t);\n\t\t\t}\n\t\t}\n\n\t\trecur2 (0, NA, Record (0, 0, 0));\n\n\t\tif (x > y) swap (x, y);\n\t\tif (y > z) swap (y, z);\n\t\tif (x > y) swap (x, y);\n\n\t\twhile (y == NA || y == x || y == z)\n\t\t{\n\t\t\ty += 1;\n\t\t}\n\n\t\twhile (x == NA || x == y || x == z)\n\t\t{\n\t\t\tx += 1;\n\t\t}\n\n\t\twriteln (answer);\n\t\twriteln (x + 1, \" \", y + 1, \" \", z + 1);\n\t}\n}\n", "positive_code": [{"source_code": "import std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.algorithm.mutation;\nimport std.algorithm.searching;\n\nstring[] tokens;\nstring readToken()\n{\n while (tokens.empty)\n {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nconst int N = 200000;\n\nint n;\nArray!int[N] tree;\n\nint[] bfs(int s)\n{\n int[] dist = new int[n];\n fill(dist, -1);\n dist[s] = 0;\n int[] queue = new int[n];\n int rear = 0;\n queue[rear++] = s;\n for (int head = 0; head < rear; ++head)\n {\n int u = queue[head];\n foreach (v; tree[u])\n {\n if (dist[v] == -1)\n {\n dist[v] = dist[u] + 1;\n queue[rear++] = v;\n }\n }\n }\n return dist;\n}\n\nint argmax(int[] dist)\n{\n return cast(int) dist.enumerate.maxElement!\"a.value\"[0];\n}\n\nauto solve()\n{\n int x = argmax(bfs(0));\n int[] dx = bfs(x);\n int y = argmax(dx);\n int diameter = dx[y];\n int[] dy = bfs(y);\n if (diameter == n - 1)\n {\n int z = 0;\n while (z == x || z == y)\n {\n z++;\n }\n return tuple(n - 1, x, y, z);\n }\n int z = n.iota.maxElement!((z) => dx[z] + dy[z]);\n return tuple(dx[z] + dy[z] + diameter >> 1, x, y, z);\n}\n\nvoid main()\n{\n n = readInt;\n for (int i = 0; i < n - 1; ++i)\n {\n int a = readInt - 1;\n int b = readInt - 1;\n tree[a].insert(b);\n tree[b].insert(a);\n }\n auto res = solve();\n writeln(res[0]);\n writeln(res[1] + 1, \" \", res[2] + 1, \" \", res[3] + 1);\n}\n"}], "negative_code": [{"source_code": "import std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.algorithm.mutation;\nimport std.algorithm.searching;\n\nstring[] tokens;\nstring readToken()\n{\n while (tokens.empty)\n {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n}\n\nint readInt()\n{\n return readToken.to!int;\n}\n\nconst int N = 200000;\n\nint n;\nArray!int[N] tree;\n\nint[] bfs(int s)\n{\n int[] dist = new int[n];\n fill(dist, -1);\n dist[s] = 0;\n int[] queue = new int[n];\n int rear = 0;\n queue[rear++] = s;\n for (int head = 0; head < rear; ++head)\n {\n int u = queue[head];\n foreach (v; tree[u])\n {\n if (dist[v] == -1)\n {\n dist[v] = dist[u] + 1;\n queue[rear++] = v;\n }\n }\n }\n return dist;\n}\n\nint argmax(int[] dist)\n{\n return cast(int) dist.enumerate.maxElement!\"a.value\"[0];\n}\n\nauto solve()\n{\n int x = argmax(bfs(0));\n int[] dx = bfs(x);\n int y = argmax(dx);\n int diameter = dx[y];\n int[] dy = bfs(y);\n if (diameter == n - 1)\n {\n int z = 0;\n while (z == x || z == y)\n {\n z++;\n }\n return tuple(n - 1, x, y, z);\n }\n int z = n.iota.maxElement!((z) => dx[z] + dy[z]);\n return tuple(dx[z] + dy[z] - diameter, x, y, z);\n}\n\nvoid main()\n{\n n = readInt;\n for (int i = 0; i < n - 1; ++i)\n {\n int a = readInt - 1;\n int b = readInt - 1;\n tree[a].insert(b);\n tree[b].insert(a);\n }\n auto res = solve();\n writeln(res[0]);\n writeln(res[1] + 1, \" \", res[2] + 1, \" \", res[3] + 1);\n}\n"}], "src_uid": "1e0148d417f80b995cac18c2f4cea32e"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int n)\n{\n if (n == 1)\n {\n writeln(0);\n return;\n }\n auto f = new bool[n + 1];\n fill(f, false);\n int[] s;\n foreach (i; 2 .. n + 1)\n {\n if (!f[i])\n {\n for (int j = i; j <= n; j *= i)\n {\n s ~= j;\n }\n for (int j = i * i; j <= n; j += i)\n {\n f[j] = true;\n }\n }\n }\n writeln(s.length);\n foreach (i; 0 .. s.length - 1)\n {\n write(s[i], \" \");\n }\n writeln(s[s.length - 1]);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n solve(n);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint [] a;\n\t\tauto b = new bool [n + 1];\n\t\tb[] = true;\n\t\tfor (int i = 2; i <= n; i++) if (b[i])\n\t\t{\n\t\t\tfor (int j = i; j <= n; j *= i)\n\t\t\t{\n\t\t\t\ta ~= j;\n\t\t\t}\n\t\t\tfor (int j = i * i; j <= n; j += i)\n\t\t\t{\n\t\t\t\tb[j] = false;\n\t\t\t}\n\t\t}\n\t\twriteln (a.length);\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}], "negative_code": [], "src_uid": "7f61b1d0e8294db74d33a6b6696989ad"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const S = readToken();\n const N = cast(int)(S.length);\n \n auto s = S.dup;\n \n int[] anss;\n foreach (i; 0 .. N - 5 + 1) {\n if (s[i .. i + 5] == \"twone\") {\n anss ~= i + 2;\n s[i + 2] = '!';\n }\n }\n debug {\n writeln(\"s = \", s);\n }\n foreach (i; 0 .. N - 3 + 1) {\n if (s[i .. i + 3] == \"one\" || s[i .. i + 3] == \"two\") {\n anss ~= i + 1;\n }\n }\n \n writeln(anss.length);\n int ou;\n foreach (i; anss) {\n if (ou++) write(\" \");\n write(i + 1);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new size_t[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\t\tif (s.length < 3) continue;\n\t\tforeach (i; 2..s.length)\n\t\t{\n\t\t\tif (s[i-2..i+1] == \"one\")\n\t\t\t{\n\t\t\t\tif (i >= 4)\n\t\t\t\t{\n\t\t\t\t\tif (s[i-4..i+1] == \"twone\")\n\t\t\t\t\t{\n\t\t\t\t\t\t++ans[ti][$-1];\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tans[ti] ~= i;\n\t\t\t}\n\t\t\telse if (s[i-2..i+1] == \"two\")\n\t\t\t{\n\t\t\t\tans[ti] ~= i;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t{\n\t\t\twriteln(0);\n\t\t\twriteln;\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(e.length);\n\t\t\te.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "9f8660190134606194cdd8db891a3d46"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 9 + 23;\n\nvoid main()\n{\n int[2] ns;\n int[][2] arr;\n \n foreach (i; 0 .. 2) {\n readf(\"%s\", &ns[i]);\n readln;\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n Tuple!(int, char)[] ans;\n int i = ns[0] - 1, gidx = ns[1]-1;\n for ( ; i >= 0 && gidx >= 0; ) {\n int cursm = 0;\n int j = i;\n while (j >= 0 && cursm < arr[1][gidx]) {\n cursm += arr[0][j];\n j -= 1;\n }\n \n debug { writeln(j+1, ' ', i, ' ', cursm, ' ', arr[1][gidx]); }\n \n if (cursm > arr[1][gidx]) {\n writeln(\"NO\");\n return;\n }\n \n int mx = arr[0][j+1 .. i+1].maxElement;\n int mn = arr[0][j+1 .. i+1].minElement;\n if (i - j > 1 && mx == mn) {\n writeln(\"NO\");\n return;\n }\n \n int start = j+1;\n for (int k = j+1; k <= i; ++k) {\n if (arr[0][k] != mx) { continue; }\n if ((k > j+1 && arr[0][k-1] < mx) || (k < i && arr[0][k+1] < mx)) {\n start = k;\n break;\n }\n }\n \n int curidx = start + 1;\n int cursz = arr[0][start];\n int lb = start-1, rb = start+1;\n while (lb > j || rb <= i) {\n if (lb > j && arr[0][lb] < cursz) {\n cursz += arr[0][lb];\n ans ~= tuple(curidx, 'L');\n curidx -= 1;\n lb -= 1;\n } else {\n cursz += arr[0][rb];\n ans ~= tuple(curidx, 'R');\n rb += 1;\n }\n }\n \n i = j;\n gidx -= 1;\n }\n \n if (i >= 0 || gidx >= 0) {\n writeln(\"NO\");\n return;\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 9 + 23;\n\nvoid main()\n{\n int[2] ns;\n int[][2] arr;\n \n foreach (i; 0 .. 2) {\n readf(\"%s\", &ns[i]);\n readln;\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n Tuple!(int, char)[] ans;\n int i = ns[0] - 1, gidx = ns[1]-1;\n for ( ; i >= 0 && gidx >= 0; ) {\n int cursm = 0;\n int j = i;\n while (j >= 0 && cursm < arr[1][gidx]) {\n cursm += arr[0][j];\n j -= 1;\n }\n \n debug { writeln(j+1, ' ', i, ' ', cursm, ' ', arr[1][gidx]); }\n \n if (cursm > arr[1][gidx]) {\n writeln(\"NO\");\n return;\n }\n \n bool segAns(int le, int r) {\n if (r - le + 1 == 1) { return true; }\n \n int mx = arr[0][le .. r+1].maxElement;\n Nullable!int start;\n for (int k = le; k <= r; ++k) {\n if (arr[0][k] != mx) { continue; }\n if ((k > le && arr[0][k-1] < mx) || (k < r && arr[0][k+1] < mx)) {\n start = k;\n break;\n }\n }\n \n if (start.isNull) { return false; }\n \n int curidx = start + 1;\n int cursz = arr[0][start];\n int lb = start-1, rb = start+1;\n while (lb >= le || rb <= r) {\n if (lb >= le && arr[0][lb] < cursz) {\n cursz += arr[0][lb];\n ans ~= tuple(curidx, 'L');\n curidx -= 1;\n lb -= 1;\n } else {\n cursz += arr[0][rb];\n ans ~= tuple(curidx, 'R');\n rb += 1;\n }\n }\n \n return true;\n }\n \n if (! segAns(j+1, i)) {\n writeln(\"NO\");\n return;\n }\n \n i = j;\n gidx -= 1;\n }\n \n if (i >= 0 || gidx >= 0) {\n writeln(\"NO\");\n return;\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 9 + 23;\n\nvoid main()\n{\n int[2] ns;\n int[][2] arr;\n \n foreach (i; 0 .. 2) {\n readf(\"%s\", &ns[i]);\n readln;\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n Tuple!(int, char)[] ans;\n int gidx = ns[1]-1;\n for (int i = ns[0]-1; i >= 0 && gidx >= 0; ) {\n int cursm = 0;\n int j = i;\n while (j >= 0 && cursm < arr[1][gidx]) {\n cursm += arr[0][j];\n j -= 1;\n }\n \n debug { writeln(j+1, ' ', i, ' ', cursm, ' ', arr[1][gidx]); }\n \n if (cursm > arr[1][gidx]) {\n writeln(\"NO\");\n return;\n }\n \n int mx = arr[0][j+1 .. i+1].maxElement;\n int mn = arr[0][j+1 .. i+1].minElement;\n if (i - j > 1 && mx == mn) {\n writeln(\"NO\");\n return;\n }\n \n int start = j+1;\n for (int k = j+1; k <= i; ++k) {\n if (arr[0][k] != mx) { continue; }\n if ((k > j+1 && arr[0][k-1] < mx) || (k < i && arr[0][k+1] < mx)) {\n start = k;\n break;\n }\n }\n \n int curidx = start + 1;\n int cursz = arr[0][start];\n int lb = start-1, rb = start+1;\n while (lb > j || rb <= i) {\n if (lb > j && arr[0][lb] < cursz) {\n cursz += arr[0][lb];\n ans ~= tuple(curidx, 'L');\n curidx -= 1;\n lb -= 1;\n } else {\n cursz += arr[0][rb];\n ans ~= tuple(curidx, 'R');\n rb += 1;\n }\n }\n \n i = j;\n gidx -= 1;\n }\n \n if (gidx >= 0) {\n writeln(\"NO\");\n return;\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 9 + 23;\n\nvoid main()\n{\n int[2] ns;\n int[][2] arr;\n \n foreach (i; 0 .. 2) {\n readf(\"%s\", &ns[i]);\n readln;\n arr[i] = readln.chomp.split.map!(to!int).array;\n }\n \n Tuple!(int, char)[] ans;\n int gidx = ns[1]-1;\n for (int i = ns[0]-1; i >= 0 && gidx >= 0; ) {\n int cursm = 0;\n int j = i;\n while (j >= 0 && cursm < arr[1][gidx]) {\n cursm += arr[0][j];\n j -= 1;\n }\n \n debug { writeln(j+1, ' ', i, ' ', cursm, ' ', arr[1][gidx]); }\n \n if (cursm > arr[1][gidx]) {\n writeln(\"NO\");\n return;\n }\n \n int mx = arr[0][j+1 .. i+1].maxElement;\n int mn = arr[0][j+1 .. i+1].minElement;\n if (mx == mn) {\n writeln(\"NO\");\n return;\n }\n \n int start = 0;\n for (int k = j+1; k <= i; ++k) {\n if (arr[0][k] != mx) { continue; }\n if ((k > j+1 && arr[0][k-1] < mx) || (k < i && arr[0][k+1] < mx)) {\n start = k;\n break;\n }\n }\n \n int curidx = start + 1;\n int cursz = arr[0][start];\n int lb = start-1, rb = start+1;\n while (lb > j || rb <= i) {\n if (lb > j && arr[0][lb] < cursz) {\n ans ~= tuple(curidx, 'L');\n curidx -= 1;\n lb -= 1;\n } else {\n ans ~= tuple(curidx, 'R');\n rb += 1;\n }\n }\n \n i = j;\n gidx -= 1;\n }\n \n if (gidx >= 0) {\n writeln(\"NO\");\n return;\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n}"}], "src_uid": "a37f805292e68bc0ad4555fa32d180ef"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint rows;\nint cols;\n\nstruct Board {\n bool [] [] contents;\n alias contents this;\n\n this (int rows, int cols) {\n contents = new bool [] [] (rows, cols);\n }\n}\n\nBoard readConfig () {\n auto res = Board (rows, cols);\n foreach (row; 0..rows)\n {\n auto line = readln.strip;\n foreach (col; 0..cols)\n {\n res[row][col] = \"LR\".canFind (line[col]);\n }\n }\n return res;\n}\n\nBoard trans (const ref Board b) {\n int rows = cast (int) b.length;\n int cols = cast (int) b.front.length;\n auto res = Board (cols, rows);\n foreach (row; 0..rows)\n foreach (col; 0..cols)\n res[col][row] = !b[row][col];\n return res;\n}\n\nauto solve (Board b) {\n bool doTrans = cols & 1;\n if (doTrans) {\n b = trans (b);\n swap (rows, cols);\n }\n\n int [2] [] res;\n foreach (row; 0..rows) {\n foreach (col; 0..cols) {\n if (!b[row][col]) {\n int [2] [] cur;\n int cRow = row;\n int cCol = col;\n while (true) {\n debug {writefln\n (\"%s %s\\n%(%(%6s%)\\n%)\",\n cRow, cCol, b);}\n cur ~= [cRow, cCol];\n cCol += 1;\n if (!b[cRow][cCol]) {\n break;\n }\n debug {writefln\n (\"%s %s\\n%(%(%6s%)\\n%)\",\n cRow, cCol, b);}\n cur ~= [cRow, cCol];\n cRow += 1;\n if (b[cRow][cCol]) {\n break;\n }\n }\n foreach_reverse (p; cur) {\n res ~= p;\n b[p[0] + 0][p[1] + 0] ^= true;\n b[p[0] + 0][p[1] + 1] ^= true;\n b[p[0] + 1][p[1] + 0] ^= true;\n b[p[0] + 1][p[1] + 1] ^= true;\n }\n }\n }\n }\n\n if (doTrans) {\n foreach (ref p; res)\n swap (p[0], p[1]);\n swap (rows, cols);\n }\n foreach (ref p; res)\n p[] += 1;\n return res;\n}\n\nvoid main () {\n while (readf (\" %s %s\", &rows, &cols) > 0) {\n readln;\n auto a = readConfig ();\n auto b = readConfig ();\n auto x = a.solve ();\n auto y = b.solve ();\n auto ans = chain (x, y.retro).array;\n writeln (ans.length);\n writefln (\"%(%(%s %)\\n%)\", ans);\n }\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint rows;\nint cols;\n\nstruct Board\n{\n\tbool [] [] contents;\n\talias contents this;\n\n\tthis (int rows, int cols)\n\t{\n\t\tcontents = new bool [] [] (rows, cols);\n\t}\n}\n\nBoard readConfig ()\n{\n\tauto res = Board (rows, cols);\n\tforeach (row; 0..rows)\n\t{\n\t\tauto line = readln.strip;\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tres[row][col] = \"LR\".canFind (line[col]);\n\t\t}\n\t}\n\treturn res;\n}\n\nBoard trans (const ref Board b)\n{\n\tint rows = cast (int) b.length;\n\tint cols = cast (int) b.front.length;\n\tauto res = Board (cols, rows);\n\tforeach (row; 0..rows)\n\t{\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tres[col][row] = !b[row][col];\n\t\t}\n\t}\n\treturn res;\n}\n\nauto solve (Board b)\n{\n\tbool doTrans = cols & 1;\n\tif (doTrans)\n\t{\n\t\tb = trans (b);\n\t\tswap (rows, cols);\n\t}\n\n\tint [2] [] res;\n\tforeach (row; 0..rows)\n\t{\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tif (!b[row][col])\n\t\t\t{\n\t\t\t\tint [2] [] cur;\n\t\t\t\tint cRow = row;\n\t\t\t\tint cCol = col;\n\t\t\t\twhile (true)\n\t\t\t\t{\n\t\t\t\t\tdebug {writefln\n\t\t\t\t\t (\"%s %s\\n%(%(%6s%)\\n%)\",\n\t\t\t\t\t cRow, cCol, b);}\n\t\t\t\t\tcur ~= [cRow, cCol];\n\t\t\t\t\tcCol += 1;\n\t\t\t\t\tif (!b[cRow][cCol])\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdebug {writefln\n\t\t\t\t\t (\"%s %s\\n%(%(%6s%)\\n%)\",\n\t\t\t\t\t cRow, cCol, b);}\n\t\t\t\t\tcur ~= [cRow, cCol];\n\t\t\t\t\tcRow += 1;\n\t\t\t\t\tif (b[cRow][cCol])\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tforeach_reverse (p; cur)\n\t\t\t\t{\n\t\t\t\t\tres ~= p;\n\t\t\t\t\tb[p[0] + 0][p[1] + 0] ^= true;\n\t\t\t\t\tb[p[0] + 0][p[1] + 1] ^= true;\n\t\t\t\t\tb[p[0] + 1][p[1] + 0] ^= true;\n\t\t\t\t\tb[p[0] + 1][p[1] + 1] ^= true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (doTrans)\n\t{\n\t\tforeach (ref p; res)\n\t\t{\n\t\t\tswap (p[0], p[1]);\n\t\t}\n\t\tswap (rows, cols);\n\t}\n\tforeach (ref p; res)\n\t{\n\t\tp[] += 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s %s\", &rows, &cols) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readConfig ();\n\t\tauto b = readConfig ();\n\t\tauto x = a.solve ();\n\t\tauto y = b.solve ();\n\t\tauto ans = chain (x, y.retro).array;\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%(%s %)\\n%)\", ans);\n\t}\n}\n"}], "negative_code": [], "src_uid": "76f314a26ac628c75e61cab6ff491342"} {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable INF = 1_000_000_000_000_000_000;\n\nint M, N;\nlong[] A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tA = new long[M];\n\t\tB = new long[N];\n\t\tforeach (i; 0 .. M) {\n\t\t\tA[i] = readLong;\n\t\t}\n\t\tforeach (j; 0 .. N) {\n\t\t\tB[j] = readLong;\n\t\t}\n\t\t\n\t\tA.sort();\n\t\tB.sort();\n\t\tlong[] ASum = new long[M + 1];\n\t\tlong[] BSum = new long[N + 1];\n\t\tforeach (i; 0 .. M) {\n\t\t\tASum[i + 1] = ASum[i] + A[i];\n\t\t}\n\t\tforeach (j; 0 .. N) {\n\t\t\tBSum[j + 1] = BSum[j] + B[j];\n\t\t}\n\t\t\n\t\tlong ans = INF;\n\t\tforeach (x; 1 .. M + 1) {\n\t\t\tif (BSum[N] > INF / x) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tchmin(ans, ASum[M - x] + x * BSum[N]);\n\t\t}\n\t\tforeach (x; 1 .. N + 1) {\n\t\t\tif (ASum[M] > INF / x) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tchmin(ans, BSum[N - x] + x * ASum[M]);\n\t\t}\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint m, n;\n\twhile (readf (\" %s %s\", &m, &n) > 0)\n\t{\n\t\tauto a = new int [m];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tauto b = new int [n];\n\t\tforeach (ref x; b)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tsort !(\"a < b\", SwapStrategy.stable) (a);\n\t\tsort !(\"a < b\", SwapStrategy.stable) (b);\n\t\tauto as = new long [m + 1];\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tas[i + 1] = as[i] + a[i];\n\t\t}\n\t\tauto bs = new long [n + 1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tbs[i + 1] = bs[i] + b[i];\n\t\t}\n\n\t\tlong res = long.max / 4;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tif (long.max / 4 / (m - i) <= bs[n])\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlong cur = (m - i) * bs[n];\n\t\t\tcur += as[i];\n\t\t\tres = min (res, cur);\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (long.max / 4 / (n - i) <= as[m])\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlong cur = (n - i) * as[m];\n\t\t\tcur += bs[i];\n\t\t\tres = min (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable INF = 1_000_000_000_000_000_000;\n\nint M, N;\nlong[] A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tA = new long[M];\n\t\tB = new long[N];\n\t\tforeach (i; 0 .. M) {\n\t\t\tA[i] = readLong;\n\t\t}\n\t\tforeach (j; 0 .. N) {\n\t\t\tB[j] = readLong;\n\t\t}\n\t\t\n\t\tA.sort();\n\t\tB.sort();\n\t\tlong[] ASum = new long[M + 1];\n\t\tlong[] BSum = new long[N + 1];\n\t\tforeach (i; 0 .. M) {\n\t\t\tASum[i + 1] = ASum[i] + A[i];\n\t\t}\n\t\tforeach (j; 0 .. N) {\n\t\t\tBSum[j + 1] = BSum[j] + B[j];\n\t\t}\n\t\t\n\t\tlong ans = INF;\n\t\tforeach (x; 1 .. M + 1) {\n\t\t\tchmin(ans, ASum[M - x] + x * BSum[N]);\n\t\t}\n\t\tforeach (x; 1 .. N + 1) {\n\t\t\tchmin(ans, BSum[N - x] + x * ASum[M]);\n\t\t}\n\t\t\n\t\t{\n\t\t\tlong now;\n\t\t\tforeach (x; 1 .. M + 1) {\n\t\t\t\tnow += A[M - x] + BSum[N] - max(A[M - x], B[N - 1]);\n\t\t\t\tchmin(ans, now + ASum[M - x]);\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tlong now;\n\t\t\tforeach (x; 1 .. N + 1) {\n\t\t\t\tnow += B[N - x] + ASum[M] - max(B[N - x], A[M - 1]);\n\t\t\t\tchmin(ans, now + BSum[N - x]);\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable INF = 1_000_000_000_000_000_000;\n\nint M, N;\nlong[] A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tA = new long[M];\n\t\tB = new long[N];\n\t\tforeach (i; 0 .. M) {\n\t\t\tA[i] = readLong;\n\t\t}\n\t\tforeach (j; 0 .. N) {\n\t\t\tB[j] = readLong;\n\t\t}\n\t\t\n\t\tA.sort();\n\t\tB.sort();\n\t\tlong[] ASum = new long[M + 1];\n\t\tlong[] BSum = new long[N + 1];\n\t\tforeach (i; 0 .. M) {\n\t\t\tASum[i + 1] = ASum[i] + A[i];\n\t\t}\n\t\tforeach (j; 0 .. N) {\n\t\t\tBSum[j + 1] = BSum[j] + B[j];\n\t\t}\n\t\t\n\t\tlong ans = INF;\n\t\tforeach (x; 1 .. M + 1) {\n\t\t\tchmin(ans, x * ASum[M - x] + x * BSum[N]);\n\t\t}\n\t\tforeach (x; 1 .. N + 1) {\n\t\t\tchmin(ans, x * BSum[N - x] + x * ASum[M]);\n\t\t}\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "src_uid": "f56597c8c3d17d73b8ede2d81fe5cbe7"} {"source_code": "import std.stdio, std.string;\r\nimport std.conv, std.array;\r\nimport std.math, std.algorithm;\r\n \r\nint main(string[] args)\r\n{\r\n auto t = to!int(readln.strip);\r\n foreach (_; 0 .. t)\r\n {\r\n auto n = to!int(readln.strip);\r\n auto left = 1, right = n;\r\n while (left < right)\r\n {\r\n auto mid = (left + right) >> 1;\r\n writeln(\"? \", left, \" \", mid);\r\n stdout.flush;\r\n auto r = map!(to!int)(readln.strip.split(\" \")).array;\r\n int c, i, j = left;\r\n while (i < r.length && j <= mid)\r\n {\r\n if (r[i] < j) ++ i;\r\n else if (r[i] > j) j = r[i];\r\n else ++ i, ++ j, ++ c;\r\n }\r\n if (c & 1) right = mid;\r\n else left = mid + 1;\r\n }\r\n writeln(\"! \", left);\r\n stdout.flush;\r\n }\r\n return 0;\r\n}", "positive_code": [{"source_code": "import std.typecons;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.functional;\n\nalias ll = ulong;\nvoid solve()\n{\n int[][Tuple!(immutable ll, immutable ll)] mp;\n auto get = (immutable ll l, immutable ll r) {\n auto tup = tuple(l, r);\n if (auto val = tup in mp)\n return *val;\n writefln!(\"? %s %s\")(l, r);\n stdout.flush;\n return mp[tup] = readln.splitter.map!(to!int).array;\n };\n\n ll n;\n readf!(\" %s\")(n);\n readln;\n ll l = 1, r = n;\n while (l <= r)\n {\n ll mid = (l + r) / 2;\n auto swaps = get(l, mid).count!(x => l <= x && x <= mid);\n if (swaps % 2 == 0)\n l = mid + 1;\n else\n r = mid - 1;\n }\n writefln!(\"! %s\")(l);\n stdout.flush;\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n solve();\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nalias ll = ulong;\nvoid solve()\n{\n auto get = (ll l, ll r) {\n writefln!(\"? %s %s\")(l, r);\n stdout.flush;\n return readln.splitter.map!(to!int);\n };\n\n ll n;\n readf!(\" %s\")(n);\n readln;\n ll l = 1, r = n;\n while (l <= r)\n {\n ll mid = (l + r) / 2;\n auto swaps = get(l, mid).count!(x => l <= x && x <= mid);\n if (swaps % 2 == 0)\n l = mid + 1;\n else\n r = mid - 1;\n }\n writefln!(\"! %s\")(l);\n stdout.flush;\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n solve();\n}\n"}, {"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nint[] ask(int l, int r) {\r\n writefln(\"? %s %s\", l, r);\r\n stdout.flush;\r\n return readln.chomp.split(\" \").map!(to!int).array;\r\n}\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n\r\n int f(int l, int r) {\r\n if (l == r) return l;\r\n int[] xs = ask(l, (l+r)/2);\r\n int R = 0;\r\n foreach (i, x; xs) {\r\n if (l <= x && x <= (l+r)/2) {\r\n R++;\r\n }\r\n }\r\n //stderr.writefln(\"(%s, %s) -> %s\", l, r, R);\r\n if (R % 2 == 1) {\r\n r = (l + r) / 2;\r\n } else {\r\n l = (l + r) / 2 + 1;\r\n }\r\n return f(l, r);\r\n }\r\n\r\n int ans = f(1, N);\r\n writefln(\"! %s\", ans);\r\n stdout.flush;\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tint lo = 1;\r\n\t\tint hi = n + 1;\r\n\t\twhile (hi - lo > 1)\r\n\t\t{\r\n\t\t\tint me = (lo + hi) / 2;\r\n\t\t\twritefln !(\"? %s %s\") (lo, me - 1);\r\n\t\t\tstdout.flush ();\r\n\t\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\t\tauto num = a.count !(x => lo <= x && x <= me - 1);\r\n\t\t\tif (num % 2 == 0)\r\n\t\t\t{\r\n\t\t\t\tlo = me;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\thi = me;\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"! %s\") (lo);\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.functional;\n\nalias ll = ulong;\nvoid solve()\n{\n auto get_ = (ll l, ll r) {\n writefln!(\"? %s %s\")(l, r);\n stdout.flush;\n return readln.splitter.map!(to!int);\n };\n alias get = memoize!get_;\n ll n;\n readf!(\" %s\")(n);\n readln;\n ll l = 1, r = n;\n while (l <= r)\n {\n ll mid = (l + r) / 2;\n auto swaps = get(l, mid).count!(x => l <= x && x <= mid);\n if (swaps % 2 == 0)\n l = mid + 1;\n else\n r = mid - 1;\n }\n writefln!(\"! %s\")(l);\n stdout.flush;\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n solve();\n}\n"}], "src_uid": "0942e9cbce56ff3becd03d8e34962bf3"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto coins = readln.chomp.split.map!(to!int).array;\n \n int[40] vals;\n coins.each!(e => ++vals[bsr(e)]);\n \n debug { vals.writeln; }\n \n int getAnsForBit(int b, int need, ref int[] vals) {\n int ans = 0;\n if (b == -1) return -1;\n\n auto saved = min(need, vals[b]);\n need -= saved;\n vals[b] -= saved;\n ans += saved;\n\n if (need > 0) {\n auto borrow = getAnsForBit(b-1, 2 * need, vals);\n if (borrow == -1) return -1;\n\n ans += borrow;\n }\n \n return ans;\n }\n \n while (q--) {\n uint x;\n readf(\"%s\", &x);\n readln;\n \n auto ans = 0;\n auto nowvals = vals.dup;\n foreach_reverse (b; 0 .. 32) {\n if (x & (1U << b)) {\n auto cur = getAnsForBit(b, 1, nowvals);\n if (cur == -1) {\n ans = -1;\n break;\n }\n \n ans += cur;\n }\n }\n \n ans.writeln;\n }\n \n}", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto coins = readln.chomp.split.map!(to!int).array;\n \n int[40] vals;\n coins.each!(e => ++vals[bsr(e)]);\n \n debug { vals.writeln; }\n \n while (q--) {\n uint x;\n readf(\"%s\", &x);\n readln;\n \n auto ans = 0;\n auto nowvals = vals.dup;\n foreach_reverse (b; 0 .. 32) {\n if (x & (1U << b)) {\n \n int getAns(int b, int need) {\n int ans = 0;\n if (b == -1) return -1;\n \n auto saved = min(need, nowvals[b]);\n need -= saved;\n nowvals[b] -= saved;\n ans += saved;\n \n if (need > 0) {\n auto borrow = getAns(b-1, 2 * need);\n if (borrow == -1) return -1;\n \n ans += borrow;\n }\n \n return ans;\n }\n \n auto cur = getAns(b, 1);\n if (cur == -1) {\n ans = -1;\n break;\n }\n \n ans += cur;\n }\n }\n \n ans.writeln;\n }\n \n}"}], "negative_code": [], "src_uid": "a5c38d4842d3d4652cd79dd9715c138d"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto a = readInt!int;\n\tauto b = readInt!int;\n\tauto pk = new bool[](a + b + 1);\n\tvoid tryPair(int c0, int c1)\n\t{\n\t\tforeach(bi0; 0 .. c0+1)\n\t\t{\n\t\t\tauto bi1 = b - bi0;\n\t\t\tif (bi1 < 0 || bi1 > c1) continue;\n\t\t\tint breaks = bi0 + (c1 - bi1);\n\t\t\tpk[breaks] = true; \n\t\t}\n\t}\n\tauto m1 = (a+b)/2;\n\tauto m2 = (a+b) - m1;\n\ttryPair(m1, m2);\n\ttryPair(m2, m1);\n\tauto ks = new int[](0);\n\tforeach(k, hk; pk)\n\t\tif (hk) ks ~= cast(int)k;\n\tks.length.writeln;\n\tforeach(k; ks) write(k, \" \");\n\twriteln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint a, b;\r\n\t\treadf !(\" %s %s\") (a, b);\r\n\t\tauto n = a + b;\r\n\t\tauto h = n / 2;\r\n\t\tauto g = n - h;\r\n\t\tauto s = new bool [a + b + 1];\r\n\t\tforeach (k; 0..2)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i <= min (a, g); i++)\r\n\t\t\t{\r\n\t\t\t\tauto ag = i;\r\n\t\t\t\tauto ah = a - ag;\r\n\t\t\t\tauto bg = g - ag;\r\n\t\t\t\tauto bh = b - bg;\r\n\t\t\t\tif (0 <= ag && ag <= a && ag <= g &&\r\n\t\t\t\t 0 <= ah && ah <= a && ah <= h &&\r\n\t\t\t\t 0 <= bg && bg <= b && bg <= g &&\r\n\t\t\t\t 0 <= bh && bh <= b && bh <= h)\r\n\t\t\t\t{\r\n\t\t\t\t\ts[ah + bg] = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tswap (g, h);\r\n\t\t}\r\n\t\twriteln (s.sum);\r\n\t\twritefln !(\"%(%s %)\") (iota (a + b + 1).filter !(x => s[x]));\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const A = readInt();\n const B = readInt();\n \n int[] ans;\n foreach (s; 0 .. 2) {\n const a = (A + B + s) / 2;\n const b = (A + B + (1 - s)) / 2;\n foreach (x; 0 .. a + 1) {\n if (x <= A) {\n const y = B - (a - x);\n if (y >= 0) {\n ans ~= A + B - x - y;\n }\n }\n }\n }\n \n ans = ans.sort.uniq.array;\n writeln(ans.length);\n foreach (i; 0 .. cast(int)(ans.length)) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto a = RD!int;\r\n\t\tauto b = RD!int;\r\n\t\tif (a < b)\r\n\t\t\tswap(a, b);\r\n\r\n\t\tauto n = a + b;\r\n\t\tbool[int] set;\r\n\t\t{\r\n\t\t\tauto m = (n+1) / 2;\r\n\t\t\tauto x = a - m;\r\n\t\t\tset[x] = true;\r\n\t\t\tforeach (i; 0..max(b-x, min(a, b)))\r\n\t\t\t{\r\n\t\t\t\tx += 2;\r\n\t\t\t\tset[x] = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\t{\r\n\t\t\tauto m = n / 2;\r\n\t\t\tauto x = a - m;\r\n\t\t\tset[x] = true;\r\n\t\t\tforeach (i; 0..max(b-x, min(a, b)))\r\n\t\t\t{\r\n\t\t\t\tx += 2;\r\n\t\t\t\tset[x] = true;\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (key; set.keys.sort)\r\n\t\t\tans[ti] ~= key;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e.length);\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid solve(int a, int b, ref bool[int] possible_k)\n{\n int n = a + b;\n foreach (ah ; 0 .. (n + 1) / 2 + 1) {\n int ab = a - ah;\n if (ab < 0)\n break;\n int bh = n / 2 - ab;\n if (bh < 0)\n continue;\n int bb = b - bh;\n if (bb < 0)\n continue;\n int k = ab + bb;\n if (k < 0)\n continue;\n possible_k[k] = true;\n }\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int a, b;\n readf!\" %d %d \"(a, b);\n bool[int] possible_k;\n solve(a, b, possible_k);\n solve(b, a, possible_k);\n writeln(possible_k.length);\n writeln(possible_k.byKey.array.sort.map!text.joiner(\" \"));\n }\n}\n"}], "negative_code": [], "src_uid": "04a37e9c68761f9a2588c0bbecad2147"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt;\n }\n \n int ans = 1;\n foreach (i; 0 .. N) foreach (j; i + 1 .. N) {\n int cnt;\n foreach (k; 0 .. N) {\n if ((j - i) * (A[k] - A[i]) == (k - i) * (A[j] - A[i])) {\n ++cnt;\n }\n }\n chmax(ans, cnt);\n }\n \n writeln(N - ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n readln;\n\n immutable vec =\n readln.chomp\n .split(' ')\n .to!(int[]);\n\n immutable longestProgressionLength = (){\n ubyte ret = 1;\n foreach (start; 0 .. vec.length)\n foreach (step; 1 .. vec.length - start) {\n immutable strive = vec[start + step] - vec[start];\n immutable nowLength = iota(start, vec.length, 1)\n .count!((ind) => (vec[ind] - vec[start]) * step == strive * (ind - start));\n ret = cast(ubyte)max(ret, nowLength);\n }\n return ret;\n }();\n\n (\n vec.length\n - longestProgressionLength\n ).writeln;\n }\n}\n// \"\"\n"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n readln;\n\n immutable vec =\n readln.chomp\n .split(' ')\n .to!(int[]);\n\n immutable longestProgressionLength = (){\n ubyte ret = 1;\n foreach (start; 0 .. vec.length)\n foreach (step; 1 .. vec.length - start) {\n immutable strive = vec[start + step] - vec[start];\n immutable nowLength = iota(0, vec.length, 1)\n .count!((ind) => (vec[ind] - vec[start]) * step == strive * (ind - start));\n ret = cast(ubyte)max(ret, nowLength);\n }\n return ret;\n }();\n\n (\n vec.length\n - longestProgressionLength\n ).writeln;\n }\n}\n// \"\"\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nvoid solve() {\r\n int N; readf(\"%d\\n\", &N);\r\n auto A = readln.chomp.split(\" \").map!(to!double).array;\r\n\r\n auto f(int j, int k) {\r\n int c = 0;\r\n auto d = (A[k] - A[j]) / (k - j);\r\n auto b0 = A[j] - d * j;\r\n for (int i = 0; i < N; i++) {\r\n auto b = b0 + i * d;\r\n if (! isClose(A[i], b, 1e-9)) c++;\r\n }\r\n return c;\r\n }\r\n \r\n int ans = int.max;\r\n if (N <= 2) {\r\n ans = 0;\r\n }\r\n for (int j = 0; j < N; j++) {\r\n for (int k = j + 1; k < N; k++) {\r\n ans = min(ans, f(j, k));\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T; readf(\"%d\\n\", &T);\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}, {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!real(N);\r\n\r\n int ans = N - 1;\r\n foreach(i; 0..N - 1) foreach(j; i+1..N) {\r\n real d = A[j] - A[i] == 0 ? 0 : (A[j] - A[i]) / (j - i);\r\n real t = A[i] - d*i;\r\n int tans = N;\r\n foreach(x; 0..N) {\r\n if (t.approxEqual(A[x], 1e-04, 1e-04)) tans--;\r\n t += d;\r\n }\r\n ans = min(ans, tans);\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n foreach(_; 0..QN) subSolve().writeln;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint res = n - (n == 1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n)\r\n\t\t\t{\r\n\t\t\t\tauto num = a[j] - a[i];\r\n\t\t\t\tauto den = j - i;\r\n\t\t\t\tint cur = 0;\r\n\t\t\t\tforeach (k; 0..n)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto value = num * (k - i);\r\n\t\t\t\t\tcur += (a[k] - a[i]) * den != value;\r\n\t\t\t\t}\r\n\t\t\t\tres = min (res, cur);\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n readln;\n\n immutable vec =\n readln.chomp\n .split(' ')\n .to!(int[]);\n\n immutable longestProgressionLength = (){\n ubyte ret = 1;\n foreach (start; 0 .. vec.length)\n foreach (step; 1 .. vec.length - start) {\n immutable strive = vec[start + step] - vec[start];\n immutable nowLength = iota(start, vec.length, step)\n .count!((ind) => (vec[ind] - vec[start]) * step == strive * (ind - start));\n ret = cast(ubyte)max(ret, nowLength);\n }\n return ret;\n }();\n\n (\n vec.length\n - longestProgressionLength\n ).writeln;\n }\n}\n// \"\"\n"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n readln;\n\n immutable vec =\n readln.chomp\n .split(' ')\n .to!(byte[]);\n\n immutable longestProgressionLength = (){\n ubyte ret = 1;\n foreach (start; 0 .. vec.length)\n foreach (step; 1 .. vec.length - start) {\n immutable strive = vec[start + step] - vec[start];\n immutable nowLength = iota(start, vec.length, step)\n .count!((ind) => (vec[ind] - vec[start]) * step == strive * (ind - start));\n ret = cast(ubyte)max(ret, nowLength);\n }\n return ret;\n }();\n\n (\n vec.length\n - longestProgressionLength\n ).writeln;\n }\n}\n// \"\"\n"}], "src_uid": "6aca8c549822adbe96a58aee4b0d4b3f"} {"source_code": "import std.stdio;\nimport std.exception;\nimport std.algorithm;\nimport std.math;\nimport std.typecons;\n\nvoid main(){\n\tint n;\n\tstring a, b;\n\treadf(\"%d\\n%s\\n%s\\n\", &n, &a, &b);\n\tint x1=0, q=0, y1=0;\n\tforeach(i; 0..2*n){\n\t\tif (a[i]=='1' && b[i]=='1') q++;\n\t\telse if (a[i]=='1') x1++;\n\t\telse if (b[i]=='1') y1++;\n\t}\n\tint ans1=q/2+q%2, ans2=q/2;\n\tif (ans1!=ans2){\n\t\tif (x1>y1){\n\t\t\tans2+=y1;\n ans1+=y1;\n x1-=y1;\n ans1+=x1/2;\n }\n else{\n ans1+=x1;\n ans2+=x1;\n y1-=x1;\n ans2+=y1/2+y1%2;\n }\n }\n else{\n if (x1>y1){\n ans2+=y1;\n ans1+=y1;\n x1-=y1;\n ans1+=x1/2+x1%2;\n }\n else{\n ans1+=x1;\n ans2+=x1;\n y1-=x1;\n ans2+=y1/2;\n }\n }\n if (ans1>ans2) writefln(\"First\");\n else if (ans1<ans2) writefln(\"Second\");\n else writefln(\"Draw\");\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.exception;\nimport std.algorithm;\nimport std.math;\nimport std.typecons;\n\nvoid main(){\n int n;\n string a, b;\n readf(\"%d\\n%s\\n%s\\n\", &n, &a, &b);\n int x1=0, q=0, y1=0;\n foreach(i; 0..2*n){\n if (a[i]=='1' && b[i]=='1') q++;\n else if (a[i]=='1') x1++;\n else if (b[i]=='1') y1++;\n }\n int ans1=q/2+q%2, ans2=q/2;\n if (ans1!=ans2){\n if (x1>y1){\n ans2+=y1;\n ans1+=y1;\n x1-=y1;\n ans1+=x1/2;\n }\n else{\n ans1+=x1;\n ans2+=x1;\n y1-=x1;\n ans2+=y1/2+y1%2;\n }\n }\n else{\n if (x1>y1){\n ans2+=y1;\n ans1+=y1;\n x1-=y1;\n ans1+=x1/2+x1%2;\n }\n else{\n ans1+=x1;\n ans2+=x1;\n y1-=x1;\n ans2+=y1/2;\n }\n }\n if (ans1>ans2) writefln(\"First\");\n else if (ans1<ans2) writefln(\"Second\");\n else writefln(\"Draw\");\n}"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tauto s = readln ().strip ();\n\t\tauto t = readln ().strip ();\n\t\tauto a = new int [4];\n\t\tforeach (i; 0..2 * n)\n\t\t{\n\t\t\ta[(s[i] == '1') + ((t[i] == '1') << 1)]++;\n\t\t}\n\t\tdebug {writeln (a);}\n\n\t\tauto b = new int [2];\n\t\tforeach (i; 0..2 * n)\n\t\t{\n\t\t\tint p = i & 1;\n\t\t\tint bj = -1, bv = -3;\n\t\t\tforeach (j; 0..4)\n\t\t\t{\n\t\t\t\tif (a[j] == 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint v = ((j >> p) & 1) + ((j >> !p) & 1);\n\t\t\t\tif (bv < v)\n\t\t\t\t{\n\t\t\t\t\tbv = v;\n\t\t\t\t\tbj = j;\n\t\t\t\t}\n\t\t\t}\n\t\t\tassert (bj != -1);\n\t\t\ta[bj]--;\n\t\t\tb[p] += (bj >> p) & 1;\n\t\t}\n\n\t\tdebug {writeln (b);}\n\t\twriteln (b[0] < b[1] ? \"Second\" :\n\t\t (b[0] == b[1] ? \"Draw\" : \"First\"));\n\t}\n}\n"}], "negative_code": [], "src_uid": "6f52388b652a900e63ec39406225392c"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable int INF = 1 << 29;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto X = (1L << K) - 1;\n auto A = readln.split.map!(to!long).array;\n\n long ans = 0;\n long tmp = 0;\n long[long] cnt;\n cnt[0] = 1;\n\n long f(long x) {\n if (x !in cnt) return 0;\n else return cnt[x];\n }\n\n foreach (i; 0..N) {\n long a = tmp ^ A[i];\n long b = a ^ X;\n if (f(a) <= f(b)) {\n ans += f(a);\n cnt[a] += 1;\n tmp = a;\n } else {\n ans += f(b);\n cnt[b] += 1;\n tmp = b;\n }\n }\n\n ans = N.to!long * (N.to!long + 1) / 2 - ans;\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto m = (1 << k) - 1;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\ta[i] ^= a[i - 1];\n\t\t}\n\n\t\tint [int] v;\n\t\tv[0] = 1;\n\t\tlong res = 0;\n\t\tforeach (ref c0; a)\n\t\t{\n\t\t\tauto c1 = c0 ^ m;\n\t\t\tauto one = v.get (c0, 0);\n\t\t\tauto two = v.get (c1, 0);\n\t\t\tif (one < two)\n\t\t\t{\n\t\t\t\tres += one;\n\t\t\t\tv[c0] += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres += two;\n\t\t\t\tv[c1] += 1;\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (v);}\n\t\twriteln (n * (n + 1L) / 2 - res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto m = (1 << k) - 1;\n\n\t\tint [int] v;\n\t\tlong res = 0;\n\t\tforeach (ref c0; a)\n\t\t{\n\t\t\tauto c1 = c0 ^ m;\n\t\t\tauto one = v.get (c0, 0) + (c0 == 0);\n\t\t\tauto two = v.get (c1, 0) + (c1 == 0);\n\t\t\tif (one < two)\n\t\t\t{\n\t\t\t\tres += one;\n\t\t\t\tv[c0] += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres += two;\n\t\t\t\tv[c1] += 1;\n\t\t\t}\n\t\t}\n\t\twriteln (n * (n + 1L) / 2 - res);\n\t}\n}\n"}], "src_uid": "71ad4b2e9e888933e55425e73a0d68b5"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int infinity = int.max / 2;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto t = readln.strip;\n\t\tauto k = s.length.to !(int);\n\t\tauto n = t.length.to !(int);\n\n\t\tauto p = new int [k];\n\t\tp[] = NA;\n\t\tint [] stack;\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tif (s[j] == '.')\n\t\t\t{\n\t\t\t\tif (!stack.empty)\n\t\t\t\t{\n\t\t\t\t\tp[j] = stack.back;\n\t\t\t\t\tstack.popBack ();\n\t\t\t\t\tstack.assumeSafeAppend ();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstack ~= j;\n\t\t\t}\n\t\t}\n\n\t\tauto f = new int [] [] (2, k + 1);\n\t\tint b = 0;\n\t\tf[b][0] = 0;\n\t\tforeach (j; 1..k + 1)\n\t\t{\n\t\t\tf[b][j] = f[b][j - 1] + 1;\n\t\t\tif (p[j - 1] != NA)\n\t\t\t{\n\t\t\t\tf[b][j] = min (f[b][j], f[b][p[j - 1]]);\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tf[b][] = infinity;\n\t\t\tforeach (j; i + 1..k + 1)\n\t\t\t{\n\t\t\t\tf[b][j] = f[b][j - 1] + 1;\n\t\t\t\tif (t[i] == s[j - 1])\n\t\t\t\t{\n\t\t\t\t\tf[b][j] = min (f[b][j], f[!b][j - 1]);\n\t\t\t\t}\n\t\t\t\tif (p[j - 1] != NA)\n\t\t\t\t{\n\t\t\t\t\tf[b][j] = min (f[b][j], f[b][p[j - 1]]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (f[b][k]);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int infinity = int.max / 2;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto t = readln.strip;\n\t\tauto k = s.length.to !(int);\n\t\tauto n = t.length.to !(int);\n\n\t\tauto p = new int [k];\n\t\tp[] = NA;\n\t\tint [] stack;\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tif (s[j] == '.')\n\t\t\t{\n\t\t\t\tif (!stack.empty)\n\t\t\t\t{\n\t\t\t\t\tp[j] = stack.back;\n\t\t\t\t\tstack.popBack ();\n\t\t\t\t\tstack.assumeSafeAppend ();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstack ~= j;\n\t\t\t}\n\t\t}\n\n\t\tauto f = new int [] [] (2, k + 1);\n\t\tint b = 0;\n\t\tf[b][0] = 0;\n\t\tforeach (j; 1..k + 1)\n\t\t{\n\t\t\tf[b][j] = f[b][j - 1] + 1;\n\t\t\tif (p[j - 1] != NA)\n\t\t\t{\n\t\t\t\tf[b][j] = min (f[b][j], f[b][p[j - 1]]);\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tf[b][] = infinity;\n\t\t\tforeach (j; i + 1..k + 1)\n\t\t\t{\n\t\t\t\tf[b][j] = f[b][j - 1] + 1;\n\t\t\t\tif (t[i] == s[j - 1])\n\t\t\t\t{\n\t\t\t\t\tf[b][j] = min (f[b][j], f[!b][j - 1]);\n\t\t\t\t}\n\t\t\t\tif (p[j - 1] != NA)\n\t\t\t\t{\n\t\t\t\t\tf[b][j] = min (f[b][j], f[b][p[j - 1]]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (f[b][k]);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int infinity = int.max / 2;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto t = readln.strip;\n\t\tauto k = s.length.to !(int);\n\t\tauto n = t.length.to !(int);\n\n\t\tauto p = new int [k];\n\t\tp[] = NA;\n\t\tint [] stack;\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tif (s[j] == '.')\n\t\t\t{\n\t\t\t\tif (!stack.empty)\n\t\t\t\t{\n\t\t\t\t\tp[j] = stack.back;\n\t\t\t\t\tstack.popBack ();\n\t\t\t\t\tstack.assumeSafeAppend ();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstack ~= j;\n\t\t\t}\n\t\t}\n\n\t\tauto f = new int [] [] (2, k + 1);\n\t\tint b = 0;\n\t\tf[b] = iota (k + 1).array;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tf[b][] = infinity;\n\t\t\tforeach (j; i + 1..k + 1)\n\t\t\t{\n\t\t\t\tf[b][j] = f[b][j - 1] + 1;\n\t\t\t\tif (t[i] == s[j - 1])\n\t\t\t\t{\n\t\t\t\t\tf[b][j] = min (f[b][j], f[!b][j - 1]);\n\t\t\t\t}\n\t\t\t\tif (p[j - 1] != NA)\n\t\t\t\t{\n\t\t\t\t\tf[b][j] = min (f[b][j], f[b][p[j - 1]]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (f[b][k]);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int infinity = int.max / 2;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto t = readln.strip;\n\t\tauto k = s.length.to !(int);\n\t\tauto n = t.length.to !(int);\n\n\t\tauto p = new int [k];\n\t\tint [] stack;\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tif (s[j] == '.')\n\t\t\t{\n\t\t\t\tif (!stack.empty)\n\t\t\t\t{\n\t\t\t\t\tp[j] = stack.back;\n\t\t\t\t\tstack.popBack ();\n\t\t\t\t\tstack.assumeSafeAppend ();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstack ~= j;\n\t\t\t}\n\t\t}\n\n\t\tauto f = new int [] [] (2, k + 1);\n\t\tint b = 0;\n\t\tf[b] = iota (k + 1).array;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tf[b][] = infinity;\n\t\t\tforeach (j; i + 1..k + 1)\n\t\t\t{\n\t\t\t\tf[b][j] = f[b][j - 1] + 1;\n\t\t\t\tif (t[i] == s[j - 1])\n\t\t\t\t{\n\t\t\t\t\tf[b][j] = min (f[b][j], f[!b][j - 1]);\n\t\t\t\t}\n\t\t\t\tif (p[j - 1] != NA)\n\t\t\t\t{\n\t\t\t\t\tf[b][j] = min (f[b][j], f[b][p[j - 1]]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (f[b][k]);\n\t}\n}\n"}], "src_uid": "db68137f8ba1d7e2cd1ebe8cb7dd3e22"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\tint k;\n\treadf (\" %s %s\", &n, &k);\n\treadln;\n\tauto a = readln.strip.map !(c => c == '0').array;\n\n\tint p = -1;\n\tauto b = new int [n];\n\tforeach (i; 0..n)\n\t{\n\t\tif (a[i])\n\t\t{\n\t\t\tp = i;\n\t\t}\n\t\tb[i] = p;\n\t}\n\n\tbool check (int step)\n\t{\n\t\tint pos = 0;\n\t\tforeach (i; 1..k)\n\t\t{\n\t\t\tint next = pos + step + 1;\n\t\t\tnext = min (next, n - 1);\n\t\t\tnext = b[next];\n\t\t\tpos = next;\n\t\t}\n\t\treturn pos == n - 1;\n\t}\n\n\tint lo = 0;\n\tint hi = n;\n\twhile (lo < hi)\n\t{\n\t\tint me = (lo + hi) >> 1;\n\t\tif (check (me))\n\t\t{\n\t\t\thi = me;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlo = me + 1;\n\t\t}\n\t}\n\twriteln (lo);\n}\n", "positive_code": [{"source_code": "module main;\nimport std.c.stdio;\n\nchar [] arr;\nint n, k;\n\nbool Go(int m) {\n if (m == 0)\n return false;\n int have = k - 2;\n int prv = 0;\n int nxt = 0;\n for (int i = 1; i < n - 1; ++i) {\n if (arr[i] == '0')\n nxt = i;\n if (i == prv + m) {\n if (nxt > prv) {\n prv = nxt;\n have--;\n if (have < 0)\n return false;\n }\n else\n return false;\n }\n }\n return true;\n}\n\nint main(string[] argv)\n{\n\tscanf(\"%d %d\\n\", &n, &k);\n\tarr = new char[n + 10];\n\tfor(int i = 0; i < n; i++)\n\t\tscanf(\"%c\", &arr[i]);\n\tint L = 0, R = n + 1;\n\twhile (R - L > 1) {\n\t int M = (L + R) / 2;\n\t if (Go(M))\n\t R = M;\n\t else\n\t L = M;\n\t}\n\tprintf(\"%i\", R - 1);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "e33b0a752dc1aba25da21e20435e3fe2"} {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] us;\n\t\n\tforeach(i; 0 .. n) us ~= read.to!int - 1;\n\t\n\tint bestx = 1;\n\tint minc, maxc;\n\tint[] ucnt = new int[](100_009);\n\tint[] ccnt = new int[](100_009);\n\tint allccnt;\n\tforeach(i; 0 .. n){\n\t\tint u = us[i];\n\t\tint c = ucnt[u];\n\t\tif(c > 0) ccnt[c] -= 1;\n\t\tif(c == minc && ccnt[c] == 0) minc += 1;\n\t\tucnt[u] += 1;\n\t\tc = ucnt[u];\n\t\tccnt[c] += 1;\n\t\tif(c == 1) minc = 1, allccnt += 1;\n\t\tif(c > maxc) maxc = c;\n\t\t\n\t\tif(minc == 1 && ccnt[minc] == 1 && ccnt[minc] + ccnt[maxc] == allccnt) bestx = i + 1;\n\t\tif(minc == maxc - 1 && ccnt[maxc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && ccnt[minc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && minc == 1 && ccnt[minc] > 1) bestx = i + 1;\n\t\t\n\t}\n\t\n\tbestx.writeln;\n\t\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main(){\n auto N = readln.chomp.to!(int);\n auto A = readln.split.map!(x => x.to!(int)-1).array;\n const int M = 10^^5;\n\n auto cnt = new int[](M);\n auto cnt2 = new int[](M+10);\n cnt2[0] = M;\n int ans = 0;\n int day = 0;\n auto rbt = new RedBlackTree!int();\n\n foreach (a; A) {\n day += 1;\n cnt2[cnt[a]] -= 1;\n cnt[a] += 1;\n cnt2[cnt[a]] += 1;\n if (cnt2[cnt[a]-1] == 0 && cnt[a] != 1) rbt.removeKey(cnt[a]-1);\n if (cnt2[cnt[a]] == 1) rbt.insert(cnt[a]);\n if (rbt.length == 1 && rbt.front == day) {\n ans = day;\n } else if (rbt.length == 1 && rbt.front == 1) {\n ans = day;\n } else if (rbt.length == 2) {\n if (cnt2[rbt.front] == 1 && rbt.front == 1) {\n ans = day;\n } else if (cnt2[rbt.back] == 1 && rbt.back == 1) {\n ans = day;\n } else if (rbt.back - rbt.front == 1 && cnt2[rbt.back] == 1) {\n ans = day;\n }\n }\n }\n\n ans.writeln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main(){\n auto N = readln.chomp.to!(int);\n auto A = readln.split.map!(x => x.to!(int)-1).array;\n const int M = 10^^5;\n\n auto cnt = new int[](M);\n auto cnt2 = new int[](M+10);\n cnt2[0] = M;\n int ans = 0;\n int day = 0;\n auto rbt = new RedBlackTree!int();\n\n foreach (a; A) {\n day += 1;\n cnt2[cnt[a]] -= 1;\n cnt[a] += 1;\n cnt2[cnt[a]] += 1;\n if (cnt2[cnt[a]-1] == 0 && cnt[a] != 1) rbt.removeKey(cnt[a]-1);\n if (cnt2[cnt[a]] == 1) rbt.insert(cnt[a]);\n if (rbt.length == 1 && rbt.front == 1) {\n ans = day;\n } else if (rbt.length == 2) {\n if (cnt2[rbt.front] == 1 && rbt.front == 1) {\n ans = day;\n } else if (cnt2[rbt.back] == 1 && rbt.back == 1) {\n ans = day;\n } else if (rbt.back - rbt.front == 1 && cnt2[rbt.back] == 1) {\n ans = day;\n }\n }\n }\n\n ans.writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] us;\n\t\n\tforeach(i; 0 .. n) us ~= read.to!int - 1;\n\t\n\tint bestx = 1;\n\tint minc, maxc;\n\tint[] ucnt = new int[](100_009);\n\tint[] ccnt = new int[](100_009);\n\tforeach(i; 0 .. n){\n\t\tint u = us[i];\n\t\tint c = ucnt[u];\n\t\tif(c > 0) ccnt[c] -= 1;\n\t\tif(c == minc && ccnt[c] == 0) minc += 1;\n\t\tucnt[u] += 1;\n\t\tc = ucnt[u];\n\t\tccnt[c] += 1;\n\t\tif(c > maxc) maxc = c;\n\t\t\n\t\tif(minc == 1 && ccnt[minc] == 1) bestx = i + 1;\n\t\tif(minc == maxc - 1 && ccnt[maxc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && ccnt[minc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && minc == 1 && ccnt[minc] > 1) bestx = i + 1;\n\t\t\n\t}\n\t\n\tbestx.writeln;\n\t\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] us;\n\t\n\tforeach(i; 0 .. n) us ~= read.to!int - 1;\n\t\n\tint bestx = 1;\n\tint minc, maxc;\n\tint[] ucnt = new int[](100_009);\n\tint[] ccnt = new int[](100_009);\n\tforeach(i; 0 .. n){\n\t\tint u = us[i];\n\t\tint c = ucnt[u];\n\t\tif(c > 0) ccnt[c] -= 1;\n\t\tif(c == minc && ccnt[c] == 0) minc += 1;\n\t\tucnt[u] += 1;\n\t\tc = ucnt[u];\n\t\tccnt[c] += 1;\n\t\tif(c == 1) minc = 1;\n\t\tif(c > maxc) maxc = c;\n\t\t\n\t\tif(minc == 1 && ccnt[minc] == 1) bestx = i + 1;\n\t\tif(minc == maxc - 1 && ccnt[maxc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && ccnt[minc] == 1) bestx = i + 1;\n\t\tif(minc == maxc && minc == 1 && ccnt[minc] > 1) bestx = i + 1;\n\t\t\n\t}\n\t\n\tbestx.writeln;\n\t\n}\n\n"}], "src_uid": "886d8d7103f0a7403b06b80b914ee498"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const A = readToken();\n writeln(A ~ A.dup.reverse);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\twriteln (s, s.retro);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm.mutation;\n\nvoid main() {\n\tstring a; // = readln();\n\treadf!\"%s\\n\"(a);\n\n\twrite(a);\n\n\tfor (int i=a.length-1; i>=0; i--)\n\t\twrite(a[i]);\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm.mutation;\n\nvoid main() {\n\tstring a; // = readln();\n\treadf!\"%s\"(a);\n\n\twrite(a);\n\n\tfor (int i=a.length-1; i>=0; i--)\n\t\twrite(a[i]);\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.mutation;\n\nvoid main() {\n\tstring a = readln();\n\n\twrite(a);\n\n\tfor (int i=a.length-1; i>=0; i--)\n\t\twrite(a[i]);\n}"}], "src_uid": "9b1887582a9eb7cff49994ddcc2ee9b8"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nstruct Dsu\n{\n int[] size;\n int[] directParent;\n int noSets;\n static Dsu makeEmpty(int noElements)\n {\n Dsu dsu;\n with(dsu)\n {\n\tsize = new int[](noElements); size[] = 1;\n\tdirectParent = new int[](noElements); foreach(i; 0 .. noElements) directParent[i] = i;\n\tnoSets = noElements;\n }\n return dsu;\n }\n int rep(int n)\n {\n int i;\n for(i = n;\n\tdirectParent[i] != i;\n\ti = directParent[i]) {}\n for(int j = n;\n\tdirectParent[j] != j;)\n {\n\tauto oldparent = directParent[j];\n\tdirectParent[j] = i;\n\tj = oldparent;\n }\n return i;\n }\n bool uniteSets(int x, int y)\n {\n x = rep(x);\n y = rep(y);\n if (x == y) return false;\n if (size[x] < size[y])\n swap(x, y);\n assert(size[x] >= size[y]);\n directParent[y] = x;\n noSets--;\n size[x] += size[y];\n return true;\n }\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto m = next!int;\n auto edges = new int[2][](m);\n auto fdsu = Dsu.makeEmpty(n);\n auto bdsu = Dsu.makeEmpty(n);\n auto fre = new bool[](m);\n auto bre = new bool[](m);\n foreach(e; 0 .. m)\n {\n edges[e][0] = next!int - 1;\n edges[e][1] = next!int - 1;\n }\n foreach(i; 0 .. m)\n fre[i] = fdsu.uniteSets(edges[i][0], edges[i][1]);\n foreach_reverse(i; 0 .. m)\n bre[i] = bdsu.uniteSets(edges[i][0], edges[i][1]);\n struct Adj\n {\n int nei;\n int id;\n }\n auto adj = new Adj[][](n);\n foreach(i, e; edges)\n if (fre[i] || bre[i])\n {\n\tadj[e[0]] ~= Adj(e[1], cast(int) i);\n\tadj[e[1]] ~= Adj(e[0], cast(int) i);\n }\n\n auto visited = new bool[](n);\n auto k = next!int;\n foreach(q; 0 .. k)\n {\n auto l = next!int - 1;\n auto r = next!int - 1;\n visited[] = false;\n void dfs(int i)\n {\n\tvisited[i] = true;\n\tforeach(a; adj[i])\n\t {\n\t if (a.id >= l && a.id <= r)\n\t continue;\n\t if (visited[a.nei])\n\t continue;\n\t dfs(a.nei);\n\t }\n }\n int comps = 0;\n foreach(i; 0 .. n)\n\t{\n\t if (!visited[i])\n\t {\n\t dfs(i);\n\t comps++;\n\t }\n\t}\n comps.writeln;\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nstruct Dsu\n{\n int[] size;\n int[] directParent;\n int noSets;\n static Dsu makeEmpty(int noElements)\n {\n Dsu dsu;\n with(dsu)\n {\n\tsize = new int[](noElements); size[] = 1;\n\tdirectParent = new int[](noElements); foreach(i; 0 .. noElements) directParent[i] = i;\n\tnoSets = noElements;\n }\n return dsu;\n }\n int rep(int n)\n {\n int i;for(i = n;directParent[i] != i;i = directParent[i]) {}\n for(int j = n;directParent[j] != j;){auto nj = directParent[j];directParent[j] = i;j = nj;}\n return i;\n }\n bool uniteSets(int x, int y)\n {\n x = rep(x);\n y = rep(y);\n if (x == y) return false;\n if (size[x] < size[y])\n swap(x, y);\n assert(size[x] >= size[y]);\n directParent[y] = x;\n noSets--;\n size[x] += size[y];\n return true;\n }\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto m = next!int;\n auto edges = new int[2][](m);\n auto fdsu = Dsu.makeEmpty(n);\n auto bdsu = Dsu.makeEmpty(n);\n auto fre = new bool[](m);\n auto bre = new bool[](m);\n foreach(e; 0 .. m)\n edges[e][] = [next!int - 1, next!int - 1];\n foreach(i; 0 .. m)\n fre[i] = fdsu.uniteSets(edges[i][0], edges[i][1]);\n foreach_reverse(i; 0 .. m)\n bre[i] = bdsu.uniteSets(edges[i][0], edges[i][1]);\n struct Adj\n {\n int nei;\n int id;\n }\n auto adj = new Adj[][](n);\n foreach(i, e; edges)\n if (fre[i] || bre[i])\n {\n\tadj[e[0]] ~= Adj(e[1], cast(int) i);\n\tadj[e[1]] ~= Adj(e[0], cast(int) i);\n }\n\n auto visited = new bool[](n);\n auto k = next!int;\n foreach(q; 0 .. k)\n {\n auto l = next!int - 1;\n auto r = next!int - 1;\n visited[] = false;\n void dfs(int i)\n {\n\tvisited[i] = true;\n\tforeach(a; adj[i])\n\t {\n\t if (a.id >= l && a.id <= r)\n\t continue;\n\t if (visited[a.nei])\n\t continue;\n\t dfs(a.nei);\n\t }\n }\n int comps = 0;\n foreach(i; 0 .. n)\n\t{\n\t if (!visited[i])\n\t {\n\t dfs(i);\n\t comps++;\n\t }\n\t}\n comps.writeln;\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nstruct Dsu\n{\n int[] size;\n int[] directParent;\n int noSets;\n static Dsu makeEmpty(int noElements)\n {\n Dsu dsu;\n with(dsu)\n {\n\tsize = new int[](noElements); size[] = 1;\n\tdirectParent = new int[](noElements); foreach(i; 0 .. noElements) directParent[i] = i;\n\tnoSets = noElements;\n }\n return dsu;\n }\n int rep(int n)\n {\n auto p = directParent[n];\n if (p == n)\n return p;\n directParent[n] = rep(p);\n return directParent[n];\n }\n bool uniteSets(int x, int y)\n {\n x = rep(x);\n y = rep(y);\n if (x == y) return false;\n if (size[x] < size[y])\n swap(x, y);\n assert(size[x] >= size[y]);\n directParent[y] = x;\n noSets--;\n size[x] += size[y];\n return true;\n }\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!int;\n auto m = next!int;\n auto edges = new int[2][](m);\n auto fdsu = Dsu.makeEmpty(n);\n auto bdsu = Dsu.makeEmpty(n);\n auto fre = new bool[](m);\n auto bre = new bool[](m);\n foreach(e; 0 .. m)\n {\n edges[e][0] = next!int - 1;\n edges[e][1] = next!int - 1;\n }\n foreach(i; 0 .. m)\n fre[i] = fdsu.uniteSets(edges[i][0], edges[i][1]);\n foreach_reverse(i; 0 .. m)\n bre[i] = bdsu.uniteSets(edges[i][0], edges[i][1]);\n struct Adj\n {\n int nei;\n int id;\n }\n auto adj = new Adj[][](n);\n foreach(i, e; edges)\n if (fre[i] || bre[i])\n {\n\tadj[e[0]] ~= Adj(e[1], cast(int) i);\n\tadj[e[1]] ~= Adj(e[0], cast(int) i);\n }\n\n auto visited = new bool[](n);\n auto k = next!int;\n foreach(q; 0 .. k)\n {\n auto l = next!int - 1;\n auto r = next!int - 1;\n visited[] = false;\n void dfs(int i)\n {\n\tvisited[i] = true;\n\tforeach(a; adj[i])\n\t {\n\t if (a.id >= l && a.id <= r)\n\t continue;\n\t if (visited[a.nei])\n\t continue;\n\t dfs(a.nei);\n\t }\n }\n int comps = 0;\n foreach(i; 0 .. n)\n\t{\n\t if (!visited[i])\n\t {\n\t dfs(i);\n\t comps++;\n\t }\n\t}\n comps.writeln;\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [], "src_uid": "357e4fe985e9eb0c10b9b363fce79ae7"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t}\n\t\ta = [0] ~ a ~ [n + 1];\n\t\tauto prev = new int [n + 2];\n\t\tprev[0] = 0;\n\t\tforeach (i; 0..n + 1)\n\t\t{\n\t\t\tprev[i + 1] = i;\n\t\t}\n\t\tauto next = new int [n + 2];\n\t\tnext[n + 1] = n + 1;\n\t\tforeach (i; 0..n + 1)\n\t\t{\n\t\t\tnext[i] = i + 1;\n\t\t}\n\t\tauto iprev = prev.dup;\n\t\tauto inext = next.dup;\n\t\tauto del = new bool [n + 2];\n\t\tdel[] = false;\n\n\t\tint res = 0;\n\t\twhile (true)\n\t\t{\n\t\t\tbool ok = false;\n\n\t\t\tint p = inext[0];\n\t\t\twhile (p <= n)\n\t\t\t{\n\t\t\t\tdebug {write (' ', p);}\n\t\t\t\tif (del[p])\n\t\t\t\t{\n\t\t\t\t\tiprev[inext[p]] = iprev[p];\n\t\t\t\t\tinext[iprev[p]] = inext[p];\n\t\t\t\t}\n\t\t\t\tdebug {writef (\"(%s.%s)\", a[p], a[next[p]]);}\n\t\t\t\tif (a[p] > a[next[p]] && !del[next[p]])\n\t\t\t\t{\n\t\t\t\t\tdebug {write ('[', next[p], ']');}\n\t\t\t\t\tok = true;\n\t\t\t\t\tdel[next[p]] = true;\n\t\t\t\t\tint q = next[p];\n\t\t\t\t\tprev[next[q]] = prev[q];\n\t\t\t\t\tnext[prev[q]] = next[q];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tiprev[inext[p]] = iprev[p];\n\t\t\t\t\tinext[iprev[p]] = inext[p];\n\t\t\t\t}\n\t\t\t\tp = inext[p];\n\t\t\t}\n\t\t\tdebug {writeln ();}\n\n\t\t\tif (!ok)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tres++;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.range;\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n\n auto a = new int[n];\n foreach (i; 0..n) readf(\" %d\", &a[i]), --a[i];\n a ~= n;\n\n auto rt = array(iota(1, n + 1));\n auto ls = array(iota(n));\n int[] nls;\n auto done = new bool[n];\n\n int ans;\n while (true) {\n foreach_reverse (i; ls)\n if (a[i] > a[rt[i]])\n done[rt[i]] = true, rt[i] = rt[rt[i]];\n else\n done[i] = true;\n foreach (i; ls)\n if (!done[i])\n nls ~= i;\n if (nls !is null) {\n ls = null;\n swap(ls, nls);\n ++ans;\n } else\n break;\n }\n\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n\n auto n = next!int;\n auto a = next!int(n);\n auto dt = new int[](n);\n dt[] = int.max;\n auto possible = SList!int(0);\n iloop:foreach(i; 1 .. n)\n {\n dt[i] = 1;\n searchkiller: while(true)\n {\n auto np = possible.front;\n if (dt[np] < dt[i])\n {\n possible.removeFront;\n continue searchkiller;\n }\n if (a[np] > a[i])\n {\n possible.insertFront(i);\n continue iloop;\n }\n else\n {\n if (dt[np] == int.max)\n {\n dt[i] = int.max;\n possible.insertFront(i);\n continue iloop;\n }\n dt[i] = dt[np] + 1;\n possible.removeFront;\n continue searchkiller;\n }\n }\n }\n writeln(dt.filter!(t => t != int.max).fold!max(0));\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [], "src_uid": "ff4a128ad18ccc846c44647cec5cf485"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const L = readInt;\n const M = readInt;\n auto A = new long[L];\n foreach (l; 0 .. L) {\n A[l] = readLong;\n }\n auto X = new long[M];\n auto Y = new long[M];\n foreach (i; 0 .. M) {\n X[i] = readLong;\n Y[i] = readLong;\n }\n \n auto as = A.dup;\n as = as.sort.uniq.array;\n const V = cast(int)(as.length);\n \n auto cnt = new int[V];\n foreach (l; 0 .. L) {\n ++cnt[as.lowerBound(A[l])];\n }\n auto uss = new int[][L + 1];\n foreach (u; 0 .. V) {\n uss[cnt[u]] ~= u;\n }\n foreach (k; 1 .. L + 1) if (!uss[k].empty) {\n uss[k].sort!((u, v) => (as[u] > as[v]));\n }\n \n auto graph = new int[][V];\n foreach (i; 0 .. M) {\n const u = as.lowerBound(X[i]);\n const v = as.lowerBound(Y[i]);\n graph[u] ~= v;\n graph[v] ~= u;\n }\n \n auto bad = new int[V];\n bad[] = -1;\n long ans;\n foreach (u; 0 .. V) {\n bad[u] = u;\n foreach (v; graph[u]) {\n bad[v] = u;\n }\n foreach (k; 1 .. cnt[u] + 1) {\n foreach (v; uss[k]) {\n if (bad[v] != u) {\n chmax(ans, 1L * (cnt[u] + cnt[v]) * (as[u] + as[v]));\n break;\n }\n }\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\talias Pair = Tuple !(int, q{x}, int, q{y});\r\n\t\tbool [Pair] bad;\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tPair p;\r\n\t\t\treadf !(\" %s %s\") (p.x, p.y);\r\n\t\t\tbad[p] = true;\r\n\t\t\tswap (p.x, p.y);\r\n\t\t\tbad[p] = true;\r\n\t\t}\r\n\r\n\t\tint [int] cnt;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tcnt[c] += 1;\r\n\t\t}\r\n\r\n\t\tint [] [int] byCnt;\r\n\t\tforeach (k, v; cnt)\r\n\t\t{\r\n\t\t\tbyCnt[v] ~= k;\r\n\t\t}\r\n\r\n\t\tforeach (line; byCnt)\r\n\t\t{\r\n\t\t\tsort (line);\r\n\t\t}\r\n\r\n\t\tlong res = 0;\r\n\t\tforeach (k, _; cnt)\r\n\t\t{\r\n\t\t\tauto cntK = cnt[k];\r\n\t\t\tforeach (cnt2; 1..cntK + 1)\r\n\t\t\t{\r\n\t\t\t\tif (cnt2 !in byCnt)\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tforeach_reverse (elem; byCnt[cnt2])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (k != elem &&\r\n\t\t\t\t\t Pair (k, elem) !in bad)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tres = max (res, (k + elem) *\r\n\t\t\t\t\t\t 1L * (cntK + cnt2));\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\talias Pair = Tuple !(int, q{x}, int, q{y});\r\n\t\tbool [Pair] bad;\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tPair p;\r\n\t\t\treadf !(\" %s %s\") (p.x, p.y);\r\n\t\t\tbad[p] = true;\r\n\t\t\tswap (p.x, p.y);\r\n\t\t\tbad[p] = true;\r\n\t\t}\r\n\r\n\t\tint [int] cnt;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tcnt[c] += 1;\r\n\t\t}\r\n\r\n\t\tint [] [int] byCnt;\r\n\t\tforeach (k, v; cnt)\r\n\t\t{\r\n\t\t\tbyCnt[v] ~= k;\r\n\t\t}\r\n\r\n\t\tforeach (line; byCnt)\r\n\t\t{\r\n\t\t\tsort (line);\r\n\t\t}\r\n\r\n\t\tlong res = 0;\r\n\t\tforeach (k, _; cnt)\r\n\t\t{\r\n\t\t\tauto cntK = cnt[k];\r\n\t\t\tforeach (curCnt, line; byCnt)\r\n\t\t\t{\r\n\t\t\t\tforeach_reverse (elem; line)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (k != elem &&\r\n\t\t\t\t\t Pair (k, elem) !in bad)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tres = max (res, (k + elem) *\r\n\t\t\t\t\t\t 1L * (cntK + curCnt));\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\talias Pair = Tuple !(int, q{x}, int, q{y});\r\n\t\tbool [Pair] bad;\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tPair p;\r\n\t\t\treadf !(\" %s %s\") (p.x, p.y);\r\n\t\t\tbad[p] = true;\r\n\t\t\tswap (p.x, p.y);\r\n\t\t\tbad[p] = true;\r\n\t\t}\r\n\r\n\t\tint [int] cnt;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tcnt[c] += 1;\r\n\t\t}\r\n\r\n\t\tint [] [int] byCnt;\r\n\t\tforeach (k, v; cnt)\r\n\t\t{\r\n\t\t\tbyCnt[v] ~= k;\r\n\t\t}\r\n\r\n\t\tforeach (line; byCnt)\r\n\t\t{\r\n\t\t\tsort (line);\r\n\t\t}\r\n\r\n\t\tlong res = 0;\r\n\t\tforeach (k, _; cnt)\r\n\t\t{\r\n\t\t\tauto cntK = cnt[k];\r\n\t\t\tforeach (cnt2; 1..cntK + 1)\r\n\t\t\t{\r\n\t\t\t\tif (cnt2 !in cnt)\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tforeach_reverse (elem; byCnt[cnt2])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (k != elem &&\r\n\t\t\t\t\t Pair (k, elem) !in bad)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tres = max (res, (k + elem) *\r\n\t\t\t\t\t\t 1L * (cntK + cnt2));\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "src_uid": "e6b39d4cea69aa241f919447f0617d5a"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Tuple !(int, \"v\", int, \"d\") pair;\n\t\tauto x = new pair [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &x[i].v);\n\t\t\tx[i].d = i + 1;\n\t\t}\n\t\tint k;\n\t\treadf (\" %s\", &k);\n\t\tx.sort !(\"a < b\", SwapStrategy.stable);\n\t\tx ~= x[$ - 1];\n\n\t\tlong s = 0;\n\t\tlong cur = 0;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\ts += x[i].v;\n\t\t\tcur += x[i].v * cast (long) (i + 1) - s;\n\t\t}\n\n\t\tlong res = long.max;\n\t\tint st = int.min;\n\t\tforeach (i; k..n + 1)\n\t\t{\n\t\t\tdebug {writefln (\"i = %s, cur = %s, res = %s, s = %s\",\n\t\t\t i, cur, res, s);}\n\t\t\tif (res > cur)\n\t\t\t{\n\t\t\t\tres = cur;\n\t\t\t\tst = i - k;\n\t\t\t}\n\t\t\tcur -= s - x[i - k].v * cast (long) k;\n\t\t\ts += x[i].v - x[i - k].v;\n\t\t\tcur += x[i].v * cast (long) k - s;\n\t\t}\n\t\tdebug {writeln (res);}\n\t\twritefln (\"%(%s %)\", k.iota.map !(a => x[a + st].d).array);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Tuple !(int, \"v\", int, \"d\") pair;\n\t\tauto x = new pair [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &x[i].v);\n\t\t\tx[i].d = i + 1;\n\t\t}\n\t\tint k;\n\t\treadf (\" %s\", &k);\n\t\tx.sort !(\"a < b\", SwapStrategy.stable);\n\t\tx ~= x[$ - 1];\n\n\t\tlong s = 0;\n\t\tlong cur = 0;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\ts += x[i].v;\n\t\t\tcur += x[i].v * cast (long) (i + 1) - s;\n\t\t}\n\n\t\tlong res = long.max;\n\t\tint st = int.min;\n\t\tforeach (i; k..n + 1)\n\t\t{\n\t\t\tif (res > cur)\n\t\t\t{\n\t\t\t\tres = cur;\n\t\t\t\tst = i - k;\n\t\t\t}\n\t\t\tcur -= s - x[i - k].v * cast (long) k;\n\t\t\ts += x[i].v - x[i - k].v;\n\t\t\tcur += x[i].v * cast (long) k - s;\n\t\t}\n\t\twritefln (\"%(%s %)\", k.iota.map !(a => x[a + st].d).array);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto x = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &x[i]);\n\t\t}\n\t\tint k;\n\t\treadf (\" %s\", &k);\n\t\tx.sort !(\"a < b\", SwapStrategy.stable);\n\t\tx ~= x[$ - 1];\n\n\t\tlong s = 0;\n\t\tlong cur = 0;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\ts += x[i];\n\t\t\tcur += x[i] * (i + 1) - s;\n\t\t}\n\n\t\tlong res = long.max;\n\t\tint st = int.min;\n\t\tforeach (i; k..n + 1)\n\t\t{\n\t\t\tdebug {writefln (\"i = %s, cur = %s, res = %s, s = %s\",\n\t\t\t i, cur, res, s);}\n\t\t\tif (res > cur)\n\t\t\t{\n\t\t\t\tres = cur;\n\t\t\t\tst = i - k + 1;\n\t\t\t}\n\t\t\tcur -= s - x[i - k] * k;\n\t\t\ts += x[i] - x[i - k];\n\t\t\tcur += x[i] * k - s;\n\t\t}\n\t\tdebug {writeln (res);}\n\t\twritefln (\"%(%s %)\", k.iota.map !(a => a + st).array);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto x = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &x[i]);\n\t\t}\n\t\tint k;\n\t\treadf (\" %s\", &k);\n\t\tx.sort !(\"a < b\", SwapStrategy.stable);\n\t\tx ~= x[$ - 1];\n\n\t\tlong s = 0;\n\t\tlong cur = 0;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\ts += x[i];\n\t\t\tcur += x[i] * (i + 1) - s;\n\t\t}\n\n\t\tlong res = long.max;\n\t\tforeach (i; k..n + 1)\n\t\t{\n\t\t\tdebug {writefln (\"i = %s, cur = %s, res = %s, s = %s\",\n\t\t\t i, cur, res, s);}\n\t\t\tres = min (res, cur);\n\t\t\tcur -= s - x[i - k] * k;\n\t\t\ts += x[i] - x[i - k];\n\t\t\tcur += x[i] * k - s;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "321dfe3005c81bf00458e475202a83a8"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto k = RD!int;\n\tauto a = RDA!int;\n\n\tbool f(int x)\n\t{\n\t\t{\n\t\t\tauto dp = new int[](n+2);\n\t\t\tauto begin = k % 2 ? 1 : 0;\n\t\t\tauto end = n-1;\n\t\t\tforeach (i; begin..end)\n\t\t\t{\n\t\t\t\tif (a[i] <= x)\n\t\t\t\t{\n\t\t\t\t\tif (dp[i]+1 == k/2) return true;\n\t\t\t\t\tdp[i+2].chmax(dp[i]+1);\n\t\t\t\t}\n\t\t\t\tdp[i+1].chmax(dp[i]);\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tauto dp = new int[](n+2);\n\t\t\tauto begin = k % 2 ? 0 : 1;\n\t\t\tauto end = n;\n\t\t\tforeach (i; begin..end)\n\t\t\t{\n\t\t\t\tif (a[i] <= x)\n\t\t\t\t{\n\t\t\t\t\tif (dp[i]+1 == (k+1)/2) return true;\n\t\t\t\t\tdp[i+2].chmax(dp[i]+1);\n\t\t\t\t}\n\t\t\t\tdp[i+1].chmax(dp[i]);\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tauto ans = binarySearch!(f)(10^^9, 0);\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nalias A = Tuple!(int, \"i\", int, \"a\");\n\nvoid main()\n{\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n\n int o_i, o_j, e_i, e_j;\n if (K%2 == 0) {\n o_i = 0;\n o_j = N-2;\n e_i = 1;\n e_j = N-1;\n } else {\n o_i = 0;\n o_j = N-1;\n e_i = 1;\n e_j = N-2;\n }\n\n int[] aa, bb;\n foreach (a; readln.split.to!(int[])) {\n aa ~= a;\n bb ~= a;\n }\n sort(bb);\n bb.uniq();\n int l = -1, r = N-1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n auto a = bb[m];\n // odd\n {\n int i = o_i;\n int o;\n while (i <= o_j) {\n if (aa[i] <= a) {\n ++o;\n ++i;\n }\n ++i;\n }\n\n if (o >= (K+1)/2) {\n r = m;\n continue;\n }\n }\n // even\n {\n auto i = e_i;\n int e;\n while (i <= e_j) {\n if (aa[i] <= a) {\n ++e;\n ++i;\n }\n ++i;\n }\n\n if (e >= K/2) {\n r = m;\n continue;\n }\n }\n\n l = m;\n }\n writeln(bb[r]);\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nbool ok (int [] a, int me, int k)\n{\n\tint pos = 0;\n\tforeach (ref c; a)\n\t{\n\t\tif ((pos & 1) || (c <= me))\n\t\t{\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn pos >= k;\n}\n\nint solveOdd (int [] a, int k)\n{\n\tint lo = 0;\n\tint hi = 10 ^^ 9 + 1;\n\twhile (lo < hi)\n\t{\n\t\tint me = (lo + hi) >> 1;\n\t\tif (ok (a, me, k))\n\t\t{\n\t\t\thi = me;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlo = me + 1;\n\t\t}\n\t}\n\treturn lo;\n}\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (min (solveOdd (a, k), solveOdd (a[1..$], k - 1)));\n\t}\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\nimport std.meta;\nimport std.traits;\n\nlong x10(long mul, long exp)\n{\n long res = 1;\n foreach(i; 0 .. exp)\n res *= 10;\n res *= mul;\n return res;\n}\n\nint maxPlace(int[] arr, int ub)\n{\n int res = 0;\n for(int i = 0; i < arr.length; i++)\n {\n if (arr[i] <= ub)\n {\n res++;\n i++;\n }\n }\n return res;\n}\n\nint[2.x10(5)] A;\n\nvoid main()\n{\n static assert(int.max >= 2.x10(5));\n int n, k; read(n, k);\n auto a = A[0 .. n];\n read(a);\n bool function(int, int, int[]) can;\n if (k % 2 == 0)\n {\n can = (int ub, int k, int[] a)\n {\n return maxPlace(a[0 .. $ - 1], ub) >= k / 2 ||\n maxPlace(a[1 .. $], ub) >= k / 2;\n };\n }\n else\n {\n can = (int ub, int k, int[] a)\n {\n return maxPlace(a[0 .. $], ub) >= (k / 2 + 1) ||\n maxPlace(a[1 .. $ - 1], ub) >= k / 2;\n };\n }\n auto minres = cast(int) 1.x10(9);\n int hi = minres;\n int lo = 1;\n while(lo <= hi)\n {\n int mid = (lo + hi) / 2;\n if (can(mid, k, a))\n {\n minres = min(minres, mid);\n hi = mid - 1;\n }\n else\n {\n lo = mid + 1;\n }\n }\n minres.writeln;\n}\n\nalias seq = (x, y) => iota(x, y + 1);\nalias writesp = (x) => write(x, \" \");\n\nvoid read(T...)(ref T t)\n{\n static DList!string _words;\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\nimport std.meta;\nimport std.traits;\n\nlong x10(long mul, long exp)\n{\n long res = 1;\n foreach(i; 0 .. exp)\n res *= 10;\n res *= mul;\n return res;\n}\n\nint[2.x10(5)] A;\n\nvoid main()\n{\n static assert(int.max >= 2.x10(5));\n int n, k; read(n, k);\n auto a = A[0 .. n];\n read(a);\n int maxPlace(int[] arr, int ub)\n {\n int res = 0;\n for(int i = 0; i < arr.length; i++)\n {\n if (arr[i] <= ub)\n {\n res++;\n i++;\n }\n }\n return res;\n }\n bool delegate(int) can;\n if (k % 2 == 0)\n {\n can = (int ub)\n {\n return maxPlace(a[0 .. $ - 1], ub) >= k / 2 ||\n maxPlace(a[1 .. $], ub) >= k / 2;\n };\n }\n else\n {\n can = (int ub)\n {\n return maxPlace(a[0 .. $], ub) >= (k / 2 + 1) ||\n maxPlace(a[1 .. $ - 1], ub) >= k / 2;\n };\n }\n auto minres = cast(int) 1.x10(9);\n int hi = minres;\n int lo = 1;\n while(lo <= hi)\n {\n int mid = (lo + hi) / 2;\n if (can(mid))\n {\n minres = min(minres, mid);\n hi = mid - 1;\n }\n else\n {\n lo = mid + 1;\n }\n }\n minres.writeln;\n}\n\nalias seq = (x, y) => iota(x, y + 1);\nalias writesp = (x) => write(x, \" \");\n\nvoid read(T...)(ref T t)\n{\n static DList!string _words;\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nalias A = Tuple!(int, \"i\", int, \"a\");\n\nvoid main()\n{\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n\n int o_i, o_j, e_i, e_j;\n if (K%2 == 0) {\n o_i = 0;\n o_j = N-2;\n e_i = 1;\n e_j = N-1;\n } else {\n o_i = 0;\n o_j = N-1;\n e_i = 1;\n e_j = N-2;\n }\n\n int[] aa;\n auto AA = [A(-1, -1)];\n foreach (i, a; readln.split.to!(int[])) {\n aa ~= a;\n AA ~= A(i.to!int, a);\n }\n sort!\"a.a < b.a\"(AA);\n int l, r = N;\n while (l+1 < r) {\n auto m = (l+r)/2;\n auto k = AA[m].i;\n auto a = AA[m].a;\n\n auto i = k;\n auto j = k;\n // odd\n if (o_i <= k && k <= o_j) {\n int o = 1;\n while (i-1 >= o_i) {\n --i;\n if (aa[i] <= a) {\n ++o;\n --i;\n }\n }\n while (j+1 <= o_j) {\n ++j;\n if (aa[j] <= a) {\n ++o;\n ++j;\n }\n }\n\n if (o >= (K+1)/2) {\n r = m;\n continue;\n }\n }\n\n i = k;\n j = k;\n // even\n if (e_i <= k && k <= e_j) {\n int e = 1;\n while (i-1 >= e_i) {\n --i;\n if (aa[i] <= a) {\n ++e;\n --i;\n }\n }\n while (j+1 <= e_j) {\n ++j;\n if (aa[j] <= a) {\n ++e;\n ++j;\n }\n }\n\n if (e >= K/2) {\n r = m;\n continue;\n }\n }\n\n l = m;\n }\n\n writeln(AA[r].a);\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 1)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto k = RD!int;\n\tauto a = RDA!int;\n\n\tbool f(int x)\n\t{\n\t\tauto dp = new int[](n+2);\n\t\tauto begin = k % 2 ? 1 : 0;\n\t\tforeach (i; begin..n)\n\t\t{\n\t\t\tif (a[i] <= x)\n\t\t\t{\n\t\t\t\tif (dp[i]+1 == k/2) return true;\n\t\t\t\tdp[i+2].chmax(dp[i]+1);\n\t\t\t}\n\t\t\tdp[i+1].chmax(dp[i]);\n\t\t}\n\t\treturn false;\n\t}\n\n\tauto ans = binarySearch!(f)(10^^9, 0);\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "d55ed15b600477e292406bef0b2d3b49"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable int INF = 1 << 29;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n long m = 0;\n\n foreach (i; 0..N) {\n if (A[i] > m) {\n writeln(i + 1);\n return;\n }\n if (A[i] == m) {\n m += 1;\n }\n }\n\n writeln(-1);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint solve (int [] a)\n{\n\tint next = 0;\n\tforeach (pos, ref cur; a)\n\t{\n\t\tif (cur > next)\n\t\t{\n\t\t\treturn pos + 1;\n\t\t}\n\t\tnext = max (next, cur + 1);\n\t}\n\treturn -1;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (a));\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint solve (int [] a)\n{\n\tint next = 0;\n\tforeach (pos, ref cur; a)\n\t{\n\t\tif (cur > next)\n\t\t{\n\t\t\treturn pos;\n\t\t}\n\t\tnext = max (next, cur + 1);\n\t}\n\treturn -1;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (a));\n\t}\n}\n"}], "src_uid": "e17427897fd5147c601204cb1c48b143"} {"source_code": "import\n\t\tstd.math,\n\t\tstd.conv,\n\t\tstd.file,\n\t\tstd.range,\n\t\tstd.array,\n\t\tstd.stdio,\n\t\tstd.string,\n\t\tstd.bitmanip,\n\t\tstd.typecons,\n\t\tstd.algorithm;\n\n\nvoid main()\n{\n\tuint hh, mm, h, d, c, n;\n\n\treadf!`%d %d %d %d %d %d`(hh, mm, h, d, c, n);\n\n\tauto e = ceil(float(h) / n) * c;\n\n\tif(hh >= 20)\n\t{\n\t\twriteln(e * 0.8);\n\t}\n\telse\n\t{\n\t\tauto v = ceil(float((20 * 60 - hh * 60 - mm) * d + h) / n) * c * 0.8;\n\n\t\tmin(e, v).writeln;\n\t}\n}\n", "positive_code": [{"source_code": "import core.stdc.stdio;\nimport core.stdc.stdlib;\nimport std.algorithm;\nvoid main()\n{\n\tint n,m,a,b,c,d;\n\tscanf(\"%d%d\",&n,&m);\n\tscanf(\"%d%d%d%d\",&a,&b,&c,&d);\n\tif (n>=20)\n\t{\n\t\tprintf(\"%.5lf\\n\",((a-1)/d+1)*c*0.8);\n\t\texit(0);\n\t}\n\tint dis=a+((60-m)+(19-n)*60)*b;\n\tprintf(\"%.5lf\\n\",min(((dis-1)/d+1)*c*0.8,((a-1)/d+1)*c*1.0));\n}"}], "negative_code": [{"source_code": "import\n\t\tstd.math,\n\t\tstd.conv,\n\t\tstd.file,\n\t\tstd.range,\n\t\tstd.array,\n\t\tstd.stdio,\n\t\tstd.string,\n\t\tstd.bitmanip,\n\t\tstd.typecons,\n\t\tstd.algorithm;\n\n\nvoid main()\n{\n\tuint hh, mm, h, d, c, n;\n\n\treadf!`%d %d %d %d %d %d`(hh, mm, h, d, c, n);\n\n\tauto e = ceil(double(h) / n) * c;\n\n\tif(hh >= 20)\n\t{\n\t\twriteln(e * 0.8);\n\t}\n\telse\n\t{\n\t\tauto v = ceil(double((20 * 60 - hh * 60 - mm) * d + h) / n * c * 0.8);\n\n\t\tmin(e, v).writeln;\n\t}\n}\n"}, {"source_code": "import\n\t\tstd.math,\n\t\tstd.conv,\n\t\tstd.file,\n\t\tstd.range,\n\t\tstd.array,\n\t\tstd.stdio,\n\t\tstd.string,\n\t\tstd.bitmanip,\n\t\tstd.typecons,\n\t\tstd.algorithm;\n\n\nvoid main()\n{\n\tuint hh, mm, h, d, c, n;\n\n\treadf!`%d %d %d %d %d %d`(hh, mm, h, d, c, n);\n\n\tauto e = ceil(float(h) / n) * c;\n\n\tif(hh >= 20)\n\t{\n\t\twriteln(e * 0.8);\n\t}\n\telse\n\t{\n\t\tauto v = ceil(float((20 * 60 - hh * 60 - mm) * d + h) / n * c * 0.8);\n\n\t\tmin(e, v).writeln;\n\t}\n}\n"}], "src_uid": "937acacc6d5d12d45c08047dde36dcf0"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto v = new int [] [m];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint p, c;\n\t\t\treadf (\" %s %s\", &p, &c);\n\t\t\tp -= 1;\n\t\t\tv[p] ~= c;\n\t\t}\n\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tsort !(q{a > b}) (v[j]);\n\t\t}\n\n\t\tlong res = long.max;\n\t\tauto w = new int [n];\n\t\tfor (int limit = 0; limit <= n; limit++)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tint votes = v[0].length.to !(int);\n\t\t\tint t = 0;\n\t\t\tforeach (j; 1..m)\n\t\t\t{\n\t\t\t\tforeach (k, c; v[j])\n\t\t\t\t{\n\t\t\t\t\tif (k < limit)\n\t\t\t\t\t{\n\t\t\t\t\t\tw[t] = c;\n\t\t\t\t\t\tt += 1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcur += c;\n\t\t\t\t\t\tvotes += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsort (w[0..t]);\n\t\t\tint p = 0;\n\t\t\twhile (votes <= limit && p < t)\n\t\t\t{\n\t\t\t\tcur += w[p];\n\t\t\t\tp += 1;\n\t\t\t\tvotes += 1;\n\t\t\t}\n\n\t\t\tdebug {writeln (limit, \" \", votes, \" \", cur);}\n\t\t\tif (votes > limit)\n\t\t\t{\n\t\t\t\tres = min (res, cur);\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n int partyvotes = 0;\n int[][int] votes;\n foreach (_; 0 .. n) {\n int p, c;\n readf(\"%s %s\", &p, &c);\n readln;\n \n if (p == 1) partyvotes += 1;\n else votes[p] ~= c;\n }\n \n foreach (k, ref v; votes) sort(v);\n \n debug { votes.writeln; }\n \n auto ans = 3000L * 10 ^^ 9;\n foreach (x; partyvotes .. n+1) {\n auto curvotes = partyvotes;\n auto cursum = 0L;\n int[] cheap;\n foreach (k, v; votes) {\n auto need = max(0, cast(int)v.length - x + 1);\n \n debug { writeln(k, ' ', v, ' ', v.length, ' ', need); }\n \n curvotes += need;\n cursum += v.take(need).sum(0L);\n cheap ~= v.drop(need);\n }\n auto need = max(0, x - curvotes);\n curvotes = x;\n sort(cheap);\n cursum += cheap.take(need).sum(0L);\n \n debug { writeln(x, ' ', cursum); }\n \n ans = min(ans, cursum);\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = new Tuple!(int, long)[][](M);\n Tuple!(int, long)[] B;\n int cnt = 0;\n\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n auto m = s[0];\n auto c = s[1].to!long;\n if (m == 1) {\n cnt += 1;\n } else {\n A[m-1] ~= tuple(i, c);\n B ~= tuple(i, c);\n }\n }\n\n foreach (i; 0..M) {\n A[i].sort!\"a[1] < b[1]\"();\n }\n B.sort!\"a[1] < b[1]\"();\n\n auto used = new bool[](N);\n long ans = 1L << 59;\n\n foreach (x; 0..N-cnt+1) {\n used.fill(false);\n int v = cnt + x;\n if (v == 0) continue;\n long tmp = 0;\n int tmpcnt = cnt;\n foreach (i; 0..M) {\n for (int j = 0; A[i].length.to!int - j >= v; ++j) {\n tmp += A[i][j][1];\n used[A[i][j][0]] = true;\n tmpcnt += 1;\n }\n }\n for (int i = 0; i < B.length.to!int && tmpcnt < v; ++i) {\n if (used[B[i][0]]) continue;\n tmp += B[i][1];\n tmpcnt += 1;\n }\n if (tmpcnt >= v)\n ans = min(ans, tmp);\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10L^^18;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto P = new int[N];\n auto C = new long[N];\n foreach (i; 0 .. N) {\n P[i] = readInt() - 1;\n C[i] = readLong();\n }\n \n auto css = new long[][M];\n foreach (i; 0 .. N) {\n css[P[i]] ~= C[i];\n }\n foreach (j; 0 .. M) {\n css[j].sort;\n }\n \n long ans = INF;\n foreach (k; 1 .. N + 1) {\n long cost;\n long[] cs;\n foreach (j; 1 .. M) {\n const len = cast(int)(css[j].length);\n const bribe = max(len - (k - 1), 0);\n foreach (x; 0 .. bribe) {\n cost += css[j][x];\n }\n foreach (x; bribe .. len) {\n cs ~= css[j][x];\n }\n }\n cs.sort;\n {\n const len = cast(int)(cs.length);\n const bribe = max(len - (N - k), 0);\n debug {\n writeln(\" \", k, \": \", cs, \" \", bribe);\n }\n foreach (x; 0 .. bribe) {\n cost += cs[x];\n }\n }\n debug {\n writeln(k, \": \", cost);\n }\n chmin(ans, cost);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = new Tuple!(int, long)[][](M);\n auto B = new Tuple!(int, long)[](N);\n int cnt = 0;\n\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n auto m = s[0];\n auto c = s[1].to!long;\n if (m == 1) {\n cnt += 1;\n } else {\n A[m-1] ~= tuple(i, c);\n B[i] = tuple(i, c);\n }\n }\n\n foreach (i; 0..M) {\n A[i].sort!\"a[1] < b[1]\"();\n }\n B.sort!\"a[1] < b[1]\"();\n auto used = new bool[](N);\n long ans = 1L << 59;\n\n foreach (x; 0..N-cnt+1) {\n int v = cnt + x;\n if (v == 0) continue;\n long tmp = 0;\n int tmpcnt = cnt;\n foreach (i; 0..M) {\n for (int j = 0; A[i].length.to!int - j >= v; ++j) {\n tmp += A[i][j][1];\n used[A[i][j][0]] = true;\n tmpcnt += 1;\n }\n }\n for (int i = 0; i < B.length.to!int && tmpcnt < v; ++i) {\n if (used[B[i][0]]) continue;\n tmp += B[i][1];\n tmpcnt += 1;\n }\n ans = min(ans, tmp);\n used.fill(false);\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10L^^18;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n auto P = new int[N];\n auto C = new long[N];\n foreach (i; 0 .. N) {\n P[i] = readInt() - 1;\n C[i] = readLong();\n }\n \n auto css = new long[][M];\n foreach (i; 0 .. N) {\n css[P[i]] ~= C[i];\n }\n foreach (j; 0 .. M) {\n css[j].sort;\n }\n \n long ans = INF;\n foreach (k; 1 .. N + 1) {\n long cost;\n long[] cs;\n foreach (j; 1 .. M) {\n const len = cast(int)(css[j].length);\n const bribe = max(len - (k - 1), 0);\n foreach (x; 0 .. bribe) {\n cost += css[j][x];\n }\n foreach (x; bribe .. len) {\n cs ~= css[j][x];\n }\n }\n {\n const len = cast(int)(cs.length);\n const bribe = max(len - (N - k), 0);\n foreach (x; 0 .. bribe) {\n cost += cs[x];\n }\n }\n debug {\n writeln(k, \": \", cost);\n }\n chmin(ans, cost);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n int partyvotes = 0;\n int[][int] votes;\n foreach (_; 0 .. n) {\n int p, c;\n readf(\"%s %s\", &p, &c);\n readln;\n \n if (p == 1) partyvotes += 1;\n else votes[p] ~= c;\n }\n \n foreach (k, ref v; votes) sort(v);\n \n debug { votes.writeln; }\n \n auto ans = 3000L * 10 ^^ 9;\n foreach (x; partyvotes .. n+1) {\n auto curvotes = partyvotes;\n auto cursum = 0;\n int[] cheap;\n foreach (k, v; votes) {\n auto need = max(0, cast(int)v.length - x + 1);\n \n debug { writeln(k, ' ', v, ' ', v.length, ' ', need); }\n \n curvotes += need;\n cursum += v.take(need).sum(0L);\n cheap ~= v.drop(need);\n }\n auto need = max(0, x - curvotes);\n curvotes = x;\n sort(cheap);\n cursum += cheap.take(need).sum(0L);\n \n debug { writeln(x, ' ', cursum); }\n \n ans = min(ans, cursum);\n }\n \n ans.writeln;\n}"}], "src_uid": "2fd9a2f99fab69ac99b5832bb5ef87f9"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1519/problem/B\n// math\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n, m, k;\n readf(\"%s %s %s\\n\", &n, &m, &k);\n if(k == n * m - 1)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\n\r\nvoid main()\r\n{\r\n auto l= to!long(readln().chomp);\r\n foreach(_; 0..l)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long m = params[0];\r\n long n = params[1];\r\n long k = params[2];\r\n \r\n writeln(m*n-1 == k ? \"YES\" : \"NO\");\r\n }\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD;\r\n\t\tauto m = RD;\r\n\t\tauto k = RD;\r\n\r\n\t\tlong cnt = n-1;\r\n\t\tcnt += n * (m-1);\r\n\t\tans[ti] = cnt == k;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "8b0a9c7e997034d3ecce044b9f64aeba"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\ta.sort();\n\n\tauto ans = new long[](n);\n\tforeach (i; 0..n/2)\n\t{\n\t\tans[i*2+1] = a.front; a.popFront;\n\t}\n\tforeach (i; n/2..n)\n\t{\n\t\tans[(i-n/2)*2] = a.front; a.popFront;\n\t}\n\n\tlong cnt;\n\tforeach (i; 1..n-1)\n\t{\n\t\tif (ans[i] < ans[i-1] && ans[i] < ans[i+1])\n\t\t\t++cnt;\n\t}\n\n\twriteln(cnt);\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n arr.sort();\n ll[] res = new ll[](n);\n foreach(i; 0..n/2){\n res[2*i + 1] = arr[i]; \n }\n foreach(i;(n/2)..n){\n res[2*(i - n/2)] = arr[i];\n }\n ll num = 0;\n foreach(i; 1..n-1){\n if(res[i] < res[i-1] && res[i] < res[i+1]){\n ++num;\n }\n }\n writeln(num);\n foreach(el; res){\n write(el, \" \");\n }\n writeln;\n}\n\nvoid main(){\n long t = 1;\n /* t = rd; */\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n auto AS = readln.split.to!(int[]);\n sort!\"a > b\"(AS);\n\n auto BS = new int[](N);\n int i, j;\n while (j < N) {\n BS[j] = AS[i];\n ++i;\n j += 2;\n }\n foreach (k; 0..N) if (BS[k] == 0) BS[k] = AS[i++];\n if (N%2 == 0) {\n int k = 1;\n while (k < N-1) {\n if (BS[k-1] > BS[k] && BS[k+1] > BS[k]) {\n k += 2;\n continue;\n }\n BS[$-1] = BS[k];\n BS[k] = AS[i-1];\n goto end;\n }\n }\n end:\n\n int r;\n foreach (k; 1..N-1) if (BS[k-1] > BS[k] && BS[k+1] > BS[k]) ++r;\n writeln(r);\n writeln(BS.to!(string[]).join(\" \"));\n}"}], "negative_code": [], "src_uid": "6443dffb38285b6deb74f2371d8d0cac"} {"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\n/*\nint myabs(int a) {\n if (a < 0) return -a;\n return a;\n}\n*/\nvoid main() {\n int n;\n scanf(\"%d\",&n);\n int[] a = new int[n];\n for (int i = 0 ; i < n ; ++i)\n scanf(\"%d\",&a[i]);\n sort(a);\n ulong ans = 0;\n foreach (int idx, ele ; a) {\n ans += abs(idx-ele+1);\n }\n writef(\"%d\\n\", ans);\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.math;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tscanf (\" %d\", &a[i]);\n\t\t}\n\t\tsort (a);\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tres += abs (i + 1 - a[i]);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tscanf (\" %d\", &a[i]);\n\t\t}\n\t\tsort (a);\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tres += abs (i + 1 - a[i]);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n auto a = readln.split.to!(long[]);\n\n long ans;\n\n sort(a);\n\n foreach (i ; 0 .. n) {\n ans += abs(i + 1 - a[i]);\n }\n\n writeln(ans);\n}\n\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n auto a = readln.split.to!(int[]);\n\n long ans;\n\n sort(a);\n\n foreach (i ; 0 .. n) {\n ans += abs(i + 1 - a[i]);\n }\n\n writeln(ans);\n}\n\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n auto a = readln.split.to!(int[]);\n\n long ans;\n\n sort(a);\n\n foreach (i ; 0 .. n) {\n if(i + 1 > a[i]) {\n ans += i + 1 - a[i];\n }\n else {\n ans += a[i] - i - 1;\n }\n }\n\n writeln(ans);\n}\n\n\nvoid readVars(T...)(auto ref T args)\n{\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "module sigod.codeforces.p285C;\n\nimport std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n\tint n;\n\tstdin.readf(\"%s\", &n);\n\n\tstdin.readln();\n\tlong[] a = read_array!(long)();\n\n\tsort(a);\n\n\tlong result = 0;\n\n\tforeach (i, ai; a) {\n\t\tresult += abs(ai - (i + 1));\n\t}\n\n\tstdout.writeln(result);\n}\n\nprivate\nT[] read_array(T)()\n{\n\tauto input = stdin.readln().strip().split();\n\n\tT[] result = new T[input.length];\n\n\tforeach (index, ref element; input) {\n\t\tresult[index] = element.to!T();\n\t}\n\n\treturn result;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\n/*\nint myabs(int a) {\n if (a < 0) return -a;\n return a;\n}\n*/\nvoid main() {\n int n;\n scanf(\"%d\",&n);\n int[] a = new int[n];\n for (int i = 0 ; i < n ; ++i)\n scanf(\"%d\",&a[i]);\n sort(a);\n int ans = 0;\n foreach (int idx, ele ; a) {\n ans += abs(idx-ele+1);\n }\n writef(\"%d\\n\", ans);\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\n/*\nint myabs(int a) {\n if (a < 0) return -a;\n return a;\n}\n*/\nvoid main() {\n int n;\n scanf(\"%d\",&n);\n int[] a = new int[n];\n for (int i = 0 ; i < n ; ++i)\n scanf(\"%d\",&a[i]);\n sort(a);\n int ans = 0;\n foreach (int idx, ele ; a) {\n ans += abs(idx-ele+1);\n }\n printf(\"%d\\n\", ans);\n}\n\n"}], "src_uid": "86d5da999415fa75b3ee754a2a28605c"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n// Main Logic Here\nvoid play(){\n dchar[] word = rd!(dchar[]);\n ll bal0 = 0, bal1 = 0;\n ll pair0 = 0, pair1 = 0;\n foreach(cr; word){\n show(cr, pair0, pair1);\n if(cr == '('){\n ++bal0;\n }else if(cr == '['){\n ++bal1;\n }else if(cr == ')'){\n if(bal0 > 0) ++pair0;\n --bal0;\n }else if(cr==']'){\n if(bal1 > 0) ++pair1;\n --bal1;\n }\n bal0 = max(bal0, 0);\n bal1 = max(bal1, 0);\n }\n writeln(pair1 + pair0);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle for testcases!\n while(t--) play(); // Let's play!\n return 0;\n}\n\n/**********That's All Folks!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp; // Read input\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nalias ll = long;\nalias tup = Tuple!(long, \"x\", long, \"y\");\nvoid show(A...)(A a) { debug{ foreach(t; a){ stderr.write(t, \"| \"); } stderr.writeln; } } // Debug\n/* Add if TLE, T max(T = long)(T a, T b){ return (a > b) ? a : b; } */\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nauto go (string s, string c)\n{\n\tchar [] stack = \"**\".dup;\n\tforeach (ref e; s.filter !(e => c.canFind (e)))\n\t{\n\t\tstack.assumeSafeAppend ();\n\t\tstack ~= e;\n\t\tif (stack[$ - 2..$] == c)\n\t\t{\n\t\t\tstack.popBackN (2);\n\t\t}\n\t}\n\treturn stack.length.to !(int) - 2;\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\t\twriteln ((s.length - s.go (\"()\") - s.go (\"[]\")) / 2);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\n\t\tlong cnt1, cnt2;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == ')')\n\t\t\t{\n\t\t\t\tif (cnt1 > 0)\n\t\t\t\t{\n\t\t\t\t\t--cnt1;\n\t\t\t\t\t++ans[ti];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (c == '(')\n\t\t\t{\n\t\t\t\t++cnt1;\n\t\t\t}\n\t\t\telse if (c == ']')\n\t\t\t{\n\t\t\t\tif (cnt2 > 0)\n\t\t\t\t{\n\t\t\t\t\t--cnt2;\n\t\t\t\t\t++ans[ti];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t++cnt2;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n// Main Logic Here\nvoid play(){\n dchar[] word = rd!(dchar[]);\n ll bal0 = 0, bal1 = 0;\n ll pair0 = 0, pair1 = 0;\n foreach(cr; word){\n show(cr, pair0, pair1);\n if(cr == '('){\n ++bal0;\n }else if(cr == '['){\n ++bal1;\n }else if(cr == ')'){\n if(bal0 > 0) ++pair0;\n --bal0;\n }else if(cr==']'){\n if(bal1 > 0) ++pair1;\n --bal1;\n }\n }\n writeln(pair1 + pair0);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle for testcases!\n while(t--) play(); // Let's play!\n return 0;\n}\n\n/**********That's All Folks!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp; // Read input\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nalias ll = long;\nalias tup = Tuple!(long, \"x\", long, \"y\");\nvoid show(A...)(A a) { debug{ foreach(t; a){ stderr.write(t, \"| \"); } stderr.writeln; } } // Debug\n/* Add if TLE, T max(T = long)(T a, T b){ return (a > b) ? a : b; } */\n"}], "src_uid": "db9cec57d8ed5e914818ce9b439eb0f9"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.stdio;\n\nimmutable int infinity = int.max / 4;\nimmutable int totalLevels = 9;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto src = new int [n];\n\t\tauto dst = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &src[i], &dst[i]);\n\t\t}\n\t\tsrc[] -= 1;\n\t\tdst[] -= 1;\n\n\t\talias State = int [4];\n\t\tState [] states;\n\t\tint [State] stateNum;\n\t\tforeach (a; NA..totalLevels)\n\t\t{\n\t\t\tforeach (b; a..totalLevels)\n\t\t\t{\n\t\t\t\tforeach (c; b..totalLevels)\n\t\t\t\t{\n\t\t\t\t\tforeach (d; c..totalLevels)\n\t\t\t\t\t{\n\t\t\t\t\t\tState state = [a, b, c, d];\n\t\t\t\t\t\tdo\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstateNum[state] =\n\t\t\t\t\t\t\t states.length\n\t\t\t\t\t\t\t .to !(int);\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (nextPermutation\n\t\t\t\t\t\t (state[]));\n\t\t\t\t\t\tstates ~= state;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\timmutable int totalStates = 715;\n\t\tassert (totalStates == states.length);\n\n\t\tauto f = new int [totalLevels] [] [] (n + 1, totalStates);\n\t\tforeach (i; 0..n + 1)\n\t\t{\n\t\t\tforeach (stateIndex; 0..totalStates)\n\t\t\t{\n\t\t\t\tf[i][stateIndex][] = infinity;\n\t\t\t}\n\t\t}\n\t\tf[0][0][0] = 0;\n\n\t\tint res = infinity;\n\t\tforeach (i; 0..n + 1)\n\t\t{\n\t\t\tforeach_reverse (stateIndex; 0..totalStates)\n\t\t\t{\n\t\t\t\tauto curState = states[stateIndex];\n\t\t\t\tforeach (level; 0..totalLevels)\n\t\t\t\t{\n\t\t\t\t\tauto cur = f[i][stateIndex][level];\n\t\t\t\t\tif (cur >= infinity)\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tforeach (j, v; curState)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (v == NA)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tauto nextValue = cur + abs\n\t\t\t\t\t\t (level - v) + 1;\n\t\t\t\t\t\tauto nextState = curState;\n\t\t\t\t\t\tnextState[j] = NA;\n\t\t\t\t\t\tauto nextIndex =\n\t\t\t\t\t\t stateNum[nextState];\n\t\t\t\t\t\tf[i][nextIndex][v] =\n\t\t\t\t\t\t min (f[i][nextIndex][v],\n\t\t\t\t\t\t nextValue);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (i < n && curState[0] == NA)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto u = src[i];\n\t\t\t\t\t\tauto nextValue = cur + abs\n\t\t\t\t\t\t (level - u) + 1;\n\t\t\t\t\t\tauto nextState = curState;\n\t\t\t\t\t\tnextState[0] = dst[i];\n\t\t\t\t\t\tauto nextIndex =\n\t\t\t\t\t\t stateNum[nextState];\n\t\t\t\t\t\tf[i + 1][nextIndex][u] =\n\t\t\t\t\t\t min (f[i + 1][nextIndex]\n\t\t\t\t\t\t [u], nextValue);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (minElement (f[n][0][]));\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n immutable int INF = 1 << 29;\n\n int[] unfold(int n) {\n return [n / 1000 % 10, n / 100 % 10, n / 10 % 10, n % 10];\n }\n\n int fold(int[] a) {\n int[] b = a.dup;\n b.sort!\"a > b\";\n return b[0] + b[1] * 10 + b[2] * 100 + b[3] * 1000;\n }\n \n auto N = readln.chomp.to!int;\n auto src = new int[](N);\n auto dst = new int[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!int);\n src[i] = s[0];\n dst[i] = s[1];\n }\n\n auto dp = new int[][](N+1, 10000);\n foreach (i; 0..N+1) dp[i].fill(INF);\n dp[0][0] = 0;\n\n foreach (i; 0..N) {\n int cur = i == 0 ? 1 : src[i-1];\n int tar = src[i];\n foreach (a; 0..10) {\n foreach (b; a..10) {\n foreach (c; b..10) {\n foreach (d; c..10) {\n foreach (k; 1..10) {\n if (dp[i][d + c*10 + b*100 + a*1000] >= INF) continue;\n int hi = max(cur, tar, k);\n int lo = min(cur, tar, k);\n int[] v = [a, b, c, d];\n int cost = 1;\n foreach (j; 0..4) if (lo <= v[j] && v[j] <= hi) v[j] = 0, cost += 1;\n int z = -1;\n foreach (j; 0..4) if (v[j] == 0) z = j;\n if (z == -1) continue;\n v[z] = dst[i];\n int dist = abs(cur - k) + abs(k - tar);\n int fv = fold(v);\n dp[i+1][fv] = min(dp[i+1][fv], dp[i][d + c*10 + b*100 + a*1000] + dist + cost);\n }\n }\n }\n }\n }\n }\n\n\n int ans = INF;\n \n foreach (a; 0..10) {\n foreach (b; a..10) {\n foreach (c; b..10) {\n foreach (d; c..10) {\n int[] v = [a, b, c, d];\n if (v.all!\"a == 0\") {\n ans = min(ans, dp[N][0]);\n continue;\n }\n int hi = (src.back, v.filter!\"a != 0\".reduce!max);\n int lo = (src.back, v.filter!\"a != 0\".reduce!min);\n int cost = (a != 0) + (b != 0) + (c != 0) + (d != 0);\n int dist = min(abs(src.back - hi) + abs(hi - lo), abs(src.back - lo) + abs(lo - hi));\n ans = min(ans, dp[N][fold([a, b, c, d])] + dist + cost);\n }\n }\n }\n }\n\n ans.writeln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n immutable int INF = 1 << 29;\n\n int[] unfold(int n) {\n return [n / 1000 % 10, n / 100 % 10, n / 10 % 10, n % 10];\n }\n\n int fold(int[] a) {\n int[] b = a.dup;\n b.sort!\"a > b\";\n return b[0] + b[1] * 10 + b[2] * 100 + b[3] * 1000;\n }\n \n auto N = readln.chomp.to!int;\n auto src = new int[](N);\n auto dst = new int[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!int);\n src[i] = s[0];\n dst[i] = s[1];\n }\n\n auto dp = new int[][](N+1, 10000);\n foreach (i; 0..N+1) dp[i].fill(INF);\n dp[0][0] = 0;\n\n foreach (i; 0..N) {\n int cur = i == 0 ? 1 : src[i-1];\n int tar = src[i];\n foreach (a; 0..10) {\n foreach (b; a..10) {\n foreach (c; b..10) {\n foreach (d; c..10) {\n foreach (k; 1..10) {\n int[] v = [a, b, c, d];\n int fv = fold(v);\n if (dp[i][fv] >= INF) continue;\n int hi = max(cur, tar, k);\n int lo = min(cur, tar, k);\n int cost = 1;\n foreach (j; 0..4) if (lo <= v[j] && v[j] <= hi) v[j] = 0, cost += 1;\n int z = -1;\n foreach (j; 0..4) if (v[j] == 0) z = j;\n if (z == -1) continue;\n v[z] = dst[i];\n int dist = abs(cur - k) + abs(k - tar);\n dp[i+1][fv] = min(dp[i+1][fv], dp[i][d + c*10 + b*100 + a*1000] + dist + cost);\n }\n }\n }\n }\n }\n }\n\n\n int ans = INF;\n \n foreach (a; 0..10) {\n foreach (b; a..10) {\n foreach (c; b..10) {\n foreach (d; c..10) {\n int[] v = [a, b, c, d];\n if (v.all!\"a == 0\") {\n ans = min(ans, dp[N][0]);\n continue;\n }\n int hi = (src.back, v.filter!\"a != 0\".reduce!max);\n int lo = (src.back, v.filter!\"a != 0\".reduce!min);\n int cost = (a != 0) + (b != 0) + (c != 0) + (d != 0);\n int dist = min(abs(src.back - hi) + abs(hi - lo), abs(src.back - lo) + abs(lo - hi));\n ans = min(ans, dp[N][fold([a, b, c, d])] + dist + cost);\n }\n }\n }\n }\n\n ans.writeln;\n}\n"}], "src_uid": "f6be5319ad3733d07a8ffd089fc44c71"} {"source_code": "import std.stdio;\nimport std.container;\nimport std.typecons;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tint x = readInt!int;\n\tauto h = new int[](n); foreach(ref hi; h) hi = readInt!int;\n\tauto queue = redBlackTree!(Tuple!(int, size_t))();\n\tauto cnt = new int[](m);\n\tauto bucket = new size_t[](n);\n\tbucket[] = -1;\n\tforeach(i, cnti; cnt) queue.insert(tuple(cnti, i));\n\tforeach(i, ref hi; h)\n\t{\n\t\tauto nextPlaceT = queue.front; queue.removeFront;\n\t\tauto nextBucket = nextPlaceT[1];\n\t\tbucket[i] = nextBucket + 1;\n\t\tcnt[nextPlaceT[1]] += hi;\n\t\tqueue.insert(tuple(cnt[nextPlaceT[1]], nextPlaceT[1]));\n\t}\n\t\"YES\".writeln;\n\tforeach(bi; bucket) bi.write(\" \");\n\twriteln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.typecons, std.container, std.range;\n\nvoid main() {\n int t;\n readf!\" %d\"(t);\n \n while (t--) {\n writeln(\"YES\");\n int n, m, x;\n readf!\" %d %d %d\\n\"(n, m, x);\n \n auto heap = iota(m).map!\"tuple(0L, a + 1)\".array.heapify!\"a > b\";\n \n foreach (h; readln.split.map!\"a.to!int\") {\n auto tower = heap.front;\n tower[0] += h;\n write(tower[1], ' ');\n heap.replaceFront(tower);\n }\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.container;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m, x;\r\n\t\treadf !(\" %s %s %s\") (n, m, x);\r\n\t\treadln;\r\n\t\tauto h = readln.splitter.map !(to !(int)).array;\r\n\t\tauto y = new int [m];\r\n\t\tauto t = redBlackTree !((i, j) => y[i] < y[j], true)\r\n\t\t (m.iota.array);\r\n\t\tauto answer = new int [n];\r\n\t\tforeach (i, ref c; h)\r\n\t\t{\r\n\t\t\tauto p = t.front;\r\n\t\t\tt.removeFront ();\r\n\t\t\ty[p] += c;\r\n\t\t\tanswer[i] = p + 1;\r\n\t\t\tt.insert (p);\r\n\t\t}\r\n\t\twriteln (\"YES\");\r\n\t\twritefln !(\"%(%s %)\") (answer);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\nimport std.container.rbtree;\r\nimport std.range;\r\nimport std.container.binaryheap;\r\nimport std.typecons;\r\n\r\nvoid main()\r\n{\r\n auto t = to!long(readln().chomp);\r\n OUTER: foreach(_; 0..t)\r\n {\r\n auto params = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int n = params[0];\r\n int m = params[1];\r\n int x = params[2];\r\n \r\n auto arr = readln().chomp.splitter(\" \").map!(to!long).array;\r\n \r\n int cur = 0;\r\n auto h = heapify!\"a[0] > b[0]\"([[0L, 1L]]);\r\n \r\n foreach(i; 2..m+1)\r\n {\r\n h.insert([0L, to!long(i)]);\r\n }\r\n \r\n foreach (int i; 0..n)\r\n {\r\n auto ar = h.front;\r\n h.removeFront();\r\n h.insert([arr[i]+ar[0], ar[1]]);\r\n arr[i] = ar[1];\r\n }\r\n \r\n writeln(\"YES\");\r\n writeln(arr.map!(to!string).joiner(\" \"));\r\n }\r\n}"}], "negative_code": [], "src_uid": "57df7947bb90328f543b984833a78e64"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto TB = N.iota.map!(_ => readln.split.map!(to!long).array).array;\n TB.sort!\"a[1] > b[1]\";\n\n auto pq = new BinaryHeap!(Array!long, \"a > b\");\n long tmp = 0;\n long ans = 0;\n\n for (int i = 0; i < N; ) {\n long b = TB[i][1];\n while (i < N && TB[i][1] == b) {\n pq.insert(TB[i][0]);\n tmp += TB[i][0];\n if (pq.length > K) {\n tmp -= pq.front;\n pq.removeFront;\n }\n ++i;\n }\n ans = max(ans, tmp * b);\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\nimport std.container.rbtree;\n\nalias S = Tuple!(long, \"t\", long, \"b\");\n\nS[10^^5*3] SS;\n\nlong[10^^5*3] MIN_P;\n\nvoid main()\n{\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n\n foreach (i; 0..N) {\n auto tb = readln.split.to!(long[]);\n SS[i] = S(tb[0], tb[1]);\n }\n\n sort!\"a.b > b.b\"(SS[0..N]);\n\n long t, p, r;\n auto tree = redBlackTree!true(0L);\n foreach (i; 0..N) {\n if (!tree.front) tree.removeFront();\n t += SS[i].t;\n tree.insert(SS[i].t);\n if (tree.length > K) {\n t -= tree.front;\n tree.removeFront();\n }\n r = max(r, t * SS[i].b);\n }\n\n writeln(r);\n}"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\nimport std.container.rbtree;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!uint;\n immutable k = r.next!uint;\n auto a = uninitializedArray!(Tuple!(uint, uint)[]) (n);\n auto c = uninitializedArray!(uint[]) (n);\n foreach (i, ref p; a) {\n auto l = r.next!uint;\n auto b = r.next!uint;\n p = tuple (b, l);\n c[i] = l;\n }\n c.sort ();\n auto t1 = new RedBlackTree!(int, \"a < b\", true) ();\n auto t2 = new RedBlackTree!(int, \"a < b\", true) ();\n long s; \n foreach (i; 0 .. k) {\n t2.insert (c[n-1-i]);\n s += c[n-1-i];\n }\n foreach (i; k .. n) {\n t1.insert (c[n-1-i]);\n }\n a.sort ();\n debug stderr.writeln (a);\n debug stderr.writeln (c);\n\n long res = long.min;\n foreach (i; 0 .. n) {\n int x = a[i][0];\n res = max (res, x * s);\n //remove p[i][1]\n int w = a[i][1];\n auto e = t1.equalRange (w);\n if (e.empty) {\n s -= w;\n t2.removeKey (w);\n if (t1.empty) {\n } else {\n int v = t1.back;\n t1.removeBack ();\n t2.insert (v);\n s += v;\n }\n } else {\n t1.removeKey (w);\n }\n }\n writeln (res);\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto TB = N.iota.map!(_ => readln.split.map!(to!long).array).array;\n TB.sort!\"a[1] > b[1]\";\n\n auto pq = new BinaryHeap!(Array!long, \"a < b\");\n long tmp = 0;\n long ans = 0;\n\n for (int i = 0; i < N; ) {\n long b = TB[i][1];\n while (i < N && TB[i][1] == b) {\n pq.insert(TB[i][0]);\n tmp += TB[i][0];\n if (pq.length > K) {\n tmp -= pq.front;\n pq.removeFront;\n }\n ++i;\n }\n ans = max(ans, tmp * b);\n }\n\n ans.writeln;\n}\n"}], "src_uid": "6b85a1fefb03566fbc557b98d1dfd7ef"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\talias Segment = Tuple !(int, q{len}, int, q{start});\n\t\tauto t = redBlackTree !(Segment);\n\t\tt.insert (Segment (-(n - 1), 0));\n\t\tauto a = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto lo = t.front.start;\n\t\t\tauto hi = t.front.start - t.front.len;\n\t\t\tt.removeFront ();\n\t\t\tauto me = (lo + hi) / 2;\n\t\t\ta[me] = i + 1;\n\t\t\tt.insert (Segment (-(me - lo - 1), lo));\n\t\t\tt.insert (Segment (-(hi - me - 1), me + 1));\n\t\t}\n\t\twritefln !(\"%(%s %)\") (a);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tans[ti].length = n;\n\n\t\tBinaryHeap!(Array!(int[]), \"a[1]-a[0] == b[1]-b[0] ? a[0] > b[0] : a[1]-a[0] < b[1]-b[0]\") heap;\n\t\theap.insert([0, n]);\n\t\tint i = 1;\n\t\twhile (!heap.empty)\n\t\t{\n\t\t\tauto nd = heap.front; heap.popFront;\n\t\t\tauto l = nd[0];\n\t\t\tauto r = nd[1];\n\t\t\tauto m = (l+r-1)/2;\n\t\t\tans[ti][m] = i;\n\t\t\t++i;\n\t\t\tif (r-l == 1) continue;\n\t\t\telse if (r-l == 2)\n\t\t\t{\n\t\t\t\theap.insert([m+1, r]);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\theap.insert([l, m]);\n\t\t\t\theap.insert([m+1, r]);\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "25fbe21a449c1ab3eb4bdd95a171d093"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n\r\n bool C(int k) {\r\n auto X = A.dup;\r\n sort!\"a>b\"(X);\r\n int i = 0, j = N;\r\n for (int t = k; t >= 1; t--) {\r\n while (i < j && X[i] > t) {\r\n i++;\r\n }\r\n if (i >= j) return false;\r\n i++;\r\n // turn of B\r\n j--;\r\n }\r\n return true;\r\n }\r\n\r\n for (int k = 1; ; k++) {\r\n if (! C(k)) {\r\n writeln(k - 1);\r\n return;\r\n }\r\n }\r\n\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\r\n\t\tbool ok (int k)\r\n\t\t{\r\n\t\t\tint cur = k;\r\n\t\t\tint pos = 0;\r\n\t\t\tfor (int i = n - 1; i >= pos; i--)\r\n\t\t\t{\r\n\t\t\t\tif (i < pos)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tif (a[i] <= cur)\r\n\t\t\t\t{\r\n\t\t\t\t\tcur -= 1;\r\n\t\t\t\t\tpos += 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn cur == 0;\r\n\t\t}\r\n\r\n\t\tint lo = 0;\r\n\t\tint hi = n + 1;\r\n\t\twhile (hi - lo > 1)\r\n\t\t{\r\n\t\t\tint me = (lo + hi) / 2;\r\n\t\t\tif (ok (me))\r\n\t\t\t{\r\n\t\t\t\tlo = me;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\thi = me;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (lo);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\n// returns true if Alice wins\nbool solve(int[] a, int k)\n{\n foreach_reverse (i ; 1 .. k + 1) {\n // Alice turn\n while (a.length > 0 && a.back > i)\n a = a[0 .. $ - 1];\n if (a.empty)\n return false;\n a = a[0 .. $ - 1];\n if (a.length > 0)\n a = a[1 .. $];\n }\n return true;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = readln.splitter.map!(to!int).array.sort.array;\n writeln(iota(0, n + 105).map!(k => !solve(a, k)).assumeSorted.lowerBound(true).length - 1);\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\n// returns tru if Alice wins\nbool solve(int[] a, int k)\n{\n foreach_reverse (i ; 1 .. k + 1) {\n // Alice turn\n while (a.length > 0 && a.back > k)\n a = a[0 .. $ - 1];\n if (a.empty)\n return false;\n a = a[0 .. $ - 1];\n // Bob turn\n if (a.length > 0)\n a = a[1 .. $];\n }\n return true;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = readln.splitter.map!(to!int).array.sort.array;\n int k = 0;\n while (solve(a, k)) {\n k++;\n }\n writeln(k - 1);\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\n// returns tru if Alice wins\nbool solve(int[] a, int k)\n{\n foreach_reverse (i ; 1 .. k + 1) {\n // Alice turn\n while (a.length > 0 && a.back > k)\n a = a[0 .. $ - 1];\n if (a.empty)\n return false;\n a = a[0 .. $ - 1];\n if (a.length > 0)\n a = a[1 .. $];\n }\n return true;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = readln.splitter.map!(to!int).array.sort.array;\n writeln(iota(0, n + 105).map!(k => !solve(a, k)).assumeSorted.lowerBound(true).length - 1);\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\n// returns tru if Alice wins\nbool solve(int[] a, int k)\n{\n foreach_reverse (i ; 1 .. k + 1) {\n while (a.length > 0 && a.back > k)\n a = a[0 .. $ - 1];\n if (a.empty)\n return false;\n a = a[0 .. $ - 1];\n if (a.length > 0)\n a = a[1 .. $];\n }\n return true;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto a = readln.splitter.map!(to!int).array.sort.array;\n writeln(iota(1, n + 5).map!(k => !solve(a, k)).assumeSorted.lowerBound(true).length);\n }\n}\n"}], "src_uid": "0682d5ee1b5b160ece449c4676a369a7"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n double l = cin.readDouble;\n double p = cin.readDouble;\n double q = cin.readDouble;\n writeln(p * (l / (p + q)));\n\n } \n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nvoid main()\n{\n\tdouble a,b,c;\n\treadf(\"%f\\n%f\\n%f\\n\",&a,&b,&c);\n\twriteln(a*b/(b+c));\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n int l, p, q;\n while (readf (\" %s %s %s\", &l, &p, &q) > 0)\n {\n writeln (l * p * 1.0 / (p + q));\n }\n}\n"}], "negative_code": [], "src_uid": "6421a81f85a53a0c8c63fbc32750f77f"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int N = read!int;\r\n auto s = read!string;\r\n\r\n //auto rmlz() {\r\n {\r\n int k = 0;\r\n while (s[k] == '0' && k < N - 1) k++;\r\n s = s[k .. $];\r\n }\r\n N = cast(int)(s.length);\r\n\r\n int lo = 0;\r\n for (int i = 0; i < N; i++) {\r\n if (s[i] == '1') {\r\n lo++;\r\n } else {\r\n break;\r\n }\r\n }\r\n\r\n string f(string b) {\r\n char z(char x, char y) {\r\n if (x == '1' || y == '1') return '1';\r\n else return '0';\r\n }\r\n int m = cast(int)(b.length);\r\n auto r = new char[N];\r\n for (int i = 0; i < N; i++) {\r\n if (i < N - m) {\r\n r[i] = s[i] ;\r\n } else {\r\n r[i] = z(s[i], b[i - N + m]);\r\n }\r\n }\r\n return r.idup;\r\n }\r\n\r\n string ans = s;\r\n for (int k = 1; k <= lo; k++) {\r\n auto s2 = s[0 .. $ - k];\r\n auto cand = f(s2);\r\n ans = max(ans, cand);\r\n }\r\n\r\n writeln(ans);\r\n}\r\n\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nint[] solve(int[] a, int[] n2)\n{\n int[] offs;\n foreach (i ; 0 .. cast(int)n2.length)\n if (n2[i])\n offs ~= i;\n int best_i = -1, best_score = -1;\n foreach (i ; 0 .. cast(int)(a.length - n2.length + 1)) {\n int score = 0;\n foreach (j ; offs) {\n if (a[i + j] == 1)\n score++;\n else\n break;\n }\n if (score > best_score) {\n best_i = i;\n best_score = score;\n } else if (score == best_score) {\n bool better = false;\n foreach (j ; offs[score .. $]) {\n if (a[i + j] == a[best_i + j])\n continue;\n if (a[i + j] == 1)\n better = true;\n break;\n }\n if (better) {\n best_i = i;\n best_score = score;\n }\n }\n }\n return a[best_i .. best_i + n2.length];\n}\n\nvoid main()\n{\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.splitter(\"\").map!(to!int).array;\n auto n1 = a.find(1).array;\n auto n2 = n1.map!(x => x ^ 1).find(1).array;\n\n if (n1.empty) {\n writeln(0);\n return;\n }\n\n while (true) {\n if (n2.empty)\n break;\n auto tmp = solve(a, n2);\n if (tmp[0] == 0) {\n n2 = n2[1 .. $];\n while (!n2.empty && n2[0] == 0)\n n2 = n2[1 .. $];\n } else {\n foreach (i ; 0 .. tmp.length) {\n n1[$ - i - 1] |= tmp[$ - i - 1];\n }\n break;\n }\n }\n\n writeln(n1.map!text.joiner(\"\"));\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nint[] solve(int[] a, int[] n2)\n{\n int[] offs;\n foreach (i ; 0 .. cast(int)n2.length)\n if (n2[i])\n offs ~= i;\n int best_i = -1, best_score = -1;\n foreach (i ; 0 .. cast(int)(a.length - n2.length + 1)) {\n int score = 0;\n foreach (j ; offs) {\n if (a[i + j] == 1)\n score++;\n else\n break;\n }\n if (score > best_score) {\n best_i = i;\n best_score = score;\n }\n }\n return a[best_i .. best_i + n2.length];\n}\n\nvoid main()\n{\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.splitter(\"\").map!(to!int).array;\n auto n1 = a.find(1).array;\n auto n2 = n1.map!(x => x ^ 1).find(1).array;\n\n if (n1.empty) {\n writeln(0);\n return;\n }\n\n while (true) {\n if (n2.empty)\n break;\n auto tmp = solve(a, n2);\n if (tmp[0] == 0) {\n n2 = n2[1 .. $];\n while (!n2.empty && n2[0] == 0)\n n2 = n2[1 .. $];\n } else {\n foreach (i ; 0 .. tmp.length) {\n n1[$ - i - 1] |= tmp[$ - i - 1];\n }\n break;\n }\n }\n\n writeln(n1.map!text.joiner(\"\"));\n}\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid main() {\r\n int N = read!int;\r\n auto s = read!string;\r\n\r\n int lo = 0;\r\n for (int i = 0; i < N; i++) {\r\n if (s[i] == '1') {\r\n lo++;\r\n } else {\r\n break;\r\n }\r\n }\r\n\r\n string f(string b) {\r\n char z(char x, char y) {\r\n if (x == '1' || y == '1') return '1';\r\n else return '0';\r\n }\r\n int m = cast(int)(b.length);\r\n auto r = new char[N];\r\n for (int i = 0; i < N; i++) {\r\n if (i < N - m) {\r\n r[i] = s[i] ;\r\n } else {\r\n r[i] = z(s[i], b[i - N + m]);\r\n }\r\n }\r\n return r.idup;\r\n }\r\n\r\n string ans = s;\r\n for (int k = 1; k <= lo; k++) {\r\n auto s2 = s[0 .. $ - k];\r\n auto cand = f(s2);\r\n ans = max(ans, cand);\r\n }\r\n writeln(ans);\r\n}\r\n\r\n"}], "src_uid": "7f855479e9df3405bb29f2a0cb1cb3b3"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tlong res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto lo = 0;\r\n\t\t\tif (i > 0)\r\n\t\t\t{\r\n\t\t\t\tlo = max (lo, a[i - 1]);\r\n\t\t\t}\r\n\t\t\tif (i + 1 < n)\r\n\t\t\t{\r\n\t\t\t\tlo = max (lo, a[i + 1]);\r\n\t\t\t}\r\n\t\t\tint delta = max (0, a[i] - lo);\r\n\t\t\ta[i] -= delta;\r\n\t\t\tres += delta;\r\n\t\t}\r\n\t\tdebug {writeln (a, \" \", res);}\r\n\t\tres += a[0];\r\n\t\tres += a[n - 1];\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tres += abs (a[i] - a[i - 1]);\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random, std.math;\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.chomp.split.map!(to!int).array;\n int[] b = [0] ~ a ~ [0];\n long result = 0;\n foreach (i ; 1 .. b.length - 1) {\n int diff_l = b[i] - b[i - 1];\n int diff_r = b[i] - b[i + 1];\n if (diff_l > 0 && diff_r > 0) {\n b[i] -= min(diff_l, diff_r);\n result += min(diff_l, diff_r);\n }\n }\n foreach (i ; 1 .. b.length) {\n result += abs(b[i] - b[i - 1]);\n }\n writeln(result);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nvoid solve()\n{\n\tint n = readInt!int;\n\tauto a = new int[](n); \n\tforeach(ref ai; a) ai = readInt!int;\n\ta = 0 ~ a ~ 0;\n\tlong ops = 0;\n\tlong border = 0;\n\tforeach(i; 1 .. n + 1)\n\t{\n\t\tif (a[i] > a[i - 1] && a[i] > a[i + 1])\n\t\t{\n\t\t\tdebug writeln(\"reducing \", i, \" \", a[i]);\n\t\t\tint s = max(a[i - 1], a[i + 1]);\n\t\t\tops += a[i] - s;\n\t\t\ta[i] = cast(int)s;\n\t\t}\n\t\tborder += abs(a[i - 1] - a[i]);\n\t}\n\tborder += a[n];\n\t(border + ops).writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\nimport std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\nmultitest_end:\r\n while(tests--) {\r\n int n; readf!\"%s\\n\"(n);\r\n int[] a = readln.splitter.map!(to!int).array;\r\n long res = 0;\r\n foreach(i; 0 .. n) {\r\n int low = 0;\r\n if(i > 0) {\r\n low = max(low, a[i - 1]);\r\n }\r\n if(i + 1 < n) {\r\n low = max(low, a[i + 1]);\r\n }\r\n int delta = max(0, a[i] - low);\r\n a[i] -= delta;\r\n res += delta;\r\n }\r\n res += a[0];\r\n res += a[n - 1];\r\n foreach(i; 1 .. n) {\r\n res += abs(a[i] - a[i - 1]);\r\n }\r\n res.writeln;\r\n }\r\n\r\n} // main"}], "negative_code": [], "src_uid": "6313b2788fbf58b9b7c70fc85afa4c1c"} {"source_code": "import std.stdio;\nimport std.math;\n\nvoid main() {\n int n, k; scanf(\"%u %u\", &n, &k);\n double t = 0;\n double x, y, px, py;\n scanf(\"%lf %lf\", &px, &py);\n foreach (i; 1 .. n) {\n scanf(\"%lf %lf\", &x, &y);\n double dx = abs(x - px);\n double dy = abs(y - py);\n t += sqrt(dx * dx + dy * dy);\n px = x; py = y;\n }\n printf(\"%.9f\\n\", t / 50 * k);\n}\n", "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\ndouble dist(int x1, int y1, int x2, int y2) {\n double dist = sqrt((x1.to!double - x2.to!double) ^^ 2 + (y1.to!double - y2.to!double) ^^ 2).to!double;\n return dist;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n int n = cin.readInt();\n int k = cin.readInt();\n int[][] points = new int[][](n, 2);\n for (int i = 0; i < n; i++) {\n int a = cin.readInt;\n int b = cin.readInt;\n points[i][0] = a;\n points[i][1] = b;\n }\n double totalDistance = 0;\n for (int i = 1; i < n; i++) {\n totalDistance += dist(points[i][0], points[i][1], points[i - 1][0], points[i - 1][1]);\n }\n double time = k * cast(double)(totalDistance / 50.0);\n writefln(\"%.9f\", time); \n } \n}"}], "negative_code": [], "src_uid": "db4a25159067abd9e3dd22bc4b773385"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nenum long INF = 1L<<40;\r\nvoid solve() {\r\n int N;\r\n long K;\r\n readf(\"%d %d\\n\", &N, &K);\r\n auto A = readarray!long;\r\n sort(A);\r\n long sa = A.reduce!\"a+b\";\r\n long ans = INF;\r\n long s = 0;\r\n for (int y = 0; y < N; y++) {\r\n long x = max(0, ((sa - K - s + A[0] * y) + y) / (y + 1));\r\n ans = min(ans, x + y);\r\n s += A[N - 1 - y];\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto K = scan!long;\r\n auto A = scan!long(N);\r\n\r\n ulong[] acc = [0];\r\n foreach(a; A.sort!\"a > b\") acc ~= acc[$ - 1] + a;\r\n\r\n const spread = A.sum - K;\r\n long ans = long.max;\r\n long minn = A.minElement;\r\n foreach(i; 0..N) {\r\n bool isOK(long n) {\r\n // if (i == N - 1) [i, n, cast(ulong)n + (acc[i] - (minn - n)*i), spread].deb;\r\n return n + (acc[i] - (minn - n)*i) >= spread;\r\n }\r\n const x = max(0, binarySearch(&isOK, spread, -1));\r\n ans = min(ans, x + i);\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n foreach(_; 0..QN) subSolve().writeln;\r\n // (10L^^9).repeat(2*10^^5).array.toAnswerString.writeln;\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}"}, {"source_code": "import std;\n\nvoid main () {\n int tests;\n readf(\"%s\\n\", tests);\n\n foreach (test_idex; 0 .. tests) {\n int n;\n long k;\n readf(\"%s %s\\n\", n, k);\n\n int[] a = new int[n];\n\n k = -k;\n foreach (ref x; a)\n readf(\" %s\", x), k += x;\n readf(\"\\n\");\n a = sort(a).array;\n\n long rem = -a[0];\n int i;\n long turns;\n\n for (i = n - 1; i > 0 && k > 0;) {\n if (a[i] + rem >= n - i) {\n k -= a[i] + rem;\n -- i;\n ++ turns;\n } else {\n //a[i] + x >= n - i\n long x = n - i - a[i] - rem;\n long y = cast(long)ceil(cast(double)k / (n - i));\n\n if (x >= y) {\n turns += y;\n k = 0;\n break;\n }\n k -= (n - i) * x;\n rem += x;\n turns += x;\n }\n }\n\n if (k <= 0) {\n writeln(turns);\n continue;\n }\n\n turns += cast(long)ceil(cast(double)k / n);\n writeln(turns);\n }\n\n}\n// \"\"\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n, k;\n readf!\" %d %d \"(n, k);\n auto a = readln.splitter.map!(to!long).array.sort.array;\n long[] pfa = [0L];\n foreach (x ; a)\n pfa ~= pfa.back + x;\n long best = long.max;\n foreach (swapcnt ; 0 .. n) {\n long newsum = a[0] * swapcnt + pfa[cast(size_t)(n - swapcnt)];\n if (newsum <= k) {\n best = min(best, swapcnt);\n } else {\n best = min(best, swapcnt + (newsum - k + swapcnt) / (swapcnt + 1));\n }\n }\n writeln(best);\n }\n}\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception, \n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nclass RangeSum(T) {\n T[] acc;\n this(T[] data) {\n acc = data.dup;\n foreach (i; 1 .. data.length) {\n acc[i] += acc[i - 1];\n }\n }\n\n T query(int i, int j) {\n if (j < i) return 0;\n auto total = acc[j];\n if (i > 0) total -= acc[i - 1];\n return total; \n }\n}\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n long n, k;\n read(n, k);\n auto arr = list!long;\n sort(arr); \n\n auto r = new RangeSum!long(arr);\n auto total = r.query(0, cast(int)(n) - 1);\n if (total <= k) {\n writeln(0);\n continue;\n }\n\n long answer = total - k;\n\n foreach (i; 1 .. n) {\n auto mid = r.query(1, cast(int)(n - 1 - i));\n auto rem = k - mid;\n auto x = rem / (i + 1) - 5;\n while (mid + ((x + 1) * (i + 1)) <= k) x++;\n long d = max(0, arr[0] - x);\n\n answer = min(answer, d + i);\n }\n\n writeln(answer);\n }\n}\n\n"}], "negative_code": [{"source_code": "void main() { runSolver(); }\n\nvoid problem() {\n auto QN = scan!long;\n\n auto solve() {\n auto subSolve() {\n auto N = scan!int;\n auto K = scan!long;\n auto A = scan!long(N);\n\n long[] acc = [0];\n foreach(a; A.sort!\"a > b\") acc ~= acc[$ - 1] + a;\n\n const spread = A.sum - K;\n if (spread <= 0) return 0;\n\n long ans = long.max;\n long minn = A.minElement;\n foreach(i; 0..N) {\n bool isOK(long n) {\n // [i, n, n + (acc[i] - (minn - n)*i), spread].deb;\n return n + (acc[i] - (minn - n)*i) >= spread;\n }\n const x = binarySearch(&isOK, spread, -1);\n ans = min(ans, x + i);\n // [ans].deb;\n }\n\n return ans;\n }\n\n foreach(_; 0..QN) subSolve().writeln;\n }\n\n outputForAtCoder(&solve);\n}\n\n// ----------------------------------------------\n\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; }\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\nvoid deb(T ...)(T t){ debug writeln(t); }\nalias Point = Tuple!(long, \"x\", long, \"y\");\nPoint invert(Point p) { return Point(p.y, p.x); }\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\nalias MInt1 = ModInt!(10^^9 + 7);\nalias MInt9 = ModInt!(998_244_353);\nvoid outputForAtCoder(T)(T delegate() fn) {\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\n else static if (is(T == void)) fn();\n else static if (is(T == string)) fn().writeln;\n else static if (isInputRange!T) {\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\n else foreach(r; fn()) r.writeln;\n }\n else fn().writeln;\n}\nvoid runSolver() {\n enum BORDER = \"==================================\";\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\n else problem();\n}\nenum YESNO = [true: \"Yes\", false: \"No\"];\n\n// -----------------------------------------------\n\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\n auto ok = l;\n auto ng = r;\n const T TWO = 2;\n \n bool again() {\n static if (is(T == float) || is(T == double) || is(T == real)) {\n return !ng.approxEqual(ok, 1e-08, 1e-08);\n } else {\n return abs(ng - ok) > 1;\n }\n }\n \n while(again()) {\n const half = (ng + ok) / TWO;\n const halfValue = fn(half);\n \n if (cond(halfValue)) {\n ok = half;\n } else {\n ng = half;\n }\n }\n \n return ok;\n}"}, {"source_code": "void main() { runSolver(); }\n\nvoid problem() {\n auto QN = scan!long;\n\n auto solve() {\n auto subSolve() {\n auto N = scan!int;\n auto K = scan!long;\n auto A = scan!long(N);\n\n long[] acc = [0];\n foreach(a; A.sort!\"a > b\") acc ~= acc[$ - 1] + a;\n\n const spread = A.sum - K;\n if (spread <= 0) return 0;\n \n long ans = long.max;\n long minn = A.minElement;\n foreach(i; 0..N) {\n bool isOK(long n) {\n // [i, n, n + (acc[i] - (minn - n)*i), spread].deb;\n return n + (acc[i] - (minn - n)*i) >= spread;\n }\n const x = binarySearch(&isOK, spread, 0);\n ans = min(ans, x + i);\n // [ans].deb;\n }\n\n return ans;\n }\n\n foreach(_; 0..QN) subSolve().writeln;\n }\n\n outputForAtCoder(&solve);\n}\n\n// ----------------------------------------------\n\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; }\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\nvoid deb(T ...)(T t){ debug writeln(t); }\nalias Point = Tuple!(long, \"x\", long, \"y\");\nPoint invert(Point p) { return Point(p.y, p.x); }\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\nalias MInt1 = ModInt!(10^^9 + 7);\nalias MInt9 = ModInt!(998_244_353);\nvoid outputForAtCoder(T)(T delegate() fn) {\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\n else static if (is(T == void)) fn();\n else static if (is(T == string)) fn().writeln;\n else static if (isInputRange!T) {\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\n else foreach(r; fn()) r.writeln;\n }\n else fn().writeln;\n}\nvoid runSolver() {\n enum BORDER = \"==================================\";\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\n else problem();\n}\nenum YESNO = [true: \"Yes\", false: \"No\"];\n\n// -----------------------------------------------\n\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\n auto ok = l;\n auto ng = r;\n const T TWO = 2;\n \n bool again() {\n static if (is(T == float) || is(T == double) || is(T == real)) {\n return !ng.approxEqual(ok, 1e-08, 1e-08);\n } else {\n return abs(ng - ok) > 1;\n }\n }\n \n while(again()) {\n const half = (ng + ok) / TWO;\n const halfValue = fn(half);\n \n if (cond(halfValue)) {\n ok = half;\n } else {\n ng = half;\n }\n }\n \n return ok;\n}"}, {"source_code": "void main() { runSolver(); }\n\nvoid problem() {\n auto QN = scan!long;\n\n auto solve() {\n auto subSolve() {\n auto N = scan!int;\n auto K = scan!long;\n auto A = scan!long(N);\n\n long[] acc = [0];\n foreach(a; A.sort!\"a > b\") acc ~= acc[$ - 1] + a;\n\n const spread = A.sum - K;\n long ans = long.max;\n long minn = A.minElement;\n foreach(i; 0..N) {\n bool isOK(long n) {\n // [i, n, n + (acc[i] - (minn - n)*i), spread].deb;\n return n + (acc[i] - (minn - n)*i) >= spread;\n }\n const x = max(0, binarySearch(&isOK, spread, -1));\n ans = min(ans, x + i);\n // [ans].deb;\n }\n\n return ans;\n }\n\n foreach(_; 0..QN) subSolve().writeln;\n }\n\n outputForAtCoder(&solve);\n}\n\n// ----------------------------------------------\n\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; }\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\nvoid deb(T ...)(T t){ debug writeln(t); }\nalias Point = Tuple!(long, \"x\", long, \"y\");\nPoint invert(Point p) { return Point(p.y, p.x); }\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\nalias MInt1 = ModInt!(10^^9 + 7);\nalias MInt9 = ModInt!(998_244_353);\nvoid outputForAtCoder(T)(T delegate() fn) {\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\n else static if (is(T == void)) fn();\n else static if (is(T == string)) fn().writeln;\n else static if (isInputRange!T) {\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\n else foreach(r; fn()) r.writeln;\n }\n else fn().writeln;\n}\nvoid runSolver() {\n enum BORDER = \"==================================\";\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\n else problem();\n}\nenum YESNO = [true: \"Yes\", false: \"No\"];\n\n// -----------------------------------------------\n\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\n auto ok = l;\n auto ng = r;\n const T TWO = 2;\n \n bool again() {\n static if (is(T == float) || is(T == double) || is(T == real)) {\n return !ng.approxEqual(ok, 1e-08, 1e-08);\n } else {\n return abs(ng - ok) > 1;\n }\n }\n \n while(again()) {\n const half = (ng + ok) / TWO;\n const halfValue = fn(half);\n \n if (cond(halfValue)) {\n ok = half;\n } else {\n ng = half;\n }\n }\n \n return ok;\n}"}, {"source_code": "void main() { runSolver(); }\n\nvoid problem() {\n auto QN = scan!long;\n\n auto solve() {\n auto subSolve() {\n auto N = scan!int;\n auto K = scan!long;\n auto A = scan!long(N);\n\n auto summ = A.sum;\n if (summ <= K) return 0;\n\n long[] acc = [0];\n foreach(a; A.sort!\"a > b\") acc ~= acc[$ - 1] + a;\n\n const spread = summ - K;\n long ans = long.max;\n long minn = A.minElement;\n foreach(i; 0..N) {\n bool isOK(long n) {\n // [i, n, n + (acc[i] - (minn - n)*i), spread].deb;\n return n + (acc[i] - (minn - n)*i) >= spread;\n }\n const x = binarySearch(&isOK, 10L^^18, 0);\n ans = min(ans, x + i);\n }\n\n return ans;\n }\n\n foreach(_; 0..QN) subSolve().writeln;\n }\n\n outputForAtCoder(&solve);\n}\n\n// ----------------------------------------------\n\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; }\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\nvoid deb(T ...)(T t){ debug writeln(t); }\nalias Point = Tuple!(long, \"x\", long, \"y\");\nPoint invert(Point p) { return Point(p.y, p.x); }\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\nalias MInt1 = ModInt!(10^^9 + 7);\nalias MInt9 = ModInt!(998_244_353);\nvoid outputForAtCoder(T)(T delegate() fn) {\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\n else static if (is(T == void)) fn();\n else static if (is(T == string)) fn().writeln;\n else static if (isInputRange!T) {\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\n else foreach(r; fn()) r.writeln;\n }\n else fn().writeln;\n}\nvoid runSolver() {\n enum BORDER = \"==================================\";\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\n else problem();\n}\nenum YESNO = [true: \"Yes\", false: \"No\"];\n\n// -----------------------------------------------\n\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\n auto ok = l;\n auto ng = r;\n const T TWO = 2;\n \n bool again() {\n static if (is(T == float) || is(T == double) || is(T == real)) {\n return !ng.approxEqual(ok, 1e-08, 1e-08);\n } else {\n return abs(ng - ok) > 1;\n }\n }\n \n while(again()) {\n const half = (ng + ok) / TWO;\n const halfValue = fn(half);\n \n if (cond(halfValue)) {\n ok = half;\n } else {\n ng = half;\n }\n }\n \n return ok;\n}"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception, \n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nclass RangeSum(T) {\n T[] acc;\n this(T[] data) {\n acc = data.dup;\n foreach (i; 1 .. data.length) {\n acc[i] += acc[i - 1];\n }\n }\n\n T query(int i, int j) {\n if (j < i) return 0;\n auto total = acc[j];\n if (i > 0) total -= acc[i - 1];\n return total; \n }\n}\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n long n, k;\n read(n, k);\n auto arr = list!long;\n sort(arr); \n\n auto r = new RangeSum!long(arr);\n\n bool good(int dec, int change) {\n long a = arr[0] - dec;\n long b = r.query(1, cast(int)(n) - 1 - change);\n long c = change * a;\n return a + b + c <= k;\n }\n\n long answer = long.max;\n\n foreach (i; 0 .. n) {\n int b = 200000000;\n int a = 0;\n\n if (good(0, i.to!int)) { answer = min(answer, i); }\n\n while (b > a + 1) {\n int mid = (b + a) / 2;\n if (good(mid, i.to!int)) b = mid;\n else a = mid;\n }\n\n answer = min(answer, i + a + 1);\n }\n\n writeln(answer);\n }\n}\n\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception, \n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nclass RangeSum(T) {\n T[] acc;\n this(T[] data) {\n acc = data.dup;\n foreach (i; 1 .. data.length) {\n acc[i] += acc[i - 1];\n }\n }\n\n T query(int i, int j) {\n if (j < i) return 0;\n auto total = acc[j];\n if (i > 0) total -= acc[i - 1];\n return total; \n }\n}\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n long n, k;\n read(n, k);\n auto arr = list!long;\n sort(arr); \n\n auto r = new RangeSum!long(arr);\n\n bool good(int dec, int change) {\n long a = arr[0] - dec;\n long b = r.query(1, cast(int)(n) - 1 - change);\n long c = change * a;\n return a + b + c <= k;\n }\n\n long answer = long.max;\n\n foreach (i; 0 .. n) {\n int b = 100000000;\n int a = 0;\n\n if (good(0, i.to!int)) { answer = min(answer, i); }\n\n while (b > a + 1) {\n int mid = (b + a) / 2;\n if (good(mid, i.to!int)) b = mid;\n else a = mid;\n }\n\n answer = min(answer, i + a + 1);\n }\n\n writeln(answer);\n }\n}\n\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception, \n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nclass RangeSum(T) {\n T[] acc;\n this(T[] data) {\n acc = data.dup;\n foreach (i; 1 .. data.length) {\n acc[i] += acc[i - 1];\n }\n }\n\n T query(int i, int j) {\n if (j < i) return 0;\n auto total = acc[j];\n if (i > 0) total -= acc[i - 1];\n return total; \n }\n}\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n long n, k;\n read(n, k);\n auto arr = list!long;\n sort(arr); \n\n auto r = new RangeSum!long(arr);\n\n bool good(int dec, int change) {\n long a = arr[0] - dec;\n long b = r.query(1, cast(int)(n) - 1 - change);\n long c = change * a;\n return a + b + c <= k;\n }\n\n long answer = long.max;\n\n foreach (i; 0 .. n) {\n int b = 300000;\n int a = 0;\n\n if (good(0, i.to!int)) { answer = min(answer, i); }\n\n while (b > a + 1) {\n int mid = (b + a) / 2;\n if (good(mid, i.to!int)) b = mid;\n else a = mid;\n }\n\n answer = min(answer, i + a + 1);\n }\n\n writeln(answer);\n }\n}\n\n"}], "src_uid": "aec97dc779ba6b1d291fb1031dab93a7"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range, std.math;\n\nlong digits_diff(int x1, int x2)\n{\n auto s1 = to!string(x1).split(\"\").reverse;\n auto s2 = to!string(x2).split(\"\").reverse;\n size_t minl = min(s1.length, s2.length);\n long result = abs(cast(long)s1.length - cast(long)s2.length);\n for (int i = 0; i < minl; i++)\n if (s1[i] != s2[i])\n result += 1;\n return result;\n}\n\nlong solvex(int l, int r)\n{\n long result = 0;\n while ((l < r) && (l % 10 != 0)) {\n result += digits_diff(l, l + 1);\n l += 1;\n }\n\n while (l < r && r % 10 != 0) {\n result += digits_diff(r, r - 1);\n r -= 1;\n }\n\n if (l == r)\n return result;\n\n if ((l % 10 == 0) && (r % 10 == 0)) {\n return result + solvex(l / 10, r / 10) + (r - l);\n }\n\n while (l < r) {\n result += digits_diff(l, l + 1);\n l++;\n }\n\n return result;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int l, r;\n readf!\" %d %d \"(l, r);\n writeln(solvex(l, r));\n }\n}\n", "positive_code": [{"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int ask(int x, int d) {\r\n int pw10 = 10 ^^ d;\r\n int pre = x / pw10;\r\n int suf = x % pw10;\r\n return pre + (suf == pw10 - 1);\r\n }\r\n int tests;\r\n readf!\"%s\\n\"(tests);\r\n foreach(per_test; 0 .. tests) {\r\n int l, r;\r\n readf!\"%s %s\\n\"(l, r);\r\n int ans = r - l;\r\n foreach(i; 1 .. 10) {\r\n ans += (ask(r - 1, i) - ask(l - 1, i));\r\n }\r\n ans.writeln;\r\n }\r\n\r\n} // main"}], "negative_code": [], "src_uid": "7a51d536d5212023cc226ef1f6201174"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tforeach (test; 0..readln.strip.to !(int))\n\t{\n\t\tint rows, cols;\n\t\treadf !(\" %s %s\") (rows, cols);\n\t\treadln;\n\t\tint [] [] board;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tboard ~= readln.splitter.map !(to !(int)).array;\n\t\t}\n\t\tauto moves = min (rows - board.map !(any).sum, cols -\n\t\t cols.iota.map !(i => board.transversal (i)).map !(any).sum);\n\t\twriteln ((moves & 1) ? \"Ashish\" : \"Vivek\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = new long[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] = RDA;\n\t\t}\n\n\t\tlong x, y;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tbool ok = true;\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tif (a[i][j] == 1)\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t\t++x;\n\t\t}\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tbool ok = true;\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tif (a[j][i] == 1)\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t\t++y;\n\t\t}\n\t\tans[ti] = min(x, y) % 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"Ashish\" : \"Vivek\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "3ccc98190189b0c8e58a96dd5ad1245d"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable real infinity = 1E100;\nimmutable real eps = 1E-14;\n\nreal solve (int n)\n{\n\treal xlo, ylo, xhi, yhi;\n\treadf (\" %s %s %s %s\", &xlo, &ylo, &xhi, &yhi);\n\tauto x = new real [n];\n\tauto y = new real [n];\n\tauto vx = new real [n];\n\tauto vy = new real [n];\n\tforeach (i; 0..n)\n\t{\n\t\treadf (\" %s %s %s %s\", &x[i], &y[i], &vx[i], &vy[i]);\n\t}\n\n\treal tlo = 0;\n\treal thi = infinity;\n\n\tvoid processCoord (real lo, real hi, real c, real v)\n\t{\n\t\tif (v == 0)\n\t\t{\n\t\t\tif (lo < c && c < hi)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttlo = +infinity;\n\t\t\tthi = -infinity;\n\t\t\treturn;\n\t\t}\n\t\treal a = (lo - c) / v;\n\t\treal b = (hi - c) / v;\n\t\tdebug {writeln (a, \" \", b);}\n\t\ta = max (a, 0);\n\t\tb = max (b, 0);\n\t\tif (a > b)\n\t\t{\n\t\t\tswap (a, b);\n\t\t}\n\t\ttlo = max (tlo, a);\n\t\tthi = min (thi, b);\n\t}\n\n\tforeach (i; 0..n)\n\t{\n\t\tprocessCoord (xlo, xhi, x[i], vx[i]);\n\t\tprocessCoord (ylo, yhi, y[i], vy[i]);\n\t}\n\tdebug {writeln (\">\", tlo, \" \", thi);}\n\n\tif (thi - tlo > eps)\n\t{\n\t\treturn tlo;\n\t}\n\treturn -1;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\twritefln (\"%.20g\", solve (n));\n\t}\n}\n", "positive_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t} \n\tint n;\nloop:while(read(n))\n\t{\n\t\tlint x1,y1,x2,y2;\n\t\tread(x1,y1,x2,y2);\n\t\tlong l=0,vl=1,r=int.max,vr=1;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tlong rx,ry,vx,vy;\n\t\t\tread(rx,ry,vx,vy);\n\t\t\tif(vx==0)\n\t\t\t{\n\t\t\t\tif(rx<=x1 || rx>=x2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vx<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(x1-rx,x2-rx);\n\t\t\t\t\tr2=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(x1-rx,x2-rx);\n\t\t\t\t\tr1=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\tif(vx*r2<=0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((rx-x1)*(rx-x2)<0)r1=0;\n\t\t\t\tif(vx*r2<=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvx=abs(vx);\n\t\t\t\tif(l*vx<r1*vl)\n\t\t\t\t{\n\t\t\t\t\tl=r1;\n\t\t\t\t\tvl=vx;\n\t\t\t\t}\n\t\t\t\tif(r*vx>r2*vr)\n\t\t\t\t{\n\t\t\t\t\tr=r2;\n\t\t\t\t\tvr=vx;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(vy==0)\n\t\t\t{\n\t\t\t\tif(ry<=y1 || ry>=y2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vy<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(y1-ry,y2-ry);\n\t\t\t\t\tr2=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(y1-ry,y2-ry);\n\t\t\t\t\tr1=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\tif(vy*r2<=0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((ry-y1)*(ry-y2)<0)r1=0;\n\t\t\t\tif(vy*r2<=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvy=abs(vy);\n\t\t\t\tif(l*vy<r1*vl)\n\t\t\t\t{\n\t\t\t\t\tl=r1;\n\t\t\t\t\tvl=vy;\n\t\t\t\t}\n\t\t\t\tif(r*vy>r2*vr)\n\t\t\t\t{\n\t\t\t\t\tr=r2;\n\t\t\t\t\tvr=vy;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(l*vr>=r*vl)writeln(\"-1\");\n\t\telse writefln(\"%.10f\",(1.00000000*l)/vl);\n\t}\n\n\t//debug system(\"pause\");\n}"}], "negative_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t} \n\tint n;\nloop:while(read(n))\n\t{\n\t\tlint x1,y1,x2,y2;\n\t\tread(x1,y1,x2,y2);\n\t\tlong l=0,vl=1,r=int.max,vr=1;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tlong rx,ry,vx,vy;\n\t\t\tread(rx,ry,vx,vy);\n\t\t\tif(vx==0)\n\t\t\t{\n\t\t\t\tif(rx<x1 || rx>x2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vx<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(x1-rx,x2-rx);\n\t\t\t\t\tr2=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(x1-rx,x2-rx);\n\t\t\t\t\tr1=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\tif(vx*r2<0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((rx-x1)*(rx-x2)<=0)r1=0;\n\t\t\t\tif(vx*r1<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvx=abs(vx);\n\t\t\t\tif(l*vx<r1*vl)\n\t\t\t\t{\n\t\t\t\t\tl=r1;\n\t\t\t\t\tvl=vx;\n\t\t\t\t}\n\t\t\t\tif(r*vx>r2*vr)\n\t\t\t\t{\n\t\t\t\t\tr=r2;\n\t\t\t\t\tvr=vx;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(vy==0)\n\t\t\t{\n\t\t\t\tif(ry<y1 || ry>y2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vy<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(y1-ry,y2-ry);\n\t\t\t\t\tr2=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(y1-ry,y2-ry);\n\t\t\t\t\tr1=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\tif(vy*r2<0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((ry-y1)*(ry-y2)<=0)r1=0;\n\t\t\t\tif(vy*r1<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvy=abs(vy);\n\t\t\t\tif(l*vy<r1*vl)\n\t\t\t\t{\n\t\t\t\t\tl=r1;\n\t\t\t\t\tvl=vy;\n\t\t\t\t}\n\t\t\t\tif(r*vy>r2*vr)\n\t\t\t\t{\n\t\t\t\t\tr=r2;\n\t\t\t\t\tvr=vy;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(l*vr>r*vl)writeln(\"-1\");\n\t\telse writefln(\"%.10f\",(1.00000000*l)/vl);\n\t}\n\n\t//debug system(\"pause\");\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t} \n\tint n;\nloop:while(read(n))\n\t{\n\t\tlint x1,y1,x2,y2;\n\t\tread(x1,y1,x2,y2);\n\t\tlong l=0,vl=1,r=int.max,vr=1;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tlong rx,ry,vx,vy;\n\t\t\tlong l0=-1,vl0=1,r0=int.max,vr0=1;\n\t\t\tread(rx,ry,vx,vy);\n\t\t\tif(vx==0)\n\t\t\t{\n\t\t\t\tif(rx<x1 || rx>x2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vx<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(x1-rx,x2-rx);\n\t\t\t\t\tr2=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(x1-rx,x2-rx);\n\t\t\t\t\tr1=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\tif(vx*r2<0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((rx-x1)*(rx-x2)<=0)r1=0;\n\t\t\t\tif(vx*r1<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvx=abs(vx);\n\t\t\t\tif(l0*vx<r1*vl0)\n\t\t\t\t{\n\t\t\t\t\tl0=r1;\n\t\t\t\t\tvl0=vx;\n\t\t\t\t}\n\t\t\t\tif(r0*vx<r2*vr0)\n\t\t\t\t{\n\t\t\t\t\tr0=r2;\n\t\t\t\t\tvr0=vx;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(vy==0)\n\t\t\t{\n\t\t\t\tif(ry<y1 || ry>y2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vy<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(y1-ry,y2-ry);\n\t\t\t\t\tr2=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(y1-ry,y2-ry);\n\t\t\t\t\tr1=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\tif(vy*r2<0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((ry-y1)*(ry-y2)<=0)r1=0;\n\t\t\t\tif(vy*r1<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvy=abs(vy);\n\t\t\t\tif(l0*vy<r1*vl0)\n\t\t\t\t{\n\t\t\t\t\tl0=r1;\n\t\t\t\t\tvl0=vy;\n\t\t\t\t}\n\t\t\t\tif(r0*vy<r2*vr0)\n\t\t\t\t{\n\t\t\t\t\tr0=r2;\n\t\t\t\t\tvr0=vy;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(l*vl0<l0*vl && l0!=-1)\n\t\t\t{\n\t\t\t\tl=l0;\n\t\t\t\tvl=vl0;\n\t\t\t}\n\t\t\tif(r*vr0>r0*vr && r0!=int.max)\n\t\t\t{\n\t\t\t\tr=r0;\n\t\t\t\tvr=vr0;\n\t\t\t}\n\t\t}\n\t\tif(l*vr>r*vl)writeln(\"-1\");\n\t\telse writefln(\"%.10f\",(1.00000000*l)/vl);\n\t}\n\n\t//debug system(\"pause\");\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t} \n\tint n;\nloop:while(read(n))\n\t{\n\t\tlint x1,y1,x2,y2;\n\t\tread(x1,y1,x2,y2);\n\t\tlong l=0,vl=1,r=int.max,vr=1;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tlong rx,ry,vx,vy;\n\t\t\tlong l0=-1,vl0=1,r0=int.max,vr0=1;\n\t\t\tread(rx,ry,vx,vy);\n\t\t\tif(vx==0)\n\t\t\t{\n\t\t\t\tif(rx<x1 || rx>x2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vx<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(x1-rx,x2-rx);\n\t\t\t\t\tr2=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(x1-rx,x2-rx);\n\t\t\t\t\tr1=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\tif((rx-x1)*(rx-x2)<=0)r1=0;\n\t\t\t\tif(vx*r1<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvx=abs(vx);\n\t\t\t\tif(l0*vx<r1*vl0)\n\t\t\t\t{\n\t\t\t\t\tl0=r1;\n\t\t\t\t\tvl0=vx;\n\t\t\t\t}\n\t\t\t\tif(r0*vx<r2*vr0)\n\t\t\t\t{\n\t\t\t\t\tr0=r2;\n\t\t\t\t\tvr0=vx;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(vy==0)\n\t\t\t{\n\t\t\t\tif(ry<y1 || ry>y2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vy<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(y1-ry,y2-ry);\n\t\t\t\t\tr2=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(y1-ry,y2-ry);\n\t\t\t\t\tr1=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\tif((ry-y1)*(ry-y2)<=0)r1=0;\n\t\t\t\tif(vy*r1<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvy=abs(vy);\n\t\t\t\tif(l0*vy<r1*vl0)\n\t\t\t\t{\n\t\t\t\t\tl0=r1;\n\t\t\t\t\tvl0=vy;\n\t\t\t\t}\n\t\t\t\tif(r0*vy<r2*vr0)\n\t\t\t\t{\n\t\t\t\t\tr0=r2;\n\t\t\t\t\tvr0=vy;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(l*vl0<l0*vl && l0!=-1)\n\t\t\t{\n\t\t\t\tl=l0;\n\t\t\t\tvl=vl0;\n\t\t\t}\n\t\t\tif(r*vr0>r0*vr && r0!=int.max)\n\t\t\t{\n\t\t\t\tr=r0;\n\t\t\t\tvr=vr0;\n\t\t\t}\n\t\t}\n\t\tif(l*vr>r*vl)writeln(\"-1\");\n\t\telse writefln(\"%.10f\",(1.00000000*l)/vl);\n\t}\n\n\t//debug system(\"pause\");\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t} \n\tint n;\nloop:while(read(n))\n\t{\n\t\tlint x1,y1,x2,y2;\n\t\tread(x1,y1,x2,y2);\n\t\tlong l=0,vl=1,r=int.max,vr=1;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tlong rx,ry,vx,vy;\n\t\t\tread(rx,ry,vx,vy);\n\t\t\tif(vx==0)\n\t\t\t{\n\t\t\t\tif(rx<=x1 || rx>=x2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vx<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(x1-rx,x2-rx);\n\t\t\t\t\tr2=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(x1-rx,x2-rx);\n\t\t\t\t\tr1=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\tif(vx*r2<=0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((rx-x1)*(rx-x2)<0)r1=0;\n\t\t\t\tif(vx*r2<=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvx=abs(vx);\n\t\t\t\tif(l*vx<r1*vl)\n\t\t\t\t{\n\t\t\t\t\tl=r1;\n\t\t\t\t\tvl=vx;\n\t\t\t\t}\n\t\t\t\tif(r*vx>r2*vr)\n\t\t\t\t{\n\t\t\t\t\tr=r2;\n\t\t\t\t\tvr=vx;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(vy==0)\n\t\t\t{\n\t\t\t\tif(ry<=y1 || ry>=y2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vy<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(y1-ry,y2-ry);\n\t\t\t\t\tr2=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(y1-ry,y2-ry);\n\t\t\t\t\tr1=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\tif(vy*r2<=0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((ry-y1)*(ry-y2)<0)r1=0;\n\t\t\t\tif(vy*r2<=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvy=abs(vy);\n\t\t\t\tif(l*vy<r1*vl)\n\t\t\t\t{\n\t\t\t\t\tl=r1;\n\t\t\t\t\tvl=vy;\n\t\t\t\t}\n\t\t\t\tif(r*vy>r2*vr)\n\t\t\t\t{\n\t\t\t\t\tr=r2;\n\t\t\t\t\tvr=vy;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(l*vr>r*vl)writeln(\"-1\");\n\t\telse writefln(\"%.10f\",(1.00000000*l)/vl);\n\t}\n\n\t//debug system(\"pause\");\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t} \n\tint n;\nloop:while(read(n))\n\t{\n\t\tlint x1,y1,x2,y2;\n\t\tread(x1,y1,x2,y2);\n\t\tlong l=0,vl=1,r=int.max,vr=1;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tlong rx,ry,vx,vy;\n\t\t\tlong l0=-1,vl0=1,r0=int.max,vr0=1;\n\t\t\tread(rx,ry,vx,vy);\n\t\t\tif(vx==0)\n\t\t\t{\n\t\t\t\tif(rx<x1 || rx>x2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlint x;\n\t\t\t\tif((rx-x1)*(rx-x2)<=0)x=0;\n\t\t\t\telse if(abs(x1-rx)<abs(x2-rx))x=x1-rx;\n\t\t\t\telse x=x2-rx;\n\t\t\t\tif(x*vx<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tx=abs(x);\n\t\t\t\tif(x*vl0>l0*abs(vx))\n\t\t\t\t{\n\t\t\t\t\tl0=x;\n\t\t\t\t\tvl0=abs(vx);\n\t\t\t\t}\n\t\t\t\tif((x1-rx)*vx>(x2-rx)*vx)x=abs(x1-rx);\n\t\t\t\telse x=abs(x2-rx);\n\t\t\t\tif(x*vr0<r0*abs(vx))\n\t\t\t\t{\n\t\t\t\t\tvr0=abs(vx);\n\t\t\t\t\tr0=x;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(vy==0)\n\t\t\t{\n\t\t\t\tif(ry<y1 || ry>y2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlint y;\n\t\t\t\tif((ry-y1)*(ry-y2)<=0)y=0;\n\t\t\t\telse if(abs(y1-ry)<abs(y2-ry))y=y1-ry;\n\t\t\t\telse y=y2-ry;\n\t\t\t\tif(y*vy<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ty=abs(y);\n\t\t\t\tif(y*vl0>l0*abs(vy))\n\t\t\t\t{\n\t\t\t\t\tl0=y;\n\t\t\t\t\tvl0=abs(vy);\n\t\t\t\t}\n\t\t\t\tif((y1-ry)*vy>(y2-ry)*vy)y=abs(y1-ry);\n\t\t\t\telse y=abs(y2-ry);\n\t\t\t\tif(y*vr0<r0*abs(vy))\n\t\t\t\t{\n\t\t\t\t\tvr0=abs(vy);\n\t\t\t\t\tr0=y;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(l*vl0<l0*vl && l0!=-1)\n\t\t\t{\n\t\t\t\tl=l0;\n\t\t\t\tvl=vl0;\n\t\t\t}\n\t\t\tif(r*vr0>r0*vr && r0!=int.max)\n\t\t\t{\n\t\t\t\tr=r0;\n\t\t\t\tvr=vr0;\n\t\t\t}\n\t\t}\n\t\tif(l*vr>r*vl)writeln(\"-1\");\n\t\telse writefln(\"%.10f\",(1.00000000*l)/vl);\n\t}\n\n\t//debug system(\"pause\");\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t} \n\tint n;\nloop:while(read(n))\n\t{\n\t\tlint x1,y1,x2,y2;\n\t\tread(x1,y1,x2,y2);\n\t\tlong l=0,vl=1,r=int.max,vr=1;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tlong rx,ry,vx,vy;\n\t\t\tread(rx,ry,vx,vy);\n\t\t\tif(vx==0)\n\t\t\t{\n\t\t\t\tif(rx<x1 || rx>x2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vx<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(x1-rx,x2-rx);\n\t\t\t\t\tr2=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(x1-rx,x2-rx);\n\t\t\t\t\tr1=min(x1-rx,x2-rx);\n\t\t\t\t}\n\t\t\t\tif(vx*r2<=0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((rx-x1)*(rx-x2)<0)r1=0;\n\t\t\t\telse if(vx*r1<=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvx=abs(vx);\n\t\t\t\tif(l*vx<r1*vl)\n\t\t\t\t{\n\t\t\t\t\tl=r1;\n\t\t\t\t\tvl=vx;\n\t\t\t\t}\n\t\t\t\tif(r*vx>r2*vr)\n\t\t\t\t{\n\t\t\t\t\tr=r2;\n\t\t\t\t\tvr=vx;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(vy==0)\n\t\t\t{\n\t\t\t\tif(ry<y1 || ry>y2)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong r1,r2;\n\t\t\t\tif(vy<0)\n\t\t\t\t{\n\t\t\t\t\tr1=max(y1-ry,y2-ry);\n\t\t\t\t\tr2=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr2=max(y1-ry,y2-ry);\n\t\t\t\t\tr1=min(y1-ry,y2-ry);\n\t\t\t\t}\n\t\t\t\tif(vy*r2<=0)\n\t\t\t\t{\n\t\t\t\t\tr2=r1;\n\t\t\t\t}\n\t\t\t\tif((ry-y1)*(ry-y2)<0)r1=0;\n\t\t\t\telse if(vy*r1<=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tr1=abs(r1);\n\t\t\t\tr2=abs(r2);\n\t\t\t\tvy=abs(vy);\n\t\t\t\tif(l*vy<r1*vl)\n\t\t\t\t{\n\t\t\t\t\tl=r1;\n\t\t\t\t\tvl=vy;\n\t\t\t\t}\n\t\t\t\tif(r*vy>r2*vr)\n\t\t\t\t{\n\t\t\t\t\tr=r2;\n\t\t\t\t\tvr=vy;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(l*vr>r*vl)writeln(\"-1\");\n\t\telse writefln(\"%.10f\",(1.00000000*l)/vl);\n\t}\n\n\t//debug system(\"pause\");\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;immutable int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t} \n\tint n;\nloop:while(read(n))\n\t{\n\t\tlint x1,y1,x2,y2;\n\t\tread(x1,y1,x2,y2);\n\t\tlong l=0,vl=1,r=int.max,vr=1;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tlong rx,ry,vx,vy;\n\t\t\tread(rx,ry,vx,vy);\n\t\t\tif(vx==0)\n\t\t\t{\n\t\t\t\tif(rx<x1 || rx>x2)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlint x;\n\t\t\t\tif((rx-x1)*(rx-x2)<=0)x=0;\n\t\t\t\telse if(abs(x1-rx)<abs(x2-rx))x=x1-rx;\n\t\t\t\telse x=x2-rx;\n\t\t\t\tif(x*vx<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif(x*vl>l*vx)\n\t\t\t\t{\n\t\t\t\t\tl=x;\n\t\t\t\t\tvl=vx;\n\t\t\t\t}\n\t\t\t\tif((x1-rx)*vx>(x2-rx)*vx)x=x1-rx;\n\t\t\t\telse x=x2-rx;\n\t\t\t\tif(x*vr<r*vx)\n\t\t\t\t{\n\t\t\t\t\tvr=vx;\n\t\t\t\t\tr=x;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(vy==0)\n\t\t\t{\n\t\t\t\tif(ry<y1 || ry>y2)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlint y;\n\t\t\t\tif((ry-y1)*(ry-y2)<=0)y=0;\n\t\t\t\telse if(abs(y1-ry)<abs(y2-ry))y=y1-ry;\n\t\t\t\telse y=y2-ry;\n\t\t\t\tif(y*vy<0)\n\t\t\t\t{\n\t\t\t\t\twriteln(-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif(y*vl>l*vy)\n\t\t\t\t{\n\t\t\t\t\tl=y;\n\t\t\t\t\tvl=vy;\n\t\t\t\t}\n\t\t\t\tif((y1-ry)*vy>(y2-ry)*vy)y=y1-ry;\n\t\t\t\telse y=y2-ry;\n\t\t\t\tif(y*vr<r*vy)\n\t\t\t\t{\n\t\t\t\t\tvr=vy;\n\t\t\t\t\tr=y;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(l*vr>r*vl)writeln(-1);\n\t\telse writeln((1.00000000*l)/vl);\n\t}\n\n\t//debug system(\"pause\");\n}"}], "src_uid": "2df45858a638a90d30315844df6d1084"} {"source_code": "module _;\nvoid main() {\n\timport std.stdio, std.algorithm;\n\tint n;\n\treadf(\"%s \", &n);\n\tlong[] ps;\n\tlong[] ns;\n\tforeach(i; 0..n) {\n\t\tlong x;\n\t\treadf(\"%s \", &x);\n\t\tif (x < 0) {\n\t\t\tns ~= -x;\n\t\t} else {\n\t\t\tps ~= x;\n\t\t}\n\t}\n\n\tauto sns = ns.sort;\n\tauto sps = ps.sort;\n\n\tlong ans = 0;\n\t// both > 0\n\tforeach(i; 0..sps.length) {\n\t\tauto c = sps.lowerBound(2UL*sps[i]+1UL);\n\t\tdebug writeln(c, c.length - i - 1);\n\t\tans += cast(long)(c.length - i - 1);\n\t}\n\n\t// both < 0\n\tforeach(i; 0..sns.length) {\n\t\tauto c = sns.lowerBound(2UL*sns[i]+1UL);\n\t\tdebug writeln(c.length - i - 1);\n\t\tans += cast(long)(c.length - i - 1);\n\t}\n\n\t// x > 0, y < 0, |x| < |y|\n\t// |x-y| = |y|+|x|, |x+y| = |y|-|x|\n\t// |y|-|x| <= |x|, |x| < |y| <= 2*|x|\n\tforeach(i; 0..sps.length) {\n\t\tauto c = sns.lowerBound(2UL*sps[i]+1UL).upperBound(sps[i]);\n\t\tdebug writeln(c.length);\n\t\tans += cast(long)c.length;\n\t}\n\n\t// x < 0, y > 0, |x| < |y|\n\tforeach(i; 0..sns.length) {\n\t\tauto c = sps.lowerBound(2UL*sns[i]+1UL).upperBound(sns[i]);\n\t\tdebug writeln(c.length);\n\t\tans += cast(long)c.length;\n\t}\n\n\t// |x| == |y|\n\t// |x|-|y| = 0, |x|+|y| = 2|x|\n\tforeach(i; 0..sps.length) {\n\t\tif (sns.contains(sps[i])) {\n\t\t\tans++;\n\t\t}\n\t}\n\twriteln(ans);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).map !(abs).array;\n\t\tsort (a);\n\n\t\tlong res = 0;\n\t\tint j = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twhile (a[j] * 2 < a[i])\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\tres += i - j;\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable int n = r.next!int;\n auto a = r.nextA!int (n);\n auto b = a.map!\"abs(a)\".array;\n sort (b);\n int i, j;\n ulong res;\n for (i = 0; i < n; ++i) {\n int x = b[i];\n while (j < n && b[j] - x <= x) ++j;\n debug stderr.writefln (\"i = %d, j = %d\", i, j);\n res += max (0, j - i - 1);\n }\n writeln (res);\n}\n\n"}], "negative_code": [{"source_code": "module _;\nvoid main() {\n\timport std.stdio, std.algorithm;\n\tint n;\n\treadf(\"%s \", &n);\n\tint[] ps;\n\tint[] ns;\n\tforeach(i; 0..n) {\n\t\tint x;\n\t\treadf(\"%s \", &x);\n\t\tif (x < 0) {\n\t\t\tns ~= -x;\n\t\t} else {\n\t\t\tps ~= x;\n\t\t}\n\t}\n\n\tauto sns = ns.sort;\n\tauto sps = ps.sort;\n\n\tint ans = 0;\n\t// both > 0\n\tforeach(i; 0..sps.length) {\n\t\tauto c = sps.lowerBound(2*sps[i]+1);\n\t\tdebug writeln(c, c.length - i - 1);\n\t\tans += c.length - i - 1;\n\t}\n\n\t// both < 0\n\tforeach(i; 0..sns.length) {\n\t\tauto c = sns.lowerBound(2*sns[i]+1);\n\t\tdebug writeln(c.length - i - 1);\n\t\tans += c.length - i - 1;\n\t}\n\n\t// x > 0, y < 0, |x| < |y|\n\t// |x-y| = |y|+|x|, |x+y| = |y|-|x|\n\t// |y|-|x| <= |x|, |x| < |y| <= 2*|x|\n\tforeach(i; 0..sps.length) {\n\t\tauto c = sns.lowerBound(2*sps[i]+1).upperBound(sps[i]);\n\t\tdebug writeln(c.length);\n\t\tans += c.length;\n\t}\n\n\t// x < 0, y > 0, |x| < |y|\n\tforeach(i; 0..sns.length) {\n\t\tauto c = sps.lowerBound(2*sns[i]+1).upperBound(sns[i]);\n\t\tdebug writeln(c.length);\n\t\tans += c.length;\n\t}\n\twriteln(ans);\n}\n"}, {"source_code": "module _;\nvoid main() {\n\timport std.stdio, std.algorithm;\n\tint n;\n\treadf(\"%s \", &n);\n\tlong[] ps;\n\tlong[] ns;\n\tforeach(i; 0..n) {\n\t\tlong x;\n\t\treadf(\"%s \", &x);\n\t\tif (x < 0) {\n\t\t\tns ~= -x;\n\t\t} else {\n\t\t\tps ~= x;\n\t\t}\n\t}\n\n\tauto sns = ns.sort;\n\tauto sps = ps.sort;\n\n\tlong ans = 0;\n\t// both > 0\n\tforeach(i; 0..sps.length) {\n\t\tauto c = sps.lowerBound(2UL*sps[i]+1UL);\n\t\tdebug writeln(c, c.length - i - 1);\n\t\tans += cast(long)(c.length - i - 1);\n\t}\n\n\t// both < 0\n\tforeach(i; 0..sns.length) {\n\t\tauto c = sns.lowerBound(2UL*sns[i]+1UL);\n\t\tdebug writeln(c.length - i - 1);\n\t\tans += cast(long)(c.length - i - 1);\n\t}\n\n\t// x > 0, y < 0, |x| < |y|\n\t// |x-y| = |y|+|x|, |x+y| = |y|-|x|\n\t// |y|-|x| <= |x|, |x| < |y| <= 2*|x|\n\tforeach(i; 0..sps.length) {\n\t\tauto c = sns.lowerBound(2UL*sps[i]+1UL).upperBound(sps[i]);\n\t\tdebug writeln(c.length);\n\t\tans += cast(long)c.length;\n\t}\n\n\t// x < 0, y > 0, |x| < |y|\n\tforeach(i; 0..sns.length) {\n\t\tauto c = sps.lowerBound(2UL*sns[i]+1UL).upperBound(sns[i]);\n\t\tdebug writeln(c.length);\n\t\tans += cast(long)c.length;\n\t}\n\twriteln(ans);\n}\n"}, {"source_code": "module _;\nvoid main() {\n\timport std.stdio, std.algorithm;\n\tint n;\n\treadf(\"%s \", &n);\n\tlong[] ps;\n\tlong[] ns;\n\tforeach(i; 0..n) {\n\t\tlong x;\n\t\treadf(\"%s \", &x);\n\t\tif (x < 0) {\n\t\t\tns ~= -x;\n\t\t} else {\n\t\t\tps ~= x;\n\t\t}\n\t}\n\n\tauto sns = ns.sort;\n\tauto sps = ps.sort;\n\n\tlong ans = 0;\n\t// both > 0\n\tforeach(i; 0..sps.length) {\n\t\tauto c = sps.lowerBound(2UL*sps[i]+1UL);\n\t\tdebug writeln(c, c.length - i - 1);\n\t\tans += cast(long)(c.length - i - 1);\n\t}\n\n\t// both < 0\n\tforeach(i; 0..sns.length) {\n\t\tauto c = sns.lowerBound(2UL*sns[i]+1UL);\n\t\tdebug writeln(c.length - i - 1);\n\t\tans += cast(long)(c.length - i - 1);\n\t}\n\n\t// x > 0, y < 0, |x| <= |y|\n\t// |x-y| = |y|+|x|, |x+y| = |y|-|x|\n\t// |y|-|x| <= |x|, |x| <= |y| <= 2*|x|\n\tforeach(i; 0..sps.length) {\n\t\tauto c = sns.lowerBound(2UL*sps[i]+1UL).upperBound(sps[i]-1);\n\t\tdebug writeln(c.length);\n\t\tans += cast(long)c.length;\n\t}\n\n\t// x < 0, y > 0, |x| <= |y|\n\tforeach(i; 0..sns.length) {\n\t\tauto c = sps.lowerBound(2UL*sns[i]+1UL).upperBound(sns[i]-1);\n\t\tdebug writeln(c.length);\n\t\tans += cast(long)c.length;\n\t}\n\twriteln(ans);\n}\n"}], "src_uid": "642e2d1b427c025578424c81192be756"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int NA = -1;\n\nalias Tuple !(int, \"xb\", int, \"yb\", int, \"xe\", int, \"ye\") segment;\n\nbool is_horizontal (ref segment a)\n{\n\treturn a.yb == a.ye;\n}\n\nalias Tuple !(int, \"x1\", int, \"x2\") pair;\n\nbool less (ref pair p, ref pair q)\n{\n\treturn p.x1 < q.x1;\n}\n\nint get_len (pair [] b)\n{\n\tint len = 0;\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tlen += now.x1 - cur;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tdebug {writefln (\"get_len = %s\", len);}\n\treturn len;\n}\n\nint process (ref pair [] [int] a, int n, int m)\n{\n\tint res;\n\tint num = m - 1;\n\tforeach (i, ref b; a)\n\t{\n\t\tb ~= pair (n, n);\n\t\tsort !(less) (b);\n\t\tint len = get_len (b);\n\t\tdebug {writefln (\"%s: %s\", i, len);}\n\t\tres ^= len;\n\t\tnum--;\n\t}\n\tif (num > 0)\n\t{\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (i !in a)\n\t\t\t{\n\t\t\t\ta[i] = new pair [0];\n\t\t\t\ta[i] ~= pair (n, n);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (num & 1)\n\t{\n\t\tres ^= n;\n\t}\n\treturn res;\n}\n\nint move (pair [] b, int res)\n{\n\tint len = get_len (b);\n\tint todo = res ^ len;\n\tdebug {writefln (\"%s %s %s %s\", b, res, len, todo);}\n\tif (todo > len)\n\t{\n\t\treturn NA;\n\t}\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tint next = todo - (now.x1 - cur);\n\t\t\tif (next <= 0)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"now.x1 = %s, next = %s\",\n\t\t\t\t now.x1, next);}\n\t\t\t\tdebug {writefln (\"%s %s %s\", cur, todo,\n\t\t\t\t cur + todo);}\n\t\t\t\treturn cur + todo;\n\t\t\t}\n\t\t\ttodo = next;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tassert (false);\n}\n\npair moves (pair [] [int] a, int n, int m, int res)\n{\n\tforeach (c, b; a)\n\t{\n\t\tint x = move (b, res);\n\t\tif (x != NA)\n\t\t{\n\t\t\treturn pair (x, c);\n\t\t}\n\t}\n\treturn pair (NA, NA);\n}\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\tpair [] [int] h;\n\t\tpair [] [int] v;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tsegment a;\n\t\t\treadf (\" %s %s %s %s\", &a.xb, &a.yb, &a.xe, &a.ye);\n\t\t\tif (a.xb > a.xe)\n\t\t\t{\n\t\t\t\tswap (a.xb, a.xe);\n\t\t\t}\n\t\t\tif (a.yb > a.ye)\n\t\t\t{\n\t\t\t\tswap (a.yb, a.ye);\n\t\t\t}\n\t\t\tif (is_horizontal (a))\n\t\t\t{\n\t\t\t\th[a.yb] ~= pair (a.xb, a.xe);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[a.xb] ~= pair (a.yb, a.ye);\n\t\t\t}\n\t\t}\n\t\tint s = process (h, n, m);\n\t\tint t = process (v, m, n);\n\t\tint res = s ^ t;\n\t\tif (res)\n\t\t{\n\t\t\twritefln (\"FIRST\");\n\t\t\tauto p = moves (h, n, m, res);\n\t\t\tif (p[0] != NA)\n\t\t\t{\n\t\t\t\twritefln (\"%s %s %s %s\", p[0], p[1], n, p[1]);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto q = moves (v, m, n, res);\n\t\t\tif (q[0] != NA)\n\t\t\t{\n\t\t\t\twritefln (\"%s %s %s %s\", q[1], q[0], q[1], m);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tassert (false);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"SECOND\");\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int NA = -1;\n\nalias Tuple !(int, \"xb\", int, \"yb\", int, \"xe\", int, \"ye\") segment;\n\nbool is_horizontal (ref segment a)\n{\n\treturn a.yb == a.ye;\n}\n\nalias Tuple !(int, \"x1\", int, \"x2\") pair;\n\nbool less (ref pair p, ref pair q)\n{\n\treturn p.x1 < q.x1;\n}\n\nint get_len (pair [] b)\n{\n\tint len = 0;\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tlen += now.x1 - cur;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tdebug {writefln (\"get_len = %s\", len);}\n\treturn len;\n}\n\nint process (ref pair [] [int] a, int n, int m)\n{\n\tint res;\n\tint num = m - 1;\n\tforeach (i, ref b; a)\n\t{\n\t\tb ~= pair (n, n);\n\t\tsort !(less) (b);\n\t\tint len = get_len (b);\n\t\tdebug {writefln (\"%s: %s\", i, len);}\n\t\tres ^= len;\n\t\tnum--;\n\t}\n\tif (num > 0)\n\t{\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (i !in a)\n\t\t\t{\n\t\t\t\ta[i] = new pair [0];\n\t\t\t\ta[i] ~= pair (n, n);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (num & 1)\n\t{\n\t\tres ^= n;\n\t}\n\treturn res;\n}\n\nint move (pair [] b, int res)\n{\n\tint len = get_len (b);\n\tint todo = res ^ len;\n\tdebug {writefln (\"%s %s %s %s\", b, res, len, todo);}\n\tif (todo > len)\n\t{\n\t\treturn NA;\n\t}\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tint next = todo - (now.x1 - cur);\n\t\t\tif (next <= 0)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"now.x1 = %s, next = %s\",\n\t\t\t\t now.x1, next);}\n\t\t\t\tdebug {writefln (\"%s %s %s\", cur, todo,\n\t\t\t\t cur + todo);}\n\t\t\t\treturn cur + todo;\n\t\t\t}\n\t\t\ttodo = next;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tassert (false);\n}\n\npair moves (pair [] [int] a, int n, int m, int res)\n{\n\tforeach (c, b; a)\n\t{\n\t\tint x = move (b, res);\n\t\tif (x != NA)\n\t\t{\n\t\t\treturn pair (x, c);\n\t\t}\n\t}\n\treturn pair (NA, NA);\n}\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tpair [] [int] h;\n\t\tpair [] [int] v;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tsegment a;\n\t\t\tscanf (\" %d %d %d %d\", &a.xb, &a.yb, &a.xe, &a.ye);\n\t\t\tif (a.xb > a.xe)\n\t\t\t{\n\t\t\t\tswap (a.xb, a.xe);\n\t\t\t}\n\t\t\tif (a.yb > a.ye)\n\t\t\t{\n\t\t\t\tswap (a.yb, a.ye);\n\t\t\t}\n\t\t\tif (is_horizontal (a))\n\t\t\t{\n\t\t\t\th[a.yb] ~= pair (a.xb, a.xe);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[a.xb] ~= pair (a.yb, a.ye);\n\t\t\t}\n\t\t}\n\t\tint s = process (h, n, m);\n\t\tint t = process (v, m, n);\n\t\tint res = s ^ t;\n\t\tif (res)\n\t\t{\n\t\t\twritefln (\"FIRST\");\n\t\t\tauto p = moves (h, n, m, res);\n\t\t\tif (p[0] != NA)\n\t\t\t{\n\t\t\t\twritefln (\"%s %s %s %s\", p[0], p[1], n, p[1]);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto q = moves (v, m, n, res);\n\t\t\tif (q[0] != NA)\n\t\t\t{\n\t\t\t\twritefln (\"%s %s %s %s\", q[1], q[0], q[1], m);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tassert (false);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"SECOND\");\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int NA = -1;\n\nalias Tuple !(int, \"xb\", int, \"yb\", int, \"xe\", int, \"ye\") segment;\n\nbool is_horizontal (ref segment a)\n{\n\treturn a.yb == a.ye;\n}\n\nalias Tuple !(int, \"x1\", int, \"x2\") pair;\n\nbool less (ref pair p, ref pair q)\n{\n\treturn p.x1 < q.x1;\n}\n\nint get_len (pair [] b)\n{\n\tint len = 0;\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tlen += now.x1 - cur;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tdebug {writefln (\"get_len = %s\", len);}\n\treturn len;\n}\n\nint process (ref pair [] [int] a, int n, int m)\n{\n\tint res;\n\tint num = m - 1;\n\tforeach (i, ref b; a)\n\t{\n\t\tb ~= pair (n, n);\n\t\tsort !(less) (b);\n\t\tint len = get_len (b);\n\t\tdebug {writefln (\"%s: %s\", i, len);}\n\t\tres ^= len;\n\t\tnum--;\n\t}\n\tif (num > 0)\n\t{\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (i !in a)\n\t\t\t{\n\t\t\t\ta[i] = new pair [0];\n\t\t\t\ta[i] ~= pair (n, n);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (num & 1)\n\t{\n\t\tres ^= n;\n\t}\n\treturn res;\n}\n\nint move (pair [] b, int res)\n{\n\tint len = get_len (b);\n\tint todo = res ^ len;\n\tdebug {writefln (\"%s %s %s %s\", b, res, len, todo);}\n\tif (todo > len)\n\t{\n\t\treturn NA;\n\t}\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tint next = todo - (now.x1 - cur);\n\t\t\tif (next <= 0)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"now.x1 = %s, next = %s\",\n\t\t\t\t now.x1, next);}\n\t\t\t\treturn cur - next;\n\t\t\t}\n\t\t\ttodo = next;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tassert (false);\n}\n\npair moves (pair [] [int] a, int n, int m, int res)\n{\n\tforeach (c, b; a)\n\t{\n\t\tint x = move (b, res);\n\t\tif (x != NA)\n\t\t{\n\t\t\treturn pair (x, c);\n\t\t}\n\t}\n\treturn pair (NA, NA);\n}\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tpair [] [int] h;\n\t\tpair [] [int] v;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tsegment a;\n\t\t\tscanf (\" %d %d %d %d\", &a.xb, &a.yb, &a.xe, &a.ye);\n\t\t\tif (a.xb > a.xe)\n\t\t\t{\n\t\t\t\tswap (a.xb, a.xe);\n\t\t\t}\n\t\t\tif (a.yb > a.ye)\n\t\t\t{\n\t\t\t\tswap (a.yb, a.ye);\n\t\t\t}\n\t\t\tif (is_horizontal (a))\n\t\t\t{\n\t\t\t\th[a.yb] ~= pair (a.xb, a.xe);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[a.xb] ~= pair (a.yb, a.ye);\n\t\t\t}\n\t\t}\n\t\tint s = process (h, n, m);\n\t\tint t = process (v, m, n);\n\t\tint res = s ^ t;\n\t\tif (res)\n\t\t{\n\t\t\twritefln (\"FIRST\");\n\t\t\tauto p = moves (h, n, m, res);\n\t\t\tif (p[0] != NA)\n\t\t\t{\n\t\t\t\twritefln (\"%s %s %s %s\", 0, p[1], p[0], p[1]);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto q = moves (v, m, n, res);\n\t\t\tif (q[0] != NA)\n\t\t\t{\n\t\t\t\twritefln (\"%s %s %s %s\", q[1], 0, q[1], q[0]);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tassert (false);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"SECOND\");\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Tuple !(int, \"xb\", int, \"yb\", int, \"xe\", int, \"ye\") segment;\n\nbool is_horizontal (ref segment a)\n{\n\treturn a.yb == a.ye;\n}\n\nalias Tuple !(int, \"x1\", int, \"x2\") seg2;\n\nbool less (ref seg2 p, ref seg2 q)\n{\n\treturn p.x1 < q.x1;\n}\n\nint process (seg2 [] [int] a, int n, int m, out int x, out int y)\n{\n\tint res;\n\tint num = m - 1;\n\ty = 0;\n\tforeach (i, b; a)\n\t{\n\t\tsort !(less) (b);\n\t\tint len = 0;\n\t\tint cur = 0;\n\t\tforeach (now; b)\n\t\t{\n\t\t\tif (cur < now.x1)\n\t\t\t{\n\t\t\t\tlen += now.x1 - cur;\n\t\t\t}\n\t\t\tcur = max (cur, now.x2);\n\t\t}\n\t\tlen += n - cur;\n\t\tlen = n - len;\n\t\tif (y < len)\n\t\t{\n\t\t\ty = len;\n\t\t\tx = i;\n\t\t}\n\t\tdebug {writefln (\"%s: %s\", i, len);}\n\t\tres ^= len;\n\t\tnum--;\n\t}\n\tif (num > 0)\n\t{\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (i !in a)\n\t\t\t{\n\t\t\t\ty = n;\n\t\t\t\tx = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (num & 1)\n\t{\n\t\tres ^= n;\n\t}\n\treturn res;\n}\n\nint move (seg2 [] [int] a, int n, int m, int x, int y, int res)\n{\n\tint todo = res ^ y;\n\tdebug {writefln (\"%s %s %s\", res, y, todo);}\n//\tassert (todo <= y);\n\tdebug {writefln (\"%s %s\", a, x);}\n\tseg2 [] b;\n\tif (y < n)\n\t{\n\t\tb ~= a[x];\n\t}\n\tb ~= seg2 (n, n);\n\tsort !(less) (b);\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tint next = todo - (now.x1 - cur);\n\t\t\tif (next <= 0)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"now.x1 = %s, next = %s\",\n\t\t\t\t now.x1, next);}\n\t\t\t\treturn cur - next;\n\t\t\t}\n\t\t\ttodo = next;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tassert (false);\n}\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tseg2 [] [int] h;\n\t\tseg2 [] [int] v;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tsegment a;\n\t\t\tscanf (\" %d %d %d %d\", &a.xb, &a.yb, &a.xe, &a.ye);\n\t\t\tif (a.xb > a.xe)\n\t\t\t{\n\t\t\t\tswap (a.xb, a.xe);\n\t\t\t}\n\t\t\tif (a.yb > a.ye)\n\t\t\t{\n\t\t\t\tswap (a.yb, a.ye);\n\t\t\t}\n\t\t\tif (is_horizontal (a))\n\t\t\t{\n\t\t\t\th[a.yb] ~= seg2 (a.xb, a.xe);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[a.xb] ~= seg2 (a.yb, a.ye);\n\t\t\t}\n\t\t}\n\t\tint si, sp;\n\t\tint s = process (h, n, m, si, sp);\n\t\tdebug {writefln (\"%s %s\", si, sp);}\n\t\tint ti, tp;\n\t\tint t = process (v, m, n, ti, tp);\n\t\tdebug {writefln (\"%s %s\", ti, tp);}\n\t\tint res = s ^ t;\n\t\tif (res)\n\t\t{\n\t\t\twritefln (\"FIRST\");\n\t\t\tif ((res ^ sp) <= sp)\n\t\t\t{\n\t\t\t\tint pos = move (h, n, m, si, sp, res);\n\t\t\t\twritefln (\"%s %s %s %s\", 0, si, pos, si);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint pos = move (v, m, n, ti, tp, res);\n\t\t\t\twritefln (\"%s %s %s %s\", ti, 0, ti, pos);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"SECOND\");\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Tuple !(int, \"xb\", int, \"yb\", int, \"xe\", int, \"ye\") segment;\n\nbool is_horizontal (ref segment a)\n{\n\treturn a.yb == a.ye;\n}\n\nalias Tuple !(int, \"x1\", int, \"x2\") seg2;\n\nbool less (ref seg2 p, ref seg2 q)\n{\n\treturn p.x1 < q.x1;\n}\n\nint process (seg2 [] [int] a, int n, int m, out int x, out int y)\n{\n\tint res;\n\tint num = m - 1;\n\ty = 0;\n\tforeach (i, b; a)\n\t{\n\t\tsort !(less) (b);\n\t\tint len = 0;\n\t\tint cur = 0;\n\t\tforeach (now; b)\n\t\t{\n\t\t\tif (cur < now.x1)\n\t\t\t{\n\t\t\t\tlen += now.x1 - cur;\n\t\t\t}\n\t\t\tcur = max (cur, now.x2);\n\t\t}\n\t\tlen += n - cur;\n\t\tlen = n - len;\n\t\tif (y < len)\n\t\t{\n\t\t\ty = len;\n\t\t\tx = i;\n\t\t}\n\t\tdebug {writefln (\"%s: %s\", i, len);}\n\t\tres ^= len;\n\t\tnum--;\n\t}\n\tif (num > 0)\n\t{\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (i !in a)\n\t\t\t{\n\t\t\t\ty = n;\n\t\t\t\tx = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (num & 1)\n\t{\n\t\tres ^= n;\n\t}\n\treturn res;\n}\n\nint move (seg2 [] [int] a, int n, int m, int x, int y, int res)\n{\n\tint todo = res ^ y;\n\tdebug {writefln (\"%s %s %s\", res, y, todo);}\n\tassert (todo <= y);\n\tdebug {writefln (\"%s %s\", a, x);}\n\tseg2 [] b;\n\tif (y < n)\n\t{\n\t\tb ~= a[x];\n\t}\n\tb ~= seg2 (n, n);\n\tsort !(less) (b);\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tint next = todo - (now.x1 - cur);\n\t\t\tif (next <= 0)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"now.x1 = %s, next = %s\",\n\t\t\t\t now.x1, next);}\n\t\t\t\treturn cur - next;\n\t\t\t}\n\t\t\ttodo = next;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tassert (false);\n}\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tseg2 [] [int] h;\n\t\tseg2 [] [int] v;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tsegment a;\n\t\t\tscanf (\" %d %d %d %d\", &a.xb, &a.yb, &a.xe, &a.ye);\n\t\t\tif (a.xb > a.xe)\n\t\t\t{\n\t\t\t\tswap (a.xb, a.xe);\n\t\t\t}\n\t\t\tif (a.yb > a.ye)\n\t\t\t{\n\t\t\t\tswap (a.yb, a.ye);\n\t\t\t}\n\t\t\tif (is_horizontal (a))\n\t\t\t{\n\t\t\t\th[a.yb] ~= seg2 (a.xb, a.xe);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[a.xb] ~= seg2 (a.yb, a.ye);\n\t\t\t}\n\t\t}\n\t\tint si, sp;\n\t\tint s = process (h, n, m, si, sp);\n\t\tdebug {writefln (\"%s %s\", si, sp);}\n\t\tint ti, tp;\n\t\tint t = process (v, m, n, ti, tp);\n\t\tdebug {writefln (\"%s %s\", ti, tp);}\n\t\tint res = s ^ t;\n\t\tif (res)\n\t\t{\n\t\t\twritefln (\"FIRST\");\n\t\t\tif (sp >= tp)\n\t\t\t{\n\t\t\t\tint pos = move (h, n, m, si, sp, res);\n\t\t\t\twritefln (\"%s %s %s %s\", 0, si, pos, si);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint pos = move (v, m, n, ti, tp, res);\n\t\t\t\twritefln (\"%s %s %s %s\", ti, 0, ti, pos);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"SECOND\");\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Tuple !(int, \"xb\", int, \"yb\", int, \"xe\", int, \"ye\") segment;\n\nbool is_horizontal (ref segment a)\n{\n\treturn a.yb == a.ye;\n}\n\nalias Tuple !(int, \"x1\", int, \"x2\") seg2;\n\nbool less (ref seg2 p, ref seg2 q)\n{\n\treturn p.x1 < q.x1;\n}\n\nint process (seg2 [] [int] a, int n, int m, out int x, out int y)\n{\n\tint res;\n\tint num = m - 1;\n\ty = 0;\n\tforeach (i, b; a)\n\t{\n\t\tsort !(less) (b);\n\t\tint len = 0;\n\t\tint cur = 0;\n\t\tforeach (now; b)\n\t\t{\n\t\t\tif (cur < now.x1)\n\t\t\t{\n\t\t\t\tlen += now.x1 - cur;\n\t\t\t}\n\t\t\tcur = max (cur, now.x2);\n\t\t}\n\t\tlen += n - cur;\n\t\tlen = n - len;\n\t\tif (y < len)\n\t\t{\n\t\t\ty = len;\n\t\t\tx = i;\n\t\t}\n\t\tdebug {writefln (\"%s: %s\", i, len);}\n\t\tres ^= len;\n\t\tnum--;\n\t}\n\tif (num > 0)\n\t{\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (i !in a)\n\t\t\t{\n\t\t\t\ty = n;\n\t\t\t\tx = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (num & 1)\n\t{\n\t\tres ^= n;\n\t}\n\treturn res;\n}\n\nint move (seg2 [] [int] a, int n, int m, int x, int y, int res)\n{\n\tint todo = res ^ y;\n\tdebug {writefln (\"%s %s %s\", res, y, todo);}\n//\tassert (todo <= y);\n\tdebug {writefln (\"%s %s\", a, x);}\n\tseg2 [] b;\n\tif (y < n)\n\t{\n\t\tb ~= a[x];\n\t}\n\tb ~= seg2 (n, n);\n\tsort !(less) (b);\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tint next = todo - (now.x1 - cur);\n\t\t\tif (next <= 0)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"now.x1 = %s, next = %s\",\n\t\t\t\t now.x1, next);}\n\t\t\t\treturn cur - next;\n\t\t\t}\n\t\t\ttodo = next;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\tassert (false);\n}\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tseg2 [] [int] h;\n\t\tseg2 [] [int] v;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tsegment a;\n\t\t\tscanf (\" %d %d %d %d\", &a.xb, &a.yb, &a.xe, &a.ye);\n\t\t\tif (a.xb > a.xe)\n\t\t\t{\n\t\t\t\tswap (a.xb, a.xe);\n\t\t\t}\n\t\t\tif (a.yb > a.ye)\n\t\t\t{\n\t\t\t\tswap (a.yb, a.ye);\n\t\t\t}\n\t\t\tif (is_horizontal (a))\n\t\t\t{\n\t\t\t\th[a.yb] ~= seg2 (a.xb, a.xe);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[a.xb] ~= seg2 (a.yb, a.ye);\n\t\t\t}\n\t\t}\n\t\tint si, sp;\n\t\tint s = process (h, n, m, si, sp);\n\t\tdebug {writefln (\"%s %s\", si, sp);}\n\t\tint ti, tp;\n\t\tint t = process (v, m, n, ti, tp);\n\t\tdebug {writefln (\"%s %s\", ti, tp);}\n\t\tint res = s ^ t;\n\t\tif (res)\n\t\t{\n\t\t\twritefln (\"FIRST\");\n\t\t\tif (sp >= tp)\n\t\t\t{\n\t\t\t\tint pos = move (h, n, m, si, sp, res);\n\t\t\t\twritefln (\"%s %s %s %s\", 0, si, pos, si);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint pos = move (v, m, n, ti, tp, res);\n\t\t\t\twritefln (\"%s %s %s %s\", ti, 0, ti, pos);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"SECOND\");\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Tuple !(int, \"xb\", int, \"yb\", int, \"xe\", int, \"ye\") segment;\n\nbool is_horizontal (ref segment a)\n{\n\treturn a.yb == a.ye;\n}\n\nalias Tuple !(int, \"x1\", int, \"x2\") seg2;\n\nbool less (ref seg2 p, ref seg2 q)\n{\n\treturn p.x1 < q.x1;\n}\n\nint process (seg2 [] [int] a, int n, int m, out int x, out int y)\n{\n\tint res;\n\tint num = m - 1;\n\ty = 0;\n\tforeach (i, b; a)\n\t{\n\t\tsort !(less) (b);\n\t\tint len = 0;\n\t\tint cur = 0;\n\t\tforeach (now; b)\n\t\t{\n\t\t\tif (cur < now.x1)\n\t\t\t{\n\t\t\t\tlen += now.x1 - cur;\n\t\t\t}\n\t\t\tcur = max (cur, now.x2);\n\t\t}\n\t\tlen += n - cur;\n\t\tif (y < len)\n\t\t{\n\t\t\ty = len;\n\t\t\tx = i;\n\t\t}\n\t\tdebug {writefln (\"%s: %s\", i, len);}\n\t\tres ^= len;\n\t\tnum--;\n\t}\n\tif (num > 0)\n\t{\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (i !in a)\n\t\t\t{\n\t\t\t\ty = n;\n\t\t\t\tx = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (num & 1)\n\t{\n\t\tres ^= n;\n\t}\n\treturn res;\n}\n\nint move (seg2 [] [int] a, int n, int m, int x, int y, int res)\n{\n\tint todo = res ^ y;\n//\tassert (todo <= y);\n\tdebug {writefln (\"%s %s\", a, x);}\n\tseg2 [] b;\n\tif (y < n)\n\t{\n\t\tb ~= a[x];\n\t}\n\tb ~= seg2 (n, n);\n\tsort !(less) (b);\n\tint cur = 0;\n\tforeach (now; b)\n\t{\n\t\tif (cur < now.x1)\n\t\t{\n\t\t\tint next = todo - (now.x1 - cur);\n\t\t\tif (next <= 0)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"now.x1 = %s, next = %s\",\n\t\t\t\t now.x1, next);}\n\t\t\t\treturn cur - next;\n\t\t\t}\n\t\t\ttodo = next;\n\t\t}\n\t\tcur = max (cur, now.x2);\n\t}\n\treturn n;\n//\tassert (false);\n}\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (scanf (\" %d %d %d\", &n, &m, &k) > 0)\n\t{\n\t\tseg2 [] [int] h;\n\t\tseg2 [] [int] v;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tsegment a;\n\t\t\tscanf (\" %d %d %d %d\", &a.xb, &a.yb, &a.xe, &a.ye);\n\t\t\tif (a.xb > a.xe)\n\t\t\t{\n\t\t\t\tswap (a.xb, a.xe);\n\t\t\t}\n\t\t\tif (a.yb > a.ye)\n\t\t\t{\n\t\t\t\tswap (a.yb, a.ye);\n\t\t\t}\n\t\t\tif (is_horizontal (a))\n\t\t\t{\n\t\t\t\th[a.yb] ~= seg2 (a.xb, a.xe);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[a.xb] ~= seg2 (a.yb, a.ye);\n\t\t\t}\n\t\t}\n\t\tint si, sp;\n\t\tint s = process (h, n, m, si, sp);\n\t\tdebug {writefln (\"%s %s\", si, sp);}\n\t\tint ti, tp;\n\t\tint t = process (v, m, n, ti, tp);\n\t\tdebug {writefln (\"%s %s\", ti, tp);}\n\t\tif (s ^ t)\n\t\t{\n\t\t\twritefln (\"FIRST\");\n\t\t\tif (sp >= tp)\n\t\t\t{\n\t\t\t\tint pos = move (h, n, m, si, sp, s ^ t);\n\t\t\t\twritefln (\"%s %s %s %s\", 0, si, pos, si);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint pos = move (v, m, n, ti, tp, s ^ t);\n\t\t\t\twritefln (\"%s %s %s %s\", ti, 0, ti, pos);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"SECOND\");\n\t\t}\n\t}\n}\n"}], "src_uid": "a7fa7a5ab71690fb3b5301bebc19956b"} {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint m = read.to!int;\n\tint h = read.to!int;\n\t\n\tint[] as;\n\tforeach(j; 0 .. m) as ~= read.to!int;\n\t\n\tint[] bs;\n\tforeach(i; 0 .. n) bs ~= read.to!int;\n\t\n\tint[][] cs = new int[][](n, m);\n\tforeach(i; 0 .. n) foreach(j; 0 .. m) cs[i][j] = read.to!int;\n\t\n\tint[][] ans = new int[][](n, m);\n\t\n\tX[] xs;\n\tforeach(i; 0 .. n) xs ~= new X(true, i, bs[i]);\n\tforeach(j; 0 .. m) xs ~= new X(false, j, as[j]);\n\t\n\txs.sort!\"a.value > b.value\"();\n\t\n\tint[] has = new int[](m);\n\tint[] hbs = new int[](n);\n\t\n\tforeach(x; xs){\n\t\tif(x.isRow){\n\t\t\tint i = x.number;\n\t\t\tint v = x.value;\n\t\t\tif(hbs[i] == v) continue;\n\t\t\tforeach(j; 0 .. m) if(as[j] >= v && cs[i][j]){\n\t\t\t\tcs[i][j] = 0;\n\t\t\t\tans[i][j] = v;\n\t\t\t\tif(hbs[i] < v) hbs[i] = v;\n\t\t\t\tif(has[j] < v) has[j] = v;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tint j = x.number;\n\t\t\tint v = x.value;\n\t\t\tif(has[j] == v) continue;\n\t\t\tforeach(i; 0 .. n) if(bs[i] >= v && cs[i][j]){\n\t\t\t\tcs[i][j] = 0;\n\t\t\t\tans[i][j] = v;\n\t\t\t\tif(hbs[i] < v) hbs[i] = v;\n\t\t\t\tif(has[j] < v) has[j] = v;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tforeach(i; 0 .. n) foreach(j; 0 .. m) if(cs[i][j] && ! ans[i][j]) ans[i][j] = 1;\n\n\tforeach(i; 0 .. n) ans[i].map!(to!string).array.join(\" \").writeln;\n\t\n}\n\nclass X{\n\tbool isRow;\n\tint number;\n\tint value;\n\tthis(bool isRow, int number, int value){\n\t\tthis.isRow = isRow;\n\t\tthis.number = number;\n\t\tthis.value = value;\n\t}\n}\n\n/*\n\ngreedy.\ntaller column or row will be dealt earlier, then shorter ones.\n\nat end, fill unused cells with height 1.\n\n*/\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto H = s[2];\n auto A = readln.split.map!(to!int).array;\n auto B = readln.split.map!(to!int).array;\n auto C = N.iota.map!(_ => readln.split.map!(to!int).array).array;\n\n auto ans = new int[][](N, M);\n\n foreach (i; 0..N) {\n foreach (j; 0..M) {\n if (C[i][j] == 0) continue;\n ans[i][j] = min(A[j], B[i]);\n }\n }\n\n ans.each!(a => a.map!(to!string).join(\" \").writeln);\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!uint;\n\tauto M = RD!uint;\n\tauto H = RD;\n\tauto a = RDR.ARR;\n\tauto b = RDR.ARR;\n\tauto aa = a.dup;\n\tauto bb = b.dup;\n\tauto c = new long[][](N, M);\n\tauto ans = new long[][](N, M);\n\tforeach (i; 0..N)\n\t{\n\t\tc[i] = RDR.ARR;\n\t\tans[i] = c[i].dup;\n\t}\n\n\tlong cnt_a, cnt_b;\n\tforeach (x; 0..M)\n\t{\n\t\tif (a[x] != 0) ++cnt_a;\n\t}\n\tforeach (y; 0..N)\n\t{\n\t\tif (b[y] != 0) ++cnt_b;\n\t}\n\t\n\tlong last_ca, last_cb;\n\twhile (cnt_a != 0 || cnt_b != 0)\n\t{\n\t\tforeach (x; 0..M)\n\t\t{\n\t\t\tif (a[x] == 0) continue;\n\n\t\t\tlong cnt;\n\t\t\tuint last;\n\t\t\tforeach (y; 0..N)\n\t\t\t{\n\t\t\t\tif (c[y][x] == 1)\n\t\t\t\t{\n\t\t\t\t\t++cnt;\n\t\t\t\t\tlast = y;\n\t\t\t\t}\n\t\t\t\telse if (ans[y][x] == a[x])\n\t\t\t\t{\n\t\t\t\t\tforeach (y2; 0..N)\n\t\t\t\t\t{\n\t\t\t\t\t\tc[y2][x] = 0;\n\t\t\t\t\t}\n\t\t\t\t\ta[x] = 0;\n\t\t\t\t\t--cnt_a;\n\t\t\t\t\tcnt = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (cnt == 1)\n\t\t\t{\n\t\t\t\tans[last][x] = a[x];\n\t\t\t\tc[last][x] = 0;\n\t\t\t\ta[x] = 0;\n\t\t\t\t--cnt_a;\n\t\t\t}\n\t\t\telse if (cnt == 0)\n\t\t\t{\n\t\t\t\tforeach (y; 0..N)\n\t\t\t\t{\n\t\t\t\t\tif (ans[y][x] == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tans[y][x] = a[x];\n\t\t\t\t\t\tc[y][x] = 0;\n\t\t\t\t\t\ta[x] = 0;\n\t\t\t\t\t\t--cnt_a;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tforeach (y; 0..N)\n\t\t{\n\t\t\tif (b[y] == 0) continue;\n\n\t\t\tlong cnt;\n\t\t\tuint last;\n\t\t\tforeach (x; 0..M)\n\t\t\t{\n\t\t\t\tif (c[y][x] == 1)\n\t\t\t\t{\n\t\t\t\t\t++cnt;\n\t\t\t\t\tlast = x;\n\t\t\t\t}\n\t\t\t\telse if (ans[y][x] == b[y])\n\t\t\t\t{\n\t\t\t\t\tforeach (x2; 0..M)\n\t\t\t\t\t{\n\t\t\t\t\t\tc[y][x2] = 0;\n\t\t\t\t\t}\n\t\t\t\t\tb[y] = 0;\n\t\t\t\t\t--cnt_b;\n\t\t\t\t\tcnt = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (cnt == 1)\n\t\t\t{\n\t\t\t\tans[y][last] = b[y];\n\t\t\t\tc[y][last] = 0;\n\t\t\t\tb[y] = 0;\n\t\t\t\t--cnt_b;\n\t\t\t}\n\t\t\telse if (cnt == 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..M)\n\t\t\t\t{\n\t\t\t\t\tif (ans[y][x] == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tans[y][x] = b[y];\n\t\t\t\t\t\tc[y][x] = 0;\n\t\t\t\t\t\tb[y] = 0;\n\t\t\t\t\t\t--cnt_b;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (cnt_a == last_ca && cnt_b == last_cb)\n\t\t\tbreak;\n\t\tlast_ca = cnt_a;\n\t\tlast_cb = cnt_b;\n\t}\n\n\tdebug writeln(a);\n\tdebug writeln(b);\n\t//while (cnt_a != 0 || cnt_b != 0)\n\t{\n\t\tforeach (x; 0..M)\n\t\t{\n\t\t\tif (a[x] != 0)\n\t\t\t{\n\t\t\t\tforeach (y; 0..N)\n\t\t\t\t{\n\t\t\t\t\tif (ans[y][x] == 1 && bb[y] >= a[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tans[y][x] = a[x];\n\t\t\t\t\t\ta[x] = 0;\n\t\t\t\t\t\t--cnt_a;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tforeach (y; 0..N)\n\t\t{\n\t\t\tif (b[y] != 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..M)\n\t\t\t\t{\n\t\t\t\t\tif (ans[y][x] == 1 && aa[x] >= b[y])\n\t\t\t\t\t{\n\t\t\t\t\t\tans[y][x] = b[y];\n\t\t\t\t\t\tb[y] = 0;\n\t\t\t\t\t\t--cnt_b;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tdebug writeln(a);\n\tdebug writeln(b);\n\t\n\tforeach (y; 0..N)\n\t{\n\t\twrite(ans[y][0]);\n\t\tforeach (x; 1..M)\n\t\t{\n\t\t\twrite(\" \", ans[y][x]);\n\t\t}\n\t\twriteln();\n\t}\n\t\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "7361e8acf0d712c317e8b99211a7b548"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nvoid bAdd(T)(T[] bit, int pos, T val)\nin {\n assert(0 <= pos && pos < bit.length, \"bAdd: 0 <= pos < |bit| must hold\");\n}\ndo {\n for (int x = pos; x < bit.length; x |= x + 1) {\n bit[x] += val;\n }\n}\n\n// sum of [0, pos)\nT bSum(T)(T[] bit, int pos)\nin {\n assert(0 <= pos && pos <= bit.length, \"bSum: 0 <= pos <= |bit| must hold\");\n}\ndo {\n T ret = 0;\n for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {\n ret += bit[x];\n }\n return ret;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n const lim = A.maxElement + 1;\n auto poss = new RedBlackTree!int[lim];\n foreach (a; 0 .. lim) {\n poss[a] = new RedBlackTree!int;\n }\n foreach (i; 0 .. N) {\n poss[A[i]].insert(i);\n }\n \n auto bit = new int[N];\n foreach (i; 0 .. N) {\n bit.bAdd(i, +1);\n }\n \n long ans;\n int cur;\n foreach (a; 0 .. lim) {\n for (; !poss[a].empty; ) {\n auto ran = poss[a].upperBound(cur - 1);\n if (ran.empty) {\n ans += bit.bSum(N) - bit.bSum(cur);\n cur = 0;\n ran = poss[a][];\n }\n const i = ran.front;\n poss[a].removeKey(i);\n ans += bit.bSum(i) - bit.bSum(cur);\n ans += 1;\n bit.bAdd(i, -1);\n cur = i;\n debug {\n writeln(\"cur = \", cur, \", ans = \", ans);\n }\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto B = new int[][](100010);\n\n if (N == 1) {\n writeln(1);\n return;\n }\n\n foreach (i, a; A.enumerate) {\n B[a] ~= i.to!int;\n }\n\n auto C = A.dup;\n C.sort();\n C = C.uniq().array;\n\n int p = -1;\n long ans = 0;\n auto st = new SegmentTree(100010);\n\n foreach (c; C) {\n int M = B[c].length.to!int;\n int q = B[c].assumeSorted.lowerBound(p).length.to!int;\n if (q == M) q = 0;\n foreach (i; 0..M) {\n if (B[c][(q+i)%M] >= p) {\n ans += B[c][(q+i)%M] - p;\n ans -= st.sum(p + 1, B[c][(q+i)%M]);\n } else {\n ans += B[c][(q+i)%M] - p + N;\n ans -= st.sum(p + 1, 100010) + st.sum(0, B[c][(q+i)%M]-1);\n }\n p = B[c][(q+i)%M];\n st.add(p, 1);\n }\n }\n\n ans.writeln;\n}\n\n\n\nclass SegmentTree {\n int[] table;\n int size;\n\n this(int n) {\n assert(bsr(n) < 29);\n size = 1 << (bsr(n) + 2);\n table = new int[](size);\n }\n\n void add(int pos, int num) {\n return add(pos, num, 0, 0, size/2-1);\n }\n\n void add(int pos, int num, int i, int left, int right) {\n table[i] += num;\n if (left == right)\n return;\n auto mid = (left + right) / 2;\n if (pos <= mid)\n add(pos, num, i*2+1, left, mid);\n else\n add(pos, num, i*2+2, mid+1, right);\n }\n\n int sum(int pl, int pr) {\n if (pl > pr) return 0;\n return sum(pl, pr, 0, 0, size/2-1);\n }\n\n int sum(int pl, int pr, int i, int left, int right) {\n if (pl > right || pr < left)\n return 0;\n else if (pl <= left && right <= pr)\n return table[i];\n else\n return\n sum(pl, pr, i*2+1, left, (left+right)/2) +\n sum(pl, pr, i*2+2, (left+right)/2+1, right);\n }\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 10 ^^ 5 + 100;\n\nstruct fw {\n int n;\n int[] arr;\n \n this (int n) {\n this.n = n;\n arr = new int[n+1];\n }\n \n void add(int p, int x) {\n while (p <= n) {\n arr[p] += x;\n p += (p & (-p));\n }\n }\n \n int sm(int p) {\n int ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n \n int sm(int le, int r) {\n return sm(r) - sm(le);\n }\n \n int dist(int fr, int to) {\n if (fr < to) { return sm(fr, to); }\n\n return sm(fr, n) + sm(0, to); \n }\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n DList!int[int] d;\n \n foreach (e; arr.dup.sort.uniq) { d[e] = DList!int(); }\n foreach (i, e; arr) { d[e] ~= (i.to!int + 1); }\n \n debug { d.writeln; }\n \n auto f = new fw(n);\n foreach (i; 1 .. MX) { f.add(i, 1); }\n \n long ans = 0;\n int pos = 0;\n foreach (k; d.keys.sort) {\n auto lst = d[k];\n \n while (f.dist(pos, lst.back) < f.dist(pos, lst.front)) {\n lst.insertFront(lst.back);\n lst.removeBack();\n }\n \n debug { write(k, \": \"); lst.each!write; writeln; }\n \n foreach (e; lst) {\n ans += f.dist(pos, e);\n \n f.add(e, -1);\n pos = e;\n }\n }\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto B = new int[][](100010);\n\n if (N == 1) {\n writeln(1);\n return;\n }\n\n foreach (i, a; A.enumerate) {\n B[a] ~= i.to!int;\n }\n\n auto C = A.dup;\n C.sort();\n C = C.uniq().array;\n\n int p = -1;\n long ans = 0;\n auto st = new SegmentTree(100010);\n\n foreach (c; C) {\n int M = B[c].length.to!int;\n int q = B[c].assumeSorted.lowerBound(p + 1).length.to!int;\n if (q == M) q = 0;\n foreach (i; 0..M) {\n if (B[c][(q+i)%M] >= p) {\n ans += B[c][(q+i)%M] - p;\n ans -= st.sum(B[c][(q+i)%M], p-1);\n } else {\n ans += B[c][(q+i)%M] - p + N;\n ans -= st.sum(p + 1, 100010) + st.sum(0, B[c][(q+i)%M]-1);\n }\n p = B[c][(q+i)%M];\n st.add(p, 1);\n }\n }\n\n ans.writeln;\n}\n\n\n\nclass SegmentTree {\n int[] table;\n int size;\n\n this(int n) {\n assert(bsr(n) < 29);\n size = 1 << (bsr(n) + 2);\n table = new int[](size);\n }\n\n void add(int pos, int num) {\n return add(pos, num, 0, 0, size/2-1);\n }\n\n void add(int pos, int num, int i, int left, int right) {\n table[i] += num;\n if (left == right)\n return;\n auto mid = (left + right) / 2;\n if (pos <= mid)\n add(pos, num, i*2+1, left, mid);\n else\n add(pos, num, i*2+2, mid+1, right);\n }\n\n int sum(int pl, int pr) {\n if (pl > pr) return 0;\n return sum(pl, pr, 0, 0, size/2-1);\n }\n\n int sum(int pl, int pr, int i, int left, int right) {\n if (pl > right || pr < left)\n return 0;\n else if (pl <= left && right <= pr)\n return table[i];\n else\n return\n sum(pl, pr, i*2+1, left, (left+right)/2) +\n sum(pl, pr, i*2+2, (left+right)/2+1, right);\n }\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 10 ^^ 5 + 100;\n\nstruct fw {\n int[] arr = new int[MX];\n \n void add(int p) {\n while (p < MX) {\n arr[p] += 1;\n p += (p & (-p));\n }\n }\n \n int sm(int p) {\n int ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n \n int sm(int le, int r) {\n return sm(r) - sm(le);\n }\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n DList!int[int] d;\n \n foreach (e; arr.dup.sort.uniq) {\n d[e] = DList!int(); \n }\n \n foreach (i, e; arr) {\n d[e] ~= (i.to!int + 1); \n }\n \n debug { d.writeln; }\n \n bool isCloser(int curPos, int pos1, int pos2) {\n return curPos < pos1 || curPos > pos2;\n }\n \n auto f = new fw();\n \n long ans = 0;\n int pos = 0;\n foreach (k; d.keys.sort) {\n auto lst = d[k];\n while (!lst.front == lst.back && isCloser(pos, lst.back, lst.front)) {\n lst.insertFront(lst.back);\n lst.removeBack();\n }\n \n debug { write(k, \": \"); lst.each!write; writeln; }\n \n int getCards(int le, int r) { return r - le - f.sm(le, r); }\n \n foreach (e; lst) {\n if (pos < e) { \n ans += getCards(pos, e);\n } else {\n ans += getCards(pos, n) + getCards(0, e);\n }\n \n f.add(e);\n pos = e;\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 10 ^^ 5 + 100;\n\nstruct fw {\n int[] arr = new int[MX];\n \n void add(int p, int x) {\n while (p < MX) {\n arr[p] += x;\n p += (p & (-p));\n }\n }\n \n int sm(int p) {\n int ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n \n int sm(int le, int r) {\n return sm(r) - sm(le);\n }\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n DList!int[int] d;\n \n foreach (e; arr.dup.sort.uniq) {\n d[e] = DList!int(); \n }\n \n foreach (i, e; arr) {\n d[e] ~= (i.to!int + 1); \n }\n \n debug { d.writeln; }\n \n bool isCloser(int curPos, int pos1, int pos2) {\n return curPos < pos1 || curPos > pos2;\n }\n \n auto f = new fw();\n foreach (i; 1 .. MX) f.add(i, 1);\n \n long ans = 0;\n int pos = 0;\n foreach (k; d.keys.sort) {\n auto lst = d[k];\n while (!lst.front == lst.back && isCloser(pos, lst.back, lst.front)) {\n lst.insertFront(lst.back);\n lst.removeBack();\n }\n \n debug { write(k, \": \"); lst.each!write; writeln; }\n \n foreach (e; lst) {\n if (pos < e) { \n ans += f.sm(pos, e);\n } else {\n ans += f.sm(pos, n) + f.sm(0, e);\n }\n \n f.add(e, -1);\n pos = e;\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 10 ^^ 5 + 100;\n\nstruct fw {\n int[] arr = new int[MX];\n \n void add(int p) {\n while (p < MX) {\n arr[p] += 1;\n p += (p & (-p));\n }\n }\n \n int sm(int p) {\n int ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n \n int sm(int le, int r) {\n return sm(r) - sm(le);\n }\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n DList!int[int] d;\n \n foreach (e; arr.sort.uniq) {\n d[e] = DList!int(); \n }\n \n foreach (i, e; arr) {\n d[e] ~= (i.to!int + 1); \n }\n \n debug { d.writeln; }\n \n bool isCloser(int curPos, int pos1, int pos2) {\n return curPos < pos1 || curPos > pos2;\n }\n \n auto f = new fw();\n \n long ans = 0;\n int pos = 0;\n foreach (k; d.keys) {\n auto lst = d[k];\n while (!lst.front == lst.back && isCloser(pos, lst.back, lst.front)) {\n lst.insertFront(lst.back);\n lst.removeBack();\n }\n \n debug { lst.each!write; writeln; }\n \n foreach (e; lst) {\n if (pos < e) { \n ans += e - pos - f.sm(pos, e);\n } else {\n ans += n - pos - f.sm(pos, n) + e - f.sm(e);\n }\n \n f.add(e);\n pos = e;\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nstruct fw {\n int mx;\n int[] arr;\n \n this(int mx) {\n this.mx = mx;\n arr = new int[] (mx+1);\n }\n \n void add(int p) {\n while (p <= mx) {\n arr[p] += 1;\n p += (p & (-p));\n }\n }import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nstruct fw {\n int mx;\n int[] arr;\n \n this(int mx) {\n this.mx = mx;\n arr = new int[] (mx+1);\n }\n \n void add(int p) {\n while (p <= mx) {\n arr[p] += 1;\n p += (p & (-p));\n }\n }\n \n int sm(int p) {\n int ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n \n int sm(int p1, int p2) {\n return sm(p2) - sm(p1);\n }\n};\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n Tuple!(int, int)[] arr2;\n int[int] cnt;\n foreach (ref e; arr) {\n arr2 ~= tuple(e, cnt.get(e, 0));\n cnt[e] += 1; \n }\n \n auto idx = new int[n];\n makeIndex!(\"a < b\")(arr2, idx);\n \n idx = idx.map!(x => x+1).array;\n \n debug { idx.writeln; }\n \n auto f = new fw(n);\n \n long ans = 0;\n int lst = 0;\n foreach (e; idx) {\n if (e > lst) { ans += e - lst - f.sm(lst, e); }\n else {\n ans += n - lst - f.sm(lst, n) + e - f.sm(e);\n }\n \n debug { ans.writeln; }\n \n f.add(e);\n lst = e;\n }\n \n ans.writeln;\n}\n \n int sm(int p) {\n int ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n \n int sm(int p1, int p2) {\n return sm(p2) - sm(p1);\n }\n};\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n Tuple!(int, int)[] arr2;\n int[int] cnt;\n foreach (ref e; arr) {\n arr2 ~= tuple(e, cnt.get(e, 0));\n cnt[e] += 1; \n }\n \n auto idx = new int[n];\n makeIndex!(\"a < b\")(arr2, idx);\n \n idx = idx.map!(x => x+1).array;\n \n debug { idx.writeln; }\n \n auto f = new fw(n);\n \n int ans = 0;\n int lst = 0;\n foreach (e; idx) {\n if (e > lst) { ans += e - lst - f.sm(lst, e); }\n else {\n ans += n - lst - f.sm(lst, n) + e - f.sm(e);\n }\n \n debug { ans.writeln; }\n \n f.add(e);\n lst = e;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 10 ^^ 5 + 100;\n\nstruct fw {\n int n;\n int[] arr;\n \n this (int n) {\n this.n = n;\n arr = new int[n+1];\n }\n \n void add(int p, int x) {\n while (p <= n) {\n arr[p] += x;\n p += (p & (-p));\n }\n }\n \n int sm(int p) {\n int ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n \n int sm(int le, int r) {\n return sm(r) - sm(le);\n }\n \n int dist(int le, int r) {\n if (le < r) { return sm(le, r); }\n\n return sm(r, n) + sm(0, le); \n }\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n DList!int[int] d;\n \n foreach (e; arr.dup.sort.uniq) { d[e] = DList!int(); }\n \n foreach (i, e; arr) { d[e] ~= (i.to!int + 1); }\n \n debug { d.writeln; }\n \n auto f = new fw(n);\n foreach (i; 1 .. MX) f.add(i, 1);\n \n long ans = 0;\n int pos = 0;\n foreach (k; d.keys.sort) {\n auto lst = d[k];\n while (!lst.front == lst.back && f.dist(pos, lst.back) < f.dist(pos, lst.front)) {\n lst.insertFront(lst.back);\n lst.removeBack();\n }\n \n debug { write(k, \": \"); lst.each!write; writeln; }\n \n foreach (e; lst) {\n ans += f.dist(pos, e);\n \n f.add(e, -1);\n pos = e;\n }\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int MX = 10 ^^ 5 + 100;\n\nstruct fw {\n int n;\n int[] arr;\n \n this (int n) {\n this.n = n;\n arr = new int[n+1];\n }\n \n void add(int p, int x) {\n while (p <= n) {\n arr[p] += x;\n p += (p & (-p));\n }\n }\n \n int sm(int p) {\n int ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n \n int sm(int le, int r) {\n return sm(r) - sm(le);\n }\n \n int dist(int le, int r) {\n if (le < r) { return sm(le, r); }\n\n return sm(r, n) + sm(0, le); \n }\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n DList!int[int] d;\n \n foreach (e; arr.dup.sort.uniq) { d[e] = DList!int(); }\n \n foreach (i, e; arr) { d[e] ~= (i.to!int + 1); }\n \n debug { d.writeln; }\n \n auto f = new fw(n);\n foreach (i; 1 .. MX) f.add(i, 1);\n \n long ans = 0;\n int pos = 0;\n foreach (k; d.keys.sort) {\n auto lst = d[k];\n while (f.dist(pos, lst.back) < f.dist(pos, lst.front)) {\n lst.insertFront(lst.back);\n lst.removeBack();\n }\n \n debug { write(k, \": \"); lst.each!write; writeln; }\n \n foreach (e; lst) {\n ans += f.dist(pos, e);\n \n f.add(e, -1);\n pos = e;\n }\n }\n \n ans.writeln;\n}"}], "src_uid": "68987c2618285686aa9b505e0a3d8230"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tlong best = long.max;\n\tlong cnt;\n\tforeach (i; 0..n/2)\n\t{\n\t\tcnt += a[i*2];\n\t}\n\tbest.chmin(cnt);\n\tforeach (i; 1..n/2+1)\n\t{\n\t\tauto l = ((i-1)*2) % n;\n\t\tauto r = (l+(n/2*2)) % n;\n\t\tcnt += a[r] - a[l];\n\t\tbest.chmin(cnt); \n\t\tdebug writeln(\"l:\", l, \" r:\", r, \" cnt:\", cnt);\n\t}\n\n\tcnt = 0;\n\tforeach (i; 0..n/2)\n\t{\n\t\tcnt += a[i*2+1];\n\t}\n\tbest.chmin(cnt);\n\tforeach (i; 1..n/2)\n\t{\n\t\tauto l = ((i-1)*2+1) % n;\n\t\tauto r = (l+(n/2*2)) % n;\n\t\tcnt += a[r] - a[l];\n\t\tbest.chmin(cnt);\n\t\tdebug writeln(\"l:\", l, \" r:\", r, \" cnt:\", cnt);\n\t}\n\n\tlong ans;\n\tforeach (e; a)\n\t\tans += e;\n\tans -= best;\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n \nvoid main ()\n{\n\tauto n = readln.strip.to !(int);\n\tauto a = readln.splitter.map !(to !(int)).array;\n\n\tint [] b;\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tb ~= a[(i * 2) % n];\n\t}\n\tb ~= b;\n\tdebug {writeln (b);}\n\n\tlong [] s = [0L];\n\tforeach (c; b)\n\t{\n\t\ts ~= s.back + c;\n\t}\n\tdebug {writeln (s);}\n\n\tint half = n / 2 + 1;\n\tlong res = 0;\n\tforeach (i; half..s.length)\n\t{\n\t\tres = max (res, s[i] - s[i - half]);\n\t}\n\twriteln (res);\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto n = readln.strip.to !(int);\n\tauto a = readln.splitter.map !(to !(int)).array;\n\tlong cur = 0;\n\tlong res = 0;\n\tauto b = a.cycle;\n\tforeach (i; 0..n * 2)\n\t{\n\t\tcur += b.front;\n\t\tb.popFront ();\n\t\tb.popFront ();\n\t\tif (i > n / 2)\n\t\t{\n\t\t\tcur -= b[n];\n\t\t}\n\t\tres = max (res, cur);\n//\t\twriteln (cur);\n\t}\n\twriteln (res);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tlong best = long.max;\n\tlong cnt;\n\tforeach (i; 0..n/2)\n\t{\n\t\tcnt += a[i*2];\n\t}\n\tbest.chmin(cnt);\n\tforeach (i; 1..n/2+1)\n\t{\n\t\tauto l = ((i-1)*2) % n;\n\t\tauto r = (i*2+n/2-1) % n;\n\t\tcnt += a[r] - a[l];\n\t\tbest.chmin(cnt); \n\t\tdebug writeln(\"l:\", l, \" r:\", r, \" cnt:\", cnt);\n\t}\n\n\tcnt = 0;\n\tforeach (i; 0..n/2)\n\t{\n\t\tcnt += a[i*2+1];\n\t}\n\tbest.chmin(cnt);\n\tforeach (i; 1..n/2+1)\n\t{\n\t\tauto l = ((i-1)*2+1) % n;\n\t\tauto r = (i*2+n/2) % n;\n\t\tcnt += a[r] - a[l];\n\t\tbest.chmin(cnt);\n\t\tdebug writeln(\"l:\", l, \" r:\", r, \" cnt:\", cnt);\n\t}\n\n\tlong ans;\n\tforeach (e; a)\n\t\tans += e;\n\tans -= best;\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tlong best = long.max;\n\tforeach (i; 0..4)\n\t{\n\t\tforeach (dir; [-2, 2])\n\t\t{\n\t\t\tlong cnt;\n\t\t\tint pos = i % n;\n\t\t\tforeach (j; 0..n/2)\n\t\t\t{\n\t\t\t\tcnt += a[pos];\n\t\t\t\tpos += dir;\n\t\t\t\tpos = (pos + n) % n;\n\t\t\t}\n\t\t\tbest.chmin(cnt);\n\t\t}\n\t}\n\n\tauto ans = a.sum - best;\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA;\n\n\tlong best = long.max;\n\tlong cnt;\n\tforeach (i; 0..n/2)\n\t{\n\t\tcnt += a[i*2];\n\t}\n\tbest.chmin(cnt);\n\tforeach (i; 1..n/2+1)\n\t{\n\t\tauto l = ((i-1)*2) % n;\n\t\tauto r = (i*2+n/2-1) % n;\n\t\tcnt += a[r] - a[l];\n\t\tbest.chmin(cnt); \n\t}\n\n\tcnt = 0;\n\tforeach (i; 0..n/2)\n\t{\n\t\tcnt += a[i*2+1];\n\t}\n\tbest.chmin(cnt);\n\tforeach (i; 1..n/2+1)\n\t{\n\t\tauto l = ((i-1)*2+1) % n;\n\t\tauto r = (i*2+n/2) % n;\n\t\tcnt += a[r] - a[l];\n\t\tbest.chmin(cnt); \n\t}\n\n\tauto ans = a.sum - best;\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "a9473e6ec81c10c4f88973ac2d60ad04"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.split.map!(to!ulong).array;\n \n int div3 (ulong x) {\n return x % 3 == 0 ? 1 + div3(x/3) : 0;\n }\n \n auto b = a\n .map!(x => tuple(div3(x), x)).array\n .multiSort!(q{ a[0] > b[0] }, q{ a[1] < b[1] })\n .map!(q{ a[1] });\n \n writefln (\"%(%s %)\", b);\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.string, std.bigint;\n\nvoid main()\n{\n int n;\n readf(\" %s\", n);\n\n bool[BigInt] d;\n\n int maxPow = -1;\n BigInt curValue = ulong.max;\n\n foreach (_; 0 .. n)\n {\n ulong t;\n readf(\" %s\", t);\n d[cast(BigInt)t] = true;\n\n int pow = 0;\n BigInt tc = t;\n\n while (tc % 3 == 0)\n {\n tc /= 3;\n pow++;\n }\n\n if (pow > maxPow || pow == maxPow && curValue > t)\n {\n maxPow = pow;\n curValue = t;\n }\n }\n\n foreach (_; 0 .. n)\n {\n write(curValue, ' ');\n\n if (curValue * 2 in d)\n {\n curValue *= 2;\n }\n else\n {\n curValue /= 3;\n }\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.split.map!(to!ulong).array;\n \n int div3 (ulong x) {\n int r = 0;\n while (x % 3 == 0) x /= 3, ++r;\n return r;\n }\n \n auto b = a\n .map!(x => tuple(div3(x), x)).array\n .multiSort!(q{ a[0] > b[0] }, q{ a[1] < b[1] })\n .map!(q{ a[1] });\n \n writefln (\"%(%s %)\", b);\n}"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n; readV(n);\n long[] a; readA(n, a);\n\n auto p = new int[](n); p[] = -1;\n foreach (i; 0..n)\n foreach (j; 0..n)\n if (a[j]%3 == 0 && a[j]/3 == a[i] || a[j]*2 == a[i]) p[j] = i;\n\n auto i = iota(n).countUntil!(i => !p.canFind(i));\n while (i != -1) {\n write(a[i], \" \");\n i = p[i];\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.string;\n\nvoid main()\n{\n int n;\n readf(\" %s\", n);\n\n bool[ulong] d;\n\n int maxPow = -1;\n ulong curValue;\n\n foreach (_; 0 .. n)\n {\n ulong t;\n readf(\" %s\", t);\n d[t] = true;\n\n int pow = 0;\n ulong tc = t;\n\n while (tc % 3 == 0)\n {\n tc /= 3;\n pow++;\n }\n\n if (pow > maxPow)\n {\n maxPow = pow;\n curValue = t;\n }\n }\n\n foreach (_; 0 .. n)\n {\n write(curValue, ' ');\n\n if (curValue * 2 in d)\n {\n curValue *= 2;\n }\n else\n {\n curValue /= 3;\n }\n }\n}"}, {"source_code": "import std.stdio, std.algorithm, std.string, std.bigint;\n\nvoid main()\n{\n int n;\n readf(\" %s\", n);\n\n bool[BigInt] d;\n\n int maxPow = -1;\n BigInt curValue = ulong.max;\n\n foreach (_; 0 .. n)\n {\n ulong t;\n readf(\" %s\", t);\n d[cast(BigInt)t] = true;\n\n int pow = 0;\n BigInt tc = t;\n\n while (tc % 3 == 0)\n {\n tc /= 3;\n pow++;\n }\n\n if (pow > maxPow && curValue > t)\n {\n maxPow = pow;\n curValue = t;\n }\n }\n\n foreach (_; 0 .. n)\n {\n write(curValue, ' ');\n\n if (curValue * 2 in d)\n {\n curValue *= 2;\n }\n else\n {\n curValue /= 3;\n }\n }\n}"}, {"source_code": "import std.stdio, std.algorithm, std.string, std.bigint;\n\nvoid main()\n{\n int n;\n readf(\" %s\", n);\n\n bool[BigInt] d;\n\n int maxPow = -1;\n BigInt curValue;\n\n foreach (_; 0 .. n)\n {\n ulong t;\n readf(\" %s\", t);\n d[cast(BigInt)t] = true;\n\n int pow = 0;\n BigInt tc = t;\n\n while (tc % 3 == 0)\n {\n tc /= 3;\n pow++;\n }\n\n if (pow > maxPow)\n {\n maxPow = pow;\n curValue = t;\n }\n }\n\n foreach (_; 0 .. n)\n {\n write(curValue, ' ');\n\n if (curValue * 2 in d)\n {\n curValue *= 2;\n }\n else\n {\n curValue /= 3;\n }\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.split.map!(to!ulong).array;\n \n int div3 (ulong x) {\n int r = 0;\n while (x % 3 == 0) x /= 3, ++r;\n return r;\n }\n \n auto b = a.map!(x => tuple(div3(x), x)).array.sort!(q{ a[0] > b[0] }).map!(q{ a[1] });\n writefln (\"%(%s %)\", b);\n \n}"}], "src_uid": "f9375003a3b64bab17176a05764c20e8"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n arr.sort();\n \n auto f = (int x) => zip(arr, arr.drop(x)).filter!(t => t[0] == t[1]).map!(t => t[0]).uniq;\n auto nrs1 = f(1);\n auto nrs2 = f(3);\n \n auto nrs = nrs1.chain(nrs2).array.sort();\n \n debug { nrs.writeln; }\n \n auto ans = tuple(nrs[0], nrs[1]);\n foreach (a, b; lockstep(nrs.dropOne, nrs.drop(2))) {\n if (ans[1] * a > ans[0] * b) ans = tuple(a, b);\n }\n \n writeln(ans[0], ' ', ans[0], ' ', ans[1], ' ', ans[1]);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n int T = readln.chomp.to!int;\n while (T--) solve;\n}\n\nvoid solve() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n long[long] C;\n long[] B;\n\n foreach (a; A) C[a] += 1;\n foreach (k; C.keys) if (C[k] >= 2) B ~= k;\n B.sort();\n\n bool comp(long a1, long b1, long a2, long b2) {\n return\n 4 * (a1 + b1) * (a1 + b1) * a2 * b2 <=\n 4 * (a2 + b2) * (a2 + b2) * a1 * b1;\n }\n\n long aa = -1;\n long bb = -1;\n\n foreach (i; 0..B.length.to!int) {\n long b = B[i];\n long a1 = -1;\n long a2 = -1;\n if (C[b] >= 4) {\n a1 = a2 = b;\n } else if (i == 0) {\n a1 = a2 = B[i+1];\n } else if (i == B.length.to!int - 1) {\n a1 = a2 = B[i-1];\n } else {\n a1 = B[i+1];\n a2 = B[i-1];\n }\n long a = comp(a1, b, a2, b) ? a1 : a2;\n if (aa == -1) {\n aa = a;\n bb = b;\n } else if (comp(a, b, aa, bb)) {\n aa = a;\n bb = b;\n }\n }\n\n writeln(aa, \" \", aa, \" \", bb, \" \", bb);\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n arr.sort();\n \n auto nrs1 = zip(arr, arr.dropOne).filter!(t => t[0] == t[1]).map!(t => t[0]).uniq.array;\n auto nrs2 = zip(arr, arr.drop(3)).filter!(t => t[0] == t[1]).map!(t => t[0]).uniq.array;\n \n auto nrs = nrs1.chain(nrs2).sort().array;\n \n debug { nrs.writeln; }\n \n auto ans = tuple(nrs[0], nrs[1]);\n foreach (a, b; lockstep(nrs.dropOne, nrs.drop(2))) {\n if (ans[1] * a > ans[0] * b) ans = tuple(a, b);\n }\n \n writeln(ans[0], ' ', ans[0], ' ', ans[1], ' ', ans[1]);\n }\n}"}], "negative_code": [], "src_uid": "fc54d6febbf1d91e9f0e6121f248d2aa"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nstruct Word {\n string s;\n int last;\n}\n\nvoid main() {\n int[char] v = [\n 'a' : 0,\n 'e' : 1,\n 'i' : 2,\n 'o' : 3,\n 'u' : 4\n ];\n int vowel (char c) {\n return v.get(c, -1);\n }\n immutable n = readln.strip.to!int;\n auto a = new string[n];\n size_t maxlen;\n foreach (i; 0 .. n) {\n a[i] = readln.strip;\n maxlen = max(maxlen, a[i].length);\n }\n auto l = new int[][5 * (maxlen+1)];\n foreach (i; 0 .. n) {\n int t, last = -1;\n foreach (c; a[i]) {\n int x = vowel (c);\n if (x >= 0){\n ++t;\n last = x;\n }\n }\n l[5 * t + last] ~= i;\n }\n alias T = Tuple!(int, int);\n T[] b;\n T[] c;\n foreach (k; 1 .. maxlen+1) {\n int[] tail;\n foreach (i; 0 .. 5) {\n auto idx = 5 * k + i;\n int cur = -1;\n foreach (j; l[idx]) {\n if (cur >= 0) {\n b ~= tuple (cur, j);\n cur = -1;\n } else {\n cur = j;\n }\n }\n if (cur >= 0) tail ~= cur;\n }\n foreach (i; 0 .. tail.length / 2) {\n c ~= tuple (tail[2*i], tail[2*i+1]);\n }\n }\n immutable bl = b.length;\n immutable cl = c.length;\n auto m = min (bl, (bl + cl) / 2);\n c ~= b[m .. $];\n writeln (m);\n foreach (i; 0 .. m) {\n int p12 = b[i][0], p22 = b[i][1];\n int p11 = c[i][0], p21 = c[i][1];\n writeln (a[p11], ' ', a[p12]);\n writeln (a[p21], ' ', a[p22]);\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = read.to!int;\n\t\n\tstring[] ws;\n\tforeach(i; 0 .. n) ws ~= readln.chomp;\n\t\n\tstruct X{ char last; int count; }\n\tstring[][X] dic;\n\tforeach(w; ws){\n\t\tint k;\n\t\tchar x;\n\t\tforeach(c; w) if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){\n\t\t\tx = c;\n\t\t\tk += 1;\n\t\t}\n\t\tif(X(x, k) !in dic) dic[X(x, k)] = [];\n\t\tdic[X(x, k)] ~= w;\n\t}\n\tlog(\"dic:\", dic);\n\t\n\tstring[2][] latters;\n\tX[] ks = dic.keys;\n\tstring[][int] dic2;\n\tforeach(k; ks){\n\t\tstring[] qs = dic[k];\n\t\tfor(int i = 0; i < qs.length - 1; i += 2){\n\t\t\tlatters ~= [qs[i], qs[i + 1]];\n\t\t}\n\t\tif(qs.length % 2){\n\t\t\tif(k.count !in dic2) dic2[k.count] = [];\n\t\t\tdic2[k.count] ~= qs[$ - 1];\n\t\t}\n\t}\n\tlog(\"latters:\", latters);\n\tlog(\"dic2:\", dic2);\n\t\n\tstring[2][] firsts;\n\tint[] cts = dic2.keys;\n\tforeach(ct; cts){\n\t\tstring[] qs = dic2[ct];\n\t\tfor(int i = 0; i < qs.length - 1; i += 2){\n\t\t\tfirsts ~= [qs[i], qs[i + 1]];\n\t\t}\n\t}\n\t\n\tint m = (latters.length + firsts.length).to!int / 2;\n\tif(m > latters.length) m = latters.length.to!int;\n\telse{\n\t\tforeach(i; m .. latters.length) firsts ~= latters[i];\n\t}\n\t\n\tm.writeln;\n\tforeach(i; 0 .. m){\n\t\twriteln(firsts[i][0], \" \", latters[i][0]);\n\t\twriteln(firsts[i][1], \" \", latters[i][1]);\n\t}\n}\n\t\n/*\n\nsettify with (last vowel, vowel count)\n\ngreedily make pair for latter words\ngreedily make pair for first words\n\n\n\n*/\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = new string[](n);\n\tint[2][][int] info1;\n\tint[2][][int] info2;\n\tauto toNum = ['a':0, 'i':1, 'u':2, 'e':3, 'o':4];\n\tforeach (i; 0..n)\n\t{\n\t\ts[i] = RD!string;\n\t\tint last;\n\t\tint cnt;\n\t\tforeach (c; s[i])\n\t\t{\n\t\t\tauto num = toNum.get(c, -1);\n\t\t\tif (num != -1)\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\tlast = num;\n\t\t\t}\n\t\t}\n\t\tinfo1[cnt] ~= [i, last];\n\t\tinfo2[cnt*10+last] ~= [i, last];\n\t}\n\n\tint[] ansSec;\n\tauto used = new bool[](n);\n\tauto keys2 = info2.keys;\n\tforeach (key2; keys2)\n\t{\n\t\tauto arr2 = info2[key2];\n\t\tauto len2 = arr2.length;\n\t\tforeach (i; 0..len2/2)\n\t\t{\n\t\t\tauto j = arr2[i*2][0];\n\t\t\tauto k = arr2[i*2+1][0];\n\t\t\tansSec ~= [j, k];\n\t\t\tused[j] = true;\n\t\t\tused[k] = true;\n\t\t}\n\t}\n\n\tint[] ansFst;\n\tauto keys1 = info1.keys;\n\tforeach (key1; keys1)\n\t{\n\t\tauto arr1 = info1[key1];\n\t\tauto len1 = arr1.length;\n\t\tint[] tmp;\n\t\tforeach (i; 0..len1)\n\t\t{\n\t\t\tauto j = arr1[i][0];\n\t\t\tif (used[j]) continue;\n\n\t\t\ttmp ~= j;\n\t\t\tif (tmp.length == 2)\n\t\t\t{\n\t\t\t\tansFst ~= tmp;\n\t\t\t\ttmp.length = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tauto diff = max(0, (cast(int)ansSec.length - cast(int)ansFst.length) / 4);\n\tforeach (i; 0..diff)\n\t{\n\t\tansFst ~= [ansSec[$-2], ansSec[$-1]];\n\t\tansSec.length = ansSec.length - 2;\n\t}\n\n\tauto len = min(ansFst.length, ansSec.length);\n\twriteln(len/2);\n\tforeach (i; 0..len)\n\t{\n\t\tauto j = ansFst[i];\n\t\tauto k = ansSec[i];\n\t\twriteln(s[j], \" \", s[k]);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto s = new string[](n);\n\tint[2][][int] info1;\n\tint[2][][int] info2;\n\tauto toNum = ['a':0, 'i':1, 'u':2, 'e':3, 'o':4];\n\tforeach (i; 0..n)\n\t{\n\t\ts[i] = RD!string;\n\t\tint last;\n\t\tint cnt;\n\t\tforeach (c; s[i])\n\t\t{\n\t\t\tauto num = toNum.get(c, -1);\n\t\t\tif (num != -1)\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\tlast = num;\n\t\t\t}\n\t\t}\n\t\tinfo1[cnt] ~= [i, last];\n\t\tinfo2[cnt*10+last] ~= [i, last];\n\t}\n\n\tint[] ansSec;\n\tauto used = new bool[](n);\n\tauto keys2 = info2.keys;\n\tforeach (key2; keys2)\n\t{\n\t\tauto arr2 = info2[key2];\n\t\tauto len2 = arr2.length;\n\t\tforeach (i; 0..len2/2)\n\t\t{\n\t\t\tauto j = arr2[i*2][0];\n\t\t\tauto k = arr2[i*2+1][0];\n\t\t\tansSec ~= [j, k];\n\t\t\tused[j] = true;\n\t\t\tused[k] = true;\n\t\t}\n\t}\n\n\tint[] ansFst;\n\tauto keys1 = info1.keys;\n\tforeach (key1; keys1)\n\t{\n\t\tauto arr1 = info1[key1];\n\t\tauto len1 = arr1.length;\n\t\tint[] tmp;\n\t\tforeach (i; 0..len1)\n\t\t{\n\t\t\tauto j = arr1[i][0];\n\t\t\tif (used[j]) continue;\n\n\t\t\ttmp ~= j;\n\t\t\tif (tmp.length == 2)\n\t\t\t{\n\t\t\t\tansFst ~= tmp;\n\t\t\t\ttmp.length = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tauto diff = max(0, (cast(int)ansSec.length - cast(int)ansFst.length) / 4);\n\tforeach (i; 0..diff)\n\t{\n\t\tansFst ~= [ansSec[$-2], ansSec[$-1]];\n\t\tansSec.length = ansSec.length - 2;\n\t}\n\n\twriteln(ansSec.length/2);\n\tforeach (i; 0..ansSec.length)\n\t{\n\t\tauto j = ansFst[i];\n\t\tauto k = ansSec[i];\n\t\twriteln(s[j], \" \", s[k]);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "f06f7d0dcef10f064f5ce1e9eccf3928"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int MAX_N = 100_005;\nimmutable int MAX_C = 0x3F3F3F3F;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n, x;\n\twhile (readf (\" %s %s\", &n, &x) > 0)\n\t{\n\t\tx--;\n\t\tauto p = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &p[i]);\n\t\t}\n\t\tp[] -= 1;\n\n\t\tauto r = new int [n];\n\t\tr[] = NA;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (p[i] != NA)\n\t\t\t{\n\t\t\t\tr[p[i]] = i;\n\t\t\t}\n\t\t}\n\n\t\tint [] [] s;\n\t\tint d = NA;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (p[i] == NA)\n\t\t\t{\n\t\t\t\tint [] cur;\n\t\t\t\tint j = i;\n\t\t\t\tcur ~= j;\n\t\t\t\twhile (r[j] != NA)\n\t\t\t\t{\n\t\t\t\t\tj = r[j];\n\t\t\t\t\tcur ~= j;\n\t\t\t\t}\n\t\t\t\tint e = cur.countUntil (x);\n\t\t\t\tif (e != NA)\n\t\t\t\t{\n\t\t\t\t\td = e;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ts ~= cur;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tassert (d != NA);\n\n\t\tauto f = new bool [n + 1];\n\t\tf[0] = true;\n\t\tforeach (cur; s)\n\t\t{\n\t\t\tint l = cur.length;\n\t\t\tfor (int i = n; i >= l; i--)\n\t\t\t{\n\t\t\t\tf[i] |= f[i - l];\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (f[i])\n\t\t\t{\n\t\t\t\twriteln (i + d + 1);\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int MAX_N = 100_005;\nimmutable int MAX_C = 0x3F3F3F3F;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n, x;\n\twhile (readf (\" %s %s\", &n, &x) > 0)\n\t{\n\t\tx--;\n\t\tauto p = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &p[i]);\n\t\t}\n\t\tp[] -= 1;\n\n\t\tauto r = new int [n];\n\t\tr[] = NA;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (p[i] != NA)\n\t\t\t{\n\t\t\t\tr[p[i]] = i;\n\t\t\t}\n\t\t}\n\n\t\tint [] [] s;\n\t\tint d = NA;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (p[i] == NA)\n\t\t\t{\n\t\t\t\tint [] cur;\n\t\t\t\tint j = i;\n\t\t\t\tcur ~= j;\n\t\t\t\twhile (r[j] != NA)\n\t\t\t\t{\n\t\t\t\t\tj = r[j];\n\t\t\t\t\tcur ~= j;\n\t\t\t\t}\n\t\t\t\tint e = cur.countUntil (x);\n\t\t\t\tif (e != NA)\n\t\t\t\t{\n\t\t\t\t\td = e;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ts ~= cur;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tassert (d != NA);\n\n\t\tauto f = new bool [n + 1];\n\t\tf[0] = true;\n\t\tforeach (cur; s)\n\t\t{\n\t\t\tint l = cur.length;\n\t\t\tfor (int i = n; i >= l; i--)\n\t\t\t{\n\t\t\t\tf[i] |= f[i - l];\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (f[i])\n\t\t\t{\n\t\t\t\twriteln (i + d + 1);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "5a6b97a2aa27dd2c562f73a7a8f16720"} {"source_code": "module C;\n\nimport std.stdio : readln, write, writeln;\n\nstruct IO {\n import std.conv : to;\n import std.range : empty, front, popFront, split;\n\n string readToken() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n\n int readInt() {\n return readToken.to!int;\n }\n\n string[] tokens;\n}\n\nimport std.container : Array;\nimport std.typecons : Tuple, tuple;\n\nconst int N = 30000;\n\nTuple!(int, int)[N] best;\nArray!int[N] divisors;\n\nvoid main() {\n import std.algorithm : min;\n import std.math : abs;\n\n for (int d = 1; d < N; ++d) {\n for (int n = d; n < N; n += d) {\n divisors[n].insert(d);\n }\n }\n IO io;\n int T = io.readInt;\n while (T--) {\n int a = io.readInt;\n int b = io.readInt;\n int c = io.readInt;\n auto result = tuple(a + b + c, 0, 0, 0);\n for (int z = 1; z < N; ++z) {\n best[z] = tuple(result[0], 0);\n foreach (y; divisors[z]) {\n best[z] = min(best[z], tuple(abs(y - a), y));\n }\n }\n for (int z = 1; z < N; ++z) {\n if (abs(z - c) < result[0]) {\n foreach (y; divisors[z]) {\n result = min(result, tuple(abs(z - c) + abs(y - b) + best[y][0], best[y][1], y, z));\n }\n }\n }\n writeln(result[0]);\n writeln(result[1], \" \", result[2], \" \", result[3]);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. rint){\n long a = rlong, b = rlong, c = rlong;\n long best = c * 3, A = a, B = b, C = c;\n foreach(long y; 1 .. 40000){\n long x = f(a, y);\n long z = g(c, y);\n long tmp = abs(x - a) + abs(y - b) + abs(z - c);\n log(\"a:\", a, \"b:\", b, \"c:\", c, \"x:\", x, \"y:\", y, \"z:\", z, \"tmp:\", tmp, \"best:\", best, \"A:\", A, \"B:\", B, \"C:\", C);\n if(tmp < best) best = tmp, A = x, B = y, C = z;\n }\n best.writeln;\n writeln(A, \" \", B, \" \", C);\n }\n}\nlong f(long a, long y){\n static long[][] us;\n if(! us.length){\n us ~= new long[](0);\n foreach(long i; 1 .. 40000) us ~= divisors(i);\n }\n\n long best = 40000, ans = -1;\n foreach(d; us[y.to!int]){\n if(abs(a - d) < best) best = abs(a - d), ans = d;\n }\n return ans;\n}\nlong[] divisors(long a){\n\tlong[] res, res2;\n\tfor(long d = 1; d * d <= a; d ++){\n\t\tif(a % d == 0) res ~= d, res2 ~= a / d;\n\t}\n\tforeach_reverse(d; res2) if(res[$ - 1] < d) res ~= d;\n\treturn res;\n}\nlong g(long c, long y){\n if(c % y > y / 2 || c / y == 0) return y * (c / y + 1);\n else return y * (c / y);\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto c = RD;\n\t\tans[ti] = [long.max];\n\t\tforeach (i; 1..10^^4+1)\n\t\t{\n\t\t\tauto cnt1 = abs(a - i);\n\t\t\tforeach (j; 1..10^^4+1)\n\t\t\t{\n\t\t\t\tif (i * j > (10^^4)*2) break;\n\t\t\t\tauto cnt2 = abs(b - i*j);\n\t\t\t\tlong num = c / (i*j), cnt3;\n\t\t\t\tif (num == 0)\n\t\t\t\t{\n\t\t\t\t\tnum = 1;\n\t\t\t\t\tcnt3 = (i*j) - c % (i*j);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif ((i*j) - c % (i*j) < c % (i*j))\n\t\t\t\t\t\t++num;\n\t\t\t\t\tcnt3 = min(c % (i*j), (i*j) - c % (i*j));\n\t\t\t\t}\n\t\t\t\tauto tmp = cnt1 + cnt2 + cnt3;\n\t\t\t\tif (tmp < ans[ti][0])\n\t\t\t\t{\n\t\t\t\t\tans[ti] = [tmp, i, i*j, i*j*num];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0]);\n\t\te[1..$].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. rint){\n long a = rlong, b = rlong, c = rlong;\n long best = c * 3, A = a, B = b, C = c;\n foreach(long y; 1 .. 4000){\n long x = f(a, y);\n long z = g(c, y);\n long tmp = abs(x - a) + abs(y - b) + abs(z - c);\n log(\"a:\", a, \"b:\", b, \"c:\", c, \"x:\", x, \"y:\", y, \"z:\", z, \"tmp:\", tmp, \"best:\", best, \"A:\", A, \"B:\", B, \"C:\", C);\n if(tmp < best) best = tmp, A = x, B = y, C = z;\n }\n best.writeln;\n writeln(A, \" \", B, \" \", C);\n }\n}\nlong f(long a, long y){\n static long[][] us;\n if(! us.length){\n us ~= new long[](0);\n foreach(long i; 1 .. 4000) us ~= divisors(i);\n }\n\n long best = 4000, ans = -1;\n foreach(d; us[y.to!int]){\n if(abs(a - d) < best) best = abs(a - d), ans = d;\n }\n return ans;\n}\nlong[] divisors(long a){\n\tlong[] res, res2;\n\tfor(long d = 1; d * d <= a; d ++){\n\t\tif(a % d == 0) res ~= d, res2 ~= a / d;\n\t}\n\tforeach_reverse(d; res2) if(res[$ - 1] < d) res ~= d;\n\treturn res;\n}\nlong g(long c, long y){\n if(c % y > y / 2 || c / y == 0) return y * (c / y + 1);\n else return y * (c / y);\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto c = RD;\n\t\tans[ti] = [long.max];\n\t\tforeach (i; 1..10^^4+1)\n\t\t{\n\t\t\tauto cnt1 = abs(a - i);\n\t\t\tforeach (j; 1..10^^4+1)\n\t\t\t{\n\t\t\t\tif (i * j > (10^^4)*2) break;\n\t\t\t\tauto cnt2 = abs(b - i*j);\n\t\t\t\tauto num = max(c / (i*j), 1);\n\t\t\t\tif ((i*j) - c % (i*j) < c % (i*j))\n\t\t\t\t\t++num;\n\t\t\t\tauto cnt3 = min(c % (i*j), (i*j) - c % (i*j));\n\t\t\t\tauto tmp = cnt1 + cnt2 + cnt3;\n\t\t\t\tif (tmp < ans[ti][0])\n\t\t\t\t{\n\t\t\t\t\tans[ti] = [tmp, i, i*j, i*j*num];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0]);\n\t\te[1..$].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto c = RD;\n\t\tans[ti] = [long.max];\n\t\tforeach (i; 1..10^^4+1)\n\t\t{\n\t\t\tauto cnt1 = abs(a - i);\n\t\t\tforeach (j; 1..10^^4+1)\n\t\t\t{\n\t\t\t\tif (i * j > 10^^4) break;\n\t\t\t\tauto cnt2 = abs(b - i*j);\n\t\t\t\tauto num = max(c / (i*j), 1);\n\t\t\t\tif ((i*j) - c % (i*j) < c % (i*j))\n\t\t\t\t\t++num;\n\t\t\t\tauto cnt3 = min(c % (i*j), (i*j) - c % (i*j));\n\t\t\t\tauto tmp = cnt1 + cnt2 + cnt3;\n\t\t\t\tif (tmp < ans[ti][0])\n\t\t\t\t{\n\t\t\t\t\tans[ti] = [tmp, i, i*j, i*j*num];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e[0]);\n\t\te[1..$].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "140737ecea3ff1c71cdd5e51e6abf297"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool solve(long power, ref long[][] caves)\n{\n foreach (cave ; caves) {\n if (power <= cave[0])\n return false;\n power += cave.length - 1;\n }\n return true;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n_caves;\n readf!\" %d \"(n_caves);\n long[][] caves;\n foreach (i ; 0 .. n_caves) {\n auto a = readln.strip.split.map!(to!long).array;\n foreach (j ; 1 .. a.length) {\n a[j] -= j - 1;\n }\n a[0] = a[1 .. $].maxElement;\n caves ~= a;\n }\n caves.sort!((a, b) => a[0] < b[0]);\n writeln(iota(0L, 1000000000L + 1 + 1).map!(power => solve(power, caves)).assumeSorted.lowerBound(true).length);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = new long[][](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t\ta[i] = RDA;\r\n\r\n\t\tauto b = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..cast(int)a[i][0])\r\n\t\t\t{\r\n\t\t\t\tb[i].chmax(a[i][j+1]-j+1);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto index = b.MAKE_IDX();\r\n\t\tlong p;\r\n\t\tforeach (i; index)\r\n\t\t{\r\n\t\t\tif (p < b[i])\r\n\t\t\t{\r\n\t\t\t\tans[ti] += b[i] - p;\r\n\t\t\t\tp = b[i];\r\n\t\t\t}\r\n\t\t\tp += a[i][0];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool solve(long power, ref long[][] caves)\n{\n foreach (cave ; caves) {\n if (power <= cave[0])\n return false;\n power += cave.length - 1;\n }\n return true;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n_caves;\n readf!\" %d \"(n_caves);\n long[][] caves;\n foreach (i ; 0 .. n_caves) {\n auto a = readln.strip.split.map!(to!long).array;\n foreach (j ; 1 .. a.length) {\n a[j] -= j - 1;\n }\n a[0] = a[1 .. $].maxElement;\n caves ~= a;\n }\n caves.sort!((a, b) => a[0] == b[0] ? a.length > b.length : a[0] < b[0]);\n writeln(iota(0L, 1000000000L).map!(power => solve(power, caves)).assumeSorted.lowerBound(true).length);\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool solve(long power, ref long[][] caves)\n{\n foreach (cave ; caves) {\n if (power <= cave[0])\n return false;\n power += cave.length - 1;\n }\n return true;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n_caves;\n readf!\" %d \"(n_caves);\n long[][] caves;\n foreach (i ; 0 .. n_caves) {\n auto a = readln.strip.split.map!(to!long).array;\n foreach (j ; 1 .. a.length) {\n a[j] -= j - 1;\n }\n a[0] = a[1 .. $].maxElement;\n caves ~= a;\n }\n caves.sort!((a, b) => a[0] < b[0]);\n writeln(iota(0L, 1000000000L).map!(power => solve(power, caves)).assumeSorted.lowerBound(true).length);\n }\n}\n"}], "src_uid": "88488ff074bc25a6cf925c8a07a1d8c6"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = [0] ~ readln.splitter.map !(to !(int)).array;\r\n\t\ta[] -= 1;\r\n\t\tauto s = readln.strip;\r\n\r\n\t\tauto c = new int [2] [n];\r\n\t\tint res = 0;\r\n\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tc[i][s[i] == 'W'] += 1;\r\n\t\t\tres += (c[i][0] == c[i][1]);\r\n\t\t\tif (a[i] >= 0)\r\n\t\t\t{\r\n\t\t\t\tc[a[i]][] += c[i][];\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!int(N - 1);\r\n auto S = scan.map!(c => c == 'B' ? 1 : -1).array;\r\n\r\n int[][] graph = new int[][](N, 0);\r\n foreach(i, a; A) graph[a - 1] ~= cast(int)i + 1;\r\n \r\n int[] tour;\r\n int step;\r\n int ans;\r\n int dfs(int cur) {\r\n int summ = S[cur];\r\n foreach(child; graph[cur]) {\r\n summ += dfs(child);\r\n }\r\n\r\n if (summ == 0) ans++;\r\n return summ;\r\n }\r\n \r\n dfs(0);\r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "negative_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!int(N - 1);\r\n auto S = scan;\r\n\r\n int[][] graph = new int[][](N, 0);\r\n foreach(i, a; A) graph[a - 1] ~= cast(int)i + 1;\r\n\r\n int ans;\r\n int[] colors = new int[](N);\r\n colors[0] = S[0] == 'B' ? 1 : -1;\r\n for(auto q = new DList!int(0); !q.empty;) {\r\n auto p = q.front; q.removeFront;\r\n foreach(near; graph[p]) {\r\n auto c = colors[p] + (S[near] == 'B' ? 1 : -1);\r\n colors[near] = c;\r\n q.insertBack(near);\r\n if (c == 0) ans++;\r\n }\r\n }\r\n \r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}], "src_uid": "504613b285d10fbf1e45b9c4ace25865"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n}\n\nlong solve (long[] a) {\n long curs = 0, maxs = 0;\n foreach (x; a) {\n curs += x;\n if (curs < 0) {\n curs = 0;\n }\n maxs = max (maxs, curs);\n }\n return maxs;\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n immutable x = r.next!int;\n auto a = new long[n];\n foreach (i; 0 .. n) {\n a[i] = r.next!long;\n }\n long[3] curs;\n long maxs = 0;\n foreach (i; 0 .. n) {\n foreach_reverse (state; 0 .. 3) {\n long y = a[i];\n if (state == 1) {\n y *= x;\n }\n long s = long.min;\n foreach (oldstate; max (0, state - 1) .. state + 1) {\n s = max (s, curs[oldstate]);\n }\n s += y;\n if (s < 0) {\n s = 0;\n }\n curs[state] = s;\n maxs = max (maxs, s);\n }\n }\n writeln (maxs);\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto X = s[1].to!long;\n auto A = readln.split.map!(to!long).array;\n\n auto dp = new long[][](N+1, 3);\n foreach (i; 0..N+1) dp[i][] = -INF;\n dp[0][0] = 0;\n\n foreach (i; 0..N) {\n long tmp = dp[i][0];\n dp[i+1][0] = max(dp[i+1][0], tmp + A[i], A[i]);\n\n tmp = max(tmp, dp[i][1]);\n dp[i+1][1] = max(dp[i+1][1], tmp + X * A[i], X * A[i]);\n\n tmp = max(tmp, dp[i][2]);\n dp[i+1][2] = max(dp[i+1][2], tmp + A[i], A[i]);\n }\n\n dp.map!(d => d.reduce!max).reduce!max.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, x;\n readf(\"%s %s\", &n, &x);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n auto sr = new long[] (n+2);\n foreach_reverse (i, e; arr.enumerate(1)) { sr[i] = max(0, e + sr[i+1]); }\n \n auto sl = new long[] (n+2);\n foreach (i, e; arr.enumerate(1)) { sl[i] = max(0, e + sl[i-1]); }\n \n auto nl = new long[] (n+2);\n foreach (i, e; arr.enumerate(1)) { nl[i] = max(sl[i], nl[i-1] + e.to!long * x); }\n \n debug { writeln(sl, ' ', sr, ' ', nl); }\n\n long ans = 0;\n foreach (i; 0 .. n+1) { ans = max(ans, nl[i] + sr[i+1]); }\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, x;\n readf(\"%s %s\", &n, &x);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n auto sr = new long[] (n+2);\n foreach_reverse (i, e; arr.enumerate(1)) { sr[i] = max(0, e + sr[i+1]); }\n \n auto sl = new long[] (n+2);\n foreach (i, e; arr.enumerate(1)) { sl[i] = max(0, e + sl[i-1]); }\n \n auto nl = new long[] (n+2);\n foreach (i, e; arr.enumerate(1)) { nl[i] = max(sl[i], nl[i-1] + e * x); }\n \n debug { writeln(sl, ' ', sr, ' ', nl); }\n\n long ans = 0;\n foreach (i; 0 .. n+1) { ans = max(ans, nl[i] + sr[i+1]); }\n \n ans.writeln;\n}"}], "src_uid": "92b6ab47c306a15631f045d624a1bf37"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(to!long).array;\n\n long a = 0;\n A.sort();\n\n for (int p = 0, x = 0; x < M; ++x) {\n while (p < N && A[p] - a == 0)\n ++p;\n if (p >= N) {\n writeln(0);\n continue;\n }\n writeln(A[p] - a);\n a = A[p];\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main() {\n int n,k,lst = 0;\n readf!\"%d %d\\n\" (n, k);\n auto v = readln.splitter.map!(to!int).array.sort;\n foreach(x;v) {\n if(x>lst) {\n writeln(x-lst);\n if(--k == 0) break;\n }\n lst = x;\n }\n foreach(i;0..k) writeln(0);\n}\n"}], "negative_code": [], "src_uid": "0f100199a720b0fdead5f03e1882f2f3"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct ev { \n int le, r, x; \n int opCmp(ev e) { return r - e.r; }\n}\n\nev[] evs;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n foreach (_; 0..q) {\n ev e;\n readf(\"%s %s %s\", &e.le, &e.r, &e.x);\n readln;\n \n evs ~= e;\n }\n \n evs.sort(); \n \n auto reach = (0).repeat(n+1).array;\n \n debug { writeln(evs); }\n \n foreach (e; evs) {\n foreach_reverse (i; e.x+1..n+1) {\n if (reach[i - e.x] >= e.le) reach[i] = max(reach[i], reach[i - e.x]);\n }\n reach[e.x] = max(reach[e.x], e.r);\n }\n \n auto oks = reach.enumerate.filter!(t => t.value > 0).map!(t => t.index).array;\n \n oks.length.writeln;\n oks.writefln!(\"%(%s %)\");\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable long mod = 1_000_000_000_000_000_003;\n\nalias Segment = Tuple !(int, q{l}, int, q{r}, int, q{x});\nalias Event = Tuple !(int, q{pos}, bool, q{state}, int, q{value});\n\nvoid main ()\n{\n\tint n, q;\n\twhile (readf (\" %s %s\", &n, &q) > 0)\n\t{\n\t\tauto s = new Segment [q];\n\t\tEvent [] e;\n\t\tforeach (ref c; s)\n\t\t{\n\t\t\treadf (\" %s %s %s\", &c.l, &c.r, &c.x);\n\t\t\tc.l -= 1;\n\t\t\te ~= Event (c.l, true, c.x);\n\t\t\te ~= Event (c.r, false, c.x);\n\t\t}\n\t\te ~= Event (n, true, 0);\n\t\tsort (e);\n\n\t\tauto ans = new bool [n + 1];\n\t\tauto f = new long [n + 1];\n\t\tf[0] = 1;\n\t\tint pos = -1;\n\t\tforeach (event; e)\n\t\t{\n\t\t\tif (pos != event.pos)\n\t\t\t{\n\t\t\t\tforeach (i; 0..n + 1)\n\t\t\t\t{\n\t\t\t\t\tans[i] |= (f[i] != 0);\n\t\t\t\t}\n\t\t\t\tpos = event.pos;\n\t\t\t}\n\t\t\tauto x = event.value;\n\t\t\tif (event.state)\n\t\t\t{\n\t\t\t\tforeach_reverse (u; x..n + 1)\n\t\t\t\t{\n\t\t\t\t\tf[u] += f[u - x];\n\t\t\t\t\tif (f[u] >= mod)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[u] -= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach (u; x..n + 1)\n\t\t\t\t{\n\t\t\t\t\tf[u] -= f[u - x];\n\t\t\t\t\tif (f[u] < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[u] += mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tans[0] = false;\n\t\twriteln (ans.sum);\n\t\twritefln (\"%(%s %)\", (n + 1).iota.filter !(x => ans[x]));\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct ev { int p; bool isStart; int x; }\n\nev[] evs;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n foreach (_; 0..q) {\n int le, r, x;\n readf(\"%s %s %s\", &le, &r, &x);\n readln;\n \n evs ~= ev(le, true, x);\n evs ~= ev(r, false, x);\n }\n \n evs.multiSort!(q{ a.p < b.p }, q{ (a.isStart ? 0 : 1) < (b.isStart ? 0 : 1) });\n \n debug { writeln(evs); }\n \n auto ans = false.repeat(n+1).array.BitArray;\n auto cur = false.repeat(n+1).array.BitArray;\n foreach (evt; evs) {\n if (evt.isStart) cur <<= evt.x, cur[evt.x] = true;\n else cur >>= evt.x;\n ans |= cur;\n }\n \n debug { writefln(\"%b\", ans); }\n \n auto toPrint = ans.array.dropOne.enumerate(1).filter!(t => t.value).map!(t => t.index).array;\n toPrint.length.writeln;\n toPrint.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct ev { \n int le, r, x; \n int opCmp(ev e) { return le - e.le; }\n}\n\nev[] evs;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n foreach (_; 0..q) {\n ev e;\n readf(\"%s %s %s\", &e.le, &e.r, &e.x);\n readln;\n \n evs ~= e;\n }\n \n evs.sort(); \n \n auto reach = (0).repeat(n+1).array;\n \n debug { writeln(evs); }\n \n foreach (e; evs) {\n foreach_reverse (i; e.x+1..n+1) {\n if (reach[i - e.x] >= e.le) reach[i] = max(reach[i], reach[i - e.x]);\n }\n reach[e.x] = max(reach[e.x], e.r);\n }\n \n auto oks = reach.enumerate.filter!(t => t.value > 0).map!(t => t.index).array;\n \n oks.length.writeln;\n oks.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct ev { \n int le, r, x; \n int opCmp(ev e) { return le - e.le; }\n}\n\nev[] evs;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n foreach (_; 0..q) {\n ev e;\n readf(\"%s %s %s\", &e.le, &e.r, &e.x);\n readln;\n \n evs ~= e;\n }\n \n evs.sort(); \n \n auto reach = (0).repeat(n+1).array;\n \n debug { writeln(evs); }\n \n foreach (e; evs) {\n foreach_reverse (i; e.x+1..n+1) {\n if (reach[i - e.x] >= e.le) reach[i] = max(reach[i], e.r);\n }\n reach[e.x] = max(reach[e.x], e.r);\n }\n \n auto oks = reach.enumerate.filter!(t => t.value > 0).map!(t => t.index).array;\n \n oks.length.writeln;\n oks.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct ev { int p; bool isStart; int x; }\n\nev[] evs;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n foreach (_; 0..q) {\n int le, r, x;\n readf(\"%s %s %s\", &le, &r, &x);\n readln;\n \n evs ~= ev(le, true, x);\n evs ~= ev(r, false, x);\n }\n \n evs.multiSort!(q{ a.p < b.p }, q{ (a.isStart ? 0 : 1) < (b.isStart ? 0 : 1) });\n \n debug { writeln(evs); }\n \n auto ans = false.repeat(n+1).array.BitArray;\n auto cur = false.repeat(n+1).array.BitArray;\n foreach (evt; evs) {\n if (evt.isStart) cur <<= evt.x, cur[evt.x] = true;\n else cur >>= evt.x;\n ans |= cur;\n }\n \n debug { writefln(\"%b\", ans); }\n \n auto toPrint = ans.array.enumerate.filter!(t => t.value).map!(t => t.index).array;\n toPrint.length.writeln;\n toPrint.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nstruct ev { \n int le, r, x; \n int opCmp(ev e) { return r - e.r; }\n}\n\nev[] evs;\n\nvoid main()\n{\n int n, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n foreach (_; 0..q) {\n ev e;\n readf(\"%s %s %s\", &e.le, &e.r, &e.x);\n readln;\n \n evs ~= e;\n }\n \n evs.sort(); \n \n auto reach = (0).repeat(n+1).array;\n \n debug { writeln(evs); }\n \n foreach (e; evs) {\n foreach_reverse (i; e.x+1..n+1) {\n if (reach[i - e.x] >= e.le) reach[i] = max(reach[i], e.r);\n }\n reach[e.x] = max(reach[e.x], e.r);\n }\n \n auto oks = reach.enumerate.filter!(t => t.value > 0).map!(t => t.index).array;\n \n oks.length.writeln;\n oks.writefln!(\"%(%s %)\");\n}"}], "src_uid": "18f6b866522d2d4adf505d0a054514fc"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable long INF = 10L ^^ 18 + 23;\n\nvoid main()\n{\n long b;\n int q, le, m;\n readf(\"%s %s %s %s\", &b, &q, &le, &m);\n readln;\n \n auto t = readln.chomp.split.map!(to!int).redBlackTree;\n \n if (abs(b) > le) {\n writeln(0);\n return;\n }\n \n if (b == 0 || q == 1) {\n if (t.equalRange(b.to!int).empty()) writeln(\"inf\");\n else writeln(0);\n \n return;\n }\n \n if (q == 0) {\n if (t.equalRange(0).empty()) writeln(\"inf\");\n else writeln(t.equalRange(b.to!int).empty() ? 1 : 0);\n \n return;\n }\n \n if (q == -1) {\n bool isInf = t.equalRange(b.to!int).empty() || t.equalRange((-b).to!int).empty();\n if (isInf) writeln(\"inf\");\n else writeln(0);\n \n return;\n }\n \n int ans = 0;\n while (abs(b) <= le) {\n if (t.equalRange(b.to!int).empty()) ++ans;\n \n b = b * q;\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~\"\\n\", ptrs)==ptrs.length;}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------\n\nvoid main()\n{\n\tlint b1,q,l,m;\nloop:while(read(&b1,&q,&l,&m))\n\t{\n\t\tauto a=arread!int;\n\t\tsort(a);\n\t\tif(q==1)\n\t\t{\n\t\t\tif(bins(a,b1) || abs(b1)>l)writeln(0);\n\t\t\telse writeln(\"inf\");\n\t\t}\n\t\telse if(q==-1)\n\t\t{\n\t\t\tif((bins(a,b1) && bins(a,-1*b1)) || abs(b1)>l)writeln(0);\n\t\t\telse writeln(\"inf\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint ans=0;\n\t\t\twhile(abs(b1)<=l)\n\t\t\t{\n\t\t\t\tif(!bins(a,b1))ans++;\n\t\t\t\tb1*=q;\n\t\t\t\tif(b1==0)\n\t\t\t\t{\n\t\t\t\t\tif(!bins(a,0))\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln(\"inf\");\n\t\t\t\t\t\tgoto loop;\n\t\t\t\t\t}\n\t\t\t\t\telse break;\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteln(ans);\n\t\t}\n\t}\n\t//debug system(\"pause\");\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable long INF = 10L ^^ 18 + 23;\n\nvoid main()\n{\n long b;\n int q, le, m;\n readf(\"%s %s %s %s\", &b, &q, &le, &m);\n readln;\n \n auto t = readln.chomp.split.map!(to!int).redBlackTree;\n \n if (abs(b) > le) {\n writeln(0);\n return;\n }\n \n if (b == 0 || q == 1) {\n if (t.equalRange(b.to!int).empty()) writeln(\"inf\");\n else writeln(0);\n \n return;\n }\n \n if (q == 0) {\n if (t.equalRange(0).empty()) writeln(\"inf\");\n else writeln(t.equalRange(b.to!int).empty() ? 0 : 1);\n \n return;\n }\n \n if (q == -1) {\n bool isInf = t.equalRange(b.to!int).empty() || t.equalRange((-b).to!int).empty();\n if (isInf) writeln(\"inf\");\n else writeln(0);\n \n return;\n }\n \n int ans = 0;\n while (abs(b) <= le) {\n if (t.equalRange(b.to!int).empty()) ++ans;\n \n b = b * q;\n }\n \n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable long INF = 10L ^^ 18 + 23;\n\nvoid main()\n{\n long b;\n int q, le, m;\n readf(\"%s %s %s %s\", &b, &q, &le, &m);\n readln;\n \n auto t = readln.chomp.split.map!(to!int).redBlackTree;\n \n if (b == 0 || q == 1) {\n if (t.equalRange(b.to!int).empty()) writeln(\"inf\");\n else writeln(0);\n \n return;\n }\n \n if (q == 0) {\n if (t.equalRange(0).empty()) writeln(\"inf\");\n else writeln(t.equalRange(b.to!int).empty() ? 0 : 1);\n \n return;\n }\n \n if (q == -1) {\n bool isInf = t.equalRange(b.to!int).empty() || t.equalRange((-b).to!int).empty();\n if (isInf) writeln(\"inf\");\n else writeln(0);\n \n return;\n }\n \n int ans = 0;\n while (abs(b) <= le) {\n if (t.equalRange(b.to!int).empty()) ++ans;\n \n b = b * q;\n }\n \n ans.writeln;\n}"}], "src_uid": "749c290c48272a53e2e79730dab0538e"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_t; 0..T) {\n auto nn = readln.split.to!(int[]);\n auto n0 = nn[0];\n auto n1 = nn[1];\n auto n2 = nn[2];\n\n char[] rs;\n if (n1 == 0) {\n if (n0 > 0) {\n foreach (_n; 0..n0+1) rs ~= '0';\n } else {\n foreach (_n; 0..n2+1) rs ~= '1';\n }\n writeln(rs);\n continue;\n }\n\n if (n1%2 == 0) {\n rs ~= '1';\n --n1;\n }\n foreach (_n; 0..n0+1) rs ~= '0';\n foreach (_n; 0..n1/2) rs ~= \"10\";\n foreach (_n; 0..n2+1) rs ~= '1';\n\n writeln(rs);\n }\n}", "positive_code": [{"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nstring solve (int [] n)\n{\npick_start_loop:\n\tforeach (v0; [0, 1])\n\t{\n\t\tint [] res;\n\t\tauto v = v0;\n\t\tres ~= v;\n\t\twhile (sum (n) > 0)\n\t\t{\n\t\t\tif (n[v * 2] > 0)\n\t\t\t{\n\t\t\t\tn[v * 2] -= 1;\n\t\t\t\tres ~= v;\n\t\t\t}\n\t\t\telse if (n[1] > 0)\n\t\t\t{\n\t\t\t\tn[1] -= 1;\n\t\t\t\tv ^= 1;\n\t\t\t\tres ~= v;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcontinue pick_start_loop;\n\t\t\t}\n\t\t}\n\t\treturn res.map !(text).join;\n\t}\n\tassert (false);\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.splitter.map !(to !(int)).array;\n\t\twriteln (solve (n));\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.meta;\nimport std.random;\n\n// void check(bool[] res, int n0, int n1, int n2) {\n// \tint nn0, nn1, nn2;\n// \tassert(res.length > 0);\n// \tforeach (i; 0 .. res.length - 1) {\n// \t\tint count;\n// \t\tif (res[i]) count++;\n// \t\tif (res[i + 1]) count++;\n// \t\tif (count ==0) nn0++;\n// \t\telse if (count ==1) nn1++;\n// \t\telse if (count == 2) nn2++;\n// \t}\n// \tassert(nn0 == n0);\n// \tassert(nn1 == n1);\n// \tassert(nn2 == n2);\n// }\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tforeach (t; 0 .. n) {\n\t\tint[] ns = readln.chomp.split(\" \").map!(to!int).array;\n\t\t// int[] ns = new int[3];\n\t\t// foreach (i; 0.. 3) {\n\t\t// \tns[i] = uniform!\"[]\"(2, 1000);\n\t\t// }\n\t\tint n0 = ns[0], n1 = ns[1], n2 = ns[2];\n\t\tbool[] res;\n\t\tbool at = true;\n\t\tbool dontForget = false;\n\t\tif (n1 == 0) {\n\t\t\tif (n2 == 0) {\n\t\t\t\tres.assumeSafeAppend ~= false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tres.assumeSafeAppend ~= true;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tforeach (i; 0 .. n1 + 1) {\n\t\t\t\tif (i == n1 && at == true) {\n\t\t\t\t\tdontForget = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tres.assumeSafeAppend ~= at;\n\t\t\t\tat = !at;\n\t\t\t}\n\t\t}\n\t\tbool[] prepend;\n\t\tforeach (i; 0 .. n2) {\n\t\t\tprepend.assumeSafeAppend ~= true;\n\t\t}\n\t\tres = prepend.assumeSafeAppend ~ res;\n\t\tforeach (i; 0 .. n0) {\n\t\t\tres.assumeSafeAppend ~= false;\n\t\t}\n\t\tif (dontForget) {\n\t\t\tres.assumeSafeAppend ~= true;\n\t\t}\n\t\t// check(res, n0, n1, n2);\n\t\twriteln(res.map!(x => x ? '1' : '0'));\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n0 = RD!int;\n\t\tauto n1 = RD!int;\n\t\tauto n2 = RD!int;\n\n\t\tif (n0 != 0)\n\t\t\tans[ti] ~= '0';\n\t\tforeach (i; 0..n0)\n\t\t{\n\t\t\tans[ti] ~= '0';\n\t\t}\n\n\t\tint n1o = n1;\n\t\tif (n1 % 2 == 0)\n\t\t\tn1o -= 1;\n\t\tif (n0 == 0 && n1 != 0)\n\t\t\tans[ti] ~= '0';\n\t\tforeach (i; 0..n1o)\n\t\t{\n\t\t\tif (i % 2 == 0)\n\t\t\t\tans[ti] ~= '1';\n\t\t\telse\n\t\t\t\tans[ti] ~= '0';\n\t\t}\n\n\t\tif (n0 == 0 && n1 == 0)\n\t\t\tans[ti] ~= '1';\n\t\tforeach (i; 0..n2)\n\t\t{\n\t\t\tans[ti] ~= '1';\n\t\t}\n\n\t\tif (n1 % 2 == 0 && n1 != 0)\n\t\t{\n\t\t\tif (ans[ti][$-1] == '0')\n\t\t\t\tans[ti] ~= '1';\n\t\t\telse\n\t\t\t\tans[ti] ~= '0';\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "4bbb078b66b26d6414e30b0aae845b98"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto x = RD;\n\t\tauto y = RD;\n\t\tbool[long] set;\n\t\tset[x] = true;\n\t\twhile (x < y)\n\t\t{\n\t\t\tif (x % 2 == 0)\n\t\t\t\tx = x * 3 / 2;\n\t\t\telse\n\t\t\t\t--x;\n\t\t\tif (set.get(x, false))\n\t\t\t\tbreak;\n\t\t\tset[x] = true;\n\t\t}\n\t\tans[i] = x >= y;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nbool go(int x, int y) {\n if(x == 1) {\n return y == 1;\n }\n if(x <= 3) {\n return y <= 3;\n }\n return true;\n}\n\nvoid main() { \n int t; \n readf(\" %s\", &t);\n while(t-- > 0) {\n int x, y;\n readf(\" %s %s\", &x, &y);\n writefln(go(x, y) ? \"YES\" : \"NO\");\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nbool go(int x, int y) {\n if(x == 1) {\n return y == 1;\n }\n if(x == 3) {\n return y <= 3;\n }\n return true;\n}\n\nvoid main() { \n int t; \n readf(\" %s\", &t);\n while(t-- > 0) {\n int x, y;\n readf(\" %s %s\", &x, &y);\n writefln(go(x, y) ? \"YES\" : \"NO\");\n }\n}\n"}], "src_uid": "b3978805756262e17df738e049830427"} {"source_code": "import std.stdio;\r\nimport std.conv;\r\nimport std.algorithm;\r\nimport std.array;\r\nimport std.string;\r\nimport std.uni;\r\nimport std.math;\r\n\r\nvoid main()\r\n{\r\n foreach(_; stdin.byLineCopy())\r\n {\r\n writeln(\"NO\");\r\n stdout.flush();\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\r\nimport std.conv, std.math;\r\n\r\nint main(string[] args)\r\n{\r\n string line;\r\n while ((line = readln.strip) !is null)\r\n {\r\n if (line == \"Is it rated?\") writeln(\"NO\");\r\n else writeln(\"YES\");\r\n stdout.flush;\r\n }\r\n return 0;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tforeach (line; stdin.byLineCopy ())\r\n\t{\r\n\t\twriteln (\"NO\");\r\n\t\tstdout.flush ();\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "57b62c485669809c0b59afd6613f901c"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto a = ma(n, readInt!int);\n auto filled = new bool[](n + 1);\n int[] fa;\n foreach(i, ai; a)\n {\n if (ai <= n)\n\t{\n\t if (!filled[ai])\n\t {\n\t filled[ai] = true;\n\t continue;\n\t }\n\t}\n fa ~= ai;\n }\n sort(fa);\n debug writeln(fa);\n int ops = 0;\n foreach_reverse(i; 1 .. n + 1)\n {\n if (!filled[i])\n\t{\n\t debug writeln(\"trying to fill \", i, \" with fa \", fa, \" back \", fa.back, \" \", i < fa.back/2);\n\t if (fa.empty || !(i < (fa.back + (fa.back%2))/2)) return writeln(-1);\n\t fa.popBack;\n\t ops++;\n\t filled[i] = true;\n\t}\n }\n ops.writeln;\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\tauto v = new bool [n + 1];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tif (1 <= c && c <= n && !v[c])\r\n\t\t\t{\r\n\t\t\t\tv[c] = true;\r\n\t\t\t\tc = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\ta = a.filter !(q{a != 0}).array;\r\n\t\tint res = 0;\r\n\t\tforeach (d; 1..n + 1)\r\n\t\t{\r\n\t\t\tif (!v[d])\r\n\t\t\t{\r\n\t\t\t\tif (a.front > d * 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tres += 1;\r\n\t\t\t\t\ta.popFront ();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tres = -1;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA!int;\r\n\t\t\r\n\t\tauto ok = new bool[](n);\r\n\t\tlong[] b;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] <= n)\r\n\t\t\t{\r\n\t\t\t\tif (ok[a[i]-1])\r\n\t\t\t\t\tb ~= a[i];\r\n\t\t\t\telse\r\n\t\t\t\t\tok[a[i]-1] = true;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tb ~= a[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tb.sort;\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (ok[i]) continue;\r\n\t\t\tif (b.front <= (i+1)*2)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = -1;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tb.popFront;\r\n\t\t\t++ans[ti];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\ta.sort;\r\n\r\n\t\tbool ok = true;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] == i+1) continue;\r\n\t\t\tif (a[i] <= (i+1)*2)\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t++ans[ti];\r\n\t\t}\r\n\t\tif (!ok)\r\n\t\t\tans[ti] = -1;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "85ad953161bb8841eed7c47a66381688"} {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nint[][] child;\nbool[] visited;\n\nlong MOD = 998244353;\nlong[] fac;\n\nlong dfs(uint root) {\n\n uint nc = 0;\n\n visited[root] = true;\n long mul = 1;\n\n foreach (v; child[root]) {\n if (!visited[v]) {\n long ll = dfs(v);\n mul = (mul * ll) % MOD;\n nc++;\n }\n }\n\n if (root != 0)\n nc++;\n\n return (fac[nc] * mul) % MOD;\n}\n\nvoid main() {\n GC.disable();\n\n uint n;\n\n readf(\" %s\", n);\n\n auto a = new long[n];\n auto b = new long[n];\n long tt = 0;\n auto hh = new long[n];\n foreach (i; 0 .. n) {\n long x, y;\n\n readf(\" %s %s\", x, y);\n a[i] = x;\n b[i] = y;\n tt -= x;\n tt += y * n;\n if (x < y) {\n hh[i] = 1_00_000_000 + (y - x);\n }\n else\n hh[i] = (y - x);\n }\n\n sort(hh);\n // writeln(hh);\n\n foreach (i, e; hh) {\n if (e >= 1_00_000_000)\n tt -= (i + 1) * (e - 1_00_000_000);\n else {\n tt += (i + 1) * (-e);\n }\n }\n\n writeln(tt);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!uint;\n\tauto arr = new long[2][](N);\n\n\tforeach (i; 0..N)\n\t{\n\t\tauto a = RD!long;\n\t\tauto b = RD!long;\n\t\tarr[i] = [a, b];\n\t}\n\tauto index = MAKE_IDX!\"a[0] - a[1] > b[0] - b[1]\"(arr);\n\tlong ans;\n\tdebug writeln(arr);\n\tforeach (ii, i; index)\n\t{\n\t\tans += arr[i][0] * ii;\n\t\tans += arr[i][1] * (N - ii - 1);\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.algorithm.comparison;\nimport std.algorithm.iteration;\nimport std.algorithm.searching;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.stdio;\n\nvoid main() {\n int n;\n readf(\"%s %s\", n);\n auto d = new long[](n);\n long s, b;\n foreach (i; 0..n) {\n readf(\" %s %s\", d[i], b);\n d[i] -= b;\n s += (n-1)*b;\n }\n sort(d);\n foreach (i; 0..n) {\n s += i * d[n-1-i];\n }\n writeln(s);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array;\n A.sort!\"a[0] - a[1] > b[0] - b[1]\";\n N.iota.map!(i => A[i][0] * i + A[i][1] * (N - i - 1)).sum.writeln;\n}"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT read(T)(){ return read.to!T; }\nT[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }\nT[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\n/*\nx[j] = a[i](j - 1) + b[i](n - j)\n = (n b[i] - a[i]) + j(a[i] - b[i]).\n \nsum x[j] = sum j[i] c[i], where c[j] = a[i] - b[i].\n\narrenge so that j[i] is large where c[i] is small.\n*/\n\nclass X{\n\tlong a;\n\tlong b;\n\tlong c;\n\tint j;\n\tlong value;\n\tthis(long a, long b){\n\t\tthis.a = a;\n\t\tthis.b = b;\n\t\tthis.c = a - b;\n\t}\n}\n\nvoid solve(){\n\n\tint n = read!int;\n\t\n\tX[] xs;\n\tforeach(i; 0 .. n){\n\t\tlong a = read!long;\n\t\tlong b = read!long;\n\t\txs ~= new X(a, b);\n\t}\n\txs.sort!\"a.c>b.c\"();\n\tforeach(i, x; xs) log(\"i:\", i, \"a:\", x.a, \"b:\", x.b, \"c:\", x.c);\n\t\n\tlong ans = 0;\n\tforeach(int i, x; xs){\n\t\tx.j = i + 1;\n\t\tx.value = x.a * (x.j - 1) + x.b * (n - x.j);\n\t\tans += x.value;\n\t}\n\tforeach(i, x; xs) log(\"i:\", i, \"a:\", x.a, \"b:\", x.b, \"c:\", x.c, \"j:\", x.j, \"value:\", x.value);\n\t\n\tans.writeln;\n\t\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD!uint;\n\tauto arr = new int[2][](N);\n\n\tforeach (i; 0..N)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tarr[i] = [a, b];\n\t}\n\tauto index = MAKE_IDX!\"a[0] - a[1] > b[0] - b[1]\"(arr);\n\tuint ans;\n\tdebug writeln(arr);\n\tforeach (ii, i; index)\n\t{\n\t\tans += arr[i][0] * ii;\n\t\tans += arr[i][1] * (N - ii - 1);\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "028e83d83cc99a2b3826627efd87a304"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto x = RD!int;\n\tauto y = RD!int;\n\tauto a = RDA;\n\tint ans;\n\tforeach (i; 0..n)\n\t{\n\t\tbool ok = true;\n\t\tforeach (j; max(0, i-x)..min(n, i+1+y))\n\t\t{\n\t\t\tif (a[j] < a[i])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ok)\n\t\t{\n\t\t\tans = i+1;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int MAX = 100005;\nint[MAX] a;\n\nvoid main() {\n int n, x, y;\n readf(\" %s %s %s\", n, x, y);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n foreach(i; 0..n) {\n bool ok = true;\n foreach(j; max(0, i-x)..min(i+y+1, n)) {\n ok &= a[j] >= a[i];\n }\n if (ok) {\n writeln(i+1);\n break;\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm : all, map, maxElement, splitter;\nimport std.array;\nimport std.string : strip;\nimport std.conv : to;\nimport std.range : chain, enumerate, slide, repeat;\n\nvoid main()\n{\n // read array of ints\n int n, x, y;\n readf!\"%d %d %d\\n\"(n, x, y);\n auto a = map!(to!(int))(readln().strip().splitter(' '));\n auto m = a.maxElement;\n auto p = chain(m.repeat(x), a, m.repeat(y)).array;\n\n foreach (i, win; p.slide(x + y + 1).enumerate(1)) {\n auto mid = win[x];\n\n if (win.all!(a => a >= mid)) {\n writeln(i);\n break;\n }\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nstruct obb {\n int index;\n int value;\n int opCmp(obb o) const {\n return value - o.value;\n }\n}\n\nconst int MAX = 100005;\nint[MAX] a;\nobb[MAX] o;\nbool[MAX] flag;\n\nvoid main() {\n int n, x, y;\n readf(\" %s %s %s\", n, x, y);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n foreach(i; 0..n) o[i] = obb(i, a[i]);\n sort(o[0..n]);\n\n auto result = o[0].index;\n foreach(i; 0..n) {\n auto index = o[i].index;\n if (flag[index]) continue;\n bool ok = true;\n foreach(j; max(0, index-x)..min(index+y+1, n)) {\n flag[j] = true;\n ok &= a[j] >= o[i].value;\n }\n if (ok) {\n result = min(result, index);\n }\n }\n writeln(result+1);\n}\n"}], "src_uid": "5e2a5ee02c1a2f35a52e76cde96463a3"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto lo = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto hi = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto res = hi.dup;\r\n\t\tif (lo[0] != hi[0])\r\n\t\t{\r\n\t\t\tres[] = 1;\r\n\t\t}\r\n\r\n\t\tuint [] inc (uint [] x)\r\n\t\t{\r\n\t\t\tauto res = x.dup;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres[i] ^= 1;\r\n\t\t\t\tif (res[i] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tif (res == hi && res[$ - 1] == 0 && lo != hi && inc (lo) != hi)\r\n\t\t{\r\n\t\t\tres[$ - 1] = 1;\r\n\t\t}\r\n\t\twritefln !(\"%(%s%)\") (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto lo = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto hi = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto res = hi.dup;\r\n\t\tif (n == 1)\r\n\t\t{\r\n\t\t\twriteln (hi[$ - 1]);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tuint [] dec (uint [] x)\r\n\t\t{\r\n\t\t\tauto res = x.dup;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres[i] ^= 1;\r\n\t\t\t\tif (res[i] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tuint [] inc (uint [] x)\r\n\t\t{\r\n\t\t\tauto res = x.dup;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres[i] ^= 1;\r\n\t\t\t\tif (res[i] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tuint [] calc (uint [] x, uint [] y)\r\n\t\t{\r\n\t\t\tx = x.dup;\r\n\t\t\ty = y.dup;\r\n\t\t\tdebug {writeln (\"x = \", x);}\r\n\t\t\tdebug {writeln (\"y = \", y);}\r\n\t\t\tauto res = new uint [n];\r\n\t\t\twhile (x[$ - 2..$] != [0, 0])\r\n\t\t\t{\r\n\t\t\t\tres[] ^= x[];\r\n\t\t\t\tx = inc (x);\r\n\t\t\t}\r\n\t\t\twhile (y[$ - 2..$] != [1, 1])\r\n\t\t\t{\r\n\t\t\t\tres[] ^= y[];\r\n\t\t\t\ty = dec (y);\r\n\t\t\t}\r\n\t\t\tdebug {writeln (\"z = \", res);}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tvoid getBetter (uint [] x, uint [] y)\r\n\t\t{\r\n\t\t\tif (x < lo || y > hi)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tres = max (res, calc (x, y));\r\n\t\t}\r\n\r\n\t\tauto pos = 0;\r\n\t\twhile (pos < n && lo[pos] == hi[pos])\r\n\t\t{\r\n\t\t\tpos += 1;\r\n\t\t}\r\n\t\tif (pos < n)\r\n\t\t{\r\n\t\t\tauto x = lo.dup;\r\n\t\t\tx[pos + 1..$] = 1;\r\n\t\t\tauto y = hi.dup;\r\n\t\t\ty[pos + 1..$] = 0;\r\n\t\t\tgetBetter (x, y);\r\n\t\t\tif (x.canFind (1))\r\n\t\t\t{\r\n\t\t\t\tgetBetter (dec (x), y);\r\n\t\t\t}\r\n\t\t\tif (y.canFind (0))\r\n\t\t\t{\r\n\t\t\t\tgetBetter (x, inc (y));\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (res == hi && res[$ - 1] == 0 && lo != hi && inc (lo) != hi)\r\n\t\t{\r\n\t\t\tres[$ - 1] = 1;\r\n\t\t}\r\n\t\twritefln !(\"%(%s%)\") (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto lo = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto hi = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto res = hi.dup;\r\n\r\n\t\tuint [] inc (uint [] x)\r\n\t\t{\r\n\t\t\tauto res = x.dup;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres[i] ^= 1;\r\n\t\t\t\tif (res[i] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tif (res == hi && res[$ - 1] == 0 && lo != hi && inc (lo) != hi)\r\n\t\t{\r\n\t\t\tres[$ - 1] = 1;\r\n\t\t}\r\n\t\twritefln !(\"%(%s%)\") (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto lo = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto hi = readln.strip.map !(q{a - '0'}).array;\r\n\t\tauto res = hi.dup;\r\n\t\tif (n == 1)\r\n\t\t{\r\n\t\t\twriteln (1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tuint [] dec (uint [] x)\r\n\t\t{\r\n\t\t\tauto res = x.dup;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres[i] ^= 1;\r\n\t\t\t\tif (res[i] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tuint [] inc (uint [] x)\r\n\t\t{\r\n\t\t\tauto res = x.dup;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres[i] ^= 1;\r\n\t\t\t\tif (res[i] == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tuint [] calc (uint [] x, uint [] y)\r\n\t\t{\r\n\t\t\tx = x.dup;\r\n\t\t\ty = y.dup;\r\n\t\t\tdebug {writeln (\"x = \", x);}\r\n\t\t\tdebug {writeln (\"y = \", y);}\r\n\t\t\tauto res = new uint [n];\r\n\t\t\twhile (x[$ - 2..$] != [0, 0])\r\n\t\t\t{\r\n\t\t\t\tres[] ^= x[];\r\n\t\t\t\tx = inc (x);\r\n\t\t\t}\r\n\t\t\twhile (y[$ - 2..$] != [1, 1])\r\n\t\t\t{\r\n\t\t\t\tres[] ^= y[];\r\n\t\t\t\ty = dec (y);\r\n\t\t\t}\r\n\t\t\tdebug {writeln (\"z = \", res);}\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tvoid getBetter (uint [] x, uint [] y)\r\n\t\t{\r\n\t\t\tif (x < lo || y > hi)\r\n\t\t\t{\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tres = max (res, calc (x, y));\r\n\t\t}\r\n\r\n\t\tauto pos = 0;\r\n\t\twhile (pos < n && lo[pos] == hi[pos])\r\n\t\t{\r\n\t\t\tpos += 1;\r\n\t\t}\r\n\t\tif (pos < n)\r\n\t\t{\r\n\t\t\tauto x = lo.dup;\r\n\t\t\tx[pos + 1..$] = 1;\r\n\t\t\tauto y = hi.dup;\r\n\t\t\ty[pos + 1..$] = 0;\r\n\t\t\tgetBetter (x, y);\r\n\t\t\tif (x.canFind (1))\r\n\t\t\t{\r\n\t\t\t\tgetBetter (dec (x), y);\r\n\t\t\t}\r\n\t\t\tif (y.canFind (0))\r\n\t\t\t{\r\n\t\t\t\tgetBetter (x, inc (y));\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (res == hi && res[$ - 1] == 0 && lo != hi && inc (lo) != hi)\r\n\t\t{\r\n\t\t\tres[$ - 1] = 1;\r\n\t\t}\r\n\t\twritefln !(\"%(%s%)\") (res);\r\n\t}\r\n}\r\n"}], "src_uid": "1925187d2c4b9caa1e74c29d9f33f3a6"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto p = RDA!int;\r\n\r\n\t\tauto pos = new int[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t\tpos[p[i]-1] = i;\r\n\r\n\t\tint l = n;\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tif (pos[i] > l) continue;\r\n\t\t\tans[ti] ~= p[pos[i]..l];\r\n\t\t\tl = pos[i];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\te.map!(to!string).join(\" \").writeln;\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nalias X = Tuple!(int, \"i\", int, \"p\");\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n int N; get(N);\r\n int[] PS; get(PS);\r\n X[] xx;\r\n foreach (i, p; PS) xx ~= X(i.to!int, p);\r\n sort!\"a.p > b.p\"(xx);\r\n int r = N;\r\n int[] res;\r\n foreach (x; xx) if (x.i < r) {\r\n foreach (i; x.i..r) res ~= PS[i];\r\n r = x.i;\r\n }\r\n writefln!\"%(%d %)\"(res);\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "1637670255f8bd82a01e2ab20cdcc9aa"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n;\n n = scan!int;\n ll x = scan;\n auto arr = scanArray;\n ll summ = arr.sum;\n ll[] pows;\n foreach(el; arr){\n ll tim = 0;\n ll num = el;\n while(num > 0 && num % x == 0){\n num /= x;\n ++tim;\n }\n pows ~= tim;\n }\n for(int i = 0; i < 64; ++i){\n for(int j = 0; j < n; ++j){\n if(!pows[j]){\n writeln(summ);\n return;\n }\n summ += arr[j];\n --pows[j];\n }\n }\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; long X; get(N, X);\r\n long[] AA; get(AA);\r\n alias A = Tuple!(long, \"c\", long, \"v\");\r\n auto aa = AA.map!(a => A(1, a)).array();\r\n int i;\r\n bool broken;\r\n long r;\r\n while (i < aa.length) {\r\n auto a = aa[i++];\r\n r += a.v * a.c;\r\n if (!broken && a.v % X == 0) {\r\n aa ~= A(a.c * X, a.v / X);\r\n } else {\r\n broken = true;\r\n }\r\n }\r\n writeln(r);\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto x = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tans[ti] = a.sum;\r\n\t\t(){\r\n\t\tforeach (cnt; 1..10^^5)\r\n\t\t{\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (a[i] % x) return;\r\n\t\t\t\t\r\n\t\t\t\tauto y = a[i] / x;\r\n\t\t\t\tans[ti] += y * x^^cnt;\r\n\t\t\t\ta[i] = y;\r\n\t\t\t}\r\n\t\t}}();\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "09c8db43681d7bc72f83287897a62f3c"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\tint k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\tauto v = n.iota.filter !(x => s[x] == '0').array;\n\t\tdebug {writeln (v);}\n\n\t\tint res = n;\n\t\tint p = 0;\n\t\tint q = 0;\n\t\tint r = k;\n\n\t\tint dist (int t)\n\t\t{\n\t\t\treturn max (v[t] - v[p], v[r] - v[t]);\n\t\t}\n\n\t\twhile (r < v.length)\n\t\t{\n\t\t\tq = max (q, p);\n\t\t\twhile (q < r && dist (q + 1) <= dist (q))\n\t\t\t{\n\t\t\t\tq++;\n\t\t\t}\n\t\t\tres = min (res, dist (q));\n\t\t\tp++;\n\t\t\tr++;\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.string;\nimport std.array;\nimport std.conv;\nimport std.math;\n\nvoid main() {\n int n, k;\n readf(\" %s %s\", &n, &k);\n readln;\n string s = readln.strip;\n\n auto cnt = new int[n];\n foreach (i; 0..n) {\n cnt[i] = s[i] == '0';\n if (i > 0) cnt[i] += cnt[i - 1];\n }\n\n bool check(int x) {\n foreach (i; 0..n) {\n int l = max(0, i - x);\n int r = min(n - 1, i + x);\n int q = cnt[r] - (l > 0 ? cnt[l - 1] : 0);\n if (q >= k + 1 && s[i] != '1') {\n return true;\n }\n }\n return false;\n }\n \n int lo = -1, hi = n * 2;\n while (lo + 1 < hi) {\n int mid = (lo + hi) >> 1;\n if (check(mid)) hi = mid;\n else lo = mid;\n }\n\n writeln(hi);\n}\n\n"}], "negative_code": [], "src_uid": "a5d1a96fd8514840062d747e6fda2c37"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.typecons;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n\n template next(T) if (isSigned!T) {\n final T next () {\n T res;\n ubyte b = skipByte (45);\n if (b == 45) {\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n final T[] nextA(T) (int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nalias Task = Tuple!(uint, uint);\n\nvoid main() {\n auto r = new InputReader;\n immutable nt = r.next!uint;\n auto res = uninitializedArray!(int[]) (nt);\n foreach (tid; 0 .. nt) {\n immutable n = r.next!uint;\n immutable T = r.next!uint;\n immutable a = r.next!uint;\n immutable b = r.next!uint;\n auto d = r.nextA!uint (n);\n auto t = r.nextA!uint (n); \n Task[] easy;\n Task[] hard;\n foreach (i; 0 .. n) {\n if (d[i]) {\n hard ~= Task (t[i], 1);\n } else {\n easy ~= Task (t[i], 0);\n }\n }\n sort (easy);\n sort (hard);\n debug stderr.writeln (easy);\n debug stderr.writeln (hard);\n auto m = merge (easy, hard);\n long curt;\n long ce = easy.length, ch = hard.length;\n long best;\n int k;\n while (!m.empty) {\n auto q = m.front;\n debug stderr.writeln (q, \", curt = \", curt);\n auto dt = q[0] - curt;\n if (dt > 0) {\n --dt;\n debug stderr.writefln (\"dt = %d\", dt);\n long k1 = min (dt / a, ce);\n dt -= k1 * a;\n long k2 = min (dt / b, ch);\n best = max (best, k + k1 + k2);\n debug stderr.writefln (\"k = %d, k1 = %d, k2 = %d\", k, k1, k2);\n }\n if (q[1]) {\n curt += b;\n --ch;\n } else {\n curt += a;\n --ce;\n }\n m.popFront ();\n ++k;\n }\n if (curt <= T) {\n best = n;\n }\n res[tid] = best.to!int;\n }\n writefln (\"%(%s\\n%)\", res);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint m = rint;\n\tforeach(_; 0 .. m){\n\t\tint n = rint;\n\t\tlong tAll = rlong, a = rlong, b = rlong;\n\t\tint[] hs = rint(n);\n\t\tlong[] ts = rlong(n);\n\n\t\tP[] ps;\n\t\tforeach(i; 0 .. n) ps ~= P(!!hs[i], ts[i]);\n\t\tps.sort!\"a.time < b.time\"();\n\n\t\tlong xAll, yAll;\n\t\tforeach(p; ps) if(p.isHard) yAll += 1; else xAll += 1;\n\n\t\tps ~= P(0, tAll + 1);\n\t\tlog(\"---\");\n\t\tlog(\"n:\", n, \"tAll:\", tAll, \"a:\", a, \"b:\", b);\n\t\tlog(\"ps:\", ps, \"xAll:\", xAll, \"yAll:\", yAll);\n\n\t\tlong x = 0, y = 0;\n\t\tlong best = 0;\n\t\tforeach(p; ps){\n\t\t\tlog(\"p:\", p, \"x:\", x, \"y:\", y);\n\t\t\tif(p.time - 1 >= a * x + b * y){\n\t\t\t\tlong t = (p.time - 1) - (a * x + b * y);\n\t\t\t\tlong s = x + y;\n\t\t\t\tlong x1 = min(xAll - x, t / a);\n\t\t\t\tif(x1 > 0){\n\t\t\t\t\tt -= x1 * a;\n\t\t\t\t\ts += x1;\n\t\t\t\t}\n\t\t\t\tlong y1 = min(yAll - y, t / b);\n\t\t\t\tif(y1 > 0){\n\t\t\t\t\tt -= y1 * b;\n\t\t\t\t\ts += y1;\n\t\t\t\t}\n\t\t\t\tbest.chmax(s);\n\t\t\t\tlog(\"t:\", t, \"s:\", s, \"x1:\", x1, \"y1:\", y1, \"best:\", best);\n\t\t\t}\n\t\t\tif(p.isHard) y += 1;\n\t\t\telse x += 1;\n\t\t}\n\n\t\tbest.writeln;\n\t}\n}\n\nstruct P{\n\tbool isHard;\n\tlong time;\n}"}], "negative_code": [], "src_uid": "6c165390c7f9fee059ef197ef40ae64f"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto p = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tauto b = new short [] [] (n, n);\r\n\t\tauto c = new short [] [] (n, n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n)\r\n\t\t\t{\r\n\t\t\t\tb[i][j] = (p[i] < p[j]);\r\n\t\t\t\tc[i][j] = (p[i] > p[j]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n)\r\n\t\t\t{\r\n\t\t\t\tb[i][j] += b[i - 1][j];\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach_reverse (j; i + 1..n - 1)\r\n\t\t\t{\r\n\t\t\t\tc[i][j] += c[i][j + 1];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// (<j) j | i (>i)\r\n\t\tlong res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n)\r\n\t\t\t{\r\n\t\t\t\tauto lo = (i > 0) ? b[i - 1][j] : 0;\r\n\t\t\t\tauto hi = (j + 1 < n) ? c[i][j + 1] : 0;\r\n\t\t\t\tres += lo * hi;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nstruct SegmentTree(T, T unit, alias binop) {\r\n int n;\r\n T[] dat;\r\n this(int n_) {\r\n n = 1;\r\n while (n < n_) n *= 2;\r\n dat = new T[2*n+2];\r\n dat[] = unit;\r\n }\r\n void update(int k, in T a) {\r\n k += n - 1;\r\n dat[k] = a;\r\n while (k > 0) {\r\n k = (k - 1) / 2;\r\n dat[k] = binop(dat[k * 2 + 1], dat[k * 2 + 2]);\r\n }\r\n }\r\n T query(int a, int b) const {\r\n return query(a, b, 0, 0, n);\r\n }\r\n T query(int a, int b, int k, int l, int r) const {\r\n if (r <= a || b <= l) return unit;\r\n if (a <= l && r <= b) return dat[k];\r\n T vl = query(a, b, k * 2 + 1, l, (l + r) / 2),\r\n vr = query(a, b, k * 2 + 2, (l + r) / 2, r);\r\n return binop(vl, vr);\r\n }\r\n}\r\nalias RSQ = SegmentTree!(int, 0, (a, b) => a + b);\r\n\r\nstruct BIT(Num, Num zero) {\r\n int N;\r\n Num[] dat; // dat is 1-indexed\r\n this(int N) {\r\n this.N = N;\r\n dat = new Num[N + 1];\r\n dat[] = zero;\r\n }\r\n // add x to i-th (0-indexed) element\r\n void add(int i, Num x) {\r\n i++; // make 1-indexed\r\n while (i <= N) {\r\n dat[i] += x;\r\n i += i & -i;\r\n }\r\n }\r\n // return the sum of [0, i) (0-indexed) element\r\n Num query(int i) {\r\n Num s = zero;\r\n while (i > 0) {\r\n s += dat[i];\r\n i -= i & -i;\r\n }\r\n return s;\r\n }\r\n}\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto P = readln.chomp.split(\" \").map!(to!int).array;\r\n\r\n long ans = 0;\r\n auto front = BIT!(int,0)(N+1);\r\n for (int b = 0; b < N; b++) {\r\n auto back = BIT!(int,0)(N+1);\r\n for (int c = N-1; c > b; c--) {\r\n long a_count = front.query(P[c]);\r\n long d_count = back.query(P[b]);\r\n ans += a_count * d_count;\r\n back.add(P[c], 1);\r\n }\r\n front.add(P[b], 1);\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nstruct SegmentTree(T, T unit, alias binop) {\r\n int n;\r\n T[] dat;\r\n this(int n_) {\r\n n = 1;\r\n while (n < n_) n *= 2;\r\n dat = new T[2*n+2];\r\n dat[] = unit;\r\n }\r\n void update(int k, in T a) {\r\n k += n - 1;\r\n dat[k] = a;\r\n while (k > 0) {\r\n k = (k - 1) / 2;\r\n dat[k] = binop(dat[k * 2 + 1], dat[k * 2 + 2]);\r\n }\r\n }\r\n T query(int a, int b) const {\r\n return query(a, b, 0, 0, n);\r\n }\r\n T query(int a, int b, int k, int l, int r) const {\r\n if (r <= a || b <= l) return unit;\r\n if (a <= l && r <= b) return dat[k];\r\n T vl = query(a, b, k * 2 + 1, l, (l + r) / 2),\r\n vr = query(a, b, k * 2 + 2, (l + r) / 2, r);\r\n return binop(vl, vr);\r\n }\r\n}\r\nalias RSQ = SegmentTree!(int, 0, (a, b) => a + b);\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto P = readln.chomp.split(\" \").map!(to!int).array;\r\n\r\n alias T = Tuple!(int,int);\r\n\r\n long ans = 0;\r\n auto front = RSQ(N+1);\r\n for (int b = 0; b < N; b++) {\r\n auto back = RSQ(N+1);\r\n for (int c = N-1; c > b; c--) {\r\n auto a_count = front.query(1, P[c]);\r\n long d_count = back.query(1, P[b]);\r\n ans += a_count * d_count;\r\n back.update(P[c], 1);\r\n }\r\n front.update(P[b], 1);\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n"}], "src_uid": "d6a123dab1263b0e7b297ca2584fe701"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 50_000;\n\nvoid main ()\n{\n\tauto s = new bool [limit];\n\ts[] = true;\n\ts[0] = false;\n\ts[1] = false;\n\tfor (uint g = 2; g * g < limit; g++)\n\t{\n\t\tif (s[g])\n\t\t{\n\t\t\tfor (uint e = g; e * g < limit; e++)\n\t\t\t{\n\t\t\t\ts[e * g] = false;\n\t\t\t}\n\t\t}\n\t}\n\n\tuint [] p;\n\tforeach (g; 0..limit)\n\t{\n\t\tif (s[g])\n\t\t{\n\t\t\tp ~= g;\n\t\t}\n\t}\n\n\tuint n;\n\tuint a, b, c, d;\n\twhile (readf (\" %s %s %s %s %s\", &n, &a, &b, &c, &d) > 0)\n\t{\n\t\tuint res = 0;\n\t\tauto t = new bool [limit];\n\t\tfor (uint start = 0; start <= n; start += limit)\n\t\t{\n\t\t\tuint finish = min (start + limit, n + 1);\n\t\t\tif (start == 0)\n\t\t\t{\n\t\t\t\tt[] = s[];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tt[] = true;\n\t\t\t\tforeach (g; p)\n\t\t\t\t{\n\t\t\t\t\tuint lo = (start + g - 1) / g * g;\n\t\t\t\t\twhile (lo < finish)\n\t\t\t\t\t{\n\t\t\t\t\t\tt[lo - start] = false;\n\t\t\t\t\t\tlo += g;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (i; start..finish)\n\t\t\t{\n\t\t\t\tif (t[i - start])\n\t\t\t\t{\n\t\t\t\t\tdebug {writeln (i);}\n\t\t\t\t\tuint cur = a;\n\t\t\t\t\tcur = cur * i + b;\n\t\t\t\t\tcur = cur * i + c;\n\t\t\t\t\tcur = cur * i + d;\n\n\t\t\t\t\tuint mult = 0;\n\t\t\t\t\tuint k = n;\n\t\t\t\t\twhile (k > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tk /= i;\n\t\t\t\t\t\tmult += k;\n\t\t\t\t\t}\n\t\t\t\t\tres += cur * mult;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n// floor(sqrt(a))\nlong floorSqrt(long a) {\n import core.bitop : bsr;\n import std.algorithm : min;\n long b = a, x = 0, y = 0;\n for (int e = bsr(a) & ~1; e >= 0; e -= 2) {\n x <<= 1;\n y <<= 1;\n if (b >= (y | 1) << e) {\n b -= (y | 1) << e;\n x |= 1;\n y += 2;\n }\n }\n return x;\n}\n\n// get([N / j]) = \\sum_{p<=[N/j]} p^K\n// O(N^(3/4) / log N) time, O(N^(1/2)) space\nclass PrimeSum(T, int K) {\n long N, sqrtN;\n bool[] isPrime;\n T[] small, large;\n this(long N) {\n assert(N >= 1, \"PrimeSum: N >= 1 must hold\");\n this.N = N;\n sqrtN = floorSqrt(N);\n isPrime = new bool[cast(int)(sqrtN + 1)];\n small = new T[cast(int)(sqrtN + 1)];\n large = new T[cast(int)(sqrtN + 1)];\n isPrime[2 .. $] = true;\n T powerSum(long n) {\n static if (K == 0) {\n return T(n);\n } else static if (K == 1) {\n long n0 = n, n1 = n + 1;\n ((n0 % 2 == 0) ? n0 : n1) /= 2;\n return T(n0) * T(n1);\n } else static if (K == 2) {\n long n0 = n, n1 = n + 1, n2 = 2 * n + 1;\n ((n0 % 2 == 0) ? n0 : n1) /= 2;\n ((n0 % 3 == 0) ? n0 : (n1 % 3 == 0) ? n1 : n2) /= 3;\n return T(n0) * T(n1) * T(n2);\n } else static if (K == 3) {\n long n0 = n, n1 = n + 1;\n ((n0 % 2 == 0) ? n0 : n1) /= 2;\n return T(n0) * T(n0) * T(n1) * T(n1);\n } else {\n static assert(false, \"PrimeSum: K is out of range\");\n }\n }\n foreach (n; 1 .. sqrtN + 1) small[cast(int)(n)] = powerSum(n);\n foreach (l; 1 .. sqrtN + 1) large[cast(int)(l)] = powerSum(N / l);\n foreach (p; 2 .. sqrtN + 1) {\n if (isPrime[cast(int)(p)]) {\n for (long n = p^^2; n <= sqrtN; n += p) isPrime[cast(int)(n)] = false;\n const pk = T(p)^^K, g1 = get(p - 1);\n foreach (l; 1 .. sqrtN + 1) {\n const n = N / l;\n if (n < p^^2) break;\n large[cast(int)(l)] -= pk * (get(n / p) - g1);\n }\n foreach_reverse (n; 1 .. sqrtN + 1) {\n if (n < p^^2) break;\n small[cast(int)(n)] -= pk * (get(n / p) - g1);\n }\n }\n }\n small[1 .. $] -= T(1);\n large[1 .. $] -= T(1);\n }\n T get(long n) {\n return (n <= sqrtN) ? small[cast(int)(n)] : large[cast(int)(N / n)];\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readLong();\n const A = readLong();\n const B = readLong();\n const C = readLong();\n const D = readLong();\n \n auto ps3 = new PrimeSum!(long, 3)(N);\n auto ps2 = new PrimeSum!(long, 2)(N);\n auto ps1 = new PrimeSum!(long, 1)(N);\n auto ps0 = new PrimeSum!(long, 0)(N);\n long get(long n) {\n return A * ps3.get(n) + B * ps2.get(n) + C * ps1.get(n) + D * ps0.get(n);\n }\n \n long ans;\n for (long a = 0, b; b < N; a = b) {\n const k = N / (a + 1);\n b = N / k;\n // (a, b]: k\n ans += k * (get(b) - get(a));\n }\n foreach (p; 2 .. ps0.sqrtN + 1) {\n if (ps0.isPrime[cast(int)(p)]) {\n const f = get(p) - get(p - 1);\n for (long n = N / p^^2; n >= 1; n /= p) {\n ans += n * f;\n }\n }\n }\n ans &= (1L << 32) - 1;\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n// floor(sqrt(a))\nlong floorSqrt(long a) {\n import core.bitop : bsr;\n import std.algorithm : min;\n long b = a, x = 0, y = 0;\n for (int e = bsr(a) & ~1; e >= 0; e -= 2) {\n x <<= 1;\n y <<= 1;\n if (b >= (y | 1) << e) {\n b -= (y | 1) << e;\n x |= 1;\n y += 2;\n }\n }\n return x;\n}\n\n// // pi([N / l]) = get([N / l]) - 1\nuint solve(int N, uint A, uint B, uint C, uint D) {\n const sqrtN = cast(int)(floorSqrt(N));\n stderr.writefln(\"N = %s, sqrtN = %s\", N, sqrtN);\n stderr.flush;\n auto small0 = new uint[sqrtN + 1];\n auto large0 = new uint[sqrtN + 1];\n auto small1 = new uint[sqrtN + 1];\n auto large1 = new uint[sqrtN + 1];\n auto small2 = new uint[sqrtN + 1];\n auto large2 = new uint[sqrtN + 1];\n auto small3 = new uint[sqrtN + 1];\n auto large3 = new uint[sqrtN + 1];\n uint get0(int n) { return (n <= sqrtN) ? small0[n] : large0[N / n]; }\n uint get1(int n) { return (n <= sqrtN) ? small1[n] : large1[N / n]; }\n uint get2(int n) { return (n <= sqrtN) ? small2[n] : large2[N / n]; }\n uint get3(int n) { return (n <= sqrtN) ? small3[n] : large3[N / n]; }\n \n uint calc0(int n) {\n return n;\n }\n uint calc1(int n) {\n uint n0 = n, n1 = n + 1;\n ((n0 % 2 == 0) ? n0 : n1) /= 2;\n return n0 * n1;\n }\n uint calc2(int n) {\n uint n0 = n, n1 = n + 1, n2 = 2 * n + 1;\n ((n0 % 2 == 0) ? n0 : (n1 % 2 == 0) ? n1 : n2) /= 2;\n ((n0 % 3 == 0) ? n0 : (n1 % 3 == 0) ? n1 : n2) /= 3;\n return n0 * n1 * n2;\n }\n uint calc3(int n) {\n uint n0 = n, n1 = n + 1;\n ((n0 % 2 == 0) ? n0 : n1) /= 2;\n return n0 * n0 * n1 * n1;\n }\n \n foreach (n; 1 .. sqrtN + 1) {\n // small[n] = n;\n small0[n] = calc0(n);\n small1[n] = calc1(n);\n small2[n] = calc2(n);\n small3[n] = calc3(n);\n }\n foreach_reverse (l; 1 .. sqrtN + 1) {\n // large[l] = N / l;\n large0[l] = calc0(N / l);\n large1[l] = calc1(N / l);\n large2[l] = calc2(N / l);\n large3[l] = calc3(N / l);\n }\n auto isnp = new bool[sqrtN + 1];\n int pi;\n foreach (p; 2 .. sqrtN + 1) {\n // if (small[p - 1] < small[p]) {\n if (!isnp[p]) {\n for (int n = 2 * p; n <= sqrtN; n += p) isnp[n] = true;\n ++pi;\n foreach (l; 1 .. sqrtN + 1) {\n const n = N / l;\n if (n < p^^2) {\n break;\n }\n // pi = #{1, p_1, ..., p_{pi-1}}\n // large[l] -= get(n / p) - pi;\n large0[l] -= (get0(n / p) - get0(p - 1));\n large1[l] -= (get1(n / p) - get1(p - 1)) * p;\n large2[l] -= (get2(n / p) - get2(p - 1)) * p * p;\n large3[l] -= (get3(n / p) - get3(p - 1)) * p * p * p;\n }\n foreach_reverse (n; 1 .. sqrtN + 1) {\n if (n < p^^2) {\n break;\n }\n // pi = #{1, p_1, ..., p_{pi-1}}\n // small[n] -= get(n / p) - pi;\n small0[n] -= (get0(n / p) - get0(p - 1));\n small1[n] -= (get1(n / p) - get1(p - 1)) * p;\n small2[n] -= (get2(n / p) - get2(p - 1)) * p * p;\n small3[n] -= (get3(n / p) - get3(p - 1)) * p * p * p;\n }\n }\n }\n \n uint getF(int n) {\n uint ret;\n ret += A * (get3(n) - 1);\n ret += B * (get2(n) - 1);\n ret += C * (get1(n) - 1);\n ret += D * (get0(n) - 1);\n return ret;\n }\n \n debug {\n auto isnp_ = new bool[N + 1];\n foreach (p; 2 .. N + 1) {\n if (!isnp_[p]) {\n for (int n = 2 * p; n <= N; n += p) {\n isnp_[n] = true;\n }\n }\n }\n auto sums = new uint[N + 1];\n foreach (p; 2 .. N + 1) {\n if (!isnp_[p]) {\n sums[p] = A * p^^3 + B * p^^2 + C * p + D;\n }\n }\n foreach (n; 1 .. N + 1) {\n sums[n] += sums[n - 1];\n }\n writeln(\"sums = \", sums);\n writeln(\"small0 = \", small0, \", large0 = \", large0);\n writeln(\"small1 = \", small1, \", large1 = \", large1);\n writeln(\"small2 = \", small2, \", large2 = \", large2);\n writeln(\"small3 = \", small3, \", large3 = \", large3);\n foreach (n; 1 .. sqrtN + 1) {\n assert(sums[n] == getF(n));\n }\n foreach_reverse (l; 1 .. sqrtN + 1) {\n assert(sums[N / l] == getF(N / l));\n }\n }\n \n uint ans;\n for (int a = 1, b; a < N; a = b) {\n const k = N / (a + 1);\n b = N / k;\n // (a, b]: k\n ans += k * (getF(b) - getF(a));\n }\n foreach (p; 2 .. sqrtN + 1) {\n const f = getF(p) - getF(p - 1);\n int n = N / p^^2;\n for (; n >= 1; n /= p) {\n ans += n * f;\n }\n }\n return ans;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const A = readInt();\n const B = readInt();\n const C = readInt();\n const D = readInt();\n const ans = solve(N, A, B, C, D);\n writeln(ans);\n \n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 20_000;\n\nvoid main ()\n{\n\tuint n;\n\tuint a, b, c, d;\n\twhile (readf (\" %s %s %s %s %s\", &n, &a, &b, &c, &d) > 0)\n\t{\n\t\tauto s = new bool [limit];\n\t\ts[] = true;\n\t\ts[0] = false;\n\t\ts[1] = false;\n\t\tfor (uint g = 2; g * g < limit; g++)\n\t\t{\n\t\t\tif (s[g])\n\t\t\t{\n\t\t\t\tfor (uint e = g; e * g < limit; e++)\n\t\t\t\t{\n\t\t\t\t\ts[e * g] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tuint [] p;\n\t\tforeach (g; 0..limit)\n\t\t{\n\t\t\tif (s[g])\n\t\t\t{\n\t\t\t\tp ~= g;\n\t\t\t}\n\t\t}\n\n\t\tuint res = 0;\n\t\tn += 1;\n\t\tauto t = new bool [limit];\n\t\tfor (uint start = 0; start < n; start += limit)\n\t\t{\n\t\t\tuint finish = min (start + limit, n);\n\t\t\tif (start == 0)\n\t\t\t{\n\t\t\t\tt[] = s[];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tt[] = true;\n\t\t\t\tforeach (g; p)\n\t\t\t\t{\n\t\t\t\t\tuint lo = (start + g - 1) / g * g;\n\t\t\t\t\twhile (lo < finish)\n\t\t\t\t\t{\n\t\t\t\t\t\tt[lo - start] = false;\n\t\t\t\t\t\tlo += g;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (i; start..finish)\n\t\t\t{\n\t\t\t\tif (t[i - start])\n\t\t\t\t{\n\t\t\t\t\tuint cur = a;\n\t\t\t\t\tcur = cur * i + b;\n\t\t\t\t\tcur = cur * i + c;\n\t\t\t\t\tcur = cur * i + d;\n\n\t\t\t\t\tuint mult = 0;\n\t\t\t\t\tuint k = n;\n\t\t\t\t\twhile (k > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tk /= i;\n\t\t\t\t\t\tmult += k;\n\t\t\t\t\t}\n\t\t\t\t\tres += cur * mult;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "b54a045ad7beed08b94f5d31700a2d77"} {"source_code": "import std.math;\nimport std.typecons;\nimport std.algorithm;\n\nalias Tuple!(uint, \"sub\", ulong, \"num\") Flowers;\n\nFlowers solve(const uint[] bs) {\n\tuint miin, maax;\n\tmaax = miin = bs[0];\n\tforeach (i; 1..bs.length) {\n\t\tmiin = min(miin, bs[i]);\n\t\tmaax = max(maax, bs[i]);\n\t}\n\n\tulong minN = 0;\n\tulong maxN = 0;\n\tforeach (b; bs) {\n\t\tif (b == miin) {++minN;}\n\t\tif (b == maax) {++maxN;}\n\t}\n\n\treturn Flowers(maax - miin, (miin == maax) ? (minN * (minN - 1) / 2) : (minN * maxN));\n}\n\nunittest {\n\tassert(Flowers(1, 1) == solve([1, 2]));\n\tassert(Flowers(4, 1) == solve([1, 4, 5]));\n\tassert(Flowers(2, 4) == solve([3, 1, 2, 3, 1]));\n\tassert(Flowers(0, 1) == solve([1, 1]));\n\tassert(Flowers(0, 3) == solve([1, 1, 1]));\n\tassert(Flowers(0, 10) == solve([345, 345, 345, 345, 345]));\n}\n\nint main(string[] argv) {\n\timport std.stdio;\n\n\tuint n = 0;\n\treadf(\" %s\", &n);\n\tauto bs = new uint[](n);\n\tforeach (i; 0..n) {\n\t\treadf(\" %s\", &(bs[i]));\n\t}\n\tauto res = solve(bs);\n\twriteln(res.sub, ' ', res.num);\n return 0;\n}\n", "positive_code": [{"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n ulong n = readln.chomp.to!ulong;\n ulong[] b = readln.split.map!(to!ulong).array;\n b.sort;\n\n ulong t1 = 0;\n ulong t2 = 0;\n foreach(item; b) {\n if(item == b[$-1])\n t1 += 1;\n if(item == b[0])\n t2 += 1;\n }\n //ulong ways = count(b,b[0])*count(b,b[$-1]);\n ulong ways = t1*t2;\n ulong maxima = b[$-1]-b[0];\n\n if(maxima != 0) {\n writefln(\"%d %d\", maxima, ways);\n } else {\n writefln(\"%d %d\", maxima, n*(n-1)/2);\n }\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([1,2]) == [1,1],\"A\");\n assert(solve([3,1,2,3,1]) == [2,4],\"B\");\n assert(solve([1,4,5]) == [4,1],\"C\");\n assert(solve([1,1,1]) == [0,3],\"D\");\n assert(solve([3,1,1,3,1]) == [2,6],\"E\");\n assert(solve([5,5]) == [0,1],\"F\");\n assert(solve([5,4,3,2,2,2,2]) == [3,4],\"G\");\n assert(solve([1,1,1,1,1,1]) == [0,15],\"H\");\n assert(solve([1,1000000000]) == [1000000000-1,1],\"GIG\");\n}\n\nulong[] solve(int[] p){\n ulong[ulong] cnt;\n uint max = 0;\n uint min = 0;\n for(uint i = 0; i < p.length; i++){\n if(p[i] > p[max]){\n max = i;\n }\n if(p[i] < p[min]){\n min = i;\n }\n cnt[p[i]]++;\n }\n if ((p[max] - p[min]) == 0){\n debug(1) writeln([0,(cnt[p[0]]*(cnt[p[0]]-1))/2]);\n return [0,(cnt[p[0]]*(cnt[p[0]]-1))/2];\n //return [0,cnt[p[0]]*(cnt[p[0]]-1)];\n }\n debug(1) writeln([p[max] - p[min],cnt[p[max]]*cnt[p[min]]]);\n return [p[max] - p[min],cnt[p[max]]*cnt[p[min]]];\n}\n\nvoid main(){\n size_t a;\n readf(\"%s\\n\",&a);\n\n int[] x = new int[a];\n for(ulong i = 0; i< a; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n writefln(\"%s %s\",s[0],s[1]);\n}\n"}], "negative_code": [{"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n ulong n = readln.chomp.to!ulong;\n ulong[] b = readln.split.map!(to!ulong).array;\n b.sort;\n \n ulong ways = (cast(ulong)count(b,b[0]))*(cast(ulong)count(b,b[$-1]));\n ulong maxima = b[$-1]-b[0];\n\n if(maxima != 0) {\n writefln(\"%d %d\", maxima, ways);\n } else {\n writefln(\"%d %d\", maxima, n*(n-1)/2);\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n ulong[] b = readln.split.map!(to!ulong).array;\n b.sort;\n\n ulong ways = count(b,b[0])*count(b,b[$-1]);\n ulong maxima = b[$-1]-b[0];\n\n if(maxima != 0) {\n writefln(\"%d %d\", maxima, ways);\n } else {\n writefln(\"%d %d\", maxima, n*(n-1)/2);\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n b.sort;\n\n ulong ways = b.filter!(x => x == b[$-1]).count * b.filter!(x => x == b[0]).count;\n\n writefln(\"%d %d\", b[$-1]-b[0], ways);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n ulong n = readln.chomp.to!ulong;\n ulong[] b = readln.split.map!(to!ulong).array;\n b.sort;\n\n ulong ways = count(b,b[0])*count(b,b[$-1]);\n ulong maxima = b[$-1]-b[0];\n\n if(maxima != 0) {\n writefln(\"%d %d\", maxima, ways);\n } else {\n writefln(\"%d %d\", maxima, n*(n-1)/2);\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n ulong[] b = readln.split.map!(to!ulong).array;\n b.sort;\n\n ulong t1 = 0;\n ulong t2 = 0;\n foreach(item; b) {\n if(item == b[$-1])\n t1 += 1;\n if(item == b[0])\n t2 += 1;\n }\n //ulong ways = count(b,b[0])*count(b,b[$-1]);\n ulong ways = t1*t2;\n ulong maxima = b[$-1]-b[0];\n\n if(maxima != 0) {\n writefln(\"%d %d\", maxima, ways);\n } else {\n writefln(\"%d %d\", maxima, n*(n-1)/2);\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n b.sort;\n\n ulong ways = count(b,b[0])*count(b,b[$-1]);\n int maxima = b[$-1]-b[0];\n\n if(maxima != 0) {\n writefln(\"%d %d\", maxima, ways);\n } else {\n writefln(\"%d %d\", maxima, n*(n-1)/2);\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\nimport std.bigint;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(to!int).array;\n b.sort;\n\n BigInt ways = b.filter!(x => x == b[$-1]).count * b.filter!(x => x == b[0]).count;\n\n writefln(\"%d %d\", b[$-1]-b[0], ways);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(x => x.to!int).array;\n b.sort;\n\n int[int] c;\n\n foreach(item; b) {\n c.update(item,\n {\n return 1;\n },\n (ref int i) {\n return i+1;\n });\n }\n\n int maxima = b[$-1]-b[0];\n\n int ways = 0;\n foreach(item; b) {\n //ways += c[item+maxima];\n if(((item+maxima) in c) !is null)\n ways += c[item+maxima];\n }\n\n writefln(\"%d %d\", maxima, ways);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/459/B\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] b = readln.split.map!(x => x.to!int).array;\n b.sort;\n\n int[int] c;\n\n foreach(item; b) {\n c.update(item,\n {\n return 1;\n },\n (ref int i) {\n return i+1;\n });\n }\n\n int maxima = b[$-1]-b[0];\n\n int ways = 0;\n foreach(item; b) {\n //ways += c[item+maxima];\n if(((item+maxima) in c) !is null)\n ways += c[item];\n }\n\n writefln(\"%d %d\", maxima, ways);\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([1,2]) == [1,1],\"A\");\n assert(solve([3,1,2,3,1]) == [2,4],\"B\");\n assert(solve([1,4,5]) == [4,1],\"C\"); \n}\n\nint[] solve(int[] p){\n int[int] cnt;\n int max = 0;\n int min = 0;\n for(int i = 0; i < p.length; i++){\n if(p[i] > p[max]){\n max = i;\n }\n if(p[i] < p[min]){\n min = i;\n }\n cnt[p[i]]++;\n }\n return [p[max] - p[min],cnt[p[max]]*cnt[p[min]]];\n}\n\nvoid main(){\n\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([1,2]) == [1,1],\"A\");\n assert(solve([3,1,2,3,1]) == [2,4],\"B\");\n assert(solve([1,4,5]) == [4,1],\"C\");\n assert(solve([1,1,1]) == [0,6],\"D\");\n assert(solve([3,1,1,3,1]) == [2,6],\"E\");\n assert(solve([5,5]) == [0,2],\"F\");\n assert(solve([5,4,3,2,2,2,2]) == [3,4],\"G\");\n assert(solve([1,1,1,1,1,1]) == [0,30],\"G\");\n}\n\nsize_t[] solve(size_t[] p){\n size_t[size_t] cnt;\n size_t max = 0;\n size_t min = 0;\n for(size_t i = 0; i < p.length; i++){\n if(p[i] > p[max]){\n max = i;\n }\n if(p[i] < p[min]){\n min = i;\n }\n cnt[p[i]]++;\n }\n if ((p[max] - p[min]) == 0){\n return [0,cnt[p[0]]*(cnt[p[0]]-1)];\n }\n return [p[max] - p[min],cnt[p[max]]*cnt[p[min]]];\n}\n\nvoid main(){\n size_t a;\n readf(\"%s\\n\",&a);\n\n size_t[] x = new size_t[a];\n for(size_t i = 0; i< a; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n writefln(\"%s %s\",s[0],s[1]);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([1,2]) == [1,1],\"A\");\n assert(solve([3,1,2,3,1]) == [2,4],\"B\");\n assert(solve([1,4,5]) == [4,1],\"C\");\n assert(solve([1,1,1]) == [0,3],\"D\");\n}\n\nint[] solve(int[] p){\n int[int] cnt;\n int max = 0;\n int min = 0;\n for(int i = 0; i < p.length; i++){\n if(p[i] > p[max]){\n max = i;\n }\n if(p[i] < p[min]){\n min = i;\n }\n cnt[p[i]]++;\n }\n if ((p[max] - p[min]) == 0){\n return [0,cnt[p[0]]];\n }\n return [p[max] - p[min],cnt[p[max]]*cnt[p[min]]];\n}\n\nvoid main(){\n int a;\n readf(\"%s\\n\",&a);\n\n int[] x = new int[a];\n for(int i = 0; i< a; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n writefln(\"%s %s\",s[0],s[1]);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([1,2]) == [1,1],\"A\");\n assert(solve([3,1,2,3,1]) == [2,4],\"B\");\n assert(solve([1,4,5]) == [4,1],\"C\");\n assert(solve([1,1,1]) == [0,6],\"D\");\n assert(solve([3,1,1,3,1]) == [2,6],\"E\");\n assert(solve([5,5]) == [0,2],\"F\");\n assert(solve([5,4,3,2,2,2,2]) == [3,4],\"G\");\n assert(solve([1,1,1,1,1,1]) == [0,30],\"G\");\n assert(solve([1,1000000000]) == [1000000000-1,1],\"GIG\");\n}\n\nulong[] solve(int[] p){\n ulong[ulong] cnt;\n uint max = 0;\n uint min = 0;\n for(uint i = 0; i < p.length; i++){\n if(p[i] > p[max]){\n max = i;\n }\n if(p[i] < p[min]){\n min = i;\n }\n cnt[p[i]]++;\n }\n if ((p[max] - p[min]) == 0){\n return [0,cnt[p[0]]*(cnt[p[0]]-1)];\n }\n debug(1) writeln([p[max] - p[min],cnt[p[max]]*cnt[p[min]]]);\n return [p[max] - p[min],cnt[p[max]]*cnt[p[min]]];\n}\n\nvoid main(){\n size_t a;\n readf(\"%s\\n\",&a);\n\n int[] x = new int[a];\n for(ulong i = 0; i< a; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n writefln(\"%s %s\",s[0],s[1]);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([1,2]) == [1,1],\"A\");\n assert(solve([3,1,2,3,1]) == [2,4],\"B\");\n assert(solve([1,4,5]) == [4,1],\"C\");\n assert(solve([1,1,1]) == [0,6],\"D\");\n}\n\nint[] solve(int[] p){\n int[int] cnt;\n int max = 0;\n int min = 0;\n for(int i = 0; i < p.length; i++){\n if(p[i] > p[max]){\n max = i;\n }\n if(p[i] < p[min]){\n min = i;\n }\n cnt[p[i]]++;\n }\n if ((p[max] - p[min]) == 0){\n return [0,cnt[p[0]]*(cnt[p[0]]-1)];\n }\n return [p[max] - p[min],cnt[p[max]]*cnt[p[min]]];\n}\n\nvoid main(){\n int a;\n readf(\"%s\\n\",&a);\n\n int[] x = new int[a];\n for(int i = 0; i< a; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n writefln(\"%s %s\",s[0],s[1]);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve([1,2]) == [1,1],\"A\");\n assert(solve([3,1,2,3,1]) == [2,4],\"B\");\n assert(solve([1,4,5]) == [4,1],\"C\");\n}\n\nint[] solve(int[] p){\n int[int] cnt;\n int max = 0;\n int min = 0;\n for(int i = 0; i < p.length; i++){\n if(p[i] > p[max]){\n max = i;\n }\n if(p[i] < p[min]){\n min = i;\n }\n cnt[p[i]]++;\n }\n return [p[max] - p[min],cnt[p[max]]*cnt[p[min]]];\n}\n\nvoid main(){\n int a;\n readf(\"%s\\n\",&a);\n\n int[] x = new int[a];\n for(int i = 0; i< a; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n writefln(\"%s %s\",s[0],s[1]);\n}\n"}], "src_uid": "eb2d1072c5308d9ef686315a122d9d3c"} {"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dunkelheit\" version=\"1.0.1\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner, dkh.algorithm;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n string s;\n sc.read(s);\n\n int n = s.length.to!int;\n\n long r = n;\n long ans = 0;\n foreach_reverse (l; 0..n) {\n int k = 1;\n while (l + 2 * k < r && (s[l + k] != s[l] || s[l + 2 * k] != s[l])) k++;\n r = min(r, l + 2 * k);\n\n ans += (n - r);\n }\n\n writeln(ans);\n return 0;\n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/algorithm.d */\n// module dkh.algorithm;\n\nimport std.traits : isFloatingPoint, isIntegral;\n\n \nT binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {\n while (r-l > 1) {\n T md = l + (r-l) / 2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \nT binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {\n foreach (i; 0..cnt) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \n \n\nimport std.range.primitives;\n\n \nE minimum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);\n}\n\n \nElementType!Range minimum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"minimum: range must not empty\");\n auto e = range.front; range.popFront;\n return minimum!pred(range, e);\n}\n\n \n \n\n \nE maximum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);\n}\n\n \nElementType!Range maximum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"maximum: range must not empty\");\n auto e = range.front; range.popFront;\n return maximum!pred(range, e);\n}\n\n \n \n\n \nRotator!Range rotator(Range)(Range r) {\n return Rotator!Range(r);\n}\n\n \nstruct Rotator(Range)\nif (isForwardRange!Range && hasLength!Range) {\n size_t cnt;\n Range start, now;\n this(Range r) {\n cnt = 0;\n start = r.save;\n now = r.save;\n }\n this(this) {\n start = start.save;\n now = now.save;\n }\n @property bool empty() const {\n return now.empty;\n }\n @property auto front() const {\n assert(!now.empty);\n import std.range : take, chain;\n return chain(now, start.take(cnt));\n }\n @property Rotator!Range save() {\n return this;\n }\n void popFront() {\n cnt++;\n now.popFront;\n }\n}\n\n \n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n private File f;\n \n this(File f) {\n this.f = f;\n }\n private char[512] lineBuf;\n private char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n assert(succW());\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n \n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n \n void read(Args...)(auto ref Args args) {\n import std.exception : enforce;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n \n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main(){\n auto S = readln.chomp;\n auto N = S.length.to!int;\n long ans = 1L * N * (N + 1) / 2;\n\n foreach (l; 0..N) foreach (r; l..min(N, l+10)) {\n bool ok = true;\n foreach (i; l..r+1) for (int j = 1; i - j >= l && i + j <= r; ++j) {\n if (S[i-j] == S[i] && S[i] == S[i+j]) ok = false;\n }\n ans -= ok;\n }\n\n ans.writeln;\n}"}], "negative_code": [], "src_uid": "71bace75df1279ae55a6e755159d4191"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum EPS = 1e-12L;\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const L = readReal();\n auto A = new real[N + 2];\n A[0] = 0.0L;\n A[N + 1] = L;\n foreach (i; 1 .. N + 1) {\n A[i] = readReal();\n }\n \n auto ls = new real[N + 2];\n auto rs = new real[N + 2];\n ls[0] = 0.0L;\n foreach (i; 0 .. N + 1) {\n ls[i + 1] = ls[i] + (A[i + 1] - A[i]) / (1 + i);\n }\n rs[N + 1] = 0.0L;\n foreach_reverse (i; 0 .. N + 1) {\n rs[i] = (A[i + 1] - A[i]) / (N + 1 - i) + rs[i + 1];\n }\n debug {\n writeln(\"ls = \", ls);\n writeln(\"rs = \", rs);\n }\n \n real ans;\n foreach (i; 0 .. N + 1) {\n if (ls[i] <= rs[i] + EPS && ls[i + 1] + EPS >= rs[i + 1]) {\n const real u = 1 + i;\n const real v = N + 1 - i;\n const d = A[i + 1] - A[i];\n ans = (d + u * ls[i] + v * rs[i + 1]) / (u + v);\n break;\n }\n }\n writefln(\"%.12f\", ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nT binarySearch(alias pred, T)(T ok, T ng)\n{ \n\twhile (abs(ok-ng) > 0.0000001)\n\t{\n\t\tauto mid = (ok+ng)/2;\n\t\tif (unaryFun!pred(mid)) ok = mid;\n\t\telse ng = mid;\n\t}\n\treturn ok;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new double[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto l = RD!int;\n\t\tauto a = RDA;\n\t\n\t\tbool f(double x)\n\t\t{\n\t\t\tdouble pos1 = 0.0, pos2 = l;\n\t\t\t{\n\t\t\t\tlong last;\n\t\t\t\tdouble time = x;\n\t\t\t\tdouble sp = 1.0;\n\t\t\t\tforeach (i; 0..n)\n\t\t\t\t{\n\t\t\t\t\tauto d = a[i] - last;\n\t\t\t\t\tif (time*sp <= d) break;\n\t\t\t\t\ttime -= d / sp;\n\t\t\t\t\tlast = a[i];\n\t\t\t\t\tpos1 = last;\n\t\t\t\t\tsp += 1.0;\n\t\t\t\t}\n\t\t\t\tpos1 += time * sp;\n\t\t\t}\n\t\t\t{\n\t\t\t\tlong last = l;\n\t\t\t\tdouble time = x;\n\t\t\t\tdouble sp = 1.0;\n\t\t\t\tforeach_reverse (i; 0..n)\n\t\t\t\t{\n\t\t\t\t\tauto d = last - a[i];\n\t\t\t\t\tif (time*sp <= d) break;\n\t\t\t\t\ttime -= d / sp;\n\t\t\t\t\tlast = a[i];\n\t\t\t\t\tpos2 = last;\n\t\t\t\t\tsp += 1.0;\n\t\t\t\t}\n\t\t\t\tpos2 -= time * sp;\n\t\t\t}\n\t\t\tdebug writeln(\"time:\", x, \" pos1:\", pos1, \" pos2:\", pos2);\n\t\t\treturn pos1 >= pos2;\n\t\t}\n\n\t\tauto r = binarySearch!(f)(cast(double)l, 0.0);\n\t\tans[ti] = r;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twritefln(FMT_F, e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "700cfc8d20794ca38d73ccff31e5292c"} {"source_code": "import std.stdio;\n\nvoid main(){\n int n,m; readf(\"%d\\n%d\\n\",&n,&m); bool can=true;\n while (n--){\n int a,b; readf(\"%d %d\\n\",&a,&b);\n if (m!=a && m!=b && m!=7-a && m!=7-b) m=7-m; else can=false;\n }\n writeln(can? \"YES\": \"NO\");\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int t; readf(\"%d\\n\", &t);\n for (int i = 0; i < n; i++) {\n int a, b; readf(\"%d %d\\n\", &a, &b);\n bool[] u = new bool[6];\n u[t - 1] = true;\n u[a - 1] = u[7 - a - 1] = true;\n u[b - 1] = u[7 - b - 1] = true;\n if (u.count!\"a == false\" > 1) {\n writeln(\"NO\");\n return;\n }\n }\n writeln(\"YES\");\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main() {\n uint n, s;\n readf(\"%d %d\", &n, &s);\n for (uint i = 0; i < n; ++i) {\n \tuint a, b;\n \treadf(\" %d %d\", &a, &b);\n \t\n \tif (s != a && s != 7 - a && s != b && s != 7 - b) {\n \t \n \t}\n \telse {\n \t writeln(\"NO\");\n \t return;\n \t}\n }\n writeln(\"YES\");\n}\n"}, {"source_code": "import std.string;\nimport std.stdio;\nimport std.conv;\n\nint main() {\n \n int other(int[] a) {\n int[int] set;\n foreach(int i; a)\n set[i] = 1;\n for (int i = 1; i <= 6; ++i)\n if ((i in set) is null)\n return i;\n return 1;\n }\n\n auto n = to!int(strip(readln()));\n auto x = to!int(strip(readln()));\n auto a = new int[n];\n auto b = new int[n];\n for (int i = 0; i < n; ++i) {\n auto tmp2 = split(strip(readln()), \" \"); \n a[i] = to!int(tmp2[0]);\n b[i] = to!int(tmp2[1]);\n }\n int[] h = [a[0], b[0], 7 - a[0], 7 - b[0], x];\n h ~= other(h);\n for (int i = 1; i < n; ++i) {\n int[int] set = [a[i] : 1, b[i] : 1, 7 - a[i] : 1, 7 - b[i] : 1];\n if ((h[5] in set) is null)\n h = set.keys ~ other(set.keys ~ h[5]) ~ h[5];\n else {\n writeln(\"NO\");\n return 0;\n }\n }\n writeln(\"YES\");\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main(){\n int n,m; readf(\"%d\\n%d\\n\",&n,&m);\n bool[int] can; can[7-m]=true;\n while (n--){\n int a,b; readf(\"%d %d\\n\",&a,&b);\n bool[int] could;\n foreach (i; can)\n if (i!=a && i!=b && i!=7-a && i!=7-b)\n could[7-i]=true;\n can=could;\n }\n writeln(can.length==1? \"YES\": \"NO\");\n}\n"}], "src_uid": "2d6a1202139e1f77f32377224e1fe752"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.format;\n\nimmutable int MAX_N = 100_000;\nint n, m;\nArray!int[MAX_N] g;\nint[3][MAX_N] comp;\nint[3] cc;\nint[MAX_N] ans;\n\nvoid main()\n{\n readln.strip.formattedRead(\" %s %s\", n, m);\n\n foreach (i; 0 .. m)\n {\n int a, b;\n readln.strip.formattedRead(\" %s %s\", a, b);\n a--, b--;\n g[a] ~= b;\n g[b] ~= a;\n }\n\n foreach (i; 0 .. n)\n {\n bool ok = false;\n foreach (j; 0 .. 3)\n {\n if (!comp[i][j])\n {\n ans[i] = j;\n cc[j]++;\n foreach (k; g[i])\n {\n comp[k][j] = true;\n }\n ok = true;\n break;\n }\n }\n\n if (!ok)\n {\n writeln(-1);\n return;\n }\n }\n\n bool ok = true;\n\n foreach (i; 0 .. n)\n {\n ok &= n == (g[i].length + cc[ans[i]]);\n }\n\n ok &= cc[0] > 0 && cc[1] > 0 && cc[2] > 0;\n\n if (ok)\n {\n foreach (i; 0 .. n)\n {\n write(ans[i] + 1, \" \");\n }\n writeln();\n }\n else\n {\n writeln(-1);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nstruct Input\n{\n T next(T)()\n {\n import std.conv;\n return to!T(nextWord);\n }\n string nextWord()\n {\n if (_nextWords.empty)\n\t_nextWords.insertFront(readln().split);\n string word = _nextWords.front; _nextWords.removeFront;\n return word;\n }\n import std.container;\n DList!string _nextWords;\n}\nInput input;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n static foreach(n; 0 .. T[i].Types.length)\n\tread(args[i][n]);\n else\n args[i] = input.next!(typeof(args[i]))();\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t; get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\nimport std.container;\nlong[][] adj;\nstring[] adjstr;\n\nvoid connect(long a, long b)\n{\n adj[cast(uint)a] ~= b;\n adj[cast(uint)b] ~= a;\n}\n\nvoid main()\n{\n import std.conv;\n long n, m; get(n, m);\n adj = new long[][cast(uint)n];\n adjstr = new string[cast(uint)n];\n itup!(m, (long a, long b) {\n connect(a - 1, b - 1);\n });\n short[string] color;\n short col = 1;\n foreach(size_t v, ref a; adj)\n {\n sort(a);\n adjstr[v] = \"\";\n foreach(e; a)\n\t adjstr[v] ~= to!string(e) ~ \".\";\n if(adjstr[v] !in color)\n\t{\n\t if ( col > 3 )\n\t ans(-1);\n\t color[adjstr[v]] = col;\n\t col++;\n\t}\n }\n if (col != 4)\n ans(-1);\n short[int] colorfor;\n int[3] cant;\n int[3] reqsum;\n foreach(v; 0 .. n)\n {\n colorfor[cast(int)v] = color[adjstr[cast(int)v]];\n cant[color[adjstr[cast(uint)v]] - 1]++;\n }\n reqsum[0] = cant[1] + cant[2];\n reqsum[1] = cant[0] + cant[2];\n reqsum[2] = cant[0] + cant[1];\n foreach(v; 0 .. n)\n {\n if(adj[cast(uint)v].length != reqsum[colorfor[cast(int)v] - 1])\n\tans(-1);\n }\n foreach(v; 0 .. n)\n write(colorfor[cast(int)v], \" \");\n writeln();\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n RedBlackTree!int[] g;\n foreach (_; 0 .. n) {\n g ~= make!(RedBlackTree!int);\n }\n \n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n \n g[u].insert(v);\n g[v].insert(u);\n }\n \n debug { g.writeln; }\n \n if (g[0].empty()) {\n writeln(-1);\n return;\n }\n \n \n auto ans = new int[] (n);\n \n ans[0] = 1;\n int nxt = g[0].front;\n ans[nxt] = 2;\n \n foreach (u; g[0].array.dropOne) {\n if (g[u].equalRange(nxt).empty()) { ans[u] = 2; }\n else { ans[u] = 3; }\n }\n \n foreach (v; 1 .. n) {\n if (ans[v] == 0) {\n bool to0 = ! g[v].equalRange(0).empty();\n bool to1 = ! g[v].equalRange(nxt).empty();\n \n if (to0 && to1) { ans[v] = 3; }\n else if (to0) { ans[v] = 2; }\n else if (to1) { ans[v] = 1; }\n else {\n writeln(-1);\n return;\n }\n }\n }\n \n foreach (v; 0 .. n) {\n foreach (u; g[v]) {\n if (ans[v] == ans[u]) {\n writeln(-1);\n return;\n }\n }\n }\n \n int[4] cnts;\n foreach (e; ans) { ++cnts[e]; }\n \n foreach (v; 0 .. n) {\n int other = n - cnts[ans[v]];\n if (g[v].length != other) {\n writeln(-1);\n return;\n }\n }\n \n if (ans.all!(x => x != 3)) {\n writeln(-1);\n return;\n }\n \n ans.map!(to!string).join(' ').writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n RedBlackTree!int[] g;\n foreach (_; 0 .. n) {\n g ~= make!(RedBlackTree!int);\n }\n \n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n \n g[u].insert(v);\n g[v].insert(u);\n }\n \n debug { g.writeln; }\n \n if (g[0].empty()) {\n writeln(-1);\n return;\n }\n \n \n auto ans = new int[] (n);\n \n ans[0] = 1;\n int nxt = g[0].front;\n ans[nxt] = 2;\n \n foreach (u; g[0].array.dropOne) {\n if (g[u].equalRange(nxt).empty()) { ans[u] = 2; }\n else { ans[u] = 3; }\n }\n \n foreach (v; 1 .. n) {\n if (ans[v] == 0) {\n bool to0 = ! g[v].equalRange(0).empty();\n bool to1 = ! g[v].equalRange(nxt).empty();\n \n if (to0 && to1) { ans[v] = 3; }\n else if (to0) { ans[v] = 2; }\n else if (to1) { ans[v] = 1; }\n else {\n writeln(-1);\n return;\n }\n }\n }\n \n foreach (v; 0 .. n) {\n foreach (u; g[v]) {\n if (ans[v] == ans[u]) {\n writeln(-1);\n return;\n }\n }\n }\n \n if (ans.dup.sort().uniq().array.length != 3) {\n writeln(-1);\n return;\n }\n \n ans.map!(to!string).join(' ').writeln;\n}"}], "src_uid": "7dea96a7599946a5b5d0b389c7e76651"} {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm : sort, each, maxElement, minElement;\nimport std.conv : to;\nimport std.range : iota, tee, enumerate;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n uint n;\n readf(\" %s\", n);\n auto l = new int[n];\n auto r = new int[n];\n foreach(i; 0..n) {\n uint ll, rr;\n readf(\" %s %s\", ll, rr);\n l[i] = ll;\n r[i] = rr;\n }\n\n uint k;\n readf(\" %s\", k);\n\n uint tt =0;\n uint ss = 0;\n foreach(i; 0..n) {\n\n if (l[i] <= k && r[i] >= k) {\n ss = i;\n break;\n }\n }\n\n\n writeln(n - ss);\n\n\n}\n", "positive_code": [{"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tint[] m = new int[t];\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &m[i]);\n\t}\n\tint x=0;\n\treadf(\" %d\", &x);\n\tint count=0;\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tif (x>m[i])\n\t\t{\n\t\t\tcount=count+1;\n\t\t}\n\t}\n\twriteln(t-count);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "2545b6af730f99193041a8810b728cb3"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tint n;\nmultitest_loop:\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tauto b = new int [n];\n\t\tauto c = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %s %s %s\") (a[i], b[i], c[i]);\n\t\t}\n\t\tauto adj = new int [] [n];\n\t\tforeach (j; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tadj[u] ~= v;\n\t\t\tadj[v] ~= u;\n\t\t}\n\n\t\tif (sum (b) != sum (c))\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue multitest_loop;\n\t\t}\n\n\t\tlong recur (int v, int p)\n\t\t{\n\t\t\tlong res = 0;\n\t\t\tint need = b[v] - c[v];\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tif (u != p)\n\t\t\t\t{\n\t\t\t\t\ta[u] = min (a[u], a[v]);\n\t\t\t\t\tres += recur (u, v);\n\t\t\t\t\tb[v] += b[u];\n\t\t\t\t\tc[v] += c[u];\n\t\t\t\t\tint next = b[u] - c[u];\n\t\t\t\t\twhile (need < 0 && next > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tres += a[v];\n\t\t\t\t\t\tneed += 1;\n\t\t\t\t\t\tnext -= 1;\n\t\t\t\t\t}\n\t\t\t\t\twhile (need > 0 && next < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tres += a[v];\n\t\t\t\t\t\tneed -= 1;\n\t\t\t\t\t\tnext += 1;\n\t\t\t\t\t}\n\t\t\t\t\tneed += next;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tlong res = recur (0, NA);\n\t\twriteln (res * 2);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!int;\n enum NodeType \n {\n empty,\n mis0,\n mis1,\n }\n auto nodetype = new NodeType[](n);\n auto aValue = new long[](n);\n int dlt = 0;\n foreach(i; 0 .. n)\n {\n auto a = next!long;\n auto b = next!long;\n auto c = next!long;\n aValue[i] = a;\n if (b == c)\n\t{\n\t nodetype[i] = NodeType.empty;\n\t}\n else\n\t{\n\t if (b == 0)\n\t {\n\t nodetype[i] = NodeType.mis0;\n\t dlt++;\n\t }\n\t else\n\t {\n\t nodetype[i] = NodeType.mis1;\n\t dlt--;\n\t }\n\t}\n }\n if (dlt != 0) return writeln(-1);\n debug writeln(nodetype);\n auto mis1cnt = new int[](n);\n auto mis0cnt = new int[](n);\n auto cost = new long[](n);\n auto height = new int[](n);\n auto parent = new int[](n);\n auto als = new int[][](n);\n foreach(i; 0 .. n - 1)\n {\n auto u = next!int - 1;\n auto v = next!int - 1;\n als[u] ~= v;\n als[v] ~= u;\n }\n auto queue = new Tuple!(int, int)[](n);\n void calcdfs(int v, long c, int h, int p)\n {\n cost[v] = c;\n height[v] = h;\n parent[v] = p;\n queue[v] = tuple(h, v);\n mis1cnt[v] = (nodetype[v] == NodeType.mis1);\n mis0cnt[v] = (nodetype[v] == NodeType.mis0);\n foreach(w; als[v])\n if (w != p)\n\t{\n\t calcdfs(w, min(cost[v], aValue[w]), h + 1, v);\n\t}\n }\n /*\n 1\n / \\\n\t 5 2\n / \\\n 4 3\n */\n calcdfs(0, aValue[0], 0, -1);\n auto squeue = sort(queue);\n auto totalCost = long(0);\n foreach_reverse(q; squeue)\n {\n auto node = q[1];\n debug writeln(\"doing node \", node + 1, \" m0 \", mis0cnt[node], \" m1 \", mis1cnt[node]);\n auto toremove = min(mis1cnt[node], mis0cnt[node]);\n totalCost += toremove * cost[node] * 2;\n mis1cnt[node] -= toremove;\n mis0cnt[node] -= toremove;\n debug writeln(\"doing node \", node + 1, \" m0 \", mis0cnt[node], \" m1 \", mis1cnt[node],\n\t\t \" p \", parent[node] + 1);\n if (parent[node] != -1)\n\t{\n\t mis1cnt[parent[node]] += mis1cnt[node];\n\t mis0cnt[parent[node]] += mis0cnt[node];\n\t}\n }\n totalCost.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = new long[](n);\n\tauto b = new long[](n);\n\tauto c = new long[](n);\n\tforeach (i; 0..n)\n\t{\n\t\ta[i] = RD;\n\t\tb[i] = RD;\n\t\tc[i] = RD;\n\t}\n\tauto edges = new int[][](n);\n\tforeach (i; 0..n-1)\n\t{\n\t\tauto u = RD!int-1;\n\t\tauto v = RD!int-1;\n\t\tedges[u] ~= v;\n\t\tedges[v] ~= u;\n\t}\n\n\tauto d = new long[](n);\n\tauto cnt = new long[](n);\n\tauto par = new int[](n);\n\t\n\tlong[] dfs(int pos, int last)\n\t{\n\t\tpar[pos] = last;\n\t\td[pos] = c[pos] - b[pos];\n\t\tcnt[pos] = b[pos] == c[pos] ? 0 : 1;\n\t\tforeach (to; edges[pos])\n\t\t{\n\t\t\tif (to == last) continue;\n\t\t\tauto r = dfs(to, pos);\n\t\t\td[pos] += r[0];\n\t\t\tcnt[pos] += r[1];\n\t\t}\n\t\treturn [d[pos], cnt[pos]];\n\t}\n\tdfs(0, -1);\n\n\tif (d[0] != 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tlong ans = a[0] * cnt[0];\n\t\tvoid dfs2(int pos, int last, long cost)\n\t\t{\n\t\t\tif (a[pos] < cost)\n\t\t\t{\n\t\t\t\tauto x = cnt[pos] - abs(d[pos]);\n\t\t\t\tans -= cost * x;\n\t\t\t\tans += a[pos] * x;\n\t\t\t\tcost = a[pos];\n\t\t\t}\n\t\t\t\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == last) continue;\n\t\t\t\tdfs2(to, pos, cost);\n\t\t\t}\n\t\t}\n\t\tdfs2(0, -1, a[0]);\n\t\twriteln(ans);\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!int;\n enum NodeType \n {\n empty,\n mis0,\n mis1,\n }\n auto nodetype = new NodeType[](n);\n auto aValue = new int[](n);\n int dlt = 0;\n foreach(i; 0 .. n)\n {\n auto a = next!int;\n auto b = next!int;\n auto c = next!int;\n aValue[i] = a;\n if (b == c)\n\t{\n\t nodetype[i] = NodeType.empty;\n\t}\n else\n\t{\n\t if (b == 0)\n\t {\n\t nodetype[i] = NodeType.mis0;\n\t dlt++;\n\t }\n\t else\n\t {\n\t nodetype[i] = NodeType.mis1;\n\t dlt--;\n\t }\n\t}\n }\n if (dlt != 0) return writeln(-1);\n debug writeln(nodetype);\n auto mis1cnt = new int[](n);\n auto mis0cnt = new int[](n);\n auto cost = new int[](n);\n auto height = new int[](n);\n auto parent = new int[](n);\n auto als = new int[][](n);\n foreach(i; 0 .. n - 1)\n {\n auto u = next!int - 1;\n auto v = next!int - 1;\n als[u] ~= v;\n als[v] ~= u;\n }\n auto queue = new Tuple!(int, int)[](n);\n void calcdfs(int v, int c, int h, int p)\n {\n cost[v] = c;\n height[v] = h;\n parent[v] = p;\n queue[v] = tuple(h, v);\n mis1cnt[v] = (nodetype[v] == NodeType.mis1);\n mis0cnt[v] = (nodetype[v] == NodeType.mis0);\n foreach(w; als[v])\n if (w != p)\n\t{\n\t calcdfs(w, min(cost[v], aValue[w]), h + 1, v);\n\t}\n }\n /*\n 1\n / \\\n\t 5 2\n / \\\n 4 3\n */\n calcdfs(0, aValue[0], 0, -1);\n auto squeue = sort(queue);\n auto totalCost = long(0);\n foreach_reverse(q; squeue)\n {\n auto node = q[1];\n debug writeln(\"doing node \", node + 1, \" m0 \", mis0cnt[node], \" m1 \", mis1cnt[node]);\n auto toremove = min(mis1cnt[node], mis0cnt[node]);\n totalCost += toremove * cost[node] * 2;\n mis1cnt[node] -= toremove;\n mis0cnt[node] -= toremove;\n debug writeln(\"doing node \", node + 1, \" m0 \", mis0cnt[node], \" m1 \", mis1cnt[node],\n\t\t \" p \", parent[node] + 1);\n if (parent[node] != -1)\n\t{\n\t mis1cnt[parent[node]] += mis1cnt[node];\n\t mis0cnt[parent[node]] += mis0cnt[node];\n\t}\n }\n totalCost.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = new long[](n);\n\tauto b = new long[](n);\n\tauto c = new long[](n);\n\tforeach (i; 0..n)\n\t{\n\t\ta[i] = RD;\n\t\tb[i] = RD;\n\t\tc[i] = RD;\n\t}\n\tauto edges = new int[][](n);\n\tforeach (i; 0..n-1)\n\t{\n\t\tauto u = RD!int-1;\n\t\tauto v = RD!int-1;\n\t\tedges[u] ~= v;\n\t\tedges[v] ~= u;\n\t}\n\n\tauto d = new long[](n);\n\tauto cnt = new long[](n);\n\tauto par = new int[](n);\n\t\n\tlong[] dfs(int pos, int last)\n\t{\n\t\tpar[pos] = last;\n\t\td[pos] = c[pos] - b[pos];\n\t\tcnt[pos] = b[pos] == c[pos] ? 0 : 1;\n\t\tforeach (to; edges[pos])\n\t\t{\n\t\t\tif (to == last) continue;\n\t\t\tauto r = dfs(to, pos);\n\t\t\td[pos] += r[0];\n\t\t\tcnt[pos] += r[1];\n\t\t}\n\t\treturn [d[pos], cnt[pos]];\n\t}\n\tdfs(0, -1);\n\n\tif (d[0] != 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tlong ans;\n\t\tauto index = a.MAKE_IDX();\n\t\tforeach (i; index)\n\t\t{\n\t\t\tauto x = min(cnt[i] - abs(d[i]), cnt[0]);\n\t\t\tcnt[i] -= x;\n\t\t\tans += x * a[i];\n\t\t\tif (cnt[0] == 0)\n\t\t\t\tbreak;\n\t\t\tauto p = par[i];\n\t\t\twhile (p != -1)\n\t\t\t{\n\t\t\t\tcnt[p] -= x;\n\t\t\t\tp = par[p];\n\t\t\t}\n\t\t}\n\t\twriteln(ans);\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "4dce15ff1446b5af2c5b49ee2d30bbb8"} {"source_code": "module main;\n__gshared:\nimport core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,\n\tstd.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\nalias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nenum mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt gcd(BigInt a, BigInt b)\n\t\t{\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (!(a[m] < g))\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (!(a[l] < g)) ? l : r;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (g < a[m])\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (g < a[l]) ? l : r;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn binf(a, g) != a.length;\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treturn s == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treadln;\n\t\treturn s == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tfreopen(\"input.txt\", \"r\", core.stdc.stdio.stdin);\n\t\t//freopen(\"output.txt\", \"w\", core.stdc.stdio.stdout);\n\t}\n\tint n;\n\tloop: while (read(n))\n\t{\n\t\tauto a = arread!int;\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\tx /= 100;\n\t\t}\n\t\tauto dp = new int[][n];\n\t\tdp[0] = new int[31];\n\t\tdp[0][] = int.max;\n\t\tdp[0][a[0] / 10] = a[0];\n\t\tforeach (int i; 1 .. n)\n\t\t{\n\t\t\tdp[i] = new int[31];\n\t\t\tdp[i][] = int.max;\n\t\t\tforeach (int j; 0 .. 31)\n\t\t\t{\n\t\t\t\tif (dp[i - 1][j] != int.max)\n\t\t\t\t{\n\t\t\t\t\tif (j + a[i] / 10 <= 30)\n\t\t\t\t\t\tdp[i][j + a[i] / 10] = min(dp[i][j + a[i] / 10], dp[i - 1][j] + a[i]);\n\t\t\t\t\tdp[i][max(0, j - a[i])] = min(dp[i][max(0, j - a[i])],\n\t\t\t\t\t\t\tdp[i - 1][j] + max(0, a[i] - j));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln(fold!(min)(dp[n - 1]) * 100);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt() / 1000;\n }\n \n auto ASum = new int[N + 1];\n foreach (i; 0 .. N) {\n ASum[i + 1] = ASum[i] + A[i];\n }\n \n int ans;\n foreach (i; 0 .. N + 1) {\n chmax(ans, min(ASum[i], 10 * (ASum[N] - ASum[i])));\n }\n \n /*\n |1 \n 22|22\n */\n foreach (i; 0 .. N) {\n if (A[i] == 1) {\n int j;\n for (j = i + 1; j < N && A[j] == 2; ++j) {}\n const s = j - (i + 1);\n foreach (t; 0 .. s + 1) {\n const a = min(ASum[i], 10);\n const score = a + min(ASum[i] - a + 2 * t, 20 * (s - t) + 10 * (ASum[N] - ASum[j]));\n chmax(ans, score);\n }\n }\n }\n /*\n 1|\n 22|22 \n */\n foreach (i; 0 .. N) {\n if (A[i] == 1) {\n int j;\n for (j = i; j > 0 && A[j - 1] == 2; --j) {}\n debug {\n writeln(\"! \", j, \" \", i);\n }\n const s = i - j;\n foreach (t; 0 .. s + 1) {\n const a = min(ASum[j] + 2 * t, 20 * (s - t));\n const score = a + min((ASum[j] + 2 * t) - a + 1, 10 * (ASum[N] - ASum[i + 1]));\n debug {\n writeln(\" \", t, \": \", score);\n }\n chmax(ans, score);\n }\n }\n }\n \n debug {\n writeln(\"ans = \", ans);\n }\n writeln(1000L * ASum[N] - 100L * ans);\n \n debug {\n auto dp = new int[][](N + 1, 2 * N + 1);\n foreach (i; 0 .. N + 1) {\n dp[i][] = -1;\n }\n dp[0][0] = 0;\n foreach (i; 0 .. N) {\n foreach (j; 0 .. 2 * N + 1) {\n if (dp[i][j] >= 0) {\n // chmax(dp[i + 1][j + A[i]], dp[i][j] + A[i]);\n foreach (dj; 1 .. A[i] + 1) {\n chmax(dp[i + 1][j + dj], dp[i][j] + dj);\n }\n chmax(dp[i + 1][max(j - 10 * A[i], 0)], dp[i][j]);\n }\n }\n }\n foreach (i; 0 .. N + 1) {\n writeln(i, \": \", dp[i]);\n }\n assert(dp[N][0] == ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt() / 1000;\n }\n \n auto ASum = new int[N + 1];\n foreach (i; 0 .. N) {\n ASum[i + 1] = ASum[i] + A[i];\n }\n \n int ans;\n foreach (i; 0 .. N + 1) {\n chmax(ans, min(ASum[i], 10 * (ASum[N] - ASum[i])));\n }\n \n /*\n |1 \n 22|22\n */\n foreach (i; 0 .. N) {\n if (A[i] == 1) {\n int j;\n for (j = i + 1; j < N && A[j] == 2; ++j) {}\n const s = j - (i + 1);\n foreach (t; 0 .. 2 * s) {\n const a = min(ASum[i], 10);\n const score = a + min(ASum[i] - a + 2 * t, 20 * (s - t) + 10 * (ASum[N] - ASum[j]));\n chmax(ans, score);\n }\n }\n }\n /*\n 1|\n 22|22 \n */\n foreach (i; 0 .. N) {\n if (A[i] == 1) {\n int j;\n for (j = i; j > 0 && A[j - 1] == 2; --j) {}\n const s = j - i;\n foreach (t; 0 .. 2 * s) {\n const a = min(ASum[j] + 2 * t, 20 * (s - t));\n const score = min((ASum[j] + 2 * t) - a + 1, 10 * (ASum[N] - ASum[i + 1]));\n chmax(ans, score);\n }\n }\n }\n \n debug {\n writeln(\"ans = \", ans);\n }\n writeln(1000L * ASum[N] - 100L * ans);\n \n debug {\n auto dp = new int[][](N + 1, 2 * N + 1);\n foreach (i; 0 .. N + 1) {\n dp[i][] = -1;\n }\n dp[0][0] = 0;\n foreach (i; 0 .. N) {\n foreach (j; 0 .. 2 * N + 1) {\n if (dp[i][j] >= 0) {\n // chmax(dp[i + 1][j + A[i]], dp[i][j] + A[i]);\n foreach (dj; 1 .. A[i] + 1) {\n chmax(dp[i + 1][j + dj], dp[i][j] + dj);\n }\n chmax(dp[i + 1][max(j - 10 * A[i], 0)], dp[i][j]);\n }\n }\n }\n foreach (i; 0 .. N + 1) {\n writeln(i, \": \", dp[i]);\n }\n assert(dp[N][0] == ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt() / 1000;\n }\n \n auto ASum = new int[N + 1];\n foreach (i; 0 .. N) {\n ASum[i + 1] = ASum[i] + A[i];\n }\n \n int ans;\n foreach (i; 0 .. N + 1) {\n chmax(ans, min(ASum[i], 10 * (ASum[N] - ASum[i])));\n }\n \n /*\n |1 \n 22|22\n */\n foreach (i; 0 .. N) {\n if (A[i] == 1) {\n int j;\n for (j = i + 1; j < N && A[j] == 2; ++j) {}\n const s = j - (i + 1);\n foreach (t; 0 .. 2 * s) {\n const a = min(ASum[i], 10);\n const score = a + min(ASum[i] - a + 2 * t, 20 * (s - t) + 10 * (ASum[N] - ASum[j]));\n chmax(ans, score);\n }\n }\n }\n /*\n 1|\n 22|22 \n */\n foreach (i; 0 .. N) {\n if (A[i] == 1) {\n int j;\n for (j = i; j > 0 && A[j - 1] == 2; --j) {}\n const s = i - j;\n foreach (t; 0 .. 2 * s) {\n const a = min(ASum[j] + 2 * t, 20 * (s - t));\n const score = min((ASum[j] + 2 * t) - a + 1, 10 * (ASum[N] - ASum[i + 1]));\n chmax(ans, score);\n }\n }\n }\n \n debug {\n writeln(\"ans = \", ans);\n }\n writeln(1000L * ASum[N] - 100L * ans);\n \n debug {\n auto dp = new int[][](N + 1, 2 * N + 1);\n foreach (i; 0 .. N + 1) {\n dp[i][] = -1;\n }\n dp[0][0] = 0;\n foreach (i; 0 .. N) {\n foreach (j; 0 .. 2 * N + 1) {\n if (dp[i][j] >= 0) {\n // chmax(dp[i + 1][j + A[i]], dp[i][j] + A[i]);\n foreach (dj; 1 .. A[i] + 1) {\n chmax(dp[i + 1][j + dj], dp[i][j] + dj);\n }\n chmax(dp[i + 1][max(j - 10 * A[i], 0)], dp[i][j]);\n }\n }\n }\n foreach (i; 0 .. N + 1) {\n writeln(i, \": \", dp[i]);\n }\n assert(dp[N][0] == ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt() / 1000;\n }\n \n auto ASum = new int[N + 1];\n foreach (i; 0 .. N) {\n ASum[i + 1] = ASum[i] + A[i];\n }\n \n int ans;\n foreach (i; 0 .. N + 1) {\n chmax(ans, min(ASum[i], 10 * (ASum[N] - ASum[i])));\n }\n \n /*\n |1 \n 22|22\n */\n foreach (i; 0 .. N) {\n if (A[i] == 1) {\n int j;\n for (j = i + 1; j < N && A[j] == 2; ++j) {}\n const s = j - (i + 1);\n foreach (t; 0 .. 2 * s) {\n const a = min(ASum[i], 10);\n const score = a + min(ASum[i] - a + 2 * t, 20 * (s - t) + 10 * (ASum[N] - ASum[j]));\n chmax(ans, score);\n }\n }\n }\n /*\n 1|\n 22|22 \n */\n foreach (i; 0 .. N) {\n if (A[i] == 1) {\n int j;\n for (j = i; j > 0 && A[j - 1] == 2; --j) {}\n const s = j - (i + 1);\n foreach (t; 0 .. 2 * s) {\n const a = min(ASum[j] + 2 * t, 20 * (s - t));\n const score = min((ASum[j] + 2 * t) - a + 1, 10 * (ASum[N] - ASum[i + 1]));\n chmax(ans, score);\n }\n }\n }\n \n debug {\n writeln(\"ans = \", ans);\n }\n writeln(1000L * ASum[N] - 100L * ans);\n \n debug {\n auto dp = new int[][](N + 1, 2 * N + 1);\n foreach (i; 0 .. N + 1) {\n dp[i][] = -1;\n }\n dp[0][0] = 0;\n foreach (i; 0 .. N) {\n foreach (j; 0 .. 2 * N + 1) {\n if (dp[i][j] >= 0) {\n // chmax(dp[i + 1][j + A[i]], dp[i][j] + A[i]);\n foreach (dj; 1 .. A[i] + 1) {\n chmax(dp[i + 1][j + dj], dp[i][j] + dj);\n }\n chmax(dp[i + 1][max(j - 10 * A[i], 0)], dp[i][j]);\n }\n }\n }\n foreach (i; 0 .. N + 1) {\n writeln(i, \": \", dp[i]);\n }\n assert(dp[N][0] == ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "381869cc46a94eea3eac105de4bbac47"} {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nalias Spell1 = Tuple!(int, `manacost`, int, `newTime`);\nalias Spell2 = Tuple!(int, `manacost`, int, `handicap`);\n\nint n, m, k;\nint baseTime, manapool;\nSpell1[200_000] _spells1;\nSpell2[200_000] _spells2;\nSpell1[ ] spells1;\nSpell2[ ] spells2;\nint[200_000] _maxHandicap;\nint[ ] maxHandicap;\n\nlong check(int mana, int time) {\n int left = 0, right = k;\n while (left != right) {\n int mid = (left + right) >>> 1;\n if (mana < spells2[mid].manacost)\n right = mid;\n else\n left = mid + 1;\n }\n return (left? n - maxHandicap[left - 1] : n) * cast(long)time;\n}\n\nvoid main() {\n while (read(&n, &m, &k, &baseTime, &manapool)) {\n spells1 = _spells1[0 .. m];\n spells2 = _spells2[0 .. k];\n maxHandicap = _maxHandicap[0 .. k];\n foreach (ref sp; spells1)\n read(&sp.newTime);\n foreach (ref sp; spells1)\n read(&sp.manacost);\n foreach (ref sp; spells2)\n read(&sp.handicap);\n foreach (ref sp; spells2)\n read(&sp.manacost);\n int t = 0;\n foreach (ref sp, ref b; lockstep(spells2, maxHandicap))\n b = t = max(t, sp.handicap);\n long result = check(manapool, baseTime);\n foreach (ref sp; spells1)\n if (sp.manacost <= manapool)\n result = min(result, check(manapool - sp.manacost, sp.newTime));\n writeln(result);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nstruct spell {\n int pnt;\n int eff;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, m, k;\n readf(\" %s %s %s\\n\", &n, &m, &k);\n int x, s;\n readf(\" %s %s\\n\", &x, &s);\n spell[] t1 = new spell[m+1];\n spell[] t2 = new spell[k+1];\n t1[0].pnt = 0;\n t1[0].eff = x;\n t2[0].pnt = 0;\n t2[0].eff = 0;\n foreach ( i; 1 .. m+1 ) {\n readf(\" %s\", &t1[i].eff);\n }\n readf(\"\\n\");\n foreach ( i; 1 .. m+1 ) {\n readf(\" %s\", &t1[i].pnt);\n }\n foreach ( i; 1 .. k+1 ) {\n readf(\" %s\", &t2[i].eff);\n }\n readf(\"\\n\");\n foreach ( i; 1 .. k+1 ) {\n readf(\" %s\", &t2[i].pnt);\n }\n readf(\"\\n\");\n\n long answer = long.max;\n int pntsAvail = s;\n long poTime = x;\n spell dummySpell;\n auto t2as = assumeSorted!\"a.pnt < b.pnt\"(t2);\n foreach ( s1; t1 ) {\n pntsAvail = s - s1.pnt;\n if (pntsAvail < 0) continue;\n poTime = s1.eff;\n dummySpell.pnt = pntsAvail;\n auto idx = k - t2as.upperBound(dummySpell).length;\n long toMake = max(0, n - t2[idx].eff);\n answer = min(answer, toMake * poTime);\n }\n writeln(answer);\n\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nstruct spell {\n int pnt;\n int eff;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, m, k;\n readf(\" %s %s %s\\n\", &n, &m, &k);\n int x, s;\n readf(\" %s %s\\n\", &x, &s);\n spell[] t1 = new spell[m+1];\n spell[] t2 = new spell[k+1];\n t1[0].pnt = 0;\n t1[0].eff = x;\n t2[0].pnt = 0;\n t2[0].eff = 0;\n foreach ( i; 1 .. m+1 ) {\n readf(\" %s\", &t1[i].eff);\n }\n readf(\"\\n\");\n foreach ( i; 1 .. m+1 ) {\n readf(\" %s\", &t1[i].pnt);\n }\n foreach ( i; 1 .. k+1 ) {\n readf(\" %s\", &t2[i].eff);\n }\n readf(\"\\n\");\n foreach ( i; 1 .. k+1 ) {\n readf(\" %s\", &t2[i].pnt);\n }\n readf(\"\\n\");\n\n long answer = long.max;\n int pntsAvail = s;\n long poTime = x;\n spell dummySpell;\n auto t2as = assumeSorted!\"a.pnt < b.pnt\"(t2);\n foreach ( s1; t1 ) {\n pntsAvail = s - s1.pnt;\n if (pntsAvail < 0) continue;\n poTime = s1.eff;\n dummySpell.pnt = pntsAvail;\n auto idx = t2as.lowerBound(dummySpell).length;\n while (idx < t2.length && t2[idx].pnt <= pntsAvail) ++idx;\n if (idx > 0) --idx;\n long toMake = max(0, n - t2[idx].eff);\n answer = min(answer, toMake * poTime);\n }\n writeln(answer);\n\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nstruct spell {\n int pnt;\n int eff;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, m, k;\n readf(\" %s %s %s\\n\", &n, &m, &k);\n int x, s;\n readf(\" %s %s\\n\", &x, &s);\n spell[] t1 = new spell[m+1];\n spell[] t2 = new spell[k+1];\n t1[0].pnt = 0;\n t1[0].eff = x;\n t2[0].pnt = 0;\n t2[0].eff = 0;\n foreach ( i; 1 .. m+1 ) {\n readf(\" %s\", &t1[i].eff);\n }\n readf(\"\\n\");\n foreach ( i; 1 .. m+1 ) {\n readf(\" %s\", &t1[i].pnt);\n }\n foreach ( i; 1 .. k+1 ) {\n readf(\" %s\", &t2[i].eff);\n }\n readf(\"\\n\");\n foreach ( i; 1 .. k+1 ) {\n readf(\" %s\", &t2[i].pnt);\n }\n readf(\"\\n\");\n\n long answer = long.max;\n int pntsAvail = s;\n long poTime = x;\n foreach ( s1; t1 ) {\n pntsAvail = s - s1.pnt;\n if (pntsAvail < 0) continue;\n poTime = s1.eff;\n int lo = 0, hi = k;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (pntsAvail < t2[mid].pnt) hi = mid;\n else lo = mid + 1;\n }\n if (pntsAvail < t2[lo].pnt) --lo;\n long toMake = max(0, n - t2[lo].eff);\n answer = min(answer, toMake * poTime);\n }\n writeln(answer);\n\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nstruct spell {\n int pnt;\n int eff;\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, m, k;\n readf(\" %s %s %s\\n\", &n, &m, &k);\n int x, s;\n readf(\" %s %s\\n\", &x, &s);\n spell[] t1 = new spell[m+1];\n spell[] t2 = new spell[k+1];\n t1[0].pnt = 0;\n t1[0].eff = x;\n t2[0].pnt = 0;\n t2[0].eff = 0;\n foreach ( i; 1 .. m+1 ) {\n readf(\" %s\", &t1[i].eff);\n }\n readf(\"\\n\");\n foreach ( i; 1 .. m+1 ) {\n readf(\" %s\", &t1[i].pnt);\n }\n foreach ( i; 1 .. k+1 ) {\n readf(\" %s\", &t2[i].eff);\n }\n readf(\"\\n\");\n foreach ( i; 1 .. k+1 ) {\n readf(\" %s\", &t2[i].pnt);\n }\n readf(\"\\n\");\n\n int answer = int.max;\n int pntsAvail = s;\n int poTime = x;\n spell dummySpell;\n auto t2as = assumeSorted!\"a.pnt < b.pnt\"(t2);\n foreach ( s1; t1 ) {\n pntsAvail = s - s1.pnt;\n if (pntsAvail < 0) continue;\n poTime = s1.eff;\n dummySpell.pnt = pntsAvail;\n auto idx = t2as.lowerBound(dummySpell).length;\n while (idx < t2.length && t2[idx].pnt <= pntsAvail) ++idx;\n if (idx > 0) --idx;\n int toMake = max(0, n - t2[idx].eff);\n answer = min(answer, toMake * poTime);\n }\n writeln(answer);\n\n return 0;\n}"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Spell1 {\n int manacost, newTime;\n}\n\nstruct Spell2 {\n int manacost, handicap;\n}\n\nint n, m, k;\nint baseTime, manapool;\nSpell1[200_000] _spells1;\nSpell2[200_000] _spells2;\nSpell1[ ] spells1;\nSpell2[ ] spells2;\nint[200_000] _maxHandicap;\nint[ ] maxHandicap;\n\nlong check(int mana, int time) {\n int left = 0, right = k;\n while (left != right) {\n int mid = (left + right) >>> 1;\n if (mana < spells2[mid].manacost)\n right = mid;\n else\n left = mid + 1;\n }\n return (left? (n - maxHandicap[left - 1]) : n) * cast(long)time;\n}\n\nvoid main() {\n while (read(&n, &m, &k, &baseTime, &manapool)) {\n spells1 = _spells1[0 .. m];\n spells2 = _spells2[0 .. k];\n maxHandicap = _maxHandicap[0 .. m];\n foreach (ref sp; spells1)\n read(&sp.newTime);\n foreach (ref sp; spells1)\n read(&sp.manacost);\n foreach (ref sp; spells2)\n read(&sp.handicap);\n foreach (ref sp; spells2)\n read(&sp.manacost);\n int t = 0;\n foreach (ref sp, ref b; lockstep(spells2, maxHandicap))\n b = t = max(t, sp.handicap);\n long result = check(manapool, baseTime);\n foreach (ref sp; spells1)\n if (sp.manacost <= manapool)\n result = min(result, check(manapool - sp.manacost, sp.newTime));\n writeln(result);\n }\n}\n"}], "src_uid": "2f9f2bdf059e5ab9c64e7b5f27cba0cb"} {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!long;\n\nvoid main() {\n GC.disable();\n\n long n, m;\n readf(\" %s %s\", n, m);\n\n auto b = new long[to!int(n)];\n auto g = new long[to!int(m)];\n\n foreach(i;0 .. n) readf(\" %s\", b[to!int(i)]);\n foreach(i;0 .. m) readf(\" %s\", g[to!int(i)]);\n\n long ans = -1;\n if (b.maxElement > g.minElement) {\n ans = -1;\n } else if (g.minElement > b.maxElement) {\n sort(b);\n long tt = sum(g) + sum(b) * m - b[$-1]*(m-1) - b[$-2];\n ans = tt;\n } else {\n long ss = sum(b);\n long tt = 0;\n auto tree = new Tree(b);\n foreach(gg; g) {\n auto rr = tree.lowerBound(gg+1);\n tt = tt + (ss - rr.back() + gg);\n }\n\n ans = tt;\n\n }\n\n\n writeln(ans);\n\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;\n\nvoid main()\n{\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n auto BS = readln.split.to!(long[]);\n auto GS = readln.split.to!(long[]);\n\n long ret;\n foreach (b; BS) {\n ret += b * M;\n }\n sort!\"a > b\"(BS);\n int c;\n sort!\"a < b\"(GS);\n foreach (g; GS) {\n if (g < BS[0]) {\n writeln(\"-1\");\n return;\n }\n if (g == BS[0]) {\n continue;\n }\n if (c == M-1) {\n ret += g - BS[1];\n } else {\n ++c;\n ret += g - BS[0];\n }\n }\n writeln(ret);\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;\n\nvoid main()\n{\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n auto BS = readln.split.to!(long[]);\n auto GS = readln.split.to!(long[]);\n\n long ret;\n foreach (b; BS) {\n ret += b * M;\n }\n sort!\"a < b\"(BS);\n int[] uc;\n uc.length = N;\n foreach (g; GS) {\n if (g < BS[$-1]) {\n writeln(\"-1\");\n return;\n }\n size_t l, r = N-1;\n while (l+1 != r) {\n auto m = (l+r)/2;\n if (BS[m] <= g) {\n l = m;\n } else {\n r = m;\n }\n }\n if (r <= g) l = r;\n if (l == g) continue;\n if (uc[l] == M-1) {\n if (l == 0) {\n writeln(\"-1\");\n return;\n }\n --l;\n }\n ++uc[l];\n ret += g - BS[l];\n }\n writeln(ret);\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;\n\nvoid main()\n{\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n auto BS = readln.split.to!(long[]);\n auto GS = readln.split.to!(long[]);\n\n long ret;\n foreach (b; BS) {\n ret += b * M;\n }\n sort!\"a > b\"(BS);\n int c;\n sort!\"a < b\"(GS);\n long prev = -1;\n foreach (g; GS) {\n if (g == prev) continue;\n prev = g;\n if (g < BS[0]) {\n writeln(\"-1\");\n return;\n }\n if (g == BS[0]) {\n continue;\n }\n if (c == M-1) {\n ret += g - BS[1];\n } else {\n ++c;\n ret += g - BS[0];\n }\n }\n writeln(ret);\n}"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range : iota, tee;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n int n, m;\n readf(\" %s %s\", n, m);\n\n auto b = new int[n];\n auto g = new int[m];\n\n foreach(i;0 .. n) readf(\" %s\", b[i]);\n foreach(i;0 .. m) readf(\" %s\", g[i]);\n\n int ans = -1;\n if (b.maxElement > g.minElement) {\n ans = -1;\n } else if (g.minElement > b.maxElement) {\n sort(b);\n int tt = sum(g) + sum(b) * m - b[$-1]*(m-1) - b[$-2];\n ans = tt;\n } else {\n int ss = sum(b);\n int tt = 0;\n auto tree = new Tree(b);\n foreach(gg; g) {\n auto rr = tree.lowerBound(gg+1);\n tt = tt + (ss - rr.back() + gg);\n }\n\n ans = tt;\n\n }\n\n\n writeln(ans);\n\n}\n"}], "src_uid": "4b4c7e7d9d5c45c8635b403bae997891"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).map!(x => x-1).array;\n \n auto g = new int[][] (n);\n foreach (_; 0 .. m) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n \n --u, --v;\n g[v] ~= u;\n }\n \n auto cnt = new int[] (n);\n foreach (u; g[arr.back]) { cnt[u] += 1; }\n \n int ans = 0, needToBypass = 1;\n foreach_reverse (e; arr.dropBackOne) {\n debug { writeln(e, ' ', cnt[e], ' ', needToBypass); }\n \n if (cnt[e] == needToBypass) { ++ans; }\n else { \n ++needToBypass;\n foreach (u; g[e]) { ++cnt[u]; }\n }\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable int n = r.next!uint;\n immutable int m = r.next!uint;\n auto p = uninitializedArray!(int[]) (n);\n auto pos = uninitializedArray!(int[]) (n + 1);\n foreach (i; 0 .. n) {\n p[i] = r.next!uint;\n pos[p[i]] = i;\n }\n auto e = new int[][n+1];\n foreach (edgeid; 0 .. m) {\n immutable i = r.next!uint;\n immutable j = r.next!uint;\n e[i] ~= j;\n }\n debug stderr.writeln (e);\n int res;\n auto d = new bool[n+1];\n int l = 1;\n foreach_reverse (i; 0 .. n - 1) {\n int cnt;\n immutable pi = p[i];\n immutable pk = pos[pi];\n foreach (j; e[pi]) {\n if (!d[j] && pk < pos[j]) ++cnt;\n }\n debug stderr.writeln (cnt, ' ', l);\n if (cnt == l) {\n ++res;\n d[pi] = true;\n } else {\n ++l;\n }\n }\n write (res);\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nclass InputReader {\n private:\n ubyte[] p;\n ubyte[] buffer;\n size_t cur;\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n p = stdin.rawRead (buffer);\n }\n final ubyte skipByte (ubyte lo) {\n while (true) {\n auto a = p[cur .. $];\n auto r = a.find! (c => c >= lo);\n if (!r.empty) {\n cur += a.length - r.length;\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n cur = 0;\n if (p.empty) return 0;\n }\n }\n final ubyte nextByte () {\n if (cur < p.length) {\n return p[cur++];\n }\n p = stdin.rawRead (buffer);\n if (p.empty) return 0;\n cur = 1;\n return p[0];\n }\n template next(T) if (isUnsigned!T) {\n final T next () {\n T res = skipByte (48) - 48;\n while (true) {\n ubyte b = nextByte ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable int n = r.next!uint;\n immutable int m = r.next!uint;\n auto p = uninitializedArray!(int[]) (n);\n auto pos = uninitializedArray!(int[]) (n + 1);\n foreach (i; 0 .. n) {\n p[i] = r.next!uint;\n pos[p[i]] = i;\n }\n auto c = new int[n+1];\n foreach (edge_id; 0 .. m) {\n immutable i = r.next!uint;\n immutable j = r.next!uint;\n if (pos[i] < pos[j]) ++c[i];\n }\n int res;\n debug stderr.writeln (c[1..$]);\n foreach_reverse (i; 0 .. n - 1) {\n debug stderr.writeln (c[p[i]], ' ', n - i - 1);\n if (c[p[i]] == n - i - 1) ++res; \n }\n write (res);\n}\n"}], "src_uid": "1716b35de299e88c891ba71f9c368b51"} {"source_code": "// problem: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A\n// require: graph/articulation_points.d\n\nimport std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\n//LRDU\n\nbool solve2(int a, int b, int x1, int x2) {\n if (x1 == 0 && x2 == 0) {\n return a == 0 && b == 0;\n } else if (a == b) {\n return true;\n } else if (a > b) {\n return abs(x1) >= a - b;\n } else {\n return abs(x2) >= b - a;\n }\n}\n\nvoid solve(int T) {\n while (T--) {\n auto s = readln.split.map!(to!int);\n auto A = s[0];\n auto B = s[1];\n auto C = s[2];\n auto D = s[3];\n s = readln.split.map!(to!int);\n auto X = s[0];\n auto Y = s[1];\n auto x1 = s[2] - X;\n auto y1 = s[3] - Y;\n auto x2 = s[4] - X;\n auto y2 = s[5] - Y;\n auto AB = A - B;\n auto ans = solve2(A, B, x1, x2) && solve2(C, D, y1, y2);\n writeln(ans ? \"Yes\" : \"No\");\n }\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n solve(T);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto abcd = RDA;\n\t\tauto x = RD;\n\t\tauto y = RD;\n\t\tauto x1 = RD;\n\t\tauto y1 = RD;\n\t\tauto x2 = RD;\n\t\tauto y2 = RD;\n\t\t\n\t\tbool check(long pos, long l, long r, long dl, long dr)\n\t\t{\n\t\t\tauto d = dr - dl;\n\t\t\tif (!inside(pos+d, l, r+1)) return false;\n\t\t\tif (dl != 0 || dr != 0)\n\t\t\t{\n\t\t\t\tif (pos == l && pos == r) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tans[ti] = check(x, x1, x2, abcd[0], abcd[1]) && check(y, y1, y2, abcd[2], abcd[3]);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "7224ffd4776af4129739e1b28f696050"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n, t;\n\twhile (readf (\" %s %s\", &n, &t) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip.dup;\n\t\tint i = 0;\n\t\twhile (s[i] != '.')\n\t\t{\n\t\t\ti += 1;\n\t\t}\n\t\tint pre = i;\n\t\ts = s[0..i] ~ s[i + 1..$];\n\t\tn -= 1;\n\t\twhile (i < n)\n\t\t{\n\t\t\tif (s[i] >= '5')\n\t\t\t{\n\t\t\t\tint j = i - 1;\n\t\t\t\twhile (j >= pre && i - j < t && s[j] >= '4')\n\t\t\t\t{\n\t\t\t\t\tj -= 1;\n\t\t\t\t}\n\t\t\t\twhile (j > 0 && s[j] == '9')\n\t\t\t\t{\n\t\t\t\t\ts[j] = '0';\n\t\t\t\t\tj -= 1;\n\t\t\t\t}\n\t\t\t\tif (s[j] == '9')\n\t\t\t\t{\n\t\t\t\t\ts[j] = '0';\n\t\t\t\t\ts = s[0..j + 1];\n\t\t\t\t\ts = '1' ~ s;\n\t\t\t\t\tpre += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ts[j] += 1;\n\t\t\t\t\ts = s[0..j + 1];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ti += 1;\n\t\t}\n\t\twhile (s.length < pre)\n\t\t{\n\t\t\ts ~= '0';\n\t\t}\n\t\twhile (s.length > pre && s[$ - 1] == '0')\n\t\t{\n\t\t\ts.length -= 1;\n\t\t}\n\t\tif (s.length > pre)\n\t\t{\n\t\t\ts = s[0..pre] ~ '.' ~ s[pre..$];\n\t\t}\n\t\twriteln (s);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.range;\n\n/// custom bigint\nstruct BigInt {\n ///value\n int[] value = [0];\n ///init\n this(string s) {\n value = [];\n foreach(char sym; s) {\n value ~= sym - '0';\n }\n }\n ///to_string\n string to_string() {\n string s = \"\";\n foreach(int sym; value) {\n s ~= sym.to!string();\n }\n return s;\n }\n ///plus_one\n void plus_one() {\n value[$ - 1] += 1;\n foreach_reverse(int idx; 1 .. value.length) {\n if (value[idx] == 10) {\n value[idx] = 0;\n value[idx - 1] += 1;\n }\n }\n if (value[0] == 10) {\n value[0] = 0;\n value = [1] ~ value;\n }\n }\n}\nunittest {\n BigInt b;\n foreach(int i; 0 .. 10) {\n b.plus_one();\n assert(b.value == [i + 1]);\n assert(b.to_string() == (i + 1).to!string());\n }\n //from_string\n b = BigInt(\"1234567890\");\n assert(b.value == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);\n //to_string\n assert(b.to_string() == \"1234567890\");\n\n // plus_one\n foreach(int i; 0 .. 100) {\n b.plus_one();\n int curr_val = 1_234_567_890 + i + 1;\n BigInt c = BigInt(curr_val.to!string());\n assert(b.value == c.value);\n }\n}\n\n///solve\nvoid solve() {\n int n, t;\n readf(\" %s %s\\n\", &n, &t);\n auto grade = split(readln().strip(), '.');\n int len = n - 1 - grade[0].length;\n BigInt base = BigInt(grade[0]);\n debug {\n len.writeln();\n grade.writeln();\n writeln(base.value);\n }\n int[] tail;\n foreach(int idx; 0 .. len) {\n tail ~= grade[1][idx] - '0';\n }\n // tail.writeln();\n len = tail.length;\n int replaces = 0;\n foreach(int idx; 0 .. len) {\n if (tail[idx] > 4) {\n if (idx == 0) {\n base.plus_one();\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n replaces++;\n break;\n }\n }\n }\n while (true) {\n bool flag = false;\n if (replaces >= t) {\n break;\n }\n foreach_reverse(int idx; 0 .. len) {\n debug writeln(idx);\n if (tail[idx] > 4) {\n if (idx == 0) {\n base.plus_one();\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n flag = true;\n replaces++;\n break;\n }\n }\n }\n if (!flag) {\n break;\n }\n }\n string ans = \"\";\n write(base.to_string());\n if (len > 0) {\n ans ~= '.';\n }\n foreach(int x; 0 .. len) {\n ans ~= tail[x].to!string;\n }\n writeln(ans);\n}\nvoid main() {\n debug {\n char[200_000] x = '9';\n string a = x.dup;\n BigInt b = BigInt(a);\n \"b\".writeln();\n b.plus_one();\n \"b + 1\".writeln;\n }\n\n solve();\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.bigint;\nimport std.range;\n\n\n\n///solve\nvoid solve() {\n int n, t;\n readf(\" %s %s\\n\", &n, &t);\n auto grade = split(readln().strip(), '.');\n int len = n - 1 - grade[0].length;\n BigInt base = grade[0].to!BigInt;\n debug {\n len.writeln();\n grade.writeln();\n base.writeln();\n }\n int[] tail;\n foreach(int idx; 0 .. len) {\n tail ~= grade[1][idx] - '0';\n }\n // tail.writeln();\n len = tail.length;\n int replaces = 0;\n foreach(int idx; 0 .. len) {\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n replaces++;\n break;\n }\n }\n }\n if (n == 200_000) {\n return;\n }\n while (true) {\n bool flag = false;\n if (replaces >= t) {\n break;\n }\n foreach_reverse(int idx; 0 .. len) {\n debug writeln(idx);\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n flag = true;\n replaces++;\n break;\n }\n }\n }\n if (!flag) {\n break;\n }\n }\n write(base);\n if (len > 0) {\n write('.');\n }\n foreach(int x; 0 .. len) {\n write(tail[x]);\n }\n writeln();\n}\nvoid main() {\n debug {\n char[200_000] x = '9';\n string a = x.dup;\n BigInt b = a.to!BigInt;\n \"b\".writeln();\n b += 1;\n \"b + 1\".writeln;\n }\n\n solve();\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.bigint;\nimport std.range;\n\n\n\n///solve\nvoid solve() {\n int n, t;\n readf(\" %s %s\\n\", &n, &t);\n auto grade = split(readln().strip(), '.');\n int len = n - 1 - grade[0].length;\n BigInt base = grade[0].to!BigInt;\n debug {\n len.writeln();\n grade.writeln();\n base.writeln();\n }\n int[] tail;\n foreach(int idx; 0 .. len) {\n tail ~= grade[1][idx] - '0';\n }\n // tail.writeln();\n len = tail.length;\n int replaces = 0;\n foreach(int idx; 0 .. len) {\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n replaces++;\n break;\n }\n }\n }\n while (true) {\n bool flag = false;\n if (replaces >= t) {\n break;\n }\n foreach_reverse(int idx; 0 .. len) {\n debug writeln(idx);\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n flag = true;\n replaces++;\n break;\n }\n }\n }\n if (!flag) {\n break;\n }\n }\n if (n == 200_000) {\n return;\n }\n string ans = base.to!string;\n if (len > 0) {\n ans ~= '.';\n }\n foreach(int x; 0 .. len) {\n ans ~= tail[x].to!string;\n }\n writeln(ans);\n}\nvoid main() {\n debug {\n char[200_000] x = '9';\n string a = x.dup;\n BigInt b = a.to!BigInt;\n \"b\".writeln();\n b += 1;\n \"b + 1\".writeln;\n }\n\n solve();\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.bigint;\nimport std.range;\n\n\n\n///solve\nvoid solve() {\n int n, t;\n readf(\" %s %s\\n\", &n, &t);\n auto grade = split(readln().strip(), '.');\n int len = n - 1 - grade[0].length;\n BigInt base = grade[0].to!BigInt;\n len.writeln();\n grade.writeln();\n base.writeln();\n int[] tail;\n foreach(int idx; 0 .. len) {\n tail ~= grade[1][idx] - '0';\n }\n // tail.writeln();\n len = tail.length;\n int replaces = 0;\n foreach(int idx; 0 .. len) {\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n replaces++;\n break;\n }\n }\n }\n if (n == 200_000) {\n return;\n }\n while (true) {\n bool flag = false;\n if (replaces >= t) {\n break;\n }\n foreach_reverse(int idx; 0 .. len) {\n debug writeln(idx);\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n flag = true;\n replaces++;\n break;\n }\n }\n }\n if (!flag) {\n break;\n }\n }\n write(base);\n if (len > 0) {\n write('.');\n }\n foreach(int x; 0 .. len) {\n write(tail[x]);\n }\n writeln();\n}\nvoid main() {\n debug {\n char[200_000] x = '9';\n string a = x.dup;\n BigInt b = a.to!BigInt;\n \"b\".writeln();\n b += 1;\n \"b + 1\".writeln;\n }\n\n solve();\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.bigint;\nimport std.range;\n\n\n\n///solve\nvoid solve() {\n int n, t;\n readf(\" %s %s\\n\", &n, &t);\n auto grade = split(readln().strip(), '.');\n int len = n - 1 - grade[0].length;\n BigInt base = grade[0].to!BigInt;\n debug {\n len.writeln();\n grade.writeln();\n base.writeln();\n }\n int[] tail;\n foreach(int idx; 0 .. len) {\n tail ~= grade[1][idx] - '0';\n }\n // tail.writeln();\n len = tail.length;\n int replaces = 0;\n foreach(int idx; 0 .. len) {\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n replaces++;\n break;\n }\n }\n }\n while (true) {\n bool flag = false;\n if (replaces >= t) {\n break;\n }\n foreach_reverse(int idx; 0 .. len) {\n debug writeln(idx);\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n flag = true;\n replaces++;\n break;\n }\n }\n }\n if (!flag) {\n break;\n }\n }\n if (n == 200_000) {\n return;\n }\n write(base);\n if (len > 0) {\n write('.');\n }\n foreach(int x; 0 .. len) {\n write(tail[x]);\n }\n writeln();\n}\nvoid main() {\n debug {\n char[200_000] x = '9';\n string a = x.dup;\n BigInt b = a.to!BigInt;\n \"b\".writeln();\n b += 1;\n \"b + 1\".writeln;\n }\n\n solve();\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.bigint;\nimport std.range;\n\n\n\n///solve\nvoid solve() {\n int n, t;\n readf(\" %s %s\\n\", &n, &t);\n auto grade = split(readln().strip(), '.');\n int len = n - 1 - grade[0].length;\n BigInt base = grade[0].to!BigInt;\n debug {\n len.writeln();\n grade.writeln();\n base.writeln();\n }\n int[] tail;\n foreach(int idx; 0 .. len) {\n tail ~= grade[1][idx] - '0';\n }\n // tail.writeln();\n len = tail.length;\n int replaces = 0;\n foreach(int idx; 0 .. len) {\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n replaces++;\n break;\n }\n }\n }\n while (true) {\n bool flag = false;\n if (replaces >= t) {\n break;\n }\n foreach_reverse(int idx; 0 .. len) {\n debug writeln(idx);\n if (tail[idx] > 4) {\n if (idx == 0) {\n base += 1;\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n flag = true;\n replaces++;\n break;\n }\n }\n }\n if (!flag) {\n break;\n }\n }\n string ans = base.to!string;\n if (len > 0) {\n ans ~= '.';\n }\n foreach(int x; 0 .. len) {\n ans ~= tail[x];\n }\n writeln(ans);\n}\nvoid main() {\n debug {\n char[200_000] x = '9';\n string a = x.dup;\n BigInt b = a.to!BigInt;\n \"b\".writeln();\n b += 1;\n \"b + 1\".writeln;\n }\n\n solve();\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.range;\n\n/// custom bigint\nstruct BigInt {\n ///value\n int[] value = [0];\n ///init\n this(string s) {\n value = [];\n foreach(char sym; s) {\n value ~= sym - '0';\n }\n }\n ///to_string\n string to_string() {\n string s = \"\";\n foreach(int sym; value) {\n s ~= sym.to!string();\n }\n return s;\n }\n ///plus_one\n void plus_one() {\n value[$ - 1] += 1;\n foreach_reverse(int idx; 1 .. value.length) {\n if (value[idx] == 10) {\n value[idx] = 0;\n value[idx - 1] += 1;\n }\n }\n if (value[0] == 10) {\n value[0] = 0;\n value = [1] ~ value;\n }\n }\n}\nunittest {\n BigInt b;\n foreach(int i; 0 .. 10) {\n b.plus_one();\n assert(b.value == [i + 1]);\n assert(b.to_string() == (i + 1).to!string());\n }\n //from_string\n b = BigInt(\"1234567890\");\n assert(b.value == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);\n //to_string\n assert(b.to_string() == \"1234567890\");\n\n // plus_one\n foreach(int i; 0 .. 100) {\n b.plus_one();\n int curr_val = 1_234_567_890 + i + 1;\n BigInt c = BigInt(curr_val.to!string());\n assert(b.value == c.value);\n }\n}\n\n///solve\nvoid solve() {\n int n, t;\n readf(\" %s %s\\n\", &n, &t);\n auto grade = split(readln().strip(), '.');\n int len = n - 1 - grade[0].length;\n BigInt base = BigInt(grade[0]);\n debug {\n len.writeln();\n grade.writeln();\n writeln(base.value);\n }\n int[] tail;\n foreach(int idx; 0 .. len) {\n tail ~= grade[1][idx] - '0';\n }\n // tail.writeln();\n len = tail.length;\n int replaces = 0;\n foreach(int idx; 0 .. len) {\n if (tail[idx] > 4) {\n if (idx == 0) {\n base.plus_one();\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n replaces++;\n break;\n }\n }\n }\n while (true) {\n bool flag = false;\n if (replaces >= t) {\n break;\n }\n foreach_reverse(int idx; 0 .. len) {\n debug writeln(idx);\n if (tail[idx] > 4) {\n if (idx == 0) {\n base.plus_one();\n len = 0;\n replaces++;\n break;\n }\n else {\n tail[idx - 1] += 1;\n len = idx;\n flag = true;\n replaces++;\n break;\n }\n }\n }\n if (!flag) {\n break;\n }\n }\n string ans = \"\";\n write(base.to_string());\n if (n == 200_000) {\n return;\n }\n if (len > 0) {\n ans ~= '.';\n }\n foreach(int x; 0 .. len) {\n ans ~= tail[x].to!string;\n }\n writeln(ans);\n}\nvoid main() {\n debug {\n char[200_000] x = '9';\n string a = x.dup;\n BigInt b = BigInt(a);\n \"b\".writeln();\n b.plus_one();\n \"b + 1\".writeln;\n }\n\n solve();\n}\n"}], "src_uid": "d563ce32596b54f48544a6085efe5cc5"} {"source_code": "import core.bitop;\nimport std.conv;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int LOG = 17;\nimmutable int MED = 1 << LOG;\nimmutable int MAX = MED << 1;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\talias pair = Tuple !(int, \"p\", int, \"v\");\n\t\tauto q = new pair [m];\n\t\tforeach (ref x; q)\n\t\t{\n\t\t\treadf (\" %s %s\", &x.p, &x.v);\n\t\t}\n\n\t\tauto ans = new long [m];\n\t\tforeach (c; 0..LOG)\n\t\t{\n\t\t\tauto b = new bool [n];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tb[i] = (a[i] >> c) & 1;\n\t\t\t}\n\t\t\tauto r = new pair [m];\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tr[j] = pair (q[j].p, (q[j].v >> c) & 1);\n\t\t\t}\n\t\t\talias node = Tuple !(long, \"s\", int, \"l\", int, \"r\");\n\t\t\tauto t = new node [MAX];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tt[i + MED + 1] = node (0, b[i], b[i]);\n\t\t\t}\n\n\t\t\tvoid recalc (int i, int w)\n\t\t\t{\n\t\t\t\tint m = t[i * 2 + 0].r + t[i * 2 + 1].l;\n\t\t\t\tt[i].l = t[i * 2 + 0].l;\n\t\t\t\tif (t[i].l == w)\n\t\t\t\t{\n\t\t\t\t\tt[i].l += t[i * 2 + 1].l;\n\t\t\t\t\tm = 0;\n\t\t\t\t}\n\t\t\t\tt[i].r = t[i * 2 + 1].r;\n\t\t\t\tif (t[i].r == w)\n\t\t\t\t{\n\t\t\t\t\tt[i].r += t[i * 2 + 0].r;\n\t\t\t\t\tm = 0;\n\t\t\t\t}\n\t\t\t\tt[i].s = t[i * 2 + 0].s + t[i * 2 + 1].s;\n\t\t\t\tt[i].s += (m * to !(long) (m + 1)) >> 1;\n\t\t\t}\n\n\t\t\tforeach_reverse (k; 0..LOG)\n\t\t\t{\n\t\t\t\tforeach (i; 1 << k..1 << (k + 1))\n\t\t\t\t{\n\t\t\t\t\trecalc (i, 1 << (LOG - k - 1));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tint p = r[j].p + MED;\n\t\t\t\tint v = r[j].v;\n\t\t\t\tif (v != t[p].l)\n\t\t\t\t{\n\t\t\t\t\tt[p] = node (0, v, v);\n\t\t\t\t\tint k = 1;\n\t\t\t\t\twhile (p > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tp >>= 1;\n\t\t\t\t\t\trecalc (p, k);\n\t\t\t\t\t\tk <<= 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tans[j] += t[1].s << c;\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%(%s\\n%)\", ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.typecons;\n\nimmutable int LOG = 17;\nimmutable int MED = 1 << LOG;\nimmutable int MAX = MED << 1;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\talias pair = Tuple !(int, \"p\", int, \"v\");\n\t\tauto q = new pair [m];\n\t\tforeach (ref x; q)\n\t\t{\n\t\t\treadf (\" %s %s\", &x.p, &x.v);\n\t\t}\n\n\t\tauto ans = new long [m];\n\t\tforeach (c; 0..LOG)\n\t\t{\n\t\t\talias node = Tuple !(long, \"s\", int, \"l\", int, \"r\");\n\t\t\tauto t = new node [MAX];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tint v = (a[i] >> c) & 1;\n\t\t\t\tt[i + MED + 1] = node (0, v, v);\n\t\t\t}\n\n\t\t\tvoid recalc (int i, int w)\n\t\t\t{\n\t\t\t\tint j = i * 2;\n\t\t\t\tint k = j + 1;\n\t\t\t\tlong m = t[j].r + t[k].l;\n\t\t\t\tt[i].l = t[j].l;\n\t\t\t\tif (t[i].l == w)\n\t\t\t\t{\n\t\t\t\t\tt[i].l += t[k].l;\n\t\t\t\t\tm = 0;\n\t\t\t\t}\n\t\t\t\tt[i].r = t[k].r;\n\t\t\t\tif (t[i].r == w)\n\t\t\t\t{\n\t\t\t\t\tt[i].r += t[j].r;\n\t\t\t\t\tm = 0;\n\t\t\t\t}\n\t\t\t\tt[i].s = t[j].s + t[k].s + (m * (m + 1)) / 2;\n\t\t\t}\n\n\t\t\tforeach_reverse (k; 0..LOG)\n\t\t\t{\n\t\t\t\tforeach (i; 1 << k..1 << (k + 1))\n\t\t\t\t{\n\t\t\t\t\trecalc (i, 1 << (LOG - k - 1));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tint p = q[j].p + MED;\n\t\t\t\tint v = (q[j].v >> c) & 1;\n\t\t\t\tif (v != t[p].l)\n\t\t\t\t{\n\t\t\t\t\tt[p] = node (0, v, v);\n\t\t\t\t\tint k = 1;\n\t\t\t\t\twhile (p > 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tp >>= 1;\n\t\t\t\t\t\trecalc (p, k);\n\t\t\t\t\t\tk <<= 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tans[j] += t[1].s << c;\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%(%s\\n%)\", ans);\n\t}\n}\n"}, {"source_code": "import core.bitop, std.stdio, std.typecons;\n\nimmutable int LOG = 17, MED = 1 << LOG, MAX = MED << 1;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t\treadf (\" %s\", &x);\n\n\t\talias pair = Tuple !(int, \"p\", int, \"v\");\n\t\tauto q = new pair [m];\n\t\tforeach (ref x; q)\n\t\t\treadf (\" %s %s\", &x.p, &x.v);\n\n\t\tauto ans = new long [m];\n\t\tforeach (c; 0..LOG)\n\t\t{\n\t\t\talias node = Tuple !(long, \"s\", int, \"l\", int, \"r\");\n\t\t\tauto t = new node [MAX];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tint v = (a[i] >> c) & 1;\n\t\t\t\tt[i + MED + 1] = node (0, v, v);\n\t\t\t}\n\n\t\t\tvoid recalc (int i)\n\t\t\t{\n\t\t\t\tint j = i * 2;\n\t\t\t\tint k = j + 1;\n\t\t\t\tint w = 1 << (LOG - bsr (i) - 1);\n\t\t\t\tlong m = (t[j].r == w || t[k].l == w) ? 0 :\n\t\t\t\t t[j].r + t[k].l;\n\t\t\t\tt[i].l = (t[j].l == w) ? w + t[k].l : t[j].l;\n\t\t\t\tt[i].r = (t[k].r == w) ? w + t[j].r : t[k].r;\n\t\t\t\tt[i].s = t[j].s + t[k].s + (m * (m + 1)) / 2;\n\t\t\t}\n\n\t\t\tforeach_reverse (i; 1..MED)\n\t\t\t\trecalc (i);\n\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tint p = q[j].p + MED;\n\t\t\t\tint v = (q[j].v >> c) & 1;\n\t\t\t\tif (v != t[p].l)\n\t\t\t\t{\n\t\t\t\t\tt[p] = node (0, v, v);\n\t\t\t\t\tfor (p >>= 1; p > 0; p >>= 1)\n\t\t\t\t\t\trecalc (p);\n\t\t\t\t}\n\t\t\t\tans[j] += t[1].s << c;\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%(%s\\n%)\", ans);\n\t}\n}\n"}, {"source_code": "import core.bitop;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int LOG = 17;\nimmutable int MED = 1 << LOG;\nimmutable int MAX = MED << 1;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\talias pair = Tuple !(int, \"p\", int, \"v\");\n\t\tauto q = new pair [m];\n\t\tforeach (ref x; q)\n\t\t{\n\t\t\treadf (\" %s %s\", &x.p, &x.v);\n\t\t}\n\n\t\tauto ans = new long [m];\n\t\tforeach (c; 0..LOG)\n\t\t{\n\t\t\talias node = Tuple !(long, \"s\", int, \"l\", int, \"r\");\n\t\t\tauto t = new node [MAX];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tint v = (a[i] >> c) & 1;\n\t\t\t\tt[i + MED + 1] = node (0, v, v);\n\t\t\t}\n\n\t\t\tvoid recalc (int i)\n\t\t\t{\n\t\t\t\tint j = i * 2;\n\t\t\t\tint k = j + 1;\n\t\t\t\tint w = 1 << (LOG - bsr (i) - 1);\n\t\t\t\tlong m = (t[j].r == w || t[k].l == w) ? 0 :\n\t\t\t\t t[j].r + t[k].l;\n\t\t\t\tt[i].l = (t[j].l == w) ? w + t[k].l : t[j].l;\n\t\t\t\tt[i].r = (t[k].r == w) ? w + t[j].r : t[k].r;\n\t\t\t\tt[i].s = t[j].s + t[k].s + (m * (m + 1)) / 2;\n\t\t\t}\n\n\t\t\tforeach_reverse (i; 1..MED)\n\t\t\t{\n\t\t\t\trecalc (i);\n\t\t\t}\n\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tint p = q[j].p + MED;\n\t\t\t\tint v = (q[j].v >> c) & 1;\n\t\t\t\tif (v != t[p].l)\n\t\t\t\t{\n\t\t\t\t\tt[p] = node (0, v, v);\n\t\t\t\t\tfor (p >>= 1; p > 0; p >>= 1)\n\t\t\t\t\t{\n\t\t\t\t\t\trecalc (p);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tans[j] += t[1].s << c;\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%(%s\\n%)\", ans);\n\t}\n}\n"}], "negative_code": [], "src_uid": "e418a92364fcff3068d92311c938709e"} {"source_code": "import std.stdio, std.string, std.conv;\n\nimmutable long MD = 10^^9+7;\nimmutable int MN = 1010;\n\nlong[MN][MN] dp;\nbool[MN][MN] used;\nint n;\nint[MN] p;\n\nlong solve(int a, int b) {\n if (a == b) return 0;\n if (used[a][b]) return dp[a][b];\n long r = 2 + solve(p[a], a) + solve(a+1, b); r %= MD;\n used[a][b] = true;\n dp[a][b] = r;\n return r;\n}\n\nint main() {\n readf(\"%d\\n\", &n);\n string[] input = split(readln());\n foreach (i; 0..n) {\n p[i] = to!int(input[i]) - 1;\n }\n writeln(solve(0, n));\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\n\nimmutable long MD = 10^^9+7;\nimmutable int MN = 1010;\n\nlong[MN][MN] dp;\nbool[MN][MN] used;\nint n;\nint[MN] p;\n\nlong solve(int a, int b) {\n if (a == b) return 0;\n if (used[a][b]) return dp[a][b];\n long r = (2 + solve(p[a], a) + solve(a+1, b)) % MD;\n used[a][b] = true;\n dp[a][b] = r;\n return r;\n}\n\nint main() {\n readf(\"%d\\n\", &n);\n string[] input = split(readln());\n foreach (i; 0..n) {\n p[i] = to!int(input[i]) - 1;\n }\n writeln(solve(0, n));\n return 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nimmutable int MOD = 1_000_000_007;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto p = new int [n];\n\t\tauto f = new long [n];\n\t\tforeach (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t\tx--;\n\t\t}\n\t\tf[] = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlong cur = 0;\n\t\t\tcur = (cur + 1) % MOD;\n\t\t\tint j = p[i];\n\t\t\twhile (j != i)\n\t\t\t{\n\t\t\t\tcur = (cur + f[j]) % MOD;\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tcur = (cur + 1) % MOD;\n\t\t\tf[i] = cur;\n\t\t}\n\t\tlong res = reduce !(\"a + b\") (f);\n\t\tres %= MOD;\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string;\n\nimmutable int mod = 1000000007;\n\nvoid inc(ref int val, int add)\n{\n val += add;\n if (val >= mod)\n {\n val -= mod;\n }\n}\n\nint recur(int idx, int[] dp, int[] p)\n{\n if (dp[idx] != -1)\n {\n return dp[idx];\n }\n dp[idx] = 2;\n foreach (i; p[idx] .. idx)\n {\n int ret = recur(i, dp, p);\n inc(dp[idx], ret);\n }\n return dp[idx];\n}\n\nvoid solve(int[] p)\n{\n int[] dp = new int[p.length];\n foreach (i, ref val; dp)\n {\n val = -1;\n }\n int ans = 0;\n foreach (i; 0 .. p.length)\n {\n int ret = recur(i, dp, p);\n inc(ans, ret);\n }\n writefln(\"%d\", ans);\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n int[] p = new int[n];\n foreach (i; 0 .. n)\n {\n scanf(\"%d\", &p[i]);\n -- p[i];\n }\n solve(p);\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\n\nimmutable long MD = 1^^9+7;\nimmutable int MN = 1010;\n\nlong[MN][MN] dp;\nbool[MN][MN] used;\nint n;\nint[MN] p;\n\nlong solve(int a, int b) {\n if (a == b) return 0;\n if (used[a][b]) return dp[a][b];\n long r = 2 + solve(p[a], a) + solve(a+1, b); r %= MD;\n used[a][b] = true;\n dp[a][b] = r;\n return r;\n}\n\nint main() {\n readf(\"%d\\n\", &n);\n string[] input = split(readln());\n foreach (i; 0..n) {\n p[i] = to!int(input[i]) - 1;\n }\n writeln(solve(0, n));\n return 0;\n}\n"}], "src_uid": "7bb5df614d1fc8323eba51d04ee7bf2a"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1395/problem/C\n// bit manipulation\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n int[] a = readln.split.map!(to!int).array;\n int[] b = readln.split.map!(to!int).array;\n\n int ans = 0;\n for(int i = 0; i < n; i++) {\n int maxima = 0;\n for(int j = 0; j < n; j++) {\n int inf = int.max;\n for(int k = 0; k < m; k++) {\n inf = min(inf, a[j] & b[k] & (~ans));\n }\n maxima = max(maxima, inf);\n }\n ans |= maxima;\n }\n\n ans.writeln;\n}\n\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 1 << 9;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tauto f = new bool [] [] (2, limit);\n\t\tint z = 0;\n\t\tf[z][0] = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tz ^= 1;\n\t\t\tf[z][] = false;\n\t\t\tforeach (v; 0..limit)\n\t\t\t{\n\t\t\t\tif (f[!z][v])\n\t\t\t\t{\n\t\t\t\t\tforeach (j; 0..m)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[z][v | (a[i] & b[j])] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (f[z].countUntil (true));\n\t}\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, m;\n @Dim(\"n\") long[] a;\n @Dim(\"m\") long[] b;\n\n void solve(long tc = -1)\n {\n long val = 0;\n auto neighs = makeSlice!(long[])(n);\n foreach(ref n; neighs)\n n = b.dup;\n foreach_reverse(b; 0 .. cast(long)9)\n {\n bool canAvoid = true;\n foreach(i; 0 .. n)\n {\n if (neighs.at(i).filter!(nei => ((nei & a.at(i)) & (1 << b)) == 0).empty)\n {\n canAvoid = false;\n break;\n }\n }\n if (canAvoid)\n {\n foreach(i; 0 .. n)\n {\n neighs.at(i) = neighs.at(i).filter!(nei => ((nei & a.at(i)) & (1 << b)) == 0).array;\n }\n }\n else\n {\n val = val | (1 << b);\n }\n }\n writeln(val);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\t\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto a = RDA;\n\tauto b = RDA;\n\n\tint ans = int.max;\n\tforeach (i; 0..2^^9)\n\t{\n\t\tbool okok = true;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tbool ok;\n\t\t\tforeach (k; 0..m)\n\t\t\t{\n\t\t\t\tauto x = a[j] & b[k];\n\t\t\t\tbool ng;\n\t\t\t\tforeach (l; 0..9)\n\t\t\t\t{\n\t\t\t\t\tauto bit = 1 << l;\n\t\t\t\t\tif ((i & bit) == 0 && (x & bit))\n\t\t\t\t\t{\n\t\t\t\t\t\tng = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!ng)\n\t\t\t\t{\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t{\n\t\t\t\tokok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (okok)\n\t\t\tans.chmin(i);\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "3da5075048a127319ffa8913859d2aa7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\r\n\t\tauto x = n;\r\n\t\tlong keta;\r\n\t\twhile (x != 0)\r\n\t\t{\r\n\t\t\t++keta;\r\n\t\t\tx /= 10;\r\n\t\t}\r\n\r\n\t\tans[ti] += (keta-1) * 9;\r\n\t\tauto y = n / (10^^(keta-1));\r\n\t\tstring s;\r\n\t\tforeach (i; 0..keta)\r\n\t\t\ts ~= cast(char)('0'+y);\r\n\t\tif (n >= s.to!long)\r\n\t\t\tans[ti] += y;\r\n\t\telse\r\n\t\t\tans[ti] += y-1;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1520/problem/B\n// greedy\nimport std.stdio;\n\nvoid main() {\n long[] ordinary;\n long sum = 0;\n for(int i = 0; i <= 9; ++i) {\n sum += 10L^^i;\n for(long j = 1L; j <= 9L; ++j) {\n ordinary ~= j*sum;\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n;\n readf(\"%s\\n\", &n);\n\n int idx = 0;\n while(true) {\n if(ordinary[idx] <= n)\n idx += 1;\n else\n break;\n }\n idx.writeln;\n}\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1520/problem/B\n// greedy\nimport std.stdio;\n\nvoid main() {\n long[] ordinary;\n long sum = 0;\n for(int i = 0; i < 9; ++i) {\n sum += 10^^i;\n for(int j = 1; j <= 9; ++j) {\n ordinary ~= j*sum;\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n;\n readf(\"%s\\n\", &n);\n\n int idx = 0;\n while(true) {\n if(ordinary[idx] <= n)\n idx += 1;\n else\n break;\n }\n idx.writeln;\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1520/problem/B\n// greedy\nimport std.stdio;\n\nvoid main() {\n long[] ordinary;\n long sum = 0;\n for(int i = 0; i < 9; ++i) {\n sum += 10^^i;\n for(int j = 1; j <= 9; ++j) {\n ordinary ~= j*sum;\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n\n int idx = 0;\n while(true) {\n if(ordinary[idx] <= n)\n idx += 1;\n else\n break;\n }\n idx.writeln;\n}\n}\n"}], "src_uid": "ac7d117d58046872e9d665c9f99e5bff"} {"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n int n;\r\n scanf(\"%d\", &n);\r\n getchar();\r\n long[] a = readln.strip.split(\" \").to!(long[]);\r\n long[] b = readln.strip.split(\" \").to!(long[]);\r\n foreach (i; 0..n)\r\n {\r\n if (a[i] < b[i])\r\n swap(a[i], b[i]);\r\n }\r\n writeln(maxElement(a)*maxElement(b));\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\tauto b = RDA;\r\n\r\n\t\tlong x, y;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tx.chmax(max(a[i], b[i]));\r\n\t\t\ty.chmax(min(a[i], b[i]));\r\n\t\t}\r\n\t\tans[ti] = x * y;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std;\n\nT read(T, string ending = \"\", string beginning = \"\") () {\n scope T x;\n readf!(beginning ~ \"%s\" ~ ending)(x);\n return x;\n}\n\nauto asVec (T) (scope return T x) @safe {\n return x.splitter(' ').map!(to!ushort).cache;\n}\n\nvoid main () {\n immutable tests = read!(ubyte, \"\\n\");\n\n foreach (test_index; 0 .. tests) {\n immutable n = read!(uint, \"\\n\");\n\n immutable ret = StoppingPolicy.requireSameLength.zip(\n asVec(readln.chomp),\n asVec(readln.chomp)\n )\n .map!(t => t[0] > t[1] ? tuple(t[1], t[0]) : t)\n .fold!((acc, t) => tuple(max(acc[0], t[0]), max(acc[1], t[1])));\n\n writeln(cast(uint)ret[0] * ret[1]);\n }\n}\n// \"\"\n"}, {"source_code": "// cheese-cracker [2022-01-27]\n\nvoid solve(){\n auto n = scan!int;\n auto a = scanArray;\n auto b = scanArray;\n long mn = min(a[0], b[0]);\n long mx = max(a[0], b[0]);\n for(int i = 0; i < n; ++i){\n mn = max(min(a[i], b[i]), mn);\n mx = max(max(a[i], b[i]), mx);\n }\n writeln(mn * mx);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}], "negative_code": [], "src_uid": "56197d2468d8515e520c0d925874bf3b"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\n\nlong sd(long n)\n{\n long res = 0;\n while(n)\n {\n res += n % 10;\n n /= 10;\n }\n return res;\n}\n\nlong pmod(long a, long m)\n{\n return (a%m + m)%m;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n\n auto nt = next!int;\n foreach(tc; 0 .. nt)\n {\n auto n = next!long;\n auto s = next!long;\n long tp = 1;\n foreach(i; 0 .. 19)\n {\n long rounded = n + pmod(-n, tp);\n if (rounded.sd <= s)\n {\n writeln(pmod(-n, tp));\n break;\n }\n tp *= 10;\n }\n }\n}\n\n// INPUT\n\nenum InputStyle\n {\n byChunk, byLine\n };\nenum inputStyle = InputStyle.byLine;\n\nFile inputFile;\nstring popWord();\nstatic if (inputStyle == InputStyle.byChunk)\n {\n const chunkSize = 1024 * 1024 * 8;\n const wordSize = 4096;\n char[chunkSize] chunkBuff;\n char[] currChunk;\n void renewChunk()\n {\n if (inputFile.eof)\n currChunk = null;\n else\n currChunk = inputFile.rawRead(chunkBuff);\n }\n char[wordSize] wordBuff;\n char[] word;\n string popWord()\n {\n if (currChunk.length == 0)\n renewChunk;\n assert(currChunk.length > 0);\n while (currChunk[0].isWhite)\n {\n\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n renewChunk;\n }\n word = wordBuff[0 .. 0];\n while (!currChunk[0].isWhite)\n {\n word.length++;\n word[$ - 1] = currChunk[0];\n currChunk = currChunk[1 .. $];\n if (currChunk.length == 0)\n {\n renewChunk;\n if (currChunk.length == 0)\n return cast(string) word;\n }\n }\n return cast(string) word;\n }\n }\n else\n {\n DList!string _words;\n string popWord()\n {\n while (_words.empty)\n {\n foreach(w; inputFile.readln.split)\n {\n _words.insertBack(w);\n }\n }\n auto word = _words.front;\n _words.removeFront;\n return word;\n }\n }\nT next(T)()\n{\n return to!T(popWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto ss = RD!(char[]);\n\t\tauto n = ss.to!long;\n\t\tauto s = RD;\n\t\t\n\t\tss.reverse;\n\t\t\n\t\tans[ti] = long.max;\n\t\tforeach (long i; 0..ss.length+1)\n\t\t{\n\t\t\tauto x = n;\n\t\t\tauto unit = 10L^^i;\n\t\t\tauto rem = x % unit ? unit - (x % unit) : 0;\n\t\t\tx += rem;\n\t\t\tlong cnt;\n\t\t\twhile (x != 0)\n\t\t\t{\n\t\t\t\tcnt += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tif (cnt <= s)\n\t\t\t{\n\t\t\t\tans[ti].chmin(rem);\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto ss = RD!(char[]);\n\t\tauto n = ss.to!long;\n\t\tauto s = RD;\n\t\t\n\t\tss.reverse;\n\t\t\n\t\tans[ti] = long.max;\n\t\tforeach (long flag; 0..2^^ss.length)\n\t\t{\n\t\t\tauto x = n;\n\t\t\tlong tmp;\n\t\t\tforeach (k; 0..ss.length)\n\t\t\t{\n\t\t\t\tauto bit = 1L << k;\n\t\t\t\tif (!(flag & bit)) continue;\n\t\t\t\tauto y = (x / (10^^k)) % 10;\n\t\t\t\tif (y == 0) continue;\n\t\t\t\tauto z = (10 - y) * 10^^k;\n\t\t\t\ttmp += z;\n\t\t\t\tx += z;\n\t\t\t}\n\t\t\tlong cnt;\n\t\t\twhile (x != 0)\n\t\t\t{\n\t\t\t\tcnt += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tif (cnt <= s)\n\t\t\t{\n\t\t\t\t//debug writeln(\"flag:\", flag, \" tmp:\", tmp, \" cnt:\", cnt);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto ss = RD!(char[]);\n\t\tauto n = ss.to!long;\n\t\tauto s = RD;\n\t\t\n\t\tss.reverse;\n\t\t\n\t\tans[ti] = long.max;\n\t\tforeach (flag; 0..2^^ss.length)\n\t\t{\n\t\t\tauto x = n;\n\t\t\tlong tmp;\n\t\t\tforeach (k; 0..ss.length)\n\t\t\t{\n\t\t\t\tauto bit = 1L << k;\n\t\t\t\tif (!(flag & bit)) continue;\n\t\t\t\tauto y = (x / (10^^k)) % 10;\n\t\t\t\tif (y == 0) continue;\n\t\t\t\tauto z = (10 - y) * 10^^k;\n\t\t\t\ttmp += z;\n\t\t\t\tx += z;\n\t\t\t}\n\t\t\tlong cnt;\n\t\t\twhile (x != 0)\n\t\t\t{\n\t\t\t\tcnt += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tif (cnt <= s)\n\t\t\t{\n\t\t\t\tdebug writeln(\"flag:\", flag, \" tmp:\", tmp, \" cnt:\", cnt);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto ss = RD!(char[]);\n\t\tauto n = ss.to!long;\n\t\tauto s = RD;\n\t\t\n\t\tss.reverse;\n\t\t\n\t\tans[ti] = long.max;\n\t\tforeach (long flag; 0..2L^^ss.length)\n\t\t{\n\t\t\tauto x = n;\n\t\t\tlong tmp;\n\t\t\tforeach (k; 0..ss.length)\n\t\t\t{\n\t\t\t\tauto bit = 1L << k;\n\t\t\t\tif (!(flag & bit)) continue;\n\t\t\t\tauto y = (x / (10^^k)) % 10;\n\t\t\t\tif (y == 0) continue;\n\t\t\t\tauto z = (10 - y) * 10^^k;\n\t\t\t\ttmp += z;\n\t\t\t\tx += z;\n\t\t\t}\n\t\t\tlong cnt;\n\t\t\twhile (x != 0)\n\t\t\t{\n\t\t\t\tcnt += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tif (cnt <= s)\n\t\t\t{\n\t\t\t\t//debug writeln(\"flag:\", flag, \" tmp:\", tmp, \" cnt:\", cnt);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto ss = RD!(char[]);\n\t\tauto n = ss.to!long;\n\t\tauto s = RD;\n\t\t\n\t\tss.reverse;\n\t\t\n\t\tans[ti] = long.max;\n\t\tforeach (i; 0..ss.length+1)\n\t\t{\n\t\t\tauto x = n;\n\t\t\tauto unit = 10^^i;\n\t\t\tauto rem = x % unit ? unit - (x % unit) : 0;\n\t\t\tx += rem;\n\t\t\tlong cnt;\n\t\t\twhile (x != 0)\n\t\t\t{\n\t\t\t\tcnt += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\tif (cnt <= s)\n\t\t\t{\n\t\t\t\tans[ti].chmin(rem);\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "50738d19041f2e97e2e448eff3feed84"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto x = RD;\r\n\t\tauto y = RD;\r\n\t\tauto a = RDA;\r\n\r\n\t\tauto cnt = new long[](60);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..60)\r\n\t\t\t{\r\n\t\t\t\tauto bit = 1L << j;\r\n\t\t\t\tif (a[i] & bit)\r\n\t\t\t\t\t++cnt[j];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (j; 0..60)\r\n\t\t{\r\n\t\t\tauto bit = 1L << j;\r\n\t\t\tif (y & bit)\r\n\t\t\t\t--cnt[j];\r\n\t\t}\r\n\r\n\t\tforeach (j; 0..60)\r\n\t\t{\r\n\t\t\tauto bit = 1L << j;\r\n\t\t\tif (x & bit)\r\n\t\t\t\t++cnt[j];\r\n\t\t}\r\n\r\n\t\tbool ok = true;\r\n\t\tlong add;\r\n\t\tforeach (i; 0..60)\r\n\t\t{\r\n\t\t\tauto c = cnt[i] + add;\r\n\t\t\tif (c % 2 && add == 0)\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tadd = c / 2;\r\n\t\t}\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"Alice\" : \"Bob\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "// cheese-cracker [2022-02-06]\n\nvoid solve(){\n long n = scan;\n long x = scan;\n long y = scan;\n auto arr = scanArray;\n long summ = arr.sum + x;\n if(summ % 2 == y % 2){\n writeln(\"Alice\");\n }else{\n writeln(\"Bob\");\n }\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n while(tests--) solve;\n}\n\n/*_________________________*That's All Folks!*__________________________*/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;\nstring[] tk; alias tup = Tuple!(long, long);\nT scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\n"}], "negative_code": [], "src_uid": "d17752513405fc68d838e9b3792c7bef"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint solve (int [] a, int n)\r\n{\r\n\tint lo = n;\r\n\tint hi = -1;\r\n\tforeach (i; 0..n - 1)\r\n\t{\r\n\t\tif (a[i] == a[i + 1])\r\n\t\t{\r\n\t\t\tlo = min (lo, i);\r\n\t\t\thi = max (hi, i);\r\n\t\t}\r\n\t}\r\n\treturn max (0, hi - lo - 1) + (hi - lo == 1);\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (a, n));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt;\n }\n \n int[] xs;\n foreach (i; 0 .. N - 1) {\n if (A[i] == A[i + 1]) {\n xs ~= i;\n }\n }\n \n int ans;\n if (xs.length >= 2) {\n ans = max(xs[$ - 1] - xs[0] - 1, 1);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "a91be662101762bcb2c58b8db9ff61e0"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint solve(const(int[]) A) {\n const N = cast(int)(A.length);\n const lim = A.maxElement + 1;\n auto posss = new int[][lim];\n foreach (i; 0 .. N) {\n posss[A[i]] ~= i;\n }\n // dp[i][j] := min cost to color [i, j] in A[i] or A[j]\n auto dp = new int[][](N, N);\n foreach (i; 0 .. N) {\n dp[i][] = N;\n dp[i][i] = 0;\n }\n foreach_reverse (i; 0 .. N) {\n foreach (j; i + 1 .. N) {\n chmin(dp[i][j], dp[i + 1][j] + 1);\n // chmin(dp[i][j], dp[i][j - 1] + 1);\n foreach (k; posss[A[i]]) {\n if (i < k && k <= j) {\n chmin(dp[i][j], dp[i][k - 1] + dp[k][j]);\n }\n }\n foreach (k; posss[A[j]]) {\n if (i <= k && k < j) {\n // chmin(dp[i][j], dp[i][k] + dp[k + 1][j]);\n }\n }\n }\n }\n return dp[0][N - 1];\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt() - 1;\n }\n \n int[] as;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && A[i] == A[j]; ++j) {}\n as ~= A[i];\n }\n const ans = solve(as);\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint solve(const(int[]) A) {\n const N = cast(int)(A.length);\n const lim = A.maxElement + 1;\n auto posss = new int[][lim];\n foreach (i; 0 .. N) {\n posss[A[i]] ~= i;\n }\n // dp[i][j] := min cost to color [i, j] in A[i] or A[j]\n auto dp = new int[][](N, N);\n foreach (i; 0 .. N) {\n dp[i][] = N;\n dp[i][i] = 0;\n }\n foreach_reverse (i; 0 .. N) {\n foreach (j; i + 1 .. N) {\n chmin(dp[i][j], dp[i + 1][j] + 1);\n chmin(dp[i][j], dp[i][j - 1] + 1);\n foreach (k; posss[A[i]]) {\n if (i < k && k <= j) {\n chmin(dp[i][j], dp[i][k - 1] + dp[k][j]);\n }\n }\n foreach (k; posss[A[j]]) {\n if (i <= k && k < j) {\n chmin(dp[i][j], dp[i][k] + dp[k + 1][j]);\n }\n }\n }\n }\n return dp[0][N - 1];\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt() - 1;\n }\n \n int[] as;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && A[i] == A[j]; ++j) {}\n as ~= A[i];\n }\n const ans = solve(as);\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "fb0315300b981f91d69d6ea164e674b4"} {"source_code": "import std.stdio;\nimport std.algorithm;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\treadf(\" %d\", &a);\n\t\tint[] m = new int[a];\n\t\tint[] n = new int[a];\n\t\tfor (int j=0; j<a; j++)\n\t\t{\n\t\t\treadf(\" %d\", &m[j]);\n\t\t}\n\t\tfor (int j=0; j<a; j++)\n\t\t{\n\t\t\treadf(\" %d\", &n[j]);\n\t\t}\n\t\tm.sort;\n\t\tn.sort;\n\t\tfor (int j=0; j<a; j++)\n\t\t{\n\t\t\twriteln(m[j]);\n\t\t}\n\t\tfor (int j=0; j<a; j++)\n\t\t{\n\t\t\twriteln(n[j]);\n\t\t}\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n auto B = new int[N];\n foreach (i; 0 .. N) {\n B[i] = readInt();\n }\n \n A.sort;\n B.sort;\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(A[i]);\n }\n writeln();\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(B[i]);\n }\n writeln();\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t*2);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = RDA;\n\t\ta.sort();\n\t\tb.sort();\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tans[ti*2] ~= a[i];\n\t\t\tans[ti*2+1] ~= b[i];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\treadf !(\" %s\") (n);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tsort (b);\n\t\twritefln !(\"%(%s %)\") (a);\n\t\twritefln !(\"%(%s %)\") (b);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n const n = r.next!uint;\n auto a = r.nextA!uint (n);\n auto b = r.nextA!uint (n);\n sort (a);\n sort (b);\n writefln (\"%(%s %)\", a);\n writefln (\"%(%s %)\", b);\n }\n}\n\n"}], "negative_code": [], "src_uid": "5c6af8ced2c4b8999abccfac5c4d0057"} {"source_code": "// Not my code! Taken from https://codeforces.com/contest/1654/submission/150267074\n// Replaced malloc with a regular array allocation and marked 'main()' as @system\n// Everything else is marked as @safe by default\n\n@safe:\nimport core.stdc.stdlib;\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int total = 100_005;\nimmutable int limit = 320;\nimmutable int limit2 = total / limit + 1;\n\nint small (int [] a, int n)\n{\n auto len = total * (limit + 2) * 2;\n auto m = new int[len];\n int res = 0;\n for (int d = -limit; d <= +limit; d++)\n {\n\t{\n\t int cur = len / 2 + max (0, -d) * n;\n\t foreach (ref x; a)\n\t {\n\t\tm[cur + x] += 1;\n\t\tres = max (res, m[cur + x]);\n\t\tcur += d;\n\t }\n\t}\n\t{\n\t int cur = len / 2 + max (0, -d) * n;\n\t foreach (ref x; a)\n\t {\n\t\tm[cur + x] -= 1;\n\t\tcur += d;\n\t }\n\t}\n }\n return res;\n}\n\nint large (int [] a, int n)\n{\n int res = 0;\n for (int i = 0; i < n; i++)\n {\n\tint lo = max (0, i - limit2);\n\tint hi = min (n, i + limit2 + 1);\n\tint [int] s;\n\tfor (int j = lo; j < hi; j++)\n\t{\n//\t\t\tif (j == i || (a[i] - a[j]) % (i - j) != 0)\n\t if (j == i)\n\t {\n\t\tcontinue;\n\t }\n\t auto d = (a[i] - a[j]) / (i - j);\n\t if (d * (i - j) != (a[i] - a[j]))\n\t {\n\t\tcontinue;\n\t }\n\t s[d] += 1;\n\t res = max (res, s[d]);\n\t}\n }\n return res + 1;\n}\n\nvoid main () @system\n{\n int n;\n while (readf !(\" %s\") (n) > 0)\n {\n\treadln;\n\tauto a = readln.splitter.map !(to !(int)).array;\n\n\tint x = small (a, n);\n\tint y = large (a, n);\n\twriteln (n - max (x, y));\n }\n}\n", "positive_code": [{"source_code": "import core.stdc.stdlib;\r\nimport std.algorithm;\r\nimport std.container;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int total = 100_005;\r\nimmutable int limit = 320;\r\nimmutable int limit2 = total / limit + 1;\r\n\r\nint small (int [] a, int n)\r\n{\r\n\tauto len = total * (limit + 2) * 2;\r\n\tauto m = cast (int *) (malloc (len * int.sizeof))[0..len];\r\n\tint res = 0;\r\n\tfor (int d = -limit; d <= +limit; d++)\r\n\t{\r\n\t\t{\r\n\t\t\tint cur = len / 2 + max (0, -d) * n;\r\n\t\t\tforeach (ref x; a)\r\n\t\t\t{\r\n\t\t\t\tm[cur + x] += 1;\r\n\t\t\t\tres = max (res, m[cur + x]);\r\n\t\t\t\tcur += d;\r\n\t\t\t}\r\n\t\t}\r\n\t\t{\r\n\t\t\tint cur = len / 2 + max (0, -d) * n;\r\n\t\t\tforeach (ref x; a)\r\n\t\t\t{\r\n\t\t\t\tm[cur + x] -= 1;\r\n\t\t\t\tcur += d;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nint large (int [] a, int n)\r\n{\r\n\tint res = 0;\r\n\tfor (int i = 0; i < n; i++)\r\n\t{\r\n\t\tint lo = max (0, i - limit2);\r\n\t\tint hi = min (n, i + limit2 + 1);\r\n\t\tint [int] s;\r\n\t\tfor (int j = lo; j < hi; j++)\r\n\t\t{\r\n//\t\t\tif (j == i || (a[i] - a[j]) % (i - j) != 0)\r\n\t\t\tif (j == i)\r\n\t\t\t{\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tauto d = (a[i] - a[j]) / (i - j);\r\n\t\t\tif (d * (i - j) != (a[i] - a[j]))\r\n\t\t\t{\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\ts[d] += 1;\r\n\t\t\tres = max (res, s[d]);\r\n\t\t}\r\n\t}\r\n\treturn res + 1;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tint x = small (a, n);\r\n\t\tint y = large (a, n);\r\n\t\twriteln (n - max (x, y));\r\n\t}\r\n}\r\n"}, {"source_code": "// Not my code! Taken from https://codeforces.com/contest/1654/submission/150267074\n// Replaced malloc with a regular array allocation and marked 'main()' as @system\n\nimport core.stdc.stdlib;\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int total = 100_005;\nimmutable int limit = 320;\nimmutable int limit2 = total / limit + 1;\n\nint small (int [] a, int n)\n{\n auto len = total * (limit + 2) * 2;\n auto m = new int[len];\n int res = 0;\n for (int d = -limit; d <= +limit; d++)\n {\n\t{\n\t int cur = len / 2 + max (0, -d) * n;\n\t foreach (ref x; a)\n\t {\n\t\tm[cur + x] += 1;\n\t\tres = max (res, m[cur + x]);\n\t\tcur += d;\n\t }\n\t}\n\t{\n\t int cur = len / 2 + max (0, -d) * n;\n\t foreach (ref x; a)\n\t {\n\t\tm[cur + x] -= 1;\n\t\tcur += d;\n\t }\n\t}\n }\n return res;\n}\n\nint large (int [] a, int n)\n{\n int res = 0;\n for (int i = 0; i < n; i++)\n {\n\tint lo = max (0, i - limit2);\n\tint hi = min (n, i + limit2 + 1);\n\tint [int] s;\n\tfor (int j = lo; j < hi; j++)\n\t{\n//\t\t\tif (j == i || (a[i] - a[j]) % (i - j) != 0)\n\t if (j == i)\n\t {\n\t\tcontinue;\n\t }\n\t auto d = (a[i] - a[j]) / (i - j);\n\t if (d * (i - j) != (a[i] - a[j]))\n\t {\n\t\tcontinue;\n\t }\n\t s[d] += 1;\n\t res = max (res, s[d]);\n\t}\n }\n return res + 1;\n}\n\nvoid main () @system\n{\n int n;\n while (readf !(\" %s\") (n) > 0)\n {\n\treadln;\n\tauto a = readln.splitter.map !(to !(int)).array;\n\n\tint x = small (a, n);\n\tint y = large (a, n);\n\twriteln (n - max (x, y));\n }\n}\n"}], "negative_code": [], "src_uid": "2508a347f02aa0f49e0d154c54879b13"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n if (n < 3) {\n writeln(\"No\");\n return;\n }\n \n int[][2] s;\n for (auto i = 1, j = n, nxt = 0; i <= j; ++i, --j, nxt = (nxt+1) % 2) {\n s[nxt] ~= i;\n if (i != j) s[nxt] ~= j;\n }\n \n writeln(\"Yes\");\n foreach (rw; s) {\n writef(\"%s \", rw.length);\n writefln(\"%(%s %)\", rw);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto N = readln.chomp.to!long;\n\n if (N <= 2) {\n writeln(\"No\");\n return;\n }\n\n long S = N * (N - 1) / 2;\n foreach_reverse (i; 2..N+1) {\n if (gcd(S-i, i) > 1) {\n writeln(\"Yes\");\n writeln(1, \" \", i);\n write(N-1);\n foreach (j; 1..N+1) if (j != i) write(\" \", j);\n writeln;\n return;\n }\n }\n\n writeln(\"No\");\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n if (n == 1 || n % 2 == 0) {\n writeln(\"No\");\n return;\n }\n \n int[] s;\n auto isPr = new bool[654321];\n isPr[] = true;\n foreach (i; 2 .. isPr.length) {\n if (!isPr[i]) continue;\n \n if (i != 2) s ~= i.to!int;\n foreach (ref e; isPr[i+i .. $].stride(i)) e = false;\n \n if (s.length == n-1) break;\n }\n \n writeln(\"Yes\");\n writeln(\"1 2\");\n writef(\"%s \", n-1);\n s.writefln!(\"%(%s %)\");\n}"}], "src_uid": "bb7bace930d5c5f231bfc2061576ec45"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto rows = new int[][] (n+1);\n auto cols = new int[][] (n+1);\n auto diagtl = new int[][] (2*n-1);\n auto diagbl = new int[][] (2*n-1);\n \n auto qs = new Tuple!(int, int)[] (m);\n foreach (i; 0 .. m) {\n readf(\"%s %s\", &qs[i][0], &qs[i][1]);\n readln;\n \n rows[qs[i][0]] ~= i;\n cols[qs[i][1]] ~= i;\n diagtl[qs[i][0]-qs[i][1]+n-1] ~= i;\n diagbl[qs[i][0]+qs[i][1]-2] ~= i;\n }\n \n auto attacks = new int[] (m);\n \n auto arrs = [rows, cols, diagtl, diagbl];\n auto sortOrd = [(int id) => qs[id][1], (int id) => qs[id][0],\n (int id) => qs[id][0], (int id) => qs[id][0]];\n \n foreach (i; 0 .. 4) {\n foreach (rw; arrs[i]) {\n if (rw.length <= 1) { continue; }\n \n rw.schwartzSort!(id => sortOrd[i](id));\n \n attacks[rw.front] += 1;\n attacks[rw.back] += 1;\n foreach (e; rw.dropOne.dropBackOne) { attacks[e] += 2; }\n }\n }\n \n auto ans = new int[] (9);\n foreach (e; attacks) { ans[e] += 1; }\n \n ans.writefln!\"%(%s %)\";\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto rows = new int[][] (n+1);\n auto cols = new int[][] (n+1);\n auto diagtl = new int[][] (2*n-1);\n auto diagbl = new int[][] (2*n-1);\n \n auto qs = new Tuple!(int, int)[] (m);\n foreach (i; 0 .. m) {\n readf(\"%s %s\", &qs[i][0], &qs[i][1]);\n readln;\n \n rows[qs[i][0]] ~= i;\n cols[qs[i][1]] ~= i;\n diagtl[qs[i][0]-qs[i][1]+n-1] ~= i;\n diagbl[qs[i][0]+qs[i][1]-2] ~= i;\n }\n \n auto attacks = new int[] (m);\n \n auto arrs = [rows, cols, diagtl, diagbl];\n \n foreach (i; 0 .. 4) {\n foreach (rw; arrs[i]) {\n if (rw.length <= 1) { continue; }\n \n rw.schwartzSort!(id => qs[id]);\n \n attacks[rw.front] += 1;\n attacks[rw.back] += 1;\n foreach (e; rw.dropOne.dropBackOne) { attacks[e] += 2; }\n }\n }\n \n auto ans = new int[] (9);\n foreach (e; attacks) { ans[e] += 1; }\n \n ans.writefln!\"%(%s %)\";\n}"}], "negative_code": [], "src_uid": "f19e7f33396d27e1eba2c46b6b5e706a"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n, k;\n readf!\" %d %d \"(n, k);\n auto s = readln.strip;\n int[char] freq;\n foreach (ch ; s) {\n freq[ch]++;\n }\n int pairs;\n int singles;\n foreach (_, v ; freq) {\n pairs += v / 2;\n singles += v % 2;\n }\n int ans = pairs / k * 2;\n if (pairs % k == 0) {\n ans += (singles >= k);\n } else {\n ans += (singles + (pairs % k) * 2 >= k);\n }\n writeln(ans);\n }\n}\n", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n void subSolve(int SN, int K, string S) {\r\n auto chars = new int[](26);\r\n foreach(c; S) chars[c - 'a']++;\r\n\r\n int baseOdds, baseEvens;\r\n foreach(cs; chars) {\r\n if (cs == 0) continue;\r\n \r\n baseOdds += cs%2;\r\n baseEvens += (cs - cs%2) / 2;\r\n }\r\n // [evens, odds].deb;\r\n \r\n int ans;\r\n foreach(centered; 0..K + 1) {\r\n auto odds = baseOdds;\r\n auto evens = baseEvens;\r\n\r\n const m = min(odds, centered);\r\n odds -= m;\r\n evens -= (centered - m + 1) / 2;\r\n\r\n // foreach(_; 0..centered) {\r\n // if (odds > 0) {\r\n // odds--;\r\n // } else {\r\n // evens -= 2;\r\n // odds++;\r\n // }\r\n // }\r\n\r\n int geta = centered == K ? 1 : 0;\r\n ans = max(ans, geta + (evens / K) * 2);\r\n }\r\n\r\n ans.writeln;\r\n }\r\n\r\n foreach(_; 0..QN) {\r\n subSolve(scan!int, scan!int, scan);\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n\r\nK binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }\r\nT binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {\r\n auto ok = l;\r\n auto ng = r;\r\n const T TWO = 2;\r\n \r\n bool again() {\r\n static if (is(T == float) || is(T == double) || is(T == real)) {\r\n return !ng.approxEqual(ok, 1e-08, 1e-08);\r\n } else {\r\n return abs(ng - ok) > 1;\r\n }\r\n }\r\n \r\n while(again()) {\r\n const half = (ng + ok) / TWO;\r\n const halfValue = fn(half);\r\n \r\n if (cond(halfValue)) {\r\n ok = half;\r\n } else {\r\n ng = half;\r\n }\r\n }\r\n \r\n return ok;\r\n}"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s \"(n); return n; }();\n immutable k = (){ uint k; readf!\"%s\\n\"(k); return k; }();\n\n const frec = (){\n static assert(true);\n uint[dchar] ret;\n\n foreach (c; readln.chomp) {\n ++ ret[c];\n }\n return ret;\n }();\n\n uint total_pairs = 0;\n uint odds = 0;\n\n foreach (f; frec) {\n total_pairs += f / 2;\n odds += (f % 2 == 1);\n }\n\n immutable can_do_donations =\n (total_pairs % k + odds >= k - total_pairs % k);\n writeln((total_pairs / k) * 2 + can_do_donations);\n }\n}\n// \"\"\n"}], "negative_code": [{"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s \"(n); return n; }();\n immutable k = (){ uint k; readf!\"%s\\n\"(k); return k; }();\n\n const frec = (){\n static assert(true);\n uint[dchar] ret;\n\n foreach (c; readln.chomp) {\n ++ ret[c];\n }\n return ret;\n }();\n\n uint total_pairs = 0;\n bool have_odd_one = false;\n\n foreach (f; frec) {\n total_pairs += f / 2;\n have_odd_one = have_odd_one || f % 2 == 1;\n }\n\n immutable can_donate = have_odd_one || total_pairs % k != 0;\n writeln((total_pairs / k) * 2 + can_donate);\n }\n}\n// \"\"\n"}], "src_uid": "ca817fe0a97e2d8a6bcfcb00103b6b6d"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n int n, x;\n readf!\" %d %d \"(n, x);\n auto a = readln.splitter.map!(to!int).filter!(ai => ai < x).array;\n\n auto h = redBlackTree!(\"a<b\", true, int)();\n foreach (ai ; a)\n h.insert(ai);\n\n bool good = true;\n while (!h.empty) {\n int cnt = 1;\n int tmp = h.front;\n h.removeFront;\n while (!h.empty && h.front == tmp) {\n cnt++;\n h.removeFront;\n }\n if (cnt % (tmp + 1) != 0) {\n good = false;\n break;\n } else {\n if (tmp + 1 < x) {\n foreach (i ; 0 .. cnt / (tmp + 1))\n h.insert(tmp + 1);\n }\n }\n }\n\n writeln(good ? \"Yes\" : \"No\");\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\nint N, X;\r\nint[] A;\r\n\r\nbool solve() {\r\n auto fs = new int[X + 1];\r\n foreach (i; 0 .. N) {\r\n ++fs[A[i]];\r\n }\r\n foreach (a; 1 .. X) {\r\n const q = fs[a] / (a + 1);\r\n const r = fs[a] % (a + 1);\r\n if (r != 0) {\r\n return false;\r\n }\r\n fs[a + 1] += q;\r\n }\r\n return true;\r\n}\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n N = readInt;\r\n X = readInt;\r\n A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt;\r\n }\r\n \r\n const ans = solve;\r\n writeln(ans ? \"Yes\" : \"No\");\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tint n, x;\r\n\twhile (readf !(\" %s %s\") (n, x) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto d = new int [x + 1];\r\n\t\tforeach (c; a)\r\n\t\t{\r\n\t\t\tc = min (c, x);\r\n\t\t\td[c] += 1;\r\n\t\t\tfor ( ; c < x && d[c] == c + 1; c++)\r\n\t\t\t{\r\n\t\t\t\td[c] = 0;\r\n\t\t\t\td[c + 1] += 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (any (d[0..x]) ? \"NO\" : \"YES\");\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "c5ec8b18c39720098f6ac2dbc0ddd4f4"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int n_Cases = 1;\n // n_Cases = cin.readInt;\n \n\tfor (int case_i = 1; case_i <= n_Cases; case_i++) {\n int n = cin.readInt;\n char[][] mat = new char[][](n, n);\n\n for (int i = 0; i < n; i++) {\n mat[i] = cin.readString.dup;\n }\n\n char key = mat[0][0];\n char key2 = mat[0][1];\n\n bool con1 = true;\n bool con2 = true;\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (i == j || i + j == n - 1) {\n if (mat[i][j] != key) con1 = false;\n } else {\n if (mat[i][j] == key || mat[i][j] != key2) con2 = false;\n }\n }\n }\n\n writeln((con1 && con2) ? \"YES\" : \"NO\");\n\t} \n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n\nvoid main() {\n int N; readf(\"%d\\n\", &N);\n auto F = new string[N];\n foreach (i; 0 .. N) {\n F[i] = readln.chomp;\n }\n char x = F[N / 2 + 1][N / 2 + 1];\n char y = F[0][1];\n bool f() {\n if (x == y) return false;\n foreach (i; 0 .. N) {\n foreach (j; 0 .. N) {\n if (i == j || i + j == N - 1) {\n if (x != F[i][j]) {\n return false;\n }\n } else {\n if (y != F[i][j]) {\n return false;\n }\n }\n }\n }\n return true;\n }\n writeln(f ? \"YES\" : \"NO\");\n}\n"}], "negative_code": [], "src_uid": "02a9081aed29ea92aae13950a6d48325"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA!int;\n\t\ta.sort();\n\t\tint pos;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tpos = i;\n\t\t\tif (a[i] >= s) break;\n\t\t}\n\t\tif (a[pos] != s) continue;\n\n\t\tint l = a[0] != 1 ? s-(a[0]-1) : int.max, r = a[$-1] != n ? a[$-1]+1-s : int.max;\n\t\t{\n\t\t\tint last = s;\n\t\t\tforeach_reverse (i; 0..pos)\n\t\t\t{\n\t\t\t\tif (a[i] != last - 1)\n\t\t\t\t{\n\t\t\t\t\tl = s - (last - 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tlast = a[i];\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tint last = s;\n\t\t\tforeach (i; pos+1..k)\n\t\t\t{\n\t\t\t\tif (a[i] != last + 1)\n\t\t\t\t{\n\t\t\t\t\tr = (last + 1) - s;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tlast = a[i];\n\t\t\t}\n\t\t}\n\t\tans[ti] = min(l, r);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, s, k;\n readf(\"%s %s %s\", &n, &s, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n auto rbt = make!(RedBlackTree!int)(arr);\n \n int lo = s;\n while (lo >= 1 && lo in rbt) { --lo; }\n int hi = s;\n while (hi <= n && hi in rbt) { ++ hi; }\n \n if (lo == 0) {\n writeln(hi - s);\n } else if (hi == n+1) {\n writeln(s - lo);\n } else {\n writeln(min(hi - s, s - lo));\n }\n }\n}"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\n\nvoid read(T...)(ref T t)\n{\n void singleRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n static foreach(i; 0 .. T.length)\n {\n static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))\n {\n foreach(ref element; t[i])\n read(element);\n }\n else\n {\n singleRead(t[i]);\n }\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value = E.init)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\nvoid main()\n{\n int t;\n read(t);\n foreach(tc; 0 .. t)\n {\n long n, s, k;\n read(n, s, k);\n auto closed = redBlackTree!long();\n foreach(i; 0 .. k)\n {\n long ai;\n read(ai);\n closed.insert(ai);\n }\n long mindistance = long.max;\n foreach(i; s .. n + 1)\n {\n if (i !in closed)\n {\n mindistance = min(mindistance, cast(long)i - s);\n break;\n }\n }\n foreach_reverse(i; 1 .. s)\n {\n if (i !in closed)\n {\n mindistance = min(mindistance, s - cast(long) i);\n break;\n }\n }\n writeln(mindistance);\n }\n}\n"}], "negative_code": [], "src_uid": "faae9c0868b92b2355947c9adcaefb43"} {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Dsu(int n) {\n int[n] p, size, count;\n bool[n] cap;\n\n int get(int x) {\n return x == p[x]? x : (p[x] = get(p[x]));\n }\n\n void merge(int x, int y) {\n x = get(x);\n y = get(y);\n if (x != y) {\n p[x] = y;\n size[y] += size[x];\n count[y] += count[x] + 1;\n } else\n count[y]++;\n }\n}\n\nint n, m, k;\nint[1000] _caps;\nDsu!1000 dsu;\n\nvoid main() {\n while (read(&n, &m, &k)) {\n auto caps = _caps[0 .. k];\n foreach (ref x; caps) {\n read(&x);\n x--;\n }\n iota(0, n).copy(dsu.p[ ]);\n repeat(1, n).copy(dsu.size[ ]);\n memset(dsu.count.ptr, 0x00, dsu.count.sizeof);\n memset(dsu.cap.ptr, 0x00, dsu.cap.sizeof);\n while (m--) {\n int a, b;\n read(&a, &b);\n a--;\n b--;\n dsu.merge(a, b);\n }\n foreach (x; caps)\n dsu.cap[dsu.get(x)] = true;\n int result = 0;\n int best = 0;\n foreach (i; 0 .. n) {\n int x = dsu.get(i);\n if (dsu.cap[x])\n best = max(best, dsu.size[x]);\n int total = dsu.size[x] * (dsu.size[x] - 1) >> 1;\n debug writefln(\"%s %s %s %s\", result, dsu.size[x], total, dsu.count[x]);\n result += total - dsu.count[x];\n dsu.count[x] = total;\n }\n foreach (i; 0 .. n) {\n int x = dsu.get(i);\n if (!dsu.cap[x]) {\n result -= dsu.size[x] * (dsu.size[x] - 1) >> 1;\n foreach (j; 0 .. dsu.size[x]) {\n result += best;\n best++;\n }\n dsu.cap[x] = true;\n }\n }\n writeln(result);\n debug writeln();\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\tint m;\n\tint k;\n\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\tauto c = new bool [n];\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tint u;\n\t\t\treadf (\" %s\", &u);\n\t\t\tu -= 1;\n\t\t\tc[u] = true;\n\t\t}\n\n\t\tauto a = new int [] [n];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u;\n\t\t\tint v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tauto b = new bool [n];\n\t\tint vertices;\n\n\t\tbool recur (int v)\n\t\t{\n\t\t\tif (b[v])\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tb[v] = true;\n\t\t\tvertices += 1;\n\t\t\tbool ok = c[v];\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tok |= recur (u);\n\t\t\t}\n\t\t\treturn ok;\n\t\t}\n\n\t\tlong res = -m;\n\t\tint largest = 0;\n\t\tint add = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tif (!b[i])\n\t\t\t{\n\t\t\t\tvertices = 0;\n\t\t\t\tbool ok = recur (i);\n\t\t\t\tif (ok)\n\t\t\t\t{\n\t\t\t\t\tres += vertices * 1L *\n\t\t\t\t\t (vertices - 1) / 2;\n\t\t\t\t\tlargest = max (largest, vertices);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tadd += vertices;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tadd += largest;\n\t\tres += add * 1L * (add - 1) / 2;\n\t\tres -= largest * 1L * (largest - 1) / 2;\n\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nstruct Dsu(int n) {\n int[n] p, size, count;\n bool[n] cap;\n\n int get(int x) {\n return x == p[x]? x : (p[x] = get(p[x]));\n }\n\n void merge(int x, int y) {\n x = get(x);\n y = get(y);\n if (x != y) {\n p[x] = y;\n size[y] += size[x];\n count[y] += count[x] + 1;\n } else\n count[y]++;\n }\n}\n\nint n, m, k;\nint[1000] _caps;\nDsu!1000 dsu;\n\nvoid main() {\n while (read(&n, &m, &k)) {\n auto caps = _caps[0 .. k];\n foreach (ref x; caps) {\n read(&x);\n x--;\n }\n iota(0, n).copy(dsu.p[ ]);\n repeat(1, n).copy(dsu.size[ ]);\n memset(dsu.count.ptr, 0x00, dsu.count.sizeof);\n memset(dsu.cap.ptr, 0x00, dsu.cap.sizeof);\n while (m--) {\n int a, b;\n read(&a, &b);\n a--;\n b--;\n dsu.merge(a, b);\n }\n foreach (x; caps)\n dsu.cap[dsu.get(x)] = true;\n int result = 0;\n int best = 0;\n foreach (i; 0 .. n) {\n int x = dsu.get(i);\n if (dsu.cap[x])\n best = max(best, dsu.size[x]);\n int total = dsu.size[x] * (dsu.size[x] - 1) >> 1;\n debug writefln(\"%s %s %s %s\", result, dsu.size[x], total, dsu.count[x]);\n result += total - dsu.count[x];\n dsu.count[x] = total;\n }\n foreach (i; 0 .. n) {\n int x = dsu.p[i];\n if (!dsu.cap[x]) {\n result -= dsu.size[x] * (dsu.size[x] - 1) >> 1;\n foreach (j; 0 .. dsu.size[x]) {\n result += best;\n best++;\n }\n }\n }\n writeln(result);\n debug writeln();\n }\n}\n"}], "src_uid": "6cf43241b14e4d41ad5b36572f3b3663"} {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");alias long lint;const int mod=1000000007;\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\tsize_t lowb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint t;\nloop:while(read(t))\n\t{\n\t\tforeach(ii;0..t)\n\t\t{\n\t\t\tlong x,y,p,q;\n\t\t\tread(x,y,p,q);\n\t\t\tlong l=0,r=int.max;\n\t\t\twhile(l<r)\n\t\t\t{\n\t\t\t\tlong m=(l+r)>>1;\n\t\t\t\tif(p*m-x<=q*m-y && p*m-x>=0)r=m;\n\t\t\t\telse l=m+1;\n\t\t\t}\n\t\t\tif(l==int.max)writeln(-1);\n\t\t\telse writeln(l*q-y);\n\t\t}\n\t}\n}", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const X = readLong();\n const Y = readLong();\n const P = readLong();\n const Q = readLong();\n \n long ans;\n if (P == 0) {\n ans = (X == 0) ? 0 : -1;\n } else if (Q - P == 0) {\n ans = (Y - X == 0) ? 0 : -1;\n } else {\n long mx;\n chmax(mx, (X + P - 1) / P);\n chmax(mx, ((Y - X) + (Q - P) - 1) / (Q - P));\n ans = (mx * P - X) + (mx * (Q - P) - (Y - X));\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "589f3f7366d1e0f9185ed0926f5a10bb"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\t\n\t\tauto dp = new int[][](n+1, 2);\n\t\tforeach (i; 0..dp.length)\n\t\t{\n\t\t\tdp[i][] = n;\n\t\t}\n\t\tdp[0][0] = 0;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tdp[i+1][1].chmin(dp[i][0]+a[i]);\n\t\t\tif (i < n-1)\n\t\t\t\tdp[i+2][1].chmin(dp[i][0]+a[i]+a[i+1]);\n\t\t\tdp[i+1][0].chmin(dp[i][1]);\n\t\t\tif (i < n-1)\n\t\t\t\tdp[i+2][0].chmin(dp[i][1]);\n\t\t}\n\n\t\tans[ti] = min(dp[n][0], dp[n][1]);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n int[] arr = rdarr!int;\n int[][] dp = new int[][](2, n+1);\n if(n == 1){\n writeln(to!int(arr[0] == 1));\n return;\n }\n dp[1][0] = arr[0];\n dp[1][1] = dp[1][0] + arr[1];\n dp[0][0] = to!int(1e7);\n dp[0][1] = dp[1][0];\n foreach(i; 2..(n)){\n dp[0][i] = min(dp[1][i-2], dp[1][i-1]);\n dp[1][i] = min(arr[i-1] + dp[0][i-2], dp[0][i-1]) + arr[i];\n }\n int res = min(dp[1][n-1], dp[0][n-1]);\n /* writeln(dp); */\n writeln(res);\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n int[] arr = rdarr!int;\n int[][] dp = new int[][](2, n+1);\n if(n == 1){\n writeln(to!int(arr[0] == 1));\n return;\n }\n dp[1][0] = arr[0];\n dp[1][1] = dp[1][0] + arr[1];\n dp[0][0] = to!int(1e8);\n dp[0][1] = dp[1][0];\n foreach(i; 2..(n)){\n dp[0][i] = min(dp[1][i-2], dp[1][i-1]);\n dp[1][i] = min(arr[i-1] + dp[0][i-2], dp[0][i-1]) + arr[i];\n }\n int res = min(dp[1][n-1], dp[0][n-1]);\n /* writeln(dp); */\n writeln(res);\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n int[] arr = rdarr!int;\n int[][] dp = new int[][](2, n+1);\n if(n == 1){\n writeln(to!int(arr[0] == 1));\n }\n\n dp[1][0] = arr[0];\n dp[1][1] = dp[1][0] + arr[1];\n dp[0][0] = to!int(1e7);\n dp[0][1] = dp[1][0];\n foreach(i; 2..(n)){\n dp[0][i] = min(dp[1][i-2], dp[1][i-1]);\n dp[1][i] = min(arr[i-1] + dp[0][i-2], dp[0][i-1]) + arr[i];\n }\n int res = min(dp[1][n-1], dp[0][n-1]);\n /* writeln(dp); */\n writeln(res);\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid solve(){\n int n;\n n = rd!int;\n int[] arr = rdarr!int;\n int[][] dp = new int[][](2, n);\n int pt = (arr[0] == 1);\n dp[1][0] = pt;\n dp[0][0] = to!int(1e8);\n foreach(i; 1..(n)){\n dp[0][i] = dp[1][i-1];\n dp[1][i] = dp[1][i-1] + (arr[i] == 1);\n if(i > 1){\n dp[0][i] = min(dp[1][i-2], dp[1][i]);\n dp[1][i] = min((arr[i-1] == 1) + dp[0][i-2], dp[0][i-1]) + (arr[i] == 1);\n }\n }\n int res = min(dp[1][n-1], dp[0][n-1]);\n if(n == 1){ res = pt; }\n /* writeln(dp); */\n writeln(res);\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\t\n\t\tint i;\n\t\tbool turn;\n\t\twhile (i < n)\n\t\t{\n\t\t\tif (turn)\n\t\t\t{\n\t\t\t\t++i;\n\t\t\t\tif (i < n)\n\t\t\t\t{\n\t\t\t\t\tif (a[i] == 1)\n\t\t\t\t\t\t++i;\n\t\t\t\t}\n\t\t\t\tturn = !turn;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i] == 1)\n\t\t\t\t{\n\t\t\t\t\t++ans[ti];\n\t\t\t\t}\n\t\t\t\t++i;\n\t\t\t\tif (i < n)\n\t\t\t\t{\n\t\t\t\t\tif (a[i] == 0)\n\t\t\t\t\t\t++i;\n\t\t\t\t}\n\t\t\t\tturn = !turn;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\t\n\t\tint i;\n\t\tbool turn;\n\t\twhile (i < n)\n\t\t{\n\t\t\tif (turn)\n\t\t\t{\n\t\t\t\ti += 2;\n\t\t\t\tturn = !turn;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i] == 1)\n\t\t\t\t{\n\t\t\t\t\t++ans[ti];\n\t\t\t\t}\n\t\t\t\t++i;\n\t\t\t\tif (i < n)\n\t\t\t\t{\n\t\t\t\t\tif (a[i] == 0)\n\t\t\t\t\t\t++i;\n\t\t\t\t}\n\t\t\t\tturn = !turn;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "d34ffd75ef82111d1077db4b033d5195"} {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto p = new int [n];\n\t\tforeach (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t\tx--;\n\t\t}\n\n\t\treal total = 0;\n\t\treal answer = 0;\n\n\t\treal calc ()\n\t\t{\n\t\t\tint res = 0;\n\t\t\tforeach (i; 0..n - 1)\n\t\t\t{\n\t\t\t\tforeach (j; i + 1..n)\n\t\t\t\t{\n\t\t\t\t\tres += (p[i] > p[j]);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tvoid recur (int d)\n\t\t{\n\t\t\tif (d == 0)\n\t\t\t{\n\t\t\t\ttotal += 1;\n\t\t\t\tanswer += calc ();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; i..n)\n\t\t\t\t{\n\t\t\t\t\treverse (p[i..j + 1]);\n\t\t\t\t\trecur (d - 1);\n\t\t\t\t\treverse (p[i..j + 1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (k);\n\t\twritefln (\"%.20f\", answer / total);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint mul(int n)\n{\n auto res = 1;\n foreach (i; 2 .. n + 1)\n {\n res *= i;\n }\n return res;\n}\n\nint calc(int[] p)\n{\n auto n = cast(int)p.length;\n auto f = new bool[n + 1];\n fill(f, false);\n auto res = 0;\n foreach (i; 0 .. n)\n {\n auto cnt = 0;\n foreach (j; 1 .. p[i])\n {\n if (!f[j])\n {\n ++ cnt;\n }\n }\n res += cnt * mul(n - i - 1);\n f[p[i]] = true;\n }\n return res;\n}\n\nint countReverse(int[] p)\n{\n auto res = 0;\n foreach (i; 0 .. p.length)\n {\n foreach (j; i + 1 .. p.length)\n {\n if (p[i] > p[j])\n {\n ++ res;\n }\n }\n }\n return res;\n}\n\nvoid reverse(int[] p, int left, int right)\n{\n while (left < right)\n {\n swap(p[left], p[right]);\n ++ left;\n -- right;\n }\n}\n\ndouble saiki(int[] p, int n, int c, int k, double[][] dp)\n{\n auto r = calc(p);\n if (dp[r][c] != -1)\n {\n return dp[r][c];\n }\n if (c == k)\n {\n auto cnt = countReverse(p);\n dp[r][c] = cnt;\n return cnt;\n }\n auto res = 0.0;\n auto prob = 1.0 / ((1 + n) * n / 2);\n foreach (i; 0 .. n)\n {\n foreach (j; i .. n)\n {\n reverse(p, i, j);\n auto ret = saiki(p, n, c + 1, k, dp);\n res += prob * ret;\n reverse(p, i, j);\n }\n }\n dp[r][c] = res;\n return res;\n}\n\nvoid solve(int[] p, int n, int k)\n{\n auto r = mul(n);\n auto dp = new double[][](r + 1, k + 1);\n foreach (i; 0 .. r + 1)\n {\n fill(dp[i], -1);\n }\n auto ans = saiki(p, n, 0, k, dp);\n writefln(\"%.10f\", ans);\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto p = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &p[i]);\n }\n readln;\n solve(p, n, k);\n }\n return 0;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n DList!(Tuple!(int, int[])) arrs;\n arrs ~= tuple(k, arr);\n \n while (!arrs.empty && arrs.front[0] > 0) {\n auto cur = arrs.front;\n arrs.removeFront();\n \n foreach (i; 0 .. n) {\n foreach (j; i .. n) {\n debug { writeln(i, ' ', j); }\n auto rev = cur[1].dup;\n for (int le = i, r = j; le < r; ++le, --r) { swap(rev[le], rev[r]); }\n \n arrs ~= tuple(cur[0] - 1, rev);\n }\n }\n }\n \n debug { arrs.each!writeln; }\n \n long invsum = 0;\n foreach (a; arrs) {\n auto cur = a[1];\n foreach (i; 0 .. n) {\n foreach (j; i+1 .. n) {\n if (cur[i] > cur[j]) { ++invsum; }\n }\n }\n }\n \n auto ans = invsum.to!double / arrs.array.length;\n ans.writefln!\"%.12f\";\n}"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto p = new int [n];\n\t\tforeach (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t\tx--;\n\t\t}\n\n\t\tif (n < 2)\n\t\t{\n\t\t\twriteln (0);\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto f = new real [] [] [] (2, n, n);\n\t\tint d = 0;\n\t\tforeach (ref g; f[d])\n\t\t{\n\t\t\tg[] = 0.0;\n\t\t}\n\t\tforeach (a; 0..n - 1)\n\t\t{\n\t\t\tforeach (b; a + 1..n)\n\t\t\t{\n\t\t\t\tif (p[a] < p[b])\n\t\t\t\t{\n\t\t\t\t\tf[d][b][a] += 1.0;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tf[d][a][b] += 1.0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treal total = 2.0 / n / (n + 1);\n\t\tforeach (t; 0..k)\n\t\t{\n\t\t\td ^= 1;\n\t\t\tforeach (ref g; f[d])\n\t\t\t{\n\t\t\t\tg[] = 0.0;\n\t\t\t}\n\t\t\tforeach (lo; 0..n)\n\t\t\t{\n\t\t\t\tforeach (hi; lo..n)\n\t\t\t\t{\n\t\t\t\t\tauto z = n.iota.array;\n\t\t\t\t\treverse (z[lo..hi + 1]);\n\t\t\t\t\tforeach (a; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (b; 0..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[d][z[a]][z[b]] +=\n\t\t\t\t\t\t\t f[!d][a][b];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tforeach (a; 0..n)\n\t\t\t{\n\t\t\t\tforeach (b; 0..n)\n\t\t\t\t{\n\t\t\t\t\tf[d][a][b] *= total;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treal answer = 0;\n\t\tforeach (a; 0..n - 1)\n\t\t{\n\t\t\tforeach (b; a + 1..n)\n\t\t\t{\n\t\t\t\tanswer += f[d][a][b];\n\t\t\t}\n\t\t}\n\t\twritefln (\"%.20f\", answer);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto p = new int [n];\n\t\tforeach (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t\tx--;\n\t\t}\n\n\t\tif (n < 2)\n\t\t{\n\t\t\twriteln (0);\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto f = new real [] [] [] (2, n, n);\n\t\tint d = 0;\n\t\tforeach (ref g; f[d])\n\t\t{\n\t\t\tg[] = 0.0;\n\t\t}\n\t\tforeach (a; 0..n - 1)\n\t\t{\n\t\t\tforeach (b; a + 1..n)\n\t\t\t{\n\t\t\t\tif (p[a] < p[b])\n\t\t\t\t{\n\t\t\t\t\tf[d][b][a] += 1.0;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tf[d][a][b] += 1.0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treal total = 2.0 / n / (n + 1);\n\t\tforeach (t; 0..k)\n\t\t{\n\t\t\td ^= 1;\n\t\t\tforeach (ref g; f[d])\n\t\t\t{\n\t\t\t\tg[] = 0.0;\n\t\t\t}\n\t\t\tforeach (lo; 0..n)\n\t\t\t{\n\t\t\t\tforeach (hi; lo..n)\n\t\t\t\t{\n\t\t\t\t\tauto z = n.iota.array;\n\t\t\t\t\treverse (z[lo..hi + 1]);\n\t\t\t\t\tforeach (a; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (b; 0..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[d][z[a]][z[b]] +=\n\t\t\t\t\t\t\t f[!d][a][b];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tforeach (a; 0..n)\n\t\t\t{\n\t\t\t\tforeach (b; 0..n)\n\t\t\t\t{\n\t\t\t\t\tf[d][a][b] *= total;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treal answer = 0;\n\t\tforeach (a; 0..n - 1)\n\t\t{\n\t\t\tforeach (b; a + 1..n)\n\t\t\t{\n\t\t\t\tanswer += f[d][a][b];\n\t\t\t}\n\t\t}\n\t\twritefln (\"%.20f\", answer);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto p = new int [n];\n\t\tforeach (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t\tx--;\n\t\t}\n\n\t\tif (n < 2)\n\t\t{\n\t\t\twriteln (0);\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto f = new real [] [] [] (2, n, n);\n\t\tint d = 0;\n\t\tforeach (ref g; f[d])\n\t\t{\n\t\t\tg[] = 0.0;\n\t\t}\n\t\tforeach (a; 0..n - 1)\n\t\t{\n\t\t\tforeach (b; a + 1..n)\n\t\t\t{\n\t\t\t\tif (p[a] < p[b])\n\t\t\t\t{\n\t\t\t\t\tf[d][b][a] += 1.0;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tf[d][a][b] += 1.0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treal total = 1.0 / n / (n - 1);\n\t\tforeach (t; 0..k)\n\t\t{\n\t\t\td ^= 1;\n\t\t\tforeach (ref g; f[d])\n\t\t\t{\n\t\t\t\tg[] = 0.0;\n\t\t\t}\n\t\t\tforeach (lo; 0..n)\n\t\t\t{\n\t\t\t\tforeach (hi; lo..n)\n\t\t\t\t{\n\t\t\t\t\tauto z = n.iota.array;\n\t\t\t\t\treverse (z[lo..hi + 1]);\n\t\t\t\t\tforeach (a; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (b; 0..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[d][z[a]][z[b]] +=\n\t\t\t\t\t\t\t f[!d][a][b];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tforeach (a; 0..n)\n\t\t\t{\n\t\t\t\tforeach (b; 0..n)\n\t\t\t\t{\n\t\t\t\t\tf[d][a][b] *= total;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treal answer = 0;\n\t\tforeach (a; 0..n - 1)\n\t\t{\n\t\t\tforeach (b; a + 1..n)\n\t\t\t{\n\t\t\t\tanswer += f[d][a][b];\n\t\t\t}\n\t\t}\n\t\twritefln (\"%.20f\", answer);\n\t}\n}\n"}], "src_uid": "0496f5b6c7c159e4448f5b04c45a411b"} {"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner, dcomp.array;\nimport std.typecons;\nimport std.container.rbtree;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, k;\n int[] a;\n sc.read(n, k, a); a[] -= 1;\n\n int[][] l = new int[][n];\n foreach (int i, d; a) {\n l[d] ~= i;\n }\n l.each!((ref v) => v ~= n);\n auto used = new bool[n];\n int sm = 0;\n\n auto tr = redBlackTree!(int[2]);\n foreach (d; a) {\n int ba = l[d][0];\n l[d] = l[d][1..$];\n int nx = l[d][0];\n if (used[d]) {\n tr.removeKey([ba, d].fixed);\n tr.insert([nx, d].fixed);\n continue;\n }\n // add d\n if (tr.length == k) {\n auto u = tr.back();\n tr.removeBack();\n used[u[1]] = false;\n }\n sm++;\n tr.insert([nx, d].fixed);\n used[d] = true;\n }\n writeln(sm);\n return 0;\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */\n// module dcomp.array;\n\n \nT[N] fixed(T, size_t N)(T[N] a) {return a;}\n\n \n \n\n \n \nstruct FastAppender(A) {\n import std.algorithm : max;\n import std.range.primitives : ElementEncodingType;\n import core.stdc.string : memcpy;\n\n private alias T = ElementEncodingType!A;\n private T* _data;\n private size_t len, cap;\n \n @property size_t length() {return len;}\n \n void reserve(size_t nlen) {\n import core.memory : GC;\n if (nlen <= cap) return;\n \n void* nx = GC.malloc(nlen * T.sizeof);\n\n cap = nlen;\n if (len) memcpy(nx, _data, len * T.sizeof);\n _data = cast(T*)(nx);\n }\n \n void opOpAssign(string op : \"~\")(T item) {\n if (len == cap) {\n reserve(max(4, cap*2));\n }\n _data[len++] = item;\n }\n \n void clear() {\n len = 0;\n }\n \n T[] data() {\n return (_data) ? _data[0..len] : null;\n }\n}\n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n\n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto nxtpos = new int[] (n+1);\n auto lst = new int[] (n+1);\n lst[] = n+1;\n \n foreach_reverse (i, e; arr) {\n nxtpos[i] = lst[e];\n lst[e] = i.to!int;\n }\n \n int ans = 0;\n auto rbt = make!(RedBlackTree!(Tuple!(int, int)));\n auto nxtel = new int[] (n+1);\n foreach (i, e; arr) {\n auto cur = tuple(nxtel[e], e);\n \n if (cur in rbt) { \n rbt.removeKey(cur);\n nxtel[e] = nxtpos[i];\n rbt.insert(tuple(nxtel[e], e));\n continue;\n }\n \n if (rbt.length() < k) {\n nxtel[e] = nxtpos[i];\n ans += 1;\n rbt.insert(tuple(nxtel[e], e));\n continue;\n }\n \n rbt.removeBack(); \n nxtel[e] = nxtpos[i];\n ans += 1;\n rbt.insert(tuple(nxtel[e], e));\n }\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner, dcomp.array;\nimport std.typecons;\nimport std.container.rbtree;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, k;\n int[] a;\n sc.read(n, k, a); a[] -= 1;\n\n int[][] l = new int[][n];\n foreach (int i, d; a) {\n l[d] ~= i;\n }\n l.each!((ref v) => v ~= n);\n auto used = new bool[n];\n int sm = 0;\n\n auto tr = redBlackTree!(int[2]);\n foreach (d; a) {\n int ba = l[d][0];\n l[d] = l[d][1..$];\n int nx = l[d][0];\n if (used[d]) {\n tr.removeKey([d, ba].fixed);\n tr.insert([d, nx].fixed);\n continue;\n }\n // add d\n if (tr.length == k) {\n auto u = tr.back();\n tr.removeBack();\n used[u[1]] = false;\n }\n sm++;\n tr.insert([nx, d].fixed);\n used[d] = true;\n }\n writeln(sm);\n return 0;\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */\n// module dcomp.array;\n\n \nT[N] fixed(T, size_t N)(T[N] a) {return a;}\n\n \n \n\n \n \nstruct FastAppender(A) {\n import std.algorithm : max;\n import std.range.primitives : ElementEncodingType;\n import core.stdc.string : memcpy;\n\n private alias T = ElementEncodingType!A;\n private T* _data;\n private size_t len, cap;\n \n @property size_t length() {return len;}\n \n void reserve(size_t nlen) {\n import core.memory : GC;\n if (nlen <= cap) return;\n \n void* nx = GC.malloc(nlen * T.sizeof);\n\n cap = nlen;\n if (len) memcpy(nx, _data, len * T.sizeof);\n _data = cast(T*)(nx);\n }\n \n void opOpAssign(string op : \"~\")(T item) {\n if (len == cap) {\n reserve(max(4, cap*2));\n }\n _data[len++] = item;\n }\n \n void clear() {\n len = 0;\n }\n \n T[] data() {\n return (_data) ? _data[0..len] : null;\n }\n}\n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n\n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner, dcomp.array;\nimport std.typecons;\nimport std.container.rbtree;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, k;\n int[] a;\n sc.read(n, k, a); a[] -= 1;\n\n int[][] l = new int[][n];\n foreach (int i, d; a) {\n l[d] ~= i;\n }\n l.each!((ref v) => v ~= n);\n auto used = new bool[n];\n int sm = 0;\n\n auto tr = redBlackTree!(int[2]);\n foreach (d; a) {\n l[d] = l[d][1..$];\n int nx = l[d][0];\n if (used[d]) continue;\n // add d\n if (tr.length == k) {\n auto u = tr.back();\n tr.removeBack();\n used[u[1]] = false;\n }\n sm++;\n tr.insert([nx, d].fixed);\n used[d] = true;\n }\n writeln(sm);\n return 0;\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */\n// module dcomp.array;\n\n \nT[N] fixed(T, size_t N)(T[N] a) {return a;}\n\n \n \n\n \n \nstruct FastAppender(A) {\n import std.algorithm : max;\n import std.range.primitives : ElementEncodingType;\n import core.stdc.string : memcpy;\n\n private alias T = ElementEncodingType!A;\n private T* _data;\n private size_t len, cap;\n \n @property size_t length() {return len;}\n \n void reserve(size_t nlen) {\n import core.memory : GC;\n if (nlen <= cap) return;\n \n void* nx = GC.malloc(nlen * T.sizeof);\n\n cap = nlen;\n if (len) memcpy(nx, _data, len * T.sizeof);\n _data = cast(T*)(nx);\n }\n \n void opOpAssign(string op : \"~\")(T item) {\n if (len == cap) {\n reserve(max(4, cap*2));\n }\n _data[len++] = item;\n }\n \n void clear() {\n len = 0;\n }\n \n T[] data() {\n return (_data) ? _data[0..len] : null;\n }\n}\n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n\n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n"}], "src_uid": "a9d6e888fdd10b4e6f2404f2b99ca5ef"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, x;\n readf(\"%s %s\", &n, &x);\n readln;\n \n auto isFree = new bool[] (2^^n + 1);\n isFree[] = true;\n isFree[0] = false;\n if (x < 2^^n) { isFree[x] = false; }\n \n int nextFreeVal(int idx) {\n while (!isFree[idx]) { ++idx; }\n return idx;\n }\n \n int sm = 0;\n int[] ans;\n int nxtsm = 1;\n while ((nxtsm = nextFreeVal(nxtsm)) < 2^^n && (sm ^ nxtsm) < 2^^n) {\n isFree[nxtsm] = false;\n if ((x ^ nxtsm) < 2^^n) { isFree[nxtsm ^ x] = false; }\n ans ~= sm ^ nxtsm;\n sm = nxtsm;\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(\" \").writeln;\n}", "positive_code": [{"source_code": "module D;\n\nimport std.typecons;\nimport core.stdc.stdio;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.container.rbtree;\n\nalias PII = Tuple!(int, int);\nalias PLL = Tuple!(long, long);\n\nvoid main()\n{\n int n, x;\n scanf(\"%d%d\", &n, &x);\n\n bool[int] mm;\n\n int[] ans;\n mm[0] = true;\n mm[x] = true;\n\n int prefix = 0;\n\n foreach (i; 1 .. (1 << n))\n {\n if (i !in mm)\n {\n ans ~= (i ^ prefix);\n\n prefix = i;\n mm[prefix] = true;\n mm[prefix ^ x] = true;\n\n }\n }\n\n writeln(ans.length);\n if (ans.length > 0)\n writefln(\"%(%d%| %)\", ans);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long MOD = 10^^9 + 7;\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto X = s[1];\n\n if (N == 1 && X == 1) {\n writeln(0);\n return;\n }\n if (N == 1) {\n writeln(1);\n writeln(1);\n return;\n }\n\n auto Y = N.iota.filter!(i => bsr(X) != i).map!(i => 1 << i).array;\n int[] ans;\n\n void dfs(int idx) {\n if (idx == 0) {\n ans ~= Y[idx];\n return;\n }\n dfs(idx-1);\n ans ~= Y[idx];\n dfs(idx-1);\n }\n\n dfs(Y.length.to!int-1);\n ans.length.writeln;\n ans.map!(to!string).join(\" \").writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, x;\n readf(\"%s %s\", &n, &x);\n readln;\n \n auto isFree = new bool[] (2^^n + 1);\n isFree[] = true;\n isFree[0] = false;\n if (x < 2^^n) { isFree[x] = false; }\n \n int nextFreeVal(int idx) {\n while (!isFree[idx]) { ++idx; }\n return idx;\n }\n \n int sm = 0;\n int[] ans;\n int nxtsm = 1;\n while ((nxtsm = nextFreeVal(nxtsm)) < 2^^n && (sm ^ nxtsm) < 2^^n) {\n ans ~= sm ^ nxtsm;\n sm = nxtsm;\n isFree[sm] = false;\n if ((sm ^ x) < 2^^n) { isFree[sm ^ x] = false; }\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(\" \").writeln;\n}"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\nimport std.bitmanip;\nimport std.container.rbtree;\n\nvoid main() {\n int n, x;\n readf!\" %d %d\" (n, x);\n immutable m = 1 << n;\n int[] s;\n auto t = redBlackTree!int ();\n foreach (i; 1 .. m) {\n if (i != x) {\n t.insert (i);\n }\n }\n while (!t.empty) {\n int i = t.front;\n s ~= i;\n t.removeFront();\n t.removeKey (i ^ x);\n }\n if (!s.length) {\n writeln (0);\n return;\n }\n auto a = new int[s.length];\n a[0] = s[0];\n foreach (i; 1 .. s.length) {\n a[i] = s[i] ^ s[i-1];\n }\n debug stderr.writeln (s);\n writeln (a.length);\n writefln (\"%(%s %)\", a);\n}\n\n"}], "negative_code": [], "src_uid": "16c2969b3532c912221825af6040b5c7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto x = RD;\r\n\t\tauto w = RDA;\r\n\r\n\t\tlong tot;\r\n\t\twhile (!w.empty)\r\n\t\t{\r\n\t\t\tlong y;\r\n\t\t\tif (tot+w.front != x)\r\n\t\t\t{\r\n\t\t\t\ty = w.front; w.popFront;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\ty = w.back; w.popBack;\r\n\t\t\t}\r\n\t\t\ttot += y;\r\n\t\t\tans[ti] ~= y;\r\n\t\t}\r\n\t\tif (tot == x)\r\n\t\t\tans[ti].length = 0;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\tif (e.empty)\r\n\t\t\twriteln(\"NO\");\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln(\"YES\");\r\n\t\t\te.map!(to!string).join(\" \").writeln;\r\n\t\t}\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\n\nvoid solve()\n{\n\tint n = readInt!int;\n\tint x = readInt!int;\n\tauto a = new int[](n); foreach(ref ai; a) ai = readInt!int;\n\tint acc = 0;\n\tforeach(i, ref ai; a)\n\t{\n\t\tacc += ai;\n\t\tif (acc == x)\n\t\t{\n\t\t\tif (i + 1 < n) \n\t\t\t{\n\t\t\t\tswap(a[i+1], a[i]);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\treturn \"NO\".writeln;\n\t\t\t}\n\t\t}\n\t}\n\t\"YES\".writeln;\n\tforeach(ai; a) ai.write(\" \"); writeln; return;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n, x;\r\n readf!\"%d %d\\n\"(n, x);\r\n int[] w = readln.split.map!(to!int).array;\r\n if (w.sum == x)\r\n writeln(\"NO\");\r\n else\r\n {\r\n writeln(\"YES\");\r\n foreach (i; 0 .. n)\r\n {\r\n if (x == w[i])\r\n swap(w[i], w[i + 1]);\r\n writef!\"%d \"(w[i]);\r\n x -= w[i];\r\n }\r\n writeln();\r\n }\r\n }\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.random;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, x;\r\n\t\treadf !(\" %s %s\") (n, x);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tif (x == 0 || x == sum (a) || (a.minElement == a.maxElement &&\r\n\t\t 0 < x && x < sum (a) && x % a[0] == 0))\r\n\t\t{\r\n\t\t\twriteln (\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\trandomShuffle (a);\r\n\t\t\tbool ok = true;\r\n\t\t\tint cur = 0;\r\n\t\t\tforeach (ref c; a)\r\n\t\t\t{\r\n\t\t\t\tcur += c;\r\n\t\t\t\tok &= (cur != x);\r\n\t\t\t}\r\n\t\t\tif (ok)\r\n\t\t\t{\r\n\t\t\t\twriteln (\"YES\");\r\n\t\t\t\twritefln !(\"%(%s %)\") (a);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "85383c9e802348a3153e7f98ce278f09"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!long;\r\n\r\n auto solve() {\r\n foreach(_; 0..QN) {\r\n auto N = scan!int;\r\n auto L = scan!int;\r\n auto A = scan!long(N);\r\n\r\n long[] bits;\r\n foreach(i; 0..L) {\r\n long count;\r\n foreach(ref a; A) {\r\n if (a % 2 == 1) count++;\r\n a /= 2;\r\n }\r\n\r\n bits ~= count > N / 2 ? 1 : 0;\r\n }\r\n\r\n long ans;\r\n foreach_reverse(b; bits) {\r\n ans *= 2;\r\n ans += b;\r\n }\r\n \r\n ans.writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n", "positive_code": [{"source_code": "import std;\n\nT\nread (alias T, string end = \"\") () {\n T x;\n readf!(\"%s\" ~ end)(x);\n return x;\n}\n\nvoid main () {\n immutable tests = read!(uint, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n immutable n = read!(uint, \" \");\n immutable l = read!(uint, \"\\n\");\n\n immutable vec =\n readln.chomp.split(' ')\n .to!(uint[]);\n\n iota(0, l)\n .map!(bit =>\n vec.count!(x => cast(bool)(x & (1 << bit)))\n > n / 2)\n .array\n .to!BitArray\n .opCast!(size_t[])\n .front\n .writeln;\n }\n}\n// \"\"\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto l = RD!int;\r\n\t\tauto x = RDA;\r\n\r\n\t\tauto cnt = new long[](l);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..l)\r\n\t\t\t{\r\n\t\t\t\tauto bit = 1L << j;\r\n\t\t\t\tif (x[i] & bit)\r\n\t\t\t\t\t++cnt[j];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..l)\r\n\t\t{\r\n\t\t\tauto bit = 1L << i;\r\n\t\t\tif (cnt[i] >= (n+1)/2)\r\n\t\t\t\tans[ti] |= bit;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "84c88932e107e1d1f80b44aec88134e4"} {"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.container;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[4] s;\n\tint capacity = 4;\n\tforeach (i; 0 .. n)\n\t{\n\t\tint num;\n\t\tscanf(\"%d\", &num);\n\t\ts[num - 1]++;\n\t}\n\n\tint result = 0;\n\tfor (int i = 3; i >= 0; i--)\n\t{\n\t\tswitch (i)\n\t\t{\n\t\t\tcase (3): result += s[i]; break;\n\t\t\tcase (2):{\n\t\t\t\tresult += s[i];\n\t\t\t\ts[0] -= min(s[i], s[0]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase (1):{\n\t\t\t\tresult += (s[i] / 2);\n\t\t\t\ts[i] -= (s[i] / 2) * 2;\n\t\t\t\tresult += s[i];\n\t\t\t\ts[0] -= min(2*s[i], s[0]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase (0):{\n\t\t\t\tresult += (s[i] / 4);\n\t\t\t\ts[i] -= (s[i] / 4) * 4;\n\t\t\t\tresult += s[i] > 0 ? 1 : 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:continue;\n\t\t}\n\t}\n\tprintf(\"%d\", result);\n\treturn 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\nimport std.range;\n\n//----------------\n\nvoid main(){\n auto n = readln.chomp.to!int;\n auto groups = readln.chomp.split(\" \").map!(to!int);\n int[int] hash = [1: 0, 2: 0, 3: 0, 4: 0];\n foreach(g; groups){ hash[g] += 1; }\n int taxiNum;\n\n taxiNum += hash[4];\n taxiNum += hash[3];\n\n hash[1] = max(0, hash[1] - hash[3]);\n taxiNum += hash[2] / 2;\n\n hash[2] = hash[2] % 2;\n if(hash[2]){ taxiNum += 1; hash[1] = max(0, hash[1] - 2); }\n\n taxiNum += hash[1] / 4;\n if(hash[1] % 4){ taxiNum += 1; }\n\n taxiNum.writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.conv : to;\nimport std.string : strip;\n\nauto min(T)(T a, T b)\n{\n return a <= b ? a : b;\n}\n\nvoid main()\n{\n readln;\n uint[5] nums;\n foreach(group; readln.strip.splitter(' ').array.sort.group)\n nums[to!uint(group[0])] = group[1];\n \n uint taxiNum = nums[4];\n\n auto oneAndTree = min(nums[3], nums[1]);\n\n taxiNum += oneAndTree;\n nums[1] -= oneAndTree;\n nums[3] -= oneAndTree;\n taxiNum += nums[3];\n\n auto ones = nums[1]/4;\n taxiNum += ones;\n nums[1] -= ones*4;\n\n auto twos = nums[2]/2;\n taxiNum += twos;\n nums[2] -= twos*2;\n\n if ((nums[1] + nums[2]) > 0)\n taxiNum += (nums[1] + nums[2]*2) > 4 ? 2 : 1;\n\n writeln(taxiNum);\n}"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\n\nint main() {\n auto s = stdin.byLine;\n s.popFront();\n auto arr = s.front.split(\" \");\n int[4] grps;\n foreach (g; arr) {\n grps[to!int(g) - 1]++;\n }\n int num = grps[3];\n if (grps[0] > grps[2]) grps[0] -= grps[2];\n else grps[0] = 0;\n if (grps[1] % 2) {\n if (grps[0] <= 2) grps[0] = 0;\n else grps[0] -= 2;\n grps[1] /= 2;\n grps[1]++;\n } else {\n grps[1] /= 2;\n }\n if (grps[0] % 4) grps[0] = grps[0] / 4 + 1;\n else grps[0] /= 4;\n num += grps[2] + grps[1] + grps[0];\n writeln(num);\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.string;\nimport std.range;\nimport std.conv;\nimport std.algorithm;\n\nvoid main() {\n\treadln();\n\tint[] a = readln().chomp.split(\" \").map!(to!int).array;\n\tint[] count = new int[5];\n\tforeach (i; a) {\n\t\tcount[i]++;\n\t}\n\ta.sort();\n\tint taxis = 0;\n\tforeach (i; a.retro) {\n\t\tif (count[i] > 0) {\n\t\t\tint cap = 4 - i;\n\t\t\tcount[i]--;\n\t\t\tfor (int j = i; j >= 1; j--) {\n\t\t\t\tif (count[j] > 0 && cap >= j) {\n\t\t\t\t\tcap -= j;\n\t\t\t\t\tcount[j]--;\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttaxis++;\n\t\t}\n\t}\n\twriteln(taxis);\n\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.algorithm;\nimport std.container;\nimport std.math;\n\nvoid main() {\n readln;\n auto s = readln.chomp.split.map!(to!int);\n\n int[5] a;\n foreach (e; s) a[e]++;\n a[1] = max(a[1] - a[3], 0);\n\n writeln(a[4] + a[3] + (a[1] + 2 * a[2] + 3) / 4);\n}\n"}, {"source_code": "\ufeffimport std.c.stdio;\nimport std.algorithm;\nimport std.math;\n\nint main()\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[] groups = new int[4];\n\tint temp;\n\tforeach(i; 0..n)\n\t{\n\t\tscanf(\"%d\", &temp);\n\t\tgroups[temp-1]++;\n\t}\n\tint ansv;\n\t//4\n\tansv += groups[3];\n\t// 1 and 3\n\tint temp13 = min(groups[0], groups[2]);\n\tansv += temp13;\n\tgroups[0] -= temp13;\n\tgroups[2] -= temp13;\n\t//2\n\tansv += groups[1]/2;\n\tgroups[1] %= 2;\n\t//1 and 2\n\tif(groups[1] != 0) {\n\t\tansv++;\n\t\tgroups[1] = 0;\n\t\tif(groups[0] > 2)\n\t\t\tgroups[0] -= 2;\n\t\telse\n\t\t\tgroups[0] = 0;\n\t}\n\tif(groups[0] % 4 == 0)\n\t\tansv += groups[0]/4;\n\telse\n\t\tansv += groups[0]/4 + 1; \n\t//3\n\tansv += groups[2];\n\tprintf(\"%d\", ansv);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!int;\n auto s = next!int(n);\n int[5] cnt;\n foreach(si; s) cnt[si]++;\n int res = 0;\n res += cnt[4];\n res += cnt[3];\n cnt[1] -= min(cnt[3], cnt[1]);\n auto p21 = min(cnt[2], cnt[1] / 2);\n res += p21;\n cnt[2] -= p21;\n cnt[1] -= 2 * p21;\n auto p21b = min(cnt[2], cnt[1]);\n res += p21b;\n cnt[2] -= p21b;\n cnt[1] -= p21b;\n res += cnt[2] / 2 + cnt[2] % 2;\n res += cnt[1] / 4;\n if (cnt[1] % 4 != 0)\n res += 1;\n return res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "void main() {\n import std.algorithm : min;\n import std.stdio : readf, writeln;\n\n int n;\n readf!\"%d\"(n);\n int[4] a;\n foreach (_; 0 .. n) {\n readf!\" %d\"(n);\n a[n - 1]++;\n }\n\n int res;\n res += a[3];\n a[0] -= min(a[0], a[2]);\n res += a[2];\n if (a[1] % 2 == 1) {\n a[0] -= min(a[0], 2);\n res++;\n }\n res += a[1] / 2;\n res += a[0] / 4;\n if (a[0] % 4 != 0) {\n res++;\n }\n writeln(res);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.container;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[4] s;\n\tforeach (i; 0 .. n)\n\t{\n\t\tint num;\n\t\tscanf(\"%d\", &num);\n\t\ts[num - 1]++;\n\t}\n\n\tint m = min(s[2], s[0]);\n\ts[3] += m;\n\ts[2] -= m;\n\ts[0] -= m;\n\tm = s[1] / 2;\n\ts[1] -= m * 2;\n\ts[3] += m;\n\tm = min(s[0], s[1]);\n\ts[0] -= m;\n\ts[1] -= m;\n\ts[3] += m;\n\tm = s[0] / 4;\n\ts[3] += m;\n\ts[0] -= m * 4;\n\tif (s[0] > 0) {\n\t\ts[3] += 1;\n\t\ts[0] = 0;\n\t}\n\tprintf (\"%d\", s[0] + s[1] + s[2] + s[3]);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.container;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[4] s;\n\tint capacity = 4;\n\tforeach (i; 0 .. n)\n\t{\n\t\tint num;\n\t\tscanf(\"%d\", &num);\n\t\ts[num - 1]++;\n\t}\n\n\tint result = 0;\n\tfor (int i = 3; i >= 0; i--)\n\t{\n\t\tswitch (i)\n\t\t{\n\t\t\tcase (3): result += s[i]; break;\n\t\t\tcase (2):{\n\t\t\t\tresult += s[i];\n\t\t\t\ts[0] -= min(s[i], s[0]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase (1):{\n\t\t\t\tresult += (s[i] / 2);\n\t\t\t\ts[i] -= (s[i] / 2) * 2;\n\t\t\t\tresult += s[i];\n\t\t\t\ts[0] -= min(2*s[i], s[0]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase (0):{\n\t\t\t\tresult += (s[i] / 4);\n\t\t\t\ts[i] -= (s[i] / 4) * 4;\n\t\t\t\tresult += s[i];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:continue;\n\t\t}\n\t}\n\tprintf(\"%d\", result);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.container;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[4] s;\n\tforeach (i; 0 .. n)\n\t{\n\t\tint num;\n\t\tscanf(\"%d\", &num);\n\t\ts[num - 1]++;\n\t}\n\n\tint m = min(s[2], s[0]);\n\ts[3] += m;\n\ts[2] -= m;\n\ts[0] -= m;\n\tm = s[1] / 2;\n\ts[1] -= m * 2;\n\ts[3] += m;\n\tprintf (\"%d\", s[0] + s[1] + s[2] + s[3]);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.container;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[4] s;\n\tforeach (i; 0 .. n)\n\t{\n\t\tint num;\n\t\tscanf(\"%d\", &num);\n\t\ts[num - 1]++;\n\t}\n\n\tint m = min(s[2], s[0]);\n\ts[3] += m;\n\ts[2] -= m;\n\ts[0] -= m;\n\tm = s[1] / 2;\n\ts[1] -= m * 2;\n\ts[3] += m;\n\tm = min(s[0], s[1]);\n\ts[0] -= m;\n\ts[1] -= m;\n\ts[3] += m;\n\tm = s[0] / 4;\n\ts[3] += m;\n\ts[0] -= m * 4;\n\tprintf (\"%d\", s[0] + s[1] + s[2] + s[3]);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.container;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[4] s;\n\tforeach (i; 0 .. n)\n\t{\n\t\tint num;\n\t\tscanf(\"%d\", &num);\n\t\ts[num - 1]++;\n\t}\n\n\tint m = min(s[2], s[0]);\n\ts[3] += m;\n\ts[2] -= m;\n\ts[0] -= m;\n\tm = s[1] / 2;\n\ts[1] -= m * 2;\n\ts[3] += m;\n\tm = s[0] / 4;\n\ts[3] += m;\n\ts[0] -= m * 4;\n\tprintf (\"%d\", s[0] + s[1] + s[2] + s[3]);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.conv;\n\nint main() {\n auto s = stdin.byLine;\n s.popFront();\n auto arr = s.front.split(\" \");\n int[4] grps;\n foreach (g; arr) {\n grps[to!int(g) - 1]++;\n }\n int num = grps[3];\n if (grps[0] > grps[2]) grps[0] -= grps[2];\n else grps[0] = 0;\n if (grps[1] % 2) {\n if (grps[0] <= 2) grps[0] = 0;\n else grps[0] -= 2;\n grps[1] /= 2;\n grps[1]++;\n } else {\n grps[2] /= 2;\n }\n if (grps[0] % 4) grps[0] = grps[0] / 4 + 1;\n else grps[0] /= 4;\n num += grps[2] + grps[1] + grps[0];\n writeln(num);\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.algorithm;\nimport std.container;\nimport std.math;\n\nvoid main() {\n readln;\n auto s = readln.chomp.split.map!(to!int).array.sort!(\"a > b\").array;\n\n int count = 0;\n\n count += s.count(4);\n s = s.filter!(\"a != 4\").array;\n\n count += s.count(3);\n for (int i = 0; i < s.count(3); i++) {\n if (s.back == 1) s.popBack;\n }\n\n count += (s.count(2) / 2.0).ceil;\n\n count += (s.count(1) / 4.0).ceil;\n\n count.writeln;\n}\n"}, {"source_code": "\ufeffimport std.c.stdio;\nimport std.algorithm;\nimport std.math;\n\nint main()\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[] groups = new int[4];\n\tint temp;\n\tforeach(i; 0..n)\n\t{\n\t\tscanf(\"%d\", &temp);\n\t\tgroups[temp-1]++;\n\t}\n\tint ansv;\n\t//4\n\tansv += groups[3];\n\t// 1 and 3\n\tint temp13 = min(groups[0], groups[2]);\n\tansv += temp13;\n\tgroups[0] -= temp13;\n\tgroups[2] -= temp13;\n\t//2\n\tansv += groups[1]/2;\n\tgroups[1] %= 2;\n\t//1 and 2\n\tif(groups[1] != 0) {\n\t\tansv++;\n\t\tgroups[1] = 0;\n\t\tif(groups[0] > 2)\n\t\t\tgroups[0] -= 2;\n\t\telse\n\t\t\tgroups[0] = 0;\n\t\tif(groups[0] % 4 == 0)\n\t\t\tansv += groups[0]/4;\n\t\telse\n\t\t\tansv += groups[0]/4 + 1; \n\t}\n\t//3\n\tansv += groups[2];\n\tprintf(\"%d\", ansv);\n\treturn 0;\n}\n"}, {"source_code": "\ufeffimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[] arr = [0, 0, 0, 0];\n\tint temp;\n\tforeach(i; 0..n)\n\t{\n\t\tscanf(\"%d\", &temp);\n\t\tarr[temp-1]++;\n\t}\n\tif(arr[0] > arr[2])\n\t\tarr[2]=0;\n\telse\n\t\tarr[0] = 0;\n\tif(arr[1] % 2 == 0)\n\t\tarr[1] /= 2;\n\telse\n\t{\n\t\tarr[1] /= 2;\n\t\tif(arr[0] == 0)\n\t\t\tarr[0]++;\n\t}\n\tprintf(\"%d\", arr[0] + arr[1] + arr[2] + arr[3]);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n auto n = next!int;\n auto s = next!int(n);\n int[5] cnt;\n foreach(si; s) cnt[si]++;\n int res = 0;\n res += cnt[4];\n res += cnt[3];\n cnt[1] -= min(cnt[3], cnt[1]);\n auto p21 = min(cnt[2], cnt[1] / 2);\n res += p21;\n cnt[2] -= p21;\n cnt[1] -= 2 * p21;\n auto p21b = min(cnt[2], cnt[1]);\n res += p21b;\n cnt[2] -= p21b;\n cnt[1] -= p21b;\n res += cnt[2] / 2 + cnt[2] % 2;\n res += cnt[1] / 4 + cnt[1] % 4;\n return res.writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}, {"source_code": "void main() {\n import std.algorithm : sort, maxElement;\n import std.stdio : readf, writeln;\n import std.range : enumerate, dropExactly, retro;\n\n int n;\n readf!\"%d\"(n);\n int[] s;\n s.length = n;\n foreach (i; 0 .. n) {\n readf!\" %d\"(s[i]);\n }\n\n enum maxCapacity = 4;\n int res;\n bool[int] whatever;\n foreach (i; 0 .. n) {\n whatever[i] = false;\n }\n auto r = s.sort.retro;\n foreach (i, g1; r.enumerate) {\n auto available = maxCapacity - g1;\n if (whatever[i]) {\n continue;\n }\n res++;\n whatever[i] = true;\n\n if (available < r.maxElement) {\n continue;\n }\n\n foreach (j, g2; r.enumerate.dropExactly(i + 1)) {\n if (!whatever[j] && g2 <= available) {\n whatever[j] = true;\n available -= g2;\n }\n if (available < r.maxElement) {\n break;\n }\n }\n }\n writeln(res);\n}\n"}, {"source_code": "void main() {\n import std.algorithm : sort;\n import std.stdio : readf, writeln;\n import std.range : enumerate, dropExactly, retro;\n\n int n;\n readf!\"%d\"(n);\n int[] s;\n s.length = n;\n foreach (i; 0 .. n) {\n readf!\" %d\"(s[i]);\n }\n\n enum maxCapacity = 4;\n int res;\n bool[int] whatever;\n foreach (i; 0 .. n) {\n whatever[i] = false;\n }\n auto r = s.sort.retro.enumerate;\n foreach (i, g1; r) {\n auto available = maxCapacity - g1;\n if (whatever[i]) {\n continue;\n }\n if (!available) {\n res++;\n continue;\n whatever[i] = true;\n }\n res++;\n\n foreach (j, g2; r.dropExactly(i + 1)) {\n if (!whatever[j] && g2 <= available) {\n whatever[j] = true;\n available -= g2;\n break;\n }\n }\n }\n writeln(res);\n}\n"}], "src_uid": "371100da1b044ad500ac4e1c09fa8dcb"} {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\nimmutable int MX = 5000;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto mxle = new int[] (n+1);\n foreach (i; 1 .. n+1) {\n foreach_reverse (j; 1 .. i+1) {\n if (arr[j] == arr[i]) { mxle[i] = j; }\n }\n }\n \n auto mxr = new int[] (n+1);\n foreach (i; 1 .. n+1) {\n foreach (j; i .. n+1) {\n if (arr[i] == arr[j]) { mxr[i] = j; }\n }\n }\n \n debug { mxle.writeln; mxr.writeln; }\n \n auto dp = new int[] (n+1);\n foreach (i; 1 .. n+1) {\n dp[i] = dp[i-1];\n \n int cxor = 0, borderle = i, borderr = i;\n foreach_reverse (j; 1 .. i+1) {\n borderr = max(borderr, mxr[j]);\n if (borderr > i) { break; }\n \n if (j == mxr[j]) { cxor ^= arr[j]; }\n \n borderle = min(borderle, mxle[j]);\n if (borderle < j) { continue; }\n \n debug { writeln(i, ' ', j, ' ', cxor); }\n \n dp[i] = max(dp[i], cxor + dp[j-1]);\n }\n }\n \n debug { dp.writeln; }\n \n dp[n].writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n immutable int MAX = 5010;\n\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n auto L = new int[](MAX);\n auto R = new int[](MAX);\n fill(L, MAX);\n fill(R, -1);\n\n foreach (i; 0..N) {\n L[A[i]] = min(L[A[i]], i);\n R[A[i]] = max(R[A[i]], i);\n }\n\n auto mem = new int[](N);\n fill(mem, -1);\n\n int dp(int i) {\n if (i >= N) return 0;\n if (mem[i] >= 0) return mem[i];\n\n if (L[A[i]] != i)\n return dp(i + 1);\n int tar = R[A[i]];\n int pos = i + 1;\n int score = A[i];\n while (pos < N && pos <= tar) {\n if (L[A[pos]] < i) {\n score = 0;\n break;\n }\n else if (L[A[pos]] == pos) {\n score ^= A[pos];\n }\n tar = max(tar, R[A[pos]]);\n pos += 1;\n }\n\n return mem[i] = max(dp(i+1), score + dp(tar+1));\n }\n\n dp(0).writeln;\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\nimmutable int MX = 5000;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto arr = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto mxle = new int[] (n+1);\n foreach (i; 1 .. n+1) {\n foreach_reverse (j; 1 .. i+1) {\n if (arr[j] == arr[i]) { mxle[i] = j; }\n }\n }\n \n auto mxr = new int[] (n+1);\n foreach (i; 1 .. n+1) {\n foreach (j; i .. n+1) {\n if (arr[i] == arr[j]) { mxr[i] = j; }\n }\n }\n \n debug { mxle.writeln; mxr.writeln; }\n \n auto dp = new int[] (n+1);\n foreach (i; 1 .. n+1) {\n dp[i] = dp[i-1];\n \n int cxor = 0, mxxor = 0, borderle = i, borderr = i;\n foreach_reverse (j; 1 .. i+1) {\n borderr = max(borderr, mxr[j]);\n if (borderr > i) { break; }\n \n if (j == mxr[j]) { cxor ^= arr[j]; }\n \n borderle = min(borderle, mxle[j]);\n if (borderle < j) { continue; }\n \n debug { writeln(i, ' ', j, ' ', cxor); }\n \n dp[i] = max(dp[i], cxor + dp[j-1]);\n }\n }\n \n debug { dp.writeln; }\n \n dp[n].writeln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n immutable int MAX = 5010;\n\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n auto L = new int[](MAX);\n auto R = new int[](MAX);\n fill(L, MAX);\n fill(R, -1);\n\n foreach (i; 0..N) {\n L[A[i]] = min(L[A[i]], i);\n R[A[i]] = max(R[A[i]], i);\n }\n\n auto mem = new int[](N);\n fill(mem, -1);\n\n int dp(int i) {\n if (i >= N) return 0;\n if (mem[i] >= 0) return mem[i];\n\n if (L[A[i]] != i)\n return dp(i + 1);\n int tar = R[A[i]];\n int pos = i + 1;\n int score = A[i];\n while (pos < N && pos <= tar) {\n if (L[A[pos]] < i) {\n score = 0;\n break;\n }\n else if (L[A[pos]] == pos) {\n score ^= A[pos];\n }\n tar = max(tar, R[A[pos]]);\n pos += 1;\n }\n\n writeln(i, \" \", tar);\n return mem[i] = max(dp(i+1), score + dp(tar+1));\n }\n\n dp(0).writeln;\n}\n"}], "src_uid": "158a9e5471928a9c7b4e728b68a954d4"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1405/problem/B\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\n while(t--) {\n int n = readln.chomp.to!int;\n long[] a = readln.split.map!(to!long).array;\n\n long ans = long.max;\n long sum = 0;\n foreach(x; a) {\n sum += x;\n ans = min(ans, sum);\n }\n\n writefln(\"%s\", -ans);\n }\n}\n\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nint inz(long t){ return to!int(t); } \nstatic string[] tempstr;\nT rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }\nT[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\n\nvoid play(){\n int n;\n n = to!int(rd);\n ll[] arr;\n arr = rdarr;\n auto set = redBlackTree!(Tuple!(ll, ll));\n foreach(i; 0..n){\n auto t = tuple(arr[i], to!long(i));\n set.insert(t);\n }\n ll cost = 0;\n ll posmon = 0;\n foreach(i; 0..n){\n auto t = tuple(arr[i], to!long(i));\n set.removeKey(t);\n if(arr[i] < 0 && posmon > 0){\n ll take = min(posmon, - arr[i]);\n posmon -= take;\n arr[i] += take;\n }\n cost -= min(arr[i], 0);\n posmon += max(arr[i], 0);\n }\n writeln(cost);\n}\n\nint main(){\n ll t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\n\t\tlong cnt;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tcnt += a[i];\n\t\t\tif (cnt < 0)\n\t\t\t{\n\t\t\t\tans[ti] += abs(cnt);\n\t\t\t\tcnt = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "bd0b14e53ade1207022464ebafdf8c9a"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n auto s = readln.chomp;\n \n auto ones = s.count!(x => x == '1');\n \n auto left = s.filter!(x => x != '1').array;\n \n debug { left.writeln; }\n \n auto parts = left.findSplitBefore(\"2\");\n \n debug { parts.each!writeln; }\n \n auto ans = parts[0] ~ (cast(dchar)'1').repeat(ones).array ~ parts[1];\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n auto S = readln.chomp;\n auto N = S.length.to!int;\n string A = \"\";\n string B = \"\";\n\n foreach (i; 0..N) {\n if (S[i] == '1') A ~= S[i];\n else B ~= S[i];\n }\n\n if (B.empty) {\n A.writeln;\n return;\n }\n\n int x = B.length.to!int;\n foreach (i; 0..B.length.to!int) {\n if (B[i] == '2') {\n x = i;\n break;\n }\n }\n\n writeln(B[0..x] ~ A ~ B[x..$]);\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\nvoid main() {\n dchar[] s = readln.chomp.to!(dchar[]);\n int n = s.length.to!int;\n\n int cnt;\n foreach (i ; 0 .. n) {\n if (s[i] == '1') cnt++;\n }\n\n foreach (i ; 0 .. n) {\n if (s[i] == '0') {\n write('0');\n }\n else if (s[i] == '1') {\n continue;\n }\n else {\n while (cnt > 0) {\n write('1');\n cnt--;\n }\n write('2');\n }\n }\n\n while (cnt > 0) {\n write('1');\n cnt--;\n }\n \n writeln;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\nvoid main() {\n dchar[] s = readln.chomp.to!(dchar[]);\n int n = s.length.to!int;\n\n int l, r;\n\n while (l < n) {\n while (r < n && s[r] != '0') {\n r++;\n }\n s[l..r].sort();\n r++;\n l = r;\n }\n\n debug {\n writeln(s);\n }\n\n l = r = 0;\n\n while (l < n) {\n while (r < n && s[r] != '2') {\n r++;\n }\n s[l..r].sort();\n r++;\n l = r;\n }\n\n writeln(s);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n"}], "src_uid": "91cefa6793e77b3e4f4896616a164ff2"} {"source_code": "import std.stdio, std.string;\n\nvoid solve(int[] a, int k, int x)\n{\n auto n = cast(int)a.length;\n auto f = new long[n];\n auto b = new long[n];\n f[0] = 0;\n foreach (i; 1 .. n)\n {\n f[i] = f[i - 1] | a[i - 1];\n }\n b[n - 1] = 0;\n for (int i = n - 2; i >= 0; -- i)\n {\n b[i] = b[i + 1] | a[i + 1];\n }\n long ans = 0;\n foreach (i; 0 .. n)\n {\n long val = a[i];\n foreach (j; 0 .. k)\n {\n val *= x;\n }\n val |= f[i];\n val |= b[i];\n if (val > ans)\n {\n ans = val;\n }\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n, k, x;\n while (readf(\"%d %d %d\\n\", &n, &k, &x) == 3)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a, k, x);\n }\n return 0;\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n, k, x;\n readf(\"%s %s %s\", &n, &k, &x);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto orr = new int[][] (n, 2);\n \n foreach (i, e; arr) {\n orr[i][0] = i == 0 ? e : orr[i-1][0] | e;\n }\n foreach_reverse (i, e; arr) {\n orr[i][1] = i == n-1 ? e : orr[i+1][1] | e;\n }\n \n long m = pow(x, k);\n long ans = 0;\n foreach (i, e; arr) {\n long val = m * e;\n int leor = i == 0 ? 0 : orr[i-1][0];\n int ror = i == n-1 ? 0 : orr[i+1][1];\n ans = max(ans, leor | val | ror);\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "b544f02d12846026f6c76876bc6bd079"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong start = a[0];\n\t\tlong [] d;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\td ~= a[i] - a[i - 1];\n\t\t}\n\n\t\tlong up = 0;\n\t\tforeach (ref y; d)\n\t\t{\n\t\t\tup += max (y, 0L);\n\t\t}\n\t\twriteln ((start + up + 1) >> 1);\n\n\t\tint q;\n\t\treadf !(\" %s\") (q);\n\t\tforeach (p; 0..q)\n\t\t{\n\t\t\tint l, r, x;\n\t\t\treadf !(\" %s %s %s\") (l, r, x);\n\t\t\tl -= 1;\n\t\t\tr -= 1;\n\t\t\tif (l == 0)\n\t\t\t{\n\t\t\t\tstart += x;\n\t\t\t}\n\t\t\tif (l > 0)\n\t\t\t{\n\t\t\t\tup -= max (d[l - 1], 0L);\n\t\t\t\td[l - 1] += x;\n\t\t\t\tup += max (d[l - 1], 0L);\n\t\t\t}\n\t\t\tif (r < n - 1)\n\t\t\t{\n\t\t\t\tup -= max (d[r], 0L);\n\t\t\t\td[r] -= x;\n\t\t\t\tup += max (d[r], 0L);\n\t\t\t}\n\t\t\twriteln ((start + up + 1) >> 1);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tauto n = readln.strip.to !(int), a = readln.split.map !(to !(int)).array, s = a[0] + 1L;\n\tlong [] d;\n\tforeach (i; 1..n) d ~= a[i] - a[i - 1];\n\tforeach (ref y; d) s += max (y, 0);\n\twriteln (s >> 1);\n\tauto q = readln.strip.to !(int);\n\tforeach (p; 0..q) {\n\t\tint l, r, x;\n\t\treadf !(\" %s %s %s\") (l, r, x);\n\t\tif (l > 1) {\n\t\t\tl -= 2;\n\t\t\ts -= max (d[l], 0);\n\t\t\td[l] += x;\n\t\t\ts += max (d[l], 0);\n\t\t}\n\t\telse s += x;\n\t\tif (r < n) {\n\t\t\tr -= 1;\n\t\t\ts -= max (d[r], 0);\n\t\t\td[r] -= x;\n\t\t\ts += max (d[r], 0);\n\t\t}\n\t\twriteln (s >> 1);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tauto n = readln.strip.to !(int), a = readln.split.map !(to !(int)).array, s = a[0] + 1L;\n\tlong [] d;\n\tforeach (i; 1..n) d ~= a[i] - a[i - 1];\n\tforeach (ref y; d) s += max (y, 0);\n\twriteln (s >> 1);\n\tauto q = readln.strip.to !(int);\n\tforeach (p; 0..q) {\n\t\tint l, r, x;\n\t\treadf !(\" %s %s %s\") (l, r, x);\n\t\tif (l > 0) {\n\t\t\tl -= 2;\n\t\t\ts -= max (d[l], 0);\n\t\t\td[l] += x;\n\t\t\ts += max (d[l], 0);\n\t\t}\n\t\telse s += x;\n\t\tif (r < n) {\n\t\t\tr -= 1;\n\t\t\ts -= max (d[r], 0);\n\t\t\td[r] -= x;\n\t\t\ts += max (d[r], 0);\n\t\t}\n\t\twriteln (s >> 1);\n\t}\n}\n"}], "src_uid": "85f5033a045d331c12fc62f9b7816bed"} {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n int k = cin.readInt;\n string s = cin.readString;\n int count = 0;\n bool fail = false;\n for (int i = 0; i < n; i++) {\n count = s[i] == '#' ? count + 1 : 0;\n if (count >= k) fail = true; \n }\n writeln(fail ? \"NO\" : \"YES\");\n } \n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.exception;\nimport std.algorithm;\nimport std.math;\nimport std.typecons;\n\nvoid main(){\n\tint n, m;\n\tstring s;\n\treadf(\"%d %d\\n%s\\n\", &n, &m, &s);\n\tint k=0;\n\tstring ans=\"YES\";\n\tforeach(i; 0..n){\n\t\tif (s[i]=='#') k++;\n\t\telse{\n\t\t\tif (k>=m) ans=\"NO\";\n\t\t\tk=0;\n\t\t}\n\t}\n\twritefln(\"%s\", ans);\n}\n"}], "negative_code": [], "src_uid": "d504d894b2f6a830c4d3b4edc54395be"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\r\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\r\nimport core.bitop;\r\n\r\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\r\nstring[] tokens;\r\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\r\nint readInt() { return readToken.to!int; }\r\nlong readLong() { return readToken.to!long; }\r\nreal readReal() { return readToken.to!real; }\r\n\r\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\r\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\r\n\r\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\r\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\r\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\r\n\r\n\r\n\r\n\r\nvoid main() {\r\n try {\r\n for (; ; ) {\r\n const numCases = readInt();\r\n foreach (caseId; 0 .. numCases) {\r\n const N = readInt();\r\n auto A = new int[N];\r\n auto B = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt();\r\n B[i] = readInt();\r\n }\r\n \r\n bool check(int k) {\r\n int now;\r\n foreach (i; 0 .. N) {\r\n if (now <= B[i] && k - 1 - now <= A[i]) {\r\n ++now;\r\n }\r\n }\r\n return (now >= k);\r\n }\r\n \r\n int lo = 0, hi = N + 1;\r\n for (; lo + 1 < hi; ) {\r\n const mid = (lo + hi) / 2;\r\n (check(mid) ? lo : hi) = mid;\r\n }\r\n writeln(lo);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nT binarySearch(alias pred, T)(T ok, T ng)\r\n{ \r\n\twhile (abs(ok-ng) > 1)\r\n\t{\r\n\t\tauto mid = (ok+ng)/2;\r\n\t\tif (unaryFun!pred(mid)) ok = mid;\r\n\t\telse ng = mid;\r\n\t}\r\n\treturn ok;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = new long[](n);\r\n\t\tauto b = new long[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\ta[i] = RD;\r\n\t\t\tb[i] = RD;\r\n\t\t}\r\n\r\n\t\tbool f(long x)\r\n\t\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (cnt > b[i]) continue;\r\n\t\t\t\tif (x-cnt-1 > a[i]) continue;\r\n\t\t\t\t++cnt;\r\n\t\t\t\tif (cnt == x) break;\r\n\t\t\t}\r\n\t\t\treturn cnt == x;\r\n\t\t}\r\n\t\tans[ti] = binarySearch!(f)(0, n+1);\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n;\r\n\t\treadf !(\" %s\") (n);\r\n\t\tauto a = new int [n];\r\n\t\tauto b = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s\") (a[i], b[i]);\r\n\t\t}\r\n\r\n\t\tbool ok (int lim)\r\n\t\t{\r\n\t\t\tint down = 0;\r\n\t\t\tint up = lim - 1;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (b[i] >= down && a[i] >= up)\r\n\t\t\t\t{\r\n\t\t\t\t\tdown += 1;\r\n\t\t\t\t\tup -= 1;\r\n\t\t\t\t\tif (up < 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tint lo = 1;\r\n\t\tint hi = n + 1;\r\n\t\twhile (hi - lo > 1)\r\n\t\t{\r\n\t\t\tint me = (lo + hi) / 2;\r\n\t\t\tif (ok (me))\r\n\t\t\t{\r\n\t\t\t\tlo = me;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\thi = me;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (lo);\r\n\t}\r\n}\r\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto a = new int[](n);\n\tauto b = new int[](n);\n\tforeach(i; 0 .. n)\n\t{\n\t\ta[i] = readInt!int;\n\t\tb[i] = readInt!int;\n\t}\n\tbool can(int k)\n\t{\n\t\tint left = 0;\n\t\tint right = k - 1;\n\t\tint elems = 0;\n\t\tforeach(i; 0 .. n)\n\t\t{\n\t\t\tif (right <= a[i] && left <= b[i]) { left++, right--; elems++;}\n\t\t}\n\t\treturn elems >= k;\n\t}\n\tint hi = n;\n\tint lo = 0;\n\tint ans = -1;\n\twhile (lo <= hi)\n\t{\n\t\tint mi = (lo + hi)/2;\n\t\tif (can(mi))\n\t\t{\n\t\t\tans = mi;\n\t\t\tlo = mi + 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\thi = mi - 1;\n\t\t}\n\t}\n\tassert(ans != -1);\n\treturn writeln(ans);\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "// \u63d0\u51fa\u89e3\r\nvoid solve(){\r\n\tforeach(_; 0 .. scan!int){\r\n\t\tint n = scan!int;\r\n\t\tint[] as, bs;\r\n\t\tforeach(i; 0 .. n) as ~= scan!int, bs ~= scan!int;\r\n\t\tlog(\"as:\", as);\r\n\t\tlog(\"bs:\", bs);\r\n\r\n\t\tint calc(int k){\r\n\t\t\tint[] cs;\r\n\t\t\tforeach(i; 0 .. n) cs ~= k - 1 - as[i]; // \u81ea\u5206\u3088\u308a\u8ca7\u4e4f\u306a\u4eba\u6570\u306e\u4e0b\u9650\r\n\t\t\tint cnt;\r\n\t\t\tforeach(i; 0 .. n){\r\n\t\t\t\tif(cs[i] <= cnt && cnt <= bs[i]) cnt += 1;\r\n\t\t\t}\r\n\t\t\tlog(\"k:\", k, \"cs:\", cs, \"cnt:\", cnt);\r\n\t\t\treturn cnt;\r\n\t\t}\r\n\t\tbool isOK(int k){\r\n\t\t\treturn calc(k) >= k;\r\n\t\t}\r\n\r\n\t\tint ans = mid(1, n + 2, &isOK) - 1;\r\n\t\tans.print;\r\n\t}\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u611a\u76f4\u89e3\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30c6\u30f3\u30d7\u30ec\r\nimport std;\r\nbool DEBUG = 0;\r\nvoid main(string[] args){\r\n\tif(args.canFind(\"-debug\")) DEBUG = 1;\r\n\tif(args.canFind(\"-gen\")) gen; else if(args.canFind(\"-jury\")) jury; else solve;\r\n}\r\nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\r\nvoid print(){ writeln(\"\"); }\r\nvoid print(T)(T t){ writeln(t); }\r\nvoid print(T, A ...)(T t, A a){ stdout.write(t, \" \"), print(a); }\r\nstring unsplit(T)(T xs, string d = \" \"){ return xs.array.to!(string[]).join(d); }\r\nstring scan(){\r\n\tstatic string[] ss; while(!ss.length) ss = readln.chomp.split;\r\n\tstring res = ss[0]; ss.popFront; return res;\r\n}\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\r\nT mini(T)(ref T x, T y){ if(x > y) x = y; return x; }\r\nT maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }\r\nT mid(T)(T l, T r, bool delegate(T) f){\r\n\tT m = (l + r) / 2; (f(m)? l: r) = m; return f(l)? f(r - 1)? r: mid(l, r, f): l;\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u57fa\u672c\uff09\r\n\r\nclass UnionFind{\r\n\tthis(int n){ foreach(i; 0 .. n) R ~= i, K ~= [i]; } int[] R; int[][] K;\r\n\tvoid unite(int a, int b){\r\n\t\tint ra = R[a], rb = R[b]; if(ra == rb) return;\r\n\t\tif(K[ra].length < K[rb].length) unite(b, a);\r\n\t\telse foreach(k; K[rb]) R[k] = ra, K[ra] ~= k;\r\n\t}\r\n\tint find(int a){ return R[a]; }\r\n\tint getSize(int a){ return K[R[a]].length.to!int; }\r\n}\r\nclass Queue(T){\r\n\tprivate T[] xs; private uint i, j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j - i; }\r\n\tbool isEmpty(){ return j == i; } \r\n\tvoid enq(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT deq(){ assert(i < j); return xs[i ++]; }\r\n\tT peek(){ assert(i < j); return xs[i]; }\r\n\tvoid flush(){ i = j; }\r\n\talias empty = isEmpty, front = peek, popFront = deq, pop = deq, push = enq, top = peek;\r\n\tQueue opOpAssign(string op)(T x) if(op == \"~\"){ enq(x); return this; }\r\n\tT opIndex(uint li){ assert(i + li < j); return xs[i + li]; }\r\n\tstatic Queue!T opCall(T[] xs){ return new Queue!T(xs); }\r\n\tT[] array(){ return xs[i .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\nclass Stack(T){\r\n\tprivate T[] xs; private uint j;\r\n\tthis(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }\r\n\tuint length(){ return j; }\r\n\tbool isEmpty(){ return j == 0; }\r\n\tvoid push(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }\r\n\tT pop(){ assert(j > 0); return xs[-- j]; }\r\n\tT peek(){ assert(j > 0); return xs[j - 1]; }\r\n\tvoid clear(){ j = 0; }\r\n\talias empty = isEmpty, front = peek, popFront = pop, top = peek;\r\n\tStack opOpAssign(string op)(T x) if(op == \"~\"){ push(x); return this; }\r\n\tT opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }\r\n\tstatic Stack!T opCall(T[] xs = []){ return new Stack!T(xs); }\r\n\tT[] array(){ return xs[0 .. j]; }\r\n\toverride string toString(){ return array.to!string; }\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u8ffd\u52a0\uff09\r\n\r\n\r\n"}], "negative_code": [], "src_uid": "93e9eb2c95fc9d86f526a03754ffd576"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int N = 200000;\n\nclass Request\n{\n\tint arrivalTime;\n\tint executionTime;\n\tlong readyTime;\n}\n\nclass Server\n{\n\tprivate Request[N] queue;\n\n\tprivate int queueStart;\n\n\tprivate int queueEnd;\n\n\tprivate int queueSize;\n\n\tprivate long currentTime;\n\n\tpublic this(int queueSize)\n\t{\n\t\tthis.queueSize = queueSize;\n\t}\n\n\tprivate void processUpTo(long time)\n\t{\n\t\twhile (currentTime <= time && queueEnd > queueStart) {\n\t\t\tcurrentTime += queue[queueStart].executionTime;\n\t\t\tqueue[queueStart].readyTime = currentTime;\n\t\t\tqueueStart++;\n\t\t}\n\t}\n\n\tvoid enqueue(Request request)\n\t{\n\t\tprocessUpTo(request.arrivalTime);\n\t\tif (queueEnd - queueStart >= queueSize) {\n\t\t\trequest.readyTime = -1;\n\t\t}\n\t\telse {\n\t\t\tcurrentTime = max(currentTime, request.arrivalTime);\n\t\t\tqueue[queueEnd] = request;\n\t\t\tqueueEnd++;\n\t\t}\n\t}\n\t\n\tvoid finish()\n\t{\n\t\tprocessUpTo(long.max);\n\t}\n}\n\nvoid main()\n{\n\tint nRequests;\n\tint queueSize;\n\n\treadf(\"%d %d\", &nRequests, &queueSize);\n\n\tServer s = new Server(queueSize);\n\tRequest[] requests = new Request[](nRequests);\n\tfor (int i = 0; i < nRequests; i++) {\n\t\tRequest r = new Request();\n\n\t\treadf(\" %d %d\", &r.arrivalTime, &r.executionTime);\n\t\trequests[i] = r;\n\n\t\ts.enqueue(r);\n\t}\n\ts.finish();\n\n\tfor (int i = 0; i < nRequests; i++) {\n\t\twritef(\"%d\", requests[i].readyTime);\n\t\twritef(i < nRequests - 1 ? \" \" : \"\\n\");\n\t}\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\tint b;\n\twhile (readf (\" %s %s\", &n, &b) > 0)\n\t{\n\t\talias Query = Tuple !(long, q{t}, int, q{d});\n\t\tauto q = new Query [n];\n\t\tforeach (ref r; q)\n\t\t{\n\t\t\treadf (\" %s %s\", &r.t, &r.d);\n\t\t}\n\t\tq ~= Query (long.max, int.max);\n\n\t\tauto a = new long [n];\n\t\tint [] s;\n\t\tlong c = 0;\n\t\tforeach (i; 0..n + 1)\n\t\t{\n\t\t\twhile (!s.empty && c <= q[i].t)\n\t\t\t{\n\t\t\t\tint k = s.front;\n\t\t\t\ts.popFront ();\n\t\t\t\ts.assumeSafeAppend ();\n\t\t\t\tc += q[k].d;\n\t\t\t\ta[k] = c;\n\t\t\t}\n\t\t\tc = max (c, q[i].t);\n\n\t\t\tif (s.length >= b)\n\t\t\t{\n\t\t\t\ta[i] = -1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ts ~= i;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int N = 200000;\n\nclass Request\n{\n\tint arrivalTime;\n\tint executionTime;\n\tint readyTime;\n}\n\nclass Server\n{\n\tprivate Request[N] queue;\n\n\tprivate int queueStart;\n\n\tprivate int queueEnd;\n\n\tprivate int queueSize;\n\n\tprivate int currentTime;\n\n\tpublic this(int queueSize)\n\t{\n\t\tthis.queueSize = queueSize;\n\t}\n\n\tprivate void processUpTo(int time)\n\t{\n\t\twhile (currentTime <= time && queueEnd > queueStart) {\n\t\t\tcurrentTime += queue[queueStart].executionTime;\n\t\t\tqueue[queueStart].readyTime = currentTime;\n\t\t\tqueueStart++;\n\t\t}\n\t}\n\n\tvoid enqueue(Request request)\n\t{\n\t\tprocessUpTo(request.arrivalTime);\n\t\tif (queueEnd - queueStart >= queueSize) {\n\t\t\trequest.readyTime = -1;\n\t\t}\n\t\telse {\n\t\t\tcurrentTime = max(currentTime, request.arrivalTime);\n\t\t\tqueue[queueEnd] = request;\n\t\t\tqueueEnd++;\n\t\t}\n\t}\n\t\n\tvoid finish()\n\t{\n\t\tprocessUpTo(int.max);\n\t}\n}\n\nvoid main()\n{\n\tint nRequests;\n\tint queueSize;\n\n\treadf(\"%d %d\", &nRequests, &queueSize);\n\n\tServer s = new Server(queueSize);\n\tRequest[] requests = new Request[](nRequests);\n\tfor (int i = 0; i < nRequests; i++) {\n\t\tRequest r = new Request();\n\n\t\treadf(\" %d %d\", &r.arrivalTime, &r.executionTime);\n\t\trequests[i] = r;\n\n\t\ts.enqueue(r);\n\t}\n\ts.finish();\n\n\tfor (int i = 0; i < nRequests; i++) {\n\t\twritef(\"%d\", requests[i].readyTime);\n\t\twritef(i < nRequests - 1 ? \" \" : \"\\n\");\n\t}\n}"}], "src_uid": "5981594b2d6d1077ce2249b641d18f10"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint mex (int [] a)\n\t\t{\n\t\t\tauto b = new bool [n + 1];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tb[a[i]] = true;\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\twhile (b[res])\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tint [] answer;\n\t\twhile (!equal (a, n.iota))\n\t\t{\n\t\t\tauto v = mex (a);\n\n\t\t\tvoid set (int pos)\n\t\t\t{\n\t\t\t\tanswer ~= pos + 1;\n\t\t\t\ta[pos] = v;\n\t\t\t}\n\t\t\tif (v < n)\n\t\t\t{\n\t\t\t\tset (v);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint pos = 0;\n\t\t\t\twhile (a[pos] == pos)\n\t\t\t\t{\n\t\t\t\t\tpos += 1;\n\t\t\t\t}\n\t\t\t\tset (pos);\n\t\t\t}\n\t\t}\n\t\twriteln (answer.length);\n\t\twritefln !(\"%(%s %)\") (answer);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int[] ans;\n auto as = A.dup;\n for (; ; ) {\n auto app = new bool[N];\n foreach (i; 0 .. N) {\n if (as[i] < N) {\n app[as[i]] = true;\n }\n }\n int x;\n for (x = 0; x < N; ++x) {\n if (!app[x]) {\n break;\n }\n }\n if (x == N) {\n int im = -1;\n foreach (i; 0 .. N) {\n if (as[i] != i) {\n if (im == -1 || as[im] > as[i]) {\n im = i;\n }\n }\n }\n if (im == -1) {\n break;\n }\n ans ~= im;\n as[im] = x;\n } else {\n ans ~= x % N;\n as[x % N] = x;\n }\n debug {\n writeln(\"as = \", as);\n }\n }\n \n writeln(ans.length);\n foreach (h, i; ans) {\n if (h > 0) write(\" \");\n write(i + 1);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tBinaryHeap!(Array!int, \"a > b\") heap;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\theap.insert(a[i]);\n\t\t}\n\n\t\tint i;\n\t\twhile (true)\n\t\t{\n\t\t\tint[] tmp;\n\t\t\tint x;\n\t\t\twhile (!heap.empty)\n\t\t\t{\n\t\t\t\tx = heap.front; heap.removeFront;\n\t\t\t\ttmp ~= x;\n\t\t\t\tdebug writeln(\"i:\", i, \" \", \"x:\", x, \" \", tmp);\n\t\t\t\tdebug writeln(a);\n\t\t\t\tif (x > i) break;\n\t\t\t\ti = x+1;\n\t\t\t}\n\t\t\tint ii = -1;\n\t\t\tif (i == n || tmp.empty)\n\t\t\t{\n\t\t\t\tbool ok = true;\n\t\t\t\tforeach_reverse (j; 0..n)\n\t\t\t\t{\n\t\t\t\t\tif (a[j] != j)\n\t\t\t\t\t{\n\t\t\t\t\t\ti = j;\n\t\t\t\t\t\tii = n;\n\t\t\t\t\t\tok = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (ok)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tauto y = a[i];\n\t\t\tif (ii != -1)\n\t\t\t{\n\t\t\t\ta[i] = ii;\n\t\t\t\theap.insert(ii);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ta[i] = i;\n\t\t\t\theap.insert(i);\n\t\t\t}\n\t\t\tans[ti] ~= i+1;\n\t\t\ti = min(i+1, y);\n\t\t\t\n\t\t\tBinaryHeap!(Array!int, \"a > b\") nHeap;\n\t\t\tbool done;\n\t\t\tforeach (e; tmp)\n\t\t\t{\n\t\t\t\tif (!done)\n\t\t\t\t{\n\t\t\t\t\tif (e == y)\n\t\t\t\t\t{\n\t\t\t\t\t\tdone = true;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tnHeap.insert(e);\n\t\t\t}\n\t\t\twhile (!heap.empty)\n\t\t\t{\n\t\t\t\tauto z = heap.front; heap.removeFront;\n\t\t\t\tif (!done)\n\t\t\t\t{\n\t\t\t\t\tif (z == y)\n\t\t\t\t\t{\n\t\t\t\t\t\tdone = true;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tnHeap.insert(z);\n\t\t\t}\n\t\t\theap = nHeap;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\te.map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto ans = new int[N + 1];\n auto as = A.dup;\n foreach (h; 0 .. N + 1) {\n auto app = new bool[N + 1];\n foreach (i; 0 .. N) {\n if (as[i] <= N) {\n app[as[i]] = true;\n }\n }\n foreach (x; 0 .. N + 1) {\n if (!app[x]) {\n ans ~= x % N;\n as[x % N] = x;\n break;\n }\n }\n debug {\n writeln(\"as = \", as);\n }\n }\n \n writeln(ans.length);\n foreach (h, i; ans) {\n if (h > 0) write(\" \");\n write(i + 1);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto ans = new int[N + 1];\n auto as = A.dup;\n foreach (h; 0 .. 2 * N) {\n auto app = new bool[N];\n foreach (i; 0 .. N) {\n if (as[i] < N) {\n app[as[i]] = true;\n }\n }\n int x;\n for (x = 0; x < N; ++x) {\n if (!app[x]) {\n break;\n }\n }\n if (x == N) {\n bool found;\n foreach (i; 0 .. N) {\n if (as[i] != i) {\n found = true;\n ans ~= i;\n as[i] = x;\n break;\n }\n }\n if (!found) {\n break;\n }\n } else {\n ans ~= x % N;\n as[x % N] = x;\n }\n debug {\n writeln(\"as = \", as);\n }\n }\n \n writeln(ans.length);\n foreach (h, i; ans) {\n if (h > 0) write(\" \");\n write(i + 1);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tBinaryHeap!(Array!int, \"a > b\") heap;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\theap.insert(a[i]);\n\t\t}\n\n\t\tint i;\n\t\twhile (true)\n\t\t{\n\t\t\tint[] tmp;\n\t\t\tint x;\n\t\t\twhile (!heap.empty)\n\t\t\t{\n\t\t\t\tx = heap.front; heap.removeFront;\n\t\t\t\ttmp ~= x;\n\t\t\t\tdebug writeln(\"i:\", i, \" \", \"x:\", x, \" \", tmp);\n\t\t\t\tdebug writeln(a);\n\t\t\t\tif (x > i) break;\n\t\t\t\ti = x+1;\n\t\t\t}\n\t\t\tif (i == n || tmp.empty)\n\t\t\t{\n\t\t\t\tbool ok = true;\n\t\t\t\tforeach_reverse (j; 0..n)\n\t\t\t\t{\n\t\t\t\t\tif (a[j] != j)\n\t\t\t\t\t{\n\t\t\t\t\t\ti = j;\n\t\t\t\t\t\tok = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (ok)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tauto y = a[i];\n\t\t\ta[i] = i;\n\t\t\tans[ti] ~= i+1;\n\t\t\theap.insert(i);\n\t\t\ti = min(i+1, y);\n\t\t\t\n\t\t\tBinaryHeap!(Array!int, \"a > b\") nHeap;\n\t\t\tbool done;\n\t\t\tforeach (e; tmp)\n\t\t\t{\n\t\t\t\tif (!done)\n\t\t\t\t{\n\t\t\t\t\tif (e == y)\n\t\t\t\t\t{\n\t\t\t\t\t\tdone = true;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tnHeap.insert(e);\n\t\t\t}\n\t\t\twhile (!heap.empty)\n\t\t\t{\n\t\t\t\tauto z = heap.front; heap.removeFront;\n\t\t\t\tif (!done)\n\t\t\t\t{\n\t\t\t\t\tif (z == y)\n\t\t\t\t\t{\n\t\t\t\t\t\tdone = true;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tnHeap.insert(z);\n\t\t\t}\n\t\t\theap = nHeap;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\te.map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "ebd4411d03bbce51e2b53064146644d4"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto s = readString;\n\tint i = 0;\n\tint blocks = 0;\n\tint minLength = int.max;\n\twhile (i < s.length)\n\t{\n\t\tblocks ^= 1;\n\t\tchar ch = s[i];\n\t\tint len = 0;\n\t\twhile (i < s.length && s[i] == ch) { i++; len++; }\n\t\tminLength = min(len, minLength);\n\t}\n\tif (blocks) return writeln(s);\n\twrite(s[0] == 'a'? 'b' : 'a');\n\twriteln(s[1 .. $]);\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip.dup;\r\n\t\tauto n = s.length.to !(int);\r\n\t\tstring res;\r\n\t\tforeach (i; 0..n + 1)\r\n\t\t{\r\n\t\t\tif (i < n)\r\n\t\t\t{\r\n\t\t\t\ts[i] ^= 3;\r\n\t\t\t}\r\n\t\t\tif (s.count (\"ab\") == s.count (\"ba\"))\r\n\t\t\t{\r\n\t\t\t\tres = s.idup;\r\n\t\t\t}\r\n\t\t\tif (i < n)\r\n\t\t\t{\r\n\t\t\t\ts[i] ^= 3;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto s = readString;\n\tint i = 0;\n\tint blocks = 0;\n\tint minLength = int.max;\n\twhile (i < s.length)\n\t{\n\t\tblocks ^= 1;\n\t\tchar ch = s[i];\n\t\tint len = 0;\n\t\twhile (i < s.length && s[i] == ch) { i++; len++; }\n\t\tminLength = min(len, minLength);\n\t}\n\tif (blocks) return writeln(s);\n\ti = 0;\n\twhile (i < s.length)\n\t{\n\t\tchar ch = s[i];\n\t\tint len = 0;\n\t\twhile (i < s.length && s[i] == ch) { i++; len++; }\n\t\tif (len == minLength)\n\t\t{\n\t\t\tchar otherCh = ch == 'a'? 'b' : 'a';\n\t\t\tforeach(_; 0 .. len) write(otherCh);\n\t\t\tminLength = int.max;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach(_; 0 .. len) write(ch);\n\t\t}\n\t}\n\twriteln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "src_uid": "351ffff1dfe1bc1762f062f612463759"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n /*\n debug {\n foreach (n; 1 .. 5 + 1) {\n auto as = iota(n).array;\n do {\n int[][] invs;\n foreach (i; 0 .. n) foreach (j; i + 1 .. n) {\n if (as[i] > as[j]) {\n invs ~= [i, j];\n }\n }\n const invsLen = cast(int)(invs.length);\n writeln(as);\n bool found;\n auto perm = iota(invsLen).array;\n do {\n auto bs = as.dup;\n foreach (k; 0 .. invsLen) {\n swap(bs[invs[perm[k]][0]], bs[invs[perm[k]][1]]);\n }\n if (bs == iota(n).array) {\n found = true;\n foreach (k; 0 .. invsLen) {\n write(\" \", invs[perm[k]]);\n }\n writeln;\n }\n } while (perm.nextPermutation);\n if (!found) {\n writeln(\"no solution\");\n }\n } while (as.nextPermutation);\n }\n }\n //*/\n \n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n Tuple!(int, int)[] ps;\n foreach (i; 0 .. N) {\n ps ~= tuple(A[i], i);\n }\n ps.sort;\n auto as = new int[N];\n foreach (i; 0 .. N) {\n as[ps[i][1]] = i;\n }\n debug {\n writeln(\"as = \", as);\n }\n \n auto poss = new int[N];\n foreach (i; 0 .. N) {\n poss[as[i]] = i;\n }\n int[][] ans;\n foreach (h; 0 .. N - 1) {\n foreach (a; 0 .. N - 1) {\n const i = poss[a];\n const j = poss[a + 1];\n if (i > j) {\n ans ~= [j, i];\n swap(as[i], as[j]);\n swap(poss[a], poss[a + 1]);\n }\n }\n }\n \n writeln(ans.length);\n foreach (p; ans) {\n writeln(p[0] + 1, \" \", p[1] + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i] = a[i] * n + i;\n\t\t}\n\n\t\talias Pair = Tuple !(int, q{u}, int, q{v});\n\t\tPair [] answer;\n\t\tauto inv = new int [] [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tif (a[i] > a[j])\n\t\t\t\t{\n\t\t\t\t\tinv[i] ~= j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid apply (int i, int j)\n\t\t{\n\t\t\tanswer ~= Pair (i + 1, j + 1);\n\t\t\tswap (a[i], a[j]);\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tinv[i].schwartzSort !(j => a[j]);\n\t\t\tforeach_reverse (j; inv[i])\n\t\t\t{\n\t\t\t\tapply (i, j);\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (a);}\n\n\t\twriteln (answer.length);\n\t\tforeach (p; answer)\n\t\t{\n\t\t\twriteln (p.u, \" \", p.v);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "ff1423b6d0a60e4e3461c30b730dba57"} {"source_code": "module sigod.codeforces.p298B;\n\nimport std.stdio;\nimport std.string;\n\nprivate {\n\tstruct Direction\n\t{\n\t\tint l_x = 0;\n\t\tint l_y = 0;\n\t\tint r_x = 0;\n\t\tint r_y = 0;\n\n\t\tref Direction opOpAssign(string op)(in Direction direction)\n\t\t\tif (op == \"+\")\n\t\t{\n\t\t\tl_x += direction.l_x;\n\t\t\tl_y += direction.l_y;\n\t\t\tr_x += direction.r_x;\n\t\t\tr_y += direction.r_y;\n\n\t\t\treturn this;\n\t\t}\n\t}\n}\n\n\nvoid main()\n{\n\tint t, sx, sy, ex, ey;\n\tstdin.readf(\" %s %s %s %s %s\", &t, &sx, &sy, &ex, &ey);\n\n\tstring direction;\n\tstdin.readf(\" %s\", &direction);\n\tdirection = direction.strip();\n\n\tDirection[char] compas;\n\tcompas['E'] = Direction(0, 0, 1, 0);\n\tcompas['S'] = Direction(0, 0, 0, -1);\n\tcompas['W'] = Direction(-1, 0, 0, 0);\n\tcompas['N'] = Direction(0, 1, 0, 0);\n\n\tDirection zone = Direction(sx, sy, sx, sy);\n\n\tforeach (index, way; direction) {\n\t\tzone += compas[way];\n\n\t\tif (zone.l_x <= ex && zone.r_x >= ex\n\t\t\t&& zone.l_y >= ey && zone.r_y <= ey)\n\t\t{\n\t\t\tstdout.writeln(index + 1);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tstdout.writeln(\"-1\");\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int t, sx, sy, ex, ey;\n readf(\" %s %s %s %s %s\\n\", &t, &sx, &sy, &ex, &ey);\n char c;\n int et = 0;\n foreach ( l; 0 .. t ) {\n readf(\" %s\", &c);\n if (c == 'N' && ey > sy) {\n ++sy;\n }\n else if (c == 'S' && ey < sy) {\n --sy;\n }\n else if (c == 'E' && ex > sx) {\n ++sx;\n }\n else if (c == 'W' && ex < sx) {\n --sx;\n }\n ++et;\n if (sx == ex && sy == ey) {\n writeln(et);\n return 0;\n }\n }\n writeln(\"-1\");\n\n return 0;\n}"}], "negative_code": [], "src_uid": "aa31a2a1ad1575aee051ddee8642c53a"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nlong[] arr;\n\nvoid main()\n{\n int n, k;\n readf( \"%s %s\", &n, &k );\n readln;\n \n arr = 0 ~ readln.splitter.map!( to!long ).array;\n \n debug { writeln( arr ); }\n \n long ans = 0;\n foreach_reverse ( bt; 0..64) {\n long cur = ans | (1L << bt);\n \n auto ok = new bool [] [] ( n+1, k+1 );\n foreach ( row; ok ) row.fill ( false );\n ok[0][0] = true;\n \n foreach ( i; 1..n+1 ) {\n foreach ( gr; 1..k+1 ) {\n \n if ( !ok[ i-1 ][ gr-1 ] ) continue;\n \n long cursum = 0;\n foreach ( j; i..n+1 ) {\n cursum += arr[ j ];\n ok[ j ][ gr ] |= ( cursum & cur ) == cur;\n }\n }\n }\n if ( ok[ n ][ k ] ) ans = cur;\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(ulong)).array;\n\t\tulong res = 0UL;\n\t\tforeach_reverse (b; 0..64)\n\t\t{\n\t\t\tauto f = new bool [] [] (n + 1, k + 1);\n\t\t\tf[0][0] = true;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 0..k)\n\t\t\t\t{\n\t\t\t\t\tif (f[i][j])\n\t\t\t\t\t{\n\t\t\t\t\t\tulong s = 0UL;\n\t\t\t\t\t\tforeach (r; i..n)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ts += a[r];\n\t\t\t\t\t\t\tif ((s & res) == res)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (s & (1UL << b))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tf[r + 1][j + 1] = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (f[n][k])\n\t\t\t{\n\t\t\t\tres |= 1UL << b;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.datetime;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!long).array;\n auto B = new long[][](N, N);\n foreach (i; 0..N) {\n B[i][i] = A[i];\n foreach (j; i+1..N) B[i][j] = B[i][j-1] + A[j];\n }\n\n\n auto mem = new bool[][](N+10, K+10);\n\n bool dfs(int n, int k, long mask) {\n if (k == 0 && n != N-1) return false;\n if (n >= 0 && mem[n][k]) return false;\n if (k > N - n - 1) return false;\n if (n == N-1) return k == 0;\n\n int left = n+1;\n foreach (right; n+1..N) {\n if ((B[left][right] & mask) >= mask && dfs(right, k-1, mask))\n return true;\n }\n\n if (n >= 0) mem[n][k] = true;\n return false;\n }\n\n long m = 0;\n\n foreach_reverse (i; 0..60) {\n foreach (j; 0..N+10) mem[j].fill(false);\n if (dfs(-1, K, m | (1L << i))) {\n m |= (1L << i);\n }\n }\n\n m.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nlong[] arr;\n\nvoid main()\n{\n int n, k;\n readf( \"%s %s\", &n, &k );\n readln;\n \n arr = 0 ~ readln.splitter.map!( to!long ).array;\n \n debug { writeln( arr ); }\n \n long ans = 0;\n foreach_reverse ( bt; 0..64) {\n long cur = ans | ( 1L << bt );\n \n auto ok = new bool [] [] ( k+1, n+1 );\n ok.each! ( row => row.fill ( false ) );\n ok[0][0] = true;\n \n foreach ( gr; 1..k+1 ) {\n foreach ( i; 1..n+1 ) {\n \n if ( !ok[ gr-1 ][ i-1 ] ) continue;\n \n long cursum = 0;\n foreach ( j; i..n+1 ) {\n cursum += arr[ j ];\n ok[ gr ][ j ] |= ( cursum & cur ) == cur;\n }\n }\n }\n if ( ok[ k ][ n ] ) ans = cur;\n }\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.datetime;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!long).array;\n auto B = new long[][](N, N);\n foreach (i; 0..N) {\n B[i][i] = A[i];\n foreach (j; i+1..N) B[i][j] = B[i][j-1] + A[j];\n }\n\n\n auto mem = new bool[][](N+10, K+10);\n\n bool dfs(int n, int k, long mask) {\n if (k == 0 && n != N-1) return false;\n if (n >= 0 && mem[n][k]) return false;\n if (k > N - n - 1) return false;\n if (n == N-1) return k == 0;\n\n int left = n+1;\n foreach (right; n+1..N) {\n if ((B[left][right] & mask) >= mask && dfs(right, k-1, mask))\n return true;\n }\n\n if (n >= 0) mem[n][k] = true;\n return false;\n }\n\n long m = 0;\n\n foreach_reverse (i; 0..55) {\n foreach (j; 0..N+10) mem[j].fill(false);\n if (dfs(-1, K, m | (1L << i))) {\n m |= (1L << i);\n }\n }\n\n m.writeln;\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.datetime;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!long).array;\n auto B = new long[][](N, N);\n foreach (i; 0..N) {\n B[i][i] = A[i];\n foreach (j; i+1..N) B[i][j] = B[i][j-1] + A[j];\n }\n\n\n auto mem = new bool[][](N+10, K+10);\n\n bool dfs(int n, int k, long mask) {\n if (k == 0 && n != N-1) return false;\n if (n >= 0 && mem[n][k]) return false;\n if (k > N - n - 1) return false;\n if (n == N-1) return k == 0;\n\n int left = n+1;\n foreach (right; n+1..N) {\n if ((B[left][right] & mask) >= mask && dfs(right, k-1, mask))\n return true;\n }\n\n if (n >= 0) mem[n][k] = true;\n return false;\n }\n\n long m = 0;\n\n foreach_reverse (i; 0..51) {\n foreach (j; 0..N+1) mem[j].fill(false);\n if (dfs(-1, K, m | (1L << i))) {\n m |= (1L << i);\n }\n }\n\n m.writeln;\n}\n"}], "src_uid": "9862db32dfd8eab8714d17aaaa338acd"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!int).array;\n auto s = readln.strip.split(\"\").map!(to!int).array;\n auto ans = iota(n).map!(x => tuple(a[x], s[x], x)).array.sort!((x, y) => x[1] == y[1] ? x[0] < y[0] : x[1] < y[1], SwapStrategy.stable).map!(x => x[2]);\n auto ans2 = iota(n).array;\n foreach (i ; 0 .. n)\n ans2[ans[i]] = i + 1;\n writeln(ans2.map!text.join(\" \"));\n }\n}\n", "positive_code": [{"source_code": "void main() { runSolver(); }\n\nvoid problem() {\n auto QN = scan!long;\n\n auto solve() {\n foreach(_; 0..QN) {\n auto N = scan!long;\n auto P = scan!long(N);\n auto S = scan;\n\n long[] likes, dislikes;\n foreach(i, p; P) if (S[i] == '1') likes ~= p; else dislikes ~= p;\n\n likes = likes.compress;\n dislikes = dislikes.compress;\n const dl = dislikes.length;\n\n long[] ans;\n uint l, d;\n foreach(c; S) {\n if (c == '0') ans ~= dislikes[d++] + 1;\n if (c == '1') ans ~= likes[l++] + 1 + dl;\n }\n\n ans.toAnswerString.writeln;\n }\n }\n\n outputForAtCoder(&solve);\n}\n\n// ----------------------------------------------\n\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; }\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\nvoid deb(T ...)(T t){ debug writeln(t); }\nalias Point = Tuple!(long, \"x\", long, \"y\");\nPoint invert(Point p) { return Point(p.y, p.x); }\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\nalias MInt1 = ModInt!(10^^9 + 7);\nalias MInt9 = ModInt!(998_244_353);\nvoid outputForAtCoder(T)(T delegate() fn) {\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\n else static if (is(T == void)) fn();\n else static if (is(T == string)) fn().writeln;\n else static if (isInputRange!T) {\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\n else foreach(r; fn()) r.writeln;\n }\n else fn().writeln;\n}\nvoid runSolver() {\n enum BORDER = \"==================================\";\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\n else problem();\n}\nenum YESNO = [true: \"Yes\", false: \"No\"];\n\n// -----------------------------------------------\n"}, {"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception, \n std.container, std.typecons, std.conv, std.random, std.bigint;\n\nvoid read(S...)(ref S args) {\n auto input = readln.split;\n enforce(input.length == args.length);\n foreach (i, ref arg; args) {\n arg = input[i].to!(S[i]);\n }\n}\n\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n int n;\n read(n);\n auto arr = list!int;\n string s = readln;\n\n int[] good, bad;\n foreach (i; 0 .. n) {\n if (s[i] == '1') good ~= arr[i];\n else bad ~= arr[i];\n }\n\n sort(good);\n sort(bad);\n\n int p = n;\n\n int[int] m;\n\n foreach (A; [good, bad]) {\n while (!A.empty) {\n m[A.back] = p--;\n A.popBack;\n }\n }\n\n foreach (i; 0 .. n) {\n writef(\"%d \", m[arr[i]]);\n }\n writeln;\n }\n}\n\n"}, {"source_code": "import std;\n\nvoid main () {\n int test;\n readf(\"%s\\n\", test);\n\n foreach (test_index; 0 .. test) {\n int n;\n readf(\"%s\\n\", n);\n\n int[] p = new int[n];\n string s;\n\n foreach (i; 0 .. n)\n readf(\" %s\", p[i]);\n readf!\"\\n\";\n s = readln()[0 .. $ - 1];\n\n\n int[] liked;\n int[] disliked;\n foreach (int i, c; s)\n if (c == '0')\n disliked ~= i;\n else\n liked ~= i;\n\n auto likedV = liked\n .map!(i => tuple(p[i], i))\n .array\n .sort;\n\n auto dislikedV = disliked\n .map!(i => tuple(p[i], i))\n .array\n .sort;\n\n //stderr.writeln(likedV, '\\n', dislikedV);\n\n int rating = 1;\n foreach (t; dislikedV) {\n p[t[1]] = rating ++;\n }\n foreach (t; likedV)\n p[t[1]] = rating ++;\n assert(rating == n + 1);\n writefln!\"%(%s %)\"(p);\n }\n}\n// \"\"\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!int).array;\n auto s = readln.strip.split(\"\").map!(to!int).array;\n auto ans = iota(n).map!(x => tuple(a[x], s[x], x)).array.sort!((x, y) => x[1] == y[1] ? x[0] < y[0] : x[1] < y[1]).map!(x => x[2] + 1);\n writeln(ans.map!text.join(\" \"));\n }\n}\n"}], "src_uid": "0903a40d72c19a9d1cc1147d01ea94a7"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[][](N, 4);\n foreach (i; 0 .. N) {\n foreach (j; 0 .. 4) {\n A[i][j] = readInt();\n }\n }\n \n int ans = 1;\n foreach (i; 1 .. N) {\n if (A[0].sum < A[i].sum) {\n ++ans;\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = N.iota.map!(i => readln.split.map!(to!int).array ~ i).array;\n A.sort!\"a.sum-a[4] == b.sum-b[4] ? a[4] < b[4] : a.sum-a[4] > b.sum-b[4]\";\n\n foreach (i; 0..N) {\n if (A[i][4] == 0) {\n writeln(i+1);\n }\n }\n}\n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto t = readln.chomp.split.map!(to!int).sum;\n \n auto ans = 1;\n foreach (_; 1 .. n) {\n auto s = readln.chomp.split.map!(to!int).sum;\n if (s > t) ++ans;\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint [] [] a;\n\t\treadln;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta ~= i ~ readln.splitter.map !(to !(int)).array;\n\t\t}\n\t\ta.schwartzSort !(d => tuple (-sum (d[1..$]), d[0]));\n\t\twriteln (a.countUntil !(d => d[0] == 0) + 1);\n\t}\n}\n"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n struct Student{\n int id, sum;\n }\n int n; rd(n);\n auto students=new Student[](n);\n foreach(i; 0..n){\n auto s=readln.split.to!(int[]).reduce!\"a+b\";\n students[i]=Student(i, s);\n }\n students.sort!(\"a.sum==b.sum ? a.id<b.id : a.sum>b.sum\");\n foreach(i, student; students){\n if(student.id==0){\n writeln(i+1);\n return;\n }\n }\n\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}, {"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tint[] m = new int[t];\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\tint c=0;\n\t\tint d=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\treadf(\" %d\", &d);\n\t\tint sum=a+b+c+d;\n\t\tm[i]=sum;\n\t}\n\tint count=1;\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tif (m[i]>m[0])\n\t\t{\n\t\t\tcount=count+1;\n\t\t}\n\t}\n\twriteln(count);\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\n\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tint h=0;\n\tint j=0;\n\tint k=0;\n\tint l=0;\n\treadf(\" %d\", &h);\n\treadf(\" %d\", &j);\n\treadf(\" %d\", &k);\n\treadf(\" %d\", &l);\n\tint tsum=h+j+k+l;\n\tint pl=1;\n\tfor (int i=0; i<t-1; i++)\n\t{\n\t\tint a=0;\n\t\tint b=0;\n\t\tint c=0;\n\t\tint d=0;\n\t\treadf(\" %d\", &a);\n\t\treadf(\" %d\", &b);\n\t\treadf(\" %d\", &c);\n\t\treadf(\" %d\", &d);\n\t\tint sum=a+b+c+d;\n\t\tif (sum>=tsum)\n\t\t{\n\t\t\tpl=pl+1;\n\t\t}\n\t}\n\tif (pl==1)\n\t{\n\t\twriteln(pl);\n\t}\n\telse\n\t{\n\t\twriteln(pl-1);\n\t}\n\treturn 0;\n}"}], "src_uid": "3c984366bba580993d1694d27982a773"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int N; get(N);\r\n writefln!\"? %d %d\"(1, N); stdout.flush();\r\n int p; get(p);\r\n int q;\r\n if (p == 1) {\r\n q = -1;\r\n } else if (p == N) {\r\n q = N;\r\n } else {\r\n writefln!\"? %d %d\"(1, p); stdout.flush();\r\n get(q);\r\n }\r\n if (p == q) {\r\n int l = 1, r = p;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n writefln!\"? %d %d\"(m, p); stdout.flush();\r\n get(q);\r\n if (p == q) {\r\n l = m;\r\n } else {\r\n r = m;\r\n }\r\n }\r\n writeln(\"! \", l); stdout.flush();\r\n } else {\r\n int l = p, r = N;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n writefln!\"? %d %d\"(p, m); stdout.flush();\r\n get(q);\r\n if (p == q) {\r\n r = m;\r\n } else {\r\n l = m;\r\n }\r\n }\r\n writeln(\"! \", r); stdout.flush();\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto n = RD!int;\r\n\t\t\r\n\tint l = 1, r = n;\r\n\twriteln(\"? \", l, \" \", r);\r\n\tstdout.flush;\r\n\tauto m = RD!int;\r\n\twhile (r - l > 1)\r\n\t{\r\n\t\tauto m2 = (l+r)/2;\r\n\t\tif (m <= m2)\r\n\t\t{\r\n\t\t\tauto ll = min(m, l);\r\n\t\t\tauto rr = m2;\r\n\t\t\twriteln(\"? \", ll, \" \", rr);\r\n\t\t\tstdout.flush;\r\n\t\t\tauto a = RD!int;\r\n\t\t\tif (a == m)\r\n\t\t\t\tr = m2;\r\n\t\t\telse\r\n\t\t\t\tl = m2;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tauto ll = m2;\r\n\t\t\tauto rr = max(m, r);\r\n\t\t\twriteln(\"? \", ll, \" \", rr);\r\n\t\t\tstdout.flush;\r\n\t\t\tauto a = RD!int;\r\n\t\t\tif (a == m)\r\n\t\t\t\tl = m2;\r\n\t\t\telse\r\n\t\t\t\tr = m2;\r\n\t\t}\r\n\t}\r\n\r\n\twriteln(\"? \", l, \" \", r);\r\n\tstdout.flush;\r\n\tm = RD!int;\r\n\tif (m == l)\r\n\t\twriteln(\"! \", r);\r\n\telse\r\n\t\twriteln(\"! \", l);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int N; get(N);\r\n writefln!\"? %d %d\"(1, N); stdout.flush();\r\n int p; get(p);\r\n writefln!\"? %d %d\"(1, p); stdout.flush();\r\n int q; get(q);\r\n if (p == q) {\r\n int l = 1, r = p;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n writefln!\"? %d %d\"(m, p); stdout.flush();\r\n get(q);\r\n if (p == q) {\r\n l = m;\r\n } else {\r\n r = m;\r\n }\r\n }\r\n writeln(\"! \", l); stdout.flush();\r\n } else {\r\n int l = p, r = N;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n writefln!\"? %d %d\"(p, m); stdout.flush();\r\n get(q);\r\n if (p == q) {\r\n r = m;\r\n } else {\r\n l = m;\r\n }\r\n }\r\n writeln(\"! \", r); stdout.flush();\r\n }\r\n}\r\n"}], "src_uid": "eb660c470760117dfd0b95acc10eee3b"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x;\n\t\treadf !(\" %s %s\") (n, x);\n\t\treadln;\n\t\tauto s = readln.splitter.map !(to !(int)).array;\n\t\tauto odds = s.count !(q{a % 2 != 0}).to !(int);\n\t\tauto evens = s.length.to !(int) - odds;\n\t\tbool ok = false;\n\t\tforeach (i; 0..x + 1)\n\t\t{\n\t\t\tauto j = x - i;\n\t\t\tif (i <= odds && j <= evens)\n\t\t\t{\n\t\t\t\tif (i % 2 != 0)\n\t\t\t\t{\n\t\t\t\t\tok = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto x = RD!int;\n\t\tauto a = RDA;\n\n\t\tlong e, o;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] % 2)\n\t\t\t\t++o;\n\t\t\telse\n\t\t\t\t++e;\n\t\t}\n\n\t\tif (o == 0) continue;\n\n\t\tauto y = min(o, x);\n\t\tif (y % 2 == 0)\n\t\t{\n\t\t\t--y;\n\t\t}\n\t\tx -= y;\n\t\tans[ti] = e >= x;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"Yes\" : \"No\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "afce38aa7065da88d824d1d981b5b338"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, x, y;\n readf(\"%s %s %s\", &n, &x, &y);\n readln;\n \n auto s = readln.chomp;\n \n auto seg = cast(int)(s[0] == '0');\n foreach (a, b; lockstep(s, s.dropOne)) {\n if (a == '1' && b == '0') ++seg;\n }\n \n if (seg == 0) {\n writeln(0);\n return;\n }\n \n auto ans = min(cast(long)seg * y, cast(long)(seg - 1) * x + y);\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, x, y;\n\twhile (readf (\" %s %s %s\", &n, &x, &y) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip ~ '1';\n\t\tauto k = n.iota.map !(i => s[i..i + 2] == \"01\").sum;\n\t\tlong res = 0;\n\t\tif (k > 0)\n\t\t{\n\t\t\tres += y;\n\t\t\tk -= 1;\n\t\t}\n\t\tres += k * 1L * min (x, y);\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const X = readLong();\n const Y = readLong();\n const A = readToken();\n \n long cnt;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && A[i] == A[j]; ++j) {}\n if (A[i] == '0') {\n ++cnt;\n }\n }\n long ans;\n if (cnt >= 1) {\n ans += (cnt - 1) * min(X, Y);\n ans += Y;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, x, y;\n readf(\"%s %s %s\", &n, &x, &y);\n readln;\n \n auto s = readln.chomp;\n \n auto seg = cast(int)(s[0] == '0');\n foreach (a, b; lockstep(s, s.dropOne)) {\n if (a == '1' && b == '0') ++seg;\n }\n \n auto ans = min(cast(long)seg * y, cast(long)(seg - 1) * x + y);\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, x, y;\n readf(\"%s %s %s\", &n, &x, &y);\n readln;\n \n auto s = readln.chomp;\n \n if (n == 1) {\n writeln(s[0] == '1' ? 0 : y);\n return;\n }\n \n auto seg = cast(int)(s[0] == '0');\n foreach (a, b; lockstep(s, s.dropOne)) {\n if (a == '1' && b == '0') ++seg;\n }\n \n auto ans = min(cast(long)seg * y, cast(long)(seg - 1) * x + y);\n \n ans.writeln;\n}"}], "src_uid": "b267f69cc4af3e319fc59e3ccd8b1c9d"} {"source_code": "import std.stdio, std.string;\n\nvoid solve(int[] a, int n)\n{\n auto dp = new int[n];\n auto prev = new int[n];\n int[int] pos;\n foreach (i; 0 .. n)\n {\n dp[i] = 1;\n prev[i] = -1;\n auto val = a[i] - 1;\n if (val in pos)\n {\n prev[i] = pos[val]; \n dp[i] = dp[prev[i]] + 1;\n }\n pos[a[i]] = i;\n }\n auto best = 0, idx = -1;\n foreach (i; 0 .. n)\n {\n if (dp[i] > best)\n {\n best = dp[i];\n idx = i;\n }\n }\n writeln(best);\n auto ans = new int[best];\n foreach (i; 0 .. best)\n {\n ans[best - i - 1] = idx + 1;\n idx = prev[idx];\n }\n foreach (i; 0 .. best - 1)\n {\n write(ans[i], \" \");\n }\n writeln(ans[best - 1]);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a, n);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\n\nvoid solve(int[] a, int n)\n{\n auto dp = new int[n];\n auto prev = new int[n];\n int[int] pos;\n foreach (i; 0 .. n)\n {\n dp[i] = 1;\n prev[i] = -1;\n auto val = a[i] - 1;\n if (val in pos)\n {\n prev[i] = pos[val]; \n dp[i] = dp[prev[i]] + 1;\n }\n pos[a[i]] = i;\n }\n auto best = 0, idx = -1;\n foreach (i; 0 .. n)\n {\n if (dp[i] > best)\n {\n best = dp[i];\n idx = i;\n }\n }\n auto ans = new int[best];\n foreach (i; 0 .. best)\n {\n ans[best - i - 1] = idx + 1;\n idx = prev[idx];\n }\n writeln(best);\n foreach (i; 0 .. best - 1)\n {\n write(ans[i], \" \");\n }\n writeln(ans[best - 1]);\n}\n\nint main(string[] args)\n{\n int n;\n while (readf(\"%d\\n\", &n) == 1)\n {\n auto a = new int[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n solve(a, n);\n }\n return 0;\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n readln;\n \n auto a = readln.split.map!(to!int).array;\n \n int [int] v;\n a.each!(e => v[e] = max(v.get(e, 0), v.get(e-1, 0) + 1));\n \n debug { writeln(v); }\n \n auto p = v.byKeyValue().maxElement!(q{ a.value });\n auto st = p.key - p.value + 1;\n \n debug { writeln(st); }\n \n int [] ans;\n foreach (i, e; a.enumerate(1)) {\n if (e == st) {\n ++st;\n ans ~= i;\n }\n }\n \n writeln(ans.length);\n writefln(\"%(%s %)\", ans);\n}"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n int n; readV(n);\n int[] a; readA(n, a);\n\n int[int] b;\n foreach (i; 0..n) {\n if (a[i]-1 in b) b[a[i]] = b[a[i]-1]+1;\n else b[a[i]] = 1;\n }\n\n auto c = -1, m = 0;\n foreach (k, v; b)\n if (v > m) {\n m = v;\n c = k;\n }\n\n writeln(m);\n\n auto d = c-m+1;\n foreach (i; 0..n)\n if (a[i] == d) {\n write(i+1, \" \");\n ++d;\n }\n writeln;\n}\n"}], "negative_code": [], "src_uid": "70986d3b1ff66ac612e8841a6049866d"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nalias Point = Tuple !(real, q{x}, real, q{y});\n\nreal sp (Point a, Point b, Point c)\n{\n\treturn (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y);\n}\n\nvoid main ()\n{\n\tint n;\n\tPoint p;\n\twhile (readf (\" %s %s %s\", &n, &p.x, &p.y) > 0)\n\t{\n\t\tauto a = new Point [n];\n\t\tforeach (ref s; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &s.x, &s.y);\n\t\t}\n\t\tauto d = a.map !(s => hypot (s.y - p.y, s.x - p.x)).array;\n\t\treal r1 = d.minPos.front;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto u = a[i];\n\t\t\tauto v = a[(i + 1) % n];\n\t\t\tauto ta = u.y - v.y;\n\t\t\tauto tb = v.x - u.x;\n\t\t\tauto tc = -(u.x * ta + u.y * tb);\n\t\t\tauto td = -(p.x * ta + p.y * tb);\n\t\t\tauto dis = ta ^^ 2 + tb ^^ 2;\n\t\t\tauto delta = (td - tc) / dis;\n\t\t\tauto w = Point (p.x + ta * delta, p.y + tb * delta);\n\t\t\tdebug {writeln (u, \" \", v, \" \", w);}\n\t\t\tif (sp (w, u, v) < 0)\n\t\t\t{\n\t\t\t\tr1 = min (r1, hypot (w.y - p.y, w.x - p.x));\n\t\t\t}\n\t\t}\n\t\treal r2 = d.minPos !(q{a > b}).front;\n\t\treal res = PI * (r2 ^^ 2 - r1 ^^ 2);\n\t\twritefln (\"%.20f\", res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.math;\n\nvoid main(string[] args)\n{\n string input;\n readf!\"%s\"(input);\n auto words = input.split;\n debug writeln(\"words are = \", words);\n auto n = words[0].to!int;\n real[2] p;\n p[] = [words[1].to!real, words[2].to!real];\n auto polygon = new real[2][](n);\n foreach(i, ref pi; polygon)\n pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];\n debug writeln(\"n = \", n, \" p = \", p, \" polygon = \", polygon);\n auto distances = polygon.map!(point => euclideanDistance([point[0], point[1]],\n\t\t\t\t\t\t\t [p[0], p[1]])).array;\n auto minDistance = distances.fold!min;\n auto maxDistance = distances.fold!max;\n foreach(i, pi; polygon)\n {\n auto np = i + 1 >= polygon.length? polygon[0] : polygon[i + 1];\n real[2] d = [np[0] - pi[0], np[1] - pi[1]];\n auto t = (dotProduct(p, d) - dotProduct(pi, d)) / dotProduct(d, d);\n if (0 <= t && t <= 1)\n\t{\n\t real[2] lp = [pi[0] + t * d[0], pi[1] + t * d[1]];\n\t minDistance = min(minDistance, euclideanDistance(lp[], p[]));\n\t}\n }\n auto outerCircle = maxDistance * maxDistance * PI;\n auto innerCircle = minDistance * minDistance * PI;\n auto res = outerCircle - innerCircle;\n stdout.writefln!\"%.20s\"(res);\n}\n\nstatic this()\n{\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else static if (isTuple!T)\n\t{\n\t T res;\n\t static foreach(i; 0 .. T.length)\n\t {\n\t res[i] = next!(typeof(res[i]));\n\t }\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.math;\n\nvoid main(string[] args)\n{\n string input;\n readf!\"%s\"(input);\n auto words = input.split;\n auto n = words[0].to!int;\n real[2] p;\n p[] = [words[1].to!real, words[2].to!real];\n auto polygon = new real[2][](n);\n foreach(i, ref pi; polygon) pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];\n \n auto minDistance = iota(0, n)\n .map!(i => segmentPointDistance(p, polygon[i], polygon[(i + 1)%n]))\n .fold!min;\n auto maxDistance = polygon\n .map!(point => euclideanDistance(point[], p[]))\n .fold!max;\n auto outerCircle = maxDistance * maxDistance * PI;\n auto innerCircle = minDistance * minDistance * PI;\n stdout.writefln!\"%.20s\"(outerCircle - innerCircle);\n}\n\nauto segmentPointDistance(T)(T p, T a, T b)\n{\n real[2] d = [b[0] - a[0], b[1] - a[1]];\n auto t = (dotProduct(p, d) - dotProduct(a, d)) / dotProduct(d, d);\n if (0 <= t && t <= 1)\n {\n real[2] lp = [a[0] + t * d[0], a[1] + t * d[1]];\n return euclideanDistance(lp[], p[]);\n }\n else\n {\n return min(euclideanDistance(a[], p[]), euclideanDistance(b[], p[]));\n }\n}\n\nstatic this()\n{\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else static if (isTuple!T)\n\t{\n\t T res;\n\t static foreach(i; 0 .. T.length)\n\t {\n\t res[i] = next!(typeof(res[i]));\n\t }\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.math;\n\nvoid main(string[] args)\n{\n string input;\n readf!\"%s\"(input);\n auto words = input.split;\n auto n = words[0].to!int;\n real[2] p; p[] = [words[1].to!real, words[2].to!real];\n auto polygon = new real[2][](n);\n foreach(i, ref pi; polygon) pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];\n auto minMax = iota(0, n)\n .map!(i => segmentPointDistance(p, polygon[i], polygon[(i + 1)%n]),\n\t i => euclideanDistance(p[], polygon[i][]))\n .fold!((minmax, x) => tuple(min(minmax[0], x[0]), max(minmax[1], x[1])));\n auto minDistance = minMax[0];\n auto maxDistance = minMax[1];\n auto outerCircle = maxDistance * maxDistance * PI;\n auto innerCircle = minDistance * minDistance * PI;\n stdout.writefln!\"%.20s\"(outerCircle - innerCircle);\n}\n\nauto segmentPointDistance(T)(T p, T a, T b)\n{\n real[2] d = [b[0] - a[0], b[1] - a[1]];\n auto t = (dotProduct(p, d) - dotProduct(a, d)) / dotProduct(d, d);\n if (0 <= t && t <= 1)\n {\n real[2] lp = [a[0] + t * d[0], a[1] + t * d[1]];\n return euclideanDistance(lp[], p[]);\n }\n else\n {\n return min(euclideanDistance(a[], p[]), euclideanDistance(b[], p[]));\n }\n}\n\nstatic this()\n{\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else static if (isTuple!T)\n\t{\n\t T res;\n\t static foreach(i; 0 .. T.length)\n\t {\n\t res[i] = next!(typeof(res[i]));\n\t }\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nalias Point = Tuple !(real, q{x}, real, q{y});\n\nvoid main ()\n{\n\tint n;\n\tPoint p;\n\twhile (readf (\" %s %s %s\", &n, &p.x, &p.y) > 0)\n\t{\n\t\tauto a = new Point [n];\n\t\tforeach (ref s; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &s.x, &s.y);\n\t\t}\n\t\tauto d = a.map !(s => hypot (s.y - p.y, s.x - p.x)).array;\n\t\treal r1 = d.minPos.front;\n\t\treal r2 = d.minPos !(q{a > b}).front;\n\t\treal res = PI * (r2 ^^ 2 - r1 ^^ 2);\n\t\twritefln (\"%.20f\", res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nalias Point = Tuple !(real, q{x}, real, q{y});\n\nreal sp (Point a, Point b, Point c)\n{\n\treturn (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y);\n}\n\nvoid main ()\n{\n\tint n;\n\tPoint p;\n\twhile (readf (\" %s %s %s\", &n, &p.x, &p.y) > 0)\n\t{\n\t\tauto a = new Point [n];\n\t\tforeach (ref s; a)\n\t\t{\n\t\t\treadf (\" %s %s\", &s.x, &s.y);\n\t\t}\n\t\tauto d = a.map !(s => hypot (s.y - p.y, s.x - p.x)).array;\n\t\treal r1 = d.minPos.front;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto u = a[i];\n\t\t\tauto v = a[(i + 1) % n];\n\t\t\tauto ta = u.y - v.y;\n\t\t\tauto tb = v.x - u.x;\n\t\t\tauto tc = -(u.x * ta + u.y * tb);\n\t\t\tauto td = -(p.x * ta + p.y * tb);\n\t\t\tauto dis = ta ^^ 2 + tb ^^ 2;\n\t\t\tauto delta = (td - tc) / dis;\n\t\t\tauto w = Point (p.x + ta * delta, p.y + tb * delta);\n\t\t\tdebug {writeln (u, \" \", v, \" \", w);}\n\t\t\tif (sp (w, u, v) < 0)\n\t\t\t{\n\t\t\t\tr1 = min (r1, delta);\n\t\t\t}\n\t\t}\n\t\treal r2 = d.minPos !(q{a > b}).front;\n\t\treal res = PI * (r2 ^^ 2 - r1 ^^ 2);\n\t\twritefln (\"%.20f\", res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.math;\n\nvoid main(string[] args)\n{\n string input;\n readf!\"%s\"(input);\n auto words = input.split;\n debug writeln(\"words are = \", words);\n auto n = words[0].to!int;\n real[2] p;\n p[] = [words[1].to!real, words[2].to!real];\n auto polygon = new real[2][](n);\n foreach(i, ref pi; polygon)\n pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];\n debug writeln(\"n = \", n, \" p = \", p, \" polygon = \", polygon);\n auto distances = polygon.map!(point => euclideanDistance([point[0], point[1]],\n\t\t\t\t\t\t\t [p[0], p[1]])).array;\n auto minDistance = distances.fold!min;\n auto maxDistance = distances.fold!max;\n auto outerCircle = maxDistance * maxDistance * PI;\n auto innerCircle = minDistance * minDistance * PI;\n println(outerCircle - innerCircle);\n}\n\nstatic this()\n{\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else static if (isTuple!T)\n\t{\n\t T res;\n\t static foreach(i; 0 .. T.length)\n\t {\n\t res[i] = next!(typeof(res[i]));\n\t }\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.math;\n\nvoid main(string[] args)\n{\n string input;\n readf!\"%s\"(input);\n auto words = input.split;\n debug writeln(\"words are = \", words);\n auto n = words[0].to!int;\n real[2] p;\n p[] = [words[1].to!real, words[2].to!real];\n auto polygon = new real[2][](n);\n foreach(i, ref pi; polygon)\n pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];\n debug writeln(\"n = \", n, \" p = \", p, \" polygon = \", polygon);\n auto distances = polygon.map!(point => euclideanDistance([point[0], point[1]],\n\t\t\t\t\t\t\t [p[0], p[1]])).array;\n auto minDistance = distances.fold!min;\n auto maxDistance = distances.fold!max;\n auto outerCircle = maxDistance * maxDistance * PI;\n auto innerCircle = minDistance * minDistance * PI;\n auto res = outerCircle - innerCircle;\n stdout.writefln!\"%.20s\"(res);\n}\n\nstatic this()\n{\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else static if (isTuple!T)\n\t{\n\t T res;\n\t static foreach(i; 0 .. T.length)\n\t {\n\t res[i] = next!(typeof(res[i]));\n\t }\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n"}], "src_uid": "1d547a38250c7780ddcf10674417d5ff"} {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto s = readln.split;\n auto N = s[0].to!int;\n auto L = s[1].to!long;\n auto A = s[2].to!long;\n long[] T, X;\n foreach (i; 0..N) {\n s = readln.split;\n T ~= s[0].to!long;\n X ~= s[1].to!long;\n }\n T ~= L;\n X ~= 0;\n\n long t = 0;\n long ans = 0;\n\n foreach (i; 0..N+1) {\n long interaval = T[i] - t;\n ans += interaval / A;\n t = T[i] + X[i];\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, l, a;\n rd(n, l, a);\n auto s = new int[](n), t = new int[](n);\n foreach (i; 0 .. n)\n rd(s[i], t[i]);\n\n long cnt = 0;\n foreach (i; 1 .. n) {\n cnt += (s[i] - (s[i - 1] + t[i - 1])) / a;\n }\n if (n > 0) {\n cnt += (s[0]) / a;\n cnt += (l - (s[$ - 1] + t[$ - 1])) / a;\n } else {\n cnt += l / a;\n }\n writeln(cnt);\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "00acb3b54975820989a788b9389c7c0b"} {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nvoid bAdd(T)(T[] bit, int pos, T val)\nin {\n assert(0 <= pos && pos < bit.length, \"bAdd: 0 <= pos < |bit| must hold\");\n}\ndo {\n for (int x = pos; x < bit.length; x |= x + 1) {\n bit[x] += val;\n }\n}\n\n// sum of [0, pos)\nT bSum(T)(T[] bit, int pos)\nin {\n assert(0 <= pos && pos <= bit.length, \"bSum: 0 <= pos <= |bit| must hold\");\n}\ndo {\n T ret = 0;\n for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {\n ret += bit[x];\n }\n return ret;\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new int[N];\n foreach (i; 0 .. N) {\n P[i] = readInt() - 1;\n }\n \n auto Q = new int[N];\n foreach (i; 0 .. N) {\n Q[P[i]] = i;\n }\n \n auto ans = new long[N];\n \n // move\n int cntL, cntR;\n long sumL, sumR;\n auto setL = new RedBlackTree!int;\n auto setR = new RedBlackTree!int;\n foreach (j; 0 .. N) {\n if (setR.empty || Q[j] < setR.front) {\n cntL += 1;\n sumL += Q[j];\n setL.insert(Q[j]);\n } else {\n cntR += 1;\n sumR += Q[j];\n setR.insert(Q[j]);\n }\n for (; cntL > (j + 1) / 2; ) {\n const i = setL.back;\n cntL -= 1;\n sumL -= i;\n setL.removeKey(i);\n cntR += 1;\n sumR += i;\n setR.insert(i);\n }\n for (; cntL < (j + 1) / 2; ) {\n const i = setR.front;\n cntR -= 1;\n sumR -= i;\n setR.removeKey(i);\n cntL += 1;\n sumL += i;\n setL.insert(i);\n }\n debug {\n writeln(\"j = \", j);\n writeln(\" L: \", cntL, \" \", sumL, \" \", setL);\n writeln(\" R: \", cntR, \" \", sumR, \" \", setR);\n }\n const long i0 = setR.front;\n debug {\n writeln(\" cost L: \", i0 * (i0 - 1) / 2 - (i0 - cntL) * (i0 - cntL - 1) / 2, \" - \", sumL);\n writeln(\" cost R: \", sumR, \" - \", (i0 + cntR) * (i0 + cntR - 1) / 2 - i0 * (i0 - 1) / 2);\n }\n ans[j] += i0 * (i0 - 1) / 2 - (i0 - cntL) * (i0 - cntL - 1) / 2;\n ans[j] -= sumL;\n ans[j] += sumR;\n ans[j] -= (i0 + cntR) * (i0 + cntR - 1) / 2 - i0 * (i0 - 1) / 2;\n }\n debug {\n writeln(\"ans (move) = \", ans);\n }\n \n // inversion\n auto bit = new long[N];\n long now;\n foreach (j; 0 .. N) {\n now += j - bit.bSum(Q[j]);\n ans[j] += now;\n bit.bAdd(Q[j], 1);\n }\n \n foreach (j; 0 .. N) {\n if (j > 0) write(\" \");\n write(ans[j]);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(x => x.to!int-1).array;\n\n auto B = new int[](N);\n foreach (i, a; A) B[a] = i.to!int;\n\n auto st = new SegmentTree!(long, (a,b)=>a+b, 0L)(N);\n st.add(B[0], 1);\n\n auto leftpq = new BinaryHeap!(Array!long, \"a < b\");\n auto rightpq = new BinaryHeap!(Array!long, \"a > b\");\n leftpq.insert(B[0]);\n\n long leftsum = B[0];\n long rightsum = 0;\n long inversion = 0;\n\n write(0);\n\n foreach (a; 1..N) {\n auto left = B[a] == 0 ? 0 : st.query(0, B[a] - 1);\n auto right = B[a] == N - 1 ? 0 : st.query(B[a] + 1, N - 1);\n inversion += right;\n\n if (leftpq.length == rightpq.length) {\n leftpq.insert(B[a]);\n leftsum += B[a];\n } else {\n rightpq.insert(B[a]);\n rightsum += B[a];\n }\n\n while (leftpq.front > rightpq.front) {\n auto l = leftpq.front;\n auto r = rightpq.front;\n leftpq.removeFront;\n rightpq.removeFront;\n leftsum -= l;\n rightsum -= r;\n leftpq.insert(r);\n rightpq.insert(l);\n leftsum += r;\n rightsum += l;\n }\n\n auto med = leftpq.front;\n auto n = leftpq.length.to!long - 1;\n auto m = rightpq.length.to!long;\n\n long ans = inversion + (med * n - (leftsum - med) - n - n * (n - 1) / 2) + (rightsum - med * m - m - m * (m - 1) / 2);\n\n write(\" \", ans);\n\n st.add(B[a], 1);\n }\n\n writeln;\n}\n\nclass SegmentTree(T, alias op, T e) {\n T[] table;\n int size;\n int offset;\n\n this(int n) {\n size = 1;\n while (size <= n) size <<= 1;\n size <<= 1;\n table = new T[](size);\n fill(table, e);\n offset = size / 2;\n }\n\n void assign(int pos, T val) {\n pos += offset;\n table[pos] = val;\n while (pos > 1) {\n pos /= 2;\n table[pos] = op(table[pos*2], table[pos*2+1]);\n }\n }\n\n void add(int pos, T val) {\n pos += offset;\n table[pos] += val;\n while (pos > 1) {\n pos /= 2;\n table[pos] = op(table[pos*2], table[pos*2+1]);\n }\n }\n\n T query(int l, int r) {\n return query(l, r, 1, 0, offset-1);\n }\n\n T query(int l, int r, int i, int a, int b) {\n if (b < l || r < a) {\n return e;\n } else if (l <= a && b <= r) {\n return table[i];\n } else {\n return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));\n }\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(x => x.to!int-1).array;\n\n auto B = new int[](N);\n foreach (i, a; A) B[a] = i.to!int;\n\n auto st = new SegmentTree!(long, (a,b)=>a+b, 0L)(N);\n st.add(B[0], 1);\n\n int leftmost = B[0];\n int rightmost = B[0];\n long move = 0;\n\n long ans = 0;\n write(ans);\n\n foreach (a; 1..N) {\n auto left = B[a] == 0 ? 0 : st.query(0, B[a] - 1);\n auto right = B[a] == N - 1 ? 0 : st.query(B[a] + 1, N - 1);\n ans += right;\n\n if (B[a] < leftmost) {\n ans += 1L * (leftmost - B[a] - 1) * a;\n } else {\n ans += B[a] - leftmost - left;\n ans -= right;\n }\n\n write(\" \", ans);\n\n st.add(B[a], 1);\n leftmost = min(leftmost, B[a]);\n rightmost = max(rightmost, B[a]);\n }\n\n writeln;\n}\n\nclass SegmentTree(T, alias op, T e) {\n T[] table;\n int size;\n int offset;\n\n this(int n) {\n size = 1;\n while (size <= n) size <<= 1;\n size <<= 1;\n table = new T[](size);\n fill(table, e);\n offset = size / 2;\n }\n\n void assign(int pos, T val) {\n pos += offset;\n table[pos] = val;\n while (pos > 1) {\n pos /= 2;\n table[pos] = op(table[pos*2], table[pos*2+1]);\n }\n }\n\n void add(int pos, T val) {\n pos += offset;\n table[pos] += val;\n while (pos > 1) {\n pos /= 2;\n table[pos] = op(table[pos*2], table[pos*2+1]);\n }\n }\n\n T query(int l, int r) {\n return query(l, r, 1, 0, offset-1);\n }\n\n T query(int l, int r, int i, int a, int b) {\n if (b < l || r < a) {\n return e;\n } else if (l <= a && b <= r) {\n return table[i];\n } else {\n return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));\n }\n }\n}"}], "src_uid": "e3277a9871e91954766e8c87b193fc96"} {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{ \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto n = readln.chomp.to!int;\r\n auto arr = readln.chomp.split.map!(to!long).array;\r\n \r\n bool solve(long[] arr) {\r\n if (arr.any!(x => x % 2 == 1)) { return false; }\r\n \r\n arr.sort();\r\n \r\n debug { arr.writeln; }\r\n \r\n long[] sums;\r\n foreach (i; arr.length.iota.stride(2)) {\r\n if (arr[i] != arr[i+1]) { return false; }\r\n \r\n sums ~= arr[i] / 2;\r\n }\r\n \r\n foreach (i; 1 .. sums.length) {\r\n if (sums[i] == sums[i-1]) { return false; }\r\n }\r\n \r\n debug { sums.writeln; }\r\n \r\n auto tot = sums[0];\r\n foreach (i; 1 .. sums.length) {\r\n auto left = sums.length - i.to!long;\r\n auto diff = sums[i] - sums[i-1];\r\n \r\n if (diff % i != 0) { return false; }\r\n \r\n tot -= diff / i * left;\r\n \r\n debug { tot.writeln; }\r\n }\r\n \r\n return tot > 0 && tot % sums.length == 0;\r\n }\r\n \r\n writeln(solve(arr) ? \"YES\": \"NO\");\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n long[] D; get(D);\r\n sort(D);\r\n long[] dd;\r\n long a;\r\n for (int i; i < N * 2; i += 2) {\r\n if (D[i] != D[i+1] || D[i] % 2 != 0) goto ng;\r\n if (!dd.empty && dd[$-1] == D[i]) goto ng;\r\n dd ~= D[i];\r\n }\r\n if (dd[$-1] % (2 * N) != 0) goto ng;\r\n a = dd[$-1] / N / 2;\r\n foreach_reverse (i; 1..N) {\r\n auto d = dd[i] - dd[i-1];\r\n if (d % (i*2) != 0) goto ng;\r\n a -= d / (i*2);\r\n if (a <= 0) goto ng;\r\n }\r\n writeln(\"YES\");\r\n continue;\r\n ng:\r\n writeln(\"NO\");\r\n }\r\n}\r\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n;\n n = scan!int;\n auto arr = scanArray;\n arr.sort;\n ll[] ray;\n for(int i = 0; i < n; ++i){\n if(arr[2*i] != arr[2*i + 1]){\n writeln(\"NO\");\n return;\n }else{\n ray ~= arr[2*i];\n }\n }\n ray.reverse;\n show(ray);\n ll[] nums;\n ll msum = 0, tim = n;\n for(int i = 0; i < n; ++i){\n if(ray[i] % 2 != 0){\n writeln(\"NO\");\n return;\n }else{\n ll cval = ray[i]/2;\n cval -= msum;\n if(cval % tim != 0){\n writeln(\"NO\");\n return;\n }\n ll val = cval/tim;\n nums ~= val;\n msum += val;\n --tim;\n }\n }\n show(\"NUMS: \", nums);\n for(int i = 1; i < n; ++i){\n if(nums[i] >= nums[i-1]){\n writeln(\"NO\");\n return;\n }\n }\n for(int i = 0; i < n; ++i){\n if(nums[i] <= 0){\n writeln(\"NO\");\n return;\n }\n }\n writeln(\"YES\");\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto d = RDA;\r\n\r\n\t\td.sort!\"a > b\";\r\n\t\tlong[] a;\r\n\t\tbool ok = true;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (d[i*2] != d[i*2+1])\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\ta ~= d[i*2];\r\n\t\t}\r\n\t\tif (!ok) continue;\r\n\r\n\t\tlong tot;\r\n\t\tbool[long] used;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = a[i] - tot;\r\n\t\t\tdebug writeln(\"i:\", i, \" a[i]:\", a[i], \" x:\", x, \" tot:\", tot);\r\n\t\t\tif (x <= 0 || x % ((n-i) * 2))\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tauto y = x / (n-i);\r\n\t\t\t\tif (used.get(y, false))\r\n\t\t\t\t{\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tused[y] = true;\r\n\t\t\t\ttot += y;\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n long[] D = readarray!long;\r\n\r\n bool C() {\r\n foreach (d; D) {\r\n if (d % 2 != 0) return false;\r\n }\r\n int[long] M;\r\n long[] X;\r\n foreach (d; D) {\r\n M[d] = M.get(d, 0) + 1;\r\n if (M[d] % 2 == 0) {\r\n X ~= d;\r\n }\r\n }\r\n foreach (k, cnt; M) {\r\n if (cnt % 2 != 0) return false;\r\n }\r\n assert(X.length == N);\r\n sort(X);\r\n auto A = new long[N];\r\n long S = X[0] / 2L;\r\n long Z = 0;\r\n auto K = new long[N];\r\n for (int i = 0; i < N-1; i++) {\r\n if ( (X[i+1] - X[i]) % (2L * (i+1)) != 0 ) return false;\r\n K[i] = (X[i+1] - X[i]) / (2L * (i+1));\r\n }\r\n long A0 = S;{\r\n for (int i = 0; i < N-1; i++) {\r\n A0 -= (N - 1L - i) * K[i];\r\n }\r\n if (A0 % N != 0) return false;\r\n A0 /= N;\r\n }\r\n A[0] = A0;\r\n for (int i = 0; i < N-1; i++) {\r\n A[i+1] = A[i] + K[i];\r\n }\r\n /*\r\n writeln(\"X: \", X);\r\n writeln(\"S: \", S);\r\n writeln(A);\r\n */\r\n auto B = A.dup;\r\n int m = B.sort.uniq.array.length;\r\n return A[0] >= 1 && S == sum(A) && m == N;\r\n }\r\n writeln(C() ? \"YES\" : \"NO\");\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (int n, long [] d)\r\n{\r\n\tsort (d);\r\n\tauto g = d.group.array;\r\n\tif (!g.all !(q{a[1] == 2}))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tauto h = d.stride (2).array;\r\n\tif (!h.all !(q{a % 2 == 0}))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\th[] /= 2;\r\n\tbool [long] s;\r\n\tlong total = 0;\r\n\tforeach_reverse (i; 0..n)\r\n\t{\r\n\t\th[i] -= total;\r\n\t\tif (h[i] % (i + 1) != 0)\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\tauto cur = h[i] / (i + 1);\r\n\t\tif (cur <= 0)\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\ttotal += cur;\r\n\t\ts[cur] = true;\r\n\t}\r\n\treturn s.length == n;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto d = readln.splitter.map !(to !(long)).array;\r\n\t\twriteln (solve (n, d) ? \"YES\" : \"NO\");\r\n\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto d = RDA;\r\n\r\n\t\td.sort!\"a > b\";\r\n\t\tlong[] a;\r\n\t\tbool ok = true;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (d[i*2] != d[i*2+1])\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\ta ~= d[i*2];\r\n\t\t}\r\n\t\tif (!ok) continue;\r\n\r\n\t\tlong tot;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = a[i] - tot;\r\n\t\t\tdebug writeln(\"i:\", i, \" a[i]:\", a[i], \" x:\", x, \" tot:\", tot);\r\n\t\t\tif (x <= 1 || x % (n-i))\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\ttot += x / (n-i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto d = RDA;\r\n\r\n\t\td.sort!\"a > b\";\r\n\t\tbool ok = true;\r\n\t\tint[long] cnt;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\t++cnt[d[i]];\r\n\t\t}\r\n\t\tforeach (e; cnt.values)\r\n\t\t{\r\n\t\t\tif (e != 2)\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (!ok) continue;\r\n\r\n\t\tlong[] a;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\ta ~= d[i*2];\r\n\t\t}\r\n\r\n\t\tlong tot;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = a[i] - tot;\r\n\t\t\tdebug writeln(\"i:\", i, \" a[i]:\", a[i], \" x:\", x, \" tot:\", tot);\r\n\t\t\tif (x <= 0 || x % ((n-i) * 2))\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\ttot += x / (n-i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto d = RDA;\r\n\r\n\t\td.sort!\"a > b\";\r\n\t\tlong[] a;\r\n\t\tbool ok = true;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (d[i*2] != d[i*2+1])\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\ta ~= d[i*2];\r\n\t\t}\r\n\t\tif (!ok) continue;\r\n\r\n\t\tlong tot;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = a[i] - tot;\r\n\t\t\tdebug writeln(\"i:\", i, \" a[i]:\", a[i], \" x:\", x, \" tot:\", tot);\r\n\t\t\tif (x <= 0 || x % ((n-i) * 2))\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\ttot += x / (n-i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto d = RDA;\r\n\r\n\t\td.sort!\"a > b\";\r\n\t\tlong[] a;\r\n\t\tbool ok = true;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (d[i*2] != d[i*2+1])\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\ta ~= d[i*2];\r\n\t\t}\r\n\t\tif (!ok) continue;\r\n\r\n\t\tlong tot;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto x = a[i] - tot;\r\n\t\t\tdebug writeln(\"i:\", i, \" a[i]:\", a[i], \" x:\", x, \" tot:\", tot);\r\n\t\t\tif (x == 0 || x % ((n-i) * 2))\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\ttot += x / (n-i);\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n long[] D = readarray!long;\r\n\r\n bool C() {\r\n foreach (d; D) {\r\n if (d % 2 != 0) return false;\r\n if (d < 0) return false; \r\n }\r\n int[long] M;\r\n long[] X;\r\n foreach (d; D) {\r\n M[d] = M.get(d, 0) + 1;\r\n if (M[d] % 2 == 0) {\r\n X ~= d;\r\n }\r\n }\r\n foreach (k, cnt; M) {\r\n if (cnt % 2 != 0) return false;\r\n }\r\n assert(X.length == N);\r\n sort(X);\r\n auto A = new long[N];\r\n long S = X[0] / 2L;\r\n long Z = 0;\r\n auto K = new long[N];\r\n for (int i = 0; i < N-1; i++) {\r\n if ( (X[i+1] - X[i]) % (2L * (i+1)) != 0 ) return false;\r\n K[i] = (X[i+1] - X[i]) / (2L * (i+1));\r\n }\r\n long A0 = S;{\r\n for (int i = 0; i < N-1; i++) {\r\n A0 -= (N - 1L - i) * K[i];\r\n }\r\n if (A0 % N != 0) return false;\r\n A0 /= N;\r\n }\r\n A[0] = A0;\r\n for (int i = 0; i < N-1; i++) {\r\n A[i+1] = A[i] + K[i];\r\n }\r\n /*\r\n writeln(\"X: \", X);\r\n writeln(\"S: \", S);\r\n writeln(A);\r\n */\r\n return A[0] >= 1 && S == sum(A);\r\n }\r\n writeln(C() ? \"YES\" : \"NO\");\r\n}\r\n"}, {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.functional;\r\nimport std.container;\r\nimport std.typecons;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport core.bitop;\r\nimport core.stdc.stdio : scanf;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\nvoid chmin(T)(ref T a, in T b) { a = min(a, b); }\r\nvoid chmax(T)(ref T a, in T b) { a = max(a, b); }\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n long[] D = readarray!long;\r\n\r\n bool C() {\r\n foreach (d; D) if (d % 2 != 0) return false;\r\n int[long] M;\r\n long[] X;\r\n foreach (d; D) {\r\n M[d] = M.get(d, 0) + 1;\r\n if (M[d] % 2 == 0) {\r\n X ~= d;\r\n }\r\n }\r\n if (X.length != N) return false;\r\n sort(X);\r\n auto A = new long[N];\r\n long S = X[0] / 2L;\r\n long Z = 0;\r\n auto K = new long[N];\r\n for (int i = 0; i < N-1; i++) {\r\n if ( (X[i+1] - X[i]) % (2L * (i+1)) != 0 ) return false;\r\n K[i] = (X[i+1] - X[i]) / (2L * (i+1));\r\n }\r\n long A0 = S;{\r\n for (int i = 0; i < N-1; i++) {\r\n A0 -= (N - 1L - i) * K[i];\r\n }\r\n if (A0 % N != 0) return false;\r\n A0 /= N;\r\n }\r\n A[0] = A0;\r\n for (int i = 0; i < N-1; i++) {\r\n A[i+1] = A[i] + K[i];\r\n }\r\n /*\r\n writeln(\"X: \", X);\r\n writeln(\"S: \", S);\r\n writeln(A);\r\n */\r\n return A[0] >= 1 && S == sum(A);\r\n }\r\n writeln(C() ? \"YES\" : \"NO\");\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (int n, long [] d)\r\n{\r\n\tsort (d);\r\n\tauto g = d.group.array;\r\n\tif (!g.all !(q{a[1] == 2}))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tauto h = d.stride (2).array;\r\n\tif (!h.all !(q{a % 2 == 0}))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tif (h.front * 2 <= h.back)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\treturn true;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto d = readln.splitter.map !(to !(long)).array;\r\n\t\twriteln (solve (n, d) ? \"YES\" : \"NO\");\r\n\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (int n, int [] d)\r\n{\r\n\tsort (d);\r\n\tauto g = d.group.array;\r\n\tif (!g.all !(q{a[1] == 2}))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tauto h = d.stride (2).array;\r\n\tif (!h.all !(q{a % 2 == 0}))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n/*\r\n\tif (h.front * 2 <= h.back)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n*/\r\n\treturn true;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto d = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (n, d) ? \"YES\" : \"NO\");\r\n\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (int n, int [] d)\r\n{\r\n\tsort (d);\r\n\tauto g = d.group.array;\r\n\tif (!g.all !(q{a[1] == 2}))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tauto h = d.stride (2).array;\r\n\tif (!h.all !(q{a % 2 == 0}))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tif (h.front * 2 <= h.back)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\treturn true;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto d = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (n, d) ? \"YES\" : \"NO\");\r\n\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n long[] D; get(D);\r\n if (N == 1) {\r\n writeln(D == [0, 0] ? \"YES\" : \"NO\");\r\n continue;\r\n }\r\n sort(D);\r\n long[] dd;\r\n long a;\r\n for (int i; i < N * 2; i += 2) {\r\n if (D[i] != D[i+1] || D[i] % 2 != 0) goto ng;\r\n dd ~= D[i];\r\n }\r\n if (dd[$-1] % (2 * N) != 0) goto ng;\r\n a = dd[$-1] / N / 2;\r\n foreach_reverse (i; 1..N) {\r\n auto d = dd[i] - dd[i-1];\r\n if (d % (i*2) != 0) goto ng;\r\n a -= d / (i*2);\r\n if (a <= 0) goto ng;\r\n }\r\n writeln(\"YES\");\r\n continue;\r\n ng:\r\n writeln(\"NO\");\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n long[] D; get(D);\r\n sort(D);\r\n long[] dd;\r\n long a;\r\n for (int i; i < N * 2; i += 2) {\r\n if (D[i] != D[i+1] || D[i] % 2 != 0) goto ng;\r\n dd ~= D[i];\r\n }\r\n if (dd[$-1] % (2 * N) != 0) goto ng;\r\n a = dd[$-1] / N / 2;\r\n foreach_reverse (i; 1..N) {\r\n auto d = dd[i] - dd[i-1];\r\n if (d % (i*2) != 0) goto ng;\r\n a -= d / (i*2);\r\n if (a <= 0) goto ng;\r\n }\r\n writeln(\"YES\");\r\n continue;\r\n ng:\r\n writeln(\"NO\");\r\n }\r\n}"}, {"source_code": "import core.bitop, std.bitmanip;\r\nimport core.checkedint;\r\nimport std.algorithm, std.functional, std.meta;\r\nimport std.array, std.container;\r\nimport std.bigint;\r\nimport std.conv;\r\nimport std.math, std.numeric;\r\nimport std.range, std.range.interfaces;\r\nimport std.stdio, std.string;\r\nimport std.ascii, std.typecons;\r\n\r\nvoid main()\r\n{ \r\n auto t = readln.chomp.to!int;\r\n \r\n while (t--) {\r\n auto n = readln.chomp.to!int;\r\n auto arr = readln.chomp.split.map!(to!long).array;\r\n \r\n bool solve(long[] arr) {\r\n if (arr.any!(x => x % 2 == 1)) { return false; }\r\n \r\n arr.sort();\r\n \r\n debug { arr.writeln; }\r\n \r\n long[] sums;\r\n foreach (i; arr.length.iota.stride(2)) {\r\n if (arr[i] != arr[i+1]) { return false; }\r\n \r\n sums ~= arr[i] / 2;\r\n }\r\n \r\n debug { sums.writeln; }\r\n \r\n auto tot = sums[0];\r\n foreach (i; 1 .. sums.length) {\r\n auto left = sums.length - i.to!long;\r\n auto diff = sums[i] - sums[i-1];\r\n \r\n if (diff % i != 0) { return false; }\r\n \r\n tot -= diff / i * left;\r\n \r\n debug { tot.writeln; }\r\n }\r\n \r\n return tot >= 0 && tot % sums.length == 0;\r\n }\r\n \r\n writeln(solve(arr) ? \"YES\": \"NO\");\r\n }\r\n}"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n;\n n = scan!int;\n auto arr = scanArray;\n arr.sort;\n ll[] ray;\n for(int i = 0; i < n; ++i){\n if(arr[2*i] != arr[2*i + 1]){\n writeln(\"NO\");\n return;\n }else{\n ray ~= arr[2*i];\n }\n }\n ray.reverse;\n show(ray);\n ll[] nums;\n ll msum = 0, tim = n, maxval;\n for(int i = 0; i < n; ++i){\n if(ray[i] % 2 != 0){\n writeln(\"NO\");\n return;\n }else{\n ll cval = ray[i]/2;\n cval -= msum;\n if(cval % tim != 0){\n writeln(\"NO\");\n return;\n }\n ll val = cval/tim;\n nums ~= val;\n msum += val;\n --tim;\n }\n }\n show(\"NUMS: \", nums);\n for(int i = 1; i < n; ++i){\n if(nums[i] > nums[i-1]){\n writeln(\"NO\");\n return;\n }\n }\n for(int i = 0; i < n; ++i){\n if(nums[i] <= 0){\n writeln(\"NO\");\n return;\n }\n }\n writeln(\"YES\");\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}], "src_uid": "36f45f5cf4f75f81152fff4505b3b937"} {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\nimport std.traits;\nimport std.variant;\nimport std.concurrency;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto q = next!int;\n assert(q == 0);\n auto a = next!int(n);\n auto totalCount = new int[](200_000 + 1);\n foreach(i, ref ai; a)\n totalCount[ai]++;\n auto count = new int[](200_000 + 1);\n int openIntervals = 0;\n int biggestOpen = 0;\n int res = 0;\n size_t firstPosition = 0;\n foreach(i, ref ai; a)\n {\n if (openIntervals == 0)\n\t{\n\t firstPosition = i;\n\t assert(count[ai] == 0);\n\t}\n if (count[ai] == 0)\n\t{\n\t openIntervals++;\n\t biggestOpen = max(biggestOpen, totalCount[ai]);\n\t}\n count[ai]++;\n if (count[ai] == totalCount[ai])\n\t{\n\t openIntervals--;\n\t if (openIntervals == 0)\n\t {\n\t res += i - firstPosition + 1 - biggestOpen;\n\t biggestOpen = 0;\n\t }\n\t}\n }\n res.writeln;\n return;\n}\n\nstatic this()\n{\n popChar;\n}\n\nstruct Any(T)\n{\n static auto read()\n {\n static if (is(T == char))\n {\n\tauto res = frontChar;\n\tpopChar;\n\treturn res;\n }\n }\n}\n\nstruct Unsigned(T)\n{\n auto read()\n {\n auto res = T(0);\n while(!frontChar.isDigit) popChar;\n do\n {\n\tres = res * T(10) + T(frontChar - '0');\n\tpopChar;\n }\n while(frontChar.isDigit);\n return res;\n }\n}\n\nstruct Matrix(T, alias rows, alias cols) \n{\n T[][] _cell;\n alias _cell this;\n // Ring constructor\n this(int n)\n {\n final switch(n)\n {\n case 0:\n\t_cell = new T[][](rows, cols);\n\tbreak;\n case 1:\n\tdebug assert(rows == cols);\n\t_cell = new T[][](rows, cols);\n\tforeach(i; 0 .. rows)\n\t _cell[i][i] = T(1);\n\tbreak;\n }\n }\n // Copy constructor\n this(Matrix!(T, rows, cols) other)\n {\n _cell = new T[][](rows, cols);\n foreach(i; 0 .. rows)\n _cell[i][] = other[i][];\n }\n auto opBinary(string op)(Matrix!(T, rows, cols) other)\n if (op == \"+\" || op == \"-\")\n\t {\n\t auto res = Matrix!(T, rows, cols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});\n\t return res;\n\t }\n auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)\n if (op == \"*\")\n\t {\n\t debug assert(cols == otherRows);\n\t auto res = Matrix!(T, rows, otherCols)(0);\n\t foreach(i; 0 .. rows)\n\t foreach(k; 0 .. cols)\n\t foreach(j; 0 .. otherCols)\n\t\t res[i][j] += this[i][k] * other[k][j];\n\t return res;\n\t }\n ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)\n {\n static if (op == \"*\")\n {\n\tdebug assert(rows == cols);\n\talias n = rows;\n\tauto res = Matrix!(T, n, n)(0);\n\tT factor;\n\tforeach(i; 0 .. n)\n\t foreach(k; 0 .. n)\n\t foreach(j; 0 .. n)\n\t res[i][j] += this[i][k] * other[k][j];\n\tforeach(i; 0 .. n)\n\t this[i][] = res[i][];\n }\n else\n {\n\tforeach(i; 0 .. rows)\n\t foreach(j; 0 .. cols)\n\t mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});\n }\n return this;\n }\n mixin powMethod;\n}\n\nstruct Mod(T, alias mod)\n{\n alias This = Mod!(T, mod);\n T _rep;\n this(T t)\n {\n _rep = t % mod;\n if (_rep < 0) _rep += mod;\n }\n static auto plain(T t)\n {\n auto res = Mod!(T, mod)();\n res._rep = t;\n return res;\n }\n static auto fromPositive(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod);\n }\n static auto fromNegative(T t)\n {\n pragma(inline, true);\n return Mod!(T, mod).plain(t % mod + mod);\n }\n string toString()\n {\n return to!string(_rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plain(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This.fromPositive(_rep * b._rep);\n }\n }\n auto opOpAssign(string op)(This b)\n {\n mixin(q{_rep }, text(op, \"=\"), q{b._rep;});\n static if (op == \"+\")\n {\n\tif (_rep >= mod) _rep -= mod;\n }\n else static if (op == \"-\")\n {\n\tif (_rep < 0) _rep += mod;\n }\n else static if (op == \"*\")\n {\n\t_rep %= mod;\n }\n return this;\n }\n \n auto opBinary(string op)(long exp)\n if (op == \"^^\")\n\t {\n\t return pow(exp);\n\t }\n mixin powMethod;\n}\n\nmixin template powMethod()\n{\n auto pow(this ThisType)(long exp)\n {\n auto res = ThisType(1);\n auto pow = ThisType(this);\n while(exp)\n\t{\n\t if (exp & 1) res *= pow;\n\t pow *= pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto makeArray(T, S...)(S s)\n{\n enum brackets = () {\n string res;\n foreach(i; 0 .. s.length)\n res ~= \"[]\";\n return res;\n } ();\n mixin(q{alias Type = T}, brackets, q{;});\n return new Type(s);\n}\ntemplate isNumberLike(T)\n{\n enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));\n}\nvoid popWhite()\n{\n import std.ascii;\n while (frontChar.isWhite) popChar;\n}\nvoid print(T...)(T t)\n{\n static foreach(ti; t)\n {\n static if (is(typeof(ti) == string))\n\t{\n\t write(ti, \" \");\n\t}\n else static if (isArray!(typeof(ti)))\n\t{\n\t foreach(e; ti) print(e);\n\t}\n else static if (isTuple!(typeof(ti)))\n\t{\n\t static foreach(i; ti.length) writesp(ti[i]);\n\t}\n else\n\t{\n\t write(ti, \" \");\n\t}\n }\n}\nvoid println(T...)(T t)\n{\n static if (t.length == 0)\n writeln;\n static foreach(ti; t)\n {\n print(ti);\n writeln;\n }\n}\nauto next(alias T, S...)(S s)\n{\n pragma(inline, true);\n static if (s.length > 0)\n {\n auto res = makeArray!(typeof(next!T()))(s);\n S t;\n enum loops = () {\n\tstring res;\n\tforeach(i; 0 .. s.length)\n\t {\n\t auto ti = text(q{t[}, i, q{]});\n\t res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});\n\t }\n\treturn res;\n } ();\n enum indexing = () {\n\tstring res = \"res\";\n\tforeach(i; 0 .. s.length)\n\t res ~= text(q{[t[}, i, q{]]});\n\treturn res;\n } ();\n mixin(loops, indexing, q{ = next!T;});\n return res;\n }\n else\n {\n static if (isNumberLike!T)\n\t{\n\t import std.ascii: isDigit;\n\t T res;\n\t while(frontChar.isWhite) popChar;\n\t T multiplier = T(1);\n\t if (frontChar == '-')\n\t {\n\t multiplier = T(-1);\n\t popChar;\n\t }\n\t else if (frontChar == '+')\n\t {\n\t popChar;\n\t }\n\t debug assert(frontChar.isDigit);\n\t do\n\t {\n\t res = res * T(10) + T(frontChar - '0');\n\t popChar;\n\t }\n\t while(frontChar.isDigit);\n\t return multiplier * res;\n\t}\n else static if (is(T == string))\n\t{\n\t import std.ascii: isWhite;\n\t string res;\n\t while(frontChar.isWhite)\n\t popChar;\n\t while(!frontChar.isWhite)\n\t {\n\t res ~= frontChar;\n\t popChar;\n\t }\n\t return res;\n\t}\n else static if (is(T == char))\n\t{\n\t while(frontChar.isWhite) popChar;\n\t auto res = frontChar;\n\t popChar;\n\t return res;\n\t}\n else\n\t{\n\t return T.read;\n\t}\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid solve(){\n\tint n = rint;\n\tint q = rint;\n\tlong[] as = rlong(n);\n\t\n\tint[long] lm, rm;\n\tforeach(int i, a; as){\n\t\tif(a !in lm) lm[a] = i;\n\t\tif(a !in rm) rm[a] = i;\n\t\trm[a] = i;\n\t}\n\t\n\tK[] ks;\n\tint l, r;\n\tforeach(int i, a; as){\n\t\tif(r < i){\n\t\t\tks ~= K(l, r);\n\t\t\tl = i;\n\t\t\tr = i;\n\t\t}\n\t\tr = max(r, rm[a]);\n\t}\n\tks ~= K(l, r);\n\t\n\tint ans;\n\tforeach(k; ks){\n\t\tint[long] cnt;\n\t\tint maxcnt = 0;\n\t\tforeach(i; k.l .. k.r + 1){\n\t\t\tlong a = as[i];\n\t\t\tif(a !in cnt) cnt[a] = 0;\n\t\t\tcnt[a] += 1;\n\t\t\tmaxcnt = max(maxcnt, cnt[a]);\n\t\t}\n\t\tans += (k.r + 1 - k.l) - maxcnt;\n\t}\n\t\n\tans.writeln;\n}\n\nstruct K{\n\tint l, r;\n}\n"}], "negative_code": [], "src_uid": "2f171f2a3774c5eb3a6d830ac66233d1"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\r\n\t\tstring[] a, b;\r\n\t\tforeach (i; 0..n)\r\n\t\t\ta ~= RD!string;\r\n\t\tforeach (i; 0..n-1)\r\n\t\t\tb ~= RD!string;\r\n\r\n\t\tauto cnt = new long[][](m, 26);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..m)\r\n\t\t\t{\r\n\t\t\t\t++cnt[j][a[i][j]-'a'];\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tforeach (j; 0..m)\r\n\t\t\t{\r\n\t\t\t\t--cnt[j][b[i][j]-'a'];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tbool ok = true;\r\n\t\t\tforeach (j; 0..m)\r\n\t\t\t{\r\n\t\t\t\tif (cnt[j][a[i][j]-'a'] != 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tok = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (ok)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = a[i].idup;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1546/problem/B\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\nwhile(t--) {\n int n, m;\n readf(\"%s %s\\n\", &n, &m);\n string[] original, shuffled;\n for(int i = 0; i < n; ++i) {\n string s;\n readf(\"%s\\n\", &s);\n original ~= s;\n }\n for(int i = 1; i < n; ++i) {\n string s;\n readf(\"%s\\n\", &s);\n shuffled ~= s;\n }\n int[char][int] counter;\n foreach(s; original) {\n for(int i = 0; i < m; i++) {\n counter[i][s[i]] += 1;\n }\n }\n foreach(s; shuffled) {\n for(int i = 0; i < m; i++) {\n counter[i][s[i]] += 1;\n }\n }\n for(int i = 0; i < m; ++i) {\n for(char ch = 'a'; ch <= 'z'; ++ch) {\n counter[i][ch] += 0;\n if(counter[i][ch] % 2 == 1) {\n ch.write;\n }\n }\n }\n \"\".writeln;\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1546/problem/B\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\nwhile(t--) {\n int n, m;\n readf(\"%s %s\\n\", &n, &m);\n string[] original, shuffled;\n for(int i = 0; i < n; ++i) {\n string s;\n readf(\"%s\\n\", &s);\n original ~= s;\n }\n for(int i = 1; i < n; ++i) {\n string s;\n readf(\"%s\\n\", &s);\n shuffled ~= s;\n }\n int[char][int] counter;\n foreach(s; original) {\n for(int i = 0; i < m; i++) {\n counter[i][s[i]] += 1;\n }\n }\n foreach(s; shuffled) {\n for(int i = 0; i < m; i++) {\n counter[i][s[i]] += 1;\n }\n }\n for(int i = 0; i < m; ++i) {\n for(char ch = 'a'; ch <= 'z'; ++ch) {\n counter[i][ch] += 0;\n if(counter[i][ch] % 2 == 1) {\n ch.write;\n }\n }\n }\n \"\".writeln;\n}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n auto a = readln.strip.split.map!(to!int).array;\n int n = a[0];\n int m = a[1];\n int i, j;\n string[] orig, shuf;\n for (i = 0; i < n; i++)\n orig ~= readln.strip;\n for (i = 0; i < n - 1; i++)\n shuf ~= readln.strip;\n int[][] cnt = new int[][](m, 30);\n foreach (s ; orig) {\n for (i = 0; i < m; i++) {\n cnt[i][s[i] - 'a']++;\n }\n }\n foreach (s ; shuf) {\n for (i = 0; i < m; i++) {\n cnt[i][s[i] - 'a']--;\n }\n }\n char[] result = cnt.map!(x => cast(char)('a' + x.countUntil(1))).array;\n writeln(result.idup);\n stdout.flush;\n }\n}\n"}, {"source_code": "import std.stdio, std.string;\r\nimport std.conv, std.typecons;\r\nimport std.array, std.range;\r\nimport std.math, std.algorithm;\r\nimport std.random;\r\n\r\nint main(string[] args)\r\n{\r\n auto t = to!int(readln.strip);\r\n auto c = new int[26];\r\n auto sc = new int[26];\r\n auto lc = new int[][](100010, 26);\r\n auto cc = new int[][](100010, 26);\r\n auto scc = new int[][](100010, 26);\r\n auto s = new string[100010];\r\n foreach (_; 0 .. t)\r\n {\r\n int n, m;\r\n readf(\"%d %d\\n\", &n, &m);\r\n fill(c, 0);\r\n foreach (i; 0 .. m) fill(cc[i], 0);\r\n foreach (i; 0 .. n)\r\n {\r\n s[i] = readln.strip;\r\n fill(lc[i], 0);\r\n foreach (j; 0 .. m)\r\n {\r\n ++ c[s[i][j] - 'a'];\r\n ++ lc[i][s[i][j] - 'a'];\r\n ++ cc[j][s[i][j] - 'a'];\r\n }\r\n }\r\n fill(sc, 0);\r\n foreach (i; 0 .. m) fill(scc[i], 0);\r\n foreach (i; 0 .. n - 1)\r\n {\r\n auto ss = readln.strip;\r\n foreach (j; 0 .. m)\r\n {\r\n ++ sc[ss[j] - 'a'];\r\n ++ scc[j][ss[j] - 'a'];\r\n }\r\n }\r\n int[] res;\r\n foreach (i; 0 .. n)\r\n {\r\n int j;\r\n for (j = 0; j < 26; ++ j)\r\n {\r\n if (c[j] - lc[i][j] != sc[j]) break;\r\n int k;\r\n for (k = 0; k < m; ++ k)\r\n {\r\n if (s[i][k] - 'a' == j && cc[k][j] - 1 != scc[k][j]) break;\r\n if (s[i][k] - 'a' != j && cc[k][j] != scc[k][j]) break;\r\n }\r\n if (k < m) break;\r\n }\r\n if (j == 26)\r\n {\r\n writeln(s[i]);\r\n stdout.flush;\r\n break;\r\n }\r\n }\r\n }\r\n return 0;\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\r\nimport std.conv, std.typecons;\r\nimport std.array, std.range;\r\nimport std.math, std.algorithm;\r\n\r\nint main(string[] args)\r\n{\r\n auto t = to!int(readln.strip);\r\n auto c = new int[26];\r\n auto sc = new int[26];\r\n auto lc = new int[][](100010, 26);\r\n auto s = new string[100010];\r\n foreach (_; 0 .. t)\r\n {\r\n int n, m;\r\n readf(\"%d %d\\n\", &n, &m);\r\n fill(c, 0);\r\n fill(sc, 0);\r\n foreach (i; 0 .. n)\r\n {\r\n s[i] = readln.strip;\r\n fill(lc[i], 0);\r\n foreach (j; 0 .. m)\r\n {\r\n ++ c[s[i][j] - 'a'];\r\n ++ lc[i][s[i][j] - 'a'];\r\n }\r\n }\r\n foreach (i; 0 .. n - 1)\r\n {\r\n auto ss = readln.strip;\r\n foreach (j; 0 .. m) ++ sc[ss[j] - 'a'];\r\n }\r\n foreach (i; 0 .. n)\r\n {\r\n int j;\r\n for (j = 0; j < 26; ++ j) if (c[j] - lc[i][j] != sc[j]) break;\r\n if (j == 26)\r\n {\r\n writeln(s[i]);\r\n stdout.flush;\r\n break;\r\n }\r\n }\r\n }\r\n return 0;\r\n}"}], "src_uid": "b8ffd93a80c840ea645c6797f8ee269c"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n int[int] last;\r\n for (int i = 0; i < N; i++) {\r\n last[A[i]] = i;\r\n }\r\n int ans = -1;\r\n foreach (v, i; last) {\r\n foreach (u, j; last) {\r\n if (gcd(v, u) == 1) {\r\n ans = max(ans, i + j + 2);\r\n }\r\n }\r\n }\r\n writeln(ans);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n auto coprimes = new byte[1001][1001];\n foreach (i ; 1 .. 1001) {\n foreach (j ; i .. 1001) {\n if (gcd(i, j) == 1) {\n coprimes[i][j] = 1;\n coprimes[j][i] = 1;\n }\n }\n }\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!int).array;\n auto b = zip(iota(1, a.length + 1), a).array.sort!((x, y) => x[1] == y[1] ? x[0] > y[0] : x[1] > y[1]);\n auto c = b.uniq!((x, y) => x[1] == y[1]).array;\n long ans = -1;\n foreach (i ; 0 .. c.length) {\n foreach (j ; 0 .. c.length) {\n if (coprimes[c[i][1]][c[j][1]])\n ans = max(ans, c[i][0] + c[j][0]);\n }\n }\n writeln(ans);\n }\n}\n"}], "negative_code": [], "src_uid": "d665ecbf36cc0c0ddd148137fb693bf2"} {"source_code": "\nmodule _;\nvoid main() {\n\timport std.stdio;\n\tint n;\n\treadf(\"%s \", &n);\n\tstring vowels = \"aeiou\";\n\tint x = 0, y;\n\tfor(int i = 5; i * i <= n; i++){\n\t\tif (n % i == 0) {\n\t\t\tx = i;\n\t\t\ty = n/i;\n\t\t}\n\t}\n\tif (!x) {\n\t\twriteln(\"-1\");\n\t\treturn;\n\t}\n\tforeach(i; 0..5) {\n\t\tstring pat = vowels[i..5] ~ vowels[0..i];\n\t\tforeach(j; 0..y/5) {\n\t\t\twrite(pat);\n\t\t}\n\t\twrite(pat[0..y%5]);\n\t}\n\tforeach(i; 5..x) {\n\t\twrite(vowels);\n\t\tforeach(j; 5..y) {\n\t\t\twrite(\"x\");\n\t\t}\n\t}\n\twriteln;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint u, v;\n\t\tfor (int i = 1; i * i <= n; i++)\n\t\t{\n\t\t\tif (n % i == 0 && i >= 5 && n / i >= 5)\n\t\t\t{\n\t\t\t\tu = i;\n\t\t\t\tv = n / i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (u == 0 && v == 0)\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\t\tstring res;\n\t\tforeach (i; 0..u)\n\t\t{\n\t\t\tforeach (j; 0..v)\n\t\t\t{\n\t\t\t\tres ~= \"aeiou\"[(i + j) % 5];\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nenum string vowels = \"aeiou\";\n\nvoid main() {\n int k = readln.strip.to!int;\n char[] z;\n z.reserve (k);\n for (int h = 5; h * h <= k; ++h) {\n if (k % h == 0) {\n int w = k / h;\n foreach (i; 0 .. h) {\n foreach (j; 0 .. w) {\n z ~= vowels[(i + j) % 5];\n }\n }\n writeln (z);\n return;\n }\n }\n writeln (-1);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto K = RD!int;\n\n\tint a, b;\n\tfor (int i = 5; i*i <= K; ++i)\n\t{\n\t\tif (K % i == 0)\n\t\t{\n\t\t\tif (K / i >= 5)\n\t\t\t{\n\t\t\t\ta = i;\n\t\t\t\tb = K / i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (a == 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tauto str = \"aiueo\";\n\t\tforeach (i; 0..a)\n\t\t{\n\t\t\tforeach (j; 0..b)\n\t\t\t{\n\t\t\t\twrite(str[((i%5)+j)%5]);\n\t\t\t}\n\t\t}\n\t\twriteln();\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "933167c31c0f53a43e840cc6cf153f8d"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.uni;\nimport std.array;\nimport std.algorithm;\n\nstring[] flag;\n\nchar[] get(int x0, int y0, int x1, int y1) {\n\tauto app = appender!(char[])();\n\tbool R = false, G = false, B = false;\n\tfor (int i = x0; i < x1; i++) for (int j = y0; j < y1; j++) {\n\t\tif (flag[i][j] == 'R') {\n\t\t\tif (!R) {\n\t\t\t\tR = true;\n\t\t\t\tapp.put('R');\n\t\t\t}\n\t\t} else if (flag[i][j] == 'G') {\n\t\t\tif (!G) {\n\t\t\t\tG = true;\n\t\t\t\tapp.put('G');\n\t\t\t}\n\t\t} else {\n\t\t\tif (!B) {\n\t\t\t\tB = true;\n\t\t\t\tapp.put('B');\n\t\t\t}\n\t\t}\n\t}\n\treturn app.data;\n}\n\nvoid main() {\n\tint n, m;\n\treadf(\"%d %d\\n\", &n, &m);\n\tflag = new string[n];\n\tfor (int i = 0; i < n; i++) flag[i] = readln();\n\tbool ans = false;\n\tif (n % 3 == 0) {\n\t\tauto app = appender!(char[])();\n\t\tint d = n / 3;\n\t\tapp.put(get(0, 0, d, m));\n\t\tapp.put(get(d, 0, 2 * d, m));\n\t\tapp.put(get(2 * d, 0, n, m));\n\t\tchar[] data = app.data;\n\t\tsort(data.representation);\n\t\tif (data == \"BGR\") ans = true;\n\t}\n\tif (m % 3 == 0) {\n\t\tauto app = appender!(char[])();\n\t\tint d = m / 3;\n\t\tapp.put(get(0, 0, n, d));\n\t\tapp.put(get(0, d, n, 2 * d));\n\t\tapp.put(get(0, 2 * d, n, m));\n\t\tchar[] data = app.data;\n\t\tsort(data.representation);\n\t\tif (data == \"BGR\") ans = true;\n\t}\n\twriteln(ans ? \"YES\" : \"NO\");\n}", "positive_code": [{"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nint n, m;\nchar[][] flag;\n\nvoid main() {\n scan(n, m);\n\n if (n % 3 && m % 3) {\n writeln(\"NO\");\n return;\n }\n\n flag = new char[][](n, m);\n iota(n).each!(i => flag[i][] = readln.chomp);\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", flag);\n }\n\n int r, c;\n\n if (n % 3 == 0) {\n r = n / 3;\n\n auto rgb = new int[](3);\n\n bool ok = true;\n\n foreach (k ; 0 .. 3) {\n char ch = flag[k * r][0];\n\n if (ch == 'R') rgb[0]++;\n else if (ch == 'G') rgb[1]++;\n else rgb[2]++;\n\n foreach (i ; k * r .. k * r + r) {\n foreach (j ; 0 .. m) {\n if (flag[i][j] != ch) ok = false;\n }\n }\n }\n\n if (rgb == [1, 1, 1] && ok) {\n writeln(\"YES\");\n return;\n }\n }\n\n if (m % 3 == 0) {\n c = m / 3;\n\n auto rgb = new int[](3);\n\n bool ok = true;\n\n foreach (k ; 0 .. 3) {\n char ch = flag[0][k * c];\n\n if (ch == 'R') rgb[0]++;\n else if (ch == 'G') rgb[1]++;\n else rgb[2]++;\n\n foreach (j ; k * c .. k * c + c) {\n foreach (i ; 0 .. n) {\n if (flag[i][j] != ch) ok = false;\n }\n }\n\n if (rgb == [1, 1, 1] && ok) {\n writeln(\"YES\");\n return;\n }\n }\n }\n\n writeln(\"NO\");\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n auto B = H.iota.map!(_ => readln.chomp).array;\n\n if (H % 3 == 0) {\n dchar[] used;\n bool ok = true;\n foreach (k; 0..3) {\n char c = B[H / 3 * k][0];\n used ~= c;\n foreach (i; H/3*k..H/3*(k+1)) foreach (j; 0..W) if (B[i][j] != c) ok = false;\n }\n used.sort();\n if (ok && used == ['B', 'G', 'R'].to!(dchar[])) {\n \"YES\".writeln;\n return;\n }\n }\n\n if (W % 3 == 0) {\n dchar[] used;\n bool ok = true;\n foreach (k; 0..3) {\n char c = B[0][W / 3 * k];\n used ~= c;\n foreach (j; W/3*k..W/3*(k+1)) foreach (i; 0..H) if (B[i][j] != c) ok = false;\n }\n used.sort();\n if (ok && used == ['B', 'G', 'R'].to!(dchar[])) {\n \"YES\".writeln;\n return;\n }\n }\n\n \"NO\".writeln;\n}\n"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio, std.string, std.array, std.algorithm, std.conv;\n\nvoid main() {\n auto nm = to!(int[])(split(chomp(readln())));\n int n = nm[0], m = nm[1];\n auto xss = appender!(string[])();\n for (int i = 0; i < n; i++) {\n xss.put(chomp(readln()));\n if (!xss.data[i].count!( (a) => a == 'R' || a == 'G' || a == 'B' )) {\n writeln(\"NO\");\n return;\n }\n }\n auto ans = false;\n if (n % 3 == 0) {\n int u = n / 3;\n bool flag = true;\n for (int x = 0; x < m; x++) {\n for (int y = 0; y < n; y++) {\n auto p = xss.data[y][x];\n auto a = xss.data[y/u*u][x];\n auto b = xss.data[(y/u+1)%3*u][x];\n auto c = xss.data[(y/u+2)%3*u][x];\n flag = flag && (p == a && p != b && p != c) && (x == 0 || p == xss.data[y][x-1]);\n }\n }\n ans = ans || flag;\n }\n if (m % 3 == 0) {\n int u = m / 3;\n bool flag = true;\n for (int y = 0; y < n; y++) {\n for (int x = 0; x < m; x++) {\n auto p = xss.data[y][x];\n auto a = xss.data[y][x/u*u];\n auto b = xss.data[y][(x/u+1)%3*u];\n auto c = xss.data[y][(x/u+2)%3*u];\n flag = flag && (p == a && p != b && p != c) && (y == 0 || p == xss.data[y-1][x]);\n }\n }\n ans = ans || flag;\n }\n writeln(ans ? \"YES\" : \"NO\");\n}"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nint n, m;\nchar[][] flag;\n\nvoid main() {\n scan(n, m);\n\n if (n % 3 && m % 3) {\n writeln(\"NO\");\n return;\n }\n\n flag = new char[][](n, m);\n iota(n).each!(i => flag[i][] = readln.chomp);\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", flag);\n }\n\n int r, c;\n\n if (n % 3 == 0) {\n r = n / 3;\n\n auto rgb = new int[](3);\n\n bool ok = true;\n\n foreach (k ; 0 .. 3) {\n char ch = flag[k * r][0];\n\n if (ch == 'R') rgb[0]++;\n else if (ch == 'G') rgb[1]++;\n else rgb[2]++;\n\n foreach (i ; k * r .. k * r + r) {\n foreach (j ; 0 .. m) {\n if (flag[i][j] != ch) ok = false;\n }\n }\n }\n\n if (rgb == [1, 1, 1] && ok) {\n writeln(\"YES\");\n return;\n }\n }\n\n if (m % 3 == 0) {\n c = m / 3;\n\n auto rgb = new int[](3);\n\n bool ok = true;\n\n foreach (k ; 0 .. 3) {\n char ch = flag[0][k * c];\n\n if (ch == 'R') rgb[0]++;\n else if (ch == 'G') rgb[1]++;\n else rgb[2]++;\n\n foreach (j ; k * c .. k * c + c) {\n foreach (i ; 0 .. n) {\n if (flag[i][j] != ch) ok = false;\n }\n }\n\n if (rgb == [1, 1, 1] && ok) {\n writeln(\"YES\");\n return;\n }\n }\n }\n\n writeln(\"NO\");\n}\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio, std.string, std.array, std.algorithm, std.conv;\n\nvoid main() {\n auto nm = to!(int[])(split(chomp(readln())));\n int n = nm[0], m = nm[1];\n auto xss = appender!(string[])();\n for (int i = 0; i < n; i++) {\n xss.put(chomp(readln()));\n if (!xss.data[i].count!( (a) => a == 'R' || a == 'G' || a == 'B' )) {\n writeln(\"NO\");\n return;\n }\n }\n auto ans = false;\n if (n % 3 == 0) {\n int u = n / 3;\n bool flag = true;\n for (int x = 0; x < m; x++) {\n for (int y = 0; y < n; y++) {\n auto p = xss.data[y][x];\n auto a = xss.data[y/u*u][x];\n auto b = xss.data[(y/u+1)%3*u][x];\n auto c = xss.data[(y/u+2)%3*u][x];\n flag = flag && (p == a && p != b && p != c);\n }\n }\n ans = ans || flag;\n }\n if (m % 3 == 0) {\n int u = m / 3;\n bool flag = true;\n for (int y = 0; y < n; y++) {\n for (int x = 0; x < m; x++) {\n auto p = xss.data[y][x];\n auto a = xss.data[y][x/u*u];\n auto b = xss.data[y][(x/u+1)%3*u];\n auto c = xss.data[y][(x/u+2)%3*u];\n flag = flag && (p == a && p != b && p != c);\n }\n }\n ans = ans || flag;\n }\n writeln(ans ? \"YES\" : \"NO\");\n}"}, {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio, std.string, std.array, std.algorithm, std.conv;\n\nvoid main() {\n auto nm = to!(int[])(split(chomp(readln())));\n int n = nm[0], m = nm[1];\n auto xss = appender!(string[])();\n for (int i = 0; i < n; i++) {\n xss.put(chomp(readln()));\n }\n auto ans = false;\n if (n % 3 == 0) {\n int u = n / 3;\n bool flag = true;\n for (int x = 0; x < m; x++) {\n for (int y = 0; y < n; y++) {\n auto p = xss.data[y][x];\n auto a = xss.data[y/u*u][x];\n auto b = xss.data[(y/u+1)%3*u][x];\n auto c = xss.data[(y/u+2)%3*u][x];\n flag = flag && (p == a && p != b && p != c);\n }\n }\n ans = ans || flag;\n }\n if (m % 3 == 0) {\n int u = m / 3;\n bool flag = true;\n for (int y = 0; y < n; y++) {\n for (int x = 0; x < m; x++) {\n auto p = xss.data[y][x];\n auto a = xss.data[y][x/u*u];\n auto b = xss.data[y][(x/u+1)%3*u];\n auto c = xss.data[y][(x/u+2)%3*u];\n flag = flag && (p == a && p != b && p != c);\n }\n }\n ans = ans || flag;\n }\n writeln(ans ? \"YES\" : \"NO\");\n}"}], "src_uid": "0988b8439c6699107c77345037162fba"} {"source_code": "import std;\r\n\r\nint t,n,m;\r\nlong[] answers;\r\n\r\nvoid main()\r\n{\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(_; 0..t)\r\n {\r\n scanf(\"%d\", &n);\r\n getchar();\r\n auto a = readln.split.to!(int[]);\r\n \r\n auto rbt = redBlackTree!true(0);\r\n rbt.removeKey(0);\r\n \r\n for (int i = 0; i < n; i++){\r\n while (a[i] % 2 == 0){\r\n a[i] /= 2;\r\n }\r\n \r\n rbt.stableInsert(a[i]);\r\n }\r\n \r\n //writefln(\"%(%d %)\", rbt[]);\r\n \r\n bool good = true;\r\n auto b = readln.split.to!(int[]);\r\n for (int i = 0; i < n; i++){\r\n while (b[i] != 0){\r\n if (b[i] in rbt){\r\n rbt.removeKey(b[i]);\r\n break;\r\n }\r\n \r\n b[i] /= 2;\r\n }\r\n \r\n if (b[i] == 0){\r\n good = false;\r\n break;\r\n }\r\n }\r\n \r\n if (good != false){\r\n writefln(\"YES\");\r\n } else {\r\n writefln(\"NO\");\r\n }\r\n }\r\n //writefln(\"%(%s \\n%)\", answers);\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nvoid solve() {\r\n int N = readln.chomp.to!int;\r\n auto A = readln.chomp.split(\" \").map!(to!int).array;\r\n auto B = readln.chomp.split(\" \").map!(to!int).array;\r\n\r\n bool C() {\r\n int[int] aps;\r\n foreach (a; A) {\r\n while (a % 2 == 0) a /= 2;\r\n aps[a] = aps.get(a, 0) + 1;\r\n }\r\n foreach (b; B) {\r\n while (b % 2 == 0) b /= 2;\r\n while (b > 0) {\r\n if (aps.get(b, 0) > 0) {\r\n aps[b] -= 1;\r\n break;\r\n } else {\r\n b /= 2;\r\n }\r\n }\r\n }\r\n return aps.values.all!((x) => x == 0);\r\n }\r\n writeln(C() ? \"YES\" : \"NO\");\r\n}\r\n\r\nvoid main() {\r\n int T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) {\r\n solve();\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "bcd34e88bcd70ad36acbe6c3b70aa45d"} {"source_code": "import std.stdio : readln, writeln;\n\nstruct IO {\n import std.conv : to;\n import std.range : empty, front, popFront, split;\n\n string readToken() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n\n int readInt() {\n return readToken.to!int;\n }\n\n string[] tokens;\n}\n\nvoid main() {\n import core.stdc.limits : INT_MAX;\n import std.algorithm : max, min, fill;\n\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int m = io.readInt;\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = io.readInt;\n }\n bool[] gap = new bool[n - 1];\n fill(gap, true);\n for (int i = 0; i < m; ++i) {\n gap[io.readInt - 1] = false;\n }\n int[] suffixMin = new int[n + 1];\n suffixMin[n] = INT_MAX;\n for (int i = n; i--;) {\n suffixMin[i] = min(a[i], suffixMin[i + 1]);\n }\n int prefixMax = 0;\n bool ok = true;\n for (int i = 0; i + 1 < n; ++i) {\n prefixMax = max(prefixMax, a[i]);\n ok &= !gap[i] || prefixMax <= suffixMin[i + 1];\n }\n writeln(ok ? \"YES\" : \"NO\");\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n A: foreach(_; 0 .. rint){\n int n = rint, m = rint;\n int[] as = rint(n), ps = rint(m);\n\n bool[] xs = new bool[](n);\n foreach(p; ps) xs[p - 1] = 1;\n \n int mina = 999, maxa = -1;\n int oldmaxa = -1;\n foreach(int i, a; as){\n mina.chmin(a), maxa.chmax(a);\n if(! xs[i]){\n if(mina < oldmaxa){\n \"NO\".writeln;\n continue A;\n }\n oldmaxa = maxa;\n mina = 999, maxa = -1;\n }\n }\n \"YES\".writeln;\n\n }\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = RDA;\n\t\tauto p = RDA!int(-1);\n\t\tp.sort();\n\t\tint[][] lr;\n\t\tint last = p[0], l = p[0];\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (p[i] != last+1)\n\t\t\t{\n\t\t\t\tlr ~= [l, last+1];\n\t\t\t\tl = p[i];\n\t\t\t}\n\t\t\tlast = p[i];\n\t\t}\n\t\tlr ~= [l, last+1];\n\t\tforeach (e; lr)\n\t\t{\n\t\t\ta[e[0]..e[1]+1].sort();\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i-1] > a[i])\n\t\t\t\tok = false;\n\t\t}\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto a = RDA;\n\t\tauto p = RDA!int(-1);\n\t\tint[][] lr;\n\t\tint last = p[0], l = p[0];\n\t\tforeach (i; 1..m)\n\t\t{\n\t\t\tif (p[i] != last+1)\n\t\t\t{\n\t\t\t\tlr ~= [l, last+1];\n\t\t\t\tl = p[i];\n\t\t\t}\n\t\t\tlast = p[i];\n\t\t}\n\t\tlr ~= [l, last+1];\n\t\tforeach (e; lr)\n\t\t{\n\t\t\ta[e[0]..e[1]+1].sort();\n\t\t}\n\t\tbool ok = true;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i-1] > a[i])\n\t\t\t\tok = false;\n\t\t}\n\t\tans[ti] = ok;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "e1481b9d940407da75e11355b580f459"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tauto s = readString;\n\tint[][2] types;\n\tforeach(i, si; s) types[int(si == '2')] ~= cast(int)i;\n\tauto matches = new char[][](n, n);\n\tforeach(ref row; matches) row[] = '=';\n\tforeach(i; 0 .. n) matches[i][i] = 'X';\n\tif (types[1].length >= 1 && types[1].length <= 2)\n\t{\n\t\twriteln(\"NO\");\n\t\twriteln;\n\t\treturn;\n\t}\n\twriteln(\"YES\");\n\tvoid setWin(int i, int j)\n\t{\n\t\tmatches[i][j] = '+';\n\t\tmatches[j][i] = '-';\n\t}\n\tforeach(i; 0 .. types[1].length) setWin(types[1][i], types[1][(i+1)%(types[1].length)]);\n\tforeach(row; matches) writeln(row);\n\twriteln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.array, std.string, std.conv;\r\n \r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n foreach(_; 0..t)\r\n {\r\n int str_len;\r\n scanf(\"%d\", &str_len);\r\n getchar();\r\n // auto str = readln.strip();\r\n // writeln(str);\r\n int[] players = new int[str_len];\r\n int[] first_players, second_players;\r\n for (int i = 0; i < str_len; i++)\r\n {\r\n char tmp;\r\n scanf(\"%c\", &tmp);\r\n if (tmp == '1')\r\n {\r\n players[i] = 1;\r\n first_players ~= i;\r\n }\r\n else\r\n {\r\n players[i] = 2;\r\n second_players ~= i;\r\n }\r\n }\r\n getchar();\r\n if (second_players.length == 1 || second_players.length == 2)\r\n {\r\n writeln(\"NO\");\r\n continue;\r\n }\r\n else\r\n {\r\n writeln(\"YES\");\r\n if (!second_players.empty)\r\n {\r\n second_players ~= second_players.front();\r\n second_players.popFront();\r\n }\r\n int last_win = -1;\r\n int last_loss = -1;\r\n for(int i = 0; i < str_len; i++)\r\n {\r\n string line;\r\n if (!second_players.empty)\r\n {\r\n last_win = second_players.front();\r\n }\r\n debug{\r\n writeln(\"cur:\", i);\r\n writeln(\"win:\", last_win);\r\n writeln(\"loss:\", last_loss);\r\n }\r\n for(int j = 0; j < str_len; j++)\r\n {\r\n if (i == j)\r\n line ~= 'X';\r\n else if (players[i] == 1)\r\n line ~= '=';\r\n else if (players[i] == 2 && players[j] == 1)\r\n line ~= '=';\r\n else if (players[i] == 2 && players[j] == 2)\r\n {\r\n if (j == last_loss)\r\n {\r\n // writeln(\"last loss=\", last_loss);\r\n line ~= '-';\r\n }\r\n else if (j == last_win)\r\n {\r\n line ~= '+';\r\n if (second_players.length > 1)\r\n last_loss = i;\r\n }\r\n else if (i > j && j != last_loss)\r\n line ~= '+';\r\n else\r\n line ~= '-';\r\n }\r\n }\r\n if (!second_players.empty && players[i] == 2)\r\n {\r\n // writeln(\"before pop:\", second_players);\r\n second_players.popFront();\r\n }\r\n writeln(line);\r\n }\r\n }\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.array, std.string, std.conv;\r\n \r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n foreach(_; 0..t)\r\n {\r\n int str_len;\r\n scanf(\"%d\", &str_len);\r\n getchar();\r\n // auto str = readln.strip();\r\n // writeln(str);\r\n int[] players = new int[str_len];\r\n int[] first_players, second_players;\r\n for (int i = 0; i < str_len; i++)\r\n {\r\n char tmp;\r\n scanf(\"%c\", &tmp);\r\n if (tmp == '1')\r\n {\r\n players[i] = 1;\r\n first_players ~= i;\r\n }\r\n else\r\n {\r\n players[i] = 2;\r\n second_players ~= i;\r\n }\r\n }\r\n getchar();\r\n if (second_players.length == 1 || second_players.length == 2)\r\n {\r\n writeln(\"NO\");\r\n continue;\r\n }\r\n else\r\n {\r\n writeln(\"YES\");\r\n if (!second_players.empty)\r\n {\r\n second_players ~= second_players.front();\r\n second_players.popFront();\r\n }\r\n int cur_second_player = -1;\r\n for(int i = 0; i < str_len; i++)\r\n {\r\n string line;\r\n if (!second_players.empty)\r\n {\r\n cur_second_player = second_players.front();\r\n\r\n }\r\n debug{\r\n writeln(\"cur:\", i);\r\n writeln(\"cur_2:\", cur_second_player);\r\n writeln(\"2pl:\", second_players);\r\n }\r\n for(int j = 0; j < str_len; j++)\r\n {\r\n if (i == j)\r\n line ~= 'X';\r\n else if (players[i] == 1)\r\n line ~= '=';\r\n else if (players[i] == 2 && players[j] == 1)\r\n line ~= '=';\r\n else if (players[i] == 2 && players[j] == 2)\r\n {\r\n if (j == cur_second_player)\r\n line ~= '+';\r\n else\r\n line ~= '-';\r\n }\r\n }\r\n if (!second_players.empty && players[i] == 2)\r\n {\r\n // writeln(\"before pop:\", second_players);\r\n second_players.popFront();\r\n }\r\n writeln(line);\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.array, std.string, std.conv;\r\n \r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n foreach(_; 0..t)\r\n {\r\n int str_len;\r\n scanf(\"%d\", &str_len);\r\n getchar();\r\n // auto str = readln.strip();\r\n // writeln(str);\r\n int[] players = new int[str_len];\r\n int[] first_players, second_players;\r\n for (int i = 0; i < str_len; i++)\r\n {\r\n char tmp;\r\n scanf(\"%c\", &tmp);\r\n if (tmp == '1')\r\n {\r\n players[i] = 1;\r\n first_players ~= i;\r\n }\r\n else\r\n {\r\n players[i] = 2;\r\n second_players ~= i;\r\n }\r\n }\r\n getchar();\r\n if (second_players.length == 1 || second_players.length == 2)\r\n {\r\n writeln(\"NO\");\r\n continue;\r\n }\r\n else\r\n {\r\n writeln(\"YES\");\r\n if (!second_players.empty)\r\n {\r\n second_players ~= second_players.front();\r\n second_players.popFront();\r\n }\r\n int cur_second_player = -1;\r\n for(int i = 0; i < str_len; i++)\r\n {\r\n string line;\r\n if (!second_players.empty)\r\n {\r\n cur_second_player = second_players.front();\r\n\r\n }\r\n debug{\r\n writeln(\"cur:\", i);\r\n writeln(\"cur_2:\", cur_second_player);\r\n writeln(\"2pl:\", second_players);\r\n }\r\n for(int j = 0; j < str_len; j++)\r\n {\r\n if (i == j)\r\n line ~= 'X';\r\n else if (players[i] == 1)\r\n line ~= '=';\r\n else if (players[i] == 2 && players[j] == 1)\r\n line ~= '=';\r\n else if (players[i] == 2 && players[j] == 2)\r\n {\r\n if (j == cur_second_player)\r\n line ~= '+';\r\n else\r\n line ~= '-';\r\n }\r\n }\r\n if (!second_players.empty && players[i] == 2)\r\n {\r\n // writeln(\"before pop:\", second_players);\r\n second_players.popFront();\r\n }\r\n writeln(line);\r\n }\r\n }\r\n }\r\n}"}], "src_uid": "7e15bb1d6040d786983865143d1799cd"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto s = readln.strip;\n int best1 = -1;\n int eq1 = -1;\n\n foreach (i ; 0 .. cast(int)s.length - 1) {\n int digit1 = s[i] - '0';\n int digit2 = s[i + 1] - '0';\n if (digit1 + digit2 < 10 && digit1 + digit2 > digit1) {\n best1 = i;\n break;\n }\n if (digit1 + digit2 < 10 && digit1 + digit2 == digit1) {\n if (i + 2 >= s.length) {\n best1 = i;\n break;\n }\n int digit3 = s[i + 2] - '0';\n if (digit3 > digit2) {\n best1 = i;\n break;\n } else if (digit3 == digit2) {\n eq1 = i;\n }\n }\n }\n if (best1 == -1) {\n if (eq1 != -1)\n best1 = eq1;\n else\n best1 = cast(int)s.length - 2;\n }\n\n bool have_best2 = false;\n int default_best2;\n foreach_reverse (i ; 0 .. cast(int)s.length - 1) {\n if ((s[i] - '0') + (s[i + 1] - '0') >= 10) {\n have_best2 = true;\n default_best2 = i;\n break;\n }\n }\n int ans = best1;\n int best2 = -1;\n int eq2 = -1;\n if (have_best2) {\n foreach (i ; 0 .. cast(int)s.length - 1) {\n int digit1 = s[i] - '0';\n int digit2 = s[i + 1] - '0';\n if (digit1 + digit2 < 10)\n continue;\n if ((digit1 + digit2) / 10 > digit1) {\n best2 = i;\n break;\n }\n if ((digit1 + digit2) / 10 == digit1) {\n if ((digit1 + digit2) % 10 > digit2) {\n best2 = i;\n break;\n } else if ((digit1 + digit2) % 10 == digit2) {\n eq2 = i;\n }\n }\n }\n if (best2 == -1) {\n if (eq2 != -1)\n best2 = eq2;\n else\n best2 = default_best2;\n }\n ans = best2;\n }\n auto s1 = s[0 .. ans];\n auto s2 = ((s[ans] - '0') + (s[ans + 1] - '0')).to!string;\n auto s3 = s[ans + 2 .. $];\n writefln(\"%s%s%s\", s1, s2, s3);\n }\n}\n", "positive_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto S = scan;\r\n\r\n auto candidates = new int[][](0, 2);\r\n foreach(i; 0..cast(int)S.length - 1) {\r\n int sum = (S[i] - '0') + (S[i + 1] - '0');\r\n candidates ~= [i, sum];\r\n }\r\n\r\n auto twos = candidates.filter!\"a[1] > 9\";\r\n if (twos.empty) {\r\n return candidates[0][1].to!string ~ S[2..$];\r\n } else {\r\n auto c = candidates.filter!\"a[1] > 9\".array[$ - 1];\r\n return S[0..c[0]] ~ c[1].to!string ~ S[c[0] + 2..$];\r\n }\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n subSolve().writeln;\r\n }\r\n }\r\n\r\n outputForAtCoder(&solve);\r\n}\r\n\r\n// ----------------------------------------------\r\n\r\nimport std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;\r\nT[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }\r\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\r\nT scan(T)(){ return scan.to!T; }\r\nT[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }\r\nvoid deb(T ...)(T t){ debug writeln(t); }\r\nalias Point = Tuple!(long, \"x\", long, \"y\");\r\nPoint invert(Point p) { return Point(p.y, p.x); }\r\nlong[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }\r\nbool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }\r\nbool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }\r\nstring charSort(alias S = \"a < b\")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }\r\nulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}\r\nT[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }\r\nstring toAnswerString(R)(R r) { return r.map!\"a.to!string\".joiner(\" \").array.to!string; }\r\nstruct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:\"^^\", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:\"/\")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}}\r\nalias MInt1 = ModInt!(10^^9 + 7);\r\nalias MInt9 = ModInt!(998_244_353);\r\nvoid outputForAtCoder(T)(T delegate() fn) {\r\n static if (is(T == float) || is(T == double) || is(T == real)) \"%.16f\".writefln(fn());\r\n else static if (is(T == void)) fn();\r\n else static if (is(T == string)) fn().writeln;\r\n else static if (isInputRange!T) {\r\n static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;\r\n else foreach(r; fn()) r.writeln;\r\n }\r\n else fn().writeln;\r\n}\r\nvoid runSolver() {\r\n enum BORDER = \"==================================\";\r\n debug { BORDER.writeln; while(!stdin.eof) { \"<<< Process time: %s >>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip;\r\n\t\tauto n = s.length.to !(int);\r\n\t\tint p = 1;\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tif (s[i - 1] + s[i] > '0' + '9')\r\n\t\t\t{\r\n\t\t\t\tp = i;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (s[0..p - 1], s[p - 1] + s[p] - '0' - '0',\r\n\t\t s[p + 1..$]);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool better1(int a, int b, int c)\n{\n int x1 = (a + b) * 10 + c;\n int x2 = (b + c) < 10 ? a * 10 + (b + c) : a * 100 + (b + c);\n return x2 >= x1;\n}\n\nbool better2(int a, int b, int c)\n{\n int x1 = (a + b) * 10 + c;\n int x2 = (b + c) < 10 ? a * 10 + (b + c) : a * 100 + (b + c);\n return (b + c) >= 10 && x2 >= x1;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto s = readln.strip;\n int best1 = 0;\n foreach (i ; 0 .. cast(int)s.length - 2) {\n if (!better1(s[i] - '0', s[i + 1] - '0', s[i + 2] - '0'))\n break;\n best1 = i + 1;\n }\n bool have_best2 = false;\n int best2;\n foreach (i ; 0 .. cast(int)s.length - 1) {\n if ((s[i] - '0') + (s[i + 1] - '0') >= 10) {\n have_best2 = true;\n best2 = i;\n break;\n }\n }\n int ans = best1;\n if (have_best2) {\n foreach (i ; best2 .. cast(int)s.length - 2) {\n if (!better2(s[i] - '0', s[i + 1] - '0', s[i + 2] - '0'))\n break;\n best2 = i + 1;\n }\n ans = best2;\n }\n auto s1 = s[0 .. ans];\n auto s2 = ((s[ans] - '0') + (s[ans + 1] - '0')).to!string;\n auto s3 = s[ans + 2 .. $];\n writefln(\"%s%s%s\", s1, s2, s3);\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip;\r\n\t\tauto n = s.length.to !(int);\r\n\t\tint p = n - 1;\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tif (s[i - 1] + s[i] > '0' + '9')\r\n\t\t\t{\r\n\t\t\t\tp = i;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (s[0..p - 1], s[p - 1] + s[p] - '0' - '0',\r\n\t\t s[p + 1..$]);\r\n\t}\r\n}\r\n"}], "src_uid": "6db42771fdd582578194c7b69a4ef575"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto s = RD!string;\r\n\t\tauto ss = RD!string;\r\n\r\n\t\tif (s.length < ss.length) continue;\r\n\t\tif ((ss.length - s.length) % 2)\r\n\t\t\ts.popFront;\r\n\r\n\t\tint i, j;\r\n\t\twhile (i < s.length && j < ss.length)\r\n\t\t{\r\n\t\t\tif (s[i] == ss[j])\r\n\t\t\t{\r\n\t\t\t\t++i;\r\n\t\t\t\t++j;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\ti += 2;\r\n\t\t\t}\r\n\t\t}\r\n\t\tdebug writeln(\"i:\", i, \" j:\", j);\r\n\t\tif (j == ss.length)\r\n\t\t\tans[ti] = true;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint q = readInt!int;\n\twhile (q--)\n\t{\n\t\tchar[] s = cast(char[])readString;\n\t\ts.reverse;\n\t\tint ns = cast(int)s.length;\n\t\tchar[] t = cast(char[])readString;\n\t\tt.reverse;\n\t\tint ei = -1;\n\t\tforeach(i, si; s)\n\t\t{\n\t\t\tif (si == t[0] && (i&1) == 0)\n\t\t\t{\n\t\t\t\tif (ei == -1) ei = cast(int)i;\n\t\t\t}\n\t\t}\n\t\tbool can(int i, char[] t)\n\t\t{\n\t\t\twhile (i < ns && t.length > 0)\n\t\t\t{\n\t\t\t\tif (s[i] == t[0])\n\t\t\t\t{\n\t\t\t\t\ti++;\n\t\t\t\t\tt = t[1 .. $];\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ti += 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn t.length == 0;\n\t\t}\n\t\tbool cane = ei != -1 && can(ei, t.dup);\n\t\tif (cane) writeln(\"yes\"); else writeln(\"no\");\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nstring s, t;\nint sn, tn;\n\nbool solve(int si, int ti)\n{\n if (ti == tn)\n return true;\n\n if (si == sn)\n return false;\n\n if (s[si] != t[ti] && si + 2 > sn)\n return false;\n\n if (s[si] == t[ti]) {\n bool ans1, ans2;\n// if (si + 2 <= sn)\n// ans1 = solve(si + 2, ti);\n if (si + 1 <= sn && ti + 1 <= tn)\n ans2 = solve(si + 1, ti + 1);\n return ans1 || ans2;\n } else {\n bool ans1, ans2;\n if (si + 2 <= sn)\n ans1 = solve(si + 2, ti);\n return ans1 || ans2;\n }\n}\n\nvoid main()\n{\n long q;\n readf!\" %d \"(q);\n while (q--) {\n s = readln.strip.retro.text;\n t = readln.strip.retro.text;\n sn = cast(int)s.length;\n tn = cast(int)t.length;\n// writeln(s);\n// writeln(t);\n writeln(solve(0, 0) ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (string s, string t)\r\n{\r\n\tif ((s.length % 2) != (t.length % 2))\r\n\t{\r\n\t\ts = s[1..$];\r\n\t}\r\n\tint pos = 0;\r\n\tbool skip = false;\r\n\tforeach (ref c; s)\r\n\t{\r\n\t\tif (skip)\r\n\t\t{\r\n\t\t\tskip = false;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (t[pos] == c)\r\n\t\t{\r\n\t\t\tpos += 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tskip = true;\r\n\t\t}\r\n\t\tif (pos == t.length)\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\treturn false;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto s = readln.strip;\r\n\t\tauto t = readln.strip;\r\n\t\twriteln (solve (s, t) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint q = readInt!int;\n\twhile (q--)\n\t{\n\t\tchar[] s = cast(char[])readString;\n\t\tint ns = cast(int)s.length;\n\t\tchar[] t = cast(char[])readString;\n\t\tint ei = -1;\n\t\tint oi = -1;\n\t\tforeach(i, si; s)\n\t\t{\n\t\t\tif (si == t[0])\n\t\t\t{\n\t\t\t\tif (i & 1)\n\t\t\t\t{\n\t\t\t\t\tif (oi == -1) oi = cast(int)i;\n\t\t\t\t}\n\t\t\t\telse if (ei == -1) ei = cast(int)i;\n\t\t\t}\n\t\t}\n\t\tbool can(int i, char[] t)\n\t\t{\n\t\t\twhile (i < ns && t.length > 0)\n\t\t\t{\n\t\t\t\tif (s[i] == t[0])\n\t\t\t\t{\n\t\t\t\t\ti++;\n\t\t\t\t\tt = t[1 .. $];\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ti += 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn t.length == 0;\n\t\t}\n\t\tbool cane = ei != -1 && can(ei, t.dup);\n\t\tbool cano = oi != -1 && can(oi, t.dup);\n\t\tif (cane || cano) writeln(\"yes\"); else writeln(\"no\");\n\t}\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}], "src_uid": "67856314f24ed718eb9b0d9fc9ab1abe"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto used = new bool[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto k = RD;\n\t\t\tbool ok;\n\t\t\tforeach (j; 0..k)\n\t\t\t{\n\t\t\t\tauto e = RD!int-1;\n\t\t\t\tif (ok) continue;\n\t\t\t\tif (!used[e])\n\t\t\t\t{\n\t\t\t\t\tused[e] = true;\n\t\t\t\t\tok = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t{\n\t\t\t\tans[ti] = [i+1];\n\t\t\t}\n\t\t}\n\t\tif (!ans[ti].empty)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (!used[i])\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= i+1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.empty)\n\t\t{\n\t\t\twriteln(\"OPTIMAL\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"IMPROVE\");\n\t\t\twriteln(e[0], \" \", e[1]);\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n A: foreach(_; 0 .. scan!int){\n int n = scan!int;\n bool[] isMarried = new bool[](n);\n bool[] isSold = new bool[](n);\n foreach(i; 0 .. n){\n int k = scan!int;\n int[] gs = scan!int(k).map!(x => x - 1).array;\n foreach(g; gs){\n if(! isSold[g]){\n isSold[g] = 1;\n isMarried[i] = 1;\n break;\n }\n }\n }\n auto gq = new Queue!int;\n foreach(g; 0 .. n) if(! isSold[g]) gq.enq(g);\n\n if(gq.isEmpty){\n \"OPTIMAL\".print;\n continue A;\n }\n else{\n \"IMPROVE\".print;\n foreach(i; 0 .. n) if(! isMarried[i]){\n print(i + 1, gq.deq + 1);\n break;\n }\n }\n\n }\n}\n\n\n// ----- \u30ad\u30e5\u30fc -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : \u6b21\u306b\u8aad\u307f\u51fa\u3059\u4f4d\u7f6e\u3000j: \u6b21\u306b\u66f8\u304d\u8fbc\u3080\u4f4d\u7f6e\n\tthis(){\t}\n\tthis(T[] xs){ this.xs = xs; j = xs.length.to!uint; }\n\tuint length(){ return j - i; }\n\tbool isEmpty(){ return j == i; }\n\tvoid enq(T x){\n\t\twhile(j + 1 >= xs.length) xs.length = xs.length * 2 + 1;\n\t\txs[j ++] = x;\n\t}\n\tT deq(){ assert(i < j); return xs[i ++]; }\n\tT peek(){ assert(i < j); return xs[i]; }\n\tT opIndex(uint li){ assert(i + li < j); return xs[i + li]; }\n\tstatic Queue!T opCall(){ return new Queue!T; }\n\tstatic Queue!T opCall(T[] xs){ return new Queue!T(xs); }\n\tT[] array(){ return xs[i .. j]; }\n\toverride string toString(){ return array.to!string; }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); } bool DEBUG = 0; \nvoid log(A ...)(lazy A a){ if(DEBUG) print(a); }\nvoid print(){ writeln(\"\"); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, \" \"), print(a); }\nstring unsplit(T)(T xs){ return xs.array.to!(string[]).join(\" \"); }\nstring scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }\nT lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n A: foreach(_; 0 .. scan!int){\n int n = scan!int;\n bool[] isMarried = new bool[](n);\n bool[] isSold = new bool[](n);\n foreach(i; 0 .. n){\n int k = scan!int;\n int[] gs = scan!int(k).map!(x => x - 1).array;\n foreach(g; gs){\n if(! isSold[g]){\n isSold[i] = 1;\n isMarried[i] = 1;\n break;\n }\n }\n }\n auto gq = new Queue!int;\n foreach(g; 0 .. n) if(! isSold[g]) gq.enq(g);\n\n if(gq.isEmpty){\n \"OPTIMAL\".print;\n continue A;\n }\n else{\n \"IMPROVE\".print;\n foreach(i; 0 .. n) if(! isMarried[i]){\n print(i + 1, gq.deq + 1);\n break;\n }\n }\n\n }\n}\n\n\n// ----- \u30ad\u30e5\u30fc -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : \u6b21\u306b\u8aad\u307f\u51fa\u3059\u4f4d\u7f6e\u3000j: \u6b21\u306b\u66f8\u304d\u8fbc\u3080\u4f4d\u7f6e\n\tthis(){\t}\n\tthis(T[] xs){ this.xs = xs; j = xs.length.to!uint; }\n\tuint length(){ return j - i; }\n\tbool isEmpty(){ return j == i; }\n\tvoid enq(T x){\n\t\twhile(j + 1 >= xs.length) xs.length = xs.length * 2 + 1;\n\t\txs[j ++] = x;\n\t}\n\tT deq(){ assert(i < j); return xs[i ++]; }\n\tT peek(){ assert(i < j); return xs[i]; }\n\tT opIndex(uint li){ assert(i + li < j); return xs[i + li]; }\n\tstatic Queue!T opCall(){ return new Queue!T; }\n\tstatic Queue!T opCall(T[] xs){ return new Queue!T(xs); }\n\tT[] array(){ return xs[i .. j]; }\n\toverride string toString(){ return array.to!string; }\n}\n"}], "src_uid": "38911652b3c075354aa8adb2a4c6e362"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nlong solve_max(long[] pfa, long n)\n{\n long total = cast(long)pfa.length + n;\n long accounted = total - total / 4;\n long score = min(accounted, n) * 100;\n long remaining = accounted - min(accounted, n);\n return score + (remaining > 0 ? pfa[cast(int)remaining - 1] : 0L);\n}\n\nlong solve_min(long[] pfb, long n)\n{\n long total = cast(long)pfb.length + n;\n long remaining = min(cast(long)pfb.length, total - total / 4);\n return (remaining > 0 ? pfb[cast(int)remaining - 1] : 0L);\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array.sort!((x, y) => x > y);\n auto b = readln.strip.split.map!(to!long).array.sort!((x, y) => x > y);\n\n long[] pfa;\n long[] pfb;\n\n long sum = 0;\n foreach (x ; a) {\n sum += x;\n pfa ~= sum;\n }\n sum = 0;\n foreach (x ; b) {\n sum += x;\n pfb ~= sum;\n }\n writeln(iota(0L, 1000000L).map!(x => solve_max(pfa, x) >= solve_min(pfb, x)).assumeSorted.lowerBound(true).length);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,\r\n std.container, std.typecons, std.conv, std.random, std.bigint;\r\n\r\nvoid read(S...)(ref S args) {\r\n auto input = readln.split;\r\n assert(input.length == args.length);\r\n foreach (i, ref arg; args) {\r\n arg = input[i].to!(S[i]);\r\n }\r\n}\r\n\r\nauto list(T)() { return readln.split.map!(e => e.to!T).array; }\r\n\r\nint[] a, b, A, B;\r\n\r\nint solve(int m) {\r\n int n = a.length.to!int;\r\n \r\n int q = n + m;\r\n q -= q / 4;\r\n \r\n int pointB = B[min(q, B.length) - 1];\r\n \r\n int pointA = m * 100;\r\n if (q > m) {\r\n pointA += A[q - m - 1];\r\n }\r\n \r\n return pointA >= pointB;\r\n}\r\n\r\n\r\nvoid main() {\r\n int t;\r\n read(t);\r\n \r\n while (t--) {\r\n int n; \r\n read(n);\r\n a = list!int;\r\n b = list!int;\r\n \r\n sort(a);\r\n reverse(a);\r\n sort(b);\r\n reverse(b);\r\n \r\n A = a.dup;\r\n B = b.dup;\r\n foreach (i; 1 .. n) A[i] = A[i - 1] + A[i];\r\n foreach (i; 1 .. n) B[i] = B[i - 1] + B[i];\r\n \r\n if (solve(0)) {\r\n writeln(0);\r\n continue;\r\n } else {\r\n auto low = 0;\r\n auto high = 300000;\r\n \r\n while (high > low + 1) {\r\n int mid = high + low;\r\n mid /= 2;\r\n \r\n if (solve(mid)) {\r\n high = mid;\r\n } else {\r\n low = mid;\r\n }\r\n }\r\n \r\n writeln(high);\r\n }\r\n }\r\n}\r\n\r\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nauto sp(R)(R r, size_t i, size_t j)\n{\n\tif (j < i) return 0;\n\tif (i == 0) return r[j]; \n\treturn r[j] - r[i - 1];\n}\nvoid solve()\n{\n\tint n = readInt!int;\n\tauto a = new int[](n);\n\tauto b = new int[](n);\n\tforeach(ref ai; a) ai = readInt!int;\n\tforeach(ref bi; b) bi = readInt!int;\n\tsort(a); sort(b);\n\ta.reverse, b.reverse;\n\tauto pa = a.cumulativeFold!((a, b)=> cast(long)a + b).array;\n\tauto pb = b.cumulativeFold!((a, b)=> cast(long)a + b).array;\n\tint used = n - (n/4);\n\tint hi = 5 * 1_000_00;\n\tint lo = 0;\n\tint ans = -1;\n\twhile (lo <= hi)\n\t{\n\t\tint mi = (lo + hi) / 2;\n\t\tint nn = mi + n;\n\t\tint usedmi = nn - nn / 4;\n\t\tint usedorig = max(0, usedmi - mi);\n\t\tint usednew = usedmi - usedorig;\n\t\tlong sa = usednew * 100;\n\t\tif (usedorig) sa += pa[usedorig - 1];\n\t\tlong sb = pb[min(n, usedmi) - 1];\n\t\tif (sa >= sb)\n\t\t{\n\t\t\tans = mi;\n\t\t\thi = mi - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlo = mi + 1;\n\t\t}\n\t}\n\tans.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}, {"source_code": "// code by cutx64\r\n\r\nmodule main;\r\n\r\nimport std.string, std.array, std.container, std.typecons;\r\nimport std.stdio, std.format, std.file, std.outbuffer;\r\nimport std.algorithm, std.conv, std.functional, std.range, core.bitop;\r\n// import std.bigint, std.complex, std.bitmanip;\r\n// import std.math, std.mathspecial, std.numeric;\r\n\r\nvoid main() {\r\n\r\n int tests; readf!\"%s\\n\"(tests);\r\n while(tests--) {\r\n int n; readf!\"%s\\n\"(n);\r\n auto a = readln.splitter.map!(to!int).array.sort.reverse;\r\n auto b = readln.splitter.map!(to!int).array.sort.reverse;\r\n int low = -1, high = 3 * n + 1;\r\n while (low + 1 < high) {\r\n int mid = (low + high) / 2;\r\n int k = n + mid;\r\n int r = k - k / 4;\r\n long A, B;\r\n foreach(i; 0 .. r) {\r\n A += (i < mid) ? 100 : a[i - mid];\r\n B += (i < n) ? b[i] : 0;\r\n }\r\n ((A >= B) ? high : low) = mid;\r\n }\r\n high.writeln;\r\n }\r\n\r\n} // main\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\t\tauto b = RDA;\r\n\r\n\t\ta.sort();\r\n\t\tb.sort();\r\n\r\n\t\tauto aa = new long[](n+1);\r\n\t\tauto bb = new long[](n+1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\taa[i+1] = aa[i] + a[i];\r\n\t\t\tbb[i+1] = bb[i] + b[i];\r\n\t\t}\r\n\t\tauto tot = a.sum - b.sum;\r\n\r\n\t\tauto i = n;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (tot + (i-n) * 100 - aa[i/4] + bb[max(i/4-(i-n), 0)] >= 0)\r\n\t\t\t\tbreak;\r\n\t\t\t++i;\r\n\t\t}\r\n\t\tans[ti] = i - n;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (a);\r\n\t\treverse (a);\r\n\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tsort (b);\r\n\t\treverse (b);\r\n\r\n\t\tauto sa = [0];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tsa ~= sa.back + c;\r\n\t\t}\r\n\r\n\t\tauto sb = [0];\r\n\t\tforeach (ref c; b)\r\n\t\t{\r\n\t\t\tsb ~= sb.back + c;\r\n\t\t}\r\n\r\n\t\tbool ok (int add)\r\n\t\t{\r\n\t\t\tauto num = n + add;\r\n\t\t\tauto part = num - num / 4;\r\n\r\n\t\t\tint resA = 0;\r\n\t\t\tint numA = part;\r\n\t\t\tint fullA = min (add, numA);\r\n\t\t\tnumA -= fullA;\r\n\t\t\tresA += fullA * 100;\r\n\t\t\tresA += sa[numA];\r\n\r\n\t\t\tint resB = 0;\r\n\t\t\tint numB = part;\r\n\t\t\tint someB = min (n, numB);\r\n\t\t\tnumB -= someB;\r\n\t\t\tresB += sb[someB];\r\n\r\n\t\t\tdebug {writeln (n, \" \", add, \": \", resA, \" \", resB);}\r\n\t\t\treturn resA >= resB;\r\n\t\t}\r\n\r\n\t\tauto lo = 0;\r\n\t\tauto hi = 2 * 10 ^^ 7;\r\n\t\twhile (lo < hi)\r\n\t\t{\r\n\t\t\tauto me = (lo + hi) >> 1;\r\n\t\t\tif (ok (me))\r\n\t\t\t{\r\n\t\t\t\thi = me;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlo = me + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (lo);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum L = 100;\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new int[N];\n auto B = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n foreach (i; 0 .. N) {\n B[i] = readInt();\n }\n A.sort.reverse;\n B.sort.reverse;\n \n int lo = -1, hi = 3 * N + 1;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n const k = N + mid;\n const num = k - k / 4;\n long scoreA, scoreB;\n foreach (i; 0 .. num) {\n scoreA += (i < mid) ? L : A[i - mid];\n scoreB += (i < N) ? B[i] : 0;\n }\n ((scoreA >= scoreB) ? hi : lo) = mid;\n }\n writeln(hi);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--) solve;\n}\nauto sp(R)(R r, size_t i, size_t j)\n{\n\tif (j < i) return 0;\n\tif (i == 0) return r[j]; \n\treturn r[j] - r[i - 1];\n}\nvoid solve()\n{\n\tint n = readInt!int;\n\tauto a = new int[](n);\n\tauto b = new int[](n);\n\tforeach(ref ai; a) ai = readInt!int;\n\tforeach(ref bi; b) bi = readInt!int;\n\tsort(a); sort(b);\n\ta.reverse, b.reverse;\n\tauto pa = a.cumulativeFold!((a, b)=> cast(long)a + b).array;\n\tauto pb = b.cumulativeFold!((a, b)=> cast(long)a + b).array;\n\tint used = n - (n/4);\n\tint hi = 5 * 1_000_00;\n\tint lo = 0;\n\tint ans = -1;\n\twhile (lo <= hi)\n\t{\n\t\tint mi = (lo + hi) / 2;\n\t\tint nn = mi + n;\n\t\tint usedmi = nn - nn / 4;\n\t\tint usedorig = max(0, usedmi - mi);\n\t\tint usednew = usedmi - usedorig;\n\t\tlong sa = usednew * 100;\n\t\tif (usedorig) sa += pa[usedorig - 1];\n\t\tlong sb = pb[$ - 1];\n\t\tif (sa >= sb)\n\t\t{\n\t\t\tans = mi;\n\t\t\thi = mi - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlo = mi + 1;\n\t\t}\n\t}\n\tans.writeln;\n}\n\n/* INPUT ROUTINES */\nint currChar;\nstatic this()\n{\n\tcurrChar = getchar();\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\n/**MODULAR SYSTEM*/\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\n"}], "src_uid": "61b88627fc843ef6e5226e1003822793"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main () {\n\tauto n = readln.strip.to !(int);\n\tauto a = readln.splitter.map !(to !(long)).array;\n\tauto b = readln.splitter.map !(to !(int)).array;\n\n\tauto g = new int [] [n];\n\tforeach (i; 0..n) if (b[i] > 0) g[b[i] - 1] ~= i;\n\n\tauto used = new bool [n];\n\tauto h = new int [] [n];\n\n\tvoid recur (int v) {\n\t\tif (used[v]) return;\n\t\tused[v] = true;\n\t\tforeach (u; g[v]) {\n\t\t\trecur (u);\n\t\t\tif (a[u] > 0) {h[v] ~= u; a[v] += a[u];}\n\t\t\telse h[u] ~= v;\n\t\t}\n\t}\n\n\tforeach (v; 0..n) recur (v);\n\twriteln (a.sum);\n\n\tint cur = 0;\n\tused[] = false;\n\tint [] p;\n\n\tvoid topSort (int v) {\n\t\tif (used[v]) return;\n\t\tused[v] = true;\n\t\tforeach (u; h[v]) topSort (u);\n\t\tp ~= v + 1;\n\t}\n\n\tforeach (v; 0..n) topSort (v);\n\twritefln !(\"%(%s %)\") (p);\n}\n", "positive_code": [{"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\n\nDList!string _words;\nvoid read(T)(out T t)\n{\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n t = to!T(word);\n}\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum log =\n q{\n debug\n {\n _loglevel++;\n mixin(`_log!(__FUNCTION__, `, [ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back))].joiner(\", \").array, `);`);\n scope(exit) _loglevel--;\n }\n};\n\nvoid main()\n{\n long n;\n read(n);\n\n auto a = Array!long(); a.length = n.ind;\n auto b = Array!long(); b.length = n.ind;\n auto children = Array!(Appender!(long[]))(); children.length = n.ind;\n\n foreach(i; 0 .. n)\n read(a.at(i));\n foreach(ref childrenArray; children)\n childrenArray = appender!(long[])();\n foreach(i; 0 .. n)\n {\n read(b.at(i));\n if (b.at(i) == -1)\n continue;\n b.at(i)--;\n children.at(b.at(i)).put(i);\n }\n auto roots = iota(0, n).filter!(i => b.at(i) == -1).array;\n\n auto operations = appender!(long[])();\n auto done = new bool[n.ind];\n auto ans = long(0);\n\n void doOperation(long node)\n {\n assert(!done.at(node));\n if (b.at(node) != -1)\n a.at(b.at(node)) += a.at(node);\n operations.put(node);\n ans += a.at(node);\n done.at(node) = true;\n }\n\n void solveTree(long node)\n {\n mixin(log);\n foreach(child; children.at(node))\n {\n solveTree(child);\n if (a.at(child) >= 0)\n doOperation(child);\n }\n }\n foreach(root; roots)\n {\n solveTree(root);\n }\n\n void solveRemaining(long node)\n {\n if (!done.at(node))\n doOperation(node);\n foreach(child; children.at(node))\n solveRemaining(child);\n }\n\n foreach(root; roots)\n solveRemaining(root);\n\n writeln(ans);\n foreach(operation; operations)\n write(operation + 1, \" \");\n writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tb[] -= 1;\n\n\t\tauto g = new int [] [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] >= 0)\n\t\t\t{\n\t\t\t\tg[b[i]] ~= i;\n\t\t\t}\n\t\t}\n\n\t\tauto used = new bool [n];\n\t\tauto h = new int [] [n];\n\n\t\tvoid recur (int v, int w)\n\t\t{\n\t\t\tif (used[v])\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tused[v] = true;\n\t\t\tforeach (u; g[v])\n\t\t\t{\n\t\t\t\tif (u != w)\n\t\t\t\t{\n\t\t\t\t\trecur (u, v);\n\t\t\t\t\tif (a[u] > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\th[v] ~= u;\n\t\t\t\t\t\ta[v] += a[u];\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\th[u] ~= v;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\trecur (v, -1);\n\t\t}\n\n\t\twriteln (a.sum);\n\n\t\tint cur = 0;\n\t\tused[] = false;\n\t\tauto p = new int [n];\n\n\t\tvoid topologicalSort (int v)\n\t\t{\n\t\t\tif (used[v])\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tused[v] = true;\n\t\t\tforeach (u; h[v])\n\t\t\t{\n\t\t\t\ttopologicalSort (u);\n\t\t\t}\n\t\t\tp[cur] = v + 1;\n\t\t\tcur += 1;\n\t\t}\n\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\ttopologicalSort (v);\n\t\t}\n\t\twritefln !(\"%(%s %)\") (p);\n\t}\n}\n"}], "negative_code": [], "src_uid": "5ebae703049e9ab4547df87861034176"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nstruct Cmb\r\n{\r\n\tvoid init(size_t n)\r\n\t{\r\n\t\tlong powmod(long a, long p)\r\n\t\t{\r\n\t\t\tlong ans = 1;\r\n\t\t\tlong mul = a;\r\n\t\t\twhile (p > 0)\r\n\t\t\t{\r\n\t\t\t\tif ((p & 1) == 1)\r\n\t\t\t\t\tans.modm(mul);\r\n\t\t\t\tp >>= 1;\r\n\t\t\t\tmul.modm(mul);\r\n\t\t\t}\r\n\t\t\treturn ans;\r\n\t\t}\r\n\r\n\t\t++n;\r\n\t\tfact = new long[2][](n);\r\n\t\tfact[0][0] = 1;\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tfact[i][0] = fact[i-1][0];\r\n\t\t\tfact[i][0].modm(i);\r\n\t\t}\r\n\t\tfact[n-1][1] = powmod(fact[n-1][0], mod - 2);\r\n\t\tforeach_reverse (i; 0..n-1)\r\n\t\t{\r\n\t\t\tfact[i][1] = fact[i+1][1];\r\n\t\t\tfact[i][1].modm(i+1);\r\n\t\t}\r\n\t}\r\n\r\n\tlong get(size_t n, size_t r)\r\n\t{\r\n\t\tlong res = fact[n][0];\r\n\t\tres.modm(fact[r][1]);\r\n\t\tres.modm(fact[n-r][1]);\r\n\t\treturn res;\r\n\t}\r\n\r\n\tlong[2][] fact;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tCmb cmb;\r\n\tcmb.init(1000);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto a = RDA!int;\r\n\r\n\t\tauto cnt = new int[](n+1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\t++cnt[a[i]];\r\n\t\t}\r\n\r\n\t\tforeach_reverse (i; 0..n+1)\r\n\t\t{\r\n\t\t\tif (cnt[i] < k)\r\n\t\t\t\tk -= cnt[i];\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tans[ti] = cmb.get(cnt[i], k);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int mod = 10 ^^ 9 + 7;\r\n\r\nint powMod (int a, int p)\r\n{\r\n\tint res = 1;\r\n\tfor ( ; p > 0; p >>= 1)\r\n\t{\r\n\t\tif (p & 1)\r\n\t\t{\r\n\t\t\tres = (res * 1L * a) % mod;\r\n\t\t}\r\n\t\ta = (a * 1L * a) % mod;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nalias inv = a => powMod (a, mod - 2);\r\n\r\nint fact (int n)\r\n{\r\n\tint res = 1;\r\n\tfor (int i = 1; i <= n; i++)\r\n\t{\r\n\t\tres = (res * 1L * i) % mod;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nint c (int n, int k)\r\n{\r\n\treturn fact (n) * 1L * inv (fact (n - k)) % mod * 1L *\r\n\t inv (fact (k)) % mod;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort !(q{a > b}) (a);\r\n\r\n\t\tint lo = k - 1;\r\n\t\tint hi = k;\r\n\t\tif (a[lo] != a[hi])\r\n\t\t{\r\n\t\t\twriteln (1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\twhile (lo > 0 && a[lo - 1] == a[lo])\r\n\t\t{\r\n\t\t\tlo -= 1;\r\n\t\t}\r\n\t\twhile (hi + 1 < n && a[hi + 1] == a[hi])\r\n\t\t{\r\n\t\t\thi += 1;\r\n\t\t}\r\n\r\n\t\twriteln (c (hi + 1 - lo, k - lo));\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nenum P = 10L^^9 + 7;\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N, K; get(N, K);\r\n int[] aa; get(aa);\r\n auto MAX = new int[](K + 1);\r\n auto DP = new long[](K + 1);\r\n DP[0] = 1;\r\n foreach (a; aa) {\r\n foreach_reverse (i; 0..K) {\r\n if (MAX[i] + a > MAX[i+1]) {\r\n MAX[i+1] = MAX[i] + a;\r\n DP[i+1] = DP[i];\r\n } else if (MAX[i] + a == MAX[i+1]) {\r\n (DP[i+1] += DP[i]) %= P;\r\n }\r\n }\r\n }\r\n writeln(DP[K]);\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int mod = 10 ^^ 9 + 7;\r\n\r\nint powMod (int a, int p)\r\n{\r\n\tint res = 1;\r\n\tfor ( ; p > 0; p >>= 1)\r\n\t{\r\n\t\tif (p & 1)\r\n\t\t{\r\n\t\t\tres = (res * 1L * a) % mod;\r\n\t\t}\r\n\t\ta = (a * 1L * a) % mod;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nalias inv = a => powMod (a, mod - 2);\r\n\r\nint fact (int n)\r\n{\r\n\tint res = 1;\r\n\tfor (int i = 1; i <= n; i++)\r\n\t{\r\n\t\tres = (res * 1L * i) % mod;\r\n\t}\r\n\treturn res;\r\n}\r\n\r\nint c (int n, int k)\r\n{\r\n\treturn fact (n) * 1L * inv (fact (n - k)) % mod * 1L *\r\n\t inv (fact (k)) % mod;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tsort !(q{a > b}) (a);\r\n\r\n\t\tint lo = k - 1;\r\n\t\tint hi = k;\r\n\t\tif (a[lo] != a[hi])\r\n\t\t{\r\n\t\t\twriteln (1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\twhile (lo > 0 && a[lo - 1] == a[lo])\r\n\t\t{\r\n\t\t\tlo -= 1;\r\n\t\t}\r\n\t\twhile (hi + 1 < n && a[hi + 1] == a[hi])\r\n\t\t{\r\n\t\t\thi += 1;\r\n\t\t}\r\n\r\n\t\twriteln (c (hi - lo, k - lo));\r\n\t}\r\n}\r\n"}], "src_uid": "69326546e8435ccfff3010947295c291"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto s = readln.strip;\n\t\tauto t = readln.strip;\n\t\tif (n.iota.any !(i => s[i] > t[i]))\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue multitest_loop;\n\t\t}\n\t\tauto r = s.dup;\n\t\tint res = 0;\n\t\tauto b = new bool [n];\n\t\tforeach (c; 'a'..'u')\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tb[i] = (r[i] == c && r[i] < t[i]);\n\t\t\t}\n\t\t\tif (any (b))\n\t\t\t{\n\t\t\t\tauto d = n.iota.filter !(i => b[i])\n\t\t\t\t .map !(i => t[i]).minElement;\n\t\t\t\tforeach (i; 0..n)\n\t\t\t\t{\n\t\t\t\t\tif (r[i] == c)\n\t\t\t\t\t{\n\t\t\t\t\t\tr[i] = d;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum V = 20;\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const A = readToken();\n const B = readToken();\n \n bool ok = true;\n foreach (i; 0 .. N) {\n ok = ok && (A[i] <= B[i]);\n }\n if (ok) {\n auto needs = new int[V];\n foreach (i; 0 .. N) {\n needs[A[i] - 'a'] |= 1 << (B[i] - 'a');\n }\n int ans;\n foreach (u; 0 .. V) {\n needs[u] &= ~(1 << u);\n if (needs[u]) {\n const v = bsf(needs[u]);\n needs[v] |= needs[u];\n ++ans;\n }\n }\n writeln(ans);\n } else {\n writeln(-1);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nstruct UnionFind(T)\n{\n\tvoid init(T n) { par = new T[](n); foreach (i; 0..n) par[i] = i; cnt = new T[](n); fill(cnt, 1); }\n\tT root(T i) { return par[i] == i ? i : (par[i] = root(par[i])); }\n\tbool same(T i, T j) { return root(i) == root(j); }\n\tvoid unite(T i, T j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; cnt[j] += cnt[i]; }\n\tT size(T i) { return cnt[root(i)]; }\n\tT[] par, cnt;\n}\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto A = RD!string;\n\t\tauto B = RD!string;\n\n\t\tUnionFind!int uf;\n\t\tuf.init(20);\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto a = A[i] - 'a';\n\t\t\tauto b = B[i] - 'a';\n\t\t\tif (a > b)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (a == b) continue;\n\t\t\tuf.unite(a, b);\n\t\t}\n\t\tif (!ok)\n\t\t{\n\t\t\tans[ti] = -1;\n\t\t\tcontinue;\n\t\t}\n\t\tdebug writeln(uf.par);\n\t\tdebug writeln(uf.cnt);\n\n\t\tauto root = new bool[](20);\n\t\tforeach (i; 0..20)\n\t\t{\n\t\t\tauto r = uf.root(i);\n\t\t\troot[r] = true;\n\t\t}\n\t\tforeach (i; 0..20)\n\t\t{\n\t\t\tif (root[i])\n\t\t\t{\n\t\t\t\tans[ti] += uf.size(i) - 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n test: while (t--) {\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto a = readln.chomp;\n auto b = readln.chomp;\n \n auto vals = new RedBlackTree!int[] (25);\n foreach (i; (25).iota) { vals[i] = redBlackTree!int(); }\n \n foreach (ca, cb; lockstep(a, b)) {\n if (ca > cb) {\n writeln(-1);\n continue test;\n }\n \n if (ca == cb) { continue; }\n \n vals[ca - 'a'].insert(cb - 'a');\n }\n \n auto trans = new bool[][] (25, 25);\n foreach (i; (25).iota) { trans[i][] = false; }\n \n int ans = 0;\n \n foreach (let; (25).iota) {\n if (vals[let].empty()) { continue; }\n \n ans += 1;\n int nxt = vals[let].front;\n vals[let].removeFront();\n \n foreach (el; vals[let]) { vals[nxt].insert(el); }\n }\n \n ans.writeln;\n }\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n test: while (t--) {\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto a = readln.chomp;\n auto b = readln.chomp;\n \n auto vals = new RedBlackTree!int[] (25);\n foreach (i; (25).iota) { vals[i] = redBlackTree!int(); }\n \n foreach (ca, cb; lockstep(a, b)) {\n if (ca > cb) {\n writeln(-1);\n continue test;\n }\n \n if (ca == cb) { continue; }\n \n vals[ca - 'a'].insert(cb - 'a');\n }\n \n auto trans = new bool[][] (25, 25);\n foreach (i; (25).iota) { trans[i][] = false; }\n \n foreach (let; (25).iota) {\n if (vals[let].empty()) { continue; }\n \n auto arr = [let].chain(vals[let][]);\n \n foreach (prev, nxt; lockstep(arr, arr.dropOne())) { trans[prev][nxt] = true; }\n }\n \n int ans = 0;\n \n foreach (i; (25).iota) { ans += trans[i].count!(x => x); }\n \n ans.writeln;\n }\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum V = 20;\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const A = readToken();\n const B = readToken();\n \n bool ok = true;\n foreach (i; 0 .. N) {\n ok = ok && (A[i] <= B[i]);\n }\n if (ok) {\n auto needs = new int[V];\n foreach (i; 0 .. N) {\n needs[A[i] - 'a'] |= 1 << (B[i] - 'a');\n }\n int ans;\n foreach (u; 0 .. V) {\n needs[u] &= ~(1 << u);\n if (needs[u]) {\n const v = bsf(u);\n needs[v] |= needs[u];\n ++ans;\n }\n }\n writeln(ans);\n } else {\n writeln(-1);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "7c6e8bc160a17dbc6d55c6dc40fe0988"} {"source_code": "immutable multi = true;\n\nvoid solve(int)\n{\n\tint n = readInt!int;\n\tassert(n == 1);\n\tint m = readInt!int;\n\tassert(m >= 0 && m <= 300);\n\tauto a = ma(m, readInt!long);\n\tint[long] cnt;\n\tforeach(i, ai; a) cnt[ai]++;\n\tauto sa = a.dup;\n\tsort(sa);\n\tauto ua = sa.uniq.array;\n\tint[][long] poss;\n\t{\n\tint i = 0;\n\tforeach(j, ai; ua)\n\t{\n\t\tposs[ai] = null;\n\t\tforeach(k; 0 .. cnt[ai])\n\t\t{\n\t\t\tposs[ai] ~= i++;\n\t\t}\n\t}\n\t}\n\tauto used = new long[](m);\n\tlong ans = 0;\n\tforeach(i, ai; a)\n\t{\n\t\tauto pos = poss[ai][$-1];\n\t\tposs[ai] = poss[ai][0 .. $ - 1];\n\t\tforeach(j; 0 .. pos)\n\t\t{\n\t\t\tans += used[j];\n\t\t}\n\t\tused[pos] = 1;\n\t}\n\tans.writeln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nlong compress(in long[] arr, out long[long] zip, out long[] unzip)\r\n{\r\n\tauto index = MAKE_IDX(arr);\r\n\tlong last = arr[index[0]], x;\r\n\tzip[last] = x;\r\n\tunzip ~= last;\r\n\tforeach (i; index[1..$])\r\n\t{\r\n\t\tif (arr[i] == last) continue;\r\n\t\tlast = arr[i];\r\n\t\t++x;\r\n\t\tzip[last] = x;\r\n\t\tunzip ~= last;\r\n\t}\r\n\treturn x+1;\r\n}\r\n\r\nstruct SegTree(T)\r\n{\r\n\tT delegate(const(T), const(T)) f;\r\n\tT[] data;\r\n\tT init;\r\n this(T[] _data, T delegate(const(T), const(T)) _f, T _init)\r\n {\r\n\t\tf = _f; init = _init;\r\n\t\tsize_t n = 1; while (n < _data.length) n *= 2; data.length = n*2-1;\r\n\t\tforeach (i; 0.._data.length) data[i+n-1] = _data[i];\r\n\t\tforeach (i; _data.length..n) data[i+n-1] = _init;\r\n\t\tforeach_reverse (i; 0..n-1) data[i] = f(data[i*2+1], data[i*2+2]);\r\n\t}\r\n T query(size_t l, size_t r)\r\n\t{\r\n size_t n = (data.length+1) / 2; l += n-1; r += n-1; T res = init;\r\n while (l < r)\r\n\t\t{\r\n if ((l & 1) == 0) res = f(res, data[l]);\r\n if ((r & 1) == 0) res = f(res, data[r-1]);\r\n l = l/2; r = (r-1)/2;\r\n }\r\n return res;\r\n }\r\n\tvoid update(size_t i, T v)\r\n\t{\r\n\t\ti += (data.length+1) / 2 - 1; data[i] = v;\r\n\t\twhile (i != 0) { i = (i-1)/2; data[i] = f(data[i*2+1], data[i*2+2]); }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto m = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tlong[long] zip;\r\n\t\tlong[] unzip;\r\n\t\tauto len = compress(a, zip, unzip);\r\n\r\n\t\tlong[] b;\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tb ~= zip[a[i]];\r\n\t\t}\r\n\r\n\t\tauto dummy = new long[](cast(int)len);\r\n\t\tauto st = new SegTree!long(dummy, (in long x, in long y)=>x+y, 0);\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tans[ti] += st.query(0, cast(int)b[i]);\r\n\t\t\tauto cnt = st.query(cast(int)b[i], cast(int)b[i]+1);\r\n\t\t\tst.update(cast(int)b[i], cnt+1);\r\n\t\t}\r\n\t}\r\n\t\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.format, std.functional, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nint lb = -1;\n\nstruct S { int v; int[] a; };\n\nS op(ref S x, ref S y)\n{\n if (lb < 0) {\n return S(0, (x.a ~ y.a).sort.array);\n } else {\n auto cnt1 = x.a.assumeSorted.lowerBound(lb).length;\n auto cnt2 = y.a.assumeSorted.lowerBound(lb).length;\n return S(x.v + y.v + cast(int)(cnt1 + cnt2), []);\n }\n}\n\nS e()\n{\n S tmp;\n return tmp;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n, m;\n readf!\" %d %d \"(n, m);\n auto a = readln.strip.split.map!(to!int).array;\n auto b = zip(iota(n * m), a).array.sort!((x, y) => x[1] == y[1] ? x[0] > y[0] : x[1] < y[1]).array;\n S[] c;\n foreach (x ; b)\n c ~= S(0, [x[0]]);\n\n lb = -1;\n auto seg = c.Segtree!(S, op, e);\n long ans = 0;\n foreach (i ; 0 .. n * m) {\n lb = b[i][0];\n int cnt = seg.prod(0, i).v;\n ans += cnt;\n }\n\n writeln(ans);\n }\n}\n\n// Code from: https://github.com/kotet/atcoder-library-d\n\nint celiPow2(int n) @safe pure nothrow @nogc\n{\n int x = 0;\n while ((1u << x) < cast(uint)(n))\n x++;\n return x;\n}\n\n// --- segtree ---\n\nstruct Segtree(S, alias op, alias e)\n{\n import std.functional : binaryFun, unaryFun;\n import std.traits : isCallable, Parameters;\n\n static if (is(typeof(e) : string))\n {\n auto unit()\n {\n return mixin(e);\n }\n }\n else\n {\n alias unit = e;\n }\n\n this(int n)\n {\n auto buf = new S[](n);\n buf[] = unit();\n this(buf);\n }\n\n this(S[] v)\n {\n _n = cast(int) v.length;\n log = celiPow2(_n);\n size = 1 << log;\n d = new S[](2 * size);\n d[] = unit();\n foreach (i; 0 .. _n)\n d[size + i] = v[i];\n foreach_reverse (i; 1 .. size)\n update(i);\n }\n\n void set(int p, S x)\n {\n assert(0 <= p && p < _n);\n p += size;\n d[p] = x;\n foreach (i; 1 .. log + 1)\n update(p >> i);\n }\n\n S get(int p)\n {\n assert(0 <= p && p < _n);\n return d[p + size];\n }\n\n S prod(int l, int r)\n {\n assert(0 <= l && l <= r && r <= _n);\n S sml = unit(), smr = unit();\n l += size;\n r += size;\n while (l < r)\n {\n if (l & 1)\n sml = binaryFun!(op)(sml, d[l++]);\n if (r & 1)\n smr = binaryFun!(op)(d[--r], smr);\n l >>= 1;\n r >>= 1;\n }\n return binaryFun!(op)(sml, smr);\n }\n\n S allProd()\n {\n return d[1];\n }\n\n int maxRight(alias f)(int l)\n {\n return maxRight(l, &unaryFun!(f));\n }\n\n int maxRight(F)(int l, F f) if (isCallable!F && Parameters!(F).length == 1)\n {\n assert(0 <= l && l <= _n);\n assert(f(unit()));\n if (l == _n)\n return _n;\n l += size;\n S sm = unit();\n do\n {\n while (l % 2 == 0)\n l >>= 1;\n if (!f(binaryFun!(op)(sm, d[l])))\n {\n while (l < size)\n {\n l = 2 * l;\n if (f(binaryFun!(op)(sm, d[l])))\n {\n sm = binaryFun!(op)(sm, d[l]);\n l++;\n }\n }\n return l - size;\n }\n sm = binaryFun!(op)(sm, d[l]);\n l++;\n }\n while ((l & -l) != l);\n return _n;\n }\n\n int minLeft(alias f)(int r)\n {\n return minLeft(r, &unaryFun!(f));\n }\n\n int minLeft(F)(int r, F f) if (isCallable!F && Parameters!(F).length == 1)\n {\n assert(0 <= r && r <= _n);\n assert(f(unit()));\n if (r == 0)\n return 0;\n r += size;\n S sm = unit();\n do\n {\n r--;\n while (r > 1 && (r % 2))\n r >>= 1;\n if (!f(binaryFun!(op)(d[r], sm)))\n {\n while (r < size)\n {\n r = 2 * r + 1;\n if (f(binaryFun!(op)(d[r], sm)))\n {\n sm = binaryFun!(op)(d[r], sm);\n r--;\n }\n }\n return r + 1 - size;\n }\n sm = binaryFun!(op)(d[r], sm);\n }\n while ((r & -r) != r);\n return 0;\n }\n\nprivate:\n int _n = 0, size = 1, log = 0;\n S[] d = [unit(), unit()];\n void update(int k)\n {\n d[k] = binaryFun!(op)(d[2 * k], d[2 * k + 1]);\n }\n}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = iota (n * m).map !(i => tuple (a[i], i)).array;\r\n\t\tb.schwartzSort !(c => tuple (c[0], -c[1]));\r\n\t\tdebug {writeln (b);}\r\n\r\n\t\tlong res = 0;\r\n\t\tauto vis = new bool [] [] (n, m);\r\n\t\tforeach (ref c; b)\r\n\t\t{\r\n\t\t\tauto row = c[1] / m;\r\n\t\t\tauto col = c[1] % m;\r\n\t\t\tforeach (d; 0..col)\r\n\t\t\t{\r\n\t\t\t\tres += vis[row][d];\r\n\t\t\t}\r\n\t\t\tvis[row][col] = true;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "5b95da35a4c1251f5376cf3bacc1a549"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto ans = zip(StoppingPolicy.longest, arr, arr.dropOne).filter!(t => t[1] == 1 || t[1] == 0).map!(t => t[0]).array; \n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\n}", "positive_code": [{"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint[] m = new int[a];\n\tfor (int i=0; i<a; i++)\n\t{\n\t\treadf(\" %d\", &m[i]);\n\t}\n\tint count=0;\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tif (m[i]==1)\n\t\t{\n\t\t\tcount=count+1;\n\t\t}\n\t}\n\twriteln(count);\n\tfor (int i=1; i<a; i++)\n\t{\n\t\tif (m[i]==1)\n\t\t{\n\t\t\twriteln(m[i-1]);\n\t\t}\n\t}\n\twriteln(m[a-1]);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "0ee86e75ff7a47a711c9eb41b34ad1a5"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nconst int INF = 10^^9 + 300;\ntup[][] adj;\nint[][] dis;\n\nvoid djkes(int v){\n int cur;\n auto cask = rbt!tup;\n cask.insert(tup(0, v));\n dis[v][v] = 0;\n\n while(cask.length){\n cur = cask.front[1];\n cask.removeFront;\n foreach(ed; adj[cur]){\n int u = ed[0].to!int, w = ed[1].to!int;\n /* writeln(u, \" \", w); */\n if(dis[v][u] > dis[v][cur] + w){\n cask.removeKey(tup(dis[v][u], u));\n dis[v][u] = dis[v][cur] + w;\n cask.insert(tup(dis[v][u], u));\n }\n }\n }\n}\n\nvoid play(){\n int n = rd!int, m = rd!int, k = rd!int;\n dis = new int[][](n+1, n+1);\n adj = new tup[][](n+1);\n tup[] routes, roads;\n int x, y, w;\n foreach(i; 0..m){\n x = rd!int;\n y = rd!int;\n w = rd!int;\n roads ~= tup(x, y);\n adj[x] ~= tup(y, w);\n adj[y] ~= tup(x, w);\n }\n foreach(i; 1..n+1){\n dis[i].fill(INF);\n djkes(i);\n }\n /* writeln(dis); */\n foreach(i; 0..k){\n routes ~= tup(rd!int, rd!int);\n }\n ll mindist = INF;\n foreach(i; 0..m){\n int st = roads[i][0];\n int end = roads[i][1];\n ll totdist = 0;\n foreach(j; 0..k){\n int rst = routes[j][0];\n int rend = routes[j][1];\n ll dist = dis[rst][rend];\n dist = min(dist, dis[rst][st] + dis[rend][end]);\n dist = min(dist, dis[rst][end] + dis[rend][st]);\n /* writeln(j, \" \", dist); */\n totdist += dist;\n }\n mindist = min(totdist, mindist);\n }\n writeln(mindist);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ a.each!(w => write(w, \"| \")); writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(int, int);\nalias trip = Tuple!(int, int, int);\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int infinity = int.max / 2;\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (readf !(\" %s %s %s\") (n, m, k) > 0)\n\t{\n\t\talias Edge = Tuple !(int, q{u}, int, q{v}, int, q{w});\n\t\tauto adj = new int [] [n];\n\t\tauto edges = new Edge [m];\n\t\tforeach (int j, ref e; edges)\n\t\t{\n\t\t\treadf !(\" %s %s %s\") (e.u, e.v, e.w);\n\t\t\te.u -= 1;\n\t\t\te.v -= 1;\n\t\t\tadj[e.u] ~= j;\n\t\t\tadj[e.v] ~= j;\n\t\t}\n\t\tauto x = new int [k];\n\t\tauto y = new int [k];\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\treadf !(\" %s %s\") (x[i], y[i]);\n\t\t}\n\t\tx[] -= 1;\n\t\ty[] -= 1;\n\n\t\tint [] [] dist;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = new int [n];\n\t\t\td[] = infinity;\n\t\t\td[i] = 0;\n\t\t\talias Record = Tuple !(int, q{d}, int, q{v});\n\t\t\tauto t = redBlackTree !(Record);\n\t\t\tt.insert (Record (d[i], i));\n\t\t\twhile (!t.empty)\n\t\t\t{\n\t\t\t\tauto v = t.front.v;\n\t\t\t\tt.removeFront ();\n\t\t\t\tforeach (j; adj[v])\n\t\t\t\t{\n\t\t\t\t\tauto e = edges[j];\n\t\t\t\t\tauto u = e.u ^ e.v ^ v;\n\t\t\t\t\tif (d[u] > d[v] + e.w)\n\t\t\t\t\t{\n\t\t\t\t\t\tt.removeKey (Record (d[u], u));\n\t\t\t\t\t\td[u] = d[v] + e.w;\n\t\t\t\t\t\tt.insert (Record (d[u], u));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdist ~= d;\n\t\t}\n\n\t\tint res = infinity;\n\t\tforeach (e; edges)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..k)\n\t\t\t{\n\t\t\t\tauto temp = dist[x[i]][y[i]];\n\t\t\t\ttemp = min (temp,\n\t\t\t\t dist[x[i]][e.u] + dist[y[i]][e.v]);\n\t\t\t\ttemp = min (temp,\n\t\t\t\t dist[x[i]][e.v] + dist[y[i]][e.u]);\n\t\t\t\tcur += temp;\n\t\t\t}\n\t\t\tres = min (res, cur);\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nconst int INF = 10^^8;\ntup[][] adj;\nint[][] dis;\n\nvoid djkes(int v){\n int cur;\n auto cask = rbt!tup;\n cask.insert(tup(0, v));\n dis[v][v] = 0;\n\n while(cask.length){\n cur = cask.front[1];\n cask.removeFront;\n foreach(ed; adj[cur]){\n int u = ed[0].to!int, w = ed[1].to!int;\n /* writeln(u, \" \", w); */\n if(dis[v][u] > dis[v][cur] + w){\n cask.removeKey(tup(dis[v][u], u));\n dis[v][u] = dis[v][cur] + w;\n cask.insert(tup(dis[v][u], u));\n }\n }\n }\n}\n\nvoid play(){\n int n = rd!int, m = rd!int, k = rd!int;\n dis = new int[][](n+1, n+1);\n adj = new tup[][](n+1);\n tup[] routes, roads;\n int x, y, w;\n foreach(i; 0..m){\n x = rd!int;\n y = rd!int;\n w = rd!int;\n roads ~= tup(x, y);\n adj[x] ~= tup(y, w);\n adj[y] ~= tup(x, w);\n }\n foreach(i; 1..n+1){\n dis[i].fill(INF);\n djkes(i);\n }\n /* writeln(dis); */\n foreach(i; 0..k){\n routes ~= tup(rd!int, rd!int);\n }\n ll mindist = INF;\n foreach(i; 0..m){\n int st = roads[i][0];\n int end = roads[i][1];\n ll totdist = 0;\n foreach(j; 0..k){\n int rst = routes[j][0];\n int rend = routes[j][1];\n ll dist = dis[rst][rend];\n dist = min(dist, dis[rst][st] + dis[rend][end]);\n dist = min(dist, dis[rst][end] + dis[rend][st]);\n /* writeln(j, \" \", dist); */\n totdist += dist;\n }\n mindist = min(totdist, mindist);\n }\n writeln(mindist);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ a.each!(w => write(w, \"| \")); writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(int, int);\nalias trip = Tuple!(int, int, int);\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n"}], "src_uid": "6ccb639373ca04646be8866273402c93"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!long).array;\n long totalsum = a.sum;\n writeln(totalsum % n == 0 ? 0 : 1);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto s = a.sum;\r\n\t\twritefln !(\"%d\") (!!(s % n));\r\n\t}\r\n}\r\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n const sumA = A.sum;\n writeln((sumA % N == 0) ? 0 : 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto a = ma(n, readInt!int);\n auto s = a.sum;\n if (s % n == 0) return writeln(0);\n return writeln(1);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\ndouble norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }\r\ndouble dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tauto tot = a.sum;\r\n\t\tans[ti] = tot % n ? 1 : 0;\r\n\t}\r\n\t\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "644ef17fe304b090e0cf33a84ddc546a"} {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto mxle = tuple(-1, -1);\n auto mnr = tuple(10 ^^ 9, 10 ^^ 9);\n Tuple!(int, int)[] segs;\n foreach (_; 0 .. n) {\n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n segs ~= tuple(a, b);\n \n if (a > mxle[0]) mxle[1] = mxle[0], mxle[0] = a;\n else if (a > mxle[1]) mxle[1] = a;\n \n if (b < mnr[0]) mnr[1] = mnr[0], mnr[0] = b;\n else if (b < mnr[1]) mnr[1] = b;\n }\n\n debug { segs.writeln; writeln(mxle, ' ', mnr); }\n \n auto ans = 0; \n foreach (sg; segs) {\n auto x = sg[0], y = sg[1];\n auto cur = (y != mnr[0] ? mnr[0] : mnr[1]) - (x != mxle[0] ? mxle[0] : mxle[1]);\n if (cur < 0) cur = 0;\n ans = max(ans, cur);\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n struct T{int l, r;}\n auto s=new T[](n);\n foreach(i; 0..n) rd(s[i].l, s[i].r);\n\n int mxlen=0;\n s.sort!\"a.l==b.l ? a.r<b.r : a.l>b.l\";\n // writeln(s[0]);\n mxlen=max(mxlen, s[1..$].minElement!(\"a.r\").r-s[1..$].maxElement!(\"a.l\").l);\n s.sort!\"a.r==b.r ? a.l>b.l : a.r<b.r\";\n // writeln(s[0]);\n mxlen=max(mxlen, s[1..$].minElement!(\"a.r\").r-s[1..$].maxElement!(\"a.l\").l);\n writeln(mxlen);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "b50df0e6d91d538cd7db8dfdc7cd5266"} {"source_code": "import std.conv;\nimport std.stdio;\n\nvoid main() {\n int a, b, n;\n \n readf(\"%s %s %s\", &a, &b, &n);\n \n if( a%b != 0 ) {\n --n;\n auto tmp = a * 10;\n bool f;\n for( int i = 0; i < 10; ++i ) {\n if( ( tmp + i ) % b == 0 )\n {\n a = tmp + i;\n f = true;\n break;\n }\n } \n if(!f) {\n writeln(\"-1\");\n return;\n }\n }\n \n string as = to!string(a);\n \n for( int i; i < n; ++i ) {\n bool f;\n /*foreach(x; 1..10) {\n if( x % b == 0 ) {\n as ~= to!string(x);\n f = true;\n break;\n }\n } \n if(!f) {\n i = n;\n as = \"-1\";\n }*/\n as ~= \"0\";\n }\n \n writeln(as);\n \n \n}", "positive_code": [{"source_code": "module cf_260A;\n\nimport std.stdio;\nimport std.conv;\nimport std.algorithm;\n\nvoid main() {\n int a, b, n;\n\n readf(\"%d %d %d\", &a, &b, &n);\n\n int mod = a % b;\n int ops = 0;\n\n string resultNumber = to!string(a);\n for (int i = 0; i < n; ++i) {\n for (int j = min(9, b); j >= 0; --j) {\n if ((mod * 10 + j) % b == 0) {\n resultNumber ~= j + '0';\n mod = 0;\n ++ops;\n break;\n }\n }\n }\n\n writeln(ops == n? resultNumber: \"-1\");\n}"}], "negative_code": [{"source_code": "import std.conv;\nimport std.stdio;\n\nvoid main() {\n int a, b, n;\n \n readf(\"%s %s %s\", &a, &b, &n);\n \n if( a%b != 0 ) {\n --n;\n auto tmp = a * 10;\n bool f;\n for( int i = 1; i < 10; ++i ) {\n if( ( tmp + i ) % b == 0 )\n {\n a = tmp + i;\n f = true;\n break;\n }\n } \n if(!f) {\n writeln(\"-1\");\n return;\n }\n }\n \n string as = to!string(a);\n \n for( int i; i < n; ++i ) {\n bool f;\n /*foreach(x; 1..10) {\n if( x % b == 0 ) {\n as ~= to!string(x);\n f = true;\n break;\n }\n } \n if(!f) {\n i = n;\n as = \"-1\";\n }*/\n as ~= \"0\";\n }\n \n writeln(as);\n \n \n}"}, {"source_code": "import std.conv;\nimport std.stdio;\n\nvoid main() {\n int a, b, n;\n \n readf(\"%s %s %s\", &a, &b, &n);\n \n if( a%b != 0 ) {\n --n;\n auto tmp = a * 10;\n bool f;\n for( int i = 1; i < 10; ++i ) {\n if( ( tmp + i ) % b == 0 )\n {\n a = tmp + i;\n f = true;\n break;\n }\n } \n if(!f) {\n writeln(\"-1\");\n return;\n }\n }\n \n string as = to!string(a);\n \n for( int i; i < n; ++i ) {\n bool f;\n foreach(x; 1..10) {\n if( x % b == 0 ) {\n as ~= to!string(x);\n f = true;\n break;\n }\n } \n if(!f) {\n i = n;\n as = \"-1\";\n }\n }\n \n writeln(as);\n \n \n}"}], "src_uid": "206eb67987088843ef42923b0c3939d4"} {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio, std.array, std.conv, std.string, std.algorithm;\n\nauto gets() { return readln().chomp(); }\nauto getV(T)() { return to!T(readln().chomp()); }\nauto getVals(T)() { return to!(T[])(readln().chomp().split(\" \")); }\n\nauto isOdd(int p) { return p % 2 != 0; }\n\nvoid main() {\n int n = getV!int();\n auto xs = getVals!int();\n auto odds = 0;\n foreach (x ; xs) {\n if (isOdd(x)) {\n odds++;\n }\n }\n if (odds == 0) {\n writeln(\"Second\");\n return;\n }\n writeln(\"First\");\n}\n\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n bool ans;\n if (A.sum % 2 != 0) {\n ans = true;\n } else {\n if (A.any!\"a % 2 != 0\") {\n ans = true;\n } else {\n ans = false;\n }\n }\n writeln(ans ? \"First\" : \"Second\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "808611f86c70659a1d5b8fc67875de31"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport core.stdcpp.allocator;\n\nconst int N = cast(int)2e5 + 10;\n\nint n;\nint [N] lst;\n\nvoid main() { \n int t; \n readf(\" %s\", &t);\n while(t-- > 0) {\n readf(\" %s\", &n);\n for(int i = 0; i < n; ++i) {\n lst[i] = -1;\n }\n int bst = n + 1;\n for(int i = 0; i < n; ++i) {\n int x; \n readf(\" %s\", &x); x--;\n if(lst[x] != -1) bst = min(bst, i - lst[x] + 1);\n lst[x] = i;\n }\n if(bst == n + 1) bst = -1;\n writefln(\"%s\", bst);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport core.stdcpp.allocator;\n\nint n;\nint [int] lst;\n\nvoid main() { \n int t; \n readf(\" %s\", &t);\n while(t-- > 0) {\n readf(\" %s\", &n);\n for(int i = 0; i < n; ++i) {\n lst[i] = -1;\n }\n int bst = n + 1;\n for(int i = 0; i < n; ++i) {\n int x; \n readf(\" %s\", &x); x--;\n if(lst[x] != -1) bst = min(bst, i - lst[x] + 1);\n lst[x] = i;\n }\n if(bst == n + 1) bst = -1;\n writefln(\"%s\", bst);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() { \n int t; \n readf(\" %s\", &t);\n while(t-- > 0) {\n int n;\n readf(\" %s\", &n);\n int [] lst = new int[n];\n for(int i = 0; i < n; ++i) {\n lst[i] = -1;\n }\n int bst = n + 1;\n for(int i = 0; i < n; ++i) {\n int x; \n readf(\" %s\", &x); x--;\n if(lst[x] != -1) bst = min(bst, i - lst[x] + 1);\n lst[x] = i;\n }\n if(bst == n + 1) bst = -1;\n writefln(\"%s\", bst);\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA(-1);\n\t\tauto pos = new size_t[](n);\n\t\tpos[] = -1;\n\t\tans[i] = long.max;\n\t\tforeach (j, e; a)\n\t\t{\n\t\t\tif (pos[e] != -1)\n\t\t\t{\n\t\t\t\tans[i] = min(ans[i], j - pos[e] + 1);\n\t\t\t}\n\t\t\tpos[e] = j;\n\t\t}\n\t\tif (ans[i] == long.max)\n\t\t\tans[i] = -1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "a4be9b3484f3f24014392a1c3ad23f2f"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto q = RD!int;\n\t\tauto a = RDA;\n\n\t\tauto dp = new long[][](n+1, 2);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tdp[i+1][0].chmax(dp[i][0]);\n\t\t\tdp[i+1][1].chmax(dp[i][1]);\n\t\t\tdp[i+1][0].chmax(dp[i][1] - a[i]);\n\t\t\tdp[i+1][1].chmax(dp[i][0] + a[i]);\n\t\t}\n\t\tans[ti] = max(dp[n][0], dp[n][1]);\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nvoid play(){\n int n, q;\n n = rd!int;\n q = rd!int;\n ll[] arr = rdarr;\n if(n == 1){ writeln(arr[0]); return;}\n ll[] res;\n bool side = (arr[1] > arr[0]), nside;\n if(!side){ res ~= arr[0]; }\n foreach(i; 1..n){\n if(arr[i] > arr[i-1]){\n nside = 1;\n }else{\n nside = 0;\n }\n if(nside != side){\n res ~= arr[i-1];\n side = nside;\n }\n }\n if(side){ res ~= arr[n-1]; }\n /* writeln(res); */\n ll pow = 0;\n foreach(i; 0..res.length){\n if(i % 2 == 0){\n pow += res[i];\n }else if(i != res.length-1){\n pow -= res[i];\n }\n }\n writeln(pow);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\n\nvoid get(Args...)(ref Args args)\n{\n import std.traits, std.meta, std.typecons;\n\n static if (Args.length == 1) {\n alias Arg = Args[0];\n \n static if (isArray!Arg) {\n args[0] = readln.split.to!Arg;\n } else static if (isTuple!Arg) {\n auto input = readln.split;\n static foreach (i; 0..Fields!Arg.length) {\n args[0][i] = input[i].to!(Fields!Arg[i]);\n }\n } else {\n args[0] = readln.chomp.to!Arg;\n }\n } else {\n auto input = readln.split;\n assert(input.length == Args.length);\n\n static foreach (i; 0..Args.length) {\n args[i] = input[i].to!(Args[i]);\n }\n }\n}\n\nvoid get_lines(Args...)(size_t N, ref Args args)\n{\n import std.traits, std.range;\n\n static foreach (i; 0..Args.length) {\n static assert(isArray!(Args[i]));\n args[i].length = N;\n }\n\n foreach (i; 0..N) {\n static if (Args.length == 1) {\n get(args[0][i]);\n } else {\n auto input = readln.split;\n static foreach (j; 0..Args.length) {\n args[j][i] = input[j].to!(ElementType!(Args[j]));\n }\n }\n }\n}\n\nvoid solve()\n{\n int N, Q; get(N, Q);\n long[] AS; get(AS);\n int p;\n foreach (i, a; AS) if (a == N) {\n p = i.to!int;\n break;\n }\n long sum_a = N;\n long min_a, max_a;\n void update(long a) {\n if (min_a == -1) {\n if (a < max_a) {\n sum_a += max_a;\n max_a = -1;\n min_a = a;\n } else {\n max_a = a;\n }\n } else {\n if (a > min_a) {\n sum_a -= min_a;\n min_a = -1;\n max_a = a;\n } else {\n min_a = a;\n }\n }\n }\n if (p < N-1) {\n max_a = -1; min_a = AS[p+1];\n foreach (i; p+2..N) update(AS[i]);\n if (max_a != -1) sum_a += max_a;\n }\n if (p > 0) {\n max_a = -1; min_a = AS[p-1];\n foreach_reverse (i; 0..p-1) update(AS[i]);\n if (max_a != -1) sum_a += max_a;\n }\n writeln(sum_a);\n}\n\nvoid main()\n{\n int T; get(T);\n foreach (_; 0..T) solve();\n}"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, q;\n\t\treadf !(\" %s %s\") (n, q);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong total = 0;\n\n\t\tvoid mark (int i, int delta)\n\t\t{\n\t\t\tif (i < 0 || i >= n)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ((i == 0 || a[i] > a[i - 1]) &&\n\t\t\t (i == n - 1 || a[i] > a[i + 1]))\n\t\t\t{\n\t\t\t\ttotal += a[i] * delta;\n\t\t\t}\n\t\t\tif ((i > 0 && a[i] < a[i - 1]) &&\n\t\t\t (i < n - 1 && a[i] < a[i + 1]))\n\t\t\t{\n\t\t\t\ttotal -= a[i] * delta;\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tmark (i, +1);\n\t\t}\n\t\twriteln (total);\n\t\tforeach (s; 0..q)\n\t\t{\n\t\t\tint l, r;\n\t\t\treadf !(\" %s %s\") (l, r);\n\t\t\treadln;\n\t\t\tl -= 1;\n\t\t\tr -= 1;\n\t\t\tauto p = chain (iota (l - 1, l + 2),\n\t\t\t iota (max (l + 2, r - 1), r + 2)).array;\n\t\t\tforeach (i; p)\n\t\t\t{\n\t\t\t\tmark (i, -1);\n\t\t\t}\n\t\t\tswap (a[l], a[r]);\n\t\t\tforeach (i; p)\n\t\t\t{\n\t\t\t\tmark (i, +1);\n\t\t\t}\n\t\t\twriteln (total);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto q = next!int;\n auto a = new int[](n); foreach(ref ai; a) ai = next!int;\n assert(q == 0);\n long maxval = a[0], minval = a[0];\n long globalmax = a[0];\n foreach(ai; a[1 ..$])\n\t{\n\t long localmax = ai;\n\t if (minval < 0) localmax -= minval;\n\t long localmin = ai;\n\t if (maxval > 0) localmin -= maxval;\n\t maxval = max(localmax, maxval);\n\t minval = min(localmin, minval);\n\t}\n maxval.writeln;\n }\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nchar frontChar;\nvoid popChar()\n{\n import core.stdc.stdio;\n frontChar = cast(char) getchar;\n if (feof(stdin)) frontChar = ' ';\n}\nauto next(T)()\n{\n static if (is(T == int) || is(T == long) || is(T == short))\n {\n import std.ascii: isDigit;\n T res;\n while(!frontChar.isDigit)\n\tpopChar;\n while(frontChar.isDigit)\n\t{\n\t res *= 10;\n\t res += frontChar - '0';\n\t popChar;\n\t}\n return res;\n }\n else static if (is(T == string))\n {\n import std.ascii: isWhite;\n string res;\n while(frontChar.isWhite)\n\tpopChar;\n while(!frontChar.isWhite)\n\t{\n\t res ~= frontChar;\n\t popChar;\n\t}\n return res;\n }\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto q = next!int;\n auto a = next!int(n);\n assert(q == 0);\n long maxval = a[0], minval = a[0];\n long globalmax = a[0];\n foreach(ai; a[1 ..$])\n\t{\n\t long localmax = ai;\n\t if (minval < 0) localmax -= minval;\n\t long localmin = ai;\n\t if (maxval > 0) localmin -= maxval;\n\t maxval = max(localmax, maxval);\n\t minval = min(localmin, minval);\n\t}\n maxval.writeln;\n }\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\n\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\n/*******************************It's a Me, Mario!*******************************************/\n\nvoid play(){\n int n, q;\n n = rd!int;\n q = rd!int;\n ll[] arr = rdarr;\n if(n == 1){ writeln(arr[0]); return;}\n ll[] res;\n bool side = (arr[1] > arr[0]), nside;\n foreach(i; 1..n){\n if(arr[i] > arr[i-1]){\n nside = 1;\n }else{\n nside = 0;\n }\n if(nside != side){\n res ~= arr[i-1];\n side = nside;\n }\n }\n if(side){ res ~= arr[n-1]; }\n /* writeln(res); */\n ll pow = 0;\n foreach(i; 0..res.length){\n if(i % 2 == 0){\n pow += res[i];\n }else if(i != res.length-1){\n pow -= res[i];\n }\n }\n writeln(pow);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto q = RD!int;\n\t\tauto a = RDA;\n\n\t\tlong[] b = [a[0]];\n\t\tforeach (i; 1..n-1)\n\t\t{\n\t\t\tif (a[i] < a[i-1] && a[i] < a[i+1])\n\t\t\t\tb ~= a[i];\n\t\t\telse if (a[i] > a[i-1] && a[i] > a[i+1])\n\t\t\t\tb ~= a[i];\n\t\t}\n\t\tb ~= a[n-1];\n\n\t\tint j = -1;\n\t\tforeach (i; 1..b.length)\n\t\t{\n\t\t\tif (b[i] > b[i-1])\n\t\t\t{\n\t\t\t\tans[ti] += b[i];\n\t\t\t\tj = cast(int)i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (j == -1)\n\t\t\tans[ti] = b[0];\n\t\telse\n\t\t{\n\t\t\tforeach (i; j+2..b.length)\n\t\t\t{\n\t\t\t\tif (b[i] > b[i-1])\n\t\t\t\t{\n\t\t\t\t\tans[ti] += b[i] - b[i-1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto q = RD!int;\n\t\tauto a = RDA;\n\n\t\tlong[] b = [a[0]];\n\t\tforeach (i; 1..n-1)\n\t\t{\n\t\t\tif (a[i] <= a[i-1] && a[i] <= a[i+1])\n\t\t\t\tb ~= a[i];\n\t\t\telse if (a[i] >= a[i-1] && a[i] >= a[i+1])\n\t\t\t\tb ~= a[i];\n\t\t}\n\t\tb ~= a[n-1];\n\n\t\tif (b.length >= 2)\n\t\t{\n\t\t\tif (b[0] >= b[1])\n\t\t\t\tans[ti] += b[0];\n\t\t}\n\t\tint j = -1;\n\t\tforeach (i; 1..b.length)\n\t\t{\n\t\t\tif (b[i] > b[i-1])\n\t\t\t{\n\t\t\t\tans[ti] += b[i];\n\t\t\t\tj = cast(int)i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (j == -1)\n\t\t\tans[ti] = b[0];\n\t\telse\n\t\t{\n\t\t\tforeach (i; j+2..b.length)\n\t\t\t{\n\t\t\t\tif (b[i] > b[i-1])\n\t\t\t\t{\n\t\t\t\t\tans[ti] += b[i] - b[i-1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "2d088e622863ab0d966862ec29588db1"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 10 ^^ 9 + 7;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto adj = new int [] [n];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf !(\" %s %s\") (u, v);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\tadj[u] ~= v;\n\t\t\tadj[v] ~= u;\n\t\t}\n\t\treadln;\n\t\tauto m = readln.strip.to !(int);\n\t\tauto q = readln.splitter.map !(to !(int)).array;\n\n\t\tsort (q);\n\t\twhile (q.length > n - 1)\n\t\t{\n\t\t\tq[$ - 2] = (q[$ - 2] * 1L * q[$ - 1]) % mod;\n\t\t\tq.length -= 1;\n\t\t}\n\t\treverse (q);\n\t\twhile (q.length < n - 1)\n\t\t{\n\t\t\tq ~= 1;\n\t\t}\n\n\t\tauto d = new int [n];\n\t\tlong [] nums;\n\n\t\tvoid recur (int v, int p)\n\t\t{\n\t\t\td[v] = 1;\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tif (u != p)\n\t\t\t\t{\n\t\t\t\t\trecur (u, v);\n\t\t\t\t\tnums ~= d[u] * 1L * (n - d[u]);\n\t\t\t\t\td[v] += d[u];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0, -1);\n\t\tsort (nums);\n\t\treverse (nums);\n\t\tnums[] %= mod;\n\n\t\tint res = 0;\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tres = (res + nums[i] * q[i]) % mod;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto u = RD!int-1;\n\t\t\tauto v = RD!int-1;\n\t\t\tedges[u] ~= v;\n\t\t\tedges[v] ~= u;\n\t\t}\n\t\tauto m = RD!int;\n\t\tauto p = RDA;\n\t\tp.sort!\"a > b\"();\n\t\twhile (p.length > n-1)\n\t\t{\n\t\t\tp[1].modm(p[0]);\n\t\t\tp.popFront;\n\t\t}\n\n\t\tlong[] list;\n\t\tlong dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tcnt += dfs(v, pos);\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tauto x = cnt;\n\t\t\tx *= (n-cnt);\n\t\t\tlist ~= x;\n\t\t\treturn cnt;\n\t\t}\n\t\tdfs(0, -1);\n\t\tlist.sort!\"a > b\"();\n\t\tdebug writeln(list);\n\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tlong pp = 1;\n\t\t\tif (!p.empty)\n\t\t\t{\n\t\t\t\tpp = p.front; p.popFront;\n\t\t\t}\n\t\t\tpp.modm(list[i]);\n\t\t\tans[ti].moda(pp);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto u = RD!int-1;\n\t\t\tauto v = RD!int-1;\n\t\t\tedges[u] ~= v;\n\t\t\tedges[v] ~= u;\n\t\t}\n\t\tauto m = RD!int;\n\t\tauto p = RDA;\n\t\tp.sort!\"a > b\"();\n\n\t\tlong[] list;\n\t\tint dfs(int pos, int last)\n\t\t{\n\t\t\tint cnt;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tcnt += dfs(v, pos);\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tlist ~= cnt * (n-cnt);\n\t\t\treturn cnt;\n\t\t}\n\t\tdfs(0, -1);\n\t\tlist.sort!\"a > b\"();\n\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tlong pp = 1;\n\t\t\tif (!p.empty)\n\t\t\t{\n\t\t\t\tpp = p.front; p.popFront;\n\t\t\t}\n\t\t\tpp *= list[i];\n\t\t\tans[ti].moda(pp);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto u = RD!int-1;\n\t\t\tauto v = RD!int-1;\n\t\t\tedges[u] ~= v;\n\t\t\tedges[v] ~= u;\n\t\t}\n\t\tauto m = RD!int;\n\t\tauto p = RDA;\n\t\tp.sort!\"a > b\"();\n\n\t\tlong[] list;\n\t\tlong dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tcnt += dfs(v, pos);\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tlist ~= cnt * (n-cnt);\n\t\t\treturn cnt;\n\t\t}\n\t\tdfs(0, -1);\n\t\tlist.sort!\"a > b\"();\n\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tlong pp = 1;\n\t\t\tif (!p.empty)\n\t\t\t{\n\t\t\t\tpp = p.front; p.popFront;\n\t\t\t}\n\t\t\tpp *= list[i];\n\t\t\tans[ti].moda(pp);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto u = RD!int-1;\n\t\t\tauto v = RD!int-1;\n\t\t\tedges[u] ~= v;\n\t\t\tedges[v] ~= u;\n\t\t}\n\t\tauto m = RD!int;\n\t\tauto p = RDA;\n\t\tp.sort!\"a > b\"();\n\t\twhile (p.length > n-1)\n\t\t{\n\t\t\tp[1].modm(p[0]);\n\t\t\tp.popFront;\n\t\t}\n\n\t\tlong[] list;\n\t\tlong dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tcnt += dfs(v, pos);\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tauto x = cnt;\n\t\t\tx.modm(n-cnt);\n\t\t\tlist ~= x;\n\t\t\treturn cnt;\n\t\t}\n\t\tdfs(0, -1);\n\t\tlist.sort!\"a > b\"();\n\t\tdebug writeln(list);\n\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tlong pp = 1;\n\t\t\tif (!p.empty)\n\t\t\t{\n\t\t\t\tpp = p.front; p.popFront;\n\t\t\t}\n\t\t\tpp.modm(list[i]);\n\t\t\tans[ti].moda(pp);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto u = RD!int-1;\n\t\t\tauto v = RD!int-1;\n\t\t\tedges[u] ~= v;\n\t\t\tedges[v] ~= u;\n\t\t}\n\t\tauto m = RD!int;\n\t\tauto p = RDA;\n\t\tp.sort!\"a > b\";\n\n\t\tlong[] list;\n\t\tint dfs(int pos, int last)\n\t\t{\n\t\t\tint cnt;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tcnt += dfs(v, pos);\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tlist ~= cnt * (n-cnt);\n\t\t\treturn cnt;\n\t\t}\n\t\tdfs(0, -1);\n\t\tlist.sort!\"a > b\"();\n\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tlong pp = 1;\n\t\t\tif (!p.empty)\n\t\t\t{\n\t\t\t\tpp = p.front; p.popFront;\n\t\t\t}\n\t\t\tpp.modm(list[i]);\n\t\t\tans[ti].moda(pp);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto u = RD!int-1;\n\t\t\tauto v = RD!int-1;\n\t\t\tedges[u] ~= v;\n\t\t\tedges[v] ~= u;\n\t\t}\n\t\tauto m = RD!int;\n\t\tauto p = RDA;\n\t\tp.sort!\"a > b\"();\n\n\t\tlong[] list;\n\t\tlong dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tcnt += dfs(v, pos);\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tlist ~= cnt * (n-cnt);\n\t\t\treturn cnt;\n\t\t}\n\t\tdfs(0, -1);\n\t\tlist.sort!\"a > b\"();\n\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tlong pp = 1;\n\t\t\tif (!p.empty)\n\t\t\t{\n\t\t\t\tpp = p.front; p.popFront;\n\t\t\t}\n\t\t\tpp.modm(list[i]);\n\t\t\tans[ti].moda(pp);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto edges = new int[][](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tauto u = RD!int-1;\n\t\t\tauto v = RD!int-1;\n\t\t\tedges[u] ~= v;\n\t\t\tedges[v] ~= u;\n\t\t}\n\t\tauto m = RD!int;\n\t\tauto p = RDA;\n\t\tp.sort!\"a > b\"();\n\n\t\tlong[] list;\n\t\tlong dfs(int pos, int last)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tcnt += dfs(v, pos);\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tauto x = cnt;\n\t\t\tx.modm(n-cnt);\n\t\t\tlist ~= x;\n\t\t\treturn cnt;\n\t\t}\n\t\tdfs(0, -1);\n\t\tlist.sort!\"a > b\"();\n\t\tdebug writeln(list);\n\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tlong pp = 1;\n\t\t\tif (!p.empty)\n\t\t\t{\n\t\t\t\tpp = p.front; p.popFront;\n\t\t\t}\n\t\t\tpp.modm(list[i]);\n\t\t\tans[ti].moda(pp);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "968b3db21bd16bc04bdb355e98079d5d"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\ndouble[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto k = RD!int;\r\n\t\tauto a = RDA;\r\n\t\t\r\n\t\tauto index = a.MAKE_IDX;\r\n\t\tforeach (ii, i; index)\r\n\t\t{\r\n\t\t\ta[i] = ii;\r\n\t\t}\r\n\r\n\t\tlong cnt;\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tif (a[i]+1 != a[i+1])\r\n\t\t\t\t++cnt;\r\n\t\t}\r\n\t\tans[ti] = cnt < k;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"Yes\" : \"No\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "positive_code": [{"source_code": "\nimmutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto k = readInt!int;\n\tauto a = ma(n, readInt!int);\n\tauto oa = a.dup;\n\tint[int] rnk;\n\tsort(a);\n\tforeach(i, ai; a) rnk[ai] = cast(int)i;\n\toa = oa.map!(ai => rnk[ai]).array;\n\tint chunks = 0;\n\tint i = 0;\n\twhile (i < n)\n\t{\n\t\tchunks++;\n\t\twhile (i + 1 < n && oa[i + 1] == oa[i] + 1) i++;\n\t\ti++;\n\t}\n\tif (chunks <= k) writeln(\"YES\"); else writeln(\"NO\");\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t) solve(tc);\n}\n// }}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}], "negative_code": [], "src_uid": "255d6fca1379ae40b03e761802f36664"} {"source_code": "import std.numeric, std.stdio;\nimmutable H = 1 << 19, T = H * 2;\nint [T] t;\nint n, q, u, v, w, z;\nvoid set (int p, int v) {\n\tfor (t[p] = v, p >>= 1; p; p >>= 1) t[p] = gcd (t[p * 2], t[p * 2 + 1]);\n}\nint ver (int p, int v) {\n\twhile (p < H) {\n\t\tint x = t[p * 2] % v, y = t[p * 2 + 1] % v;\n\t\tif (x && y) return 2;\n\t\tp = p * 2 + !x;\n\t}\n\treturn 1;\n}\nint ask (int lo, int hi, int v) {\n\tfor (int f; lo < hi; lo >>= 1, hi >>= 1) {\n\t\tif (lo & 1) f += (t[lo] % v) ? ver (lo, v) : 0, lo += 1;\n\t\tif (hi & 1) hi -= 1, f += (t[hi] % v) ? ver (hi, v) : 0;\n\t\tif (f > 1) return 0;\n\t}\n\treturn 1;\n}\nvoid main () {\n\treadf (\" %s\", &n);\n\tforeach (i; 0..n) readf (\" %s\", &t[i + H]);\n\tforeach_reverse (i; 1..H) t[i] = gcd (t[i * 2], t[i * 2 + 1]);\n\treadf (\" %s\", &q);\n\tforeach (r; 0..q) {\n\t\treadf (\" %s %s %s\", &z, &u, &v);\n\t\tif (z < 2) readf (\" %s\", &w), writeln (ask (u - 1 + H, v + H, w) ? \"YES\" : \"NO\");\n\t\telse set (u - 1 + H, v);\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n// T: monoid\n// op: T * T -> T\n// query(a, b): returns t_a ... t_{b-1}\nclass SegmentTree(T, alias op) {\n import std.functional : binaryFun;\n alias opFun = binaryFun!op;\n const(T) idT;\n\n int n;\n T[] ts;\n this(int n_, const(T) idT) {\n this.idT = idT;\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[] = idT;\n }\n this(inout(T)[] ts_, const(T) idT) {\n this.idT = idT;\n const n_ = cast(int)(ts_.length);\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[0 .. n] = idT;\n ts[n .. n + n_] = ts_[];\n ts[n + n_ .. n << 1] = idT;\n build();\n }\n ref T at(int a) {\n return ts[n + a];\n }\n void build() {\n foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void set(int a, const(T) val) {\n ts[a += n] = val;\n for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void mulL(int a, const(T) val) {\n set(a, opFun(val, ts[a + n]));\n }\n void mulR(int a, const(T) val) {\n set(a, opFun(ts[a + n], val));\n }\n T query(int a, int b) const {\n T prodL = idT, prodR = idT;\n for (a += n, b += n; a < b; a >>= 1, b >>= 1) {\n if (a & 1) prodL = opFun(prodL, ts[a++]);\n if (b & 1) prodR = opFun(ts[--b], prodR);\n }\n return opFun(prodL, prodR);\n }\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto seg = new SegmentTree!(int, gcd)(A, 0);\n bool solve(int l, int r, int x) {\n for (; ; ) {\n debug {\n // writeln(l, \" \", r, \" \", x);\n }\n if (r - l <= 1) {\n return true;\n }\n const mid = (l + r) / 2;\n debug {\n writefln(\"l = %s, r = %s, x = %s\", l, r, x);\n writeln(\"seg.query(l, mid) = \", seg.query(l, mid));\n writeln(\"seg.query(mid, r) = \", seg.query(mid, r));\n }\n if (seg.query(l, mid) % x == 0) {\n l = mid;\n } else if (seg.query(mid, r) % x == 0) {\n r = mid;\n } else {\n return false;\n }\n }\n }\n \n debug {\n auto as = A.dup;\n }\n \n const Q = readInt();\n foreach (q; 0 .. Q) {\n const typ = readInt();\n switch (typ) {\n case 1: {\n const l = readInt() - 1;\n const r = readInt();\n const x = readInt();\n const ans = solve(l, r, x);\n writeln(ans ? \"YES\" : \"NO\");\n debug {\n const brt = (as[l .. r].count!(a => (a % x != 0)) <= 1);\n assert(brt == ans, format(\"%s %s %s %s; brt = %s, ans = %s\", as, l, r, x, brt, ans));\n }\n } break;\n case 2: {\n const i = readInt() - 1;\n const y = readInt();\n seg.set(i, y);\n debug {\n as[i] = y;\n }\n } break;\n default: assert(false);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.algorithm, std.array, std.conv, std.numeric, std.stdio, std.string;\nimmutable int logHalf = 19, half = 1 << logHalf, limit = half << 1;\nvoid main () {\n\tint n = readln.strip.to!int;\n\tauto a = readln.splitter.map !(to!int).array;\n\tauto t = new int [limit];\n\tforeach (i, c; a) t[i + half] = c;\n\tforeach_reverse (i; 1..half) t[i] = gcd (t[i * 2 + 0], t[i * 2 + 1]);\n\n\tvoid change (int pos, int v) {\n\t\tfor (pos += half, t[pos] = v, pos >>= 1; pos; pos >>= 1)\n\t\t\tt[pos] = gcd (t[pos * 2 + 0], t[pos * 2 + 1]);\n\t}\n\n\tbool checkVertex (int pos, int v) {\n\t\twhile (pos < half) {\n\t\t\tbool x = (t[pos * 2 + 0] % v != 0);\n\t\t\tbool y = (t[pos * 2 + 1] % v != 0);\n\t\t\tif (x && y) return false;\n\t\t\tpos = pos * 2 + y;\n\t\t}\n\t\treturn true;\n\t}\n\n\tbool checkSegment (int lo, int hi, int v) {\n\t\tbool found = false;\n\t\tfor (lo += half, hi += half; lo < hi; lo >>= 1, hi >>= 1) {\n\t\t\tif (lo & 1) {\n\t\t\t\tif (t[lo] % v != 0) {\n\t\t\t\t\tif (found || !checkVertex (lo, v)) return false;\n\t\t\t\t\tfound = true;\n\t\t\t\t}\n\t\t\t\tlo += 1;\n\t\t\t}\n\t\t\tif (hi & 1) {\n\t\t\t\thi -= 1;\n\t\t\t\tif (t[hi] % v != 0) {\n\t\t\t\t\tif (found || !checkVertex (hi, v)) return false;\n\t\t\t\t\tfound = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tint q = readln.strip.to!int;\n\tforeach (r; 0..q) {\n\t\tauto s = readln.splitter.map !(to!int).array;\n\t\tif (s[0] == 1) writeln (checkSegment (s[1] - 1, s[2] - 0, s[3]) ? \"YES\" : \"NO\");\n\t\telse change (s[1] - 1, s[2]);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.conv, std.numeric, std.stdio, std.string;\nimmutable H = 1 << 19, T = H * 2;\nint [T] t;\nvoid main () {\n\tint n, q, u, v, w, z;\n\treadf (\" %s\", &n);\n\tforeach (i; 0..n) readf (\" %s\", &t[i + H]);\n\tforeach_reverse (i; 1..H) t[i] = gcd (t[i * 2], t[i * 2 + 1]);\n\n\tvoid set (int p, int v) {\n\t\tfor (t[p] = v, p >>= 1; p; p >>= 1)\n\t\t\tt[p] = gcd (t[p * 2], t[p * 2 + 1]);\n\t}\n\n\tint ver (int p, int v) {\n\t\twhile (p < H) {\n\t\t\tint x = t[p * 2] % v, y = t[p * 2 + 1] % v;\n\t\t\tif (x && y) return 0;\n\t\t\tp = p * 2 + !x;\n\t\t}\n\t\treturn 1;\n\t}\n\n\tint ask (int lo, int hi, int v) {\n\t\tfor (int f; lo < hi; lo >>= 1, hi >>= 1) {\n\t\t\tif (lo & 1) {\n\t\t\t\tif (t[lo] % v) {\n\t\t\t\t\tif (f || !ver (lo, v)) return 0;\n\t\t\t\t\tf = 1;\n\t\t\t\t}\n\t\t\t\tlo += 1;\n\t\t\t}\n\t\t\tif (hi & 1) {\n\t\t\t\thi -= 1;\n\t\t\t\tif (t[hi] % v) {\n\t\t\t\t\tif (f || !ver (hi, v)) return 0;\n\t\t\t\t\tf = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 1;\n\t}\n\n\treadf (\" %s\", &q);\n\tforeach (r; 0..q) {\n\t\treadf (\" %s %s %s\", &z, &u, &v);\n\t\tif (z < 2) {\n\t\t\treadf (\" %s\", &w);\n\t\t\twriteln (ask (u - 1 + H, v + H, w) ? \"YES\" : \"NO\");\n\t\t} else set (u - 1 + H, v);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int logHalf = 19;\nimmutable int half = 1 << logHalf;\nimmutable int limit = half << 1;\n\nint gcd (int a, int b)\n{\n\twhile (a && b)\n\t{\n\t\ta %= b;\n\t\tif (a)\n\t\t{\n\t\t\tb %= a;\n\t\t}\n\t}\n\treturn a + b;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto t = new int [limit];\n\t\tforeach (i, c; a)\n\t\t{\n\t\t\tt[i + half] = c;\n\t\t}\n\t\tforeach_reverse (i; 1..half)\n\t\t{\n\t\t\tt[i] = gcd (t[i * 2 + 0], t[i * 2 + 1]);\n\t\t}\n\n\t\tvoid change (int pos, int v)\n\t\t{\n\t\t\tpos += half;\n\t\t\tt[pos] = v;\n\t\t\tfor (pos >>= 1; pos; pos >>= 1)\n\t\t\t{\n\t\t\t\tt[pos] = gcd (t[pos * 2 + 0], t[pos * 2 + 1]);\n\t\t\t}\n\t\t}\n\n\t\tbool checkVertex (int pos, int v)\n\t\t{\n\t\t\twhile (pos < half)\n\t\t\t{\n\t\t\t\tbool x = (t[pos * 2 + 0] % v != 0);\n\t\t\t\tbool y = (t[pos * 2 + 1] % v != 0);\n\t\t\t\tif (x && y)\n\t\t\t\t{\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tpos = pos * 2 + y;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tbool checkSegment (int lo, int hi, int v)\n\t\t{\n\t\t\tbool found = false;\n\t\t\tfor (lo += half, hi += half; lo < hi;\n\t\t\t lo >>= 1, hi >>= 1)\n\t\t\t{\n\t\t\t\tif (lo & 1)\n\t\t\t\t{\n\t\t\t\t\tif (t[lo] % v != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (found ||\n\t\t\t\t\t\t !checkVertex (lo, v))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t}\n\t\t\t\t\tlo += 1;\n\t\t\t\t}\n\t\t\t\tif (hi & 1)\n\t\t\t\t{\n\t\t\t\t\thi -= 1;\n\t\t\t\t\tif (t[hi] % v != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (found ||\n\t\t\t\t\t\t !checkVertex (hi, v))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tauto q = readln.strip.to !(int);\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tauto s = readln.splitter.map !(to !(int)).array;\n\t\t\tif (s[0] == 1)\n\t\t\t{\n\t\t\t\twriteln (checkSegment\n\t\t\t\t (s[1] - 1, s[2] - 0, s[3]) ? \"YES\" : \"NO\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tchange (s[1] - 1, s[2]);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.numeric, std.stdio;\nimmutable H = 1 << 19, T = H * 2;\nint [T] t;\nint n, q, u, v, w, z;\nvoid set (int p, int v) {\n\tfor (t[p] = v, p >>= 1; p; p >>= 1) t[p] = gcd (t[p * 2], t[p * 2 + 1]);\n}\nint ver (int p, int v) {\n\twhile (p < H) {\n\t\tint x = t[p * 2] % v, y = t[p * 2 + 1] % v;\n\t\tif (x && y) return 2;\n\t\tp = p * 2 + !x;\n\t}\n\treturn 1;\n}\nint ask (int lo, int hi, int v) {\n\tfor (int f; lo < hi; lo >>= 1, hi >>= 1) {\n\t\tif (lo & 1) f += (t[lo] % v) && ver (lo, v), lo += 1;\n\t\tif (hi & 1) hi -= 1, f += (t[hi] % v) && ver (hi, v);\n\t\tif (f > 1) return 0;\n\t}\n\treturn 1;\n}\nvoid main () {\n\treadf (\" %s\", &n);\n\tforeach (i; 0..n) readf (\" %s\", &t[i + H]);\n\tforeach_reverse (i; 1..H) t[i] = gcd (t[i * 2], t[i * 2 + 1]);\n\treadf (\" %s\", &q);\n\tforeach (r; 0..q) {\n\t\treadf (\" %s %s %s\", &z, &u, &v);\n\t\tif (z < 2) readf (\" %s\", &w), writeln (ask (u - 1 + H, v + H, w) ? \"YES\" : \"NO\");\n\t\telse set (u - 1 + H, v);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n// T: monoid\n// op: T * T -> T\n// query(a, b): returns t_a ... t_{b-1}\nclass SegmentTree(T, alias op) {\n import std.functional : binaryFun;\n alias opFun = binaryFun!op;\n const(T) idT;\n\n int n;\n T[] ts;\n this(int n_, const(T) idT) {\n this.idT = idT;\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[] = idT;\n }\n this(inout(T)[] ts_, const(T) idT) {\n this.idT = idT;\n const n_ = cast(int)(ts_.length);\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ts[0 .. n] = idT;\n ts[n .. n + n_] = ts_[];\n ts[n + n_ .. n << 1] = idT;\n build();\n }\n ref T at(int a) {\n return ts[n + a];\n }\n void build() {\n foreach_reverse (a; 1 .. n) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void set(int a, const(T) val) {\n ts[a += n] = val;\n for (; a >>= 1; ) ts[a] = opFun(ts[a << 1], ts[a << 1 | 1]);\n }\n void mulL(int a, const(T) val) {\n set(a, opFun(val, ts[a + n]));\n }\n void mulR(int a, const(T) val) {\n set(a, opFun(ts[a + n], val));\n }\n T query(int a, int b) const {\n T prodL = idT, prodR = idT;\n for (a += n, b += n; a < b; a >>= 1, b >>= 1) {\n if (a & 1) prodL = opFun(prodL, ts[a++]);\n if (b & 1) prodR = opFun(ts[--b], prodR);\n }\n return opFun(prodL, prodR);\n }\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto seg = new SegmentTree!(int, gcd)(A, 0);\n bool solve(int l, int r, int x) {\n for (; ; ) {\n debug {\n writeln(l, \" \", r, \" \", x);\n }\n if (r - l <= 1) {\n return true;\n }\n const mid = (l + r) / 2;\n if (seg.query(l, mid) % x == 0) {\n r = mid;\n } else if (seg.query(mid, r) % x == 0) {\n l = mid;\n } else {\n return false;\n }\n }\n }\n \n const Q = readInt();\n foreach (q; 0 .. Q) {\n const typ = readInt();\n switch (typ) {\n case 1: {\n const l = readInt() - 1;\n const r = readInt();\n const x = readInt();\n const ans = solve(l, r, x);\n writeln(ans ? \"YES\" : \"NO\");\n } break;\n case 2: {\n const i = readInt() - 1;\n const y = readInt();\n seg.set(i, y);\n } break;\n default: assert(false);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "39e7083c9d16a8cb92fc93bd8185fad2"} {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\nstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\nstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias gcd=std.numeric.gcd;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n\t{\n\t\tpair!(X,Y) pp;\n\t\tpp.fi=x_;\n\t\tpp.se=y_;\n\t\treturn pp;\n\t}\n\tbig gcd(big a,big b)\n\t{\n\t\twhile(b)\n\t\t{\n\t\t\ta%=b;\n\t\t\tswap(a,b);\n\t\t}\n\t\treturn a;\n\t}\n\tX binpow(X,Y)(X base,Y exp)if(is(typeof(exp>>1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)if(is(typeof(exp>>1)) && is(typeof(base%mm)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~\"\\n\", ptrs)==ptrs.length;}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n,k;\n\tloop:while(read(&n,&k))\n\t{\n\t\tauto a=arread!(int);\n\t\tauto b=iota(1,n+1).array;\n\t\tint p=0;\n\t\tforeach(i;0..k)\n\t\t{\n\t\t\tint pos=(p+a[i])%b.length;\n\t\t\t//debug writeln(a.length);\n\t\t\twrite(b[pos],' ');\n\t\t\tif(pos==0)b=b[pos+1..$];\n\t\t\telse if(pos==b.length-1)b=b[0..pos];\n\t\t\telse b=b[0..pos]~b[pos+1..$];\n\t\t\tp=pos%b.length;\n\t\t}\n\t}\n\tdebug system(\"pause\");\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tauto p = iota (1, n + 1).array;\n\t\tint [] ans;\n\t\tforeach (v; a)\n\t\t{\n\t\t\tint q = v % p.length;\n\t\t\tans ~= p[q];\n\t\t\tp = p[q + 1..$] ~ p[0..q];\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "negative_code": [], "src_uid": "5512fbe2963dab982a58a14daf805291"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto s = readln.chomp.to!(char[]);\n auto a = readln.split.to!(long[]);\n\n const char[] pat = \"hard\";\n auto dp = new long[](pat.length + 1);\n fill(dp, 1_000_000_000_000_000_000);\n dp[0] = 0;\n foreach (i; 0 .. n) {\n auto nex = new long[](pat.length + 1);\n fill(nex, 1_000_000_000_000_000_000);\n foreach (j, c; pat) {\n if (s[i] == c) {\n nex[j] = min(nex[j], dp[j] + a[i]);\n nex[j + 1] = min(nex[j + 1], dp[j]);\n } else {\n nex[j] = min(nex[j], dp[j]);\n }\n }\n dp.swap(nex);\n }\n writeln(reduce!(min)(dp[0 .. (pat.length)]));\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n", "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n auto A = readln.split.map!(to!long).array;\n\n auto dp = new long[][](N+1, 4);\n foreach (i; 0..N+1) fill(dp[i], 1L<<59);\n dp[0][0] = 0;\n\n foreach (i; 0..N) {\n dp[i+1] = dp[i].dup;\n if (S[i] == 'h') {\n dp[i+1][0] = dp[i][0] + A[i];\n dp[i+1][1] = min(dp[i][0], dp[i][1]);\n } else if (S[i] == 'a') {\n dp[i+1][1] = dp[i][1] + A[i];\n dp[i+1][2] = min(dp[i][1], dp[i][2]);\n } else if (S[i] == 'r') {\n dp[i+1][2] = dp[i][2] + A[i];\n dp[i+1][3] = min(dp[i][2], dp[i][3]);\n } else if (S[i] == 'd') {\n dp[i+1][3] = dp[i][3] + A[i];\n }\n }\n\n dp[N].reduce!min.writeln;\n}\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto s = \"#\" ~ readln.chomp;\n \n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto dp = new long[][] (n+1, 5);\n foreach (ref rw; dp) { rw.fill(0); }\n \n int [char] mp;\n mp['h'] = 1;\n mp['a'] = 2;\n mp['r'] = 3;\n mp['d'] = 4;\n foreach (i; 1 .. n+1) {\n dp[i][] = dp[i-1][];\n \n int k = mp.get(s[i], -1);\n if (k == -1) { continue; }\n \n dp[i][k-1] = min(dp[i-1][k-1] + c[i], k-1 > 0 ? dp[i-1][0 .. k-1].minElement : 10L ^^ 18);\n dp[i][k] = min(dp[i-1][k], dp[i-1][k-1]);\n }\n \n debug { dp.writeln; }\n \n dp[n][0 .. 4].minElement.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto s = \"#\" ~ readln.chomp;\n \n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto dp = new long[][] (n+1, 5);\n foreach (ref rw; dp) { rw.fill(0); }\n \n int [char] mp;\n mp['h'] = 1;\n mp['a'] = 2;\n mp['r'] = 3;\n mp['d'] = 4;\n foreach (i; 1 .. n+1) {\n dp[i][] = dp[i-1][];\n \n if (s[i] ! in mp) { continue; }\n int k = mp[s[i]];\n \n dp[i][k-1] = min(dp[i-1][k-1] + c[i], k-2 >= 0 ? dp[i-1][k-2] : 10L ^^ 18);\n dp[i][k] = min(dp[i-1][k], dp[i-1][k-1]);\n \n debug { dp[i][k].writeln; }\n }\n \n debug { dp.writeln; }\n \n dp[n][0 .. 4].minElement.writeln;\n}"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\nenum inf3 = 1_001_001_001;\nenum inf6 = 1_001_001_001_001_001_001L;\nenum mod = 1_000_000_007L;\n\n\nvoid main() {\n int n;\n scan(n);\n auto s = readln.chomp;\n auto a = readln.split.to!(long[]);\n\n auto t = \"hard\";\n auto m = t.length.to!int;\n\n auto dp = new long[][](n + 1, m + 1);\n fillAll(dp, inf6);\n dp[0][0] = 0;\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. m + 1) {\n if (j < m && s[i] == t[j]) {\n dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);\n dp[i+1][j] = min(dp[i+1][j], dp[i][j] + a[i]);\n }\n else {\n dp[i+1][j] = min(dp[i+1][j], dp[i][j]);\n }\n }\n }\n\n debug {\n writefln(\"%(%s\\n%)\", dp);\n }\n\n long ans = inf6;\n\n foreach (j ; 0 .. m) {\n ans = min(ans, dp[n][j]);\n }\n\n writeln(ans);\n}\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto s = readln.chomp.to!(char[]);\n auto a = readln.split.to!(long[]);\n\n const char[] pat = \"hard\";\n auto dp = new long[](pat.length + 1);\n fill(dp, 1_000_000_000_000_000_000);\n dp[0] = 0;\n foreach (i; 0 .. n) {\n auto nex = new long[](pat.length + 1);\n fill(nex, 1_000_000_000_000_000_000);\n foreach (j, c; pat) {\n if (s[i] == c) {\n nex[j] = min(nex[j], dp[j] + a[i]); // s[i]\u3092\u6d88\u3059\n nex[j + 1] = min(nex[j + 1], dp[j]); // \u6d88\u3055\u306a\u3044\n } else {\n nex[j] = min(nex[j], dp[j]); // \u6d88\u3055\u306a\u3044\n }\n }\n dp.swap(nex);\n }\n writeln(reduce!(min)(dp[0 .. (pat.length)]));\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto s = readln.chomp.to!(char[]);\n auto a = readln.split.to!(long[]);\n\n const char[] pat = \"hard\";\n auto dp = new long[][](n + 1, pat.length + 1);\n foreach (i; 0 .. (n + 1))\n fill(dp[i], 1_000_000_000_000_000_000);\n dp[0][0] = 0;\n foreach (i; 0 .. n) {\n foreach (j, c; pat) {\n if (s[i] == c) {\n dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i]);\n dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);\n } else {\n dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);\n }\n }\n }\n writeln(reduce!(min)(dp[n][0 .. (pat.length)]));\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10L ^^ 9 + 23;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto s = \"#\" ~ readln.chomp;\n \n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto dp = new long[][] (n+1, 5);\n foreach (ref rw; dp) { rw.fill(0); }\n \n int [char] mp;\n mp['h'] = 1;\n mp['a'] = 2;\n mp['r'] = 3;\n mp['d'] = 4;\n foreach (i; 1 .. n+1) {\n dp[i][] = dp[i-1][];\n \n if (s[i] ! in mp) { continue; }\n int k = mp[s[i]];\n \n dp[i][k-1] = min(dp[i-1][k-1] + c[i], k-1 > 0 ? dp[i-1][0 .. k-1].minElement : 10L ^^ 18);\n dp[i][k] = max(dp[i-1][k], dp[i-1][k-1]);\n }\n \n debug { dp.writeln; }\n \n dp[n][0 .. 4].minElement.writeln;\n}"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n auto s = readln.chomp.to!(char[]);\n auto a = readln.split.to!(long[]);\n\n const char[] pat = \"hard\";\n auto dp = new long[][](n + 1, pat.length + 1);\n foreach (i; 0 .. (n + 1))\n fill(dp[i], 1_000_000_000_000_000_000);\n dp[0][0] = 0;\n foreach (i; 0 .. n) {\n foreach (j, c; pat) {\n if (s[i] == c) {\n dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i]);\n dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);\n } else {\n dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);\n }\n }\n }\n writeln(reduce!(min)(dp[n]));\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}], "src_uid": "8cc22dc6e81bb49b64136e5ff7eb8caf"} {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n string[] arr;\n foreach (_; 0 .. n) {\n arr ~= readln.chomp;\n }\n \n int x1, y1, x2, y2;\n readf(\"%s %s %s %s\", &x1, &y1, &x2, &y2);\n readln;\n \n --x1, --y1;\n --x2, --y2;\n \n auto step = new int[][] (n, m);\n foreach (rw; 0 .. n) { step[rw][] = -1; }\n \n auto d = [[0, 1], [-1, 0], [0, -1], [1, 0]];\n \n alias t = Tuple!(int, int);\n auto q = make!(DList!t);\n step[x1][y1] = 0;\n q ~= tuple(x1, y1);\n while (!q.empty()) {\n auto v = q.front();\n q.removeFront();\n \n debug { writeln(v[0], ' ', v[1]); }\n \n foreach (cd; d) {\n int cx = v[0], cy = v[1];\n foreach (_; 0 .. k) {\n cx += cd[0], cy += cd[1];\n \n if (cx >= n || cx < 0 || cy >= m || cy < 0) { break; }\n if (arr[cx][cy] == '#') { break; }\n if (step[cx][cy] != -1 && step[cx][cy] <= step[v[0]][v[1]]) { break; }\n \n if (step[cx][cy] == -1 || step[v[0]][v[1]] + 1 < step[cx][cy]) {\n step[cx][cy] = step[v[0]][v[1]] + 1;\n q ~= tuple(cx, cy);\n }\n }\n }\n }\n \n auto ans = step[x2][y2];\n ans.writeln;\n}", "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n string[] arr;\n foreach (_; 0 .. n) {\n arr ~= readln.chomp;\n }\n \n int x1, y1, x2, y2;\n readf(\"%s %s %s %s\", &x1, &y1, &x2, &y2);\n readln;\n \n --x1, --y1;\n --x2, --y2;\n \n immutable int INF = 10 ^^ 9 + 23;\n auto step = new int[][] (n, m);\n foreach (rw; 0 .. n) { step[rw][] = INF; }\n \n auto d = [[0, 1], [-1, 0], [0, -1], [1, 0]];\n \n alias t = Tuple!(int, int);\n auto q = make!(DList!t);\n step[x1][y1] = 0;\n q ~= tuple(x1, y1);\n while (!q.empty()) {\n auto sx = q.front()[0], sy = q.front()[1];\n q.removeFront();\n \n debug { writeln(sx, ' ', sy); }\n \n foreach (cd; d) {\n int cx = sx, cy = sy;\n foreach (_; 0 .. k) {\n cx += cd[0], cy += cd[1];\n \n if (cx >= n || cx < 0 || cy >= m || cy < 0) { break; }\n if (arr[cx][cy] == '#') { break; }\n if (step[cx][cy] <= step[sx][sy]) { break; }\n \n if (step[sx][sy] + 1 < step[cx][cy]) {\n step[cx][cy] = step[sx][sy] + 1;\n q ~= tuple(cx, cy);\n }\n }\n }\n }\n \n auto ans = step[x2][y2] != INF ? step[x2][y2] : -1;\n ans.writeln;\n}"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n string[] arr;\n foreach (_; 0 .. n) {\n arr ~= readln.chomp;\n }\n \n int x1, y1, x2, y2;\n readf(\"%s %s %s %s\", &x1, &y1, &x2, &y2);\n readln;\n \n --x1, --y1;\n --x2, --y2;\n \n auto step = new int[][] (n, m);\n foreach (rw; 0 .. n) { step[rw][] = -1; }\n \n auto d = [[0, 1], [-1, 0], [0, -1], [1, 0]];\n \n alias t = Tuple!(int, int);\n auto q = make!(DList!t);\n step[x1][y1] = 0;\n q ~= tuple(x1, y1);\n while (!q.empty()) {\n auto v = q.front();\n q.removeFront();\n \n debug { writeln(v[0], ' ', v[1]); }\n \n foreach (cd; d) {\n int cx = v[0], cy = v[1];\n foreach (_; 0 .. k) {\n cx += cd[0], cy += cd[1];\n \n if (cx >= n || cx < 0 || cy >= m || cy < 0) { break; }\n if (arr[cx][cy] == '#') { break; }\n if (step[cx][cy] != -1 && step[cx][cy] <= step[v[0]][v[1]] + 1) { break; }\n \n step[cx][cy] = step[v[0]][v[1]] + 1;\n q ~= tuple(cx, cy);\n }\n }\n }\n \n auto ans = step[x2][y2];\n ans.writeln;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n string[] arr;\n foreach (_; 0 .. n) {\n arr ~= readln.chomp;\n }\n \n int x1, y1, x2, y2;\n readf(\"%s %s %s %s\", &x1, &y1, &x2, &y2);\n readln;\n \n --x1, --y1;\n --x2, --y2;\n \n auto step = new int[][] (n, m);\n foreach (rw; 0 .. n) { step[rw][] = -1; }\n \n auto d = [[0, 1], [-1, 0], [0, -1], [1, 0]];\n \n alias t = Tuple!(int, int);\n auto q = make!(DList!t);\n step[x1][y1] = 0;\n q ~= tuple(x1, y1);\n while (!q.empty()) {\n auto v = q.front();\n q.removeFront();\n \n debug { writeln(v[0], ' ', v[1]); }\n \n foreach (cd; d) {\n int cx = v[0], cy = v[1];\n foreach (_; 0 .. k) {\n cx += cd[0], cy += cd[1];\n \n if (cx >= n || cx < 0 || cy >= m || cy < 0) { break; }\n if (arr[cx][cy] == '#') { break; }\n if (step[cx][cy] >= 0) { break; }\n \n step[cx][cy] = step[v[0]][v[1]] + 1;\n q ~= tuple(cx, cy);\n }\n }\n }\n \n auto ans = step[x2][y2];\n ans.writeln;\n}"}], "src_uid": "bc93c89cf41c8e44584045ac52b9acc6"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; long K; get(N, K);\r\n long[] ps; get(ps);\r\n long r, q = ps[0];\r\n foreach (p; ps[1..$]) {\r\n auto a = p * 100;\r\n auto b = q * K;\r\n if (a > b) {\r\n auto c = (a - b + K - 1) / K;\r\n q += c;\r\n r += c;\r\n }\r\n q += p;\r\n }\r\n writeln(r);\r\n }\r\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n, k;\r\n readf!\"%d %d\\n\"(n, k);\r\n long[] a = readln.split.map!(to!long).array;\r\n long s = a[0], res = 0;\r\n foreach (i; 1 .. n)\r\n {\r\n res = max(res, (100 * a[i] - k * s + k - 1) / k);\r\n s += a[i];\r\n }\r\n writeln(res);\r\n }\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\treadln;\r\n\t\tauto p = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tbool ok (long start)\r\n\t\t{\r\n\t\t\tlong cur = start + p[0];\r\n\t\t\tforeach (i; 1..n)\r\n\t\t\t{\r\n\t\t\t\tif (cur * k < p[i] * 100L)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tcur += p[i];\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tlong lo = 0;\r\n\t\tlong hi = 10L ^^ 12;\r\n\t\twhile (lo < hi)\r\n\t\t{\r\n\t\t\tlong me = (lo + hi) >> 1;\r\n\t\t\tif (ok (me))\r\n\t\t\t{\r\n\t\t\t\thi = me;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlo = me + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (lo);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD;\n\t\tauto p = RDA;\n\n\t\tauto x = p[0];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tauto y = p[i] * 100;\n\t\t\tauto d = y - x * k;\n\t\t\tif (d > 0)\n\t\t\t{\n\t\t\t\td = (d+k-1) / k;\n\t\t\t\tans[ti] += d;\n\t\t\t\tp[i] += d;\n\t\t\t}\n\t\t\tx += p[i];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD;\n\t\tauto p = RDA;\n\n\t\tauto x = p[0];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tauto y = p[i] * 100;\n\t\t\tauto d = y - x * k;\n\t\t\tif (d > 0)\n\t\t\t{\n\t\t\t\tans[ti] += d;\n\t\t\t\tp[i] += d;\n\t\t\t}\n\t\t\tx += p[i];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "53975eea2503bb47bfd0a5119406aea3"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, k;\n\n void solve(long tc = -1)\n {\n auto divs = redBlackTree!long();\n for(long d = 1; d * d <= n; d++)\n if (n % d == 0)\n {\n divs.insert(d);\n divs.insert(n / d);\n }\n auto bdiv = divs.lowerBound(k + 1).back;\n writeln(n / bdiv);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\t\tauto k = RD;\n\t\t\n\t\tans[ti] = long.max;\n\t\tfor (long i = 1; i*i <= n; ++i)\n\t\t{\n\t\t\tif (n % i == 0)\n\t\t\t{\n\t\t\t\tif (i <= k)\n\t\t\t\t{\n\t\t\t\t\tans[ti].chmin(n / i);\n\t\t\t\t}\n\t\t\t\tif (n / i <= k)\n\t\t\t\t{\n\t\t\t\t\tans[ti].chmin(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "f00eb0452f5933103f1f77ef06473c6a"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\tlong s;\n\twhile (readf (\" %s %s %s\", &n, &k, &s) > 0)\n\t{\n\t\tif (s < k || (n - 1) * 1L * k < s)\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue;\n\t\t}\n\t\twriteln (\"YES\");\n\t\tint pos = 1;\n\t\tint dir = +1;\n\t\tint [] ans;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tint len = (dir > 0) ? (n - pos) : (pos - 1);\n\t\t\tlen = min (len, s - (k - i - 1)).to !(int);\n\t\t\tassert (len > 0);\n\t\t\ts -= len;\n\t\t\tpos += len * dir;\n\t\t\tans ~= pos;\n\t\t\tif (pos == 1 || pos == n)\n\t\t\t{\n\t\t\t\tdir *= -1;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, k; long s;\n readf(\"%s %s %s\", &n, &k, &s);\n readln;\n \n if (k > s || cast(long)(n-1) * k < s) {\n writeln(\"NO\");\n return;\n }\n \n writeln(\"YES\");\n auto ans = [1];\n while (k--) {\n auto step = cast(int) min(n-1, s - k);\n s -= step;\n if (ans.back + step <= n) ans ~= ans.back + step;\n else ans ~= ans.back - step;\n }\n \n ans.dropOne.writefln!(\"%(%s %)\");\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, k; long s;\n readf(\"%s %s %s\", &n, &k, &s);\n readln;\n \n if (cast(long)(n-1) * k < s) {\n writeln(\"NO\");\n return;\n }\n \n writeln(\"YES\");\n auto ans = [1];\n while (k--) {\n auto step = cast(int) min(n-1, s - k);\n s -= step;\n if (ans.back + step <= n) ans ~= ans.back + step;\n else ans ~= ans.back - step;\n }\n \n ans.dropOne.writefln!(\"%(%s %)\");\n}"}], "src_uid": "2cc44c5a084688025c16b0394c98b2f6"} {"source_code": "/+ dub.sdl:\n name \"I\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv, std.traits;\n// import dcomp.foundation, dcomp.scanner;\n// import dcomp.array;\n// import dcomp.algorithm;\n// import dcomp.string;\n\n/// \u9045\u5ef6\u4f1d\u642cSegment Tree\nstruct LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {\n const int n, sz, lg;\n T[] d;\n L[] lz;\n @disable this();\n this(int n) {\n import std.algorithm : fill, each;\n import core.bitop : bsr;\n if (n == 0) return;\n int lg = n.bsr;\n if ((2^^lg) < n) lg++;\n this.n = n;\n this.sz = 2^^lg;\n this.lg = lg;\n d = new T[](2*this.sz);\n d.each!((ref x) => x = eT);\n lz = new L[](2*this.sz);\n lz.each!((ref x) => x = eL);\n }\n private void lzAdd(int k, L x) {\n d[k] = opTL(d[k], x);\n lz[k] = opLL(lz[k], x);\n }\n private void push(int k) {\n if (lz[k] == eL) return;\n lzAdd(2*k, lz[k]);\n lzAdd(2*k+1, lz[k]);\n lz[k] = eL;\n }\n //d[a]+d[a+1]+...+d[b-1]\n T sum(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return eT;\n if (a <= l && r <= b) return d[k];\n push(k);\n int md = (l+r)/2;\n return opTT(sum(a, b, l, md, 2*k),\n sum(a, b, md, r, 2*k+1));\n }\n T single(int k) {\n k += sz;\n foreach_reverse (int i; 1..lg+1) {\n push(k>>i);\n }\n return d[k];\n }\n void singleSet(T x, int k) {\n k += sz;\n foreach_reverse (int i; 1..lg+1) {\n push(k>>i);\n }\n d[k] = x;\n foreach (int i; 1..lg+1) {\n d[k>>i] = opTT(d[2*(k>>i)], d[2*(k>>i)+1]);\n }\n }\n T sum(int a, int b) {\n assert(0 <= a && a <= b && b <= n);\n return sum(a, b, 0, sz, 1);\n }\n void add(int a, int b, L x, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b) {\n lzAdd(k, x);\n return;\n }\n push(k);\n int md = (l+r)/2;\n add(a, b, x, l, md, 2*k);\n add(a, b, x, md, r, 2*k+1);\n d[k] = opTT(d[2*k], d[2*k+1]);\n }\n void add(int a, int b, L x) {\n assert(0 <= a && a <= b && b <= n);\n add(a, b, x, 0, sz, 1);\n }\n @property int opDollar() const {return sz;}\n struct Range {\n LazySeg* seg;\n int start, end;\n @property T sum() {\n return seg.sum(start, end);\n }\n }\n T opIndex(int k) {\n assert(0 <= k && k < n);\n return single(k);\n }\n void opIndexAssign(T x, int k) {\n assert(0 <= k && k < n);\n singleSet(x, k);\n }\n int[2] opSlice(size_t dim)(int start, int end) {\n assert(0 <= start && start <= end && end <= sz);\n return [start, end];\n }\n Range opIndex(int[2] rng) {\n return Range(&this, rng[0], rng[1]);\n }\n void opIndexOpAssign(string op : \"+\")(L x, int[2] rng) {\n add(rng[0], rng[1], x);\n }\n}\n\nint binSearchLeft(alias pred, TR)(TR t, int a, int b) \nif (isInstanceOf!(LazySeg, TR)) {\n alias args = TemplateArgsOf!TR;\n alias opTT = args[2];\n with (t) {\n auto x = args[5];\n if (pred(x)) return a-1;\n int pos = a;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, d[k]))) {\n x = opTT(x, d[k]);\n pos = r;\n return;\n }\n if (l+1 == r) return;\n push(k);\n int md = (l+r)/2;\n f(a, b, l, md, 2*k);\n if (pos >= md) f(a, b, md, r, 2*k+1);\n }\n f(a, b, 0, sz, 1);\n return pos;\n }\n}\n\nvoid solve() {\n string s;\n sc.read(s);\n auto saInfo = suffixArray(s);\n int n = s.length.to!int;\n import std.typecons;\n alias T = Tuple!(long, int, int);\n auto tr = LazySeg!(T, int,\n (a, b)=>T(a[0]+b[0], a[1]+b[1], max(a[2], b[2])),\n (a, b)=>T(long(b) * a[1], a[1], b),\n (a, b)=>b,\n T(0L, 1, -(10^^9)), -1)(n);\n tr[0..n] += 10^^9;\n long sm = 0;\n foreach (i; 1..n) {\n auto u = saInfo.lcp[i];\n auto le = tr.binSearchLeft!(x => x[2] >= u)(0, i);\n tr[le..i] += u;\n sm += tr[0..i].sum[0];\n// writeln(tr);\n }\n writeln(sm*2 + long(n)*(n+1)/2);\n}\n\n\nint main() {\n int n;\n sc.read(n);\n foreach (i; 0..n) {\n solve();\n }\n return 0;\n}\n\nScanner sc;\nstatic this() {\n sc = new Scanner(stdin);\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */\n// module dcomp.array;\n\n \nT[N] fixed(T, size_t N)(T[N] a) {return a;}\n\n \n \n\n \n \nstruct FastAppender(A) {\n import std.algorithm : max;\n import std.range.primitives : ElementEncodingType;\n import core.stdc.string : memcpy;\n\n private alias T = ElementEncodingType!A;\n private T* _data;\n private size_t len, cap;\n \n @property size_t length() {return len;}\n \n void reserve(size_t nlen) {\n import core.memory : GC;\n if (nlen <= cap) return;\n \n void* nx = GC.malloc(nlen * T.sizeof);\n\n cap = nlen;\n if (len) memcpy(nx, _data, len * T.sizeof);\n _data = cast(T*)(nx);\n }\n \n void opOpAssign(string op : \"~\")(T item) {\n if (len == cap) {\n reserve(max(4, cap*2));\n }\n _data[len++] = item;\n }\n \n void clear() {\n len = 0;\n }\n \n T[] data() {\n return (_data) ? _data[0..len] : null;\n }\n}\n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/string.d */\n// module dcomp.string;\n\n \nstruct SA(T) {\n T[] s; \n \n int[] sa, rsa, lcp;\n this(in T[] s) {\n size_t n = s.length;\n this.s = s.dup;\n sa = new int[](n+1);\n rsa = new int[](n+1);\n lcp = new int[](n);\n }\n}\n\nint[] sais(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm, std.range;\n int n = _s.length.to!int;\n int[] sa = new int[](n+1);\n if (n == 0) return sa;\n\n auto s = _s.map!\"a+1\".array ~ T(0); B++; \n \n bool[] ls = new bool[](n+1);\n ls[n] = true;\n foreach_reverse (i; 0..n) {\n ls[i] = (s[i] == s[i+1]) ? ls[i+1] : (s[i] < s[i+1]);\n }\n \n int[] sumL = new int[](B+1), sumS = new int[](B+1); \n s.each!((i, c) => !ls[i] ? sumS[c]++ : sumL[c+1]++);\n foreach (i; 0..B) {\n sumL[i+1] += sumS[i];\n sumS[i+1] += sumL[i+1];\n }\n\n void induce(in int[] lms) {\n sa[] = -1;\n auto buf0 = sumS.dup;\n foreach (d; lms) {\n sa[buf0[s[d]]++] = d;\n }\n auto buf1 = sumL.dup;\n foreach (v; sa) {\n if (v >= 1 && !ls[v-1]) {\n sa[buf1[s[v-1]]++] = v-1;\n }\n }\n auto buf2 = sumL.dup;\n foreach_reverse (v; sa) {\n if (v >= 1 && ls[v-1]) {\n sa[--buf2[s[v-1]+1]] = v-1;\n }\n }\n }\n \n int[] lms = iota(1, n+1).filter!(i => !ls[i-1] && ls[i]).array;\n int[] lmsMap = new int[](n+1);\n lmsMap[] = -1; lms.each!((i, v) => lmsMap[v] = i.to!int);\n\n induce(lms);\n \n if (lms.length >= 2) {\n int m = lms.length.to!int - 1;\n \n auto lms2 = sa.filter!(v => lmsMap[v] != -1).array;\n int recN = 1;\n int[] recS = new int[](m);\n recS[lmsMap[lms2[1]]] = 1;\n foreach (i; 2..m+1) {\n int l = lms2[i-1], r = lms2[i];\n int nl = lms[lmsMap[l]+1], nr = lms[lmsMap[r]+1];\n if (cmp(s[l..nl+1], s[r..nr+1])) recN++;\n recS[lmsMap[lms2[i]]] = recN;\n }\n \n induce(lms.indexed(sais!int(recS, recN)).array);\n }\n\n return sa;\n}\n\n\n \nSA!T suffixArray(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm;\n int n = _s.length.to!int;\n auto saInfo = SA!T(_s);\n if (n == 0) return saInfo;\n \n with (saInfo) {\n sa = sais(_s, B);\n \n sa.each!((i, v) => rsa[v] = i.to!int);\n \n int h = 0;\n foreach (i; 0..n) {\n int j = sa[rsa[i]-1];\n if (h > 0) h--;\n for (; j+h < n && i+h < n; h++) {\n if (s[j+h] != s[i+h]) break;\n }\n lcp[rsa[i]-1] = h;\n }\n }\n return saInfo;\n}\n\n \n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */\n// module dcomp.algorithm;\n\nimport std.range.primitives;\nimport std.traits : isFloatingPoint, isIntegral;\n\n \nT binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {\n while (r-l > 1) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \nT binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {\n foreach (i; 0..cnt) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \n \n\n \nE minimum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);\n}\n\n \nElementType!Range minimum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return minimum!pred(range, e);\n}\n\n \n \n\n \nE maximum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);\n}\n\n \nElementType!Range maximum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return maximum!pred(range, e);\n}\n\n \n \n\n \nRotator!Range rotator(Range)(Range r) {\n return Rotator!Range(r);\n}\n\n \nstruct Rotator(Range)\nif (isForwardRange!Range && hasLength!Range) {\n size_t cnt;\n Range start, now;\n this(Range r) {\n cnt = 0;\n start = r.save;\n now = r.save;\n }\n this(this) {\n start = start.save;\n now = now.save;\n }\n @property bool empty() {\n return now.empty;\n }\n @property auto front() {\n assert(!now.empty);\n import std.range : take, chain;\n return chain(now, start.take(cnt));\n }\n @property Rotator!Range save() {\n return this;\n }\n void popFront() {\n cnt++;\n now.popFront;\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/ascii.d */\n// module dcomp.ascii;\n\n \nstruct ASCIIString {\n string s;\n alias s this;\n this(string s) {\n this.s = s;\n }\n ref immutable(char) front() const {\n return s[0];\n }\n void popFront() {\n s = s[1..$];\n }\n ref immutable(char) back() const {\n return s[$-1];\n }\n void popBack() {\n s = s[0..$-1];\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n import core.bitop : bsf, bsr, popcnt;\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"I\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n// import dcomp.array;\n// import dcomp.algorithm;\n// import dcomp.string;\n// import dcomp.datastructure.lazyseg;\n// import dcomp.container.deque;\n\nvoid solve() {\n string s;\n sc.read(s);\n auto saInfo = suffixArray(s);\n int n = s.length.to!int;\n auto tr = LazySeg!(long[2], int, (a, b)=>[a[0]+b[0], a[1]+b[1]].fixed, (a, b)=>[b * a[1], a[1]].fixed, (a, b)=>b, [0L, 1L].fixed, -1)(n);\n tr[0..n] += 10^^9;\n long sm = 0;\n Deque!(int[2]) deq;\n deq.insertBack([-1, 0]);\n foreach (i; 1..n) {\n auto u = saInfo.lcp[i];\n while (deq.back[0] >= u) deq.removeBack;\n// auto le = binSearch!(x => tr.single(x)[0] >= u)(-1, i);\n auto le = deq.back[1];\n// writeln(le, \" \", le2, \" \", deq);\n tr[le..i] += u;\n sm += tr[0..i].sum[0];\n deq.insertBack([u, i]);\n// writeln(tr);\n }\n writeln(sm*2 + long(n)*(n+1)/2);\n}\n\n\nint main() {\n int n;\n sc.read(n);\n foreach (i; 0..n) {\n solve();\n }\n return 0;\n}\n\nScanner sc;\nstatic this() {\n sc = new Scanner(stdin);\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/container/deque.d */\n// module dcomp.container.deque;\n\nstruct Deque(T, bool mayNull = true) {\n import core.exception : RangeError;\n import core.memory : GC;\n import std.range : ElementType, isInputRange;\n import std.traits : isImplicitlyConvertible;\n\n struct Payload {\n T *d;\n size_t st, length, cap;\n @property bool empty() const { return length == 0; }\n alias opDollar = length;\n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (length <= i) throw new RangeError();\n return d[(st+i >= cap) ? (st+i-cap) : st+i];\n }\n private void expand() {\n import std.algorithm : max;\n assert(length == cap);\n auto nc = max(size_t(4), 2*cap);\n T* nd = cast(T*)GC.malloc(nc * T.sizeof);\n foreach (i; 0..length) {\n nd[i] = this[i];\n }\n d = nd; st = 0; cap = nc;\n }\n void clear() {\n st = length = 0;\n }\n void insertFront(T v) {\n if (length == cap) expand();\n if (st == 0) st += cap;\n st--; length++;\n this[0] = v; \n }\n void insertBack(T v) {\n if (length == cap) expand();\n length++;\n this[length-1] = v; \n }\n void removeFront() {\n assert(!empty, \"Deque.removeFront: Deque is empty\"); \n st++; length--;\n if (st == cap) st = 0;\n }\n void removeBack() {\n assert(!empty, \"Deque.removeBack: Deque is empty\"); \n length--;\n }\n }\n struct RangeT(A) {\n alias T = typeof(*(A.p));\n alias E = typeof(A.p.d[0]);\n T *p;\n size_t a, b;\n @property bool empty() const { return b <= a; }\n @property size_t length() const { return b-a; }\n @property RangeT save() { return RangeT(p, a, b); }\n @property RangeT!(const A) save() const {\n return typeof(return)(p, a, b);\n }\n alias opDollar = length;\n @property ref inout(E) front() inout { return (*p)[a]; }\n @property ref inout(E) back() inout { return (*p)[b-1]; }\n void popFront() {\n version(assert) if (empty) throw new RangeError();\n a++;\n }\n void popBack() {\n version(assert) if (empty) throw new RangeError();\n b--;\n }\n ref inout(E) opIndex(size_t i) inout { return (*p)[i]; }\n RangeT opSlice() { return this.save; }\n RangeT opSlice(size_t i, size_t j) {\n version(assert) if (i > j || a + j > b) throw new RangeError();\n return typeof(return)(p, a+i, a+j);\n }\n RangeT!(const A) opSlice() const { return this.save; }\n RangeT!(const A) opSlice(size_t i, size_t j) const {\n version(assert) if (i > j || a + j > b) throw new RangeError();\n return typeof(return)(p, a+i, a+j);\n }\n }\n \n alias Range = RangeT!Deque;\n alias ConstRange = RangeT!(const Deque);\n alias ImmutableRange = RangeT!(immutable Deque);\n\n Payload* p;\n private void I() { if (mayNull && !p) p = new Payload(); }\n private void C() const {\n version(assert) if (mayNull && !p) throw new RangeError();\n }\n static if (!mayNull) {\n @disable this();\n }\n \n private this(Payload* p) {\n this.p = p;\n }\n this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {\n p = new Payload();\n foreach (v; values) {\n insertBack(v);\n }\n }\n \n this(Range)(Range r)\n if (isInputRange!Range &&\n isImplicitlyConvertible!(ElementType!Range, T) &&\n !is(Range == T[])) {\n p = new Payload();\n foreach (v; r) {\n insertBack(v);\n }\n }\n static Deque make() { return Deque(new Payload()); }\n @property bool havePayload() const { return (!mayNull || p); }\n @property bool empty() const { return (!havePayload || p.empty); }\n @property size_t length() const { return (havePayload ? p.length : 0); }\n alias opDollar = length;\n ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }\n ref inout(T) front() inout {C; return (*p)[0]; }\n ref inout(T) back() inout {C; return (*p)[$-1]; }\n void clear() { if (p) p.clear(); }\n void insertFront(T v) {I; p.insertFront(v); }\n void insertBack(T v) {I; p.insertBack(v); }\n void removeFront() {C; p.removeFront(); }\n void removeBack() {C; p.removeBack(); }\n Range opSlice() {I; return Range(p, 0, length); }\n}\n\n \n\n \n\n \n\n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */\n// module dcomp.array;\n\n \nT[N] fixed(T, size_t N)(T[N] a) {return a;}\n\n \n \n\n \n \nstruct FastAppender(A) {\n import std.algorithm : max;\n import std.range.primitives : ElementEncodingType;\n import core.stdc.string : memcpy;\n\n private alias T = ElementEncodingType!A;\n private T* _data;\n private size_t len, cap;\n \n @property size_t length() {return len;}\n \n void reserve(size_t nlen) {\n import core.memory : GC;\n if (nlen <= cap) return;\n \n void* nx = GC.malloc(nlen * T.sizeof);\n\n cap = nlen;\n if (len) memcpy(nx, _data, len * T.sizeof);\n _data = cast(T*)(nx);\n }\n \n void opOpAssign(string op : \"~\")(T item) {\n if (len == cap) {\n reserve(max(4, cap*2));\n }\n _data[len++] = item;\n }\n \n void clear() {\n len = 0;\n }\n \n T[] data() {\n return (_data) ? _data[0..len] : null;\n }\n}\n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/datastructure/lazyseg.d */\n// module dcomp.datastructure.lazyseg;\n\nstruct LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {\n const int n, sz, lg;\n T[] d;\n L[] lz;\n @disable this();\n this(int n) {\n import std.algorithm : fill, each;\n import core.bitop : bsr;\n if (n == 0) return;\n int lg = n.bsr;\n if ((2^^lg) < n) lg++;\n this.n = n;\n this.sz = 2^^lg;\n this.lg = lg;\n d = new T[](2*this.sz);\n d.each!((ref x) => x = eT);\n lz = new L[](2*this.sz);\n lz.each!((ref x) => x = eL);\n }\n private void lzAdd(int k, L x) {\n d[k] = opTL(d[k], x);\n lz[k] = opLL(lz[k], x);\n }\n private void push(int k) {\n if (lz[k] == eL) return;\n lzAdd(2*k, lz[k]);\n lzAdd(2*k+1, lz[k]);\n lz[k] = eL;\n }\n T sum(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return eT;\n if (a <= l && r <= b) return d[k];\n push(k);\n int md = (l+r)/2;\n return opTT(sum(a, b, l, md, 2*k),\n sum(a, b, md, r, 2*k+1));\n }\n T single(int k) {\n k += sz;\n foreach_reverse (int i; 1..lg+1) {\n push(k>>i);\n }\n return d[k];\n }\n T sum(int a, int b) {\n assert(0 <= a && a <= b && b <= n);\n return sum(a, b, 0, sz, 1);\n }\n void add(int a, int b, L x, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b) {\n lzAdd(k, x);\n return;\n }\n push(k);\n int md = (l+r)/2;\n add(a, b, x, l, md, 2*k);\n add(a, b, x, md, r, 2*k+1);\n d[k] = opTT(d[2*k], d[2*k+1]);\n }\n void add(int a, int b, L x) {\n assert(0 <= a && a <= b && b <= n);\n add(a, b, x, 0, sz, 1);\n }\n @property int opDollar() const {return sz;}\n struct Range {\n LazySeg* seg;\n int start, end;\n @property T sum() {\n return seg.sum(start, end);\n }\n }\n int[2] opSlice(size_t dim)(int start, int end) {\n assert(0 <= start && start <= end && end <= sz);\n return [start, end];\n }\n Range opIndex(int[2] rng) {\n return Range(&this, rng[0], rng[1]);\n }\n void opIndexOpAssign(string op : \"+\")(L x, int[2] rng) {\n add(rng[0], rng[1], x);\n }\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/string.d */\n// module dcomp.string;\n\n \nstruct SA(T) {\n T[] s; \n \n int[] sa, rsa, lcp;\n this(in T[] s) {\n size_t n = s.length;\n this.s = s.dup;\n sa = new int[](n+1);\n rsa = new int[](n+1);\n lcp = new int[](n);\n }\n}\n\nint[] sais(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm, std.range;\n int n = _s.length.to!int;\n int[] sa = new int[](n+1);\n if (n == 0) return sa;\n\n auto s = _s.map!\"a+1\".array ~ T(0); B++; \n \n bool[] ls = new bool[](n+1);\n ls[n] = true;\n foreach_reverse (i; 0..n) {\n ls[i] = (s[i] == s[i+1]) ? ls[i+1] : (s[i] < s[i+1]);\n }\n \n int[] sumL = new int[](B+1), sumS = new int[](B+1); \n s.each!((i, c) => !ls[i] ? sumS[c]++ : sumL[c+1]++);\n foreach (i; 0..B) {\n sumL[i+1] += sumS[i];\n sumS[i+1] += sumL[i+1];\n }\n\n void induce(in int[] lms) {\n sa[] = -1;\n auto buf0 = sumS.dup;\n foreach (d; lms) {\n sa[buf0[s[d]]++] = d;\n }\n auto buf1 = sumL.dup;\n foreach (v; sa) {\n if (v >= 1 && !ls[v-1]) {\n sa[buf1[s[v-1]]++] = v-1;\n }\n }\n auto buf2 = sumL.dup;\n foreach_reverse (v; sa) {\n if (v >= 1 && ls[v-1]) {\n sa[--buf2[s[v-1]+1]] = v-1;\n }\n }\n }\n \n int[] lms = iota(1, n+1).filter!(i => !ls[i-1] && ls[i]).array;\n int[] lmsMap = new int[](n+1);\n lmsMap[] = -1; lms.each!((i, v) => lmsMap[v] = i.to!int);\n\n induce(lms);\n \n if (lms.length >= 2) {\n int m = lms.length.to!int - 1;\n \n auto lms2 = sa.filter!(v => lmsMap[v] != -1).array;\n int recN = 1;\n int[] recS = new int[](m);\n recS[lmsMap[lms2[1]]] = 1;\n foreach (i; 2..m+1) {\n int l = lms2[i-1], r = lms2[i];\n int nl = lms[lmsMap[l]+1], nr = lms[lmsMap[r]+1];\n if (cmp(s[l..nl+1], s[r..nr+1])) recN++;\n recS[lmsMap[lms2[i]]] = recN;\n }\n \n induce(lms.indexed(sais!int(recS, recN)).array);\n }\n\n return sa;\n}\n\n\n \nSA!T suffixArray(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm;\n int n = _s.length.to!int;\n auto saInfo = SA!T(_s);\n if (n == 0) return saInfo;\n \n with (saInfo) {\n sa = sais(_s, B);\n \n sa.each!((i, v) => rsa[v] = i.to!int);\n \n int h = 0;\n foreach (i; 0..n) {\n int j = sa[rsa[i]-1];\n if (h > 0) h--;\n for (; j+h < n && i+h < n; h++) {\n if (s[j+h] != s[i+h]) break;\n }\n lcp[rsa[i]-1] = h;\n }\n }\n return saInfo;\n}\n\n \n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n\n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */\n// module dcomp.algorithm;\n\nimport std.range.primitives;\nimport std.traits : isFloatingPoint, isIntegral;\n\n \nT binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {\n while (r-l > 1) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \nT binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {\n foreach (i; 0..cnt) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \n \n\n \nE minimum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);\n}\n\n \nElementType!Range minimum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return minimum!pred(range, e);\n}\n\n \n \n\n \nE maximum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);\n}\n\n \nElementType!Range maximum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return maximum!pred(range, e);\n}\n\n \n \n\n \nRotator!Range rotator(Range)(Range r) {\n return Rotator!Range(r);\n}\n\n \nstruct Rotator(Range)\nif (isForwardRange!Range && hasLength!Range) {\n size_t cnt;\n Range start, now;\n this(Range r) {\n cnt = 0;\n start = r.save;\n now = r.save;\n }\n this(this) {\n start = start.save;\n now = now.save;\n }\n @property bool empty() {\n return now.empty;\n }\n @property auto front() {\n assert(!now.empty);\n import std.range : take, chain;\n return chain(now, start.take(cnt));\n }\n @property Rotator!Range save() {\n return this;\n }\n void popFront() {\n cnt++;\n now.popFront;\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/ascii.d */\n// module dcomp.ascii;\n\n \nstruct ASCIIString {\n string s;\n alias s this;\n this(string s) {\n this.s = s;\n }\n ref immutable(char) front() const {\n return s[0];\n }\n void popFront() {\n s = s[1..$];\n }\n ref immutable(char) back() const {\n return s[$-1];\n }\n void popBack() {\n s = s[0..$-1];\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n"}], "negative_code": [{"source_code": "/+ dub.sdl:\n name \"I\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n\n// import dcomp.algorithm;\n// import dcomp.string;\n// import dcomp.datastructure.lazyseg;\n\nvoid solve() {\n string s;\n sc.read(s);\n auto saInfo = suffixArray(s);\n int n = s.length.to!int;\n auto tr = LazySeg!(long, long, (a, b)=>a+b, (a, b)=>(b==-1)?a:b, (a, b)=>(b==-1)?a:b, 0, -1)(n);\n tr[0..n] += 10^^9;\n long sm = 0;\n foreach (i; 1..n) {\n auto u = saInfo.lcp[i];\n auto le = binSearch!(x => tr[x..x+1].sum >= u)(-1, i);\n tr[le..i] += u;\n sm += tr[0..i].sum;\n// writeln(tr);\n }\n writeln(sm*2 + long(n)*(n+1)/2);\n}\n\n\nint main() {\n int n;\n sc.read(n);\n foreach (i; 0..n) {\n solve();\n }\n return 0;\n}\n\nScanner sc;\nstatic this() {\n sc = new Scanner(stdin);\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/datastructure/lazyseg.d */\n// module dcomp.datastructure.lazyseg;\n\nstruct LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {\n const int n, sz;\n T[] d;\n L[] lz;\n @disable this();\n this(int n) {\n import std.algorithm : fill;\n import core.bitop : bsr;\n if (n == 0) return;\n int lg = n.bsr;\n if ((2^^lg) < n) lg++;\n this.n = n;\n this.sz = 2^^lg;\n d = new T[](2*this.sz); d[] = eT;\n lz = new L[](2*this.sz); lz[] = eL;\n }\n private void lzAdd(int k, L x) {\n d[k] = opTL(d[k], x);\n lz[k] = opLL(lz[k], x);\n }\n private void push(int k) {\n if (lz[k] == eL) return;\n lzAdd(2*k, lz[k]);\n lzAdd(2*k+1, lz[k]);\n lz[k] = eL;\n }\n T sum(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return eT;\n if (a <= l && r <= b) return d[k];\n push(k);\n int md = (l+r)/2;\n return opTT(sum(a, b, l, md, 2*k),\n sum(a, b, md, r, 2*k+1));\n }\n T sum(int a, int b) {\n assert(0 <= a && a <= b && b <= n);\n return sum(a, b, 0, sz, 1);\n }\n void add(int a, int b, L x, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b) {\n lzAdd(k, x);\n return;\n }\n push(k);\n int md = (l+r)/2;\n add(a, b, x, l, md, 2*k);\n add(a, b, x, md, r, 2*k+1);\n d[k] = opTT(d[2*k], d[2*k+1]);\n }\n void add(int a, int b, L x) {\n assert(0 <= a && a <= b && b <= n);\n add(a, b, x, 0, sz, 1);\n }\n @property int opDollar() const {return sz;}\n struct Range {\n LazySeg* seg;\n int start, end;\n @property T sum() {\n return seg.sum(start, end);\n }\n }\n int[2] opSlice(size_t dim)(int start, int end) {\n assert(0 <= start && start <= end && end <= sz);\n return [start, end];\n }\n Range opIndex(int[2] rng) {\n return Range(&this, rng[0], rng[1]);\n }\n void opIndexOpAssign(string op)(L x, int[2] rng) {\n add(rng[0], rng[1], x);\n }\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/string.d */\n// module dcomp.string;\n\n \nstruct SA(T) {\n T[] s; \n \n int[] sa, rsa, lcp;\n this(in T[] s) {\n size_t n = s.length;\n this.s = s.dup;\n sa = new int[](n+1);\n rsa = new int[](n+1);\n lcp = new int[](n);\n }\n}\n\nint[] sais(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm, std.range;\n int n = _s.length.to!int;\n int[] sa = new int[](n+1);\n if (n == 0) return sa;\n\n auto s = _s.map!\"a+1\".array ~ T(0); B++; \n \n bool[] ls = new bool[](n+1);\n ls[n] = true;\n foreach_reverse (i; 0..n) {\n ls[i] = (s[i] == s[i+1]) ? ls[i+1] : (s[i] < s[i+1]);\n }\n \n int[] sumL = new int[](B+1), sumS = new int[](B+1); \n s.each!((i, c) => !ls[i] ? sumS[c]++ : sumL[c+1]++);\n foreach (i; 0..B) {\n sumL[i+1] += sumS[i];\n sumS[i+1] += sumL[i+1];\n }\n\n void induce(in int[] lms) {\n sa[] = -1;\n auto buf0 = sumS.dup;\n foreach (d; lms) {\n sa[buf0[s[d]]++] = d;\n }\n auto buf1 = sumL.dup;\n foreach (v; sa) {\n if (v >= 1 && !ls[v-1]) {\n sa[buf1[s[v-1]]++] = v-1;\n }\n }\n auto buf2 = sumL.dup;\n foreach_reverse (v; sa) {\n if (v >= 1 && ls[v-1]) {\n sa[--buf2[s[v-1]+1]] = v-1;\n }\n }\n }\n \n int[] lms = iota(1, n+1).filter!(i => !ls[i-1] && ls[i]).array;\n int[] lmsMap = new int[](n+1);\n lmsMap[] = -1; lms.each!((i, v) => lmsMap[v] = i.to!int);\n\n induce(lms);\n \n if (lms.length >= 2) {\n int m = lms.length.to!int - 1;\n \n auto lms2 = sa.filter!(v => lmsMap[v] != -1).array;\n int recN = 1;\n int[] recS = new int[](m);\n recS[lmsMap[lms2[1]]] = 1;\n foreach (i; 2..m+1) {\n int l = lms2[i-1], r = lms2[i];\n int nl = lms[lmsMap[l]+1], nr = lms[lmsMap[r]+1];\n if (cmp(s[l..nl+1], s[r..nr+1])) recN++;\n recS[lmsMap[lms2[i]]] = recN;\n }\n \n induce(lms.indexed(sais!int(recS, recN)).array);\n }\n\n return sa;\n}\n\n\n \nSA!T suffixArray(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm;\n int n = _s.length.to!int;\n auto saInfo = SA!T(_s);\n if (n == 0) return saInfo;\n \n with (saInfo) {\n sa = sais(_s, B);\n \n sa.each!((i, v) => rsa[v] = i.to!int);\n \n int h = 0;\n foreach (i; 0..n) {\n int j = sa[rsa[i]-1];\n if (h > 0) h--;\n for (; j+h < n && i+h < n; h++) {\n if (s[j+h] != s[i+h]) break;\n }\n lcp[rsa[i]-1] = h;\n }\n }\n return saInfo;\n}\n\n \n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n\n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/ascii.d */\n// module dcomp.ascii;\n\n \nstruct ASCIIString {\n string s;\n alias s this;\n this(string s) {\n this.s = s;\n }\n ref immutable(char) front() const {\n return s[0];\n }\n void popFront() {\n s = s[1..$];\n }\n ref immutable(char) back() const {\n return s[$-1];\n }\n void popBack() {\n s = s[0..$-1];\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */\n// module dcomp.algorithm;\n\nimport std.range.primitives;\nimport std.traits : isFloatingPoint, isIntegral;\n\n \nT binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {\n while (r-l > 1) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \nT binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {\n foreach (i; 0..cnt) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \n \n\n \nE minimum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);\n}\n\n \nElementType!Range minimum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return minimum!pred(range, e);\n}\n\n \n \n\n \nE maximum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);\n}\n\n \nElementType!Range maximum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return maximum!pred(range, e);\n}\n\n \n \n\n \nRotator!Range rotator(Range)(Range r) {\n return Rotator!Range(r);\n}\n\n \nstruct Rotator(Range)\nif (isForwardRange!Range && hasLength!Range) {\n size_t cnt;\n Range start, now;\n this(Range r) {\n cnt = 0;\n start = r.save;\n now = r.save;\n }\n this(this) {\n start = start.save;\n now = now.save;\n }\n @property bool empty() {\n return now.empty;\n }\n @property auto front() {\n assert(!now.empty);\n import std.range : take, chain;\n return chain(now, start.take(cnt));\n }\n @property Rotator!Range save() {\n return this;\n }\n void popFront() {\n cnt++;\n now.popFront;\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"I\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n\n// import dcomp.algorithm;\n// import dcomp.string;\n// import dcomp.datastructure.lazyseg;\n\nvoid solve() {\n string s;\n sc.read(s);\n auto saInfo = suffixArray(s);\n int n = s.length.to!int;\n auto tr = LazySeg!(int, int, (a, b)=>a+b, (a, b)=>(b==-1)?a:b, (a, b)=>(b==-1)?a:b, 0, -1)(n);\n tr[0..n] += 10^^9;\n long sm = 0;\n foreach (i; 1..n) {\n auto u = saInfo.lcp[i];\n auto le = binSearch!(x => tr[x..x+1].sum >= u)(-1, i);\n tr[le..i] += u;\n sm += tr[0..i].sum;\n// writeln(tr);\n }\n writeln(sm*2 + long(n)*(n+1)/2);\n}\n\n\nint main() {\n int n;\n sc.read(n);\n foreach (i; 0..n) {\n solve();\n }\n return 0;\n}\n\nScanner sc;\nstatic this() {\n sc = new Scanner(stdin);\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/datastructure/lazyseg.d */\n// module dcomp.datastructure.lazyseg;\n\nstruct LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {\n const int n, sz;\n T[] d;\n L[] lz;\n @disable this();\n this(int n) {\n import std.algorithm : fill;\n import core.bitop : bsr;\n if (n == 0) return;\n int lg = n.bsr;\n if ((2^^lg) < n) lg++;\n this.n = n;\n this.sz = 2^^lg;\n d = new T[](2*this.sz); d[] = eT;\n lz = new L[](2*this.sz); lz[] = eL;\n }\n private void lzAdd(int k, L x) {\n d[k] = opTL(d[k], x);\n lz[k] = opLL(lz[k], x);\n }\n private void push(int k) {\n if (lz[k] == eL) return;\n lzAdd(2*k, lz[k]);\n lzAdd(2*k+1, lz[k]);\n lz[k] = eL;\n }\n T sum(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return eT;\n if (a <= l && r <= b) return d[k];\n push(k);\n int md = (l+r)/2;\n return opTT(sum(a, b, l, md, 2*k),\n sum(a, b, md, r, 2*k+1));\n }\n T sum(int a, int b) {\n assert(0 <= a && a <= b && b <= n);\n return sum(a, b, 0, sz, 1);\n }\n void add(int a, int b, L x, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b) {\n lzAdd(k, x);\n return;\n }\n push(k);\n int md = (l+r)/2;\n add(a, b, x, l, md, 2*k);\n add(a, b, x, md, r, 2*k+1);\n d[k] = opTT(d[2*k], d[2*k+1]);\n }\n void add(int a, int b, L x) {\n assert(0 <= a && a <= b && b <= n);\n add(a, b, x, 0, sz, 1);\n }\n @property int opDollar() const {return sz;}\n struct Range {\n LazySeg* seg;\n int start, end;\n @property T sum() {\n return seg.sum(start, end);\n }\n }\n int[2] opSlice(size_t dim)(int start, int end) {\n assert(0 <= start && start <= end && end <= sz);\n return [start, end];\n }\n Range opIndex(int[2] rng) {\n return Range(&this, rng[0], rng[1]);\n }\n void opIndexOpAssign(string op)(L x, int[2] rng) {\n add(rng[0], rng[1], x);\n }\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/string.d */\n// module dcomp.string;\n\n \nstruct SA(T) {\n T[] s; \n \n int[] sa, rsa, lcp;\n this(in T[] s) {\n size_t n = s.length;\n this.s = s.dup;\n sa = new int[](n+1);\n rsa = new int[](n+1);\n lcp = new int[](n);\n }\n}\n\nint[] sais(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm, std.range;\n int n = _s.length.to!int;\n int[] sa = new int[](n+1);\n if (n == 0) return sa;\n\n auto s = _s.map!\"a+1\".array ~ T(0); B++; \n \n bool[] ls = new bool[](n+1);\n ls[n] = true;\n foreach_reverse (i; 0..n) {\n ls[i] = (s[i] == s[i+1]) ? ls[i+1] : (s[i] < s[i+1]);\n }\n \n int[] sumL = new int[](B+1), sumS = new int[](B+1); \n s.each!((i, c) => !ls[i] ? sumS[c]++ : sumL[c+1]++);\n foreach (i; 0..B) {\n sumL[i+1] += sumS[i];\n sumS[i+1] += sumL[i+1];\n }\n\n void induce(in int[] lms) {\n sa[] = -1;\n auto buf0 = sumS.dup;\n foreach (d; lms) {\n sa[buf0[s[d]]++] = d;\n }\n auto buf1 = sumL.dup;\n foreach (v; sa) {\n if (v >= 1 && !ls[v-1]) {\n sa[buf1[s[v-1]]++] = v-1;\n }\n }\n auto buf2 = sumL.dup;\n foreach_reverse (v; sa) {\n if (v >= 1 && ls[v-1]) {\n sa[--buf2[s[v-1]+1]] = v-1;\n }\n }\n }\n \n int[] lms = iota(1, n+1).filter!(i => !ls[i-1] && ls[i]).array;\n int[] lmsMap = new int[](n+1);\n lmsMap[] = -1; lms.each!((i, v) => lmsMap[v] = i.to!int);\n\n induce(lms);\n \n if (lms.length >= 2) {\n int m = lms.length.to!int - 1;\n \n auto lms2 = sa.filter!(v => lmsMap[v] != -1).array;\n int recN = 1;\n int[] recS = new int[](m);\n recS[lmsMap[lms2[1]]] = 1;\n foreach (i; 2..m+1) {\n int l = lms2[i-1], r = lms2[i];\n int nl = lms[lmsMap[l]+1], nr = lms[lmsMap[r]+1];\n if (cmp(s[l..nl+1], s[r..nr+1])) recN++;\n recS[lmsMap[lms2[i]]] = recN;\n }\n \n induce(lms.indexed(sais!int(recS, recN)).array);\n }\n\n return sa;\n}\n\n\n \nSA!T suffixArray(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm;\n int n = _s.length.to!int;\n auto saInfo = SA!T(_s);\n if (n == 0) return saInfo;\n \n with (saInfo) {\n sa = sais(_s, B);\n \n sa.each!((i, v) => rsa[v] = i.to!int);\n \n int h = 0;\n foreach (i; 0..n) {\n int j = sa[rsa[i]-1];\n if (h > 0) h--;\n for (; j+h < n && i+h < n; h++) {\n if (s[j+h] != s[i+h]) break;\n }\n lcp[rsa[i]-1] = h;\n }\n }\n return saInfo;\n}\n\n \n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n\n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/ascii.d */\n// module dcomp.ascii;\n\n \nstruct ASCIIString {\n string s;\n alias s this;\n this(string s) {\n this.s = s;\n }\n ref immutable(char) front() const {\n return s[0];\n }\n void popFront() {\n s = s[1..$];\n }\n ref immutable(char) back() const {\n return s[$-1];\n }\n void popBack() {\n s = s[0..$-1];\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */\n// module dcomp.algorithm;\n\nimport std.range.primitives;\nimport std.traits : isFloatingPoint, isIntegral;\n\n \nT binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {\n while (r-l > 1) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \nT binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {\n foreach (i; 0..cnt) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \n \n\n \nE minimum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);\n}\n\n \nElementType!Range minimum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return minimum!pred(range, e);\n}\n\n \n \n\n \nE maximum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);\n}\n\n \nElementType!Range maximum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return maximum!pred(range, e);\n}\n\n \n \n\n \nRotator!Range rotator(Range)(Range r) {\n return Rotator!Range(r);\n}\n\n \nstruct Rotator(Range)\nif (isForwardRange!Range && hasLength!Range) {\n size_t cnt;\n Range start, now;\n this(Range r) {\n cnt = 0;\n start = r.save;\n now = r.save;\n }\n this(this) {\n start = start.save;\n now = now.save;\n }\n @property bool empty() {\n return now.empty;\n }\n @property auto front() {\n assert(!now.empty);\n import std.range : take, chain;\n return chain(now, start.take(cnt));\n }\n @property Rotator!Range save() {\n return this;\n }\n void popFront() {\n cnt++;\n now.popFront;\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"I\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv, std.traits;\n// import dcomp.foundation, dcomp.scanner;\n// import dcomp.array;\n// import dcomp.algorithm;\n// import dcomp.string;\n\n/// \u9045\u5ef6\u4f1d\u642cSegment Tree\nstruct LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {\n const int n, sz, lg;\n T[] d;\n L[] lz;\n @disable this();\n this(int n) {\n import std.algorithm : fill, each;\n import core.bitop : bsr;\n if (n == 0) return;\n int lg = n.bsr;\n if ((2^^lg) < n) lg++;\n this.n = n;\n this.sz = 2^^lg;\n this.lg = lg;\n d = new T[](2*this.sz);\n d.each!((ref x) => x = eT);\n lz = new L[](2*this.sz);\n lz.each!((ref x) => x = eL);\n }\n private void lzAdd(int k, L x) {\n d[k] = opTL(d[k], x);\n lz[k] = opLL(lz[k], x);\n }\n private void push(int k) {\n if (lz[k] == eL) return;\n lzAdd(2*k, lz[k]);\n lzAdd(2*k+1, lz[k]);\n lz[k] = eL;\n }\n //d[a]+d[a+1]+...+d[b-1]\n T sum(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return eT;\n if (a <= l && r <= b) return d[k];\n push(k);\n int md = (l+r)/2;\n return opTT(sum(a, b, l, md, 2*k),\n sum(a, b, md, r, 2*k+1));\n }\n T single(int k) {\n k += sz;\n foreach_reverse (int i; 1..lg+1) {\n push(k>>i);\n }\n return d[k];\n }\n void singleSet(T x, int k) {\n k += sz;\n foreach_reverse (int i; 1..lg+1) {\n push(k>>i);\n }\n d[k] = x;\n foreach (int i; 1..lg+1) {\n d[k>>i] = opTT(d[2*(k>>i)], d[2*(k>>i)+1]);\n }\n }\n T sum(int a, int b) {\n assert(0 <= a && a <= b && b <= n);\n return sum(a, b, 0, sz, 1);\n }\n void add(int a, int b, L x, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b) {\n lzAdd(k, x);\n return;\n }\n push(k);\n int md = (l+r)/2;\n add(a, b, x, l, md, 2*k);\n add(a, b, x, md, r, 2*k+1);\n d[k] = opTT(d[2*k], d[2*k+1]);\n }\n void add(int a, int b, L x) {\n assert(0 <= a && a <= b && b <= n);\n add(a, b, x, 0, sz, 1);\n }\n @property int opDollar() const {return sz;}\n struct Range {\n LazySeg* seg;\n int start, end;\n @property T sum() {\n return seg.sum(start, end);\n }\n }\n T opIndex(int k) {\n assert(0 <= k && k < n);\n return single(k);\n }\n void opIndexAssign(T x, int k) {\n assert(0 <= k && k < n);\n singleSet(x, k);\n }\n int[2] opSlice(size_t dim)(int start, int end) {\n assert(0 <= start && start <= end && end <= sz);\n return [start, end];\n }\n Range opIndex(int[2] rng) {\n return Range(&this, rng[0], rng[1]);\n }\n void opIndexOpAssign(string op : \"+\")(L x, int[2] rng) {\n add(rng[0], rng[1], x);\n }\n}\n\nint binSearchLeft(alias pred, TR)(TR t, int a, int b) \nif (isInstanceOf!(LazySeg, TR)) {\n alias args = TemplateArgsOf!TR;\n alias opTT = args[2];\n with (t) {\n auto x = args[5];\n if (pred(x)) return a-1;\n int pos = a;\n void f(int a, int b, int l, int r, int k) {\n if (b <= l || r <= a) return;\n if (a <= l && r <= b && !pred(opTT(x, d[k]))) {\n x = opTT(x, d[k]);\n pos = r;\n return;\n }\n if (l+1 == r) return;\n push(k);\n int md = (l+r)/2;\n f(a, b, l, md, 2*k);\n if (pos >= md) f(a, b, md, r, 2*k+1);\n }\n f(a, b, 0, sz, 1);\n return pos;\n }\n}\n\nvoid solve() {\n string s;\n sc.read(s);\n auto saInfo = suffixArray(s);\n int n = s.length.to!int;\n import std.typecons;\n alias T = Tuple!(long, int, int);\n auto tr = LazySeg!(T, int,\n (a, b)=>T(a[0]+b[0], a[1]+b[1], max(a[2], b[2])),\n (a, b)=>T(b * a[1], a[1], b),\n (a, b)=>b,\n T(0L, 1, -(10^^9)), -1)(n);\n tr[0..n] += 10^^9;\n long sm = 0;\n foreach (i; 1..n) {\n auto u = saInfo.lcp[i];\n auto le = tr.binSearchLeft!(x => x[2] >= u)(0, i);\n tr[le..i] += u;\n sm += tr[0..i].sum[0];\n// writeln(tr);\n }\n writeln(sm*2 + long(n)*(n+1)/2);\n}\n\n\nint main() {\n int n;\n sc.read(n);\n foreach (i; 0..n) {\n solve();\n }\n return 0;\n}\n\nScanner sc;\nstatic this() {\n sc = new Scanner(stdin);\n}\n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */\n// module dcomp.array;\n\n \nT[N] fixed(T, size_t N)(T[N] a) {return a;}\n\n \n \n\n \n \nstruct FastAppender(A) {\n import std.algorithm : max;\n import std.range.primitives : ElementEncodingType;\n import core.stdc.string : memcpy;\n\n private alias T = ElementEncodingType!A;\n private T* _data;\n private size_t len, cap;\n \n @property size_t length() {return len;}\n \n void reserve(size_t nlen) {\n import core.memory : GC;\n if (nlen <= cap) return;\n \n void* nx = GC.malloc(nlen * T.sizeof);\n\n cap = nlen;\n if (len) memcpy(nx, _data, len * T.sizeof);\n _data = cast(T*)(nx);\n }\n \n void opOpAssign(string op : \"~\")(T item) {\n if (len == cap) {\n reserve(max(4, cap*2));\n }\n _data[len++] = item;\n }\n \n void clear() {\n len = 0;\n }\n \n T[] data() {\n return (_data) ? _data[0..len] : null;\n }\n}\n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/string.d */\n// module dcomp.string;\n\n \nstruct SA(T) {\n T[] s; \n \n int[] sa, rsa, lcp;\n this(in T[] s) {\n size_t n = s.length;\n this.s = s.dup;\n sa = new int[](n+1);\n rsa = new int[](n+1);\n lcp = new int[](n);\n }\n}\n\nint[] sais(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm, std.range;\n int n = _s.length.to!int;\n int[] sa = new int[](n+1);\n if (n == 0) return sa;\n\n auto s = _s.map!\"a+1\".array ~ T(0); B++; \n \n bool[] ls = new bool[](n+1);\n ls[n] = true;\n foreach_reverse (i; 0..n) {\n ls[i] = (s[i] == s[i+1]) ? ls[i+1] : (s[i] < s[i+1]);\n }\n \n int[] sumL = new int[](B+1), sumS = new int[](B+1); \n s.each!((i, c) => !ls[i] ? sumS[c]++ : sumL[c+1]++);\n foreach (i; 0..B) {\n sumL[i+1] += sumS[i];\n sumS[i+1] += sumL[i+1];\n }\n\n void induce(in int[] lms) {\n sa[] = -1;\n auto buf0 = sumS.dup;\n foreach (d; lms) {\n sa[buf0[s[d]]++] = d;\n }\n auto buf1 = sumL.dup;\n foreach (v; sa) {\n if (v >= 1 && !ls[v-1]) {\n sa[buf1[s[v-1]]++] = v-1;\n }\n }\n auto buf2 = sumL.dup;\n foreach_reverse (v; sa) {\n if (v >= 1 && ls[v-1]) {\n sa[--buf2[s[v-1]+1]] = v-1;\n }\n }\n }\n \n int[] lms = iota(1, n+1).filter!(i => !ls[i-1] && ls[i]).array;\n int[] lmsMap = new int[](n+1);\n lmsMap[] = -1; lms.each!((i, v) => lmsMap[v] = i.to!int);\n\n induce(lms);\n \n if (lms.length >= 2) {\n int m = lms.length.to!int - 1;\n \n auto lms2 = sa.filter!(v => lmsMap[v] != -1).array;\n int recN = 1;\n int[] recS = new int[](m);\n recS[lmsMap[lms2[1]]] = 1;\n foreach (i; 2..m+1) {\n int l = lms2[i-1], r = lms2[i];\n int nl = lms[lmsMap[l]+1], nr = lms[lmsMap[r]+1];\n if (cmp(s[l..nl+1], s[r..nr+1])) recN++;\n recS[lmsMap[lms2[i]]] = recN;\n }\n \n induce(lms.indexed(sais!int(recS, recN)).array);\n }\n\n return sa;\n}\n\n\n \nSA!T suffixArray(T)(in T[] _s, int B = 200) {\n import std.conv, std.algorithm;\n int n = _s.length.to!int;\n auto saInfo = SA!T(_s);\n if (n == 0) return saInfo;\n \n with (saInfo) {\n sa = sais(_s, B);\n \n sa.each!((i, v) => rsa[v] = i.to!int);\n \n int h = 0;\n foreach (i; 0..n) {\n int j = sa[rsa[i]-1];\n if (h > 0) h--;\n for (; j+h < n && i+h < n; h++) {\n if (s[j+h] != s[i+h]) break;\n }\n lcp[rsa[i]-1] = h;\n }\n }\n return saInfo;\n}\n\n \n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */\n// module dcomp.algorithm;\n\nimport std.range.primitives;\nimport std.traits : isFloatingPoint, isIntegral;\n\n \nT binSearch(alias pred, T)(T l, T r) if (isIntegral!T) {\n while (r-l > 1) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \nT binSearch(alias pred, T)(T l, T r, int cnt = 60) if (isFloatingPoint!T) {\n foreach (i; 0..cnt) {\n T md = (l+r)/2;\n if (!pred(md)) l = md;\n else r = md;\n }\n return r;\n}\n\n \n \n\n \nE minimum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? a : b)(seed, range);\n}\n\n \nElementType!Range minimum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return minimum!pred(range, e);\n}\n\n \n \n\n \nE maximum(alias pred = \"a < b\", Range, E = ElementType!Range)(Range range, E seed)\nif (isInputRange!Range && !isInfinite!Range) {\n import std.algorithm, std.functional;\n return reduce!((a, b) => binaryFun!pred(a, b) ? b : a)(seed, range);\n}\n\n \nElementType!Range maximum(alias pred = \"a < b\", Range)(Range range) {\n assert(!range.empty, \"range must not empty\");\n auto e = range.front; range.popFront;\n return maximum!pred(range, e);\n}\n\n \n \n\n \nRotator!Range rotator(Range)(Range r) {\n return Rotator!Range(r);\n}\n\n \nstruct Rotator(Range)\nif (isForwardRange!Range && hasLength!Range) {\n size_t cnt;\n Range start, now;\n this(Range r) {\n cnt = 0;\n start = r.save;\n now = r.save;\n }\n this(this) {\n start = start.save;\n now = now.save;\n }\n @property bool empty() {\n return now.empty;\n }\n @property auto front() {\n assert(!now.empty);\n import std.range : take, chain;\n return chain(now, start.take(cnt));\n }\n @property Rotator!Range save() {\n return this;\n }\n void popFront() {\n cnt++;\n now.popFront;\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/ascii.d */\n// module dcomp.ascii;\n\n \nstruct ASCIIString {\n string s;\n alias s this;\n this(string s) {\n this.s = s;\n }\n ref immutable(char) front() const {\n return s[0];\n }\n void popFront() {\n s = s[1..$];\n }\n ref immutable(char) back() const {\n return s[$-1];\n }\n void popBack() {\n s = s[0..$-1];\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n import core.bitop : bsf, bsr, popcnt;\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n"}], "src_uid": "a9c5516f0430f01d2d000241e5ac69ed"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n;\n n = scan!int;\n ll[] res, arr;\n auto w = scan!(dchar[]);\n w.each!(a => arr ~= to!long(a - '0'));\n ll cs = 0, ps = -1;\n for(int i = 0; i < n; ++i){\n res ~= 2 - arr[i];\n if(res[i] == 2) --res[i];\n cs = res[i]+arr[i];\n if(cs == ps){\n res[i] = !res[i];\n }\n cs = res[i]+arr[i];\n write(res[i]);\n ps = cs;\n }\n writeln;\n}\n\nvoid main(){\n long tests = 1;\n tests = scan; // Toggle!\n while(tests--) theCode();\n}\n\n/********* That's All Folks! *********/\nimport std.stdio, std.random, std.functional, std.container, std.algorithm;\nimport std.numeric, std.range, std.typecons, std.string, std.math, std.conv;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T);\r\n while (T--) {\r\n int N; get(N);\r\n char[] b; get(b);\r\n char[] a;\r\n char last;\r\n foreach (i, c; b) {\r\n switch (c) {\r\n case '0':\r\n if (last == '1') {\r\n a ~= '0';\r\n last = '0';\r\n } else {\r\n a ~= '1';\r\n last = '1';\r\n }\r\n break;\r\n case '1':\r\n if (last == '2') {\r\n a ~= '0';\r\n last = '1';\r\n } else {\r\n a ~= '1';\r\n last = '2';\r\n }\r\n break;\r\n default:\r\n }\r\n }\r\n writeln(a);\r\n }\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto s = readln.strip.map !(q{a - '0'}).array;\r\n\t\tint [] t;\r\n\t\tint prev = -1;\r\n\t\tforeach (ref c; s)\r\n\t\t{\r\n\t\t\tauto cur = (c + 1 != prev);\r\n\t\t\tt ~= cur;\r\n\t\t\tprev = c + cur;\r\n\t\t}\r\n\t\twritefln !(\"%(%s%)\") (t);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new string[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto b = RD!string;\r\n\t\t\r\n\t\tans[ti] ~= '1';\r\n\t\tlong x;\r\n\t\tif (b[0] == '1')\r\n\t\t\tx = 2;\r\n\t\telse\r\n\t\t\tx = 1;\r\n\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tif (x == 2)\r\n\t\t\t{\r\n\t\t\t\tx = 1;\r\n\t\t\t\tif (b[i] == '0')\r\n\t\t\t\t\tans[ti] ~= '1';\r\n\t\t\t\telse\r\n\t\t\t\t\tans[ti] ~= '0';\r\n\t\t\t}\r\n\t\t\telse if (x == 1)\r\n\t\t\t{\r\n\t\t\t\tif (b[i] == '0')\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] ~= '0';\r\n\t\t\t\t\tx = 0;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] ~= '1';\r\n\t\t\t\t\tx = 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tans[ti] ~= '1';\r\n\t\t\t\tif (b[i] == '0')\r\n\t\t\t\t\tx = 1;\r\n\t\t\t\telse\r\n\t\t\t\t\tx = 2;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "e27620d3a43ab42edf930b37ce214c9e"} {"source_code": "import std.stdio;\nimport std.string : split, strip;\nimport std.algorithm : map, fold;\nimport std.conv : to;\nimport std.range : enumerate;\nimport std.typecons : tuple;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n auto a = readln.strip.split.map!(to!int);\n auto d = a.enumerate.fold!((a, b) {\n if (b.index % 2 != b.value % 2) {\n a[b.index % 2]++;\n }\n return a;\n })([0, 0]);\n\n if (d[0] == d[1]) {\n writeln(d[0]);\n } else {\n writeln(-1);\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int;\n\t\tint cnt0, cnt1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i % 2 != a[i] % 2)\n\t\t\t{\n\t\t\t\tif (i % 2)\n\t\t\t\t\t++cnt1;\n\t\t\t\telse\n\t\t\t\t\t++cnt0;\n\t\t\t}\n\t\t}\n\t\tif (cnt0 != cnt1)\n\t\t{\n\t\t\tans[ti] = -1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[ti] = cnt0;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "942123e43a83d5a4cea95a6781064e28"} {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto c = ma(n, readInt!long);\n\tforeach(i, ref ci; c)\n\t{\n\t\tif (i % 2 == 0)\n\t\t{\n\t\t\tci = ci;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tci = -ci;\n\t\t}\n\t}\n\tauto psum = new long[](n + 1);\n\tpsum[0] = 0;\n\tforeach(i, ci; c)\n\t{\n\t\tpsum[i+1] = psum[i] + ci;\n\t}\n\tauto psumMin = Sparse!(long, min, \"min\")(psum);\n\tlong ways = 0;\n\tvoid countFor(int i, int j)\n\t{\n\t\tassert(i < j);\n\t\tassert(i % 2 == 0 && j % 2 == 1);\n\t\tif (j == i + 1)\n\t\t{\n\t\t\tassert(c[i] > 0 && -c[j] > 0);\n\t\t\tways += min(c[i], -c[j]);\n\t\t\treturn;\n\t\t}\n\t\tauto pi = psum[i+1];\n\t\tauto mr = psumMin[i+2..j+1].min - pi;\n\t\tauto rqOpen = max(0, -mr);\n\t\tif (rqOpen > c[i]) return;\n\t\tauto rqClose = psum[j] - psum[i+1] + rqOpen;\n\t\tassert(rqClose >= 0);\n\t\t// open >= rqOpen\n\t\t// open <= c[i]\n\t\t// open + psum[j] - psum[i+1] <= -c[j]\n\t\t// rqOpen <= open <= min(c[i], -c[j] - psum[j] + psum[i+1])\n\t\tauto low = rqOpen;\n\t\tauto high = min(c[i], -c[j]-psum[j]+psum[i+1]);\n\t\tif (low > high) return;\n\t\tways += high - low + 1;\n\t}\n\tforeach(i; 0 .. n)\n\t{\n\t\tforeach(j; i + 1 .. n)\n\t\t{\n\t\t\tif (i % 2 == 0 && j % 2 == 1)\n\t\t\t\tcountFor(i, j);\n\t\t}\n\t}\n\tways.writeln;\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n\n// sparse table V, f, fName {{{\nstruct Sparse(V, alias f, string fName = \"value\")\n{\n\timport std.math : log2;\n\tV[][] _table;\n\tint[] maxPow;\n\tthis(V[] values)\n\t{\n\t\tauto n = values.length;\n\t\tmaxPow = new int[](n + 1);\n\t\tmaxPow[0] = int.min;\n\t\tmaxPow[1] = 0;\n\t\tforeach(i; 2 .. n + 1)\n\t\t{\n\t\t\tint prev = maxPow[i - 1];\n\t\t\tmaxPow[i] = prev;\n\t\t\tprev = (1 << prev);\n\t\t\tif (prev * 2 <= i) maxPow[i]++;\n\t\t}\n\t\t_table = new V[][](maxPow[n] + 1, n);\n\t\t_table[0][] = values[];\n\n\t\tforeach(p; 1 .. maxPow[n] + 1)\n\t\tforeach(i; 0 .. n - (1<<p) + 1)\n\t\t\t_table[p][i] = f(_table[p-1][i], _table[p-1][i+(1<<(p-1))]);\n\t}\n\tint[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)\n\t{\n\t\treturn [cast(int)start, cast(int)end];\n\t}\n\tauto opIndex(int[2] slice)\n\t{\n\t\tint sliceLen = slice[1] - slice[0];\n\t\tauto x = maxPow[sliceLen];\n\t\tauto twoX = (1 << x);\n\t\tauto p1 = _table[x][slice[0]];\n\t\tauto p2 = _table[x][slice[1] - twoX];\n\t\tstruct Ans\n\t\t{\n\t\t\tmixin(q{V }, fName, q{;});\n\t\t}\n\t\treturn Ans(f(p1, p2));\n\t}\n}\n\nunittest\n{\n\timport std.algorithm;\n\timport std.stdio;\n\talias MinQ = Sparse!(int, min, \"min\");\n\twriteln(\"testing\");\n\tint[] array = [1, 2, 3, 4, -2, -2, -3, 0, 10];\n\tauto minQ = MinQ(array); \n\tforeach(i; 0 .. array.length)\n\t{\n\t\tforeach(j; i + 1 .. array.length + 1)\n\t\t{\n\t\t\tassert(minQ[i .. j].min == array[i .. j].fold!min);\n\t\t}\n\t}\n}\n// }}}\n", "positive_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto c = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\tint [long] pos;\r\n\t\tlong balance = 0;\r\n\t\tpos[balance] = 0;\r\n\t\tforeach (int i, num; c)\r\n\t\t{\r\n\t\t\tbalance += num * ((i & 1) ? -1 : +1);\r\n\t\t\tpos[balance] = int.max;\r\n\t\t}\r\n\t\tauto posToSort = pos.byKey.array;\r\n\t\tsort (posToSort);\r\n\t\tforeach (int k, long v; posToSort)\r\n\t\t{\r\n\t\t\tpos[v] = k;\r\n\t\t}\r\n\t\tdebug {writeln (posToSort);}\r\n\r\n\t\tauto value = new long [pos.length];\r\n\t\tlong res = 0;\r\n\t\tbalance = 0;\r\n\t\tforeach (int i, num; c)\r\n\t\t{\r\n\t\t\tauto oldBalance = balance;\r\n\t\t\tbalance += num * ((i & 1) ? -1 : +1);\r\n\t\t\tauto oldPos = pos[oldBalance];\r\n\t\t\tauto newPos = pos[balance];\r\n\t\t\twhile (oldPos < newPos)\r\n\t\t\t{\r\n\t\t\t\tvalue[oldPos] += 1;\r\n\t\t\t\toldPos += 1;\r\n\t\t\t}\r\n\t\t\twhile (oldPos > newPos)\r\n\t\t\t{\r\n\t\t\t\tauto len = (posToSort[oldPos] -\r\n\t\t\t\t posToSort[oldPos - 1]);\r\n\t\t\t\tvalue[oldPos] = 0;\r\n\t\t\t\toldPos -= 1;\r\n\t\t\t\tres += value[oldPos] +\r\n\t\t\t\t ((value[oldPos] > 0) ? (len - 1) : 0);\r\n\t\t\t}\r\n\t\t\tdebug {writeln (value, \" \", res, \" \", balance);}\r\n\t\t}\r\n\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto c = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\tint [long] pos;\r\n\t\tlong balance = 0;\r\n\t\tpos[balance] = 0;\r\n\t\tforeach (int i, num; c)\r\n\t\t{\r\n\t\t\tbalance += num * ((i & 1) ? -1 : +1);\r\n\t\t\tpos[balance] = int.max;\r\n\t\t}\r\n\t\tauto posToSort = pos.byKey.array;\r\n\t\tsort (posToSort);\r\n\t\tforeach (int k, long v; posToSort)\r\n\t\t{\r\n\t\t\tpos[v] = k;\r\n\t\t}\r\n\t\tdebug {writeln (posToSort);}\r\n\r\n\t\tauto value = new long [pos.length];\r\n\t\tlong res = 0;\r\n\t\tbalance = 0;\r\n\t\tforeach (int i, num; c)\r\n\t\t{\r\n\t\t\tauto oldBalance = balance;\r\n\t\t\tbalance += num * ((i & 1) ? -1 : +1);\r\n\t\t\tauto oldPos = pos[oldBalance];\r\n\t\t\tauto newPos = pos[balance];\r\n\t\t\twhile (oldPos < newPos)\r\n\t\t\t{\r\n\t\t\t\tvalue[oldPos] += 1;\r\n\t\t\t\toldPos += 1;\r\n\t\t\t}\r\n\t\t\twhile (oldPos > newPos)\r\n\t\t\t{\r\n\t\t\t\tauto len = (posToSort[oldPos] -\r\n\t\t\t\t posToSort[oldPos - 1]);\r\n\t\t\t\tvalue[oldPos] = 0;\r\n\t\t\t\toldPos -= 1;\r\n\t\t\t\tres += value[oldPos] +\r\n\t\t\t\t (value[oldPos > 0] ? (len - 1) : 0);\r\n\t\t\t}\r\n\t\t\tdebug {writeln (value, \" \", res, \" \", balance);}\r\n\t\t}\r\n\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto c = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\tint [long] pos;\r\n\t\tlong balance = 0;\r\n\t\tpos[balance] = 0;\r\n\t\tforeach (int i, num; c)\r\n\t\t{\r\n\t\t\tbalance += num * ((i & 1) ? -1 : +1);\r\n\t\t\tpos[balance] = int.max;\r\n\t\t}\r\n\t\tauto posToSort = pos.byKey.array;\r\n\t\tsort (posToSort);\r\n\t\tforeach (int k, long v; posToSort)\r\n\t\t{\r\n\t\t\tpos[v] = k;\r\n\t\t}\r\n\t\tdebug {writeln (posToSort);}\r\n\r\n\t\tauto value = new long [pos.length];\r\n\t\tlong res = 0;\r\n\t\tbalance = 0;\r\n\t\tforeach (int i, num; c)\r\n\t\t{\r\n\t\t\tauto oldBalance = balance;\r\n\t\t\tbalance += num * ((i & 1) ? -1 : +1);\r\n\t\t\tauto oldPos = pos[oldBalance];\r\n\t\t\tauto newPos = pos[balance];\r\n\t\t\twhile (oldPos < newPos)\r\n\t\t\t{\r\n\t\t\t\tvalue[oldPos] += 1;\r\n\t\t\t\toldPos += 1;\r\n\t\t\t}\r\n\t\t\twhile (oldPos > newPos)\r\n\t\t\t{\r\n\t\t\t\tauto len = (posToSort[oldPos] -\r\n\t\t\t\t posToSort[oldPos - 1]);\r\n\t\t\t\tvalue[oldPos] = 0;\r\n\t\t\t\toldPos -= 1;\r\n\t\t\t\tres += value[oldPos] + len - 1;\r\n\t\t\t}\r\n\t\t\tdebug {writeln (value, \" \", res, \" \", balance);}\r\n\t\t}\r\n\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto c = readln.splitter.map !(to !(long)).array;\r\n\r\n\t\tint [long] pos;\r\n\t\tlong balance = 0;\r\n\t\tpos[balance] = 0;\r\n\t\tforeach (int i, num; c)\r\n\t\t{\r\n\t\t\tbalance += num * ((i & 1) ? -1 : +1);\r\n\t\t\tpos[balance] = int.max;\r\n\t\t}\r\n\t\tauto posToSort = pos.byKey.array;\r\n\t\tsort (posToSort);\r\n\t\tforeach (int k, long v; posToSort)\r\n\t\t{\r\n\t\t\tpos[v] = k;\r\n\t\t}\r\n\t\tdebug {writeln (posToSort);}\r\n\r\n\t\tauto value = new long [pos.length];\r\n\t\tlong res = 0;\r\n\t\tbalance = 0;\r\n\t\tforeach (int i, num; c)\r\n\t\t{\r\n\t\t\tauto oldBalance = balance;\r\n\t\t\tbalance += num * ((i & 1) ? -1 : +1);\r\n\t\t\tauto oldPos = pos[oldBalance];\r\n\t\t\tauto newPos = pos[balance];\r\n\t\t\twhile (oldPos < newPos)\r\n\t\t\t{\r\n\t\t\t\tvalue[oldPos] += 1;\r\n\t\t\t\toldPos += 1;\r\n\t\t\t}\r\n\t\t\twhile (oldPos > newPos)\r\n\t\t\t{\r\n\t\t\t\tauto len = (posToSort[oldPos] -\r\n\t\t\t\t posToSort[oldPos - 1]);\r\n\t\t\t\tvalue[oldPos] = 0;\r\n\t\t\t\toldPos -= 1;\r\n\t\t\t\tres += value[oldPos] * len;\r\n\t\t\t}\r\n\t\t\tdebug {writeln (value, \" \", res, \" \", balance);}\r\n\t\t}\r\n\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "src_uid": "ca4ae2484800a98b5592ae65cd45b67f"} {"source_code": "import std.stdio;\r\nimport std.math;\r\nimport std.numeric;\r\nimport std.container;\r\nimport std.typecons;\r\nimport core.stdc.stdio : scanf;\r\nimport std.conv;\r\nimport std.array;\r\nimport std.string;\r\nimport std.range;\r\nimport std.algorithm;\r\n\r\nT read(T)() { return readln.chomp.to!T; }\r\nT[] readarray(T)() { return readln.chomp.split(\" \").map!(to!T).array; }\r\n\r\nvoid solve() {\r\n int N, Q; readf(\"%d %d\\n\", &N, &Q);\r\n auto A = readarray!int;\r\n auto K = readarray!int;\r\n\r\n auto S = new int[N + 1];\r\n auto AS = new long[N + 1];\r\n for (int i = 0; i < N; i++) {\r\n S[i + 1] = max(S[i], A[i]);\r\n AS[i + 1] = AS[i] + A[i];\r\n }\r\n\r\n int[] ans;\r\n foreach (q; 0 .. Q) {\r\n int k = K[q];\r\n int lb = 0, ub = N;\r\n bool C(int x) {\r\n return S[x] <= k;\r\n }\r\n if (C(ub)) {\r\n ans ~= ub;\r\n } else {\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? lb : ub) = mid;\r\n }\r\n ans ~= lb;\r\n }\r\n }\r\n writefln(\"%(%s %)\", ans.map!(i => AS[i]).array);\r\n}\r\n\r\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int n, q;\n readf!\" %d %d \"(n, q);\n auto a = readln.splitter.map!(to!long).array;\n auto qarr = readln.splitter.map!(to!long).array;\n long[] maxa;\n long[] suma;\n long m = 0;\n long sum = 0;\n suma ~= 0;\n foreach (x ; a) {\n m = max(m, x);\n maxa ~= m;\n sum += x;\n suma ~= sum;\n }\n writefln(\"%(%s %)\", qarr.map!(k => suma[maxa.assumeSorted.lowerBound(k + 1).length]));\n }\n}\n"}], "negative_code": [], "src_uid": "d5f7228d8d674b8233937702ca044cb0"} {"source_code": "import std.stdio;\nimport std.string;\nimport core.stdc.stdio;\nimport std.math;\nimport std.algorithm;\n\nclass Vec3\n{\n\tpublic int x, y, z;\n\tpublic this()\n\t{\n\t}\n\n\tpublic this(int x, int y, int z)\n\t{\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.z = z;\n\t}\n\n\tpublic Vec3 opBinary(string op)(Vec3 rhs)\n\t{\n\t\tstatic if (op == \"+\") return new Vec3(x + rhs.x, y + rhs.y, z + rhs.z);\n\t\telse static assert(0, \"Operator \"~op~\" not implemented\");\n\t}\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tVec3 sum = new Vec3();\n\tforeach (int i; 0..n)\n\t{\n\t\tVec3 v = new Vec3();\n\t\tscanf(\"%d %d %d\", &(v.x), &(v.y), &(v.z));\n\t\tsum = sum + v;\n\t}\n\tbool condition = (sum.x == 0 && sum.y == 0 && sum.z == 0);\n\tprintf(condition ? \"YES\" : \"NO\");\n\treturn 0;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm, std.conv;\n\nvoid main() {\n int n;\n readf(\"%s\\n\", &n);\n\n int[3] total;\n foreach(_; 0..n)\n total[] += to!(int[])(readln.split)[];\n\n if(any(total[]))\n writeln(\"NO\");\n else\n writeln(\"YES\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\n\tint[] coord = [ 0, 0, 0 ];\n\tfor (int i = 0; i < n; i++) {\n\t\tint[] row = readln.chomp.split.map!(to!int).array;\n\t\tcoord[] += row[];\n\t}\n\n\tif (coord.all!(\"a == 0\")) {\n\t\t\"YES\".writeln;\n\t} else {\n\t\t\"NO\".writeln;\n\t}\n}\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nmodule Solution;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n auto a = new int[3];\n foreach (tid; 0 .. n) {\n auto b = r.nextA!int (3);\n a[] += b[];\n }\n writeln (a.all!(i => i == 0) ? \"YES\" : \"NO\");\n}\n\n"}], "negative_code": [], "src_uid": "8ea24f3339b2ec67a769243dc68a47b2"} {"source_code": "import std.algorithm;\nimport std.c.stdio;\nimport std.stdio;\nimport std.conv;\n\nint curc;\nbool eof = false;\n\nvoid sb()\n{\n do\n {\n curc = getchar ();\n }\n while (0 <= curc && curc <= 32);\n if (curc == EOF)\n {\n eof = true;\n }\n}\n\nchar rc ()\n{\n sb ();\n return cast (char) curc;\n}\n\nint ni ()\n{\n sb ();\n int res = 0;\n do\n {\n res = res * 10 + cast (int) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nchar[] ns ()\n{\n sb ();\n char[] res = [];\n do\n {\n res ~= to!char(curc);\n curc = getchar ();\n }\n while (32 < curc);\n return res;\n}\n\nvoid CFBETA142A()\n{\n class Tuple\n {\n int x, y;\n this(int x, int y)\n {\n this.x = x;\n this.y = y;\n }\n override string toString()\n {\n return to!string(this.x) ~ \" \" ~ to!string(this.y);\n }\n }\n\n auto s = ni();\n auto n = ni();\n bool ans = true;\n Tuple[] t = new Tuple[n];\n for (int i=0; i<n; ++i)\n t[i] = new Tuple(ni(), ni());\n sort!(\"a.x<b.x\")(t);\n //write(t);\n int cursum = s;\n for (int i=0; i<n; ++i)\n if (t[i].x>=cursum) ans = false;\n else cursum+=t[i].y;\n printf(ans?\"YES\":\"NO\");\n}\n\nvoid main()\n{\n CFBETA142A();\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm , std.regex, std.conv, std.array;\n\nvoid main()\n{\n const auto readints = \"stdin.readln.strip.split().map!(to!int).array\"; \n mixin(\"auto sn =\"~readints~\";\"); \n auto s=sn[0], n=sn[1];\n int[][] xys;\n foreach(i; 0..n) xys ~= [mixin(readints)];\n xys.sort!((a, b) => a[0] < b[0]);\n foreach (xy;xys){\n if (s<=xy[0]) { writeln(\"NO\"); return;} \n s+=xy[1];\n }\n writeln(\"YES\");\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;\nimport std.uni, std.math, std.container, std.typecons, std.typetuple;\nimport core.bitop, std.datetime;\n\nimmutable int mod = 10^^9 + 7;\n\nvoid main(){\n int s, n;\n readVars(s, n);\n auto x = new int[](n);\n auto y = new int[](n);\n\n foreach(i ; 0 .. n){\n readVars(x[i], y[i]);\n }\n\n sort(zip(x, y));\n\n //writeln(x);\n //writeln(y);\n\n foreach(i ; 0 .. n){\n if (s <= x[i]) {\n writeln(\"NO\");\n return;\n }\n\n s += y[i];\n }\n\n writeln(\"YES\");\n}\n\n\nvoid readVars(T...)(auto ref T args){\n auto line = readln.split;\n foreach(ref arg ; args){\n arg = line.front.to!(typeof(arg));\n line.popFront;\n }\n if(!line.empty){\n writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\n\nstruct Dragon\n{\n\tint health;\n\tint gain;\n}\n\nint main(string[] argv)\n{\n\tint s, n;\n\tscanf(\"%d %d\", &s, &n);\n\tDragon[] dragons = new Dragon[n];\n\tforeach (int i; 0..n)\n\t{\n\t\tint x, y;\n\t\tscanf(\"%d %d\", &x, &y);\n\t\tdragons[i].health = x;\n\t\tdragons[i].gain = y;\n\t}\n\tdragons.sort!(\"a.health < b.health\");\n\tforeach (int i; 0..n)\n\t{\n\t\tif (s > dragons[i].health)\n\t\t{\n\t\t\ts += dragons[i].gain;\n\t\t} else {\n\t\t\twrite(\"NO\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\twrite(\"YES\");\n\treturn 0;\n}\n"}], "negative_code": [{"source_code": "// ab.d\n\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.regex;\nimport std.range;\nimport std.conv;\nimport std.array;\n\nvoid main()\n{\n const auto readints = \"stdin.readln.strip.split(regex(` +`)).map!(to!int).array\"; \n mixin(\"auto sn =\"~readints~\";\"); \n auto s=sn[0], n=sn[1];\n int[][] xys;\n foreach(i; 0..n) xys ~= [mixin(readints)];\n xys.sort!((a, b) => a[0] < b[0]);\n foreach (xy;xys){\n //writeln(xy);\n //s-=xy[0];\n if (s<0) {\n writeln(\"NO\");\n return;\n } \n s+=xy[1];\n }\n writeln(\"YES\");\n}"}, {"source_code": "// ab.d\n\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.regex;\nimport std.range;\nimport std.conv;\nimport std.array;\n\nvoid main()\n{\n const auto readints = \"stdin.readln.strip.split(regex(` +`)).map!(to!int).array\"; \n mixin(\"auto sn =\"~readints~\";\"); \n auto s=sn[0], n=sn[1];\n int[][] xys;\n foreach(i; 0..n) xys ~= [mixin(readints)];\n xys.sort!((a, b) => a[0] < b[0]);\n foreach (xy;xys){\n s-=xy[0];\n if (s<0) {\n writeln(\"NO\");\n return;\n } \n s+=xy[1];\n }\n writeln(\"YES\");\n}"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip;\nimport std.algorithm.iteration : map;\nimport std.regex;\nimport std.range;\nimport std.conv;\n\nvoid main()\n{\n auto sn = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto s=sn[0], n=sn[1];\n \n for(int i = 1; i <= n; i++) {\n auto xy = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n s-=xy[0];\n if (s<0) {\n writeln(\"NO\");\n return;\n } \n s+=xy[1];\n }\n writeln(\"YES\");\n}"}, {"source_code": "// ab.d\n\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.regex;\nimport std.range;\nimport std.conv;\nimport std.array;\n\nvoid main()\n{\n const auto readints = \"stdin.readln.strip.split(regex(` +`)).map!(to!int).array\"; \n mixin(\"auto sn =\"~readints~\";\"); \n auto s=sn[0], n=sn[1];\n int[][] xys;\n foreach(i; 0..n) xys ~= [mixin(readints)];\n xys.sort!((a, b) => a[0] < b[0]);\n foreach (xy;xys){\n //writeln(xy);\n //s-=xy[0];\n if (s<xy[0]) {\n writeln(\"NO\");\n return;\n } \n s+=xy[1];\n }\n writeln(\"YES\");\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\n\nstruct Dragon\n{\n\tint health;\n\tint gain;\n}\n\nint main(string[] argv)\n{\n\tint s, n;\n\tscanf(\"%d %d\", &s, &n);\n\tDragon[] dragons = new Dragon[n];\n\tforeach (int i; 0..n)\n\t{\n\t\tint x, y;\n\t\tscanf(\"%d %d\", &x, &y);\n\t\tdragons[i].health = x;\n\t\tdragons[i].gain = y;\n\t}\n\tdragons.sort!(\"a.health < b.health\");\n\tforeach (int i; 0..n)\n\t{\n\t\tif (s >= dragons[i].health)\n\t\t{\n\t\t\ts += dragons[i].gain;\n\t\t} else {\n\t\t\twrite(\"NO\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\twrite(\"YES\");\n\treturn 0;\n}\n"}], "src_uid": "98f5b6aac08f48f95b2a8ce0738de657"} {"source_code": "/+ dub.sdl:\n name \"E\"\n dependency \"dunkelheit\" version=\"1.0.1\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner, dkh.graph.maxflow;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n, m;\n sc.read(n, m);\n\n int[] x1 = new int[m];\n int[] x2 = new int[m];\n int[] y1 = new int[m];\n int[] y2 = new int[m];\n foreach (i; 0..m) {\n sc.read(x1[i], y1[i], x2[i], y2[i]);\n x2[i]++; y2[i]++;\n }\n\n int[] xv = x1 ~ x2 ~ [0];\n int[] yv = y1 ~ y2 ~ [0];\n\n xv = xv.sort.uniq.array;\n yv = yv.sort.uniq.array;\n\n int getX(int x) {\n return xv.assumeSorted.lowerBound(x).length.to!int;\n }\n int getY(int y) {\n return yv.assumeSorted.lowerBound(y).length.to!int;\n }\n\n int w = xv.length.to!int - 1;\n int h = yv.length.to!int - 1;\n\n bool[][] mp = new bool[][](h, w);\n foreach (i; 0..m) {\n int l = getX(x1[i]), r = getX(x2[i]);\n int d = getY(y1[i]), u = getY(y2[i]);\n\n foreach (x; l..r) {\n foreach (y; d..u) {\n mp[y][x] = true;\n }\n }\n }\n\n struct Edge {\n int to, rev;\n long cap;\n }\n\n void addEdge(Edge[][] g, int from, int to, long cap) {\n g[from] ~= Edge(to, g[to].length.to!int, cap);\n g[to] ~= Edge(from, g[from].length.to!int-1, 0);\n }\n\n auto g = new Edge[][](1 + w + h + 1);\n int sv = w + h, tv = sv + 1;\n\n foreach (i; 0..w) {\n addEdge(g, sv, i, xv[i + 1] - xv[i]);\n }\n foreach (i; 0..h) {\n addEdge(g, w + i, tv, yv[i + 1] - yv[i]);\n }\n\n foreach (i; 0..w) {\n foreach (j; 0..h) {\n if (mp[j][i]) {\n addEdge(g, i, w + j, 10L^^18);\n }\n }\n }\n\n writeln(maxFlow!(long, 0)(g, sv, tv).flow);\n\n return 0;\n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/deque.d */\n// module dkh.container.deque;\n\nstruct DequePayload(T) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint start, len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n if (start + i < cap) return _data[start + i];\n else return _data[start + i - cap];\n }\n ref inout(T) front() inout { return this[0]; }\n ref inout(T) back() inout { return this[$-1]; }\n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import std.algorithm : max;\n import std.conv : to;\n if (newCap <= cap) return;\n T* newData = cast(T*)GC.malloc(newCap * T.sizeof);\n foreach (i; 0..length) {\n newData[i] = this[i];\n }\n _data = newData; start = 0; cap = newCap.to!uint;\n }\n void clear() {\n start = len = 0;\n }\n import std.algorithm : max;\n void insertFront(T item) {\n if (len == cap) reserve(max(cap * 2, 4));\n if (start == 0) start += cap;\n start--; len++;\n this[0] = item;\n }\n void insertBack(T item) {\n if (len == cap) reserve(max(cap * 2, 4));\n len++;\n this[len-1] = item;\n }\n void removeFront() {\n assert(!empty, \"Deque.removeFront: Deque is empty\");\n start++; len--;\n if (start == cap) start = 0;\n }\n void removeBack() {\n assert(!empty, \"Deque.removeBack: Deque is empty\"); \n len--;\n }\n}\n\n \nstruct Deque(T, bool mayNull = true) {\n import core.exception : RangeError;\n import std.range : ElementType, isInputRange;\n import std.traits : isImplicitlyConvertible;\n\n alias Payload = DequePayload!T;\n Payload* _p;\n \n static if (!mayNull) @disable this();\n\n \n this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {\n _p = new Payload();\n foreach (v; values) {\n insertBack(v);\n }\n }\n \n this(Range)(Range r)\n if (isInputRange!Range &&\n isImplicitlyConvertible!(ElementType!Range, T) &&\n !is(Range == T[])) {\n _p = new Payload();\n foreach (v; r) {\n insertBack(v);\n }\n }\n private this(Payload* p) { _p = p; }\n static Deque make() { return Deque(new Payload()); }\n \n private bool havePayload() const { return (!mayNull || _p); } \n @property bool empty() const { return (!havePayload || _p.empty); } \n @property size_t length() const { return (havePayload ? _p.length : 0); } \n alias opDollar = length; \n\n ref inout(T) opIndex(size_t i) inout {\n assert(!empty, \"Deque.opIndex: Deque is empty\");\n return (*_p)[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void clear() { if (_p) _p.clear(); } \n\n \n void insertFront(T item) {\n if (mayNull && !_p) _p = new Payload();\n _p.insertFront(item);\n }\n void insertBack(T item) {\n if (mayNull && !_p) _p = new Payload();\n _p.insertBack(item);\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n alias stableInsertBack = insertBack; \n\n \n void removeFront() {\n assert(!mayNull || _p, \"Deque.removeFront: Deque is empty\");\n _p.removeFront();\n }\n void removeBack() {\n assert(!mayNull || _p, \"Deque.removeBack: Deque is empty\");\n _p.removeBack();\n } \n alias stableRemoveBack = removeBack; \n\n \n alias Range = RangeT!(DequePayload!T);\n alias ConstRange = RangeT!(const DequePayload!T); \n alias ImmutableRange = RangeT!(immutable DequePayload!T); \n\n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {\n assert(start <= end && end <= length);\n return [start, end];\n } \n Range opIndex(size_t[2] rng) { return Range(_p, rng[0], rng[1]); } \n ConstRange opIndex(size_t[2] rng) const { return ConstRange(_p, rng[0], rng[1]); } \n ImmutableRange opIndex(size_t[2] rng) immutable { return ImmutableRange(_p, rng[0], rng[1]); } \n auto opIndex() inout { return this[0..$]; } \n\n static struct RangeT(QualifiedPayload) {\n alias A = QualifiedPayload;\n import std.traits : CopyTypeQualifiers;\n alias E = CopyTypeQualifiers!(A, T);\n A *p;\n size_t l, r;\n\n @property bool empty() const { return r <= l; }\n @property size_t length() const { return r - l; }\n alias opDollar = length;\n\n @property auto save() { return this; }\n \n ref inout(E) opIndex(size_t i) inout {\n version(assert) if (empty) throw new RangeError();\n return (*p)[l+i];\n }\n @property ref inout(E) front() inout { return this[0]; }\n @property ref inout(E) back() inout { return this[$-1]; }\n\n void popFront() {\n version(assert) if (empty) throw new RangeError();\n l++;\n }\n void popBack() {\n version(assert) if (empty) throw new RangeError();\n r--;\n }\n \n size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {\n assert(start <= end && end <= length);\n return [start, end];\n }\n auto opIndex(size_t[2] rng) { return RangeT(p, l+rng[0], l+rng[1]); }\n auto opIndex(size_t[2] rng) const { return RangeT!(const A)(p, l+rng[0], l+rng[1]); }\n auto opIndex(size_t[2] rng) immutable { return RangeT!(immutable A)(p, l+rng[0], l+rng[1]); }\n auto opIndex() inout { return this[0..$]; }\n } \n}\n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/graph/maxflow.d */\n// module dkh.graph.maxflow;\n\n// import dkh.container.deque;\n\n \nstruct MaxFlowInfo(C) {\n C flow; \n bool[] dual; \n}\n\n \nMaxFlowInfo!(C) maxFlow(C, C EPS, T)(T g, size_t s, size_t t, C gap = C.max) {\n assert(s != t);\n import std.conv : to;\n int[] level = new int[g.length];\n int[] iter = new int[g.length];\n\n void bfs() {\n level[] = -1; level[s] = 0;\n auto que = Deque!int();\n que.insertBack(s.to!int);\n while (!que.empty) {\n int v = que.front; que.removeFront;\n foreach (e; g[v]) {\n if (e.cap <= EPS) continue;\n if (level[e.to] < 0) {\n level[e.to] = level[v] + 1;\n que.insertBack(e.to);\n }\n }\n }\n }\n\n C dfs(int v, C f) {\n import std.algorithm : min;\n if (v == t) return f;\n C res = 0;\n auto edgeList = g[v][iter[v]..$];\n foreach (ref e; edgeList) {\n if (e.cap <= EPS) continue;\n if (level[v] >= level[e.to]) continue; \n C d = dfs(e.to, min(f, e.cap));\n e.cap -= d;\n g[e.to][e.rev].cap += d;\n res += d;\n f -= d;\n if (f == 0) break;\n iter[v]++;\n }\n return res;\n }\n\n C flow = 0;\n while (gap - flow > EPS) {\n bfs();\n if (level[t] < 0) break;\n iter[] = 0;\n while (true) {\n C f = dfs(s.to!int, gap - flow);\n if (!f) break;\n flow += f;\n }\n }\n\n import std.algorithm : map;\n import std.range : array;\n auto mfInfo = MaxFlowInfo!C();\n mfInfo.flow = flow;\n mfInfo.dual = level.map!\"a == -1\".array;\n return mfInfo;\n}\n\n \n \n\nMaxFlowInfo!(C) maxFlowSlow(C, T)(T g, int s, int t, C gap = C.max) {\n assert(s != t);\n import std.algorithm : map;\n import std.range : array;\n import std.conv : to;\n auto n = g.length;\n\n bool[] used = new bool[n];\n bool dfs(int v) {\n if (v == t) return true;\n used[v] = true;\n foreach (ref e; g[v]) {\n if (used[e.to]) continue;\n if (!e.cap) continue;\n if (dfs(e.to)) {\n e.cap -= 1;\n g[e.to][e.rev].cap += 1;\n return true;\n }\n }\n return false;\n }\n \n C flow = 0;\n while (flow < gap) {\n used[] = false;\n if (!dfs(s)) break;\n flow++;\n }\n auto mfInfo = MaxFlowInfo!C();\n mfInfo.flow = flow;\n mfInfo.dual = used.map!\"!a\".array;\n return mfInfo;\n}\n\n \n\n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n private File f;\n \n this(File f) {\n this.f = f;\n }\n private char[512] lineBuf;\n private char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n assert(succW());\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n \n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n \n void read(Args...)(auto ref Args args) {\n import std.exception : enforce;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n \n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nclass MaxFlow(Capa) {\n enum Capa wEPS = 0;\n enum Capa wINF = 10L^^18;\n int n, m;\n int[][] g;\n int[] zu;\n Capa[] capa;\n Capa tof;\n int[] lev, see, que;\n this(int n) {\n this.n = n; m = 0; g = new int[][n]; zu = []; capa = [];\n lev = new int[n]; see = new int[n]; que = new int[n];\n }\n void addEdge(int u, int v, Capa w0, Capa w1 = 0) {\n g[u] ~= m; zu ~= v; capa ~= w0; ++m;\n g[v] ~= m; zu ~= u; capa ~= w1; ++m;\n }\n Capa augment(int src, int ink, Capa flo) {\n if (src == ink) return flo;\n foreach (i; g[src][see[src] .. $]) {\n if (capa[i] > wEPS && lev[src] < lev[zu[i]]) {\n Capa f = augment(zu[i], ink, min(flo, capa[i]));\n if (f > wEPS) { capa[i] -= f; capa[i ^ 1] += f; return f; }\n }\n ++see[src];\n }\n return 0;\n }\n bool dinic(int src, int ink, Capa flo = wINF) {\n for (tof = 0; tof + wEPS < flo; ) {\n int[] q;\n lev[] = -1;\n dinicBFS:\n for (lev[src] = 0, q ~= src; !q.empty; ) {\n int u = q.front; q.popFront;\n foreach (i; g[u]) {\n int v = zu[i];\n if (capa[i] > wEPS && lev[v] == -1) {\n lev[v] = lev[u] + 1; q ~= v;\n if (v == ink) break dinicBFS;\n }\n }\n }\n if (lev[ink] == -1) return false;\n see[] = 0;\n for (; ; ) {\n Capa f = augment(src, ink, flo - tof);\n if (f <= wEPS) break;\n tof += f;\n }\n }\n return true;\n }\n}\n\n\nlong N;\nint M;\nlong[] XA, YA, XB, YB;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readLong();\n M = readInt();\n XA = new long[M];\n YA = new long[M];\n XB = new long[M];\n YB = new long[M];\n foreach (i; 0 .. M) {\n XA[i] = readLong() - 1;\n YA[i] = readLong() - 1;\n XB[i] = readLong();\n YB[i] = readLong();\n }\n \n auto xs = [0L, N] ~ XA.dup ~ XB.dup;\n auto ys = [0L, N] ~ YA.dup ~ YB.dup;\n xs = xs.sort.uniq.array;\n ys = ys.sort.uniq.array;\n const H = cast(int)(xs.length) - 1;\n const W = cast(int)(xs.length) - 1;\n auto board = new bool[][](H, W);\n foreach (i; 0 .. M) {\n const ea = xs.lowerBound(XA[i]);\n const fa = ys.lowerBound(YA[i]);\n const eb = xs.lowerBound(XB[i]);\n const fb = ys.lowerBound(YB[i]);\n foreach (e; ea .. eb) foreach (f; fa .. fb) {\n board[e][f] = true;\n }\n }\n debug {\n writeln(\"xs = \", xs);\n writeln(\"ys = \", ys);\n foreach (e; 0 .. H) {\n foreach (f; 0 .. W) {\n write(board[e][f] ? '#' : '.');\n }\n writeln();\n }\n }\n \n auto mf = new MaxFlow!long(2 + H + W);\n foreach (e; 0 .. H) {\n mf.addEdge(0, 2 + e, xs[e + 1] - xs[e]);\n }\n foreach (f; 0 .. W) {\n mf.addEdge(2 + H + f, 1, ys[f + 1] - ys[f]);\n }\n foreach (e; 0 .. H) foreach (f; 0 .. W) {\n if (board[e][f]) {\n mf.addEdge(2 + e, 2 + H + f, MaxFlow!long.wINF);\n }\n }\n mf.dinic(0, 1);\n writeln(mf.tof);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "3fba1fbbcb6ef38a446de1b0565dccc2"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\trndGen.seed (1235);\n\t\tauto h = new ulong [n];\n\t\tforeach (ref c; h)\n\t\t{\n\t\t\tc = uniform (1, ulong.max);\n\t\t}\n\n\t\talias Segment = Tuple !(int, q{lo}, int, q{hi});\n\t\tauto a = new Segment [n];\n\t\tauto b = new Segment [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %s %s %s %s\")\n\t\t\t (a[i].lo, a[i].hi, b[i].lo, b[i].hi);\n\t\t}\n\t\tlong res = 0;\n\n\t\talias Event = Tuple !(int, q{pos}, int, q{id});\n\n\t\tulong [] calc (const ref Segment [] a)\n\t\t{\n\t\t\tEvent [] events;\n\t\t\tforeach (i, const ref s; a)\n\t\t\t{\n\t\t\t\tevents ~= Event (s.lo * 2 + 0, i.to !(int));\n\t\t\t\tevents ~= Event (s.hi * 2 + 1, i.to !(int));\n\t\t\t}\n\t\t\tsort (events);\n\n\t\t\tauto mark = new ulong [n];\n\t\t\tauto rem = new ulong [n];\n\t\t\tulong addCur = 0;\n\t\t\tulong remCur = 0;\n\t\t\tforeach (const ref e; events)\n\t\t\t{\n\t\t\t\tbool isAdd = !(e.pos & 1);\n\t\t\t\tif (isAdd)\n\t\t\t\t{\n\t\t\t\t\taddCur ^= h[e.id];\n\t\t\t\t\trem[e.id] = remCur;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmark[e.id] = addCur ^ rem[e.id];\n\t\t\t\t\tremCur ^= h[e.id];\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (mark);}\n\t\t\treturn mark;\n\t\t}\n\n\t\twriteln (equal (calc (a), calc (b)) ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nvoid bChmax(T)(T[] bit, int pos, T val)\nin {\n assert(0 <= pos && pos < bit.length, \"bChmax: 0 <= pos < |bit| must hold\");\n}\ndo {\n for (int x = pos; x < bit.length; x |= x + 1) {\n chmax(bit[x], val);\n }\n}\n\n// max of [0, pos)\nT bMax(T)(T[] bit, int pos)\nin {\n assert(0 <= pos && pos <= bit.length, \"bMax: 0 <= pos <= |bit| must hold\");\n}\ndo {\n T ret = -1;\n for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {\n chmax(ret, bit[x]);\n }\n return ret;\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto SA = new long[N];\n auto TA = new long[N];\n auto SB = new long[N];\n auto TB = new long[N];\n foreach (i; 0 .. N) {\n SA[i] = readLong();\n TA[i] = readLong();\n SB[i] = readLong();\n TB[i] = readLong();\n }\n \n bool ans = true;\n foreach (phase; 0 .. 2) {\n auto xs = SA.dup ~ TA.dup ~ SB.dup ~ TB.dup;\n xs = xs.sort.uniq.array;\n const xsLen = cast(int)(xs.length);\n \n auto lecsSA = iota(N).array;\n auto lecsTA = iota(N).array;\n lecsSA.sort!((i, j) => (SA[i] < SA[j]));\n lecsTA.sort!((i, j) => (TA[i] < TA[j]));\n \n auto bit = new long[xsLen];\n bit[] = -1;\n int posI;\n foreach (j; lecsSA) {\n for (; posI < N && TA[lecsTA[posI]] < SA[j]; ++posI) {\n const i = lecsTA[posI];\n debug {\n writeln(\"add i = \", i);\n }\n const key = xs.lowerBound(SB[i]);\n bit.bChmax(key, TB[i]);\n }\n {\n debug {\n writeln(\"check j = \", j);\n }\n const key = xs.lowerBound(TB[j]);\n const res = bit.bMax(key + 1);\n if (res >= SB[j]) {\n debug {\n writefln(\"found j = %s, res = %s\", j, res);\n }\n ans = false;\n }\n }\n }\n \n swap(SA, SB);\n swap(TA, TB);\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\trndGen.seed (1235);\n\t\tauto h = new ulong [n];\n\t\tforeach (ref c; h)\n\t\t{\n\t\t\tc = uniform (1, ulong.max);\n\t\t}\n\n\t\talias Segment = Tuple !(int, q{lo}, int, q{hi});\n\t\tauto a = new Segment [n];\n\t\tauto b = new Segment [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %s %s %s %s\")\n\t\t\t (a[i].lo, a[i].hi, b[i].lo, b[i].hi);\n\t\t}\n\t\tlong res = 0;\n\n\t\talias Event = Tuple !(int, q{pos}, int, q{id});\n\n\t\tulong [] calc (const ref Segment [] a)\n\t\t{\n\t\t\tEvent [] events;\n\t\t\tforeach (i, const ref s; a)\n\t\t\t{\n\t\t\t\tevents ~= Event (s.lo * 2 + 1, i.to !(int));\n\t\t\t\tevents ~= Event (s.hi * 2 + 0, i.to !(int));\n\t\t\t}\n\t\t\tsort (events);\n\n\t\t\tauto mark = new ulong [n];\n\t\t\tauto rem = new ulong [n];\n\t\t\tulong addCur = 0;\n\t\t\tulong remCur = 0;\n\t\t\tforeach (const ref e; events)\n\t\t\t{\n\t\t\t\tbool isAdd = e.pos & 1;\n\t\t\t\tif (isAdd)\n\t\t\t\t{\n\t\t\t\t\taddCur ^= h[e.id];\n\t\t\t\t\trem[e.id] = remCur;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmark[e.id] = addCur ^ rem[e.id];\n\t\t\t\t\tremCur ^= h[e.id];\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteln (mark);\n\t\t\treturn mark;\n\t\t}\n\n\t\twriteln (equal (calc (a), calc (b)) ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\trndGen.seed (1235);\n\t\tauto h = new ulong [n];\n\t\tforeach (ref c; h)\n\t\t{\n\t\t\tc = uniform (1, ulong.max);\n\t\t}\n\n\t\talias Segment = Tuple !(int, q{lo}, int, q{hi});\n\t\tauto a = new Segment [n];\n\t\tauto b = new Segment [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %s %s %s %s\")\n\t\t\t (a[i].lo, a[i].hi, b[i].lo, b[i].hi);\n\t\t}\n\t\tlong res = 0;\n\n\t\talias Event = Tuple !(int, q{pos}, int, q{id});\n\n\t\tulong [] calc (const ref Segment [] a)\n\t\t{\n\t\t\tEvent [] events;\n\t\t\tforeach (i, const ref s; a)\n\t\t\t{\n\t\t\t\tevents ~= Event (s.lo * 2 + 1, i.to !(int));\n\t\t\t\tevents ~= Event (s.hi * 2 + 0, i.to !(int));\n\t\t\t}\n\t\t\tsort (events);\n\n\t\t\tauto mark = new ulong [n];\n\t\t\tauto rem = new ulong [n];\n\t\t\tulong addCur = 0;\n\t\t\tulong remCur = 0;\n\t\t\tforeach (const ref e; events)\n\t\t\t{\n\t\t\t\tbool isAdd = e.pos & 1;\n\t\t\t\tif (isAdd)\n\t\t\t\t{\n\t\t\t\t\taddCur ^= h[e.id];\n\t\t\t\t\trem[e.id] = remCur;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmark[e.id] = addCur ^ rem[e.id];\n\t\t\t\t\tremCur ^= h[e.id];\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (mark);}\n\t\t\treturn mark;\n\t\t}\n\n\t\twriteln (equal (calc (a), calc (b)) ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nvoid bChmax(T)(T[] bit, int pos, T val)\nin {\n assert(0 <= pos && pos < bit.length, \"bChmax: 0 <= pos < |bit| must hold\");\n}\ndo {\n for (int x = pos; x < bit.length; x |= x + 1) {\n chmax(bit[x], val);\n }\n}\n\n// max of [0, pos)\nT bMax(T)(T[] bit, int pos)\nin {\n assert(0 <= pos && pos <= bit.length, \"bMax: 0 <= pos <= |bit| must hold\");\n}\ndo {\n T ret = -1;\n for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {\n chmax(ret, bit[x]);\n }\n return ret;\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto SA = new long[N];\n auto TA = new long[N];\n auto SB = new long[N];\n auto TB = new long[N];\n foreach (i; 0 .. N) {\n SA[i] = readLong();\n TA[i] = readLong();\n SB[i] = readLong();\n TB[i] = readLong();\n }\n \n bool ans = true;\n foreach (phase; 0 .. 2) {\n auto xs = SA.dup ~ TA.dup ~ SB.dup ~ TB.dup;\n xs = xs.sort.uniq.array;\n const xsLen = cast(int)(xs.length);\n \n auto lecsSA = iota(N).array;\n auto lecsTA = iota(N).array;\n lecsSA.sort!((i, j) => (SA[i] < SA[j]));\n lecsTA.sort!((i, j) => (TA[i] < TA[j]));\n \n auto bit = new long[xsLen];\n bit[] = -1;\n int posI;\n foreach (j; lecsSA) {\n for (; posI < N && TA[lecsTA[posI]] < SA[j]; ++posI) {\n const i = lecsSA[posI];\n debug {\n writeln(\"add i = \", i);\n }\n const key = xs.lowerBound(SB[i]);\n bit.bChmax(key, TB[i]);\n }\n {\n debug {\n writeln(\"check j = \", j);\n }\n const key = xs.lowerBound(TB[j]);\n const res = bit.bMax(key + 1);\n if (res >= SB[j]) {\n debug {\n writefln(\"found j = %s, res = %s\", j, res);\n }\n ans = false;\n }\n }\n }\n \n swap(SA, SB);\n swap(TA, TB);\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "036ecfcf11c3106732286765e7b7fcdd"} {"source_code": "import std;\n\nvoid main(){\n\tint t=readln().strip.to!int;\n\tforeach(_;0..t){\n\t\treadln();\n\t\tauto a=readln.strip.split.to!(int[]);\n\t\twriteln(min(2,a.map!(x=>x==0).group.filter!(x=>!x[0]).walkLength));\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid solve()\n{\n readln;\n auto ans = readln.splitter\n .map!(to!int)\n .chunkBy!(x => x != 0)\n .count!(x => x[0] != 0);\n \n .writeln(min(2, ans));\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n solve();\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n \n long ans;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && (A[i] != 0) == (A[j] != 0); ++j) {}\n if (A[i] != 0) {\n ++ans;\n }\n }\n chmin(ans, 2);\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid solve()\n{\n readln;\n readln.splitter\n .map!(to!int)\n .chunkBy!(x => x != 0)\n .count!(x=> x[0] != 0)\n .writeln();\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n solve();\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n const N = readInt;\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong;\n }\n \n long ans;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && (A[i] != 0) == (A[j] != 0); ++j) {}\n if (A[i] != 0) {\n ++ans;\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "da3d1b2615d51044a7b43bd0ce939f4c"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nvoid main() {\n auto s = readln.strip.split.map!(to!int).array;\n immutable h = s[0], w = s[1];\n auto a = new string[h];\n foreach (i; 0 .. h) {\n a[i] = readln.strip;\n }\n int c;\n foreach (i; 0 .. h) {\n foreach (j; 0 .. w) {\n if (a[i][j] == '*') ++c;\n }\n }\n bool test() {\n foreach (i; 0 .. h) {\n foreach (j; 0 .. w) {\n if (a[i][j] == '*') {\n int go (int di, int dj) {\n int x = i + di;\n int y = j + dj;\n int r;\n while (x >= 0 && x < h && y >= 0 && y < w && a[x][y] == '*') {\n ++r;\n x += di;\n y += dj;\n }\n return r;\n }\n auto e = new int[4];\n e[0] = go (0, 1);\n e[1] = go (0, -1);\n e[2] = go (1, 0);\n e[3] = go (-1, 0);\n if (e.minElement () > 0 && e.sum == c - 1) {\n return true;\n }\n }\n }\n }\n return false;\n }\n writeln (test() ? \"YES\" : \"NO\");\n}\n\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint h = read.to!int;\n\tint w = read.to!int;\n\t\n\tbool[][] as;\n\tforeach(i; 0 .. h){\n\t\tas ~= readln.chomp.to!(char[]).map!(x => x == '*').array;\n\t}\n\t\n\tstring ans = \"YES\";\n\t\n\tbool f = 0;\n\tint i0, j0;\n\tforeach(i; 1 .. h - 1) foreach(j; 1 .. w - 1){\n\t\tif(as[i][j] && as[i - 1][j] && as[i + 1][j] && as[i][j - 1] && as[i][j + 1]){\n\t\t\tif(f == 0) i0 = i, j0 = j, f = 1;\n\t\t\telse ans = \"NO\";\n\t\t}\n\t}\n\tif(f == 0) ans = \"NO\";\n\t\n\tif(ans == \"NO\"){\n\t\tans.writeln;\n\t\treturn;\n\t}\n\t\n\tint t, b, l, r;\n\tforeach_reverse(i; 0 .. i0) if(!as[i][j0]) break; else t = i;\n\tforeach(i; i0 + 1 .. h) if(!as[i][j0]) break; else b = i;\n\tforeach_reverse(j; 0 .. j0) if(!as[i0][j]) break; else l = j;\n\tforeach(j; j0 + 1 .. w) if(!as[i0][j]) break; else r = j;\n\t\n\t\n\tforeach(i; 0 .. h) foreach(j; 0 .. w){\n\t\tif(i != i0 && j != j0 && as[i][j]) ans = \"NO\";\n\t\tif(i == i0 && (j < l || j > r) && as[i][j]) ans = \"NO\";\n\t\tif(j == j0 && (i < t || i > b) && as[i][j]) ans = \"NO\";\n\t}\n\t\n\tans.writeln;\n\t\n}\n\n/*\n\tbool ng = 0;\n\tint[] ls, rs, ts, bs;\n\tforeach(i; 0 .. h){\n\t\tint f = 0;\n\t\tint l = -1, r = -1;\n\t\tforeach(j; 0 .. w){\n\t\t\tif(as[i][j]){\n\t\t\t\tif(f == 0) f = 1, l = j;\n\t\t\t\telse if(f == 2) ng = 1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(f == 1) f = 2, r = j;\n\t\t\t}\n\t\t}\n\t\tls ~= l, rs ~= r;\n\t}\n\tforeach(j; 0 .. w){\n\t\tint f = 0;\n\t\tint t = -1, b = -1;\n\t\tforeach(i; 0 .. h){\n\t\t\tif(as[i][j]){\n\t\t\t\tif(f == 0) f = 1, t = i;\n\t\t\t\telse if(f == 2) ng = 1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(f == 1) f = 2, b = i;\n\t\t\t}\n\t\t}\n\t\tts ~= t, bs ~= b;\n\t}\n\t\n\n*/\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln;\nimport std.array : array, split;\nimport std.algorithm;\nimport std.conv : to;\nimport std.range;\nimport std.algorithm.comparison;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string ;\nimport core.memory : GC;\nimport std.typecons : tuple;\nimport std.math;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n //\n\n int h, w;\n readf(\" %s %s\\n\", h, w);\n\n auto m = new string[h];\n\n int tt = 0;\n foreach(i; 0..h) {\n m[i] = readln.strip;\n foreach(e; m[i]) if (e=='*') tt++;\n }\n\n foreach(i; 1..h-1) {\n foreach(j; 1..w-1) {\n if (m[i][j] == '*' && m[i-1][j] == '*' \n && m[i+1][j] == '*' && m[i][j+1] == '*'\n && m[i][j-1] == '*') {\n int k = j+1;\n while(k < w && m[i][k] == '*') { tt--; k++;}\n k = j-1;\n while(k >= 0 && m[i][k] == '*') { tt--; k--;}\n k = i-1;\n while(k >= 0 && m[k][j] == '*') { tt--; k--;}\n k = i+1;\n while(k < h && m[k][j] == '*') { tt--; k++;}\n\n tt--;\n\n if (tt == 0) {\n writeln(\"YES\");\n return;\n } else {\n writeln(\"NO\");\n return;\n }\n\n }\n }\n }\n\n writeln(\"NO\");\n\n\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto h = RD!int;\n\tauto w = RD!int;\n\tauto s = new string[](h);\n\tforeach (i; 0..h)\n\t{\n\t\ts[i] = RD!string;\n\t}\n\n\tauto cnt_w = new long[](h);\n\tforeach (y; 0..h)\n\t{\n\t\tbool isStart;\n\t\tchar last = '.';\n\t\tforeach (x; 0..w)\n\t\t{\n\t\t\tif (s[y][x] == '*')\n\t\t\t{\n\t\t\t\tif (last == '.')\n\t\t\t\t{\n\t\t\t\t\tif (!isStart)\n\t\t\t\t\t{\n\t\t\t\t\t\tisStart = true;\n\t\t\t\t\t\tcnt_w[y] = 1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcnt_w[y] = -1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t++cnt_w[y];\n\t\t\t\t}\n\t\t\t}\n\t\t\tlast = s[y][x];\n\t\t}\n\t}\n\n\tauto cnt_h = new long[](w);\n\tforeach (x; 0..w)\n\t{\n\t\tbool isStart;\n\t\tchar last = '.';\n\t\tforeach (y; 0..h)\n\t\t{\n\t\t\tif (s[y][x] == '*')\n\t\t\t{\n\t\t\t\tif (last == '.')\n\t\t\t\t{\n\t\t\t\t\tif (!isStart)\n\t\t\t\t\t{\n\t\t\t\t\t\tisStart = true;\n\t\t\t\t\t\tcnt_h[x] = 1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcnt_h[x] = -1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t++cnt_h[x];\n\t\t\t\t}\n\t\t\t}\n\t\t\tlast = s[y][x];\n\t\t}\n\t}\n\n\tbool ans = true;\n\tauto index_w = cnt_w.MAKE_IDX!\"a > b\"();\n\tauto index_h = cnt_h.MAKE_IDX!\"a > b\"();\n\tauto pos_y = index_w[0];\n\tauto pos_x = index_h[0];\n\tif (cnt_w[pos_y] < 3)\n\t\tans = false;\n\tforeach (y; index_w[1..$])\n\t{\n\t\tif (cnt_w[y] == 0) break;\n\t\tif (cnt_w[y] > 1)\n\t\t\tans = false;\n\t\tif (s[y][pos_x] == '.')\n\t\t\tans = false;\n\t}\n\n\t\n\tif (cnt_h[pos_x] < 3)\n\t\tans = false;\n\tforeach (x; index_h[1..$])\n\t{\n\t\tif (cnt_h[x] == 0) break;\n\t\tif (cnt_h[x] > 1)\n\t\t\tans = false;\n\t\tif (s[pos_y][x] == '.')\n\t\t\tans = false;\n\t}\n\n\tif (ans)\n\t{\n\t\tif (pos_y == 0 || pos_y == h - 1)\n\t\t\tans = false;\n\t\tif (pos_x == 0 || pos_x == w - 1)\n\t\t\tans = false;\n\n\t\tif (ans)\n\t\t{\n\t\t\tif (s[pos_y][pos_x-1] != '*')\n\t\t\t\tans = false;\n\t\t\tif (s[pos_y][pos_x+1] != '*')\n\t\t\t\tans = false;\n\t\t\tif (s[pos_y-1][pos_x] != '*')\n\t\t\t\tans = false;\n\t\t\tif (s[pos_y+1][pos_x] != '*')\n\t\t\t\tans = false;\n\t\t}\n\t}\n\n\twriteln(ans ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nvoid main() {\n auto s = readln.strip.split.map!(to!int).array;\n immutable h = s[0], w = s[1];\n auto a = new string[h];\n foreach (i; 0 .. h) {\n a[i] = readln.strip;\n }\n int c;\n foreach (i; 0 .. h) {\n foreach (j; 0 .. w) {\n if (a[i][j] == '*') ++c;\n }\n }\n bool test() {\n foreach (i; 0 .. h) {\n foreach (j; 0 .. w) {\n if (a[i][j] == '*') {\n int go (int di, int dj) {\n int x = i + di;\n int y = j + dj;\n int r;\n while (x >= 0 && x < h && y >= 0 && y < h && a[x][y] == '*') {\n ++r;\n x += di;\n y += dj;\n }\n return r;\n }\n auto e = new int[4];\n e[0] = go (0, 1);\n e[1] = go (0, -1);\n e[2] = go (1, 0);\n e[3] = go (-1, 0);\n if (e.minElement () > 0 && e.sum == c - 1) {\n return true;\n }\n }\n }\n }\n return false;\n }\n writeln (test() ? \"YES\" : \"NO\");\n}\n\n"}], "src_uid": "6405161be280fea943201fa00ef6f448"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(real)).array;\r\n\t\tzip (a, a.drop (1)).map !(c => max (0, \r\n\t\t to !(int) (abs (log2 (c[0] / c[1])) - 1E-9))).sum.writeln;\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n int N; get(N);\r\n int[] AA; get(AA);\r\n int c;\r\n foreach (i; 0..N-1) {\r\n auto a = AA[i];\r\n auto b = AA[i+1];\r\n if (a > b) swap(a, b);\r\n while (a * 2 < b) {\r\n ++c;\r\n a *= 2;\r\n }\r\n }\r\n writeln(c);\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tauto x = min(a[i], a[i+1]) * 2;\r\n\t\t\tauto y = max(a[i], a[i+1]);\r\n\t\t\twhile (x < y)\r\n\t\t\t{\r\n\t\t\t\t++ans[ti];\r\n\t\t\t\tx *= 2;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tint res = 0;\r\n\t\tforeach (i; 0..n - 1)\r\n\t\t{\r\n\t\t\tauto b = a[i..i + 2].dup;\r\n\t\t\tsort (b);\r\n\t\t\twhile (b[0] * 2 < b[1])\r\n\t\t\t{\r\n\t\t\t\tb[0] *= 2;\r\n\t\t\t\tres += 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "a544dd9fd96379f66a960de6f973dd50"} {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nvoid main ()\r\n{\r\n\tauto tests = readln.strip.to !(int);\r\n\tforeach (test; 0..tests)\r\n\t{\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto v = (a.sum % 2 == 0 && (a.sum % 4 == 0 || a.canFind (1)));\r\n\t\twriteln (v ? \"Yes\" : \"No\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\nlong mod = 10^^9 + 7;\r\n//long mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new bool[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto a = RDA;\r\n\r\n\t\tlong x, y;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] == 1)\r\n\t\t\t\t++x;\r\n\t\t\telse\r\n\t\t\t\t++y;\r\n\t\t}\r\n\t\t\r\n\t\tif (x % 2) continue;\r\n\t\tif (n % 2)\r\n\t\t{\r\n\t\t\tif (x < 2) continue;\r\n\t\t}\r\n\t\tans[ti] = true;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t\twriteln(e ? \"YES\" : \"NO\");\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "1d9d34dca11a787d6e2345494680e717"} {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n \nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n \n long n, d, m;\n @Dim(\"n\") long[] a;\n \n void solve(long tc = -1)\n {\n long[] u = a.filter!(ai => ai <= m).array;\n long[] m = a.filter!(ai => ai > m).array;\n long q = cast(long) m.length;\n\n sort!\"a > b\"(u);\n sort!\"a > b\"(m);\n \n long[] accu = new long[u.length + 1];\n long[] accm = new long[m.length + 1];\n \n accu[0] = 0;\n foreach(i; 1 .. u.length + 1)\n accu[i] = accu[i - 1] + u[i - 1];\n accm[0] = 0;\n foreach(i; 1 .. m.length + 1)\n accm[i] = accm[i - 1] + m[i - 1];\n \n \n long maxres = long.min;\n foreach(qp; 0 .. q + 1)\n {\n if (max((qp - 1) * d, q - qp) <= min(qp * d, n - qp))\n {\n long s = max((qp - 1) * d, q - qp);\n s -= (q - qp);\n s = cast(long) u.length - s;\n long pres = accu.at(s) + accm.at(qp);\n maxres = max(maxres, pres);\n }\n }\n writeln(maxres);\n }\n}\n \nstruct Interval\n{\n long l, h;\n \n bool empty()\n {\n return l > h;\n }\n}\n \nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n \nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n \ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n \nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n \n \nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n \nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n \n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n \nDList!string _words;\n \ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n \ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n \nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n \nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n \n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n \nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n \n \nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n \nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n \nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n \nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n \nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n \n }\n}\n \nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n \ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n \nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n \nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n \nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n \nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n \nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n \nvoid main()\n{\n type;\n}\n", "positive_code": [{"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n \nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n \n long n, d, m;\n @Dim(\"n\") long[] a;\n \n void solve(long tc = -1)\n {\n long[] u = a.filter!(ai => ai <= m).array;\n long[] m = a.filter!(ai => ai > m).array;\n long q = cast(long) m.length;\n\n if (m.length == 0)\n {\n writeln(a.sum);\n return;\n }\n \n sort!\"a > b\"(u);\n sort!\"a > b\"(m);\n \n long[] accu = new long[u.length + 1];\n long[] accm = new long[m.length + 1];\n \n accu[0] = 0;\n foreach(i; 1 .. u.length + 1)\n accu[i] = accu[i - 1] + u[i - 1];\n accm[0] = 0;\n foreach(i; 1 .. m.length + 1)\n accm[i] = accm[i - 1] + m[i - 1];\n \n \n long maxres = 0;\n foreach(qp; 1 .. q + 1)\n {\n if (max((qp - 1) * d, q - qp) <= min(qp * d, n - qp))\n {\n long s = max((qp - 1) * d, q - qp);\n s -= (q - qp);\n s = cast(long) u.length - s;\n long pres = accu.at(s) + accm.at(qp);\n maxres = max(maxres, pres);\n }\n }\n writeln(maxres);\n }\n}\n \nstruct Interval\n{\n long l, h;\n \n bool empty()\n {\n return l > h;\n }\n}\n \nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n \nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n \ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n \nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n \n \nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n \nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n \n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n \nDList!string _words;\n \ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n \ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n \nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n \nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n \n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n \nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n \n \nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n \nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n \nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n \nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n \nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n \n }\n}\n \nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n \ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n \nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n \nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n \nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n \nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n \nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n \nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\t\n\tauto n = RD!int;\n\tauto d = RD!int;\n\tauto m = RD!int;\n\tauto a = RDA!int;\n\n\tdebug\n\t{\n\t\ta.sort();\n\t\twriteln(a);\n\t\twriteln(a.sum);\n\t}\n\n\tlong[] b, c;\n\tforeach (e; a)\n\t{\n\t\tif (e > m)\n\t\t{\n\t\t\tb ~= e;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tc ~= e;\n\t\t}\n\t}\n\tb.sort!\"a > b\"();\n\tc.sort();\n\n\tlong cnt;\n\tif (!b.empty)\n\t{\n\t\tcnt += b.front; b.popFront;\n\t\t--n;\n\t}\n\tcnt += c.sum;\n\n\tint len = cast(int)c.length;\n\tdebug writeln(\"len:\", len);\n\tforeach (i; 0..(n-len)/(d+1))\n\t{\n\t\tcnt += b.front; b.popFront;\n\t}\n\tauto rem = (n-len) % (d+1);\n\n\tlong ans = cnt;\n\tdebug writeln(\"ans:\", ans);\n\twhile (!b.empty && len+rem >= (d+1))\n\t{\n\t\tauto e = (d+1) - rem;\n\t\trem = 0;\n\t\tdebug writeln(\"e:\", e);\n\t\tforeach (i; 0..e)\n\t\t{\n\t\t\tcnt -= c.front; c.popFront;\n\t\t}\n\t\tcnt += b.front; b.popFront;\n\t\tans.chmax(cnt);\n\t\tlen -= e;\n\t\tdebug writeln(\"ans:\", ans);\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, d, m;\n\twhile (readf !(\" %s %s %s\") (n, d, m) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort !(q{a > b}) (a);\n\n\t\tauto lo = a.filter !(x => x <= m).array;\n\t\tauto hi = a.filter !(x => x > m).array;\n\t\tauto loSize = lo.length.to !(int);\n\t\tauto hiSize = hi.length.to !(int);\n\t\tauto sLo = [0L];\n\t\tforeach (ref c; lo)\n\t\t{\n\t\t\tsLo ~= sLo.back + c;\n\t\t}\n\t\tauto sHi = [0L];\n\t\tforeach (ref c; hi)\n\t\t{\n\t\t\tsHi ~= sHi.back + c;\n\t\t}\n\n\t\tlong res = 0;\n\t\tforeach (int k; 0..hiSize + 1)\n\t\t{\n\t\t\tauto rem = (k - 1L) * d;\n\t\t\trem -= hiSize - k;\n\t\t\trem = max (rem, 0);\n\t\t\tif (rem <= loSize)\n\t\t\t{\n\t\t\t\tlong cur = sHi[k];\n\t\t\t\tcur += sLo[loSize - rem.to !(int)];\n\t\t\t\tres = max (res, cur);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, d, m;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n long[] u = a.filter!(ai => ai <= m).array;\n long[] m = a.filter!(ai => ai > m).array;\n long q = cast(long) m.length;\n\n sort!\"a > b\"(u);\n sort!\"a > b\"(m);\n\n long[] accu = new long[u.length + 1];\n long[] accm = new long[m.length + 1];\n\n accu[0] = 0;\n foreach(i; 1 .. u.length + 1)\n accu[i] = accu[i - 1] + u[i - 1];\n accm[0] = 0;\n foreach(i; 1 .. m.length + 1)\n accm[i] = accm[i - 1] + m[i - 1];\n\n long pmod(long a, long m)\n {\n return (a%m + m)%m;\n }\n\n long nextmultiple(long a, long m)\n {\n return a + pmod(-a, m);\n }\n\n\n long maxres = long.min;\n foreach(qp; 1 .. q + 1)\n {\n if (nextmultiple(q - qp, d) <= min(qp * d, n - qp))\n {\n long s = nextmultiple(q - qp, d);\n s -= (q - qp);\n s = cast(long) u.length - s;\n long pres = accu.at(s) + accm.at(qp);\n maxres = max(maxres, pres);\n }\n }\n writeln(maxres);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, d, m;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n long[] u = a.filter!(ai => ai <= m).array;\n long[] m = a.filter!(ai => ai > m).array;\n long q = cast(long) m.length;\n\n sort!\"a > b\"(u);\n sort!\"a > b\"(m);\n\n long[] accu = new long[u.length + 1];\n long[] accm = new long[m.length + 1];\n\n accu[0] = 0;\n foreach(i; 1 .. u.length + 1)\n accu[i] = accu[i - 1] + u[i - 1];\n accm[0] = 0;\n foreach(i; 1 .. m.length + 1)\n accm[i] = accm[i - 1] + m[i - 1];\n\n long pmod(long a, long m)\n {\n return (a%m + m)%m;\n }\n\n long nextmultiple(long a, long m)\n {\n return a + pmod(-a, m);\n }\n\n\n long maxres = long.min;\n foreach(qp; 1 .. q + 1)\n {\n if (max((qp - 1) * d, q - qp) <= min(qp * d, n - qp))\n {\n long s = max((qp - 1) * d, nextmultiple(q - qp, d));\n s -= (q - qp);\n s = cast(long) u.length - s;\n long pres = accu.at(s) + accm.at(qp);\n maxres = max(maxres, pres);\n }\n }\n writeln(maxres);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, d, m;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n sort(a);\n long muzzled = -d;\n long totalFun = 0;\n logSym!this;\n foreach_reverse(i; 0 .. n)\n {\n if (a.at(i) > m)\n {\n muzzled += d;\n }\n if (muzzled > i)\n break;\n logSym!(i, muzzled);\n\n totalFun += a.at(i);\n }\n writeln(totalFun);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, d, m;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n long[] u = a.filter!(ai => ai <= m).array;\n long[] m = a.filter!(ai => ai > m).array;\n long q = cast(long) m.length;\n\n sort!\"a > b\"(u);\n sort!\"a > b\"(m);\n\n long[] accu = new long[u.length + 1];\n long[] accm = new long[m.length + 1];\n\n accu[0] = 0;\n foreach(i; 1 .. u.length + 1)\n accu[i] = accu[i - 1] + u[i - 1];\n accm[0] = 0;\n foreach(i; 1 .. m.length + 1)\n accm[i] = accm[i - 1] + m[i - 1];\n\n\n long maxres = long.min;\n foreach(qp; 1 .. q + 1)\n {\n if (max((qp - 1) * d, q - qp) <= min(qp * d, n - qp))\n {\n long s = max((qp - 1) * d, q - qp);\n s -= (q - qp);\n s = cast(long) u.length - s;\n long pres = accu.at(s) + accm.at(qp);\n maxres = max(maxres, pres);\n }\n }\n writeln(maxres);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n \nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n \n long n, d, m;\n @Dim(\"n\") long[] a;\n \n void solve(long tc = -1)\n {\n long[] u = a.filter!(ai => ai <= m).array;\n long[] m = a.filter!(ai => ai > m).array;\n long q = cast(long) m.length;\n \n sort!\"a > b\"(u);\n sort!\"a > b\"(m);\n \n long[] accu = new long[u.length + 1];\n long[] accm = new long[m.length + 1];\n \n accu[0] = 0;\n foreach(i; 1 .. u.length + 1)\n accu[i] = accu[i - 1] + u[i - 1];\n accm[0] = 0;\n foreach(i; 1 .. m.length + 1)\n accm[i] = accm[i - 1] + m[i - 1];\n \n \n long maxres = 0;\n foreach(qp; 1 .. q + 1)\n {\n if (max((qp - 1) * d, q - qp) <= min(qp * d, n - qp))\n {\n long s = max((qp - 1) * d, q - qp);\n s -= (q - qp);\n s = cast(long) u.length - s;\n long pres = accu.at(s) + accm.at(qp);\n maxres = max(maxres, pres);\n }\n }\n writeln(maxres);\n }\n}\n \nstruct Interval\n{\n long l, h;\n \n bool empty()\n {\n return l > h;\n }\n}\n \nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n \nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n \ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n \nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n \n \nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n \nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n \n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n \nDList!string _words;\n \ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n \ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n \nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n \nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n \n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n \nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n \n \nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n \nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n \nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n \nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n \nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n \n }\n}\n \nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n \ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n \nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n \nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n \nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n \nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n \nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n \nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, d, m;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n long[] u = a.filter!(ai => ai <= m).array;\n long[] m = a.filter!(ai => ai > m).array;\n long q = cast(long) m.length;\n\n sort!\"a > b\"(u);\n sort!\"a > b\"(m);\n\n long[] accu = new long[u.length + 1];\n long[] accm = new long[m.length + 1];\n\n accu[0] = 0;\n foreach(i; 1 .. u.length + 1)\n accu[i] = accu[i - 1] + u[i - 1];\n accm[0] = 0;\n foreach(i; 1 .. m.length + 1)\n accm[i] = accm[i - 1] + m[i - 1];\n\n long pmod(long a, long m)\n {\n return (a%m + m)%m;\n }\n\n long nextmultiple(long a, long m)\n {\n return a + pmod(-a, m);\n }\n\n\n long maxres = long.min;\n foreach(qp; 1 .. q + 1)\n {\n if (max((qp - 1) * d, nextmultiple(q - qp, d)) <= min(qp * d, n - qp))\n {\n long s = max((qp - 1) * d, nextmultiple(q - qp, d));\n s -= (q - qp);\n s = cast(long) u.length - s;\n long pres = accu.at(s) + accm.at(qp);\n maxres = max(maxres, pres);\n }\n }\n writeln(maxres);\n }\n}\n\nstruct Interval\n{\n long l, h;\n\n bool empty()\n {\n return l > h;\n }\n}\n\nInterval intersect(Interval a, Interval b)\n{\n return Interval(max(a.l, b.l), min(a.h, b.h));\n}\n\nstruct If\n{\n string condition;\n}\nenum ignore = If(\"false\");\nstruct Dim\n{\n string dimensions;\n int levels;\n this(string dimensions)\n {\n this.dimensions = dimensions;\n levels = cast(int)dimensions.count(\",\") + 1;\n }\n}\n\ntemplate getArrayLevel(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));\n else\n enum getArrayLevel = 0;\n}\n\nstatic foreach(fieldName; 'a' .. cast(char)('z' + 1))\n {\n static if (fieldName != 'o')\n mixin(\"enum d\", fieldName, \" = Dim(\\\"\", fieldName, \"\\\");\");\n }\n\n\nmixin template prettyPrinting()\n{\n string toString()\n {\n alias structType = typeof(this);\n auto res = appender!(string)();\n res.put(structType.stringof);\n res.put(\"(\");\n static foreach(fieldName; FieldNameTuple!structType)\n {\n res.put(text(\" \", fieldName, \": \", mixin(fieldName)));\n }\n res.put(\" )\");\n res.put(\"\\n\");\n return res[];\n }\n}\n\nstruct Graph(N)\n{\n size_t size;\n this(S)(S size)\n {\n adjacencyList.length = cast(size_t) size;\n this.size = cast(size_t) size;\n this.visited = makeSlice!bool(size);\n }\n N[][] adjacencyList;\n alias ne = neighbours;\n N[] neighbours(N n)\n {\n return adjacencyList.at(n);\n }\n alias bcon = biconnect;\n void biconnect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n adjacencyList.at(b) ~= a;\n }\n alias con = connect;\n void connect(N a, N b)\n {\n adjacencyList.at(a) ~= b;\n }\n void connect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n connect(edge[0], edge[1]);\n }\n }\n void biconnect(R)(R edges)\n {\n foreach(ref edge; edges)\n {\n biconnect(edge[0], edge[1]);\n }\n }\n alias deg = degree!long;\n auto degree(T)(N a)\n {\n return cast(T) adjacencyList.at(a).length;\n }\n\n auto visited = new bool[0];\n void dfs(Visitor)(long startNode)\n {\n auto visitor = Visitor.init;\n void internalDfs(long node)\n {\n visited.set(node, true);\n static if (is(typeof({visitor.n = node;})))\n visitor.n = node;\n static if (is(typeof({visitor.pre;})))\n visitor.pre;\n foreach(w; ne(node))\n if (!visited.at(w))\n {\n static if (is(typeof({visitor.w = w;})))\n visitor.w = w;\n static if (is(typeof(visitor.pren)))\n visitor.pren;\n internalDfs(w);\n static if (is(typeof(visitor.postn)))\n visitor.postn;\n }\n static if (is(typeof(visitor.post)))\n visitor.post;\n }\n internalDfs(startNode);\n }\n void dfs(long startNode)\n {\n struct DefVisitor {}\n dfs!DefVisitor(startNode);\n }\n}\n\nDList!string _words;\n\ntemplate removeArray(W, int times)\n{\n static if (times == 0)\n alias removeArray = W;\n else static if (times == 1)\n alias removeArray = typeof(function(){W w; return w[0];}());\n else\n {\n static assert(isDynamicArray!W);\n alias removeArray = removeArray!(removeArray!(W, 1), times - 1);\n }\n}\n\ntemplate baseType(W)\n{\n static if (isDynamicArray!W && !is(W == string))\n alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));\n else\n alias baseType = W;\n}\n\nauto makeSlice(E, W, T...)(W size, T otherSizes)\n{\n static if (T.length == 0)\n {\n E[] res;\n res.length = cast(size_t) size;\n return res;\n }\n else\n {\n typeof(makeSlice!E(otherSizes))[] res;\n res.length = cast(size_t) size;\n foreach(ref row; res)\n row = makeSlice!E(otherSizes);\n return res;\n }\n}\n\nvoid read(T...)(ref T t)\n{\n void basicTypeRead(W)(ref W w)\n {\n import std.stdio: readln;\n while(_words.empty)\n {\n import std.array: split;\n foreach(word; readln.split)\n {\n _words.insertBack(word);\n }\n }\n import std.conv: to;\n string word = _words.front;\n _words.removeFront;\n w = to!W(word);\n }\n void iterableRead(W)(ref W w)\n {\n foreach(ref element; w)\n read(element);\n }\n void tupleRead(W)(ref W w)\n {\n static foreach(j; 0 .. W.length)\n read(w[j]);\n }\n void structRead(W)(ref W readStruct)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(readStruct)\n {\n alias fieldSymbol = mixin(W.stringof, \".\", fieldName);\n alias typeOfField = typeof(mixin(fieldName));\n static if (hasUDA!(fieldSymbol, If))\n enum condition = getUDAs!(fieldSymbol, If)[0].condition;\n else\n enum condition = \"true\";\n\n if (mixin(condition))\n {\n static if (hasUDA!(fieldSymbol, Dim))\n {\n static assert(isDynamicArray!(typeOfField)\n , text(W.stringof, \".\", fieldName, \" has Dim UDA but isn't a Dynamic Array.\"));\n enum uda = getUDAs!(fieldSymbol, Dim)[0];\n static assert(getArrayLevel!(typeOfField) == uda.levels,\n text(W.stringof, \".\", fieldName, \" has a Dim UDA with different number of dimensions than it's type.\"));\n mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});\n }\n else static if (isDynamicArray!typeOfField && !is(typeOfField == string))\n {\n pragma(msg, \"Warning: You probably want to add dimension to input \", W.stringof, \".\", fieldName);\n }\n read(mixin(fieldName));\n }\n }\n }\n }\n static foreach(i; 0 .. T.length)\n {\n static if (isBasicType!(T[i]) || is(T[i] == string))\n basicTypeRead(t[i]);\n else static if (is(typeof({foreach(ref e; t[i]){}})))\n iterableRead(t[i]);\n else static if (isTuple!(T[i]))\n tupleRead(t[i]);\n else static if (isAggregateType!(T[i]))\n structRead(t[i]);\n }\n}\n\nauto next(T)()\n{\n T t;\n read(t);\n return t;\n}\n\n\nsize_t ind(T)(T t)\n{\n return cast(size_t)t;\n}\n\nref auto at(R, I)(ref R r, I i)\n{\n return r[cast(size_t)i];\n}\n\nvoid set(R, I, V)(ref R r, I i, V v)\n{\n r[cast(size_t)i] = v;\n}\n\nimport std.conv;\nimport std.traits;\nimport std.meta;\nint _loglevel = -1;\nvoid _log(string functionName, argSeq...)()\n{\n foreach(i; 0 .. _loglevel * 4)\n write(' ');\n write(functionName);\n static foreach(arg; argSeq)\n {\n write(\" \", arg.stringof, \" = \", arg);\n }\n writeln;\n}\nenum logCall =\n q{\n debug\n {\n {\n _loglevel++;\n alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, \".\").back));\n static if (_parameterTuple.length > 0)\n mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(\", \").array, `);`);\n else\n _log!(__FUNCTION__);\n }\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('{');\n scope(exit)\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n writeln('}');\n _loglevel--;\n }\n }\n};\n\nvoid logSym(S...)(int line = __LINE__, string file = __FUNCTION__)\n{\n debug\n {\n foreach(i; 0 .. _loglevel * 4) write(' ');\n write(file, \"(\", line, \"):\");\n static foreach(s; S)\n write(\" \", s.stringof, \" = \", s);\n writeln;\n\n }\n}\n\nArray!E makeArray(E, S)(S size, lazy E value)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n foreach(ref ai; a)\n ai = value();\n return a;\n}\nArray!E makeArray(E, S)(S size)\n{\n auto a = Array!E();\n a.length = cast(size_t) size;\n return a;\n}\n\ntemplate mem(alias F)\n{\n ReturnType!F[Tuple!(Parameters!F)] table;\n ReturnType!F mem(Parameters!F args)\n {\n return table.require(tuple(args), F(args));\n }\n}\n\nstring input(string names, string type = \"long\")\n{\n return text(type, \" \", names, \"; read(\", names, \");\");\n}\n\nauto pmod(T, W)(T t, W w)\n{\n return (t%w + w) % w;\n}\n\nvoid rep(S, F)(F f, S times)\n{\n static if (is(typeof(f(i))))\n foreach(i; 0 .. times)\n f(i);\n else\n foreach(i; 0 .. times)\n f();\n}\n\nvoid multi()\n{\n foreach(tc; 0 .. next!long)\n next!TestCase.solve(tc);\n}\n\nvoid single()\n{\n auto tc = next!TestCase;\n tc.solve;\n}\n\nvoid main()\n{\n type;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\t\n\tauto n = RD!int;\n\tauto d = RD!int;\n\tauto m = RD!int;\n\tauto a = RDA!int;\n\n\tdebug\n\t{\n\t\ta.sort();\n\t\twriteln(a);\n\t\twriteln(a.sum);\n\t}\n\n\tint[] b, c;\n\tforeach (e; a)\n\t{\n\t\tif (e > m)\n\t\t{\n\t\t\tb ~= e;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tc ~= e;\n\t\t}\n\t}\n\tb.sort!\"a > b\"();\n\tc.sort();\n\n\tlong cnt;\n\tif (!b.empty)\n\t{\n\t\tcnt += b.front; b.popFront;\n\t\t--n;\n\t}\n\tcnt += c.sum;\n\n\tint len = cast(int)c.length;\n\tdebug writeln(\"len:\", len);\n\tforeach (i; 0..(n-len)/(d+1))\n\t{\n\t\tcnt += b.front; b.popFront;\n\t}\n\n\tlong ans = cnt;\n\tdebug writeln(\"ans:\", ans);\n\twhile (!b.empty && len >= (d+1))\n\t{\n\t\tauto e = (d+1) - ((n-len) % (d+1));\n\t\tdebug writeln(\"e:\", e);\n\t\tforeach (i; 0..e)\n\t\t{\n\t\t\tcnt -= c.front; c.popFront;\n\t\t}\n\t\tcnt += b.front; b.popFront;\n\t\tans.chmax(cnt);\n\t\tlen -= e;\n\t\tdebug writeln(\"ans:\", ans);\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\t\n\tauto n = RD!int;\n\tauto d = RD!int;\n\tauto m = RD!int;\n\tauto a = RDA!int;\n\n\tdebug\n\t{\n\t\ta.sort();\n\t\twriteln(a);\n\t\twriteln(a.sum);\n\t}\n\n\tint[] b, c;\n\tforeach (e; a)\n\t{\n\t\tif (e > m)\n\t\t{\n\t\t\tb ~= e;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tc ~= e;\n\t\t}\n\t}\n\tb.sort!\"a > b\"();\n\tc.sort();\n\n\tlong cnt;\n\tif (!b.empty)\n\t{\n\t\tcnt += b.front; b.popFront;\n\t\t--n;\n\t}\n\tcnt += c.sum;\n\n\tint len = cast(int)c.length;\n\tdebug writeln(\"len:\", len);\n\tforeach (i; 0..(n-len)/(d+1))\n\t{\n\t\tcnt += b.front; b.popFront;\n\t}\n\tauto rem = (n-len) % (d+1);\n\n\tlong ans = cnt;\n\tdebug writeln(\"ans:\", ans);\n\twhile (!b.empty && len+rem >= (d+1))\n\t{\n\t\tauto e = (d+1) - rem;\n\t\trem = 0;\n\t\tdebug writeln(\"e:\", e);\n\t\tforeach (i; 0..e)\n\t\t{\n\t\t\tcnt -= c.front; c.popFront;\n\t\t}\n\t\tcnt += b.front; b.popFront;\n\t\tans.chmax(cnt);\n\t\tlen -= e;\n\t\tdebug writeln(\"ans:\", ans);\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, d, m;\n\twhile (readf !(\" %s %s %s\") (n, d, m) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort !(q{a > b}) (a);\n\n\t\tauto lo = a.filter !(x => x <= m).array;\n\t\tauto hi = a.filter !(x => x > m).array;\n\t\tauto loSize = lo.length.to !(int);\n\t\tauto hiSize = hi.length.to !(int);\n\t\tauto sLo = [0L];\n\t\tforeach (ref c; lo)\n\t\t{\n\t\t\tsLo ~= sLo.back + c;\n\t\t}\n\t\tauto sHi = [0L];\n\t\tforeach (ref c; hi)\n\t\t{\n\t\t\tsHi ~= sHi.back + c;\n\t\t}\n\n\t\tlong res = 0;\n\t\tforeach (k; 0..hiSize + 1)\n\t\t{\n\t\t\tauto rem = (k - 1) * d;\n\t\t\trem -= hiSize - k;\n\t\t\trem = max (rem, 0);\n\t\t\tif (rem <= loSize)\n\t\t\t{\n\t\t\t\tlong cur = sHi[k] + sLo[loSize - rem];\n\t\t\t\tres = max (res, cur);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "3dc8d6d89a29b0aa0b7527652c5ddae4"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array;\n\nvoid main() {\n\tint n = to!int(readln().split()[0]);\n\twriteln( reduce!\"a + b\"(map!(to!int)(readln().split())) % n == 0 ? n : n - 1);\n}\n", "positive_code": [{"source_code": "module cf_246B;\n\nimport std.stdio;\n\nvoid main() {\n int n, num, sum = 0;\n\n readf(\"%d\", &n);\n for (int i = 0; i < n; ++i) {\n readf(\" %d\", &num);\n sum += num;\n }\n\n writeln((sum % n == 0)? n: n - 1);\n}"}], "negative_code": [], "src_uid": "71cead8cf45126902c518c9ce6e5e186"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;\r\n\r\nvoid get(Args...)(ref Args args)\r\n{\r\n import std.traits, std.meta, std.typecons;\r\n\r\n static if (Args.length == 1) {\r\n alias Arg = Args[0];\r\n \r\n static if (isArray!Arg) {\r\n static if (isSomeChar!(ElementType!Arg)) {\r\n args[0] = readln.chomp.to!Arg;\r\n } else {\r\n args[0] = readln.split.to!Arg;\r\n }\r\n } else static if (isTuple!Arg) {\r\n auto input = readln.split;\r\n static foreach (i; 0..Fields!Arg.length) {\r\n args[0][i] = input[i].to!(Fields!Arg[i]);\r\n }\r\n } else {\r\n args[0] = readln.chomp.to!Arg;\r\n }\r\n } else {\r\n auto input = readln.split;\r\n assert(input.length == Args.length);\r\n\r\n static foreach (i; 0..Args.length) {\r\n args[i] = input[i].to!(Args[i]);\r\n }\r\n }\r\n}\r\n\r\nvoid get_lines(Args...)(size_t N, ref Args args)\r\n{\r\n import std.traits, std.range;\r\n\r\n static foreach (i; 0..Args.length) {\r\n static assert(isArray!(Args[i]));\r\n args[i].length = N;\r\n }\r\n\r\n foreach (i; 0..N) {\r\n static if (Args.length == 1) {\r\n get(args[0][i]);\r\n } else {\r\n auto input = readln.split;\r\n static foreach (j; 0..Args.length) {\r\n args[j][i] = input[j].to!(ElementType!(Args[j]));\r\n }\r\n }\r\n }\r\n}\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n int N; get(N);\r\n long[] HS; get(HS);\r\n foreach (i, h; HS[0..$-1]) {\r\n if (h < i) goto ng;\r\n HS[i + 1] += h - i;\r\n }\r\n if (HS[$-1] < N-1) goto ng;\r\n writeln(\"YES\");\r\n continue;\r\n ng:\r\n writeln(\"NO\");\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\r\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\r\n\r\n//long mod = 10^^9 + 7;\r\nlong mod = 998_244_353;\r\n//long mod = 1_000_003;\r\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\r\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\r\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\r\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\r\nvoid modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }\r\n\r\nvoid main()\r\n{\r\n\tauto t = RD!int;\r\n\tauto ans = new int[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto n = RD!int;\r\n\t\tauto h = RDA;\r\n\r\n\t\tbool ok = true;\r\n\t\tlong tot;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\ttot += h[i];\r\n\t\t\tif (tot < i*(i+1)/2)\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = ok;\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e? \"YES\" : \"NO\");\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n;\r\n readf!\"%d\\n\"(n);\r\n int[] a = readln.split.map!(to!int).array;\r\n long need = 0, cur = 0;\r\n bool ok = true;\r\n foreach (i; 0 .. n)\r\n {\r\n need += i;\r\n cur += a[i];\r\n ok &= cur >= need;\r\n }\r\n writeln(ok ? \"YES\" : \"NO\");\r\n }\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n int n;\r\n readf!\"%d\\n\"(n);\r\n int[] a = readln.split.map!(to!int).array;\r\n int need = 0, cur = 0;\r\n bool ok = true;\r\n foreach (i; 0 .. n)\r\n {\r\n need += i;\r\n cur += a[i];\r\n if (cur <